Skip to content

Commit 01d9c0d

Browse files
authored
Merge pull request #57 from lidofinance/feature/post-testnet
Post testnet fixes
2 parents 716bd99 + 81055e2 commit 01d9c0d

File tree

54 files changed

+712
-192
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+712
-192
lines changed

config/network/const.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Address } from 'viem';
22

3-
// For future overrides of APIs in devnets
4-
export const API_NAMES = {};
3+
const API_LIST = ['vaultApi'] as const;
54

65
const CONTRACT_LIST = [
76
'lido',
@@ -24,11 +23,16 @@ export const CONTRACTS = Object.fromEntries(
2423
CONTRACT_LIST.map((contract) => [contract, contract]),
2524
) as { [key in (typeof CONTRACT_LIST)[number]]: key };
2625

26+
export const APIS = Object.fromEntries(API_LIST.map((api) => [api, api])) as {
27+
[key in (typeof API_LIST)[number]]: key;
28+
};
29+
2730
export type CONTRACT_NAMES = (typeof CONTRACT_LIST)[number];
31+
export type API_NAMES = (typeof API_LIST)[number];
2832

2933
export type NetworkConfig = {
3034
api: {
31-
[K in keyof typeof API_NAMES]?: string;
35+
[K in keyof typeof APIS]?: string;
3236
};
3337
contracts: {
3438
[K in keyof typeof CONTRACTS]?: Address;

config/network/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Address } from 'viem';
55
import { CHAINS } from '@lidofinance/lido-ethereum-sdk/common';
66

77
import { getPreConfig } from 'config/get-preconfig';
8-
import type { CONTRACT_NAMES, NetworkConfig } from './const';
8+
import type { API_NAMES, CONTRACT_NAMES, NetworkConfig } from './const';
99

1010
// Main deployments
1111
import mainnetSet from 'networks/mainnet.json' assert { type: 'json' };
@@ -71,3 +71,12 @@ export const getContractAddress = (
7171

7272
return networkConfig?.contracts?.[contractName];
7373
};
74+
75+
export const getApiURL = (
76+
chain: CHAINS,
77+
apiName: API_NAMES,
78+
): string | undefined => {
79+
const networkConfig = getNetworkConfig(chain);
80+
81+
return networkConfig?.api?.[apiName];
82+
};

features/adjustment/adjustment-tabs.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useAdjustment } from 'features/adjustment/contexts/adjustment-provider';
2-
import { useVaultInfo } from 'features/overview/contexts';
2+
import { useVaultInfo } from 'modules/vaults';
33

44
import { Switch } from 'shared/components/switch';
55
import { ManifestConfigPageEnum } from 'config/external-config';
Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,52 @@
1-
import { PermissionedSubmitButton } from 'modules/vaults/components';
2-
import { useFormContext } from 'react-hook-form';
1+
import { OracleReportButton } from 'features/report';
2+
import { useVaultInfo, type VAULT_OWNER_ROLES } from 'modules/vaults';
3+
import { MultiplePermissionedSubmitButton } from 'modules/vaults/components';
4+
import { useMemo } from 'react';
5+
import { useFormContext, useWatch } from 'react-hook-form';
6+
7+
const NON_INCREASE_LOCK_ROLES = ['minter'] as VAULT_OWNER_ROLES[];
8+
const INCREASE_LOCK_ROLES = ['minter', 'locker'] as VAULT_OWNER_ROLES[];
39

410
export const SubmitButton = () => {
511
const {
612
formState: { isSubmitting, isValid },
713
} = useFormContext();
14+
15+
const { activeVault } = useVaultInfo();
16+
17+
const [amount, token] = useWatch<{
18+
amount?: bigint;
19+
token: 'stETH' | 'wstETH';
20+
}>({
21+
name: ['amount', 'token'],
22+
});
23+
24+
// TODO: move this check to upper context
25+
const roles: VAULT_OWNER_ROLES[] = useMemo(() => {
26+
if (!activeVault || !amount) return NON_INCREASE_LOCK_ROLES;
27+
const isSteth = token === 'stETH';
28+
const locked = isSteth ? activeVault.locked : activeVault.lockedShares;
29+
const newMinted =
30+
(amount as bigint) +
31+
(isSteth ? activeVault.liabilityStETH : activeVault.liabilityShares);
32+
33+
if (newMinted > locked) {
34+
return INCREASE_LOCK_ROLES;
35+
}
36+
return NON_INCREASE_LOCK_ROLES;
37+
}, [activeVault, amount, token]);
38+
839
const disabled = isSubmitting && !isValid;
940

1041
return (
11-
<PermissionedSubmitButton
12-
dashboardRole="minter"
13-
type="submit"
14-
disabled={disabled}
15-
>
16-
Mint
17-
</PermissionedSubmitButton>
42+
<OracleReportButton action="minting">
43+
<MultiplePermissionedSubmitButton
44+
dashboardRoles={roles}
45+
type="submit"
46+
disabled={disabled}
47+
>
48+
Mint
49+
</MultiplePermissionedSubmitButton>
50+
</OracleReportButton>
1851
);
1952
};

features/adjustment/mint/hooks/use-mint.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import { Address, encodeFunctionData } from 'viem';
1010

1111
import { dashboardAbi } from 'abi/dashboard-abi';
1212
import { useDappStatus } from 'modules/web3/hooks/use-dapp-status';
13-
import { useVaultInfo } from 'features/overview/contexts';
13+
import { useVaultInfo } from 'modules/vaults';
1414
import {
1515
SubmitPayload,
1616
SubmitStepEnum,
1717
} from 'shared/components/submit-modal/types';
1818
import invariant from 'tiny-invariant';
19-
import { useVaultPermissions } from 'modules/vaults/hooks/use-vault-permissions';
19+
import { useVaultPermission } from 'modules/vaults/hooks/use-vault-permissions';
2020
import { fallbackedAddress } from 'utils/fallbacked-address';
2121

2222
export const useMint = (onMutate = () => {}) => {
@@ -76,7 +76,7 @@ export const useEstimateMint = ({
7676
token,
7777
amount,
7878
}: EstimateGasMintProps) => {
79-
const { hasPermission } = useVaultPermissions('minter');
79+
const { hasPermission } = useVaultPermission('minter');
8080
const { address } = useAccount();
8181
const payload = [
8282
fallbackedAddress(recipient || address),

features/adjustment/mint/mint-form-context/mint-form-provider.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { FormProvider, useForm } from 'react-hook-form';
1111
import invariant from 'tiny-invariant';
1212

1313
import { useFormControllerRetry } from 'shared/hook-form/form-controller/use-form-controller-retry-delegate';
14-
import { useVaultInfo } from 'features/overview/contexts';
14+
import { useVaultInfo } from 'modules/vaults';
1515
import { useMint } from 'features/adjustment/mint/hooks';
1616

1717
import {
@@ -31,6 +31,7 @@ import { Address } from 'viem';
3131
type MintDataContextValue = {
3232
mintableStETH: bigint;
3333
mintableWstETH: bigint;
34+
lockedEther: bigint;
3435
};
3536

3637
const MintDataContext = createContext<MintDataContextValue | null>(null);
@@ -66,8 +67,13 @@ export const MintFormProvider: FC<{ children: ReactNode }> = ({ children }) => {
6667
const mintData = useMemo(() => {
6768
const mintableStETH = activeVault?.mintableStETH ?? 0n;
6869
const mintableWstETH = activeVault?.mintableShares ?? 0n;
70+
const lockedEther = activeVault?.locked ?? 0n;
6971

70-
return { mintableStETH, mintableWstETH };
72+
return {
73+
mintableStETH,
74+
mintableWstETH,
75+
lockedEther,
76+
};
7177
}, [activeVault]);
7278

7379
const { retryEvent, retryFire } = useFormControllerRetry();

features/adjustment/repay/form/balance/balance.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Loader } from '@lidofinance/lido-ui';
33
import { formatBalance } from 'utils';
44
import { useFormContext } from 'react-hook-form';
55
import { useRepayFormData } from 'features/adjustment/repay/repay-form-context';
6-
import { useVaultInfo } from 'features/overview/contexts';
6+
import { useVaultInfo } from 'modules/vaults';
77
import { bigIntMin } from 'utils/bigint-math';
88

99
export const Balance = () => {

features/adjustment/repay/form/feature-tx-info/feature-tx-info.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { useEstimateGasBurn } from '../../hooks';
55
import { AllowanceDataTableRow } from 'shared/components/allowance-data-table-row';
66
import { useAllowance } from 'modules/web3';
77
import { useTokenAddress } from 'shared/hooks/use-token-address';
8-
import { useVaultInfo } from 'features/overview/contexts';
8+
import { useVaultInfo } from 'modules/vaults';
99

1010
export const FeatureTxInfo = () => {
1111
const { watch } = useFormContext();

features/adjustment/repay/hooks/use-burn.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import { encodeFunctionData, maxUint256 } from 'viem';
1111

1212
import { dashboardAbi } from 'abi/dashboard-abi';
1313
import { useDappStatus } from 'modules/web3/hooks/use-dapp-status';
14-
import { useVaultInfo } from 'features/overview/contexts';
14+
import { useVaultInfo } from 'modules/vaults';
1515
import {
1616
SubmitPayload,
1717
SubmitStepEnum,
1818
} from 'shared/components/submit-modal/types';
1919
import invariant from 'tiny-invariant';
20-
import { useVaultPermissions } from 'modules/vaults/hooks/use-vault-permissions';
20+
import { useVaultPermission } from 'modules/vaults/hooks/use-vault-permissions';
2121
import { useLidoSDK } from 'modules/web3';
2222

2323
type BurnArgs = {
@@ -55,24 +55,25 @@ export const useBurn = (onMutate = () => {}) => {
5555
to: activeVault.owner,
5656
});
5757
const needsAllowance = allowance < amount;
58-
59-
setModalState({ step: SubmitStepEnum.confirming });
60-
6158
if (needsAllowance) {
62-
const receipt = await tokenContract.approve({
59+
setModalState({ step: SubmitStepEnum.confirming });
60+
61+
const result = await tokenContract.approve({
6362
amount: maxUint256,
6463
to: activeVault.owner,
64+
callback: async (props) => {
65+
if (props.stage === 'receipt') {
66+
setModalState({ step: SubmitStepEnum.submitting });
67+
}
68+
},
6569
});
6670

67-
setModalState({ step: SubmitStepEnum.submitting, tx: receipt.hash });
68-
69-
await publicClient.waitForTransactionReceipt({
70-
hash: receipt.hash,
71-
});
71+
if (result.receipt?.status === 'reverted') {
72+
throw new Error('Transaction was reverted');
73+
}
7274
}
7375

7476
setModalState({ step: SubmitStepEnum.confirming });
75-
7677
const tx = await writeContractAsync({
7778
abi: dashboardAbi,
7879
address: activeVault.owner,
@@ -109,7 +110,7 @@ export const useEstimateGasBurn = ({
109110
amount,
110111
allowance,
111112
}: EstimateGasBurnProps) => {
112-
const { hasPermission } = useVaultPermissions('repayer');
113+
const { hasPermission } = useVaultPermission('repayer');
113114
const { address } = useAccount();
114115
const payload = [amount ?? 1n] as const;
115116
const functionName = token === 'stETH' ? 'burnStETH' : 'burnWstETH';

features/claim/claim-form/claim-form-context/claim-form-provider.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { FormProvider, useForm } from 'react-hook-form';
1313

1414
import { useFormControllerRetry } from 'shared/hook-form/form-controller/use-form-controller-retry-delegate';
1515
import { useClaim } from 'features/claim/claim-form/hooks';
16-
import { useVaultInfo } from 'features/overview/contexts';
16+
import { useVaultInfo } from 'modules/vaults';
1717

1818
import {
1919
FormController,

0 commit comments

Comments
 (0)