diff --git a/subgraphs/isolated-pools/src/operations/create.ts b/subgraphs/isolated-pools/src/operations/create.ts index 293e92f6..4d7bb901 100644 --- a/subgraphs/isolated-pools/src/operations/create.ts +++ b/subgraphs/isolated-pools/src/operations/create.ts @@ -37,6 +37,7 @@ import { vWETHLiquidStakedETHAddress, vWETHCoreAddress, } from '../constants/addresses'; +import { getOrCreateRewardSpeed } from './getOrCreate'; import { getTokenPriceInCents, valueOrNotAvailableIntIfReverted } from '../utilities'; import { getAccountId, @@ -302,7 +303,7 @@ export const createMarketPositionBadDebt = ( export const createRewardDistributor = ( rewardsDistributorAddress: Address, comptrollerAddress: Address, -): void => { +): RewardsDistributor => { const rewardDistributorContract = RewardDistributorContract.bind(rewardsDistributorAddress); const rewardToken = rewardDistributorContract.rewardToken(); const id = getRewardsDistributorId(rewardsDistributorAddress); @@ -311,4 +312,22 @@ export const createRewardDistributor = ( rewardsDistributor.pool = comptrollerAddress; rewardsDistributor.reward = rewardToken; rewardsDistributor.save(); + + // we get the current speeds for all known markets at this point in time + const comptroller = Comptroller.bind(comptrollerAddress); + const marketAddresses = comptroller.getAllMarkets(); + + if (marketAddresses !== null) { + for (let i = 0; i < marketAddresses.length; i++) { + const marketAddress = marketAddresses[i]; + + const rewardSpeed = getOrCreateRewardSpeed(rewardsDistributorAddress, marketAddress); + rewardSpeed.borrowSpeedPerBlockMantissa = + rewardDistributorContract.rewardTokenBorrowSpeeds(marketAddress); + rewardSpeed.supplySpeedPerBlockMantissa = + rewardDistributorContract.rewardTokenSupplySpeeds(marketAddress); + rewardSpeed.save(); + } + } + return rewardsDistributor; }; diff --git a/subgraphs/isolated-pools/src/operations/getOrCreate.ts b/subgraphs/isolated-pools/src/operations/getOrCreate.ts index 7507d3f9..bd4c9ee3 100644 --- a/subgraphs/isolated-pools/src/operations/getOrCreate.ts +++ b/subgraphs/isolated-pools/src/operations/getOrCreate.ts @@ -10,8 +10,6 @@ import { RewardSpeed, RewardsDistributor, } from '../../generated/schema'; -import { Comptroller } from '../../generated/templates/Pool/Comptroller'; -import { RewardsDistributor as RewardDistributorContract } from '../../generated/templates/RewardsDistributor/RewardsDistributor'; import { zeroBigInt32 } from '../constants'; import { getAccountPoolId, @@ -20,7 +18,13 @@ import { getRewardSpeedId, getRewardsDistributorId, } from '../utilities/ids'; -import { createAccount, createAccountPool, createMarket, createPool } from './create'; +import { + createAccount, + createAccountPool, + createMarket, + createPool, + createRewardDistributor, +} from './create'; import { getMarketPosition, getMarket } from './get'; export const getOrCreateMarket = ( @@ -125,29 +129,7 @@ export const getOrCreateRewardDistributor = ( let rewardsDistributor = RewardsDistributor.load(id); if (!rewardsDistributor) { - const rewardDistributorContract = RewardDistributorContract.bind(rewardsDistributorAddress); - const rewardToken = rewardDistributorContract.rewardToken(); - rewardsDistributor = new RewardsDistributor(id); - rewardsDistributor.pool = comptrollerAddress; - rewardsDistributor.reward = rewardToken; - rewardsDistributor.save(); - - // we get the current speeds for all known markets at this point in time - const comptroller = Comptroller.bind(comptrollerAddress); - const marketAddresses = comptroller.getAllMarkets(); - - if (marketAddresses !== null) { - for (let i = 0; i < marketAddresses.length; i++) { - const marketAddress = marketAddresses[i]; - - const rewardSpeed = getOrCreateRewardSpeed(rewardsDistributorAddress, marketAddress); - rewardSpeed.borrowSpeedPerBlockMantissa = - rewardDistributorContract.rewardTokenBorrowSpeeds(marketAddress); - rewardSpeed.supplySpeedPerBlockMantissa = - rewardDistributorContract.rewardTokenSupplySpeeds(marketAddress); - rewardSpeed.save(); - } - } + rewardsDistributor = createRewardDistributor(rewardsDistributorAddress, comptrollerAddress); } return rewardsDistributor;