Skip to content

Commit

Permalink
update lsd
Browse files Browse the repository at this point in the history
  • Loading branch information
qwer951123 committed Nov 6, 2023
1 parent 369aa77 commit df8d921
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions packages/lsd-staking/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ type StakeRecord @entity {
poolId: BigInt!

amount: BigInt!

originShareTokenAmount: BigInt
}

type UnstakeRecord @entity {
Expand Down
17 changes: 14 additions & 3 deletions packages/lsd-staking/src/handlers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AcalaEvmEvent } from '@subql/acala-evm-processor';
import { AcalaEvmEvent, AcalaEvmCall } from '@subql/acala-evm-processor';
import { NewPoolEvent, RewardsDeductionRateSetEvent, RewardRuleUpdateEvent, StakeEvent, UnstakeEvent, ClaimRewardEvent, LSTPoolConvertedEvent } from '../types/contracts/LsdAbi';
import { Pool, Shares, RewardRule, ClaimedReward, RewardSupply, NewPoolRecord, RewardsDeductionRateSetRecord, RewardRuleUpdateRecord, StakeRecord, UnstakeRecord, ClaimRewardRecord, LSTPoolConvertedRecord } from '../types';

Expand All @@ -11,6 +11,7 @@ export async function handleNewPool(

const poolEntity = new Pool(poolId.toString());
poolEntity.shareType = shareType.toString();
poolEntity.totalShare = BigInt(0);
await poolEntity.save();

const newPoolRecordEntity = new NewPoolRecord(`${event.transactionHash}-${event.logIndex}`, event.blockTimestamp, event.from, poolId.toBigInt(), shareType.toString());
Expand All @@ -26,7 +27,6 @@ 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 Down Expand Up @@ -90,11 +90,22 @@ export async function handleStake(
sharesEntity = new Shares(shareId, poolId.toBigInt(), sender.toString());
sharesEntity.stakedAmount = BigInt(0);
}

sharesEntity.stakedAmount = sharesEntity.stakedAmount + amount.toBigInt();
await sharesEntity.save();


const stakeRecordEntity = new StakeRecord(`${event.transactionHash}-${event.logIndex}`, event.blockTimestamp, event.from, sender.toString(), poolId.toBigInt(), amount.toBigInt());
await stakeRecordEntity.save();

logger.info('Stake: success');
}

export async function handleStakeCall (
event: AcalaEvmCall<any>
) {
logger.info(`StakeCall: ${event.success}`)
logger.info(JSON.stringify(event.args.events))
}

export async function handleUnstake(
Expand Down Expand Up @@ -145,7 +156,7 @@ export async function handleLSTPoolConverted(

const poolIdEntity = await Pool.get(poolId.toString());
poolIdEntity.convertedType = afterShareType.toString();
poolIdEntity.convertedExchangeRate = afterShareTokenAmount.toBigInt() * BigInt(10 ^ 18) / beforeShareTokenAmount.toBigInt();
poolIdEntity.convertedExchangeRate = afterShareTokenAmount.toBigInt() * BigInt(10 ** 18) / beforeShareTokenAmount.toBigInt();
await poolIdEntity.save();

const lsdPoolConvertedRecordEntity = new LSTPoolConvertedRecord(`${event.transactionHash}-${event.logIndex}`, event.blockTimestamp, event.from, poolId.toBigInt(), beforeShareType.toString(), afterShareType.toString(), beforeShareTokenAmount.toBigInt(), afterShareTokenAmount.toBigInt());
Expand Down
3 changes: 3 additions & 0 deletions packages/lsd-staking/src/types/models/StakeRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export class StakeRecord implements Entity {

amount: bigint,


) {

this.id = id;
Expand Down Expand Up @@ -52,6 +53,8 @@ export class StakeRecord implements Entity {

public amount: bigint;

public originShareTokenAmount?: bigint;


get _name(): string {
return 'StakeRecord';
Expand Down

0 comments on commit df8d921

Please sign in to comment.