@layerzerolabs/oft-sui-sdk 0.0.0-stage → 1.2.100

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/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2026 - LayerZero Labs Ltd.
2
+
3
+ Permission is hereby granted, free of charge, to any
4
+ person obtaining a copy of this software and associated
5
+ documentation files (the "Software"), to deal in the
6
+ Software without restriction, including without
7
+ limitation the rights to use, copy, modify, merge,
8
+ publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software
10
+ is furnished to do so, subject to the following
11
+ conditions:
12
+ The above copyright notice and this permission notice
13
+ shall be included in all copies or substantial portions
14
+ of the Software.
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16
+ ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17
+ TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18
+ PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22
+ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
+ DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,183 @@
1
- # Temporary Holding Version
1
+ # @layerzerolabs/oft-sui-sdk
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ LayerZero V2 SUI OFT (Omnichain Fungible Token) SDK
4
+
5
+ ## Overview
6
+
7
+ This SDK provides TypeScript bindings for interacting with LayerZero V2 OFT contracts on the SUI blockchain. It enables developers to create, manage, and transfer omnichain fungible tokens across different blockchains using the LayerZero protocol.
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install @layerzerolabs/oft-sui-sdk
13
+ # or
14
+ yarn add @layerzerolabs/oft-sui-sdk
15
+ # or
16
+ pnpm add @layerzerolabs/oft-sui-sdk
17
+ ```
18
+
19
+ The package is ESM only. It replaces `@layerzerolabs/lz-sui-oft-sdk-v2`, which also shipped a CommonJS build. CommonJS code can `require` it only on Node versions with `require(esm)` (20.19+ or 22.12+). Otherwise, use `import` or a dynamic `import()`.
20
+
21
+ TypeScript consumers need `moduleResolution: bundler`. Under `node16` or `nodenext`, the package's type declarations do not resolve.
22
+
23
+ ## Features
24
+
25
+ - **Cross-chain Transfers**: Send tokens across different blockchains
26
+ - **OFT & OFT Adapter**: Interact with deployed OFT & OFT Adapter
27
+ - **OFT Composer Manager**: Advanced composition functionality for complex cross-chain operations
28
+
29
+ ## Usage
30
+
31
+ ### Initialize OFT
32
+
33
+ Create a new OFT that mints/burns tokens for cross-chain transfers:
34
+
35
+ ```typescript
36
+ import { OFT } from '@layerzerolabs/oft-sui-sdk';
37
+ import { SDK, validateTransaction } from '@layerzerolabs/lz-sui-sdk-v2';
38
+ import { Transaction } from '@mysten/sui/transactions';
39
+ import { Stage } from '@layerzerolabs/lz-definitions';
40
+
41
+ // Initialize LayerZero protocol SDK
42
+ const protocolSDK = new SDK({
43
+ client: suiClient,
44
+ stage: Stage.MAINNET,
45
+ });
46
+
47
+ // Create OFT instance with its call cap ID and coin type
48
+ const oft = new OFT(protocolSDK, oftCallCapId, undefined, coinType);
49
+
50
+ // Initialize OFT with treasury capability (for minting/burning)
51
+ const initTx = new Transaction();
52
+ const [adminCap, migrationCap] = oft.initOftMoveCall(
53
+ initTx,
54
+ coinType, // e.g., "0x123::my_coin::MY_COIN"
55
+ oftInitTicketId, // OFT creation ticket
56
+ oappObjectId, // Associated OApp object
57
+ treasuryCapId, // Treasury cap for minting/burning
58
+ metadataId, // Coin metadata
59
+ 6, // Shared decimals for cross-chain compatibility
60
+ );
61
+
62
+ // Transfer capabilities to your address
63
+ initTx.transferObjects([adminCap, migrationCap], initTx.pure.address(yourAddress));
64
+
65
+ // Execute the transaction
66
+ const result = await validateTransaction(suiClient, signer, initTx);
67
+ ```
68
+
69
+ ### Initialize OFT Adapter
70
+
71
+ Create an OFT Adapter that wraps existing tokens:
72
+
73
+ ```typescript
74
+ // Initialize OFT Adapter (wraps existing tokens without minting/burning)
75
+ const adapterTx = new Transaction();
76
+ const [adminCap, migrationCap] = oft.initOftAdapterMoveCall(
77
+ adapterTx,
78
+ coinType, // e.g., "0x123::my_coin::MY_COIN"
79
+ oftInitTicketId, // OFT creation ticket
80
+ oappObjectId, // Associated OApp object
81
+ metadataId, // Coin metadata
82
+ 6, // Shared decimals for cross-chain compatibility
83
+ );
84
+
85
+ // Transfer capabilities to your address
86
+ adapterTx.transferObjects([adminCap, migrationCap], adapterTx.pure.address(yourAddress));
87
+
88
+ // Execute the transaction
89
+ const result = await validateTransaction(suiClient, signer, adapterTx);
90
+ ```
91
+
92
+ ### Register OFT with LayerZero Endpoint
93
+
94
+ ```typescript
95
+ import { validateTransaction } from '@layerzerolabs/lz-sui-sdk-v2';
96
+
97
+ // Register the OFT as an OApp with the LayerZero endpoint
98
+ const registerTx = new Transaction();
99
+
100
+ await oft.registerOAppMoveCall(
101
+ registerTx,
102
+ coinType, // Coin type
103
+ oftObjectId, // Created OFT object ID
104
+ oappObjectId, // Associated OApp object ID
105
+ composerManagerId, // OFT Composer Manager for handling compose messages
106
+ );
107
+
108
+ // Execute the transaction
109
+ const result = await validateTransaction(suiClient, signer, registerTx);
110
+ ```
111
+
112
+ ### Set Peer for Cross-Chain Communication
113
+
114
+ ```typescript
115
+ import { validateTransaction } from '@layerzerolabs/lz-sui-sdk-v2';
116
+
117
+ // Get OApp instance from OFT
118
+ const oapp = protocolSDK.getOApp(oft.oftCallCapId);
119
+
120
+ // Set peer OFT on destination chain
121
+ const setPeerTx = new Transaction();
122
+ await oapp.setPeerMoveCall(
123
+ setPeerTx,
124
+ remoteEid, // Remote chain endpoint ID (e.g., 30102 for Ethereum)
125
+ remotePeerBytes, // Remote OFT address as 32-byte array
126
+ );
127
+
128
+ // Execute the transaction
129
+ const result = await validateTransaction(suiClient, signer, setPeerTx);
130
+ ```
131
+
132
+ ### Quote and Send Tokens
133
+
134
+ ```typescript
135
+ // Create OFT instance with its OFT object ID and coin type
136
+ const oft = new OFT(protocolSDK, oftCallCapId, oftObjectId, coinType);
137
+
138
+ // Prepare send parameters
139
+ const sendParam = {
140
+ dstEid: 30102, // Destination endpoint ID
141
+ to: recipientAddressBytes, // Recipient address as Uint8Array (32 bytes)
142
+ amountLd: 1000000n, // Amount in local decimals
143
+ minAmountLd: 990000n, // Minimum amount (slippage protection)
144
+ extraOptions: new Uint8Array(0), // LayerZero execution options
145
+ composeMsg: new Uint8Array(0), // Optional compose message
146
+ oftCmd: new Uint8Array(0), // Optional OFT command (unused in default OFT)
147
+ };
148
+
149
+ // Quote the transfer fees
150
+ const messagingFee = await oft.quoteSend(
151
+ senderAddress,
152
+ sendParam,
153
+ false, // payInZro: false = pay in native token
154
+ );
155
+
156
+ // Execute the transfer
157
+ const tx = new Transaction();
158
+
159
+ // Split coins from sender's wallet
160
+ const coin = await oft.splitCoinMoveCall(tx, senderAddress, sendParam.amountLd);
161
+
162
+ // Send the tokens
163
+ await oft.sendMoveCall(
164
+ tx,
165
+ senderAddress,
166
+ sendParam,
167
+ coin,
168
+ messagingFee.nativeFee,
169
+ messagingFee.zroFee,
170
+ senderAddress, // refund address
171
+ );
172
+
173
+ // Transfer any remaining coins back to sender
174
+ tx.transferObjects([coin], senderAddress);
175
+ ```
176
+
177
+ ## Documentation
178
+
179
+ For detailed documentation and examples, please visit the [LayerZero documentation](https://docs.layerzero.network/).
180
+
181
+ ## License
182
+
183
+ MIT
@@ -0,0 +1,106 @@
1
+ import { __name } from './VUOMXK5T.js';
2
+ import { bcs } from '@mysten/sui/bcs';
3
+ import { asObject, asAddress, asBytes32, executeSimulate } from '@layerzerolabs/lz-sui-sdk-v2';
4
+
5
+ var OFTComposerManagerErrorCode = {
6
+ // OFT Composer Manager related errors
7
+ EComposeTransferNotFound: 1,
8
+ EDepositAddressNotFound: 2
9
+ };
10
+ var OFTComposerManager = class {
11
+ static {
12
+ __name(this, "OFTComposerManager");
13
+ }
14
+ packageId;
15
+ client;
16
+ registryObjectId;
17
+ protocolSDK;
18
+ constructor(protocolSDK, packageId, registryObjectId) {
19
+ this.client = protocolSDK.client;
20
+ this.protocolSDK = protocolSDK;
21
+ this.packageId = packageId;
22
+ this.registryObjectId = registryObjectId;
23
+ }
24
+ // === Set Functions ===
25
+ /**
26
+ * Set deposit address for OFT composer
27
+ * @param tx - The transaction to add the move call to
28
+ * @param composerCallCap - The composer call capability transaction result
29
+ * @param depositAddress - The new deposit address
30
+ * @returns Transaction result containing the set operation
31
+ */
32
+ setDepositAddressMoveCall(tx, composerCallCap, depositAddress) {
33
+ return tx.moveCall({
34
+ target: this.#target("set_deposit_address"),
35
+ arguments: [
36
+ tx.object(this.registryObjectId),
37
+ asObject(tx, composerCallCap),
38
+ asAddress(tx, depositAddress)
39
+ ]
40
+ });
41
+ }
42
+ // === View Functions ===
43
+ /**
44
+ * Get deposit address for a composer
45
+ * @param tx - The transaction to add the move call to
46
+ * @param composer - The composer address
47
+ * @returns Transaction result containing the deposit address
48
+ */
49
+ getDepositAddressMoveCall(tx, composer) {
50
+ return tx.moveCall({
51
+ target: this.#target("get_deposit_address"),
52
+ arguments: [
53
+ tx.object(this.registryObjectId),
54
+ asAddress(tx, composer)
55
+ ]
56
+ });
57
+ }
58
+ /**
59
+ * Get compose transfer object for composition operations
60
+ * @param tx - The transaction to add the move call to
61
+ * @param from - The sender address
62
+ * @param guid - The GUID transaction result
63
+ * @param composer - The composer address
64
+ * @returns Transaction result containing the compose transfer object
65
+ */
66
+ getComposeTransferMoveCall(tx, from, guid, composer) {
67
+ return tx.moveCall({
68
+ target: this.#target("get_compose_transfer"),
69
+ arguments: [
70
+ tx.object(this.registryObjectId),
71
+ asAddress(tx, from),
72
+ asBytes32(tx, guid, this.protocolSDK.getUtils()),
73
+ asAddress(tx, composer)
74
+ ]
75
+ });
76
+ }
77
+ /**
78
+ * Get compose transfer object address
79
+ * @param from - The sender address
80
+ * @param guid - The GUID as number array
81
+ * @param composer - The composer address
82
+ * @returns Promise<string> - The compose transfer object address
83
+ */
84
+ async getComposeTransfer(from, guid, composer) {
85
+ return executeSimulate(this.client, (tx) => {
86
+ return this.getComposeTransferMoveCall(tx, from, asBytes32(tx, guid, this.protocolSDK.getUtils()), composer);
87
+ }, (result) => {
88
+ const parsed = bcs.Address.parse(result[0].value);
89
+ return parsed;
90
+ });
91
+ }
92
+ // === Private Functions ===
93
+ /**
94
+ * Generate the full target path for move calls
95
+ * @param func - The function name to call
96
+ * @returns The full module path for the move call
97
+ * @private
98
+ */
99
+ #target(func) {
100
+ return `${this.packageId}::oft_composer_manager::${func}`;
101
+ }
102
+ };
103
+
104
+ export { OFTComposerManager, OFTComposerManagerErrorCode };
105
+ //# sourceMappingURL=2EH6TEKC.js.map
106
+ //# sourceMappingURL=2EH6TEKC.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/modules/oft-composer-manager.ts"],"names":["OFTComposerManagerErrorCode","EComposeTransferNotFound","EDepositAddressNotFound","OFTComposerManager","packageId","client","registryObjectId","protocolSDK","setDepositAddressMoveCall","tx","composerCallCap","depositAddress","moveCall","target","arguments","object","asObject","asAddress","getDepositAddressMoveCall","composer","getComposeTransferMoveCall","from","guid","asBytes32","getUtils","getComposeTransfer","executeSimulate","result","parsed","bcs","Address","parse","value","func"],"mappings":";;;;AAOO,IAAMA,2BAAAA,GAA8B;;EAEvCC,wBAAAA,EAA0B,CAAA;EAC1BC,uBAAAA,EAAyB;AAC7B;AAQO,IAAMC,qBAAN,MAAMA;EAnBb;;;AAoBWC,EAAAA,SAAAA;AACSC,EAAAA,MAAAA;AACAC,EAAAA,gBAAAA;AACCC,EAAAA,WAAAA;EAEjB,WAAA,CAAYA,WAAAA,EA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a,IAAAA,EAAM,IAAA,CAAKf,WAAAA,CAAYiB,UAAQ,CAAA;AAC7CP,QAAAA,SAAAA,CAAUR,IAAIU,QAAAA;;KAEtB,CAAA;AACJ,EAAA;;;;;;;;EASA,MAAMM,kBAAAA,CAAmBJ,IAAAA,EAAcC,IAAAA,EAAkBH,QAAAA,EAAmC;AACxF,IAAA,OAAOO,eAAAA,CACH,IAAA,CAAKrB,MAAAA,EACL,CAACI,EAAAA,KAAAA;AACG,MAAA,OAAO,IAAA,CAAKW,0BAAAA,CACRX,EAAAA,EACAY,IAAAA,EACAE,SAAAA,CAAUd,EAAAA,EAAIa,IAAAA,EAAM,IAAA,CAAKf,WAAAA,CAAYiB,QAAAA,EAAQ,CAAA,EAC7CL,QAAAA,CAAAA;AAER,IAAA,CAAA,EACA,CAACQ,MAAAA,KAAAA;AACG,MAAA,MAAMC,SAASC,GAAAA,CAAIC,OAAAA,CAAQC,MAAMJ,MAAAA,CAAO,CAAA,EAAGK,KAAK,CAAA;AAChD,MAAA,OAAOJ,MAAAA;IACX,CAAA,CAAA;AAER,EAAA;;;;;;;;AAUA,EAAA,OAAA,CAAQK,IAAAA,EAAY;AAChB,IAAA,OAAO,CAAA,EAAG,IAAA,CAAK7B,SAAS,CAAA,wBAAA,EAA2B6B,IAAAA,CAAAA,CAAAA;AACvD,EAAA;AACJ","file":"2EH6TEKC.js","sourcesContent":["import { bcs } from '@mysten/sui/bcs';\nimport type { SuiClient } from '@mysten/sui/client';\nimport type { Transaction, TransactionArgument, TransactionResult } from '@mysten/sui/transactions';\n\nimport type { SDK } from '@layerzerolabs/lz-sui-sdk-v2';\nimport { asAddress, asBytes32, asObject, executeSimulate } from '@layerzerolabs/lz-sui-sdk-v2';\n\nexport const OFTComposerManagerErrorCode = {\n // OFT Composer Manager related errors\n EComposeTransferNotFound: 1,\n EDepositAddressNotFound: 2,\n} as const;\n\n/**\n * OFT Composer Manager\n *\n * This class manages the registry for OFT Composer operations, including\n * deposit addresses and compose transfer routing for cross-chain composition.\n */\nexport class OFTComposerManager {\n public packageId: string;\n public readonly client: SuiClient;\n public readonly registryObjectId: string;\n private readonly protocolSDK: SDK;\n\n constructor(protocolSDK: SDK, packageId: string, registryObjectId: string) {\n this.client = protocolSDK.client;\n this.protocolSDK = protocolSDK;\n this.packageId = packageId;\n this.registryObjectId = registryObjectId;\n }\n\n // === Set Functions ===\n\n /**\n * Set deposit address for OFT composer\n * @param tx - The transaction to add the move call to\n * @param composerCallCap - The composer call capability transaction result\n * @param depositAddress - The new deposit address\n * @returns Transaction result containing the set operation\n */\n setDepositAddressMoveCall(\n tx: Transaction,\n composerCallCap: string | TransactionArgument,\n depositAddress: string | TransactionArgument,\n ): TransactionResult {\n return tx.moveCall({\n target: this.#target('set_deposit_address'),\n arguments: [\n tx.object(this.registryObjectId),\n asObject(tx, composerCallCap),\n asAddress(tx, depositAddress),\n ],\n });\n }\n\n // === View Functions ===\n\n /**\n * Get deposit address for a composer\n * @param tx - The transaction to add the move call to\n * @param composer - The composer address\n * @returns Transaction result containing the deposit address\n */\n getDepositAddressMoveCall(\n tx: Transaction,\n composer: string | TransactionArgument,\n ): TransactionResult {\n return tx.moveCall({\n target: this.#target('get_deposit_address'),\n arguments: [tx.object(this.registryObjectId), asAddress(tx, composer)],\n });\n }\n\n /**\n * Get compose transfer object for composition operations\n * @param tx - The transaction to add the move call to\n * @param from - The sender address\n * @param guid - The GUID transaction result\n * @param composer - The composer address\n * @returns Transaction result containing the compose transfer object\n */\n getComposeTransferMoveCall(\n tx: Transaction,\n from: string | TransactionArgument,\n guid: Uint8Array | TransactionArgument,\n composer: string | TransactionArgument,\n ): TransactionResult {\n return tx.moveCall({\n target: this.#target('get_compose_transfer'),\n arguments: [\n tx.object(this.registryObjectId),\n asAddress(tx, from),\n asBytes32(tx, guid, this.protocolSDK.getUtils()),\n asAddress(tx, composer),\n ],\n });\n }\n\n /**\n * Get compose transfer object address\n * @param from - The sender address\n * @param guid - The GUID as number array\n * @param composer - The composer address\n * @returns Promise<string> - The compose transfer object address\n */\n async getComposeTransfer(from: string, guid: Uint8Array, composer: string): Promise<string> {\n return executeSimulate(\n this.client,\n (tx) => {\n return this.getComposeTransferMoveCall(\n tx,\n from,\n asBytes32(tx, guid, this.protocolSDK.getUtils()),\n composer,\n );\n },\n (result) => {\n const parsed = bcs.Address.parse(result[0].value);\n return parsed;\n },\n );\n }\n\n // === Private Functions ===\n\n /**\n * Generate the full target path for move calls\n * @param func - The function name to call\n * @returns The full module path for the move call\n * @private\n */\n #target(func: string): string {\n return `${this.packageId}::oft_composer_manager::${func}`;\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ // src/types.ts
2
+ var OFTMsgType = {
3
+ SEND: 1,
4
+ SEND_AND_CALL: 2
5
+ };
6
+
7
+ export { OFTMsgType };
8
+ //# sourceMappingURL=I5Z2GNDD.js.map
9
+ //# sourceMappingURL=I5Z2GNDD.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"names":["OFTMsgType","SEND","SEND_AND_CALL"],"mappings":";AACO,IAAMA,UAAAA,GAAa;EACtBC,IAAAA,EAAM,CAAA;EACNC,aAAAA,EAAe;AACnB","file":"I5Z2GNDD.js","sourcesContent":["// Constants\nexport const OFTMsgType = {\n SEND: 1,\n SEND_AND_CALL: 2,\n} as const;\n\n// Type Definitions\nexport interface SendParam {\n dstEid: number;\n to: Uint8Array;\n amountLd: bigint;\n minAmountLd: bigint;\n extraOptions: Uint8Array;\n composeMsg: Uint8Array;\n oftCmd: Uint8Array;\n}\n\nexport interface OFTLimit {\n minAmountLd: bigint;\n maxAmountLd: bigint;\n}\n\nexport interface OFTFeeDetail {\n feeAmountLd: bigint;\n description: string;\n isReward: boolean;\n}\n\nexport interface OFTReceipt {\n amountSentLd: bigint;\n amountReceivedLd: bigint;\n}\n\nexport interface OFTInfoV1 {\n oftPackage: string;\n oftObject: string;\n}\n"]}