@triadxyz/triad-protocol 2.4.9-beta → 2.5.1-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.d.ts +8 -1
- package/dist/index.js +22 -21
- package/dist/stake.d.ts +26 -29
- package/dist/stake.js +72 -62
- package/dist/types/idl_triad_protocol.json +463 -114
- package/dist/types/index.d.ts +9 -2
- package/dist/types/stake.d.ts +14 -23
- package/dist/types/triad_protocol.d.ts +541 -110
- package/dist/utils/helpers.d.ts +7 -4
- package/dist/utils/helpers.js +35 -11
- package/dist/utils/pda/stake.d.ts +2 -1
- package/dist/utils/pda/stake.js +6 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -297,7 +297,7 @@ export default class TriadProtocolClient {
|
|
|
297
297
|
* @param options - RPC options
|
|
298
298
|
*
|
|
299
299
|
*/
|
|
300
|
-
createCustomer({ id, name, authority, feeRecipient }: CreateCustomerArgs, options?: RpcOptions): Promise<string>;
|
|
300
|
+
createCustomer({ id, name, authority, feeRecipient, feeBps }: CreateCustomerArgs, options?: RpcOptions): Promise<string>;
|
|
301
301
|
/**
|
|
302
302
|
* Get User Trade Nonce With Slots
|
|
303
303
|
* @param userTrades - User Trades
|
|
@@ -416,4 +416,11 @@ export default class TriadProtocolClient {
|
|
|
416
416
|
* @param options - RPC options
|
|
417
417
|
*/
|
|
418
418
|
closeOrderBook(marketId: number, options?: RpcOptions): Promise<string>;
|
|
419
|
+
/**
|
|
420
|
+
* Create Refer
|
|
421
|
+
* @param id - The ID of the refer
|
|
422
|
+
*
|
|
423
|
+
* @param options - RPC options
|
|
424
|
+
*/
|
|
425
|
+
createRefer(id: number, options?: RpcOptions): Promise<string>;
|
|
419
426
|
}
|
package/dist/index.js
CHANGED
|
@@ -159,12 +159,6 @@ class TriadProtocolClient {
|
|
|
159
159
|
createMarket({ markets, customer, mint, poolId }, options) {
|
|
160
160
|
return __awaiter(this, void 0, void 0, function* () {
|
|
161
161
|
const ixs = [];
|
|
162
|
-
let userTrade = null;
|
|
163
|
-
try {
|
|
164
|
-
yield this.getUserTrade(this.program.provider.publicKey);
|
|
165
|
-
userTrade = (0, pda_1.getUserTradePDA)(this.program.programId, this.program.provider.publicKey);
|
|
166
|
-
}
|
|
167
|
-
catch (_a) { }
|
|
168
162
|
let poolPDA = null;
|
|
169
163
|
if (poolId) {
|
|
170
164
|
poolPDA = (0, pda_1.getPoolPDA)(this.program.programId, poolId);
|
|
@@ -184,11 +178,9 @@ class TriadProtocolClient {
|
|
|
184
178
|
})
|
|
185
179
|
.accounts({
|
|
186
180
|
signer: this.program.provider.publicKey,
|
|
187
|
-
mint,
|
|
188
181
|
tokenProgram: (0, helpers_1.getTokenProgram)(mint),
|
|
189
182
|
customer,
|
|
190
|
-
pool: poolPDA
|
|
191
|
-
userTrade
|
|
183
|
+
pool: poolPDA
|
|
192
184
|
})
|
|
193
185
|
.instruction());
|
|
194
186
|
ixs.push(yield this.program.methods
|
|
@@ -227,12 +219,6 @@ class TriadProtocolClient {
|
|
|
227
219
|
signer: this.program.provider.publicKey
|
|
228
220
|
})
|
|
229
221
|
.instruction());
|
|
230
|
-
let userTrade = null;
|
|
231
|
-
try {
|
|
232
|
-
yield this.getUserTrade(this.program.provider.publicKey);
|
|
233
|
-
userTrade = (0, pda_1.getUserTradePDA)(this.program.programId, this.program.provider.publicKey);
|
|
234
|
-
}
|
|
235
|
-
catch (_a) { }
|
|
236
222
|
for (const market of markets) {
|
|
237
223
|
if (market.question.length > 80) {
|
|
238
224
|
throw new Error('Market question must be less than 80 characters');
|
|
@@ -248,11 +234,9 @@ class TriadProtocolClient {
|
|
|
248
234
|
})
|
|
249
235
|
.accounts({
|
|
250
236
|
signer: this.program.provider.publicKey,
|
|
251
|
-
mint,
|
|
252
237
|
tokenProgram: (0, helpers_1.getTokenProgram)(mint),
|
|
253
238
|
pool: poolPDA,
|
|
254
|
-
customer
|
|
255
|
-
userTrade
|
|
239
|
+
customer
|
|
256
240
|
})
|
|
257
241
|
.instruction());
|
|
258
242
|
ixs.push(yield this.program.methods
|
|
@@ -511,11 +495,11 @@ class TriadProtocolClient {
|
|
|
511
495
|
* @param options - RPC options
|
|
512
496
|
*
|
|
513
497
|
*/
|
|
514
|
-
createCustomer({ id, name, authority, feeRecipient }, options) {
|
|
498
|
+
createCustomer({ id, name, authority, feeRecipient, feeBps }, options) {
|
|
515
499
|
return __awaiter(this, void 0, void 0, function* () {
|
|
516
500
|
const ixs = [];
|
|
517
501
|
ixs.push(yield this.program.methods
|
|
518
|
-
.createCustomer({ id, name, authority, feeRecipient })
|
|
502
|
+
.createCustomer({ id, name, authority, feeRecipient, feeBps })
|
|
519
503
|
.accounts({
|
|
520
504
|
signer: this.program.provider.publicKey
|
|
521
505
|
})
|
|
@@ -903,7 +887,6 @@ class TriadProtocolClient {
|
|
|
903
887
|
.accounts({
|
|
904
888
|
signer: this.program.provider.publicKey,
|
|
905
889
|
market: (0, pda_1.getMarketPDA)(this.program.programId, marketId),
|
|
906
|
-
feeRecipient,
|
|
907
890
|
mint: constants_1.TRD_MINT
|
|
908
891
|
})
|
|
909
892
|
.instruction());
|
|
@@ -930,5 +913,23 @@ class TriadProtocolClient {
|
|
|
930
913
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
931
914
|
});
|
|
932
915
|
}
|
|
916
|
+
/**
|
|
917
|
+
* Create Refer
|
|
918
|
+
* @param id - The ID of the refer
|
|
919
|
+
*
|
|
920
|
+
* @param options - RPC options
|
|
921
|
+
*/
|
|
922
|
+
createRefer(id, options) {
|
|
923
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
924
|
+
const ixs = [];
|
|
925
|
+
ixs.push(yield this.program.methods
|
|
926
|
+
.createRefer(new bn_js_1.default(id))
|
|
927
|
+
.accounts({
|
|
928
|
+
signer: this.program.provider.publicKey
|
|
929
|
+
})
|
|
930
|
+
.instruction());
|
|
931
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
932
|
+
});
|
|
933
|
+
}
|
|
933
934
|
}
|
|
934
935
|
exports.default = TriadProtocolClient;
|
package/dist/stake.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Program } from '@coral-xyz/anchor';
|
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { TriadProtocol } from './types/triad_protocol';
|
|
4
4
|
import { RpcOptions } from './types';
|
|
5
|
-
import {
|
|
5
|
+
import { StakeV2, UpdateStakeVaultArgs } from './types/stake';
|
|
6
6
|
export default class Stake {
|
|
7
7
|
private program;
|
|
8
8
|
constructor(program: Program<TriadProtocol>);
|
|
@@ -15,41 +15,39 @@ export default class Stake {
|
|
|
15
15
|
* Get all Stakes
|
|
16
16
|
*
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
getStakesV2(): Promise<StakeV2[]>;
|
|
19
19
|
/**
|
|
20
|
-
* Get
|
|
21
|
-
* @param wallet - User wallet
|
|
20
|
+
* Get all Stakes
|
|
22
21
|
*
|
|
23
22
|
*/
|
|
24
|
-
|
|
23
|
+
getStakes(): Promise<import("./types/stake").StakeV3[]>;
|
|
25
24
|
/**
|
|
26
25
|
* Get Stake By Wallet
|
|
27
|
-
* @param wallet - User
|
|
26
|
+
* @param wallet - User wallet
|
|
28
27
|
*
|
|
29
28
|
*/
|
|
30
29
|
getStakeByWallet(wallet: PublicKey): Promise<{
|
|
31
30
|
available: number;
|
|
32
|
-
name: string;
|
|
33
|
-
stakeVault: string;
|
|
34
31
|
authority: string;
|
|
35
32
|
initTs: number;
|
|
36
|
-
|
|
37
|
-
mint: string;
|
|
38
|
-
claimedTs: number;
|
|
39
|
-
boost: boolean;
|
|
33
|
+
checkedTs: number;
|
|
40
34
|
claimed: number;
|
|
41
35
|
amount: number;
|
|
42
|
-
}
|
|
36
|
+
}>;
|
|
37
|
+
/**
|
|
38
|
+
* Get Unstake By Wallet
|
|
39
|
+
* @param wallet - User wallet
|
|
40
|
+
*
|
|
41
|
+
*/
|
|
42
|
+
getUnstakeByWallet(wallet: PublicKey): Promise<import("./types/stake").Unstake[]>;
|
|
43
43
|
/**
|
|
44
44
|
* Stake Token
|
|
45
|
-
* @param
|
|
46
|
-
* @param args.wallet - User wallet
|
|
47
|
-
* @param args.amount - Amount to stake
|
|
45
|
+
* @param amount - Amount to stake
|
|
48
46
|
*
|
|
49
47
|
* @param options - RPC options
|
|
50
48
|
*
|
|
51
49
|
*/
|
|
52
|
-
stakeToken(
|
|
50
|
+
stakeToken(amount: number, options?: RpcOptions): Promise<string>;
|
|
53
51
|
/**
|
|
54
52
|
* Update Stake Vault
|
|
55
53
|
* @param args.amount - Reward amount to deposit (optional)
|
|
@@ -60,30 +58,29 @@ export default class Stake {
|
|
|
60
58
|
*/
|
|
61
59
|
updateStakeVault({ amount, isLocked }: UpdateStakeVaultArgs, options?: RpcOptions): Promise<string>;
|
|
62
60
|
/**
|
|
63
|
-
* Request
|
|
64
|
-
* @param
|
|
65
|
-
* @param args.nfts - NFTs to Request withdraw
|
|
61
|
+
* Request Unstake
|
|
62
|
+
* @param amount - Amount to unstake
|
|
66
63
|
*
|
|
67
64
|
* @param options - RPC options
|
|
68
65
|
*
|
|
69
66
|
*/
|
|
70
|
-
|
|
67
|
+
requestUnstake(amount: number, options?: RpcOptions): Promise<string>;
|
|
71
68
|
/**
|
|
72
|
-
*
|
|
73
|
-
* @param args.wallet - User wallet
|
|
74
|
-
* @param args.name - Stake name
|
|
75
|
-
* @param args.mint - Stake native mint (TRD)
|
|
76
|
-
*
|
|
69
|
+
* Unstake Token
|
|
77
70
|
* @param options - RPC options
|
|
78
71
|
*
|
|
79
72
|
*/
|
|
80
|
-
|
|
73
|
+
unstakeToken(options?: RpcOptions): Promise<string>;
|
|
81
74
|
/**
|
|
82
75
|
* Claim Stake Rewards
|
|
83
|
-
* @param
|
|
76
|
+
* @param options - RPC options
|
|
84
77
|
*
|
|
78
|
+
*/
|
|
79
|
+
claimStakeRewards(options?: RpcOptions): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Migrate Stake
|
|
85
82
|
* @param options - RPC options
|
|
86
83
|
*
|
|
87
84
|
*/
|
|
88
|
-
|
|
85
|
+
migrateStake(stakes: StakeV2[], options?: RpcOptions): Promise<string>;
|
|
89
86
|
}
|
package/dist/stake.js
CHANGED
|
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
16
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
16
17
|
const helpers_1 = require("./utils/helpers");
|
|
17
18
|
const stake_1 = require("./utils/pda/stake");
|
|
18
19
|
const constants_1 = require("./utils/constants");
|
|
@@ -35,57 +36,68 @@ class Stake {
|
|
|
35
36
|
* Get all Stakes
|
|
36
37
|
*
|
|
37
38
|
*/
|
|
38
|
-
|
|
39
|
+
getStakesV2() {
|
|
39
40
|
return __awaiter(this, void 0, void 0, function* () {
|
|
40
41
|
const response = yield this.program.account.stakeV2.all();
|
|
41
|
-
return response.map((stake) => (0, helpers_1.
|
|
42
|
+
return response.map((stake) => (0, helpers_1.formatStakeV2)(stake.account));
|
|
42
43
|
});
|
|
43
44
|
}
|
|
44
45
|
/**
|
|
45
|
-
* Get
|
|
46
|
-
* @param wallet - User wallet
|
|
46
|
+
* Get all Stakes
|
|
47
47
|
*
|
|
48
48
|
*/
|
|
49
|
-
|
|
49
|
+
getStakes() {
|
|
50
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
const
|
|
52
|
-
const response = stakes.filter((stake) => stake.account.authority.toBase58() === wallet.toBase58());
|
|
51
|
+
const response = yield this.program.account.stakeV3.all();
|
|
53
52
|
return response.map((stake) => (0, helpers_1.formatStake)(stake.account));
|
|
54
53
|
});
|
|
55
54
|
}
|
|
56
55
|
/**
|
|
57
56
|
* Get Stake By Wallet
|
|
58
|
-
* @param wallet - User
|
|
57
|
+
* @param wallet - User wallet
|
|
59
58
|
*
|
|
60
59
|
*/
|
|
61
60
|
getStakeByWallet(wallet) {
|
|
62
61
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const stake = yield this.program.account.stakeV3
|
|
63
|
+
.fetch((0, stake_1.getStakePDA)(this.program.programId, wallet))
|
|
64
|
+
.then((stake) => (0, helpers_1.formatStake)(stake));
|
|
65
|
+
return Object.assign(Object.assign({}, stake), { available: (0, helpers_1.calculateStakeRewards)(stake) });
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get Unstake By Wallet
|
|
70
|
+
* @param wallet - User wallet
|
|
71
|
+
*
|
|
72
|
+
*/
|
|
73
|
+
getUnstakeByWallet(wallet) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const stake = yield this.program.account.unstake.all([
|
|
76
|
+
{
|
|
77
|
+
memcmp: {
|
|
78
|
+
offset: 8 + 1,
|
|
79
|
+
bytes: wallet.toBase58()
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
]);
|
|
83
|
+
return stake.map((stake) => (0, helpers_1.formatUnstake)(stake.account));
|
|
68
84
|
});
|
|
69
85
|
}
|
|
70
86
|
/**
|
|
71
87
|
* Stake Token
|
|
72
|
-
* @param
|
|
73
|
-
* @param args.wallet - User wallet
|
|
74
|
-
* @param args.amount - Amount to stake
|
|
88
|
+
* @param amount - Amount to stake
|
|
75
89
|
*
|
|
76
90
|
* @param options - RPC options
|
|
77
91
|
*
|
|
78
92
|
*/
|
|
79
|
-
stakeToken(
|
|
93
|
+
stakeToken(amount, options) {
|
|
80
94
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
95
|
const ixs = [];
|
|
82
96
|
ixs.push(yield this.program.methods
|
|
83
97
|
.stakeToken({
|
|
84
|
-
name,
|
|
85
98
|
amount: new anchor_1.BN(amount * Math.pow(10, 6))
|
|
86
99
|
})
|
|
87
100
|
.accounts({
|
|
88
|
-
signer: wallet,
|
|
89
101
|
mint: constants_1.TRD_MINT
|
|
90
102
|
})
|
|
91
103
|
.instruction());
|
|
@@ -109,7 +121,6 @@ class Stake {
|
|
|
109
121
|
isLocked
|
|
110
122
|
})
|
|
111
123
|
.accounts({
|
|
112
|
-
signer: this.program.provider.publicKey,
|
|
113
124
|
mint: constants_1.TRD_MINT
|
|
114
125
|
})
|
|
115
126
|
.instruction());
|
|
@@ -117,47 +128,40 @@ class Stake {
|
|
|
117
128
|
});
|
|
118
129
|
}
|
|
119
130
|
/**
|
|
120
|
-
* Request
|
|
121
|
-
* @param
|
|
122
|
-
* @param args.nfts - NFTs to Request withdraw
|
|
131
|
+
* Request Unstake
|
|
132
|
+
* @param amount - Amount to unstake
|
|
123
133
|
*
|
|
124
134
|
* @param options - RPC options
|
|
125
135
|
*
|
|
126
136
|
*/
|
|
127
|
-
|
|
137
|
+
requestUnstake(amount, options) {
|
|
128
138
|
return __awaiter(this, void 0, void 0, function* () {
|
|
129
139
|
const ixs = [];
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
140
|
+
ixs.push(yield this.program.methods
|
|
141
|
+
.requestUnstake({
|
|
142
|
+
amount: new anchor_1.BN(amount),
|
|
143
|
+
ts: new anchor_1.BN(Date.now())
|
|
144
|
+
})
|
|
145
|
+
.accounts({
|
|
146
|
+
stake: (0, stake_1.getStakePDA)(this.program.programId, this.program.provider.publicKey),
|
|
147
|
+
mint: constants_1.TRD_MINT
|
|
148
|
+
})
|
|
149
|
+
.instruction());
|
|
139
150
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
140
151
|
});
|
|
141
152
|
}
|
|
142
153
|
/**
|
|
143
|
-
*
|
|
144
|
-
* @param args.wallet - User wallet
|
|
145
|
-
* @param args.name - Stake name
|
|
146
|
-
* @param args.mint - Stake native mint (TRD)
|
|
147
|
-
*
|
|
154
|
+
* Unstake Token
|
|
148
155
|
* @param options - RPC options
|
|
149
156
|
*
|
|
150
157
|
*/
|
|
151
|
-
|
|
158
|
+
unstakeToken(options) {
|
|
152
159
|
return __awaiter(this, void 0, void 0, function* () {
|
|
153
160
|
const ixs = [];
|
|
154
161
|
ixs.push(yield this.program.methods
|
|
155
|
-
.
|
|
162
|
+
.unstakeToken()
|
|
156
163
|
.accounts({
|
|
157
|
-
signer:
|
|
158
|
-
stake: (0, stake_1.getStakePDA)(this.program.programId, wallet, name),
|
|
159
|
-
admin: constants_1.TRIAD_ADMIN,
|
|
160
|
-
mint: mint
|
|
164
|
+
signer: this.program.provider.publicKey
|
|
161
165
|
})
|
|
162
166
|
.instruction());
|
|
163
167
|
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
@@ -165,32 +169,38 @@ class Stake {
|
|
|
165
169
|
}
|
|
166
170
|
/**
|
|
167
171
|
* Claim Stake Rewards
|
|
168
|
-
* @param
|
|
172
|
+
* @param options - RPC options
|
|
169
173
|
*
|
|
174
|
+
*/
|
|
175
|
+
claimStakeRewards(options) {
|
|
176
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
+
const ixs = [];
|
|
178
|
+
ixs.push(yield this.program.methods
|
|
179
|
+
.claimStakeRewards()
|
|
180
|
+
.accounts({
|
|
181
|
+
mint: constants_1.TRD_MINT,
|
|
182
|
+
stake: (0, stake_1.getStakePDA)(this.program.programId, this.program.provider.publicKey)
|
|
183
|
+
})
|
|
184
|
+
.instruction());
|
|
185
|
+
return (0, sendVersionedTransaction_1.default)(this.program, ixs, options);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Migrate Stake
|
|
170
190
|
* @param options - RPC options
|
|
171
191
|
*
|
|
172
192
|
*/
|
|
173
|
-
|
|
193
|
+
migrateStake(stakes, options) {
|
|
174
194
|
return __awaiter(this, void 0, void 0, function* () {
|
|
175
|
-
const stakes = (yield this.getUserStakes(wallet)).sort((a, b) => a.claimedTs - b.claimedTs);
|
|
176
195
|
const ixs = [];
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
items.push(stake);
|
|
183
|
-
});
|
|
184
|
-
for (const stake of items) {
|
|
185
|
-
if (ixs.length >= 10) {
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
196
|
+
for (const stake of stakes) {
|
|
197
|
+
if (stake.withdrawTs !== 0)
|
|
198
|
+
continue;
|
|
188
199
|
ixs.push(yield this.program.methods
|
|
189
|
-
.
|
|
200
|
+
.migrateStake()
|
|
190
201
|
.accounts({
|
|
191
|
-
|
|
192
|
-
mint: constants_1.TRD_MINT
|
|
193
|
-
stake: (0, stake_1.getStakePDA)(this.program.programId, wallet, stake.name)
|
|
202
|
+
stakeV2: (0, stake_1.getStakeV2PDA)(this.program.programId, new web3_js_1.PublicKey(stake.authority), stake.name),
|
|
203
|
+
mint: constants_1.TRD_MINT
|
|
194
204
|
})
|
|
195
205
|
.instruction());
|
|
196
206
|
}
|