-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ui incentives data provider v3
- Loading branch information
1 parent
5931580
commit 57363f4
Showing
12 changed files
with
3,762 additions
and
0 deletions.
There are no files selected for viewing
132 changes: 132 additions & 0 deletions
132
packages/contract-helpers/src/UiIncentiveDataProviderV3-contract/_mocks.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import { BigNumber } from 'ethers'; | ||
import { ReservesIncentiveData, UserReservesIncentivesData } from './types'; | ||
|
||
export const getReservesIncentivesDataMock: ReservesIncentiveData[] = [ | ||
{ | ||
underlyingAsset: '0xb04Aaa2A73ff3D88950BdF19Eb4AC029630a2367', | ||
aIncentiveData: { | ||
tokenAddress: '0x6d0eeb7b37BF26E182EB9a8631DCF79e4EF43DDd', | ||
incentiveControllerAddress: '0x5465485D7b15CaBc9196E73A0b1cc457262079e3', | ||
rewardsTokenInformation: [ | ||
{ | ||
rewardTokenSymbol: 'REW', | ||
rewardTokenAddress: '0x1f689325CBdF44B24DBE2ecC2b1fFD4130861b4E', | ||
rewardOracleAddress: '0xca8e9B5F9e36EbF74096223fc48810861b4FA642', | ||
emissionPerSecond: BigNumber.from({ | ||
_hex: '0x04464ecbc45ffe', | ||
_isBigNumber: true, | ||
}), | ||
incentivesLastUpdateTimestamp: BigNumber.from({ | ||
_hex: '0x61a5167a', | ||
_isBigNumber: true, | ||
}), | ||
tokenIncentivesIndex: BigNumber.from({ | ||
_hex: '0x00', | ||
_isBigNumber: true, | ||
}), | ||
emissionEndTimestamp: BigNumber.from({ | ||
_hex: '0x638649fa', | ||
_isBigNumber: true, | ||
}), | ||
rewardPriceFeed: BigNumber.from({ | ||
_hex: '0x05f5e100', | ||
_isBigNumber: true, | ||
}), | ||
rewardTokenDecimals: 18, | ||
precision: 18, | ||
priceFeedDecimals: 0, | ||
}, | ||
], | ||
}, | ||
vIncentiveData: { | ||
tokenAddress: '0xaD99ef885623E8520f631625b2675d6dAd3aaDC1', | ||
incentiveControllerAddress: '0x5465485D7b15CaBc9196E73A0b1cc457262079e3', | ||
rewardsTokenInformation: [ | ||
{ | ||
rewardTokenSymbol: 'REW', | ||
rewardTokenAddress: '0x1f689325CBdF44B24DBE2ecC2b1fFD4130861b4E', | ||
rewardOracleAddress: '0xca8e9B5F9e36EbF74096223fc48810861b4FA642', | ||
emissionPerSecond: BigNumber.from({ | ||
_hex: '0x04464ecbc45ffe', | ||
_isBigNumber: true, | ||
}), | ||
incentivesLastUpdateTimestamp: BigNumber.from({ | ||
_hex: '0x61a5167a', | ||
_isBigNumber: true, | ||
}), | ||
tokenIncentivesIndex: BigNumber.from({ | ||
_hex: '0x00', | ||
_isBigNumber: true, | ||
}), | ||
emissionEndTimestamp: BigNumber.from({ | ||
_hex: '0x638649fa', | ||
_isBigNumber: true, | ||
}), | ||
rewardPriceFeed: BigNumber.from({ | ||
_hex: '0x05f5e100', | ||
_isBigNumber: true, | ||
}), | ||
rewardTokenDecimals: 18, | ||
precision: 18, | ||
priceFeedDecimals: 0, | ||
}, | ||
], | ||
}, | ||
}, | ||
]; | ||
|
||
export const getUserIncentivesDataMock: UserReservesIncentivesData[] = [ | ||
{ | ||
underlyingAsset: '0xb04Aaa2A73ff3D88950BdF19Eb4AC029630a2367', | ||
aTokenIncentivesUserData: { | ||
tokenAddress: '0x6d0eeb7b37BF26E182EB9a8631DCF79e4EF43DDd', | ||
incentiveControllerAddress: '0x5465485D7b15CaBc9196E73A0b1cc457262079e3', | ||
userRewardsInformation: [ | ||
{ | ||
rewardTokenSymbol: 'REW', | ||
rewardOracleAddress: '0xca8e9B5F9e36EbF74096223fc48810861b4FA642', | ||
rewardTokenAddress: '0x1f689325CBdF44B24DBE2ecC2b1fFD4130861b4E', | ||
userUnclaimedRewards: BigNumber.from({ | ||
_hex: '0x00', | ||
_isBigNumber: true, | ||
}), | ||
tokenIncentivesUserIndex: BigNumber.from({ | ||
_hex: '0x00', | ||
_isBigNumber: true, | ||
}), | ||
rewardPriceFeed: BigNumber.from({ | ||
_hex: '0x05f5e100', | ||
_isBigNumber: true, | ||
}), | ||
priceFeedDecimals: 0, | ||
rewardTokenDecimals: 18, | ||
}, | ||
], | ||
}, | ||
vTokenIncentivesUserData: { | ||
tokenAddress: '0xaD99ef885623E8520f631625b2675d6dAd3aaDC1', | ||
incentiveControllerAddress: '0x5465485D7b15CaBc9196E73A0b1cc457262079e3', | ||
userRewardsInformation: [ | ||
{ | ||
rewardTokenSymbol: 'REW', | ||
rewardOracleAddress: '0xca8e9B5F9e36EbF74096223fc48810861b4FA642', | ||
rewardTokenAddress: '0x1f689325CBdF44B24DBE2ecC2b1fFD4130861b4E', | ||
userUnclaimedRewards: BigNumber.from({ | ||
_hex: '0x00', | ||
_isBigNumber: true, | ||
}), | ||
tokenIncentivesUserIndex: BigNumber.from({ | ||
_hex: '0x00', | ||
_isBigNumber: true, | ||
}), | ||
rewardPriceFeed: BigNumber.from({ | ||
_hex: '0x05f5e100', | ||
_isBigNumber: true, | ||
}), | ||
priceFeedDecimals: 0, | ||
rewardTokenDecimals: 18, | ||
}, | ||
], | ||
}, | ||
}, | ||
]; |
217 changes: 217 additions & 0 deletions
217
packages/contract-helpers/src/UiIncentiveDataProviderV3-contract/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
import { providers } from 'ethers'; | ||
import BaseService from '../commons/BaseService'; | ||
import { UiIncentiveDataProviderValidator } from '../commons/validators/methodValidators'; | ||
import { isEthAddress } from '../commons/validators/paramValidators'; | ||
import { ReservesHelperInput, UserReservesHelperInput } from '../index'; | ||
import { UiIncentiveDataProviderV3 } from './typechain/UiIncentiveDataProviderV3'; | ||
import { UiIncentiveDataProviderV3__factory } from './typechain/UiIncentiveDataProviderV3__factory'; | ||
import { | ||
FullReservesIncentiveDataResponse, | ||
IncentiveData, | ||
IncentiveDataHumanized, | ||
ReservesIncentiveData, | ||
ReservesIncentiveDataHumanized, | ||
RewardInfo, | ||
UserIncentiveData, | ||
UserIncentiveDataHumanized, | ||
UserReservesIncentivesData, | ||
UserReservesIncentivesDataHumanized, | ||
UserRewardInfo, | ||
} from './types'; | ||
export * from './types'; | ||
|
||
export interface UiIncentiveDataProviderInterface { | ||
getFullReservesIncentiveData: ( | ||
args: UserReservesHelperInput, | ||
) => Promise<FullReservesIncentiveDataResponse>; | ||
getReservesIncentivesData: ( | ||
args: ReservesHelperInput, | ||
) => Promise<ReservesIncentiveData[]>; | ||
getUserReservesIncentivesData: ( | ||
args: UserReservesHelperInput, | ||
) => Promise<UserReservesIncentivesData[]>; | ||
getReservesIncentivesDataHumanized: ( | ||
args: ReservesHelperInput, | ||
) => Promise<ReservesIncentiveDataHumanized[]>; | ||
getUserReservesIncentivesDataHumanized: ( | ||
args: UserReservesHelperInput, | ||
) => Promise<UserReservesIncentivesDataHumanized[]>; | ||
} | ||
export interface FeedResultSuccessful { | ||
rewardTokenAddress: string; | ||
answer: string; | ||
updatedAt: number; | ||
decimals: number; | ||
} | ||
|
||
export interface UiIncentiveDataProviderContext { | ||
uiIncentiveDataProviderAddress: string; | ||
provider: providers.Provider; | ||
chainId: number; | ||
} | ||
|
||
export class UiIncentiveDataProvider | ||
extends BaseService<UiIncentiveDataProviderV3> | ||
implements UiIncentiveDataProviderInterface | ||
{ | ||
readonly uiIncentiveDataProviderAddress: string; | ||
|
||
readonly chainId: number; | ||
|
||
/** | ||
* Constructor | ||
* @param context The ui incentive data provider context | ||
*/ | ||
public constructor({ | ||
provider, | ||
uiIncentiveDataProviderAddress, | ||
chainId, | ||
}: UiIncentiveDataProviderContext) { | ||
super(provider, UiIncentiveDataProviderV3__factory); | ||
this.uiIncentiveDataProviderAddress = uiIncentiveDataProviderAddress; | ||
this.chainId = chainId; | ||
} | ||
|
||
/** | ||
* Get the full reserve incentive data for the lending pool and the user | ||
* @param user The user address | ||
*/ | ||
@UiIncentiveDataProviderValidator | ||
public async getFullReservesIncentiveData( | ||
@isEthAddress('user') | ||
@isEthAddress('lendingPoolAddressProvider') | ||
{ user, lendingPoolAddressProvider }: UserReservesHelperInput, | ||
): Promise<FullReservesIncentiveDataResponse> { | ||
const uiIncentiveContract = this.getContractInstance( | ||
this.uiIncentiveDataProviderAddress, | ||
); | ||
|
||
return uiIncentiveContract.getFullReservesIncentiveData( | ||
lendingPoolAddressProvider, | ||
user, | ||
); | ||
} | ||
|
||
/** | ||
* Get the reserve incentive data for the lending pool | ||
*/ | ||
@UiIncentiveDataProviderValidator | ||
public async getReservesIncentivesData( | ||
@isEthAddress('lendingPoolAddressProvider') | ||
{ lendingPoolAddressProvider }: ReservesHelperInput, | ||
): Promise<ReservesIncentiveData[]> { | ||
const uiIncentiveContract = this.getContractInstance( | ||
this.uiIncentiveDataProviderAddress, | ||
); | ||
|
||
return uiIncentiveContract.getReservesIncentivesData( | ||
lendingPoolAddressProvider, | ||
); | ||
} | ||
|
||
/** | ||
* Get the reserve incentive data for the user | ||
* @param user The user address | ||
*/ | ||
@UiIncentiveDataProviderValidator | ||
public async getUserReservesIncentivesData( | ||
@isEthAddress('user') | ||
@isEthAddress('lendingPoolAddressProvider') | ||
{ user, lendingPoolAddressProvider }: UserReservesHelperInput, | ||
): Promise<UserReservesIncentivesData[]> { | ||
const uiIncentiveContract = this.getContractInstance( | ||
this.uiIncentiveDataProviderAddress, | ||
); | ||
|
||
return uiIncentiveContract.getUserReservesIncentivesData( | ||
lendingPoolAddressProvider, | ||
user, | ||
); | ||
} | ||
|
||
@UiIncentiveDataProviderValidator | ||
public async getReservesIncentivesDataHumanized( | ||
@isEthAddress('lendingPoolAddressProvider') | ||
{ lendingPoolAddressProvider }: ReservesHelperInput, | ||
): Promise<ReservesIncentiveDataHumanized[]> { | ||
const response: ReservesIncentiveData[] = | ||
await this.getReservesIncentivesData({ lendingPoolAddressProvider }); | ||
|
||
return response.map(r => ({ | ||
id: `${this.chainId}-${r.underlyingAsset}-${lendingPoolAddressProvider}`.toLowerCase(), | ||
underlyingAsset: r.underlyingAsset.toLowerCase(), | ||
aIncentiveData: this._formatIncentiveData(r.aIncentiveData), | ||
vIncentiveData: this._formatIncentiveData(r.vIncentiveData), | ||
})); | ||
} | ||
|
||
@UiIncentiveDataProviderValidator | ||
public async getUserReservesIncentivesDataHumanized( | ||
@isEthAddress('user') | ||
@isEthAddress('lendingPoolAddressProvider') | ||
{ user, lendingPoolAddressProvider }: UserReservesHelperInput, | ||
): Promise<UserReservesIncentivesDataHumanized[]> { | ||
const response: UserReservesIncentivesData[] = | ||
await this.getUserReservesIncentivesData({ | ||
user, | ||
lendingPoolAddressProvider, | ||
}); | ||
|
||
return response.map(r => ({ | ||
id: `${this.chainId}-${user}-${r.underlyingAsset}-${lendingPoolAddressProvider}`.toLowerCase(), | ||
underlyingAsset: r.underlyingAsset.toLowerCase(), | ||
aTokenIncentivesUserData: this._formatUserIncentiveData( | ||
r.aTokenIncentivesUserData, | ||
), | ||
vTokenIncentivesUserData: this._formatUserIncentiveData( | ||
r.vTokenIncentivesUserData, | ||
), | ||
})); | ||
} | ||
|
||
private _formatIncentiveData(data: IncentiveData): IncentiveDataHumanized { | ||
return { | ||
tokenAddress: data.tokenAddress, | ||
incentiveControllerAddress: data.incentiveControllerAddress, | ||
rewardsTokenInformation: data.rewardsTokenInformation.map( | ||
(rawRewardInfo: RewardInfo) => ({ | ||
precision: rawRewardInfo.precision, | ||
rewardTokenAddress: rawRewardInfo.rewardTokenAddress, | ||
rewardTokenDecimals: rawRewardInfo.rewardTokenDecimals, | ||
emissionPerSecond: rawRewardInfo.emissionPerSecond.toString(), | ||
incentivesLastUpdateTimestamp: | ||
rawRewardInfo.incentivesLastUpdateTimestamp.toNumber(), | ||
tokenIncentivesIndex: rawRewardInfo.tokenIncentivesIndex.toString(), | ||
emissionEndTimestamp: rawRewardInfo.emissionEndTimestamp.toNumber(), | ||
rewardTokenSymbol: rawRewardInfo.rewardTokenSymbol, | ||
rewardOracleAddress: rawRewardInfo.rewardOracleAddress, | ||
rewardPriceFeed: rawRewardInfo.rewardPriceFeed.toString(), | ||
priceFeedDecimals: rawRewardInfo.priceFeedDecimals, | ||
}), | ||
), | ||
}; | ||
} | ||
|
||
private _formatUserIncentiveData( | ||
data: UserIncentiveData, | ||
): UserIncentiveDataHumanized { | ||
return { | ||
tokenAddress: data.tokenAddress, | ||
incentiveControllerAddress: data.incentiveControllerAddress, | ||
userRewardsInformation: data.userRewardsInformation.map( | ||
(userRewardInformation: UserRewardInfo) => ({ | ||
rewardTokenAddress: userRewardInformation.rewardTokenAddress, | ||
rewardTokenDecimals: userRewardInformation.rewardTokenDecimals, | ||
tokenIncentivesUserIndex: | ||
userRewardInformation.tokenIncentivesUserIndex.toString(), | ||
userUnclaimedRewards: | ||
userRewardInformation.userUnclaimedRewards.toString(), | ||
rewardTokenSymbol: userRewardInformation.rewardTokenSymbol, | ||
rewardOracleAddress: userRewardInformation.rewardOracleAddress, | ||
rewardPriceFeed: userRewardInformation.rewardPriceFeed.toString(), | ||
priceFeedDecimals: userRewardInformation.priceFeedDecimals, | ||
}), | ||
), | ||
}; | ||
} | ||
} |
Oops, something went wrong.