From efa225262009297481d57f733e7b2c7e0b3a6ff1 Mon Sep 17 00:00:00 2001 From: smartcontracts Date: Tue, 18 Feb 2025 16:42:26 -0600 Subject: [PATCH] feat(op-stack): add support for new LegacyGame error (#3360) * feat(op-stack): add support for new LegacyGame error Adds support for the new LegacyGame error that contracts would start to return if an upcoming proposal is accepted. Note that this change is fully backwards compatible. Also cleans up this section of the code so it's easier to add or remove errors as needed. * Create giant-penguins-sniff.md --------- Co-authored-by: jxom <7336481+jxom@users.noreply.github.com> --- .changeset/giant-penguins-sniff.md | 5 + src/op-stack/abis.ts | 103 ++------------------ src/op-stack/actions/getWithdrawalStatus.ts | 43 ++++---- 3 files changed, 36 insertions(+), 115 deletions(-) create mode 100644 .changeset/giant-penguins-sniff.md diff --git a/.changeset/giant-penguins-sniff.md b/.changeset/giant-penguins-sniff.md new file mode 100644 index 0000000000..9d3da28f59 --- /dev/null +++ b/.changeset/giant-penguins-sniff.md @@ -0,0 +1,5 @@ +--- +"viem": patch +--- + +**OP Stack:** Added support for `LegacyGame` error. diff --git a/src/op-stack/abis.ts b/src/op-stack/abis.ts index 9d4dc02f2c..2a09066ece 100644 --- a/src/op-stack/abis.ts +++ b/src/op-stack/abis.ts @@ -917,19 +917,6 @@ export const portal2Abi = [ stateMutability: 'payable', type: 'receive', }, - { - inputs: [], - name: 'balance', - outputs: [ - { - internalType: 'uint256', - name: '', - type: 'uint256', - }, - ], - stateMutability: 'view', - type: 'function', - }, { inputs: [ { @@ -961,44 +948,6 @@ export const portal2Abi = [ stateMutability: 'view', type: 'function', }, - { - inputs: [ - { - internalType: 'address', - name: '_to', - type: 'address', - }, - { - internalType: 'uint256', - name: '_mint', - type: 'uint256', - }, - { - internalType: 'uint256', - name: '_value', - type: 'uint256', - }, - { - internalType: 'uint64', - name: '_gasLimit', - type: 'uint64', - }, - { - internalType: 'bool', - name: '_isCreation', - type: 'bool', - }, - { - internalType: 'bytes', - name: '_data', - type: 'bytes', - }, - ], - name: 'depositERC20Transaction', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, { inputs: [ { @@ -1056,7 +1005,7 @@ export const portal2Abi = [ name: 'disputeGameFactory', outputs: [ { - internalType: 'contract DisputeGameFactory', + internalType: 'contract IDisputeGameFactory', name: '', type: 'address', }, @@ -1214,17 +1163,17 @@ export const portal2Abi = [ { inputs: [ { - internalType: 'contract DisputeGameFactory', + internalType: 'contract IDisputeGameFactory', name: '_disputeGameFactory', type: 'address', }, { - internalType: 'contract SystemConfig', + internalType: 'contract ISystemConfig', name: '_systemConfig', type: 'address', }, { - internalType: 'contract SuperchainConfig', + internalType: 'contract ISuperchainConfig', name: '_superchainConfig', type: 'address', }, @@ -1500,34 +1449,6 @@ export const portal2Abi = [ stateMutability: 'view', type: 'function', }, - { - inputs: [ - { - internalType: 'address', - name: '_token', - type: 'address', - }, - { - internalType: 'uint8', - name: '_decimals', - type: 'uint8', - }, - { - internalType: 'bytes32', - name: '_name', - type: 'bytes32', - }, - { - internalType: 'bytes32', - name: '_symbol', - type: 'bytes32', - }, - ], - name: 'setGasPayingToken', - outputs: [], - stateMutability: 'nonpayable', - type: 'function', - }, { inputs: [ { @@ -1546,7 +1467,7 @@ export const portal2Abi = [ name: 'superchainConfig', outputs: [ { - internalType: 'contract SuperchainConfig', + internalType: 'contract ISuperchainConfig', name: '', type: 'address', }, @@ -1559,7 +1480,7 @@ export const portal2Abi = [ name: 'systemConfig', outputs: [ { - internalType: 'contract SystemConfig', + internalType: 'contract ISystemConfig', name: '', type: 'address', }, @@ -1791,7 +1712,7 @@ export const portal2Abi = [ }, { inputs: [], - name: 'NoValue', + name: 'LegacyGame', type: 'error', }, { @@ -1799,11 +1720,6 @@ export const portal2Abi = [ name: 'NonReentrant', type: 'error', }, - { - inputs: [], - name: 'OnlyCustomGasToken', - type: 'error', - }, { inputs: [], name: 'OutOfGas', @@ -1819,11 +1735,6 @@ export const portal2Abi = [ name: 'SmallGasLimit', type: 'error', }, - { - inputs: [], - name: 'TransferFailed', - type: 'error', - }, { inputs: [], name: 'Unauthorized', diff --git a/src/op-stack/actions/getWithdrawalStatus.ts b/src/op-stack/actions/getWithdrawalStatus.ts index dbf77c49ba..acf36fa634 100644 --- a/src/op-stack/actions/getWithdrawalStatus.ts +++ b/src/op-stack/actions/getWithdrawalStatus.ts @@ -249,27 +249,32 @@ export async function getWithdrawalStatus< if (checkWithdrawalResult.status === 'rejected') { const error = checkWithdrawalResult.reason as ReadContractErrorType if (error.cause instanceof ContractFunctionRevertedError) { - const errorMessage = error.cause.data?.args?.[0] - if ( - errorMessage === 'OptimismPortal: invalid game type' || - errorMessage === 'OptimismPortal: withdrawal has not been proven yet' || - errorMessage === - 'OptimismPortal: withdrawal has not been proven by proof submitter address yet' || - errorMessage === - 'OptimismPortal: dispute game created before respected game type was updated' - ) - return 'ready-to-prove' - if ( - errorMessage === - 'OptimismPortal: proven withdrawal has not matured yet' || - errorMessage === - 'OptimismPortal: output proposal has not been finalized yet' || - errorMessage === 'OptimismPortal: output proposal in air-gap' - ) - return 'waiting-to-finalize' + // All potential error causes listed here, can either be the error string or the error name + // if custom error types are returned. + const errorCauses = { + 'ready-to-prove': [ + 'OptimismPortal: invalid game type', + 'OptimismPortal: withdrawal has not been proven yet', + 'OptimismPortal: withdrawal has not been proven by proof submitter address yet', + 'OptimismPortal: dispute game created before respected game type was updated', + 'InvalidGameType', + 'LegacyGame', + ], + 'waiting-to-finalize': [ + 'OptimismPortal: proven withdrawal has not matured yet', + 'OptimismPortal: output proposal has not been finalized yet', + 'OptimismPortal: output proposal in air-gap', + ], + } - if (error.cause.data?.errorName === 'InvalidGameType') + // Pick out the error message and/or error name + // Return the status based on the error + const errorMessage = + error.cause.data?.errorName ?? (error.cause.data?.args?.[0] as string) + if (errorCauses['ready-to-prove'].includes(errorMessage)) return 'ready-to-prove' + if (errorCauses['waiting-to-finalize'].includes(errorMessage)) + return 'waiting-to-finalize' } throw checkWithdrawalResult.reason }