Skip to content

Commit 39f6d6b

Browse files
authored
Merge pull request #41 from lidofinance/fix/create-vault
feat: gas price
2 parents 0007b45 + 59e6a32 commit 39f6d6b

File tree

23 files changed

+225
-245
lines changed

23 files changed

+225
-245
lines changed

config/network/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { getPreConfig } from 'config/get-preconfig';
88
import type { CONTRACT_NAMES, NetworkConfig } from './const';
99

1010
// Main deployments
11+
import mainnetSet from 'networks/mainnet.json' assert { type: 'json' };
1112
import hoodiSet from 'networks/hoodi.json' assert { type: 'json' };
1213
import sepoliaSet from 'networks/sepolia.json' assert { type: 'json' };
1314

@@ -43,6 +44,7 @@ const DEVNETS_MAP = {
4344

4445
// Main deployments
4546
const NETWORKS_MAP = {
47+
[CHAINS.Mainnet]: mainnetSet as NetworkConfig,
4648
[CHAINS.Hoodi]: hoodiSet as NetworkConfig,
4749
[CHAINS.Sepolia]: sepoliaSet as NetworkConfig,
4850
} as Record<string, NetworkConfig>;
Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
import { useFormContext } from 'react-hook-form';
2-
import { useSimulationMint } from 'features/adjustment/mint/hooks';
2+
import { useEstimateMint } from 'features/adjustment/mint/hooks';
33

4-
import { Loader, Text } from '@lidofinance/lido-ui';
5-
import { AmountInfo, InfoRow, Wrapper } from './styles';
4+
import { Wrapper } from './styles';
5+
import { TxCostRow } from 'shared/components/tx-cost-row';
66

77
export const FeatureTxInfo = () => {
88
const { watch } = useFormContext();
99
const [token, amount, recipient] = watch(['token', 'amount', 'recipient']);
10-
const { isLoading, data, isError } = useSimulationMint({
10+
const estimateGasQuery = useEstimateMint({
1111
token,
1212
amount,
1313
recipient,
1414
});
1515

16-
// TODO: add error
1716
return (
1817
<Wrapper>
19-
<InfoRow>
20-
<Text size="xxs" color="secondary">
21-
Transaction cost
22-
</Text>
23-
{isLoading && <Loader size="small" />}
24-
{/*TODO: replace static by real data*/}
25-
{data?.result && !isLoading && <AmountInfo>{data?.result}</AmountInfo>}
26-
{isError && !isLoading && <AmountInfo>Is not available</AmountInfo>}
27-
{!isLoading && !data?.result && !isError && <AmountInfo>-</AmountInfo>}
28-
</InfoRow>
18+
<TxCostRow estimateGasQuery={estimateGasQuery}></TxCostRow>
2919
</Wrapper>
3020
);
3121
};

features/adjustment/mint/form/feature-tx-info/styles.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ export const Wrapper = styled.section`
77
gap: ${({ theme }) => theme.spaceMap.sm}px;
88
`;
99

10-
export const InfoRow = styled.div`
11-
display: flex;
12-
justify-content: space-between;
13-
`;
14-
15-
export const AmountInfo = styled.p`
16-
display: flex;
17-
align-items: center;
18-
gap: ${({ theme }) => theme.spaceMap.xs}px;
19-
color: ${({ theme }) => theme.colors.text};
20-
`;
21-
2210
export const StEthQuestion = styled(Question)`
2311
cursor: pointer;
2412

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

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { useCallback } from 'react';
22
import {
33
useConfig,
4-
useSimulateContract,
54
useWriteContract,
65
usePublicClient,
7-
UseSimulateContractParameters,
6+
useEstimateGas,
7+
useAccount,
88
} from 'wagmi';
9-
import { Address } from 'viem';
9+
import { Address, encodeFunctionData } from 'viem';
1010

1111
import { dashboardAbi } from 'abi/dashboard-abi';
1212
import { useDappStatus } from 'modules/web3/hooks/use-dapp-status';
@@ -16,6 +16,8 @@ import {
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';
20+
import { fallbackedAddress } from 'utils/fallbacked-address';
1921

2022
export const useMint = (onMutate = () => {}) => {
2123
const { chainId } = useDappStatus();
@@ -63,32 +65,39 @@ export const useMint = (onMutate = () => {}) => {
6365
};
6466
};
6567

66-
export interface SimulationMintProps {
68+
export type EstimateGasMintProps = {
6769
recipient: Address;
6870
token: string;
69-
amount: number;
70-
}
71+
amount: bigint;
72+
};
7173

72-
export const useSimulationMint = ({
74+
export const useEstimateMint = ({
7375
recipient,
7476
token,
7577
amount,
76-
}: SimulationMintProps) => {
77-
const payload = [recipient, BigInt(amount ?? 0)];
78+
}: EstimateGasMintProps) => {
79+
const { hasPermission } = useVaultPermissions('minter');
80+
const { address } = useAccount();
81+
const payload = [
82+
fallbackedAddress(recipient || address),
83+
amount ?? 1n,
84+
] as const;
7885
const functionName = token === 'stETH' ? 'mintStETH' : 'mintWstETH';
7986
const { activeVault } = useVaultInfo();
8087
const owner = activeVault?.owner;
81-
const isEnabled = !!(recipient && owner);
8288

83-
const simulationContractPayload: UseSimulateContractParameters = {
84-
abi: dashboardAbi,
85-
address: owner,
86-
functionName,
87-
args: payload,
89+
const enabled = !!(hasPermission && address);
90+
91+
return useEstimateGas({
92+
to: owner,
93+
account: address,
94+
data: encodeFunctionData({
95+
abi: dashboardAbi,
96+
functionName,
97+
args: payload,
98+
}),
8899
query: {
89-
enabled: isEnabled,
100+
enabled,
90101
},
91-
};
92-
93-
return useSimulateContract(simulationContractPayload);
102+
});
94103
};
Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,16 @@
1-
import { AmountInfo, InfoRow, Wrapper } from './styles';
2-
import { Loader, Text } from '@lidofinance/lido-ui';
3-
import { useSimulateContract } from 'wagmi';
4-
import { dashboardAbi } from 'abi/dashboard-abi';
5-
import { useVaultInfo } from 'features/overview/contexts';
1+
import { Wrapper } from './styles';
62
import { useFormContext } from 'react-hook-form';
3+
import { TxCostRow } from 'shared/components/tx-cost-row';
4+
import { useEstimateGasBurn } from '../../hooks';
75

86
export const FeatureTxInfo = () => {
9-
const { activeVault } = useVaultInfo();
107
const { watch } = useFormContext();
118
const [token, amount] = watch(['token', 'amount']);
12-
const owner = activeVault?.owner;
13-
const isEnabled = !!owner && !!amount;
14-
const amountAsArg = amount ? BigInt(amount) : BigInt(0);
15-
const functionName = token === 'stETH' ? 'burnStETH' : 'burnWstETH';
16-
const { isLoading, data, isError } = useSimulateContract({
17-
abi: dashboardAbi,
18-
address: owner,
19-
functionName,
20-
args: [amountAsArg],
21-
query: {
22-
enabled: isEnabled,
23-
},
24-
});
9+
const estimateGasQuery = useEstimateGasBurn({ token, amount });
2510

2611
return (
2712
<Wrapper>
28-
<InfoRow>
29-
<Text size="xxs" color="secondary">
30-
Transaction cost
31-
</Text>
32-
{isLoading && <Loader size="small" />}
33-
{!!data?.result && <AmountInfo>{data?.result}</AmountInfo>}
34-
{isError && !isLoading && <AmountInfo>Is not available</AmountInfo>}
35-
{!isLoading && !data?.result && !isError && <AmountInfo>-</AmountInfo>}
36-
</InfoRow>
13+
<TxCostRow estimateGasQuery={estimateGasQuery} />
3714
</Wrapper>
3815
);
3916
};

features/adjustment/repay/form/feature-tx-info/styles.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ export const Wrapper = styled.section`
77
gap: ${({ theme }) => theme.spaceMap.sm}px;
88
`;
99

10-
export const InfoRow = styled.div`
11-
display: flex;
12-
justify-content: space-between;
13-
`;
14-
15-
export const AmountInfo = styled.p`
16-
display: flex;
17-
align-items: center;
18-
gap: ${({ theme }) => theme.spaceMap.xs}px;
19-
color: ${({ theme }) => theme.colors.text};
20-
`;
21-
2210
export const StEthQuestion = styled(Question)`
2311
cursor: pointer;
2412

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

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import {
44
useWaitForTransactionReceipt,
55
useWriteContract,
66
usePublicClient,
7+
useEstimateGas,
8+
useAccount,
79
} from 'wagmi';
8-
import { Address } from 'viem';
10+
import { Address, encodeFunctionData } from 'viem';
911

1012
import { dashboardAbi } from 'abi/dashboard-abi';
1113
import { useDappStatus } from 'modules/web3/hooks/use-dapp-status';
@@ -15,6 +17,13 @@ import {
1517
SubmitStepEnum,
1618
} from 'shared/components/submit-modal/types';
1719
import invariant from 'tiny-invariant';
20+
import { useVaultPermissions } from 'modules/vaults/hooks/use-vault-permissions';
21+
22+
type BurnArgs = {
23+
token: string;
24+
amount: bigint;
25+
setModalState: (submitStep: { step: SubmitStep; tx?: Address }) => void;
26+
};
1827

1928
export const useBurn = (onMutate = () => {}) => {
2029
const { chainId } = useDappStatus();
@@ -34,15 +43,7 @@ export const useBurn = (onMutate = () => {}) => {
3443
});
3544

3645
const callBurn = useCallback(
37-
async ({
38-
token,
39-
amount,
40-
setModalState,
41-
}: {
42-
token: string;
43-
amount: bigint;
44-
setModalState: (submitStep: { step: SubmitStep; tx?: Address }) => void;
45-
}) => {
46+
async ({ token, amount, setModalState }: BurnArgs) => {
4647
invariant(publicClient, '[useBurn] publicClient is undefined');
4748

4849
setModalState({ step: SubmitStepEnum.confirming });
@@ -70,3 +71,32 @@ export const useBurn = (onMutate = () => {}) => {
7071
burnReceipt,
7172
};
7273
};
74+
75+
type EstimateGasBurnProps = {
76+
token: string;
77+
amount: bigint;
78+
};
79+
80+
export const useEstimateGasBurn = ({ token, amount }: EstimateGasBurnProps) => {
81+
const { hasPermission } = useVaultPermissions('repayer');
82+
const { address } = useAccount();
83+
const payload = [amount ?? 1n] as const;
84+
const functionName = token === 'stETH' ? 'burnStETH' : 'burnWstETH';
85+
const { activeVault } = useVaultInfo();
86+
const owner = activeVault?.owner;
87+
88+
const enabled = !!(hasPermission && address);
89+
90+
return useEstimateGas({
91+
to: owner,
92+
account: address,
93+
data: encodeFunctionData({
94+
abi: dashboardAbi,
95+
functionName,
96+
args: payload,
97+
}),
98+
query: {
99+
enabled,
100+
},
101+
});
102+
};
Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
import { useFormContext } from 'react-hook-form';
2-
3-
import { Loader, Text } from '@lidofinance/lido-ui';
4-
import { AmountInfo, InfoRow, Wrapper } from './styles';
5-
import { useSimulationClaim } from 'features/claim/claim-form/hooks';
2+
import { Wrapper } from './styles';
3+
import { useEstimateClaim } from 'features/claim/claim-form/hooks';
64
import { Address } from 'viem';
5+
import { TxCostRow } from 'shared/components/tx-cost-row';
76

87
export const FeatureTxInfo = () => {
98
const { watch } = useFormContext();
109
const recipient: Address = watch('recipient');
11-
const { data, isLoading, isError } = useSimulationClaim(recipient);
10+
const estimateQuery = useEstimateClaim(recipient);
1211

1312
return (
1413
<Wrapper>
15-
<InfoRow>
16-
<Text size="xxs" color="secondary">
17-
Transaction cost
18-
</Text>
19-
{isLoading && <Loader size="small" />}
20-
{/*TODO: get simulated data*/}
21-
{/*TODO: show error message*/}
22-
{!!data?.result && !isLoading && (
23-
<AmountInfo>{data?.result}</AmountInfo>
24-
)}
25-
{isError && !isLoading && <AmountInfo>-</AmountInfo>}
26-
{!isLoading && !data && !isError && <AmountInfo>-</AmountInfo>}
27-
</InfoRow>
14+
<TxCostRow estimateGasQuery={estimateQuery} />
2815
</Wrapper>
2916
);
3017
};
Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
11
import styled from 'styled-components';
2-
import { Question } from '@lidofinance/lido-ui';
32

43
export const Wrapper = styled.section`
54
display: flex;
65
flex-direction: column;
76
gap: ${({ theme }) => theme.spaceMap.sm}px;
87
`;
9-
10-
export const InfoRow = styled.div`
11-
display: flex;
12-
justify-content: space-between;
13-
`;
14-
15-
export const AmountInfo = styled.p`
16-
display: flex;
17-
align-items: center;
18-
gap: ${({ theme }) => theme.spaceMap.xs}px;
19-
color: ${({ theme }) => theme.colors.text};
20-
`;
21-
22-
export const StEthQuestion = styled(Question)`
23-
cursor: pointer;
24-
25-
&:hover {
26-
fill: var(--lido-color-text);
27-
}
28-
`;

0 commit comments

Comments
 (0)