Skip to content

Commit

Permalink
Merge branch 'main' into pr/jpsainsb/375
Browse files Browse the repository at this point in the history
  • Loading branch information
bergarces committed Nov 25, 2024
2 parents 4c0c12c + 823733e commit 04ee2c7
Show file tree
Hide file tree
Showing 45 changed files with 7,266 additions and 29 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.
6 changes: 3 additions & 3 deletions package-lock.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
ProtocolDataProvider__factory,
} from '../contracts'

const protocolDataProviderContractAddresses: Partial<
export const protocolDataProviderContractAddresses: Partial<
Record<Protocol, Partial<Record<Chain, string>>>
> = {
[Protocol.AaveV2]: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Chain } from '../../../../core/constants/chains'
import { CacheToDb } from '../../../../core/decorators/cacheToDb'
import { NotImplementedError } from '../../../../core/errors/errors'
import { CustomJsonRpcProvider } from '../../../../core/provider/CustomJsonRpcProvider'
import { filterMapAsync } from '../../../../core/utils/filters'
import { Helpers } from '../../../../scripts/helpers'
import {
IProtocolAdapter,
Expand All @@ -25,7 +26,15 @@ import {
} from '../../../../types/adapter'
import { AAVE_ICON_URL } from '../../../aave-v3/products/rewards/aaveV3RewardsAdapter'
import { Protocol } from '../../../protocols'
import { StakedTokenIncentivesController__factory } from '../../contracts'
import { protocolDataProviderContractAddresses } from '../../common/aaveBasePoolAdapter'
import {
ProtocolDataProvider__factory,
StakedTokenIncentivesController__factory,
} from '../../contracts'

type AdditionalMetadata = {
reserveTokensWithEmissions: string[]
}

export class AaveV2RewardsAdapter implements IProtocolAdapter {
productId = 'rewards'
Expand Down Expand Up @@ -70,29 +79,72 @@ export class AaveV2RewardsAdapter implements IProtocolAdapter {
}

@CacheToDb
async getProtocolTokens(): Promise<ProtocolToken[]> {
const stakedTokensIncentiveControllerAddress = getAddress(
'0xd784927ff2f95ba542bfc824c8a8a98f3495f6b5',
)
async getProtocolTokens(): Promise<ProtocolToken<AdditionalMetadata>[]> {
const stakedTokensIncentiveControllerAddresses: Partial<
Record<Chain, string>
> = {
[Chain.Ethereum]: getAddress(
'0xd784927ff2f95ba542bfc824c8a8a98f3495f6b5',
),
[Chain.Polygon]: getAddress('0x357D51124f59836DeD84c8a1730D72B749d8BC23'),
[Chain.Avalanche]: getAddress(
'0x01D83Fe6A10D2f2B7AF17034343746188272cAc9',
),
}
const stakedTokensIncentiveControllerAddress =
stakedTokensIncentiveControllerAddresses[this.chainId]!

const stakedTokensIncentiveController =
StakedTokenIncentivesController__factory.connect(
stakedTokensIncentiveControllerAddress,
this.provider,
)

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

const reserveTokens = await protocolDataProvider.getAllReservesTokens()

const reserveTokensWithEmissions = (
await Promise.all(
reserveTokens.map(async ({ tokenAddress }) => {
const reserveTokenAddresses =
await protocolDataProvider.getReserveTokensAddresses(tokenAddress)

const reserveTokensWithEmissions = await filterMapAsync(
reserveTokenAddresses,
async (reserveTokenAddress) => {
const assetDetails =
await stakedTokensIncentiveController.assets(
reserveTokenAddress,
)

return assetDetails.emissionPerSecond
? reserveTokenAddress
: undefined
},
)

return reserveTokensWithEmissions
}),
)
).flat()

const rewardTokenAddress =
await stakedTokensIncentiveController.REWARD_TOKEN()

const rewardToken = await this.helpers.getTokenMetadata(rewardTokenAddress)

return [
{
...rewardToken,
address: stakedTokensIncentiveControllerAddress,
name: 'Aave v2 Rewards',
symbol: 'Rewards',
address: stakedTokensIncentiveControllerAddress,
decimals: rewardToken.decimals,
underlyingTokens: [rewardToken],
reserveTokensWithEmissions,
},
]
}
Expand All @@ -102,7 +154,7 @@ export class AaveV2RewardsAdapter implements IProtocolAdapter {
blockNumber,
protocolTokenAddresses,
}: GetPositionsInput): Promise<ProtocolPosition[]> {
const { underlyingTokens, ...protocolToken } = (
const { underlyingTokens, reserveTokensWithEmissions, ...protocolToken } = (
await this.getProtocolTokens()
)[0]!

Expand All @@ -120,11 +172,16 @@ export class AaveV2RewardsAdapter implements IProtocolAdapter {
)

const rewardAmount =
await stakedTokensIncentiveController.getUserUnclaimedRewards(
await stakedTokensIncentiveController.getRewardsBalance(
reserveTokensWithEmissions,
userAddress,
{ blockTag: blockNumber },
)

if (!rewardAmount) {
return []
}

return [
{
...protocolToken,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"blockNumber": 21143202,
"latency": "Latency: 1.813 seconds",
"latency": "Latency: 2.107 seconds",
"aggregatedValues": ["USD88.37"],
"snapshot": [
{
Expand All @@ -21,41 +21,41 @@
"symbol": "Rewards",
"decimals": 18,
"type": "protocol",
"balanceRaw": "484007380433762915n",
"balanceRaw": "484007420894897694n",
"tokens": [
{
"address": "0x4da27a545c0c5B758a6BA100e3a049001de870f5",
"name": "Staked Aave",
"symbol": "stkAAVE",
"decimals": 18,
"type": "underlying-claimable",
"balanceRaw": "484007380433762915n",
"balanceRaw": "484007420894897694n",
"tokens": [
{
"address": "0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9",
"name": "Aave Token",
"symbol": "AAVE",
"decimals": 18,
"type": "underlying-claimable",
"balanceRaw": "484007380433762915n",
"balance": 0.4840073804337629,
"balanceRaw": "484007420894897694n",
"balance": 0.4840074208948977,
"price": 182.58831074981887,
"iconUrl": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9/logo.png"
}
],
"balance": 0.4840073804337629,
"balance": 0.4840074208948977,
"price": 182.58831074981887,
"iconUrl": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x4da27a545c0c5B758a6BA100e3a049001de870f5/logo.png"
}
],
"balance": 0.4840073804337629
"balance": 0.4840074208948977
}
]
}
],
"rpcResponses": {
"e2542edd3bb17e3f089d5e2fe65827d3": {
"result": "0x00000000000000000000000000000000000000000000000006b78a25eb6bfa63"
"b4639da0df30cbddde659dfe2134cc27": {
"result": "0x00000000000000000000000000000000000000000000000006b78a2f5717e61e"
},
"036f5df494d83a21caf9e17028f5a1fc": {
"result": "0x0000000000000000000000000000000000000000000000070000000000000715000000000000000000000000000000000000000000000000000000445230f70000000000000000000000000000000000000000000000000000000000672e077f00000000000000000000000000000000000000000000000000000000672e078f0000000000000000000000000000000000000000000000070000000000000715"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { VotingEscrow } from '../../../../core/adapters/votingEscrow'
import { NotImplementedError } from '../../../../core/errors/errors'
import {
GetPositionsInput,
PositionType,
ProtocolDetails,
} from '../../../../types/adapter'
import {
FeeDistributor__factory,
VotingEscrow__factory,
} from '../../../stargate/contracts'

export class BalancerV2VestingAdapter extends VotingEscrow {
productId = 'vesting'

getProtocolDetails(): ProtocolDetails {
return {
protocolId: this.protocolId,
name: 'BalancerV2',
description: 'BalancerV2 defi adapter',
siteUrl: '',
iconUrl: '',
positionType: PositionType.Staked,
chainId: this.chainId,
productId: this.productId,
}
}

addresses = {
veToken: '0xC128a9954e6c874eA3d62ce62B468bA073093F25',
underlyingToken: '0x5c6Ee304399DBdB9C8Ef030aB642B10820DB8F56',
rewardToken: '0xa13a9247ea42d743238089903570127dda72fe44',
feeDistributor: '0xD3cf852898b21fc233251427c2DC93d3d604F3BB',
}

async getRewardBalance({
userAddress,
blockNumber,
}: GetPositionsInput): Promise<bigint> {
const contract = FeeDistributor__factory.connect(
this.addresses.feeDistributor,
this.provider,
)

return contract.claimToken.staticCall(
userAddress,
this.addresses.rewardToken,
{ blockTag: blockNumber },
)
}

async getLockedDetails({
userAddress,
blockNumber,
}: GetPositionsInput): Promise<{ amount: bigint; end: bigint }> {
const votingEscrow = VotingEscrow__factory.connect(
this.addresses.veToken,
this.provider,
)

const [amount, end] = await votingEscrow.locked(userAddress, {
blockTag: blockNumber,
})

return { amount, end }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"blockNumber": 21194060,
"latency": "Latency: 1.406 seconds",
"aggregatedValues": ["USD0.00"],
"snapshot": [
{
"protocolId": "balancer-v2",
"name": "BalancerV2",
"description": "BalancerV2 defi adapter",
"siteUrl": "",
"iconUrl": "",
"positionType": "stake",
"chainId": 1,
"productId": "vesting",
"chainName": "ethereum",
"success": true,
"tokens": [
{
"type": "protocol",
"balanceRaw": "1701982822546843636967n",
"address": "0xC128a9954e6c874eA3d62ce62B468bA073093F25",
"symbol": "veBAL",
"name": "Vote Escrowed Balancer BPT - Unlock time 06/11/2025",
"decimals": 18,
"tokens": [
{
"address": "0x5c6Ee304399DBdB9C8Ef030aB642B10820DB8F56",
"name": "Balancer 80 BAL 20 WETH",
"symbol": "B-80BAL-20WETH",
"decimals": 18,
"type": "underlying",
"balanceRaw": "1701982822546843636967n",
"balance": 1701.9828225468436,
"iconUrl": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x5c6Ee304399DBdB9C8Ef030aB642B10820DB8F56/logo.png"
},
{
"address": "0xA13a9247ea42D743238089903570127DdA72fE44",
"name": "Balancer Aave Boosted StablePool",
"symbol": "bb-a-USD",
"decimals": 18,
"balanceRaw": "38777247945780920724n",
"type": "underlying-claimable",
"balance": 38.77724794578092,
"iconUrl": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA13a9247ea42D743238089903570127DdA72fE44/logo.png"
}
],
"balance": 1701.9828225468436
}
]
}
],
"rpcResponses": {
"a8ba6f41343842b48531f8605a78eaed": {
"result": "0x00000000000000000000000000000000000000000000005c43c1a79d695014e700000000000000000000000000000000000000000000000000000000690be500"
},
"bf6836bbd7b90f8f17a9d3c202ae8672": {
"result": "0x0000000000000000000000000000000000000000000000021a24758e57848194"
},
"c6443e715cde299579704a591e917756": {
"result": "0x000000000000000000000000000000000000000000000007000000000000091b000000000000000000000000000000000000000000000000000000468eb5f48000000000000000000000000000000000000000000000000000000000673766e100000000000000000000000000000000000000000000000000000000673766f3000000000000000000000000000000000000000000000007000000000000091b"
},
"66d35b4400a89c2cfef0d0d7d3a4aaf0": {
"result": "0x0000000000000000000000000000000000000000000000000000000000000000"
},
"2b4dbedeed86ea18cd4013d4b65e9ce5": {
"result": "0x0000000000000000000000000000000000000000000000000000000000000000"
}
}
}
Loading

0 comments on commit 04ee2c7

Please sign in to comment.