Skip to content

base deployments #82

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
7 changes: 7 additions & 0 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ const ARBITRUM_RPC = getEnvValSafe('ARBITRUM_RPC')
const OPTIMISM_RPC = getEnvValSafe('OPTIMISM_RPC')
const AURORA_RPC = getEnvValSafe('AURORA_RPC')
const DOGECHAIN_RPC = getEnvValSafe('DOGECHAIN_RPC')
const BASE_RPC = getEnvValSafe('BASE_RPC')
const AVALANCHE_PK_DEPLOYER = getEnvValSafe('AVALANCHE_PK_DEPLOYER')
const ARBITRUM_PK_DEPLOYER = getEnvValSafe('ARBITRUM_PK_DEPLOYER')
const OPTIMISM_PK_DEPLOYER = getEnvValSafe('OPTIMISM_PK_DEPLOYER')
const AURORA_PK_DEPLOYER = getEnvValSafe('AURORA_PK_DEPLOYER')
const DOGECHAIN_PK_DEPLOYER = getEnvValSafe('DOGECHAIN_PK_DEPLOYER')
const BASE_PK_DEPLOYER = getEnvValSafe('BASE_PK_DEPLOYER')
const ETHERSCAN_API_KEY = getEnvValSafe('ETHERSCAN_API_KEY', false)

function getEnvValSafe(key, required=true) {
Expand Down Expand Up @@ -104,6 +106,11 @@ module.exports = {
url: DOGECHAIN_RPC,
accounts: [ DOGECHAIN_PK_DEPLOYER ],
},
base: {
chainId: 8453,
url: BASE_RPC,
accounts: [ BASE_PK_DEPLOYER ],
},
},
paths: {
deployments: './src/deployments',
Expand Down
8 changes: 5 additions & 3 deletions src/contracts/adapters/UniswapV2Adapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,19 @@ import "../YakAdapter.sol";
contract UniswapV2Adapter is YakAdapter {
using SafeERC20 for IERC20;

uint256 internal constant FEE_DENOMINATOR = 1e3;
uint256 public immutable feeDenominator;
uint256 public immutable feeCompliment;
address public immutable factory;

constructor(
string memory _name,
address _factory,
uint256 _fee,
uint256 _feeDenominator,
uint256 _swapGasEstimate
) YakAdapter(_name, _swapGasEstimate) {
feeCompliment = FEE_DENOMINATOR - _fee;
feeDenominator = _feeDenominator;
feeCompliment = _feeDenominator - _fee;
factory = _factory;
}

Expand All @@ -49,7 +51,7 @@ contract UniswapV2Adapter is YakAdapter {
// Based on https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/UniswapV2Router02.sol
uint256 amountInWithFee = _amountIn * feeCompliment;
uint256 numerator = amountInWithFee * _reserveOut;
uint256 denominator = _reserveIn * FEE_DENOMINATOR + amountInWithFee;
uint256 denominator = _reserveIn * feeDenominator + amountInWithFee;
amountOut = numerator / denominator;
}

Expand Down
137 changes: 137 additions & 0 deletions src/contracts/adapters/VelodromeV2Adapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// ╟╗ ╔╬
// ╞╬╬ ╬╠╬
// ╔╣╬╬╬ ╠╠╠╠╦
// ╬╬╬╬╬╩ ╘╠╠╠╠╬
// ║╬╬╬╬╬ ╘╠╠╠╠╬
// ╣╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ╒╬╬╬╬╬╬╬╜ ╠╠╬╬╬╬╬╬╬ ╠╬╬╬╬╬╬╬ ╬╬╬╬╬╬╬╬╠╠╠╠╠╠╠╠
// ╙╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╕ ╬╬╬╬╬╬╬╜ ╣╠╠╬╬╬╬╬╬╬╬ ╠╬╬╬╬╬╬╬ ╬╬╬╬╬╬╬╬╬╠╠╠╠╠╠╠╩
// ╙╣╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ╔╬╬╬╬╬╬╬ ╔╠╠╠╬╬╬╬╬╬╬╬ ╠╬╬╬╬╬╬╬ ╣╬╬╬╬╬╬╬╬╬╬╬╠╠╠╠╝╙
// ╘╣╬╬╬╬╬╬╬╬╬╬╬╬╬╬ ╒╠╠╠╬╠╬╩╬╬╬╬╬╬ ╠╬╬╬╬╬╬╬╣╬╬╬╬╬╬╬╙
// ╣╬╬╬╬╬╬╬╬╬╬╠╣ ╣╬╠╠╠╬╩ ╚╬╬╬╬╬╬ ╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬
// ╣╬╬╬╬╬╬╬╬╬╣ ╣╬╠╠╠╬╬ ╣╬╬╬╬╬╬ ╠╬╬╬╬╬╬╬╬╬╬╬╬╬╬
// ╟╬╬╬╬╬╬╬╩ ╬╬╠╠╠╠╬╬╬╬╬╬╬╬╬╬╬ ╠╬╬╬╬╬╬╬╠╬╬╬╬╬╬╬
// ╬╬╬╬╬╬╬ ╒╬╬╠╠╬╠╠╬╬╬╬╬╬╬╬╬╬╬╬ ╠╬╬╬╬╬╬╬ ╣╬╬╬╬╬╬╬
// ╬╬╬╬╬╬╬ ╬╬╬╠╠╠╠╝╝╝╝╝╝╝╠╬╬╬╬╬╬ ╠╬╬╬╬╬╬╬ ╚╬╬╬╬╬╬╬╬
// ╬╬╬╬╬╬╬ ╣╬╬╬╬╠╠╩ ╘╬╬╬╬╬╬╬ ╠╬╬╬╬╬╬╬ ╙╬╬╬╬╬╬╬╬
//

// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.0;

import "../interface/IERC20.sol";
import "../lib/SafeERC20.sol";
import "../YakAdapter.sol";

interface IPairFactory {
function isPool(address) external view returns (bool);

function implementation() external view returns (address);
}

interface IPair {
function getAmountOut(uint256, address) external view returns (uint256);

function swap(
uint256,
uint256,
address,
bytes calldata
) external;
}

contract VelodromeV2Adapter is YakAdapter {
using SafeERC20 for IERC20;

address immutable FACTORY;

constructor(
string memory _name,
address _factory,
uint256 _swapGasEstimate
) YakAdapter(_name, _swapGasEstimate) {
FACTORY = _factory;
}

function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
}

// calculates the CREATE2 address for a pair without making any external calls
function pairFor(
address tokenA,
address tokenB,
bool stable
) internal view returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
bytes32 salt = keccak256(abi.encodePacked(token0, token1, stable));
pair = predictDeterministicAddress(IPairFactory(FACTORY).implementation(), salt, FACTORY);
}

function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(add(ptr, 0x38), deployer)
mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
mstore(add(ptr, 0x14), implementation)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
mstore(add(ptr, 0x58), salt)
mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
predicted := keccak256(add(ptr, 0x43), 0x55)
}
}

function _getAmoutOutSafe(address pair, uint amountIn, address tokenIn) internal view returns (uint) {
try IPair(pair).getAmountOut(amountIn, tokenIn) returns (uint amountOut) {
return amountOut;
} catch {
return 0;
}
}

function getQuoteAndPair(
uint256 _amountIn,
address _tokenIn,
address _tokenOut
) internal view returns (uint256 amountOut, address pair) {
address pairStable = pairFor(_tokenIn, _tokenOut, true);
uint256 amountStable;
uint256 amountVolatile;
if (IPairFactory(FACTORY).isPool(pairStable)) {
amountStable = _getAmoutOutSafe(pairStable, _amountIn, _tokenIn);
}
address pairVolatile = pairFor(_tokenIn, _tokenOut, false);
if (IPairFactory(FACTORY).isPool(pairVolatile)) {
amountVolatile = _getAmoutOutSafe(pairVolatile, _amountIn, _tokenIn);
}
(amountOut, pair) = amountStable > amountVolatile ? (amountStable, pairStable) : (amountVolatile, pairVolatile);
}

function _query(
uint256 _amountIn,
address _tokenIn,
address _tokenOut
) internal view override returns (uint256 amountOut) {
if (_tokenIn != _tokenOut && _amountIn != 0) (amountOut, ) = getQuoteAndPair(_amountIn, _tokenIn, _tokenOut);
}

function _swap(
uint256 _amountIn,
uint256 _amountOut,
address _tokenIn,
address _tokenOut,
address to
) internal override {
(uint256 amountOut, address pair) = getQuoteAndPair(_amountIn, _tokenIn, _tokenOut);
require(amountOut >= _amountOut, "Insufficent amount out");
(uint256 amount0Out, uint256 amount1Out) = (_tokenIn < _tokenOut)
? (uint256(0), amountOut)
: (amountOut, uint256(0));
IERC20(_tokenIn).safeTransfer(pair, _amountIn);
IPair(pair).swap(amount0Out, amount1Out, to, new bytes(0));
}
}
3 changes: 2 additions & 1 deletion src/deploy/arbitrum/adapters/uniswapV2/oreoswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const networkName = 'arbitrum'
const name = 'OreoswapAdapter'
const tags = [ 'oreoswap' ]
const fee = 3
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
3 changes: 2 additions & 1 deletion src/deploy/arbitrum/adapters/uniswapV2/sushiswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const networkName = 'arbitrum'
const name = 'SushiswapAdapter'
const tags = [ 'sushiswap' ]
const fee = 3
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
3 changes: 2 additions & 1 deletion src/deploy/arbitrum/adapters/uniswapV2/swapfish.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const networkName = 'arbitrum'
const name = 'SwapfishAdapter'
const tags = [ 'swapfish' ]
const fee = 3
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
3 changes: 2 additions & 1 deletion src/deploy/avalanche/adapters/uniswapV2/hakuswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ const networkName = 'avalanche'
const name = 'HakuswapAdapter'
const tags = [ 'hakuswap' ]
const fee = 2
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
3 changes: 2 additions & 1 deletion src/deploy/avalanche/adapters/uniswapV2/pangolin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ const networkName = 'avalanche'
const name = 'PangolinAdapter'
const tags = [ 'pangolin' ]
const fee = 3
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
3 changes: 2 additions & 1 deletion src/deploy/avalanche/adapters/uniswapV2/sushiswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ const networkName = 'avalanche'
const name = 'SushiswapAdapter'
const tags = [ 'sushiswap' ]
const fee = 3
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
3 changes: 2 additions & 1 deletion src/deploy/avalanche/adapters/uniswapV2/swapsicle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ const networkName = 'avalanche'
const name = 'SwapsicleAdapter'
const tags = [ 'swapsicle' ]
const fee = 3
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
3 changes: 2 additions & 1 deletion src/deploy/avalanche/adapters/uniswapV2/traderjoe.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ const networkName = 'avalanche'
const name = 'TraderjoeAdapter'
const tags = [ 'traderjoe' ]
const fee = 3
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
11 changes: 11 additions & 0 deletions src/deploy/base/adapters/uniswapV2/alienswap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { deployUniV2Contract, addresses } = require("../../../utils");
const { univ2 } = addresses.base;

const factory = univ2.factories.alienbase;
const networkName = "base";
const name = "AlienBaseAdapter";
const tags = ["alienbase"];
const fee = 16;
const feeDenominator = 10000;

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator);
11 changes: 11 additions & 0 deletions src/deploy/base/adapters/uniswapV2/baseswap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { deployUniV2Contract, addresses } = require("../../../utils");
const { univ2 } = addresses.base;

const factory = univ2.factories.baseswap;
const networkName = "base";
const name = "BaseSwapAdapter";
const tags = ["baseswap"];
const fee = 25;
const feeDenominator = 10000;

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator);
11 changes: 11 additions & 0 deletions src/deploy/base/adapters/uniswapV2/swapbased.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { deployUniV2Contract, addresses } = require("../../../utils");
const { univ2 } = addresses.base;

const factory = univ2.factories.swapbased;
const networkName = "base";
const name = "SwapBasedAdapter";
const tags = ["swapbased"];
const fee = 30;
const feeDenominator = 10000;

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator);
13 changes: 13 additions & 0 deletions src/deploy/base/adapters/uniswapV3/sushiV3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { deployAdapter, addresses } = require('../../../utils')
const { factory, quoter } = addresses.base.sushiV3

const networkName = 'base'
const contractName = 'UniswapV3Adapter'
const tags = [ 'sushiV3' ]
const name = 'SushiV3Adapter'
const gasEstimate = 300_000
const quoterGasLimit = 300_000
const defaultFees = [500, 3_000, 10_000]
const args = [ name, gasEstimate, quoterGasLimit, quoter, factory, defaultFees ]

module.exports = deployAdapter(networkName, tags, name, contractName, args)
13 changes: 13 additions & 0 deletions src/deploy/base/adapters/uniswapV3/uniV3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { deployAdapter, addresses } = require('../../../utils')
const { factory, quoter } = addresses.base.uniV3

const networkName = 'base'
const contractName = 'UniswapV3Adapter'
const tags = [ 'uniswapV3' ]
const name = contractName
const gasEstimate = 300_000
const quoterGasLimit = 300_000
const defaultFees = [500, 3_000, 10_000]
const args = [ name, gasEstimate, quoterGasLimit, quoter, factory, defaultFees ]

module.exports = deployAdapter(networkName, tags, contractName, contractName, args)
12 changes: 12 additions & 0 deletions src/deploy/base/adapters/velodromV2/aerodrom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const { deployAdapter, addresses } = require("../../../utils");
const { factory } = addresses.base.aerodrom;

const networkName = "base";
const tags = ["aerodrom"];
const name = "AerodromAdapter";
const contractName = "VelodromeV2Adapter";

const gasEstimate = 4e5;
const args = [name, factory, gasEstimate];

module.exports = deployAdapter(networkName, tags, name, contractName, args);
4 changes: 4 additions & 0 deletions src/deploy/base/routers/yakrouter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const { deployRouter } = require("../../utils");

const networkName = "base";
module.exports = deployRouter(networkName);
3 changes: 2 additions & 1 deletion src/deploy/dogechain/adapters/uniV2/dogeswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const networkName = 'dogechain'
const name = 'DogeSwapAdapter'
const tags = [ 'dogeswap' ]
const fee = 2
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
3 changes: 2 additions & 1 deletion src/deploy/dogechain/adapters/uniV2/kibbleswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const networkName = 'dogechain'
const name = 'KibbleSwapAdapter'
const tags = [ 'kibbleswap' ]
const fee = 3
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
3 changes: 2 additions & 1 deletion src/deploy/dogechain/adapters/uniV2/yodeswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const networkName = 'dogechain'
const name = 'YodeSwapAdapter'
const tags = [ 'yodeswap' ]
const fee = 5
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
3 changes: 2 additions & 1 deletion src/deploy/optimism/adapters/uniswapV2/zipswap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const networkName = 'optimism'
const name = 'ZipswapAdapter'
const tags = [ 'zipswap' ]
const fee = 3
const feeDenominator = 1000

module.exports = deployUniV2Contract(networkName, tags, name, factory, fee)
module.exports = deployUniV2Contract(networkName, tags, name, factory, fee, feeDenominator)
Loading