-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor proxy check code into helper function
- Loading branch information
1 parent
6b4b00b
commit 3f1b940
Showing
3 changed files
with
83 additions
and
59 deletions.
There are no files selected for viewing
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,55 @@ | ||
import { prompt } from 'gluegun'; | ||
import EthereumABI from '../protocols/ethereum/abi.js'; | ||
import { ContractService } from './contracts.js'; | ||
import { retryWithPrompt } from './retry.js'; | ||
import { withSpinner } from './spinner.js'; | ||
|
||
export interface CheckForProxyResult { | ||
implementationAbi: EthereumABI | null; | ||
implementationAddress: string | null; | ||
} | ||
|
||
export async function checkForProxy( | ||
contractService: ContractService, | ||
network: string, | ||
address: string, | ||
abi: EthereumABI, | ||
): Promise<CheckForProxyResult> { | ||
let implementationAddress = null; | ||
let implementationAbi = null; | ||
|
||
const maybeProxy = abi.callFunctionSignatures()?.includes('upgradeTo(address)'); | ||
if (maybeProxy) { | ||
const impl = await retryWithPrompt(() => | ||
withSpinner( | ||
'Fetching proxy implementation address...', | ||
'Failed to fetch proxy implementation address', | ||
'Warning fetching proxy implementation address', | ||
() => contractService.getProxyImplementation(network, address), | ||
), | ||
); | ||
|
||
if (impl) { | ||
const useImplementation = await prompt | ||
.confirm(`Proxy contract detected. Use implementation contract ABI at ${impl}?`, true) | ||
.catch(() => false); | ||
|
||
if (useImplementation) { | ||
implementationAddress = impl; | ||
implementationAbi = await retryWithPrompt(() => | ||
withSpinner( | ||
'Fetching implementation contract ABI...', | ||
'Failed to fetch implementation ABI', | ||
'Warning fetching implementation ABI', | ||
() => contractService.getABI(EthereumABI, network, implementationAddress!), | ||
), | ||
); | ||
} | ||
} | ||
} | ||
|
||
return { | ||
implementationAbi, | ||
implementationAddress, | ||
}; | ||
} |
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