-
Notifications
You must be signed in to change notification settings - Fork 48
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
feat: pendle #364
Changes from 1 commit
c466f13
c851366
f5169c0
797b6ea
50b9287
f7afb1e
ae882c6
d5bca7a
ba6efd8
3da3a9f
0db9e00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { | ||
|
@@ -34,6 +34,7 @@ import { RouterStatic__factory, YieldToken__factory } from '../../contracts' | |
|
||
type AdditionalMetadata = { | ||
marketAddress: string | ||
expiry: string | ||
} | ||
|
||
export class PendleYieldTokenAdapter implements IProtocolAdapter { | ||
|
@@ -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) | ||
|
@@ -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 | ||
}, | ||
) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
}) | ||
} | ||
|
||
|
There was a problem hiding this comment.
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?