Merge pull request #91 from propeller-heads/router/dc/ENG-4251-verify-on-etherscan

feat: Verify contracts on etherscan
This commit is contained in:
dianacarvalho1
2025-02-27 18:03:43 +00:00
committed by GitHub
33 changed files with 81 additions and 233 deletions

View File

@@ -1,9 +1,9 @@
{
"ethereum": {
"uniswap_v2": "0x00C1b81e3C8f6347E69e2DDb90454798A6Be975E",
"uniswap_v3": "0xF744EBfaA580cF3fFc25aD046E92BD8B770a0700",
"uniswap_v4": "0x90BE4620436354c9DfA58614B3Bdd5a80FBfAF31",
"vm:balancer_v2": "0xffe5B139b396c9A3d5d9ab89AAE78bF3070CbD64"
"uniswap_v2": "0xf6c5be66FFf9DC69962d73da0A617a827c382329",
"uniswap_v3": "0xdD8559c917393FC8DD2b4dD289c52Ff445fDE1B0",
"uniswap_v4": "0x042C0ebBEAb9d9987c2f64Ee05f2B3aeB86eAf70",
"vm:balancer_v2": "0x00BE8EfAE40219Ff76287b0F9b9e497942f5BC91"
},
"tenderly_ethereum": {
"uniswap_v2": "0x00C1b81e3C8f6347E69e2DDb90454798A6Be975E",

View File

@@ -1,5 +1,6 @@
/** @type import('hardhat/config').HardhatUserConfig */
require("@tenderly/hardhat-tenderly");
require("@nomicfoundation/hardhat-verify");
require("@nomiclabs/hardhat-ethers");
require("@nomicfoundation/hardhat-foundry");
@@ -40,6 +41,10 @@ module.exports = {
tenderly: {
project: "project",
username: "tvinagre",
privateVerification: true,
privateVerification: false,
},
etherscan: {
apiKey: process.env.ETHERSCAN_API_KEY,
}
};

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
interface ICallback {

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
library LibSwap {

View File

@@ -1,110 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.26;
import {Constants} from "./Constants.sol";
import {ActionConstants} from "@uniswap/v4-periphery/src/libraries/ActionConstants.sol";
import {BipsLibrary} from "@uniswap/v4-periphery/src/libraries/BipsLibrary.sol";
import {PaymentsImmutables} from "./PaymentsImmutables.sol";
import {SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol";
import {ERC20} from "solmate/src/tokens/ERC20.sol";
/// @title Payments contract
/// @notice Performs various operations around the payment of ETH and tokens
abstract contract Payments is PaymentsImmutables {
using SafeTransferLib for ERC20;
using SafeTransferLib for address;
using BipsLibrary for uint256;
error InsufficientToken();
error InsufficientETH();
/// @notice Pays an amount of ETH or ERC20 to a recipient
/// @param token The token to pay (can be ETH using Constants.ETH)
/// @param recipient The address that will receive the payment
/// @param value The amount to pay
function pay(address token, address recipient, uint256 value) internal {
if (token == Constants.ETH) {
recipient.safeTransferETH(value);
} else {
if (value == ActionConstants.CONTRACT_BALANCE) {
value = ERC20(token).balanceOf(address(this));
}
ERC20(token).safeTransfer(recipient, value);
}
}
/// @notice Pays a proportion of the contract's ETH or ERC20 to a recipient
/// @param token The token to pay (can be ETH using Constants.ETH)
/// @param recipient The address that will receive payment
/// @param bips Portion in bips of whole balance of the contract
function payPortion(
address token,
address recipient,
uint256 bips
) internal {
if (token == Constants.ETH) {
uint256 balance = address(this).balance;
uint256 amount = balance.calculatePortion(bips);
recipient.safeTransferETH(amount);
} else {
uint256 balance = ERC20(token).balanceOf(address(this));
uint256 amount = balance.calculatePortion(bips);
ERC20(token).safeTransfer(recipient, amount);
}
}
/// @notice Sweeps all of the contract's ERC20 or ETH to an address
/// @param token The token to sweep (can be ETH using Constants.ETH)
/// @param recipient The address that will receive payment
/// @param amountMinimum The minimum desired amount
function sweep(
address token,
address recipient,
uint256 amountMinimum
) internal {
uint256 balance;
if (token == Constants.ETH) {
balance = address(this).balance;
if (balance < amountMinimum) revert InsufficientETH();
if (balance > 0) recipient.safeTransferETH(balance);
} else {
balance = ERC20(token).balanceOf(address(this));
if (balance < amountMinimum) revert InsufficientToken();
if (balance > 0) ERC20(token).safeTransfer(recipient, balance);
}
}
/// @notice Wraps an amount of ETH into WETH
/// @param recipient The recipient of the WETH
/// @param amount The amount to wrap (can be CONTRACT_BALANCE)
function wrapETH(address recipient, uint256 amount) internal {
if (amount == ActionConstants.CONTRACT_BALANCE) {
amount = address(this).balance;
} else if (amount > address(this).balance) {
revert InsufficientETH();
}
if (amount > 0) {
WETH9.deposit{value: amount}();
if (recipient != address(this)) {
WETH9.transfer(recipient, amount);
}
}
}
/// @notice Unwraps all of the contract's WETH into ETH
/// @param recipient The recipient of the ETH
/// @param amountMinimum The minimum amount of ETH desired
function unwrapWETH9(address recipient, uint256 amountMinimum) internal {
uint256 value = WETH9.balanceOf(address(this));
if (value < amountMinimum) {
revert InsufficientETH();
}
if (value > 0) {
WETH9.withdraw(value);
if (recipient != address(this)) {
recipient.safeTransferETH(value);
}
}
}
}

View File

@@ -1,23 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.26;
import {IWETH9} from "@uniswap/v4-periphery/src/interfaces/external/IWETH9.sol";
import {IPermit2} from "permit2/src/interfaces/IPermit2.sol";
struct PaymentsParameters {
address permit2;
address weth9;
}
contract PaymentsImmutables {
/// @notice WETH9 address
IWETH9 internal immutable WETH9;
/// @notice Permit2 address
IPermit2 internal immutable PERMIT2;
constructor(PaymentsParameters memory params) {
WETH9 = IWETH9(params.weth9);
PERMIT2 = IPermit2(params.permit2);
}
}

View File

@@ -1,57 +0,0 @@
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.26;
import {IAllowanceTransfer} from "permit2/src/interfaces/IAllowanceTransfer.sol";
import {SafeCast160} from "permit2/src/libraries/SafeCast160.sol";
import {Payments} from "./Payments.sol";
/// @title Payments through Permit2
/// @notice Performs interactions with Permit2 to transfer tokens
abstract contract Permit2Payments is Payments {
using SafeCast160 for uint256;
error FromAddressIsNotOwner();
/// @notice Performs a transferFrom on Permit2
/// @param token The token to transfer
/// @param from The address to transfer from
/// @param to The recipient of the transfer
/// @param amount The amount to transfer
function permit2TransferFrom(
address token,
address from,
address to,
uint160 amount
) internal {
PERMIT2.transferFrom(from, to, amount, token);
}
/// @notice Performs a batch transferFrom on Permit2
/// @param batchDetails An array detailing each of the transfers that should occur
/// @param owner The address that should be the owner of all transfers
function permit2TransferFrom(
IAllowanceTransfer.AllowanceTransferDetails[] calldata batchDetails,
address owner
) internal {
uint256 batchLength = batchDetails.length;
for (uint256 i = 0; i < batchLength; ++i) {
if (batchDetails[i].from != owner) revert FromAddressIsNotOwner();
}
PERMIT2.transferFrom(batchDetails);
}
/// @notice Either performs a regular payment or transferFrom on Permit2, depending on the payer address
/// @param token The token to transfer
/// @param payer The address to pay for the transfer
/// @param recipient The recipient of the transfer
/// @param amount The amount to transfer
function payOrPermit2Transfer(
address token,
address payer,
address recipient,
uint256 amount
) internal {
if (payer == address(this)) pay(token, recipient, amount);
else permit2TransferFrom(token, payer, recipient, amount.toUint160());
}
}

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
/**

View File

@@ -11,6 +11,7 @@
"prompt-sync": "^4.2.0"
},
"devDependencies": {
"@nomicfoundation/hardhat-verify": "^2.0.13",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@tenderly/hardhat-tenderly": "^2.5.2",
"dotenv": "^16.4.7",
@@ -1928,9 +1929,9 @@
}
},
"node_modules/@nomicfoundation/hardhat-verify": {
"version": "2.0.12",
"resolved": "https://registry.npmjs.org/@nomicfoundation/hardhat-verify/-/hardhat-verify-2.0.12.tgz",
"integrity": "sha512-Lg3Nu7DCXASQRVI/YysjuAX2z8jwOCbS0w5tz2HalWGSTZThqA0v9N0v0psHbKNqzPJa8bNOeapIVSziyJTnAg==",
"version": "2.0.13",
"resolved": "https://registry.npmjs.org/@nomicfoundation/hardhat-verify/-/hardhat-verify-2.0.13.tgz",
"integrity": "sha512-i57GX1sC0kYGyRVnbQrjjyBTpWTKgrvKC+jH8CMKV6gHp959Upb8lKaZ58WRHIU0espkulTxLnacYeUDirwJ2g==",
"dev": true,
"dependencies": {
"@ethersproject/abi": "^5.1.2",

View File

@@ -1,6 +1,7 @@
{
"name": "hardhat-project",
"devDependencies": {
"@nomicfoundation/hardhat-verify": "^2.0.13",
"@nomiclabs/hardhat-ethers": "^2.2.3",
"@tenderly/hardhat-tenderly": "^2.5.2",
"dotenv": "^16.4.7",

View File

@@ -5,7 +5,7 @@
## Deploy on a Tenderly fork
1. Make a new [fork](https://dashboard.tenderly.co/) in tenderly dashboard for the
1. Make a new [fork](https://dashboard.tenderly.co/) in tenderly dashboard for the
chain that you wish to deploy on.
2. Set the following environment variables:
@@ -25,6 +25,7 @@ export PRIVATE_KEY=<private-key>
export RPC_URL=<chain-rpc-url>
export DEPLOY_WALLET=<wallet-address>
export PRIVATE_KEY=<private-key>
export ETHERSCAN_API_KEY=<etherscan-api-key>
```
Make sure to run `unset HISTFILE` in your terminal before setting the private key. This will prevent the private key

View File

@@ -5,9 +5,9 @@ const hre = require("hardhat");
// Comment out the executors you don't want to deploy
const executors_to_deploy = [
{exchange: "UniswapV2Executor", args: []},
// {exchange: "UniswapV3Executor", args: ["0x1F98431c8aD98523631AE4a59f267346ea31F984"]},
// {exchange: "UniswapV4Executor", args: ["0x000000000004444c5dc75cB358380D2e3dE08A90"]},
// {exchange: "BalancerV2Executor", args: []},
{exchange: "UniswapV3Executor", args: ["0x1F98431c8aD98523631AE4a59f267346ea31F984"]},
{exchange: "UniswapV4Executor", args: ["0x000000000004444c5dc75cB358380D2e3dE08A90"]},
{exchange: "BalancerV2Executor", args: []},
]
async function main() {
@@ -25,6 +25,7 @@ async function main() {
await deployedExecutor.deployed();
console.log(`${exchange} deployed to: ${deployedExecutor.address}`);
// Verify on Tenderly
try {
await hre.tenderly.verify({
name: exchange,
@@ -34,6 +35,19 @@ async function main() {
} catch (error) {
console.error("Error during contract verification:", error);
}
console.log("Waiting for 1 minute before verifying the contract...");
await new Promise(resolve => setTimeout(resolve, 60000));
// Verify on Etherscan
try {
await hre.run("verify:verify", {
address: deployedExecutor.address,
constructorArguments: args,
});
console.log(`${exchange} verified successfully on Etherscan!`);
} catch (error) {
console.error(`Error during Etherscan verification:`, error);
}
}
}

View File

@@ -6,11 +6,11 @@ async function main() {
const network = hre.network.name;
let permit2;
let weth;
if (network === "mainnet" || network === "tenderly_mainnet") {
if (network === "ethereum" || network === "tenderly_ethereum") {
permit2 = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
weth = "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2";
} else if (network === "base" || network === "tenderly_base") {
// permit2 address is the same as on mainnet
// permit2 address is the same as on ethereum
permit2 = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
weth = "0x4200000000000000000000000000000000000006";
} else {
@@ -31,6 +31,7 @@ async function main() {
await router.deployed();
console.log(`TychoRouter deployed to: ${router.address}`);
// Verify on Tenderly
try {
console.log("Verifying contract on Tenderly...");
await hre.tenderly.verify({
@@ -41,6 +42,21 @@ async function main() {
} catch (error) {
console.error("Error during contract verification:", error);
}
console.log("Waiting for 1 minute before verifying the contract...");
await new Promise(resolve => setTimeout(resolve, 60000));
// Verify on Etherscan
try {
await hre.run("verify:verify", {
address: router.address,
constructorArguments: [permit2, weth],
});
console.log(`TychoRouter verified successfully on Etherscan!`);
} catch (error) {
console.error(`Error during Etherscan verification:`, error);
}
}
main()

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@interfaces/IExecutor.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "../lib/IWETH.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@interfaces/IExecutor.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@interfaces/IExecutor.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@interfaces/IExecutor.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@interfaces/IExecutor.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "forge-std/Test.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@src/Dispatcher.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import {Test} from "forge-std/Test.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "forge-std/Test.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@src/executors/UniswapV4Executor.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "../src/executors/UniswapV2Executor.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@src/executors/BalancerV2Executor.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@src/executors/UniswapV2Executor.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@src/executors/UniswapV3Executor.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "../../src/executors/UniswapV4Executor.sol";

View File

@@ -1,4 +1,4 @@
// SPDX-License-Identifier: UNLICENSED
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.26;
import "@src/executors/UniswapV4Executor.sol";

View File

@@ -400,7 +400,7 @@ mod tests {
let hex_protocol_data = encode(&protocol_data);
assert_eq!(
executor_address,
Bytes::from_str("0x00C1b81e3C8f6347E69e2DDb90454798A6Be975E").unwrap()
Bytes::from_str("0xf6c5be66FFf9DC69962d73da0A617a827c382329").unwrap()
);
assert_eq!(
hex_protocol_data,
@@ -525,7 +525,7 @@ mod tests {
let hex_protocol_data = encode(&protocol_data);
assert_eq!(
executor_address,
Bytes::from_str("0x90BE4620436354c9DfA58614B3Bdd5a80FBfAF31").unwrap()
Bytes::from_str("0x042C0ebBEAb9d9987c2f64Ee05f2B3aeB86eAf70").unwrap()
);
assert_eq!(
hex_protocol_data,
@@ -537,7 +537,7 @@ mod tests {
// zero for one
"00",
// executor address
"90be4620436354c9dfa58614b3bdd5a80fbfaf31",
"042c0ebbeab9d9987c2f64ee05f2b3aeb86eaf70",
// first pool intermediary token (ETH)
"0000000000000000000000000000000000000000",
// fee
@@ -669,7 +669,7 @@ mod tests {
"01", // token out index
"000000", // split
// Swap data
"00c1b81e3c8f6347e69e2ddb90454798a6be975e", // executor address
"f6c5be66fff9dc69962d73da0a617a827c382329", // executor address
"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // token in
"a478c2975ab1ea89e8196811f51a7b7ade33eb11", // component id
"3ede3eca2a72b3aecc820e955b36f38437d01395", // receiver
@@ -990,12 +990,12 @@ mod tests {
"01", // token out index
"000000", // split
// Swap data header
"90be4620436354c9dfa58614b3bdd5a80fbfaf31", // executor address
"042c0ebbeab9d9987c2f64ee05f2b3aeb86eaf70", // executor address
// Protocol data
"a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // group token in
"6982508145454ce325ddbe47a25d4ec3d2311933", // group token in
"00", // zero2one
"90be4620436354c9dfa58614b3bdd5a80fbfaf31", // executor address
"042c0ebbeab9d9987c2f64ee05f2b3aeb86eaf70", // executor address
// First pool params
"0000000000000000000000000000000000000000", // intermediary token (ETH)
"000bb8", // fee
@@ -1076,7 +1076,7 @@ mod tests {
"01", // token out index
"000000", // split
// Swap data
"00c1b81e3c8f6347e69e2ddb90454798a6be975e", // executor address
"f6c5be66fff9dc69962d73da0a617a827c382329", // executor address
"c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // token in
"a478c2975ab1ea89e8196811f51a7b7ade33eb11", // component id
"3ede3eca2a72b3aecc820e955b36f38437d01395", // receiver