Skip to content

Commit 4504921

Browse files
committed
updated claim to use V2, but method is not used so no update is needed
1 parent 9ef65e1 commit 4504921

File tree

2 files changed

+180
-37
lines changed

2 files changed

+180
-37
lines changed

apps/box/src/contracts/abis.ts

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3870,6 +3870,35 @@ export const REWARD_ENGINE_ABI = [
38703870
"stateMutability": "view",
38713871
"type": "function"
38723872
},
3873+
{
3874+
"inputs": [
3875+
{
3876+
"internalType": "address",
3877+
"name": "account",
3878+
"type": "address"
3879+
},
3880+
{
3881+
"internalType": "bytes32",
3882+
"name": "peerId",
3883+
"type": "bytes32"
3884+
},
3885+
{
3886+
"internalType": "uint32",
3887+
"name": "poolId",
3888+
"type": "uint32"
3889+
}
3890+
],
3891+
"name": "calculateEligibleMiningRewardsV2",
3892+
"outputs": [
3893+
{
3894+
"internalType": "uint256",
3895+
"name": "eligibleRewards",
3896+
"type": "uint256"
3897+
}
3898+
],
3899+
"stateMutability": "view",
3900+
"type": "function"
3901+
},
38733902
{
38743903
"inputs": [
38753904
{
@@ -3930,6 +3959,47 @@ export const REWARD_ENGINE_ABI = [
39303959
"stateMutability": "nonpayable",
39313960
"type": "function"
39323961
},
3962+
{
3963+
"inputs": [
3964+
{
3965+
"internalType": "bytes32",
3966+
"name": "peerId",
3967+
"type": "bytes32"
3968+
},
3969+
{
3970+
"internalType": "uint32",
3971+
"name": "poolId",
3972+
"type": "uint32"
3973+
}
3974+
],
3975+
"name": "claimRewardsV2",
3976+
"outputs": [],
3977+
"stateMutability": "nonpayable",
3978+
"type": "function"
3979+
},
3980+
{
3981+
"inputs": [
3982+
{
3983+
"internalType": "bytes32",
3984+
"name": "peerId",
3985+
"type": "bytes32"
3986+
},
3987+
{
3988+
"internalType": "uint32",
3989+
"name": "poolId",
3990+
"type": "uint32"
3991+
},
3992+
{
3993+
"internalType": "uint256",
3994+
"name": "maxPeriods",
3995+
"type": "uint256"
3996+
}
3997+
],
3998+
"name": "claimRewardsWithLimitV2",
3999+
"outputs": [],
4000+
"stateMutability": "nonpayable",
4001+
"type": "function"
4002+
},
39334003
{
39344004
"inputs": [
39354005
{
@@ -4078,6 +4148,84 @@ export const REWARD_ENGINE_ABI = [
40784148
"stateMutability": "view",
40794149
"type": "function"
40804150
},
4151+
{
4152+
"inputs": [
4153+
{
4154+
"internalType": "address",
4155+
"name": "account",
4156+
"type": "address"
4157+
},
4158+
{
4159+
"internalType": "bytes32",
4160+
"name": "peerId",
4161+
"type": "bytes32"
4162+
},
4163+
{
4164+
"internalType": "uint32",
4165+
"name": "poolId",
4166+
"type": "uint32"
4167+
}
4168+
],
4169+
"name": "getClaimStatusV2",
4170+
"outputs": [
4171+
{
4172+
"internalType": "uint256",
4173+
"name": "totalUnclaimedPeriods",
4174+
"type": "uint256"
4175+
},
4176+
{
4177+
"internalType": "uint256",
4178+
"name": "defaultPeriodsPerClaim",
4179+
"type": "uint256"
4180+
},
4181+
{
4182+
"internalType": "uint256",
4183+
"name": "maxPeriodsPerClaim",
4184+
"type": "uint256"
4185+
},
4186+
{
4187+
"internalType": "uint256",
4188+
"name": "estimatedClaimsNeeded",
4189+
"type": "uint256"
4190+
},
4191+
{
4192+
"internalType": "bool",
4193+
"name": "hasMoreToClaim",
4194+
"type": "bool"
4195+
}
4196+
],
4197+
"stateMutability": "view",
4198+
"type": "function"
4199+
},
4200+
{
4201+
"inputs": [
4202+
{
4203+
"internalType": "address",
4204+
"name": "account",
4205+
"type": "address"
4206+
}
4207+
],
4208+
"name": "getRewardStatistics",
4209+
"outputs": [
4210+
{
4211+
"internalType": "uint256",
4212+
"name": "totalClaimed",
4213+
"type": "uint256"
4214+
},
4215+
{
4216+
"internalType": "uint256",
4217+
"name": "totalDistributed",
4218+
"type": "uint256"
4219+
},
4220+
{
4221+
"internalType": "uint256",
4222+
"name": "claimPercentage",
4223+
"type": "uint256"
4224+
}
4225+
],
4226+
"stateMutability": "view",
4227+
"type": "function"
4228+
},
40814229
{
40824230
"inputs": [
40834231
{

apps/box/src/contracts/contractService.ts

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,9 +1081,9 @@ export class ContractService {
10811081
const rewardEngineAddress = chainConfig.contracts.rewardEngine;
10821082
const iface = this.rewardEngineContract.interface;
10831083

1084-
console.log('🔧 claimRewardsForPeer: Encoding function data...');
1084+
console.log('🔧 claimRewardsForPeer: Encoding function data for claimRewardsV2...');
10851085
const data = iface.encodeFunctionData(
1086-
"claimRewards(bytes32,uint32)",
1086+
"claimRewardsV2(bytes32,uint32)",
10871087
[peerIdBytes32, Number(poolId)]
10881088
);
10891089

@@ -1172,56 +1172,51 @@ export class ContractService {
11721172
}
11731173

11741174
// Reward Methods
1175+
// DEPRECATED: Use claimRewardsForPeer(peerId, poolId) instead - V2 contract requires peerId
11751176
async claimRewards(poolId: string): Promise<void> {
1176-
try {
1177-
if (!this.rewardEngineContract) throw new Error('Contract not initialized');
1178-
1179-
const tx = await this.rewardEngineContract.claimRewards(poolId, {
1180-
gasLimit: METHOD_GAS_LIMITS.claimRewards,
1181-
});
1182-
1183-
await tx.wait();
1184-
} catch (error) {
1185-
throw this.handleError(error);
1186-
}
1177+
console.warn('claimRewards(poolId) is DEPRECATED. Use claimRewardsForPeer(peerId, poolId) instead.');
1178+
throw new Error('claimRewards(poolId) is deprecated in V2 contract. Use claimRewardsForPeer(peerId, poolId) instead.');
11871179
}
11881180

1181+
// DEPRECATED: getRewards does not exist in V2 contract
1182+
// Use getUnclaimedRewards(account, peerId, poolId) or getClaimedRewardsInfo(account, peerId, poolId) instead
11891183
async getRewards(account: string, poolId: string): Promise<RewardInfo> {
1190-
try {
1191-
if (!this.rewardEngineContract) throw new Error('Contract not initialized');
1192-
1193-
const reward = await this.rewardEngineContract.getRewards(account, poolId);
1194-
return {
1195-
account: reward.account,
1196-
poolId: reward.poolId.toString(),
1197-
amount: ethers.utils.formatEther(reward.amount),
1198-
lastClaimEpoch: reward.lastClaimEpoch.toNumber(),
1199-
};
1200-
} catch (error) {
1201-
throw this.handleError(error);
1202-
}
1184+
console.warn('getRewards is DEPRECATED and not available in V2 contract. Use getUnclaimedRewards or getClaimedRewardsInfo instead.');
1185+
// Return empty/default values for backward compatibility
1186+
return {
1187+
account: account,
1188+
poolId: poolId,
1189+
amount: '0',
1190+
lastClaimEpoch: 0,
1191+
};
12031192
}
12041193

1194+
// Get total rewards claimed by an account using V2 getRewardStatistics
12051195
async getTotalRewards(account: string): Promise<string> {
12061196
try {
1207-
if (!this.rewardEngineContract) throw new Error('Contract not initialized');
1197+
if (!this.readOnlyProvider) throw new Error('Read-only provider not initialized');
1198+
1199+
const chainConfig = getChainConfigByName(this.chain);
1200+
const readOnlyRewardContract = new ethers.Contract(
1201+
chainConfig.contracts.rewardEngine,
1202+
REWARD_ENGINE_ABI,
1203+
this.readOnlyProvider
1204+
);
12081205

1209-
const total = await this.rewardEngineContract.getTotalRewards(account);
1210-
return ethers.utils.formatEther(total);
1206+
// V2 uses getRewardStatistics which returns (totalClaimed, totalDistributed, claimPercentage)
1207+
const result = await readOnlyRewardContract.getRewardStatistics(account);
1208+
return ethers.utils.formatEther(result.totalClaimed || result[0] || 0);
12111209
} catch (error) {
1210+
console.error('getTotalRewards error:', error);
12121211
throw this.handleError(error);
12131212
}
12141213
}
12151214

1215+
// DEPRECATED: Use getUnclaimedRewards(account, peerId, poolId) instead - V2 requires peerId
12161216
async getClaimableRewards(account: string, poolId: string): Promise<string> {
1217-
try {
1218-
if (!this.rewardEngineContract) throw new Error('Contract not initialized');
1219-
1220-
const claimable = await this.rewardEngineContract.getClaimableRewards(account, poolId);
1221-
return ethers.utils.formatEther(claimable);
1222-
} catch (error) {
1223-
throw this.handleError(error);
1224-
}
1217+
console.warn('getClaimableRewards(account, poolId) is DEPRECATED. Use getUnclaimedRewards(account, peerId, poolId) instead.');
1218+
// Return '0' for backward compatibility - callers should migrate to getUnclaimedRewards
1219+
return '0';
12251220
}
12261221

12271222
// User Membership Methods

0 commit comments

Comments
 (0)