-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: rename reward Speed to MarketReward and add missing details
- Loading branch information
Showing
9 changed files
with
183 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 99 additions & 3 deletions
102
subgraphs/isolated-pools/src/mappings/rewardsDistributor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,113 @@ | ||
import { BigInt } from '@graphprotocol/graph-ts'; | ||
import { | ||
MarketInitialized, | ||
RewardTokenBorrowSpeedUpdated, | ||
RewardTokenSupplySpeedUpdated, | ||
RewardTokenSupplyIndexUpdated, | ||
SupplyLastRewardingBlockUpdated, | ||
BorrowLastRewardingBlockUpdated, | ||
SupplyLastRewardingBlockTimestampUpdated, | ||
BorrowLastRewardingBlockTimestampUpdated, | ||
} from '../../generated/templates/RewardsDistributor/RewardsDistributor'; | ||
import { getOrCreateRewardSpeed } from '../operations/getOrCreate'; | ||
import { RewardsDistributor as RewardDistributorContract } from '../../generated/templates/RewardsDistributor/RewardsDistributor'; | ||
import { zeroBigInt32 } from '../constants'; | ||
import exponentToBigInt from '../utilities/exponentToBigInt'; | ||
import { getRewardDistributor } from '../operations/get'; | ||
import { getOrCreateMarketReward } from '../operations/getOrCreate'; | ||
|
||
export function handleMarketInitialized(event: MarketInitialized): void { | ||
const marketReward = getOrCreateMarketReward(event.address, event.params.vToken); | ||
const rewardsDistributor = getRewardDistributor(event.address)!; | ||
if (marketReward.supplyStateIndex.equals(zeroBigInt32)) { | ||
marketReward.supplyStateIndex = BigInt.fromI64(exponentToBigInt(BigInt.fromI32(36))); | ||
} | ||
if (marketReward.borrowStateIndex.equals(zeroBigInt32)) { | ||
marketReward.borrowStateIndex = BigInt.fromI64(exponentToBigInt(BigInt.fromI32(36))); | ||
} | ||
if (rewardsDistributor.isTimeBased) { | ||
marketReward.supplyStateBlockNumberOrTimestamp = event.block.timestamp; | ||
marketReward.borrowStateBlockNumberOrTimestamp = event.block.timestamp; | ||
} else { | ||
marketReward.supplyStateBlockNumberOrTimestamp = event.block.number; | ||
marketReward.borrowStateBlockNumberOrTimestamp = event.block.number; | ||
marketReward.save(); | ||
} | ||
} | ||
|
||
export function handleRewardTokenBorrowSpeedUpdated(event: RewardTokenBorrowSpeedUpdated): void { | ||
const rewardSpeed = getOrCreateRewardSpeed(event.address, event.params.vToken); | ||
const rewardSpeed = getOrCreateMarketReward(event.address, event.params.vToken); | ||
rewardSpeed.borrowSpeedPerBlockMantissa = event.params.newSpeed; | ||
rewardSpeed.save(); | ||
} | ||
|
||
export function handleRewardTokenSupplySpeedUpdated(event: RewardTokenSupplySpeedUpdated): void { | ||
const rewardSpeed = getOrCreateRewardSpeed(event.address, event.params.vToken); | ||
const rewardSpeed = getOrCreateMarketReward(event.address, event.params.vToken); | ||
rewardSpeed.supplySpeedPerBlockMantissa = event.params.newSpeed; | ||
rewardSpeed.save(); | ||
} | ||
|
||
export function handleRewardTokenSupplyIndexUpdated(event: RewardTokenSupplyIndexUpdated): void { | ||
const rewardDistributorContract = RewardDistributorContract.bind(event.address); | ||
const rewardsDistributor = getRewardDistributor(event.address)!; | ||
const marketReward = getOrCreateMarketReward(event.address, event.params.vToken); | ||
if (rewardsDistributor.isTimeBased) { | ||
const supplyState = rewardDistributorContract.rewardTokenSupplyStateTimeBased( | ||
event.params.vToken, | ||
); | ||
marketReward.supplyStateIndex = supplyState.getIndex(); | ||
marketReward.supplyStateBlockNumberOrTimestamp = supplyState.getTimestamp(); | ||
} else { | ||
const supplyState = rewardDistributorContract.rewardTokenSupplyState(event.params.vToken); | ||
marketReward.supplyStateIndex = supplyState.getIndex(); | ||
marketReward.supplyStateBlockNumberOrTimestamp = supplyState.getBlock(); | ||
} | ||
} | ||
|
||
export function handleRewardTokenBorrowIndexUpdated(event: RewardTokenSupplyIndexUpdated): void { | ||
const rewardDistributorContract = RewardDistributorContract.bind(event.address); | ||
const rewardsDistributor = getRewardDistributor(event.address)!; | ||
const marketReward = getOrCreateMarketReward(event.address, event.params.vToken); | ||
if (rewardsDistributor.isTimeBased) { | ||
const borrowState = rewardDistributorContract.rewardTokenBorrowStateTimeBased( | ||
event.params.vToken, | ||
); | ||
marketReward.borrowStateIndex = borrowState.getIndex(); | ||
marketReward.borrowStateBlockNumberOrTimestamp = borrowState.getTimestamp(); | ||
} else { | ||
const borrowState = rewardDistributorContract.rewardTokenBorrowState(event.params.vToken); | ||
marketReward.borrowStateIndex = borrowState.getIndex(); | ||
marketReward.borrowStateBlockNumberOrTimestamp = borrowState.getBlock(); | ||
} | ||
} | ||
|
||
export function handleSupplyLastRewardingBlockUpdated( | ||
event: SupplyLastRewardingBlockUpdated, | ||
): void { | ||
const marketReward = getOrCreateMarketReward(event.address, event.params.vToken); | ||
marketReward.supplyLastRewardingBlockTimestamp = event.params.newBlock; | ||
marketReward.save(); | ||
} | ||
|
||
export function handleBorrowLastRewardingBlockUpdated( | ||
event: BorrowLastRewardingBlockUpdated, | ||
): void { | ||
const marketReward = getOrCreateMarketReward(event.address, event.params.vToken); | ||
marketReward.borrowLastRewardingBlockTimestamp = event.params.newBlock; | ||
marketReward.save(); | ||
} | ||
|
||
export function handleSupplyLastRewardingBlockTimestampUpdated( | ||
event: SupplyLastRewardingBlockTimestampUpdated, | ||
): void { | ||
const marketReward = getOrCreateMarketReward(event.address, event.params.vToken); | ||
marketReward.supplyLastRewardingBlockTimestamp = event.params.newTimestamp; | ||
marketReward.save(); | ||
} | ||
|
||
export function handleBorrowLastRewardingBlockTimestampUpdated( | ||
event: BorrowLastRewardingBlockTimestampUpdated, | ||
): void { | ||
const marketReward = getOrCreateMarketReward(event.address, event.params.vToken); | ||
marketReward.borrowLastRewardingBlockTimestamp = event.params.newTimestamp; | ||
marketReward.save(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters