@triadxyz/triad-protocol 1.5.3-beta → 1.5.5-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.
package/dist/trade.d.ts CHANGED
@@ -13,6 +13,12 @@ export default class Trade {
13
13
  *
14
14
  */
15
15
  getAllMarkets(): Promise<import("./types/trade").Market[]>;
16
+ /**
17
+ * Get All User Trades
18
+ * @param user - User PublicKey
19
+ *
20
+ */
21
+ getAllUserTrade(user: PublicKey): Promise<import("./types/trade").UserTrade[]>;
16
22
  /**
17
23
  * Get Market By ID
18
24
  * @param marketId - The ID of the market
@@ -98,8 +104,11 @@ export default class Trade {
98
104
  } & {
99
105
  flop: Record<string, never>;
100
106
  });
107
+ userNonce: number;
101
108
  padding: number[];
102
109
  }[];
110
+ nonce: number;
111
+ isSubUser: boolean;
103
112
  padding: number[];
104
113
  }>;
105
114
  /**
@@ -172,20 +181,6 @@ export default class Trade {
172
181
  marketToAddLiquidity: OrderDirection;
173
182
  amount: number;
174
183
  }, options?: RpcOptions): Promise<string>;
175
- /**
176
- * Settle an Order for a V1 Market
177
- * @param args.marketId - The ID of the Market
178
- * @param args.orderId - The ID of the Order to Settle
179
- * @param args.user - The user to settle the order for
180
- *
181
- * @param options - RPC options
182
- *
183
- */
184
- settleOrder({ marketId, orderId, user }: {
185
- marketId: number;
186
- orderId: number;
187
- user: PublicKey;
188
- }, options?: RpcOptions): Promise<string>;
189
184
  /**
190
185
  * Add Liquidity
191
186
  * @param marketId - The ID of the market
package/dist/trade.js CHANGED
@@ -30,13 +30,26 @@ class Trade {
30
30
  */
31
31
  getAllMarkets() {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
- const marketV1 = yield this.program.account.market
34
- .all()
35
- .then((markets) => markets.map(({ account, publicKey }) => (0, helpers_1.accountToMarketV1)(account, publicKey)));
36
- const marketV2 = yield this.program.account.marketV2
37
- .all()
38
- .then((markets) => markets.map(({ account, publicKey }) => (0, helpers_1.formatMarket)(account, publicKey)));
39
- return [...marketV1, ...marketV2];
33
+ const marketV2 = yield this.program.account.marketV2.all();
34
+ return marketV2.map(({ account, publicKey }) => (0, helpers_1.formatMarket)(account, publicKey));
35
+ });
36
+ }
37
+ /**
38
+ * Get All User Trades
39
+ * @param user - User PublicKey
40
+ *
41
+ */
42
+ getAllUserTrade(user) {
43
+ return __awaiter(this, void 0, void 0, function* () {
44
+ const response = yield this.program.account.userTrade.all([
45
+ {
46
+ memcmp: {
47
+ offset: 8 + 1,
48
+ bytes: user.toBase58()
49
+ }
50
+ }
51
+ ]);
52
+ return response.map(({ account, publicKey }) => (0, helpers_1.formatUserTrade)(account, publicKey));
40
53
  });
41
54
  }
42
55
  /**
@@ -234,28 +247,6 @@ class Trade {
234
247
  return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
235
248
  });
236
249
  }
237
- /**
238
- * Settle an Order for a V1 Market
239
- * @param args.marketId - The ID of the Market
240
- * @param args.orderId - The ID of the Order to Settle
241
- * @param args.user - The user to settle the order for
242
- *
243
- * @param options - RPC options
244
- *
245
- */
246
- settleOrder({ marketId, orderId, user }, options) {
247
- return __awaiter(this, void 0, void 0, function* () {
248
- const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
249
- const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, user);
250
- return (0, sendTransactionWithOptions_1.default)(this.program.methods.settleOrder(new bn_js_1.default(orderId)).accounts({
251
- signer: this.provider.publicKey,
252
- user: user,
253
- userTrade: userTradePDA,
254
- market: marketPDA,
255
- mint: constants_1.TRD_MINT
256
- }), options);
257
- });
258
- }
259
250
  /**
260
251
  * Add Liquidity
261
252
  * @param marketId - The ID of the market
@@ -240,6 +240,11 @@
240
240
  "writable": true,
241
241
  "signer": true
242
242
  },
243
+ {
244
+ "name": "squads",
245
+ "writable": true,
246
+ "address": "6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq"
247
+ },
243
248
  {
244
249
  "name": "user_trade",
245
250
  "writable": true
@@ -446,6 +451,54 @@
446
451
  ],
447
452
  "args": []
448
453
  },
454
+ {
455
+ "name": "create_sub_user_trade",
456
+ "discriminator": [77, 201, 111, 73, 47, 229, 244, 161],
457
+ "accounts": [
458
+ {
459
+ "name": "signer",
460
+ "writable": true,
461
+ "signer": true
462
+ },
463
+ {
464
+ "name": "user_trade",
465
+ "writable": true,
466
+ "pda": {
467
+ "seeds": [
468
+ {
469
+ "kind": "const",
470
+ "value": [117, 115, 101, 114, 95, 116, 114, 97, 100, 101]
471
+ },
472
+ {
473
+ "kind": "account",
474
+ "path": "signer"
475
+ }
476
+ ]
477
+ }
478
+ },
479
+ {
480
+ "name": "sub_user_trade",
481
+ "writable": true,
482
+ "pda": {
483
+ "seeds": [
484
+ {
485
+ "kind": "const",
486
+ "value": [117, 115, 101, 114, 95, 116, 114, 97, 100, 101]
487
+ },
488
+ {
489
+ "kind": "arg",
490
+ "path": "sub_user_key"
491
+ }
492
+ ]
493
+ }
494
+ },
495
+ {
496
+ "name": "system_program",
497
+ "address": "11111111111111111111111111111111"
498
+ }
499
+ ],
500
+ "args": []
501
+ },
449
502
  {
450
503
  "name": "create_user_trade",
451
504
  "discriminator": [232, 235, 58, 194, 135, 248, 153, 1],
@@ -844,140 +897,6 @@
844
897
  }
845
898
  ]
846
899
  },
847
- {
848
- "name": "settle_order",
849
- "discriminator": [80, 74, 204, 34, 12, 183, 66, 66],
850
- "accounts": [
851
- {
852
- "name": "signer",
853
- "writable": true,
854
- "signer": true
855
- },
856
- {
857
- "name": "squads",
858
- "writable": true,
859
- "address": "6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq"
860
- },
861
- {
862
- "name": "user",
863
- "writable": true
864
- },
865
- {
866
- "name": "user_trade",
867
- "writable": true
868
- },
869
- {
870
- "name": "market",
871
- "writable": true
872
- },
873
- {
874
- "name": "mint",
875
- "writable": true
876
- },
877
- {
878
- "name": "user_ata",
879
- "writable": true,
880
- "pda": {
881
- "seeds": [
882
- {
883
- "kind": "account",
884
- "path": "user"
885
- },
886
- {
887
- "kind": "account",
888
- "path": "token_program"
889
- },
890
- {
891
- "kind": "account",
892
- "path": "mint"
893
- }
894
- ],
895
- "program": {
896
- "kind": "const",
897
- "value": [
898
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
899
- 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
900
- 219, 233, 248, 89
901
- ]
902
- }
903
- }
904
- },
905
- {
906
- "name": "market_ata",
907
- "writable": true,
908
- "pda": {
909
- "seeds": [
910
- {
911
- "kind": "account",
912
- "path": "market"
913
- },
914
- {
915
- "kind": "account",
916
- "path": "token_program"
917
- },
918
- {
919
- "kind": "account",
920
- "path": "mint"
921
- }
922
- ],
923
- "program": {
924
- "kind": "const",
925
- "value": [
926
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
927
- 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
928
- 219, 233, 248, 89
929
- ]
930
- }
931
- }
932
- },
933
- {
934
- "name": "squads_ata",
935
- "writable": true,
936
- "pda": {
937
- "seeds": [
938
- {
939
- "kind": "account",
940
- "path": "squads"
941
- },
942
- {
943
- "kind": "account",
944
- "path": "token_program"
945
- },
946
- {
947
- "kind": "account",
948
- "path": "mint"
949
- }
950
- ],
951
- "program": {
952
- "kind": "const",
953
- "value": [
954
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
955
- 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
956
- 219, 233, 248, 89
957
- ]
958
- }
959
- }
960
- },
961
- {
962
- "name": "token_program",
963
- "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
964
- },
965
- {
966
- "name": "associated_token_program",
967
- "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
968
- },
969
- {
970
- "name": "system_program",
971
- "address": "11111111111111111111111111111111"
972
- }
973
- ],
974
- "args": [
975
- {
976
- "name": "order_id",
977
- "type": "u64"
978
- }
979
- ]
980
- },
981
900
  {
982
901
  "name": "stake_token",
983
902
  "discriminator": [191, 127, 193, 101, 37, 96, 87, 211],
@@ -1420,10 +1339,6 @@
1420
1339
  "name": "Collection",
1421
1340
  "discriminator": [48, 160, 232, 205, 191, 207, 26, 141]
1422
1341
  },
1423
- {
1424
- "name": "Market",
1425
- "discriminator": [219, 190, 213, 55, 0, 227, 198, 154]
1426
- },
1427
1342
  {
1428
1343
  "name": "MarketV2",
1429
1344
  "discriminator": [27, 60, 50, 75, 191, 193, 86, 227]
@@ -1754,157 +1669,6 @@
1754
1669
  ]
1755
1670
  }
1756
1671
  },
1757
- {
1758
- "name": "Market",
1759
- "type": {
1760
- "kind": "struct",
1761
- "fields": [
1762
- {
1763
- "name": "bump",
1764
- "type": "u8"
1765
- },
1766
- {
1767
- "name": "authority",
1768
- "type": "pubkey"
1769
- },
1770
- {
1771
- "name": "market_id",
1772
- "docs": ["Unique identifier for the market"],
1773
- "type": "u64"
1774
- },
1775
- {
1776
- "name": "name",
1777
- "docs": ["The event being predicted (e.g., \"tJUP/TRD\")"],
1778
- "type": "string"
1779
- },
1780
- {
1781
- "name": "hype_price",
1782
- "docs": [
1783
- "Current price for Hype outcome (0-1000000, representing 0 to 1 TRD)",
1784
- "1000000 = 1 TRD, 500000 = 0.5 TRD, etc."
1785
- ],
1786
- "type": "u64"
1787
- },
1788
- {
1789
- "name": "flop_price",
1790
- "docs": [
1791
- "Current price for Flop outcome (0-1000000, representing 0 to 1 TRD)"
1792
- ],
1793
- "type": "u64"
1794
- },
1795
- {
1796
- "name": "hype_liquidity",
1797
- "docs": ["Total liquidity for Hype (in TRD)"],
1798
- "type": "u64"
1799
- },
1800
- {
1801
- "name": "flop_liquidity",
1802
- "docs": ["Total liquidity for Flop (in TRD)"],
1803
- "type": "u64"
1804
- },
1805
- {
1806
- "name": "total_hype_shares",
1807
- "docs": ["Total number of Hype shares issued"],
1808
- "type": "u64"
1809
- },
1810
- {
1811
- "name": "total_flop_shares",
1812
- "docs": ["Total number of Flop shares issued"],
1813
- "type": "u64"
1814
- },
1815
- {
1816
- "name": "total_volume",
1817
- "docs": ["Total trading volume (in TRD) for all resolutions"],
1818
- "type": "u64"
1819
- },
1820
- {
1821
- "name": "mint",
1822
- "docs": ["Mint $TRD token"],
1823
- "type": "pubkey"
1824
- },
1825
- {
1826
- "name": "ts",
1827
- "docs": ["Timestamp of the init"],
1828
- "type": "i64"
1829
- },
1830
- {
1831
- "name": "update_ts",
1832
- "type": "i64"
1833
- },
1834
- {
1835
- "name": "open_orders_count",
1836
- "docs": ["Total number of open orders in this market"],
1837
- "type": "u64"
1838
- },
1839
- {
1840
- "name": "next_order_id",
1841
- "docs": ["Next available order ID"],
1842
- "type": "u64"
1843
- },
1844
- {
1845
- "name": "fee_bps",
1846
- "docs": [
1847
- "Fees applied to trades (in basis points, e.g., 2.131% fee)"
1848
- ],
1849
- "type": "u16"
1850
- },
1851
- {
1852
- "name": "fee_vault",
1853
- "docs": ["Vault to Receive fees"],
1854
- "type": "pubkey"
1855
- },
1856
- {
1857
- "name": "is_active",
1858
- "docs": ["Whether the market is currently active for trading"],
1859
- "type": "bool"
1860
- },
1861
- {
1862
- "name": "market_price",
1863
- "type": "u64"
1864
- },
1865
- {
1866
- "name": "previous_resolved_question",
1867
- "type": {
1868
- "defined": {
1869
- "name": "ResolvedQuestion"
1870
- }
1871
- }
1872
- },
1873
- {
1874
- "name": "current_question_id",
1875
- "docs": [
1876
- "Index of the current week in the weekly_results array initialized with default values"
1877
- ],
1878
- "type": "u64"
1879
- },
1880
- {
1881
- "name": "current_question_start",
1882
- "type": "i64"
1883
- },
1884
- {
1885
- "name": "current_question_end",
1886
- "type": "i64"
1887
- },
1888
- {
1889
- "name": "current_question",
1890
- "docs": ["The question or prediction topic for the current week"],
1891
- "type": {
1892
- "array": ["u8", 80]
1893
- }
1894
- },
1895
- {
1896
- "name": "liquidity",
1897
- "type": "u64"
1898
- },
1899
- {
1900
- "name": "padding",
1901
- "type": {
1902
- "array": ["u8", 200]
1903
- }
1904
- }
1905
- ]
1906
- }
1907
- },
1908
1672
  {
1909
1673
  "name": "MarketAllowedToPayoutEvent",
1910
1674
  "type": {
@@ -2208,10 +1972,14 @@
2208
1972
  }
2209
1973
  }
2210
1974
  },
1975
+ {
1976
+ "name": "user_nonce",
1977
+ "type": "u32"
1978
+ },
2211
1979
  {
2212
1980
  "name": "padding",
2213
1981
  "type": {
2214
- "array": ["u8", 32]
1982
+ "array": ["u8", 28]
2215
1983
  }
2216
1984
  }
2217
1985
  ]
@@ -2380,84 +2148,6 @@
2380
2148
  ]
2381
2149
  }
2382
2150
  },
2383
- {
2384
- "name": "ResolvedQuestion",
2385
- "type": {
2386
- "kind": "struct",
2387
- "fields": [
2388
- {
2389
- "name": "question_id",
2390
- "type": "u64"
2391
- },
2392
- {
2393
- "name": "question",
2394
- "docs": ["The question or prediction topic for this week"],
2395
- "type": {
2396
- "array": ["u8", 80]
2397
- }
2398
- },
2399
- {
2400
- "name": "start_time",
2401
- "docs": ["Start timestamp of the week"],
2402
- "type": "i64"
2403
- },
2404
- {
2405
- "name": "end_time",
2406
- "docs": ["End timestamp of the week"],
2407
- "type": "i64"
2408
- },
2409
- {
2410
- "name": "hype_liquidity",
2411
- "docs": ["Total liquidity for Hype (in TRD)"],
2412
- "type": "u64"
2413
- },
2414
- {
2415
- "name": "flop_liquidity",
2416
- "docs": ["Total liquidity for Flop (in TRD)"],
2417
- "type": "u64"
2418
- },
2419
- {
2420
- "name": "winning_direction",
2421
- "docs": ["The winning direction (Hype, Flop or None)"],
2422
- "type": {
2423
- "defined": {
2424
- "name": "WinningDirection"
2425
- }
2426
- }
2427
- },
2428
- {
2429
- "name": "market_price",
2430
- "type": "u64"
2431
- },
2432
- {
2433
- "name": "final_hype_price",
2434
- "docs": ["Final price for Hype outcome at the end of the week"],
2435
- "type": "u64"
2436
- },
2437
- {
2438
- "name": "final_flop_price",
2439
- "docs": ["Final price for Flop outcome at the end of the week"],
2440
- "type": "u64"
2441
- },
2442
- {
2443
- "name": "total_hype_shares",
2444
- "docs": ["Total number of Hype shares issued"],
2445
- "type": "u64"
2446
- },
2447
- {
2448
- "name": "total_flop_shares",
2449
- "docs": ["Total number of Flop shares issued"],
2450
- "type": "u64"
2451
- },
2452
- {
2453
- "name": "padding",
2454
- "type": {
2455
- "array": ["u8", 40]
2456
- }
2457
- }
2458
- ]
2459
- }
2460
- },
2461
2151
  {
2462
2152
  "name": "StakeRewardsEvent",
2463
2153
  "type": {
@@ -2768,10 +2458,18 @@
2768
2458
  ]
2769
2459
  }
2770
2460
  },
2461
+ {
2462
+ "name": "nonce",
2463
+ "type": "u32"
2464
+ },
2465
+ {
2466
+ "name": "is_sub_user",
2467
+ "type": "bool"
2468
+ },
2771
2469
  {
2772
2470
  "name": "padding",
2773
2471
  "type": {
2774
- "array": ["u8", 32]
2472
+ "array": ["u8", 27]
2775
2473
  }
2776
2474
  }
2777
2475
  ]
@@ -26,6 +26,28 @@ export type Market = {
26
26
  winningDirection: WinningDirection;
27
27
  marketLiquidityAtStart: string;
28
28
  };
29
+ export type UserTrade = {
30
+ user: string;
31
+ totalDeposits: string;
32
+ totalWithdraws: string;
33
+ openedOrders: string;
34
+ orders: Order[];
35
+ nonce: string;
36
+ isSubUser: boolean;
37
+ };
38
+ export type Order = {
39
+ ts: string;
40
+ orderId: string;
41
+ questionId: string;
42
+ marketId: string;
43
+ status: OrderStatus;
44
+ price: string;
45
+ totalAmount: string;
46
+ totalShares: string;
47
+ orderType: OrderType;
48
+ direction: OrderDirection;
49
+ userNonce: string;
50
+ };
29
51
  export declare enum WinningDirection {
30
52
  HYPE = "Hype",
31
53
  FLOP = "Flop",
@@ -362,6 +362,11 @@ export type TriadProtocol = {
362
362
  writable: true;
363
363
  signer: true;
364
364
  },
365
+ {
366
+ name: 'squads';
367
+ writable: true;
368
+ address: '6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq';
369
+ },
365
370
  {
366
371
  name: 'userTrade';
367
372
  writable: true;
@@ -684,6 +689,54 @@ export type TriadProtocol = {
684
689
  ];
685
690
  args: [];
686
691
  },
692
+ {
693
+ name: 'createSubUserTrade';
694
+ discriminator: [77, 201, 111, 73, 47, 229, 244, 161];
695
+ accounts: [
696
+ {
697
+ name: 'signer';
698
+ writable: true;
699
+ signer: true;
700
+ },
701
+ {
702
+ name: 'userTrade';
703
+ writable: true;
704
+ pda: {
705
+ seeds: [
706
+ {
707
+ kind: 'const';
708
+ value: [117, 115, 101, 114, 95, 116, 114, 97, 100, 101];
709
+ },
710
+ {
711
+ kind: 'account';
712
+ path: 'signer';
713
+ }
714
+ ];
715
+ };
716
+ },
717
+ {
718
+ name: 'subUserTrade';
719
+ writable: true;
720
+ pda: {
721
+ seeds: [
722
+ {
723
+ kind: 'const';
724
+ value: [117, 115, 101, 114, 95, 116, 114, 97, 100, 101];
725
+ },
726
+ {
727
+ kind: 'arg';
728
+ path: 'subUserKey';
729
+ }
730
+ ];
731
+ };
732
+ },
733
+ {
734
+ name: 'systemProgram';
735
+ address: '11111111111111111111111111111111';
736
+ }
737
+ ];
738
+ args: [];
739
+ },
687
740
  {
688
741
  name: 'createUserTrade';
689
742
  discriminator: [232, 235, 58, 194, 135, 248, 153, 1];
@@ -1227,227 +1280,6 @@ export type TriadProtocol = {
1227
1280
  }
1228
1281
  ];
1229
1282
  },
1230
- {
1231
- name: 'settleOrder';
1232
- discriminator: [80, 74, 204, 34, 12, 183, 66, 66];
1233
- accounts: [
1234
- {
1235
- name: 'signer';
1236
- writable: true;
1237
- signer: true;
1238
- },
1239
- {
1240
- name: 'squads';
1241
- writable: true;
1242
- address: '6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq';
1243
- },
1244
- {
1245
- name: 'user';
1246
- writable: true;
1247
- },
1248
- {
1249
- name: 'userTrade';
1250
- writable: true;
1251
- },
1252
- {
1253
- name: 'market';
1254
- writable: true;
1255
- },
1256
- {
1257
- name: 'mint';
1258
- writable: true;
1259
- },
1260
- {
1261
- name: 'userAta';
1262
- writable: true;
1263
- pda: {
1264
- seeds: [
1265
- {
1266
- kind: 'account';
1267
- path: 'user';
1268
- },
1269
- {
1270
- kind: 'account';
1271
- path: 'tokenProgram';
1272
- },
1273
- {
1274
- kind: 'account';
1275
- path: 'mint';
1276
- }
1277
- ];
1278
- program: {
1279
- kind: 'const';
1280
- value: [
1281
- 140,
1282
- 151,
1283
- 37,
1284
- 143,
1285
- 78,
1286
- 36,
1287
- 137,
1288
- 241,
1289
- 187,
1290
- 61,
1291
- 16,
1292
- 41,
1293
- 20,
1294
- 142,
1295
- 13,
1296
- 131,
1297
- 11,
1298
- 90,
1299
- 19,
1300
- 153,
1301
- 218,
1302
- 255,
1303
- 16,
1304
- 132,
1305
- 4,
1306
- 142,
1307
- 123,
1308
- 216,
1309
- 219,
1310
- 233,
1311
- 248,
1312
- 89
1313
- ];
1314
- };
1315
- };
1316
- },
1317
- {
1318
- name: 'marketAta';
1319
- writable: true;
1320
- pda: {
1321
- seeds: [
1322
- {
1323
- kind: 'account';
1324
- path: 'market';
1325
- },
1326
- {
1327
- kind: 'account';
1328
- path: 'tokenProgram';
1329
- },
1330
- {
1331
- kind: 'account';
1332
- path: 'mint';
1333
- }
1334
- ];
1335
- program: {
1336
- kind: 'const';
1337
- value: [
1338
- 140,
1339
- 151,
1340
- 37,
1341
- 143,
1342
- 78,
1343
- 36,
1344
- 137,
1345
- 241,
1346
- 187,
1347
- 61,
1348
- 16,
1349
- 41,
1350
- 20,
1351
- 142,
1352
- 13,
1353
- 131,
1354
- 11,
1355
- 90,
1356
- 19,
1357
- 153,
1358
- 218,
1359
- 255,
1360
- 16,
1361
- 132,
1362
- 4,
1363
- 142,
1364
- 123,
1365
- 216,
1366
- 219,
1367
- 233,
1368
- 248,
1369
- 89
1370
- ];
1371
- };
1372
- };
1373
- },
1374
- {
1375
- name: 'squadsAta';
1376
- writable: true;
1377
- pda: {
1378
- seeds: [
1379
- {
1380
- kind: 'account';
1381
- path: 'squads';
1382
- },
1383
- {
1384
- kind: 'account';
1385
- path: 'tokenProgram';
1386
- },
1387
- {
1388
- kind: 'account';
1389
- path: 'mint';
1390
- }
1391
- ];
1392
- program: {
1393
- kind: 'const';
1394
- value: [
1395
- 140,
1396
- 151,
1397
- 37,
1398
- 143,
1399
- 78,
1400
- 36,
1401
- 137,
1402
- 241,
1403
- 187,
1404
- 61,
1405
- 16,
1406
- 41,
1407
- 20,
1408
- 142,
1409
- 13,
1410
- 131,
1411
- 11,
1412
- 90,
1413
- 19,
1414
- 153,
1415
- 218,
1416
- 255,
1417
- 16,
1418
- 132,
1419
- 4,
1420
- 142,
1421
- 123,
1422
- 216,
1423
- 219,
1424
- 233,
1425
- 248,
1426
- 89
1427
- ];
1428
- };
1429
- };
1430
- },
1431
- {
1432
- name: 'tokenProgram';
1433
- address: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';
1434
- },
1435
- {
1436
- name: 'associatedTokenProgram';
1437
- address: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
1438
- },
1439
- {
1440
- name: 'systemProgram';
1441
- address: '11111111111111111111111111111111';
1442
- }
1443
- ];
1444
- args: [
1445
- {
1446
- name: 'orderId';
1447
- type: 'u64';
1448
- }
1449
- ];
1450
- },
1451
1283
  {
1452
1284
  name: 'stakeToken';
1453
1285
  discriminator: [191, 127, 193, 101, 37, 96, 87, 211];
@@ -2064,10 +1896,6 @@ export type TriadProtocol = {
2064
1896
  name: 'collection';
2065
1897
  discriminator: [48, 160, 232, 205, 191, 207, 26, 141];
2066
1898
  },
2067
- {
2068
- name: 'market';
2069
- discriminator: [219, 190, 213, 55, 0, 227, 198, 154];
2070
- },
2071
1899
  {
2072
1900
  name: 'marketV2';
2073
1901
  discriminator: [27, 60, 50, 75, 191, 193, 86, 227];
@@ -2398,155 +2226,6 @@ export type TriadProtocol = {
2398
2226
  ];
2399
2227
  };
2400
2228
  },
2401
- {
2402
- name: 'market';
2403
- type: {
2404
- kind: 'struct';
2405
- fields: [
2406
- {
2407
- name: 'bump';
2408
- type: 'u8';
2409
- },
2410
- {
2411
- name: 'authority';
2412
- type: 'pubkey';
2413
- },
2414
- {
2415
- name: 'marketId';
2416
- docs: ['Unique identifier for the market'];
2417
- type: 'u64';
2418
- },
2419
- {
2420
- name: 'name';
2421
- docs: ['The event being predicted (e.g., "tJUP/TRD")'];
2422
- type: 'string';
2423
- },
2424
- {
2425
- name: 'hypePrice';
2426
- docs: [
2427
- 'Current price for Hype outcome (0-1000000, representing 0 to 1 TRD)',
2428
- '1000000 = 1 TRD, 500000 = 0.5 TRD, etc.'
2429
- ];
2430
- type: 'u64';
2431
- },
2432
- {
2433
- name: 'flopPrice';
2434
- docs: [
2435
- 'Current price for Flop outcome (0-1000000, representing 0 to 1 TRD)'
2436
- ];
2437
- type: 'u64';
2438
- },
2439
- {
2440
- name: 'hypeLiquidity';
2441
- docs: ['Total liquidity for Hype (in TRD)'];
2442
- type: 'u64';
2443
- },
2444
- {
2445
- name: 'flopLiquidity';
2446
- docs: ['Total liquidity for Flop (in TRD)'];
2447
- type: 'u64';
2448
- },
2449
- {
2450
- name: 'totalHypeShares';
2451
- docs: ['Total number of Hype shares issued'];
2452
- type: 'u64';
2453
- },
2454
- {
2455
- name: 'totalFlopShares';
2456
- docs: ['Total number of Flop shares issued'];
2457
- type: 'u64';
2458
- },
2459
- {
2460
- name: 'totalVolume';
2461
- docs: ['Total trading volume (in TRD) for all resolutions'];
2462
- type: 'u64';
2463
- },
2464
- {
2465
- name: 'mint';
2466
- docs: ['Mint $TRD token'];
2467
- type: 'pubkey';
2468
- },
2469
- {
2470
- name: 'ts';
2471
- docs: ['Timestamp of the init'];
2472
- type: 'i64';
2473
- },
2474
- {
2475
- name: 'updateTs';
2476
- type: 'i64';
2477
- },
2478
- {
2479
- name: 'openOrdersCount';
2480
- docs: ['Total number of open orders in this market'];
2481
- type: 'u64';
2482
- },
2483
- {
2484
- name: 'nextOrderId';
2485
- docs: ['Next available order ID'];
2486
- type: 'u64';
2487
- },
2488
- {
2489
- name: 'feeBps';
2490
- docs: ['Fees applied to trades (in basis points, e.g., 2.131% fee)'];
2491
- type: 'u16';
2492
- },
2493
- {
2494
- name: 'feeVault';
2495
- docs: ['Vault to Receive fees'];
2496
- type: 'pubkey';
2497
- },
2498
- {
2499
- name: 'isActive';
2500
- docs: ['Whether the market is currently active for trading'];
2501
- type: 'bool';
2502
- },
2503
- {
2504
- name: 'marketPrice';
2505
- type: 'u64';
2506
- },
2507
- {
2508
- name: 'previousResolvedQuestion';
2509
- type: {
2510
- defined: {
2511
- name: 'resolvedQuestion';
2512
- };
2513
- };
2514
- },
2515
- {
2516
- name: 'currentQuestionId';
2517
- docs: [
2518
- 'Index of the current week in the weekly_results array initialized with default values'
2519
- ];
2520
- type: 'u64';
2521
- },
2522
- {
2523
- name: 'currentQuestionStart';
2524
- type: 'i64';
2525
- },
2526
- {
2527
- name: 'currentQuestionEnd';
2528
- type: 'i64';
2529
- },
2530
- {
2531
- name: 'currentQuestion';
2532
- docs: ['The question or prediction topic for the current week'];
2533
- type: {
2534
- array: ['u8', 80];
2535
- };
2536
- },
2537
- {
2538
- name: 'liquidity';
2539
- type: 'u64';
2540
- },
2541
- {
2542
- name: 'padding';
2543
- type: {
2544
- array: ['u8', 200];
2545
- };
2546
- }
2547
- ];
2548
- };
2549
- },
2550
2229
  {
2551
2230
  name: 'marketAllowedToPayoutEvent';
2552
2231
  type: {
@@ -2850,10 +2529,14 @@ export type TriadProtocol = {
2850
2529
  };
2851
2530
  };
2852
2531
  },
2532
+ {
2533
+ name: 'userNonce';
2534
+ type: 'u32';
2535
+ },
2853
2536
  {
2854
2537
  name: 'padding';
2855
2538
  type: {
2856
- array: ['u8', 32];
2539
+ array: ['u8', 28];
2857
2540
  };
2858
2541
  }
2859
2542
  ];
@@ -3022,84 +2705,6 @@ export type TriadProtocol = {
3022
2705
  ];
3023
2706
  };
3024
2707
  },
3025
- {
3026
- name: 'resolvedQuestion';
3027
- type: {
3028
- kind: 'struct';
3029
- fields: [
3030
- {
3031
- name: 'questionId';
3032
- type: 'u64';
3033
- },
3034
- {
3035
- name: 'question';
3036
- docs: ['The question or prediction topic for this week'];
3037
- type: {
3038
- array: ['u8', 80];
3039
- };
3040
- },
3041
- {
3042
- name: 'startTime';
3043
- docs: ['Start timestamp of the week'];
3044
- type: 'i64';
3045
- },
3046
- {
3047
- name: 'endTime';
3048
- docs: ['End timestamp of the week'];
3049
- type: 'i64';
3050
- },
3051
- {
3052
- name: 'hypeLiquidity';
3053
- docs: ['Total liquidity for Hype (in TRD)'];
3054
- type: 'u64';
3055
- },
3056
- {
3057
- name: 'flopLiquidity';
3058
- docs: ['Total liquidity for Flop (in TRD)'];
3059
- type: 'u64';
3060
- },
3061
- {
3062
- name: 'winningDirection';
3063
- docs: ['The winning direction (Hype, Flop or None)'];
3064
- type: {
3065
- defined: {
3066
- name: 'winningDirection';
3067
- };
3068
- };
3069
- },
3070
- {
3071
- name: 'marketPrice';
3072
- type: 'u64';
3073
- },
3074
- {
3075
- name: 'finalHypePrice';
3076
- docs: ['Final price for Hype outcome at the end of the week'];
3077
- type: 'u64';
3078
- },
3079
- {
3080
- name: 'finalFlopPrice';
3081
- docs: ['Final price for Flop outcome at the end of the week'];
3082
- type: 'u64';
3083
- },
3084
- {
3085
- name: 'totalHypeShares';
3086
- docs: ['Total number of Hype shares issued'];
3087
- type: 'u64';
3088
- },
3089
- {
3090
- name: 'totalFlopShares';
3091
- docs: ['Total number of Flop shares issued'];
3092
- type: 'u64';
3093
- },
3094
- {
3095
- name: 'padding';
3096
- type: {
3097
- array: ['u8', 40];
3098
- };
3099
- }
3100
- ];
3101
- };
3102
- },
3103
2708
  {
3104
2709
  name: 'stakeRewardsEvent';
3105
2710
  type: {
@@ -3410,10 +3015,18 @@ export type TriadProtocol = {
3410
3015
  ];
3411
3016
  };
3412
3017
  },
3018
+ {
3019
+ name: 'nonce';
3020
+ type: 'u32';
3021
+ },
3022
+ {
3023
+ name: 'isSubUser';
3024
+ type: 'bool';
3025
+ },
3413
3026
  {
3414
3027
  name: 'padding';
3415
3028
  type: {
3416
- array: ['u8', 32];
3029
+ array: ['u8', 27];
3417
3030
  };
3418
3031
  }
3419
3032
  ];
@@ -1,6 +1,6 @@
1
1
  import { Stake, StakeVault } from './../types/stake';
2
2
  import { User } from './../types';
3
- import { Market } from '../types/trade';
3
+ import { Market, Order, UserTrade } from '../types/trade';
4
4
  import { PublicKey } from '@solana/web3.js';
5
5
  export declare const encodeString: (value: string, alloc?: number) => number[];
6
6
  export declare const decodeString: (bytes: number[]) => string;
@@ -8,5 +8,6 @@ export declare const formatStakeVault: (stakeVault: any) => StakeVault;
8
8
  export declare const formatStake: (stake: any) => Stake;
9
9
  export declare const formatUser: (user: any) => User;
10
10
  export declare const formatMarket: (account: any, address: PublicKey) => Market;
11
- export declare const accountToMarketV1: (account: any, address: PublicKey) => Market;
11
+ export declare const formatOrder: (order: any) => Order;
12
+ export declare const formatUserTrade: (account: any, publicKey: PublicKey) => UserTrade;
12
13
  export declare const calculateStakeRewards: (stake: Stake, multiplier: number) => number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.calculateStakeRewards = exports.accountToMarketV1 = exports.formatMarket = exports.formatUser = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
3
+ exports.calculateStakeRewards = exports.formatUserTrade = exports.formatOrder = exports.formatMarket = exports.formatUser = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
4
4
  const trade_1 = require("../types/trade");
5
5
  const constants_1 = require("./constants");
6
6
  const encodeString = (value, alloc = 32) => {
@@ -93,39 +93,34 @@ const formatMarket = (account, address) => {
93
93
  };
94
94
  };
95
95
  exports.formatMarket = formatMarket;
96
- const accountToMarketV1 = (account, address) => {
96
+ const formatOrder = (order) => {
97
97
  return {
98
- bump: account.bump,
99
- address: address.toString(),
100
- authority: account.authority.toString(),
101
- marketId: account.marketId.toString(),
102
- hypePrice: account.hypePrice.toString(),
103
- flopPrice: account.flopPrice.toString(),
104
- hypeLiquidity: account.hypeLiquidity.toString(),
105
- flopLiquidity: account.flopLiquidity.toString(),
106
- hypeShares: account.totalHypeShares.toString(),
107
- flopShares: account.totalFlopShares.toString(),
108
- volume: account.totalVolume.toString(),
109
- mint: account.mint.toString(),
110
- updateTs: account.updateTs.toString(),
111
- openedOrders: account.openOrdersCount.toString(),
112
- nextOrderId: account.nextOrderId.toString(),
113
- feeBps: account.feeBps,
114
- isAllowedToPayout: account.isActive,
115
- marketStart: account.currentQuestionStart.toString(),
116
- marketEnd: account.currentQuestionEnd.toString(),
117
- question: Buffer.from(account.currentQuestion)
118
- .toString()
119
- .replace(/\0+$/, ''),
120
- nftHoldersFeeAvailable: '0',
121
- nftHoldersFeeClaimed: '0',
122
- marketFeeAvailable: '0',
123
- marketFeeClaimed: '0',
124
- winningDirection: trade_1.WinningDirection[Object.keys(account.previousResolvedQuestion.winningDirection)[0].toUpperCase()],
125
- marketLiquidityAtStart: '0'
98
+ ts: order.ts.toString(),
99
+ orderId: order.orderId.toString(),
100
+ questionId: order.questionId.toString(),
101
+ marketId: order.marketId.toString(),
102
+ status: order.status,
103
+ price: order.price.toString(),
104
+ totalAmount: order.totalAmount.toString(),
105
+ totalShares: order.totalShares.toString(),
106
+ orderType: order.orderType,
107
+ direction: order.direction,
108
+ userNonce: order.userNonce.toString()
109
+ };
110
+ };
111
+ exports.formatOrder = formatOrder;
112
+ const formatUserTrade = (account, publicKey) => {
113
+ return {
114
+ user: publicKey.toString(),
115
+ totalDeposits: account.totalDeposits.toString(),
116
+ totalWithdraws: account.totalWithdraws.toString(),
117
+ openedOrders: account.openedOrders.toString(),
118
+ orders: account.orders.map((order) => (0, exports.formatOrder)(order)),
119
+ nonce: account.nonce.toString(),
120
+ isSubUser: account.isSubUser
126
121
  };
127
122
  };
128
- exports.accountToMarketV1 = accountToMarketV1;
123
+ exports.formatUserTrade = formatUserTrade;
129
124
  const calculateStakeRewards = (stake, multiplier) => {
130
125
  if (stake.withdrawTs !== 0)
131
126
  return 0;
@@ -1,3 +1,4 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
2
  export declare const getMarketPDA: (programId: PublicKey, marketId: number) => PublicKey;
3
3
  export declare const getUserTradePDA: (programId: PublicKey, wallet: PublicKey) => PublicKey;
4
+ export declare const getSubUserTradePDA: (programId: PublicKey, wallet: PublicKey, nonce: number) => PublicKey;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getUserTradePDA = exports.getMarketPDA = void 0;
6
+ exports.getSubUserTradePDA = exports.getUserTradePDA = exports.getMarketPDA = void 0;
7
7
  const web3_js_1 = require("@solana/web3.js");
8
8
  const bn_js_1 = __importDefault(require("bn.js"));
9
9
  const getMarketPDA = (programId, marketId) => {
@@ -14,3 +14,11 @@ const getUserTradePDA = (programId, wallet) => {
14
14
  return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('user_trade'), wallet.toBuffer()], programId)[0];
15
15
  };
16
16
  exports.getUserTradePDA = getUserTradePDA;
17
+ const getSubUserTradePDA = (programId, wallet, nonce) => {
18
+ return web3_js_1.PublicKey.findProgramAddressSync([
19
+ Buffer.from('sub_user_trade'),
20
+ wallet.toBuffer(),
21
+ new bn_js_1.default(nonce).toArrayLike(Buffer, 'le', 8)
22
+ ], programId)[0];
23
+ };
24
+ exports.getSubUserTradePDA = getSubUserTradePDA;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "1.5.3-beta",
3
+ "version": "1.5.5-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -32,6 +32,7 @@
32
32
  "license": "ISC",
33
33
  "dependencies": {
34
34
  "@coral-xyz/anchor": "0.30.1",
35
+ "@shadow-drive/sdk": "^6.0.0",
35
36
  "@solana/spl-token": "0.4.8",
36
37
  "@solana/web3.js": "^1.95.3",
37
38
  "axios": "^1.5.1",