Skip to content

Commit c68f842

Browse files
chore: update docs (#5140)
2 parents 677f093 + abc58d0 commit c68f842

File tree

1 file changed

+66
-168
lines changed
  • docs/src/content/docs/ucs

1 file changed

+66
-168
lines changed

docs/src/content/docs/ucs/03.mdx

Lines changed: 66 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ import Mermaid from "#/components/Mermaid.astro";
77
`ucs03-zkgm-0` is the most advanced and recommended protocol to use for
88

99
- message passing
10-
- transfers (assets and NFTs)
10+
- asset transfers
1111
- intents
1212
- storage proofs
13-
- staking and governance
1413

1514
It's the most gas-efficient version and suitable for almost all use cases.
1615

@@ -96,10 +95,8 @@ Each instruction has a version and opcode to allow for protocol evolution.
9695
Its features include:
9796
- batching
9897
- forward/callback envelopes
99-
- channel multiplexing
100-
- fungible assets transfer
101-
- non-fungible assets transfer
102-
- staking and governance
98+
- channel routing
99+
- fungible asset transfers
103100

104101
## Packet
105102

@@ -172,17 +169,12 @@ Fields:
172169
- 0x01: [Call](#0x01---call)
173170
- 0x02: [Batch](#0x02---batch)
174171
- 0x03: [TokenOrder](#0x03---token-order)
175-
- 0x04: [Stake](#0x04---stake)
176-
- 0x05: [Unstake](#0x05---unstake)
177-
- 0x06: [WithdrawStake](#0x06---withdraw-stake)
178-
- 0x07: [WithdrawRewards](#0x07---withdraw-rewards)
179172

180173
- `operand`: Instruction-specific data as `bytes`
181174
- Forward: Path, timeouts and instruction to forward
182175
- Call: Sender, callback mode and contract call data
183176
- Batch: Array of instructions to execute atomically
184177
- TokenOrder: Transfer details like tokens, amounts and parties
185-
- Stake/Unstake/WithdrawStake/WithdrawRewards: Staking operation parameters
186178

187179
:::note
188180

@@ -280,13 +272,14 @@ Fields:
280272
- Interpreted by target contract's implementation
281273
- Available in both standard and eureka modes
282274

283-
The multiplexcall instruction has two modes:
275+
The Call instruction has two modes:
284276

285277
1. Standard Mode (eureka = false):
286278
- Target must implement IZkgmable interface
287279
- Calls `onZkgm(path, sourceChannel, destChannel, sender, calldata)` on target
288280
- Returns success acknowledgement immediately
289281
- Fire-and-forget style, no callback to sender
282+
- **ProxyAccount Auto-Creation**: If the target address matches a predictable ProxyAccount address derived from the sender, path, and channel, the ProxyAccount is automatically created before the call is executed
290283

291284
2. IBC Mode (eureka = true):
292285
- Calls `onRecvPacket(packet, relayer, relayerMsg)` on target
@@ -298,6 +291,64 @@ If the target contract is invalid or calls fail:
298291
- Standard mode returns failure acknowledgement
299292
- IBC mode propagates target's error response
300293

294+
#### ProxyAccount
295+
296+
ProxyAccount is a smart contract wallet that enables cross-chain account abstraction. It allows users to control accounts on remote chains through the ZKGM protocol.
297+
298+
**Key Features:**
299+
- **Deterministic Addresses**: ProxyAccount addresses are derived deterministically from the sender address, channel ID and path, ensuring the same sender always gets the same ProxyAccount address
300+
- **Auto-Creation**: When a Call instruction targets a ProxyAccount address that doesn't exist yet, the protocol automatically deploys it before executing the call
301+
- **Multi-Admin Support**: Supports both local admins (on the same chain) and remote admins (on other chains)
302+
- **Upgradeable**: Implements UUPS pattern for upgradeability on EVM
303+
- **Multicall Support**: Can execute multiple calls in a single transaction
304+
305+
**Address Prediction:**
306+
```solidity
307+
function predictProxyAccount(
308+
uint256 path,
309+
uint32 channel,
310+
bytes calldata sender
311+
) external returns (address, bytes32);
312+
```
313+
314+
The ProxyAccount address is computed as:
315+
1. Salt = `keccak256(abi.encode(path, channelId, sender))`
316+
2. Address = `CREATE3.predictDeterministicAddress(salt)`
317+
318+
**Remote Control:**
319+
When called via zkgm (eureka = false), the ProxyAccount:
320+
1. Verifies the caller is the authorized zkgm contract
321+
2. Checks if the sender is a registered remote admin for the given path/channel
322+
3. Decodes the message as `(address target, uint256 value, bytes payload)`
323+
4. Executes the call to the target contract
324+
325+
**Example Usage:**
326+
```solidity
327+
// On source chain, prepare a call to be executed via ProxyAccount
328+
bytes memory proxyCalldata = abi.encode(
329+
targetContract, // Contract to call on destination
330+
0, // ETH value to send
331+
abi.encodeCall( // The actual function call
332+
IERC20.transfer,
333+
(recipient, amount)
334+
)
335+
);
336+
337+
// Prepare a call instruction to submit.
338+
Call memory call = Call({
339+
sender: abi.encodePacked(msg.sender),
340+
eureka: false,
341+
contractAddress: abi.encodePacked(proxyAccountAddress),
342+
contractCalldata: proxyCalldata
343+
});
344+
```
345+
346+
This enables users to:
347+
- Own and control accounts on any chain without deploying contracts in advance
348+
- Execute arbitrary transactions on remote chains
349+
- Manage assets and interact with DeFi protocols cross-chain
350+
- Maintain consistent account addresses across deployments
351+
301352
:::tip
302353
Example of a contract implementing `IZkgmable`:
303354
```solidity
@@ -365,13 +416,13 @@ struct Batch {
365416

366417
Fields:
367418
- `instructions`: Array of [Instructions](#instruction) to execute atomically
368-
- Only specific instructions allowed (Call, TokenOrder, Stake, Unstake, WithdrawStake)
419+
- Only specific instructions allowed (Call, TokenOrder)
369420
- Executed in sequential order
370421
- All must succeed or entire batch reverts
371422
- Individual acknowledgements collected in array
372423
- Minimum 2 instructions required
373424

374-
This allows atomic composition of transfers, contract calls, and staking operations in a single transaction.
425+
This allows atomic composition of transfers and contract calls in a single transaction.
375426

376427
<Mermaid
377428
content={`
@@ -385,7 +436,7 @@ sequenceDiagram
385436

386437
:::tip
387438

388-
In combination with forward envelopes or multiplexing, this batching mechanism is very useful to call contract before/after message execution (transfer an asset, swap it then stake the final asset).
439+
In combination with forward envelopes, this batching mechanism is very useful to call contract before/after message execution (transfer an asset, swap it, then execute another operation with the final asset).
389440

390441
:::
391442

@@ -962,159 +1013,6 @@ If any of the order in the `orders` list is failing on execution, the whole pack
9621013

9631014
:::
9641015

965-
### 0x04 - Stake
966-
967-
The stake instruction uses opcode `0x04` and requires version `INSTR_VERSION_0`.
968-
969-
```solidity
970-
struct Stake {
971-
uint256 tokenId; // NFT token ID for the staking position
972-
bytes governanceToken; // Governance token address
973-
bytes governanceTokenWrapped; // Wrapped governance token address
974-
bytes sender; // Source chain sender address
975-
bytes beneficiary; // Address that will receive the staking NFT
976-
bytes validator; // Validator address to stake with
977-
uint256 amount; // Amount to stake
978-
}
979-
```
980-
981-
The stake instruction allows cross-chain staking of governance tokens with validators. The process:
982-
1. Tokens are locked on the source chain
983-
2. Staking is initiated on the destination chain
984-
3. A staking position NFT is minted to the beneficiary
985-
4. The NFT represents ownership of the staked position and can be used to manage it
986-
987-
<Mermaid
988-
content={`
989-
sequenceDiagram
990-
participant S as Sender
991-
participant B as Beneficiary
992-
participant Chain1 as Source Chain
993-
participant Chain2 as Destination Chain
994-
participant V as Validator
995-
996-
S ->> Chain1: Send Stake Instruction
997-
Chain1 ->> Chain1: Lock Governance Tokens
998-
Chain1 ->> Chain2: Stake Packet
999-
Chain2 ->> V: Delegate Tokens
1000-
Chain2 ->> Chain2: Mint Staking NFT
1001-
Chain2 ->> Chain1: Success Acknowledgement
1002-
Chain1 ->> B: Transfer NFT
1003-
`}/>
1004-
1005-
### 0x05 - Unstake
1006-
1007-
The unstake instruction uses opcode `0x05` and requires version `INSTR_VERSION_0`.
1008-
1009-
```solidity
1010-
struct Unstake {
1011-
uint256 tokenId; // NFT token ID for the staking position
1012-
bytes governanceToken; // Governance token address
1013-
bytes governanceTokenWrapped; // Wrapped governance token address
1014-
bytes sender; // Source chain sender address
1015-
bytes validator; // Validator address to unstake from
1016-
}
1017-
```
1018-
1019-
The unstake instruction initiates the unbonding process for staked tokens. When successful:
1020-
1. The staking position enters the UNSTAKING state
1021-
2. The unstakingCompletion time is set
1022-
3. The NFT is returned to the sender
1023-
4. After completion time, tokens can be withdrawn
1024-
1025-
<Mermaid
1026-
content={`
1027-
sequenceDiagram
1028-
participant S as Sender/NFT Owner
1029-
participant Chain1 as Source Chain
1030-
participant Chain2 as Destination Chain
1031-
participant V as Validator
1032-
1033-
S ->> Chain1: Send Unstake Instruction
1034-
Chain1 ->> Chain1: Lock NFT
1035-
Chain1 ->> Chain2: Unstake Packet
1036-
Chain2 ->> V: Begin Unbonding
1037-
Chain2 ->> Chain1: Acknowledgement with Completion Time
1038-
Chain1 ->> Chain1: Set NFT to UNSTAKING state
1039-
Chain1 ->> Chain1: Record unstakingCompletion time
1040-
Chain1 ->> S: Return NFT
1041-
`}/>
1042-
1043-
### 0x06 - Withdraw Stake
1044-
1045-
The withdraw stake instruction uses opcode `0x06` and requires version `INSTR_VERSION_0`.
1046-
1047-
```solidity
1048-
struct WithdrawStake {
1049-
uint256 tokenId; // NFT token ID for the staking position
1050-
bytes governanceToken; // Governance token address
1051-
bytes governanceTokenWrapped; // Wrapped governance token address
1052-
bytes sender; // Source chain sender address
1053-
bytes beneficiary; // Address that will receive the tokens
1054-
}
1055-
```
1056-
1057-
The withdraw stake instruction allows a user to claim their tokens after the unbonding period. On success:
1058-
1. The staking position enters the UNSTAKED state
1059-
2. The staked tokens are transferred to the beneficiary
1060-
3. Any rewards are also transferred
1061-
4. If there was slashing, the appropriate amount is burned
1062-
1063-
<Mermaid
1064-
content={`
1065-
sequenceDiagram
1066-
participant S as Sender/NFT Owner
1067-
participant B as Beneficiary
1068-
participant Chain1 as Source Chain
1069-
participant Chain2 as Destination Chain
1070-
1071-
S ->> Chain1: Send WithdrawStake Instruction
1072-
Note right of S: Must be after unbonding period
1073-
Chain1 ->> Chain1: Lock NFT
1074-
Chain1 ->> Chain2: WithdrawStake Packet
1075-
Chain2 ->> Chain2: Unbond Tokens
1076-
Chain2 ->> Chain1: Acknowledgement with Final Amount
1077-
Chain1 ->> Chain1: Set NFT to UNSTAKED state
1078-
Chain1 ->> B: Transfer Tokens + Rewards
1079-
Chain1 ->> Chain1: Burn NFT
1080-
`}/>
1081-
1082-
### 0x07 - Withdraw Rewards
1083-
1084-
The withdraw rewards instruction uses opcode `0x07` and requires version `INSTR_VERSION_0`.
1085-
1086-
```solidity
1087-
struct WithdrawRewards {
1088-
uint256 tokenId; // NFT token ID for the staking position
1089-
bytes governanceToken; // Governance token address
1090-
bytes governanceTokenWrapped; // Wrapped governance token address
1091-
bytes validator; // Validator address
1092-
bytes sender; // Source chain sender address
1093-
bytes beneficiary; // Address that will receive the rewards
1094-
}
1095-
```
1096-
1097-
The withdraw rewards instruction allows claiming rewards without unstaking. On success:
1098-
1. The staking position remains in the STAKED state
1099-
2. Any accumulated rewards are transferred to the beneficiary
1100-
3. The NFT is returned to the sender
1101-
1102-
<Mermaid
1103-
content={`
1104-
sequenceDiagram
1105-
participant S as Sender/NFT Owner
1106-
participant B as Beneficiary
1107-
participant Chain1 as Source Chain
1108-
participant Chain2 as Destination Chain
1109-
1110-
S ->> Chain1: Send WithdrawRewards Instruction
1111-
Chain1 ->> Chain1: Lock NFT
1112-
Chain1 ->> Chain2: WithdrawRewards Packet
1113-
Chain2 ->> Chain2: Calculate Rewards
1114-
Chain2 ->> Chain1: Acknowledgement with Reward Amount
1115-
Chain1 ->> B: Mint/Transfer Rewards
1116-
Chain1 ->> S: Return NFT
1117-
`}/>
11181016

11191017
## Implementations
11201018

0 commit comments

Comments
 (0)