@triadxyz/triad-protocol 0.5.8-beta.devnet → 0.6.0-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/local-test.js +6 -1
- package/dist/trade.js +30 -12
- package/dist/types/idl_triad_protocol.json +62 -6
- package/dist/types/triad_protocol.d.ts +91 -35
- package/dist/utils/helpers.d.ts +1 -0
- package/dist/utils/helpers.js +6 -1
- package/package.json +1 -1
package/dist/local-test.js
CHANGED
|
@@ -17,6 +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");
|
|
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-devnet.txt');
|
|
22
23
|
const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
|
|
@@ -76,6 +77,7 @@ const initializeAllMarkets = () => __awaiter(void 0, void 0, void 0, function* (
|
|
|
76
77
|
}
|
|
77
78
|
});
|
|
78
79
|
const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
80
|
+
const userTradePDA = (0, helpers_1.getUserTradeAddressSync)(triadProtocol.program.programId, wallet.publicKey);
|
|
79
81
|
const response = yield triadProtocol.trade.openOrder(0, {
|
|
80
82
|
amount: 100,
|
|
81
83
|
direction: {
|
|
@@ -84,7 +86,10 @@ const openOrder = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
84
86
|
orderType: {
|
|
85
87
|
market: {}
|
|
86
88
|
},
|
|
87
|
-
comment: 'test'
|
|
89
|
+
comment: 'test',
|
|
90
|
+
limitPrice: 10
|
|
91
|
+
}, {
|
|
92
|
+
skipPreflight: true
|
|
88
93
|
});
|
|
89
94
|
console.log(response);
|
|
90
95
|
});
|
package/dist/trade.js
CHANGED
|
@@ -111,29 +111,47 @@ class Trade {
|
|
|
111
111
|
openOrder(marketId, args, options) {
|
|
112
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
113
113
|
const marketPDA = (0, helpers_1.getMarketAddressSync)(this.program.programId, marketId);
|
|
114
|
-
const
|
|
114
|
+
const ixs = [];
|
|
115
|
+
try {
|
|
116
|
+
const userTradePDA = (0, helpers_1.getUserTradeAddressSync)(this.program.programId, this.provider.publicKey);
|
|
117
|
+
yield this.program.account.userTrade.fetch(userTradePDA);
|
|
118
|
+
}
|
|
119
|
+
catch (_a) {
|
|
120
|
+
ixs.push(yield this.program.methods
|
|
121
|
+
.createUserTrade()
|
|
122
|
+
.accounts({
|
|
123
|
+
signer: this.provider.publicKey
|
|
124
|
+
})
|
|
125
|
+
.instruction());
|
|
126
|
+
}
|
|
127
|
+
ixs.push(yield this.program.methods
|
|
115
128
|
.openOrder({
|
|
116
129
|
amount: new bn_js_1.default(args.amount / Math.pow(10, constants_1.TRD_DECIMALS)),
|
|
117
130
|
direction: args.direction,
|
|
118
131
|
orderType: args.orderType,
|
|
119
|
-
limitPrice: args.limitPrice
|
|
120
|
-
? new bn_js_1.default(args.limitPrice / Math.pow(10, constants_1.TRD_DECIMALS))
|
|
121
|
-
: undefined,
|
|
132
|
+
limitPrice: new bn_js_1.default(args.limitPrice / Math.pow(10, constants_1.TRD_DECIMALS)),
|
|
122
133
|
comment: (0, helpers_1.encodeString)(args.comment, 64)
|
|
123
134
|
})
|
|
124
135
|
.accounts({
|
|
125
136
|
signer: this.provider.publicKey,
|
|
126
137
|
market: marketPDA,
|
|
127
|
-
mint: constants_1.
|
|
128
|
-
})
|
|
138
|
+
mint: constants_1.TRD_MINT_DEVNET
|
|
139
|
+
})
|
|
140
|
+
.instruction());
|
|
129
141
|
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
})
|
|
134
|
-
]);
|
|
142
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
143
|
+
microLamports: options.microLamports
|
|
144
|
+
}));
|
|
135
145
|
}
|
|
136
|
-
|
|
146
|
+
const { blockhash } = yield this.provider.connection.getLatestBlockhash();
|
|
147
|
+
return this.provider.sendAndConfirm(new web3_js_1.VersionedTransaction(new web3_js_1.TransactionMessage({
|
|
148
|
+
instructions: ixs,
|
|
149
|
+
recentBlockhash: blockhash,
|
|
150
|
+
payerKey: this.provider.publicKey
|
|
151
|
+
}).compileToV0Message()), [], {
|
|
152
|
+
skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight,
|
|
153
|
+
commitment: 'confirmed'
|
|
154
|
+
});
|
|
137
155
|
});
|
|
138
156
|
}
|
|
139
157
|
}
|
|
@@ -164,6 +164,38 @@
|
|
|
164
164
|
}
|
|
165
165
|
]
|
|
166
166
|
},
|
|
167
|
+
{
|
|
168
|
+
"name": "create_user_trade",
|
|
169
|
+
"discriminator": [232, 235, 58, 194, 135, 248, 153, 1],
|
|
170
|
+
"accounts": [
|
|
171
|
+
{
|
|
172
|
+
"name": "signer",
|
|
173
|
+
"writable": true,
|
|
174
|
+
"signer": true
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
"name": "user_trade",
|
|
178
|
+
"writable": true,
|
|
179
|
+
"pda": {
|
|
180
|
+
"seeds": [
|
|
181
|
+
{
|
|
182
|
+
"kind": "const",
|
|
183
|
+
"value": [117, 115, 101, 114, 95, 116, 114, 97, 100, 101]
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
"kind": "account",
|
|
187
|
+
"path": "signer"
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
"name": "system_program",
|
|
194
|
+
"address": "11111111111111111111111111111111"
|
|
195
|
+
}
|
|
196
|
+
],
|
|
197
|
+
"args": []
|
|
198
|
+
},
|
|
167
199
|
{
|
|
168
200
|
"name": "initialize_market",
|
|
169
201
|
"discriminator": [35, 35, 189, 193, 155, 48, 170, 203],
|
|
@@ -205,6 +237,34 @@
|
|
|
205
237
|
]
|
|
206
238
|
}
|
|
207
239
|
},
|
|
240
|
+
{
|
|
241
|
+
"name": "fee_vault_token_account",
|
|
242
|
+
"writable": true,
|
|
243
|
+
"pda": {
|
|
244
|
+
"seeds": [
|
|
245
|
+
{
|
|
246
|
+
"kind": "account",
|
|
247
|
+
"path": "fee_vault"
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
"kind": "account",
|
|
251
|
+
"path": "token_program"
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
"kind": "account",
|
|
255
|
+
"path": "mint"
|
|
256
|
+
}
|
|
257
|
+
],
|
|
258
|
+
"program": {
|
|
259
|
+
"kind": "const",
|
|
260
|
+
"value": [
|
|
261
|
+
140, 151, 37, 143, 78, 36, 137, 241, 187, 61, 16, 41, 20, 142,
|
|
262
|
+
13, 131, 11, 90, 19, 153, 218, 255, 16, 132, 4, 142, 123, 216,
|
|
263
|
+
219, 233, 248, 89
|
|
264
|
+
]
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
},
|
|
208
268
|
{
|
|
209
269
|
"name": "mint",
|
|
210
270
|
"writable": true
|
|
@@ -376,12 +436,8 @@
|
|
|
376
436
|
"path": "fee_vault"
|
|
377
437
|
},
|
|
378
438
|
{
|
|
379
|
-
"kind": "
|
|
380
|
-
"
|
|
381
|
-
6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206,
|
|
382
|
-
235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140,
|
|
383
|
-
245, 133, 126, 255, 0, 169
|
|
384
|
-
]
|
|
439
|
+
"kind": "account",
|
|
440
|
+
"path": "token_program"
|
|
385
441
|
},
|
|
386
442
|
{
|
|
387
443
|
"kind": "account",
|
|
@@ -228,6 +228,38 @@ export type TriadProtocol = {
|
|
|
228
228
|
}
|
|
229
229
|
];
|
|
230
230
|
},
|
|
231
|
+
{
|
|
232
|
+
name: 'createUserTrade';
|
|
233
|
+
discriminator: [232, 235, 58, 194, 135, 248, 153, 1];
|
|
234
|
+
accounts: [
|
|
235
|
+
{
|
|
236
|
+
name: 'signer';
|
|
237
|
+
writable: true;
|
|
238
|
+
signer: true;
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'userTrade';
|
|
242
|
+
writable: true;
|
|
243
|
+
pda: {
|
|
244
|
+
seeds: [
|
|
245
|
+
{
|
|
246
|
+
kind: 'const';
|
|
247
|
+
value: [117, 115, 101, 114, 95, 116, 114, 97, 100, 101];
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
kind: 'account';
|
|
251
|
+
path: 'signer';
|
|
252
|
+
}
|
|
253
|
+
];
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
name: 'systemProgram';
|
|
258
|
+
address: '11111111111111111111111111111111';
|
|
259
|
+
}
|
|
260
|
+
];
|
|
261
|
+
args: [];
|
|
262
|
+
},
|
|
231
263
|
{
|
|
232
264
|
name: 'initializeMarket';
|
|
233
265
|
discriminator: [35, 35, 189, 193, 155, 48, 170, 203];
|
|
@@ -269,6 +301,63 @@ export type TriadProtocol = {
|
|
|
269
301
|
];
|
|
270
302
|
};
|
|
271
303
|
},
|
|
304
|
+
{
|
|
305
|
+
name: 'feeVaultTokenAccount';
|
|
306
|
+
writable: true;
|
|
307
|
+
pda: {
|
|
308
|
+
seeds: [
|
|
309
|
+
{
|
|
310
|
+
kind: 'account';
|
|
311
|
+
path: 'feeVault';
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
kind: 'account';
|
|
315
|
+
path: 'tokenProgram';
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
kind: 'account';
|
|
319
|
+
path: 'mint';
|
|
320
|
+
}
|
|
321
|
+
];
|
|
322
|
+
program: {
|
|
323
|
+
kind: 'const';
|
|
324
|
+
value: [
|
|
325
|
+
140,
|
|
326
|
+
151,
|
|
327
|
+
37,
|
|
328
|
+
143,
|
|
329
|
+
78,
|
|
330
|
+
36,
|
|
331
|
+
137,
|
|
332
|
+
241,
|
|
333
|
+
187,
|
|
334
|
+
61,
|
|
335
|
+
16,
|
|
336
|
+
41,
|
|
337
|
+
20,
|
|
338
|
+
142,
|
|
339
|
+
13,
|
|
340
|
+
131,
|
|
341
|
+
11,
|
|
342
|
+
90,
|
|
343
|
+
19,
|
|
344
|
+
153,
|
|
345
|
+
218,
|
|
346
|
+
255,
|
|
347
|
+
16,
|
|
348
|
+
132,
|
|
349
|
+
4,
|
|
350
|
+
142,
|
|
351
|
+
123,
|
|
352
|
+
216,
|
|
353
|
+
219,
|
|
354
|
+
233,
|
|
355
|
+
248,
|
|
356
|
+
89
|
|
357
|
+
];
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
},
|
|
272
361
|
{
|
|
273
362
|
name: 'mint';
|
|
274
363
|
writable: true;
|
|
@@ -527,41 +616,8 @@ export type TriadProtocol = {
|
|
|
527
616
|
path: 'feeVault';
|
|
528
617
|
},
|
|
529
618
|
{
|
|
530
|
-
kind: '
|
|
531
|
-
|
|
532
|
-
6,
|
|
533
|
-
221,
|
|
534
|
-
246,
|
|
535
|
-
225,
|
|
536
|
-
215,
|
|
537
|
-
101,
|
|
538
|
-
161,
|
|
539
|
-
147,
|
|
540
|
-
217,
|
|
541
|
-
203,
|
|
542
|
-
225,
|
|
543
|
-
70,
|
|
544
|
-
206,
|
|
545
|
-
235,
|
|
546
|
-
121,
|
|
547
|
-
172,
|
|
548
|
-
28,
|
|
549
|
-
180,
|
|
550
|
-
133,
|
|
551
|
-
237,
|
|
552
|
-
95,
|
|
553
|
-
91,
|
|
554
|
-
55,
|
|
555
|
-
145,
|
|
556
|
-
58,
|
|
557
|
-
140,
|
|
558
|
-
245,
|
|
559
|
-
133,
|
|
560
|
-
126,
|
|
561
|
-
255,
|
|
562
|
-
0,
|
|
563
|
-
169
|
|
564
|
-
];
|
|
619
|
+
kind: 'account';
|
|
620
|
+
path: 'tokenProgram';
|
|
565
621
|
},
|
|
566
622
|
{
|
|
567
623
|
kind: 'account';
|
package/dist/utils/helpers.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export declare const encodeString: (value: string, alloc?: number) => number[];
|
|
|
6
6
|
export declare const decodeString: (bytes: number[]) => string;
|
|
7
7
|
export declare const getMarketAddressSync: (programId: PublicKey, marketId: number) => PublicKey;
|
|
8
8
|
export declare const getFeeVaultAddressSync: (programId: PublicKey, market: PublicKey) => PublicKey;
|
|
9
|
+
export declare const getUserTradeAddressSync: (programId: PublicKey, wallet: PublicKey) => PublicKey;
|
|
9
10
|
export declare const getStakeVaultAddressSync: (programId: PublicKey, vaultName: string) => PublicKey;
|
|
10
11
|
export declare const getStakeAddressSync: (programId: PublicKey, wallet: PublicKey, name: string) => PublicKey;
|
|
11
12
|
export declare const getNFTRewardsAddressSync: (programId: PublicKey, stake: PublicKey) => PublicKey;
|
package/dist/utils/helpers.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.calculateAPR = exports.calculateTotalMultiplier = exports.formatUser = exports.formatStake = exports.formatStakeVault = exports.formatNumber = exports.getUserAddressSync = exports.getATASync = exports.getNFTRewardsAddressSync = exports.getStakeAddressSync = exports.getStakeVaultAddressSync = exports.getFeeVaultAddressSync = exports.getMarketAddressSync = exports.decodeString = exports.encodeString = exports.getTickerAddressSync = void 0;
|
|
6
|
+
exports.calculateAPR = exports.calculateTotalMultiplier = exports.formatUser = exports.formatStake = exports.formatStakeVault = exports.formatNumber = exports.getUserAddressSync = exports.getATASync = exports.getNFTRewardsAddressSync = exports.getStakeAddressSync = exports.getStakeVaultAddressSync = exports.getUserTradeAddressSync = exports.getFeeVaultAddressSync = exports.getMarketAddressSync = exports.decodeString = exports.encodeString = exports.getTickerAddressSync = void 0;
|
|
7
7
|
const stake_1 = require("./../types/stake");
|
|
8
8
|
const web3_js_1 = require("@solana/web3.js");
|
|
9
9
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
@@ -35,6 +35,11 @@ const getFeeVaultAddressSync = (programId, market) => {
|
|
|
35
35
|
return FeeVaultPDA;
|
|
36
36
|
};
|
|
37
37
|
exports.getFeeVaultAddressSync = getFeeVaultAddressSync;
|
|
38
|
+
const getUserTradeAddressSync = (programId, wallet) => {
|
|
39
|
+
const [UserTradePDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('user_trade'), wallet.toBuffer()], programId);
|
|
40
|
+
return UserTradePDA;
|
|
41
|
+
};
|
|
42
|
+
exports.getUserTradeAddressSync = getUserTradeAddressSync;
|
|
38
43
|
const getStakeVaultAddressSync = (programId, vaultName) => {
|
|
39
44
|
const [StakeVaultPDA] = web3_js_1.PublicKey.findProgramAddressSync([Buffer.from('stake_vault'), Buffer.from(vaultName)], programId);
|
|
40
45
|
return StakeVaultPDA;
|