Skip to content

Commit

Permalink
feat(op-stack): add support for new LegacyGame error (#3360)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
smartcontracts and jxom authored Feb 18, 2025
1 parent 6e3a3ca commit efa2252
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 115 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-penguins-sniff.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"viem": patch
---

**OP Stack:** Added support for `LegacyGame` error.
103 changes: 7 additions & 96 deletions src/op-stack/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down Expand Up @@ -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: [
{
Expand Down Expand Up @@ -1056,7 +1005,7 @@ export const portal2Abi = [
name: 'disputeGameFactory',
outputs: [
{
internalType: 'contract DisputeGameFactory',
internalType: 'contract IDisputeGameFactory',
name: '',
type: 'address',
},
Expand Down Expand Up @@ -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',
},
Expand Down Expand Up @@ -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: [
{
Expand All @@ -1546,7 +1467,7 @@ export const portal2Abi = [
name: 'superchainConfig',
outputs: [
{
internalType: 'contract SuperchainConfig',
internalType: 'contract ISuperchainConfig',
name: '',
type: 'address',
},
Expand All @@ -1559,7 +1480,7 @@ export const portal2Abi = [
name: 'systemConfig',
outputs: [
{
internalType: 'contract SystemConfig',
internalType: 'contract ISystemConfig',
name: '',
type: 'address',
},
Expand Down Expand Up @@ -1791,19 +1712,14 @@ export const portal2Abi = [
},
{
inputs: [],
name: 'NoValue',
name: 'LegacyGame',
type: 'error',
},
{
inputs: [],
name: 'NonReentrant',
type: 'error',
},
{
inputs: [],
name: 'OnlyCustomGasToken',
type: 'error',
},
{
inputs: [],
name: 'OutOfGas',
Expand All @@ -1819,11 +1735,6 @@ export const portal2Abi = [
name: 'SmallGasLimit',
type: 'error',
},
{
inputs: [],
name: 'TransferFailed',
type: 'error',
},
{
inputs: [],
name: 'Unauthorized',
Expand Down
43 changes: 24 additions & 19 deletions src/op-stack/actions/getWithdrawalStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit efa2252

Please sign in to comment.