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/staked gho sm #570

Merged
merged 38 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
8434bb9
chore: mock stkgho
foodaka Dec 1, 2023
8790777
chore fix mocks stkGHO
foodaka Dec 1, 2023
1db8f1a
chore: update labels
foodaka Dec 1, 2023
6ccaa8d
mocking stk
foodaka Dec 18, 2023
5eb6c4e
fix: debug
foodaka Jan 5, 2024
55ab377
fix: debug
foodaka Jan 5, 2024
71ef9c3
fix: debug
foodaka Jan 5, 2024
e46e232
fix: debug
foodaka Jan 5, 2024
67854d5
fix: debug
foodaka Jan 5, 2024
f521a6d
fix: debug
foodaka Jan 5, 2024
4efa2cc
fix: debug
foodaka Jan 5, 2024
8b03ceb
feat: stk gho utils
foodaka Jan 12, 2024
91ee5ae
feat: stk gho
foodaka Jan 12, 2024
f09304b
chore: cleanup
foodaka Jan 12, 2024
dfdd9e3
chore: cleanup
foodaka Jan 12, 2024
233892e
chore: cleanup
foodaka Jan 12, 2024
3a21cf4
chore: temp remove check
foodaka Jan 12, 2024
6881998
chore: bump package
foodaka Jan 12, 2024
fc77745
chore: cleaup
foodaka Jan 12, 2024
6e9644d
chore: cleaup
foodaka Jan 12, 2024
f32a7c0
chore: stub mocks
foodaka Jan 15, 2024
6da7576
chore: update abi and eth to usd
foodaka Jan 17, 2024
72dadcd
chore: update abi and eth to usd
foodaka Jan 17, 2024
a10c111
chore: update abi and eth to usd
foodaka Jan 17, 2024
4da87f2
chore: abi on staketoken contract
foodaka Jan 18, 2024
13d9b86
chore: abi on staketoken contract
foodaka Jan 18, 2024
96d03a4
chore: stkaetokentests
foodaka Jan 18, 2024
f208ba3
Merge branch 'master' into feat/staked-gho-sm
grothem Jan 19, 2024
d304548
chore: minor update
foodaka Jan 23, 2024
f9db62e
Merge branch 'master' into feat/staked-gho-sm
foodaka Jan 23, 2024
5819477
Merge branch 'feat/staked-gho-sm' of github.com:aave/aave-utilities i…
foodaka Jan 23, 2024
957af1e
chore: remove unused code
foodaka Jan 24, 2024
8ad592f
chore: webpack imports
foodaka Jan 24, 2024
cb6a47f
chore: webpack imports
foodaka Jan 24, 2024
6dc6c14
chore: remove unused abis
foodaka Jan 24, 2024
4d726e6
chore: pr comments
foodaka Jan 24, 2024
2ab3082
chore: cleanup
grothem Jan 24, 2024
df2a0da
chore: cleanup
grothem Jan 24, 2024
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2640,4 +2640,4 @@ welcome();

```

</details>
</details>
3 changes: 2 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ module.exports = {
'packages/contract-helpers/src/lendingPool-contract/typechain',
'packages/contract-helpers/src/v3-migration-contract/typechain',
'packages/contract-helpers/src/index.ts',
'packages/math-utils/src/formatters/reserve/index.ts', // TODO: remove
'packages/math-utils/src/formatters/reserve/index.ts',
'packages/contract-helpers/src/V3-uiStakeDataProvider-contract/index.ts',
],
modulePathIgnorePatterns: ['node_modules'],
testEnvironment: 'node',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
/* istanbul ignore file */
import { BigNumber } from 'ethers';

export const GeneralStakeUIDataHumanized = {
stakeData: [
{
inPostSlashingPeriod: false,
stakeTokenTotalSupply: '0',
stakeTokenTotalRedeemableAmount: '0',
stakeCooldownSeconds: 0,
stakeUnstakeWindow: 0,
stakeTokenPriceUSD: '0',
rewardTokenPriceUSD: '0',
stakeApy: '0',
distributionPerSecond: '0',
distributionEnd: '0',
},
],
ethPriceUsd: '0',
};

export const GetUserStakeUIDataHumanized = {
stakeUserData: [
{
stakeTokenUserBalance: '0',
underlyingTokenUserBalance: '0',
stakeTokenRedeemableAmount: '0',
userCooldownAmount: '0',
userCooldownTimestamp: 0,
userIncentivesToClaim: '0',
},
],
ethPriceUsd: '0',
};

export const stakedUserDataRaw = [
[{}],
[
{
stakedTokenUserBalance: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
underlyingTokenUserBalance: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
stakedTokenRedeemableAmount: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
userCooldownAmount: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
userIncentivesToClaim: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
userCooldownTimestamp: 0,
rewardsToClaim: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
0: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
1: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
2: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
3: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
4: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
5: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
// 6: BigNumber.from({
// _hex: '0x0',
// _isBigNumber: true,
// }),
// 7: 0,
// 8: BigNumber.from({
// _hex: '0x0',
// _isBigNumber: true,
// }),
},
],
];

export const mockStakedData = [
[
{
stakedTokenTotalSupply: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
stakedTokenTotalRedeemableAmount: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
stakeCooldownSeconds: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
stakeUnstakeWindow: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
stakedTokenPriceUsd: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
rewardTokenPriceUsd: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
stakeApy: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
distributionPerSecond: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
distributionEnd: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
0: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
1: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
2: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
3: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
4: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
5: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
6: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
7: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
8: BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
},
],
[
BigNumber.from({
_hex: '0x0',
_isBigNumber: true,
}),
],
];
115 changes: 115 additions & 0 deletions packages/contract-helpers/src/V3-uiStakeDataProvider-contract/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/* istanbul ignore file */
import { providers } from 'ethers';

import { Abi as IStakedTokenDataProvider } from './typechain/Abi';
import { Abi__factory } from './typechain/factories/Abi__factory';

import {
StakedTokenData,
GeneralStakeUIDataHumanized,
StakedContractUserData,
GetUserStakeUIDataHumanized,
} from './types';

type EthAddress = string;

export interface UiStakeDataProviderInterfaceV3 {
getStakedAssetDataBatch: (
stakedAssets: EthAddress[],
oracles: EthAddress[],
) => Promise<GeneralStakeUIDataHumanized>;
getUserStakeUIDataHumanized: (params: {
user: string;
stakedAssets: EthAddress[];
oracles: EthAddress[];
}) => Promise<GetUserStakeUIDataHumanized>;
}

export type UiStakeDataProviderContext = {
uiStakeDataProvider: string;
provider: providers.Provider;
};

export class UiStakeDataProviderV3 implements UiStakeDataProviderInterfaceV3 {
private readonly _contract: IStakedTokenDataProvider;

public constructor(context: UiStakeDataProviderContext) {
this._contract = Abi__factory.connect(
context.uiStakeDataProvider,
context.provider,
);
}

public async getUserStakeUIDataHumanized({
user,
stakedAssets,
oracles,
}: {
user: string;
stakedAssets: EthAddress[];
oracles: EthAddress[];
}): Promise<GetUserStakeUIDataHumanized> {
const [, stakedUserData] = await this._contract.getStakedUserDataBatch(
stakedAssets,
oracles,
user,
);

// // NOTE only fetching eth price here, should we call oracle directly?
const [, ethPrice] = await this._contract.getStakedAssetDataBatch(
stakedAssets,
oracles,
);

const parsedUserStakedData = handleUserStakedData(stakedUserData);

return {
stakeUserData: parsedUserStakedData,
ethPriceUsd: ethPrice.toString(),
};
}

public async getStakedAssetDataBatch(
stakedAssets: EthAddress[],
oracles: EthAddress[],
): Promise<GeneralStakeUIDataHumanized> {
const [stakedData, ethPrice] = await this._contract.getStakedAssetDataBatch(
stakedAssets,
oracles,
);

const parsedStakedData = handleParsedStakedData(stakedData);
return { stakeData: parsedStakedData, ethPriceUsd: ethPrice.toString() };
}
}

function handleUserStakedData(stakeUserData: StakedContractUserData[]) {
return stakeUserData.map((data: StakedContractUserData) => {
return {
stakeTokenUserBalance: data.stakedTokenUserBalance.toString(),
underlyingTokenUserBalance: data.underlyingTokenUserBalance.toString(),
stakeTokenRedeemableAmount: data.stakedTokenRedeemableAmount.toString(),
userCooldownAmount: data.userCooldownAmount.toString(),
userCooldownTimestamp: data.userCooldownTimestamp,
userIncentivesToClaim: data.rewardsToClaim.toString(),
};
});
}

function handleParsedStakedData(stakedData: StakedTokenData[]) {
return stakedData.map((data: StakedTokenData) => {
return {
inPostSlashingPeriod: data.inPostSlashingPeriod || false,
stakeTokenTotalSupply: data.stakedTokenTotalSupply.toString(),
stakeTokenTotalRedeemableAmount:
data.stakedTokenTotalRedeemableAmount.toString(),
stakeCooldownSeconds: data.stakeCooldownSeconds.toNumber(),
stakeUnstakeWindow: data.stakeUnstakeWindow.toNumber(),
stakeTokenPriceUSD: data.stakedTokenPriceUsd.toString(),
rewardTokenPriceUSD: data.rewardTokenPriceUsd.toString(),
stakeApy: data.stakeApy.toString(),
distributionPerSecond: data.distributionPerSecond.toString(),
distributionEnd: data.distributionEnd.toString(),
};
});
}
Loading
Loading