Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Add boosted savings vault data #249

Merged
merged 5 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 0 additions & 38 deletions .eslintrc

This file was deleted.

53 changes: 53 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const realConfig = {
extends: [
'airbnb-typescript',
'airbnb/hooks',
'plugin:@typescript-eslint/recommended',
'prettier',
'prettier/react',
'prettier/@typescript-eslint',
],
env: {
node: true,
browser: true,
jest: true,
},
parserOptions: {
project: './tsconfig.json',
},
rules: {
'@typescript-eslint/explicit-function-return-type': [
'error',
{ allowExpressions: true, allowTypedFunctionExpressions: true },
],
'@typescript-eslint/no-unused-vars': ['error', { varsIgnorePattern: '_' }],
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/naming-convention': 'off',
'arrow-body-style': 'off',
'no-underscore-dangle': 'off',
'no-console': ['error', { allow: ['warn', 'error'] }],
'react/no-unescaped-entities': 'off',
'import/prefer-default-export': 'off',
'import/no-default-export': 'error',
'react/prop-types': 'off',
'no-nested-ternary': 'off',
},
};

const nopConfig = {
/*

This config is meant to do nothing.

It exists because there's no good way to disable ESLint in Create React App:
https://github.com/facebook/create-react-app/issues/9929

So the workaround here is to craft a config that does as little as possible,
and then conditionally use it.

*/

ignorePatterns: ['**/*.ts', '**/*.tsx', './*.js', 'config/*.js'],
};

module.exports = process.env.DISABLE_ESLINT ? nopConfig : realConfig;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"eject": "react-scripts eject",
"lint": "yarn eslint './src/**/*.{ts,tsx}' --fix",
"provision": "sh ./scripts/provision.sh",
"start": "react-scripts start",
"start": "DISABLE_ESLINT=true react-scripts start",
"test:ropsten": "env-cmd -f .env.example.ropsten react-scripts test",
"test": "react-scripts test",
"script": "yarn ts-node --project ./scripts/tsconfig.json ./scripts/run.ts",
Expand Down
3 changes: 3 additions & 0 deletions src/components/pages/Save/SaveInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
SaveVersion,
useSelectedSavingsContractState,
} from '../../../context/SelectedSaveVersionProvider';
import { useTokenSubscription } from '../../../context/TokensProvider';
import { SaveMigration } from './SaveMigration';

const CreditBalance = styled.div`
Expand Down Expand Up @@ -84,6 +85,8 @@ export const SaveInfo: FC = () => {
savingsContractState?.version === SaveVersion.V1 &&
!savingsContractState.current;

useTokenSubscription(savingsContractState?.address);

return (
<BalanceInfoRow>
<H3>
Expand Down
5 changes: 5 additions & 0 deletions src/context/DataProvider/DataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const useRawData = (): [MassetsQueryResult['data'], Tokens] => {
return useMemo(() => [subscription.data, tokens], [
blockNumber,
subscription.loading,
tokens,
]);
};

Expand Down Expand Up @@ -78,6 +79,10 @@ export const DataProvider: FC = ({ children }) => {
[data],
);

if (process.env.NODE_ENV === 'development') {
(window as { dataState?: DataState }).dataState = dataState;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a cheeky global var for local dev

}

return (
<dataStateCtx.Provider value={dataState}>{children}</dataStateCtx.Provider>
);
Expand Down
71 changes: 65 additions & 6 deletions src/context/DataProvider/transformRawData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,21 @@ import { MassetName, SubscribedToken } from '../../types';
import { MassetsQueryResult, TokenAllFragment } from '../../graphql/protocol';
import {
BassetStatus,
BoostedSavingsVaultState,
DataState,
MassetState,
SavingsContractState,
} from './types';
import { Tokens } from '../TokensProvider';

type SavingsContractV1QueryResult = NonNullable<
MassetsQueryResult['data']
>['massets'][number]['savingsContractsV1'][number];

type SavingsContractV2QueryResult = NonNullable<
MassetsQueryResult['data']
>['massets'][number]['savingsContractsV2'][number];

const transformBassets = (
bassets: NonNullable<
MassetsQueryResult['data']
Expand Down Expand Up @@ -61,9 +70,7 @@ const transformBassets = (
};

const transformSavingsContractV1 = (
savingsContract: NonNullable<
MassetsQueryResult['data']
>['massets'][number]['savingsContractsV1'][number],
savingsContract: SavingsContractV1QueryResult,
tokens: Tokens,
massetAddress: string,
current: boolean,
Expand Down Expand Up @@ -106,10 +113,58 @@ const transformSavingsContractV1 = (
};
};

const transformBoostedSavingsVault = ({
id: address,
totalSupply,
accounts,
rewardPerTokenStored,
rewardRate,
stakingContract,
totalStakingRewards,
}: NonNullable<
SavingsContractV2QueryResult['boostedSavingsVaults'][number]
>): BoostedSavingsVaultState => {
let account: BoostedSavingsVaultState['account'];

if (accounts?.[0]) {
const [
{
rewardCount,
rewardEntries,
rewardPerTokenPaid,
rewards,
lastAction,
lastClaim,
},
] = accounts;
account = {
rewardCount,
rewardPerTokenPaid: bigNumberify(rewardPerTokenPaid),
rewards: bigNumberify(rewards),
rewardEntries: rewardEntries.map(({ rate, finish, index, start }) => ({
rate: bigNumberify(rate),
finish,
index,
start,
})),
lastAction,
lastClaim,
};
}

return {
address,
account,
rewardRate: bigNumberify(rewardRate),
rewardPerTokenStored: bigNumberify(rewardPerTokenStored),
stakingContract,
totalSupply: new BigDecimal(totalSupply),
totalStakingRewards: BigDecimal.parse(totalStakingRewards),
};
};

const transformSavingsContractV2 = (
savingsContract: NonNullable<
MassetsQueryResult['data']
>['massets'][number]['savingsContractsV2'][number],
savingsContract: SavingsContractV2QueryResult,
tokens: Tokens,
massetAddress: string,
current: boolean,
Expand All @@ -121,6 +176,7 @@ const transformSavingsContractV2 = (
latestExchangeRate,
totalSavings,
version,
boostedSavingsVaults,
} = savingsContract;

return {
Expand All @@ -139,6 +195,9 @@ const transformSavingsContractV2 = (
token: tokens[id],
totalSavings: BigDecimal.fromMetric(totalSavings),
version: version as 2,
boostedSavingsVault: boostedSavingsVaults[0]
? transformBoostedSavingsVault(boostedSavingsVaults[0])
: undefined,
};
};

Expand Down
25 changes: 25 additions & 0 deletions src/context/DataProvider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,30 @@ export interface MassetState {
};
}

export interface BoostedSavingsVaultAccountState {
lastAction: number;
lastClaim: number;
rewardCount: number;
rewardPerTokenPaid: BigNumber;
rewards: BigNumber;
rewardEntries: {
finish: number;
start: number;
index: number;
rate: BigNumber;
}[];
}

export interface BoostedSavingsVaultState {
address: string;
rewardPerTokenStored: BigNumber;
rewardRate: BigNumber;
stakingContract: string;
totalStakingRewards: BigDecimal;
totalSupply: BigDecimal;
account?: BoostedSavingsVaultAccountState;
}

export type SavingsContractState = {
active: boolean;
current: boolean;
Expand All @@ -73,6 +97,7 @@ export type SavingsContractState = {
| {
version: 2;
token?: SubscribedToken;
boostedSavingsVault?: BoostedSavingsVaultState;
}
);

Expand Down