@triadxyz/triad-protocol 1.8.7-beta → 1.8.9-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 +2 -3
- package/dist/trade.js +17 -8
- package/dist/types/idl_triad_protocol.json +11 -56
- package/dist/types/trade.d.ts +1 -1
- package/dist/types/triad_protocol.d.ts +8 -111
- package/dist/utils/helpers.js +0 -1
- package/dist/utils/pda/index.d.ts +1 -1
- package/dist/utils/pda/index.js +2 -2
- package/package.json +2 -3
package/dist/trade.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ import BN from 'bn.js';
|
|
|
7
7
|
export default class Trade {
|
|
8
8
|
private program;
|
|
9
9
|
private provider;
|
|
10
|
-
mint: PublicKey;
|
|
11
10
|
decimals: number;
|
|
12
11
|
constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
|
|
13
12
|
/**
|
|
@@ -50,7 +49,7 @@ export default class Trade {
|
|
|
50
49
|
authority: PublicKey;
|
|
51
50
|
totalDeposits: BN;
|
|
52
51
|
totalWithdraws: BN;
|
|
53
|
-
|
|
52
|
+
padding2: number[];
|
|
54
53
|
orders: {
|
|
55
54
|
ts: BN;
|
|
56
55
|
orderId: BN;
|
|
@@ -288,7 +287,7 @@ export default class Trade {
|
|
|
288
287
|
* @param options - RPC options
|
|
289
288
|
*
|
|
290
289
|
*/
|
|
291
|
-
placeOrder({ marketId, amount, direction, orderSide, mint, price, bidOrderId }: PlaceOrderArgs, options?: RpcOptions): Promise<string>;
|
|
290
|
+
placeOrder({ marketId, amount, direction, orderSide, mint, price, bidOrderId, bidNonce }: PlaceOrderArgs, options?: RpcOptions): Promise<string>;
|
|
292
291
|
/**
|
|
293
292
|
* Cancel Order
|
|
294
293
|
* @param args.marketId - The ID of the Market
|
package/dist/trade.js
CHANGED
|
@@ -21,11 +21,11 @@ const trade_2 = require("./utils/pda/trade");
|
|
|
21
21
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
22
22
|
const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
|
|
23
23
|
const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
|
|
24
|
+
const pda_1 = require("./utils/pda");
|
|
24
25
|
class Trade {
|
|
25
26
|
constructor(program, provider) {
|
|
26
27
|
this.program = program;
|
|
27
28
|
this.provider = provider;
|
|
28
|
-
this.mint = constants_1.TRD_MINT;
|
|
29
29
|
this.decimals = constants_1.TRD_DECIMALS; // We're using only TRD or USDC so we can use the same decimals 6
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
@@ -196,7 +196,7 @@ class Trade {
|
|
|
196
196
|
return (0, sendTransactionWithOptions_1.default)(this.program.methods.closeOrder(new bn_js_1.default(orderId)).accounts({
|
|
197
197
|
signer: this.provider.publicKey,
|
|
198
198
|
market: marketPDA,
|
|
199
|
-
mint:
|
|
199
|
+
mint: constants_1.TRD_MINT,
|
|
200
200
|
userTrade: userTradePDA
|
|
201
201
|
}), options);
|
|
202
202
|
});
|
|
@@ -424,12 +424,11 @@ class Trade {
|
|
|
424
424
|
* @param options - RPC options
|
|
425
425
|
*
|
|
426
426
|
*/
|
|
427
|
-
placeOrder({ marketId, amount, direction, orderSide, mint, price, bidOrderId }, options) {
|
|
427
|
+
placeOrder({ marketId, amount, direction, orderSide, mint, price, bidOrderId, bidNonce }, options) {
|
|
428
428
|
return __awaiter(this, void 0, void 0, function* () {
|
|
429
429
|
const marketPDA = (0, trade_2.getMarketPDA)(this.program.programId, marketId);
|
|
430
430
|
const ixs = [];
|
|
431
431
|
const { userTradePDA, ixs: userTradeIxs } = yield this.getUserTradeIxs();
|
|
432
|
-
console.log(userTradePDA);
|
|
433
432
|
if (userTradeIxs.length > 0) {
|
|
434
433
|
ixs.push(...userTradeIxs);
|
|
435
434
|
}
|
|
@@ -450,6 +449,11 @@ class Trade {
|
|
|
450
449
|
.instruction());
|
|
451
450
|
}
|
|
452
451
|
if (Object.keys(orderSide)[0] === 'ask' && bidOrderId) {
|
|
452
|
+
let bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, this.provider.publicKey);
|
|
453
|
+
if (bidNonce !== 0) {
|
|
454
|
+
const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, this.provider.publicKey, bidNonce);
|
|
455
|
+
bidUserTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
456
|
+
}
|
|
453
457
|
ixs.push(yield this.program.methods
|
|
454
458
|
.placeAskOrder({
|
|
455
459
|
shares: new bn_js_1.default(amount * Math.pow(10, this.decimals)),
|
|
@@ -460,7 +464,8 @@ class Trade {
|
|
|
460
464
|
.accounts({
|
|
461
465
|
signer: this.provider.publicKey,
|
|
462
466
|
market: marketPDA,
|
|
463
|
-
userTrade: userTradePDA
|
|
467
|
+
userTrade: userTradePDA,
|
|
468
|
+
bidUserTrade: bidUserTradePDA
|
|
464
469
|
})
|
|
465
470
|
.instruction());
|
|
466
471
|
}
|
|
@@ -501,7 +506,7 @@ class Trade {
|
|
|
501
506
|
return (0, sendTransactionWithOptions_1.default)(this.program.methods.cancelAskOrder(new bn_js_1.default(orderId)).accounts({
|
|
502
507
|
signer: this.provider.publicKey,
|
|
503
508
|
market: marketPDA,
|
|
504
|
-
|
|
509
|
+
askUserTrade: userTradePDA,
|
|
505
510
|
bidUserTrade: bidUserTradePDA
|
|
506
511
|
}), options);
|
|
507
512
|
});
|
|
@@ -532,6 +537,7 @@ class Trade {
|
|
|
532
537
|
if (order.authority === this.provider.publicKey.toBase58()) {
|
|
533
538
|
continue;
|
|
534
539
|
}
|
|
540
|
+
console.log(order);
|
|
535
541
|
const orderPrice = Number(order.price);
|
|
536
542
|
const maxSharesForPrice = remainingUSDC / orderPrice;
|
|
537
543
|
const availableShares = Number(order.totalShares);
|
|
@@ -542,6 +548,7 @@ class Trade {
|
|
|
542
548
|
const subUserTradePDA = (0, trade_2.getSubUserTradePDA)(this.program.programId, new web3_js_1.PublicKey(order.authority), Number(order.userNonce));
|
|
543
549
|
sellerTradePDA = (0, trade_2.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
544
550
|
}
|
|
551
|
+
const tokenProgram = (0, helpers_1.getTokenProgram)(mint);
|
|
545
552
|
ixs.push(yield this.program.methods
|
|
546
553
|
.marketBidOrder({
|
|
547
554
|
amount: new bn_js_1.default(usdcAmount),
|
|
@@ -554,8 +561,10 @@ class Trade {
|
|
|
554
561
|
buyerTrade,
|
|
555
562
|
sellerTrade: sellerTradePDA,
|
|
556
563
|
mint,
|
|
557
|
-
tokenProgram
|
|
558
|
-
sellerAuthority: new web3_js_1.PublicKey(order.authority)
|
|
564
|
+
tokenProgram,
|
|
565
|
+
sellerAuthority: new web3_js_1.PublicKey(order.authority),
|
|
566
|
+
marketToAta: (0, pda_1.getTokenATA)(marketPDA, mint, tokenProgram),
|
|
567
|
+
userFromAta: (0, pda_1.getTokenATA)(this.provider.publicKey, mint, tokenProgram)
|
|
559
568
|
})
|
|
560
569
|
.instruction());
|
|
561
570
|
remainingUSDC -= usdcAmount;
|
|
@@ -74,15 +74,15 @@
|
|
|
74
74
|
"signer": true
|
|
75
75
|
},
|
|
76
76
|
{
|
|
77
|
-
"name": "
|
|
77
|
+
"name": "ask_user_trade",
|
|
78
78
|
"writable": true
|
|
79
79
|
},
|
|
80
80
|
{
|
|
81
|
-
"name": "
|
|
81
|
+
"name": "bid_user_trade",
|
|
82
82
|
"writable": true
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
|
-
"name": "
|
|
85
|
+
"name": "market",
|
|
86
86
|
"writable": true
|
|
87
87
|
},
|
|
88
88
|
{
|
|
@@ -856,7 +856,8 @@
|
|
|
856
856
|
},
|
|
857
857
|
{
|
|
858
858
|
"name": "squads",
|
|
859
|
-
"writable": true
|
|
859
|
+
"writable": true,
|
|
860
|
+
"address": "6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq"
|
|
860
861
|
},
|
|
861
862
|
{
|
|
862
863
|
"name": "seller_authority",
|
|
@@ -880,59 +881,11 @@
|
|
|
880
881
|
},
|
|
881
882
|
{
|
|
882
883
|
"name": "user_from_ata",
|
|
883
|
-
"writable": true
|
|
884
|
-
"pda": {
|
|
885
|
-
"seeds": [
|
|
886
|
-
{
|
|
887
|
-
"kind": "account",
|
|
888
|
-
"path": "signer"
|
|
889
|
-
},
|
|
890
|
-
{
|
|
891
|
-
"kind": "account",
|
|
892
|
-
"path": "token_program"
|
|
893
|
-
},
|
|
894
|
-
{
|
|
895
|
-
"kind": "account",
|
|
896
|
-
"path": "mint"
|
|
897
|
-
}
|
|
898
|
-
],
|
|
899
|
-
"program": {
|
|
900
|
-
"kind": "const",
|
|
901
|
-
"value": [
|
|
902
|
-
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
|
|
903
|
-
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
|
|
904
|
-
219, 233, 248, 89
|
|
905
|
-
]
|
|
906
|
-
}
|
|
907
|
-
}
|
|
884
|
+
"writable": true
|
|
908
885
|
},
|
|
909
886
|
{
|
|
910
887
|
"name": "market_to_ata",
|
|
911
|
-
"writable": true
|
|
912
|
-
"pda": {
|
|
913
|
-
"seeds": [
|
|
914
|
-
{
|
|
915
|
-
"kind": "account",
|
|
916
|
-
"path": "market"
|
|
917
|
-
},
|
|
918
|
-
{
|
|
919
|
-
"kind": "account",
|
|
920
|
-
"path": "token_program"
|
|
921
|
-
},
|
|
922
|
-
{
|
|
923
|
-
"kind": "account",
|
|
924
|
-
"path": "mint"
|
|
925
|
-
}
|
|
926
|
-
],
|
|
927
|
-
"program": {
|
|
928
|
-
"kind": "const",
|
|
929
|
-
"value": [
|
|
930
|
-
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
|
|
931
|
-
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
|
|
932
|
-
219, 233, 248, 89
|
|
933
|
-
]
|
|
934
|
-
}
|
|
935
|
-
}
|
|
888
|
+
"writable": true
|
|
936
889
|
},
|
|
937
890
|
{
|
|
938
891
|
"name": "seller_to_ata",
|
|
@@ -3208,8 +3161,10 @@
|
|
|
3208
3161
|
"type": "u64"
|
|
3209
3162
|
},
|
|
3210
3163
|
{
|
|
3211
|
-
"name": "
|
|
3212
|
-
"type":
|
|
3164
|
+
"name": "padding_2",
|
|
3165
|
+
"type": {
|
|
3166
|
+
"array": ["u8", 8]
|
|
3167
|
+
}
|
|
3213
3168
|
},
|
|
3214
3169
|
{
|
|
3215
3170
|
"name": "orders",
|
package/dist/types/trade.d.ts
CHANGED
|
@@ -33,7 +33,6 @@ export type UserTrade = {
|
|
|
33
33
|
user: string;
|
|
34
34
|
totalDeposits: string;
|
|
35
35
|
totalWithdraws: string;
|
|
36
|
-
openedOrders: string;
|
|
37
36
|
orders: Order[];
|
|
38
37
|
nonce: string;
|
|
39
38
|
poseidon: string;
|
|
@@ -98,6 +97,7 @@ export type PlaceOrderArgs = {
|
|
|
98
97
|
};
|
|
99
98
|
mint: PublicKey;
|
|
100
99
|
bidOrderId: number | null;
|
|
100
|
+
bidNonce: number | null;
|
|
101
101
|
};
|
|
102
102
|
export type InitializeMarketArgs = {
|
|
103
103
|
marketId: number;
|
|
@@ -80,15 +80,15 @@ export type TriadProtocol = {
|
|
|
80
80
|
signer: true;
|
|
81
81
|
},
|
|
82
82
|
{
|
|
83
|
-
name: '
|
|
83
|
+
name: 'askUserTrade';
|
|
84
84
|
writable: true;
|
|
85
85
|
},
|
|
86
86
|
{
|
|
87
|
-
name: '
|
|
87
|
+
name: 'bidUserTrade';
|
|
88
88
|
writable: true;
|
|
89
89
|
},
|
|
90
90
|
{
|
|
91
|
-
name: '
|
|
91
|
+
name: 'market';
|
|
92
92
|
writable: true;
|
|
93
93
|
},
|
|
94
94
|
{
|
|
@@ -1182,6 +1182,7 @@ export type TriadProtocol = {
|
|
|
1182
1182
|
{
|
|
1183
1183
|
name: 'squads';
|
|
1184
1184
|
writable: true;
|
|
1185
|
+
address: '6fcSf6qfwPNR9AUUNC1UWYZDy5cQ4TzTb2aaipN2zFdq';
|
|
1185
1186
|
},
|
|
1186
1187
|
{
|
|
1187
1188
|
name: 'sellerAuthority';
|
|
@@ -1206,116 +1207,10 @@ export type TriadProtocol = {
|
|
|
1206
1207
|
{
|
|
1207
1208
|
name: 'userFromAta';
|
|
1208
1209
|
writable: true;
|
|
1209
|
-
pda: {
|
|
1210
|
-
seeds: [
|
|
1211
|
-
{
|
|
1212
|
-
kind: 'account';
|
|
1213
|
-
path: 'signer';
|
|
1214
|
-
},
|
|
1215
|
-
{
|
|
1216
|
-
kind: 'account';
|
|
1217
|
-
path: 'tokenProgram';
|
|
1218
|
-
},
|
|
1219
|
-
{
|
|
1220
|
-
kind: 'account';
|
|
1221
|
-
path: 'mint';
|
|
1222
|
-
}
|
|
1223
|
-
];
|
|
1224
|
-
program: {
|
|
1225
|
-
kind: 'const';
|
|
1226
|
-
value: [
|
|
1227
|
-
140,
|
|
1228
|
-
151,
|
|
1229
|
-
37,
|
|
1230
|
-
143,
|
|
1231
|
-
78,
|
|
1232
|
-
36,
|
|
1233
|
-
137,
|
|
1234
|
-
241,
|
|
1235
|
-
187,
|
|
1236
|
-
61,
|
|
1237
|
-
16,
|
|
1238
|
-
41,
|
|
1239
|
-
20,
|
|
1240
|
-
142,
|
|
1241
|
-
13,
|
|
1242
|
-
131,
|
|
1243
|
-
11,
|
|
1244
|
-
90,
|
|
1245
|
-
19,
|
|
1246
|
-
153,
|
|
1247
|
-
218,
|
|
1248
|
-
255,
|
|
1249
|
-
16,
|
|
1250
|
-
132,
|
|
1251
|
-
4,
|
|
1252
|
-
142,
|
|
1253
|
-
123,
|
|
1254
|
-
216,
|
|
1255
|
-
219,
|
|
1256
|
-
233,
|
|
1257
|
-
248,
|
|
1258
|
-
89
|
|
1259
|
-
];
|
|
1260
|
-
};
|
|
1261
|
-
};
|
|
1262
1210
|
},
|
|
1263
1211
|
{
|
|
1264
1212
|
name: 'marketToAta';
|
|
1265
1213
|
writable: true;
|
|
1266
|
-
pda: {
|
|
1267
|
-
seeds: [
|
|
1268
|
-
{
|
|
1269
|
-
kind: 'account';
|
|
1270
|
-
path: 'market';
|
|
1271
|
-
},
|
|
1272
|
-
{
|
|
1273
|
-
kind: 'account';
|
|
1274
|
-
path: 'tokenProgram';
|
|
1275
|
-
},
|
|
1276
|
-
{
|
|
1277
|
-
kind: 'account';
|
|
1278
|
-
path: 'mint';
|
|
1279
|
-
}
|
|
1280
|
-
];
|
|
1281
|
-
program: {
|
|
1282
|
-
kind: 'const';
|
|
1283
|
-
value: [
|
|
1284
|
-
140,
|
|
1285
|
-
151,
|
|
1286
|
-
37,
|
|
1287
|
-
143,
|
|
1288
|
-
78,
|
|
1289
|
-
36,
|
|
1290
|
-
137,
|
|
1291
|
-
241,
|
|
1292
|
-
187,
|
|
1293
|
-
61,
|
|
1294
|
-
16,
|
|
1295
|
-
41,
|
|
1296
|
-
20,
|
|
1297
|
-
142,
|
|
1298
|
-
13,
|
|
1299
|
-
131,
|
|
1300
|
-
11,
|
|
1301
|
-
90,
|
|
1302
|
-
19,
|
|
1303
|
-
153,
|
|
1304
|
-
218,
|
|
1305
|
-
255,
|
|
1306
|
-
16,
|
|
1307
|
-
132,
|
|
1308
|
-
4,
|
|
1309
|
-
142,
|
|
1310
|
-
123,
|
|
1311
|
-
216,
|
|
1312
|
-
219,
|
|
1313
|
-
233,
|
|
1314
|
-
248,
|
|
1315
|
-
89
|
|
1316
|
-
];
|
|
1317
|
-
};
|
|
1318
|
-
};
|
|
1319
1214
|
},
|
|
1320
1215
|
{
|
|
1321
1216
|
name: 'sellerToAta';
|
|
@@ -3968,8 +3863,10 @@ export type TriadProtocol = {
|
|
|
3968
3863
|
type: 'u64';
|
|
3969
3864
|
},
|
|
3970
3865
|
{
|
|
3971
|
-
name: '
|
|
3972
|
-
type:
|
|
3866
|
+
name: 'padding2';
|
|
3867
|
+
type: {
|
|
3868
|
+
array: ['u8', 8];
|
|
3869
|
+
};
|
|
3973
3870
|
},
|
|
3974
3871
|
{
|
|
3975
3872
|
name: 'orders';
|
package/dist/utils/helpers.js
CHANGED
|
@@ -113,7 +113,6 @@ const formatUserTrade = (account, publicKey) => {
|
|
|
113
113
|
user: publicKey.toString(),
|
|
114
114
|
totalDeposits: account.totalDeposits.toString(),
|
|
115
115
|
totalWithdraws: account.totalWithdraws.toString(),
|
|
116
|
-
openedOrders: account.openedOrders.toString(),
|
|
117
116
|
orders: account.orders.map((order) => (0, exports.formatOrder)(order, account.authority.toString())),
|
|
118
117
|
nonce: account.nonce.toString(),
|
|
119
118
|
poseidon: account.poseidon ? account.poseidon.toString() : '',
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
2
|
export declare const getUserPositionPDA: (programId: PublicKey, wallet: PublicKey, ticker: PublicKey) => PublicKey;
|
|
3
|
-
export declare const getTokenATA: (address: PublicKey, Mint: PublicKey) => PublicKey;
|
|
3
|
+
export declare const getTokenATA: (address: PublicKey, Mint: PublicKey, program?: PublicKey) => PublicKey;
|
|
4
4
|
export declare const getWheelPDA: (programId: PublicKey, name: string) => PublicKey;
|
|
5
5
|
export declare const getCollectionPDA: (programId: PublicKey, collectionSymbol: string) => PublicKey;
|
|
6
6
|
export declare const getNftPDA: (programId: PublicKey, number: number) => PublicKey;
|
package/dist/utils/pda/index.js
CHANGED
|
@@ -11,8 +11,8 @@ const getUserPositionPDA = (programId, wallet, ticker) => {
|
|
|
11
11
|
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('user_position'), wallet.toBuffer(), ticker.toBuffer()], programId)[0];
|
|
12
12
|
};
|
|
13
13
|
exports.getUserPositionPDA = getUserPositionPDA;
|
|
14
|
-
const getTokenATA = (address, Mint) => {
|
|
15
|
-
return web3_js_1.PublicKey.findProgramAddressSync([address.toBytes(),
|
|
14
|
+
const getTokenATA = (address, Mint, program = spl_token_1.TOKEN_2022_PROGRAM_ID) => {
|
|
15
|
+
return web3_js_1.PublicKey.findProgramAddressSync([address.toBytes(), program.toBytes(), Mint.toBytes()], new web3_js_1.PublicKey(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID))[0];
|
|
16
16
|
};
|
|
17
17
|
exports.getTokenATA = getTokenATA;
|
|
18
18
|
const getWheelPDA = (programId, name) => {
|
package/package.json
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@triadxyz/triad-protocol",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.9-beta",
|
|
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
|
-
"prepublishOnly": "yarn build"
|
|
11
|
-
"test": "rimraf dist && tsc && node ./dist/local-test/index.js"
|
|
10
|
+
"prepublishOnly": "yarn build"
|
|
12
11
|
},
|
|
13
12
|
"publishConfig": {
|
|
14
13
|
"access": "public"
|