Skip to content

Commit

Permalink
revert(adapters): make AdapterL1.getFullRequiredDepositFee work wit…
Browse files Browse the repository at this point in the history
…h overrides

This reverts commit 9feb1e1.

BREAKING CHANGE: Remove support from `AdapterL1.getFullRequiredDepositFee` for
considering `overrides.from` as the initiator of the operation. This functionality
was previously used to calculate the full deposit fee for accounts whose private
key is unknown. However, this feature is no longer necessary because
`L1VoidSigner.getFullRequiredDepositFee` is specifically designed to handle such
cases.
  • Loading branch information
danijelTxFusion committed Mar 5, 2024
1 parent 5ee87e8 commit 0ed9389
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 66 deletions.
22 changes: 4 additions & 18 deletions src/adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
tx.gasPerPubdataByte ??= REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT;

let l2GasLimit: bigint;
const bridgeContracts = await this.getL1BridgeContracts();
if (tx.bridgeAddress) {
const bridgeContracts = await this.getL1BridgeContracts();
const customBridgeData =
tx.customBridgeData ??
(await bridgeContracts.weth.getAddress()) === tx.bridgeAddress
Expand Down Expand Up @@ -617,9 +617,7 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
tx.gasPerPubdataByte
);

const selfBalanceETH = tx.overrides.from
? await this._providerL1().getBalance(tx.overrides.from)
: await this.getBalanceL1();
const selfBalanceETH = await this.getBalanceL1();

// We could zero in, because the final fee will anyway be bigger than
if (baseCost >= selfBalanceETH + dummyAmount) {
Expand All @@ -646,20 +644,8 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
amountForEstimate = dummyAmount;
} else {
amountForEstimate = dummyAmount;
let allowance: bigint;
if (tx.overrides.from) {
const erc20contract = IERC20__factory.connect(
tx.token,
this._providerL1()
);
allowance = await erc20contract.allowance(
tx.overrides.from,
await bridgeContracts.erc20.getAddress()
);
} else {
allowance = await this.getAllowanceL1(tx.token);
}
if (allowance < amountForEstimate) {

if ((await this.getAllowanceL1(tx.token)) < amountForEstimate) {
throw new Error('Not enough allowance to cover the deposit!');
}
}
Expand Down
48 changes: 0 additions & 48 deletions tests/integration/wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,54 +722,6 @@ describe('Wallet', () => {
);
}
}).timeout(10_000);

it('should estimate a fee for ETH when `from` is used in overrides', async () => {
const feeData = {
baseCost: 311_192_000_000_000n,
l1GasLimit: 135_759n,
l2GasLimit: '0x97f30',
maxFeePerGas: 1_500_000_010n,
maxPriorityFeePerGas: 1_500_000_000n,
};

const randomWallet = new Wallet(
ethers.Wallet.createRandom().privateKey,
provider,
ethProvider
);
const result = await randomWallet.getFullRequiredDepositFee({
token: utils.ETH_ADDRESS,
to: await wallet.getAddress(),
overrides: {from: ADDRESS},
});
expect(result).to.be.deepEqualExcluding(feeData, ['l1GasLimit']);
}).timeout(10_000);

it('should estimate a fee for DAI when `from` is used in overrides', async () => {
const feeData = {
baseCost: 288_992_000_000_000n,
l1GasLimit: 253_177n,
l2GasLimit: '0x8d1c0',
maxFeePerGas: 1_500_000_010n,
maxPriorityFeePerGas: 1_500_000_000n,
};

const randomWallet = new Wallet(
ethers.Wallet.createRandom().privateKey,
provider,
ethProvider
);

const tx = await wallet.approveERC20(DAI_L1, 5);
await tx.wait();

const result = await randomWallet.getFullRequiredDepositFee({
token: DAI_L1,
to: await wallet.getAddress(),
overrides: {from: ADDRESS},
});
expect(result).to.be.deep.equal(feeData);
}).timeout(10_000);
});

describe('#withdraw()', () => {
Expand Down

0 comments on commit 0ed9389

Please sign in to comment.