Skip to content

Commit 0174162

Browse files
committed
use registry in swap
1 parent 3814912 commit 0174162

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

examples/swap/commands/deploy.ts

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const main = async (opts: any) => {
2222

2323
const initData = new ethers.utils.Interface(abi).encodeFunctionData(
2424
"initialize",
25-
[opts.uniswapRouter, opts.gasLimit, signer.address]
25+
[opts.gasLimit, signer.address]
2626
);
2727

2828
const { abi: proxyAbi, bytecode: proxyBytecode } = getAbi("ERC1967Proxy");
@@ -74,16 +74,6 @@ export const deploy = new Command("deploy")
7474
)
7575
.requiredOption("-k, --private-key <key>", "Private key")
7676
.option("-n, --name <name>", "Contract name", "Swap")
77-
.requiredOption(
78-
"-u, --uniswap-router <address>",
79-
"Uniswap V2 Router address (default: testnet)",
80-
"0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe"
81-
)
82-
.option(
83-
"-g, --gateway <address>",
84-
"Gateway address (default: testnet)",
85-
"0x6c533f7fe93fae114d0954697069df33c9b74fd7"
86-
)
8777
.option("--gas-limit <number>", "Gas limit for the transaction", "1000000")
8878
.option(
8979
"--tx-gas-limit <number>",

examples/swap/contracts/Swap.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,15 @@ contract Swap is
4040
}
4141

4242
function initialize(
43-
address uniswapRouterAddress,
4443
uint256 gasLimitAmount,
4544
address owner
4645
) external initializer {
4746
__UUPSUpgradeable_init();
4847
__Ownable_init(owner);
49-
uniswapRouter = uniswapRouterAddress;
48+
(bool active, bytes memory uniswapRouterBytes) = registry
49+
.getContractInfo(block.chainid, "uniswapV2Router02");
50+
if (!active) revert InvalidAddress();
51+
uniswapRouter = address(uint160(bytes20(uniswapRouterBytes)));
5052
gasLimit = gasLimitAmount;
5153
}
5254

examples/swap/scripts/localnet.sh

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ ZRC20_ETHEREUM=$(jq -r '."11155112".zrc20Tokens[] | select(.coinType == "gas" an
1313
USDC_ETHEREUM=$(jq -r '."11155112".zrc20Tokens[] | select(.symbol == "USDC.ETH") | .address' ~/.zetachain/localnet/registry.json) && echo $USDC_ETHEREUM
1414
GATEWAY_ETHEREUM=$(jq -r '.["11155112"].contracts[] | select(.contractType == "gateway") | .address' ~/.zetachain/localnet/registry.json) && echo $GATEWAY_ETHEREUM
1515
GATEWAY_BNB=$(jq -r '."98".contracts[] | select(.contractType == "gateway") | .address' ~/.zetachain/localnet/registry.json) && echo $GATEWAY_BNB
16-
GATEWAY_ZETACHAIN=$(jq -r '.["31337"].contracts[] | select(.contractType == "gateway") | .address' ~/.zetachain/localnet/registry.json) && echo $GATEWAY_ZETACHAIN
17-
UNISWAP_ROUTER=$(jq -r '."31337".contracts[] | select(.contractType == "uniswapV2Router02") | .address' ~/.zetachain/localnet/registry.json) && echo $UNISWAP_ROUTER
1816
WZETA=$(jq -r '."31337".contracts[] | select(.contractType == "zetaToken") | .address' ~/.zetachain/localnet/registry.json) && echo $WZETA
1917
PRIVATE_KEY=$(jq -r '.private_keys[0]' ~/.zetachain/localnet/anvil.json) && echo $PRIVATE_KEY
2018
RECIPIENT=$(cast wallet address $PRIVATE_KEY) && echo $RECIPIENT
2119
RPC=http://localhost:8545
2220

2321
UNIVERSAL=$(npx ts-node commands/index.ts deploy \
2422
--private-key $PRIVATE_KEY \
25-
--gateway $GATEWAY_ZETACHAIN \
26-
--rpc $RPC \
27-
--uniswap-router $UNISWAP_ROUTER | jq -r .contractAddress)
23+
--rpc $RPC | jq -r .contractAddress)
2824

2925
npx zetachain evm deposit-and-call \
3026
--rpc http://localhost:8545 \

0 commit comments

Comments
 (0)