Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ require (
github.com/spf13/cobra v1.9.1
github.com/stretchr/testify v1.10.0
github.com/testcontainers/testcontainers-go v0.37.0
github.com/trufnetwork/kwil-db v0.10.3-0.20251204134443-d43bfe5b400b
github.com/trufnetwork/kwil-db/core v0.4.3-0.20251204134443-d43bfe5b400b
github.com/trufnetwork/kwil-db v0.10.3-0.20251229074241-278c1930ac63
github.com/trufnetwork/kwil-db/core v0.4.3-0.20251229074241-278c1930ac63
github.com/trufnetwork/sdk-go v0.3.2-0.20250630062504-841b40cdb709
go.uber.org/zap v1.27.0
golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1214,8 +1214,12 @@ github.com/tklauser/numcpus v0.9.0 h1:lmyCHtANi8aRUgkckBgoDk1nHCux3n2cgkJLXdQGPD
github.com/tklauser/numcpus v0.9.0/go.mod h1:SN6Nq1O3VychhC1npsWostA+oW+VOQTxZrS604NSRyI=
github.com/trufnetwork/kwil-db v0.10.3-0.20251204134443-d43bfe5b400b h1:IAYxPaxlsn7+63cvZjrCcQKoWeKOXNPqp9NGifecKqw=
github.com/trufnetwork/kwil-db v0.10.3-0.20251204134443-d43bfe5b400b/go.mod h1:LiBAC48uZl2B0IiLtD2hpOce7RNfpuDdghVAOc3u1Qo=
github.com/trufnetwork/kwil-db v0.10.3-0.20251229074241-278c1930ac63 h1:MqZsMaNyX3sF/hSPF+8e7k8Rg+YJxU8jX8jHPr096x4=
github.com/trufnetwork/kwil-db v0.10.3-0.20251229074241-278c1930ac63/go.mod h1:LiBAC48uZl2B0IiLtD2hpOce7RNfpuDdghVAOc3u1Qo=
github.com/trufnetwork/kwil-db/core v0.4.3-0.20251204134443-d43bfe5b400b h1:CGtjMi1JqG/z1g+hnLVpYNS0yHz4Yif7Zflj6tzyTM8=
github.com/trufnetwork/kwil-db/core v0.4.3-0.20251204134443-d43bfe5b400b/go.mod h1:HnOsh9+BN13LJCjiH0+XKaJzyjWKf+H9AofFFp90KwQ=
github.com/trufnetwork/kwil-db/core v0.4.3-0.20251229074241-278c1930ac63 h1:M3eB0d2Vq9uI1vrYWPUW8nFow6qrKpTvMLvdQAnHNwU=
github.com/trufnetwork/kwil-db/core v0.4.3-0.20251229074241-278c1930ac63/go.mod h1:HnOsh9+BN13LJCjiH0+XKaJzyjWKf+H9AofFFp90KwQ=
github.com/trufnetwork/openzeppelin-merkle-tree-go v0.0.2 h1:DCq8MzbWH0wZmICNmMVsSzUHUPl+2vqRhluEABjxl88=
github.com/trufnetwork/openzeppelin-merkle-tree-go v0.0.2/go.mod h1:Y0MJpPp9QXU5vC6Gpoilql2NkgmGNcbHm9HYC2v2N8s=
github.com/trufnetwork/sdk-go v0.3.2-0.20250630062504-841b40cdb709 h1:d9EqPXIjbq/atzEncK5dM3Z9oStx1BxCGuL/sjefeCw=
Expand Down
9 changes: 8 additions & 1 deletion internal/migrations/erc20-bridge/000-extension.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@
USE erc20 {
chain: 'sepolia',
escrow: '0x502430eD0BbE0f230215870c9C2853e126eE5Ae3'
} AS sepolia_bridge;
} AS sepolia_bridge;

-- The following is for test environments where the hoodi bridge is used. Please comment for production and use the above.
USE erc20 {
chain: 'hoodi',
escrow: '0x878d6aaeb6e746033f50b8dc268d54b4631554e7',
distribution_period: '30m'
} AS hoodi_bridge;
60 changes: 59 additions & 1 deletion internal/migrations/erc20-bridge/001-actions.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,62 @@
-- TESTNET
-- HOODI TESTNET
CREATE OR REPLACE ACTION hoodi_get_erc20_bridge_info()
PUBLIC VIEW RETURNS (
chain TEXT,
escrow TEXT,
epoch_period TEXT,
erc20 TEXT,
decimals INT,
balance NUMERIC(78, 0),
synced BOOLEAN,
synced_at INT8,
enabled BOOLEAN
) {
FOR $row IN hoodi_bridge.info() {
RETURN $row.chain, $row.escrow, $row.epoch_period, $row.erc20, $row.decimals, $row.balance, $row.synced, $row.synced_at, $row.enabled;
}
};

CREATE OR REPLACE ACTION hoodi_wallet_balance($wallet_address TEXT) PUBLIC VIEW RETURNS (balance NUMERIC(78, 0)) {
$balance := hoodi_bridge.balance($wallet_address);
RETURN $balance;
};

CREATE OR REPLACE ACTION hoodi_bridge_tokens($recipient TEXT DEFAULT NULL, $amount TEXT) PUBLIC {
-- ===== FEE COLLECTION (NO EXEMPTION - USER-FACING OPERATION) =====
$withdrawal_fee := '40000000000000000000'::NUMERIC(78, 0); -- 40 TRUF with 18 decimals
$withdrawal_amount := $amount::NUMERIC(78, 0);
$total_required := $withdrawal_amount + $withdrawal_fee;

$caller_balance := COALESCE(hoodi_bridge.balance(@caller), 0::NUMERIC(78, 0));

IF $caller_balance < $total_required {
ERROR('Insufficient balance for withdrawal. Required: ' ||
($total_required / '1000000000000000000'::NUMERIC(78, 0))::TEXT ||
' TRUF (' || $withdrawal_amount::TEXT || ' wei withdrawal + ' ||
($withdrawal_fee / '1000000000000000000'::NUMERIC(78, 0))::TEXT || ' TRUF fee)');
}

IF @leader_sender IS NULL {
ERROR('Leader address not available for fee transfer');
}
$leader_hex TEXT := encode(@leader_sender, 'hex')::TEXT;
hoodi_bridge.transfer($leader_hex, $withdrawal_fee);
-- ===== END FEE COLLECTION =====

$bridge_recipient TEXT := LOWER(COALESCE($recipient, @caller));

-- Execute withdrawal using the bridge extension
hoodi_bridge.bridge($bridge_recipient, $withdrawal_amount);

record_transaction_event(
5,
$withdrawal_fee,
'0x' || $leader_hex,
NULL
);
};

-- SEPOLIA TESTNET (kept for reference)
CREATE OR REPLACE ACTION sepolia_get_erc20_bridge_info()
PUBLIC VIEW RETURNS (
chain TEXT,
Expand Down
Loading
Loading