|
| 1 | +# Sui Gateway |
| 2 | + |
| 3 | +To interact with universal applications from Sui chain, use the Sui Gateway. |
| 4 | + |
| 5 | +For step-by-step examples of using the Sui gateway, see the [Sui |
| 6 | +tutorial](/developers/tutorials/sui/). |
| 7 | + |
| 8 | +The Sui Gateway supports: |
| 9 | + |
| 10 | +- Depositing native SUI and other coins to a universal app or an account on |
| 11 | + ZetaChain |
| 12 | +- Depositing coins and calling a universal app |
| 13 | + |
| 14 | +## Deposit Coins |
| 15 | + |
| 16 | +To deposit coins to an EOA or a universal contract on ZetaChain, use the |
| 17 | +`deposit` function: |
| 18 | + |
| 19 | +```move |
| 20 | +public entry fun deposit<T>( |
| 21 | + gateway: &mut Gateway, |
| 22 | + coins: Coin<T>, |
| 23 | + receiver: String, |
| 24 | + ctx: &mut TxContext, |
| 25 | +) |
| 26 | +``` |
| 27 | + |
| 28 | +The `deposit` function accepts any whitelisted coin type `T` (including native |
| 29 | +SUI), which will be sent to the specified `receiver` on ZetaChain. |
| 30 | + |
| 31 | +The `receiver` parameter should be a valid EVM-style address (0x-prefixed hex |
| 32 | +string) representing either an externally-owned account (EOA) or a universal app |
| 33 | +address on ZetaChain. Even if the receiver is a universal app contract, the |
| 34 | +`deposit` function will not trigger a contract call. If you want to deposit and |
| 35 | +call a universal app, use the `deposit_and_call` function instead. |
| 36 | + |
| 37 | +After the deposit is processed, the receiver receives the ZRC-20 version of the |
| 38 | +deposited token on ZetaChain. |
| 39 | + |
| 40 | +## Deposit Coins and Call a Universal App |
| 41 | + |
| 42 | +To deposit coins and call a universal app contract, use the `deposit_and_call` |
| 43 | +function: |
| 44 | + |
| 45 | +```move |
| 46 | +public entry fun deposit_and_call<T>( |
| 47 | + gateway: &mut Gateway, |
| 48 | + coins: Coin<T>, |
| 49 | + receiver: String, |
| 50 | + payload: vector<u8>, |
| 51 | + ctx: &mut TxContext, |
| 52 | +) |
| 53 | +``` |
| 54 | + |
| 55 | +The `receiver` must be the address of a universal app contract on ZetaChain. The |
| 56 | +`payload` parameter will be passed to the `onCall` function of the universal app |
| 57 | +contract. |
| 58 | + |
| 59 | +The maximum payload size is 1024 bytes. The transaction will fail if the payload |
| 60 | +exceeds this limit. |
| 61 | + |
| 62 | +## Administrative Functions |
| 63 | + |
| 64 | +The Sui Gateway includes several administrative functions that require special |
| 65 | +capability objects: |
| 66 | + |
| 67 | +- `whitelist<T>` - Enables deposits for a new coin type (requires |
| 68 | + `WhitelistCap`) |
| 69 | +- `withdraw<T>` - Called by the TSS address when tokens are withdrawn from |
| 70 | + ZetaChain to Sui. This function requires a special capability object |
| 71 | + (`WithdrawCap`) that is only held by the TSS nodes. The `nonce` parameter |
| 72 | + prevents replay attacks by ensuring each withdrawal is processed exactly once. |
| 73 | +- `unwhitelist<T>` - Disables deposits for a coin type (requires `AdminCap`) |
| 74 | +- `pause` - Temporarily disables all deposits (requires `AdminCap`) |
| 75 | +- `unpause` - Re-enables deposits (requires `AdminCap`) |
| 76 | +- `issue_withdraw_and_whitelist_cap` - Rotates the TSS capabilities (requires |
| 77 | + `AdminCap`) |
| 78 | + |
| 79 | +## Events |
| 80 | + |
| 81 | +The Gateway emits several events that can be monitored: |
| 82 | + |
| 83 | +- `DepositEvent` - Emitted when coins are deposited |
| 84 | +- `DepositAndCallEvent` - Emitted when coins are deposited with a contract call |
| 85 | +- `WithdrawEvent` - Emitted when coins are withdrawn |
| 86 | +- `NonceIncreaseEvent` - Emitted when the withdrawal nonce is increased |
| 87 | + |
| 88 | +## View Functions |
| 89 | + |
| 90 | +The Gateway provides several read-only functions: |
| 91 | + |
| 92 | +- `nonce()` - Returns the current withdrawal nonce |
| 93 | +- `vault_balance<T>()` - Returns the balance of a specific coin type in the |
| 94 | + gateway |
| 95 | +- `is_whitelisted<T>()` - Checks if a coin type is enabled for deposits |
| 96 | +- `is_paused()` - Checks if deposits are currently paused |
0 commit comments