@triadxyz/triad-protocol 0.5.9-beta.devnet → 0.6.1-beta.devnet

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.
@@ -17,7 +17,7 @@ const index_1 = __importDefault(require("./index"));
17
17
  const anchor_1 = require("@coral-xyz/anchor");
18
18
  const axios_1 = __importDefault(require("axios"));
19
19
  const web3_js_1 = require("@solana/web3.js");
20
- const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
20
+ const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/dan-builder.json');
21
21
  const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc-devnet.txt');
22
22
  const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
23
23
  const connection = new web3_js_1.Connection(rpc_file.toString(), 'confirmed');
@@ -75,17 +75,74 @@ const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* (
75
75
  }
76
76
  }
77
77
  });
78
- const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
79
- const response = yield triadProtocol.trade.openOrder(0, {
80
- amount: 100,
78
+ const ordersHypeAndFloopBot = [
79
+ {
80
+ marketId: 0,
81
+ amount: 1000,
81
82
  direction: {
82
83
  hype: {}
83
84
  },
84
85
  orderType: {
85
86
  market: {}
86
87
  },
87
- comment: 'test'
88
- });
89
- console.log(response);
88
+ limitPrice: 0
89
+ },
90
+ {
91
+ marketId: 0,
92
+ amount: 9009,
93
+ direction: {
94
+ flop: {}
95
+ },
96
+ orderType: {
97
+ market: {}
98
+ },
99
+ limitPrice: 0
100
+ },
101
+ {
102
+ marketId: 0,
103
+ amount: 213,
104
+ direction: {
105
+ hype: {}
106
+ },
107
+ orderType: {
108
+ market: {}
109
+ },
110
+ limitPrice: 0.8
111
+ },
112
+ {
113
+ marketId: 0,
114
+ amount: 2223,
115
+ direction: {
116
+ flop: {}
117
+ },
118
+ orderType: {
119
+ market: {}
120
+ },
121
+ limitPrice: 0.2
122
+ },
123
+ {
124
+ marketId: 0,
125
+ amount: 1323,
126
+ direction: {
127
+ hype: {}
128
+ },
129
+ orderType: {
130
+ market: {}
131
+ }
132
+ }
133
+ ];
134
+ const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
135
+ for (const order of ordersHypeAndFloopBot) {
136
+ const response = yield triadProtocol.trade.openOrder(0, {
137
+ amount: order.amount,
138
+ direction: order.direction,
139
+ orderType: order.orderType,
140
+ comment: `hype/flop bot ${order.amount} - ${order.direction}`,
141
+ limitPrice: order.limitPrice
142
+ }, {
143
+ skipPreflight: true
144
+ });
145
+ console.log(response);
146
+ }
90
147
  });
91
148
  openOrder();
package/dist/trade.d.ts CHANGED
@@ -6,6 +6,7 @@ import { RpcOptions } from './types';
6
6
  export default class Trade {
7
7
  program: Program<TriadProtocol>;
8
8
  provider: AnchorProvider;
9
+ mint: PublicKey;
9
10
  constructor(program: Program<TriadProtocol>, provider: AnchorProvider);
10
11
  /**
11
12
  * Get all Markets
@@ -29,4 +30,8 @@ export default class Trade {
29
30
  limitPrice?: number;
30
31
  comment?: string;
31
32
  }, options?: RpcOptions): Promise<string>;
33
+ closeOrder({ marketId, orderId }: {
34
+ marketId: number;
35
+ orderId: number;
36
+ }, options?: RpcOptions): Promise<string>;
32
37
  }
package/dist/trade.js CHANGED
@@ -18,6 +18,7 @@ const constants_1 = require("./utils/constants");
18
18
  const helpers_1 = require("./utils/helpers");
19
19
  class Trade {
20
20
  constructor(program, provider) {
21
+ this.mint = constants_1.TRD_MINT_DEVNET;
21
22
  this.provider = provider;
22
23
  this.program = program;
23
24
  }
@@ -114,7 +115,7 @@ class Trade {
114
115
  const ixs = [];
115
116
  try {
116
117
  const userTradePDA = (0, helpers_1.getUserTradeAddressSync)(this.program.programId, this.provider.publicKey);
117
- this.program.account.userTrade.fetch(userTradePDA);
118
+ yield this.program.account.userTrade.fetch(userTradePDA);
118
119
  }
119
120
  catch (_a) {
120
121
  ixs.push(yield this.program.methods
@@ -126,18 +127,16 @@ class Trade {
126
127
  }
127
128
  ixs.push(yield this.program.methods
128
129
  .openOrder({
129
- amount: new bn_js_1.default(args.amount / Math.pow(10, constants_1.TRD_DECIMALS)),
130
+ amount: new bn_js_1.default(args.amount * Math.pow(10, constants_1.TRD_DECIMALS)),
130
131
  direction: args.direction,
131
132
  orderType: args.orderType,
132
- limitPrice: args.limitPrice
133
- ? new bn_js_1.default(args.limitPrice / Math.pow(10, constants_1.TRD_DECIMALS))
134
- : undefined,
135
- comment: args.comment ? (0, helpers_1.encodeString)(args.comment, 64) : undefined
133
+ limitPrice: new bn_js_1.default(args.limitPrice * Math.pow(10, constants_1.TRD_DECIMALS)),
134
+ comment: (0, helpers_1.encodeString)(args.comment, 64)
136
135
  })
137
136
  .accounts({
138
137
  signer: this.provider.publicKey,
139
138
  market: marketPDA,
140
- mint: constants_1.TRD_MINT_DEVNET
139
+ mint: this.mint
141
140
  })
142
141
  .instruction());
143
142
  if (options === null || options === void 0 ? void 0 : options.microLamports) {
@@ -156,5 +155,23 @@ class Trade {
156
155
  });
157
156
  });
158
157
  }
158
+ closeOrder({ marketId, orderId }, options) {
159
+ return __awaiter(this, void 0, void 0, function* () {
160
+ const marketPDA = (0, helpers_1.getMarketAddressSync)(this.program.programId, marketId);
161
+ const method = this.program.methods.closeOrder(new bn_js_1.default(orderId)).accounts({
162
+ signer: this.provider.publicKey,
163
+ market: marketPDA,
164
+ mint: this.mint
165
+ });
166
+ if (options === null || options === void 0 ? void 0 : options.microLamports) {
167
+ method.postInstructions([
168
+ web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
169
+ microLamports: options.microLamports
170
+ })
171
+ ]);
172
+ }
173
+ return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
174
+ });
175
+ }
159
176
  }
160
177
  exports.default = Trade;
@@ -114,6 +114,115 @@
114
114
  ],
115
115
  "returns": "u64"
116
116
  },
117
+ {
118
+ "name": "close_order",
119
+ "discriminator": [90, 103, 209, 28, 7, 63, 168, 4],
120
+ "accounts": [
121
+ {
122
+ "name": "signer",
123
+ "writable": true,
124
+ "signer": true
125
+ },
126
+ {
127
+ "name": "user_trade",
128
+ "writable": true,
129
+ "pda": {
130
+ "seeds": [
131
+ {
132
+ "kind": "const",
133
+ "value": [117, 115, 101, 114, 95, 116, 114, 97, 100, 101]
134
+ },
135
+ {
136
+ "kind": "account",
137
+ "path": "signer"
138
+ }
139
+ ]
140
+ }
141
+ },
142
+ {
143
+ "name": "market",
144
+ "writable": true
145
+ },
146
+ {
147
+ "name": "mint",
148
+ "writable": true
149
+ },
150
+ {
151
+ "name": "user_ata",
152
+ "writable": true,
153
+ "pda": {
154
+ "seeds": [
155
+ {
156
+ "kind": "account",
157
+ "path": "signer"
158
+ },
159
+ {
160
+ "kind": "account",
161
+ "path": "token_program"
162
+ },
163
+ {
164
+ "kind": "account",
165
+ "path": "mint"
166
+ }
167
+ ],
168
+ "program": {
169
+ "kind": "const",
170
+ "value": [
171
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
172
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
173
+ 219, 233, 248, 89
174
+ ]
175
+ }
176
+ }
177
+ },
178
+ {
179
+ "name": "market_vault",
180
+ "writable": true,
181
+ "pda": {
182
+ "seeds": [
183
+ {
184
+ "kind": "account",
185
+ "path": "market"
186
+ },
187
+ {
188
+ "kind": "account",
189
+ "path": "token_program"
190
+ },
191
+ {
192
+ "kind": "account",
193
+ "path": "mint"
194
+ }
195
+ ],
196
+ "program": {
197
+ "kind": "const",
198
+ "value": [
199
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
200
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
201
+ 219, 233, 248, 89
202
+ ]
203
+ }
204
+ }
205
+ },
206
+ {
207
+ "name": "token_program",
208
+ "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
209
+ },
210
+ {
211
+ "name": "associated_token_program",
212
+ "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
213
+ },
214
+ {
215
+ "name": "system_program",
216
+ "address": "11111111111111111111111111111111"
217
+ }
218
+ ],
219
+ "args": [
220
+ {
221
+ "name": "order_id",
222
+ "type": "u64"
223
+ }
224
+ ]
225
+ },
117
226
  {
118
227
  "name": "create_user",
119
228
  "discriminator": [108, 227, 130, 130, 252, 109, 75, 218],
@@ -237,6 +346,34 @@
237
346
  ]
238
347
  }
239
348
  },
349
+ {
350
+ "name": "fee_vault_token_account",
351
+ "writable": true,
352
+ "pda": {
353
+ "seeds": [
354
+ {
355
+ "kind": "account",
356
+ "path": "fee_vault"
357
+ },
358
+ {
359
+ "kind": "account",
360
+ "path": "token_program"
361
+ },
362
+ {
363
+ "kind": "account",
364
+ "path": "mint"
365
+ }
366
+ ],
367
+ "program": {
368
+ "kind": "const",
369
+ "value": [
370
+ 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
371
+ 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
372
+ 219, 233, 248, 89
373
+ ]
374
+ }
375
+ }
376
+ },
240
377
  {
241
378
  "name": "mint",
242
379
  "writable": true
@@ -408,12 +545,8 @@
408
545
  "path": "fee_vault"
409
546
  },
410
547
  {
411
- "kind": "const",
412
- "value": [
413
- 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206,
414
- 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140,
415
- 245, 133, 126, 255, 0, 169
416
- ]
548
+ "kind": "account",
549
+ "path": "token_program"
417
550
  },
418
551
  {
419
552
  "kind": "account",
@@ -178,6 +178,173 @@ export type TriadProtocol = {
178
178
  ];
179
179
  returns: 'u64';
180
180
  },
181
+ {
182
+ name: 'closeOrder';
183
+ discriminator: [90, 103, 209, 28, 7, 63, 168, 4];
184
+ accounts: [
185
+ {
186
+ name: 'signer';
187
+ writable: true;
188
+ signer: true;
189
+ },
190
+ {
191
+ name: 'userTrade';
192
+ writable: true;
193
+ pda: {
194
+ seeds: [
195
+ {
196
+ kind: 'const';
197
+ value: [117, 115, 101, 114, 95, 116, 114, 97, 100, 101];
198
+ },
199
+ {
200
+ kind: 'account';
201
+ path: 'signer';
202
+ }
203
+ ];
204
+ };
205
+ },
206
+ {
207
+ name: 'market';
208
+ writable: true;
209
+ },
210
+ {
211
+ name: 'mint';
212
+ writable: true;
213
+ },
214
+ {
215
+ name: 'userAta';
216
+ writable: true;
217
+ pda: {
218
+ seeds: [
219
+ {
220
+ kind: 'account';
221
+ path: 'signer';
222
+ },
223
+ {
224
+ kind: 'account';
225
+ path: 'tokenProgram';
226
+ },
227
+ {
228
+ kind: 'account';
229
+ path: 'mint';
230
+ }
231
+ ];
232
+ program: {
233
+ kind: 'const';
234
+ value: [
235
+ 140,
236
+ 151,
237
+ 37,
238
+ 143,
239
+ 78,
240
+ 36,
241
+ 137,
242
+ 241,
243
+ 187,
244
+ 61,
245
+ 16,
246
+ 41,
247
+ 20,
248
+ 142,
249
+ 13,
250
+ 131,
251
+ 11,
252
+ 90,
253
+ 19,
254
+ 153,
255
+ 218,
256
+ 255,
257
+ 16,
258
+ 132,
259
+ 4,
260
+ 142,
261
+ 123,
262
+ 216,
263
+ 219,
264
+ 233,
265
+ 248,
266
+ 89
267
+ ];
268
+ };
269
+ };
270
+ },
271
+ {
272
+ name: 'marketVault';
273
+ writable: true;
274
+ pda: {
275
+ seeds: [
276
+ {
277
+ kind: 'account';
278
+ path: 'market';
279
+ },
280
+ {
281
+ kind: 'account';
282
+ path: 'tokenProgram';
283
+ },
284
+ {
285
+ kind: 'account';
286
+ path: 'mint';
287
+ }
288
+ ];
289
+ program: {
290
+ kind: 'const';
291
+ value: [
292
+ 140,
293
+ 151,
294
+ 37,
295
+ 143,
296
+ 78,
297
+ 36,
298
+ 137,
299
+ 241,
300
+ 187,
301
+ 61,
302
+ 16,
303
+ 41,
304
+ 20,
305
+ 142,
306
+ 13,
307
+ 131,
308
+ 11,
309
+ 90,
310
+ 19,
311
+ 153,
312
+ 218,
313
+ 255,
314
+ 16,
315
+ 132,
316
+ 4,
317
+ 142,
318
+ 123,
319
+ 216,
320
+ 219,
321
+ 233,
322
+ 248,
323
+ 89
324
+ ];
325
+ };
326
+ };
327
+ },
328
+ {
329
+ name: 'tokenProgram';
330
+ address: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb';
331
+ },
332
+ {
333
+ name: 'associatedTokenProgram';
334
+ address: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
335
+ },
336
+ {
337
+ name: 'systemProgram';
338
+ address: '11111111111111111111111111111111';
339
+ }
340
+ ];
341
+ args: [
342
+ {
343
+ name: 'orderId';
344
+ type: 'u64';
345
+ }
346
+ ];
347
+ },
181
348
  {
182
349
  name: 'createUser';
183
350
  discriminator: [108, 227, 130, 130, 252, 109, 75, 218];
@@ -301,6 +468,63 @@ export type TriadProtocol = {
301
468
  ];
302
469
  };
303
470
  },
471
+ {
472
+ name: 'feeVaultTokenAccount';
473
+ writable: true;
474
+ pda: {
475
+ seeds: [
476
+ {
477
+ kind: 'account';
478
+ path: 'feeVault';
479
+ },
480
+ {
481
+ kind: 'account';
482
+ path: 'tokenProgram';
483
+ },
484
+ {
485
+ kind: 'account';
486
+ path: 'mint';
487
+ }
488
+ ];
489
+ program: {
490
+ kind: 'const';
491
+ value: [
492
+ 140,
493
+ 151,
494
+ 37,
495
+ 143,
496
+ 78,
497
+ 36,
498
+ 137,
499
+ 241,
500
+ 187,
501
+ 61,
502
+ 16,
503
+ 41,
504
+ 20,
505
+ 142,
506
+ 13,
507
+ 131,
508
+ 11,
509
+ 90,
510
+ 19,
511
+ 153,
512
+ 218,
513
+ 255,
514
+ 16,
515
+ 132,
516
+ 4,
517
+ 142,
518
+ 123,
519
+ 216,
520
+ 219,
521
+ 233,
522
+ 248,
523
+ 89
524
+ ];
525
+ };
526
+ };
527
+ },
304
528
  {
305
529
  name: 'mint';
306
530
  writable: true;
@@ -559,41 +783,8 @@ export type TriadProtocol = {
559
783
  path: 'feeVault';
560
784
  },
561
785
  {
562
- kind: 'const';
563
- value: [
564
- 6,
565
- 221,
566
- 246,
567
- 225,
568
- 215,
569
- 101,
570
- 161,
571
- 147,
572
- 217,
573
- 203,
574
- 225,
575
- 70,
576
- 206,
577
- 235,
578
- 121,
579
- 172,
580
- 28,
581
- 180,
582
- 133,
583
- 237,
584
- 95,
585
- 91,
586
- 55,
587
- 145,
588
- 58,
589
- 140,
590
- 245,
591
- 133,
592
- 126,
593
- 255,
594
- 0,
595
- 169
596
- ];
786
+ kind: 'account';
787
+ path: 'tokenProgram';
597
788
  },
598
789
  {
599
790
  kind: 'account';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "0.5.9-beta.devnet",
3
+ "version": "0.6.1-beta.devnet",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",