@triadxyz/triad-protocol 4.0.2 → 4.0.4-beta.1

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.
@@ -16,12 +16,12 @@ export default class Customer {
16
16
  * Get Costumer By Wallet Address
17
17
  * @param wallet - The wallet address of the customer
18
18
  */
19
- getCustomerByWallet(wallet: PublicKey): Promise<import("@triadxyz/triad-protocol").Customer>;
19
+ getCustomerByWallet(wallet: PublicKey): Promise<import("./types/customer").Customer>;
20
20
  /**
21
21
  * Get Customer By ID
22
22
  * @param customerId - The ID of the customer
23
23
  */
24
- getCustomerById(customerId: number): Promise<import("@triadxyz/triad-protocol").Customer>;
24
+ getCustomerById(customerId: number): Promise<import("./types/customer").Customer>;
25
25
  /**
26
26
  * Create Customer
27
27
  * @param args.id - The ID of the customer
package/dist/customer.js CHANGED
@@ -13,7 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
16
- const triad_protocol_1 = require("@triadxyz/triad-protocol");
16
+ const helpers_1 = require("./utils/helpers");
17
+ const pda_1 = require("./utils/pda");
17
18
  class Customer {
18
19
  constructor(program, rpcOptions) {
19
20
  this.program = program;
@@ -42,7 +43,7 @@ class Customer {
42
43
  }
43
44
  }
44
45
  ]);
45
- return (0, triad_protocol_1.formatCustomer)(customer.account, customer.publicKey);
46
+ return (0, helpers_1.formatCustomer)(customer.account, customer.publicKey);
46
47
  });
47
48
  }
48
49
  /**
@@ -51,9 +52,9 @@ class Customer {
51
52
  */
52
53
  getCustomerById(customerId) {
53
54
  return __awaiter(this, void 0, void 0, function* () {
54
- const customerPDA = (0, triad_protocol_1.getCustomerPDA)(this.program.programId, customerId);
55
+ const customerPDA = (0, pda_1.getCustomerPDA)(this.program.programId, customerId);
55
56
  const customer = yield this.program.account.customer.fetch(customerPDA, this.rpcOptions.commitment);
56
- return (0, triad_protocol_1.formatCustomer)(customer, customerPDA);
57
+ return (0, helpers_1.formatCustomer)(customer, customerPDA);
57
58
  });
58
59
  }
59
60
  /**
@@ -1,25 +1,32 @@
1
1
  /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
+ import { PublicKey } from '@solana/web3.js';
2
3
  import { Program } from '@coral-xyz/anchor';
3
4
  import { TriadProtocol } from './types/triad_protocol';
4
5
  import { RpcOptions } from './types';
5
- import { DepositArgs, WithdrawArgs } from './types/predictor';
6
+ import { DepositArgs, WithdrawArgs, Predictor as PredictorType } from './types/predictor';
6
7
  export default class Predictor {
7
8
  private program;
8
9
  private rpcOptions;
9
10
  constructor(program: Program<TriadProtocol>, rpcOptions: RpcOptions);
11
+ /**
12
+ * Get predictor
13
+ * @param authority - Authority public key
14
+ * @param customerId - Customer ID (optional) defaults to 7 from Triadmarkets
15
+ */
16
+ getPredictor(authority: PublicKey, customerId?: number): Promise<PredictorType>;
10
17
  /**
11
18
  * Deposit
12
19
  * @param args.authority - Authority of the deposit
13
20
  * @param args.amount - Amount to deposit
14
21
  * @param args.refer - Referral public key (optional) defaults to Triadmarkets public key
15
- * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
22
+ * @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
16
23
  */
17
- deposit({ authority, amount, refer, customer }: DepositArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
24
+ deposit({ authority, amount, refer, customerId }: DepositArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
18
25
  /**
19
26
  * Withdraw
20
27
  * @param args.authority - Authority of the withdraw
21
28
  * @param args.amount - Amount to deposit
22
- * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
29
+ * @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
23
30
  */
24
- withdraw({ authority, amount, customer }: WithdrawArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
31
+ withdraw({ authority, amount, customerId }: WithdrawArgs): Promise<string | import("@solana/web3.js").VersionedTransaction>;
25
32
  }
package/dist/predictor.js CHANGED
@@ -17,29 +17,55 @@ const bn_js_1 = __importDefault(require("bn.js"));
17
17
  const constants_1 = require("./utils/constants");
18
18
  const pda_1 = require("./utils/pda");
19
19
  const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
20
+ const helpers_1 = require("./utils/helpers");
21
+ const spl_token_1 = require("@solana/spl-token");
20
22
  class Predictor {
21
23
  constructor(program, rpcOptions) {
22
24
  this.program = program;
23
25
  this.rpcOptions = rpcOptions;
24
26
  }
27
+ /**
28
+ * Get predictor
29
+ * @param authority - Authority public key
30
+ * @param customerId - Customer ID (optional) defaults to 7 from Triadmarkets
31
+ */
32
+ getPredictor(authority, customerId = 7) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
35
+ try {
36
+ const predictor = yield this.program.account.predictor.fetch(predictorPDA);
37
+ const balance = yield this.program.provider.connection.getTokenAccountBalance((0, pda_1.getTokenATA)(predictorPDA, constants_1.UNIT_MINT, spl_token_1.TOKEN_PROGRAM_ID));
38
+ return (0, helpers_1.formatPredictor)(predictor, predictorPDA, new bn_js_1.default(balance.value.amount));
39
+ }
40
+ catch (e) {
41
+ return {
42
+ address: predictorPDA.toBase58(),
43
+ authority: authority.toBase58(),
44
+ balance: 0,
45
+ customerId,
46
+ refer: '11111111111111111111111111111111'
47
+ };
48
+ }
49
+ });
50
+ }
25
51
  /**
26
52
  * Deposit
27
53
  * @param args.authority - Authority of the deposit
28
54
  * @param args.amount - Amount to deposit
29
55
  * @param args.refer - Referral public key (optional) defaults to Triadmarkets public key
30
- * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
56
+ * @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
31
57
  */
32
- deposit({ authority, amount, refer = new web3_js_1.PublicKey('DqL77dzdTruyY9qssbU1aQNeDDywxL587k9FquxVv6iX'), customer = 7 }) {
58
+ deposit({ authority, amount, refer = new web3_js_1.PublicKey('DqL77dzdTruyY9qssbU1aQNeDDywxL587k9FquxVv6iX'), customerId = 7 }) {
33
59
  return __awaiter(this, void 0, void 0, function* () {
34
60
  const ixs = [];
35
- const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customer);
61
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
36
62
  try {
37
63
  yield this.program.account.predictor.fetch(predictorPDA);
38
64
  }
39
65
  catch (e) {
40
66
  ixs.push(yield this.program.methods
41
67
  .createPredictor({
42
- customer,
68
+ customerId,
43
69
  refer
44
70
  })
45
71
  .accounts({
@@ -63,12 +89,12 @@ class Predictor {
63
89
  * Withdraw
64
90
  * @param args.authority - Authority of the withdraw
65
91
  * @param args.amount - Amount to deposit
66
- * @param args.customer - Customer ID (optional) defaults to 7 from Triadmarkets
92
+ * @param args.customerId - Customer ID (optional) defaults to 7 from Triadmarkets
67
93
  */
68
- withdraw({ authority, amount, customer = 7 }) {
94
+ withdraw({ authority, amount, customerId = 7 }) {
69
95
  return __awaiter(this, void 0, void 0, function* () {
70
96
  const ixs = [];
71
- const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customer);
97
+ const predictorPDA = (0, pda_1.getPredictorPDA)(this.program.programId, authority, customerId);
72
98
  ixs.push(yield this.program.methods
73
99
  .withdraw(new bn_js_1.default(amount * Math.pow(10, constants_1.BASE_DECIMALS)))
74
100
  .accounts({
package/dist/trade.js CHANGED
@@ -215,7 +215,7 @@ class Trade {
215
215
  }
216
216
  const orderPrice = new bn_js_1.default(order.price);
217
217
  const availableShares = new bn_js_1.default(order.totalShares).sub(new bn_js_1.default(order.filledShares));
218
- const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000, 700);
218
+ const effectivePriceDecimal = (0, feeCalculator_1.applyBuyFee)(orderPrice.toNumber() / 1000000, 500);
219
219
  const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
220
220
  const maxSharesForPrice = remainingUSDC
221
221
  .mul(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS)))
@@ -287,7 +287,7 @@ class Trade {
287
287
  continue;
288
288
  remainingShares = remainingShares.sub(sharesToSell);
289
289
  const orderPrice = new bn_js_1.default(order.price);
290
- const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 700);
290
+ const effectivePriceDecimal = (0, feeCalculator_1.applySellFee)(orderPrice.toNumber() / 1000000, 500);
291
291
  const adjustedPrice = new bn_js_1.default(Math.floor(effectivePriceDecimal * 1000000));
292
292
  amountOfUSDC = amountOfUSDC.add(sharesToSell.mul(adjustedPrice).div(new bn_js_1.default(Math.pow(10, constants_1.BASE_DECIMALS))));
293
293
  ixs.push(yield this.program.methods
@@ -1,4 +1,3 @@
1
- /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
1
  import { PublicKey } from '@solana/web3.js';
3
2
  export type Customer = {
4
3
  id: number;
@@ -422,9 +422,8 @@
422
422
  "signer": true
423
423
  },
424
424
  {
425
- "name": "squads",
426
- "writable": true,
427
- "address": "Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4"
425
+ "name": "authority",
426
+ "writable": true
428
427
  },
429
428
  {
430
429
  "name": "market",
@@ -847,7 +846,7 @@
847
846
  },
848
847
  {
849
848
  "kind": "arg",
850
- "path": "args.customer"
849
+ "path": "args.customer_id"
851
850
  }
852
851
  ]
853
852
  }
@@ -1509,6 +1508,116 @@
1509
1508
  }
1510
1509
  ]
1511
1510
  },
1511
+ {
1512
+ "name": "place_order_v0",
1513
+ "discriminator": [100, 204, 57, 226, 245, 228, 61, 187],
1514
+ "accounts": [
1515
+ {
1516
+ "name": "signer",
1517
+ "writable": true,
1518
+ "signer": true
1519
+ },
1520
+ {
1521
+ "name": "payer",
1522
+ "writable": true,
1523
+ "signer": true
1524
+ },
1525
+ {
1526
+ "name": "market",
1527
+ "writable": true
1528
+ },
1529
+ {
1530
+ "name": "order_book",
1531
+ "writable": true
1532
+ },
1533
+ {
1534
+ "name": "order",
1535
+ "writable": true
1536
+ },
1537
+ {
1538
+ "name": "mint",
1539
+ "address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
1540
+ },
1541
+ {
1542
+ "name": "user_ata",
1543
+ "writable": true,
1544
+ "pda": {
1545
+ "seeds": [
1546
+ {
1547
+ "kind": "account",
1548
+ "path": "signer"
1549
+ },
1550
+ {
1551
+ "kind": "account",
1552
+ "path": "token_program"
1553
+ },
1554
+ {
1555
+ "kind": "account",
1556
+ "path": "mint"
1557
+ }
1558
+ ],
1559
+ "program": {
1560
+ "kind": "const",
1561
+ "value": [
1562
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
1563
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
1564
+ 219, 233, 248, 89
1565
+ ]
1566
+ }
1567
+ }
1568
+ },
1569
+ {
1570
+ "name": "market_ata",
1571
+ "writable": true,
1572
+ "pda": {
1573
+ "seeds": [
1574
+ {
1575
+ "kind": "account",
1576
+ "path": "market"
1577
+ },
1578
+ {
1579
+ "kind": "account",
1580
+ "path": "token_program"
1581
+ },
1582
+ {
1583
+ "kind": "account",
1584
+ "path": "mint"
1585
+ }
1586
+ ],
1587
+ "program": {
1588
+ "kind": "const",
1589
+ "value": [
1590
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
1591
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
1592
+ 219, 233, 248, 89
1593
+ ]
1594
+ }
1595
+ }
1596
+ },
1597
+ {
1598
+ "name": "token_program",
1599
+ "address": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
1600
+ },
1601
+ {
1602
+ "name": "associated_token_program",
1603
+ "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
1604
+ },
1605
+ {
1606
+ "name": "system_program",
1607
+ "address": "11111111111111111111111111111111"
1608
+ }
1609
+ ],
1610
+ "args": [
1611
+ {
1612
+ "name": "args",
1613
+ "type": {
1614
+ "defined": {
1615
+ "name": "PlaceOrderV0Args"
1616
+ }
1617
+ }
1618
+ }
1619
+ ]
1620
+ },
1512
1621
  {
1513
1622
  "name": "remove_trader_poseidon",
1514
1623
  "discriminator": [150, 5, 46, 188, 189, 13, 246, 11],
@@ -2369,10 +2478,6 @@
2369
2478
  "name": "ActivityEvent",
2370
2479
  "discriminator": [231, 225, 142, 104, 209, 97, 39, 202]
2371
2480
  },
2372
- {
2373
- "name": "BookOrderEvent",
2374
- "discriminator": [175, 216, 61, 224, 98, 215, 181, 62]
2375
- },
2376
2481
  {
2377
2482
  "name": "ClaimTokenEvent",
2378
2483
  "discriminator": [127, 10, 14, 49, 47, 171, 31, 127]
@@ -2744,66 +2849,6 @@
2744
2849
  ]
2745
2850
  }
2746
2851
  },
2747
- {
2748
- "name": "BookOrderEvent",
2749
- "type": {
2750
- "kind": "struct",
2751
- "fields": [
2752
- {
2753
- "name": "market_id",
2754
- "type": "u64"
2755
- },
2756
- {
2757
- "name": "timestamp",
2758
- "type": "i64"
2759
- },
2760
- {
2761
- "name": "price",
2762
- "type": "u64"
2763
- },
2764
- {
2765
- "name": "total_shares",
2766
- "type": "u64"
2767
- },
2768
- {
2769
- "name": "filled_shares",
2770
- "type": "u64"
2771
- },
2772
- {
2773
- "name": "authority",
2774
- "type": "pubkey"
2775
- },
2776
- {
2777
- "name": "user_nonce",
2778
- "type": "u32"
2779
- },
2780
- {
2781
- "name": "id",
2782
- "type": "u8"
2783
- },
2784
- {
2785
- "name": "linked_book_order_id",
2786
- "type": "u8"
2787
- },
2788
- {
2789
- "name": "order_direction",
2790
- "type": {
2791
- "defined": {
2792
- "name": "OrderDirection"
2793
- }
2794
- }
2795
- },
2796
- {
2797
- "name": "order_side",
2798
- "type": {
2799
- "defined": {
2800
- "name": "OrderSide"
2801
- }
2802
- }
2803
- }
2804
- ]
2805
- }
2806
- },
2807
2852
  {
2808
2853
  "name": "CancelOrderArgs",
2809
2854
  "type": {
@@ -3106,7 +3151,7 @@
3106
3151
  "type": "pubkey"
3107
3152
  },
3108
3153
  {
3109
- "name": "customer",
3154
+ "name": "customer_id",
3110
3155
  "type": "u16"
3111
3156
  }
3112
3157
  ]
@@ -3806,6 +3851,38 @@
3806
3851
  ]
3807
3852
  }
3808
3853
  },
3854
+ {
3855
+ "name": "PlaceOrderV0Args",
3856
+ "type": {
3857
+ "kind": "struct",
3858
+ "fields": [
3859
+ {
3860
+ "name": "shares",
3861
+ "type": "u64"
3862
+ },
3863
+ {
3864
+ "name": "price",
3865
+ "type": "u64"
3866
+ },
3867
+ {
3868
+ "name": "order_direction",
3869
+ "type": {
3870
+ "defined": {
3871
+ "name": "OrderDirection"
3872
+ }
3873
+ }
3874
+ },
3875
+ {
3876
+ "name": "order_side",
3877
+ "type": {
3878
+ "defined": {
3879
+ "name": "OrderSide"
3880
+ }
3881
+ }
3882
+ }
3883
+ ]
3884
+ }
3885
+ },
3809
3886
  {
3810
3887
  "name": "Pool",
3811
3888
  "type": {
@@ -3886,7 +3963,7 @@
3886
3963
  "type": "pubkey"
3887
3964
  },
3888
3965
  {
3889
- "name": "customer",
3966
+ "name": "customer_id",
3890
3967
  "type": "u16"
3891
3968
  },
3892
3969
  {
@@ -1,4 +1,3 @@
1
- /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
1
  import { Commitment, PublicKey } from '@solana/web3.js';
3
2
  export type RpcOptions = {
4
3
  skipPreflight?: boolean;
@@ -1,13 +1,19 @@
1
- /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
1
  import { PublicKey } from '@solana/web3.js';
2
+ export type Predictor = {
3
+ address: string;
4
+ authority: string;
5
+ refer: string;
6
+ customerId: number;
7
+ balance: number;
8
+ };
3
9
  export type DepositArgs = {
4
10
  authority: PublicKey;
5
11
  amount: number;
6
12
  refer?: PublicKey;
7
- customer?: number;
13
+ customerId?: number;
8
14
  };
9
15
  export type WithdrawArgs = {
10
16
  authority: PublicKey;
11
17
  amount: number;
12
- customer?: number;
18
+ customerId?: number;
13
19
  };
@@ -1,4 +1,3 @@
1
- /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
1
  import { PublicKey } from '@solana/web3.js';
3
2
  import { OrderDirectionEncoded } from './';
4
3
  export type PlaceBidOrderArgs = {
@@ -626,9 +626,8 @@ export type TriadProtocol = {
626
626
  signer: true;
627
627
  },
628
628
  {
629
- name: 'squads';
629
+ name: 'authority';
630
630
  writable: true;
631
- address: 'Hk1r2NUL4LbUhx1agg1w44tyZiNr72mbeLsg6suF5MA4';
632
631
  },
633
632
  {
634
633
  name: 'market';
@@ -1167,7 +1166,7 @@ export type TriadProtocol = {
1167
1166
  },
1168
1167
  {
1169
1168
  kind: 'arg';
1170
- path: 'args.customer';
1169
+ path: 'args.customer_id';
1171
1170
  }
1172
1171
  ];
1173
1172
  };
@@ -2159,6 +2158,174 @@ export type TriadProtocol = {
2159
2158
  }
2160
2159
  ];
2161
2160
  },
2161
+ {
2162
+ name: 'placeOrderV0';
2163
+ discriminator: [100, 204, 57, 226, 245, 228, 61, 187];
2164
+ accounts: [
2165
+ {
2166
+ name: 'signer';
2167
+ writable: true;
2168
+ signer: true;
2169
+ },
2170
+ {
2171
+ name: 'payer';
2172
+ writable: true;
2173
+ signer: true;
2174
+ },
2175
+ {
2176
+ name: 'market';
2177
+ writable: true;
2178
+ },
2179
+ {
2180
+ name: 'orderBook';
2181
+ writable: true;
2182
+ },
2183
+ {
2184
+ name: 'order';
2185
+ writable: true;
2186
+ },
2187
+ {
2188
+ name: 'mint';
2189
+ address: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';
2190
+ },
2191
+ {
2192
+ name: 'userAta';
2193
+ writable: true;
2194
+ pda: {
2195
+ seeds: [
2196
+ {
2197
+ kind: 'account';
2198
+ path: 'signer';
2199
+ },
2200
+ {
2201
+ kind: 'account';
2202
+ path: 'tokenProgram';
2203
+ },
2204
+ {
2205
+ kind: 'account';
2206
+ path: 'mint';
2207
+ }
2208
+ ];
2209
+ program: {
2210
+ kind: 'const';
2211
+ value: [
2212
+ 140,
2213
+ 151,
2214
+ 37,
2215
+ 143,
2216
+ 78,
2217
+ 36,
2218
+ 137,
2219
+ 241,
2220
+ 187,
2221
+ 61,
2222
+ 16,
2223
+ 41,
2224
+ 20,
2225
+ 142,
2226
+ 13,
2227
+ 131,
2228
+ 11,
2229
+ 90,
2230
+ 19,
2231
+ 153,
2232
+ 218,
2233
+ 255,
2234
+ 16,
2235
+ 132,
2236
+ 4,
2237
+ 142,
2238
+ 123,
2239
+ 216,
2240
+ 219,
2241
+ 233,
2242
+ 248,
2243
+ 89
2244
+ ];
2245
+ };
2246
+ };
2247
+ },
2248
+ {
2249
+ name: 'marketAta';
2250
+ writable: true;
2251
+ pda: {
2252
+ seeds: [
2253
+ {
2254
+ kind: 'account';
2255
+ path: 'market';
2256
+ },
2257
+ {
2258
+ kind: 'account';
2259
+ path: 'tokenProgram';
2260
+ },
2261
+ {
2262
+ kind: 'account';
2263
+ path: 'mint';
2264
+ }
2265
+ ];
2266
+ program: {
2267
+ kind: 'const';
2268
+ value: [
2269
+ 140,
2270
+ 151,
2271
+ 37,
2272
+ 143,
2273
+ 78,
2274
+ 36,
2275
+ 137,
2276
+ 241,
2277
+ 187,
2278
+ 61,
2279
+ 16,
2280
+ 41,
2281
+ 20,
2282
+ 142,
2283
+ 13,
2284
+ 131,
2285
+ 11,
2286
+ 90,
2287
+ 19,
2288
+ 153,
2289
+ 218,
2290
+ 255,
2291
+ 16,
2292
+ 132,
2293
+ 4,
2294
+ 142,
2295
+ 123,
2296
+ 216,
2297
+ 219,
2298
+ 233,
2299
+ 248,
2300
+ 89
2301
+ ];
2302
+ };
2303
+ };
2304
+ },
2305
+ {
2306
+ name: 'tokenProgram';
2307
+ address: 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
2308
+ },
2309
+ {
2310
+ name: 'associatedTokenProgram';
2311
+ address: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
2312
+ },
2313
+ {
2314
+ name: 'systemProgram';
2315
+ address: '11111111111111111111111111111111';
2316
+ }
2317
+ ];
2318
+ args: [
2319
+ {
2320
+ name: 'args';
2321
+ type: {
2322
+ defined: {
2323
+ name: 'placeOrderV0Args';
2324
+ };
2325
+ };
2326
+ }
2327
+ ];
2328
+ },
2162
2329
  {
2163
2330
  name: 'removeTraderPoseidon';
2164
2331
  discriminator: [150, 5, 46, 188, 189, 13, 246, 11];
@@ -3257,10 +3424,6 @@ export type TriadProtocol = {
3257
3424
  name: 'activityEvent';
3258
3425
  discriminator: [231, 225, 142, 104, 209, 97, 39, 202];
3259
3426
  },
3260
- {
3261
- name: 'bookOrderEvent';
3262
- discriminator: [175, 216, 61, 224, 98, 215, 181, 62];
3263
- },
3264
3427
  {
3265
3428
  name: 'claimTokenEvent';
3266
3429
  discriminator: [127, 10, 14, 49, 47, 171, 31, 127];
@@ -3632,66 +3795,6 @@ export type TriadProtocol = {
3632
3795
  ];
3633
3796
  };
3634
3797
  },
3635
- {
3636
- name: 'bookOrderEvent';
3637
- type: {
3638
- kind: 'struct';
3639
- fields: [
3640
- {
3641
- name: 'marketId';
3642
- type: 'u64';
3643
- },
3644
- {
3645
- name: 'timestamp';
3646
- type: 'i64';
3647
- },
3648
- {
3649
- name: 'price';
3650
- type: 'u64';
3651
- },
3652
- {
3653
- name: 'totalShares';
3654
- type: 'u64';
3655
- },
3656
- {
3657
- name: 'filledShares';
3658
- type: 'u64';
3659
- },
3660
- {
3661
- name: 'authority';
3662
- type: 'pubkey';
3663
- },
3664
- {
3665
- name: 'userNonce';
3666
- type: 'u32';
3667
- },
3668
- {
3669
- name: 'id';
3670
- type: 'u8';
3671
- },
3672
- {
3673
- name: 'linkedBookOrderId';
3674
- type: 'u8';
3675
- },
3676
- {
3677
- name: 'orderDirection';
3678
- type: {
3679
- defined: {
3680
- name: 'orderDirection';
3681
- };
3682
- };
3683
- },
3684
- {
3685
- name: 'orderSide';
3686
- type: {
3687
- defined: {
3688
- name: 'orderSide';
3689
- };
3690
- };
3691
- }
3692
- ];
3693
- };
3694
- },
3695
3798
  {
3696
3799
  name: 'cancelOrderArgs';
3697
3800
  type: {
@@ -3994,7 +4097,7 @@ export type TriadProtocol = {
3994
4097
  type: 'pubkey';
3995
4098
  },
3996
4099
  {
3997
- name: 'customer';
4100
+ name: 'customerId';
3998
4101
  type: 'u16';
3999
4102
  }
4000
4103
  ];
@@ -4694,6 +4797,38 @@ export type TriadProtocol = {
4694
4797
  ];
4695
4798
  };
4696
4799
  },
4800
+ {
4801
+ name: 'placeOrderV0Args';
4802
+ type: {
4803
+ kind: 'struct';
4804
+ fields: [
4805
+ {
4806
+ name: 'shares';
4807
+ type: 'u64';
4808
+ },
4809
+ {
4810
+ name: 'price';
4811
+ type: 'u64';
4812
+ },
4813
+ {
4814
+ name: 'orderDirection';
4815
+ type: {
4816
+ defined: {
4817
+ name: 'orderDirection';
4818
+ };
4819
+ };
4820
+ },
4821
+ {
4822
+ name: 'orderSide';
4823
+ type: {
4824
+ defined: {
4825
+ name: 'orderSide';
4826
+ };
4827
+ };
4828
+ }
4829
+ ];
4830
+ };
4831
+ },
4697
4832
  {
4698
4833
  name: 'pool';
4699
4834
  type: {
@@ -4774,7 +4909,7 @@ export type TriadProtocol = {
4774
4909
  type: 'pubkey';
4775
4910
  },
4776
4911
  {
4777
- name: 'customer';
4912
+ name: 'customerId';
4778
4913
  type: 'u16';
4779
4914
  },
4780
4915
  {
@@ -1,7 +1,7 @@
1
- /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
1
  import { PublicKey } from '@solana/web3.js';
3
2
  export declare const USDC_MINT: PublicKey;
4
3
  export declare const TRD_MINT: PublicKey;
4
+ export declare const UNIT_MINT: PublicKey;
5
5
  export declare const TRIAD_ADMIN: PublicKey;
6
6
  export declare const TICKET_CORE_COLLECTION: PublicKey;
7
7
  export declare const POSEIDON_CORE_COLLECTION: PublicKey;
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BOOK_ORDER_NULL = exports.BASE_DECIMALS = exports.TICKET_COLLECTION_SYMBOL = exports.POSEIDON_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.TICKET_CORE_COLLECTION = exports.TRIAD_ADMIN = exports.TRD_MINT = exports.USDC_MINT = void 0;
3
+ exports.BOOK_ORDER_NULL = exports.BASE_DECIMALS = exports.TICKET_COLLECTION_SYMBOL = exports.POSEIDON_COLLECTION_SYMBOL = exports.POSEIDON_CORE_COLLECTION = exports.TICKET_CORE_COLLECTION = exports.TRIAD_ADMIN = exports.UNIT_MINT = exports.TRD_MINT = exports.USDC_MINT = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  exports.USDC_MINT = new web3_js_1.PublicKey('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
6
6
  exports.TRD_MINT = new web3_js_1.PublicKey('t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV');
7
+ exports.UNIT_MINT = new web3_js_1.PublicKey('75wzVU6j9U6oZVJjQYLtiN7Z5Ah97it1UyWZN29HgE4m');
7
8
  exports.TRIAD_ADMIN = new web3_js_1.PublicKey('82ppCojm3yrEKgdpH8B5AmBJTU1r1uAWXFWhxvPs9UCR');
8
9
  exports.TICKET_CORE_COLLECTION = new web3_js_1.PublicKey('BaqopH1VXYUCT6VsojbTibVcd3k5jpGGT6296HFb6fVa');
9
10
  exports.POSEIDON_CORE_COLLECTION = new web3_js_1.PublicKey('69CLccefLRmvDSAJP7Er632dvn878qkpdcnvq5ZUspSm');
@@ -7,7 +7,7 @@ exports.simulateSellOrder = exports.simulateBuyOrder = exports.applySellFee = ex
7
7
  */
8
8
  function calculateDynamicFeeBps(price, feeBps) {
9
9
  const internalPrice = price * Math.pow(10, 6);
10
- if (internalPrice <= 900000) {
10
+ if (internalPrice < 900000) {
11
11
  return feeBps;
12
12
  }
13
13
  return Math.floor(((990000 - internalPrice) * 1900) / price);
@@ -8,16 +8,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const axios_1 = __importDefault(require("axios"));
16
12
  const getPriorityFee = () => __awaiter(void 0, void 0, void 0, function* () {
17
13
  let fee = 1000;
18
14
  try {
19
- const response = yield axios_1.default.get('https://solanacompass.com/api/fees');
20
- fee = response.data[1].priorityTx;
15
+ const response = yield fetch('https://solanacompass.com/api/fees');
16
+ const data = yield response.json();
17
+ fee = data[1].priorityTx;
21
18
  }
22
19
  catch (_a) { }
23
20
  return fee;
@@ -1,9 +1,10 @@
1
1
  import { PublicKey } from '@solana/web3.js';
2
- import { IdlAccounts } from '@coral-xyz/anchor';
2
+ import { BN, IdlAccounts } from '@coral-xyz/anchor';
3
3
  import { Market, Order, OrderDirection, OrderSide, OrderStatus, OrderType, OrderDirectionEncoded, OrderTypeEncoded, OrderSideEncoded, OrderStatusEncoded, Pool, BookOrder } from '../types';
4
4
  import { Stake, StakeVault, Unstake } from '../types/stake';
5
5
  import { Customer } from '../types/customer';
6
6
  import { TriadProtocol } from '../types/triad_protocol';
7
+ import { Predictor } from '../types/predictor';
7
8
  export declare const encodeString: (value: string, alloc?: number) => number[];
8
9
  export declare const decodeString: (bytes: number[]) => string;
9
10
  export declare const formatStakeVault: (stakeVault: IdlAccounts<TriadProtocol>['stakeVault']) => StakeVault;
@@ -25,3 +26,4 @@ export declare const getOrderStatus: (status: OrderStatusEncoded) => OrderStatus
25
26
  export declare const getOrderDirectionEncoded: (orderDirection: OrderDirection) => OrderDirectionEncoded;
26
27
  export declare const getOppositeOrderDirection: (orderDirection: OrderDirection) => OrderDirection;
27
28
  export declare const getOppositeOrderDirectionEncoded: (orderDirection: OrderDirectionEncoded) => OrderDirectionEncoded;
29
+ export declare const formatPredictor: (account: IdlAccounts<TriadProtocol>['predictor'], publicKey: PublicKey, balance: BN) => Predictor;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getOppositeOrderDirectionEncoded = exports.getOppositeOrderDirection = exports.getOrderDirectionEncoded = exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderSideFromNumber = exports.getOrderDirectionFromNumber = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatCustomer = exports.formatBookOrder = exports.formatOrder = exports.formatMarket = exports.formatPool = exports.formatUnstake = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
3
+ exports.formatPredictor = exports.getOppositeOrderDirectionEncoded = exports.getOppositeOrderDirection = exports.getOrderDirectionEncoded = exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderSideFromNumber = exports.getOrderDirectionFromNumber = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatCustomer = exports.formatBookOrder = exports.formatOrder = exports.formatMarket = exports.formatPool = exports.formatUnstake = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
4
4
  const web3_js_1 = require("@solana/web3.js");
5
5
  const spl_token_1 = require("@solana/spl-token");
6
6
  const types_1 = require("../types");
@@ -245,3 +245,13 @@ const getOppositeOrderDirectionEncoded = (orderDirection) => {
245
245
  return { hype: {} };
246
246
  };
247
247
  exports.getOppositeOrderDirectionEncoded = getOppositeOrderDirectionEncoded;
248
+ const formatPredictor = (account, publicKey, balance) => {
249
+ return {
250
+ address: publicKey.toBase58(),
251
+ authority: publicKey.toString(),
252
+ refer: account.refer.toString(),
253
+ customerId: account.customerId,
254
+ balance: balance.toNumber() / 1e6
255
+ };
256
+ };
257
+ exports.formatPredictor = formatPredictor;
@@ -1,4 +1,3 @@
1
- /// <reference types="@coral-xyz/anchor/node_modules/@solana/web3.js" />
2
1
  import { PublicKey } from '@solana/web3.js';
3
2
  import { OrderDirection } from '../types';
4
3
  export declare const getTokenATA: (address: PublicKey, Mint: PublicKey, program?: PublicKey) => PublicKey;
@@ -13,5 +12,5 @@ export declare const getPoseidonPDA: (programId: PublicKey, number: number) => P
13
12
  export declare const getClaimVaultPDA: (programId: PublicKey, name: string) => PublicKey;
14
13
  export declare const getClaimedUserPDA: (programId: PublicKey, claimVault: PublicKey, user: PublicKey) => PublicKey;
15
14
  export declare const getOrderPDA: (programId: PublicKey, authority: PublicKey, marketId: number, orderDirection: OrderDirection) => PublicKey;
16
- export declare const getPredictorPDA: (programId: PublicKey, authority: PublicKey, customer: number) => PublicKey;
15
+ export declare const getPredictorPDA: (programId: PublicKey, authority: PublicKey, customerId: number) => PublicKey;
17
16
  export declare const getCentralPDA: (programId: PublicKey) => PublicKey;
package/dist/utils/pda.js CHANGED
@@ -64,11 +64,11 @@ const getOrderPDA = (programId, authority, marketId, orderDirection) => {
64
64
  ], programId)[0];
65
65
  };
66
66
  exports.getOrderPDA = getOrderPDA;
67
- const getPredictorPDA = (programId, authority, customer) => {
67
+ const getPredictorPDA = (programId, authority, customerId) => {
68
68
  return web3_js_1.PublicKey.findProgramAddressSync([
69
69
  Buffer.from('predictor'),
70
70
  authority.toBuffer(),
71
- new bn_js_1.default(customer).toArrayLike(Buffer, 'le', 2)
71
+ new bn_js_1.default(customerId).toArrayLike(Buffer, 'le', 2)
72
72
  ], programId)[0];
73
73
  };
74
74
  exports.getPredictorPDA = getPredictorPDA;
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "4.0.2",
3
+ "version": "4.0.4-beta.1",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
7
7
  "scripts": {
8
8
  "clean": "rimraf dist",
9
9
  "build": "yarn run clean && tsc",
10
+ "docs": "typedoc",
10
11
  "prepublishOnly": "yarn build"
11
12
  },
12
13
  "publishConfig": {
@@ -34,20 +35,12 @@
34
35
  "@coral-xyz/anchor": "0.30.1",
35
36
  "@solana/spl-token": "0.4.8",
36
37
  "@solana/web3.js": "1.95.3",
37
- "axios": "1.9.0",
38
- "bn.js": "5.2.2",
38
+ "bn.js": "5.2.3",
39
39
  "bs58": "6.0.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@typescript-eslint/eslint-plugin": "6.7.3",
43
- "@typescript-eslint/parser": "6.7.3",
44
42
  "@types/bn.js": "^5.1.0",
45
- "eslint": "8.50.0",
46
- "eslint-config-prettier": "9.0.0",
47
- "eslint-plugin-prettier": "5.0.0",
48
- "prettier": "3.2.4",
49
- "rimraf": "^5.0.5",
50
- "typedoc": "0.25.1",
43
+ "rimraf": "6.1.3",
51
44
  "typescript": "5.2.2"
52
45
  }
53
46
  }