Skip to content

Commit

Permalink
swap works
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 8, 2024
1 parent b6a444d commit a5e15a1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 47 deletions.
38 changes: 19 additions & 19 deletions examples/swap/contracts/Swap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,25 +91,25 @@ contract Swap is UniversalContract {
0
);

// if (gasZRC20 == targetToken) {
// IZRC20(gasZRC20).approve(address(gateway), outputAmount + gasFee);
// } else {
// IZRC20(gasZRC20).approve(address(gateway), gasFee);
// IZRC20(targetToken).approve(address(gateway), outputAmount);
// }

// gateway.withdraw(
// recipient,
// outputAmount,
// targetToken,
// RevertOptions({
// revertAddress: address(0),
// callOnRevert: false,
// abortAddress: address(0),
// revertMessage: "",
// onRevertGasLimit: 0
// })
// );
if (gasZRC20 == targetToken) {
IZRC20(gasZRC20).approve(address(gateway), outputAmount + gasFee);
} else {
IZRC20(gasZRC20).approve(address(gateway), gasFee);
IZRC20(targetToken).approve(address(gateway), outputAmount);
}

gateway.withdraw(
recipient,
outputAmount,
targetToken,
RevertOptions({
revertAddress: address(0),
callOnRevert: false,
abortAddress: address(0),
revertMessage: "",
onRevertGasLimit: 0
})
);
}

function onRevert(
Expand Down
4 changes: 2 additions & 2 deletions examples/swap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test": "echo \"Error: no test specified\" && exit 1",
"lint:fix": "npx eslint . --ext .js,.ts --fix",
"lint": "npx eslint . --ext .js,.ts",
"deploy:localnet": "npx hardhat compile --force && npx hardhat deploy --network localhost --gateway 0x9A676e781A523b5d0C0e43731313A708CB607508",
"deploy:localnet": "npx hardhat compile --force && npx hardhat deploy --network localhost --gateway 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707",
"deploy-any:localnet": "npx hardhat compile --force && npx hardhat deploy --name SwapToAnyToken --network localhost --gateway 0x9A676e781A523b5d0C0e43731313A708CB607508"
},
"keywords": [],
Expand Down Expand Up @@ -60,4 +60,4 @@
"@zetachain/protocol-contracts": "11.0.0-rc3",
"@zetachain/toolkit": "13.0.0-rc5"
}
}
}
44 changes: 20 additions & 24 deletions examples/swap/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
#!/bin/bash

set -e
set -x

npx hardhat deploy --name Swap --network localhost --gateway 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 --json
if [ "$1" = "localnet" ]; then npx hardhat localnet --exit-on-error & sleep 10; fi

echo -e "\n🚀 Compiling contracts..."
npx hardhat compile --force --quiet

npx hardhat swap-from-evm --network localhost --receiver 0xB0D4afd8879eD9F52b28595d31B441D079B2Ca07 --amount 10 --target 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891 --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
ZRC20_ETHEREUM=$(jq -r '.addresses[] | select(.type=="ZRC-20 ETH on 5") | .address' localnet.json)
ZRC20_USDC=$(jq -r '.addresses[] | select(.type=="ZRC-20 USDC on 97") | .address' localnet.json)
GATEWAY_ETHEREUM=$(jq -r '.addresses[] | select(.type=="gatewayEVM" and .chain=="ethereum") | .address' localnet.json)
GATEWAY_ZETACHAIN=$(jq -r '.addresses[] | select(.type=="gatewayZEVM" and .chain=="zetachain") | .address' localnet.json)
SENDER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

# if [ "$1" = "localnet" ]; then npx hardhat localnet --exit-on-error & sleep 10; fi
CONTRACT_ZETACHAIN=$(npx hardhat deploy --name Swap --network localhost --gateway "$GATEWAY_ZETACHAIN" --json | jq -r '.contractAddress')
echo -e "\n🚀 Deployed contract on ZetaChain: $CONTRACT_ZETACHAIN"

# echo -e "\n🚀 Compiling contracts..."
# npx hardhat compile --force --quiet
npx hardhat swap-from-evm \
--network localhost \
--receiver "$CONTRACT_ZETACHAIN" \
--amount 1 \
--target "$ZRC20_USDC" \
--recipient "$SENDER"

# ZRC20_ETHEREUM=$(jq -r '.addresses[] | select(.type=="ZRC-20 ETH on 5") | .address' localnet.json)
# ZRC20_USDC=$(jq -r '.addresses[] | select(.type=="ZRC-20 USDC on 5") | .address' localnet.json)
# GATEWAY_ETHEREUM=$(jq -r '.addresses[] | select(.type=="gatewayEVM" and .chain=="ethereum") | .address' localnet.json)
# GATEWAY_ZETACHAIN=$(jq -r '.addresses[] | select(.type=="gatewayZEVM" and .chain=="zetachain") | .address' localnet.json)
# SENDER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

# CONTRACT_ZETACHAIN=$(npx hardhat deploy --name Swap --network localhost --gateway "$GATEWAY_ZETACHAIN" --json | jq -r '.contractAddress')
# echo -e "\n🚀 Deployed contract on ZetaChain: $CONTRACT_ZETACHAIN"

# npx hardhat swap-from-evm \
# --network localhost \
# --receiver "$CONTRACT_ZETACHAIN" \
# --amount 10 \
# --target "$ZRC20_USDC" \
# --recipient "$SENDER"

# npx hardhat localnet-check
npx hardhat localnet-check

# npx hardhat swap-from-evm --network localhost --receiver 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB --amount 1 --target 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --erc20 0x0B306BF915C4d645ff596e518fAf3F9669b97016

# npx hardhat localnet-stop
# npx hardhat localnet-stop

if [ "$1" = "localnet" ]; then npx hardhat localnet-stop; fi
4 changes: 2 additions & 2 deletions examples/swap/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ task("deploy", "Deploy the contract", main)
.addOptionalParam(
"systemContract",
"System contract",
"0xA51c1fc2f0D1a1b8494Ed1FE312d7C3a78Ed91C0"
"0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"
)
.addOptionalParam(
"gateway",
"Gateway address (default: ZetaChain Gateway)",
"0x9A676e781A523b5d0C0e43731313A708CB607508"
"0x5FC8d32690cc91D4c39d9d3abcBD16989F875707"
);

0 comments on commit a5e15a1

Please sign in to comment.