@layerzerolabs/lz-sui-oft-sdk-v2 3.0.145 → 3.0.146
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +133 -44
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @layerzerolabs/lz-sui-oft-sdk-v2
|
|
2
2
|
|
|
3
|
+
## 3.0.146
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 13da033: Endpoints/nov13
|
|
8
|
+
- Updated dependencies [13da033]
|
|
9
|
+
- @layerzerolabs/lz-definitions@3.0.146
|
|
10
|
+
- @layerzerolabs/lz-sui-sdk-v2@3.0.146
|
|
11
|
+
|
|
3
12
|
## 3.0.145
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -20,70 +20,159 @@ pnpm add @layerzerolabs/lz-sui-oft-sdk-v2
|
|
|
20
20
|
|
|
21
21
|
- **Cross-chain Transfers**: Send tokens across different blockchains
|
|
22
22
|
- **OFT & OFT Adapter**: Interact with deployed OFT & OFT Adapter
|
|
23
|
-
- **OFT Composer**: Advanced composition functionality for complex cross-chain operations
|
|
23
|
+
- **OFT Composer Manager**: Advanced composition functionality for complex cross-chain operations
|
|
24
24
|
|
|
25
25
|
## Usage
|
|
26
26
|
|
|
27
|
-
###
|
|
27
|
+
### Initialize OFT
|
|
28
|
+
|
|
29
|
+
Create a new OFT that mints/burns tokens for cross-chain transfers:
|
|
28
30
|
|
|
29
31
|
```typescript
|
|
30
32
|
import { OFT } from "@layerzerolabs/lz-sui-oft-sdk-v2";
|
|
31
|
-
import { SDK } from "@layerzerolabs/lz-sui-sdk-v2";
|
|
33
|
+
import { SDK, validateTransaction } from "@layerzerolabs/lz-sui-sdk-v2";
|
|
34
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
32
35
|
|
|
33
|
-
// Initialize SDK
|
|
34
|
-
const
|
|
36
|
+
// Initialize LayerZero protocol SDK
|
|
37
|
+
const protocolSDK = new SDK({
|
|
35
38
|
client: suiClient,
|
|
36
|
-
packages: packageOptions,
|
|
37
|
-
objects: objectOptions,
|
|
38
39
|
stage: Stage.MAINNET,
|
|
39
40
|
});
|
|
40
41
|
|
|
41
|
-
// Create OFT instance
|
|
42
|
-
const oft = new OFT(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
// Create OFT instance with package ID
|
|
43
|
+
const oft = new OFT(protocolSDK, oftPackageId);
|
|
44
|
+
|
|
45
|
+
// Initialize OFT with treasury capability (for minting/burning)
|
|
46
|
+
const initTx = new Transaction();
|
|
47
|
+
const [adminCap, migrationCap] = oft.initOftMoveCall(
|
|
48
|
+
initTx,
|
|
49
|
+
coinType, // e.g., "0x123::my_coin::MY_COIN"
|
|
50
|
+
oftInitTicketId, // OFT creation ticket
|
|
51
|
+
oappObjectId, // Associated OApp object
|
|
52
|
+
treasuryCapId, // Treasury cap for minting/burning
|
|
53
|
+
metadataId, // Coin metadata
|
|
54
|
+
6, // Shared decimals for cross-chain compatibility
|
|
52
55
|
);
|
|
53
56
|
|
|
54
|
-
//
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
57
|
+
// Transfer capabilities to your address
|
|
58
|
+
initTx.transferObjects(
|
|
59
|
+
[adminCap, migrationCap],
|
|
60
|
+
initTx.pure.address(yourAddress),
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
// Execute the transaction
|
|
64
|
+
const result = await validateTransaction(suiClient, signer, initTx);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Initialize OFT Adapter
|
|
68
|
+
|
|
69
|
+
Create an OFT Adapter that wraps existing tokens:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
// Initialize OFT Adapter (wraps existing tokens without minting/burning)
|
|
73
|
+
const adapterTx = new Transaction();
|
|
74
|
+
const [adminCap, migrationCap] = oft.initOftAdapterMoveCall(
|
|
75
|
+
adapterTx,
|
|
76
|
+
coinType, // e.g., "0x123::my_coin::MY_COIN"
|
|
77
|
+
oftInitTicketId, // OFT creation ticket
|
|
78
|
+
oappObjectId, // Associated OApp object
|
|
79
|
+
metadataId, // Coin metadata
|
|
80
|
+
6, // Shared decimals for cross-chain compatibility
|
|
81
|
+
);
|
|
64
82
|
|
|
65
|
-
|
|
83
|
+
// Transfer capabilities to your address
|
|
84
|
+
adapterTx.transferObjects(
|
|
85
|
+
[adminCap, migrationCap],
|
|
86
|
+
adapterTx.pure.address(yourAddress),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
// Execute the transaction
|
|
90
|
+
const result = await validateTransaction(suiClient, signer, adapterTx);
|
|
66
91
|
```
|
|
67
92
|
|
|
68
|
-
### OFT
|
|
93
|
+
### Register OFT with LayerZero Endpoint
|
|
69
94
|
|
|
70
95
|
```typescript
|
|
71
|
-
import {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
96
|
+
import { validateTransaction } from "@layerzerolabs/lz-sui-sdk-v2";
|
|
97
|
+
|
|
98
|
+
// Register the OFT as an OApp with the LayerZero endpoint
|
|
99
|
+
const registerTx = new Transaction();
|
|
100
|
+
|
|
101
|
+
await oft.registerOAppMoveCall(
|
|
102
|
+
registerTx,
|
|
103
|
+
coinType, // Coin type
|
|
104
|
+
oftObjectId, // Created OFT object ID
|
|
105
|
+
oappObjectId, // Associated OApp object ID
|
|
106
|
+
composerManagerId, // OFT Composer Manager for handling compose messages
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// Execute the transaction
|
|
110
|
+
const result = await validateTransaction(suiClient, signer, registerTx);
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Set Peer for Cross-Chain Communication
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
import { validateTransaction } from "@layerzerolabs/lz-sui-sdk-v2";
|
|
117
|
+
|
|
118
|
+
// Get OApp instance from OFT
|
|
119
|
+
const oapp = protocolSDK.getOApp(oft.oftCallCapId);
|
|
120
|
+
|
|
121
|
+
// Set peer OFT on destination chain
|
|
122
|
+
const setPeerTx = new Transaction();
|
|
123
|
+
await oapp.setPeerMoveCall(
|
|
124
|
+
setPeerTx,
|
|
125
|
+
remoteEid, // Remote chain endpoint ID (e.g., 30102 for Ethereum)
|
|
126
|
+
remotePeerBytes, // Remote OFT address as 32-byte array
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// Execute the transaction
|
|
130
|
+
const result = await validateTransaction(suiClient, signer, setPeerTx);
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Quote and Send Tokens
|
|
134
|
+
|
|
135
|
+
```typescript
|
|
136
|
+
// Create OFT instance (with optional parameters for convenience)
|
|
137
|
+
const oft = new OFT(protocolSDK, oftPackageId);
|
|
138
|
+
|
|
139
|
+
// Prepare send parameters
|
|
140
|
+
const sendParam = {
|
|
141
|
+
dstEid: 30102, // Destination endpoint ID
|
|
142
|
+
to: recipientAddressBytes, // Recipient address as Uint8Array (32 bytes)
|
|
143
|
+
amountLd: 1000000n, // Amount in local decimals
|
|
144
|
+
minAmountLd: 990000n, // Minimum amount (slippage protection)
|
|
145
|
+
extraOptions: new Uint8Array(0), // LayerZero execution options
|
|
146
|
+
composeMsg: new Uint8Array(0), // Optional compose message
|
|
147
|
+
oftCmd: new Uint8Array(0), // Optional OFT command (unused in default OFT)
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Quote the transfer fees
|
|
151
|
+
const messagingFee = await oft.quoteSend(
|
|
152
|
+
senderAddress,
|
|
153
|
+
sendParam,
|
|
154
|
+
false, // payInZro: false = pay in native token
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
// Execute the transfer
|
|
158
|
+
const tx = new Transaction();
|
|
159
|
+
|
|
160
|
+
// Split coins from sender's wallet
|
|
161
|
+
const coin = await oft.splitCoinMoveCall(tx, senderAddress, sendParam.amountLd);
|
|
162
|
+
|
|
163
|
+
// Send the tokens
|
|
164
|
+
await oft.sendMoveCall(
|
|
165
|
+
tx,
|
|
166
|
+
senderAddress,
|
|
167
|
+
sendParam,
|
|
168
|
+
coin,
|
|
169
|
+
messagingFee.nativeFee,
|
|
170
|
+
messagingFee.zroFee,
|
|
171
|
+
senderAddress, // refund address
|
|
82
172
|
);
|
|
83
173
|
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
composer.registerComposerMoveCall(tx, lzComposeInfo);
|
|
174
|
+
// Transfer any remaining coins back to sender
|
|
175
|
+
tx.transferObjects([coin], senderAddress);
|
|
87
176
|
```
|
|
88
177
|
|
|
89
178
|
## Documentation
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/lz-sui-oft-sdk-v2",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.146",
|
|
4
4
|
"license": "BUSL-1.1",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -28,16 +28,16 @@
|
|
|
28
28
|
"typecheck": "tsc --noEmit"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@layerzerolabs/lz-definitions": "^3.0.
|
|
32
|
-
"@layerzerolabs/lz-sui-sdk-v2": "^3.0.
|
|
31
|
+
"@layerzerolabs/lz-definitions": "^3.0.146",
|
|
32
|
+
"@layerzerolabs/lz-sui-sdk-v2": "^3.0.146",
|
|
33
33
|
"@mysten/sui": "^1.33.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@layerzerolabs/lz-foundation": "^3.0.
|
|
37
|
-
"@layerzerolabs/lz-utilities": "^3.0.
|
|
38
|
-
"@layerzerolabs/lz-v2-utilities": "^3.0.
|
|
39
|
-
"@layerzerolabs/tsup-config-next": "^3.0.
|
|
40
|
-
"@layerzerolabs/typescript-config-next": "^3.0.
|
|
36
|
+
"@layerzerolabs/lz-foundation": "^3.0.146",
|
|
37
|
+
"@layerzerolabs/lz-utilities": "^3.0.146",
|
|
38
|
+
"@layerzerolabs/lz-v2-utilities": "^3.0.146",
|
|
39
|
+
"@layerzerolabs/tsup-config-next": "^3.0.146",
|
|
40
|
+
"@layerzerolabs/typescript-config-next": "^3.0.146",
|
|
41
41
|
"@types/chai": "^4.3.11",
|
|
42
42
|
"@types/chai-as-promised": "^7.1.0",
|
|
43
43
|
"@types/mocha": "^10.0.6",
|