@fogo/sessions-sdk 0.1.7 → 0.1.9
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/cjs/connection.d.ts +12 -11
- package/cjs/connection.js +29 -26
- package/cjs/context.d.ts +4 -4
- package/cjs/context.js +4 -4
- package/cjs/crypto.js +1 -1
- package/cjs/index.d.ts +218 -2028
- package/cjs/index.js +115 -72
- package/cjs/instructions.js +9 -9
- package/esm/connection.d.ts +12 -11
- package/esm/connection.js +30 -27
- package/esm/context.d.ts +4 -4
- package/esm/context.js +4 -4
- package/esm/crypto.js +1 -1
- package/esm/index.d.ts +218 -2028
- package/esm/index.js +82 -72
- package/esm/instructions.js +9 -9
- package/package.json +41 -40
package/cjs/index.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -9,7 +42,7 @@ const sessions_idls_1 = require("@fogo/sessions-idls");
|
|
|
9
42
|
const mpl_token_metadata_1 = require("@metaplex-foundation/mpl-token-metadata");
|
|
10
43
|
const umi_1 = require("@metaplex-foundation/umi");
|
|
11
44
|
const umi_bundle_defaults_1 = require("@metaplex-foundation/umi-bundle-defaults");
|
|
12
|
-
const
|
|
45
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
13
46
|
const compat_1 = require("@solana/compat");
|
|
14
47
|
const kit_1 = require("@solana/kit");
|
|
15
48
|
const spl_token_1 = require("@solana/spl-token");
|
|
@@ -17,6 +50,7 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
17
50
|
const sdk_1 = require("@wormhole-foundation/sdk");
|
|
18
51
|
const solana_1 = __importDefault(require("@wormhole-foundation/sdk/solana"));
|
|
19
52
|
const sdk_base_1 = require("@wormhole-foundation/sdk-base");
|
|
53
|
+
const routes = __importStar(require("@wormhole-foundation/sdk-connect/routes"));
|
|
20
54
|
const sdk_route_ntt_1 = require("@wormhole-foundation/sdk-route-ntt");
|
|
21
55
|
const sdk_solana_core_1 = require("@wormhole-foundation/sdk-solana-core");
|
|
22
56
|
const sdk_solana_ntt_1 = require("@wormhole-foundation/sdk-solana-ntt");
|
|
@@ -29,6 +63,7 @@ const crypto_js_1 = require("./crypto.js");
|
|
|
29
63
|
const instructions_js_1 = require("./instructions.js");
|
|
30
64
|
const mints_js_1 = require("./mints.js");
|
|
31
65
|
const network_js_1 = require("./network.js");
|
|
66
|
+
(0, sdk_solana_ntt_1.register)();
|
|
32
67
|
var connection_js_2 = require("./connection.js");
|
|
33
68
|
Object.defineProperty(exports, "createSessionConnection", { enumerable: true, get: function () { return connection_js_2.createSessionConnection; } });
|
|
34
69
|
Object.defineProperty(exports, "TransactionResultType", { enumerable: true, get: function () { return connection_js_2.TransactionResultType; } });
|
|
@@ -83,9 +118,9 @@ const establishSession = async (options) => {
|
|
|
83
118
|
exports.establishSession = establishSession;
|
|
84
119
|
const sendSessionEstablishTransaction = async (options, sessionKey, instructions, sessionEstablishmentLookupTable) => {
|
|
85
120
|
const result = await options.context.sendTransaction(sessionKey, instructions, options.walletPublicKey, {
|
|
86
|
-
variation: "Session Establishment",
|
|
87
121
|
addressLookupTable: sessionEstablishmentLookupTable ??
|
|
88
122
|
SESSION_ESTABLISHMENT_LOOKUP_TABLE_ADDRESS[options.context.network],
|
|
123
|
+
variation: "Session Establishment",
|
|
89
124
|
});
|
|
90
125
|
switch (result.type) {
|
|
91
126
|
case connection_js_1.TransactionResultType.Success: {
|
|
@@ -109,8 +144,8 @@ const revokeSession = async (options) => {
|
|
|
109
144
|
const instruction = await new sessions_idls_1.SessionManagerProgram(new anchor_1.AnchorProvider(options.context.connection, {}, {})).methods
|
|
110
145
|
.revokeSession()
|
|
111
146
|
.accounts({
|
|
112
|
-
sponsor: options.session.sessionInfo.sponsor,
|
|
113
147
|
session: options.session.sessionPublicKey,
|
|
148
|
+
sponsor: options.session.sessionInfo.sponsor,
|
|
114
149
|
})
|
|
115
150
|
.instruction();
|
|
116
151
|
return options.context.sendTransaction(options.session.sessionKey, [instruction], options.session.walletPublicKey, {
|
|
@@ -163,17 +198,17 @@ const createSession = async (context, walletPublicKey, sessionKey) => {
|
|
|
163
198
|
!authorizedProgramsMatchDomainRegistry(sessionInfo.authorizedPrograms, domainRegistryAuthorizedPrograms)
|
|
164
199
|
? undefined
|
|
165
200
|
: {
|
|
166
|
-
sessionPublicKey,
|
|
167
|
-
walletPublicKey,
|
|
168
|
-
sessionKey,
|
|
169
|
-
payer: context.payer,
|
|
170
|
-
getSystemProgramSessionWrapInstruction: (amount) => (0, instructions_js_1.createSystemProgramSessionWrapInstruction)(sessionPublicKey, walletPublicKey, amount),
|
|
171
|
-
getSessionWrapInstructions: (amount) => (0, instructions_js_1.createSessionWrapInstructions)(sessionPublicKey, walletPublicKey, amount),
|
|
172
201
|
getSessionUnwrapInstructions: () => [
|
|
173
202
|
(0, instructions_js_1.createSessionUnwrapInstruction)(sessionPublicKey, walletPublicKey),
|
|
174
203
|
],
|
|
204
|
+
getSessionWrapInstructions: (amount) => (0, instructions_js_1.createSessionWrapInstructions)(sessionPublicKey, walletPublicKey, amount),
|
|
205
|
+
getSystemProgramSessionWrapInstruction: (amount) => (0, instructions_js_1.createSystemProgramSessionWrapInstruction)(sessionPublicKey, walletPublicKey, amount),
|
|
206
|
+
payer: context.payer,
|
|
175
207
|
sendTransaction: (instructions, extraConfig) => context.sendTransaction(sessionKey, instructions, walletPublicKey, extraConfig),
|
|
176
208
|
sessionInfo,
|
|
209
|
+
sessionKey,
|
|
210
|
+
sessionPublicKey,
|
|
211
|
+
walletPublicKey,
|
|
177
212
|
};
|
|
178
213
|
};
|
|
179
214
|
const authorizedTokensSchema = zod_1.z.union([
|
|
@@ -185,9 +220,9 @@ const authorizedTokensSchema = zod_1.z.union([
|
|
|
185
220
|
zod_1.z.object({ All: zod_1.z.object({}) }),
|
|
186
221
|
]);
|
|
187
222
|
const revokedSessionInfoSchema = zod_1.z.object({
|
|
188
|
-
user: zod_1.z.instanceof(web3_js_1.PublicKey),
|
|
189
|
-
expiration: zod_1.z.instanceof(bn_js_1.default),
|
|
190
223
|
authorized_tokens_with_mints: authorizedTokensSchema,
|
|
224
|
+
expiration: zod_1.z.instanceof(bn_js_1.default),
|
|
225
|
+
user: zod_1.z.instanceof(web3_js_1.PublicKey),
|
|
191
226
|
});
|
|
192
227
|
const activeSessionInfoSchema = zod_1.z.object({
|
|
193
228
|
authorized_programs: zod_1.z.union([
|
|
@@ -219,6 +254,7 @@ const activeSessionInfoSchema = zod_1.z.object({
|
|
|
219
254
|
});
|
|
220
255
|
const sessionInfoSchema = zod_1.z
|
|
221
256
|
.object({
|
|
257
|
+
major: zod_1.z.number(),
|
|
222
258
|
session_info: zod_1.z.union([
|
|
223
259
|
zod_1.z.object({
|
|
224
260
|
V1: zod_1.z.object({
|
|
@@ -312,8 +348,8 @@ const sessionInfoSchema = zod_1.z
|
|
|
312
348
|
zod_1.z.object({
|
|
313
349
|
Active: zod_1.z.object({
|
|
314
350
|
"0": zod_1.z.object({
|
|
315
|
-
domain_hash: zod_1.z.array(zod_1.z.number()).length(32),
|
|
316
351
|
active_session_info: activeSessionInfoSchema,
|
|
352
|
+
domain_hash: zod_1.z.array(zod_1.z.number()).length(32),
|
|
317
353
|
}),
|
|
318
354
|
}),
|
|
319
355
|
}),
|
|
@@ -321,7 +357,6 @@ const sessionInfoSchema = zod_1.z
|
|
|
321
357
|
}),
|
|
322
358
|
}),
|
|
323
359
|
]),
|
|
324
|
-
major: zod_1.z.number(),
|
|
325
360
|
sponsor: zod_1.z.instanceof(web3_js_1.PublicKey),
|
|
326
361
|
})
|
|
327
362
|
.transform(({ session_info, major, sponsor }) => {
|
|
@@ -360,8 +395,8 @@ const sessionInfoSchema = zod_1.z
|
|
|
360
395
|
extra: activeSessionInfo.extra[0],
|
|
361
396
|
major: major,
|
|
362
397
|
minor: minor,
|
|
363
|
-
user: activeSessionInfo.user,
|
|
364
398
|
sponsor,
|
|
399
|
+
user: activeSessionInfo.user,
|
|
365
400
|
};
|
|
366
401
|
});
|
|
367
402
|
var AuthorizedProgramsType;
|
|
@@ -372,8 +407,8 @@ var AuthorizedProgramsType;
|
|
|
372
407
|
const AuthorizedPrograms = {
|
|
373
408
|
All: () => ({ type: AuthorizedProgramsType.All }),
|
|
374
409
|
Specific: (programs) => ({
|
|
375
|
-
type: AuthorizedProgramsType.Specific,
|
|
376
410
|
programs,
|
|
411
|
+
type: AuthorizedProgramsType.Specific,
|
|
377
412
|
}),
|
|
378
413
|
};
|
|
379
414
|
var AuthorizedTokens;
|
|
@@ -387,13 +422,13 @@ var SymbolOrMintType;
|
|
|
387
422
|
SymbolOrMintType[SymbolOrMintType["Mint"] = 1] = "Mint";
|
|
388
423
|
})(SymbolOrMintType || (SymbolOrMintType = {}));
|
|
389
424
|
const SymbolOrMint = {
|
|
390
|
-
Symbol: (symbol) => ({
|
|
391
|
-
type: SymbolOrMintType.Symbol,
|
|
392
|
-
symbol,
|
|
393
|
-
}),
|
|
394
425
|
Mint: (mint) => ({
|
|
395
|
-
type: SymbolOrMintType.Mint,
|
|
396
426
|
mint,
|
|
427
|
+
type: SymbolOrMintType.Mint,
|
|
428
|
+
}),
|
|
429
|
+
Symbol: (symbol) => ({
|
|
430
|
+
symbol,
|
|
431
|
+
type: SymbolOrMintType.Symbol,
|
|
397
432
|
}),
|
|
398
433
|
};
|
|
399
434
|
const getTokenInfo = (context, limits) => {
|
|
@@ -406,17 +441,19 @@ const getTokenInfo = (context, limits) => {
|
|
|
406
441
|
(0, mpl_token_metadata_1.safeFetchMetadata)(umi, metadataAddress),
|
|
407
442
|
]);
|
|
408
443
|
return {
|
|
444
|
+
amount,
|
|
445
|
+
decimals: mintInfo.decimals,
|
|
446
|
+
metadataAddress: new web3_js_1.PublicKey(metadataAddress),
|
|
447
|
+
mint,
|
|
409
448
|
symbolOrMint: metadata?.symbol
|
|
410
449
|
? SymbolOrMint.Symbol(metadata.symbol)
|
|
411
450
|
: SymbolOrMint.Mint(mint),
|
|
412
|
-
metadataAddress: new web3_js_1.PublicKey(metadataAddress),
|
|
413
|
-
amount,
|
|
414
|
-
mint,
|
|
415
|
-
decimals: mintInfo.decimals,
|
|
416
451
|
};
|
|
417
452
|
}));
|
|
418
453
|
};
|
|
419
|
-
const buildStartSessionIntentInstruction = async (options, sessionKey, tokens) => buildIntentInstruction(options, MESSAGE_HEADER,
|
|
454
|
+
const buildStartSessionIntentInstruction = async (options, sessionKey, tokens) => buildIntentInstruction(options, MESSAGE_HEADER,
|
|
455
|
+
// biome-ignore assist/source/useSortedKeys: The sort order is important here
|
|
456
|
+
{
|
|
420
457
|
version: `${CURRENT_MAJOR}.${CURRENT_MINOR}`,
|
|
421
458
|
chain_id: options.context.chainId,
|
|
422
459
|
domain: options.context.domain,
|
|
@@ -428,9 +465,9 @@ const buildIntentInstruction = async (options, header, body, extra) => {
|
|
|
428
465
|
const message = new TextEncoder().encode([header, serializeKV(body), extra && serializeExtra(extra)].join("\n"));
|
|
429
466
|
const { signature, signedMessage } = await options.signMessage(message);
|
|
430
467
|
return web3_js_1.Ed25519Program.createInstructionWithPublicKey({
|
|
468
|
+
message: signedMessage,
|
|
431
469
|
publicKey: options.walletPublicKey.toBytes(),
|
|
432
470
|
signature,
|
|
433
|
-
message: signedMessage,
|
|
434
471
|
});
|
|
435
472
|
};
|
|
436
473
|
const serializeExtra = (extra) => {
|
|
@@ -474,7 +511,7 @@ const amountToString = (amount, decimals) => {
|
|
|
474
511
|
].join("");
|
|
475
512
|
};
|
|
476
513
|
const getDomainRecordAddress = (domain) => {
|
|
477
|
-
const hash = (0,
|
|
514
|
+
const hash = (0, sha2_js_1.sha256)(new TextEncoder().encode(domain));
|
|
478
515
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("domain-record"), hash], new web3_js_1.PublicKey(sessions_idls_1.DomainRegistryIdl.address))[0];
|
|
479
516
|
};
|
|
480
517
|
exports.getDomainRecordAddress = getDomainRecordAddress;
|
|
@@ -492,30 +529,30 @@ const buildStartSessionInstruction = async (options, sessionKey, tokens) => {
|
|
|
492
529
|
const instruction = new sessions_idls_1.SessionManagerProgram(new anchor_1.AnchorProvider(options.context.connection, {}, {})).methods
|
|
493
530
|
.startSession()
|
|
494
531
|
.accounts({
|
|
495
|
-
sponsor: options.context.payer,
|
|
496
|
-
session: await (0, kit_1.getAddressFromPublicKey)(sessionKey.publicKey),
|
|
497
532
|
domainRegistry: (0, exports.getDomainRecordAddress)(options.context.domain),
|
|
533
|
+
session: await (0, kit_1.getAddressFromPublicKey)(sessionKey.publicKey),
|
|
534
|
+
sponsor: options.context.payer,
|
|
498
535
|
});
|
|
499
536
|
return tokens === undefined
|
|
500
537
|
? instruction.instruction()
|
|
501
538
|
: instruction
|
|
502
539
|
.remainingAccounts(tokens.flatMap(({ symbolOrMint, mint, metadataAddress }) => [
|
|
503
540
|
{
|
|
504
|
-
pubkey: (0, spl_token_1.getAssociatedTokenAddressSync)(mint, options.walletPublicKey),
|
|
505
|
-
isWritable: true,
|
|
506
541
|
isSigner: false,
|
|
542
|
+
isWritable: true,
|
|
543
|
+
pubkey: (0, spl_token_1.getAssociatedTokenAddressSync)(mint, options.walletPublicKey),
|
|
507
544
|
},
|
|
508
545
|
{
|
|
509
|
-
pubkey: mint,
|
|
510
|
-
isWritable: false,
|
|
511
546
|
isSigner: false,
|
|
547
|
+
isWritable: false,
|
|
548
|
+
pubkey: mint,
|
|
512
549
|
},
|
|
513
550
|
...(symbolOrMint.type === SymbolOrMintType.Symbol
|
|
514
551
|
? [
|
|
515
552
|
{
|
|
516
|
-
pubkey: metadataAddress,
|
|
517
|
-
isWritable: false,
|
|
518
553
|
isSigner: false,
|
|
554
|
+
isWritable: false,
|
|
555
|
+
pubkey: metadataAddress,
|
|
519
556
|
},
|
|
520
557
|
]
|
|
521
558
|
: []),
|
|
@@ -528,15 +565,15 @@ var SessionResultType;
|
|
|
528
565
|
SessionResultType[SessionResultType["Failed"] = 1] = "Failed";
|
|
529
566
|
})(SessionResultType || (exports.SessionResultType = SessionResultType = {}));
|
|
530
567
|
const EstablishSessionResult = {
|
|
531
|
-
Success: (signature, session) => ({
|
|
532
|
-
type: SessionResultType.Success,
|
|
533
|
-
signature,
|
|
534
|
-
session,
|
|
535
|
-
}),
|
|
536
568
|
Failed: (signature, error) => ({
|
|
569
|
+
error,
|
|
570
|
+
signature,
|
|
537
571
|
type: SessionResultType.Failed,
|
|
572
|
+
}),
|
|
573
|
+
Success: (signature, session) => ({
|
|
574
|
+
session,
|
|
538
575
|
signature,
|
|
539
|
-
|
|
576
|
+
type: SessionResultType.Success,
|
|
540
577
|
}),
|
|
541
578
|
};
|
|
542
579
|
const getTransferFee = async (context) => {
|
|
@@ -563,16 +600,16 @@ const getFee = async (context) => {
|
|
|
563
600
|
const [feeConfigPda] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("fee_config"), usdcMint.toBytes()], program.programId);
|
|
564
601
|
const feeConfig = await program.account.feeConfig.fetch(feeConfigPda);
|
|
565
602
|
return {
|
|
603
|
+
decimals: mints_js_1.USDC_DECIMALS,
|
|
604
|
+
fee: {
|
|
605
|
+
bridgeTransfer: BigInt(feeConfig.bridgeTransferFee.toString()),
|
|
606
|
+
intrachainTransfer: BigInt(feeConfig.intrachainTransferFee.toString()),
|
|
607
|
+
},
|
|
566
608
|
metadata: (0, mpl_token_metadata_1.findMetadataPda)(umi, {
|
|
567
609
|
mint: (0, umi_1.publicKey)(usdcMintAddress),
|
|
568
610
|
})[0],
|
|
569
611
|
mint: usdcMint,
|
|
570
612
|
symbolOrMint: "USDC.s",
|
|
571
|
-
decimals: mints_js_1.USDC_DECIMALS,
|
|
572
|
-
fee: {
|
|
573
|
-
intrachainTransfer: BigInt(feeConfig.intrachainTransferFee.toString()),
|
|
574
|
-
bridgeTransfer: BigInt(feeConfig.bridgeTransferFee.toString()),
|
|
575
|
-
},
|
|
576
613
|
};
|
|
577
614
|
};
|
|
578
615
|
const TRANSFER_MESSAGE_HEADER = `Fogo Transfer:
|
|
@@ -595,17 +632,17 @@ const sendTransfer = async (options) => {
|
|
|
595
632
|
feeMetadata: options.feeConfig.metadata,
|
|
596
633
|
feeMint: options.feeConfig.mint,
|
|
597
634
|
feeSource: (0, spl_token_1.getAssociatedTokenAddressSync)(options.feeConfig.mint, options.walletPublicKey),
|
|
598
|
-
mint: options.mint,
|
|
599
|
-
source: sourceAta,
|
|
600
|
-
sponsor: options.context.internalPayer,
|
|
601
635
|
metadata:
|
|
602
636
|
// eslint-disable-next-line unicorn/no-null
|
|
603
637
|
symbol === undefined ? null : new web3_js_1.PublicKey(metadataAddress),
|
|
638
|
+
mint: options.mint,
|
|
639
|
+
source: sourceAta,
|
|
640
|
+
sponsor: options.context.internalPayer,
|
|
604
641
|
})
|
|
605
642
|
.instruction(),
|
|
606
643
|
], options.walletPublicKey, {
|
|
607
|
-
variation: "Intent Transfer",
|
|
608
644
|
paymasterDomain: context_js_1.SESSIONS_INTERNAL_PAYMASTER_DOMAIN,
|
|
645
|
+
variation: "Intent Transfer",
|
|
609
646
|
});
|
|
610
647
|
};
|
|
611
648
|
exports.sendTransfer = sendTransfer;
|
|
@@ -614,7 +651,9 @@ const buildTransferIntentInstruction = async (program, options, symbol, feeToken
|
|
|
614
651
|
getNonce(program, options.walletPublicKey, NonceType.Transfer),
|
|
615
652
|
(0, spl_token_1.getMint)(options.context.connection, options.mint),
|
|
616
653
|
]);
|
|
617
|
-
return buildIntentInstruction(options, TRANSFER_MESSAGE_HEADER,
|
|
654
|
+
return buildIntentInstruction(options, TRANSFER_MESSAGE_HEADER,
|
|
655
|
+
// biome-ignore assist/source/useSortedKeys: The sort order is important here
|
|
656
|
+
{
|
|
618
657
|
version: `${CURRENT_INTENT_TRANSFER_MAJOR}.${CURRENT_INTENT_TRANSFER_MINOR}`,
|
|
619
658
|
chain_id: options.context.chainId,
|
|
620
659
|
token: symbol ?? options.mint.toBase58(),
|
|
@@ -632,25 +671,27 @@ const sendNativeTransfer = async (options) => {
|
|
|
632
671
|
await program.methods
|
|
633
672
|
.sendNative()
|
|
634
673
|
.accounts({
|
|
674
|
+
destination: options.recipient,
|
|
675
|
+
feeDestination: sessions_idls_1.IntentTransferIdl.address,
|
|
635
676
|
feeMetadata: options.feeConfig.metadata,
|
|
636
677
|
feeMint: options.feeConfig.mint,
|
|
637
678
|
feeSource: (0, spl_token_1.getAssociatedTokenAddressSync)(options.feeConfig.mint, options.walletPublicKey),
|
|
638
|
-
feeDestination: sessions_idls_1.IntentTransferIdl.address,
|
|
639
679
|
source: options.walletPublicKey,
|
|
640
|
-
destination: options.recipient,
|
|
641
680
|
sponsor: options.context.internalPayer,
|
|
642
681
|
})
|
|
643
682
|
.instruction(),
|
|
644
683
|
], options.walletPublicKey, {
|
|
645
|
-
variation: "Intent Transfer",
|
|
646
684
|
paymasterDomain: context_js_1.SESSIONS_INTERNAL_PAYMASTER_DOMAIN,
|
|
685
|
+
variation: "Intent Transfer",
|
|
647
686
|
});
|
|
648
687
|
};
|
|
649
688
|
exports.sendNativeTransfer = sendNativeTransfer;
|
|
650
689
|
const FOGO_DECIMALS = 9;
|
|
651
690
|
const buildNativeTransferIntentInstruction = async (program, options, feeToken, feeAmount) => {
|
|
652
691
|
const nonce = await getNonce(program, options.walletPublicKey, NonceType.Transfer);
|
|
653
|
-
return buildIntentInstruction(options, TRANSFER_MESSAGE_HEADER,
|
|
692
|
+
return buildIntentInstruction(options, TRANSFER_MESSAGE_HEADER,
|
|
693
|
+
// biome-ignore assist/source/useSortedKeys: The sort order is important here
|
|
694
|
+
{
|
|
654
695
|
version: `${CURRENT_INTENT_TRANSFER_MAJOR}.${CURRENT_INTENT_TRANSFER_MINOR}`,
|
|
655
696
|
chain_id: options.context.chainId,
|
|
656
697
|
token: "FOGO",
|
|
@@ -688,17 +729,17 @@ const bridgeOut = async (options) => {
|
|
|
688
729
|
signedQuoteBytes: [...quote.signedQuote],
|
|
689
730
|
})
|
|
690
731
|
.accounts({
|
|
691
|
-
|
|
692
|
-
|
|
732
|
+
feeMetadata: options.feeConfig.metadata,
|
|
733
|
+
feeMint: options.feeConfig.mint,
|
|
734
|
+
feeSource: (0, spl_token_1.getAssociatedTokenAddressSync)(options.feeConfig.mint, options.walletPublicKey),
|
|
693
735
|
metadata: metadata?.symbol === undefined
|
|
694
736
|
? // eslint-disable-next-line unicorn/no-null
|
|
695
737
|
null
|
|
696
738
|
: new web3_js_1.PublicKey(metadataAddress),
|
|
697
|
-
|
|
739
|
+
mint: options.fromToken.mint,
|
|
698
740
|
ntt: nttPdas,
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
feeSource: (0, spl_token_1.getAssociatedTokenAddressSync)(options.feeConfig.mint, options.walletPublicKey),
|
|
741
|
+
source: (0, spl_token_1.getAssociatedTokenAddressSync)(options.fromToken.mint, options.walletPublicKey),
|
|
742
|
+
sponsor: options.context.internalPayer,
|
|
702
743
|
})
|
|
703
744
|
.instruction(),
|
|
704
745
|
]);
|
|
@@ -706,10 +747,10 @@ const bridgeOut = async (options) => {
|
|
|
706
747
|
web3_js_1.ComputeBudgetProgram.setComputeUnitLimit({ units: BRIDGE_OUT_CUS }),
|
|
707
748
|
...instructions,
|
|
708
749
|
], options.walletPublicKey, {
|
|
709
|
-
variation: "Intent NTT Bridge",
|
|
710
|
-
paymasterDomain: context_js_1.SESSIONS_INTERNAL_PAYMASTER_DOMAIN,
|
|
711
|
-
extraSigners: [outboxItem],
|
|
712
750
|
addressLookupTable: BRIDGING_ADDRESS_LOOKUP_TABLE[options.context.network]?.[options.fromToken.mint.toBase58()],
|
|
751
|
+
extraSigners: [outboxItem],
|
|
752
|
+
paymasterDomain: context_js_1.SESSIONS_INTERNAL_PAYMASTER_DOMAIN,
|
|
753
|
+
variation: "Intent NTT Bridge",
|
|
713
754
|
});
|
|
714
755
|
};
|
|
715
756
|
exports.bridgeOut = bridgeOut;
|
|
@@ -752,16 +793,18 @@ const getNttPdas = async (options, wh, program, outboxItemPublicKey, quotePayeeA
|
|
|
752
793
|
nttTokenAuthority: pdas.tokenAuthority(),
|
|
753
794
|
payeeNttWithExecutor: quotePayeeAddress,
|
|
754
795
|
transceiver: registeredTransceiverPda,
|
|
755
|
-
wormholeProgram: coreBridgeContract,
|
|
756
796
|
wormholeBridge: wormholePdas.wormholeBridge,
|
|
757
797
|
wormholeFeeCollector: wormholePdas.wormholeFeeCollector,
|
|
758
798
|
wormholeMessage: transceiverPdas.wormholeMessageAccount(outboxItemPublicKey),
|
|
799
|
+
wormholeProgram: coreBridgeContract,
|
|
759
800
|
wormholeSequence: wormholePdas.wormholeSequence,
|
|
760
801
|
};
|
|
761
802
|
};
|
|
762
803
|
const buildBridgeOutIntent = async (program, options, decimals, symbol, feeToken, feeAmount) => {
|
|
763
804
|
const nonce = await getNonce(program, options.walletPublicKey, NonceType.Bridge);
|
|
764
|
-
return buildIntentInstruction(options, BRIDGE_OUT_MESSAGE_HEADER,
|
|
805
|
+
return buildIntentInstruction(options, BRIDGE_OUT_MESSAGE_HEADER,
|
|
806
|
+
// biome-ignore assist/source/useSortedKeys: The sort order is important here
|
|
807
|
+
{
|
|
765
808
|
version: `${CURRENT_BRIDGE_OUT_MAJOR}.${CURRENT_BRIDGE_OUT_MINOR}`,
|
|
766
809
|
from_chain_id: options.context.chainId,
|
|
767
810
|
to_chain_id: "solana",
|
|
@@ -780,7 +823,7 @@ const bridgeIn = async (options) => {
|
|
|
780
823
|
// properly represent the runtime representation.
|
|
781
824
|
const quote = await route.quote(transferRequest, transferParams);
|
|
782
825
|
if (quote.success) {
|
|
783
|
-
return await
|
|
826
|
+
return await routes.checkAndCompleteTransfer(route, await route.initiate(transferRequest, {
|
|
784
827
|
address: () => options.walletPublicKey.toBase58(),
|
|
785
828
|
chain: () => "Solana",
|
|
786
829
|
sign: (transactions) => Promise.all(transactions.map(async ({ transaction }) => {
|
|
@@ -839,10 +882,10 @@ const buildWormholeTransfer = async (options, connection) => {
|
|
|
839
882
|
},
|
|
840
883
|
});
|
|
841
884
|
const route = new Route(wh);
|
|
842
|
-
const transferRequest = await
|
|
885
|
+
const transferRequest = await routes.RouteTransferRequest.create(wh, {
|
|
886
|
+
destination: sdk_1.Wormhole.tokenId(options.toToken.chain, options.toToken.mint.toBase58()),
|
|
843
887
|
recipient: sdk_1.Wormhole.chainAddress(options.toToken.chain, options.walletPublicKey.toBase58()),
|
|
844
888
|
source: sdk_1.Wormhole.tokenId(options.fromToken.chain, options.fromToken.mint.toBase58()),
|
|
845
|
-
destination: sdk_1.Wormhole.tokenId(options.toToken.chain, options.toToken.mint.toBase58()),
|
|
846
889
|
});
|
|
847
890
|
const validated = await route.validate(transferRequest, {
|
|
848
891
|
amount: amountToString(options.amount, decimals),
|
|
@@ -850,11 +893,11 @@ const buildWormholeTransfer = async (options, connection) => {
|
|
|
850
893
|
});
|
|
851
894
|
if (validated.valid) {
|
|
852
895
|
return {
|
|
853
|
-
|
|
896
|
+
decimals,
|
|
854
897
|
route,
|
|
855
|
-
transferRequest,
|
|
856
898
|
transferParams: validated.params,
|
|
857
|
-
|
|
899
|
+
transferRequest,
|
|
900
|
+
wh,
|
|
858
901
|
};
|
|
859
902
|
}
|
|
860
903
|
else {
|
package/cjs/instructions.js
CHANGED
|
@@ -6,7 +6,7 @@ exports.createSessionWrapInstructions = createSessionWrapInstructions;
|
|
|
6
6
|
exports.createSessionUnwrapInstruction = createSessionUnwrapInstruction;
|
|
7
7
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
8
8
|
const sessions_idls_1 = require("@fogo/sessions-idls");
|
|
9
|
-
const
|
|
9
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
10
10
|
const spl_token_1 = require("@solana/spl-token");
|
|
11
11
|
const web3_js_1 = require("@solana/web3.js");
|
|
12
12
|
const SESSION_WRAP_DISCRIMINATOR = 4_000_000;
|
|
@@ -23,17 +23,17 @@ function createSystemProgramSessionWrapInstruction(sessionKey, walletPublicKey,
|
|
|
23
23
|
view.setUint32(0, SESSION_WRAP_DISCRIMINATOR, true);
|
|
24
24
|
view.setBigUint64(4, amount, true);
|
|
25
25
|
return new web3_js_1.TransactionInstruction({
|
|
26
|
-
|
|
26
|
+
data: Buffer.from(data),
|
|
27
27
|
keys: [
|
|
28
|
-
{
|
|
28
|
+
{ isSigner: false, isWritable: true, pubkey: walletPublicKey },
|
|
29
29
|
{
|
|
30
|
-
pubkey: getNativeMintAssociatedTokenAddressSync(walletPublicKey),
|
|
31
30
|
isSigner: false,
|
|
32
31
|
isWritable: true,
|
|
32
|
+
pubkey: getNativeMintAssociatedTokenAddressSync(walletPublicKey),
|
|
33
33
|
},
|
|
34
|
-
{
|
|
34
|
+
{ isSigner: true, isWritable: false, pubkey: sessionKey },
|
|
35
35
|
],
|
|
36
|
-
|
|
36
|
+
programId: web3_js_1.SystemProgram.programId,
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
@@ -59,7 +59,7 @@ function createSessionUnwrapInstruction(sessionKey, walletPublicKey) {
|
|
|
59
59
|
return (0, spl_token_1.createCloseAccountInstruction)(getNativeMintAssociatedTokenAddressSync(walletPublicKey), walletPublicKey, sessionKey);
|
|
60
60
|
}
|
|
61
61
|
const getDomainTollRecipientAddress = (domain) => {
|
|
62
|
-
const hash = (0,
|
|
62
|
+
const hash = (0, sha2_js_1.sha256)(new TextEncoder().encode(domain));
|
|
63
63
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from("toll_recipient"), Buffer.from([0]), hash], new web3_js_1.PublicKey(sessions_idls_1.TollboothIdl.address))[0];
|
|
64
64
|
};
|
|
65
65
|
/**
|
|
@@ -72,10 +72,10 @@ const createPaymasterFeeInstruction = ({ sessionKey, walletPublicKey, domain, fe
|
|
|
72
72
|
return new sessions_idls_1.TollboothProgram(new anchor_1.AnchorProvider({}, {})).methods
|
|
73
73
|
.payToll(feeAmount, 0)
|
|
74
74
|
.accounts({
|
|
75
|
-
session: sessionKey,
|
|
76
|
-
source: (0, spl_token_1.getAssociatedTokenAddressSync)(feeMint, walletPublicKey),
|
|
77
75
|
destination: (0, spl_token_1.getAssociatedTokenAddressSync)(feeMint, recipient, true),
|
|
78
76
|
mint: feeMint,
|
|
77
|
+
session: sessionKey,
|
|
78
|
+
source: (0, spl_token_1.getAssociatedTokenAddressSync)(feeMint, walletPublicKey),
|
|
79
79
|
})
|
|
80
80
|
.instruction();
|
|
81
81
|
};
|
package/esm/connection.d.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import type { GetLatestBlockhashApi, Instruction, Rpc, Transaction, TransactionWithLifetime } from "@solana/kit";
|
|
2
|
-
import type { TransactionError } from "@solana/web3.js";
|
|
3
|
-
import { Keypair, PublicKey,
|
|
1
|
+
import type { Address, GetLatestBlockhashApi, Instruction, Rpc, Transaction, TransactionWithLifetime } from "@solana/kit";
|
|
2
|
+
import type { TransactionError, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
+
import { Keypair, PublicKey, VersionedTransaction, Connection as Web3Connection } from "@solana/web3.js";
|
|
4
4
|
import { Network } from "./network.js";
|
|
5
5
|
export declare enum TransactionResultType {
|
|
6
6
|
Success = 0,
|
|
7
7
|
Failed = 1
|
|
8
8
|
}
|
|
9
9
|
declare const TransactionResult: {
|
|
10
|
-
Success: (signature: string) => {
|
|
11
|
-
type: TransactionResultType.Success;
|
|
12
|
-
signature: string;
|
|
13
|
-
};
|
|
14
10
|
Failed: (signature: string, error: TransactionError) => {
|
|
11
|
+
error: TransactionError;
|
|
12
|
+
signature: string;
|
|
15
13
|
type: TransactionResultType.Failed;
|
|
14
|
+
};
|
|
15
|
+
Success: (signature: string) => {
|
|
16
16
|
signature: string;
|
|
17
|
-
|
|
17
|
+
type: TransactionResultType.Success;
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
export type TransactionResult = ReturnType<(typeof TransactionResult)[keyof typeof TransactionResult]>;
|
|
@@ -30,18 +30,19 @@ export declare const createSessionConnection: (options: {
|
|
|
30
30
|
sendToPaymaster: (transaction: Transaction) => Promise<TransactionResult>;
|
|
31
31
|
sponsor: PublicKey;
|
|
32
32
|
})) => {
|
|
33
|
-
rpc: Rpc<import("@solana/kit").RequestAirdropApi & import("@solana/kit").GetAccountInfoApi & import("@solana/kit").GetBalanceApi & import("@solana/kit").GetBlockApi & import("@solana/kit").GetBlockCommitmentApi & import("@solana/kit").GetBlockHeightApi & import("@solana/kit").GetBlockProductionApi & import("@solana/kit").GetBlocksApi & import("@solana/kit").GetBlocksWithLimitApi & import("@solana/kit").GetBlockTimeApi & import("@solana/kit").GetClusterNodesApi & import("@solana/kit").GetEpochInfoApi & import("@solana/kit").GetEpochScheduleApi & import("@solana/kit").GetFeeForMessageApi & import("@solana/kit").GetFirstAvailableBlockApi & import("@solana/kit").GetGenesisHashApi & import("@solana/kit").GetHealthApi & import("@solana/kit").GetHighestSnapshotSlotApi & import("@solana/kit").GetIdentityApi & import("@solana/kit").GetInflationGovernorApi & import("@solana/kit").GetInflationRateApi & import("@solana/kit").GetInflationRewardApi & import("@solana/kit").GetLargestAccountsApi & GetLatestBlockhashApi & import("@solana/kit").GetLeaderScheduleApi & import("@solana/kit").GetMaxRetransmitSlotApi & import("@solana/kit").GetMaxShredInsertSlotApi & import("@solana/kit").GetMinimumBalanceForRentExemptionApi & import("@solana/kit").GetMultipleAccountsApi & import("@solana/kit").GetProgramAccountsApi & import("@solana/kit").GetRecentPerformanceSamplesApi & import("@solana/kit").GetRecentPrioritizationFeesApi & import("@solana/kit").GetSignaturesForAddressApi & import("@solana/kit").GetSignatureStatusesApi & import("@solana/kit").GetSlotApi & import("@solana/kit").GetSlotLeaderApi & import("@solana/kit").GetSlotLeadersApi & import("@solana/kit").GetStakeMinimumDelegationApi & import("@solana/kit").GetSupplyApi & import("@solana/kit").GetTokenAccountBalanceApi & import("@solana/kit").GetTokenAccountsByDelegateApi & import("@solana/kit").GetTokenAccountsByOwnerApi & import("@solana/kit").GetTokenLargestAccountsApi & import("@solana/kit").GetTokenSupplyApi & import("@solana/kit").GetTransactionApi & import("@solana/kit").GetTransactionCountApi & import("@solana/kit").GetVersionApi & import("@solana/kit").GetVoteAccountsApi & import("@solana/kit").IsBlockhashValidApi & import("@solana/kit").MinimumLedgerSlotApi & import("@solana/kit").SendTransactionApi & import("@solana/kit").SimulateTransactionApi>;
|
|
34
33
|
connection: Web3Connection;
|
|
35
|
-
network: Network;
|
|
36
34
|
getSolanaConnection: () => Promise<Web3Connection>;
|
|
37
|
-
sendToPaymaster: (domain: string, sessionKey: CryptoKeyPair | undefined, instructions: TransactionOrInstructions, walletPublicKey: PublicKey, extraConfig?: SendTransactionOptions) => Promise<TransactionResult>;
|
|
38
35
|
getSponsor: (domain: string) => Promise<PublicKey>;
|
|
36
|
+
network: Network;
|
|
37
|
+
rpc: Rpc<import("@solana/kit").RequestAirdropApi & import("@solana/kit").GetAccountInfoApi & import("@solana/kit").GetBalanceApi & import("@solana/kit").GetBlockApi & import("@solana/kit").GetBlockCommitmentApi & import("@solana/kit").GetBlockHeightApi & import("@solana/kit").GetBlockProductionApi & import("@solana/kit").GetBlocksApi & import("@solana/kit").GetBlocksWithLimitApi & import("@solana/kit").GetBlockTimeApi & import("@solana/kit").GetClusterNodesApi & import("@solana/kit").GetEpochInfoApi & import("@solana/kit").GetEpochScheduleApi & import("@solana/kit").GetFeeForMessageApi & import("@solana/kit").GetFirstAvailableBlockApi & import("@solana/kit").GetGenesisHashApi & import("@solana/kit").GetHealthApi & import("@solana/kit").GetHighestSnapshotSlotApi & import("@solana/kit").GetIdentityApi & import("@solana/kit").GetInflationGovernorApi & import("@solana/kit").GetInflationRateApi & import("@solana/kit").GetInflationRewardApi & import("@solana/kit").GetLargestAccountsApi & GetLatestBlockhashApi & import("@solana/kit").GetLeaderScheduleApi & import("@solana/kit").GetMaxRetransmitSlotApi & import("@solana/kit").GetMaxShredInsertSlotApi & import("@solana/kit").GetMinimumBalanceForRentExemptionApi & import("@solana/kit").GetMultipleAccountsApi & import("@solana/kit").GetProgramAccountsApi & import("@solana/kit").GetRecentPerformanceSamplesApi & import("@solana/kit").GetRecentPrioritizationFeesApi & import("@solana/kit").GetSignaturesForAddressApi & import("@solana/kit").GetSignatureStatusesApi & import("@solana/kit").GetSlotApi & import("@solana/kit").GetSlotLeaderApi & import("@solana/kit").GetSlotLeadersApi & import("@solana/kit").GetStakeMinimumDelegationApi & import("@solana/kit").GetSupplyApi & import("@solana/kit").GetTokenAccountBalanceApi & import("@solana/kit").GetTokenAccountsByDelegateApi & import("@solana/kit").GetTokenAccountsByOwnerApi & import("@solana/kit").GetTokenLargestAccountsApi & import("@solana/kit").GetTokenSupplyApi & import("@solana/kit").GetTransactionApi & import("@solana/kit").GetTransactionCountApi & import("@solana/kit").GetVersionApi & import("@solana/kit").GetVoteAccountsApi & import("@solana/kit").IsBlockhashValidApi & import("@solana/kit").MinimumLedgerSlotApi & import("@solana/kit").SendTransactionApi & import("@solana/kit").SimulateTransactionApi>;
|
|
38
|
+
sendToPaymaster: (domain: string, sessionKey: CryptoKeyPair | undefined, instructions: TransactionOrInstructions, walletPublicKey: PublicKey, extraConfig?: SendTransactionOptions) => Promise<TransactionResult>;
|
|
39
39
|
};
|
|
40
40
|
export type TransactionOrInstructions = (TransactionInstruction | Instruction)[] | VersionedTransaction | (Transaction & TransactionWithLifetime);
|
|
41
41
|
export type SendTransactionOptions = {
|
|
42
42
|
variation?: string | undefined;
|
|
43
43
|
addressLookupTable?: string | undefined;
|
|
44
44
|
extraSigners?: (CryptoKeyPair | Keypair)[] | undefined;
|
|
45
|
+
feeMint?: PublicKey | Address;
|
|
45
46
|
};
|
|
46
47
|
export type Connection = ReturnType<typeof createSessionConnection>;
|
|
47
48
|
export {};
|