@triadxyz/triad-protocol 0.0.7-beta → 0.0.8-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/stake.d.ts +4 -4
- package/dist/stake.js +18 -32
- package/dist/test.js +13 -111
- package/dist/types/idl_triad_protocol.json +428 -157
- package/dist/types/stake.d.ts +7 -3
- package/dist/types/triad_protocol.d.ts +770 -151
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/constants.js +2 -2
- package/dist/utils/helpers.js +9 -5
- package/package.json +1 -1
package/dist/stake.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export default class Stake {
|
|
|
56
56
|
* @param rarity - NFT rarity
|
|
57
57
|
*
|
|
58
58
|
*/
|
|
59
|
-
|
|
59
|
+
stakeNft({ name, wallet, mint, collections, rarity, stakeVault }: StakeArgs, options?: RpcOptions): Promise<string>;
|
|
60
60
|
/**
|
|
61
61
|
* Initialize Stake Vault
|
|
62
62
|
* @param name - The ticker's name
|
|
@@ -82,14 +82,14 @@ export default class Stake {
|
|
|
82
82
|
*/
|
|
83
83
|
requestWithdraw({ wallet, nftName, mint, stakeVault }: RequestWithdrawArgs, options?: RpcOptions): Promise<string>;
|
|
84
84
|
/**
|
|
85
|
-
* Withdraw
|
|
85
|
+
* Withdraw Stake
|
|
86
86
|
* @param wallet - User wallet
|
|
87
|
-
* @param nftName -
|
|
87
|
+
* @param nftName - Stake name
|
|
88
88
|
* @param mint - NFT mint
|
|
89
89
|
* @param stakeVault - Name of the stake vault
|
|
90
90
|
*
|
|
91
91
|
*/
|
|
92
|
-
|
|
92
|
+
withdrawStake({ wallet, nftName, mint, stakeVault }: WithdrawArgs, options?: RpcOptions): Promise<string>;
|
|
93
93
|
/**
|
|
94
94
|
* Update Stake Vault Status
|
|
95
95
|
* @param wallet - User wallet
|
package/dist/stake.js
CHANGED
|
@@ -157,11 +157,9 @@ class Stake {
|
|
|
157
157
|
* @param rarity - NFT rarity
|
|
158
158
|
*
|
|
159
159
|
*/
|
|
160
|
-
|
|
160
|
+
stakeNft({ name, wallet, mint, collections, rarity, stakeVault }, options) {
|
|
161
161
|
return __awaiter(this, void 0, void 0, function* () {
|
|
162
162
|
const FromAta = (0, helpers_1.getATASync)(wallet, mint);
|
|
163
|
-
const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
164
|
-
const ToAta = (0, helpers_1.getATASync)(StakeVault, mint);
|
|
165
163
|
let items = [];
|
|
166
164
|
Object.keys(collections).forEach((key) => {
|
|
167
165
|
if (collections[key]) {
|
|
@@ -169,7 +167,7 @@ class Stake {
|
|
|
169
167
|
}
|
|
170
168
|
});
|
|
171
169
|
const method = this.program.methods
|
|
172
|
-
.
|
|
170
|
+
.stakeNft({
|
|
173
171
|
name,
|
|
174
172
|
collections: items,
|
|
175
173
|
rarity,
|
|
@@ -178,7 +176,6 @@ class Stake {
|
|
|
178
176
|
.accounts({
|
|
179
177
|
signer: wallet,
|
|
180
178
|
fromAta: FromAta,
|
|
181
|
-
toAta: ToAta,
|
|
182
179
|
mint: mint
|
|
183
180
|
});
|
|
184
181
|
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
@@ -230,8 +227,6 @@ class Stake {
|
|
|
230
227
|
depositStakeRewards({ wallet, mint, amount, stakeVault }, options) {
|
|
231
228
|
return __awaiter(this, void 0, void 0, function* () {
|
|
232
229
|
const FromAta = (0, helpers_1.getATASync)(wallet, mint);
|
|
233
|
-
const StakeVault = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
234
|
-
const ToAta = (0, helpers_1.getATASync)(StakeVault, mint);
|
|
235
230
|
const method = this.program.methods
|
|
236
231
|
.depositStakeRewards({
|
|
237
232
|
amount,
|
|
@@ -240,7 +235,6 @@ class Stake {
|
|
|
240
235
|
.accounts({
|
|
241
236
|
signer: wallet,
|
|
242
237
|
fromAta: FromAta,
|
|
243
|
-
toAta: ToAta,
|
|
244
238
|
mint: mint
|
|
245
239
|
});
|
|
246
240
|
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
@@ -262,14 +256,13 @@ class Stake {
|
|
|
262
256
|
*/
|
|
263
257
|
requestWithdraw({ wallet, nftName, mint, stakeVault }, options) {
|
|
264
258
|
return __awaiter(this, void 0, void 0, function* () {
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
stakeVault
|
|
269
|
-
})
|
|
270
|
-
.accounts({
|
|
259
|
+
const stakeVaultPDA = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
260
|
+
const stakePDA = (0, helpers_1.getStakeAddressSync)(this.program.programId, nftName);
|
|
261
|
+
const method = this.program.methods.requestWithdrawStake().accounts({
|
|
271
262
|
signer: wallet,
|
|
272
|
-
mint: mint
|
|
263
|
+
mint: mint,
|
|
264
|
+
stake: stakePDA,
|
|
265
|
+
stakeVault: stakeVaultPDA
|
|
273
266
|
});
|
|
274
267
|
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
275
268
|
method.postInstructions([
|
|
@@ -282,30 +275,25 @@ class Stake {
|
|
|
282
275
|
});
|
|
283
276
|
}
|
|
284
277
|
/**
|
|
285
|
-
* Withdraw
|
|
278
|
+
* Withdraw Stake
|
|
286
279
|
* @param wallet - User wallet
|
|
287
|
-
* @param nftName -
|
|
280
|
+
* @param nftName - Stake name
|
|
288
281
|
* @param mint - NFT mint
|
|
289
282
|
* @param stakeVault - Name of the stake vault
|
|
290
283
|
*
|
|
291
284
|
*/
|
|
292
|
-
|
|
285
|
+
withdrawStake({ wallet, nftName, mint, stakeVault }, options) {
|
|
293
286
|
return __awaiter(this, void 0, void 0, function* () {
|
|
294
|
-
const
|
|
295
|
-
const FromAta = (0, helpers_1.getATASync)(
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
-
const
|
|
299
|
-
const method = this.program.methods
|
|
300
|
-
.withdrawNft({
|
|
301
|
-
nftName,
|
|
302
|
-
stakeVault
|
|
303
|
-
})
|
|
304
|
-
.accounts({
|
|
287
|
+
const stakeVaultPDA = (0, helpers_1.getStakeVaultAddressSync)(this.program.programId, stakeVault);
|
|
288
|
+
const FromAta = (0, helpers_1.getATASync)(stakeVaultPDA, mint);
|
|
289
|
+
const stakePDA = (0, helpers_1.getStakeAddressSync)(this.program.programId, nftName);
|
|
290
|
+
const NFTRewards = (0, helpers_1.getNFTRewardsAddressSync)(this.program.programId, stakePDA);
|
|
291
|
+
const method = this.program.methods.withdrawStake().accounts({
|
|
305
292
|
signer: wallet,
|
|
306
293
|
fromAta: FromAta,
|
|
307
|
-
toAta: ToAta,
|
|
308
294
|
nftRewards: NFTRewards,
|
|
295
|
+
stake: stakePDA,
|
|
296
|
+
stakeVault: stakeVaultPDA,
|
|
309
297
|
admin: new web3_js_1.PublicKey('82ppCojm3yrEKgdpH8B5AmBJTU1r1uAWXFWhxvPs9UCR'),
|
|
310
298
|
mint: mint
|
|
311
299
|
});
|
|
@@ -410,7 +398,6 @@ class Stake {
|
|
|
410
398
|
const Stake = (0, helpers_1.getStakeAddressSync)(this.program.programId, nftName);
|
|
411
399
|
const NFTRewards = (0, helpers_1.getNFTRewardsAddressSync)(this.program.programId, Stake);
|
|
412
400
|
const FromAta = (0, helpers_1.getATASync)(StakeVault, mint);
|
|
413
|
-
const ToAta = (0, helpers_1.getATASync)(wallet, mint);
|
|
414
401
|
let ixs = [];
|
|
415
402
|
for (let w of week) {
|
|
416
403
|
ixs.push(yield this.program.methods
|
|
@@ -420,7 +407,6 @@ class Stake {
|
|
|
420
407
|
.accounts({
|
|
421
408
|
signer: wallet,
|
|
422
409
|
fromAta: FromAta,
|
|
423
|
-
toAta: ToAta,
|
|
424
410
|
mint: mint,
|
|
425
411
|
nftRewards: NFTRewards,
|
|
426
412
|
stake: Stake,
|
package/dist/test.js
CHANGED
|
@@ -17,66 +17,12 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
17
17
|
const index_1 = __importDefault(require("./index"));
|
|
18
18
|
const anchor_1 = require("@coral-xyz/anchor");
|
|
19
19
|
const constants_1 = require("./utils/constants");
|
|
20
|
-
const rarity_json_1 = __importDefault(require("./utils/stake-season-1/rarity.json"));
|
|
21
|
-
const users_collections_week_1_json_1 = __importDefault(require("./utils/stake-season-1/users-collections-week-1.json"));
|
|
22
|
-
const helpers_1 = require("./utils/helpers");
|
|
23
20
|
const file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/id.json');
|
|
24
21
|
const rpc_file = fs_1.default.readFileSync('/Users/dannpl/.config/solana/rpc.txt');
|
|
25
22
|
const keypair = web3_js_1.Keypair.fromSecretKey(new Uint8Array(JSON.parse(file.toString())));
|
|
26
23
|
const connection = new web3_js_1.Connection(rpc_file.toString(), 'confirmed');
|
|
27
24
|
const wallet = new anchor_1.Wallet(keypair);
|
|
28
25
|
const triadProtocol = new index_1.default(connection, wallet);
|
|
29
|
-
const populateStakeDay = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
-
const { perDay } = yield triadProtocol.stake.getStakeVaultRewards(constants_1.STAKE_SEASON_1);
|
|
31
|
-
const day = 1720360651;
|
|
32
|
-
const stakes = yield triadProtocol.stake.getStakesByDay(constants_1.STAKE_SEASON_1, day);
|
|
33
|
-
const newItems = [];
|
|
34
|
-
const itemsByAuthority = stakes.reduce((acc, item) => {
|
|
35
|
-
const itemRarity = rarity_json_1.default.find((rarity) => rarity.onchainId === item.mint);
|
|
36
|
-
if (!itemRarity) {
|
|
37
|
-
return acc;
|
|
38
|
-
}
|
|
39
|
-
if (item.withdrawTs !== 0 && item.withdrawTs < 1720441379) {
|
|
40
|
-
return acc;
|
|
41
|
-
}
|
|
42
|
-
if (!acc[item.authority]) {
|
|
43
|
-
acc[item.authority] = [];
|
|
44
|
-
}
|
|
45
|
-
acc[item.authority].push(Object.assign(Object.assign({}, item), { rarity: itemRarity.rarity, rarityRankHrtt: itemRarity.rarityRankHrtt, collections: {} }));
|
|
46
|
-
return acc;
|
|
47
|
-
}, {});
|
|
48
|
-
Object.keys(itemsByAuthority).forEach((authority) => {
|
|
49
|
-
const items = itemsByAuthority[authority];
|
|
50
|
-
items.sort((a, b) => a.rarityRankHrtt - b.rarityRankHrtt);
|
|
51
|
-
items.forEach((item, index) => {
|
|
52
|
-
var _a;
|
|
53
|
-
const collections = (_a = users_collections_week_1_json_1.default[item.authority]) !== null && _a !== void 0 ? _a : {};
|
|
54
|
-
const items = [];
|
|
55
|
-
Object.keys(collections).forEach((collection) => {
|
|
56
|
-
if (collections[collection]) {
|
|
57
|
-
items.push(collection);
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
let totalMultiplier = (0, helpers_1.calculateTotalMultiplier)(index === 0 ? items.map((item) => item.toUpperCase()) : [], {
|
|
61
|
-
max: 1839,
|
|
62
|
-
currentPosition: item.rarityRankHrtt
|
|
63
|
-
});
|
|
64
|
-
newItems.push(Object.assign(Object.assign({}, item), { totalMultiplier, collections: index === 0 ? collections[0] : {} }));
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
const totalMultiplierSum = newItems.reduce((sum, user) => sum + user.totalMultiplier, 0);
|
|
68
|
-
const rewards = newItems.map((item) => {
|
|
69
|
-
const rewards = (item.totalMultiplier / totalMultiplierSum) * perDay;
|
|
70
|
-
return Object.assign(Object.assign({}, item), { rewards, apr: (0, helpers_1.calculateAPR)({
|
|
71
|
-
rewards,
|
|
72
|
-
rate: 7,
|
|
73
|
-
amount: 1,
|
|
74
|
-
baseRewards: perDay
|
|
75
|
-
}) });
|
|
76
|
-
});
|
|
77
|
-
const orderedRewards = rewards.sort((a, b) => b.rewards - a.rewards);
|
|
78
|
-
fs_1.default.writeFileSync(`./src/utils/stake-season-1/stakes/2/${day}.json`, JSON.stringify(orderedRewards, null, 2));
|
|
79
|
-
});
|
|
80
26
|
const requestWithdraw = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
81
27
|
const response = yield triadProtocol.stake.requestWithdraw({
|
|
82
28
|
wallet: wallet.publicKey,
|
|
@@ -93,8 +39,8 @@ const updateStakeVaultStatus = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
93
39
|
const response = yield triadProtocol.stake.updateStakeVaultStatus({
|
|
94
40
|
wallet: wallet.publicKey,
|
|
95
41
|
isLocked: true,
|
|
96
|
-
week:
|
|
97
|
-
stakeVault: constants_1.
|
|
42
|
+
week: 4,
|
|
43
|
+
stakeVault: constants_1.STAKE_SEASON
|
|
98
44
|
}, {
|
|
99
45
|
skipPreflight: true,
|
|
100
46
|
microLamports: 10000
|
|
@@ -102,7 +48,7 @@ const updateStakeVaultStatus = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
102
48
|
console.log(response);
|
|
103
49
|
});
|
|
104
50
|
const withdraw = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
-
const response = yield triadProtocol.stake.
|
|
51
|
+
const response = yield triadProtocol.stake.withdrawStake({
|
|
106
52
|
wallet: wallet.publicKey,
|
|
107
53
|
nftName: 'Triad 0',
|
|
108
54
|
mint: new web3_js_1.PublicKey('FXRhaGeYue7bMCwcksNw4hJRY7jZ1YMwgmCu1Y8fyUNd'),
|
|
@@ -114,26 +60,27 @@ const withdraw = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
114
60
|
console.log(response);
|
|
115
61
|
});
|
|
116
62
|
const getStake = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
117
|
-
const response = yield triadProtocol.stake.getStakeByWallet(new web3_js_1.PublicKey('E48CKgbZVpDzerQ7DdommgqNobRHLqHy8RUVi8HXkSHE'), constants_1.
|
|
63
|
+
const response = yield triadProtocol.stake.getStakeByWallet(new web3_js_1.PublicKey('E48CKgbZVpDzerQ7DdommgqNobRHLqHy8RUVi8HXkSHE'), constants_1.STAKE_SEASON);
|
|
118
64
|
const stakeVaults = yield triadProtocol.stake.getStakeVaults();
|
|
119
65
|
console.log(response);
|
|
120
66
|
console.log(stakeVaults);
|
|
121
67
|
});
|
|
122
|
-
const
|
|
68
|
+
const claimStakeRewardsV1 = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
69
|
const response = yield triadProtocol.stake.claimStakeRewards({
|
|
124
70
|
wallet: wallet.publicKey,
|
|
125
|
-
mint: new web3_js_1.PublicKey(''),
|
|
126
|
-
week: [],
|
|
127
|
-
stakeVault: constants_1.
|
|
128
|
-
nftName: ''
|
|
71
|
+
mint: new web3_js_1.PublicKey('t3DohmswhKk94PPbPYwA6ZKACyY3y5kbcqeQerAJjmV'),
|
|
72
|
+
week: [4],
|
|
73
|
+
stakeVault: constants_1.STAKE_SEASON,
|
|
74
|
+
nftName: 'Triad 2807'
|
|
129
75
|
}, {
|
|
130
76
|
skipPreflight: true,
|
|
131
77
|
microLamports: 10000
|
|
132
78
|
});
|
|
133
79
|
console.log(response);
|
|
134
80
|
});
|
|
135
|
-
|
|
136
|
-
|
|
81
|
+
claimStakeRewardsV1();
|
|
82
|
+
const getStakers = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
83
|
+
const response = yield triadProtocol.stake.getStakes(constants_1.STAKE_SEASON);
|
|
137
84
|
console.log(JSON.stringify(response, null, 2));
|
|
138
85
|
const users = response
|
|
139
86
|
.filter((item, index, self) => index === self.findIndex((t) => t.authority === item.authority))
|
|
@@ -141,7 +88,7 @@ const getStakes = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
141
88
|
fs_1.default.writeFileSync('./src/utils/stake-season-1/users.json', JSON.stringify(users, null, 2));
|
|
142
89
|
});
|
|
143
90
|
const stake = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
144
|
-
const response = yield triadProtocol.stake.
|
|
91
|
+
const response = yield triadProtocol.stake.stakeNft({
|
|
145
92
|
name: 'Triad 0',
|
|
146
93
|
wallet: wallet.publicKey,
|
|
147
94
|
stakeVault: 'Rev 1',
|
|
@@ -159,48 +106,3 @@ const stake = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
159
106
|
});
|
|
160
107
|
console.log(response);
|
|
161
108
|
});
|
|
162
|
-
const updateStakeRewards = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
163
|
-
const day = null;
|
|
164
|
-
const ts = null;
|
|
165
|
-
let file = fs_1.default.readFileSync(`./src/utils/stake-season-1/stakes/2/${ts}.json`);
|
|
166
|
-
const data = JSON.parse(file.toString());
|
|
167
|
-
const chunkLengths = 10;
|
|
168
|
-
const chunks = [];
|
|
169
|
-
for (let i = 0; i < data.length; i += chunkLengths) {
|
|
170
|
-
chunks.push(data.slice(i, i + chunkLengths));
|
|
171
|
-
}
|
|
172
|
-
console.log(chunks.length);
|
|
173
|
-
const failedChunks = [];
|
|
174
|
-
for (let i = 0; i < chunks.length; i++) {
|
|
175
|
-
const chunk = chunks[i];
|
|
176
|
-
const items = [];
|
|
177
|
-
console.log(`Processing chunk ${i + 1} of ${chunks.length}`);
|
|
178
|
-
for (let j = 0; j < chunk.length; j++) {
|
|
179
|
-
const item = chunk[j];
|
|
180
|
-
items.push({
|
|
181
|
-
rewards: new anchor_1.BN(item.rewards * Math.pow(10, constants_1.TTRIAD_DECIMALS)),
|
|
182
|
-
apr: item.apr,
|
|
183
|
-
nftName: item.name
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
try {
|
|
187
|
-
const rewards = yield triadProtocol.stake.updateStakeRewards({
|
|
188
|
-
day,
|
|
189
|
-
wallet: wallet.publicKey,
|
|
190
|
-
items: items
|
|
191
|
-
}, {
|
|
192
|
-
skipPreflight: false,
|
|
193
|
-
microLamports: 20000
|
|
194
|
-
});
|
|
195
|
-
console.log(rewards);
|
|
196
|
-
}
|
|
197
|
-
catch (error) {
|
|
198
|
-
console.error(`Failed to update stake rewards for chunk ${i}:`, error);
|
|
199
|
-
failedChunks.push(chunk);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
if (failedChunks.length > 0) {
|
|
203
|
-
fs_1.default.writeFileSync(`./src/utils/stake-season-1/stakes/2/failedChunks_${ts}.json`, JSON.stringify(failedChunks, null, 2));
|
|
204
|
-
console.log(`Failed chunks saved to ./src/utils/stake-season-1/stakes/2/failedChunks_${ts}.json`);
|
|
205
|
-
}
|
|
206
|
-
});
|