Skip to content

Commit

Permalink
Merge pull request #5 from lambdaclass/fix-non-native-tokens
Browse files Browse the repository at this point in the history
Fix non native tokens
  • Loading branch information
jrchatruc authored Feb 14, 2024
2 parents 0b95231 + c8ca851 commit 46f4881
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 23 deletions.
5 changes: 5 additions & 0 deletions abi/IL1Bridge.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@
"internalType": "address",
"name": "_refundRecipient",
"type": "address"
},
{
"internalType": "uint256",
"name": "_l2MaxFee",
"type": "uint256"
}
],
"name": "deposit",
Expand Down
5 changes: 5 additions & 0 deletions build/abi/IL1Bridge.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@
"internalType": "address",
"name": "_refundRecipient",
"type": "address"
},
{
"internalType": "uint256",
"name": "_l2MaxFee",
"type": "uint256"
}
],
"name": "deposit",
Expand Down
7 changes: 5 additions & 2 deletions build/src/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ function AdapterL1(Base) {
var _d;
const depositTx = await this.getDepositTx(transaction, nativeERC20);
if (transaction.token == utils_1.ETH_ADDRESS || nativeERC20 == transaction.token) {
console.log("NATIVE ERC20 VERSION");
// Check allowance only if we are operating with a native ERC20
if (nativeERC20 == transaction.token) {
const bridgeAddress = (await this.getMainContract()).address;
Expand Down Expand Up @@ -154,9 +153,12 @@ function AdapterL1(Base) {
}
}
const baseGasLimit = await this._providerL1().estimateGas(depositTx);
// const baseGasLimit = BigNumber.from(5_000_000);
const gasLimit = (0, utils_1.scaleGasLimit)(baseGasLimit);
(_c = depositTx.gasLimit) !== null && _c !== void 0 ? _c : (depositTx.gasLimit = gasLimit);
return await this._providerL2().getPriorityOpResponse(await this._signerL1().sendTransaction(depositTx));
const txSended = await this._signerL1().sendTransaction(depositTx);
const getPrioOrRes = await this._providerL2().getPriorityOpResponse(txSended);
return getPrioOrRes;
}
}
async estimateGasDeposit(transaction) {
Expand Down Expand Up @@ -223,6 +225,7 @@ function AdapterL1(Base) {
tx.l2GasLimit,
tx.gasPerPubdataByte,
refundRecipient,
999999999999999 // remove this hardcode
];
(_l = overrides.value) !== null && _l !== void 0 ? _l : (overrides.value = baseCost.add(operatorTip));
await (0, utils_1.checkBaseCost)(baseCost, overrides.value);
Expand Down
24 changes: 17 additions & 7 deletions build/typechain/IL1Bridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi";
interface Il1BridgeInterface extends ethers.utils.Interface {
functions: {
"claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])": FunctionFragment;
"deposit(address,address,uint256,uint256,uint256,address)": FunctionFragment;
"deposit(address,address,uint256,uint256,uint256,address,uint256)": FunctionFragment;
"finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])": FunctionFragment;
"isWithdrawalFinalized(uint256,uint256)": FunctionFragment;
"l2Bridge()": FunctionFragment;
Expand All @@ -45,7 +45,7 @@ interface Il1BridgeInterface extends ethers.utils.Interface {
): string;
encodeFunctionData(
functionFragment: "deposit",
values: [string, string, BigNumberish, BigNumberish, BigNumberish, string]
values: [string, string, BigNumberish, BigNumberish, BigNumberish, string, BigNumberish]
): string;
encodeFunctionData(
functionFragment: "finalizeWithdrawal",
Expand Down Expand Up @@ -134,16 +134,18 @@ export class IL1Bridge extends Contract {
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<ContractTransaction>;

"deposit(address,address,uint256,uint256,uint256,address)"(
"deposit(address,address,uint256,uint256,uint256,address,uint256)"(
_l2Receiver: string,
_l1Token: string,
_amount: BigNumberish,
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<ContractTransaction>;

Expand Down Expand Up @@ -233,16 +235,18 @@ export class IL1Bridge extends Contract {
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<ContractTransaction>;

"deposit(address,address,uint256,uint256,uint256,address)"(
"deposit(address,address,uint256,uint256,uint256,address,uint256)"(
_l2Receiver: string,
_l1Token: string,
_amount: BigNumberish,
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<ContractTransaction>;

Expand Down Expand Up @@ -317,16 +321,18 @@ export class IL1Bridge extends Contract {
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: CallOverrides
): Promise<string>;

"deposit(address,address,uint256,uint256,uint256,address)"(
"deposit(address,address,uint256,uint256,uint256,address,uint256)"(
_l2Receiver: string,
_l1Token: string,
_amount: BigNumberish,
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: CallOverrides
): Promise<string>;

Expand Down Expand Up @@ -427,16 +433,18 @@ export class IL1Bridge extends Contract {
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<BigNumber>;

"deposit(address,address,uint256,uint256,uint256,address)"(
"deposit(address,address,uint256,uint256,uint256,address,uint256)"(
_l2Receiver: string,
_l1Token: string,
_amount: BigNumberish,
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<BigNumber>;

Expand Down Expand Up @@ -515,16 +523,18 @@ export class IL1Bridge extends Contract {
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<PopulatedTransaction>;

"deposit(address,address,uint256,uint256,uint256,address)"(
"deposit(address,address,uint256,uint256,uint256,address,uint256)"(
_l2Receiver: string,
_l1Token: string,
_amount: BigNumberish,
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<PopulatedTransaction>;

Expand Down
5 changes: 5 additions & 0 deletions build/typechain/IL1BridgeFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ const _abi = [
name: "_refundRecipient",
type: "address",
},
{
internalType: "uint256",
name: "_l2MaxFee",
type: "uint256",
},
],
name: "deposit",
outputs: [
Expand Down
13 changes: 6 additions & 7 deletions src/adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
): Promise<PriorityOpResponse> {
const depositTx = await this.getDepositTx(transaction, nativeERC20);
if (transaction.token == ETH_ADDRESS || nativeERC20 == transaction.token) {
console.log("NATIVE ERC20 VERSION")
// Check allowance only if we are operating with a native ERC20
if (nativeERC20 == transaction.token) {
const bridgeAddress = (await this.getMainContract()).address;
Expand Down Expand Up @@ -244,15 +243,14 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
await approveTx.wait();
}
}

const baseGasLimit = await this._providerL1().estimateGas(depositTx);
// const baseGasLimit = BigNumber.from(5_000_000);
const gasLimit = scaleGasLimit(baseGasLimit);

depositTx.gasLimit ??= gasLimit;

return await this._providerL2().getPriorityOpResponse(
await this._signerL1().sendTransaction(depositTx),
);
const txSended = await this._signerL1().sendTransaction(depositTx);
const getPrioOrRes = await this._providerL2().getPriorityOpResponse(txSended);
return getPrioOrRes;
}
}

Expand Down Expand Up @@ -365,13 +363,14 @@ 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 args: [Address, Address, BigNumberish, BigNumberish, BigNumberish, Address, BigNumberish] = [
to,
token,
amount,
tx.l2GasLimit,
tx.gasPerPubdataByte,
refundRecipient,
999999999999999 // remove this hardcode
];

overrides.value ??= baseCost.add(operatorTip);
Expand Down
24 changes: 17 additions & 7 deletions typechain/IL1Bridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { FunctionFragment, EventFragment, Result } from "@ethersproject/abi";
interface Il1BridgeInterface extends ethers.utils.Interface {
functions: {
"claimFailedDeposit(address,address,bytes32,uint256,uint256,uint16,bytes32[])": FunctionFragment;
"deposit(address,address,uint256,uint256,uint256,address)": FunctionFragment;
"deposit(address,address,uint256,uint256,uint256,address,uint256)": FunctionFragment;
"finalizeWithdrawal(uint256,uint256,uint16,bytes,bytes32[])": FunctionFragment;
"isWithdrawalFinalized(uint256,uint256)": FunctionFragment;
"l2Bridge()": FunctionFragment;
Expand All @@ -45,7 +45,7 @@ interface Il1BridgeInterface extends ethers.utils.Interface {
): string;
encodeFunctionData(
functionFragment: "deposit",
values: [string, string, BigNumberish, BigNumberish, BigNumberish, string]
values: [string, string, BigNumberish, BigNumberish, BigNumberish, string, BigNumberish]
): string;
encodeFunctionData(
functionFragment: "finalizeWithdrawal",
Expand Down Expand Up @@ -134,16 +134,18 @@ export class IL1Bridge extends Contract {
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<ContractTransaction>;

"deposit(address,address,uint256,uint256,uint256,address)"(
"deposit(address,address,uint256,uint256,uint256,address,uint256)"(
_l2Receiver: string,
_l1Token: string,
_amount: BigNumberish,
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<ContractTransaction>;

Expand Down Expand Up @@ -233,16 +235,18 @@ export class IL1Bridge extends Contract {
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<ContractTransaction>;

"deposit(address,address,uint256,uint256,uint256,address)"(
"deposit(address,address,uint256,uint256,uint256,address,uint256)"(
_l2Receiver: string,
_l1Token: string,
_amount: BigNumberish,
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<ContractTransaction>;

Expand Down Expand Up @@ -317,16 +321,18 @@ export class IL1Bridge extends Contract {
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: CallOverrides
): Promise<string>;

"deposit(address,address,uint256,uint256,uint256,address)"(
"deposit(address,address,uint256,uint256,uint256,address,uint256)"(
_l2Receiver: string,
_l1Token: string,
_amount: BigNumberish,
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: CallOverrides
): Promise<string>;

Expand Down Expand Up @@ -427,16 +433,18 @@ export class IL1Bridge extends Contract {
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<BigNumber>;

"deposit(address,address,uint256,uint256,uint256,address)"(
"deposit(address,address,uint256,uint256,uint256,address,uint256)"(
_l2Receiver: string,
_l1Token: string,
_amount: BigNumberish,
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<BigNumber>;

Expand Down Expand Up @@ -515,16 +523,18 @@ export class IL1Bridge extends Contract {
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<PopulatedTransaction>;

"deposit(address,address,uint256,uint256,uint256,address)"(
"deposit(address,address,uint256,uint256,uint256,address,uint256)"(
_l2Receiver: string,
_l1Token: string,
_amount: BigNumberish,
_l2TxGasLimit: BigNumberish,
_l2TxGasPerPubdataByte: BigNumberish,
_refundRecipient: string,
_l2MaxFee: BigNumberish,
overrides?: PayableOverrides
): Promise<PopulatedTransaction>;

Expand Down
5 changes: 5 additions & 0 deletions typechain/IL1BridgeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ const _abi = [
name: "_refundRecipient",
type: "address",
},
{
internalType: "uint256",
name: "_l2MaxFee",
type: "uint256",
},
],
name: "deposit",
outputs: [
Expand Down

0 comments on commit 46f4881

Please sign in to comment.