@triadxyz/triad-protocol 1.9.2-beta → 1.9.4-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 +28 -8
- package/dist/trade.js +87 -54
- package/dist/types/idl_triad_protocol.json +8 -8
- package/dist/types/trade.d.ts +21 -10
- package/dist/types/triad_protocol.d.ts +8 -8
- package/dist/utils/helpers.js +2 -2
- package/package.json +1 -1
package/dist/trade.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
2
2
|
import { TriadProtocol } from './types/triad_protocol';
|
|
3
3
|
import { PublicKey, TransactionInstruction } from '@solana/web3.js';
|
|
4
|
-
import { CreateMarketArgs, OpenOrderArgs, UserTrade, CreateCustomerArgs,
|
|
4
|
+
import { CreateMarketArgs, OpenOrderArgs, UserTrade, CreateCustomerArgs, Order, MarketBidOrderArgs, UpdateMarketAdminArgs, CancelBidOrderArgs, CancelAskOrderArgs, PlaceBidOrderArgs, PlaceAskOrderArgs } from './types/trade';
|
|
5
5
|
import { RpcOptions } from './types';
|
|
6
6
|
import BN from 'bn.js';
|
|
7
7
|
export default class Trade {
|
|
@@ -136,8 +136,8 @@ export default class Trade {
|
|
|
136
136
|
ask: Record<string, never>;
|
|
137
137
|
});
|
|
138
138
|
linkedOrderId: BN;
|
|
139
|
-
linkedAskOrderId: BN;
|
|
140
139
|
createdAt: BN;
|
|
140
|
+
linkedBidOrderId: BN;
|
|
141
141
|
padding: number[];
|
|
142
142
|
}[];
|
|
143
143
|
nonce: number;
|
|
@@ -277,28 +277,48 @@ export default class Trade {
|
|
|
277
277
|
nonce?: undefined;
|
|
278
278
|
}>;
|
|
279
279
|
/**
|
|
280
|
-
* Place Order
|
|
280
|
+
* Place Bid Order
|
|
281
281
|
* @param args.marketId - The ID of the Market
|
|
282
282
|
* @param args.amount - The amount of the Order
|
|
283
283
|
* @param args.direction - The direction of the Order
|
|
284
|
-
* @param args.orderSide - The side of the Order
|
|
285
284
|
* @param args.mint - The mint of the Order
|
|
286
285
|
* @param args.price - The price of the Order
|
|
287
286
|
*
|
|
288
287
|
* @param options - RPC options
|
|
288
|
+
*/
|
|
289
|
+
placeBidOrder({ marketId, amount, direction, mint, price }: PlaceBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
290
|
+
/**
|
|
291
|
+
* Place Ask Order
|
|
292
|
+
* @param args.marketId - The ID of the Market
|
|
293
|
+
* @param args.amount - The amount of the Order
|
|
294
|
+
* @param args.direction - The direction of the Order
|
|
295
|
+
* @param args.price - The price of the Order
|
|
296
|
+
* @param args.bidOrderId - The ID of the Bid Order
|
|
297
|
+
* @param args.bidNonce - The nonce of the Bid Order
|
|
298
|
+
*
|
|
299
|
+
* @param options - RPC options
|
|
289
300
|
*
|
|
290
301
|
*/
|
|
291
|
-
|
|
302
|
+
placeAskOrder({ marketId, amount, direction, price, bidOrderId, bidNonce }: PlaceAskOrderArgs, options?: RpcOptions): Promise<string>;
|
|
303
|
+
/**
|
|
304
|
+
* Cancel Bid Order
|
|
305
|
+
* @param args.marketId - The ID of the Market
|
|
306
|
+
* @param args.orderId - The ID of the Order
|
|
307
|
+
* @param args.userNonce - The nonce of the user
|
|
308
|
+
*
|
|
309
|
+
* @param options - RPC options
|
|
310
|
+
*/
|
|
311
|
+
cancelBidOrder({ marketId, orderId, userNonce, mint }: CancelBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
292
312
|
/**
|
|
293
|
-
* Cancel Order
|
|
313
|
+
* Cancel Ask Order
|
|
294
314
|
* @param args.marketId - The ID of the Market
|
|
295
315
|
* @param args.orderId - The ID of the Order
|
|
296
316
|
* @param args.userNonce - The nonce of the user
|
|
297
|
-
* @param args.
|
|
317
|
+
* @param args.userNonceBidOrder - The nonce of the bid user
|
|
298
318
|
*
|
|
299
319
|
* @param options - RPC options
|
|
300
320
|
*/
|
|
301
|
-
|
|
321
|
+
cancelAskOrder({ marketId, orderId, userNonce, userNonceBidOrder }: CancelAskOrderArgs, options?: RpcOptions): Promise<string>;
|
|
302
322
|
/**
|
|
303
323
|
* Market Bid Order
|
|
304
324
|
* @param args.marketId - The ID of the Market
|
package/dist/trade.js
CHANGED
|
@@ -413,18 +413,16 @@ class Trade {
|
|
|
413
413
|
});
|
|
414
414
|
}
|
|
415
415
|
/**
|
|
416
|
-
* Place Order
|
|
416
|
+
* Place Bid Order
|
|
417
417
|
* @param args.marketId - The ID of the Market
|
|
418
418
|
* @param args.amount - The amount of the Order
|
|
419
419
|
* @param args.direction - The direction of the Order
|
|
420
|
-
* @param args.orderSide - The side of the Order
|
|
421
420
|
* @param args.mint - The mint of the Order
|
|
422
421
|
* @param args.price - The price of the Order
|
|
423
422
|
*
|
|
424
423
|
* @param options - RPC options
|
|
425
|
-
*
|
|
426
424
|
*/
|
|
427
|
-
|
|
425
|
+
placeBidOrder({ marketId, amount, direction, mint, price }, options) {
|
|
428
426
|
return __awaiter(this, void 0, void 0, function* () {
|
|
429
427
|
const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
|
|
430
428
|
const ixs = [];
|
|
@@ -432,81 +430,116 @@ class Trade {
|
|
|
432
430
|
if (userTradeIxs.length > 0) {
|
|
433
431
|
ixs.push(...userTradeIxs);
|
|
434
432
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
433
|
+
ixs.push(yield this.program.methods
|
|
434
|
+
.placeBidOrder({
|
|
435
|
+
amount: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
|
|
436
|
+
price: new bn_js_1.default(price * Math.pow(10, this.decimals)),
|
|
437
|
+
orderDirection: direction
|
|
438
|
+
})
|
|
439
|
+
.accounts({
|
|
440
|
+
signer: this.provider.publicKey,
|
|
441
|
+
market: marketPDA,
|
|
442
|
+
userTrade: userTradePDA,
|
|
443
|
+
mint,
|
|
444
|
+
tokenProgram: (0, helpers_1.getTokenProgram)(mint)
|
|
445
|
+
})
|
|
446
|
+
.instruction());
|
|
447
|
+
return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Place Ask Order
|
|
452
|
+
* @param args.marketId - The ID of the Market
|
|
453
|
+
* @param args.amount - The amount of the Order
|
|
454
|
+
* @param args.direction - The direction of the Order
|
|
455
|
+
* @param args.price - The price of the Order
|
|
456
|
+
* @param args.bidOrderId - The ID of the Bid Order
|
|
457
|
+
* @param args.bidNonce - The nonce of the Bid Order
|
|
458
|
+
*
|
|
459
|
+
* @param options - RPC options
|
|
460
|
+
*
|
|
461
|
+
*/
|
|
462
|
+
placeAskOrder({ marketId, amount, direction, price, bidOrderId, bidNonce }, options) {
|
|
463
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
464
|
+
const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
|
|
465
|
+
const ixs = [];
|
|
466
|
+
const { userTradePDA: askUserTradePDA, ixs: userTradeIxs } = yield this.getUserTradeIxs();
|
|
467
|
+
if (userTradeIxs.length > 0) {
|
|
468
|
+
ixs.push(...userTradeIxs);
|
|
450
469
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
456
|
-
}
|
|
457
|
-
ixs.push(yield this.program.methods
|
|
458
|
-
.placeAskOrder({
|
|
459
|
-
shares: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
|
|
460
|
-
price: new bn_js_1.default(price * Math.pow(10, this.decimals)),
|
|
461
|
-
bidOrderId: new bn_js_1.default(bidOrderId),
|
|
462
|
-
orderDirection: direction
|
|
463
|
-
})
|
|
464
|
-
.accounts({
|
|
465
|
-
signer: this.provider.publicKey,
|
|
466
|
-
market: marketPDA,
|
|
467
|
-
askUserTrade: userTradePDA,
|
|
468
|
-
bidUserTrade: bidUserTradePDA
|
|
469
|
-
})
|
|
470
|
-
.instruction());
|
|
470
|
+
let bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
471
|
+
if (bidNonce !== 0) {
|
|
472
|
+
const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, bidNonce);
|
|
473
|
+
bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
471
474
|
}
|
|
475
|
+
ixs.push(yield this.program.methods
|
|
476
|
+
.placeAskOrder({
|
|
477
|
+
shares: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
|
|
478
|
+
price: new bn_js_1.default(price * Math.pow(10, this.decimals)),
|
|
479
|
+
bidOrderId: new bn_js_1.default(bidOrderId),
|
|
480
|
+
orderDirection: direction
|
|
481
|
+
})
|
|
482
|
+
.accounts({
|
|
483
|
+
signer: this.provider.publicKey,
|
|
484
|
+
market: marketPDA,
|
|
485
|
+
askUserTrade: askUserTradePDA,
|
|
486
|
+
bidUserTrade: bidUserTradePDA
|
|
487
|
+
})
|
|
488
|
+
.instruction());
|
|
472
489
|
return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
|
|
473
490
|
});
|
|
474
491
|
}
|
|
475
492
|
/**
|
|
476
|
-
* Cancel Order
|
|
493
|
+
* Cancel Bid Order
|
|
477
494
|
* @param args.marketId - The ID of the Market
|
|
478
495
|
* @param args.orderId - The ID of the Order
|
|
479
496
|
* @param args.userNonce - The nonce of the user
|
|
480
|
-
* @param args.orderSide - The side of the Order
|
|
481
497
|
*
|
|
482
498
|
* @param options - RPC options
|
|
483
499
|
*/
|
|
484
|
-
|
|
500
|
+
cancelBidOrder({ marketId, orderId, userNonce, mint }, options) {
|
|
485
501
|
return __awaiter(this, void 0, void 0, function* () {
|
|
486
502
|
const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
|
|
487
503
|
let userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
488
|
-
let bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
489
504
|
if (userNonce !== 0) {
|
|
490
505
|
const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, userNonce);
|
|
491
506
|
userTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
492
507
|
}
|
|
493
|
-
|
|
508
|
+
return (0, sendTransactionWithOptions_1.default)(this.program.methods.cancelBidOrder(new bn_js_1.default(orderId)).accounts({
|
|
509
|
+
signer: this.provider.publicKey,
|
|
510
|
+
market: marketPDA,
|
|
511
|
+
userTrade: userTradePDA,
|
|
512
|
+
mint,
|
|
513
|
+
tokenProgram: (0, helpers_1.getTokenProgram)(mint)
|
|
514
|
+
}), options);
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* Cancel Ask Order
|
|
519
|
+
* @param args.marketId - The ID of the Market
|
|
520
|
+
* @param args.orderId - The ID of the Order
|
|
521
|
+
* @param args.userNonce - The nonce of the user
|
|
522
|
+
* @param args.userNonceBidOrder - The nonce of the bid user
|
|
523
|
+
*
|
|
524
|
+
* @param options - RPC options
|
|
525
|
+
*/
|
|
526
|
+
cancelAskOrder({ marketId, orderId, userNonce, userNonceBidOrder }, options) {
|
|
527
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
528
|
+
const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
|
|
529
|
+
let askUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
530
|
+
if (userNonce !== 0) {
|
|
531
|
+
const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, userNonce);
|
|
532
|
+
askUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
533
|
+
}
|
|
534
|
+
let bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
535
|
+
if (userNonceBidOrder !== 0) {
|
|
494
536
|
const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, userNonceBidOrder);
|
|
495
537
|
bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
496
538
|
}
|
|
497
|
-
if (orderSide === trade_1.OrderSide.BID) {
|
|
498
|
-
return (0, sendTransactionWithOptions_1.default)(this.program.methods.cancelBidOrder(new bn_js_1.default(orderId)).accounts({
|
|
499
|
-
signer: this.provider.publicKey,
|
|
500
|
-
market: marketPDA,
|
|
501
|
-
userTrade: userTradePDA,
|
|
502
|
-
mint,
|
|
503
|
-
tokenProgram: (0, helpers_1.getTokenProgram)(mint)
|
|
504
|
-
}), options);
|
|
505
|
-
}
|
|
506
539
|
return (0, sendTransactionWithOptions_1.default)(this.program.methods.cancelAskOrder(new bn_js_1.default(orderId)).accounts({
|
|
507
540
|
signer: this.provider.publicKey,
|
|
508
541
|
market: marketPDA,
|
|
509
|
-
askUserTrade:
|
|
542
|
+
askUserTrade: askUserTradePDA,
|
|
510
543
|
bidUserTrade: bidUserTradePDA
|
|
511
544
|
}), options);
|
|
512
545
|
});
|
|
@@ -2686,14 +2686,14 @@
|
|
|
2686
2686
|
"name": "linked_order_id",
|
|
2687
2687
|
"type": "u64"
|
|
2688
2688
|
},
|
|
2689
|
-
{
|
|
2690
|
-
"name": "linked_ask_order_id",
|
|
2691
|
-
"type": "u64"
|
|
2692
|
-
},
|
|
2693
2689
|
{
|
|
2694
2690
|
"name": "created_at",
|
|
2695
2691
|
"type": "i64"
|
|
2696
2692
|
},
|
|
2693
|
+
{
|
|
2694
|
+
"name": "linked_bid_order_id",
|
|
2695
|
+
"type": "u64"
|
|
2696
|
+
},
|
|
2697
2697
|
{
|
|
2698
2698
|
"name": "padding",
|
|
2699
2699
|
"type": {
|
|
@@ -2802,13 +2802,13 @@
|
|
|
2802
2802
|
"name": "linked_order_id",
|
|
2803
2803
|
"type": "u64"
|
|
2804
2804
|
},
|
|
2805
|
-
{
|
|
2806
|
-
"name": "linked_ask_order_id",
|
|
2807
|
-
"type": "u64"
|
|
2808
|
-
},
|
|
2809
2805
|
{
|
|
2810
2806
|
"name": "created_at",
|
|
2811
2807
|
"type": "i64"
|
|
2808
|
+
},
|
|
2809
|
+
{
|
|
2810
|
+
"name": "linked_bid_order_id",
|
|
2811
|
+
"type": "u64"
|
|
2812
2812
|
}
|
|
2813
2813
|
]
|
|
2814
2814
|
}
|
package/dist/types/trade.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export type Order = {
|
|
|
52
52
|
orderSide: OrderSide;
|
|
53
53
|
userNonce: string;
|
|
54
54
|
linkedOrderId: string;
|
|
55
|
-
|
|
55
|
+
linkedBidOrderId: string;
|
|
56
56
|
authority: string;
|
|
57
57
|
createdAt: string;
|
|
58
58
|
};
|
|
@@ -82,7 +82,7 @@ export declare enum OrderSide {
|
|
|
82
82
|
BID = "bid",
|
|
83
83
|
ASK = "ask"
|
|
84
84
|
}
|
|
85
|
-
export type
|
|
85
|
+
export type PlaceBidOrderArgs = {
|
|
86
86
|
marketId: number;
|
|
87
87
|
amount: number;
|
|
88
88
|
price: number;
|
|
@@ -91,15 +91,22 @@ export type PlaceOrderArgs = {
|
|
|
91
91
|
} | {
|
|
92
92
|
flop: {};
|
|
93
93
|
};
|
|
94
|
-
orderSide: {
|
|
95
|
-
bid: {};
|
|
96
|
-
} | {
|
|
97
|
-
ask: {};
|
|
98
|
-
};
|
|
99
94
|
mint: PublicKey;
|
|
100
95
|
bidOrderId: number | null;
|
|
101
96
|
bidNonce: number | null;
|
|
102
97
|
};
|
|
98
|
+
export type PlaceAskOrderArgs = {
|
|
99
|
+
marketId: number;
|
|
100
|
+
amount: number;
|
|
101
|
+
price: number;
|
|
102
|
+
direction: {
|
|
103
|
+
hype: {};
|
|
104
|
+
} | {
|
|
105
|
+
flop: {};
|
|
106
|
+
};
|
|
107
|
+
bidOrderId: number;
|
|
108
|
+
bidNonce: number;
|
|
109
|
+
};
|
|
103
110
|
export type InitializeMarketArgs = {
|
|
104
111
|
marketId: number;
|
|
105
112
|
startTime: number;
|
|
@@ -147,13 +154,17 @@ export type CreateMarketArgs = {
|
|
|
147
154
|
payoutFee: number;
|
|
148
155
|
mint: PublicKey;
|
|
149
156
|
};
|
|
150
|
-
export type
|
|
157
|
+
export type CancelBidOrderArgs = {
|
|
151
158
|
marketId: number;
|
|
152
159
|
orderId: number;
|
|
153
160
|
userNonce: number;
|
|
154
|
-
orderSide: OrderSide;
|
|
155
161
|
mint: PublicKey;
|
|
156
|
-
|
|
162
|
+
};
|
|
163
|
+
export type CancelAskOrderArgs = {
|
|
164
|
+
marketId: number;
|
|
165
|
+
orderId: number;
|
|
166
|
+
userNonce: number;
|
|
167
|
+
userNonceBidOrder: number;
|
|
157
168
|
};
|
|
158
169
|
export type MarketBidOrderArgs = {
|
|
159
170
|
marketId: number;
|
|
@@ -3388,14 +3388,14 @@ export type TriadProtocol = {
|
|
|
3388
3388
|
name: 'linkedOrderId';
|
|
3389
3389
|
type: 'u64';
|
|
3390
3390
|
},
|
|
3391
|
-
{
|
|
3392
|
-
name: 'linkedAskOrderId';
|
|
3393
|
-
type: 'u64';
|
|
3394
|
-
},
|
|
3395
3391
|
{
|
|
3396
3392
|
name: 'createdAt';
|
|
3397
3393
|
type: 'i64';
|
|
3398
3394
|
},
|
|
3395
|
+
{
|
|
3396
|
+
name: 'linkedBidOrderId';
|
|
3397
|
+
type: 'u64';
|
|
3398
|
+
},
|
|
3399
3399
|
{
|
|
3400
3400
|
name: 'padding';
|
|
3401
3401
|
type: {
|
|
@@ -3504,13 +3504,13 @@ export type TriadProtocol = {
|
|
|
3504
3504
|
name: 'linkedOrderId';
|
|
3505
3505
|
type: 'u64';
|
|
3506
3506
|
},
|
|
3507
|
-
{
|
|
3508
|
-
name: 'linkedAskOrderId';
|
|
3509
|
-
type: 'u64';
|
|
3510
|
-
},
|
|
3511
3507
|
{
|
|
3512
3508
|
name: 'createdAt';
|
|
3513
3509
|
type: 'i64';
|
|
3510
|
+
},
|
|
3511
|
+
{
|
|
3512
|
+
name: 'linkedBidOrderId';
|
|
3513
|
+
type: 'u64';
|
|
3514
3514
|
}
|
|
3515
3515
|
];
|
|
3516
3516
|
};
|
package/dist/utils/helpers.js
CHANGED
|
@@ -102,8 +102,8 @@ const formatOrder = (order, authority) => {
|
|
|
102
102
|
orderSide: (0, exports.getOrderSide)(order.orderSide),
|
|
103
103
|
userNonce: order.userNonce.toString(),
|
|
104
104
|
linkedOrderId: order.linkedOrderId ? order.linkedOrderId.toString() : '',
|
|
105
|
-
|
|
106
|
-
? order.
|
|
105
|
+
linkedBidOrderId: order.linkedBidOrderId
|
|
106
|
+
? order.linkedBidOrderId.toString()
|
|
107
107
|
: '',
|
|
108
108
|
filledShares: order.filledShares ? order.filledShares.toString() : '',
|
|
109
109
|
authority: authority ? authority : '',
|