@triadxyz/triad-protocol 1.1.8-beta → 1.2.0-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.
@@ -23,7 +23,59 @@ const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.t
23
23
  const connection = new web3_js_1.Connection(rpc_file.toString(), 'confirmed');
24
24
  const wallet = new anchor_1.Wallet(keypair);
25
25
  const triadProtocol = new _1.default(connection, wallet);
26
- const markets = [{ name: 'Triad', marketId: 0 }];
26
+ const markets = [
27
+ // { name: 'Triad', marketId: 0 },
28
+ // { name: 'PYTH', marketId: 1 },
29
+ // { name: 'DRIFT', marketId: 2 },
30
+ // { name: 'SYMMETRY', marketId: 3 },
31
+ // { name: 'ORE', marketId: 4 },
32
+ // { name: 'COLETA', marketId: 5 },
33
+ // { name: 'UNDEADS', marketId: 6 }
34
+ ];
35
+ const questions = [
36
+ {
37
+ name: 'Pyth',
38
+ marketId: 1,
39
+ question: "$PYTH's market cap exceed $1.5B by the end of October?",
40
+ startTime: 1728415578,
41
+ endTime: 1730394000
42
+ },
43
+ {
44
+ name: 'Drift',
45
+ marketId: 2,
46
+ question: 'Drift surpass $33M in volume on prediction markets by the end of October?',
47
+ startTime: 1728415578,
48
+ endTime: 1730394000
49
+ },
50
+ {
51
+ name: 'Symmetry',
52
+ marketId: 3,
53
+ question: "Symmetry's TVL exceed $5.5M by the end of October?",
54
+ startTime: 1728415578,
55
+ endTime: 1730394000
56
+ },
57
+ {
58
+ name: 'Ore',
59
+ marketId: 4,
60
+ question: 'ORE surpass 20k on-chain miners by the end of October?',
61
+ startTime: 1728415578,
62
+ endTime: 1730394000
63
+ },
64
+ {
65
+ name: 'Coleta',
66
+ marketId: 5,
67
+ question: 'COLETA PFP reach 500 SOL in total volume by the end of October (based on Tensor)?',
68
+ startTime: 1728415578,
69
+ endTime: 1730394000
70
+ },
71
+ {
72
+ name: 'Undeads',
73
+ marketId: 6,
74
+ question: 'The Undeads reach more than 1,600 holders by the end of October?',
75
+ startTime: 1728415578,
76
+ endTime: 1730394000
77
+ }
78
+ ];
27
79
  const ordersHypeAndFloopBot = [
28
80
  {
29
81
  marketId: 0,
@@ -78,8 +130,9 @@ const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
78
130
  const markets = yield triadProtocol.trade.getAllMarkets();
79
131
  console.log(markets);
80
132
  });
133
+ getAllMarkets();
81
134
  const getMarket = () => __awaiter(void 0, void 0, void 0, function* () {
82
- const market = yield triadProtocol.trade.getMarketById(0);
135
+ const market = yield triadProtocol.trade.getMarketById(2);
83
136
  console.log(market);
84
137
  });
85
138
  const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -95,62 +148,66 @@ const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* (
95
148
  }
96
149
  }
97
150
  });
98
- const getOrders = () => __awaiter(void 0, void 0, void 0, function* () {
99
- const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === wallet.publicKey.toBase58());
100
- return response.account.orders.map((order) => order.orderId.toNumber());
101
- });
102
- const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
103
- for (const order of ordersHypeAndFloopBot) {
104
- const response = yield triadProtocol.trade.openOrder({
105
- marketId: 0,
106
- amount: order.amount,
107
- direction: order.direction,
108
- token: 'So11111111111111111111111111111111111111112',
109
- comment: `hype/flop bot ${order.amount} - ${order.direction}`
110
- }, {
111
- skipPreflight: true
112
- });
113
- console.log(response);
114
- }
151
+ const getOrders = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
152
+ const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === walletAddress.toBase58());
153
+ console.log(response.account);
115
154
  });
116
- openOrder();
117
- const closeOrder = () => __awaiter(void 0, void 0, void 0, function* () {
118
- for (const order of yield getOrders()) {
155
+ // const openOrder = async () => {
156
+ // for (const order of ordersHypeAndFloopBot) {
157
+ // const response = await triadProtocol.trade.openOrder(
158
+ // {
159
+ // marketId: 0,
160
+ // amount: order.amount,
161
+ // direction: order.direction as any,
162
+ // token: 'So11111111111111111111111111111111111111112',
163
+ // comment: `hype/flop bot ${order.amount} - ${order.direction}`
164
+ // },
165
+ // {
166
+ // skipPreflight: true
167
+ // }
168
+ // )
169
+ // console.log(response)
170
+ // }
171
+ // }
172
+ // const closeOrder = async () => {
173
+ // for (const order of await getOrders()) {
174
+ // try {
175
+ // const response = await triadProtocol.trade.closeOrder({
176
+ // marketId: 1,
177
+ // orderId: order
178
+ // })
179
+ // console.log(response)
180
+ // } catch (e) {
181
+ // console.log('Error closing order')
182
+ // }
183
+ // }
184
+ // }
185
+ // const runBot = async () => {
186
+ // while (true) {
187
+ // const hasOpenOrders = (await getOrders()).find((order) => order !== 0)
188
+ // if (hasOpenOrders) {
189
+ // await closeOrder()
190
+ // }
191
+ // await openOrder()
192
+ // await new Promise((resolve) => setTimeout(resolve, 40000))
193
+ // }
194
+ // }
195
+ const initializeQuestion = () => __awaiter(void 0, void 0, void 0, function* () {
196
+ for (const question of questions) {
119
197
  try {
120
- const response = yield triadProtocol.trade.closeOrder({
121
- marketId: 1,
122
- orderId: order
198
+ const response = yield triadProtocol.trade.initializeQuestion({
199
+ marketId: question.marketId,
200
+ question: question.question,
201
+ startTime: question.startTime,
202
+ endTime: question.endTime
203
+ }, {
204
+ skipPreflight: true
123
205
  });
124
206
  console.log(response);
125
207
  }
126
208
  catch (e) {
127
- console.log('Error closing order');
128
- }
129
- }
130
- });
131
- const runBot = () => __awaiter(void 0, void 0, void 0, function* () {
132
- while (true) {
133
- const hasOpenOrders = (yield getOrders()).find((order) => order !== 0);
134
- if (hasOpenOrders) {
135
- yield closeOrder();
209
+ console.log(e);
136
210
  }
137
- yield openOrder();
138
- yield new Promise((resolve) => setTimeout(resolve, 40000));
139
- }
140
- });
141
- const initializeQuestion = () => __awaiter(void 0, void 0, void 0, function* () {
142
- const currentTime = Math.floor(Date.now() / 1000) + 10; // Current time in seconds
143
- try {
144
- const response = yield triadProtocol.trade.initializeQuestion({
145
- marketId: 0,
146
- question: 'Will Triad send the project to the Radar Hackathon?',
147
- startTime: currentTime,
148
- endTime: 1728320400
149
- });
150
- console.log(response);
151
- }
152
- catch (e) {
153
- console.log(e);
154
211
  }
155
212
  });
156
213
  const resolveQuestion = () => __awaiter(void 0, void 0, void 0, function* () {
package/dist/stake.js CHANGED
@@ -243,17 +243,24 @@ class Stake {
243
243
  return __awaiter(this, void 0, void 0, function* () {
244
244
  const stakes = (yield this.getUserStakes(wallet)).sort((a, b) => a.claimedTs - b.claimedTs);
245
245
  const ixs = [];
246
- for (const stake of stakes) {
246
+ let tokenStakes = [];
247
+ let nftStakes = [];
248
+ stakes.forEach((stake) => {
247
249
  if (stake.withdrawTs !== 0) {
248
- continue;
250
+ return;
249
251
  }
252
+ if (stake.mint === constants_1.TRD_MINT.toBase58()) {
253
+ tokenStakes.push(stake);
254
+ return;
255
+ }
256
+ nftStakes.push(stake);
257
+ });
258
+ let items = isToken ? tokenStakes : nftStakes;
259
+ for (const stake of items) {
250
260
  const rank = (0, getRarityRank_1.default)(ranks, stake.mint, stake.name);
251
261
  if (ixs.length >= 10) {
252
262
  break;
253
263
  }
254
- if (isToken && stake.mint !== constants_1.TRD_MINT.toBase58()) {
255
- continue;
256
- }
257
264
  const stakeVaultPDA = (0, stake_1.getStakeVaultPDA)(this.program.programId, this.stakeVaultName);
258
265
  const stakePDA = (0, stake_1.getStakePDA)(this.program.programId, wallet, stake.name);
259
266
  ixs.push(yield this.program.methods
@@ -1522,6 +1522,11 @@
1522
1522
  "code": 6040,
1523
1523
  "name": "MarketStillActive",
1524
1524
  "msg": "Market still active"
1525
+ },
1526
+ {
1527
+ "code": 6041,
1528
+ "name": "OrderNotOpen",
1529
+ "msg": "Order not open"
1525
1530
  }
1526
1531
  ],
1527
1532
  "types": [
@@ -1743,7 +1748,7 @@
1743
1748
  {
1744
1749
  "name": "fee_bps",
1745
1750
  "docs": [
1746
- "Fees applied to trades (in basis points, e.g., 1.131% fee)"
1751
+ "Fees applied to trades (in basis points, e.g., 2.131% fee)"
1747
1752
  ],
1748
1753
  "type": "u16"
1749
1754
  },
@@ -1791,6 +1796,10 @@
1791
1796
  "array": ["u8", 80]
1792
1797
  }
1793
1798
  },
1799
+ {
1800
+ "name": "liquidity",
1801
+ "type": "u64"
1802
+ },
1794
1803
  {
1795
1804
  "name": "padding",
1796
1805
  "type": {
@@ -39,9 +39,9 @@ export type ResolvedQuestion = {
39
39
  finalFlopPrice: string;
40
40
  };
41
41
  export declare enum WinningDirection {
42
- Hype = "Hype",
43
- Flop = "Flop",
44
- None = "None"
42
+ HYPE = "Hype",
43
+ FLOP = "Flop",
44
+ NONE = "None"
45
45
  }
46
46
  export type OrderDirection = {
47
47
  hype: {};
@@ -53,11 +53,11 @@ export type OrderStatus = {
53
53
  } | {
54
54
  open: {};
55
55
  } | {
56
- filled: {};
56
+ closed: {};
57
57
  } | {
58
- canceled: {};
58
+ claimed: {};
59
59
  } | {
60
- closed: {};
60
+ liquidated: {};
61
61
  };
62
62
  export type OrderType = {
63
63
  limit: {};
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WinningDirection = void 0;
4
4
  var WinningDirection;
5
5
  (function (WinningDirection) {
6
- WinningDirection["Hype"] = "Hype";
7
- WinningDirection["Flop"] = "Flop";
8
- WinningDirection["None"] = "None";
6
+ WinningDirection["HYPE"] = "Hype";
7
+ WinningDirection["FLOP"] = "Flop";
8
+ WinningDirection["NONE"] = "None";
9
9
  })(WinningDirection || (exports.WinningDirection = WinningDirection = {}));
@@ -2050,6 +2050,11 @@ export type TriadProtocol = {
2050
2050
  code: 6040;
2051
2051
  name: 'marketStillActive';
2052
2052
  msg: 'Market still active';
2053
+ },
2054
+ {
2055
+ code: 6041;
2056
+ name: 'orderNotOpen';
2057
+ msg: 'Order not open';
2053
2058
  }
2054
2059
  ];
2055
2060
  types: [
@@ -2270,7 +2275,7 @@ export type TriadProtocol = {
2270
2275
  },
2271
2276
  {
2272
2277
  name: 'feeBps';
2273
- docs: ['Fees applied to trades (in basis points, e.g., 1.131% fee)'];
2278
+ docs: ['Fees applied to trades (in basis points, e.g., 2.131% fee)'];
2274
2279
  type: 'u16';
2275
2280
  },
2276
2281
  {
@@ -2317,6 +2322,10 @@ export type TriadProtocol = {
2317
2322
  array: ['u8', 80];
2318
2323
  };
2319
2324
  },
2325
+ {
2326
+ name: 'liquidity';
2327
+ type: 'u64';
2328
+ },
2320
2329
  {
2321
2330
  name: 'padding';
2322
2331
  type: {
@@ -97,13 +97,14 @@ const accountToMarket = (account, address) => {
97
97
  };
98
98
  exports.accountToMarket = accountToMarket;
99
99
  const accountToResolvedQuestion = (question) => {
100
+ console.log(question);
100
101
  return {
101
102
  question: Buffer.from(question.question).toString().replace(/\0+$/, ''),
102
103
  startTime: question.startTime.toString(),
103
104
  endTime: question.endTime.toString(),
104
105
  hypeLiquidity: question.hypeLiquidity.toString(),
105
106
  flopLiquidity: question.flopLiquidity.toString(),
106
- winningDirection: trade_1.WinningDirection[question.winningDirection],
107
+ winningDirection: trade_1.WinningDirection[Object.keys(question.winningDirection)[0].toUpperCase()],
107
108
  marketPrice: question.marketPrice.toString(),
108
109
  finalHypePrice: question.finalHypePrice.toString(),
109
110
  finalFlopPrice: question.finalFlopPrice.toString()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triadxyz/triad-protocol",
3
- "version": "1.1.8-beta",
3
+ "version": "1.2.0-beta",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",