@triadxyz/triad-protocol 2.1.2-beta → 2.1.4-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/index.js +51 -24
- package/dist/stake.js +41 -25
- package/dist/trade.d.ts +1 -1
- package/dist/trade.js +124 -69
- package/dist/types/idl_triad_protocol.json +2 -2
- package/dist/types/trade.d.ts +1 -0
- package/dist/types/triad_protocol.d.ts +2 -2
- package/package.json +1 -1
- package/dist/utils/sendMethod.d.ts +0 -5
- package/dist/utils/sendMethod.js +0 -35
package/dist/index.js
CHANGED
|
@@ -19,7 +19,6 @@ const poseidon_1 = require("./utils/pda/poseidon");
|
|
|
19
19
|
const stake_1 = __importDefault(require("./stake"));
|
|
20
20
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
21
21
|
const constants_1 = require("./utils/constants");
|
|
22
|
-
const sendMethod_1 = __importDefault(require("./utils/sendMethod"));
|
|
23
22
|
const pda_1 = require("./utils/pda");
|
|
24
23
|
class TriadProtocolClient {
|
|
25
24
|
constructor(connection, wallet) {
|
|
@@ -68,13 +67,20 @@ class TriadProtocolClient {
|
|
|
68
67
|
* @param options - RPC options
|
|
69
68
|
*/
|
|
70
69
|
withdrawPoseidon({ poseidonAsset, nft }, options) {
|
|
71
|
-
return (0,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const ixs = [];
|
|
72
|
+
ixs.push(yield this.program.methods
|
|
73
|
+
.withdrawPoseidon()
|
|
74
|
+
.accounts({
|
|
75
|
+
signer: this.provider.wallet.publicKey,
|
|
76
|
+
nft: (0, poseidon_1.getPoseidonPDA)(this.program.programId, nft),
|
|
77
|
+
poseidonAsset,
|
|
78
|
+
poseidonCollection: (0, poseidon_1.getCollectionPDA)(this.program.programId, constants_1.POSEIDON_COLLECTION_SYMBOL),
|
|
79
|
+
corePoseidonCollection: constants_1.POSEIDON_CORE_COLLECTION
|
|
80
|
+
})
|
|
81
|
+
.instruction());
|
|
82
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
83
|
+
});
|
|
78
84
|
}
|
|
79
85
|
/**
|
|
80
86
|
* Collect Royalty
|
|
@@ -83,10 +89,17 @@ class TriadProtocolClient {
|
|
|
83
89
|
* @param options - RPC options
|
|
84
90
|
*/
|
|
85
91
|
collectRoyalty(collection, options) {
|
|
86
|
-
return (0,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
const ixs = [];
|
|
94
|
+
ixs.push(yield this.program.methods
|
|
95
|
+
.collectRoyalty()
|
|
96
|
+
.accounts({
|
|
97
|
+
signer: this.provider.wallet.publicKey,
|
|
98
|
+
collection: (0, poseidon_1.getCollectionPDA)(this.program.programId, collection)
|
|
99
|
+
})
|
|
100
|
+
.instruction());
|
|
101
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
102
|
+
});
|
|
90
103
|
}
|
|
91
104
|
/**
|
|
92
105
|
* Add Trader Poseidon
|
|
@@ -96,12 +109,19 @@ class TriadProtocolClient {
|
|
|
96
109
|
* @param options - RPC options
|
|
97
110
|
*/
|
|
98
111
|
addTraderPoseidon({ user, poseidonAsset }, options) {
|
|
99
|
-
return (0,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
const ixs = [];
|
|
114
|
+
ixs.push(yield this.program.methods
|
|
115
|
+
.addTraderPoseidon()
|
|
116
|
+
.accounts({
|
|
117
|
+
poseidonAsset,
|
|
118
|
+
userTrade: (0, pda_1.getUserTradePDA)(this.program.programId, user),
|
|
119
|
+
corePoseidonCollection: constants_1.POSEIDON_CORE_COLLECTION,
|
|
120
|
+
poseidonCollection: (0, poseidon_1.getCollectionPDA)(this.program.programId, constants_1.POSEIDON_COLLECTION_SYMBOL)
|
|
121
|
+
})
|
|
122
|
+
.instruction());
|
|
123
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
124
|
+
});
|
|
105
125
|
}
|
|
106
126
|
/**
|
|
107
127
|
* Remove Trader Poseidon
|
|
@@ -110,12 +130,19 @@ class TriadProtocolClient {
|
|
|
110
130
|
* @param options - RPC options
|
|
111
131
|
*/
|
|
112
132
|
removeTraderPoseidon({ user, poseidonAsset }, options) {
|
|
113
|
-
return (0,
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
133
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
const ixs = [];
|
|
135
|
+
ixs.push(yield this.program.methods
|
|
136
|
+
.removeTraderPoseidon()
|
|
137
|
+
.accounts({
|
|
138
|
+
userTrade: (0, pda_1.getUserTradePDA)(this.program.programId, user),
|
|
139
|
+
poseidonAsset,
|
|
140
|
+
corePoseidonCollection: constants_1.POSEIDON_CORE_COLLECTION,
|
|
141
|
+
poseidonCollection: (0, poseidon_1.getCollectionPDA)(this.program.programId, constants_1.POSEIDON_COLLECTION_SYMBOL)
|
|
142
|
+
})
|
|
143
|
+
.instruction());
|
|
144
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
145
|
+
});
|
|
119
146
|
}
|
|
120
147
|
}
|
|
121
148
|
exports.default = TriadProtocolClient;
|
package/dist/stake.js
CHANGED
|
@@ -17,7 +17,6 @@ const helpers_1 = require("./utils/helpers");
|
|
|
17
17
|
const stake_1 = require("./utils/pda/stake");
|
|
18
18
|
const constants_1 = require("./utils/constants");
|
|
19
19
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
20
|
-
const sendMethod_1 = __importDefault(require("./utils/sendMethod"));
|
|
21
20
|
class Stake {
|
|
22
21
|
constructor(program) {
|
|
23
22
|
this.program = program;
|
|
@@ -80,15 +79,20 @@ class Stake {
|
|
|
80
79
|
*
|
|
81
80
|
*/
|
|
82
81
|
stakeToken({ name, wallet, amount }, options) {
|
|
83
|
-
return (0,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const ixs = [];
|
|
84
|
+
ixs.push(yield this.program.methods
|
|
85
|
+
.stakeToken({
|
|
86
|
+
name,
|
|
87
|
+
amount: new anchor_1.BN(amount * Math.pow(10, 6))
|
|
88
|
+
})
|
|
89
|
+
.accounts({
|
|
90
|
+
signer: wallet,
|
|
91
|
+
mint: constants_1.TRD_MINT
|
|
92
|
+
})
|
|
93
|
+
.instruction());
|
|
94
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
95
|
+
});
|
|
92
96
|
}
|
|
93
97
|
/**
|
|
94
98
|
* Update Stake Vault
|
|
@@ -99,15 +103,20 @@ class Stake {
|
|
|
99
103
|
*
|
|
100
104
|
*/
|
|
101
105
|
updateStakeVault({ amount, isLocked }, options) {
|
|
102
|
-
return (0,
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
+
const ixs = [];
|
|
108
|
+
ixs.push(yield this.program.methods
|
|
109
|
+
.updateStakeVault({
|
|
110
|
+
amount,
|
|
111
|
+
isLocked
|
|
112
|
+
})
|
|
113
|
+
.accounts({
|
|
114
|
+
signer: this.program.provider.publicKey,
|
|
115
|
+
mint: constants_1.TRD_MINT
|
|
116
|
+
})
|
|
117
|
+
.instruction());
|
|
118
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
119
|
+
});
|
|
111
120
|
}
|
|
112
121
|
/**
|
|
113
122
|
* Request Withdraw
|
|
@@ -142,12 +151,19 @@ class Stake {
|
|
|
142
151
|
*
|
|
143
152
|
*/
|
|
144
153
|
withdrawStake({ wallet, name, mint }, options) {
|
|
145
|
-
return (0,
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
+
const ixs = [];
|
|
156
|
+
ixs.push(yield this.program.methods
|
|
157
|
+
.withdrawStake()
|
|
158
|
+
.accounts({
|
|
159
|
+
signer: wallet,
|
|
160
|
+
stake: (0, stake_1.getStakePDA)(this.program.programId, wallet, name),
|
|
161
|
+
admin: constants_1.TRIAD_ADMIN,
|
|
162
|
+
mint: mint
|
|
163
|
+
})
|
|
164
|
+
.instruction());
|
|
165
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
166
|
+
});
|
|
151
167
|
}
|
|
152
168
|
/**
|
|
153
169
|
* Claim Stake Rewards
|
package/dist/trade.d.ts
CHANGED
|
@@ -336,7 +336,7 @@ export default class Trade {
|
|
|
336
336
|
*
|
|
337
337
|
* @param options - RPC options
|
|
338
338
|
*/
|
|
339
|
-
marketBidOrder({ marketId, amount, direction, mint }: MarketBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
339
|
+
marketBidOrder({ marketId, amount, direction, mint, feeBps }: MarketBidOrderArgs, options?: RpcOptions): Promise<string>;
|
|
340
340
|
/**
|
|
341
341
|
* Get Orders By Market ID
|
|
342
342
|
* @param marketId - The ID of the market
|
package/dist/trade.js
CHANGED
|
@@ -19,7 +19,6 @@ const constants_1 = require("./utils/constants");
|
|
|
19
19
|
const helpers_1 = require("./utils/helpers");
|
|
20
20
|
const pda_1 = require("./utils/pda");
|
|
21
21
|
const sendVersionedTransaction_1 = __importDefault(require("./utils/sendVersionedTransaction"));
|
|
22
|
-
const sendMethod_1 = __importDefault(require("./utils/sendMethod"));
|
|
23
22
|
const bytes_1 = require("@coral-xyz/anchor/dist/cjs/utils/bytes");
|
|
24
23
|
const pda_2 = require("./utils/pda");
|
|
25
24
|
class Trade {
|
|
@@ -118,25 +117,30 @@ class Trade {
|
|
|
118
117
|
*
|
|
119
118
|
*/
|
|
120
119
|
createMarket({ marketId, startTime, endTime, question, feeBps, customer, payoutFee, mint }, options) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
120
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
121
|
+
if (question.length > 80) {
|
|
122
|
+
throw new Error('Question must be less than 80 characters');
|
|
123
|
+
}
|
|
124
|
+
const ixs = [];
|
|
125
|
+
ixs.push(yield this.program.methods
|
|
126
|
+
.createMarket({
|
|
127
|
+
marketId: new bn_js_1.default(marketId),
|
|
128
|
+
question: (0, helpers_1.encodeString)(question, 80),
|
|
129
|
+
marketStart: new bn_js_1.default(startTime),
|
|
130
|
+
marketEnd: new bn_js_1.default(endTime),
|
|
131
|
+
feeBps,
|
|
132
|
+
payoutFee
|
|
133
|
+
})
|
|
134
|
+
.accounts({
|
|
135
|
+
signer: this.program.provider.publicKey,
|
|
136
|
+
mint,
|
|
137
|
+
tokenProgram: (0, helpers_1.getTokenProgram)(mint),
|
|
138
|
+
customer,
|
|
139
|
+
pool: null
|
|
140
|
+
})
|
|
141
|
+
.instruction());
|
|
142
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
143
|
+
});
|
|
140
144
|
}
|
|
141
145
|
/**
|
|
142
146
|
* Create Pool
|
|
@@ -231,17 +235,22 @@ class Trade {
|
|
|
231
235
|
*/
|
|
232
236
|
closeOrder({ marketId, orderId, userNonce }, options) {
|
|
233
237
|
return __awaiter(this, void 0, void 0, function* () {
|
|
238
|
+
const ixs = [];
|
|
234
239
|
let userTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, this.program.provider.publicKey);
|
|
235
240
|
if (userNonce !== 0) {
|
|
236
241
|
const subUserTradePDA = (0, pda_1.getSubUserTradePDA)(this.program.programId, this.program.provider.publicKey, userNonce);
|
|
237
242
|
userTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
238
243
|
}
|
|
239
|
-
|
|
244
|
+
ixs.push(yield this.program.methods
|
|
245
|
+
.closeOrder(new bn_js_1.default(orderId))
|
|
246
|
+
.accounts({
|
|
240
247
|
signer: this.program.provider.publicKey,
|
|
241
248
|
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
242
249
|
mint: constants_1.TRD_MINT,
|
|
243
250
|
userTrade: userTradePDA
|
|
244
|
-
})
|
|
251
|
+
})
|
|
252
|
+
.instruction());
|
|
253
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
245
254
|
});
|
|
246
255
|
}
|
|
247
256
|
/**
|
|
@@ -253,16 +262,21 @@ class Trade {
|
|
|
253
262
|
*
|
|
254
263
|
*/
|
|
255
264
|
resolveMarket({ marketId, winningDirection }, options) {
|
|
256
|
-
return (0,
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
265
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
266
|
+
const ixs = [];
|
|
267
|
+
ixs.push(yield this.program.methods
|
|
268
|
+
.updateMarket({
|
|
269
|
+
winningDirection,
|
|
270
|
+
allowPayout: null,
|
|
271
|
+
marketEnd: null
|
|
272
|
+
})
|
|
273
|
+
.accounts({
|
|
274
|
+
signer: this.program.provider.publicKey,
|
|
275
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
|
|
276
|
+
})
|
|
277
|
+
.instruction());
|
|
278
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
279
|
+
});
|
|
266
280
|
}
|
|
267
281
|
/**
|
|
268
282
|
* Collect Remaining Liquidity
|
|
@@ -273,13 +287,18 @@ class Trade {
|
|
|
273
287
|
*/
|
|
274
288
|
collectRemainingLiquidity(marketId, options) {
|
|
275
289
|
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
+
const ixs = [];
|
|
276
291
|
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
277
292
|
const market = yield this.getMarketByAddress(marketPDA);
|
|
278
|
-
|
|
293
|
+
ixs.push(yield this.program.methods
|
|
294
|
+
.collectRemainingLiquidity()
|
|
295
|
+
.accounts({
|
|
279
296
|
signer: this.program.provider.publicKey,
|
|
280
297
|
market: marketPDA,
|
|
281
298
|
mint: market.mint
|
|
282
|
-
})
|
|
299
|
+
})
|
|
300
|
+
.instruction());
|
|
301
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
283
302
|
});
|
|
284
303
|
}
|
|
285
304
|
/**
|
|
@@ -325,16 +344,21 @@ class Trade {
|
|
|
325
344
|
*
|
|
326
345
|
*/
|
|
327
346
|
allowMarketToPayout(marketId, options) {
|
|
328
|
-
return (0,
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
347
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
348
|
+
const ixs = [];
|
|
349
|
+
ixs.push(yield this.program.methods
|
|
350
|
+
.updateMarket({
|
|
351
|
+
winningDirection: null,
|
|
352
|
+
allowPayout: true,
|
|
353
|
+
marketEnd: null
|
|
354
|
+
})
|
|
355
|
+
.accounts({
|
|
356
|
+
signer: this.program.provider.publicKey,
|
|
357
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
|
|
358
|
+
})
|
|
359
|
+
.instruction());
|
|
360
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
361
|
+
});
|
|
338
362
|
}
|
|
339
363
|
/**
|
|
340
364
|
* Create Sub User Trade
|
|
@@ -345,11 +369,16 @@ class Trade {
|
|
|
345
369
|
*/
|
|
346
370
|
createSubUserTrade(user, options) {
|
|
347
371
|
return __awaiter(this, void 0, void 0, function* () {
|
|
372
|
+
const ixs = [];
|
|
348
373
|
const userTrade = yield this.getUserTrade(user);
|
|
349
374
|
const subUserTradePDA = (0, pda_1.getSubUserTradePDA)(this.program.programId, user, userTrade.nonce + 1);
|
|
350
|
-
|
|
375
|
+
ixs.push(yield this.program.methods
|
|
376
|
+
.createSubUserTrade(subUserTradePDA)
|
|
377
|
+
.accounts({
|
|
351
378
|
signer: this.program.provider.publicKey
|
|
352
|
-
})
|
|
379
|
+
})
|
|
380
|
+
.instruction());
|
|
381
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
353
382
|
});
|
|
354
383
|
}
|
|
355
384
|
/**
|
|
@@ -361,16 +390,21 @@ class Trade {
|
|
|
361
390
|
*
|
|
362
391
|
*/
|
|
363
392
|
updateMarket(marketId, marketEnd, options) {
|
|
364
|
-
return (0,
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
393
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
394
|
+
const ixs = [];
|
|
395
|
+
ixs.push(yield this.program.methods
|
|
396
|
+
.updateMarket({
|
|
397
|
+
marketEnd: new bn_js_1.default(marketEnd),
|
|
398
|
+
winningDirection: null,
|
|
399
|
+
allowPayout: null
|
|
400
|
+
})
|
|
401
|
+
.accounts({
|
|
402
|
+
signer: this.program.provider.publicKey,
|
|
403
|
+
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId)
|
|
404
|
+
})
|
|
405
|
+
.instruction());
|
|
406
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
407
|
+
});
|
|
374
408
|
}
|
|
375
409
|
/**
|
|
376
410
|
* Create Customer
|
|
@@ -382,11 +416,16 @@ class Trade {
|
|
|
382
416
|
*
|
|
383
417
|
*/
|
|
384
418
|
createCustomer({ id, name, authority, feeRecipient }, options) {
|
|
385
|
-
return (0,
|
|
386
|
-
|
|
387
|
-
.
|
|
388
|
-
|
|
389
|
-
|
|
419
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
420
|
+
const ixs = [];
|
|
421
|
+
ixs.push(yield this.program.methods
|
|
422
|
+
.createCustomer({ id, name, authority, feeRecipient })
|
|
423
|
+
.accounts({
|
|
424
|
+
signer: this.program.provider.publicKey
|
|
425
|
+
})
|
|
426
|
+
.instruction());
|
|
427
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
428
|
+
});
|
|
390
429
|
}
|
|
391
430
|
/**
|
|
392
431
|
* Get User Trade Nonce With Slots
|
|
@@ -549,18 +588,23 @@ class Trade {
|
|
|
549
588
|
*/
|
|
550
589
|
cancelBidOrder({ marketId, orderId, userNonce, mint }, options) {
|
|
551
590
|
return __awaiter(this, void 0, void 0, function* () {
|
|
591
|
+
const ixs = [];
|
|
552
592
|
let userTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, this.program.provider.publicKey);
|
|
553
593
|
if (userNonce !== 0) {
|
|
554
594
|
const subUserTradePDA = (0, pda_1.getSubUserTradePDA)(this.program.programId, this.program.provider.publicKey, userNonce);
|
|
555
595
|
userTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
556
596
|
}
|
|
557
|
-
|
|
597
|
+
ixs.push(yield this.program.methods
|
|
598
|
+
.cancelBidOrder(new bn_js_1.default(orderId))
|
|
599
|
+
.accounts({
|
|
558
600
|
signer: this.program.provider.publicKey,
|
|
559
601
|
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
560
602
|
bidUserTrade: userTradePDA,
|
|
561
603
|
mint,
|
|
562
604
|
tokenProgram: (0, helpers_1.getTokenProgram)(mint)
|
|
563
|
-
})
|
|
605
|
+
})
|
|
606
|
+
.instruction());
|
|
607
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
564
608
|
});
|
|
565
609
|
}
|
|
566
610
|
/**
|
|
@@ -574,6 +618,7 @@ class Trade {
|
|
|
574
618
|
*/
|
|
575
619
|
cancelAskOrder({ marketId, orderId, userNonce, userNonceBidOrder }, options) {
|
|
576
620
|
return __awaiter(this, void 0, void 0, function* () {
|
|
621
|
+
const ixs = [];
|
|
577
622
|
let askUserTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, this.program.provider.publicKey);
|
|
578
623
|
if (userNonce !== 0) {
|
|
579
624
|
const subUserTradePDA = (0, pda_1.getSubUserTradePDA)(this.program.programId, this.program.provider.publicKey, userNonce);
|
|
@@ -584,12 +629,16 @@ class Trade {
|
|
|
584
629
|
const subUserTradePDA = (0, pda_1.getSubUserTradePDA)(this.program.programId, this.program.provider.publicKey, userNonceBidOrder);
|
|
585
630
|
bidUserTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, subUserTradePDA);
|
|
586
631
|
}
|
|
587
|
-
|
|
632
|
+
ixs.push(yield this.program.methods
|
|
633
|
+
.cancelAskOrder(new bn_js_1.default(orderId))
|
|
634
|
+
.accounts({
|
|
588
635
|
signer: this.program.provider.publicKey,
|
|
589
636
|
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
590
637
|
askUserTrade: askUserTradePDA,
|
|
591
638
|
bidUserTrade: bidUserTradePDA
|
|
592
|
-
})
|
|
639
|
+
})
|
|
640
|
+
.instruction());
|
|
641
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
593
642
|
});
|
|
594
643
|
}
|
|
595
644
|
/**
|
|
@@ -601,7 +650,7 @@ class Trade {
|
|
|
601
650
|
*
|
|
602
651
|
* @param options - RPC options
|
|
603
652
|
*/
|
|
604
|
-
marketBidOrder({ marketId, amount, direction, mint }, options) {
|
|
653
|
+
marketBidOrder({ marketId, amount, direction, mint, feeBps = 0 }, options) {
|
|
605
654
|
return __awaiter(this, void 0, void 0, function* () {
|
|
606
655
|
const marketPDA = (0, pda_1.getMarketPDA)(this.program.programId, marketId);
|
|
607
656
|
const ixs = [];
|
|
@@ -613,7 +662,7 @@ class Trade {
|
|
|
613
662
|
: orderBook.flop.ask;
|
|
614
663
|
const sortedOrders = orders.sort((a, b) => Number(a.price) - Number(b.price));
|
|
615
664
|
for (const order of sortedOrders) {
|
|
616
|
-
if (remainingUSDC.div(new bn_js_1.default(Math.pow(10, this.decimals))).
|
|
665
|
+
if (remainingUSDC.div(new bn_js_1.default(Math.pow(10, this.decimals))).toNumber() === 0)
|
|
617
666
|
break;
|
|
618
667
|
if (order.authority === this.program.provider.publicKey.toBase58()) {
|
|
619
668
|
return;
|
|
@@ -634,14 +683,20 @@ class Trade {
|
|
|
634
683
|
}
|
|
635
684
|
const orderPrice = new bn_js_1.default(order.price);
|
|
636
685
|
const availableShares = new bn_js_1.default(order.totalShares);
|
|
686
|
+
let adjustedPrice = orderPrice;
|
|
687
|
+
if (feeBps > 0) {
|
|
688
|
+
const priceSpread = new bn_js_1.default(1000000).sub(orderPrice);
|
|
689
|
+
const fee = priceSpread.mul(new bn_js_1.default(feeBps)).div(new bn_js_1.default(10000));
|
|
690
|
+
adjustedPrice = orderPrice.add(fee);
|
|
691
|
+
}
|
|
637
692
|
const maxSharesForPrice = remainingUSDC
|
|
638
693
|
.mul(new bn_js_1.default(Math.pow(10, this.decimals)))
|
|
639
|
-
.div(
|
|
694
|
+
.div(adjustedPrice);
|
|
640
695
|
const sharesToBuy = bn_js_1.default.min(maxSharesForPrice, availableShares);
|
|
641
696
|
if (sharesToBuy.lten(0))
|
|
642
697
|
continue;
|
|
643
698
|
const usdcAmount = sharesToBuy
|
|
644
|
-
.mul(
|
|
699
|
+
.mul(adjustedPrice)
|
|
645
700
|
.div(new bn_js_1.default(Math.pow(10, this.decimals)));
|
|
646
701
|
let sellerTradePDA = (0, pda_1.getUserTradePDA)(this.program.programId, new web3_js_1.PublicKey(order.authority));
|
|
647
702
|
if (order.userNonce !== '0') {
|
package/dist/types/trade.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { RpcOptions } from '../types';
|
|
2
|
-
import { MethodsBuilder } from '@coral-xyz/anchor/dist/cjs/program/namespace/methods';
|
|
3
|
-
import { TriadProtocol } from '../types/triad_protocol';
|
|
4
|
-
declare const sendMethod: (method: MethodsBuilder<TriadProtocol, any, any>, options?: RpcOptions) => Promise<string>;
|
|
5
|
-
export default sendMethod;
|
package/dist/utils/sendMethod.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
16
|
-
const getPriorityFee_1 = __importDefault(require("./getPriorityFee"));
|
|
17
|
-
const sendMethod = (method, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
19
|
-
method.postInstructions([
|
|
20
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
21
|
-
microLamports: options.microLamports
|
|
22
|
-
})
|
|
23
|
-
]);
|
|
24
|
-
}
|
|
25
|
-
if (!(options === null || options === void 0 ? void 0 : options.microLamports)) {
|
|
26
|
-
const priorityFee = yield (0, getPriorityFee_1.default)();
|
|
27
|
-
method.postInstructions([
|
|
28
|
-
web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
29
|
-
microLamports: priorityFee
|
|
30
|
-
})
|
|
31
|
-
]);
|
|
32
|
-
}
|
|
33
|
-
return method.rpc({ skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight });
|
|
34
|
-
});
|
|
35
|
-
exports.default = sendMethod;
|