Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 8, 2024
1 parent afa11f1 commit b6a444d
Show file tree
Hide file tree
Showing 7 changed files with 475 additions and 70 deletions.
42 changes: 22 additions & 20 deletions examples/swap/contracts/Swap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract Swap is UniversalContract {
address zrc20,
uint256 amount,
bytes calldata message
) external override onlyGateway {
) external onlyGateway {
Params memory params = Params({target: address(0), to: bytes("")});
if (context.chainID == BITCOIN) {
params.target = BytesHelperLib.bytesToAddress(message, 0);
Expand All @@ -55,6 +55,8 @@ contract Swap is UniversalContract {
swapAndWithdraw(zrc20, amount, params.target, params.to);
}

event Evv(address, uint256, address);

function swapAndWithdraw(
address inputToken,
uint256 amount,
Expand Down Expand Up @@ -89,28 +91,28 @@ 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);
}
// 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
})
);
// gateway.withdraw(
// recipient,
// outputAmount,
// targetToken,
// RevertOptions({
// revertAddress: address(0),
// callOnRevert: false,
// abortAddress: address(0),
// revertMessage: "",
// onRevertGasLimit: 0
// })
// );
}

function onRevert(
RevertContext calldata revertContext
) external override onlyGateway {}
) external onlyGateway {}
}
4 changes: 2 additions & 2 deletions examples/swap/contracts/SwapToAnyToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract SwapToAnyToken is UniversalContract {
address zrc20,
uint256 amount,
bytes calldata message
) external virtual override onlyGateway {
) external onlyGateway {
Params memory params = Params({
target: address(0),
to: bytes(""),
Expand Down Expand Up @@ -154,5 +154,5 @@ contract SwapToAnyToken is UniversalContract {

function onRevert(
RevertContext calldata revertContext
) external override onlyGateway {}
) external onlyGateway {}
}
4 changes: 2 additions & 2 deletions examples/swap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@types/node": ">=12.0.0",
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@zetachain/localnet": "^3.5.0",
"@zetachain/localnet": "4.0.0-rc5",
"axios": "^1.3.6",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
Expand Down Expand Up @@ -57,7 +57,7 @@
"@solana-developers/helpers": "^2.4.0",
"@solana/spl-memo": "^0.2.5",
"@solana/web3.js": "^1.95.2",
"@zetachain/protocol-contracts": "10.0.0-rc11",
"@zetachain/protocol-contracts": "11.0.0-rc3",
"@zetachain/toolkit": "13.0.0-rc5"
}
}
35 changes: 27 additions & 8 deletions examples/swap/scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
#!/bin/bash

set -e
set -x

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

yarn deploy:localnet

npx hardhat swap-from-evm --network localhost --receiver 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB --amount 1 --target 0x9fd96203f7b22bCF72d9DCb40ff98302376cE09c --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
npx hardhat swap-from-evm --network localhost --receiver 0xB0D4afd8879eD9F52b28595d31B441D079B2Ca07 --amount 10 --target 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891 --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

npx hardhat localnet-check
# if [ "$1" = "localnet" ]; then npx hardhat localnet --exit-on-error & sleep 10; fi

npx hardhat swap-from-evm --network localhost --receiver 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB --amount 1 --target 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --erc20 0x0B306BF915C4d645ff596e518fAf3F9669b97016
# echo -e "\n🚀 Compiling contracts..."
# npx hardhat compile --force --quiet

npx hardhat localnet-stop
# 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 swap-from-evm --network localhost --receiver 0x84eA74d481Ee0A5332c457a4d796187F6Ba67fEB --amount 1 --target 0x2ca7d64A7EFE2D62A725E2B35Cf7230D6677FfEe --recipient 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --erc20 0x0B306BF915C4d645ff596e518fAf3F9669b97016

# npx hardhat localnet-stop
9 changes: 8 additions & 1 deletion examples/swap/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
await contract.deployed();

if (args.json) {
console.log(JSON.stringify(contract));
console.log(
JSON.stringify({
contractAddress: contract.address,
deployer: signer.address,
network: network,
transactionHash: contract.deployTransaction.hash,
})
);
} else {
console.log(`🔑 Using account: ${signer.address}
Expand Down
2 changes: 1 addition & 1 deletion examples/swap/tasks/swapFromEVM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ task("swap-from-evm", "Swap tokens from EVM", evmDepositAndCall)
.addOptionalParam(
"gatewayEvm",
"contract address of gateway on EVM",
"0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0"
"0x610178dA211FEF7D417bC0e6FeD39F05609AD788"
)
.addFlag("callOnRevert", "Whether to call on revert")
.addOptionalParam(
Expand Down
Loading

0 comments on commit b6a444d

Please sign in to comment.