@triadxyz/triad-protocol 0.7.5-beta.devnet → 0.7.6-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.
package/dist/trade.js CHANGED
@@ -12,12 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- const web3_js_1 = require("@solana/web3.js");
16
15
  const bn_js_1 = __importDefault(require("bn.js"));
17
16
  const constants_1 = require("./utils/constants");
18
17
  const helpers_1 = require("./utils/helpers");
19
18
  const trade_1 = require("./utils/pda/trade");
20
19
  const pda_1 = require("./utils/pda");
20
+ const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
21
+ const sendTransactionWithOptions_1 = __importDefault(require("./utils/sendTransactionWithOptions"));
21
22
  class Trade {
22
23
  constructor(program, provider) {
23
24
  this.mint = constants_1.TRD_MINT_DEVNET;
@@ -27,30 +28,58 @@ class Trade {
27
28
  /**
28
29
  * Get all Markets
29
30
  */
30
- getMarkets() {
31
+ getAllMarkets() {
31
32
  return __awaiter(this, void 0, void 0, function* () {
32
33
  return this.program.account.market
33
34
  .all()
34
35
  .then((markets) => markets.map(({ account, publicKey }) => (0, helpers_1.accountToMarket)(account, publicKey)));
35
36
  });
36
37
  }
38
+ /**
39
+ * Get Market by ID
40
+ * @param marketId - The ID of the market
41
+ *
42
+ */
43
+ getMarketById(marketId) {
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
46
+ const response = yield this.program.account.market.fetch(marketPDA);
47
+ return (0, helpers_1.accountToMarket)(response, marketPDA);
48
+ });
49
+ }
50
+ /**
51
+ * Get Market by Address
52
+ * @param address - The address of the market
53
+ *
54
+ */
37
55
  getMarketByAddress(address) {
38
56
  return __awaiter(this, void 0, void 0, function* () {
39
57
  const account = yield this.program.account.market.fetch(address);
40
58
  return (0, helpers_1.accountToMarket)(account, address);
41
59
  });
42
60
  }
61
+ /**
62
+ * Get User Trade
63
+ * @param user - The user's public key
64
+ *
65
+ */
66
+ getUserTrade(user) {
67
+ return __awaiter(this, void 0, void 0, function* () {
68
+ const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, user);
69
+ return this.program.account.userTrade.fetch(userTradePDA);
70
+ });
71
+ }
43
72
  /**
44
73
  * Initialize Market
45
74
  * @param market id - new markert id - length + 1
46
75
  * @param name - PYTH/TRD JUP/TRD DRIFT/TRD
47
76
  *
77
+ * @param options - RPC options
78
+ *
48
79
  */
49
80
  initializeMarket({ marketId, name }, options) {
50
81
  return __awaiter(this, void 0, void 0, function* () {
51
- const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
52
- const feeVaultPDA = (0, trade_1.getFeeVaultPDA)(this.program.programId, marketId);
53
- const method = this.program.methods
82
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods
54
83
  .initializeMarket({
55
84
  marketId: new bn_js_1.default(marketId),
56
85
  name: name
@@ -58,24 +87,20 @@ class Trade {
58
87
  .accounts({
59
88
  signer: this.provider.publicKey,
60
89
  mint: this.mint
61
- });
62
- if (options === null || options === void 0 ? void 0 : options.microLamports) {
63
- method.postInstructions([
64
- web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
65
- microLamports: options.microLamports
66
- })
67
- ]);
68
- }
69
- return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
70
- });
71
- }
72
- getUserTrade() {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
75
- return this.program.account.userTrade.fetch(userTradePDA);
90
+ }), options);
76
91
  });
77
92
  }
78
- openOrder(marketId, args, options) {
93
+ /**
94
+ * Open Order
95
+ * @param marketId - The ID of the market
96
+ * @param amount - The amount of the order
97
+ * @param direction - The direction of the order
98
+ * @param comment - The comment of the order
99
+ *
100
+ * @param options - RPC options
101
+ *
102
+ */
103
+ openOrder({ marketId, amount, direction, comment }, options) {
79
104
  return __awaiter(this, void 0, void 0, function* () {
80
105
  const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
81
106
  const feeVualtPDA = (0, trade_1.getFeeVaultPDA)(this.program.programId, marketId);
@@ -97,9 +122,9 @@ class Trade {
97
122
  }
98
123
  ixs.push(yield this.program.methods
99
124
  .openOrder({
100
- amount: new bn_js_1.default(args.amount * Math.pow(10, constants_1.TRD_DECIMALS)),
101
- direction: args.direction,
102
- comment: (0, helpers_1.encodeString)(args.comment, 64)
125
+ amount: new bn_js_1.default(amount * Math.pow(10, constants_1.TRD_DECIMALS)),
126
+ direction: direction,
127
+ comment: (0, helpers_1.encodeString)(comment, 64)
103
128
  })
104
129
  .accounts({
105
130
  signer: this.provider.publicKey,
@@ -110,40 +135,69 @@ class Trade {
110
135
  userFromAta: userFromATA
111
136
  })
112
137
  .instruction());
113
- if (options === null || options === void 0 ? void 0 : options.microLamports) {
114
- ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
115
- microLamports: options.microLamports
116
- }));
117
- }
118
- const { blockhash } = yield this.provider.connection.getLatestBlockhash();
119
- return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(new web3_js_1.TransactionMessage({
120
- instructions: ixs,
121
- recentBlockhash: blockhash,
122
- payerKey: this.provider.publicKey
123
- }).compileToV0Message()), [], {
124
- skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight,
125
- commitment: 'confirmed'
126
- });
138
+ return (0, sendVersionedTransaction_1.default)(this.provider, ixs, options);
127
139
  });
128
140
  }
141
+ /**
142
+ * Close Order
143
+ * @param marketId - The ID of the market
144
+ * @param orderId - The ID of the order
145
+ *
146
+ * @param options - RPC options
147
+ *
148
+ */
129
149
  closeOrder({ marketId, orderId }, options) {
130
150
  return __awaiter(this, void 0, void 0, function* () {
131
151
  const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
132
152
  const userTradePDA = (0, trade_1.getUserTradePDA)(this.program.programId, this.provider.publicKey);
133
- const method = this.program.methods.closeOrder(new bn_js_1.default(orderId)).accounts({
153
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods.closeOrder(new bn_js_1.default(orderId)).accounts({
134
154
  signer: this.provider.publicKey,
135
155
  market: marketPDA,
136
156
  mint: this.mint,
137
157
  userTrade: userTradePDA
158
+ }), options);
159
+ });
160
+ }
161
+ /**
162
+ * Initialize a new question for a market
163
+ * @param marketId - The ID of the market
164
+ * @param question - The question to initialize
165
+ * @param startTime - The start time of the question
166
+ * @param endTime - The end time of the question
167
+ *
168
+ * @param options - RPC options
169
+ *
170
+ */
171
+ initializeQuestion({ marketId, question, startTime, endTime }, options) {
172
+ return __awaiter(this, void 0, void 0, function* () {
173
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
174
+ return (0, sendTransactionWithOptions_1.default)(this.program.methods
175
+ .initializeQuestion({
176
+ question: (0, helpers_1.encodeString)(question, 80),
177
+ startTime: new bn_js_1.default(startTime),
178
+ endTime: new bn_js_1.default(endTime)
179
+ })
180
+ .accounts({
181
+ signer: this.provider.publicKey,
182
+ market: marketPDA
183
+ }), options);
184
+ });
185
+ }
186
+ /**
187
+ * Resolve the current question for a market
188
+ * @param marketId - The ID of the market
189
+ *
190
+ * @param options - RPC options
191
+ *
192
+ */
193
+ resolveQuestion(marketId, options) {
194
+ return __awaiter(this, void 0, void 0, function* () {
195
+ const marketPDA = (0, trade_1.getMarketPDA)(this.program.programId, marketId);
196
+ const method = this.program.methods.resolveQuestion().accounts({
197
+ signer: this.provider.publicKey,
198
+ market: marketPDA
138
199
  });
139
- if (options === null || options === void 0 ? void 0 : options.microLamports) {
140
- method.postInstructions([
141
- web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
142
- microLamports: options.microLamports
143
- })
144
- ]);
145
- }
146
- return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
200
+ return (0, sendTransactionWithOptions_1.default)(method, options);
147
201
  });
148
202
  }
149
203
  }
@@ -418,46 +418,6 @@
418
418
  "name": "market",
419
419
  "writable": true
420
420
  },
421
- {
422
- "name": "mint",
423
- "writable": true
424
- },
425
- {
426
- "name": "market_vault",
427
- "writable": true,
428
- "pda": {
429
- "seeds": [
430
- {
431
- "kind": "account",
432
- "path": "market"
433
- },
434
- {
435
- "kind": "account",
436
- "path": "token_program"
437
- },
438
- {
439
- "kind": "account",
440
- "path": "mint"
441
- }
442
- ],
443
- "program": {
444
- "kind": "const",
445
- "value": [
446
- 140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
447
- 13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
448
- 219, 233, 248, 89
449
- ]
450
- }
451
- }
452
- },
453
- {
454
- "name": "token_program",
455
- "address": "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
456
- },
457
- {
458
- "name": "associated_token_program",
459
- "address": "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
460
- },
461
421
  {
462
422
  "name": "system_program",
463
423
  "address": "11111111111111111111111111111111"
@@ -1169,6 +1129,10 @@
1169
1129
  {
1170
1130
  "name": "QuestionUpdate",
1171
1131
  "discriminator": [110, 108, 240, 86, 176, 226, 54, 113]
1132
+ },
1133
+ {
1134
+ "name": "StakeRewards",
1135
+ "discriminator": [236, 217, 227, 239, 6, 129, 188, 218]
1172
1136
  }
1173
1137
  ],
1174
1138
  "errors": [
@@ -1244,133 +1208,133 @@
1244
1208
  },
1245
1209
  {
1246
1210
  "code": 6014,
1247
- "name": "StakeVaultLocked",
1248
- "msg": "Stake vault locked"
1249
- },
1250
- {
1251
- "code": 6015,
1252
1211
  "name": "StakeLocked",
1253
1212
  "msg": "Stake is locked"
1254
1213
  },
1255
1214
  {
1256
- "code": 6016,
1215
+ "code": 6015,
1257
1216
  "name": "StakeVaultFull",
1258
1217
  "msg": "Stake vault full"
1259
1218
  },
1260
1219
  {
1261
- "code": 6017,
1220
+ "code": 6016,
1262
1221
  "name": "InvalidMint",
1263
1222
  "msg": "Invalid mint"
1264
1223
  },
1265
1224
  {
1266
- "code": 6018,
1225
+ "code": 6017,
1267
1226
  "name": "InvalidStakeVaultWeek",
1268
1227
  "msg": "Invalid stake vault week"
1269
1228
  },
1270
1229
  {
1271
- "code": 6019,
1230
+ "code": 6018,
1272
1231
  "name": "RewardsAlreadyClaimed",
1273
1232
  "msg": "Rewards already claimed"
1274
1233
  },
1275
1234
  {
1276
- "code": 6020,
1235
+ "code": 6019,
1277
1236
  "name": "StakeOverflow",
1278
1237
  "msg": "Stake overflow"
1279
1238
  },
1280
1239
  {
1281
- "code": 6021,
1240
+ "code": 6020,
1282
1241
  "name": "SwapsReachedLimit",
1283
1242
  "msg": "Swaps reached limit"
1284
1243
  },
1285
1244
  {
1286
- "code": 6022,
1245
+ "code": 6021,
1287
1246
  "name": "InsufficientFunds",
1288
1247
  "msg": "Insufficient funds"
1289
1248
  },
1290
1249
  {
1291
- "code": 6023,
1250
+ "code": 6022,
1292
1251
  "name": "NoRewardsAvailable",
1293
1252
  "msg": "No rewards available"
1294
1253
  },
1295
1254
  {
1296
- "code": 6024,
1255
+ "code": 6023,
1297
1256
  "name": "InvalidPrice",
1298
1257
  "msg": "Invalid price"
1299
1258
  },
1300
1259
  {
1301
- "code": 6025,
1260
+ "code": 6024,
1302
1261
  "name": "InvalidOrderSize",
1303
1262
  "msg": "Invalid order size"
1304
1263
  },
1305
1264
  {
1306
- "code": 6026,
1265
+ "code": 6025,
1307
1266
  "name": "MaxOpenOrdersReached",
1308
1267
  "msg": "Maximum number of open orders reached"
1309
1268
  },
1310
1269
  {
1311
- "code": 6027,
1270
+ "code": 6026,
1312
1271
  "name": "NoAvailableOrderSlot",
1313
1272
  "msg": "No available order slot"
1314
1273
  },
1315
1274
  {
1316
- "code": 6028,
1275
+ "code": 6027,
1317
1276
  "name": "MarketInactive",
1318
1277
  "msg": "Market is inactive"
1319
1278
  },
1320
1279
  {
1321
- "code": 6029,
1280
+ "code": 6028,
1322
1281
  "name": "InvalidOrderType",
1323
1282
  "msg": "Invalid order type"
1324
1283
  },
1325
1284
  {
1326
- "code": 6030,
1285
+ "code": 6029,
1327
1286
  "name": "InvalidOrderDirection",
1328
1287
  "msg": "Invalid order direction"
1329
1288
  },
1330
1289
  {
1331
- "code": 6031,
1290
+ "code": 6030,
1332
1291
  "name": "OrderNotFound",
1333
1292
  "msg": "Order not found"
1334
1293
  },
1335
1294
  {
1336
- "code": 6032,
1295
+ "code": 6031,
1337
1296
  "name": "InvalidOrderStatus",
1338
1297
  "msg": "Invalid order status"
1339
1298
  },
1340
1299
  {
1341
- "code": 6033,
1300
+ "code": 6032,
1342
1301
  "name": "ArithmeticOverflow",
1343
1302
  "msg": "Arithmetic overflow"
1344
1303
  },
1345
1304
  {
1346
- "code": 6034,
1305
+ "code": 6033,
1347
1306
  "name": "OrderSizeTooLarge",
1348
1307
  "msg": "Order size too large"
1349
1308
  },
1350
1309
  {
1351
- "code": 6035,
1310
+ "code": 6034,
1352
1311
  "name": "QuestionPeriodNotEnded",
1353
1312
  "msg": "Question period not ended"
1354
1313
  },
1355
1314
  {
1356
- "code": 6036,
1315
+ "code": 6035,
1357
1316
  "name": "InvalidStartTime",
1358
1317
  "msg": "Invalid start time"
1359
1318
  },
1360
1319
  {
1361
- "code": 6037,
1320
+ "code": 6036,
1362
1321
  "name": "InvalidEndTime",
1363
1322
  "msg": "Invalid end time"
1364
1323
  },
1365
1324
  {
1366
- "code": 6038,
1325
+ "code": 6037,
1367
1326
  "name": "QuestionPeriodNotStarted",
1368
1327
  "msg": "Question period not started"
1369
1328
  },
1370
1329
  {
1371
- "code": 6039,
1330
+ "code": 6038,
1372
1331
  "name": "QuestionPeriodEnded",
1373
1332
  "msg": "Question period ended"
1333
+ },
1334
+ {
1335
+ "code": 6039,
1336
+ "name": "StakeVaultLocked",
1337
+ "msg": "Stake vault is locked"
1374
1338
  }
1375
1339
  ],
1376
1340
  "types": [
@@ -1627,9 +1591,6 @@
1627
1591
  },
1628
1592
  {
1629
1593
  "name": "current_question_start",
1630
- "docs": [
1631
- "Start timestamp of the current week if 7 days have passed since the start of the week"
1632
- ],
1633
1594
  "type": "i64"
1634
1595
  },
1635
1596
  {
@@ -2120,6 +2081,34 @@
2120
2081
  ]
2121
2082
  }
2122
2083
  },
2084
+ {
2085
+ "name": "StakeRewards",
2086
+ "type": {
2087
+ "kind": "struct",
2088
+ "fields": [
2089
+ {
2090
+ "name": "user",
2091
+ "type": "pubkey"
2092
+ },
2093
+ {
2094
+ "name": "mint",
2095
+ "type": "pubkey"
2096
+ },
2097
+ {
2098
+ "name": "amount",
2099
+ "type": "u64"
2100
+ },
2101
+ {
2102
+ "name": "timestamp",
2103
+ "type": "i64"
2104
+ },
2105
+ {
2106
+ "name": "rank",
2107
+ "type": "u16"
2108
+ }
2109
+ ]
2110
+ }
2111
+ },
2123
2112
  {
2124
2113
  "name": "StakeTokenArgs",
2125
2114
  "type": {
@@ -64,3 +64,15 @@ export type OrderType = {
64
64
  } | {
65
65
  market: {};
66
66
  };
67
+ export type InitializeQuestionArgs = {
68
+ marketId: number;
69
+ question: string;
70
+ startTime: number;
71
+ endTime: number;
72
+ };
73
+ export type OpenOrderArgs = {
74
+ marketId: number;
75
+ amount: number;
76
+ direction: OrderDirection;
77
+ comment?: string;
78
+ };