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

Problem: zksync-web3.js does not support custom gas token #26

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: add support for custom gas token
XinyuCRO committed Jul 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 8b8525f12f5259cd31237b05b1d375a892636eea
37 changes: 22 additions & 15 deletions sdk/zksync-web3.js/src/adapters.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigNumber, BigNumberish, BytesLike, ethers } from 'ethers';
import { IERC20MetadataFactory, IL1BridgeFactory, IL2BridgeFactory, IZkSyncFactory } from '../typechain';
import { IERC20MetadataFactory, IL1Bridge, IL1BridgeFactory, IL2BridgeFactory, IZkSyncFactory } from '../typechain';
import { Provider } from './provider';
import {
Address,
@@ -177,7 +177,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {

return this.requestExecute(depositTx);
} else {
const bridgeContracts = await this.getL1BridgeContracts();
const bridgeContracts = await this.getL1BridgeContracts();
if (transaction.approveERC20) {
const l2WethToken = await bridgeContracts.weth.l2TokenAddress(transaction.token);
// If the token is Wrapped Ether, use its bridge.
@@ -299,9 +299,8 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
);

if (token == ETH_ADDRESS) {
overrides.value ??= baseCost.add(operatorTip).add(amount);

return {
l1Value: baseCost.add(operatorTip).add(amount),
contractAddress: to,
calldata: '0x',
l2Value: amount,
@@ -312,17 +311,18 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
};
} else {
let refundRecipient = tx.refundRecipient ?? ethers.constants.AddressZero;
const args: [Address, Address, BigNumberish, BigNumberish, BigNumberish, Address] = [
const cost = baseCost.add(operatorTip);
const args: [Address, Address, BigNumberish, BigNumberish, BigNumberish, Address, BigNumberish] = [
to,
token,
amount,
tx.l2GasLimit,
tx.gasPerPubdataByte,
refundRecipient
refundRecipient,
cost
];

overrides.value ??= baseCost.add(operatorTip);
await checkBaseCost(baseCost, overrides.value);
await checkBaseCost(baseCost, cost);

const l2WethToken = await bridgeContracts.weth.l2TokenAddress(tx.token);
const bridge =
@@ -600,6 +600,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
}

async requestExecute(transaction: {
l1Value: BigNumberish;
contractAddress: Address;
calldata: BytesLike;
l2GasLimit?: BigNumberish;
@@ -615,6 +616,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
}

async estimateGasRequestExecute(transaction: {
l1Value?: BigNumberish;
contractAddress: Address;
calldata: BytesLike;
l2GasLimit?: BigNumberish;
@@ -635,6 +637,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
}

async getRequestExecuteTx(transaction: {
l1Value?: BigNumberish;
contractAddress: Address;
calldata: BytesLike;
l2GasLimit?: BigNumberish;
@@ -648,6 +651,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
const zksyncContract = await this.getMainContract();

const { ...tx } = transaction;
tx.l1Value ??= BigNumber.from(0);
tx.l2Value ??= BigNumber.from(0);
tx.operatorTip ??= BigNumber.from(0);
tx.factoryDeps ??= [];
@@ -658,6 +662,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {

const {
contractAddress,
l1Value,
l2Value,
calldata,
l2GasLimit,
@@ -677,16 +682,18 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
gasLimit: l2GasLimit
});

overrides.value ??= baseCost.add(operatorTip).add(l2Value);

await checkBaseCost(baseCost, overrides.value);
await checkBaseCost(baseCost, l1Value);

return await zksyncContract.populateTransaction.requestL2Transaction(
contractAddress,
l2Value,
l1Value,
{
l2Contract: contractAddress,
l2Value,
gasAmount: baseCost.add(operatorTip),
l2GasLimit,
l2GasPerPubdataByteLimit: REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT
},
calldata,
l2GasLimit,
REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT,
factoryDeps,
refundRecipient,
overrides