@triadxyz/triad-protocol 1.1.4-beta → 1.1.6-beta

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.
@@ -17,10 +17,7 @@ const _1 = __importDefault(require("./"));
17
17
  const anchor_1 = require("@coral-xyz/anchor");
18
18
  const axios_1 = __importDefault(require("axios"));
19
19
  const web3_js_1 = require("@solana/web3.js");
20
- const spl_token_1 = require("@solana/spl-token");
21
- const constants_1 = require("./utils/constants");
22
- const pda_1 = require("./utils/pda");
23
- const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/triad.json');
20
+ const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
24
21
  const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
25
22
  const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
26
23
  const connection = new web3_js_1.Connection(rpc_file.toString(), 'confirmed');
@@ -45,6 +42,10 @@ const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
45
42
  });
46
43
  console.log(response);
47
44
  });
45
+ const getStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
46
+ const response = yield triadProtocol.stake.getStakeVaults();
47
+ console.log(response);
48
+ });
48
49
  const updateStakeVaultStatus = () => __awaiter(void 0, void 0, void 0, function* () {
49
50
  const response = yield triadProtocol.stake.updateStakeVault({
50
51
  wallet: wallet.publicKey,
@@ -53,6 +54,7 @@ const updateStakeVaultStatus = () => __awaiter(void 0, void 0, void 0, function*
53
54
  });
54
55
  console.log(response);
55
56
  });
57
+ updateStakeVaultStatus();
56
58
  const updateBoost = () => __awaiter(void 0, void 0, void 0, function* () {
57
59
  const response = (yield axios_1.default.get('https://api.triadfi.co/boost'))
58
60
  .data;
@@ -77,7 +79,6 @@ const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
77
79
  const markets = yield triadProtocol.trade.getAllMarkets();
78
80
  console.log(markets);
79
81
  });
80
- getAllMarkets();
81
82
  const getMarket = () => __awaiter(void 0, void 0, void 0, function* () {
82
83
  const market = yield triadProtocol.trade.getMarketById(1);
83
84
  console.log(market);
@@ -176,20 +177,3 @@ const getTickers = () => __awaiter(void 0, void 0, void 0, function* () {
176
177
  const response = yield triadProtocol.getTickers();
177
178
  console.log(response);
178
179
  });
179
- // Claim 3 TRD
180
- const claim3Trd = (user) => __awaiter(void 0, void 0, void 0, function* () {
181
- const adminATA = (0, pda_1.getTokenATA)(keypair.publicKey, constants_1.TRD_MINT);
182
- const userATA = (0, pda_1.getTokenATA)(user, constants_1.TRD_MINT);
183
- const ixs = [
184
- (0, spl_token_1.createAssociatedTokenAccountIdempotentInstruction)(user, userATA, user, constants_1.TRD_MINT, spl_token_1.TOKEN_2022_PROGRAM_ID),
185
- (0, spl_token_1.createTransferCheckedInstruction)(adminATA, constants_1.TRD_MINT, userATA, keypair.publicKey, 3 * Math.pow(10, 6), constants_1.TRD_DECIMALS, [], spl_token_1.TOKEN_2022_PROGRAM_ID)
186
- ];
187
- const tx = new web3_js_1.Transaction().add(...ixs);
188
- tx.recentBlockhash = (yield connection.getLatestBlockhash()).blockhash;
189
- tx.feePayer = user;
190
- tx.sign(keypair);
191
- // add wallet as signer FE
192
- const signature = yield connection.sendRawTransaction(tx.serialize());
193
- console.log(signature);
194
- });
195
- claim3Trd(new web3_js_1.PublicKey('FbegLWayrXB7pEhtNXqzLQ8KWcWALpfwetf65oBodAsc'));
package/dist/stake.js CHANGED
@@ -244,6 +244,9 @@ class Stake {
244
244
  const stakes = (yield this.getUserStakes(wallet)).sort((a, b) => a.claimedTs - b.claimedTs);
245
245
  const ixs = [];
246
246
  for (const stake of stakes) {
247
+ if (stake.withdrawTs !== 0) {
248
+ continue;
249
+ }
247
250
  const rank = (0, getRarityRank_1.default)(ranks, stake.mint, stake.name);
248
251
  if (ixs.length >= 10) {
249
252
  break;
package/dist/trade.d.ts CHANGED
@@ -44,18 +44,38 @@ export default class Trade {
44
44
  status: ({
45
45
  open?: never;
46
46
  closed?: never;
47
+ claimed?: never;
48
+ liquidated?: never;
47
49
  } & {
48
50
  init: Record<string, never>;
49
51
  }) | ({
50
52
  init?: never;
51
53
  closed?: never;
54
+ claimed?: never;
55
+ liquidated?: never;
52
56
  } & {
53
57
  open: Record<string, never>;
54
58
  }) | ({
55
59
  init?: never;
56
60
  open?: never;
61
+ claimed?: never;
62
+ liquidated?: never;
57
63
  } & {
58
64
  closed: Record<string, never>;
65
+ }) | ({
66
+ init?: never;
67
+ open?: never;
68
+ closed?: never;
69
+ liquidated?: never;
70
+ } & {
71
+ claimed: Record<string, never>;
72
+ }) | ({
73
+ init?: never;
74
+ open?: never;
75
+ closed?: never;
76
+ claimed?: never;
77
+ } & {
78
+ liquidated: Record<string, never>;
59
79
  });
60
80
  price: BN;
61
81
  totalAmount: BN;
@@ -136,4 +156,16 @@ export default class Trade {
136
156
  *
137
157
  */
138
158
  resolveQuestion(marketId: number, options?: RpcOptions): Promise<string>;
159
+ /**
160
+ * Settle an order
161
+ * @param marketId - The ID of the market
162
+ * @param orderId - The ID of the order to settle
163
+ *
164
+ * @param options - RPC options
165
+ *
166
+ */
167
+ settleOrder({ marketId, orderId }: {
168
+ marketId: number;
169
+ orderId: number;
170
+ }, options?: RpcOptions): Promise<string>;
139
171
  }
package/dist/trade.js CHANGED
@@ -200,5 +200,25 @@ class Trade {
200
200
  return (0, sendTransactionWithOptions_1.default)(method, options);
201
201
  });
202
202
  }
203
+ /**
204
+ * Settle an order
205
+ * @param marketId - The ID of the market
206
+ * @param orderId - The ID of the order to settle
207
+ *
208
+ * @param options - RPC options
209
+ *
210
+ */
211
+ settleOrder({ marketId, orderId }, options) {
212
+ return __awaiter(this, void 0, void 0, function* () {
213
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
214
+ const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
215
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods.settleOrder(new bn_js_1.default(orderId)).accounts({
216
+ signer: this.provider.publicKey,
217
+ userTrade: userTradePDA,
218
+ market: marketPDA,
219
+ mint: this.mint
220
+ }), options);
221
+ });
222
+ }
203
223
  }
204
224
  exports.default = Trade;
@@ -599,6 +599,103 @@
599
599
  ],
600
600
  "args": []
601
601
  },
602
+ {
603
+ "name": "settle_order",
604
+ "discriminator": [80, 74, 204, 34, 12, 183, 66, 66],
605
+ "accounts": [
606
+ {
607
+ "name": "signer",
608
+ "writable": true,
609
+ "signer": true
610
+ },
611
+ {
612
+ "name": "user_trade",
613
+ "writable": true
614
+ },
615
+ {
616
+ "name": "market",
617
+ "writable": true
618
+ },
619
+ {
620
+ "name": "mint",
621
+ "writable": true
622
+ },
623
+ {
624
+ "name": "user_ata",
625
+ "writable": true,
626
+ "pda": {
627
+ "seeds": [
628
+ {
629
+ "kind": "account",
630
+ "path": "signer"
631
+ },
632
+ {
633
+ "kind": "account",
634
+ "path": "token_program"
635
+ },
636
+ {
637
+ "kind": "account",
638
+ "path": "mint"
639
+ }
640
+ ],
641
+ "program": {
642
+ "kind": "const",
643
+ "value": [
644
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
645
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
646
+ 219, 233, 248, 89
647
+ ]
648
+ }
649
+ }
650
+ },
651
+ {
652
+ "name": "market_vault",
653
+ "writable": true,
654
+ "pda": {
655
+ "seeds": [
656
+ {
657
+ "kind": "account",
658
+ "path": "market"
659
+ },
660
+ {
661
+ "kind": "account",
662
+ "path": "token_program"
663
+ },
664
+ {
665
+ "kind": "account",
666
+ "path": "mint"
667
+ }
668
+ ],
669
+ "program": {
670
+ "kind": "const",
671
+ "value": [
672
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
673
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
674
+ 219, 233, 248, 89
675
+ ]
676
+ }
677
+ }
678
+ },
679
+ {
680
+ "name": "token_program",
681
+ "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
682
+ },
683
+ {
684
+ "name": "associated_token_program",
685
+ "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
686
+ },
687
+ {
688
+ "name": "system_program",
689
+ "address": "11111111111111111111111111111111"
690
+ }
691
+ ],
692
+ "args": [
693
+ {
694
+ "name": "order_id",
695
+ "type": "u64"
696
+ }
697
+ ]
698
+ },
602
699
  {
603
700
  "name": "stake_nft",
604
701
  "discriminator": [38, 27, 66, 46, 69, 65, 151, 219],
@@ -1119,6 +1216,10 @@
1119
1216
  "name": "user_token_account",
1120
1217
  "writable": true
1121
1218
  },
1219
+ {
1220
+ "name": "associated_token_program",
1221
+ "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
1222
+ },
1122
1223
  {
1123
1224
  "name": "system_program",
1124
1225
  "address": "11111111111111111111111111111111"
@@ -1392,6 +1493,11 @@
1392
1493
  "code": 6039,
1393
1494
  "name": "StakeVaultLocked",
1394
1495
  "msg": "Stake vault is locked"
1496
+ },
1497
+ {
1498
+ "code": 6040,
1499
+ "name": "MarketStillActive",
1500
+ "msg": "Market still active"
1395
1501
  }
1396
1502
  ],
1397
1503
  "types": [
@@ -1794,6 +1900,12 @@
1794
1900
  },
1795
1901
  {
1796
1902
  "name": "Closed"
1903
+ },
1904
+ {
1905
+ "name": "Claimed"
1906
+ },
1907
+ {
1908
+ "name": "Liquidated"
1797
1909
  }
1798
1910
  ]
1799
1911
  }
@@ -808,6 +808,161 @@ export type TriadProtocol = {
808
808
  ];
809
809
  args: [];
810
810
  },
811
+ {
812
+ name: 'settleOrder';
813
+ discriminator: [80, 74, 204, 34, 12, 183, 66, 66];
814
+ accounts: [
815
+ {
816
+ name: 'signer';
817
+ writable: true;
818
+ signer: true;
819
+ },
820
+ {
821
+ name: 'userTrade';
822
+ writable: true;
823
+ },
824
+ {
825
+ name: 'market';
826
+ writable: true;
827
+ },
828
+ {
829
+ name: 'mint';
830
+ writable: true;
831
+ },
832
+ {
833
+ name: 'userAta';
834
+ writable: true;
835
+ pda: {
836
+ seeds: [
837
+ {
838
+ kind: 'account';
839
+ path: 'signer';
840
+ },
841
+ {
842
+ kind: 'account';
843
+ path: 'tokenProgram';
844
+ },
845
+ {
846
+ kind: 'account';
847
+ path: 'mint';
848
+ }
849
+ ];
850
+ program: {
851
+ kind: 'const';
852
+ value: [
853
+ 140,
854
+ 151,
855
+ 37,
856
+ 143,
857
+ 78,
858
+ 36,
859
+ 137,
860
+ 241,
861
+ 187,
862
+ 61,
863
+ 16,
864
+ 41,
865
+ 20,
866
+ 142,
867
+ 13,
868
+ 131,
869
+ 11,
870
+ 90,
871
+ 19,
872
+ 153,
873
+ 218,
874
+ 255,
875
+ 16,
876
+ 132,
877
+ 4,
878
+ 142,
879
+ 123,
880
+ 216,
881
+ 219,
882
+ 233,
883
+ 248,
884
+ 89
885
+ ];
886
+ };
887
+ };
888
+ },
889
+ {
890
+ name: 'marketVault';
891
+ writable: true;
892
+ pda: {
893
+ seeds: [
894
+ {
895
+ kind: 'account';
896
+ path: 'market';
897
+ },
898
+ {
899
+ kind: 'account';
900
+ path: 'tokenProgram';
901
+ },
902
+ {
903
+ kind: 'account';
904
+ path: 'mint';
905
+ }
906
+ ];
907
+ program: {
908
+ kind: 'const';
909
+ value: [
910
+ 140,
911
+ 151,
912
+ 37,
913
+ 143,
914
+ 78,
915
+ 36,
916
+ 137,
917
+ 241,
918
+ 187,
919
+ 61,
920
+ 16,
921
+ 41,
922
+ 20,
923
+ 142,
924
+ 13,
925
+ 131,
926
+ 11,
927
+ 90,
928
+ 19,
929
+ 153,
930
+ 218,
931
+ 255,
932
+ 16,
933
+ 132,
934
+ 4,
935
+ 142,
936
+ 123,
937
+ 216,
938
+ 219,
939
+ 233,
940
+ 248,
941
+ 89
942
+ ];
943
+ };
944
+ };
945
+ },
946
+ {
947
+ name: 'tokenProgram';
948
+ address: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';
949
+ },
950
+ {
951
+ name: 'associatedTokenProgram';
952
+ address: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
953
+ },
954
+ {
955
+ name: 'systemProgram';
956
+ address: '11111111111111111111111111111111';
957
+ }
958
+ ];
959
+ args: [
960
+ {
961
+ name: 'orderId';
962
+ type: 'u64';
963
+ }
964
+ ];
965
+ },
811
966
  {
812
967
  name: 'stakeNft';
813
968
  discriminator: [38, 27, 66, 46, 69, 65, 151, 219];
@@ -1560,6 +1715,10 @@ export type TriadProtocol = {
1560
1715
  name: 'userTokenAccount';
1561
1716
  writable: true;
1562
1717
  },
1718
+ {
1719
+ name: 'associatedTokenProgram';
1720
+ address: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
1721
+ },
1563
1722
  {
1564
1723
  name: 'systemProgram';
1565
1724
  address: '11111111111111111111111111111111';
@@ -1833,6 +1992,11 @@ export type TriadProtocol = {
1833
1992
  code: 6039;
1834
1993
  name: 'stakeVaultLocked';
1835
1994
  msg: 'Stake vault is locked';
1995
+ },
1996
+ {
1997
+ code: 6040;
1998
+ name: 'marketStillActive';
1999
+ msg: 'Market still active';
1836
2000
  }
1837
2001
  ];
1838
2002
  types: [
@@ -2233,6 +2397,12 @@ export type TriadProtocol = {
2233
2397
  },
2234
2398
  {
2235
2399
  name: 'closed';
2400
+ },
2401
+ {
2402
+ name: 'claimed';
2403
+ },
2404
+ {
2405
+ name: 'liquidated';
2236
2406
  }
2237
2407
  ];
2238
2408
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "1.1.4-beta",
3
+ "version": "1.1.6-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",