Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

viem 2 #150

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "op-viem",
"version": "1.1.0",
"version": "1.3.1-alpha",
"type": "module",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down Expand Up @@ -107,7 +107,7 @@
},
"peerDependencies": {
"typescript": ">=5.0.4",
"viem": "1.x"
"viem": "2.0.0-beta.0"
},
"peerDependenciesMeta": {
"typescript": {
Expand Down
72 changes: 57 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/_test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const rollupAnvilChain = {
...base,
id: 8453,
name: 'Rollup Localhost',
network: 'localhost',
nativeCurrency: {
decimals: 18,
name: 'Ether',
Expand Down
75 changes: 66 additions & 9 deletions src/actions/public/L1/simulateDepositERC20.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import type { Chain, PublicClient, SimulateContractParameters, SimulateContractReturnType, Transport } from 'viem'
import type {
Account,
Address,
Chain,
ContractFunctionArgs,
PublicClient,
SimulateContractParameters,
SimulateContractReturnType,
Transport,
} from 'viem'
import { simulateContract } from 'viem/actions'
import { type RawOrContractAddress, resolveAddress } from '../../../types/addresses.js'
import { ABI, type DepositERC20Parameters, FUNCTION } from '../../../types/depositERC20.js'
Expand All @@ -7,15 +16,36 @@ import type { L1SimulateActionBaseType } from '../../../types/l1Actions.js'
export type SimulateDepositERC20Parameters<
TChain extends Chain | undefined = Chain,
TChainOverride extends Chain | undefined = Chain | undefined,
TAccountOverride extends Account | Address | undefined = undefined,
_chainId = TChain extends Chain ? TChain['id'] : number,
> =
& { args: DepositERC20Parameters; l1StandardBridge: RawOrContractAddress<_chainId> }
& L1SimulateActionBaseType<TChain, TChainOverride, typeof ABI, typeof FUNCTION>
& L1SimulateActionBaseType<
typeof ABI,
typeof FUNCTION,
ContractFunctionArgs<typeof ABI, 'nonpayable', typeof FUNCTION>,
TChain,
TChainOverride,
TAccountOverride
>

export type SimulateDepositERC20ReturnType<
TChain extends Chain | undefined,
TChainOverride extends Chain | undefined = undefined,
> = SimulateContractReturnType<typeof ABI, typeof FUNCTION, TChain, TChainOverride>
TChain extends Chain | undefined = Chain | undefined,
TAccount extends Account | undefined = Account | undefined,
TChainOverride extends Chain | undefined = Chain | undefined,
TAccountOverride extends Account | Address | undefined =
| Account
| Address
| undefined,
> = SimulateContractReturnType<
typeof ABI,
typeof FUNCTION,
ContractFunctionArgs<typeof ABI, 'nonpayable', typeof FUNCTION>,
TChain,
TAccount,
TChainOverride,
TAccountOverride
>

/**
* Simulates a deposit of ERC20 tokens to L2
Expand All @@ -24,20 +54,47 @@ export type SimulateDepositERC20ReturnType<
*/
export async function simulateDepositERC20<
TChain extends Chain | undefined,
TChainOverride extends Chain | undefined = undefined,
TAccount extends Account | undefined,
TChainOverride extends Chain | undefined,
TAccountOverride extends Account | Address | undefined = undefined,
>(
client: PublicClient<Transport, TChain>,
{
args: { l1Token, l2Token, to, amount, minGasLimit, extraData = '0x' },
l1StandardBridge,
...rest
}: SimulateDepositERC20Parameters<TChain, TChainOverride>,
): Promise<SimulateContractReturnType<typeof ABI, typeof FUNCTION, TChain, TChainOverride>> {
}: SimulateDepositERC20Parameters<TChain, TChainOverride, TAccountOverride>,
): Promise<
SimulateContractReturnType<
typeof ABI,
typeof FUNCTION,
ContractFunctionArgs<typeof ABI, 'nonpayable', typeof FUNCTION>,
TChain,
TAccount,
TChainOverride,
TAccountOverride
>
> {
return simulateContract(client, {
address: resolveAddress(l1StandardBridge),
abi: ABI,
functionName: FUNCTION,
args: [l1Token, l2Token, to, amount, minGasLimit, extraData],
...rest,
} as unknown as SimulateContractParameters<typeof ABI, typeof FUNCTION, TChain, TChainOverride>)
} as unknown as SimulateContractParameters<
typeof ABI,
typeof FUNCTION,
ContractFunctionArgs<typeof ABI, 'nonpayable', typeof FUNCTION>,
TChain,
TChainOverride,
TAccountOverride
>) as unknown as SimulateContractReturnType<
typeof ABI,
typeof FUNCTION,
ContractFunctionArgs<typeof ABI, 'nonpayable', typeof FUNCTION>,
TChain,
TAccount,
TChainOverride,
TAccountOverride
>
}
Loading