@triadxyz/triad-protocol 0.6.0-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,8 +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 helpers_1 = require("./utils/helpers");
21
- 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');
22
21
  const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc-devnet.txt');
23
22
  const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
24
23
  const connection = new web3_js_1.Connection(rpc_file.toString(), 'confirmed');
@@ -76,21 +75,74 @@ const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* (
76
75
  }
77
76
  }
78
77
  });
79
- const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
80
- const userTradePDA = (0, helpers_1.getUserTradeAddressSync)(triadProtocol.program.programId, wallet.publicKey);
81
- const response = yield triadProtocol.trade.openOrder(0, {
82
- amount: 100,
78
+ const ordersHypeAndFloopBot = [
79
+ {
80
+ marketId: 0,
81
+ amount: 1000,
83
82
  direction: {
84
83
  hype: {}
85
84
  },
86
85
  orderType: {
87
86
  market: {}
88
87
  },
89
- comment: 'test',
90
- limitPrice: 10
91
- }, {
92
- skipPreflight: true
93
- });
94
- 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
+ }
95
147
  });
96
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
  }
@@ -126,16 +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: new bn_js_1.default(args.limitPrice / Math.pow(10, constants_1.TRD_DECIMALS)),
133
+ limitPrice: new bn_js_1.default(args.limitPrice * Math.pow(10, constants_1.TRD_DECIMALS)),
133
134
  comment: (0, helpers_1.encodeString)(args.comment, 64)
134
135
  })
135
136
  .accounts({
136
137
  signer: this.provider.publicKey,
137
138
  market: marketPDA,
138
- mint: constants_1.TRD_MINT_DEVNET
139
+ mint: this.mint
139
140
  })
140
141
  .instruction());
141
142
  if (options === null || options === void 0 ? void 0 : options.microLamports) {
@@ -154,5 +155,23 @@ class Trade {
154
155
  });
155
156
  });
156
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
+ }
157
176
  }
158
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],
@@ -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];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "0.6.0-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",