@triadxyz/triad-protocol 0.0.3-beta → 0.0.5-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.js +31 -19
- package/dist/test.js +65 -8
- package/dist/types/stake.d.ts +1 -1
- package/dist/utils/stake-season-1/users-collections-week-1.json +3289 -4385
- package/package.json +1 -1
package/dist/stake.js
CHANGED
|
@@ -392,27 +392,39 @@ class Stake {
|
|
|
392
392
|
const NFTRewards = (0, helpers_1.getNFTRewardsAddressSync)(this.program.programId, Stake);
|
|
393
393
|
const FromAta = (0, helpers_1.getATASync)(StakeVault, mint);
|
|
394
394
|
const ToAta = (0, helpers_1.getATASync)(wallet, mint);
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
395
|
+
let ixs = [];
|
|
396
|
+
for (let w of week) {
|
|
397
|
+
ixs.push(yield this.program.methods
|
|
398
|
+
.claimStakeRewards({
|
|
399
|
+
week: w
|
|
400
|
+
})
|
|
401
|
+
.accounts({
|
|
402
|
+
signer: wallet,
|
|
403
|
+
fromAta: FromAta,
|
|
404
|
+
toAta: ToAta,
|
|
405
|
+
mint: mint,
|
|
406
|
+
nftRewards: NFTRewards,
|
|
407
|
+
stake: Stake,
|
|
408
|
+
stakeVault: StakeVault
|
|
409
|
+
})
|
|
410
|
+
.instruction());
|
|
411
|
+
}
|
|
408
412
|
if (options === null || options === void 0 ? void 0 : options.microLamports) {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
})
|
|
413
|
-
]);
|
|
413
|
+
ixs.push(web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
|
|
414
|
+
microLamports: options.microLamports
|
|
415
|
+
}));
|
|
414
416
|
}
|
|
415
|
-
|
|
417
|
+
const { blockhash } = yield this.provider.connection.getLatestBlockhash();
|
|
418
|
+
const messageV0 = new web3_js_1.TransactionMessage({
|
|
419
|
+
payerKey: wallet,
|
|
420
|
+
recentBlockhash: blockhash,
|
|
421
|
+
instructions: ixs
|
|
422
|
+
}).compileToV0Message();
|
|
423
|
+
const tx = new web3_js_1.VersionedTransaction(messageV0);
|
|
424
|
+
return this.provider.sendAndConfirm(tx, [], {
|
|
425
|
+
skipPreflight: options === null || options === void 0 ? void 0 : options.skipPreflight,
|
|
426
|
+
commitment: 'confirmed'
|
|
427
|
+
});
|
|
416
428
|
});
|
|
417
429
|
}
|
|
418
430
|
}
|
package/dist/test.js
CHANGED
|
@@ -28,7 +28,7 @@ const wallet = new anchor_1.Wallet(keypair);
|
|
|
28
28
|
const triadProtocol = new index_1.default(connection, wallet);
|
|
29
29
|
const populateStakeDay = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
30
|
const { perDay } = yield triadProtocol.stake.getStakeVaultRewards(constants_1.STAKE_SEASON_1);
|
|
31
|
-
const day =
|
|
31
|
+
const day = 1720360651;
|
|
32
32
|
const stakes = yield triadProtocol.stake.getStakesByDay(constants_1.STAKE_SEASON_1, day);
|
|
33
33
|
const newItems = [];
|
|
34
34
|
const itemsByAuthority = stakes.reduce((acc, item) => {
|
|
@@ -36,6 +36,9 @@ const populateStakeDay = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
36
36
|
if (!itemRarity) {
|
|
37
37
|
return acc;
|
|
38
38
|
}
|
|
39
|
+
if (item.withdrawTs !== 0 && item.withdrawTs < 1720441379) {
|
|
40
|
+
return acc;
|
|
41
|
+
}
|
|
39
42
|
if (!acc[item.authority]) {
|
|
40
43
|
acc[item.authority] = [];
|
|
41
44
|
}
|
|
@@ -46,14 +49,19 @@ const populateStakeDay = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
46
49
|
const items = itemsByAuthority[authority];
|
|
47
50
|
items.sort((a, b) => a.rarityRankHrtt - b.rarityRankHrtt);
|
|
48
51
|
items.forEach((item, index) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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()) : [], {
|
|
53
61
|
max: 1839,
|
|
54
62
|
currentPosition: item.rarityRankHrtt
|
|
55
63
|
});
|
|
56
|
-
newItems.push(Object.assign(Object.assign({}, item), { totalMultiplier, collections: index === 0 ? collections : {} }));
|
|
64
|
+
newItems.push(Object.assign(Object.assign({}, item), { totalMultiplier, collections: index === 0 ? collections[0] : {} }));
|
|
57
65
|
});
|
|
58
66
|
});
|
|
59
67
|
const totalMultiplierSum = newItems.reduce((sum, user) => sum + user.totalMultiplier, 0);
|
|
@@ -85,7 +93,7 @@ const updateStakeVaultStatus = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
85
93
|
const response = yield triadProtocol.stake.updateStakeVaultStatus({
|
|
86
94
|
wallet: wallet.publicKey,
|
|
87
95
|
isLocked: true,
|
|
88
|
-
week:
|
|
96
|
+
week: 1,
|
|
89
97
|
stakeVault: constants_1.STAKE_SEASON_1
|
|
90
98
|
}, {
|
|
91
99
|
skipPreflight: true,
|
|
@@ -115,7 +123,7 @@ const claimStakeRewards = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
115
123
|
const response = yield triadProtocol.stake.claimStakeRewards({
|
|
116
124
|
wallet: wallet.publicKey,
|
|
117
125
|
mint: new web3_js_1.PublicKey(''),
|
|
118
|
-
week:
|
|
126
|
+
week: [],
|
|
119
127
|
stakeVault: constants_1.STAKE_SEASON_1,
|
|
120
128
|
nftName: ''
|
|
121
129
|
}, {
|
|
@@ -126,6 +134,7 @@ const claimStakeRewards = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
126
134
|
});
|
|
127
135
|
const getStakes = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
128
136
|
const response = yield triadProtocol.stake.getStakes(constants_1.STAKE_SEASON_1);
|
|
137
|
+
console.log(JSON.stringify(response, null, 2));
|
|
129
138
|
const users = response
|
|
130
139
|
.filter((item, index, self) => index === self.findIndex((t) => t.authority === item.authority))
|
|
131
140
|
.map((user) => user.authority);
|
|
@@ -150,3 +159,51 @@ const stake = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
150
159
|
});
|
|
151
160
|
console.log(response);
|
|
152
161
|
});
|
|
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
|
+
});
|
|
207
|
+
triadProtocol.stake
|
|
208
|
+
.getStakeByWallet(new web3_js_1.PublicKey('HTbGREt61NFttBCoANvhT58SrmUAy1sFbtCk7BQqaNYh'), constants_1.STAKE_SEASON_1)
|
|
209
|
+
.then(console.log);
|