Skip to content

Commit

Permalink
add lido and EtherFi markets (#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
bergarces authored Dec 5, 2024
1 parent 4ca6b6d commit 86e0f6b
Show file tree
Hide file tree
Showing 20 changed files with 424 additions and 147 deletions.
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 @@ -3,7 +3,7 @@ import { AdaptersController } from '../../../core/adaptersController'
import { ZERO_ADDRESS } from '../../../core/constants/ZERO_ADDRESS'
import { Chain } from '../../../core/constants/chains'
import { CustomJsonRpcProvider } from '../../../core/provider/CustomJsonRpcProvider'
import { getTokenMetadata } from '../../../core/utils/getTokenMetadata'
import { filterMapAsync } from '../../../core/utils/filters'
import { Helpers } from '../../../scripts/helpers'
import {
IProtocolAdapter,
Expand All @@ -30,21 +30,111 @@ import {
} from '../contracts'

export const protocolDataProviderContractAddresses: Partial<
Record<Protocol, Partial<Record<Chain, string>>>
Record<
Protocol,
Partial<
Record<
Chain,
{
marketLabel?: string
protocolDataProvider: string
}[]
>
>
>
> = {
[Protocol.AaveV2]: {
[Chain.Ethereum]: getAddress('0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d'),
[Chain.Polygon]: getAddress('0x7551b5D2763519d4e37e8B81929D336De671d46d'),
[Chain.Avalanche]: getAddress('0x65285E9dfab318f57051ab2b139ccCf232945451'),
[Chain.Ethereum]: [
{
protocolDataProvider: getAddress(
'0x057835Ad21a177dbdd3090bB1CAE03EaCF78Fc6d',
),
},
],
[Chain.Polygon]: [
{
protocolDataProvider: getAddress(
'0x7551b5D2763519d4e37e8B81929D336De671d46d',
),
},
],
[Chain.Avalanche]: [
{
protocolDataProvider: getAddress(
'0x65285E9dfab318f57051ab2b139ccCf232945451',
),
},
],
},
[Protocol.AaveV3]: {
[Chain.Ethereum]: getAddress('0x7B4EB56E7CD4b454BA8ff71E4518426369a138a3'),
[Chain.Optimism]: getAddress('0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654'),
[Chain.Arbitrum]: getAddress('0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654'),
[Chain.Polygon]: getAddress('0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654'),
[Chain.Fantom]: getAddress('0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654'),
[Chain.Avalanche]: getAddress('0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654'),
[Chain.Base]: getAddress('0x2d8A3C5677189723C4cB8873CfC9C8976FDF38Ac'),
[Chain.Ethereum]: [
{
protocolDataProvider: getAddress(
'0x41393e5e337606dc3821075Af65AeE84D7688CBD',
),
},
{
marketLabel: 'Lido Market',
protocolDataProvider: getAddress(
'0x08795CFE08C7a81dCDFf482BbAAF474B240f31cD',
),
},
{
marketLabel: 'EtherFi Market',
protocolDataProvider: getAddress(
'0xE7d490885A68f00d9886508DF281D67263ed5758',
),
},
],
[Chain.Optimism]: [
{
protocolDataProvider: getAddress(
'0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654',
),
},
],
[Chain.Arbitrum]: [
{
protocolDataProvider: getAddress(
'0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654',
),
},
],
[Chain.Polygon]: [
{
protocolDataProvider: getAddress(
'0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654',
),
},
],
[Chain.Fantom]: [
{
protocolDataProvider: getAddress(
'0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654',
),
},
],
[Chain.Avalanche]: [
{
protocolDataProvider: getAddress(
'0x69FA688f1Dc47d4B5d8029D5a35FB7a548310654',
),
},
],
[Chain.Base]: [
{
protocolDataProvider: getAddress(
'0x2d8A3C5677189723C4cB8873CfC9C8976FDF38Ac',
),
},
],
[Chain.Bsc]: [
{
protocolDataProvider: getAddress(
'0x23dF2a19384231aFD114b036C14b6b03324D79BC',
),
},
],
},
}

Expand Down Expand Up @@ -165,45 +255,56 @@ export abstract class AaveBasePoolAdapter implements IProtocolAdapter {
}

async getProtocolTokens(): Promise<ProtocolToken[]> {
const protocolDataProviderContract = ProtocolDataProvider__factory.connect(
protocolDataProviderContractAddresses[this.protocolId]![this.chainId]!,
this.provider,
)

const reserveTokens =
await protocolDataProviderContract.getAllReservesTokens()

const metadataObject: ProtocolToken[] = []

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

const protocolTokenPromise = this.helpers.getTokenMetadata(
this.getReserveTokenAddress(reserveTokenAddresses),
const dataProviderEntry =
protocolDataProviderContractAddresses[this.protocolId]![this.chainId]!

const factories = Array.isArray(dataProviderEntry)
? dataProviderEntry
: [{ protocolDataProvider: dataProviderEntry, marketLabel: undefined }]

return (
await Promise.all(
factories.map(async ({ protocolDataProvider, marketLabel }) => {
const protocolDataProviderContract =
ProtocolDataProvider__factory.connect(
protocolDataProvider,
this.provider,
)

const reserveTokens =
await protocolDataProviderContract.getAllReservesTokens()

return await filterMapAsync(
reserveTokens,
async ({ tokenAddress }) => {
const reserveTokenAddresses =
await protocolDataProviderContract.getReserveTokensAddresses(
tokenAddress,
)

const [protocolToken, underlyingToken] = await Promise.all([
this.helpers.getTokenMetadata(
this.getReserveTokenAddress(reserveTokenAddresses),
),
this.helpers.getTokenMetadata(tokenAddress),
])

if (protocolToken.address === ZERO_ADDRESS) {
return undefined
}

return {
...protocolToken,
name: `${protocolToken.name}${
marketLabel ? ` (${marketLabel})` : ''
}`,
underlyingTokens: [underlyingToken],
}
},
)
}),
)
const underlyingTokenPromise = this.helpers.getTokenMetadata(tokenAddress)

const [protocolToken, underlyingToken] = await Promise.all([
protocolTokenPromise,
underlyingTokenPromise,
])

if (protocolToken.address === ZERO_ADDRESS) {
return
}

metadataObject.push({
...protocolToken,
underlyingTokens: [underlyingToken],
})
})

await Promise.all(promises)

return metadataObject
).flat()
}

protected async getProtocolToken(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ export class AaveV2RewardsAdapter implements IProtocolAdapter {
)

const protocolDataProvider = ProtocolDataProvider__factory.connect(
protocolDataProviderContractAddresses[this.protocolId]![this.chainId]!,
protocolDataProviderContractAddresses[this.protocolId]![this.chainId]![0]!
.protocolDataProvider,
this.provider,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"blockNumber": 21330292,
"latency": "Latency: 1.038 seconds",
"aggregatedValues": ["USD422,914.82"],
"snapshot": [
{
"protocolId": "aave-v3",
"name": "Aave v3 AToken",
"description": "Aave v3 defi adapter for yield-generating token",
"siteUrl": "https://aave.com/",
"iconUrl": "https://cryptologos.cc/logos/aave-aave-logo.png",
"positionType": "supply",
"chainId": 1,
"productId": "a-token",
"chainName": "ethereum",
"success": true,
"tokens": [
{
"address": "0xfA1fDbBD71B0aA16162D76914d69cD8CB3Ef92da",
"name": "Aave Ethereum Lido WETH",
"symbol": "aEthLidoWETH",
"decimals": 18,
"balanceRaw": "111290153207368083227n",
"type": "protocol",
"tokens": [
{
"address": "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
"name": "Wrapped Ether",
"symbol": "WETH",
"decimals": 18,
"type": "underlying",
"balanceRaw": "111290153207368083227n",
"balance": 111.29015320736808,
"price": 3800.11,
"iconUrl": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2/logo.png"
}
],
"balance": 111.29015320736808
}
]
}
],
"rpcResponses": {
"c73cfc074e1255e7715b9bbaec5d84f5": {
"result": "0x00000000000000000000000000000000000000000000000608760cb39bf9671b"
},
"2e8c205a0104fe2340d426989c7c3da7": {
"result": "0x0000000000000000000000000000000000000000000000070000000000000cca000000000000000000000000000000000000000000000000000000587a6bb0c00000000000000000000000000000000000000000000000000000000067508006000000000000000000000000000000000000000000000000000000006750801b0000000000000000000000000000000000000000000000070000000000000cca"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ export const testCases: TestCase[] = [

blockNumber: 19818581,
},
{
key: 'lido-market',
chainId: Chain.Ethereum,
method: 'positions',

input: {
userAddress: '0xb83F1688C0b7ebb155a830ae78F71527Ef55e759',
filterProtocolTokens: ['0xfA1fDbBD71B0aA16162D76914d69cD8CB3Ef92da'],
},

blockNumber: 21330292,
},
{
chainId: Chain.Ethereum,
method: 'profits',
Expand Down
Loading

0 comments on commit 86e0f6b

Please sign in to comment.