Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into doc/rollup-readme
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmountaintop committed Sep 2, 2023
2 parents 785d421 + 8699a22 commit acf3af9
Show file tree
Hide file tree
Showing 6 changed files with 514 additions and 19 deletions.
2 changes: 1 addition & 1 deletion common/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"runtime/debug"
)

var tag = "v4.2.17"
var tag = "v4.2.18"

var commit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
Expand Down
33 changes: 23 additions & 10 deletions contracts/integration-test/GasSwap.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable node/no-unpublished-import */
/* eslint-disable node/no-missing-import */
import { ethers } from "hardhat";
import { GasSwap, MinimalForwarder, MockERC20, MockGasSwapTarget } from "../typechain";
import { GasSwap, ERC2771Forwarder, MockERC20, MockGasSwapTarget } from "../typechain";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import { expect } from "chai";
import { BigNumber, constants } from "ethers";
Expand All @@ -11,16 +11,16 @@ describe("GasSwap.spec", async () => {
let deployer: SignerWithAddress;
let signer: SignerWithAddress;

let forwarder: MinimalForwarder;
let forwarder: ERC2771Forwarder;
let swap: GasSwap;
let target: MockGasSwapTarget;
let token: MockERC20;

beforeEach(async () => {
[deployer, signer] = await ethers.getSigners();

const MinimalForwarder = await ethers.getContractFactory("MinimalForwarder", deployer);
forwarder = await MinimalForwarder.deploy();
const ERC2771Forwarder = await ethers.getContractFactory("ERC2771Forwarder", deployer);
forwarder = await ERC2771Forwarder.deploy("ERC2771Forwarder");
await forwarder.deployed();

const GasSwap = await ethers.getContractFactory("GasSwap", deployer);
Expand Down Expand Up @@ -253,12 +253,13 @@ describe("GasSwap.spec", async () => {
await swap.updateFeeRatio(ethers.utils.parseEther(feeRatio).div(100));
const fee = amountOut.mul(feeRatio).div(100);

const req = {
const reqWithoutSignature = {
from: signer.address,
to: swap.address,
value: constants.Zero,
gas: 1000000,
nonce: 0,
nonce: await forwarder.nonces(signer.address),
deadline: 2000000000,
data: swap.interface.encodeFunctionData("swap", [
{
token: token.address,
Expand All @@ -278,8 +279,8 @@ describe("GasSwap.spec", async () => {

const signature = await signer._signTypedData(
{
name: "MinimalForwarder",
version: "0.0.1",
name: "ERC2771Forwarder",
version: "1",
chainId: (await ethers.provider.getNetwork()).chainId,
verifyingContract: forwarder.address,
},
Expand All @@ -305,17 +306,29 @@ describe("GasSwap.spec", async () => {
name: "nonce",
type: "uint256",
},
{
name: "deadline",
type: "uint48",
},
{
name: "data",
type: "bytes",
},
],
},
req
reqWithoutSignature
);

const balanceBefore = await signer.getBalance();
await forwarder.execute(req, signature);
await forwarder.execute({
from: reqWithoutSignature.from,
to: reqWithoutSignature.to,
value: reqWithoutSignature.value,
gas: reqWithoutSignature.gas,
deadline: reqWithoutSignature.deadline,
data: reqWithoutSignature.data,
signature,
});
const balanceAfter = await signer.getBalance();
expect(balanceAfter.sub(balanceBefore)).to.eq(amountOut.sub(fee));
expect(await token.balanceOf(signer.address)).to.eq(amountIn.mul(refundRatio).div(100));
Expand Down
21 changes: 13 additions & 8 deletions contracts/src/libraries/FeeVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,34 @@ abstract contract FeeVault is OwnableBase {
receive() external payable {}

/// @notice Triggers a withdrawal of funds to the L1 fee wallet.
function withdraw() external {
uint256 value = address(this).balance;

/// @param _value The amount of ETH to withdraw.
function withdraw(uint256 _value) public {
require(
value >= minWithdrawAmount,
_value >= minWithdrawAmount,
"FeeVault: withdrawal amount must be greater than minimum withdrawal amount"
);

unchecked {
totalProcessed += value;
totalProcessed += _value;
}

emit Withdrawal(value, recipient, msg.sender);
emit Withdrawal(_value, recipient, msg.sender);

// no fee provided
IL2ScrollMessenger(messenger).sendMessage{value: value}(
IL2ScrollMessenger(messenger).sendMessage{value: _value}(
recipient,
value,
_value,
bytes(""), // no message (simple eth transfer)
0 // _gasLimit can be zero for fee vault.
);
}

/// @notice Triggers a withdrawal of all available funds to the L1 fee wallet.
function withdraw() external {
uint256 value = address(this).balance;
withdraw(value);
}

/************************
* Restricted Functions *
************************/
Expand Down
Loading

0 comments on commit acf3af9

Please sign in to comment.