From df8d9214132deba0b74ff9e6b180e6a9b287de79 Mon Sep 17 00:00:00 2001 From: qwer951123 Date: Mon, 6 Nov 2023 20:26:17 +0800 Subject: [PATCH] update lsd --- packages/lsd-staking/schema.graphql | 2 ++ packages/lsd-staking/src/handlers/index.ts | 17 ++++++++++++++--- .../lsd-staking/src/types/models/StakeRecord.ts | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/lsd-staking/schema.graphql b/packages/lsd-staking/schema.graphql index 0a7eedf..d6186a2 100644 --- a/packages/lsd-staking/schema.graphql +++ b/packages/lsd-staking/schema.graphql @@ -98,6 +98,8 @@ type StakeRecord @entity { poolId: BigInt! amount: BigInt! + + originShareTokenAmount: BigInt } type UnstakeRecord @entity { diff --git a/packages/lsd-staking/src/handlers/index.ts b/packages/lsd-staking/src/handlers/index.ts index 6c44952..1e4c22e 100644 --- a/packages/lsd-staking/src/handlers/index.ts +++ b/packages/lsd-staking/src/handlers/index.ts @@ -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'; @@ -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()); @@ -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()); @@ -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 +) { + logger.info(`StakeCall: ${event.success}`) + logger.info(JSON.stringify(event.args.events)) } export async function handleUnstake( @@ -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()); diff --git a/packages/lsd-staking/src/types/models/StakeRecord.ts b/packages/lsd-staking/src/types/models/StakeRecord.ts index 0be763e..ea5062f 100644 --- a/packages/lsd-staking/src/types/models/StakeRecord.ts +++ b/packages/lsd-staking/src/types/models/StakeRecord.ts @@ -23,6 +23,7 @@ export class StakeRecord implements Entity { amount: bigint, + ) { this.id = id; @@ -52,6 +53,8 @@ export class StakeRecord implements Entity { public amount: bigint; + public originShareTokenAmount?: bigint; + get _name(): string { return 'StakeRecord';