Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: pendle #364

Merged
merged 11 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified arb.db
Binary file not shown.
Binary file modified avax.db
Binary file not shown.
Binary file modified base.db
Binary file not shown.
Binary file modified ethereum.db
Binary file not shown.
Binary file modified matic.db
Binary file not shown.
Binary file modified op.db
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,6 @@ export abstract class AaveBasePoolAdapter implements IProtocolAdapter {
const metadataObject: ProtocolToken[] = []

const promises = reserveTokens.map(async ({ tokenAddress }) => {
const reserveConfigurationData =
await protocolDataProviderContract.getReserveConfigurationData(
tokenAddress,
)

if (
!reserveConfigurationData.isActive ||
reserveConfigurationData.isFrozen
) {
return
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So... we want to show inactive and frozen pools?

I don't remember why we added this in the first place. Is there any example that wasn't showing before?


const reserveTokenAddresses =
await protocolDataProviderContract.getReserveTokensAddresses(
tokenAddress,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { getAddress } from 'ethers'
import { Block, getAddress } from 'ethers'
import { AdaptersController } from '../../../../core/adaptersController'
import { Chain } from '../../../../core/constants/chains'
import { CacheToDb } from '../../../../core/decorators/cacheToDb'
import { CustomJsonRpcProvider } from '../../../../core/provider/CustomJsonRpcProvider'
import { filterMapAsync } from '../../../../core/utils/filters'
import { filterMapAsync, filterMapSync } from '../../../../core/utils/filters'
import { getTokenMetadata } from '../../../../core/utils/getTokenMetadata'
import { Helpers } from '../../../../scripts/helpers'
import {
Expand Down Expand Up @@ -34,6 +34,7 @@ import { RouterStatic__factory, YieldToken__factory } from '../../contracts'

type AdditionalMetadata = {
marketAddress: string
expiry: string
}

export class PendleYieldTokenAdapter implements IProtocolAdapter {
Expand Down Expand Up @@ -78,6 +79,32 @@ export class PendleYieldTokenAdapter implements IProtocolAdapter {
}
}

async isExpiredAtBlock(
expiry: string,
blockNumber?: number,
): Promise<boolean> {
let comparisonDate: Date

if (blockNumber) {
// Get the block details if a block number is provided
const block = await this.provider.getBlock(blockNumber)

if (!block) {
throw new Error(`Block ${blockNumber} not found`)
}

comparisonDate = new Date(block.timestamp * 1000) // Convert seconds to milliseconds
} else {
// If no block number is provided, use today's date
comparisonDate = new Date()
}

const expiryDate = new Date(expiry)

// Compare the expiry date with either the block date or today's date
return comparisonDate > expiryDate
}

@CacheToDb
async getProtocolTokens(): Promise<ProtocolToken<AdditionalMetadata>[]> {
const resp = await fetchAllMarkets(this.chainId)
Expand All @@ -103,14 +130,26 @@ export class PendleYieldTokenAdapter implements IProtocolAdapter {
...yt,
underlyingTokens: [sy],
marketAddress,
expiry: value.expiry,
}
})
}

async getPositions(input: GetPositionsInput): Promise<ProtocolPosition[]> {
const tokens = await filterMapAsync(
await this.getProtocolTokens(),
async (protocolToken) => {
if (await this.isExpiredAtBlock(protocolToken.expiry)) {
return undefined
}

return protocolToken
},
)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least add a TODO here, because when we can update the metadata db dynamically we 1000000% don't want to do this, as it's just delaying fetching positions whilst waiting for block info.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,

I see - you are saying we run metadata daily then save isExpired to true in db, interesting

You found a good use case to run the metadata daily.

return this.helpers.getBalanceOfTokens({
...input,
protocolTokens: await this.getProtocolTokens(),
protocolTokens: tokens,
})
}

Expand Down
Loading