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

feat: Use preprocessor for native token checks. #8

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
21 changes: 15 additions & 6 deletions build/src/adapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,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, _l;
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
const bridgeContracts = await this.getL1BridgeContracts();
if (transaction.bridgeAddress != null) {
bridgeContracts.erc20 = bridgeContracts.erc20.attach(transaction.bridgeAddress);
Expand Down Expand Up @@ -222,7 +222,9 @@ function AdapterL1(Base) {
(_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));
// now the native token case should send zero in the msg.value
// overrides.value ??= baseCost.add(operatorTip);
overrides.value = 0;
}
return {
contractAddress: to,
Expand All @@ -235,7 +237,16 @@ function AdapterL1(Base) {
};
}
else {
let refundRecipient = (_k = tx.refundRecipient) !== null && _k !== void 0 ? _k : ethers_1.ethers.constants.AddressZero;
let refundRecipient = (_j = tx.refundRecipient) !== null && _j !== void 0 ? _j : ethers_1.ethers.constants.AddressZero;
const cost = baseCost.add(operatorTip);
// overrides.value ??= baseCost.add(operatorTip);
await (0, utils_1.checkBaseCost)(baseCost, cost);
if (!nativeERC20) {
overrides.value = cost;
}
else {
overrides.value = 0;
}
// l2MaxFee needs to be zero if the native token is eth, otherwise should be a good value
const args = [
to,
Expand All @@ -244,10 +255,8 @@ function AdapterL1(Base) {
tx.l2GasLimit,
tx.gasPerPubdataByte,
refundRecipient,
(nativeERC20) ? 999999999999999 : 0 // remove this hardcode
(nativeERC20) ? cost : 0 // remove this hardcode
];
(_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);
Expand Down
19 changes: 14 additions & 5 deletions src/adapters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,9 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
if(token == ETH_ADDRESS) {
overrides.value ??= baseCost.add(operatorTip).add(amount);
} else {
overrides.value ??= baseCost.add(operatorTip);
// now the native token case should send zero in the msg.value
// overrides.value ??= baseCost.add(operatorTip);
overrides.value = 0;
}
return {
contractAddress: to,
Expand All @@ -391,6 +393,16 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
};
} else {
let refundRecipient = tx.refundRecipient ?? ethers.constants.AddressZero;

const cost = baseCost.add(operatorTip);
// overrides.value ??= baseCost.add(operatorTip);
await checkBaseCost(baseCost, cost);
if (!nativeERC20) {
overrides.value = cost;
} else {
overrides.value = 0;
}

// l2MaxFee needs to be zero if the native token is eth, otherwise should be a good value
const args: [Address, Address, BigNumberish, BigNumberish, BigNumberish, Address, BigNumberish] = [
to,
Expand All @@ -399,12 +411,9 @@ export function AdapterL1<TBase extends Constructor<TxSender>>(Base: TBase) {
tx.l2GasLimit,
tx.gasPerPubdataByte,
refundRecipient,
(nativeERC20) ? 999999999999999 : 0 // remove this hardcode
(nativeERC20) ? cost : 0 // remove this hardcode
];

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

let l2WethToken = ethers.constants.AddressZero;
try {
l2WethToken = await bridgeContracts.weth.l2TokenAddress(tx.token);
Expand Down