Skip to content

Commit

Permalink
Merge pull request #1147 from multiversx/MEX-353
Browse files Browse the repository at this point in the history
[MEX-353] fix outdated claim progress
  • Loading branch information
dragos-rebegea authored Aug 18, 2023
2 parents a555d25 + 15df34e commit 61a8281
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import { Injectable } from '@nestjs/common';
import { scAddress } from '../../../../config';
import { EnergyType } from '@multiversx/sdk-exchange';
import { ClaimProgress } from '../../../../submodules/weekly-rewards-splitting/models/weekly-rewards-splitting.model';
import { ContractType, OutdatedContract, UserDualYiledToken, UserLockedFarmTokenV2 } from '../../models/user.model';
import {
ContractType,
OutdatedContract,
UserDualYiledToken,
UserLockedFarmTokenV2,
} from '../../models/user.model';
import { UserMetaEsdtService } from '../user.metaEsdt.service';
import { PaginationArgs } from '../../../dex.model';
import { ProxyService } from '../../../proxy/services/proxy.service';
Expand All @@ -11,9 +16,7 @@ import { FarmVersion } from '../../../farm/models/farm.model';
import { farmVersion } from '../../../../utils/farm.utils';
import { BigNumber } from 'bignumber.js';
import { WeekTimekeepingAbiService } from 'src/submodules/week-timekeeping/services/week-timekeeping.abi.service';
import {
WeeklyRewardsSplittingAbiService,
} from 'src/submodules/weekly-rewards-splitting/services/weekly-rewards-splitting.abi.service';
import { WeeklyRewardsSplittingAbiService } from 'src/submodules/weekly-rewards-splitting/services/weekly-rewards-splitting.abi.service';
import { StakingProxyAbiService } from 'src/modules/staking-proxy/services/staking.proxy.abi.service';
import { FarmAbiFactory } from 'src/modules/farm/farm.abi.factory';
import { FarmFactoryService } from 'src/modules/farm/farm.factory';
Expand Down Expand Up @@ -105,12 +108,16 @@ export class UserEnergyComputeService {
this.energyAbi.energyEntryForUser(userAddress),
]);

if (this.isEnergyOutdated(userEnergy, currentClaimProgress)) {
const outdatedClaimProgress = currentClaimProgress.week !== currentWeek;

if (
this.isEnergyOutdated(userEnergy, currentClaimProgress) ||
outdatedClaimProgress
) {
return new OutdatedContract({
address: contractAddress,
type: ContractType.Farm,
claimProgressOutdated:
currentClaimProgress.week !== currentWeek,
claimProgressOutdated: outdatedClaimProgress,
farmToken: farmToken.collection,
});
}
Expand All @@ -130,11 +137,16 @@ export class UserEnergyComputeService {
this.energyAbi.energyEntryForUser(userAddress),
]);

if (this.isEnergyOutdated(userEnergy, currentClaimProgress)) {
const outdatedClaimProgress = currentClaimProgress.week !== currentWeek;

if (
this.isEnergyOutdated(userEnergy, currentClaimProgress) ||
outdatedClaimProgress
) {
return new OutdatedContract({
address: scAddress.feesCollector,
type: ContractType.FeesCollector,
claimProgressOutdated: currentClaimProgress.week != currentWeek,
claimProgressOutdated: outdatedClaimProgress,
});
}
return new OutdatedContract();
Expand Down
47 changes: 47 additions & 0 deletions src/modules/user/specs/user.energy.compute.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ import { StakingProxyService } from '../../staking-proxy/services/staking.proxy.
import { StakingProxyAbiService } from '../../staking-proxy/services/staking.proxy.abi.service';
import { UserEnergyComputeService } from '../services/userEnergy/user.energy.compute.service';
import { MXProxyServiceProvider } from '../../../services/multiversx-communication/mx.proxy.service.mock';
import { Address } from '@multiversx/sdk-core/out';
import { scAddress } from 'src/config';
import { ContractType } from '../models/user.model';
import { WeeklyRewardsSplittingAbiService } from 'src/submodules/weekly-rewards-splitting/services/weekly-rewards-splitting.abi.service';
import { WeekTimekeepingAbiService } from 'src/submodules/week-timekeeping/services/week-timekeeping.abi.service';
import { EnergyAbiService } from 'src/modules/energy/services/energy.abi.service';

describe('UserEnergyComputeService', () => {
let module: TestingModule;
Expand Down Expand Up @@ -193,5 +199,46 @@ describe('UserEnergyComputeService', () => {
})).toBe(false);
});

it('should get outdated contracts on old claim progress', async () => {
const service = module.get<UserEnergyComputeService>(
UserEnergyComputeService,
);
const weeklyRewardsSplittingAbi =
module.get<WeeklyRewardsSplittingAbiService>(
WeeklyRewardsSplittingAbiService,
);
const weekTimekeepingAbi = module.get<WeekTimekeepingAbiService>(
WeekTimekeepingAbiService,
);
const energyAbi = module.get<EnergyAbiService>(EnergyAbiService);
jest.spyOn(
weeklyRewardsSplittingAbi,
'currentClaimProgress',
).mockResolvedValue({
week: 9,
energy: {
amount: '105',
lastUpdateEpoch: 9,
totalLockedTokens: '5',
},
});
jest.spyOn(weekTimekeepingAbi, 'currentWeek').mockResolvedValue(10);
jest.spyOn(energyAbi, 'energyEntryForUser').mockResolvedValue({
amount: '100',
lastUpdateEpoch: 10,
totalLockedTokens: '5',
});

const outdatedContracts =
await service.computeFeesCollectorOutdatedContract(
Address.Zero().bech32(),
);

expect(outdatedContracts).toEqual({
address: scAddress.feesCollector,
type: ContractType.FeesCollector,
claimProgressOutdated: true,
});
});

});

0 comments on commit 61a8281

Please sign in to comment.