@triadxyz/triad-protocol 1.7.5-beta → 1.7.7-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
@@ -270,6 +270,11 @@ export default class Trade {
270
270
  getUserTradeIxs(): Promise<{
271
271
  userTradePDA: PublicKey;
272
272
  ixs: TransactionInstruction[];
273
+ nonce: number;
274
+ } | {
275
+ userTradePDA: PublicKey;
276
+ ixs: TransactionInstruction[];
277
+ nonce?: undefined;
273
278
  }>;
274
279
  /**
275
280
  * Place Order
@@ -294,17 +299,6 @@ export default class Trade {
294
299
  * @param options - RPC options
295
300
  */
296
301
  cancelOrder({ marketId, orderId, userNonce, orderSide, mint, userNonceBidOrder }: CancelOrderArgs, options?: RpcOptions): Promise<string>;
297
- /**
298
- * Update Customer Fee
299
- * @param args.id - The ID of the Customer
300
- * @param args.feeRecipient - The fee account
301
- *
302
- * @param options - RPC options
303
- */
304
- updateCustomerFee({ id, feeRecipient }: {
305
- id: number;
306
- feeRecipient: PublicKey;
307
- }, options?: RpcOptions): Promise<string>;
308
302
  /**
309
303
  * Market Bid Order
310
304
  * @param args.marketId - The ID of the Market
package/dist/trade.js CHANGED
@@ -408,45 +408,30 @@ class Trade {
408
408
  signer: this.provider.publicKey
409
409
  })
410
410
  .instruction());
411
+ return {
412
+ userTradePDA,
413
+ ixs,
414
+ nonce: 0
415
+ };
411
416
  }
412
- if (myUserTrades.length > 0) {
413
- try {
414
- userTradePDA = yield this.getUserTradeNonceWithSlots(myUserTrades);
415
- // Check if we need to create a new sub user trade
416
- // This happens when all existing slots have open orders
417
- const allSlotsHaveOpenOrders = myUserTrades.every((trade) => trade.orders.some((order) => order.orderStatus === trade_1.OrderStatus.OPEN ||
418
- order.orderStatus === trade_1.OrderStatus.WAITING));
419
- if (allSlotsHaveOpenOrders) {
420
- // Find the main user trade to get the current nonce
421
- const mainUserTrade = myUserTrades.find((userTrade) => !userTrade.isSubUser);
422
- if (!mainUserTrade) {
423
- throw new Error('No main user trade found');
424
- }
425
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, Number(mainUserTrade.nonce) + 1);
426
- ixs.push(yield this.program.methods
427
- .createSubUserTrade(subUserTradePDA)
428
- .accounts({
429
- signer: this.provider.publicKey
430
- })
431
- .instruction());
432
- }
433
- }
434
- catch (error) {
435
- const mainUserTrade = myUserTrades.find((userTrade) => !userTrade.isSubUser);
436
- const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, Number(mainUserTrade.nonce) + 1);
437
- userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
438
- ixs.push(yield this.program.methods
439
- .createSubUserTrade(subUserTradePDA)
440
- .accounts({
441
- signer: this.provider.publicKey
442
- })
443
- .instruction());
444
- }
417
+ try {
418
+ const userTradePDA = yield this.getUserTradeNonceWithSlots(myUserTrades);
419
+ return { userTradePDA, ixs };
420
+ }
421
+ catch (_a) {
422
+ const mainUserTrade = myUserTrades.find((trade) => !trade.isSubUser);
423
+ const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, Number(mainUserTrade.nonce) + 1);
424
+ ixs.push(yield this.program.methods
425
+ .createSubUserTrade(subUserTradePDA)
426
+ .accounts({
427
+ signer: this.provider.publicKey
428
+ })
429
+ .instruction());
430
+ return {
431
+ userTradePDA: (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA),
432
+ ixs
433
+ };
445
434
  }
446
- return {
447
- userTradePDA,
448
- ixs
449
- };
450
435
  });
451
436
  }
452
437
  /**
@@ -466,7 +451,10 @@ class Trade {
466
451
  const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
467
452
  const ixs = [];
468
453
  const { userTradePDA, ixs: userTradeIxs } = yield this.getUserTradeIxs();
469
- ixs.push(...userTradeIxs);
454
+ console.log(userTradePDA);
455
+ if (userTradeIxs.length > 0) {
456
+ ixs.push(...userTradeIxs);
457
+ }
470
458
  if (Object.keys(orderSide)[0] === 'bid') {
471
459
  ixs.push(yield this.program.methods
472
460
  .placeBidOrder({
@@ -539,20 +527,6 @@ class Trade {
539
527
  }), options);
540
528
  });
541
529
  }
542
- /**
543
- * Update Customer Fee
544
- * @param args.id - The ID of the Customer
545
- * @param args.feeRecipient - The fee account
546
- *
547
- * @param options - RPC options
548
- */
549
- updateCustomerFee({ id, feeRecipient }, options) {
550
- return __awaiter(this, void 0, void 0, function* () {
551
- return (0, sendTransactionWithOptions_1.default)(this.program.methods.updateCustomerFee({ id, feeRecipient }).accounts({
552
- signer: this.provider.publicKey
553
- }), options);
554
- });
555
- }
556
530
  /**
557
531
  * Market Bid Order
558
532
  * @param args.marketId - The ID of the Market
@@ -573,7 +547,7 @@ class Trade {
573
547
  ixs.push(yield this.program.methods
574
548
  .marketBidOrder({
575
549
  amount: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
576
- direction
550
+ orderDirection: direction
577
551
  })
578
552
  .accounts({
579
553
  signer: this.provider.publicKey,
@@ -602,10 +576,8 @@ class Trade {
602
576
  8 + // total_deposits
603
577
  8 + // total_withdraws
604
578
  8 + // opened_orders
605
- // Per order: index * (8 + 8 + 8 + 8 + 1 + 8 + 8 + 8 + 1 + 1 + 4 + 28)
606
- index * (8 + 8 + 8 + 8 + 1 + 8 + 8 + 8 + 1 + 1 + 4 + 1 + 27) +
607
- // Then offset to market_id: 8 + 8 + 8
608
- (8 + 8 + 8),
579
+ index * 91 + // total size of each order
580
+ 24,
609
581
  bytes: marketIdBytes
610
582
  }
611
583
  }));
@@ -1476,47 +1476,6 @@
1476
1476
  ],
1477
1477
  "args": []
1478
1478
  },
1479
- {
1480
- "name": "update_customer_fee",
1481
- "discriminator": [218, 240, 1, 38, 34, 166, 40, 25],
1482
- "accounts": [
1483
- {
1484
- "name": "signer",
1485
- "writable": true,
1486
- "signer": true
1487
- },
1488
- {
1489
- "name": "customer",
1490
- "writable": true,
1491
- "pda": {
1492
- "seeds": [
1493
- {
1494
- "kind": "const",
1495
- "value": [99, 117, 115, 116, 111, 109, 101, 114]
1496
- },
1497
- {
1498
- "kind": "arg",
1499
- "path": "args.id"
1500
- }
1501
- ]
1502
- }
1503
- },
1504
- {
1505
- "name": "system_program",
1506
- "address": "11111111111111111111111111111111"
1507
- }
1508
- ],
1509
- "args": [
1510
- {
1511
- "name": "args",
1512
- "type": {
1513
- "defined": {
1514
- "name": "UpdateCustomerFeeArgs"
1515
- }
1516
- }
1517
- }
1518
- ]
1519
- },
1520
1479
  {
1521
1480
  "name": "update_market",
1522
1481
  "discriminator": [153, 39, 2, 197, 179, 50, 199, 217],
@@ -2229,7 +2188,7 @@
2229
2188
  "type": "u64"
2230
2189
  },
2231
2190
  {
2232
- "name": "direction",
2191
+ "name": "order_direction",
2233
2192
  "type": {
2234
2193
  "defined": {
2235
2194
  "name": "OrderDirection"
@@ -3039,22 +2998,6 @@
3039
2998
  ]
3040
2999
  }
3041
3000
  },
3042
- {
3043
- "name": "UpdateCustomerFeeArgs",
3044
- "type": {
3045
- "kind": "struct",
3046
- "fields": [
3047
- {
3048
- "name": "id",
3049
- "type": "u16"
3050
- },
3051
- {
3052
- "name": "fee_recipient",
3053
- "type": "pubkey"
3054
- }
3055
- ]
3056
- }
3057
- },
3058
3001
  {
3059
3002
  "name": "UpdateStakeVaultArgs",
3060
3003
  "type": {
@@ -53,7 +53,7 @@ export type Order = {
53
53
  orderSide: OrderSide;
54
54
  userNonce: string;
55
55
  linkedOrderId: string;
56
- account: string;
56
+ authority: string;
57
57
  createdAt: string;
58
58
  };
59
59
  export declare enum WinningDirection {
@@ -2033,47 +2033,6 @@ export type TriadProtocol = {
2033
2033
  ];
2034
2034
  args: [];
2035
2035
  },
2036
- {
2037
- name: 'updateCustomerFee';
2038
- discriminator: [218, 240, 1, 38, 34, 166, 40, 25];
2039
- accounts: [
2040
- {
2041
- name: 'signer';
2042
- writable: true;
2043
- signer: true;
2044
- },
2045
- {
2046
- name: 'customer';
2047
- writable: true;
2048
- pda: {
2049
- seeds: [
2050
- {
2051
- kind: 'const';
2052
- value: [99, 117, 115, 116, 111, 109, 101, 114];
2053
- },
2054
- {
2055
- kind: 'arg';
2056
- path: 'args.id';
2057
- }
2058
- ];
2059
- };
2060
- },
2061
- {
2062
- name: 'systemProgram';
2063
- address: '11111111111111111111111111111111';
2064
- }
2065
- ];
2066
- args: [
2067
- {
2068
- name: 'args';
2069
- type: {
2070
- defined: {
2071
- name: 'updateCustomerFeeArgs';
2072
- };
2073
- };
2074
- }
2075
- ];
2076
- },
2077
2036
  {
2078
2037
  name: 'updateMarket';
2079
2038
  discriminator: [153, 39, 2, 197, 179, 50, 199, 217];
@@ -2902,7 +2861,7 @@ export type TriadProtocol = {
2902
2861
  type: 'u64';
2903
2862
  },
2904
2863
  {
2905
- name: 'direction';
2864
+ name: 'orderDirection';
2906
2865
  type: {
2907
2866
  defined: {
2908
2867
  name: 'orderDirection';
@@ -3712,22 +3671,6 @@ export type TriadProtocol = {
3712
3671
  ];
3713
3672
  };
3714
3673
  },
3715
- {
3716
- name: 'updateCustomerFeeArgs';
3717
- type: {
3718
- kind: 'struct';
3719
- fields: [
3720
- {
3721
- name: 'id';
3722
- type: 'u16';
3723
- },
3724
- {
3725
- name: 'feeRecipient';
3726
- type: 'pubkey';
3727
- }
3728
- ];
3729
- };
3730
- },
3731
3674
  {
3732
3675
  name: 'updateStakeVaultArgs';
3733
3676
  type: {
@@ -1,12 +1,40 @@
1
1
  import { Stake, StakeVault } from './../types/stake';
2
- import { Market, Order, UserTrade } from '../types/trade';
2
+ import { Market, Order, OrderDirection, OrderSide, OrderStatus, OrderType, UserTrade } from '../types/trade';
3
3
  import { PublicKey } from '@solana/web3.js';
4
4
  export declare const encodeString: (value: string, alloc?: number) => number[];
5
5
  export declare const decodeString: (bytes: number[]) => string;
6
6
  export declare const formatStakeVault: (stakeVault: any) => StakeVault;
7
7
  export declare const formatStake: (stake: any) => Stake;
8
8
  export declare const formatMarket: (account: any, address: PublicKey) => Market;
9
- export declare const formatOrder: (order: any) => Order;
9
+ export declare const formatOrder: (order: any, authority?: string) => Order;
10
10
  export declare const formatUserTrade: (account: any, publicKey: PublicKey) => UserTrade;
11
11
  export declare const calculateStakeRewards: (stake: Stake, multiplier: number) => number;
12
12
  export declare const getTokenProgram: (mint: PublicKey) => PublicKey;
13
+ export declare const getOrderDirection: (direction: {
14
+ hype: {};
15
+ } | {
16
+ flop: {};
17
+ }) => OrderDirection;
18
+ export declare const getOrderType: (type: {
19
+ limit: {};
20
+ } | {
21
+ market: {};
22
+ }) => OrderType;
23
+ export declare const getOrderSide: (side: {
24
+ bid: {};
25
+ } | {
26
+ ask: {};
27
+ }) => OrderSide;
28
+ export declare const getOrderStatus: (status: {
29
+ init: {};
30
+ } | {
31
+ open: {};
32
+ } | {
33
+ closed: {};
34
+ } | {
35
+ claimed: {};
36
+ } | {
37
+ liquidated: {};
38
+ } | {
39
+ waiting: {};
40
+ }) => OrderStatus;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTokenProgram = exports.calculateStakeRewards = exports.formatUserTrade = exports.formatOrder = exports.formatMarket = exports.formatStake = exports.formatStakeVault = exports.decodeString = exports.encodeString = void 0;
3
+ exports.getOrderStatus = exports.getOrderSide = exports.getOrderType = exports.getOrderDirection = exports.getTokenProgram = exports.calculateStakeRewards = exports.formatUserTrade = exports.formatOrder = exports.formatMarket = 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 spl_token_1 = require("@solana/spl-token");
@@ -87,22 +87,22 @@ const formatMarket = (account, address) => {
87
87
  };
88
88
  };
89
89
  exports.formatMarket = formatMarket;
90
- const formatOrder = (order) => {
90
+ const formatOrder = (order, authority) => {
91
91
  return {
92
92
  ts: order.ts.toString(),
93
93
  orderId: order.orderId.toString(),
94
94
  marketId: order.marketId.toString(),
95
- orderStatus: order.orderStatus,
95
+ orderStatus: (0, exports.getOrderStatus)(order.orderStatus),
96
96
  price: order.price.toString(),
97
97
  totalAmount: order.totalAmount.toString(),
98
98
  totalShares: order.totalShares.toString(),
99
- orderType: order.orderType,
100
- orderDirection: order.orderDirection,
101
- orderSide: order.orderSide,
99
+ orderType: (0, exports.getOrderType)(order.orderType),
100
+ orderDirection: (0, exports.getOrderDirection)(order.orderDirection),
101
+ orderSide: (0, exports.getOrderSide)(order.orderSide),
102
102
  userNonce: order.userNonce.toString(),
103
103
  linkedOrderId: order.linkedOrderId,
104
104
  filledShares: order.filledShares ? order.filledShares.toString() : '',
105
- account: order.account,
105
+ authority: authority ? authority : '',
106
106
  createdAt: order.createdAt ? order.createdAt.toString() : ''
107
107
  };
108
108
  };
@@ -149,3 +149,44 @@ const getTokenProgram = (mint) => {
149
149
  return spl_token_2.TOKEN_PROGRAM_ID;
150
150
  };
151
151
  exports.getTokenProgram = getTokenProgram;
152
+ const getOrderDirection = (direction) => {
153
+ if (Object.keys(direction)[0] === 'hype') {
154
+ return trade_1.OrderDirection.HYPE;
155
+ }
156
+ return trade_1.OrderDirection.FLOP;
157
+ };
158
+ exports.getOrderDirection = getOrderDirection;
159
+ const getOrderType = (type) => {
160
+ if (Object.keys(type)[0] === 'limit') {
161
+ return trade_1.OrderType.LIMIT;
162
+ }
163
+ return trade_1.OrderType.MARKET;
164
+ };
165
+ exports.getOrderType = getOrderType;
166
+ const getOrderSide = (side) => {
167
+ if (Object.keys(side)[0] === 'bid') {
168
+ return trade_1.OrderSide.BID;
169
+ }
170
+ return trade_1.OrderSide.ASK;
171
+ };
172
+ exports.getOrderSide = getOrderSide;
173
+ const getOrderStatus = (status) => {
174
+ let currentStatus = Object.keys(status)[0];
175
+ switch (currentStatus) {
176
+ case 'init':
177
+ return trade_1.OrderStatus.INIT;
178
+ case 'open':
179
+ return trade_1.OrderStatus.OPEN;
180
+ case 'closed':
181
+ return trade_1.OrderStatus.CLOSED;
182
+ case 'claimed':
183
+ return trade_1.OrderStatus.CLAIMED;
184
+ case 'liquidated':
185
+ return trade_1.OrderStatus.LIQUIDATED;
186
+ case 'waiting':
187
+ return trade_1.OrderStatus.WAITING;
188
+ default:
189
+ throw new Error('Invalid order status');
190
+ }
191
+ };
192
+ exports.getOrderStatus = getOrderStatus;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "1.7.5-beta",
3
+ "version": "1.7.7-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",