Skip to content

Commit

Permalink
fix lsd staking
Browse files Browse the repository at this point in the history
  • Loading branch information
qwer951123 committed Oct 7, 2023
1 parent d0c5cf3 commit d4a07f3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/lsd-staking/project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ dataSources:
kind: substrate/AcalaEvmEvent
filter:
topics:
- LSTPoolConverted(uint256 poolId, address beforeShareType, address afterShareType, uint256 beforeShareTokenAmount, uint256 afterShareTokenAmount)
- LSTPoolConverted(uint256 poolId, address beforeShareType, address afterShareType, uint256 beforeShareTokenAmount, uint256 afterShareTokenAmount)
6 changes: 4 additions & 2 deletions packages/lsd-staking/src/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export async function handleRewardsDeductionRateSet(

const poolEntity = await Pool.get(poolId.toString());
poolEntity.rewardsDeductionRate = rate.toBigInt();
poolEntity.totalShare = BigInt(0);
await poolEntity.save();

const rewardsDeductionRateSetRecordEntity = new RewardsDeductionRateSetRecord(`${event.transactionHash}-${event.logIndex}`, event.blockTimestamp, event.from, poolId.toBigInt(), rate.toBigInt());
Expand All @@ -48,17 +49,18 @@ export async function handleRewardRuleUpdate(
}

let rewardSupplyEntity = await RewardSupply.get(id);
if (rewardRuleEntity === undefined) {
if (rewardSupplyEntity === undefined) {
rewardSupplyEntity = new RewardSupply(id);
rewardSupplyEntity.amount = BigInt(0);
}

const now = BigInt(event.blockTimestamp.getTime() / 1000);
const now = BigInt(Math.floor(event.blockTimestamp.getTime() / 1000));
const remain = rewardRuleEntity.endTime > now ? (rewardRuleEntity.endTime - now) * rewardRuleEntity.rewardRate : BigInt(0);

rewardRuleEntity.rewardRate = rewardRate.toBigInt();
rewardRuleEntity.endTime = endTime.toBigInt();


const added = rewardRuleEntity.rewardRate * (rewardRuleEntity.endTime - now) - remain;
if (added > BigInt(0)) {
rewardSupplyEntity.amount = rewardSupplyEntity.amount + remain;
Expand Down
2 changes: 1 addition & 1 deletion packages/lsd-staking/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
//Exports all handler functions
// export * from './mappings/mappingHandlers'
export * from './mappings/mappingHandlers'
2 changes: 1 addition & 1 deletion packages/lsd-staking/src/mappings/mappingHandlers.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
// export * from '../handlers';
export * from '../handlers';

0 comments on commit d4a07f3

Please sign in to comment.