-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1a5cc7c
commit 370bfca
Showing
1 changed file
with
56 additions
and
0 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,56 @@ | ||
import { | ||
Address, | ||
encodeFunctionData as viemEncodeFunctionData, | ||
EncodeFunctionDataParameters as ViemEncodeFunctionDataParameters, | ||
} from 'viem'; | ||
import { GetFunctionName } from './types/utils'; | ||
import { arbOwner, sequencerInbox } from './contracts'; | ||
import { upgradeExecutorEncodeFunctionData } from './upgradeExecutorEncodeFunctionData'; | ||
|
||
type ABIs = typeof sequencerInbox.abi | typeof arbOwner.abi; | ||
type FunctionName<TAbi extends ABIs> = GetFunctionName<TAbi>; | ||
|
||
type EncodeFunctionDataParameters< | ||
TAbi extends ABIs, | ||
TFunctionName extends FunctionName<TAbi>, | ||
> = ViemEncodeFunctionDataParameters<TAbi, TFunctionName>; | ||
|
||
function encodeFunctionData<TAbi extends ABIs, TFunctionName extends GetFunctionName<TAbi>>({ | ||
abi, | ||
functionName, | ||
args, | ||
}: EncodeFunctionDataParameters<TAbi, TFunctionName>) { | ||
return viemEncodeFunctionData({ | ||
abi, | ||
functionName, | ||
args, | ||
} as unknown as ViemEncodeFunctionDataParameters<TAbi, TFunctionName>); | ||
} | ||
|
||
export function withUpgradeExecutor<TAbi extends ABIs, TFunctionName extends FunctionName<TAbi>>( | ||
params: EncodeFunctionDataParameters<TAbi, TFunctionName> & { | ||
to: Address; | ||
upgradeExecutor: false | Address; | ||
}, | ||
) { | ||
const { upgradeExecutor } = params; | ||
if (!upgradeExecutor) { | ||
return { | ||
to: params.to, | ||
data: encodeFunctionData(params), | ||
value: BigInt(0), | ||
}; | ||
} | ||
|
||
return { | ||
to: upgradeExecutor, | ||
data: upgradeExecutorEncodeFunctionData({ | ||
functionName: 'executeCall', | ||
args: [ | ||
params.to, // target | ||
encodeFunctionData(params), // targetCallData | ||
], | ||
}), | ||
value: BigInt(0), | ||
}; | ||
} |