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
15 changes: 14 additions & 1 deletion internal/migrations/erc20-bridge/000-extension.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
-- This is not meant to be run on tests as the contract address is valid for mainnet only.
-- USE erc20 {
-- chain: 'sepolia',
-- escrow: '0xf6009345d772a04f4e52150b5ec91617db79be58',
-- distribution_period: '30m'
-- } AS sepolia_bridge;

-- USE erc20 {
-- chain: 'ethereum',
-- escrow: '0x964dd66477c22BC5726dfeBCf9BA49aa8625978C',
-- distribution_period: '30m'
-- } AS ethereum_bridge;
Comment thread
williamrusdyputra marked this conversation as resolved.

-- TESTING ONLY ---
-- The following is for test environments where the sepolia bridge is used. Please comment for production and use the above.
Comment thread
williamrusdyputra marked this conversation as resolved.
USE erc20 {
chain: 'sepolia',
escrow: '0x2D4f435867066737bA1617ef024E073413909Ad2'
escrow: '0x502430eD0BbE0f230215870c9C2853e126eE5Ae3'
} AS sepolia_bridge;
Comment thread
williamrusdyputra marked this conversation as resolved.
25 changes: 21 additions & 4 deletions internal/migrations/erc20-bridge/001-actions.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
CREATE OR REPLACE ACTION get_erc20_bridge_info()
-- TESTNET
CREATE OR REPLACE ACTION sepolia_get_erc20_bridge_info()
PUBLIC VIEW RETURNS (
chain TEXT,
escrow TEXT,
Expand All @@ -15,7 +16,6 @@ PUBLIC VIEW RETURNS (
}
};

-- TESTNET
CREATE OR REPLACE ACTION sepolia_wallet_balance($wallet_address TEXT) PUBLIC VIEW RETURNS (balance NUMERIC(78, 0)) {
$balance := sepolia_bridge.balance($wallet_address);
RETURN $balance;
Expand All @@ -26,11 +26,28 @@ CREATE OR REPLACE ACTION sepolia_bridge_tokens($recipient TEXT DEFAULT NULL, $am
};

-- MAINNET
CREATE OR REPLACE ACTION ethereum_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 ethereum_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 ethereum_wallet_balance($wallet_address TEXT) PUBLIC VIEW RETURNS (balance NUMERIC(78, 0)) {
$balance := mainnet_bridge.balance($wallet_address);
$balance := ethereum_bridge.balance($wallet_address);
RETURN $balance;
};

CREATE OR REPLACE ACTION ethereum_bridge_tokens($recipient TEXT DEFAULT NULL, $amount TEXT) PUBLIC {
mainnet_bridge.bridge(COALESCE($recipient, @caller), $amount::NUMERIC(78, 0));
ethereum_bridge.bridge(COALESCE($recipient, @caller), $amount::NUMERIC(78, 0));
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ CREATE OR REPLACE ACTION sepolia_transfer($to_address TEXT, $amount TEXT) PUBLIC


-- MAINNET TRANSFERS
CREATE OR REPLACE ACTION mainnet_transfer($to_address TEXT, $amount TEXT) PUBLIC {
CREATE OR REPLACE ACTION ethereum_transfer($to_address TEXT, $amount TEXT) PUBLIC {
-- Validate Ethereum address format
if NOT check_ethereum_address($to_address) {
ERROR('Invalid Ethereum address format. Must be a valid Ethereum address: ' || $to_address);
Expand All @@ -31,6 +31,6 @@ CREATE OR REPLACE ACTION mainnet_transfer($to_address TEXT, $amount TEXT) PUBLIC
}

-- Execute transfer using the bridge extension
mainnet_bridge.transfer($to_address, $amount::NUMERIC(78, 0));
ethereum_bridge.transfer($to_address, $amount::NUMERIC(78, 0));
};

Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func getBridgeEscrowAddress(ctx context.Context, platform *kwilTesting.Platform)
engineCtx := engCtx(ctx, platform, "0x0000000000000000000000000000000000000000", 1, false)

var escrow string
res, err := platform.Engine.Call(engineCtx, platform.DB, "", "get_erc20_bridge_info", []any{}, func(row *common.Row) error {
res, err := platform.Engine.Call(engineCtx, platform.DB, "", "sepolia_get_erc20_bridge_info", []any{}, func(row *common.Row) error {
if len(row.Values) < 2 {
return fmt.Errorf("expected at least 2 columns, got %d", len(row.Values))
}
Expand Down
Loading