Skip to content

Commit

Permalink
unallocated supply, gauntlet strategies, weth balance for native str…
Browse files Browse the repository at this point in the history
…ategies
  • Loading branch information
apexearth committed Jan 7, 2025
1 parent 3c94272 commit a06a97b
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 7 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ type OToken @entity {
otoken: String! @index
timestamp: DateTime! @index
blockNumber: Int! @index
unallocatedSupply: BigInt!
totalSupply: BigInt!
rebasingSupply: BigInt!
nonRebasingSupply: BigInt!
Expand Down
1 change: 1 addition & 0 deletions src/base/super-oeth-b.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const otokenProcessor = createOTokenProcessor({
yieldSent: true,
},
otokenVaultAddress: baseAddresses.superOETHb.vault,
redemptionAsset: { asset: baseAddresses.tokens.WETH, symbol: 'WETH' },
oTokenAssets: [
{ asset: baseAddresses.tokens.superOETHb, symbol: 'superOETHb' },
{
Expand Down
10 changes: 9 additions & 1 deletion src/mainnet/processors/erc20s.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { createERC20EventTracker } from '@templates/erc20/erc20-event'
import { createERC20PollingTracker } from '@templates/erc20/erc20-polling'
import { OETH_DRIPPER_ADDRESS, OETH_VAULT_ADDRESS, WOETH_ADDRESS, oethStrategyArray, tokens } from '@utils/addresses'
import {
OETH_DRIPPER_ADDRESS,
OETH_NATIVE_STRATEGIES,
OETH_VAULT_ADDRESS,
WOETH_ADDRESS,
oethStrategyArray,
tokens,
} from '@utils/addresses'
import { TokenSymbol } from '@utils/symbols'

// TODO: Would be nice if interested parties could register their desires here from other parts of the code,
Expand Down Expand Up @@ -45,6 +52,7 @@ const tracks: Record<string, Parameters<typeof createERC20PollingTracker>[0]> =
...oethStrategyArray,
OETH_VAULT_ADDRESS,
OETH_DRIPPER_ADDRESS,
...OETH_NATIVE_STRATEGIES.map((s) => s.address),
// '0xa4e0faA58465A2D369aa21B3e42d43374c6F9613', // Uniswap wstETH/WETH
// '0x109830a1aaad605bbf02a9dfa7b0b92ec2fb7daa', // Uniswap rETH/WETH
],
Expand Down
1 change: 1 addition & 0 deletions src/mainnet/processors/native-staking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export const process = async (ctx: Context) => {
}
}
}

await ctx.store.upsert([...result.pubkeys.values()])
await ctx.store.insert([...result.deposits.values()])
}
Expand Down
3 changes: 3 additions & 0 deletions src/model/generated/oToken.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export class OToken {
@IntColumn_({nullable: false})
blockNumber!: number

@BigIntColumn_({nullable: false})
unallocatedSupply!: bigint

@BigIntColumn_({nullable: false})
totalSupply!: bigint

Expand Down
1 change: 1 addition & 0 deletions src/oeth/processors/oeth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const otokenProcessor = createOTokenProcessor({
from: 17067707,
},
otokenVaultAddress: OETH_VAULT_ADDRESS,
redemptionAsset: { asset: WETH_ADDRESS, symbol: 'WETH' },
oTokenAssets: [
{ asset: ETH_ADDRESS, symbol: 'ETH' },
{ asset: WETH_ADDRESS, symbol: 'WETH' },
Expand Down
28 changes: 27 additions & 1 deletion src/ousd/processors/strategies/strategies.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { Context } from '@processor'
import { mainnetCurrencies } from '@shared/post-processors/exchange-rates/mainnetCurrencies'
import { EvmBatchProcessor } from '@subsquid/evm-processor'
import { IStrategyData, createStrategyProcessor, createStrategySetup } from '@templates/strategy'
import { createStrategyRewardProcessor, createStrategyRewardSetup } from '@templates/strategy-rewards'
import * as mainnetAddresses from '@utils/addresses'

import { aaveStrategy } from './aave-strategy'
import { USDC, USDT } from './const'
import { convexMetaStrategy } from './convex-meta-strategy'
import { fluxStrategy } from './flux-strategy'
import { makerDsrStrategy } from './maker-dsr-strategy'
Expand All @@ -19,7 +22,30 @@ export const ousdStrategies: readonly IStrategyData[] = [
fluxStrategy,
makerDsrStrategy,
metamorphoStrategy,

{
chainId: 1,
from: 21425796,
oTokenAddress: mainnetAddresses.OUSD_ADDRESS,
kind: 'Generic',
name: 'OUSD Gauntlet Prime USDC',
contractName: 'Generalized4626Strategy',
address: mainnetAddresses.strategies.ousd.GauntletPrimeUSDCStrategy,
base: { address: mainnetCurrencies.USD, decimals: 18 },
assets: [USDC],
earnings: { passiveByDepositWithdrawal: true, rewardTokenCollected: true },
},
{
chainId: 1,
from: 21425837,
oTokenAddress: mainnetAddresses.OUSD_ADDRESS,
kind: 'Generic',
name: 'OUSD Gauntlet Prime USDT',
contractName: 'Generalized4626Strategy',
address: mainnetAddresses.strategies.ousd.GauntletPrimeUSDTStrategy,
base: { address: mainnetCurrencies.USD, decimals: 18 },
assets: [USDT],
earnings: { passiveByDepositWithdrawal: true, rewardTokenCollected: true },
},
// Deprecated
// {
// from: 13369299,
Expand Down
1 change: 1 addition & 0 deletions src/templates/otoken/otoken.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type OToken @entity {
otoken: String! @index
timestamp: DateTime! @index
blockNumber: Int! @index
unallocatedSupply: BigInt!
totalSupply: BigInt!
rebasingSupply: BigInt!
nonRebasingSupply: BigInt!
Expand Down
31 changes: 30 additions & 1 deletion src/templates/otoken/otoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { Between, LessThanOrEqual } from 'typeorm'
import { formatUnits } from 'viem'

import * as erc20 from '@abi/erc20'
import * as otokenVault from '@abi/oeth-vault'
import * as otoken from '@abi/otoken'
import * as otokenHarvester from '@abi/otoken-base-harvester'
import * as otokenDripper from '@abi/otoken-dripper'
import * as otokenVault from '@abi/otoken-vault'
import * as wotoken from '@abi/woeth'
import {
ERC20,
Expand Down Expand Up @@ -69,6 +69,7 @@ export const createOTokenProcessor = (params: {
yieldSent: boolean
}
otokenVaultAddress: string
redemptionAsset?: { asset: CurrencyAddress; symbol: CurrencySymbol }
oTokenAssets: { asset: CurrencyAddress; symbol: CurrencySymbol }[]
getAmoSupply: (ctx: Context, height: number) => Promise<bigint>
upgrades?: {
Expand All @@ -93,6 +94,15 @@ export const createOTokenProcessor = (params: {
topic0: [otoken.events.YieldUndelegated.topic],
range: { from: params.from },
})
const withdrawalRelatedFilter = logFilter({
address: [params.otokenVaultAddress],
topic0: [
otokenVault.events.WithdrawalRequested.topic,
otokenVault.events.WithdrawalClaimable.topic,
otokenVault.events.WithdrawalClaimed.topic,
],
range: { from: params.from },
})

const rebaseEventTopics = {
[otoken.events.AccountRebasingEnabled.topic]: otoken.events.AccountRebasingEnabled,
Expand Down Expand Up @@ -137,6 +147,7 @@ export const createOTokenProcessor = (params: {
if (harvesterYieldSentFilter) {
processor.addLog(harvesterYieldSentFilter.value)
}
processor.addLog(withdrawalRelatedFilter.value)
}

const initialize = async (ctx: Context) => {
Expand Down Expand Up @@ -738,6 +749,20 @@ export const createOTokenProcessor = (params: {
time('processHarvesterYieldSent')
}

// Update the unallocatedSupply of OToken.
const processWithdrawalRelated = async (block: Block, log: Log) => {
if (!params.redemptionAsset) return
const vault = new otokenVault.Contract(ctx, block.header, params.otokenVaultAddress)
const redeemingAsset = new erc20.Contract(ctx, block.header, params.redemptionAsset.asset)
const [otokenObject, withdrawalQueueMetadata, redeemingAssetBalance] = await Promise.all([
getOTokenObject(block),
vault.withdrawalQueueMetadata(),
redeemingAsset.balanceOf(params.otokenVaultAddress),
])
const claimableSupply = withdrawalQueueMetadata.queued - withdrawalQueueMetadata.claimed
otokenObject.unallocatedSupply = redeemingAssetBalance - claimableSupply
}

const getOTokenObject = async (block: Block) => {
const timestamp = new Date(block.header.timestamp)
const otokenId = `${ctx.chain.id}-${params.otokenAddress}-${timestamp.toISOString()}`
Expand All @@ -761,6 +786,7 @@ export const createOTokenProcessor = (params: {
otoken: params.otokenAddress,
timestamp: new Date(block.header.timestamp),
blockNumber: block.header.height,
unallocatedSupply: latest?.unallocatedSupply ?? 0n,
totalSupply: latest?.totalSupply ?? 0n,
rebasingSupply: latest?.rebasingSupply ?? 0n,
nonRebasingSupply: latest?.nonRebasingSupply ?? 0n,
Expand Down Expand Up @@ -900,6 +926,9 @@ export const createOTokenProcessor = (params: {
if (yieldUndelegatedFilter.matches(log)) {
await processYieldUndelegated(block, log)
}
if (withdrawalRelatedFilter.matches(log)) {
await processWithdrawalRelated(block, log)
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/utils/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,14 @@ export const strategies = {
MorphoCompoundStrategy: '0x5a4eee58744d1430876d5ca93cab5ccb763c037d',
MorphoAaveStrategy: '0x79f2188ef9350a1dc11a062cca0abe90684b0197',
FluxStrategy: '0x76bf500b6305dc4ea851384d3d5502f1c7a0ed44',
Generalized4626Strategy: '0x6b69b755c629590ed59618a2712d8a2957ca98fc',
MakerDsrStrategy: '0x6b69b755c629590ed59618a2712d8a2957ca98fc',
CompoundStrategy: '0x9c459eeb3fa179a40329b81c1635525e9a0ef094', // Deprecated
ConvexStrategy: '0xea2ef2e2e5a749d4a66b41db9ad85a38aa264cb3', // Deprecated
LUSDMetaStrategy: '0x7A192DD9Cc4Ea9bdEdeC9992df74F1DA55e60a19', // Deprecated
MetaMorphoStrategy: '0x603cdeaec82a60e3c4a10da6ab546459e5f64fa0',
MakerStrategy: '0x6b69b755c629590ed59618a2712d8a2957ca98fc',
GauntletPrimeUSDCStrategy: '0x2b8f37893ee713a4e9ff0ceb79f27539f20a32a1',
GauntletPrimeUSDTStrategy: '0xe3ae7c80a1b02ccd3fb0227773553aeb14e32f26',
},
} as const

Expand Down

0 comments on commit a06a97b

Please sign in to comment.