@triadxyz/triad-protocol 1.2.0-beta → 1.2.2-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/local-test.js +321 -128
- package/dist/stake.d.ts +2 -2
- package/dist/stake.js +3 -3
- package/dist/trade.d.ts +36 -17
- package/dist/trade.js +57 -53
- package/dist/types/idl_triad_protocol.json +452 -288
- package/dist/types/stake.d.ts +1 -1
- package/dist/types/trade.d.ts +16 -42
- package/dist/types/triad_protocol.d.ts +564 -315
- package/dist/utils/helpers.d.ts +2 -1
- package/dist/utils/helpers.js +44 -29
- package/dist/utils/pda/trade.d.ts +0 -1
- package/dist/utils/pda/trade.js +1 -5
- package/dist/utils/sendVersionedTransaction.js +1 -1
- package/package.json +1 -1
package/dist/local-test.js
CHANGED
|
@@ -17,80 +17,97 @@ const _1 = __importDefault(require("./"));
|
|
|
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 spl_token_1 = require("@solana/spl-token");
|
|
20
21
|
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
|
|
21
22
|
const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
|
|
22
23
|
const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
|
|
23
|
-
const connection = new web3_js_1.Connection(
|
|
24
|
+
const connection = new web3_js_1.Connection('https://mainnet.helius-rpc.com/?api-key=428d811e-ba57-4def-8876-de95d53b7c9d');
|
|
24
25
|
const wallet = new anchor_1.Wallet(keypair);
|
|
25
26
|
const triadProtocol = new _1.default(connection, wallet);
|
|
27
|
+
const mint = new web3_js_1.PublicKey('X41iRJUPkKaEvhqWdxqrS5P7M5d8A9oathki5sT47KR');
|
|
26
28
|
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 }
|
|
29
|
+
// { name: 'Triad', marketId: 0 },
|
|
30
|
+
// { name: 'PYTH', marketId: 1 }
|
|
31
|
+
// { name: 'DRIFT', marketId: 2 }
|
|
32
|
+
// { name: 'SYMMETRY', marketId: 3 }
|
|
33
|
+
// { name: 'ORE', marketId: 4 }
|
|
34
|
+
// { name: 'COLETA', marketId: 5 }
|
|
35
|
+
// { name: 'UNDEADS', marketId: 6 },
|
|
36
|
+
// { name: 'SOL x ETH', marketId: 7 }
|
|
37
|
+
// { name: 'SOL vs ETH', marketId: 8 }
|
|
38
|
+
{ name: 'SOL vs ETH 2', marketId: 9 }
|
|
39
|
+
// { name: 'PYTH x LINK', marketId: 8 },
|
|
40
|
+
// { name: 'SOL PRICE', marketId: 9 }
|
|
34
41
|
];
|
|
35
42
|
const questions = [
|
|
36
43
|
{
|
|
37
44
|
name: 'Pyth',
|
|
38
45
|
marketId: 1,
|
|
39
|
-
question:
|
|
40
|
-
startTime:
|
|
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,
|
|
46
|
+
question: 'test 2',
|
|
47
|
+
startTime: 1719513866,
|
|
76
48
|
endTime: 1730394000
|
|
77
49
|
}
|
|
50
|
+
// },
|
|
51
|
+
// {
|
|
52
|
+
// name: 'Pyth',
|
|
53
|
+
// marketId: 1,
|
|
54
|
+
// question: "$PYTH's market cap exceed $1.5B by the end of October?",
|
|
55
|
+
// startTime: 1728415578,
|
|
56
|
+
// endTime: 1730394000
|
|
57
|
+
// },
|
|
58
|
+
// {
|
|
59
|
+
// name: 'Drift',
|
|
60
|
+
// marketId: 2,
|
|
61
|
+
// question:
|
|
62
|
+
// 'Drift surpass $33M in volume on prediction markets by the end of October?',
|
|
63
|
+
// startTime: 1728415578,
|
|
64
|
+
// endTime: 1730394000
|
|
65
|
+
// },
|
|
66
|
+
// {
|
|
67
|
+
// name: 'Symmetry',
|
|
68
|
+
// marketId: 3,
|
|
69
|
+
// question: "Symmetry's TVL exceed $5.5M by the end of October?",
|
|
70
|
+
// startTime: 1728415578,
|
|
71
|
+
// endTime: 1730394000
|
|
72
|
+
// },
|
|
73
|
+
// {
|
|
74
|
+
// name: 'Ore',
|
|
75
|
+
// marketId: 4,
|
|
76
|
+
// question: 'ORE surpass 20k on-chain miners by the end of October?',
|
|
77
|
+
// startTime: 1728415578,
|
|
78
|
+
// endTime: 1730394000
|
|
79
|
+
// },
|
|
80
|
+
// {
|
|
81
|
+
// name: 'Coleta',
|
|
82
|
+
// marketId: 5,
|
|
83
|
+
// question:
|
|
84
|
+
// 'COLETA PFP reach 500 SOL in total volume by the end of October (based on Tensor)?',
|
|
85
|
+
// startTime: 1728415578,
|
|
86
|
+
// endTime: 1730394000
|
|
87
|
+
// },
|
|
88
|
+
// {
|
|
89
|
+
// name: 'Undeads',
|
|
90
|
+
// marketId: 6,
|
|
91
|
+
// question:
|
|
92
|
+
// 'The Undeads reach more than 1,600 holders by the end of October?',
|
|
93
|
+
// startTime: 1728415578,
|
|
94
|
+
// endTime: 1730394000
|
|
95
|
+
// }
|
|
78
96
|
];
|
|
79
97
|
const ordersHypeAndFloopBot = [
|
|
80
98
|
{
|
|
81
|
-
marketId:
|
|
82
|
-
amount:
|
|
99
|
+
marketId: 7,
|
|
100
|
+
amount: 5000,
|
|
83
101
|
direction: {
|
|
84
102
|
flop: {}
|
|
85
|
-
},
|
|
86
|
-
orderType: {
|
|
87
|
-
market: {}
|
|
88
103
|
}
|
|
89
104
|
}
|
|
90
105
|
];
|
|
91
106
|
const updateStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
92
107
|
const response = yield triadProtocol.stake.updateStakeVault({
|
|
93
|
-
wallet: wallet.publicKey
|
|
108
|
+
wallet: wallet.publicKey,
|
|
109
|
+
amount: new anchor_1.BN(5000 * Math.pow(10, 6)),
|
|
110
|
+
isLocked: false
|
|
94
111
|
});
|
|
95
112
|
console.log(response);
|
|
96
113
|
});
|
|
@@ -98,16 +115,8 @@ const getStakeVault = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
98
115
|
const response = yield triadProtocol.stake.getStakeVaults();
|
|
99
116
|
console.log(response);
|
|
100
117
|
});
|
|
101
|
-
const updateStakeVaultStatus = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
|
-
const response = yield triadProtocol.stake.updateStakeVault({
|
|
103
|
-
wallet: wallet.publicKey,
|
|
104
|
-
amount: new anchor_1.BN(0),
|
|
105
|
-
status: false
|
|
106
|
-
});
|
|
107
|
-
console.log(response);
|
|
108
|
-
});
|
|
109
118
|
const updateBoost = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
110
|
-
const response = (yield axios_1.default.get('
|
|
119
|
+
const response = (yield axios_1.default.get('http://localhost:8080/boost'))
|
|
111
120
|
.data;
|
|
112
121
|
const stakes = yield triadProtocol.stake.getStakes();
|
|
113
122
|
const update = [];
|
|
@@ -130,78 +139,208 @@ const getAllMarkets = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
130
139
|
const markets = yield triadProtocol.trade.getAllMarkets();
|
|
131
140
|
console.log(markets);
|
|
132
141
|
});
|
|
133
|
-
getAllMarkets();
|
|
134
142
|
const getMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
135
|
-
const market = yield triadProtocol.trade.getMarketById(
|
|
143
|
+
const market = yield triadProtocol.trade.getMarketById(9);
|
|
136
144
|
console.log(market);
|
|
137
145
|
});
|
|
138
|
-
const initializeAllMarkets = () =>
|
|
139
|
-
|
|
140
|
-
try {
|
|
141
|
-
const response = yield triadProtocol.trade.initializeMarket(market, {
|
|
142
|
-
skipPreflight: true
|
|
143
|
-
});
|
|
144
|
-
console.log(`Initialized market ${market.name}:`, response);
|
|
145
|
-
}
|
|
146
|
-
catch (error) {
|
|
147
|
-
console.error(`Error initializing market ${market.name}:`, error);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
});
|
|
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);
|
|
154
|
-
});
|
|
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()) {
|
|
146
|
+
// const initializeAllMarkets = async () => {
|
|
147
|
+
// for (const market of markets) {
|
|
174
148
|
// try {
|
|
175
|
-
// const response = await triadProtocol.trade.
|
|
176
|
-
//
|
|
177
|
-
//
|
|
149
|
+
// const response = await triadProtocol.trade.initializeMarket(market, {
|
|
150
|
+
// skipPreflight: false,
|
|
151
|
+
// microLamports: 5000
|
|
178
152
|
// })
|
|
179
|
-
// console.log(response)
|
|
180
|
-
// } catch (
|
|
181
|
-
// console.
|
|
153
|
+
// console.log(`Initialized market ${market.name}:`, response)
|
|
154
|
+
// } catch (error) {
|
|
155
|
+
// console.error(`Error initializing market ${market.name}:`, error)
|
|
182
156
|
// }
|
|
183
157
|
// }
|
|
184
158
|
// }
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
159
|
+
const getOrders = (walletAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
160
|
+
const response = (yield triadProtocol.program.account.userTrade.all()).find((userTrade) => userTrade.account.authority.toBase58() === walletAddress.toBase58());
|
|
161
|
+
let orders = [];
|
|
162
|
+
for (const order of response.account.orders) {
|
|
163
|
+
if (!order.status.open) {
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
orders.push({
|
|
167
|
+
marketId: order.marketId,
|
|
168
|
+
orderId: order.orderId.toNumber(),
|
|
169
|
+
totalShares: order.totalShares.toString(),
|
|
170
|
+
amount: order.totalAmount.toString(),
|
|
171
|
+
direction: order.direction,
|
|
172
|
+
questionId: order.questionId,
|
|
173
|
+
price: order.price.toString(),
|
|
174
|
+
status: order.status
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
console.log(orders);
|
|
178
|
+
return orders;
|
|
179
|
+
});
|
|
180
|
+
// getOrders(new PublicKey('HjJQdfTHgC3EBX3471w4st8BXbBmtbaMyCAXNgcUb7dq'))
|
|
181
|
+
const getLiquidityToRecovery = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
182
|
+
const response = yield triadProtocol.program.account.userTrade.all();
|
|
183
|
+
const allMarkets = yield triadProtocol.trade.getAllMarkets();
|
|
184
|
+
const liquidityToRecovery = {
|
|
185
|
+
0: {
|
|
186
|
+
name: 'triad',
|
|
187
|
+
liquidityToPay: 0,
|
|
188
|
+
sharesToPay: 0,
|
|
189
|
+
openOrders: 0,
|
|
190
|
+
medPrice: 0,
|
|
191
|
+
direction: {
|
|
192
|
+
flop: {}
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
1: {
|
|
196
|
+
name: 'pyth',
|
|
197
|
+
liquidityToPay: 0,
|
|
198
|
+
sharesToPay: 0,
|
|
199
|
+
openOrders: 0,
|
|
200
|
+
medPrice: 0,
|
|
201
|
+
direction: {
|
|
202
|
+
flop: {}
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
2: {
|
|
206
|
+
name: 'drift',
|
|
207
|
+
liquidityToPay: 0,
|
|
208
|
+
sharesToPay: 0,
|
|
209
|
+
openOrders: 0,
|
|
210
|
+
medPrice: 0,
|
|
211
|
+
direction: {
|
|
212
|
+
flop: {}
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
3: {
|
|
216
|
+
name: 'symmetry',
|
|
217
|
+
liquidityToPay: 0,
|
|
218
|
+
sharesToPay: 0,
|
|
219
|
+
openOrders: 0,
|
|
220
|
+
medPrice: 0,
|
|
221
|
+
direction: {
|
|
222
|
+
flop: {}
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
4: {
|
|
226
|
+
name: 'ore',
|
|
227
|
+
liquidityToPay: 0,
|
|
228
|
+
sharesToPay: 0,
|
|
229
|
+
openOrders: 0,
|
|
230
|
+
medPrice: 0,
|
|
231
|
+
direction: {
|
|
232
|
+
hype: {}
|
|
233
|
+
}
|
|
234
|
+
},
|
|
235
|
+
5: {
|
|
236
|
+
name: 'coleta',
|
|
237
|
+
liquidityToPay: 0,
|
|
238
|
+
sharesToPay: 0,
|
|
239
|
+
openOrders: 0,
|
|
240
|
+
medPrice: 0,
|
|
241
|
+
direction: {
|
|
242
|
+
flop: {}
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
6: {
|
|
246
|
+
name: 'undead',
|
|
247
|
+
liquidityToPay: 0,
|
|
248
|
+
sharesToPay: 0,
|
|
249
|
+
openOrders: 0,
|
|
250
|
+
medPrice: 0,
|
|
251
|
+
direction: {
|
|
252
|
+
hype: {}
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
7: {
|
|
256
|
+
name: 'solxeth',
|
|
257
|
+
liquidityToPay: 0,
|
|
258
|
+
sharesToPay: 0,
|
|
259
|
+
openOrders: 0,
|
|
260
|
+
medPrice: 0,
|
|
261
|
+
direction: {
|
|
262
|
+
flop: {}
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
8: {
|
|
266
|
+
name: 'solxeth2',
|
|
267
|
+
liquidityToPay: 0,
|
|
268
|
+
sharesToPay: 0,
|
|
269
|
+
openOrders: 0,
|
|
270
|
+
medPrice: 0,
|
|
271
|
+
direction: {
|
|
272
|
+
flop: {}
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
9: {
|
|
276
|
+
name: 'solxeth3',
|
|
277
|
+
liquidityToPay: 0,
|
|
278
|
+
sharesToPay: 0,
|
|
279
|
+
openOrders: 0,
|
|
280
|
+
medPrice: 0,
|
|
281
|
+
direction: {
|
|
282
|
+
flop: {}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
for (const market of allMarkets) {
|
|
287
|
+
let currentMarket = liquidityToRecovery[market.marketId];
|
|
288
|
+
if ('flop' in currentMarket.direction) {
|
|
289
|
+
let shares = parseFloat(market.flopShares.toString()) / Math.pow(10, 6);
|
|
290
|
+
currentMarket.medPrice =
|
|
291
|
+
parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6) / shares;
|
|
292
|
+
currentMarket.sharesToPay = shares;
|
|
293
|
+
currentMarket.liquidityToPay =
|
|
294
|
+
parseFloat(market.hypeLiquidity.toString()) / Math.pow(10, 6);
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
let shares = parseFloat(market.hypeShares.toString()) / Math.pow(10, 6);
|
|
298
|
+
currentMarket.medPrice =
|
|
299
|
+
parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6) / shares;
|
|
300
|
+
currentMarket.sharesToPay = shares;
|
|
301
|
+
currentMarket.liquidityToPay =
|
|
302
|
+
parseFloat(market.flopLiquidity.toString()) / Math.pow(10, 6);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
for (const userTrade of response) {
|
|
306
|
+
for (const order of userTrade.account.orders) {
|
|
307
|
+
const market = liquidityToRecovery[order.marketId.toNumber()];
|
|
308
|
+
if (Object.keys(order.direction)[0] === Object.keys(market.direction)[0]) {
|
|
309
|
+
market.openOrders += 1;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
console.log(liquidityToRecovery);
|
|
314
|
+
});
|
|
315
|
+
getLiquidityToRecovery();
|
|
316
|
+
const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
317
|
+
yield getMarket();
|
|
318
|
+
for (const order of ordersHypeAndFloopBot) {
|
|
319
|
+
const response = yield triadProtocol.trade.openOrder({
|
|
320
|
+
marketId: order.marketId,
|
|
321
|
+
amount: order.amount,
|
|
322
|
+
direction: order.direction,
|
|
323
|
+
token: mint.toBase58(),
|
|
324
|
+
comment: `hype/flop bot ${order.amount} - ${order.direction}`
|
|
325
|
+
});
|
|
326
|
+
console.log(response);
|
|
327
|
+
}
|
|
328
|
+
yield new Promise((resolve) => setTimeout(resolve, 50000));
|
|
329
|
+
getMarket();
|
|
330
|
+
});
|
|
331
|
+
const closeOrder = (orderId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
332
|
+
const response = yield triadProtocol.trade.closeOrder({
|
|
333
|
+
marketId: 7,
|
|
334
|
+
orderId: orderId
|
|
335
|
+
});
|
|
336
|
+
console.log(response);
|
|
337
|
+
});
|
|
338
|
+
const closeOrders = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
339
|
+
for (const order of yield getOrders(wallet.publicKey)) {
|
|
197
340
|
try {
|
|
198
|
-
const response = yield triadProtocol.trade.
|
|
199
|
-
marketId:
|
|
200
|
-
|
|
201
|
-
startTime: question.startTime,
|
|
202
|
-
endTime: question.endTime
|
|
203
|
-
}, {
|
|
204
|
-
skipPreflight: true
|
|
341
|
+
const response = yield triadProtocol.trade.closeOrder({
|
|
342
|
+
marketId: order.marketId,
|
|
343
|
+
orderId: order.orderId
|
|
205
344
|
});
|
|
206
345
|
console.log(response);
|
|
207
346
|
}
|
|
@@ -210,11 +349,65 @@ const initializeQuestion = () => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
210
349
|
}
|
|
211
350
|
}
|
|
212
351
|
});
|
|
213
|
-
const
|
|
214
|
-
const
|
|
215
|
-
|
|
352
|
+
const mintTokens = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
353
|
+
// const mint = await createMint(
|
|
354
|
+
// connection,
|
|
355
|
+
// keypair,
|
|
356
|
+
// keypair.publicKey,
|
|
357
|
+
// null,
|
|
358
|
+
// 6,
|
|
359
|
+
// undefined,
|
|
360
|
+
// undefined,
|
|
361
|
+
// TOKEN_2022_PROGRAM_ID
|
|
362
|
+
// )
|
|
363
|
+
// console.log(mint)
|
|
364
|
+
const ataAddress = yield (0, spl_token_1.getAssociatedTokenAddress)(keypair.publicKey, mint);
|
|
365
|
+
console.log(ataAddress);
|
|
366
|
+
const ata = yield (0, spl_token_1.createAssociatedTokenAccount)(connection, keypair, mint, keypair.publicKey, undefined, spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
367
|
+
const mintTx = yield (0, spl_token_1.mintTo)(connection, keypair, mint, ata, keypair, 1000000 * Math.pow(10, 6), [keypair], undefined, spl_token_1.TOKEN_2022_PROGRAM_ID);
|
|
368
|
+
console.log(mintTx);
|
|
216
369
|
});
|
|
217
|
-
const
|
|
218
|
-
const
|
|
370
|
+
const resolveMarket = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
371
|
+
const marketsToResolve = [
|
|
372
|
+
{ marketId: 8, winningDirection: { flop: {} } },
|
|
373
|
+
{ marketId: 9, winningDirection: { flop: {} } }
|
|
374
|
+
];
|
|
375
|
+
for (const market of marketsToResolve) {
|
|
376
|
+
const response = yield triadProtocol.trade.resolveMarket({
|
|
377
|
+
marketId: market.marketId,
|
|
378
|
+
winningDirection: market.winningDirection
|
|
379
|
+
}, {
|
|
380
|
+
microLamports: 5000
|
|
381
|
+
});
|
|
382
|
+
console.log(response);
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
const addLiquidity = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
386
|
+
const response = yield triadProtocol.trade.addLiquidity({
|
|
387
|
+
marketId: 5,
|
|
388
|
+
amount: 4729,
|
|
389
|
+
direction: {
|
|
390
|
+
hype: {}
|
|
391
|
+
}
|
|
392
|
+
});
|
|
219
393
|
console.log(response);
|
|
220
394
|
});
|
|
395
|
+
const collectFees = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
396
|
+
console.log('Collecting fees');
|
|
397
|
+
const allMarkets = yield triadProtocol.trade.getAllMarkets();
|
|
398
|
+
for (const market of allMarkets) {
|
|
399
|
+
if (Number(market.marketId) === 0 || Number(market.marketId) === 7) {
|
|
400
|
+
continue;
|
|
401
|
+
}
|
|
402
|
+
console.log(`Collecting fees for market ${market.marketId}`);
|
|
403
|
+
try {
|
|
404
|
+
const response = yield triadProtocol.trade.collectFee({
|
|
405
|
+
marketId: Number(market.marketId)
|
|
406
|
+
});
|
|
407
|
+
console.log(response);
|
|
408
|
+
}
|
|
409
|
+
catch (e) {
|
|
410
|
+
console.log(e);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
});
|
package/dist/stake.d.ts
CHANGED
|
@@ -54,10 +54,10 @@ export default class Stake {
|
|
|
54
54
|
* Update Stake Vault
|
|
55
55
|
* @param wallet - User wallet
|
|
56
56
|
* @param amount - Reward amount to deposit (optional)
|
|
57
|
-
* @param
|
|
57
|
+
* @param isLocked - is locked stake vault (optional)
|
|
58
58
|
*
|
|
59
59
|
*/
|
|
60
|
-
updateStakeVault({ wallet, amount,
|
|
60
|
+
updateStakeVault({ wallet, amount, isLocked }: UpdateStakeVaultArgs, options?: RpcOptions): Promise<any>;
|
|
61
61
|
/**
|
|
62
62
|
* Request Withdraw
|
|
63
63
|
* @param wallet - User wallet
|
package/dist/stake.js
CHANGED
|
@@ -166,15 +166,15 @@ class Stake {
|
|
|
166
166
|
* Update Stake Vault
|
|
167
167
|
* @param wallet - User wallet
|
|
168
168
|
* @param amount - Reward amount to deposit (optional)
|
|
169
|
-
* @param
|
|
169
|
+
* @param isLocked - is locked stake vault (optional)
|
|
170
170
|
*
|
|
171
171
|
*/
|
|
172
|
-
updateStakeVault({ wallet, amount,
|
|
172
|
+
updateStakeVault({ wallet, amount, isLocked }, options) {
|
|
173
173
|
return __awaiter(this, void 0, void 0, function* () {
|
|
174
174
|
return (0, sendTransactionWithOptions_1.default)(this.program.methods
|
|
175
175
|
.updateStakeVault({
|
|
176
176
|
amount,
|
|
177
|
-
|
|
177
|
+
isLocked,
|
|
178
178
|
stakeVault: this.stakeVaultName
|
|
179
179
|
})
|
|
180
180
|
.accounts({
|
package/dist/trade.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AnchorProvider, Program } from '@coral-xyz/anchor';
|
|
2
2
|
import { TriadProtocol } from './types/triad_protocol';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
|
-
import {
|
|
4
|
+
import { InitializeMarketArgs, Market, OpenOrderArgs, OrderDirection } from './types/trade';
|
|
5
5
|
import { RpcOptions } from './types';
|
|
6
6
|
import BN from 'bn.js';
|
|
7
7
|
export default class Trade {
|
|
@@ -13,7 +13,6 @@ export default class Trade {
|
|
|
13
13
|
* Get all Markets
|
|
14
14
|
*/
|
|
15
15
|
getAllMarkets(): Promise<Market[]>;
|
|
16
|
-
getFeeVault(marketId: number): Promise<FeeVault>;
|
|
17
16
|
/**
|
|
18
17
|
* Get Market by ID
|
|
19
18
|
* @param marketId - The ID of the market
|
|
@@ -111,10 +110,7 @@ export default class Trade {
|
|
|
111
110
|
* @param options - RPC options
|
|
112
111
|
*
|
|
113
112
|
*/
|
|
114
|
-
initializeMarket({ marketId, name }:
|
|
115
|
-
marketId: number;
|
|
116
|
-
name: string;
|
|
117
|
-
}, options?: RpcOptions): Promise<any>;
|
|
113
|
+
initializeMarket({ marketId, name, startTime, endTime, question }: InitializeMarketArgs, options?: RpcOptions): Promise<any>;
|
|
118
114
|
/**
|
|
119
115
|
* Open Order
|
|
120
116
|
* @param marketId - The ID of the market
|
|
@@ -140,34 +136,57 @@ export default class Trade {
|
|
|
140
136
|
orderId: number;
|
|
141
137
|
}, options?: RpcOptions): Promise<string>;
|
|
142
138
|
/**
|
|
143
|
-
*
|
|
139
|
+
* Resolve Market
|
|
144
140
|
* @param marketId - The ID of the market
|
|
145
|
-
* @param
|
|
146
|
-
* @param startTime - The start time of the question
|
|
147
|
-
* @param endTime - The end time of the question
|
|
141
|
+
* @param winningDirection - The winning direction of the market
|
|
148
142
|
*
|
|
149
143
|
* @param options - RPC options
|
|
150
144
|
*
|
|
151
145
|
*/
|
|
152
|
-
|
|
146
|
+
resolveMarket({ marketId, winningDirection }: {
|
|
147
|
+
marketId: number;
|
|
148
|
+
winningDirection: {
|
|
149
|
+
hype: {};
|
|
150
|
+
} | {
|
|
151
|
+
flop: {};
|
|
152
|
+
} | {
|
|
153
|
+
none: {};
|
|
154
|
+
};
|
|
155
|
+
}, options?: RpcOptions): Promise<string>;
|
|
153
156
|
/**
|
|
154
|
-
*
|
|
157
|
+
* Settle an order
|
|
155
158
|
* @param marketId - The ID of the market
|
|
159
|
+
* @param orderId - The ID of the order to settle
|
|
156
160
|
*
|
|
157
161
|
* @param options - RPC options
|
|
158
162
|
*
|
|
159
163
|
*/
|
|
160
|
-
|
|
164
|
+
settleOrder({ marketId, orderId }: {
|
|
165
|
+
marketId: number;
|
|
166
|
+
orderId: number;
|
|
167
|
+
}, options?: RpcOptions): Promise<string>;
|
|
161
168
|
/**
|
|
162
|
-
*
|
|
169
|
+
* Add Liquidity
|
|
163
170
|
* @param marketId - The ID of the market
|
|
164
|
-
* @param
|
|
171
|
+
* @param amount - The amount of the order
|
|
172
|
+
* @param direction - The direction of the order
|
|
165
173
|
*
|
|
166
174
|
* @param options - RPC options
|
|
167
175
|
*
|
|
168
176
|
*/
|
|
169
|
-
|
|
177
|
+
addLiquidity({ marketId, amount, direction }: {
|
|
178
|
+
marketId: number;
|
|
179
|
+
amount: number;
|
|
180
|
+
direction: OrderDirection;
|
|
181
|
+
}, options?: RpcOptions): Promise<string>;
|
|
182
|
+
/**
|
|
183
|
+
* Collect Fee
|
|
184
|
+
* @param marketId - The ID of the market
|
|
185
|
+
*
|
|
186
|
+
* @param options - RPC options
|
|
187
|
+
*
|
|
188
|
+
*/
|
|
189
|
+
collectFee({ marketId }: {
|
|
170
190
|
marketId: number;
|
|
171
|
-
orderId: number;
|
|
172
191
|
}, options?: RpcOptions): Promise<string>;
|
|
173
192
|
}
|