@triadxyz/poseidons-protocol 0.4.6 → 0.4.8
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/game/chest.d.ts +12 -0
- package/dist/game/chest.js +24 -0
- package/dist/types/idl_poseidons_protocol.json +155 -0
- package/dist/types/poseidons_protocol.d.ts +213 -0
- package/package.json +1 -1
- package/dist/utils/getTokenBalance.d.ts +0 -3
- package/dist/utils/getTokenBalance.js +0 -47
- package/dist/utils/swap.d.ts +0 -16
- package/dist/utils/swap.js +0 -108
package/dist/game/chest.d.ts
CHANGED
|
@@ -60,4 +60,16 @@ export default class Chest {
|
|
|
60
60
|
amount: number;
|
|
61
61
|
}[];
|
|
62
62
|
}): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
63
|
+
/**
|
|
64
|
+
* Add a wheel ticket
|
|
65
|
+
* @param id - The id of the wheel
|
|
66
|
+
* @param tickets - The tickets to add
|
|
67
|
+
* @param isUsdc - Whether to use USDC or SOL
|
|
68
|
+
* @returns The transaction signature or versioned transaction
|
|
69
|
+
*/
|
|
70
|
+
addWheelTicket({ wheelId, tickets, isUsdc }: {
|
|
71
|
+
wheelId: number;
|
|
72
|
+
tickets: number;
|
|
73
|
+
isUsdc: boolean;
|
|
74
|
+
}): Promise<string | import("@solana/web3.js").VersionedTransaction>;
|
|
63
75
|
}
|
package/dist/game/chest.js
CHANGED
|
@@ -133,5 +133,29 @@ class Chest {
|
|
|
133
133
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
134
134
|
});
|
|
135
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Add a wheel ticket
|
|
138
|
+
* @param id - The id of the wheel
|
|
139
|
+
* @param tickets - The tickets to add
|
|
140
|
+
* @param isUsdc - Whether to use USDC or SOL
|
|
141
|
+
* @returns The transaction signature or versioned transaction
|
|
142
|
+
*/
|
|
143
|
+
addWheelTicket({ wheelId, tickets, isUsdc }) {
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
const ixs = [
|
|
146
|
+
yield this.program.methods
|
|
147
|
+
.addWheelTicket({
|
|
148
|
+
tickets: new anchor_1.BN(tickets),
|
|
149
|
+
isUsdc
|
|
150
|
+
})
|
|
151
|
+
.accounts({
|
|
152
|
+
signer: this.program.provider.publicKey,
|
|
153
|
+
wheel: (0, pda_1.getWheelPDA)(wheelId)
|
|
154
|
+
})
|
|
155
|
+
.instruction()
|
|
156
|
+
];
|
|
157
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, this.rpcOptions);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
136
160
|
}
|
|
137
161
|
exports.default = Chest;
|
|
@@ -404,6 +404,113 @@
|
|
|
404
404
|
}
|
|
405
405
|
]
|
|
406
406
|
},
|
|
407
|
+
{
|
|
408
|
+
"name": "add_wheel_ticket",
|
|
409
|
+
"discriminator": [193, 237, 240, 196, 109, 121, 105, 63],
|
|
410
|
+
"accounts": [
|
|
411
|
+
{
|
|
412
|
+
"name": "signer",
|
|
413
|
+
"writable": true,
|
|
414
|
+
"signer": true
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
"name": "wheel",
|
|
418
|
+
"writable": true
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
"name": "squads",
|
|
422
|
+
"writable": true,
|
|
423
|
+
"address": "Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4"
|
|
424
|
+
},
|
|
425
|
+
{
|
|
426
|
+
"name": "user",
|
|
427
|
+
"writable": true
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
"name": "mint",
|
|
431
|
+
"writable": true,
|
|
432
|
+
"address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
|
|
433
|
+
},
|
|
434
|
+
{
|
|
435
|
+
"name": "user_ata",
|
|
436
|
+
"writable": true,
|
|
437
|
+
"pda": {
|
|
438
|
+
"seeds": [
|
|
439
|
+
{
|
|
440
|
+
"kind": "account",
|
|
441
|
+
"path": "signer"
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
"kind": "account",
|
|
445
|
+
"path": "token_program"
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
"kind": "account",
|
|
449
|
+
"path": "mint"
|
|
450
|
+
}
|
|
451
|
+
],
|
|
452
|
+
"program": {
|
|
453
|
+
"kind": "const",
|
|
454
|
+
"value": [
|
|
455
|
+
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
|
|
456
|
+
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
|
|
457
|
+
219, 233, 248, 89
|
|
458
|
+
]
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
},
|
|
462
|
+
{
|
|
463
|
+
"name": "squads_ata",
|
|
464
|
+
"writable": true,
|
|
465
|
+
"pda": {
|
|
466
|
+
"seeds": [
|
|
467
|
+
{
|
|
468
|
+
"kind": "account",
|
|
469
|
+
"path": "squads"
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
"kind": "account",
|
|
473
|
+
"path": "token_program"
|
|
474
|
+
},
|
|
475
|
+
{
|
|
476
|
+
"kind": "account",
|
|
477
|
+
"path": "mint"
|
|
478
|
+
}
|
|
479
|
+
],
|
|
480
|
+
"program": {
|
|
481
|
+
"kind": "const",
|
|
482
|
+
"value": [
|
|
483
|
+
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
|
|
484
|
+
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
|
|
485
|
+
219, 233, 248, 89
|
|
486
|
+
]
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
{
|
|
491
|
+
"name": "token_program",
|
|
492
|
+
"address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
|
|
493
|
+
},
|
|
494
|
+
{
|
|
495
|
+
"name": "associated_token_program",
|
|
496
|
+
"address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
"name": "system_program",
|
|
500
|
+
"address": "11111111111111111111111111111111"
|
|
501
|
+
}
|
|
502
|
+
],
|
|
503
|
+
"args": [
|
|
504
|
+
{
|
|
505
|
+
"name": "args",
|
|
506
|
+
"type": {
|
|
507
|
+
"defined": {
|
|
508
|
+
"name": "AddWheelTicketArgs"
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
]
|
|
513
|
+
},
|
|
407
514
|
{
|
|
408
515
|
"name": "burn_nft",
|
|
409
516
|
"discriminator": [119, 13, 183, 17, 194, 243, 38, 31],
|
|
@@ -1050,6 +1157,10 @@
|
|
|
1050
1157
|
}
|
|
1051
1158
|
],
|
|
1052
1159
|
"events": [
|
|
1160
|
+
{
|
|
1161
|
+
"name": "AddWheelTicketEvent",
|
|
1162
|
+
"discriminator": [119, 181, 93, 250, 118, 155, 193, 130]
|
|
1163
|
+
},
|
|
1053
1164
|
{
|
|
1054
1165
|
"name": "BidChestEvent",
|
|
1055
1166
|
"discriminator": [162, 64, 11, 176, 231, 173, 217, 89]
|
|
@@ -1217,6 +1328,50 @@
|
|
|
1217
1328
|
]
|
|
1218
1329
|
}
|
|
1219
1330
|
},
|
|
1331
|
+
{
|
|
1332
|
+
"name": "AddWheelTicketArgs",
|
|
1333
|
+
"type": {
|
|
1334
|
+
"kind": "struct",
|
|
1335
|
+
"fields": [
|
|
1336
|
+
{
|
|
1337
|
+
"name": "is_usdc",
|
|
1338
|
+
"type": "bool"
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
"name": "tickets",
|
|
1342
|
+
"type": "u64"
|
|
1343
|
+
}
|
|
1344
|
+
]
|
|
1345
|
+
}
|
|
1346
|
+
},
|
|
1347
|
+
{
|
|
1348
|
+
"name": "AddWheelTicketEvent",
|
|
1349
|
+
"type": {
|
|
1350
|
+
"kind": "struct",
|
|
1351
|
+
"fields": [
|
|
1352
|
+
{
|
|
1353
|
+
"name": "authority",
|
|
1354
|
+
"type": "pubkey"
|
|
1355
|
+
},
|
|
1356
|
+
{
|
|
1357
|
+
"name": "wheel_id",
|
|
1358
|
+
"type": "u8"
|
|
1359
|
+
},
|
|
1360
|
+
{
|
|
1361
|
+
"name": "tickets",
|
|
1362
|
+
"type": "u64"
|
|
1363
|
+
},
|
|
1364
|
+
{
|
|
1365
|
+
"name": "fee",
|
|
1366
|
+
"type": "u64"
|
|
1367
|
+
},
|
|
1368
|
+
{
|
|
1369
|
+
"name": "timestamp",
|
|
1370
|
+
"type": "i64"
|
|
1371
|
+
}
|
|
1372
|
+
]
|
|
1373
|
+
}
|
|
1374
|
+
},
|
|
1220
1375
|
{
|
|
1221
1376
|
"name": "BaseAssetV1",
|
|
1222
1377
|
"type": {
|
|
@@ -567,6 +567,171 @@ export type PoseidonsProtocol = {
|
|
|
567
567
|
}
|
|
568
568
|
];
|
|
569
569
|
},
|
|
570
|
+
{
|
|
571
|
+
name: 'addWheelTicket';
|
|
572
|
+
discriminator: [193, 237, 240, 196, 109, 121, 105, 63];
|
|
573
|
+
accounts: [
|
|
574
|
+
{
|
|
575
|
+
name: 'signer';
|
|
576
|
+
writable: true;
|
|
577
|
+
signer: true;
|
|
578
|
+
},
|
|
579
|
+
{
|
|
580
|
+
name: 'wheel';
|
|
581
|
+
writable: true;
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
name: 'squads';
|
|
585
|
+
writable: true;
|
|
586
|
+
address: 'Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4';
|
|
587
|
+
},
|
|
588
|
+
{
|
|
589
|
+
name: 'user';
|
|
590
|
+
writable: true;
|
|
591
|
+
},
|
|
592
|
+
{
|
|
593
|
+
name: 'mint';
|
|
594
|
+
writable: true;
|
|
595
|
+
address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
|
|
596
|
+
},
|
|
597
|
+
{
|
|
598
|
+
name: 'userAta';
|
|
599
|
+
writable: true;
|
|
600
|
+
pda: {
|
|
601
|
+
seeds: [
|
|
602
|
+
{
|
|
603
|
+
kind: 'account';
|
|
604
|
+
path: 'signer';
|
|
605
|
+
},
|
|
606
|
+
{
|
|
607
|
+
kind: 'account';
|
|
608
|
+
path: 'tokenProgram';
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
kind: 'account';
|
|
612
|
+
path: 'mint';
|
|
613
|
+
}
|
|
614
|
+
];
|
|
615
|
+
program: {
|
|
616
|
+
kind: 'const';
|
|
617
|
+
value: [
|
|
618
|
+
140,
|
|
619
|
+
151,
|
|
620
|
+
37,
|
|
621
|
+
143,
|
|
622
|
+
78,
|
|
623
|
+
36,
|
|
624
|
+
137,
|
|
625
|
+
241,
|
|
626
|
+
187,
|
|
627
|
+
61,
|
|
628
|
+
16,
|
|
629
|
+
41,
|
|
630
|
+
20,
|
|
631
|
+
142,
|
|
632
|
+
13,
|
|
633
|
+
131,
|
|
634
|
+
11,
|
|
635
|
+
90,
|
|
636
|
+
19,
|
|
637
|
+
153,
|
|
638
|
+
218,
|
|
639
|
+
255,
|
|
640
|
+
16,
|
|
641
|
+
132,
|
|
642
|
+
4,
|
|
643
|
+
142,
|
|
644
|
+
123,
|
|
645
|
+
216,
|
|
646
|
+
219,
|
|
647
|
+
233,
|
|
648
|
+
248,
|
|
649
|
+
89
|
|
650
|
+
];
|
|
651
|
+
};
|
|
652
|
+
};
|
|
653
|
+
},
|
|
654
|
+
{
|
|
655
|
+
name: 'squadsAta';
|
|
656
|
+
writable: true;
|
|
657
|
+
pda: {
|
|
658
|
+
seeds: [
|
|
659
|
+
{
|
|
660
|
+
kind: 'account';
|
|
661
|
+
path: 'squads';
|
|
662
|
+
},
|
|
663
|
+
{
|
|
664
|
+
kind: 'account';
|
|
665
|
+
path: 'tokenProgram';
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
kind: 'account';
|
|
669
|
+
path: 'mint';
|
|
670
|
+
}
|
|
671
|
+
];
|
|
672
|
+
program: {
|
|
673
|
+
kind: 'const';
|
|
674
|
+
value: [
|
|
675
|
+
140,
|
|
676
|
+
151,
|
|
677
|
+
37,
|
|
678
|
+
143,
|
|
679
|
+
78,
|
|
680
|
+
36,
|
|
681
|
+
137,
|
|
682
|
+
241,
|
|
683
|
+
187,
|
|
684
|
+
61,
|
|
685
|
+
16,
|
|
686
|
+
41,
|
|
687
|
+
20,
|
|
688
|
+
142,
|
|
689
|
+
13,
|
|
690
|
+
131,
|
|
691
|
+
11,
|
|
692
|
+
90,
|
|
693
|
+
19,
|
|
694
|
+
153,
|
|
695
|
+
218,
|
|
696
|
+
255,
|
|
697
|
+
16,
|
|
698
|
+
132,
|
|
699
|
+
4,
|
|
700
|
+
142,
|
|
701
|
+
123,
|
|
702
|
+
216,
|
|
703
|
+
219,
|
|
704
|
+
233,
|
|
705
|
+
248,
|
|
706
|
+
89
|
|
707
|
+
];
|
|
708
|
+
};
|
|
709
|
+
};
|
|
710
|
+
},
|
|
711
|
+
{
|
|
712
|
+
name: 'tokenProgram';
|
|
713
|
+
address: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
name: 'associatedTokenProgram';
|
|
717
|
+
address: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
name: 'systemProgram';
|
|
721
|
+
address: '11111111111111111111111111111111';
|
|
722
|
+
}
|
|
723
|
+
];
|
|
724
|
+
args: [
|
|
725
|
+
{
|
|
726
|
+
name: 'args';
|
|
727
|
+
type: {
|
|
728
|
+
defined: {
|
|
729
|
+
name: 'addWheelTicketArgs';
|
|
730
|
+
};
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
];
|
|
734
|
+
},
|
|
570
735
|
{
|
|
571
736
|
name: 'burnNft';
|
|
572
737
|
discriminator: [119, 13, 183, 17, 194, 243, 38, 31];
|
|
@@ -1399,6 +1564,10 @@ export type PoseidonsProtocol = {
|
|
|
1399
1564
|
}
|
|
1400
1565
|
];
|
|
1401
1566
|
events: [
|
|
1567
|
+
{
|
|
1568
|
+
name: 'addWheelTicketEvent';
|
|
1569
|
+
discriminator: [119, 181, 93, 250, 118, 155, 193, 130];
|
|
1570
|
+
},
|
|
1402
1571
|
{
|
|
1403
1572
|
name: 'bidChestEvent';
|
|
1404
1573
|
discriminator: [162, 64, 11, 176, 231, 173, 217, 89];
|
|
@@ -1566,6 +1735,50 @@ export type PoseidonsProtocol = {
|
|
|
1566
1735
|
];
|
|
1567
1736
|
};
|
|
1568
1737
|
},
|
|
1738
|
+
{
|
|
1739
|
+
name: 'addWheelTicketArgs';
|
|
1740
|
+
type: {
|
|
1741
|
+
kind: 'struct';
|
|
1742
|
+
fields: [
|
|
1743
|
+
{
|
|
1744
|
+
name: 'isUsdc';
|
|
1745
|
+
type: 'bool';
|
|
1746
|
+
},
|
|
1747
|
+
{
|
|
1748
|
+
name: 'tickets';
|
|
1749
|
+
type: 'u64';
|
|
1750
|
+
}
|
|
1751
|
+
];
|
|
1752
|
+
};
|
|
1753
|
+
},
|
|
1754
|
+
{
|
|
1755
|
+
name: 'addWheelTicketEvent';
|
|
1756
|
+
type: {
|
|
1757
|
+
kind: 'struct';
|
|
1758
|
+
fields: [
|
|
1759
|
+
{
|
|
1760
|
+
name: 'authority';
|
|
1761
|
+
type: 'pubkey';
|
|
1762
|
+
},
|
|
1763
|
+
{
|
|
1764
|
+
name: 'wheelId';
|
|
1765
|
+
type: 'u8';
|
|
1766
|
+
},
|
|
1767
|
+
{
|
|
1768
|
+
name: 'tickets';
|
|
1769
|
+
type: 'u64';
|
|
1770
|
+
},
|
|
1771
|
+
{
|
|
1772
|
+
name: 'fee';
|
|
1773
|
+
type: 'u64';
|
|
1774
|
+
},
|
|
1775
|
+
{
|
|
1776
|
+
name: 'timestamp';
|
|
1777
|
+
type: 'i64';
|
|
1778
|
+
}
|
|
1779
|
+
];
|
|
1780
|
+
};
|
|
1781
|
+
},
|
|
1569
1782
|
{
|
|
1570
1783
|
name: 'baseAssetV1';
|
|
1571
1784
|
type: {
|
package/package.json
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { Connection } from '@solana/web3.js';
|
|
2
|
-
export declare function getTokenBalance(tokenAddress: string, wallet: string, connection: Connection): Promise<number>;
|
|
3
|
-
export declare function getBalanceSol(wallet: string, connection: Connection): Promise<number | undefined>;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getBalanceSol = exports.getTokenBalance = void 0;
|
|
13
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
14
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
15
|
-
const formatBigNumber = (number, decimals = 6) => Number(number.toString()) / Math.pow(10, decimals);
|
|
16
|
-
function getTokenBalance(tokenAddress, wallet, connection) {
|
|
17
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
-
if (!wallet)
|
|
19
|
-
return 0;
|
|
20
|
-
try {
|
|
21
|
-
const token = yield (0, spl_token_1.getAssociatedTokenAddress)(new web3_js_1.PublicKey(tokenAddress), new web3_js_1.PublicKey(wallet));
|
|
22
|
-
const mint = yield (0, spl_token_1.getMint)(connection, new web3_js_1.PublicKey(tokenAddress));
|
|
23
|
-
const account = yield (0, spl_token_1.getAccount)(connection, token);
|
|
24
|
-
const formattedAmount = formatBigNumber(account.amount, mint.decimals);
|
|
25
|
-
return formattedAmount;
|
|
26
|
-
}
|
|
27
|
-
catch (error) {
|
|
28
|
-
return 0;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
exports.getTokenBalance = getTokenBalance;
|
|
33
|
-
function getBalanceSol(wallet, connection) {
|
|
34
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
35
|
-
if (!wallet)
|
|
36
|
-
return;
|
|
37
|
-
try {
|
|
38
|
-
const balanceSol = yield connection.getBalance(new web3_js_1.PublicKey(wallet));
|
|
39
|
-
const amountInSol = balanceSol / web3_js_1.LAMPORTS_PER_SOL;
|
|
40
|
-
return amountInSol;
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
/* empty */
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
exports.getBalanceSol = getBalanceSol;
|
package/dist/utils/swap.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { AddressLookupTableAccount, Connection, TransactionInstruction } from '@solana/web3.js';
|
|
2
|
-
export declare const swap: ({ connection, wallet, inToken, outToken, amount, payer }: {
|
|
3
|
-
connection: Connection;
|
|
4
|
-
wallet: string;
|
|
5
|
-
inToken: string;
|
|
6
|
-
outToken: string;
|
|
7
|
-
amount: number;
|
|
8
|
-
payer: string;
|
|
9
|
-
}) => Promise<{
|
|
10
|
-
swapIxs: TransactionInstruction[];
|
|
11
|
-
closeAccountIxs: TransactionInstruction[];
|
|
12
|
-
addressLookupTableAccounts: AddressLookupTableAccount[];
|
|
13
|
-
setupInstructions: any[];
|
|
14
|
-
outAmount: any;
|
|
15
|
-
}>;
|
|
16
|
-
export declare const getPrice: (token: string) => Promise<any>;
|
package/dist/utils/swap.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.getPrice = exports.swap = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
18
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
19
|
-
const pda_1 = require("./pda");
|
|
20
|
-
const constants_1 = require("./constants");
|
|
21
|
-
const swap = ({ connection, wallet, inToken, outToken, amount, payer }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
try {
|
|
23
|
-
const token = TOKENS[inToken];
|
|
24
|
-
if (!token) {
|
|
25
|
-
throw new Error('Token not found');
|
|
26
|
-
}
|
|
27
|
-
const formattedAmountIn = Math.round(amount * Math.pow(10, token.decimals));
|
|
28
|
-
const quoteResponse = yield axios_1.default.get(`https://lite-api.jup.ag/swap/v1/quote?inputMint=${inToken}&outputMint=${outToken}&amount=${formattedAmountIn}&slippageBps=20&onlyDirectRoutes=true&platformFeeBps=60`);
|
|
29
|
-
const { data: quoteData } = quoteResponse;
|
|
30
|
-
const swapResponse = yield axios_1.default.post('https://lite-api.jup.ag/swap/v1/swap-instructions', {
|
|
31
|
-
quoteResponse: quoteData,
|
|
32
|
-
userPublicKey: wallet,
|
|
33
|
-
payer,
|
|
34
|
-
feeAccount: inToken === constants_1.USDC_MINT.toString() ? getFeeAccount() : undefined,
|
|
35
|
-
wrapAndUnwrapSol: false
|
|
36
|
-
});
|
|
37
|
-
const { setupInstructions, swapInstruction, addressLookupTableAddresses } = swapResponse.data;
|
|
38
|
-
const swapIxs = [
|
|
39
|
-
deserializeInstruction(swapInstruction)
|
|
40
|
-
];
|
|
41
|
-
const closeAccountIxs = [];
|
|
42
|
-
if (outToken === constants_1.SOL_MINT.toString()) {
|
|
43
|
-
const wsolATA = (0, pda_1.getTokenATA)(new web3_js_1.PublicKey(wallet), constants_1.SOL_MINT, spl_token_1.TOKEN_PROGRAM_ID);
|
|
44
|
-
closeAccountIxs.push((0, spl_token_1.createCloseAccountInstruction)(wsolATA, new web3_js_1.PublicKey(wallet), new web3_js_1.PublicKey(wallet), [], spl_token_1.TOKEN_PROGRAM_ID));
|
|
45
|
-
}
|
|
46
|
-
return {
|
|
47
|
-
swapIxs,
|
|
48
|
-
closeAccountIxs,
|
|
49
|
-
addressLookupTableAccounts: yield getAddressLookupTableAccounts(connection, addressLookupTableAddresses),
|
|
50
|
-
setupInstructions: setupInstructions.length > 0
|
|
51
|
-
? [...setupInstructions.map(deserializeInstruction)]
|
|
52
|
-
: [],
|
|
53
|
-
outAmount: quoteData.otherAmountThreshold
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
throw error;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
exports.swap = swap;
|
|
61
|
-
const getPrice = (token) => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
-
var _a, _b;
|
|
63
|
-
const response = yield axios_1.default.get(`https://lite-api.jup.ag/price/v3?ids=${token}`);
|
|
64
|
-
return (_b = (_a = response.data[token]) === null || _a === void 0 ? void 0 : _a.usdPrice) !== null && _b !== void 0 ? _b : 0;
|
|
65
|
-
});
|
|
66
|
-
exports.getPrice = getPrice;
|
|
67
|
-
const deserializeInstruction = (instruction) => {
|
|
68
|
-
return new web3_js_1.TransactionInstruction({
|
|
69
|
-
programId: new web3_js_1.PublicKey(instruction.programId),
|
|
70
|
-
keys: instruction.accounts.map((key) => ({
|
|
71
|
-
pubkey: new web3_js_1.PublicKey(key.pubkey),
|
|
72
|
-
isSigner: key.isSigner,
|
|
73
|
-
isWritable: key.isWritable
|
|
74
|
-
})),
|
|
75
|
-
data: Buffer.from(instruction.data, 'base64')
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
const getAddressLookupTableAccounts = (connection, keys) => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
-
const addressLookupTableAccountInfos = yield connection.getMultipleAccountsInfo(keys.map((key) => new web3_js_1.PublicKey(key)));
|
|
80
|
-
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
|
|
81
|
-
const addressLookupTableAddress = keys[index];
|
|
82
|
-
if (accountInfo) {
|
|
83
|
-
const addressLookupTableAccount = new web3_js_1.AddressLookupTableAccount({
|
|
84
|
-
key: new web3_js_1.PublicKey(addressLookupTableAddress),
|
|
85
|
-
state: web3_js_1.AddressLookupTableAccount.deserialize(new Uint8Array(accountInfo.data))
|
|
86
|
-
});
|
|
87
|
-
acc.push(addressLookupTableAccount);
|
|
88
|
-
}
|
|
89
|
-
return acc;
|
|
90
|
-
}, new Array());
|
|
91
|
-
});
|
|
92
|
-
const TOKENS = {
|
|
93
|
-
So11111111111111111111111111111111111111112: {
|
|
94
|
-
mint: 'So11111111111111111111111111111111111111112',
|
|
95
|
-
decimals: 9
|
|
96
|
-
},
|
|
97
|
-
EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v: {
|
|
98
|
-
mint: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',
|
|
99
|
-
decimals: 6
|
|
100
|
-
},
|
|
101
|
-
t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV: {
|
|
102
|
-
mint: 't3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV',
|
|
103
|
-
decimals: 6
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
const getFeeAccount = () => {
|
|
107
|
-
return (0, pda_1.getTokenATA)(new web3_js_1.PublicKey('Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4'), constants_1.USDC_MINT, spl_token_1.TOKEN_PROGRAM_ID);
|
|
108
|
-
};
|