diff --git a/build/src/adapters.js b/build/src/adapters.js index e657d2fa1713..35fd3b0783ca 100644 --- a/build/src/adapters.js +++ b/build/src/adapters.js @@ -158,7 +158,7 @@ function AdapterL1(Base) { return (0, utils_1.scaleGasLimit)(baseGasLimit); } async getDepositTx(transaction, nativeERC20) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; const bridgeContracts = await this.getL1BridgeContracts(); if (transaction.bridgeAddress != null) { bridgeContracts.erc20 = bridgeContracts.erc20.attach(transaction.bridgeAddress); @@ -185,7 +185,12 @@ function AdapterL1(Base) { const zksyncContract = await this.getMainContract(); const baseCost = await zksyncContract.l2TransactionBaseCost(await gasPriceForEstimation, tx.l2GasLimit, tx.gasPerPubdataByte); if (token == utils_1.ETH_ADDRESS || nativeERC20 == token) { - (_h = overrides.value) !== null && _h !== void 0 ? _h : (overrides.value = baseCost.add(operatorTip).add(amount)); + if (token == utils_1.ETH_ADDRESS) { + (_h = overrides.value) !== null && _h !== void 0 ? _h : (overrides.value = baseCost.add(operatorTip).add(amount)); + } + else { + (_j = overrides.value) !== null && _j !== void 0 ? _j : (overrides.value = baseCost.add(operatorTip)); + } return { contractAddress: to, calldata: "0x", @@ -197,7 +202,7 @@ function AdapterL1(Base) { }; } else { - let refundRecipient = (_j = tx.refundRecipient) !== null && _j !== void 0 ? _j : ethers_1.ethers.constants.AddressZero; + let refundRecipient = (_k = tx.refundRecipient) !== null && _k !== void 0 ? _k : ethers_1.ethers.constants.AddressZero; const args = [ to, token, @@ -206,7 +211,7 @@ function AdapterL1(Base) { tx.gasPerPubdataByte, refundRecipient, ]; - (_k = overrides.value) !== null && _k !== void 0 ? _k : (overrides.value = baseCost.add(operatorTip)); + (_l = overrides.value) !== null && _l !== void 0 ? _l : (overrides.value = baseCost.add(operatorTip)); await (0, utils_1.checkBaseCost)(baseCost, overrides.value); let l2WethToken = ethers_1.ethers.constants.AddressZero; try { @@ -395,7 +400,7 @@ function AdapterL1(Base) { return this._providerL1().estimateGas(requestExecuteTx); } async getRequestExecuteTx(transaction) { - var _a, _b, _c, _d, _e, _f, _g, _h; + var _a, _b, _c, _d, _e, _f, _g; const zksyncContract = await this.getMainContract(); const { ...tx } = transaction; (_a = tx.l2Value) !== null && _a !== void 0 ? _a : (tx.l2Value = ethers_1.BigNumber.from(0)); @@ -408,13 +413,16 @@ function AdapterL1(Base) { const { contractAddress, l2Value, calldata, l2GasLimit, factoryDeps, operatorTip, overrides, gasPerPubdataByte, refundRecipient, } = tx; await insertGasPrice(this._providerL1(), overrides); const gasPriceForEstimation = overrides.maxFeePerGas || overrides.gasPrice; - const baseCost = await this.getBaseCost({ + // This base cost has to be priced in the ERC20 token because it will be paid on L2. + let baseCost = await this.getBaseCost({ gasPrice: await gasPriceForEstimation, gasPerPubdataByte, gasLimit: l2GasLimit, }); - (_h = overrides.value) !== null && _h !== void 0 ? _h : (overrides.value = baseCost.add(operatorTip).add(l2Value)); - await (0, utils_1.checkBaseCost)(baseCost, overrides.value); + const conversionRate = await this._providerL2().getConversionRate(); + baseCost = baseCost.mul(conversionRate); + overrides.value = 0; + await (0, utils_1.checkBaseCost)(baseCost, l2Value); return await zksyncContract.populateTransaction.requestL2Transaction(contractAddress, l2Value, baseCost.add(operatorTip).add(l2Value), calldata, l2GasLimit, utils_1.REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT, factoryDeps, refundRecipient, overrides); } }; diff --git a/build/src/provider.d.ts b/build/src/provider.d.ts index 7e1efc57b099..86a4789f68f9 100644 --- a/build/src/provider.d.ts +++ b/build/src/provider.d.ts @@ -50,6 +50,7 @@ export declare class Provider extends ethers.providers.JsonRpcProvider { getTransactionDetails(txHash: BytesLike): Promise; getBytecodeByHash(bytecodeHash: BytesLike): Promise; getRawBlockTransactions(number: number): Promise; + getConversionRate(): Promise; getWithdrawTx(transaction: { token: Address; amount: BigNumberish; diff --git a/build/src/provider.js b/build/src/provider.js index 7f662363a61d..cb29036730e0 100644 --- a/build/src/provider.js +++ b/build/src/provider.js @@ -489,6 +489,9 @@ class Provider extends ethers_1.ethers.providers.JsonRpcProvider { async getRawBlockTransactions(number) { return await this.send("zks_getRawBlockTransactions", [number]); } + async getConversionRate() { + return await this.send("zks_getConversionRate", []); + } async getWithdrawTx(transaction) { var _a, _b, _c; var _d; diff --git a/src/adapters.ts b/src/adapters.ts index 75f4f3f28d46..81a9561fe69d 100644 --- a/src/adapters.ts +++ b/src/adapters.ts @@ -336,8 +336,11 @@ export function AdapterL1>(Base: TBase) { ); if (token == ETH_ADDRESS || nativeERC20 == token) { - overrides.value ??= baseCost.add(operatorTip).add(amount); - + if(token == ETH_ADDRESS) { + overrides.value ??= baseCost.add(operatorTip).add(amount); + } else { + overrides.value ??= baseCost.add(operatorTip); + } return { contractAddress: to, calldata: "0x", @@ -724,15 +727,19 @@ export function AdapterL1>(Base: TBase) { await insertGasPrice(this._providerL1(), overrides); const gasPriceForEstimation = overrides.maxFeePerGas || overrides.gasPrice; - const baseCost = await this.getBaseCost({ + // This base cost has to be priced in the ERC20 token because it will be paid on L2. + let baseCost = await this.getBaseCost({ gasPrice: await gasPriceForEstimation, gasPerPubdataByte, gasLimit: l2GasLimit, }); - overrides.value ??= baseCost.add(operatorTip).add(l2Value); + const conversionRate = await this._providerL2().getConversionRate(); + baseCost = baseCost.mul(conversionRate); + + overrides.value = 0; - await checkBaseCost(baseCost, overrides.value); + await checkBaseCost(baseCost, l2Value); return await zksyncContract.populateTransaction.requestL2Transaction( contractAddress, diff --git a/src/provider.ts b/src/provider.ts index beb2c2a4556f..7a270ee78e4f 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -627,6 +627,10 @@ export class Provider extends ethers.providers.JsonRpcProvider { return await this.send("zks_getRawBlockTransactions", [number]); } + async getConversionRate(): Promise { + return await this.send("zks_getConversionRate", []); + } + async getWithdrawTx(transaction: { token: Address; amount: BigNumberish;