@m0-foundation/ntt-sdk-route 0.0.7 → 0.0.10
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/dist/index.d.mts +23 -4
- package/dist/index.d.ts +23 -4
- package/dist/index.js +603 -22
- package/dist/index.mjs +600 -24
- package/package.json +7 -2
package/dist/index.js
CHANGED
|
@@ -2,24 +2,502 @@
|
|
|
2
2
|
|
|
3
3
|
var sdkConnect = require('@wormhole-foundation/sdk-connect');
|
|
4
4
|
var sdkDefinitionsNtt = require('@wormhole-foundation/sdk-definitions-ntt');
|
|
5
|
-
require('@wormhole-foundation/sdk-solana-ntt');
|
|
5
|
+
var sdkSolanaNtt = require('@wormhole-foundation/sdk-solana-ntt');
|
|
6
6
|
var sdkEvm = require('@wormhole-foundation/sdk-evm');
|
|
7
|
-
require('@wormhole-foundation/sdk-solana');
|
|
7
|
+
var sdkSolana = require('@wormhole-foundation/sdk-solana');
|
|
8
8
|
var sdkRouteNtt = require('@wormhole-foundation/sdk-route-ntt');
|
|
9
9
|
var ethers = require('ethers');
|
|
10
|
+
var web3_js = require('@solana/web3.js');
|
|
11
|
+
var splToken = require('@solana/spl-token');
|
|
12
|
+
var BN = require('bn.js');
|
|
13
|
+
var sha2 = require('@noble/hashes/sha2');
|
|
14
|
+
|
|
15
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
16
|
+
|
|
17
|
+
var BN__default = /*#__PURE__*/_interopDefault(BN);
|
|
10
18
|
|
|
11
19
|
// src/m0AutomaticRoute.ts
|
|
12
|
-
var
|
|
13
|
-
|
|
20
|
+
var SolanaRoutes = class {
|
|
21
|
+
constructor(network) {
|
|
22
|
+
if (network === "Devnet") {
|
|
23
|
+
throw new Error("Solana does not support Devnet for NTT contracts");
|
|
24
|
+
}
|
|
25
|
+
this.network = network;
|
|
26
|
+
this.programs = {
|
|
27
|
+
Mainnet: {
|
|
28
|
+
swap: pk("MSwapi3WhNKMUGm9YrxGhypgUEt7wYQH3ZgG32XoWzH"),
|
|
29
|
+
earn: pk("mz2vDzjbQDUDXBH6FPF5s4odCJ4y8YLE5QWaZ8XdZ9Z"),
|
|
30
|
+
lut: pk("9JLRqBqkznKiSoNfotA4ywSRdnWb2fE76SiFrAfkaRCD"),
|
|
31
|
+
mMint: pk("mzerokyEX9TNDoK4o2YZQBDmMzjokAeN6M2g2S3pLJo"),
|
|
32
|
+
portal: pk("mzp1q2j5Hr1QuLC3KFBCAUz5aUckT6qyuZKZ3WJnMmY"),
|
|
33
|
+
quoter: pk("Nqd6XqA8LbsCuG8MLWWuP865NV6jR1MbXeKxD4HLKDJ")
|
|
34
|
+
},
|
|
35
|
+
Testnet: {
|
|
36
|
+
swap: pk("MSwapi3WhNKMUGm9YrxGhypgUEt7wYQH3ZgG32XoWzH"),
|
|
37
|
+
earn: pk("mz2vDzjbQDUDXBH6FPF5s4odCJ4y8YLE5QWaZ8XdZ9Z"),
|
|
38
|
+
lut: pk("6GhuWPuAmiJeeSVsr58KjqHcAejJRndCx9BVtHkaYHUR"),
|
|
39
|
+
mMint: pk("mzeroZRGCah3j5xEWp2Nih3GDejSBbH1rbHoxDg8By6"),
|
|
40
|
+
portal: pk("mzp1q2j5Hr1QuLC3KFBCAUz5aUckT6qyuZKZ3WJnMmY"),
|
|
41
|
+
quoter: pk("Nqd6XqA8LbsCuG8MLWWuP865NV6jR1MbXeKxD4HLKDJ")
|
|
42
|
+
}
|
|
43
|
+
}[network];
|
|
44
|
+
this.extPrograms = {
|
|
45
|
+
Mainnet: {
|
|
46
|
+
mzeroXDoBpRVhnEXBra27qzAMdxgpWVY3DzQW7xMVJp: {
|
|
47
|
+
program: pk("wMXX1K1nca5W4pZr1piETe78gcAVVrEFi9f4g46uXko"),
|
|
48
|
+
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID
|
|
49
|
+
},
|
|
50
|
+
usdkbee86pkLyRmxfFCdkyySpxRb5ndCxVsK2BkRXwX: {
|
|
51
|
+
program: pk("extaykYu5AQcDm3qZAbiDN3yp6skqn6Nssj7veUUGZw"),
|
|
52
|
+
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID
|
|
53
|
+
},
|
|
54
|
+
usdkyPPxgV7sfNyKb8eDz66ogPrkRXG3wS2FVb6LLUf: {
|
|
55
|
+
program: pk("extMahs9bUFMYcviKCvnSRaXgs5PcqmMzcnHRtTqE85"),
|
|
56
|
+
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
Testnet: {
|
|
60
|
+
mzeroXDoBpRVhnEXBra27qzAMdxgpWVY3DzQW7xMVJp: {
|
|
61
|
+
program: pk("wMXX1K1nca5W4pZr1piETe78gcAVVrEFi9f4g46uXko"),
|
|
62
|
+
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID
|
|
63
|
+
},
|
|
64
|
+
usdkbee86pkLyRmxfFCdkyySpxRb5ndCxVsK2BkRXwX: {
|
|
65
|
+
program: pk("Fb2AsCKmPd4gKhabT6KsremSHMrJ8G2Mopnc6rDQZX9e"),
|
|
66
|
+
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID
|
|
67
|
+
},
|
|
68
|
+
usdkyPPxgV7sfNyKb8eDz66ogPrkRXG3wS2FVb6LLUf: {
|
|
69
|
+
program: pk("3PskKTHgboCbUSQPMcCAZdZNFHbNvSoZ8zEFYANCdob7"),
|
|
70
|
+
tokenProgram: splToken.TOKEN_2022_PROGRAM_ID
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}[network];
|
|
74
|
+
}
|
|
75
|
+
getSolanaContracts() {
|
|
14
76
|
return {
|
|
15
|
-
token:
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
quoter: "Nqd6XqA8LbsCuG8MLWWuP865NV6jR1MbXeKxD4HLKDJ"
|
|
77
|
+
token: this.programs.mMint.toBase58(),
|
|
78
|
+
mLikeTokens: Object.keys(this.extPrograms),
|
|
79
|
+
manager: this.programs.portal.toBase58(),
|
|
80
|
+
transceiver: { wormhole: this.programs.portal.toBase58() },
|
|
81
|
+
quoter: this.programs.quoter.toBase58()
|
|
21
82
|
};
|
|
22
83
|
}
|
|
84
|
+
getTransferExtensionBurnIx(ntt, amount2, recipient, payer, outboxItem, extMint, destinationToken, shouldQueue = true) {
|
|
85
|
+
const recipientAddress = Buffer.alloc(32);
|
|
86
|
+
const dest = Buffer.from(recipient.address.toUint8Array());
|
|
87
|
+
dest.copy(recipientAddress);
|
|
88
|
+
if (destinationToken.length !== 32) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`destinationToken must be 32 bytes, got ${destinationToken.length} bytes`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const extension = this.extPrograms[extMint.toBase58()];
|
|
94
|
+
if (!extension) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`No extension program found for mint ${extMint.toBase58()}`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
const { program: extProgram, tokenProgram: extTokenProgram } = extension;
|
|
100
|
+
return new web3_js.TransactionInstruction({
|
|
101
|
+
programId: ntt.program.programId,
|
|
102
|
+
keys: [
|
|
103
|
+
{
|
|
104
|
+
pubkey: payer,
|
|
105
|
+
isSigner: true,
|
|
106
|
+
isWritable: true
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
// config
|
|
110
|
+
pubkey: ntt.pdas.configAccount(),
|
|
111
|
+
isSigner: false,
|
|
112
|
+
isWritable: false
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
// m mint
|
|
116
|
+
pubkey: this.programs.mMint,
|
|
117
|
+
isSigner: false,
|
|
118
|
+
isWritable: true
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
// from (token auth m token account)
|
|
122
|
+
pubkey: splToken.getAssociatedTokenAddressSync(
|
|
123
|
+
this.programs.mMint,
|
|
124
|
+
web3_js.PublicKey.findProgramAddressSync(
|
|
125
|
+
[Buffer.from("token_authority")],
|
|
126
|
+
ntt.program.programId
|
|
127
|
+
)[0],
|
|
128
|
+
true,
|
|
129
|
+
splToken.TOKEN_2022_PROGRAM_ID
|
|
130
|
+
),
|
|
131
|
+
isSigner: false,
|
|
132
|
+
isWritable: true
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
// m token program
|
|
136
|
+
pubkey: splToken.TOKEN_2022_PROGRAM_ID,
|
|
137
|
+
isSigner: false,
|
|
138
|
+
isWritable: false
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
// outbox item
|
|
142
|
+
pubkey: outboxItem,
|
|
143
|
+
isSigner: true,
|
|
144
|
+
isWritable: true
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
// outbox rate limit
|
|
148
|
+
pubkey: ntt.pdas.outboxRateLimitAccount(),
|
|
149
|
+
isSigner: false,
|
|
150
|
+
isWritable: true
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
// custody
|
|
154
|
+
pubkey: ntt.config.custody,
|
|
155
|
+
isSigner: false,
|
|
156
|
+
isWritable: true
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
// system program
|
|
160
|
+
pubkey: web3_js.SystemProgram.programId,
|
|
161
|
+
isSigner: false,
|
|
162
|
+
isWritable: false
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
// inbox rate limit
|
|
166
|
+
pubkey: ntt.pdas.inboxRateLimitAccount(recipient.chain),
|
|
167
|
+
isSigner: false,
|
|
168
|
+
isWritable: true
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
// peer
|
|
172
|
+
pubkey: ntt.pdas.peerAccount(recipient.chain),
|
|
173
|
+
isSigner: false,
|
|
174
|
+
isWritable: false
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
// session auth
|
|
178
|
+
pubkey: ntt.pdas.sessionAuthority(payer, {
|
|
179
|
+
amount: new BN__default.default(amount2),
|
|
180
|
+
recipientChain: {
|
|
181
|
+
id: 2
|
|
182
|
+
// Ethereum
|
|
183
|
+
},
|
|
184
|
+
recipientAddress: [...Array(32)],
|
|
185
|
+
shouldQueue: false
|
|
186
|
+
}),
|
|
187
|
+
isSigner: false,
|
|
188
|
+
isWritable: false
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
// token auth
|
|
192
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
193
|
+
[Buffer.from("token_authority")],
|
|
194
|
+
ntt.program.programId
|
|
195
|
+
)[0],
|
|
196
|
+
isSigner: false,
|
|
197
|
+
isWritable: false
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
// ext mint
|
|
201
|
+
pubkey: extMint,
|
|
202
|
+
isSigner: false,
|
|
203
|
+
isWritable: true
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
// swap global
|
|
207
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
208
|
+
[Buffer.from("global")],
|
|
209
|
+
this.programs.swap
|
|
210
|
+
)[0],
|
|
211
|
+
isSigner: false,
|
|
212
|
+
isWritable: false
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
// m global
|
|
216
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
217
|
+
[Buffer.from("global")],
|
|
218
|
+
this.programs.earn
|
|
219
|
+
)[0],
|
|
220
|
+
isSigner: false,
|
|
221
|
+
isWritable: false
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
// ext global
|
|
225
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
226
|
+
[Buffer.from("global")],
|
|
227
|
+
extProgram
|
|
228
|
+
)[0],
|
|
229
|
+
isSigner: false,
|
|
230
|
+
isWritable: true
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
// ext token account
|
|
234
|
+
pubkey: splToken.getAssociatedTokenAddressSync(
|
|
235
|
+
extMint,
|
|
236
|
+
payer,
|
|
237
|
+
true,
|
|
238
|
+
extTokenProgram
|
|
239
|
+
),
|
|
240
|
+
isSigner: false,
|
|
241
|
+
isWritable: true
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
// ext m vault
|
|
245
|
+
pubkey: splToken.getAssociatedTokenAddressSync(
|
|
246
|
+
this.programs.mMint,
|
|
247
|
+
web3_js.PublicKey.findProgramAddressSync(
|
|
248
|
+
[Buffer.from("m_vault")],
|
|
249
|
+
extProgram
|
|
250
|
+
)[0],
|
|
251
|
+
true,
|
|
252
|
+
splToken.TOKEN_2022_PROGRAM_ID
|
|
253
|
+
),
|
|
254
|
+
isSigner: false,
|
|
255
|
+
isWritable: true
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
// ext m vault auth
|
|
259
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
260
|
+
[Buffer.from("m_vault")],
|
|
261
|
+
extProgram
|
|
262
|
+
)[0],
|
|
263
|
+
isSigner: false,
|
|
264
|
+
isWritable: false
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
// ext mint auth
|
|
268
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
269
|
+
[Buffer.from("mint_authority")],
|
|
270
|
+
extProgram
|
|
271
|
+
)[0],
|
|
272
|
+
isSigner: false,
|
|
273
|
+
isWritable: false
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
// ext program
|
|
277
|
+
pubkey: extProgram,
|
|
278
|
+
isSigner: false,
|
|
279
|
+
isWritable: false
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
// swap program
|
|
283
|
+
pubkey: this.programs.swap,
|
|
284
|
+
isSigner: false,
|
|
285
|
+
isWritable: false
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
// ext token program
|
|
289
|
+
pubkey: extTokenProgram,
|
|
290
|
+
isSigner: false,
|
|
291
|
+
isWritable: false
|
|
292
|
+
}
|
|
293
|
+
],
|
|
294
|
+
data: Buffer.concat([
|
|
295
|
+
Buffer.from(sha2.sha256("global:transfer_extension_burn").subarray(0, 8)),
|
|
296
|
+
new BN__default.default(amount2).toArrayLike(Buffer, "le", 8),
|
|
297
|
+
// amount
|
|
298
|
+
new BN__default.default(sdkConnect.chainToChainId(recipient.chain)).toArrayLike(Buffer, "le", 2),
|
|
299
|
+
// chain_id
|
|
300
|
+
recipientAddress,
|
|
301
|
+
// recipient_address
|
|
302
|
+
destinationToken,
|
|
303
|
+
// destination_token
|
|
304
|
+
Buffer.from([Number(shouldQueue)])
|
|
305
|
+
// should_queue
|
|
306
|
+
])
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
getReleaseInboundMintExtensionIx(ntt, payer, inboxItem, mMint, extMint, extAta) {
|
|
310
|
+
const extension = this.extPrograms[extMint.toBase58()];
|
|
311
|
+
if (!extension) {
|
|
312
|
+
throw new Error(
|
|
313
|
+
`No extension program found for mint ${extMint.toBase58()}`
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
const { program: extProgram, tokenProgram: extTokenProgram } = extension;
|
|
317
|
+
return new web3_js.TransactionInstruction({
|
|
318
|
+
programId: ntt.program.programId,
|
|
319
|
+
keys: [
|
|
320
|
+
{
|
|
321
|
+
pubkey: pk(payer),
|
|
322
|
+
isSigner: true,
|
|
323
|
+
isWritable: true
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
// config
|
|
327
|
+
pubkey: ntt.pdas.configAccount(),
|
|
328
|
+
isSigner: false,
|
|
329
|
+
isWritable: false
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
// inbox item
|
|
333
|
+
pubkey: inboxItem,
|
|
334
|
+
isSigner: false,
|
|
335
|
+
isWritable: true
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
// recipient (mint to token auth which wraps to user)
|
|
339
|
+
pubkey: splToken.getAssociatedTokenAddressSync(
|
|
340
|
+
mMint,
|
|
341
|
+
web3_js.PublicKey.findProgramAddressSync(
|
|
342
|
+
[Buffer.from("token_authority")],
|
|
343
|
+
ntt.program.programId
|
|
344
|
+
)[0],
|
|
345
|
+
true,
|
|
346
|
+
splToken.TOKEN_2022_PROGRAM_ID
|
|
347
|
+
),
|
|
348
|
+
isSigner: false,
|
|
349
|
+
isWritable: true
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
// token auth
|
|
353
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
354
|
+
[Buffer.from("token_authority")],
|
|
355
|
+
ntt.program.programId
|
|
356
|
+
)[0],
|
|
357
|
+
isSigner: false,
|
|
358
|
+
isWritable: false
|
|
359
|
+
},
|
|
360
|
+
{
|
|
361
|
+
// m mint
|
|
362
|
+
pubkey: mMint,
|
|
363
|
+
isSigner: false,
|
|
364
|
+
isWritable: true
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
// m token program
|
|
368
|
+
pubkey: splToken.TOKEN_2022_PROGRAM_ID,
|
|
369
|
+
isSigner: false,
|
|
370
|
+
isWritable: false
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
// custody
|
|
374
|
+
pubkey: ntt.config.custody,
|
|
375
|
+
isSigner: false,
|
|
376
|
+
isWritable: true
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
// earn program
|
|
380
|
+
pubkey: this.programs.earn,
|
|
381
|
+
isSigner: false,
|
|
382
|
+
isWritable: false
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
// m global
|
|
386
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
387
|
+
[Buffer.from("global")],
|
|
388
|
+
this.programs.earn
|
|
389
|
+
)[0],
|
|
390
|
+
isSigner: false,
|
|
391
|
+
isWritable: false
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
// ext mint
|
|
395
|
+
pubkey: extMint,
|
|
396
|
+
isSigner: false,
|
|
397
|
+
isWritable: true
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
// swap global
|
|
401
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
402
|
+
[Buffer.from("global")],
|
|
403
|
+
this.programs.swap
|
|
404
|
+
)[0],
|
|
405
|
+
isSigner: false,
|
|
406
|
+
isWritable: false
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
// ext global
|
|
410
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
411
|
+
[Buffer.from("global")],
|
|
412
|
+
extProgram
|
|
413
|
+
)[0],
|
|
414
|
+
isSigner: false,
|
|
415
|
+
isWritable: true
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
// ext m vault auth
|
|
419
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
420
|
+
[Buffer.from("m_vault")],
|
|
421
|
+
extProgram
|
|
422
|
+
)[0],
|
|
423
|
+
isSigner: false,
|
|
424
|
+
isWritable: false
|
|
425
|
+
},
|
|
426
|
+
{
|
|
427
|
+
// ext mint auth
|
|
428
|
+
pubkey: web3_js.PublicKey.findProgramAddressSync(
|
|
429
|
+
[Buffer.from("mint_authority")],
|
|
430
|
+
extProgram
|
|
431
|
+
)[0],
|
|
432
|
+
isSigner: false,
|
|
433
|
+
isWritable: false
|
|
434
|
+
},
|
|
435
|
+
{
|
|
436
|
+
// ext m vault
|
|
437
|
+
pubkey: splToken.getAssociatedTokenAddressSync(
|
|
438
|
+
mMint,
|
|
439
|
+
web3_js.PublicKey.findProgramAddressSync(
|
|
440
|
+
[Buffer.from("m_vault")],
|
|
441
|
+
extProgram
|
|
442
|
+
)[0],
|
|
443
|
+
true,
|
|
444
|
+
splToken.TOKEN_2022_PROGRAM_ID
|
|
445
|
+
),
|
|
446
|
+
isSigner: false,
|
|
447
|
+
isWritable: true
|
|
448
|
+
},
|
|
449
|
+
{
|
|
450
|
+
// ext token account
|
|
451
|
+
pubkey: extAta,
|
|
452
|
+
isSigner: false,
|
|
453
|
+
isWritable: true
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
// ext token account
|
|
457
|
+
pubkey: this.programs.swap,
|
|
458
|
+
isSigner: false,
|
|
459
|
+
isWritable: false
|
|
460
|
+
},
|
|
461
|
+
{
|
|
462
|
+
// ext program
|
|
463
|
+
pubkey: extProgram,
|
|
464
|
+
isSigner: false,
|
|
465
|
+
isWritable: false
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
// ext token program
|
|
469
|
+
pubkey: extTokenProgram,
|
|
470
|
+
isSigner: false,
|
|
471
|
+
isWritable: false
|
|
472
|
+
},
|
|
473
|
+
{
|
|
474
|
+
// system program
|
|
475
|
+
pubkey: web3_js.SystemProgram.programId,
|
|
476
|
+
isSigner: false,
|
|
477
|
+
isWritable: false
|
|
478
|
+
}
|
|
479
|
+
],
|
|
480
|
+
data: Buffer.concat([
|
|
481
|
+
Buffer.from(
|
|
482
|
+
sha2.sha256("global:release_inbound_mint_extension").subarray(0, 8)
|
|
483
|
+
)
|
|
484
|
+
])
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
async getAddressLookupTableAccounts(connection) {
|
|
488
|
+
const info = await connection.getAccountInfo(this.programs.lut);
|
|
489
|
+
return new web3_js.AddressLookupTableAccount({
|
|
490
|
+
key: this.programs.lut,
|
|
491
|
+
state: web3_js.AddressLookupTableAccount.deserialize(info.data)
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
function pk(address) {
|
|
496
|
+
return new web3_js.PublicKey(address);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// src/m0AutomaticRoute.ts
|
|
500
|
+
var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.AutomaticRoute {
|
|
23
501
|
static supportedNetworks() {
|
|
24
502
|
return ["Mainnet", "Testnet"];
|
|
25
503
|
}
|
|
@@ -29,9 +507,15 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
29
507
|
static supportedChains(network) {
|
|
30
508
|
switch (network) {
|
|
31
509
|
case "Mainnet":
|
|
32
|
-
return ["Ethereum", "Arbitrum", "Optimism", "Solana"];
|
|
510
|
+
return ["Ethereum", "Arbitrum", "Optimism", "Solana", "Fogo"];
|
|
33
511
|
case "Testnet":
|
|
34
|
-
return [
|
|
512
|
+
return [
|
|
513
|
+
"Sepolia",
|
|
514
|
+
"ArbitrumSepolia",
|
|
515
|
+
"OptimismSepolia",
|
|
516
|
+
"Solana",
|
|
517
|
+
"Fogo"
|
|
518
|
+
];
|
|
35
519
|
default:
|
|
36
520
|
throw new Error(`Unsupported network: ${network}`);
|
|
37
521
|
}
|
|
@@ -51,7 +535,9 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
51
535
|
case "ArbitrumSepolia":
|
|
52
536
|
return this.EVM_CONTRACTS;
|
|
53
537
|
case "Solana":
|
|
54
|
-
return
|
|
538
|
+
return new SolanaRoutes(chainContext.network).getSolanaContracts();
|
|
539
|
+
case "Fogo":
|
|
540
|
+
return new SolanaRoutes(chainContext.network).getSolanaContracts();
|
|
55
541
|
default:
|
|
56
542
|
throw new Error(`Unsupported chain: ${chainContext.chain}`);
|
|
57
543
|
}
|
|
@@ -69,10 +555,9 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
69
555
|
return [];
|
|
70
556
|
}
|
|
71
557
|
const { token: mToken, mLikeTokens } = this.getContracts(toChain);
|
|
72
|
-
return [
|
|
73
|
-
sdkConnect.Wormhole.tokenId(toChain.chain,
|
|
74
|
-
|
|
75
|
-
];
|
|
558
|
+
return [mToken, ...mLikeTokens].map(
|
|
559
|
+
(x) => sdkConnect.Wormhole.tokenId(toChain.chain, x)
|
|
560
|
+
);
|
|
76
561
|
}
|
|
77
562
|
static isProtocolSupported(chain) {
|
|
78
563
|
return chain.supportsProtocol("Ntt");
|
|
@@ -167,14 +652,39 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
167
652
|
const platform = sdkConnect.chainToPlatform(fromChain.chain);
|
|
168
653
|
const transferAmount = sdkConnect.amount.units(params.normalizedParams.amount);
|
|
169
654
|
const options = params.normalizedParams.options;
|
|
170
|
-
if (platform
|
|
655
|
+
if (!_M0AutomaticRoute.isPlatformSupported(platform))
|
|
171
656
|
throw new Error(`Unsupported platform ${platform}`);
|
|
172
657
|
const ntt = await fromChain.getProtocol("Ntt", {
|
|
173
658
|
ntt: _M0AutomaticRoute.getContracts(fromChain)
|
|
174
659
|
});
|
|
175
660
|
const sourceToken = sdkConnect.canonicalAddress(request.source.id);
|
|
176
661
|
const destinationToken = sdkConnect.canonicalAddress(request.destination.id);
|
|
177
|
-
const initXfer = platform === "Evm" ?
|
|
662
|
+
const initXfer = platform === "Evm" ? (
|
|
663
|
+
// for EVM call transferMLike function
|
|
664
|
+
this.transferMLike(
|
|
665
|
+
ntt,
|
|
666
|
+
// @ts-ignore
|
|
667
|
+
sender,
|
|
668
|
+
transferAmount,
|
|
669
|
+
to,
|
|
670
|
+
sourceToken,
|
|
671
|
+
destinationToken,
|
|
672
|
+
options
|
|
673
|
+
)
|
|
674
|
+
) : (
|
|
675
|
+
// for Solana use custom transfer instruction
|
|
676
|
+
this.transferSolanaExtension(
|
|
677
|
+
ntt,
|
|
678
|
+
request.fromChain.network,
|
|
679
|
+
// @ts-ignore
|
|
680
|
+
sender,
|
|
681
|
+
transferAmount,
|
|
682
|
+
to,
|
|
683
|
+
sourceToken,
|
|
684
|
+
destinationToken,
|
|
685
|
+
options
|
|
686
|
+
)
|
|
687
|
+
);
|
|
178
688
|
const txids = await sdkConnect.signSendWait(fromChain, initXfer, signer);
|
|
179
689
|
return {
|
|
180
690
|
from: fromChain.chain,
|
|
@@ -234,6 +744,76 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
234
744
|
parallelizable
|
|
235
745
|
);
|
|
236
746
|
}
|
|
747
|
+
async *transferSolanaExtension(ntt, network, sender, amount2, recipient, sourceToken, destinationToken, options) {
|
|
748
|
+
const router = new SolanaRoutes(network);
|
|
749
|
+
if (router.getSolanaContracts().token === sourceToken) {
|
|
750
|
+
return ntt.transfer(sender, amount2, recipient, options);
|
|
751
|
+
}
|
|
752
|
+
const config = await ntt.getConfig();
|
|
753
|
+
if (config.paused) throw new Error("Contract is paused");
|
|
754
|
+
const outboxItem = web3_js.Keypair.generate();
|
|
755
|
+
const payerAddress = new sdkSolana.SolanaAddress(sender).unwrap();
|
|
756
|
+
const ixs = [
|
|
757
|
+
router.getTransferExtensionBurnIx(
|
|
758
|
+
ntt,
|
|
759
|
+
amount2,
|
|
760
|
+
recipient,
|
|
761
|
+
new web3_js.PublicKey(sender.toUint8Array()),
|
|
762
|
+
outboxItem.publicKey,
|
|
763
|
+
new web3_js.PublicKey(sourceToken),
|
|
764
|
+
sdkConnect.toUniversal(recipient.chain, destinationToken).toUint8Array(),
|
|
765
|
+
options.queue
|
|
766
|
+
)
|
|
767
|
+
];
|
|
768
|
+
for (let ix = 0; ix < ntt.transceivers.length; ++ix) {
|
|
769
|
+
if (ix === 0) {
|
|
770
|
+
const whTransceiver = await ntt.getWormholeTransceiver();
|
|
771
|
+
if (!whTransceiver) {
|
|
772
|
+
throw new Error("wormhole transceiver not found");
|
|
773
|
+
}
|
|
774
|
+
const releaseIx = await whTransceiver.createReleaseWormholeOutboundIx(
|
|
775
|
+
payerAddress,
|
|
776
|
+
outboxItem.publicKey,
|
|
777
|
+
!options.queue
|
|
778
|
+
);
|
|
779
|
+
ixs.push(releaseIx);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
const tx = new web3_js.Transaction();
|
|
783
|
+
tx.feePayer = payerAddress;
|
|
784
|
+
tx.add(...ixs);
|
|
785
|
+
if (options.automatic) {
|
|
786
|
+
if (!ntt.quoter)
|
|
787
|
+
throw new Error(
|
|
788
|
+
"No quoter available, cannot initiate an automatic transfer."
|
|
789
|
+
);
|
|
790
|
+
const fee = await ntt.quoteDeliveryPrice(recipient.chain, options);
|
|
791
|
+
const relayIx = await ntt.quoter.createRequestRelayInstruction(
|
|
792
|
+
payerAddress,
|
|
793
|
+
outboxItem.publicKey,
|
|
794
|
+
recipient.chain,
|
|
795
|
+
Number(fee) / web3_js.LAMPORTS_PER_SOL,
|
|
796
|
+
Number(options.gasDropoff ?? 0n) / sdkSolanaNtt.WEI_PER_GWEI
|
|
797
|
+
);
|
|
798
|
+
tx.add(relayIx);
|
|
799
|
+
}
|
|
800
|
+
const luts = [];
|
|
801
|
+
try {
|
|
802
|
+
luts.push(await ntt.getAddressLookupTable());
|
|
803
|
+
luts.push(await router.getAddressLookupTableAccounts(ntt.connection));
|
|
804
|
+
} catch {
|
|
805
|
+
}
|
|
806
|
+
const messageV0 = new web3_js.TransactionMessage({
|
|
807
|
+
payerKey: payerAddress,
|
|
808
|
+
instructions: tx.instructions,
|
|
809
|
+
recentBlockhash: (await ntt.connection.getLatestBlockhash()).blockhash
|
|
810
|
+
}).compileToV0Message(luts);
|
|
811
|
+
const vtx = new web3_js.VersionedTransaction(messageV0);
|
|
812
|
+
yield ntt.createUnsignedTx(
|
|
813
|
+
{ transaction: vtx, signers: [outboxItem] },
|
|
814
|
+
"Ntt.Transfer"
|
|
815
|
+
);
|
|
816
|
+
}
|
|
237
817
|
async *track(receipt, timeout) {
|
|
238
818
|
const isEvmPlatform = (chain) => sdkConnect.chainToPlatform(chain) === "Evm";
|
|
239
819
|
if (sdkConnect.isSourceInitiated(receipt) || sdkConnect.isSourceFinalized(receipt)) {
|
|
@@ -276,7 +856,9 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
276
856
|
}
|
|
277
857
|
}
|
|
278
858
|
if (sdkConnect.isRedeemed(receipt)) {
|
|
279
|
-
const {
|
|
859
|
+
const {
|
|
860
|
+
attestation: { attestation: vaa }
|
|
861
|
+
} = receipt;
|
|
280
862
|
const payload = vaa.payloadName === "WormholeTransfer" ? vaa.payload : vaa.payload["payload"];
|
|
281
863
|
const isExecuted = isEvmPlatform(receipt.to) ? await ntt.manager.isMessageExecuted(
|
|
282
864
|
sdkDefinitionsNtt.Ntt.messageDigest(vaa.emitterChain, payload["nttManagerPayload"])
|
|
@@ -296,8 +878,6 @@ var _M0AutomaticRoute = class _M0AutomaticRoute extends sdkConnect.routes.Automa
|
|
|
296
878
|
_M0AutomaticRoute.NATIVE_GAS_DROPOFF_SUPPORTED = false;
|
|
297
879
|
// Wrapped M token address is the same on EVM chains
|
|
298
880
|
_M0AutomaticRoute.EVM_WRAPPED_M_TOKEN = "0x437cc33344a0B27A429f795ff6B469C72698B291";
|
|
299
|
-
_M0AutomaticRoute.SOLANA_MAINNET_M_TOKEN = "mzerokyEX9TNDoK4o2YZQBDmMzjokAeN6M2g2S3pLJo";
|
|
300
|
-
_M0AutomaticRoute.SOLANA_TESTNET_M_TOKEN = "mzeroZRGCah3j5xEWp2Nih3GDejSBbH1rbHoxDg8By6";
|
|
301
881
|
// Contract addresses are the same on all EVM chains
|
|
302
882
|
_M0AutomaticRoute.EVM_CONTRACTS = {
|
|
303
883
|
// M token address is the same on EVM chains
|
|
@@ -313,3 +893,4 @@ _M0AutomaticRoute.meta = { name: "M0AutomaticRoute", provider: "M0" };
|
|
|
313
893
|
var M0AutomaticRoute = _M0AutomaticRoute;
|
|
314
894
|
|
|
315
895
|
exports.M0AutomaticRoute = M0AutomaticRoute;
|
|
896
|
+
exports.SolanaRoutes = SolanaRoutes;
|