diff --git a/src/clients/bridges/ArbitrumAdapter.ts b/src/clients/bridges/ArbitrumAdapter.ts index aa230d5ef..36b8b57b5 100644 --- a/src/clients/bridges/ArbitrumAdapter.ts +++ b/src/clients/bridges/ArbitrumAdapter.ts @@ -195,17 +195,25 @@ export class ArbitrumAdapter extends BaseAdapter { ); } - async wrapEthIfAboveThreshold(threshold: BigNumber, simMode = false): Promise { + // The arbitrum relayer expects to receive ETH steadily per HubPool bundle processed, since it is the L2 refund + // address hardcoded in the Arbitrum Adapter. Therefore, to avoid excessively wrapping ETH, we only wrap + // it once it gets above a certain threshold. + async wrapEthIfAboveThreshold(target: BigNumber, simMode = false): Promise { const { chainId } = this; assert(42161 === chainId, `chainId ${chainId} is not supported`); const weth = CONTRACT_ADDRESSES[this.chainId].weth; const ethBalance = await this.getSigner(chainId).getBalance(); + + // For Arbitrum specifically, ETH should accumulate steadily. So reduce ETH balance down to the target + // if it exceeds a threshold. + // TODO: Add a configurable ETH target as opposed to just a threshold. + const threshold = target.mul(10); if (ethBalance.gt(threshold)) { const l2Signer = this.getSigner(chainId); const contract = new Contract(weth.address, weth.abi, l2Signer); - const value = ethBalance.sub(threshold); - this.logger.debug({ at: this.getName(), message: "Wrapping ETH", threshold, value, ethBalance }); + const value = ethBalance.sub(target); + this.logger.debug({ at: this.getName(), message: "Wrapping ETH", threshold, target, value, ethBalance }); return await this._wrapEthIfAboveThreshold(threshold, contract, value, simMode); } return null; diff --git a/src/clients/bridges/BaseAdapter.ts b/src/clients/bridges/BaseAdapter.ts index 4a2f8867c..d219ac98b 100644 --- a/src/clients/bridges/BaseAdapter.ts +++ b/src/clients/bridges/BaseAdapter.ts @@ -325,9 +325,13 @@ export abstract class BaseAdapter { const { chainId, txnClient } = this; const method = "deposit"; const mrkdwn = - `Ether on chain ${this.chainId} was wrapped due to being over the threshold of ` + + `${createFormatFunction(2, 4, false, 18)(toBN(value).toString())} Ether on chain ${ + this.chainId + } was wrapped due to being over the threshold of ` + `${createFormatFunction(2, 4, false, 18)(toBN(wrapThreshold).toString())} ETH.`; - const message = `Eth wrapped on target chain ${this.chainId}🎁`; + const message = `${createFormatFunction(2, 4, false, 18)(toBN(value).toString())} Eth wrapped on target chain ${ + this.chainId + }🎁`; if (simMode) { const { succeed, reason } = ( await txnClient.simulate([{ contract: l2WEthContract, chainId, method, args: [], value, mrkdwn, message }])