@layerzerolabs/oft-iota-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-iota-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 IOTA OFT (Omnichain Fungible Token) SDK
4
+
5
+ ## Overview
6
+
7
+ This SDK provides TypeScript bindings for interacting with LayerZero V2 OFT contracts on the IOTA 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-iota-sdk
13
+ # or
14
+ yarn add @layerzerolabs/oft-iota-sdk
15
+ # or
16
+ pnpm add @layerzerolabs/oft-iota-sdk
17
+ ```
18
+
19
+ The package is ESM only. It replaces `@layerzerolabs/lz-iotal1-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-iota-sdk';
37
+ import { SDK, validateTransaction } from '@layerzerolabs/lz-iotal1-sdk-v2';
38
+ import { Transaction } from '@iota/iota-sdk/transactions';
39
+ import { Stage } from '@layerzerolabs/lz-definitions';
40
+
41
+ // Initialize LayerZero protocol SDK
42
+ const protocolSDK = new SDK({
43
+ client: iotaClient,
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(iotaClient, 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(iotaClient, signer, adapterTx);
90
+ ```
91
+
92
+ ### Register OFT with LayerZero Endpoint
93
+
94
+ ```typescript
95
+ import { validateTransaction } from '@layerzerolabs/lz-iotal1-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(iotaClient, signer, registerTx);
110
+ ```
111
+
112
+ ### Set Peer for Cross-Chain Communication
113
+
114
+ ```typescript
115
+ import { validateTransaction } from '@layerzerolabs/lz-iotal1-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(iotaClient, 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,58 @@
1
+ import { __name } from './VUOMXK5T.js';
2
+ import { bcs } from '@iota/iota-sdk/bcs';
3
+
4
+ var OFTLimitBcs = bcs.struct("OFTLimit", {
5
+ min_amount_ld: bcs.U64,
6
+ max_amount_ld: bcs.U64
7
+ });
8
+ var OFTFeeDetailBcs = bcs.struct("OFTFeeDetail", {
9
+ fee_amount_ld: bcs.U64,
10
+ is_reward: bcs.Bool,
11
+ description: bcs.String
12
+ });
13
+ var OFTReceiptBcs = bcs.struct("OFTReceipt", {
14
+ amount_sent_ld: bcs.U64,
15
+ amount_received_ld: bcs.U64
16
+ });
17
+ var OFTInfoV1Bcs = bcs.struct("OFTInfoV1", {
18
+ oft_package: bcs.Address,
19
+ oft_object: bcs.Address
20
+ });
21
+ function parseOFTLimit(data) {
22
+ const parsed = OFTLimitBcs.parse(data);
23
+ return {
24
+ minAmountLd: BigInt(parsed.min_amount_ld),
25
+ maxAmountLd: BigInt(parsed.max_amount_ld)
26
+ };
27
+ }
28
+ __name(parseOFTLimit, "parseOFTLimit");
29
+ function parseOFTFeeDetails(data) {
30
+ const vectorBcs = bcs.vector(OFTFeeDetailBcs);
31
+ const parsed = vectorBcs.parse(data);
32
+ return parsed.map((detail) => ({
33
+ feeAmountLd: BigInt(detail.fee_amount_ld),
34
+ isReward: detail.is_reward,
35
+ description: detail.description
36
+ }));
37
+ }
38
+ __name(parseOFTFeeDetails, "parseOFTFeeDetails");
39
+ function parseOFTReceipt(data) {
40
+ const parsed = OFTReceiptBcs.parse(data);
41
+ return {
42
+ amountSentLd: BigInt(parsed.amount_sent_ld),
43
+ amountReceivedLd: BigInt(parsed.amount_received_ld)
44
+ };
45
+ }
46
+ __name(parseOFTReceipt, "parseOFTReceipt");
47
+ function parseOFTInfoV1(data) {
48
+ const parsed = OFTInfoV1Bcs.parse(data);
49
+ return {
50
+ oftPackage: parsed.oft_package,
51
+ oftObject: parsed.oft_object
52
+ };
53
+ }
54
+ __name(parseOFTInfoV1, "parseOFTInfoV1");
55
+
56
+ export { OFTFeeDetailBcs, OFTInfoV1Bcs, OFTLimitBcs, OFTReceiptBcs, parseOFTFeeDetails, parseOFTInfoV1, parseOFTLimit, parseOFTReceipt };
57
+ //# sourceMappingURL=CDSWWWJ7.js.map
58
+ //# sourceMappingURL=CDSWWWJ7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bcs/oft.ts"],"names":["OFTLimitBcs","bcs","struct","min_amount_ld","U64","max_amount_ld","OFTFeeDetailBcs","fee_amount_ld","is_reward","Bool","description","String","OFTReceiptBcs","amount_sent_ld","amount_received_ld","OFTInfoV1Bcs","oft_package","Address","oft_object","parseOFTLimit","data","parsed","parse","minAmountLd","BigInt","maxAmountLd","parseOFTFeeDetails","vectorBcs","vector","map","detail","feeAmountLd","isReward","parseOFTReceipt","amountSentLd","amountReceivedLd","parseOFTInfoV1","oftPackage","oftObject"],"mappings":";;;AAKO,IAAMA,WAAAA,GAAcC,GAAAA,CAAIC,MAAAA,CAAO,UAAA,EAAY;AAC9CC,EAAAA,aAAAA,EAAeF,GAAAA,CAAIG,GAAAA;AACnBC,EAAAA,aAAAA,EAAeJ,GAAAA,CAAIG;AACvB,CAAA;AAGO,IAAME,eAAAA,GAAkBL,GAAAA,CAAIC,MAAAA,CAAO,cAAA,EAAgB;AACtDK,EAAAA,aAAAA,EAAeN,GAAAA,CAAIG,GAAAA;AACnBI,EAAAA,SAAAA,EAAWP,GAAAA,CAAIQ,IAAAA;AACfC,EAAAA,WAAAA,EAAaT,GAAAA,CAAIU;AACrB,CAAA;AAGO,IAAMC,aAAAA,GAAgBX,GAAAA,CAAIC,MAAAA,CAAO,YAAA,EAAc;AAClDW,EAAAA,cAAAA,EAAgBZ,GAAAA,CAAIG,GAAAA;AACpBU,EAAAA,kBAAAA,EAAoBb,GAAAA,CAAIG;AAC5B,CAAA;AAGO,IAAMW,YAAAA,GAAed,GAAAA,CAAIC,MAAAA,CAAO,WAAA,EAAa;AAChDc,EAAAA,WAAAA,EAAaf,GAAAA,CAAIgB,OAAAA;AACjBC,EAAAA,UAAAA,EAAYjB,GAAAA,CAAIgB;AACpB,CAAA;AAGO,SAASE,cAAcC,IAAAA,EAAgB;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EAAYhB,MAAAA,CAAOL,WAAAA;AACnBsB,IAAAA,SAAAA,EAAWjB,MAAAA,CAAOH;AACtB,GAAA;AACJ;AANgBkB,MAAAA,CAAAA,cAAAA,EAAAA,gBAAAA,CAAAA","file":"CDSWWWJ7.js","sourcesContent":["import { bcs } from '@iota/iota-sdk/bcs';\n\nimport type { OFTFeeDetail, OFTInfoV1, OFTLimit, OFTReceipt } from '../types';\n\n// OFTLimit struct BCS definition\nexport const OFTLimitBcs = bcs.struct('OFTLimit', {\n min_amount_ld: bcs.U64,\n max_amount_ld: bcs.U64,\n});\n\n// OFTFeeDetail struct BCS definition\nexport const OFTFeeDetailBcs = bcs.struct('OFTFeeDetail', {\n fee_amount_ld: bcs.U64,\n is_reward: bcs.Bool,\n description: bcs.String,\n});\n\n// OFTReceipt struct BCS definition\nexport const OFTReceiptBcs = bcs.struct('OFTReceipt', {\n amount_sent_ld: bcs.U64,\n amount_received_ld: bcs.U64,\n});\n\n// OFTInfoV1 struct BCS definition\nexport const OFTInfoV1Bcs = bcs.struct('OFTInfoV1', {\n oft_package: bcs.Address,\n oft_object: bcs.Address,\n});\n\n// Helper function to parse OFTLimit\nexport function parseOFTLimit(data: Uint8Array): OFTLimit {\n const parsed = OFTLimitBcs.parse(data);\n return {\n minAmountLd: BigInt(parsed.min_amount_ld),\n maxAmountLd: BigInt(parsed.max_amount_ld),\n };\n}\n\n// Helper function to parse OFTFeeDetail array\nexport function parseOFTFeeDetails(data: Uint8Array): OFTFeeDetail[] {\n // Parse as vector of OFTFeeDetail\n const vectorBcs = bcs.vector(OFTFeeDetailBcs);\n const parsed = vectorBcs.parse(data);\n\n return parsed.map(\n (detail: {\n fee_amount_ld: string | number | bigint;\n is_reward: boolean;\n description: string;\n }) => ({\n feeAmountLd: BigInt(detail.fee_amount_ld),\n isReward: detail.is_reward,\n description: detail.description,\n }),\n );\n}\n\n// Helper function to parse OFTReceipt\nexport function parseOFTReceipt(data: Uint8Array): OFTReceipt {\n const parsed = OFTReceiptBcs.parse(data);\n return {\n amountSentLd: BigInt(parsed.amount_sent_ld),\n amountReceivedLd: BigInt(parsed.amount_received_ld),\n };\n}\n\n// Helper function to parse OFTInfoV1\nexport function parseOFTInfoV1(data: Uint8Array): OFTInfoV1 {\n const parsed = OFTInfoV1Bcs.parse(data);\n return {\n oftPackage: parsed.oft_package,\n oftObject: parsed.oft_object,\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"]}