@triadxyz/triad-protocol 0.0.3-beta → 0.0.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/stake.d.ts CHANGED
@@ -118,5 +118,5 @@ export default class Stake {
118
118
  * @param nftName - Name of the nft
119
119
  *
120
120
  */
121
- claimStakeRewards({ wallet, mint, week, stakeVault, nftName }: ClaimStakeRewardsArgs, options?: RpcOptions): Promise<string>;
121
+ claimStakeRewards({ wallet, mint, week, stakeVault, nftName }: ClaimStakeRewardsArgs, options?: RpcOptions): Promise<any>;
122
122
  }
package/dist/stake.js CHANGED
@@ -392,19 +392,22 @@ 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
- const method = this.program.methods
396
- .claimStakeRewards({
397
- week
398
- })
399
- .accounts({
400
- signer: wallet,
401
- fromAta: FromAta,
402
- toAta: ToAta,
403
- mint: mint,
404
- nftRewards: NFTRewards,
405
- stake: Stake,
406
- stakeVault: StakeVault
407
- });
395
+ let method;
396
+ for (let w of week) {
397
+ method = 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
+ }
408
411
  if (options === null || options === void 0 ? void 0 : options.microLamports) {
409
412
  method.postInstructions([
410
413
  web3_js_1.ComputeBudgetProgram.setComputeUnitPrice({
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 = 1719755851;
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
- const collections = Object.values(users_collections_week_1_json_1.default.find((collection) => Object.keys(collection)[0] === item.authority))[0];
50
- let totalMultiplier = (0, helpers_1.calculateTotalMultiplier)(index === 0
51
- ? Object.keys(item.collections).map((x) => x.toUpperCase())
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: 0,
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: 0,
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,48 @@ 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
+ });
@@ -53,7 +53,7 @@ export type UpdateStakeVaultStatusArgs = {
53
53
  };
54
54
  export type ClaimStakeRewardsArgs = {
55
55
  wallet: PublicKey;
56
- week: number;
56
+ week: number[];
57
57
  mint: PublicKey;
58
58
  stakeVault: string;
59
59
  nftName: string;