Skip to content

Commit cab904c

Browse files
committed
Finish warp deployment implementation
1 parent 3e2c42c commit cab904c

16 files changed

+184
-123
lines changed

src/components/icons/ConfirmedIcon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Color } from '../../styles/Color';
66
function _ConfirmedIcon({ color, ...rest }: DefaultIconProps) {
77
return (
88
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 26" {...rest}>
9-
<g clip-path="url(#confirmed-icon-clip-path)">
9+
<g clipPath="url(#confirmed-icon-clip-path)">
1010
<path
1111
d="M1.93105 13.4815C1.93076 11.6219 2.42129 9.79511 3.35333 8.1846C4.28537 6.57409 5.62608 5.23667 7.24067 4.30678C8.85527 3.37689 10.6869 2.8873 12.5513 2.88723C14.4158 2.88716 16.2474 3.3766 17.8621 4.30637C18.0837 4.43205 18.3462 4.46519 18.5923 4.39857C18.8383 4.33194 19.048 4.17096 19.1754 3.95074C19.3029 3.73052 19.3379 3.46895 19.2727 3.22311C19.2076 2.97727 19.0475 2.76712 18.8276 2.63851C16.4348 1.26067 13.653 0.708778 10.9136 1.06842C8.17424 1.42807 5.63041 2.67916 3.67662 4.62766C1.72282 6.57616 0.468253 9.11318 0.107478 11.8453C-0.253297 14.5774 0.299883 17.3519 1.68123 19.7384C3.06257 22.125 5.19488 23.9903 7.74747 25.0451C10.3001 26.0998 13.1303 26.2851 15.7992 25.5721C18.4681 24.8592 20.8266 23.2878 22.5088 21.1018C24.1911 18.9157 25.1031 16.2372 25.1035 13.4815C25.1035 13.2261 25.0017 12.9812 24.8207 12.8006C24.6396 12.62 24.394 12.5185 24.1379 12.5185C23.8819 12.5185 23.6363 12.62 23.4552 12.8006C23.2741 12.9812 23.1724 13.2261 23.1724 13.4815C23.1724 16.2908 22.0535 18.9851 20.0617 20.9716C18.0699 22.9581 15.3685 24.0741 12.5517 24.0741C9.73495 24.0741 7.03354 22.9581 5.04178 20.9716C3.05001 18.9851 1.93105 16.2908 1.93105 13.4815Z"
1212
fill={color || Color.black}

src/components/toast/TxSuccessToast.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { toast } from 'react-toastify';
22
import { useMultiProvider } from '../../features/chains/hooks';
33

4-
export function toastTxSuccess(msg: string, txHash: string, chain: ChainName) {
4+
export function toastTxSuccess(msg: string, txHash: string, chain: ChainName, autoClose = 10_000) {
55
toast.success(<TxSuccessToast msg={msg} txHash={txHash} chain={chain} />, {
6-
autoClose: 12000,
6+
autoClose,
77
});
88
}
99

src/features/deployerWallet/fund.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ async function executeTransfer({
9494
});
9595
const txReceipt = await confirm();
9696
logger.debug(`Deployer funding tx confirmed on ${chainName}, hash: ${hash}`);
97-
toastTxSuccess(`Deployer funded on ${chainName}!`, hash, origin);
97+
toastTxSuccess(`Deployer funded on ${chainName}!`, hash, origin, 5_000);
9898
return txReceipt;
9999
} catch (error: any) {
100100
const errorDetails = error.message || error.toString();

src/features/deployerWallet/refund.ts

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export function useRefundDeployerAccounts(onSettled?: () => void) {
2525
const { wallets } = useDeployerWallets();
2626
const { accounts } = useAccounts(multiProvider);
2727

28-
const { error, mutate, isIdle, isPending } = useMutation({
29-
mutationKey: ['refundDeployerAccounts', chains, wallets, accounts],
28+
const { error, mutate, mutateAsync, isIdle, isPending } = useMutation({
29+
mutationKey: ['refundDeployerAccounts', chains, accounts],
3030
mutationFn: () => refundDeployerAccounts(chains, wallets, multiProvider, accounts),
3131
retry: false,
3232
onSettled,
@@ -39,6 +39,7 @@ export function useRefundDeployerAccounts(onSettled?: () => void) {
3939

4040
return {
4141
refund: mutate,
42+
refundAsync: mutateAsync,
4243
isIdle,
4344
isPending,
4445
};
@@ -63,39 +64,43 @@ async function transferBalances(
6364
multiProvider: MultiProtocolProvider,
6465
accounts: Record<ProtocolType, AccountInfo>,
6566
) {
66-
const txReceipts: Array<PromiseSettledResult<TypedTransactionReceipt>> = await Promise.allSettled(
67-
balances.map(async (balance) => {
68-
const { chainName, protocol, amount: balanceAmount, address: deployerAddress } = balance;
69-
logger.debug('Preparing transfer from deployer', chainName, balanceAmount);
67+
const txReceipts: Array<PromiseSettledResult<TypedTransactionReceipt | undefined>> =
68+
await Promise.allSettled(
69+
balances.map(async (balance) => {
70+
const { chainName, protocol, amount: balanceAmount, address: deployerAddress } = balance;
71+
logger.debug('Preparing transfer from deployer', chainName, balanceAmount);
7072

71-
try {
72-
const chainMetadata = multiProvider.getChainMetadata(chainName);
73-
const token = Token.FromChainMetadataNativeToken(chainMetadata);
74-
const recipient = getAccountAddressForChain(multiProvider, chainName, accounts);
75-
assert(recipient, `No user account found for chain ${chainName}`);
76-
const deployer = wallets[protocol];
77-
assert(deployer, `No deployer wallet found for protocol ${protocol}`);
73+
try {
74+
const chainMetadata = multiProvider.getChainMetadata(chainName);
75+
const token = Token.FromChainMetadataNativeToken(chainMetadata);
76+
const recipient = getAccountAddressForChain(multiProvider, chainName, accounts);
77+
assert(recipient, `No user account found for chain ${chainName}`);
78+
const deployer = wallets[protocol];
79+
assert(deployer, `No deployer wallet found for protocol ${protocol}`);
7880

79-
const estimationTx = await getTransferTx(recipient, balanceAmount, token, multiProvider);
80-
const adjustedAmount = await computeNetTransferAmount(
81-
chainName,
82-
estimationTx,
83-
balanceAmount,
84-
multiProvider,
85-
deployerAddress,
86-
);
87-
const tx = await getTransferTx(recipient, adjustedAmount, token, multiProvider);
81+
const estimationTx = await getTransferTx(recipient, balanceAmount, token, multiProvider);
8882

89-
const txReceipt = await sendTxFromWallet(deployer, tx, chainName, multiProvider);
90-
logger.debug('Transfer tx confirmed on chain', chainName, txReceipt.receipt);
91-
return txReceipt;
92-
} catch (error) {
93-
const msg = `Error refunding balance on chain ${chainName}`;
94-
logger.error(msg, error);
95-
throw new Error(msg, { cause: error });
96-
}
97-
}),
98-
);
83+
const adjustedAmount = await computeNetTransferAmount(
84+
chainName,
85+
estimationTx,
86+
balanceAmount,
87+
multiProvider,
88+
deployerAddress,
89+
);
90+
if (adjustedAmount <= 0n) return undefined;
91+
92+
const tx = await getTransferTx(recipient, adjustedAmount, token, multiProvider);
93+
94+
const txReceipt = await sendTxFromWallet(deployer, tx, chainName, multiProvider);
95+
logger.debug('Transfer tx confirmed on chain', chainName, txReceipt.receipt);
96+
return txReceipt;
97+
} catch (error) {
98+
const msg = `Error refunding balance on chain ${chainName}`;
99+
logger.error(msg, error);
100+
throw new Error(msg, { cause: error });
101+
}
102+
}),
103+
);
99104

100105
const failedTransferChains = balances
101106
.filter((_, i) => txReceipts[i].status === 'rejected')
@@ -106,7 +111,10 @@ async function transferBalances(
106111
`Failed to transfer deployer balances on chains: ${failedTransferChains.join(', ')}`,
107112
);
108113
} else {
109-
return txReceipts.filter((t) => t.status === 'fulfilled').map((r) => r.value);
114+
return txReceipts
115+
.filter((t) => t.status === 'fulfilled')
116+
.map((t) => t.value)
117+
.filter((t): t is TypedTransactionReceipt => !!t);
110118
}
111119
}
112120

@@ -133,7 +141,7 @@ async function computeNetTransferAmount(
133141
logger.debug(`Net amount for transfer on ${chain}`, netAmountBn);
134142
return netAmountBn;
135143
} else {
136-
logger.warn(`Estimated fee is greater than balance on ${chain}`);
144+
logger.debug(`Estimated fee is greater than balance on ${chain}`);
137145
return 0n;
138146
}
139147
}

src/features/deployerWallet/wallets.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function useDeployerWallets() {
1818
const { deployerKeys } = useStore((s) => ({
1919
deployerKeys: s.deployerKeys,
2020
}));
21-
const { error, isLoading, data } = useQuery({
21+
const { error, isLoading, data, refetch } = useQuery({
2222
queryKey: ['getDeployerWallets', deployerKeys],
2323
queryFn: () => getDeployerWallets(deployerKeys),
2424
retry: false,
@@ -28,6 +28,7 @@ export function useDeployerWallets() {
2828
isLoading,
2929
error,
3030
wallets: data || {},
31+
refetch,
3132
};
3233
}
3334

@@ -43,7 +44,7 @@ export function useOrCreateDeployerWallets(
4344
deployerKeys: s.deployerKeys,
4445
setDeployerKey: s.setDeployerKey,
4546
}));
46-
const { error, isLoading, data } = useQuery({
47+
const { error, isLoading, data, refetch } = useQuery({
4748
queryKey: ['getOrCreateDeployerWallets', protocols, deployerKeys, setDeployerKey],
4849
queryFn: () => getOrCreateDeployerWallets(protocols, deployerKeys, setDeployerKey),
4950
retry: false,
@@ -59,6 +60,7 @@ export function useOrCreateDeployerWallets(
5960
isLoading,
6061
error,
6162
wallets: data || {},
63+
refetch,
6264
};
6365
}
6466

@@ -156,10 +158,10 @@ async function decryptDeployerWallet(
156158
}
157159

158160
// TODO multi-protocol support
159-
export function getDeployerWalletKey(wallet: TypedWallet) {
160-
if (wallet.type === ProviderType.EthersV5) {
161-
return wallet.wallet.privateKey;
161+
export function getDeployerWalletKey({ wallet, type }: TypedWallet) {
162+
if (type === ProviderType.EthersV5) {
163+
return wallet.privateKey;
162164
} else {
163-
throw new Error(`Unsupported wallet type for address: ${wallet.type}`);
165+
throw new Error(`Unsupported wallet type: ${type}`);
164166
}
165167
}

src/features/deployment/hooks.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ export function useDeploymentHistory() {
2828
deployments: s.deployments,
2929
addDeployment: s.addDeployment,
3030
updateDeploymentStatus: s.updateDeploymentStatus,
31+
completeDeployment: s.completeDeployment,
3132
}));
3233
return {
3334
...state,
3435
currentIndex: state.deployments.length - 1,
3536
};
3637
}
3738

39+
export function useLatestDeployment() {
40+
const { deployments, currentIndex } = useDeploymentHistory();
41+
return deployments[currentIndex];
42+
}
43+
3844
export function usePastDeploymentChains() {
3945
const multiProvider = useMultiProvider();
4046
const { deployments } = useDeploymentHistory();

src/features/deployment/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export interface WarpDeploymentResult extends ResultBase {
5959

6060
export interface CoreDeploymentResult extends ResultBase {
6161
type: DeploymentType.Core;
62-
config: any; // TODO
62+
result: any; // TODO
6363
}
6464

6565
export type DeploymentResult = WarpDeploymentResult | CoreDeploymentResult;

src/features/deployment/utils.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { tryClipboardSet } from '@hyperlane-xyz/widgets';
22
import { toast } from 'react-toastify';
33
import { stringify } from 'yaml';
4-
import { DeploymentConfig } from './types';
54

6-
export async function tryCopyConfig(deploymentConfig: DeploymentConfig | undefined) {
7-
if (!deploymentConfig) return;
8-
const yamlConfig = stringify(deploymentConfig.config);
5+
export async function tryCopyConfig(config: unknown | undefined) {
6+
if (!config) return;
7+
const yamlConfig = stringify(config);
98
const result = await tryClipboardSet(yamlConfig);
109
if (result) toast.success('Config copied to clipboard');
1110
else toast.error('Unable to set clipboard');

0 commit comments

Comments
 (0)