From 440cf40851ed00008ffaeb8967992c53958b4552 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Tue, 25 Mar 2025 14:41:31 +0300 Subject: [PATCH 01/15] Sui withdraw and call example --- .../tutorials/sui-withdraw-and-call.mdx | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/pages/developers/tutorials/sui-withdraw-and-call.mdx diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx new file mode 100644 index 000000000..13c1ada8b --- /dev/null +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -0,0 +1,94 @@ +``` +PUBLISHED=$(sui client publish --skip-dependency-verification --json) && echo $PUBLISHED +``` + +``` +PACKAGE=$(echo $PUBLISHED | jq -r '.objectChanges[] | select(.type == "published") | .packageId') && echo $PACKAGE +``` + +``` +TREASURY=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "0x2::coin::TreasuryCap<\($pkg)::token::TOKEN>") | .objectId') && echo $TREASURY +``` + +``` +POOL=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Pool<0x2::sui::SUI, \($pkg)::token::TOKEN>") | .objectId') && echo $POOL +``` + +``` +RECIPIENT=$(sui client active-address) && echo $RECIPIENT +``` + +``` +sui client call \ + --package "$PACKAGE" \ + --module token \ + --function mint \ + --args "$TREASURY" 1000000 "$RECIPIENT" +``` + +``` +TOKEN=$(sui client objects --json | jq -r --arg pkg "$PACKAGE" '.[].data | select(.type == "0x2::coin::Coin<\($pkg)::token::TOKEN>") | .objectId') && echo $TOKEN +``` + +``` +sui client call \ + --package "$PACKAGE" \ + --module cetusmock \ + --function deposit \ + --type-args "0x2::sui::SUI" "$PACKAGE::token::TOKEN" \ + --args "$POOL" "$TOKEN" +``` + +``` +COIN=$(sui client gas --json | jq -r '.[0].gasCoinId') && echo $COIN +``` + +``` +ETH_ADDRESS=0x4955a3F38ff86ae92A914445099caa8eA2B9bA32 +GATEWAY_PACKAGE=0x277523e54387b83a6826bd6e3b91b9dbd16a058d149dd57f4ebb379ae54549ae +GATEWAY_OBJECT=0xd0972cb4ab7bf0b35b249c6b1e1bd06ad7b860c8584adf27eb261fdf8add8fac +``` + +``` +sui client call \ + --package "$GATEWAY_PACKAGE" \ + --module gateway \ + --function deposit \ + --type-args 0x2::sui::SUI \ + --args "$GATEWAY_OBJECT" "$COIN" "$ETH_ADDRESS" +``` + +``` +cast send 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891 "approve(address,uint256)" 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 1000000000000000000000000 --private-key ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +``` + +``` +CONFIG=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::GlobalConfig") | .objectId') && echo $CONFIG +``` + +``` +CLOCK=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Clock") | .objectId') && echo $CLOCK +``` + +``` +PARTNER=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Partner") | .objectId') && echo $PARTNER +``` + +``` +MESSAGE=$RECIPIENT && echo $MESSAGE +``` + +``` +PAYLOAD=$(npx ts-node sui/setup/encodeCallArgs.ts "$TOKEN_TYPE" "$CONFIG,$POOL,$PARTNER,$CLOCK" "$MESSAGE") && echo $PAYLOAD +``` + +``` +cast send 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 "withdrawAndCall(bytes,uint256,address,bytes,(uint256,bool),(address,bool,address,bytes,uint256))" \ + "$PACKAGE" \ + "1000000" \ + "0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891" \ + "$PAYLOAD" \ + "(10000,false)" \ + "(0xB0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,true,0xC0b86991c6218b36c1d19D4a2e9Eb0cE3606eB49,0xdeadbeef,50000)" \ + --private-key ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +``` From 8abd5d8dc951d0e733f3c42886d7810267578122 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Tue, 25 Mar 2025 15:37:58 +0300 Subject: [PATCH 02/15] add token type --- src/pages/developers/tutorials/sui-withdraw-and-call.mdx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index 13c1ada8b..0137ff4ad 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -45,8 +45,8 @@ COIN=$(sui client gas --json | jq -r '.[0].gasCoinId') && echo $COIN ``` ETH_ADDRESS=0x4955a3F38ff86ae92A914445099caa8eA2B9bA32 -GATEWAY_PACKAGE=0x277523e54387b83a6826bd6e3b91b9dbd16a058d149dd57f4ebb379ae54549ae -GATEWAY_OBJECT=0xd0972cb4ab7bf0b35b249c6b1e1bd06ad7b860c8584adf27eb261fdf8add8fac +GATEWAY_PACKAGE=0xa3ce10f68ed22d2cbbc31eaa709ee15e2e30348bfc6ff97b7d128d03b679c5c2 +GATEWAY_OBJECT=0xe925d4059435083b70bc504ce912202214edd06f693bdc3f9573a996292780c7 ``` ``` @@ -78,6 +78,10 @@ PARTNER=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | selec MESSAGE=$RECIPIENT && echo $MESSAGE ``` +``` +TOKEN_TYPE=$(echo "$PACKAGE::token::TOKEN") && echo $TOKEN_TYPE +``` + ``` PAYLOAD=$(npx ts-node sui/setup/encodeCallArgs.ts "$TOKEN_TYPE" "$CONFIG,$POOL,$PARTNER,$CLOCK" "$MESSAGE") && echo $PAYLOAD ``` From 9ee04fd2864b2cfbb92103792c71bd2308822136 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 9 Apr 2025 16:06:50 +0300 Subject: [PATCH 03/15] doc --- .../tutorials/sui-withdraw-and-call.mdx | 150 ++++++++++++++---- 1 file changed, 118 insertions(+), 32 deletions(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index 0137ff4ad..b2d636615 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -1,24 +1,108 @@ +Interacting with ZetaChain universal apps from the Sui blockchain includes the +ability to withdraw tokens back to Sui while simultaneously executing contract +calls. This functionality allows for seamless cross-chain operations where you +can both withdraw assets and trigger contract logic in a single transaction. + +In this tutorial, you'll: + +- Set up a local development environment using + [localnet](/developers/tutorials/localnet). +- Deploy a universal contract on ZetaChain. +- Deploy a mock Cetus pool contract on Sui. +- Execute withdraw-and-call to withdraw tokens and call a contract on Sui in a + single transaction. + +By the end, you'll understand how to perform complex cross-chain operations that +combine asset withdrawals with contract calls on Sui. + +## Prerequisites + +Ensure you have installed and configured the following tools before starting: + +- [Sui CLI](https://docs.sui.io/references/cli): Required for starting a local + Sui node and interacting with it. +- [Foundry](https://getfoundry.sh/): Needed for encoding payload data using ABI. +- [jq](https://stedolan.github.io/jq/): Required for parsing JSON output from + Sui CLI. + +## Clone the Example Project + +Begin by cloning the example contracts repository and installing its +dependencies: + +```bash +git clone https://github.com/zeta-chain/example-contracts +cd example-contracts/examples/call +yarn ``` -PUBLISHED=$(sui client publish --skip-dependency-verification --json) && echo $PUBLISHED + +## Launch Localnet + +Start your local development environment, which sets up instances of ZetaChain +and Sui: + +```bash +npx hardhat localnet ``` +Keep this terminal window open. You should see a table displaying the deployment +details, including Gateway module and object IDs. + +## Deploying a Universal Contract + +Open a new terminal window to compile and deploy your Universal Contract: + +```bash +npx hardhat compile --force +npx hardhat deploy --name Universal --network localhost --gateway 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 ``` -PACKAGE=$(echo $PUBLISHED | jq -r '.objectChanges[] | select(.type == "published") | .packageId') && echo $PACKAGE + +A successful deployment will output the contract address. + +## Deploy the Cetus Mock Contract + +Navigate to the Sui contract directory and deploy the mock Cetus pool contract: + +```bash +cd sui ``` ``` -TREASURY=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "0x2::coin::TreasuryCap<\($pkg)::token::TOKEN>") | .objectId') && echo $TREASURY +sui move build --force ``` ``` -POOL=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Pool<0x2::sui::SUI, \($pkg)::token::TOKEN>") | .objectId') && echo $POOL +PUBLISHED=$(sui client publish --skip-dependency-verification --json) ``` ``` -RECIPIENT=$(sui client active-address) && echo $RECIPIENT +PACKAGE=$(echo $PUBLISHED | jq -r '.objectChanges[] | select(.type == "published") | .packageId') ``` +This will deploy the contract and store the package ID in the `$PACKAGE` +variable. + +## Set Up the Pool + +After deployment, you'll need to set up the pool by minting tokens and creating +the initial liquidity. + +Get the treasury cap: + +```bash +TREASURY=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "0x2::coin::TreasuryCap<\($pkg)::token::TOKEN>") | .objectId') ``` + +Get the pool ID: + +``` +POOL=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Pool<0x2::sui::SUI, \($pkg)::token::TOKEN>") | .objectId') +``` + +Mint tokens to your address: + +``` +RECIPIENT=$(sui client active-address) sui client call \ --package "$PACKAGE" \ --module token \ @@ -26,10 +110,14 @@ sui client call \ --args "$TREASURY" 1000000 "$RECIPIENT" ``` +Get the token ID: + ``` -TOKEN=$(sui client objects --json | jq -r --arg pkg "$PACKAGE" '.[].data | select(.type == "0x2::coin::Coin<\($pkg)::token::TOKEN>") | .objectId') && echo $TOKEN +TOKEN=$(sui client objects --json | jq -r --arg pkg "$PACKAGE" '.[].data | select(.type == "0x2::coin::Coin<\($pkg)::token::TOKEN>") | .objectId') ``` +Deposit tokens into the pool: + ``` sui client call \ --package "$PACKAGE" \ @@ -39,53 +127,41 @@ sui client call \ --args "$POOL" "$TOKEN" ``` -``` -COIN=$(sui client gas --json | jq -r '.[0].gasCoinId') && echo $COIN -``` +## Execute Withdraw and Call -``` -ETH_ADDRESS=0x4955a3F38ff86ae92A914445099caa8eA2B9bA32 -GATEWAY_PACKAGE=0xa3ce10f68ed22d2cbbc31eaa709ee15e2e30348bfc6ff97b7d128d03b679c5c2 -GATEWAY_OBJECT=0xe925d4059435083b70bc504ce912202214edd06f693bdc3f9573a996292780c7 -``` +Now you can execute the withdraw and call operation. This will withdraw tokens +from ZetaChain to Sui and simultaneously call the Cetus pool contract. -``` -sui client call \ - --package "$GATEWAY_PACKAGE" \ - --module gateway \ - --function deposit \ - --type-args 0x2::sui::SUI \ - --args "$GATEWAY_OBJECT" "$COIN" "$ETH_ADDRESS" -``` +Get the required contract IDs: -``` -cast send 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891 "approve(address,uint256)" 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 1000000000000000000000000 --private-key ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +```bash +CONFIG=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::GlobalConfig") | .objectId') ``` ``` -CONFIG=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::GlobalConfig") | .objectId') && echo $CONFIG +CLOCK=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Clock") | .objectId') ``` ``` -CLOCK=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Clock") | .objectId') && echo $CLOCK +PARTNER=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Partner") | .objectId') ``` -``` -PARTNER=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Partner") | .objectId') && echo $PARTNER -``` +Prepare the payload: ``` -MESSAGE=$RECIPIENT && echo $MESSAGE +MESSAGE=$RECIPIENT ``` ``` -TOKEN_TYPE=$(echo "$PACKAGE::token::TOKEN") && echo $TOKEN_TYPE +TOKEN_TYPE="$PACKAGE::token::TOKEN" ``` ``` -PAYLOAD=$(npx ts-node sui/setup/encodeCallArgs.ts "$TOKEN_TYPE" "$CONFIG,$POOL,$PARTNER,$CLOCK" "$MESSAGE") && echo $PAYLOAD +PAYLOAD=$(npx ts-node ./setup/encodeCallArgs.ts "$TOKEN_TYPE" "$CONFIG,$POOL,$PARTNER,$CLOCK" "$MESSAGE") ``` +# Execute the withdraw and call + ``` cast send 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 "withdrawAndCall(bytes,uint256,address,bytes,(uint256,bool),(address,bool,address,bytes,uint256))" \ "$PACKAGE" \ @@ -96,3 +172,13 @@ cast send 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 "withdrawAndCall(bytes,uint "(0xB0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48,true,0xC0b86991c6218b36c1d19D4a2e9Eb0cE3606eB49,0xdeadbeef,50000)" \ --private-key ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 ``` + +This transaction will: + +1. Withdraw tokens from ZetaChain to Sui +2. Call the Cetus pool contract with the specified parameters +3. Execute the contract logic on Sui + +The operation demonstrates how to perform complex cross-chain operations that +combine asset withdrawals with contract calls, enabling sophisticated DeFi +interactions between ZetaChain and Sui. From 7bb936a8b765f244a9e283723ae99f3f7d12fe01 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 9 Apr 2025 16:09:24 +0300 Subject: [PATCH 04/15] doc --- .../developers/tutorials/sui-withdraw-and-call.mdx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index b2d636615..6c9259959 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -8,7 +8,8 @@ In this tutorial, you'll: - Set up a local development environment using [localnet](/developers/tutorials/localnet). - Deploy a universal contract on ZetaChain. -- Deploy a mock Cetus pool contract on Sui. +- Deploy a Sui contract capable of receiving calls from ZetaChain universal + apps. - Execute withdraw-and-call to withdraw tokens and call a contract on Sui in a single transaction. @@ -59,9 +60,9 @@ npx hardhat deploy --name Universal --network localhost --gateway 0x5FC8d32690cc A successful deployment will output the contract address. -## Deploy the Cetus Mock Contract +## Deploy a Contract on Sui -Navigate to the Sui contract directory and deploy the mock Cetus pool contract: +Navigate to the Sui contract directory and deploy the contract: ```bash cd sui @@ -130,7 +131,7 @@ sui client call \ ## Execute Withdraw and Call Now you can execute the withdraw and call operation. This will withdraw tokens -from ZetaChain to Sui and simultaneously call the Cetus pool contract. +from ZetaChain to Sui and simultaneously call a contract on Sui. Get the required contract IDs: @@ -176,8 +177,7 @@ cast send 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 "withdrawAndCall(bytes,uint This transaction will: 1. Withdraw tokens from ZetaChain to Sui -2. Call the Cetus pool contract with the specified parameters -3. Execute the contract logic on Sui +2. Call a Sui contract with the specified parameters The operation demonstrates how to perform complex cross-chain operations that combine asset withdrawals with contract calls, enabling sophisticated DeFi From 7b4724f98f882f944542006c1d2d265b9b935d47 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 9 Apr 2025 16:16:41 +0300 Subject: [PATCH 05/15] doc --- .../tutorials/sui-withdraw-and-call.mdx | 44 ++++++++----------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index 6c9259959..4c197ffde 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -1,20 +1,13 @@ Interacting with ZetaChain universal apps from the Sui blockchain includes the -ability to withdraw tokens back to Sui while simultaneously executing contract -calls. This functionality allows for seamless cross-chain operations where you -can both withdraw assets and trigger contract logic in a single transaction. +This tutorial demonstrates how to withdraw tokens to Sui while calling a Sui +contract in the same transaction—enabling seamless cross-chain operations and +powerful DeFi flows. -In this tutorial, you'll: +You’ll learn how to: -- Set up a local development environment using - [localnet](/developers/tutorials/localnet). -- Deploy a universal contract on ZetaChain. -- Deploy a Sui contract capable of receiving calls from ZetaChain universal - apps. -- Execute withdraw-and-call to withdraw tokens and call a contract on Sui in a - single transaction. - -By the end, you'll understand how to perform complex cross-chain operations that -combine asset withdrawals with contract calls on Sui. +- Set up a localnet environment with ZetaChain and Sui +- Deploy and configure a Sui contract that responds to ZetaChain calls +- Execute withdrawAndCall() to send tokens and trigger contract logic on Sui ## Prerequisites @@ -26,6 +19,18 @@ Ensure you have installed and configured the following tools before starting: - [jq](https://stedolan.github.io/jq/): Required for parsing JSON output from Sui CLI. +## Contract Overview + +The example contract demonstrates how to handle cross-chain interactions between +ZetaChain and Sui. The contract implements a `connected` module that: + +- Receives tokens from ZetaChain through the `on_call` function +- Performs a token swap using a mock Cetus DEX implementation +- Transfers the swapped tokens to a specified receiver address + +The Sui contract uses `0x2::coin` and a custom `token::TOKEN` type to represent +the transferred asset. + ## Clone the Example Project Begin by cloning the example contracts repository and installing its @@ -49,17 +54,6 @@ npx hardhat localnet Keep this terminal window open. You should see a table displaying the deployment details, including Gateway module and object IDs. -## Deploying a Universal Contract - -Open a new terminal window to compile and deploy your Universal Contract: - -```bash -npx hardhat compile --force -npx hardhat deploy --name Universal --network localhost --gateway 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 -``` - -A successful deployment will output the contract address. - ## Deploy a Contract on Sui Navigate to the Sui contract directory and deploy the contract: From 52e91407121be9018f676b086e7a9ed48744149a Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 9 Apr 2025 16:17:37 +0300 Subject: [PATCH 06/15] doc --- src/pages/developers/tutorials/sui-withdraw-and-call.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index 4c197ffde..dffb10e5d 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -122,7 +122,7 @@ sui client call \ --args "$POOL" "$TOKEN" ``` -## Execute Withdraw and Call +## Prepare Withdraw and Call Now you can execute the withdraw and call operation. This will withdraw tokens from ZetaChain to Sui and simultaneously call a contract on Sui. @@ -155,7 +155,7 @@ TOKEN_TYPE="$PACKAGE::token::TOKEN" PAYLOAD=$(npx ts-node ./setup/encodeCallArgs.ts "$TOKEN_TYPE" "$CONFIG,$POOL,$PARTNER,$CLOCK" "$MESSAGE") ``` -# Execute the withdraw and call +## Execute the withdraw and call ``` cast send 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 "withdrawAndCall(bytes,uint256,address,bytes,(uint256,bool),(address,bool,address,bytes,uint256))" \ From d3ddc71bb7a06733f2a1b195ff245835adf36a5d Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 9 Apr 2025 16:22:09 +0300 Subject: [PATCH 07/15] sidebar --- src/pages/developers/tutorials/_meta.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pages/developers/tutorials/_meta.json b/src/pages/developers/tutorials/_meta.json index 7def65f30..3faa83a46 100644 --- a/src/pages/developers/tutorials/_meta.json +++ b/src/pages/developers/tutorials/_meta.json @@ -24,6 +24,11 @@ "readTime": "60 min", "description": "Deposit assets and call universal apps from Sui" }, + "sui-withdraw-and-call": { + "title": "Sui Withdraw & Call", + "readTime": "60 min", + "description": "Withdraw assets and call contracts on Sui" + }, "swap": { "title": "Swap", "readTime": "30 min", From 1d92d682ebff333d583d3cde3991c661f664384d Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 9 Apr 2025 16:26:21 +0300 Subject: [PATCH 08/15] echo --- .../tutorials/sui-withdraw-and-call.mdx | 41 ++++++++++++------- 1 file changed, 26 insertions(+), 15 deletions(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index dffb10e5d..7321e26f7 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -71,7 +71,7 @@ PUBLISHED=$(sui client publish --skip-dependency-verification --json) ``` ``` -PACKAGE=$(echo $PUBLISHED | jq -r '.objectChanges[] | select(.type == "published") | .packageId') +PACKAGE=$(echo $PUBLISHED | jq -r '.objectChanges[] | select(.type == "published") | .packageId') && echo $PACKAGE ``` This will deploy the contract and store the package ID in the `$PACKAGE` @@ -85,42 +85,53 @@ the initial liquidity. Get the treasury cap: ```bash -TREASURY=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "0x2::coin::TreasuryCap<\($pkg)::token::TOKEN>") | .objectId') +TREASURY=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "0x2::coin::TreasuryCap<\($pkg)::token::TOKEN>") | .objectId') && echo $TREASURY ``` Get the pool ID: ``` -POOL=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Pool<0x2::sui::SUI, \($pkg)::token::TOKEN>") | .objectId') +POOL=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Pool<0x2::sui::SUI, \($pkg)::token::TOKEN>") | .objectId') && echo $POOL ``` Mint tokens to your address: ``` -RECIPIENT=$(sui client active-address) +RECIPIENT=$(sui client active-address) && echo $RECIPIENT +`` + +``` + sui client call \ - --package "$PACKAGE" \ + --package "$PACKAGE" \ --module token \ --function mint \ --args "$TREASURY" 1000000 "$RECIPIENT" + ``` Get the token ID: ``` -TOKEN=$(sui client objects --json | jq -r --arg pkg "$PACKAGE" '.[].data | select(.type == "0x2::coin::Coin<\($pkg)::token::TOKEN>") | .objectId') + +TOKEN=$(sui client objects --json | jq -r --arg pkg "$PACKAGE" '.[].data | +select(.type == "0x2::coin::Coin<\($pkg)::token::TOKEN>") | .objectId') && echo +$TOKEN + ``` Deposit tokens into the pool: ``` + sui client call \ - --package "$PACKAGE" \ + --package "$PACKAGE" \ --module cetusmock \ --function deposit \ --type-args "0x2::sui::SUI" "$PACKAGE::token::TOKEN" \ - --args "$POOL" "$TOKEN" -``` + --args "$POOL" "$TOKEN" + +```` ## Prepare Withdraw and Call @@ -130,15 +141,15 @@ from ZetaChain to Sui and simultaneously call a contract on Sui. Get the required contract IDs: ```bash -CONFIG=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::GlobalConfig") | .objectId') -``` +CONFIG=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::GlobalConfig") | .objectId') && echo $CONFIG +```` ``` -CLOCK=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Clock") | .objectId') +CLOCK=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Clock") | .objectId') && echo $CLOCK ``` ``` -PARTNER=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Partner") | .objectId') +PARTNER=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Partner") | .objectId') && echo $PARTNER ``` Prepare the payload: @@ -148,11 +159,11 @@ MESSAGE=$RECIPIENT ``` ``` -TOKEN_TYPE="$PACKAGE::token::TOKEN" +TOKEN_TYPE="$PACKAGE::token::TOKEN" && echo $TOKEN_TYPE ``` ``` -PAYLOAD=$(npx ts-node ./setup/encodeCallArgs.ts "$TOKEN_TYPE" "$CONFIG,$POOL,$PARTNER,$CLOCK" "$MESSAGE") +PAYLOAD=$(npx ts-node ./setup/encodeCallArgs.ts "$TOKEN_TYPE" "$CONFIG,$POOL,$PARTNER,$CLOCK" "$MESSAGE") && echo $PAYLOAD ``` ## Execute the withdraw and call From e9da9522fd3910bd1b84264e3093d4831945e0ba Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 9 Apr 2025 16:35:00 +0300 Subject: [PATCH 09/15] fix --- .../tutorials/sui-withdraw-and-call.mdx | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index 7321e26f7..a620d8875 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -98,40 +98,32 @@ Mint tokens to your address: ``` RECIPIENT=$(sui client active-address) && echo $RECIPIENT -`` - ``` +``` sui client call \ --package "$PACKAGE" \ --module token \ --function mint \ --args "$TREASURY" 1000000 "$RECIPIENT" - ``` Get the token ID: ``` - -TOKEN=$(sui client objects --json | jq -r --arg pkg "$PACKAGE" '.[].data | -select(.type == "0x2::coin::Coin<\($pkg)::token::TOKEN>") | .objectId') && echo -$TOKEN - +TOKEN=$(sui client objects --json | jq -r --arg pkg "$PACKAGE" '.[].data | select(.type == "0x2::coin::Coin<\($pkg)::token::TOKEN>") | .objectId') && echo $TOKEN ``` Deposit tokens into the pool: ``` - sui client call \ - --package "$PACKAGE" \ + --package "$PACKAGE" \ --module cetusmock \ --function deposit \ --type-args "0x2::sui::SUI" "$PACKAGE::token::TOKEN" \ - --args "$POOL" "$TOKEN" - -```` + --args "$POOL" "$TOKEN" +``` ## Prepare Withdraw and Call @@ -142,7 +134,7 @@ Get the required contract IDs: ```bash CONFIG=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::GlobalConfig") | .objectId') && echo $CONFIG -```` +``` ``` CLOCK=$(echo $PUBLISHED | jq -r --arg pkg "$PACKAGE" '.objectChanges[] | select(.type == "created" and .objectType == "\($pkg)::cetusmock::Clock") | .objectId') && echo $CLOCK From da18d57e16df37025b9551d122c81a6d1d01ccb6 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 9 Apr 2025 16:36:36 +0300 Subject: [PATCH 10/15] fix --- .../tutorials/sui-withdraw-and-call.mdx | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index a620d8875..d5ff19faf 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -3,7 +3,7 @@ This tutorial demonstrates how to withdraw tokens to Sui while calling a Sui contract in the same transaction—enabling seamless cross-chain operations and powerful DeFi flows. -You’ll learn how to: +You'll learn how to: - Set up a localnet environment with ZetaChain and Sui - Deploy and configure a Sui contract that responds to ZetaChain calls @@ -125,6 +125,37 @@ sui client call \ --args "$POOL" "$TOKEN" ``` +## Deposit SUI to Gateway + +To enable cross-chain operations, you need to deposit SUI tokens to the +ZetaChain gateway. First, get your SUI coin ID: + +``` +COIN=$(sui client gas --json | jq -r '.[0].gasCoinId') && echo $COIN +``` + +``` +ETH_ADDRESS=0x4955a3F38ff86ae92A914445099caa8eA2B9bA32 +GATEWAY_PACKAGE=0xa3ce10f68ed22d2cbbc31eaa709ee15e2e30348bfc6ff97b7d128d03b679c5c2 +GATEWAY_OBJECT=0xe925d4059435083b70bc504ce912202214edd06f693bdc3f9573a996292780c7 +``` + +Then, deposit SUI to the gateway using the gateway addresses from your localnet +output: + +``` +sui client call \ + --package "$GATEWAY_PACKAGE" \ + --module gateway \ + --function deposit \ + --type-args 0x2::sui::SUI \ + --args "$GATEWAY_OBJECT" "$COIN" "$ETH_ADDRESS" +``` + +> **Note**: Make sure to replace the `GATEWAY_PACKAGE` and `GATEWAY_OBJECT` +> values with the ones from your localnet output. These addresses are displayed +> in the table when you start the localnet. + ## Prepare Withdraw and Call Now you can execute the withdraw and call operation. This will withdraw tokens From 99928bf9a2f4e04b2feb836672b5c1590de1976e Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Wed, 9 Apr 2025 16:42:07 +0300 Subject: [PATCH 11/15] approve --- src/pages/developers/tutorials/sui-withdraw-and-call.mdx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index d5ff19faf..7ba9d9d6a 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -191,6 +191,14 @@ PAYLOAD=$(npx ts-node ./setup/encodeCallArgs.ts "$TOKEN_TYPE" "$CONFIG,$POOL,$PA ## Execute the withdraw and call +Approve Gateway to spend ZRC-20 Sui: + +``` +cast send 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891 "approve(address,uint256)" 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 1000000000000000000000000 --private-key ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +``` + +Withdraw and call: + ``` cast send 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 "withdrawAndCall(bytes,uint256,address,bytes,(uint256,bool),(address,bool,address,bytes,uint256))" \ "$PACKAGE" \ From 6c832246ae88e132760b0ee8ae10998ca34b0780 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Tue, 22 Apr 2025 17:04:11 +0300 Subject: [PATCH 12/15] faucet and gateway zetachain address --- .../developers/tutorials/sui-withdraw-and-call.mdx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index 7ba9d9d6a..26fe9d98d 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -66,6 +66,12 @@ cd sui sui move build --force ``` +Get some Sui tokens from the faucet: + +``` +sui client faucet +``` + ``` PUBLISHED=$(sui client publish --skip-dependency-verification --json) ``` @@ -194,13 +200,13 @@ PAYLOAD=$(npx ts-node ./setup/encodeCallArgs.ts "$TOKEN_TYPE" "$CONFIG,$POOL,$PA Approve Gateway to spend ZRC-20 Sui: ``` -cast send 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891 "approve(address,uint256)" 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 1000000000000000000000000 --private-key ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 +cast send 0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891 "approve(address,uint256)" 0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6 1000000000000000000000000 --private-key ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 ``` Withdraw and call: ``` -cast send 0x5FC8d32690cc91D4c39d9d3abcBD16989F875707 "withdrawAndCall(bytes,uint256,address,bytes,(uint256,bool),(address,bool,address,bytes,uint256))" \ +cast send 0x2279B7A0a67DB372996a5FaB50D91eAA73d2eBe6 "withdrawAndCall(bytes,uint256,address,bytes,(uint256,bool),(address,bool,address,bytes,uint256))" \ "$PACKAGE" \ "1000000" \ "0xd97B1de3619ed2c6BEb3860147E30cA8A7dC9891" \ From 53a70204cea82b6e428166c1307927c9912af9d0 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Thu, 24 Apr 2025 07:28:50 +0300 Subject: [PATCH 13/15] mint and transfer --- src/pages/developers/tutorials/sui-withdraw-and-call.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index 26fe9d98d..c9dd003f5 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -108,9 +108,9 @@ RECIPIENT=$(sui client active-address) && echo $RECIPIENT ``` sui client call \ - --package "$PACKAGE" \ + --package "$PACKAGE" \ --module token \ - --function mint \ + --function mint_and_transfer \ --args "$TREASURY" 1000000 "$RECIPIENT" ``` From 055f45a654cb82e09716ce5f5caa6901c86a1855 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Thu, 24 Apr 2025 07:29:42 +0300 Subject: [PATCH 14/15] default address --- src/pages/developers/tutorials/sui-withdraw-and-call.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index c9dd003f5..cb599c5fa 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -141,7 +141,7 @@ COIN=$(sui client gas --json | jq -r '.[0].gasCoinId') && echo $COIN ``` ``` -ETH_ADDRESS=0x4955a3F38ff86ae92A914445099caa8eA2B9bA32 +ETH_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 GATEWAY_PACKAGE=0xa3ce10f68ed22d2cbbc31eaa709ee15e2e30348bfc6ff97b7d128d03b679c5c2 GATEWAY_OBJECT=0xe925d4059435083b70bc504ce912202214edd06f693bdc3f9573a996292780c7 ``` From b3de971d37bea510268ba400563a826277c2e749 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Fri, 9 May 2025 14:01:07 +0300 Subject: [PATCH 15/15] update to using zetachain cli --- src/pages/developers/tutorials/sui-withdraw-and-call.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx index cb599c5fa..591ee5cac 100644 --- a/src/pages/developers/tutorials/sui-withdraw-and-call.mdx +++ b/src/pages/developers/tutorials/sui-withdraw-and-call.mdx @@ -37,8 +37,8 @@ Begin by cloning the example contracts repository and installing its dependencies: ```bash -git clone https://github.com/zeta-chain/example-contracts -cd example-contracts/examples/call +npx zetachain@next new --project call +cd call yarn ``` @@ -48,7 +48,7 @@ Start your local development environment, which sets up instances of ZetaChain and Sui: ```bash -npx hardhat localnet +npx zetachain localnet start ``` Keep this terminal window open. You should see a table displaying the deployment