Skip to content

Commit

Permalink
Merge branch 'native_erc20_changes' into use-conversion-rate-and-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fkrause98 committed Jan 15, 2024
2 parents 7b95c34 + 71a910c commit 6bc9681
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 200 deletions.
4 changes: 2 additions & 2 deletions build/src/adapters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export declare function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBa
overrides?: ethers.PayableOverrides;
approveOverrides?: ethers.Overrides;
customBridgeData?: BytesLike;
}): Promise<PriorityOpResponse>;
}, nativeERC20?: Address): Promise<PriorityOpResponse>;
estimateGasDeposit(transaction: {
token: Address;
amount: BigNumberish;
Expand All @@ -64,7 +64,7 @@ export declare function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBa
customBridgeData?: BytesLike;
refundRecipient?: Address;
overrides?: ethers.PayableOverrides;
}): Promise<any>;
}, nativeERC20?: Address): Promise<any>;
getFullRequiredDepositFee(transaction: {
token: Address;
to?: Address;
Expand Down
164 changes: 83 additions & 81 deletions build/src/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,52 +103,48 @@ function AdapterL1(Base) {
(_b = parameters.gasPerPubdataByte) !== null && _b !== void 0 ? _b : (parameters.gasPerPubdataByte = utils_1.REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_LIMIT);
return ethers_1.BigNumber.from(await zksyncContract.l2TransactionBaseCost(parameters.gasPrice, parameters.gasLimit, parameters.gasPerPubdataByte));
}
async deposit(transaction) {
var _a, _b;
var _c;
const depositTx = await this.getDepositTx(transaction);
// if (transaction.token == ETH_ADDRESS) {
const baseGasLimit = await this.estimateGasRequestExecute(depositTx);
const gasLimit = (0, utils_1.scaleGasLimit)(baseGasLimit);
(_a = depositTx.overrides) !== null && _a !== void 0 ? _a : (depositTx.overrides = {});
(_b = (_c = depositTx.overrides).gasLimit) !== null && _b !== void 0 ? _b : (_c.gasLimit = gasLimit);
return this.requestExecute(depositTx);
// } else {
// const bridgeContracts = await this.getL1BridgeContracts();
// if (transaction.approveERC20) {
// let l2WethToken = ethers.constants.AddressZero;
// try {
// l2WethToken = await bridgeContracts.weth.l2TokenAddress(transaction.token);
// } catch (e) {}
// // If the token is Wrapped Ether, use its bridge.
// const proposedBridge =
// l2WethToken != ethers.constants.AddressZero
// ? bridgeContracts.weth.address
// : bridgeContracts.erc20.address;
// const bridgeAddress = transaction.bridgeAddress
// ? transaction.bridgeAddress
// : proposedBridge;
// // We only request the allowance if the current one is not enough.
// const allowance = await this.getAllowanceL1(transaction.token, bridgeAddress);
// if (allowance.lt(transaction.amount)) {
// const approveTx = await this.approveERC20(
// transaction.token,
// transaction.amount,
// {
// bridgeAddress,
// ...transaction.approveOverrides,
// },
// );
// await approveTx.wait();
// }
// }
// const baseGasLimit = await this._providerL1().estimateGas(depositTx);
// const gasLimit = scaleGasLimit(baseGasLimit);
// depositTx.gasLimit ??= gasLimit;
// return await this._providerL2().getPriorityOpResponse(
// await this._signerL1().sendTransaction(depositTx),
// );
// }
async deposit(transaction, nativeERC20) {
var _a, _b, _c;
var _d;
const depositTx = await this.getDepositTx(transaction, nativeERC20);
if (transaction.token == utils_1.ETH_ADDRESS || nativeERC20 == transaction.token) {
console.error("NATIVE ERC20 VERSION");
const baseGasLimit = await this.estimateGasRequestExecute(depositTx);
const gasLimit = (0, utils_1.scaleGasLimit)(baseGasLimit);
(_a = depositTx.overrides) !== null && _a !== void 0 ? _a : (depositTx.overrides = {});
(_b = (_d = depositTx.overrides).gasLimit) !== null && _b !== void 0 ? _b : (_d.gasLimit = gasLimit);
return this.requestExecute(depositTx);
}
else {
const bridgeContracts = await this.getL1BridgeContracts();
if (transaction.approveERC20) {
let l2WethToken = ethers_1.ethers.constants.AddressZero;
try {
l2WethToken = await bridgeContracts.weth.l2TokenAddress(transaction.token);
}
catch (e) { }
// If the token is Wrapped Ether, use its bridge.
const proposedBridge = l2WethToken != ethers_1.ethers.constants.AddressZero
? bridgeContracts.weth.address
: bridgeContracts.erc20.address;
const bridgeAddress = transaction.bridgeAddress
? transaction.bridgeAddress
: proposedBridge;
// We only request the allowance if the current one is not enough.
const allowance = await this.getAllowanceL1(transaction.token, bridgeAddress);
if (allowance.lt(transaction.amount)) {
const approveTx = await this.approveERC20(transaction.token, transaction.amount, {
bridgeAddress,
...transaction.approveOverrides,
});
await approveTx.wait();
}
}
const baseGasLimit = await this._providerL1().estimateGas(depositTx);
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));
}
}
async estimateGasDeposit(transaction) {
const depositTx = await this.getDepositTx(transaction);
Expand All @@ -161,8 +157,8 @@ function AdapterL1(Base) {
}
return (0, utils_1.scaleGasLimit)(baseGasLimit);
}
async getDepositTx(transaction) {
var _a, _b, _c, _d, _e, _f, _g, _h;
async getDepositTx(transaction, nativeERC20) {
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);
Expand All @@ -188,39 +184,45 @@ function AdapterL1(Base) {
const gasPriceForEstimation = overrides.maxFeePerGas || overrides.gasPrice;
const zksyncContract = await this.getMainContract();
const baseCost = await zksyncContract.l2TransactionBaseCost(await gasPriceForEstimation, tx.l2GasLimit, tx.gasPerPubdataByte);
// if (token == ETH_ADDRESS) {
(_h = overrides.value) !== null && _h !== void 0 ? _h : (overrides.value = baseCost.add(operatorTip));
return {
contractAddress: to,
calldata: "0x",
l2Value: amount,
// For some reason typescript can not deduce that we've already set the
// tx.l2GasLimit
l2GasLimit: tx.l2GasLimit,
...tx,
};
// } else {
// let refundRecipient = tx.refundRecipient ?? ethers.constants.AddressZero;
// const args: [Address, Address, BigNumberish, BigNumberish, BigNumberish, Address] = [
// to,
// token,
// amount,
// tx.l2GasLimit,
// tx.gasPerPubdataByte,
// refundRecipient,
// ];
// overrides.value ??= baseCost.add(operatorTip);
// await checkBaseCost(baseCost, overrides.value);
// let l2WethToken = ethers.constants.AddressZero;
// try {
// l2WethToken = await bridgeContracts.weth.l2TokenAddress(tx.token);
// } catch (e) {}
// const bridge =
// l2WethToken != ethers.constants.AddressZero
// ? bridgeContracts.weth
// : bridgeContracts.erc20;
// return await bridge.populateTransaction.deposit(...args, overrides);
// }
if (token == utils_1.ETH_ADDRESS || nativeERC20 == token) {
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",
l2Value: amount,
// For some reason typescript can not deduce that we've already set the
// tx.l2GasLimit
l2GasLimit: tx.l2GasLimit,
...tx,
};
}
else {
let refundRecipient = (_k = tx.refundRecipient) !== null && _k !== void 0 ? _k : ethers_1.ethers.constants.AddressZero;
const args = [
to,
token,
amount,
tx.l2GasLimit,
tx.gasPerPubdataByte,
refundRecipient,
];
(_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 {
l2WethToken = await bridgeContracts.weth.l2TokenAddress(tx.token);
}
catch (e) { }
const bridge = l2WethToken != ethers_1.ethers.constants.AddressZero
? bridgeContracts.weth
: bridgeContracts.erc20;
return await bridge.populateTransaction.deposit(...args, overrides);
}
}
// Retrieves the full needed ETH fee for the deposit.
// Returns the L1 fee and the L2 fee.
Expand Down
8 changes: 4 additions & 4 deletions build/src/signer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ declare const L1Signer_base: {
overrides?: ethers.PayableOverrides;
approveOverrides?: ethers.Overrides;
customBridgeData?: ethers.utils.BytesLike;
}): Promise<import("./types").PriorityOpResponse>;
}, nativeERC20?: string): Promise<import("./types").PriorityOpResponse>;
estimateGasDeposit(transaction: {
token: string;
amount: ethers.BigNumberish;
Expand All @@ -128,7 +128,7 @@ declare const L1Signer_base: {
customBridgeData?: ethers.utils.BytesLike;
refundRecipient?: string;
overrides?: ethers.PayableOverrides;
}): Promise<any>;
}, nativeERC20?: string): Promise<any>;
getFullRequiredDepositFee(transaction: {
token: string;
to?: string;
Expand Down Expand Up @@ -275,7 +275,7 @@ declare const L1VoidSigner_base: {
overrides?: ethers.PayableOverrides;
approveOverrides?: ethers.Overrides;
customBridgeData?: ethers.utils.BytesLike;
}): Promise<import("./types").PriorityOpResponse>;
}, nativeERC20?: string): Promise<import("./types").PriorityOpResponse>;
estimateGasDeposit(transaction: {
token: string;
amount: ethers.BigNumberish;
Expand All @@ -299,7 +299,7 @@ declare const L1VoidSigner_base: {
customBridgeData?: ethers.utils.BytesLike;
refundRecipient?: string;
overrides?: ethers.PayableOverrides;
}): Promise<any>;
}, nativeERC20?: string): Promise<any>;
getFullRequiredDepositFee(transaction: {
token: string;
to?: string;
Expand Down
4 changes: 2 additions & 2 deletions build/src/wallet.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ declare const Wallet_base: {
overrides?: ethers.PayableOverrides;
approveOverrides?: ethers.Overrides;
customBridgeData?: ethers.utils.BytesLike;
}): Promise<import("./types").PriorityOpResponse>;
}, nativeERC20?: string): Promise<import("./types").PriorityOpResponse>;
estimateGasDeposit(transaction: {
token: string;
amount: ethers.BigNumberish;
Expand All @@ -89,7 +89,7 @@ declare const Wallet_base: {
customBridgeData?: ethers.utils.BytesLike;
refundRecipient?: string;
overrides?: ethers.PayableOverrides;
}): Promise<any>;
}, nativeERC20?: string): Promise<any>;
getFullRequiredDepositFee(transaction: {
token: string;
to?: string;
Expand Down
Loading

0 comments on commit 6bc9681

Please sign in to comment.