-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Progress on deployer funding
- Loading branch information
Showing
5 changed files
with
177 additions
and
42 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { MultiProtocolProvider } from '@hyperlane-xyz/sdk'; | ||
import { Numberish } from '@hyperlane-xyz/utils'; | ||
import { useAccounts, useActiveChains, useTransactionFns } from '@hyperlane-xyz/widgets'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { Wallet } from 'ethers'; | ||
import { useMultiProvider } from '../chains/hooks'; | ||
|
||
export function useFundDeployerAccount(deployer: Wallet, chainName: ChainName, amount: Numberish) { | ||
const multiProvider = useMultiProvider(); | ||
const activeAccounts = useAccounts(multiProvider); | ||
const activeChains = useActiveChains(multiProvider); | ||
const transactionFns = useTransactionFns(multiProvider); | ||
|
||
const { isPending, mutateAsync, error } = useMutation({ | ||
mutationKey: ['fundDeployerAccount', deployer.address, chainName, amount], | ||
mutationFn: () => | ||
executeTransfer({ multiProvider, activeAccounts, activeChains, transactionFns }), | ||
}); | ||
|
||
return { | ||
fund: mutateAsync, | ||
isPending, | ||
error, | ||
}; | ||
} | ||
|
||
async function executeTransfer({ | ||
multiProvider, | ||
activeAccounts, | ||
activeChains, | ||
transactionFns, | ||
}: { | ||
multiProvider: MultiProtocolProvider; | ||
activeAccounts: ReturnType<typeof useAccounts>; | ||
activeChains: ReturnType<typeof useActiveChains>; | ||
transactionFns: ReturnType<typeof useTransactionFns>; | ||
}) { | ||
//TODO | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { utils, Wallet } from 'ethers'; | ||
import { config } from '../../consts/config'; | ||
import { logger } from '../../utils/logger'; | ||
import { getTempDeployerWallet, setTempDeployerWallet } from './storage'; | ||
|
||
function createTempDeployerWallet(): Wallet { | ||
logger.info('Creating temp deployer wallet'); | ||
const entropy = utils.randomBytes(32); | ||
const mnemonic = utils.entropyToMnemonic(entropy); | ||
logger.info('Temp deployer wallet created'); | ||
return Wallet.fromMnemonic(mnemonic); | ||
} | ||
|
||
export async function getOrCreateTempDeployerWallet(): Promise<Wallet> { | ||
try { | ||
const existingWallet = await getTempDeployerWallet( | ||
config.tempWalletEncryptionKey, | ||
config.tempWalletEncryptionSalt, | ||
); | ||
if (existingWallet) { | ||
logger.info('Using existing wallet from storage'); | ||
return existingWallet; | ||
} else { | ||
const newWallet = createTempDeployerWallet(); | ||
await setTempDeployerWallet( | ||
newWallet, | ||
config.tempWalletEncryptionKey, | ||
config.tempWalletEncryptionSalt, | ||
); | ||
return newWallet; | ||
} | ||
} catch (error) { | ||
throw new Error('Error preparing temp deployer wallet', { cause: error }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters