Skip to content

Commit

Permalink
replace system contract with uniswap router
Browse files Browse the repository at this point in the history
  • Loading branch information
fadeev committed Nov 18, 2024
1 parent 85f91be commit 1495357
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 58 deletions.
10 changes: 5 additions & 5 deletions examples/nft/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract Universal is
Events
{
GatewayZEVM public immutable gateway;
SystemContract public immutable systemContract;
address public immutable uniswapRouter;
uint256 private _nextTokenId;
bool public isUniversal = true;
uint256 public gasLimit;
Expand All @@ -46,16 +46,16 @@ contract Universal is
string memory name,
string memory symbol,
uint256 gas,
address systemContractAddress
address uniswapRouterAddress
) ERC721(name, symbol) Ownable(owner) {
if (
gatewayAddress == address(0) ||
owner == address(0) ||
systemContractAddress == address(0)
uniswapRouterAddress == address(0)
) revert InvalidAddress();
if (gas == 0) revert InvalidGasLimit();
gateway = GatewayZEVM(gatewayAddress);
systemContract = SystemContract(systemContractAddress);
uniswapRouter = uniswapRouterAddress;
gasLimit = gas;
}

Expand Down Expand Up @@ -144,7 +144,7 @@ contract Universal is
);

SwapHelperLib.swapExactTokensForTokens(
systemContract,
uniswapRouter,
zrc20,
amount,
destination,
Expand Down
2 changes: 1 addition & 1 deletion examples/nft/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@zetachain/localnet": "4.0.0-rc6",
"@zetachain/toolkit": "13.0.0-rc7",
"@zetachain/toolkit": "13.0.0-rc8",
"axios": "^1.3.6",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
Expand Down
4 changes: 2 additions & 2 deletions examples/nft/scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ ZRC20_BNB=$(jq -r '.addresses[] | select(.type=="ZRC-20 BNB on 97") | .address'
GATEWAY_ZETACHAIN=$(jq -r '.addresses[] | select(.type=="gatewayZEVM" and .chain=="zetachain") | .address' localnet.json)
GATEWAY_ETHEREUM=$(jq -r '.addresses[] | select(.type=="gatewayEVM" and .chain=="ethereum") | .address' localnet.json)
GATEWAY_BNB=$(jq -r '.addresses[] | select(.type=="gatewayEVM" and .chain=="bnb") | .address' localnet.json)
SYSTEM_CONTRACT=$(jq -r '.addresses[] | select(.type=="systemContract" and .chain=="zetachain") | .address' localnet.json)
UNISWAP_ROUTER=$(jq -r '.addresses[] | select(.type=="uniswapRouterInstance" and .chain=="zetachain") | .address' localnet.json)
SENDER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

CONTRACT_ZETACHAIN=$(npx hardhat deploy --network localhost --gateway "$GATEWAY_ZETACHAIN" --system-contract "$SYSTEM_CONTRACT" --json | jq -r '.contractAddress')
CONTRACT_ZETACHAIN=$(npx hardhat deploy --network localhost --gateway "$GATEWAY_ZETACHAIN" --uniswap-router "$UNISWAP_ROUTER" --json | jq -r '.contractAddress')
echo -e "\n🚀 Deployed NFT contract on ZetaChain: $CONTRACT_ZETACHAIN"

CONTRACT_ETHEREUM=$(npx hardhat deploy --name Connected --json --network localhost --gateway "$GATEWAY_ETHEREUM" | jq -r '.contractAddress')
Expand Down
4 changes: 2 additions & 2 deletions examples/nft/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
args.tokenName,
args.tokenSymbol,
args.gasLimit,
...(args.systemContract ? [args.systemContract] : []),
...(args.uniswapRouter ? [args.uniswapRouter] : []),
{
gasPrice: args.deployGasPrice,
}
Expand Down Expand Up @@ -64,4 +64,4 @@ task("deploy", "Deploy the NFT contract", main)
"Gas price for deploy transaction",
"10000000000"
)
.addOptionalParam("systemContract", "System contract address");
.addOptionalParam("uniswapRouter", "Uniswap v2 router address on ZetaChain");
8 changes: 4 additions & 4 deletions examples/nft/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2780,10 +2780,10 @@
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-9.0.0.tgz#c20ad5da43f6f3676f31556b303d1cb4ea17357e"
integrity sha512-L4A8bddlyhjaBAsIv/x1Bvxc38RJz8U8rbbBtxK5oVyOAd5Zz04ZiT3HqzO4FuKq6RGGM1uiA8jvUfmRkKchXw==

"@zetachain/[email protected]rc7":
version "13.0.0-rc7"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-13.0.0-rc7.tgz#d8710dfeed6c84d7d5808de253887da3e67bf050"
integrity sha512-rh9q66iipRF3XJ4jlkawYqc10eA2mYgIS2rl1PiWvcqi39R1PgUzperKVwwoVmRuJi0FxE5fetP4SmqzfkfBXw==
"@zetachain/[email protected]rc8":
version "13.0.0-rc8"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-13.0.0-rc8.tgz#1f8b975428f6f1b7bdef4ccc0a1312de81f90e7d"
integrity sha512-lXAyyMpgN/dsGIUTR/hi5M+6/tsnzONLAaisAnJzsrEUB4nYkoZtQCR4lwP4oWhNl4i3SK5k+bFjAfBo1DU3iw==
dependencies:
"@coral-xyz/anchor" "^0.30.1"
"@inquirer/prompts" "^2.1.1"
Expand Down
10 changes: 5 additions & 5 deletions examples/swap/contracts/Swap.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "@zetachain/protocol-contracts/contracts/zevm/interfaces/IGatewayZEVM.sol
import {GatewayZEVM} from "@zetachain/protocol-contracts/contracts/zevm/GatewayZEVM.sol";

contract Swap is UniversalContract {
SystemContract public systemContract;
address public immutable uniswapRouter;
GatewayZEVM public gateway;
uint256 constant BITCOIN = 18332;

Expand All @@ -21,8 +21,8 @@ contract Swap is UniversalContract {
_;
}

constructor(address systemContractAddress, address payable gatewayAddress) {
systemContract = SystemContract(systemContractAddress);
constructor(address payable gatewayAddress, address uniswapRouterAddress) {

Check notice

Code scanning / Slither

Missing zero address validation Low

uniswapRouter = uniswapRouterAddress;
gateway = GatewayZEVM(gatewayAddress);
}

Expand Down Expand Up @@ -74,7 +74,7 @@ contract Swap is UniversalContract {
swapAmount = amount - gasFee;
} else {
inputForGas = SwapHelperLib.swapTokensForExactTokens(
systemContract,
uniswapRouter,
inputToken,
gasFee,
gasZRC20,
Expand All @@ -84,7 +84,7 @@ contract Swap is UniversalContract {
}

uint256 outputAmount = SwapHelperLib.swapExactTokensForTokens(
systemContract,
uniswapRouter,
inputToken,
swapAmount,
targetToken,
Expand Down
10 changes: 5 additions & 5 deletions examples/swap/contracts/SwapToAnyToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "@zetachain/protocol-contracts/contracts/zevm/interfaces/IWZETA.sol";
import {GatewayZEVM} from "@zetachain/protocol-contracts/contracts/zevm/GatewayZEVM.sol";

contract SwapToAnyToken is UniversalContract {
SystemContract public systemContract;
address public immutable uniswapRouter;
GatewayZEVM public gateway;
uint256 constant BITCOIN = 18332;

Expand All @@ -22,8 +22,8 @@ contract SwapToAnyToken is UniversalContract {
_;
}

constructor(address systemContractAddress, address payable gatewayAddress) {
systemContract = SystemContract(systemContractAddress);
constructor(address payable gatewayAddress, address uniswapRouterAddress) {

Check notice

Code scanning / Slither

Missing zero address validation Low

uniswapRouter = uniswapRouterAddress;
gateway = GatewayZEVM(gatewayAddress);
}

Expand Down Expand Up @@ -92,7 +92,7 @@ contract SwapToAnyToken is UniversalContract {
swapAmount = amount - gasFee;
} else {
inputForGas = SwapHelperLib.swapTokensForExactTokens(
systemContract,
uniswapRouter,
inputToken,
gasFee,
gasZRC20,
Expand All @@ -103,7 +103,7 @@ contract SwapToAnyToken is UniversalContract {
}

uint256 outputAmount = SwapHelperLib.swapExactTokensForTokens(
systemContract,
uniswapRouter,
inputToken,
swapAmount,
targetToken,
Expand Down
2 changes: 1 addition & 1 deletion examples/swap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@
"@solana/spl-memo": "^0.2.5",
"@solana/web3.js": "^1.95.2",
"@zetachain/protocol-contracts": "11.0.0-rc3",
"@zetachain/toolkit": "13.0.0-rc7"
"@zetachain/toolkit": "13.0.0-rc8"
}
}
3 changes: 2 additions & 1 deletion examples/swap/scripts/localnet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ ZRC20_ETHEREUM=$(jq -r '.addresses[] | select(.type=="ZRC-20 ETH on 5") | .addre
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)
UNISWAP_ROUTER=$(jq -r '.addresses[] | select(.type=="uniswapRouterInstance" and .chain=="zetachain") | .address' localnet.json)
SENDER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266

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

npx hardhat swap-from-evm \
Expand Down
10 changes: 3 additions & 7 deletions examples/swap/tasks/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {

const factory = await hre.ethers.getContractFactory(args.name);
const contract = await (factory as any).deploy(
args.systemContract,
args.gateway
args.gateway,
args.uniswapRouter
);
await contract.deployed();

Expand All @@ -39,11 +39,7 @@ const main = async (args: any, hre: HardhatRuntimeEnvironment) => {
task("deploy", "Deploy the contract", main)
.addFlag("json", "Output in JSON")
.addOptionalParam("name", "Contract to deploy", "Swap")
.addOptionalParam(
"systemContract",
"System contract",
"0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9"
)
.addOptionalParam("uniswapRouter", "Uniswap v2 Router address on ZetaChain")
.addOptionalParam(
"gateway",
"Gateway address (default: ZetaChain Gateway)",
Expand Down
18 changes: 4 additions & 14 deletions examples/swap/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2513,25 +2513,15 @@
"@zetachain/networks" "^10.0.0"
ethers "5.6.8"

"@zetachain/[email protected]":
version "10.0.0-rc11"
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-10.0.0-rc11.tgz#53f55ead492f7b5802b1feae4e51abc75730af33"
integrity sha512-qWazjqnIGRngf4OmyeSIv7sHICQRdMQ1CKPIQIqxA8qFR+gHhDHSfvMdRAvgWbsfkimXOIFiHVIATypyWhviJw==
dependencies:
"@openzeppelin/contracts" "^5.0.2"
"@openzeppelin/contracts-upgradeable" "^5.0.2"
"@zetachain/networks" "^10.0.0"
ethers "^6.13.1"

"@zetachain/[email protected]":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-9.0.0.tgz#c20ad5da43f6f3676f31556b303d1cb4ea17357e"
integrity sha512-L4A8bddlyhjaBAsIv/x1Bvxc38RJz8U8rbbBtxK5oVyOAd5Zz04ZiT3HqzO4FuKq6RGGM1uiA8jvUfmRkKchXw==

"@zetachain/[email protected]rc7":
version "13.0.0-rc7"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-13.0.0-rc7.tgz#d8710dfeed6c84d7d5808de253887da3e67bf050"
integrity sha512-rh9q66iipRF3XJ4jlkawYqc10eA2mYgIS2rl1PiWvcqi39R1PgUzperKVwwoVmRuJi0FxE5fetP4SmqzfkfBXw==
"@zetachain/[email protected]rc8":
version "13.0.0-rc8"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-13.0.0-rc8.tgz#1f8b975428f6f1b7bdef4ccc0a1312de81f90e7d"
integrity sha512-lXAyyMpgN/dsGIUTR/hi5M+6/tsnzONLAaisAnJzsrEUB4nYkoZtQCR4lwP4oWhNl4i3SK5k+bFjAfBo1DU3iw==
dependencies:
"@coral-xyz/anchor" "^0.30.1"
"@inquirer/prompts" "^2.1.1"
Expand Down
8 changes: 4 additions & 4 deletions examples/token/contracts/Universal.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "./shared/Events.sol";

contract Universal is ERC20, Ownable2Step, UniversalContract, Events {
GatewayZEVM public immutable gateway;
SystemContract public immutable systemContract;
address public immutable uniswapRouter;
uint256 private _nextTokenId;
bool public isUniversal = true;
uint256 public gasLimit;
Expand All @@ -36,13 +36,13 @@ contract Universal is ERC20, Ownable2Step, UniversalContract, Events {
string memory name,
string memory symbol,
uint256 gas,
address systemContractAddress
address uniswapRouterAddress

Check notice

Code scanning / Slither

Missing zero address validation Low

) ERC20(name, symbol) Ownable(owner) {
if (gatewayAddress == address(0) || owner == address(0))
revert InvalidAddress();
if (gas == 0) revert InvalidGasLimit();
gateway = GatewayZEVM(gatewayAddress);
systemContract = SystemContract(systemContractAddress);
uniswapRouter = uniswapRouterAddress;
gasLimit = gas;
}

Expand Down Expand Up @@ -112,7 +112,7 @@ contract Universal is ERC20, Ownable2Step, UniversalContract, Events {
gasLimit
);
SwapHelperLib.swapExactTokensForTokens(
systemContract,
uniswapRouter,
zrc20,
amount,
destination,
Expand Down
2 changes: 1 addition & 1 deletion examples/token/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@typescript-eslint/eslint-plugin": "^5.59.9",
"@typescript-eslint/parser": "^5.59.9",
"@zetachain/localnet": "4.0.0-rc4",
"@zetachain/toolkit": "13.0.0-rc4",
"@zetachain/toolkit": "13.0.0-rc8",
"axios": "^1.3.6",
"chai": "^4.2.0",
"dotenv": "^16.0.3",
Expand Down
13 changes: 7 additions & 6 deletions examples/token/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2758,7 +2758,7 @@
hardhat "^2.22.8"
wait-on "^7.2.0"

"@zetachain/networks@^10.0.0":
"@zetachain/networks@10.0.0", "@zetachain/networks@^10.0.0":
version "10.0.0"
resolved "https://registry.yarnpkg.com/@zetachain/networks/-/networks-10.0.0.tgz#dd5d14a0870f6b658644aded8c96859f15531089"
integrity sha512-FPolaO19oVkSLSPDUA/Hu+8AhG3lDEslRDpLnMzbMbnNSC669Fkah0/TEf+6egrQbAifBRfFLzwWidAGs8oxtA==
Expand All @@ -2780,10 +2780,10 @@
resolved "https://registry.yarnpkg.com/@zetachain/protocol-contracts/-/protocol-contracts-9.0.0.tgz#c20ad5da43f6f3676f31556b303d1cb4ea17357e"
integrity sha512-L4A8bddlyhjaBAsIv/x1Bvxc38RJz8U8rbbBtxK5oVyOAd5Zz04ZiT3HqzO4FuKq6RGGM1uiA8jvUfmRkKchXw==

"@zetachain/[email protected]rc4":
version "13.0.0-rc4"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-13.0.0-rc4.tgz#e137fc16043f1416469f709c48808cfa301d9299"
integrity sha512-4z4MKbQKjRIeNruUyDBjZDRO5oTLa1w/7wVn+PfMsXn++mFFGkiawkLcitnkH9dadBJiERzmo89MRJxsLQ3U6w==
"@zetachain/[email protected]rc8":
version "13.0.0-rc8"
resolved "https://registry.yarnpkg.com/@zetachain/toolkit/-/toolkit-13.0.0-rc8.tgz#1f8b975428f6f1b7bdef4ccc0a1312de81f90e7d"
integrity sha512-lXAyyMpgN/dsGIUTR/hi5M+6/tsnzONLAaisAnJzsrEUB4nYkoZtQCR4lwP4oWhNl4i3SK5k+bFjAfBo1DU3iw==
dependencies:
"@coral-xyz/anchor" "^0.30.1"
"@inquirer/prompts" "^2.1.1"
Expand All @@ -2794,12 +2794,13 @@
"@solana/web3.js" "^1.95.3"
"@uniswap/v2-periphery" "^1.1.0-beta.0"
"@zetachain/faucet-cli" "^4.1.1"
"@zetachain/networks" "^10.0.0"
"@zetachain/networks" "10.0.0"
"@zetachain/protocol-contracts" "9.0.0"
axios "^1.4.0"
bech32 "^2.0.0"
bip39 "^3.1.0"
bitcoinjs-lib "^6.1.3"
bs58 "^6.0.0"
dotenv "16.0.3"
ecpair "^2.1.0"
envfile "^6.18.0"
Expand Down

0 comments on commit 1495357

Please sign in to comment.