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/wagmi: rename supERC20 actions and hooks to superchainERC20 #621

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/khaki-mirrors-learn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@eth-optimism/wagmi": minor
"@eth-optimism/viem": minor
---

rename SupERC20 to SuperchainERC20
1 change: 1 addition & 0 deletions lib/optimism
Submodule optimism added at 43b4e7
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import { parseAbi } from 'viem'
import { erc20Abi, parseAbi } from 'viem'
import { beforeAll, describe, expect, it } from 'vitest'

import { supersimL2B } from '@/chains/supersim.js'
import { publicClientA, testAccount, walletClientA } from '@/test/clients.js'
import { SUPERSIM_SUPERC20_ADDRESS } from '@/test/supERC20.js'
import { createInteropSentL2ToL2Messages } from '@/utils/l2ToL2CrossDomainMessenger.js'

const balanceOfAbi = parseAbi([
'function balanceOf(address account) view returns (uint256)',
])

const AMOUNT_TO_SEND = 10n

describe('sendSupERC20', () => {
describe('sendSuperchainERC20', () => {
beforeAll(async () => {
const hash = await walletClientA.writeContract({
address: SUPERSIM_SUPERC20_ADDRESS,
Expand All @@ -28,12 +24,12 @@ describe('sendSupERC20', () => {
it('should return expected request', async () => {
const startingBalance = await publicClientA.readContract({
address: SUPERSIM_SUPERC20_ADDRESS,
abi: balanceOfAbi,
abi: erc20Abi,
functionName: 'balanceOf',
args: [testAccount.address],
})

const hash = await walletClientA.sendSupERC20({
const hash = await walletClientA.sendSuperchainERC20({
tokenAddress: SUPERSIM_SUPERC20_ADDRESS,
to: testAccount.address,
amount: AMOUNT_TO_SEND,
Expand All @@ -50,7 +46,7 @@ describe('sendSupERC20', () => {

const endingBalance = await publicClientA.readContract({
address: SUPERSIM_SUPERC20_ADDRESS,
abi: balanceOfAbi,
abi: erc20Abi,
functionName: 'balanceOf',
args: [testAccount.address],
})
Expand All @@ -61,7 +57,7 @@ describe('sendSupERC20', () => {

describe('estimate gas', () => {
it('should estimate gas', async () => {
const gas = await publicClientA.estimateSendSupERC20Gas({
const gas = await publicClientA.estimateSendSuperchainERC20Gas({
account: testAccount.address,
tokenAddress: SUPERSIM_SUPERC20_ADDRESS,
to: testAccount.address,
Expand All @@ -76,7 +72,7 @@ describe('sendSupERC20', () => {
describe('simulate', () => {
it('should simulate', async () => {
expect(() =>
publicClientA.simulateSendSupERC20({
publicClientA.simulateSendSuperchainERC20({
account: testAccount.address,
tokenAddress: SUPERSIM_SUPERC20_ADDRESS,
to: testAccount.address,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @module sendSupERC20 */
/** @module sendSuperchainERC20 */
import type {
Account,
Address,
Expand All @@ -24,7 +24,7 @@ import type { ErrorType } from '@/types/utils.js'
/**
* @category Types
*/
export type SendSupERC20Parameters<
export type SendSuperchainERC20Parameters<
TChain extends Chain | undefined = Chain | undefined,
TAccount extends Account | undefined = Account | undefined,
TChainOverride extends Chain | undefined = Chain | undefined,
Expand All @@ -48,12 +48,12 @@ export type SendSupERC20Parameters<
/**
* @category Types
*/
export type SendSupERC20ReturnType = Hash
export type SendSuperchainERC20ReturnType = Hash

/**
* @category Types
*/
export type SendSupERC20ContractReturnType = ContractFunctionReturnType<
export type SendSuperchainERC20ContractReturnType = ContractFunctionReturnType<
typeof superchainTokenBridgeAbi,
'nonpayable',
'sendERC20'
Expand All @@ -62,7 +62,7 @@ export type SendSupERC20ContractReturnType = ContractFunctionReturnType<
/**
* @category Types
*/
export type SendSupERC20ErrorType =
export type SendSuperchainERC20ErrorType =
| EstimateContractGasErrorType
| WriteContractErrorType
| ErrorType
Expand All @@ -71,17 +71,17 @@ export type SendSupERC20ErrorType =
* Sends tokens to a target address on another chain. Used in the interop flow.
* @category L2 Wallet Actions
* @param client - L2 Wallet Client
* @param parameters - {@link SendSupERC20Parameters}
* @returns The sendSupERC20 transaction hash. {@link SendSupERC20ReturnType}
* @param parameters - {@link SendSuperchainERC20Parameters}
* @returns The sendSuperchainERC20 transaction hash. {@link SendSuperchainERC20ReturnType}
*/
export async function sendSupERC20<
export async function sendSuperchainERC20<
chain extends Chain | undefined,
account extends Account | undefined,
chainOverride extends Chain | undefined = undefined,
>(
client: Client<Transport, chain, account>,
parameters: SendSupERC20Parameters<chain, account, chainOverride>,
): Promise<SendSupERC20ReturnType> {
parameters: SendSuperchainERC20Parameters<chain, account, chainOverride>,
): Promise<SendSuperchainERC20ReturnType> {
const { tokenAddress, to, amount, chainId, ...txParameters } = parameters

return baseWriteAction(
Expand All @@ -97,19 +97,19 @@ export async function sendSupERC20<
}

/**
* Estimates gas for {@link sendSupERC20}
* Estimates gas for {@link sendSuperchainERC20}
* @category L2 Wallet Actions
* @param client - L2 Wallet Client
* @param parameters - {@link SendSupERC20Parameters}
* @param parameters - {@link SendSuperchainERC20Parameters}
* @returns The estimated gas value.
*/
export async function estimateSendSupERC20Gas<
export async function estimateSendSuperchainERC20Gas<
TChain extends Chain | undefined,
TAccount extends Account | undefined,
TChainOverride extends Chain | undefined = undefined,
>(
client: Client<Transport, TChain, TAccount>,
parameters: SendSupERC20Parameters<TChain, TAccount, TChainOverride>,
parameters: SendSuperchainERC20Parameters<TChain, TAccount, TChainOverride>,
): Promise<bigint> {
const { tokenAddress, to, amount, chainId, ...txParameters } = parameters

Expand All @@ -123,20 +123,20 @@ export async function estimateSendSupERC20Gas<
}

/**
* Simulate contract call for {@link sendSupERC20}
* Simulate contract call for {@link sendSuperchainERC20}
* @category L2 Public Actions
* @param client - L2 Public Client
* @param parameters - {@link SendSupERC20Parameters}
* @returns The contract functions return value. {@link SendSupERC20ContractReturnType}
* @param parameters - {@link SendSuperchainERC20Parameters}
* @returns The contract functions return value. {@link SendSuperchainERC20ContractReturnType}
*/
export async function simulateSendSupERC20<
export async function simulateSendSuperchainERC20<
TChain extends Chain | undefined,
TAccount extends Account | undefined,
TChainOverride extends Chain | undefined = undefined,
>(
client: Client<Transport, TChain, TAccount>,
parameters: SendSupERC20Parameters<TChain, TAccount, TChainOverride>,
): Promise<SendSupERC20ContractReturnType> {
parameters: SendSuperchainERC20Parameters<TChain, TAccount, TChainOverride>,
): Promise<SendSuperchainERC20ContractReturnType> {
const { account, tokenAddress, to, amount, chainId } = parameters

const res = await simulateContract(client, {
Expand All @@ -148,5 +148,5 @@ export async function simulateSendSupERC20<
args: [tokenAddress, to, amount, BigInt(chainId)],
} as SimulateContractParameters)

return res.result as SendSupERC20ContractReturnType
return res.result as SendSuperchainERC20ContractReturnType
}
10 changes: 3 additions & 7 deletions packages/viem/src/actions/sendSuperchainWETH.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { parseAbi } from 'viem'
import { erc20Abi } from 'viem'
import { beforeAll, describe, expect, it } from 'vitest'

import { supersimL2B } from '@/chains/supersim.js'
import { contracts } from '@/contracts.js'
import { publicClientA, testAccount, walletClientA } from '@/test/clients.js'
import { createInteropSentL2ToL2Messages } from '@/utils/l2ToL2CrossDomainMessenger.js'

const balanceOfAbi = parseAbi([
'function balanceOf(address account) view returns (uint256)',
])

const AMOUNT_TO_SEND = 10n

describe('sendSuperchainWETH', () => {
Expand All @@ -25,7 +21,7 @@ describe('sendSuperchainWETH', () => {
it('should return expected request', async () => {
const startingBalance = await publicClientA.readContract({
address: contracts.superchainWETH.address,
abi: balanceOfAbi,
abi: erc20Abi,
functionName: 'balanceOf',
args: [testAccount.address],
})
Expand All @@ -46,7 +42,7 @@ describe('sendSuperchainWETH', () => {

const endingBalance = await publicClientA.readContract({
address: contracts.superchainWETH.address,
abi: balanceOfAbi,
abi: erc20Abi,
functionName: 'balanceOf',
args: [testAccount.address],
})
Expand Down
28 changes: 14 additions & 14 deletions packages/viem/src/actions/sendSuperchainWETH.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { contracts } from '@/contracts.js'
import type { BaseWriteContractActionParameters } from '@/core/baseWriteAction.js'

import type {
SendSupERC20ContractReturnType,
SendSupERC20ReturnType,
} from './sendSupERC20.js'
SendSuperchainERC20ContractReturnType,
SendSuperchainERC20ReturnType,
} from './sendSuperchainERC20.js'
import {
estimateSendSupERC20Gas,
sendSupERC20,
simulateSendSupERC20,
} from './sendSupERC20.js'
estimateSendSuperchainERC20Gas,
sendSuperchainERC20,
simulateSendSuperchainERC20,
} from './sendSuperchainERC20.js'

/**
* @category Types
Expand Down Expand Up @@ -48,7 +48,7 @@ export type SendSuperchainWETHParameters<
* @category L2 Wallet Actions
* @param client - L2 Wallet Client
* @param parameters - {@link SendSuperchainWETHParameters}
* @returns The sendSuperchainWETH transaction hash. {@link SendSupERC20ReturnType}
* @returns The sendSuperchainWETH transaction hash. {@link SendSuperchainERC20ReturnType}
*/
export async function sendSuperchainWETH<
chain extends Chain | undefined,
Expand All @@ -57,8 +57,8 @@ export async function sendSuperchainWETH<
>(
client: Client<Transport, chain, account>,
parameters: SendSuperchainWETHParameters<chain, account, chainOverride>,
): Promise<SendSupERC20ReturnType> {
return sendSupERC20(client, {
): Promise<SendSuperchainERC20ReturnType> {
return sendSuperchainERC20(client, {
...parameters,
tokenAddress: contracts.superchainWETH.address,
})
Expand All @@ -79,7 +79,7 @@ export async function estimateSendSuperchainWETHGas<
client: Client<Transport, TChain, TAccount>,
parameters: SendSuperchainWETHParameters<TChain, TAccount, TChainOverride>,
): Promise<bigint> {
return estimateSendSupERC20Gas(client, {
return estimateSendSuperchainERC20Gas(client, {
...parameters,
tokenAddress: contracts.superchainWETH.address,
})
Expand All @@ -90,7 +90,7 @@ export async function estimateSendSuperchainWETHGas<
* @category L2 Public Actions
* @param client - L2 Public Client
* @param parameters - {@link SendSuperchainWETHParameters}
* @returns The contract functions return value. {@link SendSupERC20ContractReturnType}
* @returns The contract functions return value. {@link SendSuperchainERC20ContractReturnType}
*/
export async function simulateSendSuperchainWETH<
TChain extends Chain | undefined,
Expand All @@ -99,8 +99,8 @@ export async function simulateSendSuperchainWETH<
>(
client: Client<Transport, TChain, TAccount>,
parameters: SendSuperchainWETHParameters<TChain, TAccount, TChainOverride>,
): Promise<SendSupERC20ContractReturnType> {
return simulateSendSupERC20(client, {
): Promise<SendSuperchainERC20ContractReturnType> {
return simulateSendSuperchainERC20(client, {
...parameters,
tokenAddress: contracts.superchainWETH.address,
})
Expand Down
32 changes: 18 additions & 14 deletions packages/viem/src/decorators/publicL2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ import {
simulateSendL2ToL2Message,
} from '@/actions/sendL2ToL2Message.js'
import type {
SendSupERC20ContractReturnType,
SendSupERC20Parameters,
} from '@/actions/sendSupERC20.js'
SendSuperchainERC20ContractReturnType,
SendSuperchainERC20Parameters,
} from '@/actions/sendSuperchainERC20.js'
import {
estimateSendSupERC20Gas,
simulateSendSupERC20,
} from '@/actions/sendSupERC20.js'
estimateSendSuperchainERC20Gas,
simulateSendSuperchainERC20,
} from '@/actions/sendSuperchainERC20.js'
import type { SendSuperchainWETHParameters } from '@/actions/sendSuperchainWETH.js'
import {
estimateSendSuperchainWETHGas,
Expand Down Expand Up @@ -70,10 +70,10 @@ export type PublicActionsL2<
parameters: RelayL2ToL2MessageParameters<TChain, TAccount, TChainOverride>,
) => Promise<bigint>

estimateSendSupERC20Gas: <
estimateSendSuperchainERC20Gas: <
TChainOverride extends Chain | undefined = undefined,
>(
parameters: SendSupERC20Parameters<TChain, TAccount, TChainOverride>,
parameters: SendSuperchainERC20Parameters<TChain, TAccount, TChainOverride>,
) => Promise<bigint>

estimateDepositSuperchainWETHGas: <
Expand Down Expand Up @@ -120,9 +120,11 @@ export type PublicActionsL2<
parameters: RelayL2ToL2MessageParameters<TChain, TAccount, TChainOverride>,
) => Promise<RelayL2ToL2MessageContractReturnType>

simulateSendSupERC20: <TChainOverride extends Chain | undefined = undefined>(
parameters: SendSupERC20Parameters<TChain, TAccount, TChainOverride>,
) => Promise<SendSupERC20ContractReturnType>
simulateSendSuperchainERC20: <
TChainOverride extends Chain | undefined = undefined,
>(
parameters: SendSuperchainERC20Parameters<TChain, TAccount, TChainOverride>,
) => Promise<SendSuperchainERC20ContractReturnType>

simulateDepositSuperchainWETH: <
TChainOverride extends Chain | undefined = undefined,
Expand Down Expand Up @@ -154,7 +156,7 @@ export type PublicActionsL2<
TChainOverride extends Chain | undefined = undefined,
>(
parameters: SendSuperchainWETHParameters<TChain, TAccount, TChainOverride>,
) => Promise<SendSupERC20ContractReturnType>
) => Promise<SendSuperchainERC20ContractReturnType>
}

export function publicActionsL2() {
Expand All @@ -171,7 +173,8 @@ export function publicActionsL2() {
estimateSendL2ToL2MessageGas(client, args),
estimateRelayL2ToL2MessageGas: (args) =>
estimateRelayL2ToL2MessageGas(client, args),
estimateSendSupERC20Gas: (args) => estimateSendSupERC20Gas(client, args),
estimateSendSuperchainERC20Gas: (args) =>
estimateSendSuperchainERC20Gas(client, args),
estimateSendSuperchainWETHGas: (args) =>
estimateSendSuperchainWETHGas(client, args),
estimateDepositSuperchainWETHGas: (args) =>
Expand All @@ -184,7 +187,8 @@ export function publicActionsL2() {
simulateSendL2ToL2Message(client, args),
simulateRelayL2ToL2Message: (args) =>
simulateRelayL2ToL2Message(client, args),
simulateSendSupERC20: (args) => simulateSendSupERC20(client, args),
simulateSendSuperchainERC20: (args) =>
simulateSendSuperchainERC20(client, args),
simulateDepositSuperchainWETH: (args) =>
simulateDepositSuperchainWETH(client, args),
simulateWithdrawSuperchainWETH: (args) =>
Expand Down
Loading
Loading