Source Code
Latest 25 from a total of 229,225 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Swap | 28122045 | 44 secs ago | IN | 0 FRAX | 0.00038671 | ||||
| Swap | 28121834 | 7 mins ago | IN | 0 FRAX | 0.00027457 | ||||
| Swap | 28121814 | 8 mins ago | IN | 0 FRAX | 0.00029085 | ||||
| Swap | 28121726 | 11 mins ago | IN | 0 FRAX | 0.0006859 | ||||
| Swap | 28121703 | 12 mins ago | IN | 0 FRAX | 0.00068425 | ||||
| Swap | 28121686 | 12 mins ago | IN | 0 FRAX | 0.00035274 | ||||
| Swap | 28121545 | 17 mins ago | IN | 0 FRAX | 0.00037924 | ||||
| Swap | 28121445 | 20 mins ago | IN | 0 FRAX | 0.00077575 | ||||
| Swap | 28121410 | 21 mins ago | IN | 0 FRAX | 0.00042828 | ||||
| Swap | 28121276 | 26 mins ago | IN | 0 FRAX | 0.00048983 | ||||
| Swap | 28121187 | 29 mins ago | IN | 0 FRAX | 0.00030792 | ||||
| Swap | 28121173 | 29 mins ago | IN | 0 FRAX | 0.00050965 | ||||
| Swap | 28121152 | 30 mins ago | IN | 0 FRAX | 0.00045788 | ||||
| Swap | 28121143 | 30 mins ago | IN | 0 FRAX | 0.00030747 | ||||
| Swap | 28121129 | 31 mins ago | IN | 0 FRAX | 0.00050897 | ||||
| Swap | 28121121 | 31 mins ago | IN | 0 FRAX | 0.00030725 | ||||
| Swap | 28121107 | 32 mins ago | IN | 0 FRAX | 0.00064289 | ||||
| Swap | 28121099 | 32 mins ago | IN | 0 FRAX | 0.00032165 | ||||
| Swap | 28121091 | 32 mins ago | IN | 0 FRAX | 0.00028815 | ||||
| Swap | 28121085 | 32 mins ago | IN | 0 FRAX | 0.00042355 | ||||
| Swap | 28121077 | 33 mins ago | IN | 0 FRAX | 0.00023674 | ||||
| Swap | 28121063 | 33 mins ago | IN | 0 FRAX | 0.00038939 | ||||
| Swap | 28121053 | 33 mins ago | IN | 0 FRAX | 0.00042847 | ||||
| Swap | 28121038 | 34 mins ago | IN | 0 FRAX | 0.0004311 | ||||
| Swap | 28121029 | 34 mins ago | IN | 0 FRAX | 0.00024084 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
BAMMWrapper
Compiler Version
v0.8.23+commit.f704f362
Optimization Enabled:
Yes with 1000 runs
Other Settings:
shanghai EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;
import {console} from "frax-std/FraxTest.sol";
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ============================ FraxWrapper ===========================
// ====================================================================
/*
** FraxWrapper
** Wrapper class to manage multiple BAMM positions
*/
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Math } from "dev-fraxswap/src/contracts/core/libraries/Math.sol";
import "src/contracts/interfaces/IBAMM.sol";
import { BAMM } from "./BAMM.sol";
import { BAMMUIHelper } from "./BAMMUIHelper.sol";
import { BAMMFactory } from "./factories/BAMMFactory.sol";
import { console } from "frax-std/FraxTest.sol";
contract BAMMWrapper is Ownable {
/// @notice The set of operators
mapping(address=> bool) public isOperator;
/// @notice The BAMM factory
BAMMFactory public immutable factory;
/// @notice The bammUIHelper
BAMMUIHelper public immutable bammUIHelper;
/// @notice BAMMs that are allowed to be used
mapping(address => bool) public allowedBAMMs;
/// @notice List of BAMMs that have been used
address[] public bammList;
/// @notice The default target LTV
int256 defaultTargetLTV = 0.97999E18;
/// @notice The max ustility rate
uint256 defaultMaxUtilRate = 0.94999E18;
/// @notice Thes default setting of maxRent
bool defaultMaxRent = false;
modifier onlyOperatorOwner() {
require(isOperator[msg.sender] || msg.sender==owner() || msg.sender==address(0));
_;
}
modifier bammAllowed(address bamm) {
require (allowedBAMMs[bamm],"BAMM not allowed");
_;
}
constructor(address _factory, address _bammUIHelper) Ownable(msg.sender) {
factory = BAMMFactory(_factory);
bammUIHelper = BAMMUIHelper(_bammUIHelper);
}
// ############################################
// ############ Operator actions ##############
// ############################################
/// @notice Rents the maximum possible amount
/// @param bamm The Bamm to use
/// @param targetLTV The max LTV to target
/// @param maxUtilRate The max utilisation rate allowed
/// @return vault the vault after the action
function rentMax(address bamm, int256 targetLTV, uint256 maxUtilRate) public returns (IBAMM.Vault memory vault) {
vault = actionWithTargetLTV(bamm,0,0,targetLTV,maxUtilRate, true);
}
/// @notice Deposit or withdraw collateral
/// @param bamm The Bamm to use
/// @param token0Amount The amount of token0 to deposit (positive) or withdraw (negative)
/// @param token1Amount The amount of token1 to deposit (positive) or withdraw (negative)
/// @return vault the vault after the action
function depositWithdraw(address bamm, int256 token0Amount, int256 token1Amount) public returns (IBAMM.Vault memory vault) {
vault = actionWithTargetLTV(bamm,token0Amount,token1Amount, defaultTargetLTV, defaultMaxUtilRate, defaultMaxRent);
}
/// @notice Swap token0 for token1 in the vault
/// @param bamm The Bamm to use
/// @param token0 The amount of token0 to swap
/// @param amountOutMin The minimal amount of token1 to get get in return
/// @return vault the vault after the action
function swapToken0(address bamm, int256 token0, uint256 amountOutMin) public returns (IBAMM.Vault memory vault) {
vault = swapWithTargetLTV(bamm, token0, 0, amountOutMin, defaultTargetLTV, defaultMaxUtilRate, defaultMaxRent);
}
/// @notice Swap token1 for token0 in the vault
/// @param bamm The Bamm to use
/// @param token1 The amount of token1 to swap
/// @param amountOutMin The minimal amount of token0 to get get in return
/// @return vault the vault after the action
function swapToken1(address bamm, int256 token1, uint256 amountOutMin) public returns (IBAMM.Vault memory vault) {
vault = swapWithTargetLTV(bamm, 0,token1, amountOutMin, defaultTargetLTV, defaultMaxUtilRate, defaultMaxRent);
}
/// @notice Execute a swap in the vault
/// @param bamm The Bamm to use
/// @param swapParams the parameters for the swap.
/// @return vault the vault after the action
function swap(address bamm, IFraxswapRouterMultihop.FraxswapParams memory swapParams) public returns (IBAMM.Vault memory vault) {
vault = swap(bamm, swapParams,defaultTargetLTV, defaultMaxUtilRate, defaultMaxRent);
}
/// @notice Execute a swap in the vault
/// @param bamm The Bamm to use
/// @param swapParams the parameters for the swap.
/// @param targetLTV The max LTV to target
/// @param maxUtilRate The max utilisation rate allowed
/// @param maxRent true if the amount to rent is maximize, false if the amount to rent is minimalized.
/// @return vault the vault after the action
function swap(address bamm, IFraxswapRouterMultihop.FraxswapParams memory swapParams,int256 targetLTV, uint256 maxUtilRate, bool maxRent) public onlyOperatorOwner bammAllowed(bamm) returns (IBAMM.Vault memory vault) {
BAMMUIHelper.BAMMState memory bammState = bammUIHelper.getBAMMState(BAMM(bamm));
BAMMUIHelper.BAMMVault memory vaultState = bammUIHelper.getVaultState(BAMM(bamm),address(this));
int256 token0;
int256 token1;
if (swapParams.tokenIn==address(BAMM(bamm).token0())) {
token0 = int256(swapParams.amountIn);
token1 = -int256(swapParams.amountOutMinimum);
} else if (swapParams.tokenIn==address(BAMM(bamm).token1())) {
token1 = int256(swapParams.amountIn);
token0 = -int256(swapParams.amountOutMinimum);
}
int256 rentReal = maxRent?
calcMaxRentForLTV(uint256(int256(bammState.reserve0)),uint256(int256(bammState.reserve1)),vaultState.token0-vaultState.rentedToken0-token0,vaultState.token1-vaultState.rentedToken1-token1,targetLTV)
:calcRentForLTV(uint256(int256(bammState.reserve0)),uint256(int256(bammState.reserve1)),vaultState.token0-vaultState.rentedToken0-token0,vaultState.token1-vaultState.rentedToken1-token1,targetLTV);
int256 rentRealDelta = rentReal - vaultState.rented*int256(bammState.rentedMultiplier)/1E18;
if (rentRealDelta>0) {
int256 maxRentReal = int256(((bammState.sqrtBalance+bammState.sqrtRentedReal)*maxUtilRate/1E18)-bammState.sqrtRentedReal);
if (rentRealDelta>maxRentReal) rentRealDelta = maxRentReal;
}
IBAMM.Action memory action;
action.rent = rentRealDelta*1E18/int256(bammState.rentedMultiplier);
if (action.rent>-1E6 && action.rent<1E6) action.rent=0; // Avoid micro rents that can cause problems.
if (action.rent<0) ammPriceCheck(BAMM(bamm), bammState.reserve0, bammState.reserve1);
vault = IBAMM(bamm).executeActionsAndSwap(action,swapParams);
}
/// @notice Execute an deposit withdraw action
/// @param bamm The Bamm to use
/// @param token0Amount The amount of token0 to deposit (positive) or withdraw (negative)
/// @param token1Amount The amount of token1 to deposit (positive) or withdraw (negative)
/// @param targetLTV The max LTV to target
/// @param maxUtilRate The max utilisation rate allowed
/// @param maxRent true if the amount to rent is maximize, false if the amount to rent is minimalized.
/// @return vault the vault after the action
function actionWithTargetLTV(address bamm, int256 token0Amount, int256 token1Amount, int256 targetLTV, uint256 maxUtilRate, bool maxRent) public onlyOperatorOwner bammAllowed(bamm) returns (IBAMM.Vault memory vault) {
BAMMUIHelper.BAMMState memory bammState = bammUIHelper.getBAMMState(BAMM(bamm));
BAMMUIHelper.BAMMVault memory vaultState = bammUIHelper.getVaultState(BAMM(bamm),address(this));
int256 netToken0 = vaultState.token0-vaultState.rentedToken0+token0Amount;
int256 netToken1 = vaultState.token1-vaultState.rentedToken1+token1Amount;
int256 rentReal = maxRent?calcMaxRentForLTV(bammState.reserve0,bammState.reserve1,netToken0,netToken1,targetLTV):calcRentForLTV(bammState.reserve0,bammState.reserve1,netToken0,netToken1,targetLTV);
int256 rentRealDelta = rentReal - vaultState.rented*int256(bammState.rentedMultiplier)/1E18;
if (rentRealDelta>0) {
int256 maxRentReal = int256(((bammState.sqrtBalance+bammState.sqrtRentedReal)*maxUtilRate/1E18)-bammState.sqrtRentedReal);
if (rentRealDelta>maxRentReal) rentRealDelta = maxRentReal;
}
IBAMM.Action memory action;
action.token0Amount = token0Amount;
action.token1Amount = token1Amount;
action.rent = rentRealDelta*1E18/int256(bammState.rentedMultiplier);
if (action.rent>-1E6 && action.rent<1E6) action.rent=0; // Avoid micro rents that can cause problems.
if (action.rent<0) ammPriceCheck(BAMM(bamm), bammState.reserve0, bammState.reserve1);
vault = IBAMM(bamm).executeActions(action);
}
/// @notice Execute a swap on the AMM and target a specific LTV
/// @param bamm The Bamm to use
/// @param token0 The amount of token0 to buy (positive) or sell (negative)
/// @param token1 The amount of token1 to buy (positive) or sell (negative)
/// @param targetLTV The max LTV to target
/// @param maxUtilRate The max utilisation rate allowed
/// @param maxRent true if the amount to rent is maximize, false if the amount to rent is minimalized.
/// @return vault the vault after the action
function swapWithTargetLTV(address bamm, int256 token0, int256 token1, uint256 amountOutMin, int256 targetLTV, uint256 maxUtilRate, bool maxRent) public onlyOperatorOwner bammAllowed(bamm) returns (IBAMM.Vault memory vault) {
if (maxRent) {
return _swapWithMaxRent(bamm, token0, token1, amountOutMin, targetLTV, maxUtilRate);
} else return _swapWithTargetLTV(bamm, token0, token1, amountOutMin, targetLTV );
}
struct swapWithParams {
BAMMUIHelper.BAMMState bammState;
BAMMUIHelper.BAMMVault vaultState;
IFraxswapRouterMultihop.FraxswapParams swapParams;
IBAMM.Action action;
}
function _swapWithMaxRent(address bamm, int256 token0, int256 token1, uint256 amountOutMin, int256 targetLTV, uint256 maxUtilRate) internal returns (IBAMM.Vault memory vault) {
swapWithParams memory p;
p.bammState = bammUIHelper.getBAMMState(BAMM(bamm));
p.vaultState = bammUIHelper.getVaultState(BAMM(bamm),address(this));
if (token0>0) {
p.swapParams = getSwapParameters(bamm, true, uint256(token0), amountOutMin);
} else if (token1>0) {
p.swapParams = getSwapParameters(bamm, false, uint256(token1), amountOutMin);
}
for (uint256 i=0;i<3;++i) {
uint256 reserve0;
uint256 reserve1;
(vault, reserve0, reserve1) = _estimateAction(bamm,p.bammState,p.vaultState, p.action,p.swapParams);
int256 sqrtK = int256(Math.sqrt(reserve0 * reserve1));
int256 rentedReal = vault.rented*int256(p.bammState.rentedMultiplier)/1E18;
int256 rent = calcMaxRentForLTV(reserve0,reserve1,vault.token0 - rentedReal*int256(reserve0)/sqrtK, vault.token1 - rentedReal*int256(reserve1)/sqrtK, targetLTV);
p.action.rent = (rent - int256(p.vaultState.rentedReal))*1e18/int256(p.bammState.rentedMultiplier);
if (p.action.rent>0) {
int256 maxRentReal = int256(((p.bammState.sqrtBalance+p.bammState.sqrtRentedReal)*maxUtilRate/1E18)-p.bammState.sqrtRentedReal);
if (p.action.rent>maxRentReal) p.action.rent = maxRentReal;
}
}
if (p.action.rent>-1E6 && p.action.rent<1E6) p.action.rent=0; // Avoid micro rents that can cause problems.
if (p.action.rent<0) ammPriceCheck(BAMM(bamm), p.bammState.reserve0, p.bammState.reserve1);
vault = IBAMM(bamm).executeActionsAndSwap(p.action,p.swapParams);
}
function _swapWithTargetLTV(address bamm, int256 token0, int256 token1, uint256 amountOutMin, int256 targetLTV ) internal returns (IBAMM.Vault memory vault) {
swapWithParams memory p;
p.bammState = bammUIHelper.getBAMMState(BAMM(bamm));
p.vaultState = bammUIHelper.getVaultState(BAMM(bamm),address(this));
if (token0>0) {
p.swapParams = getSwapParameters(bamm, true, uint256(token0), amountOutMin);
} else if (token1>0) {
p.swapParams = getSwapParameters(bamm, false, uint256(token1), amountOutMin);
}
for (uint256 i=0;i<3;++i) {
uint256 reserve0;
uint256 reserve1;
(vault, reserve0, reserve1) = _estimateAction(bamm,p.bammState,p.vaultState, p.action,p.swapParams);
int256 sqrtK = int256(Math.sqrt(reserve0 * reserve1));
int256 rentedReal = vault.rented*int256(p.bammState.rentedMultiplier)/1E18;
int256 rent = calcRentForLTV(reserve0,reserve1,vault.token0 - rentedReal*int256(reserve0)/sqrtK, vault.token1 - rentedReal*int256(reserve1)/sqrtK, targetLTV);
p.action.rent = (rent - int256(p.vaultState.rentedReal))*1e18/int256(p.bammState.rentedMultiplier);
}
if (p.action.rent>-1E6 && p.action.rent<1E6) p.action.rent=0; // Avoid micro rents that can cause problems.
if (p.action.rent<0) ammPriceCheck(BAMM(bamm), p.bammState.reserve0, p.bammState.reserve1);
vault = IBAMM(bamm).executeActionsAndSwap(p.action,p.swapParams);
}
/// @notice Closes a vaults position
/// @param bamm The Bamm to use
/// @return vault the vault after the action
function closePosition(address bamm) onlyOperatorOwner bammAllowed(bamm) public returns (IBAMM.Vault memory vault) {
IBAMM.Action memory action;
action.closePosition=true;
vault = executeActions(bamm, action);
}
/// @notice executes a BAMM action
/// @param bamm The Bamm to use
/// @param action The action to execute
/// @return vault the vault after the action
function executeActions(address bamm, IBAMM.Action memory action) onlyOperatorOwner bammAllowed(bamm) public returns (IBAMM.Vault memory vault) {
action.to = address(this);
vault = IBAMM(bamm).executeActions(action);
}
// ############################################
// ############## Admin actions ###############
// ############################################
/// @notice Add/remove a BAMM to the allow list
/// @param bamm The Bamm
/// @param allowed true to allow, false to disallow
function allowBAMM(address bamm, bool allowed) onlyOwner external {
require(factory.isBamm(bamm),"Not BAMM");
allowedBAMMs[bamm]=allowed;
if (allowed) {
bammList.push(bamm);
IERC20(IBAMM(bamm).token0()).approve(bamm,type(uint256).max);
IERC20(IBAMM(bamm).token1()).approve(bamm,type(uint256).max);
} else {
IERC20(IBAMM(bamm).token0()).approve(bamm,0);
IERC20(IBAMM(bamm).token1()).approve(bamm,0);
}
}
/// @notice Withdraw ERC20 tokens
/// @param _token The token
/// @param _to the reciever of the token
/// @param _value the amount of tokens
function withdrawERC20(IERC20 _token, address _to, uint256 _value) onlyOwner external {
SafeERC20.safeTransfer(_token, _to, _value);
}
/// @notice Withdraw native gas token
/// @param _to the reciever of the gas token
/// @param _value the amount of gas tokens
function withdrawETH(address _to, uint256 _value) onlyOwner external {
(bool sent,)=_to.call{value: _value}("");
require(sent, "Failed to send Ether");
}
/// @notice Set default targetLTV to be used when not specified
/// @param _defaultTargetLTV the new default
function setDefaultTargetLTV(int256 _defaultTargetLTV) onlyOwner external {
defaultTargetLTV = _defaultTargetLTV;
}
/// @notice Set default maxUtilRate to be used when not specified
/// @param _defaultMaxUtilRate the new default
function setDefaultMaxUtilRate(uint256 _defaultMaxUtilRate) onlyOwner external {
defaultMaxUtilRate = _defaultMaxUtilRate;
}
/// @notice Set default maxRent, true when the amount rented in maximize, false when it is minimalized
/// @param _defaultMaxRent the new default
function setDefaultMaxRent(bool _defaultMaxRent) onlyOwner external {
defaultMaxRent = _defaultMaxRent;
}
/// @notice Update the operator status of an address
/// @param _operator the address to update
/// @param allowed Whether the addres is to be set as an operator.
function setOperator(address _operator, bool allowed) onlyOwner external {
isOperator[_operator]=allowed;
}
// Generic proxy
/// @notice Generic proxy execute
/// @param _to the address to call
/// @param _value The amount of gas tokens to send
/// @param _data data to use in the call
function execute(
address _to,
uint256 _value,
bytes calldata _data
) external onlyOwner returns (bool, bytes memory) {
(bool success, bytes memory result) = _to.call{value:_value}(_data);
return (success, result);
}
// ############################################
// ############### Utils views ################
// ############################################
function getSwapParameters(address bamm, bool token0In, uint256 amountIn, uint256 amountOutMin) internal view returns (IFraxswapRouterMultihop.FraxswapParams memory swapParams) {
address tokenIn = address(token0In?BAMM(bamm).token0():BAMM(bamm).token1());
address tokenOut = address(token0In?BAMM(bamm).token1():BAMM(bamm).token0());
IFraxswapRouterMultihop routerMultihop = BAMM(bamm).routerMultihop();
bytes[] memory steps = new bytes[](1);
steps[0] = routerMultihop.encodeStep(0, 0, 0, tokenOut, address(BAMM(bamm).pair()), 1, token0In?1:2, 10_000);
bytes[] memory routes = new bytes[](1);
routes[0] = routerMultihop.encodeRoute(tokenOut, 10_000, steps, new bytes[](0));
bytes memory outerRoute = routerMultihop.encodeRoute(tokenOut, 10_000, new bytes[](0), routes);
swapParams = IFraxswapRouterMultihop.FraxswapParams(
tokenIn,
amountIn,
address(tokenOut),
amountOutMin,
address(this),
block.timestamp,
false,
0,
bytes32(0),
bytes32(0),
outerRoute
);
}
function calcRentForLTV(
uint256 reserve0,
uint256 reserve1,
int256 netToken0,
int256 netToken1,
int256 targetLTV
) internal pure returns (int256 rent) {
int256 sqrtK = int256(Math.sqrt(reserve0 * reserve1));
if (netToken0 < 0) {
rent =
(((netToken1 * sqrtK) / int256(reserve1)) *
_calcRentForLTV(
1e22,
(1e22 * ((netToken0 * int256(reserve1)) / int256(reserve0))) / netToken1,
targetLTV,
false
)) /
1e22;
} else if (netToken1 < 0) {
rent =
(((netToken0 * sqrtK) / int256(reserve0)) *
_calcRentForLTV(
1e22,
(1e22 * ((netToken1 * int256(reserve0)) / int256(reserve1))) / netToken0,
targetLTV,
false
)) /
1e22;
}
}
function calcMaxRentForLTV(
uint256 reserve0,
uint256 reserve1,
int256 netToken0,
int256 netToken1,
int256 targetLTV
) internal pure returns (int256 rent) {
int256 sqrtK = int256(Math.sqrt(reserve0 * reserve1));
if (netToken1 > 0 && netToken1*int256(reserve0)/int256(reserve1)>netToken0) {
rent =
(((netToken1 * sqrtK) / int256(reserve1)) *
_calcRentForLTV(
1e22,
(1e22 * ((netToken0 * int256(reserve1)) / int256(reserve0))) / netToken1,
targetLTV,
true
)) /
1e22;
} else if (netToken0 > 0) {
rent =
(((netToken0 * sqrtK) / int256(reserve0)) *
_calcRentForLTV(
1e22,
(1e22 * ((netToken1 * int256(reserve0)) / int256(reserve1))) / netToken0,
targetLTV,
true
)) /
1e22;
}
}
function _calcRentForLTV(int256 token0, int256 token1, int256 targetLTV, bool max) public pure returns (int256 rent) {
// Solve rent*PRECISION/sqrt((token0+rent)*(token1+rent))=targetLTV;
int256 PREC = 1e6;
targetLTV=targetLTV/1e12;
int256 mul = max?int256(-1):int256(1);
rent =
(mul*targetLTV *
int256(
Math.sqrt(
uint256(
targetLTV *
targetLTV *
(token0 + token1) *
(token0 + token1) -
4 *
token0 *
token1 *
(targetLTV * targetLTV - PREC * PREC)
)
)
) -
targetLTV *
targetLTV *
(token0 + token1)) /
(2 * (targetLTV * targetLTV - PREC * PREC));
}
function _estimateAction(address bamm, BAMMUIHelper.BAMMState memory bammState,BAMMUIHelper.BAMMVault memory vaultState,IBAMM.Action memory action,IFraxswapRouterMultihop.FraxswapParams memory swapParams) internal view returns (IBAMM.Vault memory vault, uint256 reserve0, uint256 reserve1) {
reserve0 = bammState.reserve0;
reserve1 = bammState.reserve1;
vault.token0 = vaultState.token0;
vault.token1 = vaultState.token1;
vault.rented = vaultState.rented + action.rent;
int256 rentedReal = action.rent*int256(bammState.rentedMultiplier)/1E18;
// Execute rent
if (action.rent>0) {
int256 sqrtK = int256(Math.sqrt(reserve0*reserve1));
int256 rent0 = (rentedReal*int256(reserve0))/sqrtK;
int256 rent1 = (rentedReal*int256(reserve1))/sqrtK;
reserve0=uint256(int256(reserve0) - rent0);
reserve1=uint256(int256(reserve1) - rent1);
vault.token0+=rent0;
vault.token1+=rent1;
}
// Execute swap
{
uint256 fee = BAMM(bamm).pair().fee();
uint256 amountIn = swapParams.amountIn;
if (swapParams.tokenIn==address(BAMM(bamm).token0())) {
uint256 amountOut = getAmountOut(reserve0,reserve1,amountIn,fee);
reserve0+=amountIn;
reserve1-=amountOut;
vault.token0-=int256(amountIn);
vault.token1+=int256(amountOut);
} else {
uint256 amountOut = getAmountOut(reserve1,reserve1,amountIn,fee);
reserve1+=amountIn;
reserve0-=amountOut;
vault.token1-=int256(amountIn);
vault.token0+=int256(amountOut);
}
}
// Execute repay rent
if (action.rent<0) {
int256 sqrtK = int256(Math.sqrt(reserve0*reserve1));
int256 rent0 = (rentedReal*int256(reserve0))/sqrtK;
int256 rent1 = (rentedReal*int256(reserve1))/sqrtK;
reserve0=uint256(int256(reserve0) - rent0);
reserve1=uint256(int256(reserve1) - rent1);
vault.token0+=rent0;
vault.token1+=rent1;
}
}
function ammPriceCheck(BAMM bamm, uint256 reserve0, uint256 reserve1) internal view {
// 30 minutes and max 1024 blocks
(uint256 result0, uint256 result1) = bamm.fraxswapOracle().getPrice({
pool: bamm.pair(),
period: 60 * 30,
rounds: 10,
maxDiffPerc: 10_000
});
result0 = 1e68 / result0;
uint256 spotPrice = (uint256(reserve0) * 1e34) / reserve1;
// Check the price differences and revert if they are too much
uint256 diff = (spotPrice > result0 ? spotPrice - result0 : result0 - spotPrice);
if ((diff * 10_000) / result0 > 500) {
revert OraclePriceDeviated();
}
diff = (spotPrice > result1 ? spotPrice - result1 : result1 - spotPrice);
if ((diff * 10_000) / result1 > 500) {
revert OraclePriceDeviated();
}
}
function getAmountOut(
uint256 reserveIn,
uint256 reserveOut,
uint256 amountIn,
uint256 fee
) internal pure returns (uint256) {
require(amountIn > 0 && reserveIn > 0 && reserveOut > 0); // INSUFFICIENT_INPUT_AMOUNT, INSUFFICIENT_LIQUIDITY
uint256 amountInWithFee = amountIn * fee;
uint256 numerator = amountInWithFee * reserveOut;
uint256 denominator = (reserveIn * 10_000) + amountInWithFee;
return numerator / denominator;
}
error OraclePriceDeviated();
}// SPDX-License-Identifier: ISC
pragma solidity >=0.8.0;
import { console2 as console, StdAssertions, StdChains, StdCheats, stdError, StdInvariant, stdJson, stdMath, StdStorage, stdStorage, StdUtils, Vm, StdStyle, TestBase, DSTest, Test } from "forge-std/Test.sol";
import { VmHelper } from "./VmHelper.sol";
import { Strings } from "./StringsHelper.sol";
abstract contract FraxTest is VmHelper, Test {
uint256[] internal snapShotIds;
function()[] internal setupFunctions;
// ========================================================================
// ~~~~~~~~~~~~~~~~~~ Different State Testing Helpers ~~~~~~~~~~~~~~~~~~~~~
// ========================================================================
modifier useMultipleSetupFunctions() {
if (snapShotIds.length == 0) _;
for (uint256 i = 0; i < snapShotIds.length; i++) {
uint256 _originalSnapshotId = vm.snapshot();
if (!vm.revertTo(snapShotIds[i])) {
revert VmDidNotRevert(snapShotIds[i]);
}
_;
vm.clearMockedCalls();
vm.revertTo(_originalSnapshotId);
}
}
function addSetupFunctions(function()[] memory _setupFunctions) internal {
for (uint256 i = 0; i < _setupFunctions.length; i++) {
_setupFunctions[i]();
snapShotIds.push(vm.snapshot());
vm.clearMockedCalls();
}
}
// ========================================================================
// ~~~~~~~~~~~~~~~~~~~~~~~ Storage Slot Helpers ~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ========================================================================
/// @notice Helper function to dump the storage slots of a contract to the console
/// @param target The target contract whose state we wish to view
/// @param slotsToDump The # of lower storage slots we want to log
function dumpStorageLayout(address target, uint256 slotsToDump) internal view {
console.log("===================================");
console.log("Storage dump for: ", target);
console.log("===================================");
for (uint i; i <= slotsToDump; i++) {
bytes32 slot = vm.load(target, bytes32(uint256(i)));
string memory exp = Strings.toHexString(uint256(slot), 32);
console.log("slot", i, ":", exp);
}
}
/// @notice Helper function for unpacking low level storage slots
/// @param dataToUnpack The bytes32|uint256 of the slot to unpack
/// @param offset The bits to remove st. the target bits are LSB
/// @param lenOfTarget The length target result in bits
/// @return result The target bits expressed as a uint256
function unpackBits(
uint256 dataToUnpack,
uint256 offset,
uint256 lenOfTarget
) internal pure returns (uint256 result) {
uint256 mask = (1 << lenOfTarget) - 1;
result = (dataToUnpack >> offset) & mask;
}
function unpackBits(
bytes32 dataToUnpack,
uint256 offset,
uint256 lenOfTarget
) internal pure returns (uint256 result) {
uint256 mask = (1 << lenOfTarget) - 1;
result = (uint256(dataToUnpack) >> offset) & mask;
}
function unpackBitsAndLogUint(
uint256 dataToUnpack,
uint256 offset,
uint256 lenOfTarget
) internal pure returns (uint256 result) {
result = unpackBits(dataToUnpack, offset, lenOfTarget);
console.log(result);
}
function unpackBitsAndLogUint(
bytes32 dataToUnpack,
uint256 offset,
uint256 lenOfTarget
) internal pure returns (uint256 result) {
result = unpackBits(dataToUnpack, offset, lenOfTarget);
console.log(result);
}
error VmDidNotRevert(uint256 _snapshotId);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}// SPDX-Licence-Identifier: MIT
pragma solidity ^0.8.0;
// a library for performing various math operations
library Math {
function min(uint256 x, uint256 y) internal pure returns (uint256 z) {
z = x < y ? x : y;
}
// babylonian method (https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method)
function sqrt(uint256 y) internal pure returns (uint256 z) {
if (y > 3) {
z = y;
uint256 x = y / 2 + 1;
while (x < z) {
z = x;
x = (y / x + x) / 2;
}
} else if (y != 0) {
z = 1;
}
}
}pragma solidity ^0.8.0;
import { IERC20Metadata as IERC20 } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { IFraxswapPair } from "dev-fraxswap/src/contracts/core/interfaces/IFraxswapPair.sol";
import { IFraxswapFactory } from "dev-fraxswap/src/contracts/core/interfaces/IFraxswapFactory.sol";
import { IFraxswapRouterMultihop } from "dev-fraxswap/src/contracts/periphery/interfaces/IFraxswapRouterMultihop.sol";
import { BAMMERC20 } from "src/contracts/BAMMERC20.sol";
import { IFraxswapOracle } from "src/contracts/interfaces/IFraxswapOracle.sol";
import { IBAMMFactory } from "src/contracts/interfaces/IBAMMFactory.sol";
import { IVariableInterestRate } from "src/contracts/interfaces/IVariableInterestRate.sol";
interface IBAMM {
// #####################################
// ############## Errors ###############
// #####################################
error CannotWithdrawToSelf();
error InsufficientAmount();
error ZeroLiquidityMinted();
error NotSolvent();
error Solvent();
error IncorrectSwapTokens();
error InvalidVault();
error InvalidUtilityRate();
error OraclePriceDeviated();
error IncorrectAmountOutMinimum();
error InvalidRent();
error NotFactory();
error NoBAMMTokensMinted();
// #####################################
// ############## Structs ##############
// #####################################
/// @notice Details for a user's vault
struct Vault {
int256 token0; // Token 0 in the LP
int256 token1; // Token 1 in the LP
int256 rented; // SQRT(#token0 * #token1) that is rented
}
/// @notice Function parameter pack for various actions. Different parts may be empty for different actions.
struct Action {
int256 token0Amount; // Amount of token 0. Positive = add to vault. Negative = remove from vault
int256 token1Amount; // Amount of token 1. Positive = add to vault. Negative = remove from vault
int256 rent; // SQRT(#token0 * #token1). Positive if borrowing, negative if repaying
address to; // A destination address
uint256 token0AmountMin; // Minimum amount of token 0 expected
uint256 token1AmountMin; // Minimum amount of token 1 expected
bool closePosition; // Whether to close the position or not
bool approveMax; // Whether to approve max (e.g. uint256(-1) or similar)
uint8 v; // Part of a signature
bytes32 r; // Part of a signature
bytes32 s; // Part of a signature
uint256 deadline; // Deadline of this action
}
// #####################################
// ######### State variables ###########
// #####################################
function iBammErc20() external view returns (BAMMERC20);
function token0() external view returns (IERC20);
function token1() external view returns (IERC20);
function pair() external view returns (IFraxswapPair);
function routerMultihop() external view returns (IFraxswapRouterMultihop);
function fraxswapOracle() external view returns (IFraxswapOracle);
function factory() external view returns (address);
function sqrtRented() external view returns (int256);
function rentedMultiplier() external view returns (uint256);
function timeSinceLastInterestPayment() external view returns (uint256);
function fullUtilizationRate() external view returns (uint256);
function variableInterestRate() external view returns (IVariableInterestRate);
function getUserVault(address user) external view returns (Vault memory vault);
// #####################################
// ############ Functions ##############
// #####################################
function version() external pure returns (uint256 major, uint256 minor, uint256 patch);
function mint(address to, uint256 lpIn) external returns (uint256 bammOut);
function redeem(address to, uint256 bammIn) external returns (uint256 lpOut);
function executeActions(Action memory action) external returns (Vault memory vault);
function executeActionsAndSwap(
Action memory action,
IFraxswapRouterMultihop.FraxswapParams memory swapParams
) external returns (Vault memory vault);
function microLiquidate(address user) external returns (uint256 token0Fee, uint256 token1Fee);
function addInterest()
external
returns (uint256 reserve0, uint256 reserve1, uint256 totalSupply, uint256 _rentedMultiplier);
function previewInterestRate(uint256 _utilization) external view returns (uint256 newRatePerSec);
// ####################################
// ############## Events ##############
// ####################################
/// @notice Emitted when BAMM state changes
/// @param sqrtRentedReal rented sqrt amount
/// @param sqrtBalance sqrt of the LP tokens held
/// @param rentedMultiplier multiplier that increases with interest
/// @param interestRate current interest rate
event BAMMState(uint256 sqrtRentedReal, uint256 sqrtBalance, uint256 rentedMultiplier, uint256 interestRate);
/// @notice Emitted when BAMM tokens get minted by a user directly
/// @param lender The person lending the LP
/// @param recipient The recipient of the minted BAMM tokens
/// @param lpIn The amount of LP being sent in
/// @param bammOut The amount of BAMM tokens minted
event BAMMMinted(address indexed lender, address indexed recipient, uint256 lpIn, uint256 bammOut);
/// @notice Emitted when BAMM tokens get redeemed by a user directly
/// @param lender The person redeeming the BAMM tokens
/// @param recipient The recipient of the LP tokens
/// @param bammIn The amount of BAMM tokens being sent in
/// @param lpOut The amount of LP sent out
event BAMMRedeemed(address indexed lender, address indexed recipient, uint256 bammIn, uint256 lpOut);
/// @notice Emitted when a vault is updated
/// @param user The address of the user
/// @param token0 The amount of token0 in the vault
/// @param token1 The amount of token1 in the vault
event VaultUpdated(address indexed user, int256 token0, int256 token1, int256 rent);
/// @notice Emitted a users executes a vault action
/// @param user The address of the user
/// @param token0 token0 changed (positive is tokens added, negative is tokens withdrawn)
/// @param token1 token1 changed (positive is tokens added, negative is tokens withdrawn)
/// @param rent Rent changed (positive is renting, negative is paying back)
event ExecuteAction(address indexed user, int256 token0, int256 token1, int256 rent);
/// @notice Emitted a users vault changes
/// @param user The address of the user
/// @param token0 token0 swapped (positive is in, negative is out)
/// @param token1 token1 swapped (positive is in, negative is out)
event VaultSwap(address indexed user, int256 token0, int256 token1);
/// @notice Emitted when a user pays back the rented LP
/// @param user The user
/// @param rent The rent change
/// @param token0ToAddToLp Token0 paid back
/// @param token1ToAddToLp Token1 paid back
/// @param closePosition Whether the position was closed or not
event RentRepaid(
address indexed user,
int256 rent,
uint256 token0ToAddToLp,
uint256 token1ToAddToLp,
bool closePosition
);
/// @notice Emitted when a user starts renting
/// @param user The user
/// @param rent The rent change
/// @param token0Amount Token0 credited to borrower's vault
/// @param token1Amount Token1 credited to borrower's vault
event Renting(address indexed user, int256 rent, int256 token0Amount, int256 token1Amount);
/// @notice Emitted when a user gets micro liquidated
/// @param user The user being liquidated
/// @param liquidator The person doing the liquidating
/// @param token0Fee Amount of liquidation fee in token0 paid
/// @param token1Fee Amount of liquidation fee in token1 paid
event MicroLiquidate(address indexed user, address indexed liquidator, uint256 token0Fee, uint256 token1Fee);
/// @notice Emitted when a the interest rate contract is updated
/// @param previousVariableInterestRate The previous interest rate contract
/// @param newVariableInterestRate The new interest rate contract
event NewVariableInterestRate(
address indexed previousVariableInterestRate,
address indexed newVariableInterestRate
);
/// @notice Emitted when a new `maxOracleDiff` is set
/// @param oldMaxOracleDiff The old `maxOracleDiff`
/// @param newMaxOracleDiff The new `maxOracleDiff`
event NewMaxOracleDiff(uint256 oldMaxOracleDiff, uint256 newMaxOracleDiff);
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.23;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// =============================== BAMM ===============================
// ====================================================================
/*
** BAMM (Borrow AMM)
** - The BAMM wraps Uniswap/Fraxswap like LP tokens (#token0 * #token1 = K), giving out an ERC-20 wrapper token in return
** - Users have a personal vault where they can add / remove token0 and token1.
** - Users can rent the LP constituent token0s and token1s, the liquidity from which will be removed and stored in the users vault.
** - Rented LP constituent token0s and token1s are accounted as SQRT(#token0 * #token1)
** - The user can remove tokens from their personal vault as long as the SQRT(#token0 * #token1) is more than the rented value
** - Borrowers pay an interest rate based on the utility factor
** - Borrowers can only be liquidated due to interest rate payments, not due to price movements.
** - Liquidations will be auctioned, to be small and cheap
** - No price oracle needed!
*/
/*
-----------------------------------------------------------
-------------------- EXAMPLE SCENARIOS --------------------
-----------------------------------------------------------
Assume Fraxswap FRAX/FXS LP @ 0x03B59Bd1c8B9F6C265bA0c3421923B93f15036Fa.
token0 = FXS, token1 = FRAX
Scenario 1: User wants to rent some FXS using FRAX as collateral
===================================
1) User obtains some FRAX, which will be used as collateral
2) User calls executeActionsAndSwap() with
a) Positive token1Amount (add FRAX to vault)
b) Negative token0Amount (withdraw FXS from vault)
c) Positive rent (renting)
d) The swapParams to swap SOME of the excess FRAX for FXS (they need to remain solvent at the end of the day)
e) (Optional) v,r,s for a permit (token1 to this contract) for the vault add
3) The internal call flow will be:
i) BAMM-owned LP is unwound into BOTH FRAX and FXS, according to the supplied rent parameter. Both tokens are added to the user's vault.
ii) User supplied FRAX is added to their vault to increase their collateral
iii) Some of the excess FRAX from the LP unwind is swapped for FXS (according to swapParams)
iv) FXS is sent to the user
v) Contract will revert if the user is insolvent or the LP utility is above MAX_UTILITY_RATE
Scenario 2: User from Scenario 1 wants to repay SOME of their rented FXS and get SOME FRAX back
===================================
1) User calls executeActionsAndSwap() with
a) Negative token1Amount (withdraw FRAX from vault)
b) Positive token0Amount (add FXS to vault)
c) Negative rent (repaying)
d) token0AmountMin to prevent sandwiches from the LP add
e) token1AmountMin to prevent sandwiches from the LP add
f) The swapParams to swap SOME of the FXS for FRAX. LP will be added at the current ratio so this is helpful.
g) (Optional) v,r,s for a permit (token0 to this contract) for the vault add
2) The internal call flow will be:
i) Interest accrues so the user owes a little bit more FXS (and/or FRAX) now.
ii) User-supplied FXS is added to the vault
iii) Some of the FXS is swapped for FRAX (according to swapParams).
iv) FRAX and FXS are added (at current LP ratio) to make the Fraxswap LP, which becomes BAMM-owned, according to the supplied rent parameter.
v) Accounting updated to lower rent and vaulted tokens.
vi) FRAX is sent to the user
vii) Contract will revert if the user is insolvent or the LP utility is above MAX_UTILITY_RATE
Scenario 3: User from Scenario 1 wants to repay the remaining rented FXS, get their FRAX back, and close the position
===================================
1) User calls executeActionsAndSwap() with
a) Negative token1Amount (withdraw FRAX from vault)
b) Positive token0Amount (add FXS to vault)
c) closePosition as true. No need to supply rent as the function will override it anyways
d) token0AmountMin to prevent sandwiches from the LP add
e) token1AmountMin to prevent sandwiches from the LP add
f) The swapParams to swap SOME of the FXS for FRAX. LP will be added at the current ratio so this is helpful.
g) (Optional) v,r,s for a permit (token0 to this contract) for the vault add
2) The internal call flow will be:
i) Interest accrues so the user owes a little bit more FXS (and/or FRAX) now.
ii) User-supplied FXS is added to the vault
iii) Some of the FXS is swapped for FRAX (according to swapParams).
iv) Accounting updated to lower rent and vaulted tokens.
v) Any remaining FRAX or FXS needed is safeTransferFrom'd the user
vi) FRAX and FXS are added (at current LP ratio) to make the Fraxswap LP, which becomes BAMM-owned, according to the supplied rent parameter
vii) FRAX is sent back to the user
viii) Contract will revert if the user is insolvent or the LP utility is above MAX_UTILITY_RATE
Scenario 4: User wants to loan some LP and earn interest
===================================
1) Approve LP to this BAMM contract
2) Call mint(), which will give you BAMM tokens as a "receipt"
3) Wait some time, and assume some other people borrow. Interest accrues
4) Call redeem(), which burns your BAMM tokens and gives you your LP back, plus some extra LP as interest.
*/
// Frax Finance: https://github.com/FraxFinance
import { IERC20Permit } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { Math } from "dev-fraxswap/src/contracts/core/libraries/Math.sol";
import "src/contracts/interfaces/IBAMM.sol";
contract BAMM is IBAMM, ReentrancyGuard {
using SafeCast for *;
using Strings for uint256;
// ############################################
// ############## STATE VARIABLES #############
// ############################################
BAMMERC20 public immutable iBammErc20;
/// @notice Token 0 in the Fraxswap LP
IERC20 public immutable token0;
/// @notice Token 1 in the Fraxswap LP
IERC20 public immutable token1;
/// @notice Address of the Fraxswap pair
IFraxswapPair public immutable pair;
/// @notice Address of the Fraxswap factory
IFraxswapFactory public immutable pairFactory;
/// @notice The Fraxswap router
IFraxswapRouterMultihop public immutable routerMultihop;
/// @notice Price oracle for the Fraxswap pair
IFraxswapOracle public immutable fraxswapOracle;
/// @notice Address of the BAMMFactory to create this contract
address public immutable factory;
/// @notice The variableInterestRate associated
IVariableInterestRate public variableInterestRate;
/// @notice Tracks the amount of rented liquidity
/// @dev Will never be < 0
int256 public sqrtRented;
/// @notice Multiplier used in interest rate and rent amount calculations. Never decreases and acts like an accumulator of sorts.
uint256 public rentedMultiplier = PRECISION; // Initialized at PRECISION, but will change
/// @notice The last time an interest payment was made
uint256 public timeSinceLastInterestPayment = block.timestamp;
/// @notice The `fullUtilizationRate` returned from the variable rate oracle
uint256 public fullUtilizationRate;
/// @notice Vault information for a given user
mapping(address => Vault) public userVaults;
/// @notice arrays of all BAMM users
address[] public users;
/// @notice mapping of all BAMM users
mapping(address => bool) public isUser;
/// @notice Max Oracle deviation per pair
uint256 public maxOracleDiff = 250;
// #######################################
// ############## CONSTANTS ##############
// #######################################
/// @notice The precision to use and conform to
uint256 public constant PRECISION = 1e18;
/// @notice Percent above which the position is considered insolvent and can be liquidated
uint256 public constant SOLVENCY_THRESHOLD_LIQUIDATION = (980 * PRECISION) / 1000; // 98%
/// @notice Percent at wich the position can be liquidated with the max fee
uint256 public constant SOLVENCY_THRESHOLD_FULL_LIQUIDATION = (990 * PRECISION) / 1000; // 99%
/// @notice Percent above which the position is considered insolvent after a user action
uint256 public constant SOLVENCY_THRESHOLD_AFTER_ACTION = (980 * PRECISION) / 1000; // 98%
/// @notice Protocol's cut of the interest rate
uint256 public constant FEE_SHARE = (10 * 10_000) / 100; // 10%
/// @notice The fee when a liquidation occurs
uint256 public constant LIQUIDATION_FEE = 10_000; // 1%
/// @notice The maximum utility rate for an LP
uint256 public constant MAX_UTILITY_RATE = (PRECISION * 95) / 100; // 95%
/// @notice The minimum liquidity allowed for the pool
uint256 public constant MINIMUM_LIQUIDITY = 1e3;
// #########################################
// ############## Constructor ##############
// #########################################
constructor(bytes memory _encodedBammConstructorArgs) {
(
uint256 _id,
address _pair,
address _fraxswapRouter,
address _fraxswapOracle,
address _variableInterestRateAddress,
uint64 startFullUtilRate
) = abi.decode(_encodedBammConstructorArgs, (uint256, address, address, address, address, uint64));
// fill in state variables
pair = IFraxswapPair(_pair);
pairFactory = IFraxswapFactory(IFraxswapPair(_pair).factory());
token0 = IERC20(pair.token0());
token1 = IERC20(pair.token1());
routerMultihop = IFraxswapRouterMultihop(_fraxswapRouter);
fraxswapOracle = IFraxswapOracle(_fraxswapOracle);
factory = msg.sender;
variableInterestRate = IVariableInterestRate(_variableInterestRateAddress);
fullUtilizationRate = startFullUtilRate;
// Create BAMM ERC20
// Setup name/symbol
string memory ticker;
{
string memory symbol0 = token0.symbol();
string memory symbol1 = token1.symbol();
ticker = string(abi.encodePacked(symbol0, "/", symbol1));
}
string memory name = string(abi.encodePacked("BAMM_", _id.toString(), "_", ticker, " Fraxswap V2"));
string memory symbol = string(abi.encodePacked("BAMM_", ticker));
iBammErc20 = new BAMMERC20(name, symbol);
}
/// @notice Semantic version of this contract
/// @return _major The major version
/// @return _minor The minor version
/// @return _patch The patch version
function version() external pure returns (uint256 _major, uint256 _minor, uint256 _patch) {
return (0, 5, 0);
}
// ############################################
// ############## Lender actions ##############
// ############################################
/// @notice Mint BAMM wrapper tokens with LP tokens
/// @param to Destination address for the wrapper tokens
/// @param lpIn The amount of Fraxswap LP to wrap
/// @return bammOut The amount of BAMM tokens generated
/// @dev Make sure to approve first
function mint(address to, uint256 lpIn) external nonReentrant returns (uint256 bammOut) {
// Sync the LP, then add the interest
(uint112 reserve0, uint112 reserve1, uint256 pairTotalSupply) = _addInterest();
// Calculate the LP to BAMM conversion
uint256 sqrtReserve = Math.sqrt(uint256(reserve0) * reserve1);
uint256 sqrtAmount = (lpIn * sqrtReserve) / pairTotalSupply;
uint256 balance = pair.balanceOf(address(this));
// Take the LP from the sender and mint them BAMM wrapper tokens
uint256 totalSupply_ = iBammErc20.totalSupply();
if (totalSupply_ == 0) {
// At 0 supply, mint initial liquidity and lock it
bammOut = sqrtAmount - MINIMUM_LIQUIDITY;
iBammErc20.mint(address(1), MINIMUM_LIQUIDITY);
} else {
uint256 sqrtBalance = (balance * sqrtReserve) / pairTotalSupply;
if ((sqrtBalance * pairTotalSupply) / sqrtReserve < balance) sqrtBalance += 1;
uint256 sqrtRentedReal = (uint256(sqrtRented) * rentedMultiplier) / PRECISION;
if ((sqrtRentedReal * PRECISION) / rentedMultiplier < uint256(sqrtRented)) sqrtRentedReal += 1;
bammOut = (sqrtAmount * totalSupply_) / (sqrtBalance + sqrtRentedReal);
}
/// Revert if lpIn == 0 as sqrtAmount = 0 and in rounding down small amounts
if (bammOut == 0) revert ZeroLiquidityMinted();
// Transfer LP token to bamm and give `to` the BAMM wrapper tokens
SafeERC20.safeTransferFrom({ token: IERC20(address(pair)), from: msg.sender, to: address(this), value: lpIn });
iBammErc20.mint({ account: ((to == address(0)) ? msg.sender : to), value: bammOut });
emit BAMMMinted({ lender: msg.sender, recipient: to, lpIn: lpIn, bammOut: bammOut });
_emitBAMMState(reserve0, reserve1, pairTotalSupply);
}
/// @notice Redeem BAMM wrapper tokens for LP tokens
/// @param to Destination address for the LP tokens
/// @param bammIn The amount of BAMM tokens to redeem for Fraxswap LP
/// @return lpOut The amount of LP tokens generated
function redeem(address to, uint256 bammIn) external nonReentrant returns (uint256 lpOut) {
// Sync the LP, then add the interest
(uint112 reserve0, uint112 reserve1, uint256 pairTotalSupply) = _addInterest();
// Calculate the BAMM to LP conversion
uint256 sqrtToRedeem;
uint256 sqrtReserve;
{
uint256 balance = pair.balanceOf(address(this));
sqrtReserve = Math.sqrt(uint256(reserve0) * reserve1);
uint256 sqrtBalance = (balance * sqrtReserve) / pairTotalSupply;
uint256 sqrtRentedReal = (uint256(sqrtRented) * rentedMultiplier) / PRECISION;
sqrtToRedeem = (bammIn * (sqrtBalance + sqrtRentedReal)) / iBammErc20.totalSupply();
}
// Burn the BAMM wrapper tokens from the sender and give them LP
if (sqrtToRedeem > 0) {
lpOut = (sqrtToRedeem * pairTotalSupply) / sqrtReserve;
SafeERC20.safeTransfer({
token: IERC20(address(pair)),
to: (to == address(0) ? msg.sender : to),
value: lpOut
});
}
iBammErc20.burn({ account: msg.sender, value: bammIn });
// Max sure the max utility is within acceptable range
if (!_isValidUtilityRate({ reserve0: reserve0, reserve1: reserve1, pairTotalSupply: pairTotalSupply })) {
revert InvalidUtilityRate();
}
emit BAMMRedeemed({ lender: msg.sender, recipient: to, bammIn: bammIn, lpOut: lpOut });
_emitBAMMState(reserve0, reserve1, pairTotalSupply);
}
// ############################################
// ############# Borrower actions #############
// ############################################
/// @notice Execute actions
/// @param action The details of the action to be executed
/// @return vault Ending vault state
function executeActions(Action memory action) public returns (Vault memory vault) {
IFraxswapRouterMultihop.FraxswapParams memory swapParams;
return executeActionsAndSwap({ action: action, swapParams: swapParams });
}
/// @notice Calculate total supply adjustment due to protocol fees in the Fraxswap pair.
/// @dev see: https://github.com/FraxFinance/dev-fraxswap/blob/9744c757f7e51c1deee3f5db50d3aaec495aea01/src/contracts/core/FraxswapPair.sol#L317
/// @param reserve0 The reserves for token0 of the pair
/// @param reserve1 The reserves for token1 of the pair
/// @param totalSupply The total supply of the pair token
/// @return tsAdjustment The total supply adjustment of the lp token due to fees
function _calcMintedSupplyFromPairMintFee(
uint256 reserve0,
uint256 reserve1,
uint256 totalSupply
) internal view returns (uint256 tsAdjustment) {
if (pairFactory.feeTo() != address(0)) {
uint256 kLast = pair.kLast();
if (kLast != 0) {
uint256 rootK = Math.sqrt(uint256(reserve0) * reserve1);
uint256 rootKLast = Math.sqrt(kLast);
if (rootK > rootKLast) {
uint256 num = totalSupply * (rootK - rootKLast);
uint256 denom = (rootK * 5) + rootKLast;
tsAdjustment = num / denom;
}
}
}
}
function _syncVault(
Vault memory _vault,
int256 _rent,
uint112 _reserve0,
uint112 _reserve1,
uint256 _pairTotalSupply
) internal returns (int256 lpTokenAmount, int256 token0Amount, int256 token1Amount) {
// Calculate the amount of LP, token0, and token1
int256 rentedMultiplierAsInt = rentedMultiplier.toInt256(); // gas
int256 sqrtAmountRented = (_rent * rentedMultiplierAsInt) / 1e18;
if (((sqrtAmountRented * 1e18) / rentedMultiplierAsInt) > _rent) sqrtAmountRented -= 1;
lpTokenAmount =
(sqrtAmountRented * _pairTotalSupply.toInt256()) /
int256(Math.sqrt(uint256(_reserve0) * _reserve1));
token0Amount = (int256(uint256(_reserve0)) * lpTokenAmount) / _pairTotalSupply.toInt256();
token1Amount = (int256(uint256(_reserve1)) * lpTokenAmount) / _pairTotalSupply.toInt256();
if (_rent < 0) {
if (((token0Amount * _pairTotalSupply.toInt256()) / _reserve0.toInt256()) > lpTokenAmount) {
token0Amount -= 1;
}
if (((token1Amount * _pairTotalSupply.toInt256()) / _reserve1.toInt256()) > lpTokenAmount) {
token1Amount -= 1;
}
}
// Update the rent and credit the user some token0 and token1
_vault.rented += _rent;
_vault.token0 += token0Amount;
_vault.token1 += token1Amount;
// Update the total rented liquidity
sqrtRented += _rent;
}
/// @dev _rent is positive
function _borrow(
Vault memory _vault,
int256 _rent,
uint112 _reserve0,
uint112 _reserve1,
uint256 _pairTotalSupply
) internal {
if (sqrtRented == 0 && iBammErc20.totalSupply() == 0) revert NoBAMMTokensMinted();
(int256 lpTokenAmount, int256 token0Amount, int256 token1Amount) = _syncVault({
_vault: _vault,
_rent: _rent,
_reserve0: _reserve0,
_reserve1: _reserve1,
_pairTotalSupply: _pairTotalSupply
});
// Transfer LP to the LP contract, then optimistically burn it there to release token0 and token1 to this contract
// The tokens will be given to the borrower later, assuming action.token0Amount and/or action.token1Amount is negative
SafeERC20.safeTransfer({ token: IERC20(address(pair)), to: address(pair), value: uint256(lpTokenAmount) });
pair.burn(address(this));
emit Renting({ user: msg.sender, rent: _rent, token0Amount: token0Amount, token1Amount: token1Amount });
}
/// @dev rent is negative
function _repay(
Vault memory _vault,
int256 _rent,
uint112 _reserve0,
uint112 _reserve1,
uint256 _pairTotalSupply,
uint256 _token0AmountMin,
uint256 _token1AmountMin
) internal returns (uint256 token0ToAddToLp, uint256 token1ToAddToLp) {
(, int256 token0Amount, int256 token1Amount) = _syncVault({
_vault: _vault,
_rent: _rent,
_reserve0: _reserve0,
_reserve1: _reserve1,
_pairTotalSupply: _pairTotalSupply
});
// token0Amount and token1Amount are negative as they subtracted balances from the vault, so we need to convert positive
token0ToAddToLp = uint256(-token0Amount);
token1ToAddToLp = uint256(-token1Amount);
// Avoid sandwich attacks
if ((token0ToAddToLp < _token0AmountMin) || (token1ToAddToLp < _token1AmountMin)) {
revert InsufficientAmount();
}
}
/// @notice Execute actions and also do a swap
/// @param action The details of the action to be executed
/// @param swapParams The details of the swap to be executed
/// @return vault Ending vault state
function executeActionsAndSwap(
Action memory action,
IFraxswapRouterMultihop.FraxswapParams memory swapParams
) public nonReentrant returns (Vault memory vault) {
// Get the existing vault info for the user
vault = userVaults[msg.sender];
// Add to users array if needed.
if (!isUser[msg.sender]) {
isUser[msg.sender] = true;
users.push(msg.sender);
}
// Sync the LP, then add the interest
(uint112 reserve0, uint112 reserve1, uint256 pairTotalSupply) = _addInterest();
// Note if the user is closing the position
if (action.closePosition) {
if (action.rent != 0) revert InvalidRent();
action.rent = -vault.rented;
}
// Rent LP constituent tokens (if specified). Positive rent means borrowing
if (action.rent > 0) {
_borrow({
_vault: vault,
_rent: action.rent,
_reserve0: reserve0,
_reserve1: reserve1,
_pairTotalSupply: pairTotalSupply
});
}
// If specified in the action, add tokens to the vault (vault is modified by reference)
// Positive token0Amount and/or token1Amount means add from vault
if (action.token0Amount > 0 || action.token1Amount > 0) _addTokensToVault({ _vault: vault, _action: action });
// Execute the swap if there are swapParams
if (swapParams.amountIn != 0) {
// Do the swap
_executeSwap(vault, swapParams);
// Swap might have changed the reserves of the pair.
(reserve0, reserve1, pairTotalSupply) = _addInterest();
}
// Return rented LP constituent tokens (if specified) to this contract.
// Negative rent means repaying but not closing.
uint256 token0ToAddToLp;
uint256 token1ToAddToLp;
if (action.rent < 0) {
(token0ToAddToLp, token1ToAddToLp) = _repay({
_vault: vault,
_rent: action.rent,
_reserve0: reserve0,
_reserve1: reserve1,
_pairTotalSupply: pairTotalSupply,
_token0AmountMin: action.token0AmountMin,
_token1AmountMin: action.token1AmountMin
});
}
// Close the position (if specified)
if (action.closePosition) {
// You might have some leftover tokens you can withdraw later if you over-collateralized
action.token0Amount = -vault.token0;
action.token1Amount = -vault.token1;
_addTokensToVault({ _vault: vault, _action: action });
}
// Return rented LP constituent tokens (continued from above)
// This portion recovers the LP and gives it to this BAMM contract
if (token0ToAddToLp > 0) {
// Send token0 and token1 directly to the LP address
SafeERC20.safeTransfer({ token: token0, to: address(pair), value: token0ToAddToLp });
SafeERC20.safeTransfer({ token: token1, to: address(pair), value: token1ToAddToLp });
// Mint repayed LP last, so we know we have enough tokens in the contract
pair.mint(address(this));
emit RentRepaid({
user: msg.sender,
rent: -action.rent,
token0ToAddToLp: token0ToAddToLp,
token1ToAddToLp: token1ToAddToLp,
closePosition: action.closePosition
});
}
// Remove token0 from the vault and give to the user (if specified)
// Negative token0Amount means remove from vault
if (action.token0Amount < 0) {
if (action.to == address(this)) revert CannotWithdrawToSelf();
_moveTokenForVault({
_vault: vault,
_token: token0,
_to: (action.to == address(0) ? msg.sender : action.to),
_tokenAmount: action.token0Amount
});
}
// Remove token1 from the vault and give to the user (if specified)
// Negative token1Amount means remove from vault
if (action.token1Amount < 0) {
if (action.to == address(this)) revert CannotWithdrawToSelf();
_moveTokenForVault({
_vault: vault,
_token: token1,
_to: (action.to == address(0) ? msg.sender : action.to),
_tokenAmount: action.token1Amount
});
}
emit ExecuteAction({
user: msg.sender,
token0: action.token0Amount,
token1: action.token1Amount,
rent: action.rent
});
emit VaultUpdated({ user: msg.sender, token0: vault.token0, token1: vault.token1, rent: vault.rented });
_emitBAMMState(reserve0, reserve1, pairTotalSupply);
// Write the final vault state to storage after all the above operations are completed
userVaults[msg.sender] = vault;
// Make sure the user is still solvent
if (!_solvent(vault, SOLVENCY_THRESHOLD_AFTER_ACTION)) {
revert NotSolvent();
}
// Check max utility after a rent
if (action.rent > 0) {
if (!_isValidUtilityRate({ reserve0: reserve0, reserve1: reserve1, pairTotalSupply: pairTotalSupply })) {
revert InvalidUtilityRate();
}
}
}
function _moveTokenForVault(Vault memory _vault, IERC20 _token, address _to, int256 _tokenAmount) internal {
// NOTE: _tokenAmount is negative when withdrawing from vault and positive when depositing to vault
if (_token == token0) {
_vault.token0 += _tokenAmount;
} else {
// _token == token1
/// @dev _token will always be either token0 or token1
_vault.token1 += _tokenAmount;
}
if (_to == address(this)) {
// deposit
SafeERC20.safeTransferFrom({
token: _token,
from: msg.sender,
to: address(this), // for clarity
value: uint256(_tokenAmount)
});
} else {
// withdrawal (_tokenAmount is currently negative)
SafeERC20.safeTransfer({ token: _token, to: _to, value: uint256(-_tokenAmount) });
}
}
function _emitBAMMState(uint256 reserve0, uint256 reserve1, uint256 pairTotalSupply) internal {
uint256 rentedMultiplier_ = rentedMultiplier;
uint256 balance = pair.balanceOf(address(this));
uint256 sqrtReserve = Math.sqrt(uint256(reserve0) * reserve1);
uint256 sqrtBalance = pairTotalSupply == 0 ? 0 : ((balance * sqrtReserve) / pairTotalSupply);
uint256 sqrtRentedReal = (uint256(sqrtRented) * rentedMultiplier_) / PRECISION;
uint256 utilityRate;
if (sqrtBalance + sqrtRentedReal > 0) {
utilityRate = (uint256(sqrtRentedReal) * PRECISION) / (sqrtBalance + sqrtRentedReal);
}
uint256 interestRate = _getVariableInterestRate(0, utilityRate);
emit BAMMState({
sqrtRentedReal: sqrtRentedReal,
sqrtBalance: sqrtBalance,
rentedMultiplier: rentedMultiplier_,
interestRate: interestRate
});
}
// ############################################
// ############ Liquidator actions ############
// ############################################
// Approximates how much of a token must be sold in a vault for the ratio in the vault to be the same as the ratio in the AMM.
function getMaxSell(
uint256 tokenIn,
uint256 tokenOut,
uint256 reserveIn,
uint256 reserveOut
) public pure returns (uint256 maxSell) {
// Solve x for: (reserveOut-y)/(reserveIn+x) = (tokenOut+y)/(tokenIn-x), (reserveOut-y)*(reserveIn+x)=reserveIn*reserveOut
uint256 prod = Math.sqrt(reserveOut * reserveIn) * Math.sqrt((reserveOut + tokenOut) * (reserveIn + tokenIn));
uint256 minus = reserveIn * tokenOut + reserveOut * reserveIn;
if (prod > minus) maxSell = (prod - minus) / (reserveOut + tokenOut);
}
// Calculates how much of the vault is being repayed, based on the LTV
// Starts at 0.25%, goes to 20% half way and up to 100% at the end.
function repayPercentage(uint256 _ltv) internal pure returns (uint256 _repayPercentage) {
uint256 kink = (SOLVENCY_THRESHOLD_FULL_LIQUIDATION + SOLVENCY_THRESHOLD_LIQUIDATION) / 2;
if (_ltv > SOLVENCY_THRESHOLD_FULL_LIQUIDATION) {
_repayPercentage = 1e18;
} else if (_ltv > kink) {
_repayPercentage = 0.2e18 + (0.8e18 * (_ltv - kink)) / (SOLVENCY_THRESHOLD_FULL_LIQUIDATION - kink);
} else {
_repayPercentage =
0.002e18 +
(0.198e18 * (_ltv - SOLVENCY_THRESHOLD_LIQUIDATION)) /
(kink - SOLVENCY_THRESHOLD_LIQUIDATION);
}
}
/// @notice Auctioned micro-liquidation by doing a small swap and paying back rented liquidity
/// @param user The user to be micro-liquidated
/// @return token0Fee The number of token0 received as liquidation fee
/// @return token1Fee The number of token1 received as liquidation fee
function microLiquidate(address user) external nonReentrant returns (uint256 token0Fee, uint256 token1Fee) {
// Sync the LP, then add the interest
(uint112 reserve0, uint112 reserve1, uint256 pairTotalSupply) = _addInterest();
// Compare the spot price from the reserves to the oracle price. Revert if they are off by too much.
ammPriceCheck(reserve0, reserve1);
// Get the existing vault info for the user
Vault memory vault = userVaults[user];
// Make sure the user is NOT solvent for micro liquidations
uint256 _ltv = ltv(vault);
if (_ltv < SOLVENCY_THRESHOLD_LIQUIDATION) revert("User solvent");
uint256 sqrtToLiquidity;
uint256 _repayPercentage = repayPercentage(_ltv);
if (uint256(vault.token0) > (uint256(vault.token1) * reserve0) / reserve1) {
// Excess token0, swap token0 to token1
uint256 maxSell = getMaxSell(
uint256(vault.token0),
uint256(vault.token1),
uint256(reserve0),
uint256(reserve1)
);
// sellPercentage is twice the repay percentage (capped at 100%)
uint256 sellPercentage = _repayPercentage > 0.498e18 ? 1e18 : 0.004e18 + _repayPercentage * 2;
uint256 sellToken0 = (maxSell * sellPercentage) / PRECISION;
// Cap the amount sold to 1/350 of the total liquidity, to avoid high slippage
if (sellPercentage < 0.1e18 && sellToken0 > reserve0 / 350) {
sellToken0 = reserve0 / 350;
sellPercentage = (sellToken0 * PRECISION) / maxSell;
}
if (sellToken0 > 0) {
uint256 token1Out = getAmountOut(reserve0, reserve1, sellToken0, pair.fee());
if (sellToken0 == reserve0 / 350) {
// At most repay from swapped amount when capped
_repayPercentage = Math.min(
_repayPercentage,
(token1Out * PRECISION) / (token1Out + uint256(vault.token1))
);
}
if (token1Out > 0) {
// Do the swap
SafeERC20.safeTransfer(token0, address(pair), sellToken0);
pair.swap(0, token1Out, address(this), "");
vault.token0 -= int256(sellToken0);
vault.token1 += int256(token1Out);
reserve0 += uint112(sellToken0);
reserve1 -= uint112(token1Out);
emit VaultSwap({ user: user, token0: -int256(sellToken0), token1: int256(token1Out) });
}
}
if (
_ltv < SOLVENCY_THRESHOLD_FULL_LIQUIDATION &&
uint256(vault.token1) * _repayPercentage > (reserve1 * PRECISION) / 25
) _repayPercentage = (reserve1 * PRECISION) / (25 * uint256(vault.token1));
uint256 token1ToLiquidity = (uint256(vault.token1) * _repayPercentage) / PRECISION;
sqrtToLiquidity = Math.sqrt(token1ToLiquidity * ((token1ToLiquidity * reserve0) / reserve1));
} else {
// Excess token1, swap token1 to token0
uint256 maxSell = getMaxSell(
uint256(vault.token1),
uint256(vault.token0),
uint256(reserve1),
uint256(reserve0)
);
// sellPercentage is twice the repay percentage (capped at 100%)
uint256 sellPercentage = _repayPercentage > 0.498e18 ? 1e18 : 0.004e18 + _repayPercentage * 2;
uint256 sellToken1 = (maxSell * sellPercentage) / PRECISION;
// Cap the amount sold to 1/350 of the total liquidity, to avoid high slippage
if (sellPercentage < 0.1e18 && sellToken1 > reserve1 / 350) {
sellToken1 = reserve1 / 350;
sellPercentage = (sellToken1 * PRECISION) / maxSell;
}
if (sellToken1 > 0) {
uint256 token0Out = getAmountOut(reserve1, reserve0, sellToken1, pair.fee());
if (sellToken1 == reserve1 / 350) {
// At most repay from swapped amount when capped
_repayPercentage = Math.min(
_repayPercentage,
(token0Out * PRECISION) / (token0Out + uint256(vault.token0))
);
}
if (token0Out > 0) {
// Do the swap
SafeERC20.safeTransfer(token1, address(pair), sellToken1);
pair.swap(token0Out, 0, address(this), "");
vault.token0 += int256(token0Out);
vault.token1 -= int256(sellToken1);
reserve0 -= uint112(token0Out);
reserve1 += uint112(sellToken1);
emit VaultSwap({ user: user, token0: int256(token0Out), token1: -int256(sellToken1) });
}
}
if (
_ltv < SOLVENCY_THRESHOLD_FULL_LIQUIDATION &&
uint256(vault.token0) * _repayPercentage > (reserve0 * PRECISION) / 25
) _repayPercentage = (reserve0 * PRECISION) / (25 * uint256(vault.token0));
uint256 token0ToLiquidity = (uint256(vault.token0) * _repayPercentage) / PRECISION;
sqrtToLiquidity = Math.sqrt(token0ToLiquidity * ((token0ToLiquidity * reserve1) / reserve0));
}
int256 rentToLiquidity = int256((sqrtToLiquidity * PRECISION) / rentedMultiplier);
if (rentToLiquidity > 0) {
int256 liquidationFee = int256(
_ltv > SOLVENCY_THRESHOLD_FULL_LIQUIDATION
? LIQUIDATION_FEE
: (LIQUIDATION_FEE * (_ltv - SOLVENCY_THRESHOLD_LIQUIDATION)) /
(SOLVENCY_THRESHOLD_FULL_LIQUIDATION - SOLVENCY_THRESHOLD_LIQUIDATION)
);
rentToLiquidity = (rentToLiquidity * (1_000_000 - liquidationFee)) / 1_000_000;
if (rentToLiquidity > vault.rented) rentToLiquidity = vault.rented;
(reserve0, reserve1, pairTotalSupply) = _addInterest();
(, int256 token0Amount, int256 token1Amount) = _syncVault(
vault,
-rentToLiquidity,
reserve0,
reserve1,
pairTotalSupply
);
if (token0Amount < 0 || token1Amount < 0) {
//Mint the LP tokens
SafeERC20.safeTransfer({ token: token0, to: address(pair), value: uint256(-token0Amount) });
SafeERC20.safeTransfer({ token: token1, to: address(pair), value: uint256(-token1Amount) });
pair.mint(address(this));
emit RentRepaid({
user: user,
rent: rentToLiquidity,
token0ToAddToLp: uint256(-token0Amount),
token1ToAddToLp: uint256(-token1Amount),
closePosition: false
});
}
// Give the liquidation fee to the liquidator as a percentage of the liquidated value
token0Fee = uint256((-token0Amount * liquidationFee) / (1_000_000 - liquidationFee));
token1Fee = uint256((-token1Amount * liquidationFee) / (1_000_000 - liquidationFee));
if (int256(token0Fee) > vault.token0 || int256(token1Fee) > vault.token1) {
// When there are not enough tokens for the fee, give all tokens left as fee
token0Fee = uint256(vault.token0);
token1Fee = uint256(vault.token1);
}
vault.token0 -= int256(token0Fee);
vault.token1 -= int256(token1Fee);
if (vault.token0 == 0 || vault.token1 == 0 || (_repayPercentage == 1e18 && ltv(vault) > PRECISION)) {
// Debt restructuring
token0Fee += uint256(vault.token0);
token1Fee += uint256(vault.token1);
vault.token0 = 0;
vault.token1 = 0;
sqrtRented -= vault.rented;
vault.rented = 0;
}
// Send liquidation fee to the liquidator
SafeERC20.safeTransfer(IERC20(address(token0)), msg.sender, token0Fee);
SafeERC20.safeTransfer(IERC20(address(token1)), msg.sender, token1Fee);
emit MicroLiquidate({ user: user, liquidator: msg.sender, token0Fee: token0Fee, token1Fee: token1Fee });
}
emit VaultUpdated({ user: user, token0: vault.token0, token1: vault.token1, rent: vault.rented });
_emitBAMMState(reserve0, reserve1, pairTotalSupply);
// Write the final vault state to storage
if (!_isValidVault(vault)) revert InvalidVault();
userVaults[user] = vault;
}
function getAmountOut(
uint256 reserveIn,
uint256 reserveOut,
uint256 amountIn,
uint256 fee
) internal pure returns (uint256) {
require(amountIn > 0 && reserveIn > 0 && reserveOut > 0); // INSUFFICIENT_INPUT_AMOUNT, INSUFFICIENT_LIQUIDITY
uint256 amountInWithFee = amountIn * fee;
uint256 numerator = amountInWithFee * reserveOut;
uint256 denominator = (reserveIn * 10_000) + amountInWithFee;
return numerator / denominator;
}
// ############################################
// ############# Factory functions ############
// ############################################
/// @notice Update the interest rate contract
/// @param newVariableInterestRate the new interest rate contract
function setVariableInterestRate(address newVariableInterestRate) external {
if (msg.sender != factory) revert NotFactory();
emit NewVariableInterestRate(address(variableInterestRate), newVariableInterestRate);
variableInterestRate = IVariableInterestRate(newVariableInterestRate);
}
/// @notice Update the maximum oracle deviation on the bamm
/// @param newMaxDiff The new max % difference between twap and spot
/// @dev percent in denomination of 1e5
function setMaxOracleDeviation(uint256 newMaxDiff) external {
if (msg.sender != factory) revert NotFactory();
emit NewMaxOracleDiff(maxOracleDiff, newMaxDiff);
maxOracleDiff = newMaxDiff;
}
// ############################################
// ############# External utility #############
// ############################################
/// @notice Accrue interest payments
/// @return reserve0 The LP's reserve0
/// @return reserve1 The LP's reserve1
/// @return totalSupply The LP's totalSupply()
/// @return _rentedMultiplier rentedMultiplier after interest calculation
function addInterest()
external
nonReentrant
returns (uint256 reserve0, uint256 reserve1, uint256 totalSupply, uint256 _rentedMultiplier)
{
(reserve0, reserve1, totalSupply) = _addInterest();
_rentedMultiplier = rentedMultiplier;
_emitBAMMState(reserve0, reserve1, totalSupply);
}
/// @notice Get the interest rate at the specified _utilization
/// @param _deltaTime The time in seconds between now and the previous interest accrual
/// @param _utilization The internal Bamm Utilization represented in 1e18 w/ a max of MAX_UTILITY_RATE
/// @return newRatePerSec The interest rate per second
function _getVariableInterestRate(
uint256 _deltaTime,
uint256 _utilization
) internal returns (uint256 newRatePerSec) {
uint256 utilScaled = (_utilization * 1e5) / MAX_UTILITY_RATE;
(newRatePerSec, fullUtilizationRate) = variableInterestRate.getNewRate(
_deltaTime,
utilScaled,
uint64(fullUtilizationRate)
);
}
/// @notice public view function to view the calculated interest rate at a given utilization
/// @param _utilization The internal Bamm Utilization represented in 1e18 w/ a max of MAX_UTILITY_RATE
/// @return newRatePerSec The interest rate per second
function previewInterestRate(uint256 _utilization) public view returns (uint256 newRatePerSec) {
uint256 utilScaled = (_utilization * 1e5) / MAX_UTILITY_RATE;
uint256 period = block.timestamp - timeSinceLastInterestPayment;
(newRatePerSec, ) = variableInterestRate.getNewRate(period, utilScaled, uint64(fullUtilizationRate));
}
// ############################################
// ################# Internal #################
// ############################################
/// @notice Transfers LP constituent tokens from the user to this contract, and marks it as part of their vault.
/// @param _vault The _vault you are modifying
/// @param _action The _action
/// @dev _vault is passed by reference, so it modified in the caller
function _addTokensToVault(Vault memory _vault, Action memory _action) internal {
// Approve via permit
if (_action.v != 0 && (_action.token0Amount > 0 || _action.token1Amount > 0)) {
// Determine the token of the permit
IERC20 token = _action.token0Amount > 0 ? token0 : token1;
// Do the permit
uint256 amount = _action.approveMax
? type(uint256).max
: uint256(_action.token0Amount > 0 ? _action.token0Amount : _action.token1Amount);
IERC20Permit(address(token)).permit({
owner: msg.sender,
spender: address(this),
value: amount,
deadline: _action.deadline,
v: _action.v,
r: _action.r,
s: _action.s
});
// Clear out v to prevent a potential duplicate failing permit
_action.v = 0;
}
// Add token0 to the vault
if (_action.token0Amount > 0) {
_moveTokenForVault({
_vault: _vault,
_token: token0,
_to: address(this),
_tokenAmount: _action.token0Amount
});
}
// Add token1 to the vault
if (_action.token1Amount > 0) {
_moveTokenForVault({
_vault: _vault,
_token: token1,
_to: address(this),
_tokenAmount: _action.token1Amount
});
}
}
/// @notice Swaps tokens in the users vault
/// @param vault The vault you are modifying
/// @param swapParams Info about the swap. Is modified
/// @dev vault and swapParams are passed by reference, so they modified in the caller
function _executeSwap(Vault memory vault, IFraxswapRouterMultihop.FraxswapParams memory swapParams) internal {
// Make sure the order of the swap is one of two directions
if (
!(swapParams.tokenIn == address(token0) && swapParams.tokenOut == address(token1)) &&
!(swapParams.tokenIn == address(token1) && swapParams.tokenOut == address(token0))
) {
revert IncorrectSwapTokens();
}
// Approve the input token to the router
SafeERC20.safeIncreaseAllowance({
token: IERC20(swapParams.tokenIn),
spender: address(routerMultihop),
value: swapParams.amountIn
});
// Set the recipient to this address
swapParams.recipient = address(this);
// Require an amountOutMinimum to avoid bad swaps
if (swapParams.amountOutMinimum == 0) revert IncorrectAmountOutMinimum();
// Router checks the minAmountOut
/// @dev: ensure swapParams are correct - fat-fingered route data may result in lost funds
/// @dev: we trust the output of the routerMultihop, token transfered in and out are checked in the router
uint256 amountOut = routerMultihop.swap(swapParams);
if (swapParams.tokenIn == address(token0)) {
vault.token0 -= swapParams.amountIn.toInt256();
vault.token1 += amountOut.toInt256();
emit VaultSwap({
user: msg.sender,
token0: -int256(swapParams.amountIn.toInt256()),
token1: int256(amountOut.toInt256())
});
} else {
vault.token1 -= swapParams.amountIn.toInt256();
vault.token0 += amountOut.toInt256();
emit VaultSwap({
user: msg.sender,
token0: int256(amountOut.toInt256()),
token1: -int256(swapParams.amountIn.toInt256())
});
}
}
/// @notice Sync the LP and accrue interest
/// @return reserve0 The LP's reserve0
/// @return reserve1 The LP's reserve1
/// @return pairTotalSupply The LP's totalSupply()
function _addInterest() internal returns (uint112 reserve0, uint112 reserve1, uint256 pairTotalSupply) {
// We need to call sync for Fraxswap pairs first to execute TWAMMs
pair.sync();
// Get the total supply and the updated reserves
(reserve0, reserve1, ) = pair.getReserves();
pairTotalSupply = pair.totalSupply();
pairTotalSupply += _calcMintedSupplyFromPairMintFee(reserve0, reserve1, pairTotalSupply);
// Calculate and accumulate interest if time has passed
uint256 period = block.timestamp - timeSinceLastInterestPayment;
uint256 sqrtRentedAsUint = sqrtRented.toUint256(); // gas
uint256 rentedMultiplier_ = rentedMultiplier; // gas
if (period > 0) {
// If there are outstanding rents, proceed
if (sqrtRentedAsUint > 0) {
// Do the interest calculations
uint256 balance = pair.balanceOf(address(this));
uint256 sqrtBalance = Math.sqrt(
((balance * reserve0) / pairTotalSupply) * ((balance * reserve1) / pairTotalSupply)
);
uint256 sqrtRentedReal = (sqrtRentedAsUint * rentedMultiplier_) / PRECISION;
uint256 utilityRate = (uint256(sqrtRentedReal) * PRECISION) / (sqrtBalance + sqrtRentedReal);
uint256 interestRate = _getVariableInterestRate(period, utilityRate);
uint256 sqrtInterest = (interestRate * period * sqrtRentedAsUint) / (PRECISION);
// Update the rentedMultiplier
// The original lender will get more LP back as their "earnings" when they redeem their BAMM tokens
rentedMultiplier_ = (rentedMultiplier_ * (sqrtInterest + sqrtRentedAsUint)) / sqrtRentedAsUint;
// Give the fee recipient their cut of the fee, directly as BAMM tokens
{
address feeTo = IBAMMFactory(factory).feeTo();
if (feeTo != address(0)) {
// accrue fee
uint256 fee = (sqrtInterest * rentedMultiplier_ * FEE_SHARE) / (10_000 * PRECISION);
uint256 feeMintAmount = (fee * iBammErc20.totalSupply()) /
(sqrtBalance + ((sqrtRentedAsUint * rentedMultiplier_) / PRECISION));
iBammErc20.mint(feeTo, feeMintAmount);
}
}
// Store updated rentedMultiplier
rentedMultiplier = rentedMultiplier_;
}
// Update the timeSinceLastInterestPayment
timeSinceLastInterestPayment = block.timestamp;
}
}
function _isValidVault(Vault memory vault) internal pure returns (bool) {
if (vault.rented < 0 || vault.token0 < 0 || vault.token1 < 0) {
// A vault should never end with negative balances
return false;
} else if (vault.rented > 0 && (vault.token0 == 0 || vault.token1 == 0)) {
// If a vault has outstanding rent, both token0 and token1 must not be 0
return false;
}
return true;
}
function ltv(Vault memory vault) internal view returns (uint256) {
if (vault.rented == 0) return 0;
return (uint256(vault.rented) * rentedMultiplier) / Math.sqrt(uint256(vault.token0 * vault.token1));
}
/// @dev Helper to return Vault struct over tuple
function getUserVault(address user) external view returns (Vault memory vault) {
vault = userVaults[user];
}
/// @notice Is the vault solvent?
/// @param vault The vault to check
/// @param solvencyThreshold If vault ltv is at least this value, it is deemed insolvent
/// @return bool If the vault is solvent
function _solvent(Vault memory vault, uint256 solvencyThreshold) internal view returns (bool) {
return _isValidVault(vault) && (vault.rented == 0 || ltv(vault) < solvencyThreshold);
}
function usersArray() external view returns (address[] memory) {
return users;
}
function usersLength() external view returns (uint256) {
return users.length;
}
/// @param reserve0 The LP's reserve0
/// @param reserve1 The LP's reserve1
/// @param pairTotalSupply The LP's totalSupply
/// @return current utility rate
function _currentUtilityRate(
uint112 reserve0,
uint112 reserve1,
uint256 pairTotalSupply
) internal view returns (uint256) {
uint256 sqrtRentedAsUint = sqrtRented.toUint256(); // gas
if (sqrtRentedAsUint == 0) {
return 0;
}
uint256 balance = pair.balanceOf(address(this));
uint256 sqrtBalance = Math.sqrt(
((balance * reserve0) / pairTotalSupply) * ((balance * reserve1) / pairTotalSupply)
);
uint256 sqrtRentedReal = (sqrtRentedAsUint * rentedMultiplier) / PRECISION;
uint256 utilityRate = (sqrtRentedReal * PRECISION) / (sqrtBalance + sqrtRentedReal);
return utilityRate;
}
/// @dev Returns true if 0 <= {all outstanding rent} < MAX_UTILITY_RATE
function _isValidUtilityRate(
uint112 reserve0,
uint112 reserve1,
uint256 pairTotalSupply
) internal view returns (bool) {
if (sqrtRented < 0) {
return false;
}
if (
_currentUtilityRate({ reserve0: reserve0, reserve1: reserve1, pairTotalSupply: pairTotalSupply }) >
MAX_UTILITY_RATE
) {
return false;
}
return true;
}
/// @notice Compare the spot price from the reserves to the oracle price. Revert if they are off by too much.
/// @param reserve0 The LP's reserve0
/// @param reserve1 The LP's reserve1
function ammPriceCheck(uint112 reserve0, uint112 reserve1) internal view {
// 30 minutes and max 2048 blocks
(uint256 result0, uint256 result1) = fraxswapOracle.getPrice({
pool: pair,
period: 60 * 30,
rounds: 11,
maxDiffPerc: 10_000
});
result0 = 1e68 / result0;
uint256 spotPrice = (uint256(reserve0) * 1e34) / reserve1;
// Check the price differences and revert if they are too much
uint256 diff = (spotPrice > result0 ? spotPrice - result0 : result0 - spotPrice);
if ((diff * 10_000) / result0 > maxOracleDiff) {
revert OraclePriceDeviated();
}
diff = (spotPrice > result1 ? spotPrice - result1 : result1 - spotPrice);
if ((diff * 10_000) / result1 > maxOracleDiff) {
revert OraclePriceDeviated();
}
}
}
// .,,.
// ,;;<!;;;,'``<!!!!;,
// =c,`<!!!!!!!!!>;``<!!!!>,
// ,zcc;$$c`'!!!!!!!!!,;`<!!!!!>
// . $$$;F?b`!'!!!!!!!, ;!!!!>
// ;!; `",,,`"b " ;!!!!!!!! .!!!!!!;
// ;!>>;; r' :<!!!!!!!''''```,,,,,,,,,,,,.
// ;!>;!>; ""):!```.,,,nmMMb`'!!!!!!!!!!!!!!!!!!!!!'''`,,,,;;;
// <!!;;;;;''.,,ndMr'4MMMMMMMMb,``'''''''''''''',,;;<!!!!!!!!'
// !!!'''''. "TMMMMMPJ,)MMMMMMMMMMMMMMMMMnmnmdM !!!!!!!!!!!!'
// `.,nMbmnm $e."MMM J$ MMMMMMMMMMMMMMMMMMMMMP `!!!!!!!''
// .MMMMMMMM>$$$b 4 c$$>4MMMMMMM?MMMMM"MMM4M",M
// 4MMMMMMM>$$$P "?$>,MMMMMP,dMMM",;M",",nMM
// 'MMMMMMM $$Ez$$$$$$>JMMM",MMMP .' .c nMMMMM
// 4Mf4MMP $$$$$$$$P"uP",uP"",zdc,'$$F;MMMfP
// "M'MM d$$",="=,cccccc$$$$$$$$$$$P MMM"
// \/\"f.$$$cb ,b$$$$$$$" -."?$$$$ dP)"
// `$c, $$$$$$$$$$",,,,"$$ "J$$$'J" ,c
// `"$ $$$$$$P)3$ccd$,,$$$$$$$$$'',z$$F
// `$$$$$$$`?$$$$$$"$$$$$$$P,c$P"
// "?$$$$;=,""',c$$$$$$$"
// `"??bc,,z$$$$PF""
// .,,,,,,,,. 4c,,,,,
// 4$$$$$$$$$$$??$bd$$$$$P";!' ccd$$PF" c,
// 4$$$$$$$$$P.d$$$$$?$P"<!! z$$$P",c$$$$$$$b.
// `$$c,""??".$$$$$?4P';!!! J$$P'z$$$$$$$$$$P"
// `?$$$$L z$$$$$$ C ,<!! $$$"J$$$?$$$PF"""
// `?$$$".$$$$$$$F ;!!! zP" J$$$$-;;;
// ,$$%z$$$$$$$";!!!' d$L`z?$?$" <!';
// ..'$$"-",nr"$" !!!!! $$$$;3L?c"? `<>`;
// "C": \'MMM ";!!!!!'<$$$$$ !! <;
// <`.dMMT4bn`.!';! ???$$F !!! <>
// !!>;`T",;- !! emudMMb.?? <!!! <>
// !<!!!!,,`''!!! `TMMMP",!!!> !!!!!.`!
// !!!!!!!!!>.`'!`:MMM.<!!!! !!!!!!>`!;
// !!!!!!`<!!!!!;,,`TT" <!!!, ;!'.`'!!! <>
// '!''<! ,.`!!!``!!!!'`!!! '! !! <!:`'!!.`!;
// ' ?",`! dc''`,r;`,- ` ;!!!`!!!;`!!:`!>
// cbccc$$$$c$$$bd$$bcd `!!! <;'!;`!! !!>
// <$$$$$$$$$$$$$?)$$P" `!!! <! ! !!>`!!
// d$$$$$$P$$?????"" `!!> !> ,!!',!!
// .$$$$$$ cccc$$$ `!!>`!!!!! !!!
// "$C" ",d$$$$$$$$ `!!:`!!!! !!!
// ` `,c$$$$"" <!!;,,,<!!!
// `!!!!!'`
// `
// ------------------------------------------------
// https://asciiart.website/index.php?art=cartoons/flintstones// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.19;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ========================== BAMMUIHelper ============================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { IFraxswapPair } from "dev-fraxswap/src/contracts/core/interfaces/IFraxswapPair.sol";
import { IFraxswapRouterMultihop } from "dev-fraxswap/src/contracts/periphery/interfaces/IFraxswapRouterMultihop.sol";
import { Math } from "dev-fraxswap/src/contracts/core/libraries/Math.sol";
import { VariableInterestRate } from "src/contracts/VariableInterestRate.sol";
import { BAMM } from "./BAMM.sol";
contract BAMMUIHelper {
uint256 constant PRECISION = 1e18;
struct BAMMState {
uint256 reserve0;
uint256 reserve1;
uint256 totalSupply;
uint256 rentedMultiplier;
uint256 sqrtBalance;
uint256 sqrtRentedReal;
uint256 utilityRate;
uint256 ratePerSec;
uint256 bammTokenTotalSupply;
uint256 sqrtPerBAMMToken;
uint256 sqrtPerLPToken;
uint256 token0PerSqrt;
uint256 token1PerSqrt;
}
function getBAMMState(BAMM bamm) public returns (BAMMState memory state) {
(state.reserve0, state.reserve1, state.totalSupply, state.rentedMultiplier) = bamm.addInterest();
if (state.totalSupply > 0) {
uint256 balance = bamm.pair().balanceOf(address(bamm));
state.sqrtBalance = Math.sqrt(
((balance * state.reserve0) / state.totalSupply) * ((balance * state.reserve1) / state.totalSupply)
);
state.sqrtRentedReal = (uint256(bamm.sqrtRented()) * state.rentedMultiplier) / PRECISION;
if (state.sqrtRentedReal > 0) {
state.utilityRate = (state.sqrtRentedReal * PRECISION) / (state.sqrtBalance + state.sqrtRentedReal);
}
uint256 utilScaled = (state.utilityRate * 1e5) / 0.9e18;
uint256 period = block.timestamp - bamm.timeSinceLastInterestPayment();
(state.ratePerSec, ) = VariableInterestRate(address(bamm.variableInterestRate())).getNewRate(
period,
utilScaled,
uint64(bamm.fullUtilizationRate())
);
state.bammTokenTotalSupply = bamm.iBammErc20().totalSupply();
if (state.bammTokenTotalSupply > 0) {
state.sqrtPerBAMMToken =
((state.sqrtBalance + state.sqrtRentedReal) * PRECISION) /
state.bammTokenTotalSupply;
}
uint256 _sqrtK = Math.sqrt(state.reserve0 * state.reserve1);
state.sqrtPerLPToken = (_sqrtK * PRECISION) / state.totalSupply;
state.token0PerSqrt = (state.reserve0 * PRECISION) / _sqrtK;
state.token1PerSqrt = (state.reserve1 * PRECISION) / _sqrtK;
}
}
struct BAMMVault {
int256 token0;
int256 token1;
int256 rented;
uint256 rentedReal;
int256 rentedToken0;
int256 rentedToken1;
uint256 ltv;
int256 value0;
int256 value1;
int256 leverage0;
int256 leverage1;
bool solvent;
bool solventAfterAction;
}
function getVaultState(BAMM bamm, address user) public returns (BAMMVault memory vault) {
(int256 token0, int256 token1, int256 rented) = bamm.userVaults(user);
return getVaultState(bamm, token0, token1, rented);
}
function getVaultState(
BAMM bamm,
int256 token0,
int256 token1,
int256 rented
) public returns (BAMMVault memory vault) {
(uint256 reserve0, uint256 reserve1, , uint256 rentedMultiplier) = bamm.addInterest();
vault.token0 = token0;
vault.token1 = token1;
vault.rented = rented;
vault.rentedReal = (uint256(vault.rented) * rentedMultiplier) / PRECISION;
uint256 sqrtK = Math.sqrt(reserve0 * reserve1);
if (sqrtK > 0) {
vault.rentedToken0 = int256((reserve0 * vault.rentedReal) / sqrtK);
vault.rentedToken1 = int256((reserve1 * vault.rentedReal) / sqrtK);
}
vault.value0 = (token0 + (token1 * int256(reserve0)) / int256(reserve1) - 2 * int256(vault.rentedToken0));
vault.value1 = (token1 + (token0 * int256(reserve1)) / int256(reserve0) - 2 * int256(vault.rentedToken1));
if (vault.token0 > 0 && vault.token1 > 0) {
vault.ltv =
(uint256(vault.rented) * rentedMultiplier) /
Math.sqrt(uint256(vault.token0) * uint256(vault.token1));
vault.leverage0 = ((token0 - int256(vault.rentedToken0)) * 1e18) / vault.value0;
vault.leverage1 = ((token1 - int256(vault.rentedToken1)) * 1e18) / vault.value1;
}
vault.solvent = vault.rented == 0 || vault.ltv < bamm.SOLVENCY_THRESHOLD_LIQUIDATION();
vault.solventAfterAction = vault.rented == 0 || vault.ltv < bamm.SOLVENCY_THRESHOLD_LIQUIDATION();
}
function calcZap(
BAMM bamm,
int256 token0,
int256 token1,
int256 rented,
int256 targetLTV,
int256 targetVaultRatio
) external returns (int256 rent, int256 swap) {
CalcZapData memory d;
(d.reserve0, d.reserve1, d.pairTotalSupply, d.rentedMultiplier) = bamm.addInterest();
d.fee = bamm.pair().fee();
d.sqrtK = int256(Math.sqrt(d.reserve0 * d.reserve1));
int256 target0 = 1e18;
int256 target1 = int256((uint256(targetVaultRatio) * d.reserve1) / d.reserve0);
int256 targetRent = (targetLTV * int256(Math.sqrt(uint256(target0 * target1)))) / 1e18;
int256 targetValue = target0 +
int256((uint256(target1) * d.reserve0) / d.reserve1) -
(2 * targetRent * int256(d.reserve0)) /
d.sqrtK;
for (uint256 i = 0; i < 20; ++i) {
d.rentedReal = (rented * int256(d.rentedMultiplier)) / 1e18 + rent;
d.resultToken0 = token0;
d.resultToken1 = token1;
if (rent > 0) {
d.resultToken0 += (rent * int256(d.reserve0)) / d.sqrtK;
d.resultToken1 += (rent * int256(d.reserve1)) / d.sqrtK;
}
if (swap < 0) {
// swap token0 for token1
d.resultToken0 += swap;
d.resultToken1 += int256(getAmountOut(d.reserve0, d.reserve1, d.fee, uint256(-swap)));
} else if (swap > 0) {
// swap token1 for token0
d.resultToken0 += swap;
d.resultToken1 -= int256(getAmountIn(d.reserve1, d.reserve0, d.fee, uint256(swap)));
}
if (rent < 0) {
int256 newReserve0 = int256(d.reserve0) + token0 - d.resultToken0;
int256 newReserve1 = int256(d.reserve1) + token1 - d.resultToken1;
int256 newSqrt = int256(Math.sqrt(uint256(newReserve0 * newReserve1)));
d.resultToken0 += (rent * newReserve0) / newSqrt;
d.resultToken1 += (rent * newReserve1) / newSqrt;
}
d.value =
d.resultToken0 +
(d.resultToken1 * int256(d.reserve0)) /
int256(d.reserve1) -
(2 * d.rentedReal * int256(d.reserve0)) /
d.sqrtK;
if (i % 2 == 0) rent = rent + ((targetRent * d.value) / targetValue) - d.rentedReal;
else swap = swap + ((target0 * d.value) / targetValue) - d.resultToken0;
}
}
function calcRentForLTV(int256 token0, int256 token1, int256 targetLTV) public pure returns (int256 rent) {
// Solve rent*PRECISION/sqrt((token0+rent)*(token1+rent))=targetLTV;
int256 PREC = 1e18;
rent =
(targetLTV *
int256(
Math.sqrt(
uint256(
targetLTV *
targetLTV *
(token0 + token1) *
(token0 + token1) -
4 *
token0 *
token1 *
(targetLTV * targetLTV - PREC * PREC)
)
)
) -
targetLTV *
targetLTV *
(token0 + token1)) /
(2 * (targetLTV * targetLTV - PREC * PREC));
}
function calcRentForLTV(
BAMM bamm,
int256 token0,
int256 token1,
int256 rented,
int256 targetLTV
) public returns (int256 rent) {
BAMMState memory state = getBAMMState(bamm);
BAMMVault memory vault = getVaultState(bamm, token0, token1, rented);
int256 netToken0 = vault.token0 - int256(vault.rentedToken0);
int256 netToken1 = vault.token1 - int256(vault.rentedToken1);
int256 sqrtK = int256(Math.sqrt(state.reserve0 * state.reserve1));
if (netToken0 < 0) {
rent =
(((netToken1 * sqrtK) / int256(state.reserve1)) *
calcRentForLTV(
1e18,
(1e18 * ((netToken0 * int256(state.reserve1)) / int256(state.reserve0))) / netToken1,
targetLTV
)) /
1e18;
} else if (netToken1 < 0) {
rent =
(((netToken0 * sqrtK) / int256(state.reserve0)) *
calcRentForLTV(
1e18,
(1e18 * ((netToken1 * int256(state.reserve0)) / int256(state.reserve1))) / netToken0,
targetLTV
)) /
1e18;
}
}
uint256 public constant MAX_WITHDRAW_BORROW_LTV = 0.66666666666666666e18;
int256 public constant MAX_WITHDRAW_BAMM_LTV = 0.97999e18;
uint256 public constant TARGET_UTILITY_RATE = 0.949999e18;
function getMaxWithdraw(
BAMM bamm,
int256 token0,
int256 token1,
int256 rented
) public returns (int256 maxWithdrawToken0, int256 maxWithdrawToken1) {
BAMMState memory state = getBAMMState(bamm);
int256 rentedReal = (rented * int256(state.rentedMultiplier)) / 1e18;
int256 netToken0 = token0 -
(int256(state.reserve0) * rentedReal) /
int256(Math.sqrt(state.reserve0 * state.reserve1));
int256 netToken1 = token1 -
(int256(state.reserve1) * rentedReal) /
int256(Math.sqrt(state.reserve0 * state.reserve1));
{
int256 minToken0;
if (netToken1 > 0) {
minToken0 = -int256(
(((uint256(netToken1) * MAX_WITHDRAW_BORROW_LTV) / 1e18) * state.reserve0) / state.reserve1
);
} else if (netToken0 > 0) {
minToken0 = int256(
(((uint256(-netToken1) * 1e18) / MAX_WITHDRAW_BORROW_LTV) * state.reserve0) / state.reserve1
);
}
int256 rent = calcRentForLTV(bamm, minToken0, netToken1, 0, MAX_WITHDRAW_BAMM_LTV);
int256 maxRentReal = int256(
(TARGET_UTILITY_RATE * (state.sqrtRentedReal + state.sqrtBalance)) / 1e18 - state.sqrtRentedReal
);
if (rent > maxRentReal + rentedReal) {
rent = maxRentReal + rentedReal;
int256 token0Rented = (rent * int256(state.reserve0)) /
int256(Math.sqrt(state.reserve0 * state.reserve1));
int256 token1AfterRent = netToken1 +
(rent * int256(state.reserve1)) /
int256(Math.sqrt(state.reserve0 * state.reserve1));
if (rent ** 2 < (type(int256).max / 1e18)) {
minToken0 =
int256(
(((uint256(rent) * uint256(rent) * 1e18) / uint256(MAX_WITHDRAW_BAMM_LTV)) * 1e18) /
uint256(MAX_WITHDRAW_BAMM_LTV)
) /
token1AfterRent -
token0Rented;
} else {
minToken0 = netToken0;
}
}
maxWithdrawToken0 = minToken0 - netToken0;
}
{
int256 minToken1;
if (netToken0 > 0) {
minToken1 = -int256(
(((uint256(netToken0) * MAX_WITHDRAW_BORROW_LTV) / 1e18) * state.reserve1) / state.reserve0
);
} else if (netToken1 > 0) {
minToken1 = int256(
(((uint256(-netToken0) * 1e18) / MAX_WITHDRAW_BORROW_LTV) * state.reserve1) / state.reserve0
);
}
int256 rent = calcRentForLTV(bamm, netToken0, minToken1, 0, MAX_WITHDRAW_BAMM_LTV);
int256 maxRentReal = int256(
(TARGET_UTILITY_RATE * (state.sqrtRentedReal + state.sqrtBalance)) / 1e18 - state.sqrtRentedReal
);
if (rent > maxRentReal + rentedReal) {
rent = maxRentReal + rentedReal;
int256 token1Rented = (rent * int256(state.reserve1)) /
int256(Math.sqrt(state.reserve0 * state.reserve1));
int256 token0AfterRent = netToken0 +
(rent * int256(state.reserve0)) /
int256(Math.sqrt(state.reserve0 * state.reserve1));
if (rent ** 2 < (type(int256).max / 1e18)) {
minToken1 =
int256(
(((uint256(rent) * uint256(rent) * 1e18) / uint256(MAX_WITHDRAW_BAMM_LTV)) * 1e18) /
uint256(MAX_WITHDRAW_BAMM_LTV)
) /
token0AfterRent -
token1Rented;
} else {
minToken1 = netToken1;
}
}
maxWithdrawToken1 = minToken1 - netToken1;
}
}
struct ChartPoint {
int256 price;
int256 value;
int256 blValue; // Value when using regular B&L.
int256 rentedToken0;
int256 rentedToken1;
}
// Price of token1 in token0, value of the vault in token0
function getChartData0(BAMM bamm, address user) external returns (ChartPoint[1000] memory points) {
BAMMState memory state = getBAMMState(bamm);
BAMMVault memory vault = getVaultState(bamm, user);
int256 currentPrice = int256((state.reserve0 * 1e18) / state.reserve1);
int256 price = 1e18 / 1000;
uint256 sqrtK = Math.sqrt(state.reserve0 * state.reserve1);
for (uint256 i = 0; i < 1000; ++i) {
points[i].price = (currentPrice * price) / 1e18;
uint256 newReserve0 = (state.reserve0 * Math.sqrt(uint256(price * 1e18))) / 1e18;
uint256 newReserve1 = (state.reserve1 * 1e18) / Math.sqrt(uint256(price * 1e18));
int256 rentedToken0 = int256((newReserve0 * vault.rentedReal) / sqrtK);
int256 rentedToken1 = int256((newReserve1 * vault.rentedReal) / sqrtK);
points[i].value =
vault.token0 -
rentedToken0 +
((vault.token1 - rentedToken1) * int256(newReserve0)) /
int256(newReserve1);
points[i].blValue =
vault.token0 -
vault.rentedToken0 +
((vault.token1 - vault.rentedToken1) * int256(newReserve0)) /
int256(newReserve1);
if (points[i].blValue < 0) points[i].blValue = 0;
price = (price * 1_008_046_583) / 1_000_000_000; // 3000^(1/999)
points[i].rentedToken0 = rentedToken0;
points[i].rentedToken1 = rentedToken1;
}
}
// Price of token0 in token1, value of the vault in token1
function getChartData1(BAMM bamm, address user) external returns (ChartPoint[1000] memory points) {
BAMMState memory state = getBAMMState(bamm);
BAMMVault memory vault = getVaultState(bamm, user);
int256 currentPrice = int256((state.reserve1 * 1e18) / state.reserve0);
int256 price = 1e18 / 1000;
uint256 sqrtK = Math.sqrt(state.reserve0 * state.reserve1);
for (uint256 i = 0; i < 1000; ++i) {
points[i].price = (currentPrice * price) / 1e18;
uint256 newReserve0 = (state.reserve0 * 1e18) / Math.sqrt(uint256(price * 1e18));
uint256 newReserve1 = (state.reserve1 * Math.sqrt(uint256(price * 1e18))) / 1e18;
int256 rentedToken0 = int256((newReserve0 * vault.rentedReal) / sqrtK);
int256 rentedToken1 = int256((newReserve1 * vault.rentedReal) / sqrtK);
points[i].value =
vault.token1 -
rentedToken1 +
((vault.token0 - rentedToken0) * int256(newReserve1)) /
int256(newReserve0);
points[i].blValue =
vault.token1 -
vault.rentedToken1 +
((vault.token0 - vault.rentedToken0) * int256(newReserve1)) /
int256(newReserve0);
if (points[i].blValue < 0) points[i].blValue = 0;
price = (price * 1_008_046_583) / 1_000_000_000; // 3000^(1/999)
points[i].rentedToken0 = rentedToken0;
points[i].rentedToken1 = rentedToken1;
}
}
struct CalcZapData {
uint256 reserve0;
uint256 reserve1;
uint256 pairTotalSupply;
uint256 rentedMultiplier;
uint256 fee;
int256 sqrtK;
int256 rentedReal;
int256 resultToken0;
int256 resultToken1;
int256 value;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(
uint256 reserveIn,
uint256 reserveOut,
uint256 fee,
uint256 amountIn
) internal pure returns (uint256) {
uint256 amountInWithFee = amountIn * fee;
uint256 numerator = amountInWithFee * reserveOut;
uint256 denominator = (reserveIn * 10_000) + amountInWithFee;
return numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(
uint256 reserveIn,
uint256 reserveOut,
uint256 fee,
uint256 amountOut
) internal pure returns (uint256) {
uint256 numerator = reserveIn * amountOut * 10_000;
uint256 denominator = (reserveOut - amountOut) * fee;
return (numerator / denominator) + 1;
}
/// @notice Given a token you want to borrow, how much rent do you need.
/// @notice Modifies state because the TWAMMs and interest need to be synced.
/// @param token Address of the token you want to borrow
/// @param amountOutDesired How much of the token you want to borrow
/// @return rent The value of "rent" you should use in executeActions's Action
/// @return lpUnwound Informational: the amount of BAMM LP that was unwound to release your desired token
/// @return amountOutOtherToken How much of the other token was also released in the LP unwinding.
/// You can swap it out for even more of your desired token if you want with executeActionsAndSwap's swapParams
function calcRent(
BAMM bamm,
address token,
uint256 amountOutDesired
) external returns (int256 rent, uint256 lpUnwound, uint256 amountOutOtherToken) {
// Sync the LP, then add the interest
(uint256 reserve0, uint256 reserve1, uint256 pairTotalSupply, uint256 rentedMultiplier) = bamm.addInterest();
// Get the price (in terms of the other token) of your desired token
{
uint256 reserveDesired;
uint256 reserveOther;
if (token == address(bamm.token0())) {
reserveDesired = reserve0;
reserveOther = reserve1;
} else if (token == address(bamm.token1())) {
reserveDesired = reserve1;
reserveOther = reserve0;
} else {
revert InvalidToken();
}
// Calculate the amount of the other token, as well as the LP
// Use substitution to avoid rounding errors
lpUnwound = (amountOutDesired * pairTotalSupply) / reserveDesired;
if ((lpUnwound * reserveDesired) / pairTotalSupply < amountOutDesired) lpUnwound += 1;
amountOutOtherToken = (lpUnwound * reserveOther) / pairTotalSupply;
}
uint256 sqrtAmountRented = (Math.sqrt(uint256(reserve0) * reserve1) * lpUnwound) / pairTotalSupply;
if ((sqrtAmountRented * pairTotalSupply) / Math.sqrt(uint256(reserve0) * reserve1) < lpUnwound) {
sqrtAmountRented += 1;
}
uint256 rentedMultiplier_ = rentedMultiplier; // gas
rent = int256((sqrtAmountRented * 1e18) / rentedMultiplier_);
if ((uint256(rent) * rentedMultiplier_) / 1e18 < sqrtAmountRented) rent += 1;
}
/// @notice public view function to view the calculated interest rate at a given utilization
/// @dev see: https://github.com/FraxFinance/dev-fraxswap/blob/9744c757f7e51c1deee3f5db50d3aaec495aea01/src/contracts/core/FraxswapPair.sol#L317
/// @param reserve0 The reserves for token0 of the pair
/// @param reserve1 The reserves for token1 of the pair
/// @return tsAdjustment The total supply adjustment of the lp token due to fees
function _calcMintedSupplyFromPairMintFee(
BAMM bamm,
uint256 reserve0,
uint256 reserve1,
uint256 totalSupply
) internal view returns (uint256 tsAdjustment) {
uint256 k = Math.sqrt(uint256(reserve0) * reserve1);
IFraxswapPair pair = bamm.pair();
uint256 kLast = pair.kLast();
if (kLast != 0) {
kLast = Math.sqrt(kLast);
if (k > kLast) {
uint256 num = totalSupply * (k - kLast);
uint256 denom = (k * 5) + kLast;
tsAdjustment = num / denom;
}
}
}
error InvalidToken();
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { SSTORE2 } from "solmate/src/utils/SSTORE2.sol";
import { BytesLib } from "solidity-bytes-utils/contracts/BytesLib.sol";
import { Ownable, Ownable2Step } from "@openzeppelin/contracts/access/Ownable2Step.sol";
import { IFraxswapPair } from "dev-fraxswap/src/contracts/core/interfaces/IFraxswapPair.sol";
import "src/contracts/interfaces/IBAMMFactory.sol";
import { BAMM } from "../BAMM.sol";
contract BAMMFactory is IBAMMFactory, Ownable2Step {
IFraxswapFactory public immutable iFraxswapFactory;
address public immutable routerMultihop;
address public immutable fraxswapOracle;
address public variableInterestRate;
/// @dev state updated on createBamm()
mapping(address bamm => bool exists) public isBamm;
mapping(address pair => address bamm) public pairToBamm;
address[] public bamms;
/// @dev storage for contract exceeding the size limit by splitting the creation code into two
address private contractAddress1;
address private contractAddress2;
address public feeTo;
constructor(
address _fraxswapFactory,
address _routerMultihop,
address _fraxswapOracle,
address _variableInterestRate,
address _feeTo
) Ownable(msg.sender) {
iFraxswapFactory = IFraxswapFactory(_fraxswapFactory);
routerMultihop = _routerMultihop;
fraxswapOracle = _fraxswapOracle;
variableInterestRate = _variableInterestRate;
feeTo = _feeTo;
}
/// @notice work-around to set creation code which exceeds the contract size limit
function setCreationCode(bytes calldata _creationCode) external onlyOwner {
require(contractAddress1 == address(0));
if (_creationCode.length > 20_500) {
bytes memory firstHalf = BytesLib.slice(_creationCode, 0, 20_500);
bytes memory secondHalf = BytesLib.slice(_creationCode, 20_500, _creationCode.length - 20_500);
contractAddress1 = SSTORE2.write(firstHalf);
contractAddress2 = SSTORE2.write(secondHalf);
} else {
contractAddress1 = SSTORE2.write(_creationCode);
}
}
/// @notice Semantic version of this contract
/// @return _major The major version
/// @return _minor The minor version
/// @return _patch The patch version
function version() external pure returns (uint256 _major, uint256 _minor, uint256 _patch) {
return (0, 4, 1);
}
/// @notice Create a BAMM for a given FraxswapPair
/// @notice Incompatible for fee-on-transfer tokens
/// @param _pair Address of the Fraxswap-created token pair
/// @return bamm Address of the newly-created BAMM contract
function createBamm(address _pair) external returns (address bamm) {
// require pair to have been created from factory
address token0 = IFraxswapPair(_pair).token0();
address token1 = IFraxswapPair(_pair).token1();
address getPair = iFraxswapFactory.getPair(token0, token1);
if (_pair != getPair) revert PairNotFromFraxswapFactory();
// revert if bamm exists for pair
if (pairToBamm[_pair] != address(0)) revert BammAlreadyCreated();
uint256 id = bamms.length;
// Get init code from creation code
bytes memory creationCode;
if (contractAddress2 != address(0)) {
creationCode = BytesLib.concat(SSTORE2.read(contractAddress1), SSTORE2.read(contractAddress2));
} else {
creationCode = SSTORE2.read(contractAddress1);
}
bytes memory constArgs = abi.encode(
id,
_pair,
routerMultihop,
fraxswapOracle,
variableInterestRate,
30 * 2 * 158_247_046
);
bytes memory initCode = abi.encodePacked(creationCode, abi.encode(constArgs));
// Get Salt
bytes32 salt = keccak256(abi.encode(id, _pair, routerMultihop, fraxswapOracle));
/// @solidity memory-safe-assembly
uint256 size;
assembly {
bamm := create2(0, add(initCode, 32), mload(initCode), salt)
size := extcodesize(bamm)
}
if (bamm == address(0)) revert Create2Failed();
if (size == 0) revert Create2Failed();
// Update state
isBamm[bamm] = true;
pairToBamm[_pair] = bamm;
bamms.push(bamm);
emit BammCreated(_pair, bamm);
}
function bammsArray() external view returns (address[] memory) {
return bamms;
}
function bammsLength() external view returns (uint256) {
return bamms.length;
}
function setFeeTo(address _feeTo) external onlyOwner {
feeTo = _feeTo;
}
function setVariableInterestRate(address newVariableInterestRate) external onlyOwner {
variableInterestRate = newVariableInterestRate;
}
function setBAMMVariableInterestRate(address bamm, address newVariableInterestRate) external onlyOwner {
if (!isBamm[bamm]) revert NotBAMM();
BAMM(bamm).setVariableInterestRate(newVariableInterestRate);
}
function setBammMaxOracleDiff(address bamm, uint256 newMaxOracleDiff) external onlyOwner {
if (!isBamm[bamm]) revert NotBAMM();
BAMM(bamm).setMaxOracleDeviation(newMaxOracleDiff);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
pragma experimental ABIEncoderV2;
// 💬 ABOUT
// Standard Library's default Test
// 🧩 MODULES
import {console} from "./console.sol";
import {console2} from "./console2.sol";
import {StdAssertions} from "./StdAssertions.sol";
import {StdChains} from "./StdChains.sol";
import {StdCheats} from "./StdCheats.sol";
import {stdError} from "./StdError.sol";
import {StdInvariant} from "./StdInvariant.sol";
import {stdJson} from "./StdJson.sol";
import {stdMath} from "./StdMath.sol";
import {StdStorage, stdStorage} from "./StdStorage.sol";
import {StdUtils} from "./StdUtils.sol";
import {Vm} from "./Vm.sol";
import {StdStyle} from "./StdStyle.sol";
// 📦 BOILERPLATE
import {TestBase} from "./Base.sol";
import {DSTest} from "ds-test/test.sol";
// ⭐️ TEST
abstract contract Test is DSTest, StdAssertions, StdChains, StdCheats, StdInvariant, StdUtils, TestBase {
// Note: IS_TEST() must return true.
// Note: Must have failure system, https://github.com/dapphub/ds-test/blob/cd98eff28324bfac652e63a239a60632a761790b/src/test.sol#L39-L76.
}pragma solidity >=0.8.0;
import { CommonBase } from "forge-std/Base.sol";
contract VmHelper is CommonBase {
struct MineBlocksResult {
uint256 timeElapsed;
uint256 blocksElapsed;
uint256 currentTimestamp;
uint256 currentBlockNumber;
}
function mineOneBlock() public returns (MineBlocksResult memory result) {
uint256 timeElapsed = 12;
uint256 blocksElapsed = 1;
vm.warp(block.timestamp + timeElapsed);
vm.roll(block.number + blocksElapsed);
result.timeElapsed = timeElapsed;
result.blocksElapsed = blocksElapsed;
result.currentTimestamp = block.timestamp;
result.currentBlockNumber = block.number;
}
// helper to move forward multiple blocks
function mineBlocks(uint256 _blocks) public returns (MineBlocksResult memory result) {
uint256 timeElapsed = (12 * _blocks);
uint256 blocksElapsed = _blocks;
vm.warp(block.timestamp + timeElapsed);
vm.roll(block.number + blocksElapsed);
result.timeElapsed = timeElapsed;
result.blocksElapsed = blocksElapsed;
result.currentTimestamp = block.timestamp;
result.currentBlockNumber = block.number;
}
function mineBlocksBySecond(uint256 secondsElapsed) public returns (MineBlocksResult memory result) {
uint256 timeElapsed = secondsElapsed;
uint256 blocksElapsed = secondsElapsed / 12;
vm.warp(block.timestamp + timeElapsed);
vm.roll(block.number + blocksElapsed);
result.timeElapsed = timeElapsed;
result.blocksElapsed = blocksElapsed;
result.currentTimestamp = block.timestamp;
result.currentBlockNumber = block.number;
}
function mineBlocksToTimestamp(uint256 _timestamp) public returns (MineBlocksResult memory result) {
uint256 timeElapsed = _timestamp - block.timestamp;
uint256 blocksElapsed = timeElapsed / 12;
vm.warp(_timestamp);
vm.roll(block.number + blocksElapsed);
result.timeElapsed = timeElapsed;
result.blocksElapsed = blocksElapsed;
result.currentTimestamp = block.timestamp;
result.currentBlockNumber = block.number;
}
function labelAndDeal(address _address, string memory _label) public returns (address payable) {
vm.label(_address, _label);
vm.deal(_address, 1_000_000_000);
return payable(_address);
}
}// SPDX-License-Identifier: ISC
pragma solidity ^0.8.0;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ========================== StringsHelper ===========================
// ====================================================================
// Frax Finance: https://github.com/FraxFinance
// Primary Author
// Drake Evans: https://github.com/DrakeEvans
// ====================================================================
import { console2 as console } from "forge-std/Test.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
library StringsHelper {
using Strings for *;
function padLeft(string memory _string, string memory _pad, uint256 _length) public pure returns (string memory) {
while (bytes(_string).length < _length) {
_string = string(abi.encodePacked(_pad, _string));
}
return _string;
}
function padRight(string memory _string, string memory _pad, uint256 _length) public pure returns (string memory) {
while (bytes(_string).length < _length) {
_string = string(abi.encodePacked(_string, _pad));
}
return _string;
}
function slice(string memory _string, uint256 _start, uint256 _end) public pure returns (string memory) {
bytes memory _stringBytes = bytes(_string);
bytes memory _result = new bytes(_end - _start);
for (uint256 i = _start; i < _end; i++) {
_result[i - _start] = _stringBytes[i];
}
return string(_result);
}
function trim(string memory _string) public pure returns (string memory) {
bytes memory _stringBytes = bytes(_string);
uint256 _start = 0;
uint256 _end = _stringBytes.length - 1;
for (uint256 i = 0; i < _stringBytes.length; i++) {
if (_stringBytes[i] != " ") {
_start = i;
break;
}
}
for (uint256 i = _stringBytes.length - 1; i >= 0; i--) {
if (_stringBytes[i] != " ") {
_end = i;
break;
}
}
return slice(_string, _start, _end + 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {FailedInnerCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {FailedInnerCall}) in case of an
* unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {FailedInnerCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {FailedInnerCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/IERC20Metadata.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*/
interface IERC20Metadata is IERC20 {
/**
* @dev Returns the name of the token.
*/
function name() external view returns (string memory);
/**
* @dev Returns the symbol of the token.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the decimals places of the token.
*/
function decimals() external view returns (uint8);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.0;
import { IUniswapV2Pair } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Pair.sol";
/// @dev Fraxswap LP Pair Interface
interface IFraxswapPair is IUniswapV2Pair {
// TWAMM
struct TWAPObservation {
uint256 timestamp;
uint256 price0CumulativeLast;
uint256 price1CumulativeLast;
}
function TWAPObservationHistory(uint256 index) external view returns (TWAPObservation memory);
event LongTermSwap0To1(address indexed addr, uint256 orderId, uint256 amount0In, uint256 numberOfTimeIntervals);
event LongTermSwap1To0(address indexed addr, uint256 orderId, uint256 amount1In, uint256 numberOfTimeIntervals);
event CancelLongTermOrder(
address indexed addr,
uint256 orderId,
address sellToken,
uint256 unsoldAmount,
address buyToken,
uint256 purchasedAmount
);
event WithdrawProceedsFromLongTermOrder(
address indexed addr,
uint256 orderId,
address indexed proceedToken,
uint256 proceeds,
bool orderExpired
);
function fee() external view returns (uint256);
function longTermSwapFrom0To1(uint256 amount0In, uint256 numberOfTimeIntervals) external returns (uint256 orderId);
function longTermSwapFrom1To0(uint256 amount1In, uint256 numberOfTimeIntervals) external returns (uint256 orderId);
function cancelLongTermSwap(uint256 orderId) external;
function withdrawProceedsFromLongTermSwap(
uint256 orderId
) external returns (bool is_expired, address rewardTkn, uint256 totalReward);
function executeVirtualOrders(uint256 blockTimestamp) external;
function getAmountOut(uint256 amountIn, address tokenIn) external view returns (uint256);
function getAmountIn(uint256 amountOut, address tokenOut) external view returns (uint256);
function orderTimeInterval() external returns (uint256);
function getTWAPHistoryLength() external view returns (uint256);
function getTwammReserves()
external
view
returns (
uint112 _reserve0,
uint112 _reserve1,
uint32 _blockTimestampLast,
uint112 _twammReserve0,
uint112 _twammReserve1,
uint256 _fee
);
function getReserveAfterTwamm(
uint256 blockTimestamp
)
external
view
returns (
uint112 _reserve0,
uint112 _reserve1,
uint256 lastVirtualOrderTimestamp,
uint112 _twammReserve0,
uint112 _twammReserve1
);
function getNextOrderID() external view returns (uint256);
function getOrderIDsForUser(address user) external view returns (uint256[] memory);
function getOrderIDsForUserLength(address user) external view returns (uint256);
function twammUpToDate() external view returns (bool);
function getTwammState()
external
view
returns (
uint256 token0Rate,
uint256 token1Rate,
uint256 lastVirtualOrderTimestamp,
uint256 orderTimeInterval_rtn,
uint256 rewardFactorPool0,
uint256 rewardFactorPool1
);
function getTwammSalesRateEnding(
uint256 _blockTimestamp
) external view returns (uint256 orderPool0SalesRateEnding, uint256 orderPool1SalesRateEnding);
function getTwammRewardFactor(
uint256 _blockTimestamp
) external view returns (uint256 rewardFactorPool0AtTimestamp, uint256 rewardFactorPool1AtTimestamp);
function getTwammOrder(
uint256 orderId
)
external
view
returns (
uint256 id,
uint256 creationTimestamp,
uint256 expirationTimestamp,
uint256 saleRate,
address owner,
address sellTokenAddr,
address buyTokenAddr
);
function getTwammOrderProceedsView(
uint256 orderId,
uint256 blockTimestamp
) external view returns (bool orderExpired, uint256 totalReward);
function getTwammOrderProceeds(uint256 orderId) external returns (bool orderExpired, uint256 totalReward);
function togglePauseNewSwaps() external;
}pragma solidity ^0.8.0;
import { IUniswapV2Factory } from "@uniswap/v2-core/contracts/interfaces/IUniswapV2Factory.sol";
interface IFraxswapFactory is IUniswapV2Factory {
function createPair(address tokenA, address tokenB, uint256 fee) external returns (address pair);
function globalPause() external view returns (bool);
function toggleGlobalPause() external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IFraxswapRouterMultihop {
/// @notice Input to the swap function
/// @dev contains the top level info for the swap
/// @param tokenIn input token address
/// @param amountIn input token amount
/// @param tokenOut output token address
/// @param amountOutMinimum output token minimum amount (reverts if lower)
/// @param recipient recipient of the output token
/// @param deadline deadline for this swap transaction (reverts if exceeded)
/// @param v v value for permit signature if supported
/// @param r r value for permit signature if supported
/// @param s s value for permit signature if supported
/// @param route byte encoded
struct FraxswapParams {
address tokenIn;
uint256 amountIn;
address tokenOut;
uint256 amountOutMinimum;
address recipient;
uint256 deadline;
bool approveMax;
uint8 v;
bytes32 r;
bytes32 s;
bytes route;
}
/// @notice A hop along the swap route
/// @dev a series of swaps (steps) containing the same input token and output token
/// @param tokenOut output token address
/// @param amountOut output token amount
/// @param percentOfHop amount of output tokens from the previous hop going into this hop
/// @param steps list of swaps from the same input token to the same output token
/// @param nextHops next hops from this one, the next hops' input token is the tokenOut
struct FraxswapRoute {
address tokenOut;
uint256 amountOut;
uint256 percentOfHop;
bytes[] steps;
bytes[] nextHops;
}
/// @notice A swap step in a specific route. routes can have multiple swap steps
/// @dev a single swap to a token from the token of the previous hop in the route
/// @param swapType type of the swap performed (Uniswap V2, Fraxswap,Curve, etc)
/// @param directFundNextPool 0 = funds go via router, 1 = fund are sent directly to pool
/// @param directFundThisPool 0 = funds go via router, 1 = fund are sent directly to pool
/// @param tokenOut the target token of the step. output token address
/// @param pool address of the pool to use in the step
/// @param extraParam1 extra data used in the step
/// @param extraParam2 extra data used in the step
/// @param percentOfHop percentage of all of the steps in this route (hop)
struct FraxswapStepData {
uint8 swapType;
uint8 directFundNextPool;
uint8 directFundThisPool;
address tokenOut;
address pool;
uint256 extraParam1;
uint256 extraParam2;
uint256 percentOfHop;
}
/// @notice struct for Uniswap V3 callback
/// @param tokenIn address of input token
/// @param directFundThisPool this pool already been funded
struct SwapCallbackData {
address tokenIn;
bool directFundThisPool;
}
/// @notice Routing event emitted every swap
/// @param tokenIn address of the original input token
/// @param tokenOut address of the final output token
/// @param amountIn input amount for original input token
/// @param amountOut output amount for the final output token
event Routed(address tokenIn, address tokenOut, uint256 amountIn, uint256 amountOut);
function encodeRoute(
address tokenOut,
uint256 percentOfHop,
bytes[] memory steps,
bytes[] memory nextHops
) external pure returns (bytes memory out);
function encodeStep(
uint8 swapType,
uint8 directFundNextPool,
uint8 directFundThisPool,
address tokenOut,
address pool,
uint256 extraParam1,
uint256 extraParam2,
uint256 percentOfHop
) external pure returns (bytes memory out);
function swap(FraxswapParams memory params) external payable returns (uint256 amountOut);
function uniswapV3SwapCallback(int256 amount0Delta, int256 amount1Delta, bytes memory _data) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity 0.8.23;
import { IBAMMERC20 } from "./interfaces/IBAMMERC20.sol";
import { ERC20Permit, ERC20 } from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
/// @dev supports OZ 5.0 interface
contract BAMMERC20 is IBAMMERC20, ERC20Permit, Ownable {
constructor(
string memory name_,
string memory symbol_
) ERC20(name_, symbol_) ERC20Permit(name_) Ownable(msg.sender) {}
function mint(address account, uint256 value) external onlyOwner {
_mint(account, value);
}
function burn(address account, uint256 value) external onlyOwner {
_burn(account, value);
}
}pragma solidity ^0.8.0;
import { IFraxswapPair } from "dev-fraxswap/src/contracts/core/interfaces/IFraxswapPair.sol";
interface IFraxswapOracle {
function getPrice(
IFraxswapPair pool,
uint256 period,
uint256 rounds,
uint256 maxDiffPerc
) external view returns (uint256 result0, uint256 result1);
function getPrice0(
IFraxswapPair pool,
uint256 period,
uint256 rounds,
uint256 maxDiffPerc
) external view returns (uint256 result0);
function getPrice1(
IFraxswapPair pool,
uint256 period,
uint256 rounds,
uint256 maxDiffPerc
) external view returns (uint256 result1);
function mulDecode(uint224 value) external pure returns (uint256 result);
}pragma solidity ^0.8.0;
import { IFraxswapFactory } from "dev-fraxswap/src/contracts/core/interfaces/IFraxswapFactory.sol";
interface IBAMMFactory {
// State variables
function iFraxswapFactory() external view returns (IFraxswapFactory);
function routerMultihop() external view returns (address);
function fraxswapOracle() external view returns (address);
function variableInterestRate() external view returns (address);
function isBamm(address bamm) external view returns (bool exists);
function pairToBamm(address pair) external view returns (address bamm);
function feeTo() external view returns (address);
// Functions
function version() external pure returns (uint256 _major, uint256 _minor, uint256 _patch);
function createBamm(address _pair) external returns (address bamm);
function bammsArray() external view returns (address[] memory);
function bammsLength() external view returns (uint256);
function setFeeTo(address _feeTo) external;
// Events
event BammCreated(address pair, address bamm);
// Errors
error Create2Failed();
error BammAlreadyCreated();
error PairNotFromFraxswapFactory();
error NotBAMM();
}// SPDX-License-Identifier: ISC
pragma solidity ^0.8.0;
interface IVariableInterestRate {
function MAX_FULL_UTIL_RATE() external view returns (uint256);
function MAX_TARGET_UTIL() external view returns (uint256);
function MIN_FULL_UTIL_RATE() external view returns (uint256);
function MIN_TARGET_UTIL() external view returns (uint256);
function RATE_HALF_LIFE() external view returns (uint256);
function RATE_PREC() external view returns (uint256);
function UTIL_PREC() external view returns (uint256);
function VERTEX_RATE_PERCENT() external view returns (uint256);
function VERTEX_UTILIZATION() external view returns (uint256);
function ZERO_UTIL_RATE() external view returns (uint256);
function getNewRate(
uint256 _deltaTime,
uint256 _utilization,
uint64 _oldFullUtilizationInterest
) external view returns (uint64 _newRatePerSec, uint64 _newFullUtilizationInterest);
function name() external view returns (string memory);
function version() external view returns (uint256 _major, uint256 _minor, uint256 _patch);
function suffix() external view returns (string memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Strings.sol)
pragma solidity ^0.8.20;
import {Math} from "./math/Math.sol";
import {SignedMath} from "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant HEX_DIGITS = "0123456789abcdef";
uint8 private constant ADDRESS_LENGTH = 20;
/**
* @dev The `value` string doesn't fit in the specified `length`.
*/
error StringsInsufficientHexLength(uint256 value, uint256 length);
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), HEX_DIGITS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toStringSigned(int256 value) internal pure returns (string memory) {
return string.concat(value < 0 ? "-" : "", toString(SignedMath.abs(value)));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
uint256 localValue = value;
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = HEX_DIGITS[localValue & 0xf];
localValue >>= 4;
}
if (localValue != 0) {
revert StringsInsufficientHexLength(value, length);
}
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal
* representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return bytes(a).length == bytes(b).length && keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: ISC
pragma solidity 0.8.23;
// ====================================================================
// | ______ _______ |
// | / _____________ __ __ / ____(_____ ____ _____ ________ |
// | / /_ / ___/ __ `| |/_/ / /_ / / __ \/ __ `/ __ \/ ___/ _ \ |
// | / __/ / / / /_/ _> < / __/ / / / / / /_/ / / / / /__/ __/ |
// | /_/ /_/ \__,_/_/|_| /_/ /_/_/ /_/\__,_/_/ /_/\___/\___/ |
// | |
// ====================================================================
// ====================== VariableInterestRate ========================
// ====================================================================
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { IVariableInterestRate } from "./interfaces/IVariableInterestRate.sol";
/// @title A formula for calculating interest rates as a function of utilization and time
/// @author Frax Finance (https://github.com/FraxFinance)
/// @notice A Contract for calculating interest rates as a function of utilization and time
contract VariableInterestRate is IVariableInterestRate {
using Strings for uint256;
/// @notice The name suffix for the interest rate calculator
string public suffix;
// Utilization Settings
/// @notice The minimum utilization wherein no adjustment to full utilization and vertex rates occurs
uint256 public immutable MIN_TARGET_UTIL;
/// @notice The maximum utilization wherein no adjustment to full utilization and vertex rates occurs
uint256 public immutable MAX_TARGET_UTIL;
/// @notice The utilization at which the slope increases
uint256 public immutable VERTEX_UTILIZATION;
/// @notice The second utilization at which the slope increases
uint256 public immutable VERTEX_2_UTILIZATION;
/// @notice precision of utilization calculations
uint256 public constant UTIL_PREC = 1e5; // 5 decimals
// Interest Rate Settings (all rates are per second), 365.24 days per year
/// @notice The minimum interest rate (per second) when utilization is 100%
uint256 public immutable MIN_FULL_UTIL_RATE; // 18 decimals
/// @notice The maximum interest rate (per second) when utilization is 100%
uint256 public immutable MAX_FULL_UTIL_RATE; // 18 decimals
/// @notice The interest rate (per second) when utilization is 0%
uint256 public immutable ZERO_UTIL_RATE; // 18 decimals
/// @notice The interest rate half life in seconds, determines rate of adjustments to rate curve
uint256 public immutable RATE_HALF_LIFE; // 1 decimals
/// @notice The percent of the delta between max and min at the first kink
uint256 public immutable VERTEX_RATE_PERCENT; // 18 decimals
/// @notice The percent of the delta between max and min at the second kink
uint256 public immutable VERTEX_2_RATE_PERCENT; // 18 decimals
/// @notice The precision of interest rate calculations
uint256 public constant RATE_PREC = 1e18; // 18 decimals
error MaxUtilizationTooLow();
error MaxFullUtilizationTooLow();
error DivideByZero();
error VertexUtilizationTooHigh();
error UtilizationRateTooHigh();
error Vertex2UtilizationTooLow();
/// @param _params Abi Encoding of the following schema:
/// param _suffix The suffix of the contract name
/// param _vertexUtilization The utilization at which the slope increases
/// param _vertex2Utilization The utilization at which the slope increases
/// param _vertexRatePercentOfDelta The percent of the delta between max and min, defines vertex rate
/// param _vertex2RatePercentOfDelta The percent of delta between the
/// param _minUtil The minimum utilization wherein no adjustment to full utilization and vertex rates occurs
/// param _maxUtil The maximum utilization wherein no adjustment to full utilization and vertex rates occurs
/// param _zeroUtilizationRate The interest rate (per second) when utilization is 0%
/// param _minFullUtilizationRate The minimum interest rate at 100% utilization
/// param _maxFullUtilizationRate The maximum interest rate at 100% utilization
/// param _rateHalfLife The half life parameter for interest rate adjustments
constructor(bytes memory _params) {
(
suffix,
VERTEX_UTILIZATION,
VERTEX_2_UTILIZATION,
VERTEX_RATE_PERCENT,
VERTEX_2_RATE_PERCENT,
MIN_TARGET_UTIL,
MAX_TARGET_UTIL,
ZERO_UTIL_RATE,
MIN_FULL_UTIL_RATE,
MAX_FULL_UTIL_RATE,
RATE_HALF_LIFE
) = abi.decode(
_params,
(string, uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256, uint256)
);
if (MAX_TARGET_UTIL <= MIN_TARGET_UTIL) {
revert MaxUtilizationTooLow();
}
if (MAX_FULL_UTIL_RATE <= MIN_FULL_UTIL_RATE) {
revert MaxFullUtilizationTooLow();
}
if (VERTEX_UTILIZATION > UTIL_PREC) {
revert VertexUtilizationTooHigh();
}
if (VERTEX_2_UTILIZATION > UTIL_PREC) {
revert VertexUtilizationTooHigh();
}
if (VERTEX_2_UTILIZATION <= VERTEX_UTILIZATION) {
revert Vertex2UtilizationTooLow();
}
if (
MAX_TARGET_UTIL == 0 ||
RATE_HALF_LIFE == 0 ||
VERTEX_UTILIZATION == 0 ||
VERTEX_UTILIZATION == UTIL_PREC ||
VERTEX_2_UTILIZATION == 0 ||
VERTEX_2_UTILIZATION == UTIL_PREC ||
MAX_TARGET_UTIL == UTIL_PREC
) {
revert DivideByZero();
}
if (MAX_TARGET_UTIL > UTIL_PREC || MAX_FULL_UTIL_RATE > RATE_PREC) {
revert UtilizationRateTooHigh();
}
}
/// @notice The ```name``` function returns the name of the rate contract
/// @return memory name of contract
function name() external view returns (string memory) {
return string.concat("Variable Rate V3 ", suffix);
}
/// @notice The ```version``` function returns the semantic version of the rate contract
/// @dev Follows semantic versioning
/// @return _major Major version
/// @return _minor Minor version
/// @return _patch Patch version
function version() external pure returns (uint256 _major, uint256 _minor, uint256 _patch) {
_major = 3;
_minor = 0;
_patch = 0;
}
/// @notice The ```getFullUtilizationInterest``` function calculate the new maximum interest rate, i.e. rate when utilization is 100%
/// @dev Given in interest per second
/// @param _deltaTime The elapsed time since last update given in seconds
/// @param _utilization The utilization %, given with 5 decimals of precision
/// @param _fullUtilizationInterest The interest value when utilization is 100%, given with 18 decimals of precision
/// @return _newFullUtilizationInterest The new maximum interest rate
function getFullUtilizationInterest(
uint256 _deltaTime,
uint256 _utilization,
uint64 _fullUtilizationInterest
) internal view returns (uint64 _newFullUtilizationInterest) {
if (_utilization < MIN_TARGET_UTIL) {
// 18 decimals
uint256 _deltaUtilization = ((MIN_TARGET_UTIL - _utilization) * 1e18) / MIN_TARGET_UTIL;
// 36 decimals
uint256 _decayGrowth = (RATE_HALF_LIFE * 1e36) + (_deltaUtilization * _deltaUtilization * _deltaTime);
// 18 decimals
_newFullUtilizationInterest = uint64((_fullUtilizationInterest * (RATE_HALF_LIFE * 1e36)) / _decayGrowth);
} else if (_utilization > MAX_TARGET_UTIL) {
// 18 decimals
uint256 _deltaUtilization = ((_utilization - MAX_TARGET_UTIL) * 1e18) / (UTIL_PREC - MAX_TARGET_UTIL);
// 36 decimals
uint256 _decayGrowth = (RATE_HALF_LIFE * 1e36) + (_deltaUtilization * _deltaUtilization * _deltaTime);
// 18 decimals
_newFullUtilizationInterest = uint64((_fullUtilizationInterest * _decayGrowth) / (RATE_HALF_LIFE * 1e36));
} else {
_newFullUtilizationInterest = _fullUtilizationInterest;
}
if (_newFullUtilizationInterest > MAX_FULL_UTIL_RATE) {
_newFullUtilizationInterest = uint64(MAX_FULL_UTIL_RATE);
} else if (_newFullUtilizationInterest < MIN_FULL_UTIL_RATE) {
_newFullUtilizationInterest = uint64(MIN_FULL_UTIL_RATE);
}
}
/// @notice The ```getNewRate``` function calculates interest rates using two linear functions f(utilization)
/// @param _deltaTime The elapsed time since last update, given in seconds
/// @param _utilization The utilization %, given with 5 decimals of precision
/// @param _oldFullUtilizationInterest The interest value when utilization is 100%, given with 18 decimals of precision
/// @return _newRatePerSec The new interest rate, 18 decimals of precision
/// @return _newFullUtilizationInterest The new max interest rate, 18 decimals of precision
function getNewRate(
uint256 _deltaTime,
uint256 _utilization,
uint64 _oldFullUtilizationInterest
) external view returns (uint64 _newRatePerSec, uint64 _newFullUtilizationInterest) {
_newFullUtilizationInterest = getFullUtilizationInterest(_deltaTime, _utilization, _oldFullUtilizationInterest);
// _vertexInterest is calculated as the percentage of the delta between min and max interest
uint256 _vertexInterest = (((_newFullUtilizationInterest - ZERO_UTIL_RATE) * VERTEX_RATE_PERCENT) / RATE_PREC) +
ZERO_UTIL_RATE;
uint256 _vertex2Interest = (((_newFullUtilizationInterest - ZERO_UTIL_RATE) * VERTEX_2_RATE_PERCENT) /
RATE_PREC) + ZERO_UTIL_RATE;
if (_utilization < VERTEX_UTILIZATION) {
// For readability, the following formula is equivalent to:
// uint256 _slope = ((_vertexInterest - ZERO_UTIL_RATE) * UTIL_PREC) / VERTEX_UTILIZATION;
// _newRatePerSec = uint64(ZERO_UTIL_RATE + ((_utilization * _slope) / UTIL_PREC));
_newRatePerSec = uint64(
ZERO_UTIL_RATE + (_utilization * (_vertexInterest - ZERO_UTIL_RATE)) / VERTEX_UTILIZATION
);
} else if (_utilization < VERTEX_2_UTILIZATION) {
// For readability, the following formula is equivalent to:
// uint256 _slope = (((_vertex2Interest - _vertexInterest) * UTIL_PREC) / (VERTEX_2_UTILIZATION - VERTEX_UTILIZATION));
// _newRatePerSec = uint64(_vertexInterest + (((_utilization - VERTEX_UTILIZATION) * _slope) / UTIL_PREC));
_newRatePerSec = uint64(
_vertexInterest +
((_utilization - VERTEX_UTILIZATION) * ((_vertex2Interest - _vertexInterest))) /
((VERTEX_2_UTILIZATION - VERTEX_UTILIZATION))
);
} else {
// For readability, the following formula is equivalent to:
// uint256 _slope = (((_newFullUtilizationInterest - _vertex2Interest) * UTIL_PREC) / (UTIL_PREC - VERTEX_2_UTILIZATION));
// _newRatePerSec = uint64(_vertex2Interest + (((_utilization - VERTEX_2_UTILIZATION) * _slope) / UTIL_PREC))
_newRatePerSec = uint64(
_vertex2Interest +
((_utilization - VERTEX_2_UTILIZATION) * (_newFullUtilizationInterest - _vertex2Interest)) /
((UTIL_PREC - VERTEX_2_UTILIZATION))
);
}
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Read and write to persistent storage at a fraction of the cost.
/// @author Solmate (https://github.com/Rari-Capital/solmate/blob/main/src/utils/SSTORE2.sol)
/// @author Modified from 0xSequence (https://github.com/0xSequence/sstore2/blob/master/contracts/SSTORE2.sol)
library SSTORE2 {
uint256 internal constant DATA_OFFSET = 1; // We skip the first byte as it's a STOP opcode to ensure the contract can't be called.
/*///////////////////////////////////////////////////////////////
WRITE LOGIC
//////////////////////////////////////////////////////////////*/
function write(bytes memory data) internal returns (address pointer) {
// Prefix the bytecode with a STOP opcode to ensure it cannot be called.
bytes memory runtimeCode = abi.encodePacked(hex"00", data);
bytes memory creationCode = abi.encodePacked(
//---------------------------------------------------------------------------------------------------------------//
// Opcode | Opcode + Arguments | Description | Stack View //
//---------------------------------------------------------------------------------------------------------------//
// 0x60 | 0x600B | PUSH1 11 | codeOffset //
// 0x59 | 0x59 | MSIZE | 0 codeOffset //
// 0x81 | 0x81 | DUP2 | codeOffset 0 codeOffset //
// 0x38 | 0x38 | CODESIZE | codeSize codeOffset 0 codeOffset //
// 0x03 | 0x03 | SUB | (codeSize - codeOffset) 0 codeOffset //
// 0x80 | 0x80 | DUP | (codeSize - codeOffset) (codeSize - codeOffset) 0 codeOffset //
// 0x92 | 0x92 | SWAP3 | codeOffset (codeSize - codeOffset) 0 (codeSize - codeOffset) //
// 0x59 | 0x59 | MSIZE | 0 codeOffset (codeSize - codeOffset) 0 (codeSize - codeOffset) //
// 0x39 | 0x39 | CODECOPY | 0 (codeSize - codeOffset) //
// 0xf3 | 0xf3 | RETURN | //
//---------------------------------------------------------------------------------------------------------------//
hex"60_0B_59_81_38_03_80_92_59_39_F3", // Returns all code in the contract except for the first 11 (0B in hex) bytes.
runtimeCode // The bytecode we want the contract to have after deployment. Capped at 1 byte less than the code size limit.
);
assembly {
// Deploy a new contract with the generated creation code.
// We start 32 bytes into the code to avoid copying the byte length.
pointer := create(0, add(creationCode, 32), mload(creationCode))
}
require(pointer != address(0), "DEPLOYMENT_FAILED");
}
/*///////////////////////////////////////////////////////////////
READ LOGIC
//////////////////////////////////////////////////////////////*/
function read(address pointer) internal view returns (bytes memory) {
return readBytecode(pointer, DATA_OFFSET, pointer.code.length - DATA_OFFSET);
}
function read(address pointer, uint256 start) internal view returns (bytes memory) {
start += DATA_OFFSET;
return readBytecode(pointer, start, pointer.code.length - start);
}
function read(
address pointer,
uint256 start,
uint256 end
) internal view returns (bytes memory) {
start += DATA_OFFSET;
end += DATA_OFFSET;
require(pointer.code.length >= end, "OUT_OF_BOUNDS");
return readBytecode(pointer, start, end - start);
}
/*///////////////////////////////////////////////////////////////
INTERNAL HELPER LOGIC
//////////////////////////////////////////////////////////////*/
function readBytecode(
address pointer,
uint256 start,
uint256 size
) private view returns (bytes memory data) {
assembly {
// Get a pointer to some free memory.
data := mload(0x40)
// Update the free memory pointer to prevent overriding our data.
// We use and(x, not(31)) as a cheaper equivalent to sub(x, mod(x, 32)).
// Adding 31 to size and running the result through the logic above ensures
// the memory pointer remains word-aligned, following the Solidity convention.
mstore(0x40, add(data, and(add(add(size, 32), 31), not(31))))
// Store the size of the data in the first 32 byte chunk of free memory.
mstore(data, size)
// Copy the code into memory right after the 32 bytes we used to store the size.
extcodecopy(pointer, add(data, 32), start, size)
}
}
}// SPDX-License-Identifier: Unlicense /* * @title Solidity Bytes Arrays Utils * @author Gonçalo Sá <[email protected]> * * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity. * The library lets you concatenate, slice and type cast bytes arrays both in memory and storage. */ pragma solidity >=0.8.0 <0.9.0; library BytesLib { function concat( bytes memory _preBytes, bytes memory _postBytes ) internal pure returns (bytes memory) { bytes memory tempBytes; assembly { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // Store the length of the first bytes array at the beginning of // the memory for tempBytes. let length := mload(_preBytes) mstore(tempBytes, length) // Maintain a memory counter for the current write location in the // temp bytes array by adding the 32 bytes for the array length to // the starting location. let mc := add(tempBytes, 0x20) // Stop copying when the memory counter reaches the length of the // first bytes array. let end := add(mc, length) for { // Initialize a copy counter to the start of the _preBytes data, // 32 bytes into its memory. let cc := add(_preBytes, 0x20) } lt(mc, end) { // Increase both counters by 32 bytes each iteration. mc := add(mc, 0x20) cc := add(cc, 0x20) } { // Write the _preBytes data into the tempBytes memory 32 bytes // at a time. mstore(mc, mload(cc)) } // Add the length of _postBytes to the current length of tempBytes // and store it as the new length in the first 32 bytes of the // tempBytes memory. length := mload(_postBytes) mstore(tempBytes, add(length, mload(tempBytes))) // Move the memory counter back from a multiple of 0x20 to the // actual end of the _preBytes data. mc := end // Stop copying when the memory counter reaches the new combined // length of the arrays. end := add(mc, length) for { let cc := add(_postBytes, 0x20) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } // Update the free-memory pointer by padding our last write location // to 32 bytes: add 31 bytes to the end of tempBytes to move to the // next 32 byte block, then round down to the nearest multiple of // 32. If the sum of the length of the two arrays is zero then add // one before rounding down to leave a blank 32 bytes (the length block with 0). mstore(0x40, and( add(add(end, iszero(add(length, mload(_preBytes)))), 31), not(31) // Round down to the nearest 32 bytes. )) } return tempBytes; } function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal { assembly { // Read the first 32 bytes of _preBytes storage, which is the length // of the array. (We don't need to use the offset into the slot // because arrays use the entire slot.) let fslot := sload(_preBytes.slot) // Arrays of 31 bytes or less have an even value in their slot, // while longer arrays have an odd value. The actual length is // the slot divided by two for odd values, and the lowest order // byte divided by two for even values. // If the slot is even, bitwise and the slot with 255 and divide by // two to get the length. If the slot is odd, bitwise and the slot // with -1 and divide by two. let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2) let mlength := mload(_postBytes) let newlength := add(slength, mlength) // slength can contain both the length and contents of the array // if length < 32 bytes so let's prepare for that // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage switch add(lt(slength, 32), lt(newlength, 32)) case 2 { // Since the new array still fits in the slot, we just need to // update the contents of the slot. // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length sstore( _preBytes.slot, // all the modifications to the slot are inside this // next block add( // we can just add to the slot contents because the // bytes we want to change are the LSBs fslot, add( mul( div( // load the bytes from memory mload(add(_postBytes, 0x20)), // zero all bytes to the right exp(0x100, sub(32, mlength)) ), // and now shift left the number of bytes to // leave space for the length in the slot exp(0x100, sub(32, newlength)) ), // increase length by the double of the memory // bytes length mul(mlength, 2) ) ) ) } case 1 { // The stored value fits in the slot, but the combined value // will exceed it. // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) let sc := add(keccak256(0x0, 0x20), div(slength, 32)) // save new length sstore(_preBytes.slot, add(mul(newlength, 2), 1)) // The contents of the _postBytes array start 32 bytes into // the structure. Our first read should obtain the `submod` // bytes that can fit into the unused space in the last word // of the stored array. To get this, we read 32 bytes starting // from `submod`, so the data we read overlaps with the array // contents by `submod` bytes. Masking the lowest-order // `submod` bytes allows us to add that value directly to the // stored value. let submod := sub(32, slength) let mc := add(_postBytes, submod) let end := add(_postBytes, mlength) let mask := sub(exp(0x100, submod), 1) sstore( sc, add( and( fslot, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00 ), and(mload(mc), mask) ) ) for { mc := add(mc, 0x20) sc := add(sc, 1) } lt(mc, end) { sc := add(sc, 1) mc := add(mc, 0x20) } { sstore(sc, mload(mc)) } mask := exp(0x100, sub(mc, end)) sstore(sc, mul(div(mload(mc), mask), mask)) } default { // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) // Start copying to the last used word of the stored array. let sc := add(keccak256(0x0, 0x20), div(slength, 32)) // save new length sstore(_preBytes.slot, add(mul(newlength, 2), 1)) // Copy over the first `submod` bytes of the new data as in // case 1 above. let slengthmod := mod(slength, 32) let mlengthmod := mod(mlength, 32) let submod := sub(32, slengthmod) let mc := add(_postBytes, submod) let end := add(_postBytes, mlength) let mask := sub(exp(0x100, submod), 1) sstore(sc, add(sload(sc), and(mload(mc), mask))) for { sc := add(sc, 1) mc := add(mc, 0x20) } lt(mc, end) { sc := add(sc, 1) mc := add(mc, 0x20) } { sstore(sc, mload(mc)) } mask := exp(0x100, sub(mc, end)) sstore(sc, mul(div(mload(mc), mask), mask)) } } } function slice( bytes memory _bytes, uint256 _start, uint256 _length ) internal pure returns (bytes memory) { require(_length + 31 >= _length, "slice_overflow"); require(_bytes.length >= _start + _length, "slice_outOfBounds"); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) //zero out the 32 bytes slice we are about to return //we need to do it because Solidity does not garbage collect mstore(tempBytes, 0) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) { require(_bytes.length >= _start + 20, "toAddress_outOfBounds"); address tempAddress; assembly { tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000) } return tempAddress; } function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) { require(_bytes.length >= _start + 1 , "toUint8_outOfBounds"); uint8 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x1), _start)) } return tempUint; } function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) { require(_bytes.length >= _start + 2, "toUint16_outOfBounds"); uint16 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x2), _start)) } return tempUint; } function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) { require(_bytes.length >= _start + 4, "toUint32_outOfBounds"); uint32 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x4), _start)) } return tempUint; } function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) { require(_bytes.length >= _start + 8, "toUint64_outOfBounds"); uint64 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x8), _start)) } return tempUint; } function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) { require(_bytes.length >= _start + 12, "toUint96_outOfBounds"); uint96 tempUint; assembly { tempUint := mload(add(add(_bytes, 0xc), _start)) } return tempUint; } function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) { require(_bytes.length >= _start + 16, "toUint128_outOfBounds"); uint128 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x10), _start)) } return tempUint; } function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) { require(_bytes.length >= _start + 32, "toUint256_outOfBounds"); uint256 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x20), _start)) } return tempUint; } function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) { require(_bytes.length >= _start + 32, "toBytes32_outOfBounds"); bytes32 tempBytes32; assembly { tempBytes32 := mload(add(add(_bytes, 0x20), _start)) } return tempBytes32; } function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) { bool success = true; assembly { let length := mload(_preBytes) // if lengths don't match the arrays are not equal switch eq(length, mload(_postBytes)) case 1 { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 let mc := add(_preBytes, 0x20) let end := add(mc, length) for { let cc := add(_postBytes, 0x20) // the next line is the loop condition: // while(uint256(mc < end) + cb == 2) } eq(add(lt(mc, end), cb), 2) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { // if any of these checks fails then arrays are not equal if iszero(eq(mload(mc), mload(cc))) { // unsuccess: success := 0 cb := 0 } } } default { // unsuccess: success := 0 } } return success; } function equal_nonAligned(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) { bool success = true; assembly { let length := mload(_preBytes) // if lengths don't match the arrays are not equal switch eq(length, mload(_postBytes)) case 1 { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 let endMinusWord := add(_preBytes, length) let mc := add(_preBytes, 0x20) let cc := add(_postBytes, 0x20) for { // the next line is the loop condition: // while(uint256(mc < endWord) + cb == 2) } eq(add(lt(mc, endMinusWord), cb), 2) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { // if any of these checks fails then arrays are not equal if iszero(eq(mload(mc), mload(cc))) { // unsuccess: success := 0 cb := 0 } } // Only if still successful // For <1 word tail bytes if gt(success, 0) { // Get the remainder of length/32 // length % 32 = AND(length, 32 - 1) let numTailBytes := and(length, 0x1f) let mcRem := mload(mc) let ccRem := mload(cc) for { let i := 0 // the next line is the loop condition: // while(uint256(i < numTailBytes) + cb == 2) } eq(add(lt(i, numTailBytes), cb), 2) { i := add(i, 1) } { if iszero(eq(byte(i, mcRem), byte(i, ccRem))) { // unsuccess: success := 0 cb := 0 } } } } default { // unsuccess: success := 0 } } return success; } function equalStorage( bytes storage _preBytes, bytes memory _postBytes ) internal view returns (bool) { bool success = true; assembly { // we know _preBytes_offset is 0 let fslot := sload(_preBytes.slot) // Decode the length of the stored array like in concatStorage(). let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2) let mlength := mload(_postBytes) // if lengths don't match the arrays are not equal switch eq(slength, mlength) case 1 { // slength can contain both the length and contents of the array // if length < 32 bytes so let's prepare for that // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage if iszero(iszero(slength)) { switch lt(slength, 32) case 1 { // blank the last byte which is the length fslot := mul(div(fslot, 0x100), 0x100) if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) { // unsuccess: success := 0 } } default { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) let sc := keccak256(0x0, 0x20) let mc := add(_postBytes, 0x20) let end := add(mc, mlength) // the next line is the loop condition: // while(uint256(mc < end) + cb == 2) for {} eq(add(lt(mc, end), cb), 2) { sc := add(sc, 1) mc := add(mc, 0x20) } { if iszero(eq(sload(sc), mload(mc))) { // unsuccess: success := 0 cb := 0 } } } } } default { // unsuccess: success := 0 } } return success; } }
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable2Step.sol)
pragma solidity ^0.8.20;
import {Ownable} from "./Ownable.sol";
/**
* @dev Contract module which provides access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is specified at deployment time in the constructor for `Ownable`. This
* can later be changed with {transferOwnership} and {acceptOwnership}.
*
* This module is used through inheritance. It will make available all functions
* from parent (Ownable).
*/
abstract contract Ownable2Step is Ownable {
address private _pendingOwner;
event OwnershipTransferStarted(address indexed previousOwner, address indexed newOwner);
/**
* @dev Returns the address of the pending owner.
*/
function pendingOwner() public view virtual returns (address) {
return _pendingOwner;
}
/**
* @dev Starts the ownership transfer of the contract to a new account. Replaces the pending transfer if there is one.
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual override onlyOwner {
_pendingOwner = newOwner;
emit OwnershipTransferStarted(owner(), newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`) and deletes any pending owner.
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual override {
delete _pendingOwner;
super._transferOwnership(newOwner);
}
/**
* @dev The new owner accepts the ownership transfer.
*/
function acceptOwnership() public virtual {
address sender = _msgSender();
if (pendingOwner() != sender) {
revert OwnableUnauthorizedAccount(sender);
}
_transferOwnership(sender);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
library console {
address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
function _sendLogPayload(bytes memory payload) private view {
uint256 payloadLength = payload.length;
address consoleAddress = CONSOLE_ADDRESS;
/// @solidity memory-safe-assembly
assembly {
let payloadStart := add(payload, 32)
let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
}
}
function log() internal view {
_sendLogPayload(abi.encodeWithSignature("log()"));
}
function logInt(int p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(int)", p0));
}
function logUint(uint p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint)", p0));
}
function logString(string memory p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function logBool(bool p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function logAddress(address p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function logBytes(bytes memory p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes)", p0));
}
function logBytes1(bytes1 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0));
}
function logBytes2(bytes2 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0));
}
function logBytes3(bytes3 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0));
}
function logBytes4(bytes4 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0));
}
function logBytes5(bytes5 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0));
}
function logBytes6(bytes6 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0));
}
function logBytes7(bytes7 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0));
}
function logBytes8(bytes8 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0));
}
function logBytes9(bytes9 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0));
}
function logBytes10(bytes10 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0));
}
function logBytes11(bytes11 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0));
}
function logBytes12(bytes12 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0));
}
function logBytes13(bytes13 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0));
}
function logBytes14(bytes14 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0));
}
function logBytes15(bytes15 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0));
}
function logBytes16(bytes16 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0));
}
function logBytes17(bytes17 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0));
}
function logBytes18(bytes18 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0));
}
function logBytes19(bytes19 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0));
}
function logBytes20(bytes20 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0));
}
function logBytes21(bytes21 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0));
}
function logBytes22(bytes22 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0));
}
function logBytes23(bytes23 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0));
}
function logBytes24(bytes24 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0));
}
function logBytes25(bytes25 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0));
}
function logBytes26(bytes26 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0));
}
function logBytes27(bytes27 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0));
}
function logBytes28(bytes28 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0));
}
function logBytes29(bytes29 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0));
}
function logBytes30(bytes30 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0));
}
function logBytes31(bytes31 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0));
}
function logBytes32(bytes32 p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0));
}
function log(uint p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint)", p0));
}
function log(string memory p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function log(bool p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function log(address p0) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function log(uint p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint)", p0, p1));
}
function log(uint p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string)", p0, p1));
}
function log(uint p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool)", p0, p1));
}
function log(uint p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address)", p0, p1));
}
function log(string memory p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint)", p0, p1));
}
function log(string memory p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1));
}
function log(string memory p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1));
}
function log(string memory p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1));
}
function log(bool p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint)", p0, p1));
}
function log(bool p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1));
}
function log(bool p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1));
}
function log(bool p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1));
}
function log(address p0, uint p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint)", p0, p1));
}
function log(address p0, string memory p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1));
}
function log(address p0, bool p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1));
}
function log(address p0, address p1) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1));
}
function log(uint p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint)", p0, p1, p2));
}
function log(uint p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string)", p0, p1, p2));
}
function log(uint p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool)", p0, p1, p2));
}
function log(uint p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address)", p0, p1, p2));
}
function log(uint p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint)", p0, p1, p2));
}
function log(uint p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string)", p0, p1, p2));
}
function log(uint p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool)", p0, p1, p2));
}
function log(uint p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address)", p0, p1, p2));
}
function log(uint p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint)", p0, p1, p2));
}
function log(uint p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string)", p0, p1, p2));
}
function log(uint p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool)", p0, p1, p2));
}
function log(uint p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address)", p0, p1, p2));
}
function log(uint p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint)", p0, p1, p2));
}
function log(uint p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string)", p0, p1, p2));
}
function log(uint p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool)", p0, p1, p2));
}
function log(uint p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address)", p0, p1, p2));
}
function log(string memory p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint)", p0, p1, p2));
}
function log(string memory p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string)", p0, p1, p2));
}
function log(string memory p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool)", p0, p1, p2));
}
function log(string memory p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address)", p0, p1, p2));
}
function log(string memory p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint)", p0, p1, p2));
}
function log(string memory p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
}
function log(string memory p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2));
}
function log(string memory p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2));
}
function log(string memory p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint)", p0, p1, p2));
}
function log(string memory p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2));
}
function log(string memory p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2));
}
function log(string memory p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2));
}
function log(string memory p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint)", p0, p1, p2));
}
function log(string memory p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2));
}
function log(string memory p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2));
}
function log(string memory p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2));
}
function log(bool p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint)", p0, p1, p2));
}
function log(bool p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string)", p0, p1, p2));
}
function log(bool p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool)", p0, p1, p2));
}
function log(bool p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address)", p0, p1, p2));
}
function log(bool p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint)", p0, p1, p2));
}
function log(bool p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2));
}
function log(bool p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2));
}
function log(bool p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2));
}
function log(bool p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint)", p0, p1, p2));
}
function log(bool p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2));
}
function log(bool p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2));
}
function log(bool p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2));
}
function log(bool p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint)", p0, p1, p2));
}
function log(bool p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2));
}
function log(bool p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2));
}
function log(bool p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2));
}
function log(address p0, uint p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint)", p0, p1, p2));
}
function log(address p0, uint p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string)", p0, p1, p2));
}
function log(address p0, uint p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool)", p0, p1, p2));
}
function log(address p0, uint p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address)", p0, p1, p2));
}
function log(address p0, string memory p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint)", p0, p1, p2));
}
function log(address p0, string memory p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2));
}
function log(address p0, string memory p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2));
}
function log(address p0, string memory p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2));
}
function log(address p0, bool p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint)", p0, p1, p2));
}
function log(address p0, bool p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2));
}
function log(address p0, bool p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2));
}
function log(address p0, bool p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2));
}
function log(address p0, address p1, uint p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint)", p0, p1, p2));
}
function log(address p0, address p1, string memory p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2));
}
function log(address p0, address p1, bool p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2));
}
function log(address p0, address p1, address p2) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2));
}
function log(uint p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,string,address)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,string)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,uint,address,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,string,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,string)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,string,address,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,string,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,string)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,bool,address,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,uint,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,string,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,bool,address)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,uint)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,string)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,bool)", p0, p1, p2, p3));
}
function log(uint p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(uint,address,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,uint,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,string,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,string)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint,address,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,uint,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,string,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,bool,address)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,uint)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,string)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,bool)", p0, p1, p2, p3));
}
function log(address p0, uint p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,uint,address,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, uint p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, string memory p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, bool p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, address p3) internal view {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
/// @dev The original console.sol uses `int` and `uint` for computing function selectors, but it should
/// use `int256` and `uint256`. This modified version fixes that. This version is recommended
/// over `console.sol` if you don't need compatibility with Hardhat as the logs will show up in
/// forge stack traces. If you do need compatibility with Hardhat, you must use `console.sol`.
/// Reference: https://github.com/NomicFoundation/hardhat/issues/2178
library console2 {
address constant CONSOLE_ADDRESS = address(0x000000000000000000636F6e736F6c652e6c6f67);
function _castLogPayloadViewToPure(
function(bytes memory) internal view fnIn
) internal pure returns (function(bytes memory) internal pure fnOut) {
assembly {
fnOut := fnIn
}
}
function _sendLogPayload(bytes memory payload) internal pure {
_castLogPayloadViewToPure(_sendLogPayloadView)(payload);
}
function _sendLogPayloadView(bytes memory payload) private view {
uint256 payloadLength = payload.length;
address consoleAddress = CONSOLE_ADDRESS;
/// @solidity memory-safe-assembly
assembly {
let payloadStart := add(payload, 32)
let r := staticcall(gas(), consoleAddress, payloadStart, payloadLength, 0, 0)
}
}
function log() internal pure {
_sendLogPayload(abi.encodeWithSignature("log()"));
}
function logInt(int256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(int256)", p0));
}
function logUint(uint256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
}
function logString(string memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function logBool(bool p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function logAddress(address p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function logBytes(bytes memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes)", p0));
}
function logBytes1(bytes1 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes1)", p0));
}
function logBytes2(bytes2 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes2)", p0));
}
function logBytes3(bytes3 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes3)", p0));
}
function logBytes4(bytes4 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes4)", p0));
}
function logBytes5(bytes5 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes5)", p0));
}
function logBytes6(bytes6 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes6)", p0));
}
function logBytes7(bytes7 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes7)", p0));
}
function logBytes8(bytes8 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes8)", p0));
}
function logBytes9(bytes9 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes9)", p0));
}
function logBytes10(bytes10 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes10)", p0));
}
function logBytes11(bytes11 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes11)", p0));
}
function logBytes12(bytes12 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes12)", p0));
}
function logBytes13(bytes13 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes13)", p0));
}
function logBytes14(bytes14 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes14)", p0));
}
function logBytes15(bytes15 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes15)", p0));
}
function logBytes16(bytes16 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes16)", p0));
}
function logBytes17(bytes17 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes17)", p0));
}
function logBytes18(bytes18 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes18)", p0));
}
function logBytes19(bytes19 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes19)", p0));
}
function logBytes20(bytes20 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes20)", p0));
}
function logBytes21(bytes21 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes21)", p0));
}
function logBytes22(bytes22 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes22)", p0));
}
function logBytes23(bytes23 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes23)", p0));
}
function logBytes24(bytes24 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes24)", p0));
}
function logBytes25(bytes25 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes25)", p0));
}
function logBytes26(bytes26 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes26)", p0));
}
function logBytes27(bytes27 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes27)", p0));
}
function logBytes28(bytes28 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes28)", p0));
}
function logBytes29(bytes29 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes29)", p0));
}
function logBytes30(bytes30 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes30)", p0));
}
function logBytes31(bytes31 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes31)", p0));
}
function logBytes32(bytes32 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bytes32)", p0));
}
function log(uint256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256)", p0));
}
function log(int256 p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(int256)", p0));
}
function log(string memory p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string)", p0));
}
function log(bool p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool)", p0));
}
function log(address p0) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address)", p0));
}
function log(uint256 p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256)", p0, p1));
}
function log(uint256 p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string)", p0, p1));
}
function log(uint256 p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool)", p0, p1));
}
function log(uint256 p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address)", p0, p1));
}
function log(string memory p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256)", p0, p1));
}
function log(string memory p0, int256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,int256)", p0, p1));
}
function log(string memory p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string)", p0, p1));
}
function log(string memory p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool)", p0, p1));
}
function log(string memory p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address)", p0, p1));
}
function log(bool p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256)", p0, p1));
}
function log(bool p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string)", p0, p1));
}
function log(bool p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool)", p0, p1));
}
function log(bool p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address)", p0, p1));
}
function log(address p0, uint256 p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256)", p0, p1));
}
function log(address p0, string memory p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string)", p0, p1));
}
function log(address p0, bool p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool)", p0, p1));
}
function log(address p0, address p1) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address)", p0, p1));
}
function log(uint256 p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool)", p0, p1, p2));
}
function log(uint256 p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address)", p0, p1, p2));
}
function log(uint256 p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256)", p0, p1, p2));
}
function log(uint256 p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string)", p0, p1, p2));
}
function log(uint256 p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool)", p0, p1, p2));
}
function log(uint256 p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address)", p0, p1, p2));
}
function log(uint256 p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256)", p0, p1, p2));
}
function log(uint256 p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string)", p0, p1, p2));
}
function log(uint256 p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool)", p0, p1, p2));
}
function log(uint256 p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool)", p0, p1, p2));
}
function log(string memory p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address)", p0, p1, p2));
}
function log(string memory p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256)", p0, p1, p2));
}
function log(string memory p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string)", p0, p1, p2));
}
function log(string memory p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool)", p0, p1, p2));
}
function log(string memory p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address)", p0, p1, p2));
}
function log(string memory p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256)", p0, p1, p2));
}
function log(string memory p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string)", p0, p1, p2));
}
function log(string memory p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool)", p0, p1, p2));
}
function log(string memory p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address)", p0, p1, p2));
}
function log(string memory p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256)", p0, p1, p2));
}
function log(string memory p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string)", p0, p1, p2));
}
function log(string memory p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool)", p0, p1, p2));
}
function log(string memory p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address)", p0, p1, p2));
}
function log(bool p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256)", p0, p1, p2));
}
function log(bool p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string)", p0, p1, p2));
}
function log(bool p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool)", p0, p1, p2));
}
function log(bool p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address)", p0, p1, p2));
}
function log(bool p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256)", p0, p1, p2));
}
function log(bool p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string)", p0, p1, p2));
}
function log(bool p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool)", p0, p1, p2));
}
function log(bool p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address)", p0, p1, p2));
}
function log(bool p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256)", p0, p1, p2));
}
function log(bool p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string)", p0, p1, p2));
}
function log(bool p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool)", p0, p1, p2));
}
function log(bool p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address)", p0, p1, p2));
}
function log(bool p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256)", p0, p1, p2));
}
function log(bool p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string)", p0, p1, p2));
}
function log(bool p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool)", p0, p1, p2));
}
function log(bool p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address)", p0, p1, p2));
}
function log(address p0, uint256 p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256)", p0, p1, p2));
}
function log(address p0, uint256 p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string)", p0, p1, p2));
}
function log(address p0, uint256 p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool)", p0, p1, p2));
}
function log(address p0, uint256 p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address)", p0, p1, p2));
}
function log(address p0, string memory p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256)", p0, p1, p2));
}
function log(address p0, string memory p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string)", p0, p1, p2));
}
function log(address p0, string memory p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool)", p0, p1, p2));
}
function log(address p0, string memory p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address)", p0, p1, p2));
}
function log(address p0, bool p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256)", p0, p1, p2));
}
function log(address p0, bool p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string)", p0, p1, p2));
}
function log(address p0, bool p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool)", p0, p1, p2));
}
function log(address p0, bool p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address)", p0, p1, p2));
}
function log(address p0, address p1, uint256 p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256)", p0, p1, p2));
}
function log(address p0, address p1, string memory p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string)", p0, p1, p2));
}
function log(address p0, address p1, bool p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool)", p0, p1, p2));
}
function log(address p0, address p1, address p2) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address)", p0, p1, p2));
}
function log(uint256 p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,uint256,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,string,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,bool,address,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,uint256,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,string,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,bool,address)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,uint256)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,string)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,bool)", p0, p1, p2, p3));
}
function log(uint256 p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(uint256,address,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,uint256,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,string,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,bool,address,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,uint256,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,string,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,bool,address)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,uint256)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,string)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,bool)", p0, p1, p2, p3));
}
function log(string memory p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(string,address,address,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,string,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,string)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,uint256,address,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,string,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,string)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,string,address,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,string,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,string)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,bool,address,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,uint256,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,string,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,bool,address)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,uint256)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,string)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,bool)", p0, p1, p2, p3));
}
function log(bool p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(bool,address,address,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,string,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,bool,address)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,string)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,bool)", p0, p1, p2, p3));
}
function log(address p0, uint256 p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,uint256,address,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,string,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,bool,address)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,string)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,bool)", p0, p1, p2, p3));
}
function log(address p0, string memory p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,string,address,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,string,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,bool,address)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,string)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,bool)", p0, p1, p2, p3));
}
function log(address p0, bool p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,bool,address,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, uint256 p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,uint256,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, string memory p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,string,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, bool p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,bool,address)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, uint256 p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,uint256)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, string memory p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,string)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, bool p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,bool)", p0, p1, p2, p3));
}
function log(address p0, address p1, address p2, address p3) internal pure {
_sendLogPayload(abi.encodeWithSignature("log(address,address,address,address)", p0, p1, p2, p3));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
import {DSTest} from "ds-test/test.sol";
import {stdMath} from "./StdMath.sol";
abstract contract StdAssertions is DSTest {
event log_array(uint256[] val);
event log_array(int256[] val);
event log_array(address[] val);
event log_named_array(string key, uint256[] val);
event log_named_array(string key, int256[] val);
event log_named_array(string key, address[] val);
function fail(string memory err) internal virtual {
emit log_named_string("Error", err);
fail();
}
function assertFalse(bool data) internal virtual {
assertTrue(!data);
}
function assertFalse(bool data, string memory err) internal virtual {
assertTrue(!data, err);
}
function assertEq(bool a, bool b) internal virtual {
if (a != b) {
emit log("Error: a == b not satisfied [bool]");
emit log_named_string(" Left", a ? "true" : "false");
emit log_named_string(" Right", b ? "true" : "false");
fail();
}
}
function assertEq(bool a, bool b, string memory err) internal virtual {
if (a != b) {
emit log_named_string("Error", err);
assertEq(a, b);
}
}
function assertEq(bytes memory a, bytes memory b) internal virtual {
assertEq0(a, b);
}
function assertEq(bytes memory a, bytes memory b, string memory err) internal virtual {
assertEq0(a, b, err);
}
function assertEq(uint256[] memory a, uint256[] memory b) internal virtual {
if (keccak256(abi.encode(a)) != keccak256(abi.encode(b))) {
emit log("Error: a == b not satisfied [uint[]]");
emit log_named_array(" Left", a);
emit log_named_array(" Right", b);
fail();
}
}
function assertEq(int256[] memory a, int256[] memory b) internal virtual {
if (keccak256(abi.encode(a)) != keccak256(abi.encode(b))) {
emit log("Error: a == b not satisfied [int[]]");
emit log_named_array(" Left", a);
emit log_named_array(" Right", b);
fail();
}
}
function assertEq(address[] memory a, address[] memory b) internal virtual {
if (keccak256(abi.encode(a)) != keccak256(abi.encode(b))) {
emit log("Error: a == b not satisfied [address[]]");
emit log_named_array(" Left", a);
emit log_named_array(" Right", b);
fail();
}
}
function assertEq(uint256[] memory a, uint256[] memory b, string memory err) internal virtual {
if (keccak256(abi.encode(a)) != keccak256(abi.encode(b))) {
emit log_named_string("Error", err);
assertEq(a, b);
}
}
function assertEq(int256[] memory a, int256[] memory b, string memory err) internal virtual {
if (keccak256(abi.encode(a)) != keccak256(abi.encode(b))) {
emit log_named_string("Error", err);
assertEq(a, b);
}
}
function assertEq(address[] memory a, address[] memory b, string memory err) internal virtual {
if (keccak256(abi.encode(a)) != keccak256(abi.encode(b))) {
emit log_named_string("Error", err);
assertEq(a, b);
}
}
// Legacy helper
function assertEqUint(uint256 a, uint256 b) internal virtual {
assertEq(uint256(a), uint256(b));
}
function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta) internal virtual {
uint256 delta = stdMath.delta(a, b);
if (delta > maxDelta) {
emit log("Error: a ~= b not satisfied [uint]");
emit log_named_uint(" Left", a);
emit log_named_uint(" Right", b);
emit log_named_uint(" Max Delta", maxDelta);
emit log_named_uint(" Delta", delta);
fail();
}
}
function assertApproxEqAbs(uint256 a, uint256 b, uint256 maxDelta, string memory err) internal virtual {
uint256 delta = stdMath.delta(a, b);
if (delta > maxDelta) {
emit log_named_string("Error", err);
assertApproxEqAbs(a, b, maxDelta);
}
}
function assertApproxEqAbsDecimal(uint256 a, uint256 b, uint256 maxDelta, uint256 decimals) internal virtual {
uint256 delta = stdMath.delta(a, b);
if (delta > maxDelta) {
emit log("Error: a ~= b not satisfied [uint]");
emit log_named_decimal_uint(" Left", a, decimals);
emit log_named_decimal_uint(" Right", b, decimals);
emit log_named_decimal_uint(" Max Delta", maxDelta, decimals);
emit log_named_decimal_uint(" Delta", delta, decimals);
fail();
}
}
function assertApproxEqAbsDecimal(uint256 a, uint256 b, uint256 maxDelta, uint256 decimals, string memory err)
internal
virtual
{
uint256 delta = stdMath.delta(a, b);
if (delta > maxDelta) {
emit log_named_string("Error", err);
assertApproxEqAbsDecimal(a, b, maxDelta, decimals);
}
}
function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta) internal virtual {
uint256 delta = stdMath.delta(a, b);
if (delta > maxDelta) {
emit log("Error: a ~= b not satisfied [int]");
emit log_named_int(" Left", a);
emit log_named_int(" Right", b);
emit log_named_uint(" Max Delta", maxDelta);
emit log_named_uint(" Delta", delta);
fail();
}
}
function assertApproxEqAbs(int256 a, int256 b, uint256 maxDelta, string memory err) internal virtual {
uint256 delta = stdMath.delta(a, b);
if (delta > maxDelta) {
emit log_named_string("Error", err);
assertApproxEqAbs(a, b, maxDelta);
}
}
function assertApproxEqAbsDecimal(int256 a, int256 b, uint256 maxDelta, uint256 decimals) internal virtual {
uint256 delta = stdMath.delta(a, b);
if (delta > maxDelta) {
emit log("Error: a ~= b not satisfied [int]");
emit log_named_decimal_int(" Left", a, decimals);
emit log_named_decimal_int(" Right", b, decimals);
emit log_named_decimal_uint(" Max Delta", maxDelta, decimals);
emit log_named_decimal_uint(" Delta", delta, decimals);
fail();
}
}
function assertApproxEqAbsDecimal(int256 a, int256 b, uint256 maxDelta, uint256 decimals, string memory err)
internal
virtual
{
uint256 delta = stdMath.delta(a, b);
if (delta > maxDelta) {
emit log_named_string("Error", err);
assertApproxEqAbsDecimal(a, b, maxDelta, decimals);
}
}
function assertApproxEqRel(
uint256 a,
uint256 b,
uint256 maxPercentDelta // An 18 decimal fixed point number, where 1e18 == 100%
) internal virtual {
if (b == 0) return assertEq(a, b); // If the left is 0, right must be too.
uint256 percentDelta = stdMath.percentDelta(a, b);
if (percentDelta > maxPercentDelta) {
emit log("Error: a ~= b not satisfied [uint]");
emit log_named_uint(" Left", a);
emit log_named_uint(" Right", b);
emit log_named_decimal_uint(" Max % Delta", maxPercentDelta * 100, 18);
emit log_named_decimal_uint(" % Delta", percentDelta * 100, 18);
fail();
}
}
function assertApproxEqRel(
uint256 a,
uint256 b,
uint256 maxPercentDelta, // An 18 decimal fixed point number, where 1e18 == 100%
string memory err
) internal virtual {
if (b == 0) return assertEq(a, b, err); // If the left is 0, right must be too.
uint256 percentDelta = stdMath.percentDelta(a, b);
if (percentDelta > maxPercentDelta) {
emit log_named_string("Error", err);
assertApproxEqRel(a, b, maxPercentDelta);
}
}
function assertApproxEqRelDecimal(
uint256 a,
uint256 b,
uint256 maxPercentDelta, // An 18 decimal fixed point number, where 1e18 == 100%
uint256 decimals
) internal virtual {
if (b == 0) return assertEq(a, b); // If the left is 0, right must be too.
uint256 percentDelta = stdMath.percentDelta(a, b);
if (percentDelta > maxPercentDelta) {
emit log("Error: a ~= b not satisfied [uint]");
emit log_named_decimal_uint(" Left", a, decimals);
emit log_named_decimal_uint(" Right", b, decimals);
emit log_named_decimal_uint(" Max % Delta", maxPercentDelta * 100, 18);
emit log_named_decimal_uint(" % Delta", percentDelta * 100, 18);
fail();
}
}
function assertApproxEqRelDecimal(
uint256 a,
uint256 b,
uint256 maxPercentDelta, // An 18 decimal fixed point number, where 1e18 == 100%
uint256 decimals,
string memory err
) internal virtual {
if (b == 0) return assertEq(a, b, err); // If the left is 0, right must be too.
uint256 percentDelta = stdMath.percentDelta(a, b);
if (percentDelta > maxPercentDelta) {
emit log_named_string("Error", err);
assertApproxEqRelDecimal(a, b, maxPercentDelta, decimals);
}
}
function assertApproxEqRel(int256 a, int256 b, uint256 maxPercentDelta) internal virtual {
if (b == 0) return assertEq(a, b); // If the left is 0, right must be too.
uint256 percentDelta = stdMath.percentDelta(a, b);
if (percentDelta > maxPercentDelta) {
emit log("Error: a ~= b not satisfied [int]");
emit log_named_int(" Left", a);
emit log_named_int(" Right", b);
emit log_named_decimal_uint(" Max % Delta", maxPercentDelta * 100, 18);
emit log_named_decimal_uint(" % Delta", percentDelta * 100, 18);
fail();
}
}
function assertApproxEqRel(int256 a, int256 b, uint256 maxPercentDelta, string memory err) internal virtual {
if (b == 0) return assertEq(a, b, err); // If the left is 0, right must be too.
uint256 percentDelta = stdMath.percentDelta(a, b);
if (percentDelta > maxPercentDelta) {
emit log_named_string("Error", err);
assertApproxEqRel(a, b, maxPercentDelta);
}
}
function assertApproxEqRelDecimal(int256 a, int256 b, uint256 maxPercentDelta, uint256 decimals) internal virtual {
if (b == 0) return assertEq(a, b); // If the left is 0, right must be too.
uint256 percentDelta = stdMath.percentDelta(a, b);
if (percentDelta > maxPercentDelta) {
emit log("Error: a ~= b not satisfied [int]");
emit log_named_decimal_int(" Left", a, decimals);
emit log_named_decimal_int(" Right", b, decimals);
emit log_named_decimal_uint(" Max % Delta", maxPercentDelta * 100, 18);
emit log_named_decimal_uint(" % Delta", percentDelta * 100, 18);
fail();
}
}
function assertApproxEqRelDecimal(int256 a, int256 b, uint256 maxPercentDelta, uint256 decimals, string memory err)
internal
virtual
{
if (b == 0) return assertEq(a, b, err); // If the left is 0, right must be too.
uint256 percentDelta = stdMath.percentDelta(a, b);
if (percentDelta > maxPercentDelta) {
emit log_named_string("Error", err);
assertApproxEqRelDecimal(a, b, maxPercentDelta, decimals);
}
}
function assertEqCall(address target, bytes memory callDataA, bytes memory callDataB) internal virtual {
assertEqCall(target, callDataA, target, callDataB, true);
}
function assertEqCall(address targetA, bytes memory callDataA, address targetB, bytes memory callDataB)
internal
virtual
{
assertEqCall(targetA, callDataA, targetB, callDataB, true);
}
function assertEqCall(address target, bytes memory callDataA, bytes memory callDataB, bool strictRevertData)
internal
virtual
{
assertEqCall(target, callDataA, target, callDataB, strictRevertData);
}
function assertEqCall(
address targetA,
bytes memory callDataA,
address targetB,
bytes memory callDataB,
bool strictRevertData
) internal virtual {
(bool successA, bytes memory returnDataA) = address(targetA).call(callDataA);
(bool successB, bytes memory returnDataB) = address(targetB).call(callDataB);
if (successA && successB) {
assertEq(returnDataA, returnDataB, "Call return data does not match");
}
if (!successA && !successB && strictRevertData) {
assertEq(returnDataA, returnDataB, "Call revert data does not match");
}
if (!successA && successB) {
emit log("Error: Calls were not equal");
emit log_named_bytes(" Left call revert data", returnDataA);
emit log_named_bytes(" Right call return data", returnDataB);
fail();
}
if (successA && !successB) {
emit log("Error: Calls were not equal");
emit log_named_bytes(" Left call return data", returnDataA);
emit log_named_bytes(" Right call revert data", returnDataB);
fail();
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
pragma experimental ABIEncoderV2;
import {VmSafe} from "./Vm.sol";
/**
* StdChains provides information about EVM compatible chains that can be used in scripts/tests.
* For each chain, the chain's name, chain ID, and a default RPC URL are provided. Chains are
* identified by their alias, which is the same as the alias in the `[rpc_endpoints]` section of
* the `foundry.toml` file. For best UX, ensure the alias in the `foundry.toml` file match the
* alias used in this contract, which can be found as the first argument to the
* `setChainWithDefaultRpcUrl` call in the `initializeStdChains` function.
*
* There are two main ways to use this contract:
* 1. Set a chain with `setChain(string memory chainAlias, ChainData memory chain)` or
* `setChain(string memory chainAlias, Chain memory chain)`
* 2. Get a chain with `getChain(string memory chainAlias)` or `getChain(uint256 chainId)`.
*
* The first time either of those are used, chains are initialized with the default set of RPC URLs.
* This is done in `initializeStdChains`, which uses `setChainWithDefaultRpcUrl`. Defaults are recorded in
* `defaultRpcUrls`.
*
* The `setChain` function is straightforward, and it simply saves off the given chain data.
*
* The `getChain` methods use `getChainWithUpdatedRpcUrl` to return a chain. For example, let's say
* we want to retrieve the RPC URL for `mainnet`:
* - If you have specified data with `setChain`, it will return that.
* - If you have configured a mainnet RPC URL in `foundry.toml`, it will return the URL, provided it
* is valid (e.g. a URL is specified, or an environment variable is given and exists).
* - If neither of the above conditions is met, the default data is returned.
*
* Summarizing the above, the prioritization hierarchy is `setChain` -> `foundry.toml` -> environment variable -> defaults.
*/
abstract contract StdChains {
VmSafe private constant vm = VmSafe(address(uint160(uint256(keccak256("hevm cheat code")))));
bool private stdChainsInitialized;
struct ChainData {
string name;
uint256 chainId;
string rpcUrl;
}
struct Chain {
// The chain name.
string name;
// The chain's Chain ID.
uint256 chainId;
// The chain's alias. (i.e. what gets specified in `foundry.toml`).
string chainAlias;
// A default RPC endpoint for this chain.
// NOTE: This default RPC URL is included for convenience to facilitate quick tests and
// experimentation. Do not use this RPC URL for production test suites, CI, or other heavy
// usage as you will be throttled and this is a disservice to others who need this endpoint.
string rpcUrl;
}
// Maps from the chain's alias (matching the alias in the `foundry.toml` file) to chain data.
mapping(string => Chain) private chains;
// Maps from the chain's alias to it's default RPC URL.
mapping(string => string) private defaultRpcUrls;
// Maps from a chain ID to it's alias.
mapping(uint256 => string) private idToAlias;
bool private fallbackToDefaultRpcUrls = true;
// The RPC URL will be fetched from config or defaultRpcUrls if possible.
function getChain(string memory chainAlias) internal virtual returns (Chain memory chain) {
require(bytes(chainAlias).length != 0, "StdChains getChain(string): Chain alias cannot be the empty string.");
initializeStdChains();
chain = chains[chainAlias];
require(
chain.chainId != 0,
string(abi.encodePacked("StdChains getChain(string): Chain with alias \"", chainAlias, "\" not found."))
);
chain = getChainWithUpdatedRpcUrl(chainAlias, chain);
}
function getChain(uint256 chainId) internal virtual returns (Chain memory chain) {
require(chainId != 0, "StdChains getChain(uint256): Chain ID cannot be 0.");
initializeStdChains();
string memory chainAlias = idToAlias[chainId];
chain = chains[chainAlias];
require(
chain.chainId != 0,
string(abi.encodePacked("StdChains getChain(uint256): Chain with ID ", vm.toString(chainId), " not found."))
);
chain = getChainWithUpdatedRpcUrl(chainAlias, chain);
}
// set chain info, with priority to argument's rpcUrl field.
function setChain(string memory chainAlias, ChainData memory chain) internal virtual {
require(
bytes(chainAlias).length != 0,
"StdChains setChain(string,ChainData): Chain alias cannot be the empty string."
);
require(chain.chainId != 0, "StdChains setChain(string,ChainData): Chain ID cannot be 0.");
initializeStdChains();
string memory foundAlias = idToAlias[chain.chainId];
require(
bytes(foundAlias).length == 0 || keccak256(bytes(foundAlias)) == keccak256(bytes(chainAlias)),
string(
abi.encodePacked(
"StdChains setChain(string,ChainData): Chain ID ",
vm.toString(chain.chainId),
" already used by \"",
foundAlias,
"\"."
)
)
);
uint256 oldChainId = chains[chainAlias].chainId;
delete idToAlias[oldChainId];
chains[chainAlias] =
Chain({name: chain.name, chainId: chain.chainId, chainAlias: chainAlias, rpcUrl: chain.rpcUrl});
idToAlias[chain.chainId] = chainAlias;
}
// set chain info, with priority to argument's rpcUrl field.
function setChain(string memory chainAlias, Chain memory chain) internal virtual {
setChain(chainAlias, ChainData({name: chain.name, chainId: chain.chainId, rpcUrl: chain.rpcUrl}));
}
function _toUpper(string memory str) private pure returns (string memory) {
bytes memory strb = bytes(str);
bytes memory copy = new bytes(strb.length);
for (uint256 i = 0; i < strb.length; i++) {
bytes1 b = strb[i];
if (b >= 0x61 && b <= 0x7A) {
copy[i] = bytes1(uint8(b) - 32);
} else {
copy[i] = b;
}
}
return string(copy);
}
// lookup rpcUrl, in descending order of priority:
// current -> config (foundry.toml) -> environment variable -> default
function getChainWithUpdatedRpcUrl(string memory chainAlias, Chain memory chain) private returns (Chain memory) {
if (bytes(chain.rpcUrl).length == 0) {
try vm.rpcUrl(chainAlias) returns (string memory configRpcUrl) {
chain.rpcUrl = configRpcUrl;
} catch (bytes memory err) {
string memory envName = string(abi.encodePacked(_toUpper(chainAlias), "_RPC_URL"));
if (fallbackToDefaultRpcUrls) {
chain.rpcUrl = vm.envOr(envName, defaultRpcUrls[chainAlias]);
} else {
chain.rpcUrl = vm.envString(envName);
}
// distinguish 'not found' from 'cannot read'
bytes memory notFoundError =
abi.encodeWithSignature("CheatCodeError", string(abi.encodePacked("invalid rpc url ", chainAlias)));
if (keccak256(notFoundError) != keccak256(err) || bytes(chain.rpcUrl).length == 0) {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, err), mload(err))
}
}
}
}
return chain;
}
function setFallbackToDefaultRpcUrls(bool useDefault) internal {
fallbackToDefaultRpcUrls = useDefault;
}
function initializeStdChains() private {
if (stdChainsInitialized) return;
stdChainsInitialized = true;
// If adding an RPC here, make sure to test the default RPC URL in `testRpcs`
setChainWithDefaultRpcUrl("anvil", ChainData("Anvil", 31337, "http://127.0.0.1:8545"));
setChainWithDefaultRpcUrl(
"mainnet", ChainData("Mainnet", 1, "https://mainnet.infura.io/v3/b9794ad1ddf84dfb8c34d6bb5dca2001")
);
setChainWithDefaultRpcUrl(
"goerli", ChainData("Goerli", 5, "https://goerli.infura.io/v3/b9794ad1ddf84dfb8c34d6bb5dca2001")
);
setChainWithDefaultRpcUrl(
"sepolia", ChainData("Sepolia", 11155111, "https://sepolia.infura.io/v3/b9794ad1ddf84dfb8c34d6bb5dca2001")
);
setChainWithDefaultRpcUrl("optimism", ChainData("Optimism", 10, "https://mainnet.optimism.io"));
setChainWithDefaultRpcUrl("optimism_goerli", ChainData("Optimism Goerli", 420, "https://goerli.optimism.io"));
setChainWithDefaultRpcUrl("arbitrum_one", ChainData("Arbitrum One", 42161, "https://arb1.arbitrum.io/rpc"));
setChainWithDefaultRpcUrl(
"arbitrum_one_goerli", ChainData("Arbitrum One Goerli", 421613, "https://goerli-rollup.arbitrum.io/rpc")
);
setChainWithDefaultRpcUrl("arbitrum_nova", ChainData("Arbitrum Nova", 42170, "https://nova.arbitrum.io/rpc"));
setChainWithDefaultRpcUrl("polygon", ChainData("Polygon", 137, "https://polygon-rpc.com"));
setChainWithDefaultRpcUrl(
"polygon_mumbai", ChainData("Polygon Mumbai", 80001, "https://rpc-mumbai.maticvigil.com")
);
setChainWithDefaultRpcUrl("avalanche", ChainData("Avalanche", 43114, "https://api.avax.network/ext/bc/C/rpc"));
setChainWithDefaultRpcUrl(
"avalanche_fuji", ChainData("Avalanche Fuji", 43113, "https://api.avax-test.network/ext/bc/C/rpc")
);
setChainWithDefaultRpcUrl(
"bnb_smart_chain", ChainData("BNB Smart Chain", 56, "https://bsc-dataseed1.binance.org")
);
setChainWithDefaultRpcUrl(
"bnb_smart_chain_testnet",
ChainData("BNB Smart Chain Testnet", 97, "https://rpc.ankr.com/bsc_testnet_chapel")
);
setChainWithDefaultRpcUrl("gnosis_chain", ChainData("Gnosis Chain", 100, "https://rpc.gnosischain.com"));
}
// set chain info, with priority to chainAlias' rpc url in foundry.toml
function setChainWithDefaultRpcUrl(string memory chainAlias, ChainData memory chain) private {
string memory rpcUrl = chain.rpcUrl;
defaultRpcUrls[chainAlias] = rpcUrl;
chain.rpcUrl = "";
setChain(chainAlias, chain);
chain.rpcUrl = rpcUrl; // restore argument
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
pragma experimental ABIEncoderV2;
import {StdStorage, stdStorage} from "./StdStorage.sol";
import {Vm} from "./Vm.sol";
import {console2} from "./console2.sol";
abstract contract StdCheatsSafe {
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
bool private gasMeteringOff;
// Data structures to parse Transaction objects from the broadcast artifact
// that conform to EIP1559. The Raw structs is what is parsed from the JSON
// and then converted to the one that is used by the user for better UX.
struct RawTx1559 {
string[] arguments;
address contractAddress;
string contractName;
// json value name = function
string functionSig;
bytes32 hash;
// json value name = tx
RawTx1559Detail txDetail;
// json value name = type
string opcode;
}
struct RawTx1559Detail {
AccessList[] accessList;
bytes data;
address from;
bytes gas;
bytes nonce;
address to;
bytes txType;
bytes value;
}
struct Tx1559 {
string[] arguments;
address contractAddress;
string contractName;
string functionSig;
bytes32 hash;
Tx1559Detail txDetail;
string opcode;
}
struct Tx1559Detail {
AccessList[] accessList;
bytes data;
address from;
uint256 gas;
uint256 nonce;
address to;
uint256 txType;
uint256 value;
}
// Data structures to parse Transaction objects from the broadcast artifact
// that DO NOT conform to EIP1559. The Raw structs is what is parsed from the JSON
// and then converted to the one that is used by the user for better UX.
struct TxLegacy {
string[] arguments;
address contractAddress;
string contractName;
string functionSig;
string hash;
string opcode;
TxDetailLegacy transaction;
}
struct TxDetailLegacy {
AccessList[] accessList;
uint256 chainId;
bytes data;
address from;
uint256 gas;
uint256 gasPrice;
bytes32 hash;
uint256 nonce;
bytes1 opcode;
bytes32 r;
bytes32 s;
uint256 txType;
address to;
uint8 v;
uint256 value;
}
struct AccessList {
address accessAddress;
bytes32[] storageKeys;
}
// Data structures to parse Receipt objects from the broadcast artifact.
// The Raw structs is what is parsed from the JSON
// and then converted to the one that is used by the user for better UX.
struct RawReceipt {
bytes32 blockHash;
bytes blockNumber;
address contractAddress;
bytes cumulativeGasUsed;
bytes effectiveGasPrice;
address from;
bytes gasUsed;
RawReceiptLog[] logs;
bytes logsBloom;
bytes status;
address to;
bytes32 transactionHash;
bytes transactionIndex;
}
struct Receipt {
bytes32 blockHash;
uint256 blockNumber;
address contractAddress;
uint256 cumulativeGasUsed;
uint256 effectiveGasPrice;
address from;
uint256 gasUsed;
ReceiptLog[] logs;
bytes logsBloom;
uint256 status;
address to;
bytes32 transactionHash;
uint256 transactionIndex;
}
// Data structures to parse the entire broadcast artifact, assuming the
// transactions conform to EIP1559.
struct EIP1559ScriptArtifact {
string[] libraries;
string path;
string[] pending;
Receipt[] receipts;
uint256 timestamp;
Tx1559[] transactions;
TxReturn[] txReturns;
}
struct RawEIP1559ScriptArtifact {
string[] libraries;
string path;
string[] pending;
RawReceipt[] receipts;
TxReturn[] txReturns;
uint256 timestamp;
RawTx1559[] transactions;
}
struct RawReceiptLog {
// json value = address
address logAddress;
bytes32 blockHash;
bytes blockNumber;
bytes data;
bytes logIndex;
bool removed;
bytes32[] topics;
bytes32 transactionHash;
bytes transactionIndex;
bytes transactionLogIndex;
}
struct ReceiptLog {
// json value = address
address logAddress;
bytes32 blockHash;
uint256 blockNumber;
bytes data;
uint256 logIndex;
bytes32[] topics;
uint256 transactionIndex;
uint256 transactionLogIndex;
bool removed;
}
struct TxReturn {
string internalType;
string value;
}
struct Account {
address addr;
uint256 key;
}
// Checks that `addr` is not blacklisted by token contracts that have a blacklist.
function assumeNoBlacklisted(address token, address addr) internal virtual {
// Nothing to check if `token` is not a contract.
uint256 tokenCodeSize;
assembly {
tokenCodeSize := extcodesize(token)
}
require(tokenCodeSize > 0, "StdCheats assumeNoBlacklisted(address,address): Token address is not a contract.");
bool success;
bytes memory returnData;
// 4-byte selector for `isBlacklisted(address)`, used by USDC.
(success, returnData) = token.staticcall(abi.encodeWithSelector(0xfe575a87, addr));
vm.assume(!success || abi.decode(returnData, (bool)) == false);
// 4-byte selector for `isBlackListed(address)`, used by USDT.
(success, returnData) = token.staticcall(abi.encodeWithSelector(0xe47d6060, addr));
vm.assume(!success || abi.decode(returnData, (bool)) == false);
}
function assumeNoPrecompiles(address addr) internal virtual {
// Assembly required since `block.chainid` was introduced in 0.8.0.
uint256 chainId;
assembly {
chainId := chainid()
}
assumeNoPrecompiles(addr, chainId);
}
function assumeNoPrecompiles(address addr, uint256 chainId) internal pure virtual {
// Note: For some chains like Optimism these are technically predeploys (i.e. bytecode placed at a specific
// address), but the same rationale for excluding them applies so we include those too.
// These should be present on all EVM-compatible chains.
vm.assume(addr < address(0x1) || addr > address(0x9));
// forgefmt: disable-start
if (chainId == 10 || chainId == 420) {
// https://github.com/ethereum-optimism/optimism/blob/eaa371a0184b56b7ca6d9eb9cb0a2b78b2ccd864/op-bindings/predeploys/addresses.go#L6-L21
vm.assume(addr < address(0x4200000000000000000000000000000000000000) || addr > address(0x4200000000000000000000000000000000000800));
} else if (chainId == 42161 || chainId == 421613) {
// https://developer.arbitrum.io/useful-addresses#arbitrum-precompiles-l2-same-on-all-arb-chains
vm.assume(addr < address(0x0000000000000000000000000000000000000064) || addr > address(0x0000000000000000000000000000000000000068));
} else if (chainId == 43114 || chainId == 43113) {
// https://github.com/ava-labs/subnet-evm/blob/47c03fd007ecaa6de2c52ea081596e0a88401f58/precompile/params.go#L18-L59
vm.assume(addr < address(0x0100000000000000000000000000000000000000) || addr > address(0x01000000000000000000000000000000000000ff));
vm.assume(addr < address(0x0200000000000000000000000000000000000000) || addr > address(0x02000000000000000000000000000000000000FF));
vm.assume(addr < address(0x0300000000000000000000000000000000000000) || addr > address(0x03000000000000000000000000000000000000Ff));
}
// forgefmt: disable-end
}
function readEIP1559ScriptArtifact(string memory path)
internal
view
virtual
returns (EIP1559ScriptArtifact memory)
{
string memory data = vm.readFile(path);
bytes memory parsedData = vm.parseJson(data);
RawEIP1559ScriptArtifact memory rawArtifact = abi.decode(parsedData, (RawEIP1559ScriptArtifact));
EIP1559ScriptArtifact memory artifact;
artifact.libraries = rawArtifact.libraries;
artifact.path = rawArtifact.path;
artifact.timestamp = rawArtifact.timestamp;
artifact.pending = rawArtifact.pending;
artifact.txReturns = rawArtifact.txReturns;
artifact.receipts = rawToConvertedReceipts(rawArtifact.receipts);
artifact.transactions = rawToConvertedEIPTx1559s(rawArtifact.transactions);
return artifact;
}
function rawToConvertedEIPTx1559s(RawTx1559[] memory rawTxs) internal pure virtual returns (Tx1559[] memory) {
Tx1559[] memory txs = new Tx1559[](rawTxs.length);
for (uint256 i; i < rawTxs.length; i++) {
txs[i] = rawToConvertedEIPTx1559(rawTxs[i]);
}
return txs;
}
function rawToConvertedEIPTx1559(RawTx1559 memory rawTx) internal pure virtual returns (Tx1559 memory) {
Tx1559 memory transaction;
transaction.arguments = rawTx.arguments;
transaction.contractName = rawTx.contractName;
transaction.functionSig = rawTx.functionSig;
transaction.hash = rawTx.hash;
transaction.txDetail = rawToConvertedEIP1559Detail(rawTx.txDetail);
transaction.opcode = rawTx.opcode;
return transaction;
}
function rawToConvertedEIP1559Detail(RawTx1559Detail memory rawDetail)
internal
pure
virtual
returns (Tx1559Detail memory)
{
Tx1559Detail memory txDetail;
txDetail.data = rawDetail.data;
txDetail.from = rawDetail.from;
txDetail.to = rawDetail.to;
txDetail.nonce = _bytesToUint(rawDetail.nonce);
txDetail.txType = _bytesToUint(rawDetail.txType);
txDetail.value = _bytesToUint(rawDetail.value);
txDetail.gas = _bytesToUint(rawDetail.gas);
txDetail.accessList = rawDetail.accessList;
return txDetail;
}
function readTx1559s(string memory path) internal view virtual returns (Tx1559[] memory) {
string memory deployData = vm.readFile(path);
bytes memory parsedDeployData = vm.parseJson(deployData, ".transactions");
RawTx1559[] memory rawTxs = abi.decode(parsedDeployData, (RawTx1559[]));
return rawToConvertedEIPTx1559s(rawTxs);
}
function readTx1559(string memory path, uint256 index) internal view virtual returns (Tx1559 memory) {
string memory deployData = vm.readFile(path);
string memory key = string(abi.encodePacked(".transactions[", vm.toString(index), "]"));
bytes memory parsedDeployData = vm.parseJson(deployData, key);
RawTx1559 memory rawTx = abi.decode(parsedDeployData, (RawTx1559));
return rawToConvertedEIPTx1559(rawTx);
}
// Analogous to readTransactions, but for receipts.
function readReceipts(string memory path) internal view virtual returns (Receipt[] memory) {
string memory deployData = vm.readFile(path);
bytes memory parsedDeployData = vm.parseJson(deployData, ".receipts");
RawReceipt[] memory rawReceipts = abi.decode(parsedDeployData, (RawReceipt[]));
return rawToConvertedReceipts(rawReceipts);
}
function readReceipt(string memory path, uint256 index) internal view virtual returns (Receipt memory) {
string memory deployData = vm.readFile(path);
string memory key = string(abi.encodePacked(".receipts[", vm.toString(index), "]"));
bytes memory parsedDeployData = vm.parseJson(deployData, key);
RawReceipt memory rawReceipt = abi.decode(parsedDeployData, (RawReceipt));
return rawToConvertedReceipt(rawReceipt);
}
function rawToConvertedReceipts(RawReceipt[] memory rawReceipts) internal pure virtual returns (Receipt[] memory) {
Receipt[] memory receipts = new Receipt[](rawReceipts.length);
for (uint256 i; i < rawReceipts.length; i++) {
receipts[i] = rawToConvertedReceipt(rawReceipts[i]);
}
return receipts;
}
function rawToConvertedReceipt(RawReceipt memory rawReceipt) internal pure virtual returns (Receipt memory) {
Receipt memory receipt;
receipt.blockHash = rawReceipt.blockHash;
receipt.to = rawReceipt.to;
receipt.from = rawReceipt.from;
receipt.contractAddress = rawReceipt.contractAddress;
receipt.effectiveGasPrice = _bytesToUint(rawReceipt.effectiveGasPrice);
receipt.cumulativeGasUsed = _bytesToUint(rawReceipt.cumulativeGasUsed);
receipt.gasUsed = _bytesToUint(rawReceipt.gasUsed);
receipt.status = _bytesToUint(rawReceipt.status);
receipt.transactionIndex = _bytesToUint(rawReceipt.transactionIndex);
receipt.blockNumber = _bytesToUint(rawReceipt.blockNumber);
receipt.logs = rawToConvertedReceiptLogs(rawReceipt.logs);
receipt.logsBloom = rawReceipt.logsBloom;
receipt.transactionHash = rawReceipt.transactionHash;
return receipt;
}
function rawToConvertedReceiptLogs(RawReceiptLog[] memory rawLogs)
internal
pure
virtual
returns (ReceiptLog[] memory)
{
ReceiptLog[] memory logs = new ReceiptLog[](rawLogs.length);
for (uint256 i; i < rawLogs.length; i++) {
logs[i].logAddress = rawLogs[i].logAddress;
logs[i].blockHash = rawLogs[i].blockHash;
logs[i].blockNumber = _bytesToUint(rawLogs[i].blockNumber);
logs[i].data = rawLogs[i].data;
logs[i].logIndex = _bytesToUint(rawLogs[i].logIndex);
logs[i].topics = rawLogs[i].topics;
logs[i].transactionIndex = _bytesToUint(rawLogs[i].transactionIndex);
logs[i].transactionLogIndex = _bytesToUint(rawLogs[i].transactionLogIndex);
logs[i].removed = rawLogs[i].removed;
}
return logs;
}
// Deploy a contract by fetching the contract bytecode from
// the artifacts directory
// e.g. `deployCode(code, abi.encode(arg1,arg2,arg3))`
function deployCode(string memory what, bytes memory args) internal virtual returns (address addr) {
bytes memory bytecode = abi.encodePacked(vm.getCode(what), args);
/// @solidity memory-safe-assembly
assembly {
addr := create(0, add(bytecode, 0x20), mload(bytecode))
}
require(addr != address(0), "StdCheats deployCode(string,bytes): Deployment failed.");
}
function deployCode(string memory what) internal virtual returns (address addr) {
bytes memory bytecode = vm.getCode(what);
/// @solidity memory-safe-assembly
assembly {
addr := create(0, add(bytecode, 0x20), mload(bytecode))
}
require(addr != address(0), "StdCheats deployCode(string): Deployment failed.");
}
/// @dev deploy contract with value on construction
function deployCode(string memory what, bytes memory args, uint256 val) internal virtual returns (address addr) {
bytes memory bytecode = abi.encodePacked(vm.getCode(what), args);
/// @solidity memory-safe-assembly
assembly {
addr := create(val, add(bytecode, 0x20), mload(bytecode))
}
require(addr != address(0), "StdCheats deployCode(string,bytes,uint256): Deployment failed.");
}
function deployCode(string memory what, uint256 val) internal virtual returns (address addr) {
bytes memory bytecode = vm.getCode(what);
/// @solidity memory-safe-assembly
assembly {
addr := create(val, add(bytecode, 0x20), mload(bytecode))
}
require(addr != address(0), "StdCheats deployCode(string,uint256): Deployment failed.");
}
// creates a labeled address and the corresponding private key
function makeAddrAndKey(string memory name) internal virtual returns (address addr, uint256 privateKey) {
privateKey = uint256(keccak256(abi.encodePacked(name)));
addr = vm.addr(privateKey);
vm.label(addr, name);
}
// creates a labeled address
function makeAddr(string memory name) internal virtual returns (address addr) {
(addr,) = makeAddrAndKey(name);
}
// Destroys an account immediately, sending the balance to beneficiary.
// Destroying means: balance will be zero, code will be empty, and nonce will be 0
// This is similar to selfdestruct but not identical: selfdestruct destroys code and nonce
// only after tx ends, this will run immediately.
function destroyAccount(address who, address beneficiary) internal virtual {
uint256 currBalance = who.balance;
vm.etch(who, abi.encode());
vm.deal(who, 0);
vm.resetNonce(who);
uint256 beneficiaryBalance = beneficiary.balance;
vm.deal(beneficiary, currBalance + beneficiaryBalance);
}
// creates a struct containing both a labeled address and the corresponding private key
function makeAccount(string memory name) internal virtual returns (Account memory account) {
(account.addr, account.key) = makeAddrAndKey(name);
}
function deriveRememberKey(string memory mnemonic, uint32 index)
internal
virtual
returns (address who, uint256 privateKey)
{
privateKey = vm.deriveKey(mnemonic, index);
who = vm.rememberKey(privateKey);
}
function _bytesToUint(bytes memory b) private pure returns (uint256) {
require(b.length <= 32, "StdCheats _bytesToUint(bytes): Bytes length exceeds 32.");
return abi.decode(abi.encodePacked(new bytes(32 - b.length), b), (uint256));
}
function isFork() internal view virtual returns (bool status) {
try vm.activeFork() {
status = true;
} catch (bytes memory) {}
}
modifier skipWhenForking() {
if (!isFork()) {
_;
}
}
modifier skipWhenNotForking() {
if (isFork()) {
_;
}
}
modifier noGasMetering() {
vm.pauseGasMetering();
// To prevent turning gas monitoring back on with nested functions that use this modifier,
// we check if gasMetering started in the off position. If it did, we don't want to turn
// it back on until we exit the top level function that used the modifier
//
// i.e. funcA() noGasMetering { funcB() }, where funcB has noGasMetering as well.
// funcA will have `gasStartedOff` as false, funcB will have it as true,
// so we only turn metering back on at the end of the funcA
bool gasStartedOff = gasMeteringOff;
gasMeteringOff = true;
_;
// if gas metering was on when this modifier was called, turn it back on at the end
if (!gasStartedOff) {
gasMeteringOff = false;
vm.resumeGasMetering();
}
}
// a cheat for fuzzing addresses that are payable only
// see https://github.com/foundry-rs/foundry/issues/3631
function assumePayable(address addr) internal virtual {
(bool success,) = payable(addr).call{value: 0}("");
vm.assume(success);
}
}
// Wrappers around cheatcodes to avoid footguns
abstract contract StdCheats is StdCheatsSafe {
using stdStorage for StdStorage;
StdStorage private stdstore;
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
// Skip forward or rewind time by the specified number of seconds
function skip(uint256 time) internal virtual {
vm.warp(block.timestamp + time);
}
function rewind(uint256 time) internal virtual {
vm.warp(block.timestamp - time);
}
// Setup a prank from an address that has some ether
function hoax(address msgSender) internal virtual {
vm.deal(msgSender, 1 << 128);
vm.prank(msgSender);
}
function hoax(address msgSender, uint256 give) internal virtual {
vm.deal(msgSender, give);
vm.prank(msgSender);
}
function hoax(address msgSender, address origin) internal virtual {
vm.deal(msgSender, 1 << 128);
vm.prank(msgSender, origin);
}
function hoax(address msgSender, address origin, uint256 give) internal virtual {
vm.deal(msgSender, give);
vm.prank(msgSender, origin);
}
// Start perpetual prank from an address that has some ether
function startHoax(address msgSender) internal virtual {
vm.deal(msgSender, 1 << 128);
vm.startPrank(msgSender);
}
function startHoax(address msgSender, uint256 give) internal virtual {
vm.deal(msgSender, give);
vm.startPrank(msgSender);
}
// Start perpetual prank from an address that has some ether
// tx.origin is set to the origin parameter
function startHoax(address msgSender, address origin) internal virtual {
vm.deal(msgSender, 1 << 128);
vm.startPrank(msgSender, origin);
}
function startHoax(address msgSender, address origin, uint256 give) internal virtual {
vm.deal(msgSender, give);
vm.startPrank(msgSender, origin);
}
function changePrank(address msgSender) internal virtual {
vm.stopPrank();
vm.startPrank(msgSender);
}
function changePrank(address msgSender, address txOrigin) internal virtual {
vm.stopPrank();
vm.startPrank(msgSender, txOrigin);
}
// The same as Vm's `deal`
// Use the alternative signature for ERC20 tokens
function deal(address to, uint256 give) internal virtual {
vm.deal(to, give);
}
// Set the balance of an account for any ERC20 token
// Use the alternative signature to update `totalSupply`
function deal(address token, address to, uint256 give) internal virtual {
deal(token, to, give, false);
}
// Set the balance of an account for any ERC1155 token
// Use the alternative signature to update `totalSupply`
function dealERC1155(address token, address to, uint256 id, uint256 give) internal virtual {
dealERC1155(token, to, id, give, false);
}
function deal(address token, address to, uint256 give, bool adjust) internal virtual {
// get current balance
(, bytes memory balData) = token.staticcall(abi.encodeWithSelector(0x70a08231, to));
uint256 prevBal = abi.decode(balData, (uint256));
// update balance
stdstore.target(token).sig(0x70a08231).with_key(to).checked_write(give);
// update total supply
if (adjust) {
(, bytes memory totSupData) = token.staticcall(abi.encodeWithSelector(0x18160ddd));
uint256 totSup = abi.decode(totSupData, (uint256));
if (give < prevBal) {
totSup -= (prevBal - give);
} else {
totSup += (give - prevBal);
}
stdstore.target(token).sig(0x18160ddd).checked_write(totSup);
}
}
function dealERC1155(address token, address to, uint256 id, uint256 give, bool adjust) internal virtual {
// get current balance
(, bytes memory balData) = token.staticcall(abi.encodeWithSelector(0x00fdd58e, to, id));
uint256 prevBal = abi.decode(balData, (uint256));
// update balance
stdstore.target(token).sig(0x00fdd58e).with_key(to).with_key(id).checked_write(give);
// update total supply
if (adjust) {
(, bytes memory totSupData) = token.staticcall(abi.encodeWithSelector(0xbd85b039, id));
require(
totSupData.length != 0,
"StdCheats deal(address,address,uint,uint,bool): target contract is not ERC1155Supply."
);
uint256 totSup = abi.decode(totSupData, (uint256));
if (give < prevBal) {
totSup -= (prevBal - give);
} else {
totSup += (give - prevBal);
}
stdstore.target(token).sig(0xbd85b039).with_key(id).checked_write(totSup);
}
}
function dealERC721(address token, address to, uint256 id) internal virtual {
// check if token id is already minted and the actual owner.
(bool successMinted, bytes memory ownerData) = token.staticcall(abi.encodeWithSelector(0x6352211e, id));
require(successMinted, "StdCheats deal(address,address,uint,bool): id not minted.");
// get owner current balance
(, bytes memory fromBalData) =
token.staticcall(abi.encodeWithSelector(0x70a08231, abi.decode(ownerData, (address))));
uint256 fromPrevBal = abi.decode(fromBalData, (uint256));
// get new user current balance
(, bytes memory toBalData) = token.staticcall(abi.encodeWithSelector(0x70a08231, to));
uint256 toPrevBal = abi.decode(toBalData, (uint256));
// update balances
stdstore.target(token).sig(0x70a08231).with_key(abi.decode(ownerData, (address))).checked_write(--fromPrevBal);
stdstore.target(token).sig(0x70a08231).with_key(to).checked_write(++toPrevBal);
// update owner
stdstore.target(token).sig(0x6352211e).with_key(id).checked_write(to);
}
}// SPDX-License-Identifier: MIT
// Panics work for versions >=0.8.0, but we lowered the pragma to make this compatible with Test
pragma solidity >=0.6.2 <0.9.0;
library stdError {
bytes public constant assertionError = abi.encodeWithSignature("Panic(uint256)", 0x01);
bytes public constant arithmeticError = abi.encodeWithSignature("Panic(uint256)", 0x11);
bytes public constant divisionError = abi.encodeWithSignature("Panic(uint256)", 0x12);
bytes public constant enumConversionError = abi.encodeWithSignature("Panic(uint256)", 0x21);
bytes public constant encodeStorageError = abi.encodeWithSignature("Panic(uint256)", 0x22);
bytes public constant popError = abi.encodeWithSignature("Panic(uint256)", 0x31);
bytes public constant indexOOBError = abi.encodeWithSignature("Panic(uint256)", 0x32);
bytes public constant memOverflowError = abi.encodeWithSignature("Panic(uint256)", 0x41);
bytes public constant zeroVarError = abi.encodeWithSignature("Panic(uint256)", 0x51);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
pragma experimental ABIEncoderV2;
contract StdInvariant {
struct FuzzSelector {
address addr;
bytes4[] selectors;
}
address[] private _excludedContracts;
address[] private _excludedSenders;
address[] private _targetedContracts;
address[] private _targetedSenders;
string[] private _excludedArtifacts;
string[] private _targetedArtifacts;
FuzzSelector[] private _targetedArtifactSelectors;
FuzzSelector[] private _targetedSelectors;
// Functions for users:
// These are intended to be called in tests.
function excludeContract(address newExcludedContract_) internal {
_excludedContracts.push(newExcludedContract_);
}
function excludeSender(address newExcludedSender_) internal {
_excludedSenders.push(newExcludedSender_);
}
function excludeArtifact(string memory newExcludedArtifact_) internal {
_excludedArtifacts.push(newExcludedArtifact_);
}
function targetArtifact(string memory newTargetedArtifact_) internal {
_targetedArtifacts.push(newTargetedArtifact_);
}
function targetArtifactSelector(FuzzSelector memory newTargetedArtifactSelector_) internal {
_targetedArtifactSelectors.push(newTargetedArtifactSelector_);
}
function targetContract(address newTargetedContract_) internal {
_targetedContracts.push(newTargetedContract_);
}
function targetSelector(FuzzSelector memory newTargetedSelector_) internal {
_targetedSelectors.push(newTargetedSelector_);
}
function targetSender(address newTargetedSender_) internal {
_targetedSenders.push(newTargetedSender_);
}
// Functions for forge:
// These are called by forge to run invariant tests and don't need to be called in tests.
function excludeArtifacts() public view returns (string[] memory excludedArtifacts_) {
excludedArtifacts_ = _excludedArtifacts;
}
function excludeContracts() public view returns (address[] memory excludedContracts_) {
excludedContracts_ = _excludedContracts;
}
function excludeSenders() public view returns (address[] memory excludedSenders_) {
excludedSenders_ = _excludedSenders;
}
function targetArtifacts() public view returns (string[] memory targetedArtifacts_) {
targetedArtifacts_ = _targetedArtifacts;
}
function targetArtifactSelectors() public view returns (FuzzSelector[] memory targetedArtifactSelectors_) {
targetedArtifactSelectors_ = _targetedArtifactSelectors;
}
function targetContracts() public view returns (address[] memory targetedContracts_) {
targetedContracts_ = _targetedContracts;
}
function targetSelectors() public view returns (FuzzSelector[] memory targetedSelectors_) {
targetedSelectors_ = _targetedSelectors;
}
function targetSenders() public view returns (address[] memory targetedSenders_) {
targetedSenders_ = _targetedSenders;
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.0 <0.9.0;
pragma experimental ABIEncoderV2;
import {VmSafe} from "./Vm.sol";
// Helpers for parsing and writing JSON files
// To parse:
// ```
// using stdJson for string;
// string memory json = vm.readFile("some_peth");
// json.parseUint("<json_path>");
// ```
// To write:
// ```
// using stdJson for string;
// string memory json = "deploymentArtifact";
// Contract contract = new Contract();
// json.serialize("contractAddress", address(contract));
// json = json.serialize("deploymentTimes", uint(1));
// // store the stringified JSON to the 'json' variable we have been using as a key
// // as we won't need it any longer
// string memory json2 = "finalArtifact";
// string memory final = json2.serialize("depArtifact", json);
// final.write("<some_path>");
// ```
library stdJson {
VmSafe private constant vm = VmSafe(address(uint160(uint256(keccak256("hevm cheat code")))));
function parseRaw(string memory json, string memory key) internal pure returns (bytes memory) {
return vm.parseJson(json, key);
}
function readUint(string memory json, string memory key) internal returns (uint256) {
return vm.parseJsonUint(json, key);
}
function readUintArray(string memory json, string memory key) internal returns (uint256[] memory) {
return vm.parseJsonUintArray(json, key);
}
function readInt(string memory json, string memory key) internal returns (int256) {
return vm.parseJsonInt(json, key);
}
function readIntArray(string memory json, string memory key) internal returns (int256[] memory) {
return vm.parseJsonIntArray(json, key);
}
function readBytes32(string memory json, string memory key) internal returns (bytes32) {
return vm.parseJsonBytes32(json, key);
}
function readBytes32Array(string memory json, string memory key) internal returns (bytes32[] memory) {
return vm.parseJsonBytes32Array(json, key);
}
function readString(string memory json, string memory key) internal returns (string memory) {
return vm.parseJsonString(json, key);
}
function readStringArray(string memory json, string memory key) internal returns (string[] memory) {
return vm.parseJsonStringArray(json, key);
}
function readAddress(string memory json, string memory key) internal returns (address) {
return vm.parseJsonAddress(json, key);
}
function readAddressArray(string memory json, string memory key) internal returns (address[] memory) {
return vm.parseJsonAddressArray(json, key);
}
function readBool(string memory json, string memory key) internal returns (bool) {
return vm.parseJsonBool(json, key);
}
function readBoolArray(string memory json, string memory key) internal returns (bool[] memory) {
return vm.parseJsonBoolArray(json, key);
}
function readBytes(string memory json, string memory key) internal returns (bytes memory) {
return vm.parseJsonBytes(json, key);
}
function readBytesArray(string memory json, string memory key) internal returns (bytes[] memory) {
return vm.parseJsonBytesArray(json, key);
}
function serialize(string memory jsonKey, string memory key, bool value) internal returns (string memory) {
return vm.serializeBool(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, bool[] memory value)
internal
returns (string memory)
{
return vm.serializeBool(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, uint256 value) internal returns (string memory) {
return vm.serializeUint(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, uint256[] memory value)
internal
returns (string memory)
{
return vm.serializeUint(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, int256 value) internal returns (string memory) {
return vm.serializeInt(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, int256[] memory value)
internal
returns (string memory)
{
return vm.serializeInt(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, address value) internal returns (string memory) {
return vm.serializeAddress(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, address[] memory value)
internal
returns (string memory)
{
return vm.serializeAddress(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, bytes32 value) internal returns (string memory) {
return vm.serializeBytes32(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, bytes32[] memory value)
internal
returns (string memory)
{
return vm.serializeBytes32(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, bytes memory value) internal returns (string memory) {
return vm.serializeBytes(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, bytes[] memory value)
internal
returns (string memory)
{
return vm.serializeBytes(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, string memory value)
internal
returns (string memory)
{
return vm.serializeString(jsonKey, key, value);
}
function serialize(string memory jsonKey, string memory key, string[] memory value)
internal
returns (string memory)
{
return vm.serializeString(jsonKey, key, value);
}
function write(string memory jsonKey, string memory path) internal {
vm.writeJson(jsonKey, path);
}
function write(string memory jsonKey, string memory path, string memory valueKey) internal {
vm.writeJson(jsonKey, path, valueKey);
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
library stdMath {
int256 private constant INT256_MIN = -57896044618658097711785492504343953926634992332820282019728792003956564819968;
function abs(int256 a) internal pure returns (uint256) {
// Required or it will fail when `a = type(int256).min`
if (a == INT256_MIN) {
return 57896044618658097711785492504343953926634992332820282019728792003956564819968;
}
return uint256(a > 0 ? a : -a);
}
function delta(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a - b : b - a;
}
function delta(int256 a, int256 b) internal pure returns (uint256) {
// a and b are of the same sign
// this works thanks to two's complement, the left-most bit is the sign bit
if ((a ^ b) > -1) {
return delta(abs(a), abs(b));
}
// a and b are of opposite signs
return abs(a) + abs(b);
}
function percentDelta(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 absDelta = delta(a, b);
return absDelta * 1e18 / b;
}
function percentDelta(int256 a, int256 b) internal pure returns (uint256) {
uint256 absDelta = delta(a, b);
uint256 absB = abs(b);
return absDelta * 1e18 / absB;
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
import {Vm} from "./Vm.sol";
struct StdStorage {
mapping(address => mapping(bytes4 => mapping(bytes32 => uint256))) slots;
mapping(address => mapping(bytes4 => mapping(bytes32 => bool))) finds;
bytes32[] _keys;
bytes4 _sig;
uint256 _depth;
address _target;
bytes32 _set;
}
library stdStorageSafe {
event SlotFound(address who, bytes4 fsig, bytes32 keysHash, uint256 slot);
event WARNING_UninitedSlot(address who, uint256 slot);
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
function sigs(string memory sigStr) internal pure returns (bytes4) {
return bytes4(keccak256(bytes(sigStr)));
}
/// @notice find an arbitrary storage slot given a function sig, input data, address of the contract and a value to check against
// slot complexity:
// if flat, will be bytes32(uint256(uint));
// if map, will be keccak256(abi.encode(key, uint(slot)));
// if deep map, will be keccak256(abi.encode(key1, keccak256(abi.encode(key0, uint(slot)))));
// if map struct, will be bytes32(uint256(keccak256(abi.encode(key1, keccak256(abi.encode(key0, uint(slot)))))) + structFieldDepth);
function find(StdStorage storage self) internal returns (uint256) {
address who = self._target;
bytes4 fsig = self._sig;
uint256 field_depth = self._depth;
bytes32[] memory ins = self._keys;
// calldata to test against
if (self.finds[who][fsig][keccak256(abi.encodePacked(ins, field_depth))]) {
return self.slots[who][fsig][keccak256(abi.encodePacked(ins, field_depth))];
}
bytes memory cald = abi.encodePacked(fsig, flatten(ins));
vm.record();
bytes32 fdat;
{
(, bytes memory rdat) = who.staticcall(cald);
fdat = bytesToBytes32(rdat, 32 * field_depth);
}
(bytes32[] memory reads,) = vm.accesses(address(who));
if (reads.length == 1) {
bytes32 curr = vm.load(who, reads[0]);
if (curr == bytes32(0)) {
emit WARNING_UninitedSlot(who, uint256(reads[0]));
}
if (fdat != curr) {
require(
false,
"stdStorage find(StdStorage): Packed slot. This would cause dangerous overwriting and currently isn't supported."
);
}
emit SlotFound(who, fsig, keccak256(abi.encodePacked(ins, field_depth)), uint256(reads[0]));
self.slots[who][fsig][keccak256(abi.encodePacked(ins, field_depth))] = uint256(reads[0]);
self.finds[who][fsig][keccak256(abi.encodePacked(ins, field_depth))] = true;
} else if (reads.length > 1) {
for (uint256 i = 0; i < reads.length; i++) {
bytes32 prev = vm.load(who, reads[i]);
if (prev == bytes32(0)) {
emit WARNING_UninitedSlot(who, uint256(reads[i]));
}
// store
vm.store(who, reads[i], bytes32(hex"1337"));
bool success;
bytes memory rdat;
{
(success, rdat) = who.staticcall(cald);
fdat = bytesToBytes32(rdat, 32 * field_depth);
}
if (success && fdat == bytes32(hex"1337")) {
// we found which of the slots is the actual one
emit SlotFound(who, fsig, keccak256(abi.encodePacked(ins, field_depth)), uint256(reads[i]));
self.slots[who][fsig][keccak256(abi.encodePacked(ins, field_depth))] = uint256(reads[i]);
self.finds[who][fsig][keccak256(abi.encodePacked(ins, field_depth))] = true;
vm.store(who, reads[i], prev);
break;
}
vm.store(who, reads[i], prev);
}
} else {
revert("stdStorage find(StdStorage): No storage use detected for target.");
}
require(
self.finds[who][fsig][keccak256(abi.encodePacked(ins, field_depth))],
"stdStorage find(StdStorage): Slot(s) not found."
);
delete self._target;
delete self._sig;
delete self._keys;
delete self._depth;
return self.slots[who][fsig][keccak256(abi.encodePacked(ins, field_depth))];
}
function target(StdStorage storage self, address _target) internal returns (StdStorage storage) {
self._target = _target;
return self;
}
function sig(StdStorage storage self, bytes4 _sig) internal returns (StdStorage storage) {
self._sig = _sig;
return self;
}
function sig(StdStorage storage self, string memory _sig) internal returns (StdStorage storage) {
self._sig = sigs(_sig);
return self;
}
function with_key(StdStorage storage self, address who) internal returns (StdStorage storage) {
self._keys.push(bytes32(uint256(uint160(who))));
return self;
}
function with_key(StdStorage storage self, uint256 amt) internal returns (StdStorage storage) {
self._keys.push(bytes32(amt));
return self;
}
function with_key(StdStorage storage self, bytes32 key) internal returns (StdStorage storage) {
self._keys.push(key);
return self;
}
function depth(StdStorage storage self, uint256 _depth) internal returns (StdStorage storage) {
self._depth = _depth;
return self;
}
function read(StdStorage storage self) private returns (bytes memory) {
address t = self._target;
uint256 s = find(self);
return abi.encode(vm.load(t, bytes32(s)));
}
function read_bytes32(StdStorage storage self) internal returns (bytes32) {
return abi.decode(read(self), (bytes32));
}
function read_bool(StdStorage storage self) internal returns (bool) {
int256 v = read_int(self);
if (v == 0) return false;
if (v == 1) return true;
revert("stdStorage read_bool(StdStorage): Cannot decode. Make sure you are reading a bool.");
}
function read_address(StdStorage storage self) internal returns (address) {
return abi.decode(read(self), (address));
}
function read_uint(StdStorage storage self) internal returns (uint256) {
return abi.decode(read(self), (uint256));
}
function read_int(StdStorage storage self) internal returns (int256) {
return abi.decode(read(self), (int256));
}
function bytesToBytes32(bytes memory b, uint256 offset) private pure returns (bytes32) {
bytes32 out;
uint256 max = b.length > 32 ? 32 : b.length;
for (uint256 i = 0; i < max; i++) {
out |= bytes32(b[offset + i] & 0xFF) >> (i * 8);
}
return out;
}
function flatten(bytes32[] memory b) private pure returns (bytes memory) {
bytes memory result = new bytes(b.length * 32);
for (uint256 i = 0; i < b.length; i++) {
bytes32 k = b[i];
/// @solidity memory-safe-assembly
assembly {
mstore(add(result, add(32, mul(32, i))), k)
}
}
return result;
}
}
library stdStorage {
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
function sigs(string memory sigStr) internal pure returns (bytes4) {
return stdStorageSafe.sigs(sigStr);
}
function find(StdStorage storage self) internal returns (uint256) {
return stdStorageSafe.find(self);
}
function target(StdStorage storage self, address _target) internal returns (StdStorage storage) {
return stdStorageSafe.target(self, _target);
}
function sig(StdStorage storage self, bytes4 _sig) internal returns (StdStorage storage) {
return stdStorageSafe.sig(self, _sig);
}
function sig(StdStorage storage self, string memory _sig) internal returns (StdStorage storage) {
return stdStorageSafe.sig(self, _sig);
}
function with_key(StdStorage storage self, address who) internal returns (StdStorage storage) {
return stdStorageSafe.with_key(self, who);
}
function with_key(StdStorage storage self, uint256 amt) internal returns (StdStorage storage) {
return stdStorageSafe.with_key(self, amt);
}
function with_key(StdStorage storage self, bytes32 key) internal returns (StdStorage storage) {
return stdStorageSafe.with_key(self, key);
}
function depth(StdStorage storage self, uint256 _depth) internal returns (StdStorage storage) {
return stdStorageSafe.depth(self, _depth);
}
function checked_write(StdStorage storage self, address who) internal {
checked_write(self, bytes32(uint256(uint160(who))));
}
function checked_write(StdStorage storage self, uint256 amt) internal {
checked_write(self, bytes32(amt));
}
function checked_write(StdStorage storage self, bool write) internal {
bytes32 t;
/// @solidity memory-safe-assembly
assembly {
t := write
}
checked_write(self, t);
}
function checked_write(StdStorage storage self, bytes32 set) internal {
address who = self._target;
bytes4 fsig = self._sig;
uint256 field_depth = self._depth;
bytes32[] memory ins = self._keys;
bytes memory cald = abi.encodePacked(fsig, flatten(ins));
if (!self.finds[who][fsig][keccak256(abi.encodePacked(ins, field_depth))]) {
find(self);
}
bytes32 slot = bytes32(self.slots[who][fsig][keccak256(abi.encodePacked(ins, field_depth))]);
bytes32 fdat;
{
(, bytes memory rdat) = who.staticcall(cald);
fdat = bytesToBytes32(rdat, 32 * field_depth);
}
bytes32 curr = vm.load(who, slot);
if (fdat != curr) {
require(
false,
"stdStorage find(StdStorage): Packed slot. This would cause dangerous overwriting and currently isn't supported."
);
}
vm.store(who, slot, set);
delete self._target;
delete self._sig;
delete self._keys;
delete self._depth;
}
function read_bytes32(StdStorage storage self) internal returns (bytes32) {
return stdStorageSafe.read_bytes32(self);
}
function read_bool(StdStorage storage self) internal returns (bool) {
return stdStorageSafe.read_bool(self);
}
function read_address(StdStorage storage self) internal returns (address) {
return stdStorageSafe.read_address(self);
}
function read_uint(StdStorage storage self) internal returns (uint256) {
return stdStorageSafe.read_uint(self);
}
function read_int(StdStorage storage self) internal returns (int256) {
return stdStorageSafe.read_int(self);
}
// Private function so needs to be copied over
function bytesToBytes32(bytes memory b, uint256 offset) private pure returns (bytes32) {
bytes32 out;
uint256 max = b.length > 32 ? 32 : b.length;
for (uint256 i = 0; i < max; i++) {
out |= bytes32(b[offset + i] & 0xFF) >> (i * 8);
}
return out;
}
// Private function so needs to be copied over
function flatten(bytes32[] memory b) private pure returns (bytes memory) {
bytes memory result = new bytes(b.length * 32);
for (uint256 i = 0; i < b.length; i++) {
bytes32 k = b[i];
/// @solidity memory-safe-assembly
assembly {
mstore(add(result, add(32, mul(32, i))), k)
}
}
return result;
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
pragma experimental ABIEncoderV2;
import {IMulticall3} from "./interfaces/IMulticall3.sol";
import {VmSafe} from "./Vm.sol";
abstract contract StdUtils {
/*//////////////////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////////////////*/
IMulticall3 private constant multicall = IMulticall3(0xcA11bde05977b3631167028862bE2a173976CA11);
VmSafe private constant vm = VmSafe(address(uint160(uint256(keccak256("hevm cheat code")))));
address private constant CONSOLE2_ADDRESS = 0x000000000000000000636F6e736F6c652e6c6f67;
uint256 private constant INT256_MIN_ABS =
57896044618658097711785492504343953926634992332820282019728792003956564819968;
uint256 private constant SECP256K1_ORDER =
115792089237316195423570985008687907852837564279074904382605163141518161494337;
uint256 private constant UINT256_MAX =
115792089237316195423570985008687907853269984665640564039457584007913129639935;
// Used by default when deploying with create2, https://github.com/Arachnid/deterministic-deployment-proxy.
address private constant CREATE2_FACTORY = 0x4e59b44847b379578588920cA78FbF26c0B4956C;
/*//////////////////////////////////////////////////////////////////////////
INTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
function _bound(uint256 x, uint256 min, uint256 max) internal pure virtual returns (uint256 result) {
require(min <= max, "StdUtils bound(uint256,uint256,uint256): Max is less than min.");
// If x is between min and max, return x directly. This is to ensure that dictionary values
// do not get shifted if the min is nonzero. More info: https://github.com/foundry-rs/forge-std/issues/188
if (x >= min && x <= max) return x;
uint256 size = max - min + 1;
// If the value is 0, 1, 2, 3, wrap that to min, min+1, min+2, min+3. Similarly for the UINT256_MAX side.
// This helps ensure coverage of the min/max values.
if (x <= 3 && size > x) return min + x;
if (x >= UINT256_MAX - 3 && size > UINT256_MAX - x) return max - (UINT256_MAX - x);
// Otherwise, wrap x into the range [min, max], i.e. the range is inclusive.
if (x > max) {
uint256 diff = x - max;
uint256 rem = diff % size;
if (rem == 0) return max;
result = min + rem - 1;
} else if (x < min) {
uint256 diff = min - x;
uint256 rem = diff % size;
if (rem == 0) return min;
result = max - rem + 1;
}
}
function bound(uint256 x, uint256 min, uint256 max) internal view virtual returns (uint256 result) {
result = _bound(x, min, max);
console2_log("Bound Result", result);
}
function _bound(int256 x, int256 min, int256 max) internal pure virtual returns (int256 result) {
require(min <= max, "StdUtils bound(int256,int256,int256): Max is less than min.");
// Shifting all int256 values to uint256 to use _bound function. The range of two types are:
// int256 : -(2**255) ~ (2**255 - 1)
// uint256: 0 ~ (2**256 - 1)
// So, add 2**255, INT256_MIN_ABS to the integer values.
//
// If the given integer value is -2**255, we cannot use `-uint256(-x)` because of the overflow.
// So, use `~uint256(x) + 1` instead.
uint256 _x = x < 0 ? (INT256_MIN_ABS - ~uint256(x) - 1) : (uint256(x) + INT256_MIN_ABS);
uint256 _min = min < 0 ? (INT256_MIN_ABS - ~uint256(min) - 1) : (uint256(min) + INT256_MIN_ABS);
uint256 _max = max < 0 ? (INT256_MIN_ABS - ~uint256(max) - 1) : (uint256(max) + INT256_MIN_ABS);
uint256 y = _bound(_x, _min, _max);
// To move it back to int256 value, subtract INT256_MIN_ABS at here.
result = y < INT256_MIN_ABS ? int256(~(INT256_MIN_ABS - y) + 1) : int256(y - INT256_MIN_ABS);
}
function bound(int256 x, int256 min, int256 max) internal view virtual returns (int256 result) {
result = _bound(x, min, max);
console2_log("Bound result", vm.toString(result));
}
function boundPrivateKey(uint256 privateKey) internal view virtual returns (uint256 result) {
result = _bound(privateKey, 1, SECP256K1_ORDER - 1);
}
function bytesToUint(bytes memory b) internal pure virtual returns (uint256) {
require(b.length <= 32, "StdUtils bytesToUint(bytes): Bytes length exceeds 32.");
return abi.decode(abi.encodePacked(new bytes(32 - b.length), b), (uint256));
}
/// @dev Compute the address a contract will be deployed at for a given deployer address and nonce
/// @notice adapted from Solmate implementation (https://github.com/Rari-Capital/solmate/blob/main/src/utils/LibRLP.sol)
function computeCreateAddress(address deployer, uint256 nonce) internal pure virtual returns (address) {
// forgefmt: disable-start
// The integer zero is treated as an empty byte string, and as a result it only has a length prefix, 0x80, computed via 0x80 + 0.
// A one byte integer uses its own value as its length prefix, there is no additional "0x80 + length" prefix that comes before it.
if (nonce == 0x00) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, bytes1(0x80))));
if (nonce <= 0x7f) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd6), bytes1(0x94), deployer, uint8(nonce))));
// Nonces greater than 1 byte all follow a consistent encoding scheme, where each value is preceded by a prefix of 0x80 + length.
if (nonce <= 2**8 - 1) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd7), bytes1(0x94), deployer, bytes1(0x81), uint8(nonce))));
if (nonce <= 2**16 - 1) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd8), bytes1(0x94), deployer, bytes1(0x82), uint16(nonce))));
if (nonce <= 2**24 - 1) return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xd9), bytes1(0x94), deployer, bytes1(0x83), uint24(nonce))));
// forgefmt: disable-end
// More details about RLP encoding can be found here: https://eth.wiki/fundamentals/rlp
// 0xda = 0xc0 (short RLP prefix) + 0x16 (length of: 0x94 ++ proxy ++ 0x84 ++ nonce)
// 0x94 = 0x80 + 0x14 (0x14 = the length of an address, 20 bytes, in hex)
// 0x84 = 0x80 + 0x04 (0x04 = the bytes length of the nonce, 4 bytes, in hex)
// We assume nobody can have a nonce large enough to require more than 32 bytes.
return addressFromLast20Bytes(
keccak256(abi.encodePacked(bytes1(0xda), bytes1(0x94), deployer, bytes1(0x84), uint32(nonce)))
);
}
function computeCreate2Address(bytes32 salt, bytes32 initcodeHash, address deployer)
internal
pure
virtual
returns (address)
{
return addressFromLast20Bytes(keccak256(abi.encodePacked(bytes1(0xff), deployer, salt, initcodeHash)));
}
/// @dev returns the address of a contract created with CREATE2 using the default CREATE2 deployer
function computeCreate2Address(bytes32 salt, bytes32 initCodeHash) internal pure returns (address) {
return computeCreate2Address(salt, initCodeHash, CREATE2_FACTORY);
}
/// @dev returns the hash of the init code (creation code + no args) used in CREATE2 with no constructor arguments
/// @param creationCode the creation code of a contract C, as returned by type(C).creationCode
function hashInitCode(bytes memory creationCode) internal pure returns (bytes32) {
return hashInitCode(creationCode, "");
}
/// @dev returns the hash of the init code (creation code + ABI-encoded args) used in CREATE2
/// @param creationCode the creation code of a contract C, as returned by type(C).creationCode
/// @param args the ABI-encoded arguments to the constructor of C
function hashInitCode(bytes memory creationCode, bytes memory args) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(creationCode, args));
}
// Performs a single call with Multicall3 to query the ERC-20 token balances of the given addresses.
function getTokenBalances(address token, address[] memory addresses)
internal
virtual
returns (uint256[] memory balances)
{
uint256 tokenCodeSize;
assembly {
tokenCodeSize := extcodesize(token)
}
require(tokenCodeSize > 0, "StdUtils getTokenBalances(address,address[]): Token address is not a contract.");
// ABI encode the aggregate call to Multicall3.
uint256 length = addresses.length;
IMulticall3.Call[] memory calls = new IMulticall3.Call[](length);
for (uint256 i = 0; i < length; ++i) {
// 0x70a08231 = bytes4("balanceOf(address)"))
calls[i] = IMulticall3.Call({target: token, callData: abi.encodeWithSelector(0x70a08231, (addresses[i]))});
}
// Make the aggregate call.
(, bytes[] memory returnData) = multicall.aggregate(calls);
// ABI decode the return data and return the balances.
balances = new uint256[](length);
for (uint256 i = 0; i < length; ++i) {
balances[i] = abi.decode(returnData[i], (uint256));
}
}
/*//////////////////////////////////////////////////////////////////////////
PRIVATE FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
function addressFromLast20Bytes(bytes32 bytesValue) private pure returns (address) {
return address(uint160(uint256(bytesValue)));
}
// Used to prevent the compilation of console, which shortens the compilation time when console is not used elsewhere.
function console2_log(string memory p0, uint256 p1) private view {
(bool status,) = address(CONSOLE2_ADDRESS).staticcall(abi.encodeWithSignature("log(string,uint256)", p0, p1));
status;
}
function console2_log(string memory p0, string memory p1) private view {
(bool status,) = address(CONSOLE2_ADDRESS).staticcall(abi.encodeWithSignature("log(string,string)", p0, p1));
status;
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
pragma experimental ABIEncoderV2;
// Cheatcodes are marked as view/pure/none using the following rules:
// 0. A call's observable behaviour includes its return value, logs, reverts and state writes,
// 1. If you can influence a later call's observable behaviour, you're neither `view` nor `pure (you are modifying some state be it the EVM, interpreter, filesystem, etc),
// 2. Otherwise if you can be influenced by an earlier call, or if reading some state, you're `view`,
// 3. Otherwise you're `pure`.
interface VmSafe {
struct Log {
bytes32[] topics;
bytes data;
address emitter;
}
struct Rpc {
string key;
string url;
}
struct DirEntry {
string errorMessage;
string path;
uint64 depth;
bool isDir;
bool isSymlink;
}
struct FsMetadata {
bool isDir;
bool isSymlink;
uint256 length;
bool readOnly;
uint256 modified;
uint256 accessed;
uint256 created;
}
// Loads a storage slot from an address
function load(address target, bytes32 slot) external view returns (bytes32 data);
// Signs data
function sign(uint256 privateKey, bytes32 digest) external pure returns (uint8 v, bytes32 r, bytes32 s);
// Gets the address for a given private key
function addr(uint256 privateKey) external pure returns (address keyAddr);
// Gets the nonce of an account
function getNonce(address account) external view returns (uint64 nonce);
// Performs a foreign function call via the terminal
function ffi(string[] calldata commandInput) external returns (bytes memory result);
// Sets environment variables
function setEnv(string calldata name, string calldata value) external;
// Reads environment variables, (name) => (value)
function envBool(string calldata name) external view returns (bool value);
function envUint(string calldata name) external view returns (uint256 value);
function envInt(string calldata name) external view returns (int256 value);
function envAddress(string calldata name) external view returns (address value);
function envBytes32(string calldata name) external view returns (bytes32 value);
function envString(string calldata name) external view returns (string memory value);
function envBytes(string calldata name) external view returns (bytes memory value);
// Reads environment variables as arrays
function envBool(string calldata name, string calldata delim) external view returns (bool[] memory value);
function envUint(string calldata name, string calldata delim) external view returns (uint256[] memory value);
function envInt(string calldata name, string calldata delim) external view returns (int256[] memory value);
function envAddress(string calldata name, string calldata delim) external view returns (address[] memory value);
function envBytes32(string calldata name, string calldata delim) external view returns (bytes32[] memory value);
function envString(string calldata name, string calldata delim) external view returns (string[] memory value);
function envBytes(string calldata name, string calldata delim) external view returns (bytes[] memory value);
// Read environment variables with default value
function envOr(string calldata name, bool defaultValue) external returns (bool value);
function envOr(string calldata name, uint256 defaultValue) external returns (uint256 value);
function envOr(string calldata name, int256 defaultValue) external returns (int256 value);
function envOr(string calldata name, address defaultValue) external returns (address value);
function envOr(string calldata name, bytes32 defaultValue) external returns (bytes32 value);
function envOr(string calldata name, string calldata defaultValue) external returns (string memory value);
function envOr(string calldata name, bytes calldata defaultValue) external returns (bytes memory value);
// Read environment variables as arrays with default value
function envOr(string calldata name, string calldata delim, bool[] calldata defaultValue)
external
returns (bool[] memory value);
function envOr(string calldata name, string calldata delim, uint256[] calldata defaultValue)
external
returns (uint256[] memory value);
function envOr(string calldata name, string calldata delim, int256[] calldata defaultValue)
external
returns (int256[] memory value);
function envOr(string calldata name, string calldata delim, address[] calldata defaultValue)
external
returns (address[] memory value);
function envOr(string calldata name, string calldata delim, bytes32[] calldata defaultValue)
external
returns (bytes32[] memory value);
function envOr(string calldata name, string calldata delim, string[] calldata defaultValue)
external
returns (string[] memory value);
function envOr(string calldata name, string calldata delim, bytes[] calldata defaultValue)
external
returns (bytes[] memory value);
// Records all storage reads and writes
function record() external;
// Gets all accessed reads and write slot from a recording session, for a given address
function accesses(address target) external returns (bytes32[] memory readSlots, bytes32[] memory writeSlots);
// Gets the _creation_ bytecode from an artifact file. Takes in the relative path to the json file
function getCode(string calldata artifactPath) external view returns (bytes memory creationBytecode);
// Gets the _deployed_ bytecode from an artifact file. Takes in the relative path to the json file
function getDeployedCode(string calldata artifactPath) external view returns (bytes memory runtimeBytecode);
// Labels an address in call traces
function label(address account, string calldata newLabel) external;
// Gets the label for the specified address
function getLabel(address account) external returns (string memory label);
// Using the address that calls the test contract, has the next call (at this call depth only) create a transaction that can later be signed and sent onchain
function broadcast() external;
// Has the next call (at this call depth only) create a transaction with the address provided as the sender that can later be signed and sent onchain
function broadcast(address signer) external;
// Has the next call (at this call depth only) create a transaction with the private key provided as the sender that can later be signed and sent onchain
function broadcast(uint256 privateKey) external;
// Using the address that calls the test contract, has all subsequent calls (at this call depth only) create transactions that can later be signed and sent onchain
function startBroadcast() external;
// Has all subsequent calls (at this call depth only) create transactions with the address provided that can later be signed and sent onchain
function startBroadcast(address signer) external;
// Has all subsequent calls (at this call depth only) create transactions with the private key provided that can later be signed and sent onchain
function startBroadcast(uint256 privateKey) external;
// Stops collecting onchain transactions
function stopBroadcast() external;
// Get the path of the current project root.
function projectRoot() external view returns (string memory path);
// Reads the entire content of file to string. `path` is relative to the project root.
function readFile(string calldata path) external view returns (string memory data);
// Reads the entire content of file as binary. `path` is relative to the project root.
function readFileBinary(string calldata path) external view returns (bytes memory data);
// Reads next line of file to string.
function readLine(string calldata path) external view returns (string memory line);
// Writes data to file, creating a file if it does not exist, and entirely replacing its contents if it does.
// `path` is relative to the project root.
function writeFile(string calldata path, string calldata data) external;
// Writes binary data to a file, creating a file if it does not exist, and entirely replacing its contents if it does.
// `path` is relative to the project root.
function writeFileBinary(string calldata path, bytes calldata data) external;
// Writes line to file, creating a file if it does not exist.
// `path` is relative to the project root.
function writeLine(string calldata path, string calldata data) external;
// Closes file for reading, resetting the offset and allowing to read it from beginning with readLine.
// `path` is relative to the project root.
function closeFile(string calldata path) external;
// Removes a file from the filesystem.
// This cheatcode will revert in the following situations, but is not limited to just these cases:
// - `path` points to a directory.
// - The file doesn't exist.
// - The user lacks permissions to remove the file.
// `path` is relative to the project root.
function removeFile(string calldata path) external;
// Creates a new, empty directory at the provided path.
// This cheatcode will revert in the following situations, but is not limited to just these cases:
// - User lacks permissions to modify `path`.
// - A parent of the given path doesn't exist and `recursive` is false.
// - `path` already exists and `recursive` is false.
// `path` is relative to the project root.
function createDir(string calldata path, bool recursive) external;
// Removes a directory at the provided path.
// This cheatcode will revert in the following situations, but is not limited to just these cases:
// - `path` doesn't exist.
// - `path` isn't a directory.
// - User lacks permissions to modify `path`.
// - The directory is not empty and `recursive` is false.
// `path` is relative to the project root.
function removeDir(string calldata path, bool recursive) external;
// Reads the directory at the given path recursively, up to `max_depth`.
// `max_depth` defaults to 1, meaning only the direct children of the given directory will be returned.
// Follows symbolic links if `follow_links` is true.
function readDir(string calldata path) external view returns (DirEntry[] memory entries);
function readDir(string calldata path, uint64 maxDepth) external view returns (DirEntry[] memory entries);
function readDir(string calldata path, uint64 maxDepth, bool followLinks)
external
view
returns (DirEntry[] memory entries);
// Reads a symbolic link, returning the path that the link points to.
// This cheatcode will revert in the following situations, but is not limited to just these cases:
// - `path` is not a symbolic link.
// - `path` does not exist.
function readLink(string calldata linkPath) external view returns (string memory targetPath);
// Given a path, query the file system to get information about a file, directory, etc.
function fsMetadata(string calldata path) external view returns (FsMetadata memory metadata);
// Convert values to a string
function toString(address value) external pure returns (string memory stringifiedValue);
function toString(bytes calldata value) external pure returns (string memory stringifiedValue);
function toString(bytes32 value) external pure returns (string memory stringifiedValue);
function toString(bool value) external pure returns (string memory stringifiedValue);
function toString(uint256 value) external pure returns (string memory stringifiedValue);
function toString(int256 value) external pure returns (string memory stringifiedValue);
// Convert values from a string
function parseBytes(string calldata stringifiedValue) external pure returns (bytes memory parsedValue);
function parseAddress(string calldata stringifiedValue) external pure returns (address parsedValue);
function parseUint(string calldata stringifiedValue) external pure returns (uint256 parsedValue);
function parseInt(string calldata stringifiedValue) external pure returns (int256 parsedValue);
function parseBytes32(string calldata stringifiedValue) external pure returns (bytes32 parsedValue);
function parseBool(string calldata stringifiedValue) external pure returns (bool parsedValue);
// Record all the transaction logs
function recordLogs() external;
// Gets all the recorded logs
function getRecordedLogs() external returns (Log[] memory logs);
// Derive a private key from a provided mnenomic string (or mnenomic file path) at the derivation path m/44'/60'/0'/0/{index}
function deriveKey(string calldata mnemonic, uint32 index) external pure returns (uint256 privateKey);
// Derive a private key from a provided mnenomic string (or mnenomic file path) at {derivationPath}{index}
function deriveKey(string calldata mnemonic, string calldata derivationPath, uint32 index)
external
pure
returns (uint256 privateKey);
// Adds a private key to the local forge wallet and returns the address
function rememberKey(uint256 privateKey) external returns (address keyAddr);
//
// parseJson
//
// ----
// In case the returned value is a JSON object, it's encoded as a ABI-encoded tuple. As JSON objects
// don't have the notion of ordered, but tuples do, they JSON object is encoded with it's fields ordered in
// ALPHABETICAL order. That means that in order to successfully decode the tuple, we need to define a tuple that
// encodes the fields in the same order, which is alphabetical. In the case of Solidity structs, they are encoded
// as tuples, with the attributes in the order in which they are defined.
// For example: json = { 'a': 1, 'b': 0xa4tb......3xs}
// a: uint256
// b: address
// To decode that json, we need to define a struct or a tuple as follows:
// struct json = { uint256 a; address b; }
// If we defined a json struct with the opposite order, meaning placing the address b first, it would try to
// decode the tuple in that order, and thus fail.
// ----
// Given a string of JSON, return it as ABI-encoded
function parseJson(string calldata json, string calldata key) external pure returns (bytes memory abiEncodedData);
function parseJson(string calldata json) external pure returns (bytes memory abiEncodedData);
// The following parseJson cheatcodes will do type coercion, for the type that they indicate.
// For example, parseJsonUint will coerce all values to a uint256. That includes stringified numbers '12'
// and hex numbers '0xEF'.
// Type coercion works ONLY for discrete values or arrays. That means that the key must return a value or array, not
// a JSON object.
function parseJsonUint(string calldata, string calldata) external returns (uint256);
function parseJsonUintArray(string calldata, string calldata) external returns (uint256[] memory);
function parseJsonInt(string calldata, string calldata) external returns (int256);
function parseJsonIntArray(string calldata, string calldata) external returns (int256[] memory);
function parseJsonBool(string calldata, string calldata) external returns (bool);
function parseJsonBoolArray(string calldata, string calldata) external returns (bool[] memory);
function parseJsonAddress(string calldata, string calldata) external returns (address);
function parseJsonAddressArray(string calldata, string calldata) external returns (address[] memory);
function parseJsonString(string calldata, string calldata) external returns (string memory);
function parseJsonStringArray(string calldata, string calldata) external returns (string[] memory);
function parseJsonBytes(string calldata, string calldata) external returns (bytes memory);
function parseJsonBytesArray(string calldata, string calldata) external returns (bytes[] memory);
function parseJsonBytes32(string calldata, string calldata) external returns (bytes32);
function parseJsonBytes32Array(string calldata, string calldata) external returns (bytes32[] memory);
// Serialize a key and value to a JSON object stored in-memory that can be later written to a file
// It returns the stringified version of the specific JSON file up to that moment.
function serializeBool(string calldata objectKey, string calldata valueKey, bool value)
external
returns (string memory json);
function serializeUint(string calldata objectKey, string calldata valueKey, uint256 value)
external
returns (string memory json);
function serializeInt(string calldata objectKey, string calldata valueKey, int256 value)
external
returns (string memory json);
function serializeAddress(string calldata objectKey, string calldata valueKey, address value)
external
returns (string memory json);
function serializeBytes32(string calldata objectKey, string calldata valueKey, bytes32 value)
external
returns (string memory json);
function serializeString(string calldata objectKey, string calldata valueKey, string calldata value)
external
returns (string memory json);
function serializeBytes(string calldata objectKey, string calldata valueKey, bytes calldata value)
external
returns (string memory json);
function serializeBool(string calldata objectKey, string calldata valueKey, bool[] calldata values)
external
returns (string memory json);
function serializeUint(string calldata objectKey, string calldata valueKey, uint256[] calldata values)
external
returns (string memory json);
function serializeInt(string calldata objectKey, string calldata valueKey, int256[] calldata values)
external
returns (string memory json);
function serializeAddress(string calldata objectKey, string calldata valueKey, address[] calldata values)
external
returns (string memory json);
function serializeBytes32(string calldata objectKey, string calldata valueKey, bytes32[] calldata values)
external
returns (string memory json);
function serializeString(string calldata objectKey, string calldata valueKey, string[] calldata values)
external
returns (string memory json);
function serializeBytes(string calldata objectKey, string calldata valueKey, bytes[] calldata values)
external
returns (string memory json);
//
// writeJson
//
// ----
// Write a serialized JSON object to a file. If the file exists, it will be overwritten.
// Let's assume we want to write the following JSON to a file:
//
// { "boolean": true, "number": 342, "object": { "title": "finally json serialization" } }
//
// ```
// string memory json1 = "some key";
// vm.serializeBool(json1, "boolean", true);
// vm.serializeBool(json1, "number", uint256(342));
// json2 = "some other key";
// string memory output = vm.serializeString(json2, "title", "finally json serialization");
// string memory finalJson = vm.serialize(json1, "object", output);
// vm.writeJson(finalJson, "./output/example.json");
// ```
// The critical insight is that every invocation of serialization will return the stringified version of the JSON
// up to that point. That means we can construct arbitrary JSON objects and then use the return stringified version
// to serialize them as values to another JSON object.
//
// json1 and json2 are simply keys used by the backend to keep track of the objects. So vm.serializeJson(json1,..)
// will find the object in-memory that is keyed by "some key".
function writeJson(string calldata json, string calldata path) external;
// Write a serialized JSON object to an **existing** JSON file, replacing a value with key = <value_key>
// This is useful to replace a specific value of a JSON file, without having to parse the entire thing
function writeJson(string calldata json, string calldata path, string calldata valueKey) external;
// Returns the RPC url for the given alias
function rpcUrl(string calldata rpcAlias) external view returns (string memory json);
// Returns all rpc urls and their aliases `[alias, url][]`
function rpcUrls() external view returns (string[2][] memory urls);
// Returns all rpc urls and their aliases as structs.
function rpcUrlStructs() external view returns (Rpc[] memory urls);
// If the condition is false, discard this run's fuzz inputs and generate new ones.
function assume(bool condition) external pure;
// Pauses gas metering (i.e. gas usage is not counted). Noop if already paused.
function pauseGasMetering() external;
// Resumes gas metering (i.e. gas usage is counted again). Noop if already on.
function resumeGasMetering() external;
// Writes a breakpoint to jump to in the debugger
function breakpoint(string calldata char) external;
// Writes a conditional breakpoint to jump to in the debugger
function breakpoint(string calldata char, bool value) external;
}
interface Vm is VmSafe {
// Sets block.timestamp
function warp(uint256 newTimestamp) external;
// Sets block.height
function roll(uint256 newHeight) external;
// Sets block.basefee
function fee(uint256 newBasefee) external;
// Sets block.difficulty
// Not available on EVM versions from Paris onwards. Use `prevrandao` instead.
// If used on unsupported EVM versions it will revert.
function difficulty(uint256 newDifficulty) external;
// Sets block.prevrandao
// Not available on EVM versions before Paris. Use `difficulty` instead.
// If used on unsupported EVM versions it will revert.
function prevrandao(bytes32 newPrevrandao) external;
// Sets block.chainid
function chainId(uint256 newChainId) external;
// Sets tx.gasprice
function txGasPrice(uint256 newGasPrice) external;
// Stores a value to an address' storage slot.
function store(address target, bytes32 slot, bytes32 value) external;
// Sets the nonce of an account; must be higher than the current nonce of the account
function setNonce(address account, uint64 newNonce) external;
// Sets the nonce of an account to an arbitrary value
function setNonceUnsafe(address account, uint64 newNonce) external;
// Resets the nonce of an account to 0 for EOAs and 1 for contract accounts
function resetNonce(address account) external;
// Sets the *next* call's msg.sender to be the input address
function prank(address msgSender) external;
// Sets all subsequent calls' msg.sender to be the input address until `stopPrank` is called
function startPrank(address msgSender) external;
// Sets the *next* call's msg.sender to be the input address, and the tx.origin to be the second input
function prank(address msgSender, address txOrigin) external;
// Sets all subsequent calls' msg.sender to be the input address until `stopPrank` is called, and the tx.origin to be the second input
function startPrank(address msgSender, address txOrigin) external;
// Resets subsequent calls' msg.sender to be `address(this)`
function stopPrank() external;
// Sets an address' balance
function deal(address account, uint256 newBalance) external;
// Sets an address' code
function etch(address target, bytes calldata newRuntimeBytecode) external;
// Expects an error on next call
function expectRevert(bytes calldata revertData) external;
function expectRevert(bytes4 revertData) external;
function expectRevert() external;
// Prepare an expected log with all four checks enabled.
// Call this function, then emit an event, then call a function. Internally after the call, we check if
// logs were emitted in the expected order with the expected topics and data.
// Second form also checks supplied address against emitting contract.
function expectEmit() external;
function expectEmit(address emitter) external;
// Prepare an expected log with (bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData).
// Call this function, then emit an event, then call a function. Internally after the call, we check if
// logs were emitted in the expected order with the expected topics and data (as specified by the booleans).
// Second form also checks supplied address against emitting contract.
function expectEmit(bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData) external;
function expectEmit(bool checkTopic1, bool checkTopic2, bool checkTopic3, bool checkData, address emitter)
external;
// Mocks a call to an address, returning specified data.
// Calldata can either be strict or a partial match, e.g. if you only
// pass a Solidity selector to the expected calldata, then the entire Solidity
// function will be mocked.
function mockCall(address callee, bytes calldata data, bytes calldata returnData) external;
// Mocks a call to an address with a specific msg.value, returning specified data.
// Calldata match takes precedence over msg.value in case of ambiguity.
function mockCall(address callee, uint256 msgValue, bytes calldata data, bytes calldata returnData) external;
// Reverts a call to an address with specified revert data.
function mockCallRevert(address callee, bytes calldata data, bytes calldata revertData) external;
// Reverts a call to an address with a specific msg.value, with specified revert data.
function mockCallRevert(address callee, uint256 msgValue, bytes calldata data, bytes calldata revertData)
external;
// Clears all mocked calls
function clearMockedCalls() external;
// Expects a call to an address with the specified calldata.
// Calldata can either be a strict or a partial match
function expectCall(address callee, bytes calldata data) external;
// Expects given number of calls to an address with the specified calldata.
function expectCall(address callee, bytes calldata data, uint64 count) external;
// Expects a call to an address with the specified msg.value and calldata
function expectCall(address callee, uint256 msgValue, bytes calldata data) external;
// Expects given number of calls to an address with the specified msg.value and calldata
function expectCall(address callee, uint256 msgValue, bytes calldata data, uint64 count) external;
// Expect a call to an address with the specified msg.value, gas, and calldata.
function expectCall(address callee, uint256 msgValue, uint64 gas, bytes calldata data) external;
// Expects given number of calls to an address with the specified msg.value, gas, and calldata.
function expectCall(address callee, uint256 msgValue, uint64 gas, bytes calldata data, uint64 count) external;
// Expect a call to an address with the specified msg.value and calldata, and a *minimum* amount of gas.
function expectCallMinGas(address callee, uint256 msgValue, uint64 minGas, bytes calldata data) external;
// Expect given number of calls to an address with the specified msg.value and calldata, and a *minimum* amount of gas.
function expectCallMinGas(address callee, uint256 msgValue, uint64 minGas, bytes calldata data, uint64 count)
external;
// Only allows memory writes to offsets [0x00, 0x60) ∪ [min, max) in the current subcontext. If any other
// memory is written to, the test will fail. Can be called multiple times to add more ranges to the set.
function expectSafeMemory(uint64 min, uint64 max) external;
// Only allows memory writes to offsets [0x00, 0x60) ∪ [min, max) in the next created subcontext.
// If any other memory is written to, the test will fail. Can be called multiple times to add more ranges
// to the set.
function expectSafeMemoryCall(uint64 min, uint64 max) external;
// Sets block.coinbase
function coinbase(address newCoinbase) external;
// Snapshot the current state of the evm.
// Returns the id of the snapshot that was created.
// To revert a snapshot use `revertTo`
function snapshot() external returns (uint256 snapshotId);
// Revert the state of the EVM to a previous snapshot
// Takes the snapshot id to revert to.
// This deletes the snapshot and all snapshots taken after the given snapshot id.
function revertTo(uint256 snapshotId) external returns (bool success);
// Creates a new fork with the given endpoint and block and returns the identifier of the fork
function createFork(string calldata urlOrAlias, uint256 blockNumber) external returns (uint256 forkId);
// Creates a new fork with the given endpoint and the _latest_ block and returns the identifier of the fork
function createFork(string calldata urlOrAlias) external returns (uint256 forkId);
// Creates a new fork with the given endpoint and at the block the given transaction was mined in, replays all transaction mined in the block before the transaction,
// and returns the identifier of the fork
function createFork(string calldata urlOrAlias, bytes32 txHash) external returns (uint256 forkId);
// Creates _and_ also selects a new fork with the given endpoint and block and returns the identifier of the fork
function createSelectFork(string calldata urlOrAlias, uint256 blockNumber) external returns (uint256 forkId);
// Creates _and_ also selects new fork with the given endpoint and at the block the given transaction was mined in, replays all transaction mined in the block before
// the transaction, returns the identifier of the fork
function createSelectFork(string calldata urlOrAlias, bytes32 txHash) external returns (uint256 forkId);
// Creates _and_ also selects a new fork with the given endpoint and the latest block and returns the identifier of the fork
function createSelectFork(string calldata urlOrAlias) external returns (uint256 forkId);
// Takes a fork identifier created by `createFork` and sets the corresponding forked state as active.
function selectFork(uint256 forkId) external;
/// Returns the identifier of the currently active fork. Reverts if no fork is currently active.
function activeFork() external view returns (uint256 forkId);
// Updates the currently active fork to given block number
// This is similar to `roll` but for the currently active fork
function rollFork(uint256 blockNumber) external;
// Updates the currently active fork to given transaction
// this will `rollFork` with the number of the block the transaction was mined in and replays all transaction mined before it in the block
function rollFork(bytes32 txHash) external;
// Updates the given fork to given block number
function rollFork(uint256 forkId, uint256 blockNumber) external;
// Updates the given fork to block number of the given transaction and replays all transaction mined before it in the block
function rollFork(uint256 forkId, bytes32 txHash) external;
// Marks that the account(s) should use persistent storage across fork swaps in a multifork setup
// Meaning, changes made to the state of this account will be kept when switching forks
function makePersistent(address account) external;
function makePersistent(address account0, address account1) external;
function makePersistent(address account0, address account1, address account2) external;
function makePersistent(address[] calldata accounts) external;
// Revokes persistent status from the address, previously added via `makePersistent`
function revokePersistent(address account) external;
function revokePersistent(address[] calldata accounts) external;
// Returns true if the account is marked as persistent
function isPersistent(address account) external view returns (bool persistent);
// In forking mode, explicitly grant the given address cheatcode access
function allowCheatcodes(address account) external;
// Fetches the given transaction from the active fork and executes it on the current state
function transact(bytes32 txHash) external;
// Fetches the given transaction from the given fork and executes it on the current state
function transact(uint256 forkId, bytes32 txHash) external;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.4.22 <0.9.0;
import {Vm} from "./Vm.sol";
library StdStyle {
Vm private constant vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
string constant RED = "\u001b[91m";
string constant GREEN = "\u001b[92m";
string constant YELLOW = "\u001b[93m";
string constant BLUE = "\u001b[94m";
string constant MAGENTA = "\u001b[95m";
string constant CYAN = "\u001b[96m";
string constant BOLD = "\u001b[1m";
string constant DIM = "\u001b[2m";
string constant ITALIC = "\u001b[3m";
string constant UNDERLINE = "\u001b[4m";
string constant INVERSE = "\u001b[7m";
string constant RESET = "\u001b[0m";
function styleConcat(string memory style, string memory self) private pure returns (string memory) {
return string(abi.encodePacked(style, self, RESET));
}
function red(string memory self) internal pure returns (string memory) {
return styleConcat(RED, self);
}
function red(uint256 self) internal pure returns (string memory) {
return red(vm.toString(self));
}
function red(int256 self) internal pure returns (string memory) {
return red(vm.toString(self));
}
function red(address self) internal pure returns (string memory) {
return red(vm.toString(self));
}
function red(bool self) internal pure returns (string memory) {
return red(vm.toString(self));
}
function redBytes(bytes memory self) internal pure returns (string memory) {
return red(vm.toString(self));
}
function redBytes32(bytes32 self) internal pure returns (string memory) {
return red(vm.toString(self));
}
function green(string memory self) internal pure returns (string memory) {
return styleConcat(GREEN, self);
}
function green(uint256 self) internal pure returns (string memory) {
return green(vm.toString(self));
}
function green(int256 self) internal pure returns (string memory) {
return green(vm.toString(self));
}
function green(address self) internal pure returns (string memory) {
return green(vm.toString(self));
}
function green(bool self) internal pure returns (string memory) {
return green(vm.toString(self));
}
function greenBytes(bytes memory self) internal pure returns (string memory) {
return green(vm.toString(self));
}
function greenBytes32(bytes32 self) internal pure returns (string memory) {
return green(vm.toString(self));
}
function yellow(string memory self) internal pure returns (string memory) {
return styleConcat(YELLOW, self);
}
function yellow(uint256 self) internal pure returns (string memory) {
return yellow(vm.toString(self));
}
function yellow(int256 self) internal pure returns (string memory) {
return yellow(vm.toString(self));
}
function yellow(address self) internal pure returns (string memory) {
return yellow(vm.toString(self));
}
function yellow(bool self) internal pure returns (string memory) {
return yellow(vm.toString(self));
}
function yellowBytes(bytes memory self) internal pure returns (string memory) {
return yellow(vm.toString(self));
}
function yellowBytes32(bytes32 self) internal pure returns (string memory) {
return yellow(vm.toString(self));
}
function blue(string memory self) internal pure returns (string memory) {
return styleConcat(BLUE, self);
}
function blue(uint256 self) internal pure returns (string memory) {
return blue(vm.toString(self));
}
function blue(int256 self) internal pure returns (string memory) {
return blue(vm.toString(self));
}
function blue(address self) internal pure returns (string memory) {
return blue(vm.toString(self));
}
function blue(bool self) internal pure returns (string memory) {
return blue(vm.toString(self));
}
function blueBytes(bytes memory self) internal pure returns (string memory) {
return blue(vm.toString(self));
}
function blueBytes32(bytes32 self) internal pure returns (string memory) {
return blue(vm.toString(self));
}
function magenta(string memory self) internal pure returns (string memory) {
return styleConcat(MAGENTA, self);
}
function magenta(uint256 self) internal pure returns (string memory) {
return magenta(vm.toString(self));
}
function magenta(int256 self) internal pure returns (string memory) {
return magenta(vm.toString(self));
}
function magenta(address self) internal pure returns (string memory) {
return magenta(vm.toString(self));
}
function magenta(bool self) internal pure returns (string memory) {
return magenta(vm.toString(self));
}
function magentaBytes(bytes memory self) internal pure returns (string memory) {
return magenta(vm.toString(self));
}
function magentaBytes32(bytes32 self) internal pure returns (string memory) {
return magenta(vm.toString(self));
}
function cyan(string memory self) internal pure returns (string memory) {
return styleConcat(CYAN, self);
}
function cyan(uint256 self) internal pure returns (string memory) {
return cyan(vm.toString(self));
}
function cyan(int256 self) internal pure returns (string memory) {
return cyan(vm.toString(self));
}
function cyan(address self) internal pure returns (string memory) {
return cyan(vm.toString(self));
}
function cyan(bool self) internal pure returns (string memory) {
return cyan(vm.toString(self));
}
function cyanBytes(bytes memory self) internal pure returns (string memory) {
return cyan(vm.toString(self));
}
function cyanBytes32(bytes32 self) internal pure returns (string memory) {
return cyan(vm.toString(self));
}
function bold(string memory self) internal pure returns (string memory) {
return styleConcat(BOLD, self);
}
function bold(uint256 self) internal pure returns (string memory) {
return bold(vm.toString(self));
}
function bold(int256 self) internal pure returns (string memory) {
return bold(vm.toString(self));
}
function bold(address self) internal pure returns (string memory) {
return bold(vm.toString(self));
}
function bold(bool self) internal pure returns (string memory) {
return bold(vm.toString(self));
}
function boldBytes(bytes memory self) internal pure returns (string memory) {
return bold(vm.toString(self));
}
function boldBytes32(bytes32 self) internal pure returns (string memory) {
return bold(vm.toString(self));
}
function dim(string memory self) internal pure returns (string memory) {
return styleConcat(DIM, self);
}
function dim(uint256 self) internal pure returns (string memory) {
return dim(vm.toString(self));
}
function dim(int256 self) internal pure returns (string memory) {
return dim(vm.toString(self));
}
function dim(address self) internal pure returns (string memory) {
return dim(vm.toString(self));
}
function dim(bool self) internal pure returns (string memory) {
return dim(vm.toString(self));
}
function dimBytes(bytes memory self) internal pure returns (string memory) {
return dim(vm.toString(self));
}
function dimBytes32(bytes32 self) internal pure returns (string memory) {
return dim(vm.toString(self));
}
function italic(string memory self) internal pure returns (string memory) {
return styleConcat(ITALIC, self);
}
function italic(uint256 self) internal pure returns (string memory) {
return italic(vm.toString(self));
}
function italic(int256 self) internal pure returns (string memory) {
return italic(vm.toString(self));
}
function italic(address self) internal pure returns (string memory) {
return italic(vm.toString(self));
}
function italic(bool self) internal pure returns (string memory) {
return italic(vm.toString(self));
}
function italicBytes(bytes memory self) internal pure returns (string memory) {
return italic(vm.toString(self));
}
function italicBytes32(bytes32 self) internal pure returns (string memory) {
return italic(vm.toString(self));
}
function underline(string memory self) internal pure returns (string memory) {
return styleConcat(UNDERLINE, self);
}
function underline(uint256 self) internal pure returns (string memory) {
return underline(vm.toString(self));
}
function underline(int256 self) internal pure returns (string memory) {
return underline(vm.toString(self));
}
function underline(address self) internal pure returns (string memory) {
return underline(vm.toString(self));
}
function underline(bool self) internal pure returns (string memory) {
return underline(vm.toString(self));
}
function underlineBytes(bytes memory self) internal pure returns (string memory) {
return underline(vm.toString(self));
}
function underlineBytes32(bytes32 self) internal pure returns (string memory) {
return underline(vm.toString(self));
}
function inverse(string memory self) internal pure returns (string memory) {
return styleConcat(INVERSE, self);
}
function inverse(uint256 self) internal pure returns (string memory) {
return inverse(vm.toString(self));
}
function inverse(int256 self) internal pure returns (string memory) {
return inverse(vm.toString(self));
}
function inverse(address self) internal pure returns (string memory) {
return inverse(vm.toString(self));
}
function inverse(bool self) internal pure returns (string memory) {
return inverse(vm.toString(self));
}
function inverseBytes(bytes memory self) internal pure returns (string memory) {
return inverse(vm.toString(self));
}
function inverseBytes32(bytes32 self) internal pure returns (string memory) {
return inverse(vm.toString(self));
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
import {StdStorage} from "./StdStorage.sol";
import {Vm, VmSafe} from "./Vm.sol";
abstract contract CommonBase {
// Cheat code address, 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D.
address internal constant VM_ADDRESS = address(uint160(uint256(keccak256("hevm cheat code"))));
// console.sol and console2.sol work by executing a staticcall to this address.
address internal constant CONSOLE = 0x000000000000000000636F6e736F6c652e6c6f67;
// Used when deploying with create2, https://github.com/Arachnid/deterministic-deployment-proxy.
address internal constant CREATE2_FACTORY = 0x4e59b44847b379578588920cA78FbF26c0B4956C;
// Default address for tx.origin and msg.sender, 0x1804c8AB1F12E6bbf3894d4083f33e07309d1f38.
address internal constant DEFAULT_SENDER = address(uint160(uint256(keccak256("foundry default caller"))));
// Address of the test contract, deployed by the DEFAULT_SENDER.
address internal constant DEFAULT_TEST_CONTRACT = 0x5615dEB798BB3E4dFa0139dFa1b3D433Cc23b72f;
// Deterministic deployment address of the Multicall3 contract.
address internal constant MULTICALL3_ADDRESS = 0xcA11bde05977b3631167028862bE2a173976CA11;
// The order of the secp256k1 curve.
uint256 internal constant SECP256K1_ORDER =
115792089237316195423570985008687907852837564279074904382605163141518161494337;
uint256 internal constant UINT256_MAX =
115792089237316195423570985008687907853269984665640564039457584007913129639935;
Vm internal constant vm = Vm(VM_ADDRESS);
StdStorage internal stdstore;
}
abstract contract TestBase is CommonBase {}
abstract contract ScriptBase is CommonBase {
VmSafe internal constant vmSafe = VmSafe(VM_ADDRESS);
}// SPDX-License-Identifier: GPL-3.0-or-later
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
pragma solidity >=0.5.0;
contract DSTest {
event log (string);
event logs (bytes);
event log_address (address);
event log_bytes32 (bytes32);
event log_int (int);
event log_uint (uint);
event log_bytes (bytes);
event log_string (string);
event log_named_address (string key, address val);
event log_named_bytes32 (string key, bytes32 val);
event log_named_decimal_int (string key, int val, uint decimals);
event log_named_decimal_uint (string key, uint val, uint decimals);
event log_named_int (string key, int val);
event log_named_uint (string key, uint val);
event log_named_bytes (string key, bytes val);
event log_named_string (string key, string val);
bool public IS_TEST = true;
bool private _failed;
address constant HEVM_ADDRESS =
address(bytes20(uint160(uint256(keccak256('hevm cheat code')))));
modifier mayRevert() { _; }
modifier testopts(string memory) { _; }
function failed() public returns (bool) {
if (_failed) {
return _failed;
} else {
bool globalFailed = false;
if (hasHEVMContext()) {
(, bytes memory retdata) = HEVM_ADDRESS.call(
abi.encodePacked(
bytes4(keccak256("load(address,bytes32)")),
abi.encode(HEVM_ADDRESS, bytes32("failed"))
)
);
globalFailed = abi.decode(retdata, (bool));
}
return globalFailed;
}
}
function fail() internal virtual {
if (hasHEVMContext()) {
(bool status, ) = HEVM_ADDRESS.call(
abi.encodePacked(
bytes4(keccak256("store(address,bytes32,bytes32)")),
abi.encode(HEVM_ADDRESS, bytes32("failed"), bytes32(uint256(0x01)))
)
);
status; // Silence compiler warnings
}
_failed = true;
}
function hasHEVMContext() internal view returns (bool) {
uint256 hevmCodeSize = 0;
assembly {
hevmCodeSize := extcodesize(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D)
}
return hevmCodeSize > 0;
}
modifier logs_gas() {
uint startGas = gasleft();
_;
uint endGas = gasleft();
emit log_named_uint("gas", startGas - endGas);
}
function assertTrue(bool condition) internal {
if (!condition) {
emit log("Error: Assertion Failed");
fail();
}
}
function assertTrue(bool condition, string memory err) internal {
if (!condition) {
emit log_named_string("Error", err);
assertTrue(condition);
}
}
function assertEq(address a, address b) internal {
if (a != b) {
emit log("Error: a == b not satisfied [address]");
emit log_named_address(" Left", a);
emit log_named_address(" Right", b);
fail();
}
}
function assertEq(address a, address b, string memory err) internal {
if (a != b) {
emit log_named_string ("Error", err);
assertEq(a, b);
}
}
function assertEq(bytes32 a, bytes32 b) internal {
if (a != b) {
emit log("Error: a == b not satisfied [bytes32]");
emit log_named_bytes32(" Left", a);
emit log_named_bytes32(" Right", b);
fail();
}
}
function assertEq(bytes32 a, bytes32 b, string memory err) internal {
if (a != b) {
emit log_named_string ("Error", err);
assertEq(a, b);
}
}
function assertEq32(bytes32 a, bytes32 b) internal {
assertEq(a, b);
}
function assertEq32(bytes32 a, bytes32 b, string memory err) internal {
assertEq(a, b, err);
}
function assertEq(int a, int b) internal {
if (a != b) {
emit log("Error: a == b not satisfied [int]");
emit log_named_int(" Left", a);
emit log_named_int(" Right", b);
fail();
}
}
function assertEq(int a, int b, string memory err) internal {
if (a != b) {
emit log_named_string("Error", err);
assertEq(a, b);
}
}
function assertEq(uint a, uint b) internal {
if (a != b) {
emit log("Error: a == b not satisfied [uint]");
emit log_named_uint(" Left", a);
emit log_named_uint(" Right", b);
fail();
}
}
function assertEq(uint a, uint b, string memory err) internal {
if (a != b) {
emit log_named_string("Error", err);
assertEq(a, b);
}
}
function assertEqDecimal(int a, int b, uint decimals) internal {
if (a != b) {
emit log("Error: a == b not satisfied [decimal int]");
emit log_named_decimal_int(" Left", a, decimals);
emit log_named_decimal_int(" Right", b, decimals);
fail();
}
}
function assertEqDecimal(int a, int b, uint decimals, string memory err) internal {
if (a != b) {
emit log_named_string("Error", err);
assertEqDecimal(a, b, decimals);
}
}
function assertEqDecimal(uint a, uint b, uint decimals) internal {
if (a != b) {
emit log("Error: a == b not satisfied [decimal uint]");
emit log_named_decimal_uint(" Left", a, decimals);
emit log_named_decimal_uint(" Right", b, decimals);
fail();
}
}
function assertEqDecimal(uint a, uint b, uint decimals, string memory err) internal {
if (a != b) {
emit log_named_string("Error", err);
assertEqDecimal(a, b, decimals);
}
}
function assertNotEq(address a, address b) internal {
if (a == b) {
emit log("Error: a != b not satisfied [address]");
emit log_named_address(" Left", a);
emit log_named_address(" Right", b);
fail();
}
}
function assertNotEq(address a, address b, string memory err) internal {
if (a == b) {
emit log_named_string ("Error", err);
assertNotEq(a, b);
}
}
function assertNotEq(bytes32 a, bytes32 b) internal {
if (a == b) {
emit log("Error: a != b not satisfied [bytes32]");
emit log_named_bytes32(" Left", a);
emit log_named_bytes32(" Right", b);
fail();
}
}
function assertNotEq(bytes32 a, bytes32 b, string memory err) internal {
if (a == b) {
emit log_named_string ("Error", err);
assertNotEq(a, b);
}
}
function assertNotEq32(bytes32 a, bytes32 b) internal {
assertNotEq(a, b);
}
function assertNotEq32(bytes32 a, bytes32 b, string memory err) internal {
assertNotEq(a, b, err);
}
function assertNotEq(int a, int b) internal {
if (a == b) {
emit log("Error: a != b not satisfied [int]");
emit log_named_int(" Left", a);
emit log_named_int(" Right", b);
fail();
}
}
function assertNotEq(int a, int b, string memory err) internal {
if (a == b) {
emit log_named_string("Error", err);
assertNotEq(a, b);
}
}
function assertNotEq(uint a, uint b) internal {
if (a == b) {
emit log("Error: a != b not satisfied [uint]");
emit log_named_uint(" Left", a);
emit log_named_uint(" Right", b);
fail();
}
}
function assertNotEq(uint a, uint b, string memory err) internal {
if (a == b) {
emit log_named_string("Error", err);
assertNotEq(a, b);
}
}
function assertNotEqDecimal(int a, int b, uint decimals) internal {
if (a == b) {
emit log("Error: a != b not satisfied [decimal int]");
emit log_named_decimal_int(" Left", a, decimals);
emit log_named_decimal_int(" Right", b, decimals);
fail();
}
}
function assertNotEqDecimal(int a, int b, uint decimals, string memory err) internal {
if (a == b) {
emit log_named_string("Error", err);
assertNotEqDecimal(a, b, decimals);
}
}
function assertNotEqDecimal(uint a, uint b, uint decimals) internal {
if (a == b) {
emit log("Error: a != b not satisfied [decimal uint]");
emit log_named_decimal_uint(" Left", a, decimals);
emit log_named_decimal_uint(" Right", b, decimals);
fail();
}
}
function assertNotEqDecimal(uint a, uint b, uint decimals, string memory err) internal {
if (a == b) {
emit log_named_string("Error", err);
assertNotEqDecimal(a, b, decimals);
}
}
function assertGt(uint a, uint b) internal {
if (a <= b) {
emit log("Error: a > b not satisfied [uint]");
emit log_named_uint(" Value a", a);
emit log_named_uint(" Value b", b);
fail();
}
}
function assertGt(uint a, uint b, string memory err) internal {
if (a <= b) {
emit log_named_string("Error", err);
assertGt(a, b);
}
}
function assertGt(int a, int b) internal {
if (a <= b) {
emit log("Error: a > b not satisfied [int]");
emit log_named_int(" Value a", a);
emit log_named_int(" Value b", b);
fail();
}
}
function assertGt(int a, int b, string memory err) internal {
if (a <= b) {
emit log_named_string("Error", err);
assertGt(a, b);
}
}
function assertGtDecimal(int a, int b, uint decimals) internal {
if (a <= b) {
emit log("Error: a > b not satisfied [decimal int]");
emit log_named_decimal_int(" Value a", a, decimals);
emit log_named_decimal_int(" Value b", b, decimals);
fail();
}
}
function assertGtDecimal(int a, int b, uint decimals, string memory err) internal {
if (a <= b) {
emit log_named_string("Error", err);
assertGtDecimal(a, b, decimals);
}
}
function assertGtDecimal(uint a, uint b, uint decimals) internal {
if (a <= b) {
emit log("Error: a > b not satisfied [decimal uint]");
emit log_named_decimal_uint(" Value a", a, decimals);
emit log_named_decimal_uint(" Value b", b, decimals);
fail();
}
}
function assertGtDecimal(uint a, uint b, uint decimals, string memory err) internal {
if (a <= b) {
emit log_named_string("Error", err);
assertGtDecimal(a, b, decimals);
}
}
function assertGe(uint a, uint b) internal {
if (a < b) {
emit log("Error: a >= b not satisfied [uint]");
emit log_named_uint(" Value a", a);
emit log_named_uint(" Value b", b);
fail();
}
}
function assertGe(uint a, uint b, string memory err) internal {
if (a < b) {
emit log_named_string("Error", err);
assertGe(a, b);
}
}
function assertGe(int a, int b) internal {
if (a < b) {
emit log("Error: a >= b not satisfied [int]");
emit log_named_int(" Value a", a);
emit log_named_int(" Value b", b);
fail();
}
}
function assertGe(int a, int b, string memory err) internal {
if (a < b) {
emit log_named_string("Error", err);
assertGe(a, b);
}
}
function assertGeDecimal(int a, int b, uint decimals) internal {
if (a < b) {
emit log("Error: a >= b not satisfied [decimal int]");
emit log_named_decimal_int(" Value a", a, decimals);
emit log_named_decimal_int(" Value b", b, decimals);
fail();
}
}
function assertGeDecimal(int a, int b, uint decimals, string memory err) internal {
if (a < b) {
emit log_named_string("Error", err);
assertGeDecimal(a, b, decimals);
}
}
function assertGeDecimal(uint a, uint b, uint decimals) internal {
if (a < b) {
emit log("Error: a >= b not satisfied [decimal uint]");
emit log_named_decimal_uint(" Value a", a, decimals);
emit log_named_decimal_uint(" Value b", b, decimals);
fail();
}
}
function assertGeDecimal(uint a, uint b, uint decimals, string memory err) internal {
if (a < b) {
emit log_named_string("Error", err);
assertGeDecimal(a, b, decimals);
}
}
function assertLt(uint a, uint b) internal {
if (a >= b) {
emit log("Error: a < b not satisfied [uint]");
emit log_named_uint(" Value a", a);
emit log_named_uint(" Value b", b);
fail();
}
}
function assertLt(uint a, uint b, string memory err) internal {
if (a >= b) {
emit log_named_string("Error", err);
assertLt(a, b);
}
}
function assertLt(int a, int b) internal {
if (a >= b) {
emit log("Error: a < b not satisfied [int]");
emit log_named_int(" Value a", a);
emit log_named_int(" Value b", b);
fail();
}
}
function assertLt(int a, int b, string memory err) internal {
if (a >= b) {
emit log_named_string("Error", err);
assertLt(a, b);
}
}
function assertLtDecimal(int a, int b, uint decimals) internal {
if (a >= b) {
emit log("Error: a < b not satisfied [decimal int]");
emit log_named_decimal_int(" Value a", a, decimals);
emit log_named_decimal_int(" Value b", b, decimals);
fail();
}
}
function assertLtDecimal(int a, int b, uint decimals, string memory err) internal {
if (a >= b) {
emit log_named_string("Error", err);
assertLtDecimal(a, b, decimals);
}
}
function assertLtDecimal(uint a, uint b, uint decimals) internal {
if (a >= b) {
emit log("Error: a < b not satisfied [decimal uint]");
emit log_named_decimal_uint(" Value a", a, decimals);
emit log_named_decimal_uint(" Value b", b, decimals);
fail();
}
}
function assertLtDecimal(uint a, uint b, uint decimals, string memory err) internal {
if (a >= b) {
emit log_named_string("Error", err);
assertLtDecimal(a, b, decimals);
}
}
function assertLe(uint a, uint b) internal {
if (a > b) {
emit log("Error: a <= b not satisfied [uint]");
emit log_named_uint(" Value a", a);
emit log_named_uint(" Value b", b);
fail();
}
}
function assertLe(uint a, uint b, string memory err) internal {
if (a > b) {
emit log_named_string("Error", err);
assertLe(a, b);
}
}
function assertLe(int a, int b) internal {
if (a > b) {
emit log("Error: a <= b not satisfied [int]");
emit log_named_int(" Value a", a);
emit log_named_int(" Value b", b);
fail();
}
}
function assertLe(int a, int b, string memory err) internal {
if (a > b) {
emit log_named_string("Error", err);
assertLe(a, b);
}
}
function assertLeDecimal(int a, int b, uint decimals) internal {
if (a > b) {
emit log("Error: a <= b not satisfied [decimal int]");
emit log_named_decimal_int(" Value a", a, decimals);
emit log_named_decimal_int(" Value b", b, decimals);
fail();
}
}
function assertLeDecimal(int a, int b, uint decimals, string memory err) internal {
if (a > b) {
emit log_named_string("Error", err);
assertLeDecimal(a, b, decimals);
}
}
function assertLeDecimal(uint a, uint b, uint decimals) internal {
if (a > b) {
emit log("Error: a <= b not satisfied [decimal uint]");
emit log_named_decimal_uint(" Value a", a, decimals);
emit log_named_decimal_uint(" Value b", b, decimals);
fail();
}
}
function assertLeDecimal(uint a, uint b, uint decimals, string memory err) internal {
if (a > b) {
emit log_named_string("Error", err);
assertLeDecimal(a, b, decimals);
}
}
function assertEq(string memory a, string memory b) internal {
if (keccak256(abi.encodePacked(a)) != keccak256(abi.encodePacked(b))) {
emit log("Error: a == b not satisfied [string]");
emit log_named_string(" Left", a);
emit log_named_string(" Right", b);
fail();
}
}
function assertEq(string memory a, string memory b, string memory err) internal {
if (keccak256(abi.encodePacked(a)) != keccak256(abi.encodePacked(b))) {
emit log_named_string("Error", err);
assertEq(a, b);
}
}
function assertNotEq(string memory a, string memory b) internal {
if (keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b))) {
emit log("Error: a != b not satisfied [string]");
emit log_named_string(" Left", a);
emit log_named_string(" Right", b);
fail();
}
}
function assertNotEq(string memory a, string memory b, string memory err) internal {
if (keccak256(abi.encodePacked(a)) == keccak256(abi.encodePacked(b))) {
emit log_named_string("Error", err);
assertNotEq(a, b);
}
}
function checkEq0(bytes memory a, bytes memory b) internal pure returns (bool ok) {
ok = true;
if (a.length == b.length) {
for (uint i = 0; i < a.length; i++) {
if (a[i] != b[i]) {
ok = false;
}
}
} else {
ok = false;
}
}
function assertEq0(bytes memory a, bytes memory b) internal {
if (!checkEq0(a, b)) {
emit log("Error: a == b not satisfied [bytes]");
emit log_named_bytes(" Left", a);
emit log_named_bytes(" Right", b);
fail();
}
}
function assertEq0(bytes memory a, bytes memory b, string memory err) internal {
if (!checkEq0(a, b)) {
emit log_named_string("Error", err);
assertEq0(a, b);
}
}
function assertNotEq0(bytes memory a, bytes memory b) internal {
if (checkEq0(a, b)) {
emit log("Error: a != b not satisfied [bytes]");
emit log_named_bytes(" Left", a);
emit log_named_bytes(" Right", b);
fail();
}
}
function assertNotEq0(bytes memory a, bytes memory b, string memory err) internal {
if (checkEq0(a, b)) {
emit log_named_string("Error", err);
assertNotEq0(a, b);
}
}
}pragma solidity >=0.5.0;
interface IUniswapV2Pair {
event Approval(address indexed owner, address indexed spender, uint value);
event Transfer(address indexed from, address indexed to, uint value);
function name() external pure returns (string memory);
function symbol() external pure returns (string memory);
function decimals() external pure returns (uint8);
function totalSupply() external view returns (uint);
function balanceOf(address owner) external view returns (uint);
function allowance(address owner, address spender) external view returns (uint);
function approve(address spender, uint value) external returns (bool);
function transfer(address to, uint value) external returns (bool);
function transferFrom(address from, address to, uint value) external returns (bool);
function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint);
function permit(address owner, address spender, uint value, uint deadline, uint8 v, bytes32 r, bytes32 s) external;
event Mint(address indexed sender, uint amount0, uint amount1);
event Burn(address indexed sender, uint amount0, uint amount1, address indexed to);
event Swap(
address indexed sender,
uint amount0In,
uint amount1In,
uint amount0Out,
uint amount1Out,
address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);
function MINIMUM_LIQUIDITY() external pure returns (uint);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns (uint112 reserve0, uint112 reserve1, uint32 blockTimestampLast);
function price0CumulativeLast() external view returns (uint);
function price1CumulativeLast() external view returns (uint);
function kLast() external view returns (uint);
function mint(address to) external returns (uint liquidity);
function burn(address to) external returns (uint amount0, uint amount1);
function swap(uint amount0Out, uint amount1Out, address to, bytes calldata data) external;
function skim(address to) external;
function sync() external;
function initialize(address, address) external;
}pragma solidity >=0.5.0;
interface IUniswapV2Factory {
event PairCreated(address indexed token0, address indexed token1, address pair, uint);
function feeTo() external view returns (address);
function feeToSetter() external view returns (address);
function getPair(address tokenA, address tokenB) external view returns (address pair);
function allPairs(uint) external view returns (address pair);
function allPairsLength() external view returns (uint);
function createPair(address tokenA, address tokenB) external returns (address pair);
function setFeeTo(address) external;
function setFeeToSetter(address) external;
}pragma solidity ^0.8.0;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
interface IBAMMERC20 is IERC20 {
function mint(address account, uint256 value) external;
function burn(address account, uint256 value) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/extensions/ERC20Permit.sol)
pragma solidity ^0.8.20;
import {IERC20Permit} from "./IERC20Permit.sol";
import {ERC20} from "../ERC20.sol";
import {ECDSA} from "../../../utils/cryptography/ECDSA.sol";
import {EIP712} from "../../../utils/cryptography/EIP712.sol";
import {Nonces} from "../../../utils/Nonces.sol";
/**
* @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712, Nonces {
bytes32 private constant PERMIT_TYPEHASH =
keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
/**
* @dev Permit deadline has expired.
*/
error ERC2612ExpiredSignature(uint256 deadline);
/**
* @dev Mismatched signature.
*/
error ERC2612InvalidSigner(address signer, address owner);
/**
* @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`.
*
* It's a good idea to use the same `name` that is defined as the ERC20 token name.
*/
constructor(string memory name) EIP712(name, "1") {}
/**
* @inheritdoc IERC20Permit
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
if (block.timestamp > deadline) {
revert ERC2612ExpiredSignature(deadline);
}
bytes32 structHash = keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline));
bytes32 hash = _hashTypedDataV4(structHash);
address signer = ECDSA.recover(hash, v, r, s);
if (signer != owner) {
revert ERC2612InvalidSigner(signer, owner);
}
_approve(owner, spender, value);
}
/**
* @inheritdoc IERC20Permit
*/
function nonces(address owner) public view virtual override(IERC20Permit, Nonces) returns (uint256) {
return super.nonces(owner);
}
/**
* @inheritdoc IERC20Permit
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view virtual returns (bytes32) {
return _domainSeparatorV4();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/Math.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
/**
* @dev Muldiv operation overflow.
*/
error MathOverflowedMulDiv();
enum Rounding {
Floor, // Toward negative infinity
Ceil, // Toward positive infinity
Trunc, // Toward zero
Expand // Away from zero
}
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds towards infinity instead
* of rounding towards zero.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
if (b == 0) {
// Guarantee the same behavior as in a regular Solidity division.
return a / b;
}
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or
* denominator == 0.
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) with further edits by
* Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0 = x * y; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
if (denominator <= prod1) {
revert MathOverflowedMulDiv();
}
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator.
// Always >= 1. See https://cs.stackexchange.com/q/138556/92363.
uint256 twos = denominator & (0 - denominator);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also
// works in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (unsignedRoundsUp(rounding) && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded
* towards zero.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (unsignedRoundsUp(rounding) && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (unsignedRoundsUp(rounding) && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10 of a positive value rounded towards zero.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (unsignedRoundsUp(rounding) && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256 of a positive value rounded towards zero.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (unsignedRoundsUp(rounding) && 1 << (result << 3) < value ? 1 : 0);
}
}
/**
* @dev Returns whether a provided rounding mode is considered rounding up for unsigned integers.
*/
function unsignedRoundsUp(Rounding rounding) internal pure returns (bool) {
return uint8(rounding) % 2 == 1;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;
pragma experimental ABIEncoderV2;
interface IMulticall3 {
struct Call {
address target;
bytes callData;
}
struct Call3 {
address target;
bool allowFailure;
bytes callData;
}
struct Call3Value {
address target;
bool allowFailure;
uint256 value;
bytes callData;
}
struct Result {
bool success;
bytes returnData;
}
function aggregate(Call[] calldata calls)
external
payable
returns (uint256 blockNumber, bytes[] memory returnData);
function aggregate3(Call3[] calldata calls) external payable returns (Result[] memory returnData);
function aggregate3Value(Call3Value[] calldata calls) external payable returns (Result[] memory returnData);
function blockAndAggregate(Call[] calldata calls)
external
payable
returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData);
function getBasefee() external view returns (uint256 basefee);
function getBlockHash(uint256 blockNumber) external view returns (bytes32 blockHash);
function getBlockNumber() external view returns (uint256 blockNumber);
function getChainId() external view returns (uint256 chainid);
function getCurrentBlockCoinbase() external view returns (address coinbase);
function getCurrentBlockDifficulty() external view returns (uint256 difficulty);
function getCurrentBlockGasLimit() external view returns (uint256 gaslimit);
function getCurrentBlockTimestamp() external view returns (uint256 timestamp);
function getEthBalance(address addr) external view returns (uint256 balance);
function getLastBlockHash() external view returns (bytes32 blockHash);
function tryAggregate(bool requireSuccess, Call[] calldata calls)
external
payable
returns (Result[] memory returnData);
function tryBlockAndAggregate(bool requireSuccess, Call[] calldata calls)
external
payable
returns (uint256 blockNumber, bytes32 blockHash, Result[] memory returnData);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/ERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC20Metadata} from "./extensions/IERC20Metadata.sol";
import {Context} from "../../utils/Context.sol";
import {IERC20Errors} from "../../interfaces/draft-IERC6093.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*/
abstract contract ERC20 is Context, IERC20, IERC20Metadata, IERC20Errors {
mapping(address account => uint256) private _balances;
mapping(address account => mapping(address spender => uint256)) private _allowances;
uint256 private _totalSupply;
string private _name;
string private _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/
function name() public view virtual returns (string memory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/
function symbol() public view virtual returns (string memory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/
function decimals() public view virtual returns (uint8) {
return 18;
}
/**
* @dev See {IERC20-totalSupply}.
*/
function totalSupply() public view virtual returns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/
function balanceOf(address account) public view virtual returns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `value`.
*/
function transfer(address to, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_transfer(owner, to, value);
return true;
}
/**
* @dev See {IERC20-allowance}.
*/
function allowance(address owner, address spender) public view virtual returns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `value` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/
function approve(address spender, uint256 value) public virtual returns (bool) {
address owner = _msgSender();
_approve(owner, spender, value);
return true;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `value`.
* - the caller must have allowance for ``from``'s tokens of at least
* `value`.
*/
function transferFrom(address from, address to, uint256 value) public virtual returns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, value);
_transfer(from, to, value);
return true;
}
/**
* @dev Moves a `value` amount of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _transfer(address from, address to, uint256 value) internal {
if (from == address(0)) {
revert ERC20InvalidSender(address(0));
}
if (to == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(from, to, value);
}
/**
* @dev Transfers a `value` amount of tokens from `from` to `to`, or alternatively mints (or burns) if `from`
* (or `to`) is the zero address. All customizations to transfers, mints, and burns should be done by overriding
* this function.
*
* Emits a {Transfer} event.
*/
function _update(address from, address to, uint256 value) internal virtual {
if (from == address(0)) {
// Overflow check required: The rest of the code assumes that totalSupply never overflows
_totalSupply += value;
} else {
uint256 fromBalance = _balances[from];
if (fromBalance < value) {
revert ERC20InsufficientBalance(from, fromBalance, value);
}
unchecked {
// Overflow not possible: value <= fromBalance <= totalSupply.
_balances[from] = fromBalance - value;
}
}
if (to == address(0)) {
unchecked {
// Overflow not possible: value <= totalSupply or value <= fromBalance <= totalSupply.
_totalSupply -= value;
}
} else {
unchecked {
// Overflow not possible: balance + value is at most totalSupply, which we know fits into a uint256.
_balances[to] += value;
}
}
emit Transfer(from, to, value);
}
/**
* @dev Creates a `value` amount of tokens and assigns them to `account`, by transferring it from address(0).
* Relies on the `_update` mechanism
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead.
*/
function _mint(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidReceiver(address(0));
}
_update(address(0), account, value);
}
/**
* @dev Destroys a `value` amount of tokens from `account`, lowering the total supply.
* Relies on the `_update` mechanism.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* NOTE: This function is not virtual, {_update} should be overridden instead
*/
function _burn(address account, uint256 value) internal {
if (account == address(0)) {
revert ERC20InvalidSender(address(0));
}
_update(account, address(0), value);
}
/**
* @dev Sets `value` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*
* Overrides to this logic should be done to the variant with an additional `bool emitEvent` argument.
*/
function _approve(address owner, address spender, uint256 value) internal {
_approve(owner, spender, value, true);
}
/**
* @dev Variant of {_approve} with an optional flag to enable or disable the {Approval} event.
*
* By default (when calling {_approve}) the flag is set to true. On the other hand, approval changes made by
* `_spendAllowance` during the `transferFrom` operation set the flag to false. This saves gas by not emitting any
* `Approval` event during `transferFrom` operations.
*
* Anyone who wishes to continue emitting `Approval` events on the`transferFrom` operation can force the flag to
* true using the following override:
* ```
* function _approve(address owner, address spender, uint256 value, bool) internal virtual override {
* super._approve(owner, spender, value, true);
* }
* ```
*
* Requirements are the same as {_approve}.
*/
function _approve(address owner, address spender, uint256 value, bool emitEvent) internal virtual {
if (owner == address(0)) {
revert ERC20InvalidApprover(address(0));
}
if (spender == address(0)) {
revert ERC20InvalidSpender(address(0));
}
_allowances[owner][spender] = value;
if (emitEvent) {
emit Approval(owner, spender, value);
}
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `value`.
*
* Does not update the allowance value in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Does not emit an {Approval} event.
*/
function _spendAllowance(address owner, address spender, uint256 value) internal virtual {
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance != type(uint256).max) {
if (currentAllowance < value) {
revert ERC20InsufficientAllowance(spender, currentAllowance, value);
}
unchecked {
_approve(owner, spender, currentAllowance - value, false);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.20;
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS
}
/**
* @dev The signature derives the `address(0)`.
*/
error ECDSAInvalidSignature();
/**
* @dev The signature has an invalid length.
*/
error ECDSAInvalidSignatureLength(uint256 length);
/**
* @dev The signature has an S value that is in the upper half order.
*/
error ECDSAInvalidSignatureS(bytes32 s);
/**
* @dev Returns the address that signed a hashed message (`hash`) with `signature` or an error. This will not
* return address(0) without also returning an error description. Errors are documented using an enum (error type)
* and a bytes32 providing additional information about the error.
*
* If no error is returned, then the address can be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError, bytes32) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength, bytes32(signature.length));
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM precompile allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {MessageHashUtils-toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, signature);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError, bytes32) {
unchecked {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
// We do not check for an overflow here since the shift operation results in 0 or 1.
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, r, vs);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function tryRecover(
bytes32 hash,
uint8 v,
bytes32 r,
bytes32 s
) internal pure returns (address, RecoverError, bytes32) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS, s);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature, bytes32(0));
}
return (signer, RecoverError.NoError, bytes32(0));
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error, bytes32 errorArg) = tryRecover(hash, v, r, s);
_throwError(error, errorArg);
return recovered;
}
/**
* @dev Optionally reverts with the corresponding custom error according to the `error` argument provided.
*/
function _throwError(RecoverError error, bytes32 errorArg) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert ECDSAInvalidSignature();
} else if (error == RecoverError.InvalidSignatureLength) {
revert ECDSAInvalidSignatureLength(uint256(errorArg));
} else if (error == RecoverError.InvalidSignatureS) {
revert ECDSAInvalidSignatureS(errorArg);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.20;
import {MessageHashUtils} from "./MessageHashUtils.sol";
import {ShortStrings, ShortString} from "../ShortStrings.sol";
import {IERC5267} from "../../interfaces/IERC5267.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding scheme specified in the EIP requires a domain separator and a hash of the typed structured data, whose
* encoding is very generic and therefore its implementation in Solidity is not feasible, thus this contract
* does not implement the encoding itself. Protocols need to implement the type-specific encoding they need in order to
* produce the hash of their typed data using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
* separator of the implementation contract. This will cause the {_domainSeparatorV4} function to always rebuild the
* separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
*
* @custom:oz-upgrades-unsafe-allow state-variable-immutable
*/
abstract contract EIP712 is IERC5267 {
using ShortStrings for *;
bytes32 private constant TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _cachedDomainSeparator;
uint256 private immutable _cachedChainId;
address private immutable _cachedThis;
bytes32 private immutable _hashedName;
bytes32 private immutable _hashedVersion;
ShortString private immutable _name;
ShortString private immutable _version;
string private _nameFallback;
string private _versionFallback;
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
_name = name.toShortStringWithFallback(_nameFallback);
_version = version.toShortStringWithFallback(_versionFallback);
_hashedName = keccak256(bytes(name));
_hashedVersion = keccak256(bytes(version));
_cachedChainId = block.chainid;
_cachedDomainSeparator = _buildDomainSeparator();
_cachedThis = address(this);
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
return _cachedDomainSeparator;
} else {
return _buildDomainSeparator();
}
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return MessageHashUtils.toTypedDataHash(_domainSeparatorV4(), structHash);
}
/**
* @dev See {IERC-5267}.
*/
function eip712Domain()
public
view
virtual
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)
{
return (
hex"0f", // 01111
_EIP712Name(),
_EIP712Version(),
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}
/**
* @dev The name parameter for the EIP712 domain.
*
* NOTE: By default this function reads _name which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Name() internal view returns (string memory) {
return _name.toStringWithFallback(_nameFallback);
}
/**
* @dev The version parameter for the EIP712 domain.
*
* NOTE: By default this function reads _version which is an immutable value.
* It only reads from storage if necessary (in case the value is too large to fit in a ShortString).
*/
// solhint-disable-next-line func-name-mixedcase
function _EIP712Version() internal view returns (string memory) {
return _version.toStringWithFallback(_versionFallback);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/Nonces.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides tracking nonces for addresses. Nonces will only increment.
*/
abstract contract Nonces {
/**
* @dev The nonce used for an `account` is not the expected current nonce.
*/
error InvalidAccountNonce(address account, uint256 currentNonce);
mapping(address account => uint256) private _nonces;
/**
* @dev Returns the next unused nonce for an address.
*/
function nonces(address owner) public view virtual returns (uint256) {
return _nonces[owner];
}
/**
* @dev Consumes a nonce.
*
* Returns the current value and increments nonce.
*/
function _useNonce(address owner) internal virtual returns (uint256) {
// For each account, the nonce has an initial value of 0, can only be incremented by one, and cannot be
// decremented or reset. This guarantees that the nonce never overflows.
unchecked {
// It is important to do x++ and not ++x here.
return _nonces[owner]++;
}
}
/**
* @dev Same as {_useNonce} but checking that `nonce` is the next valid for `owner`.
*/
function _useCheckedNonce(address owner, uint256 nonce) internal virtual {
uint256 current = _useNonce(owner);
if (nonce != current) {
revert InvalidAccountNonce(owner, current);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/draft-IERC6093.sol)
pragma solidity ^0.8.20;
/**
* @dev Standard ERC20 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC20 tokens.
*/
interface IERC20Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientBalance(address sender, uint256 balance, uint256 needed);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC20InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC20InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `spender`’s `allowance`. Used in transfers.
* @param spender Address that may be allowed to operate on tokens without being their owner.
* @param allowance Amount of tokens a `spender` is allowed to operate with.
* @param needed Minimum amount required to perform a transfer.
*/
error ERC20InsufficientAllowance(address spender, uint256 allowance, uint256 needed);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC20InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `spender` to be approved. Used in approvals.
* @param spender Address that may be allowed to operate on tokens without being their owner.
*/
error ERC20InvalidSpender(address spender);
}
/**
* @dev Standard ERC721 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC721 tokens.
*/
interface IERC721Errors {
/**
* @dev Indicates that an address can't be an owner. For example, `address(0)` is a forbidden owner in EIP-20.
* Used in balance queries.
* @param owner Address of the current owner of a token.
*/
error ERC721InvalidOwner(address owner);
/**
* @dev Indicates a `tokenId` whose `owner` is the zero address.
* @param tokenId Identifier number of a token.
*/
error ERC721NonexistentToken(uint256 tokenId);
/**
* @dev Indicates an error related to the ownership over a particular token. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param tokenId Identifier number of a token.
* @param owner Address of the current owner of a token.
*/
error ERC721IncorrectOwner(address sender, uint256 tokenId, address owner);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC721InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC721InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param tokenId Identifier number of a token.
*/
error ERC721InsufficientApproval(address operator, uint256 tokenId);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC721InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC721InvalidOperator(address operator);
}
/**
* @dev Standard ERC1155 Errors
* Interface of the https://eips.ethereum.org/EIPS/eip-6093[ERC-6093] custom errors for ERC1155 tokens.
*/
interface IERC1155Errors {
/**
* @dev Indicates an error related to the current `balance` of a `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
* @param balance Current balance for the interacting account.
* @param needed Minimum amount required to perform a transfer.
* @param tokenId Identifier number of a token.
*/
error ERC1155InsufficientBalance(address sender, uint256 balance, uint256 needed, uint256 tokenId);
/**
* @dev Indicates a failure with the token `sender`. Used in transfers.
* @param sender Address whose tokens are being transferred.
*/
error ERC1155InvalidSender(address sender);
/**
* @dev Indicates a failure with the token `receiver`. Used in transfers.
* @param receiver Address to which tokens are being transferred.
*/
error ERC1155InvalidReceiver(address receiver);
/**
* @dev Indicates a failure with the `operator`’s approval. Used in transfers.
* @param operator Address that may be allowed to operate on tokens without being their owner.
* @param owner Address of the current owner of a token.
*/
error ERC1155MissingApprovalForAll(address operator, address owner);
/**
* @dev Indicates a failure with the `approver` of a token to be approved. Used in approvals.
* @param approver Address initiating an approval operation.
*/
error ERC1155InvalidApprover(address approver);
/**
* @dev Indicates a failure with the `operator` to be approved. Used in approvals.
* @param operator Address that may be allowed to operate on tokens without being their owner.
*/
error ERC1155InvalidOperator(address operator);
/**
* @dev Indicates an array length mismatch between ids and values in a safeBatchTransferFrom operation.
* Used in batch transfers.
* @param idsLength Length of the array of token identifiers
* @param valuesLength Length of the array of token amounts
*/
error ERC1155InvalidArrayLength(uint256 idsLength, uint256 valuesLength);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/cryptography/MessageHashUtils.sol)
pragma solidity ^0.8.20;
import {Strings} from "../Strings.sol";
/**
* @dev Signature message hash utilities for producing digests to be consumed by {ECDSA} recovery or signing.
*
* The library provides methods for generating a hash of a message that conforms to the
* https://eips.ethereum.org/EIPS/eip-191[EIP 191] and https://eips.ethereum.org/EIPS/eip-712[EIP 712]
* specifications.
*/
library MessageHashUtils {
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing a bytes32 `messageHash` with
* `"\x19Ethereum Signed Message:\n32"` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* NOTE: The `messageHash` parameter is intended to be the result of hashing a raw message with
* keccak256, although any bytes32 value can be safely used because the final digest will
* be re-hashed.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes32 messageHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32") // 32 is the bytes-length of messageHash
mstore(0x1c, messageHash) // 0x1c (28) is the length of the prefix
digest := keccak256(0x00, 0x3c) // 0x3c is the length of the prefix (0x1c) + messageHash (0x20)
}
}
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x45` (`personal_sign` messages).
*
* The digest is calculated by prefixing an arbitrary `message` with
* `"\x19Ethereum Signed Message:\n" + len(message)` and hashing the result. It corresponds with the
* hash signed when using the https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] JSON-RPC method.
*
* See {ECDSA-recover}.
*/
function toEthSignedMessageHash(bytes memory message) internal pure returns (bytes32) {
return
keccak256(bytes.concat("\x19Ethereum Signed Message:\n", bytes(Strings.toString(message.length)), message));
}
/**
* @dev Returns the keccak256 digest of an EIP-191 signed data with version
* `0x00` (data with intended validator).
*
* The digest is calculated by prefixing an arbitrary `data` with `"\x19\x00"` and the intended
* `validator` address. Then hashing the result.
*
* See {ECDSA-recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(hex"19_00", validator, data));
}
/**
* @dev Returns the keccak256 digest of an EIP-712 typed data (EIP-191 version `0x01`).
*
* The digest is calculated from a `domainSeparator` and a `structHash`, by prefixing them with
* `\x19\x01` and hashing the result. It corresponds to the hash signed by the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] JSON-RPC method as part of EIP-712.
*
* See {ECDSA-recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 digest) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, hex"19_01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
digest := keccak256(ptr, 0x42)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/ShortStrings.sol)
pragma solidity ^0.8.20;
import {StorageSlot} from "./StorageSlot.sol";
// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
// | length | 0x BB |
type ShortString is bytes32;
/**
* @dev This library provides functions to convert short memory strings
* into a `ShortString` type that can be used as an immutable variable.
*
* Strings of arbitrary length can be optimized using this library if
* they are short enough (up to 31 bytes) by packing them with their
* length (1 byte) in a single EVM word (32 bytes). Additionally, a
* fallback mechanism can be used for every other case.
*
* Usage example:
*
* ```solidity
* contract Named {
* using ShortStrings for *;
*
* ShortString private immutable _name;
* string private _nameFallback;
*
* constructor(string memory contractName) {
* _name = contractName.toShortStringWithFallback(_nameFallback);
* }
*
* function name() external view returns (string memory) {
* return _name.toStringWithFallback(_nameFallback);
* }
* }
* ```
*/
library ShortStrings {
// Used as an identifier for strings longer than 31 bytes.
bytes32 private constant FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
error StringTooLong(string str);
error InvalidShortString();
/**
* @dev Encode a string of at most 31 chars into a `ShortString`.
*
* This will trigger a `StringTooLong` error is the input string is too long.
*/
function toShortString(string memory str) internal pure returns (ShortString) {
bytes memory bstr = bytes(str);
if (bstr.length > 31) {
revert StringTooLong(str);
}
return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
}
/**
* @dev Decode a `ShortString` back to a "normal" string.
*/
function toString(ShortString sstr) internal pure returns (string memory) {
uint256 len = byteLength(sstr);
// using `new string(len)` would work locally but is not memory safe.
string memory str = new string(32);
/// @solidity memory-safe-assembly
assembly {
mstore(str, len)
mstore(add(str, 0x20), sstr)
}
return str;
}
/**
* @dev Return the length of a `ShortString`.
*/
function byteLength(ShortString sstr) internal pure returns (uint256) {
uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
if (result > 31) {
revert InvalidShortString();
}
return result;
}
/**
* @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
*/
function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
if (bytes(value).length < 32) {
return toShortString(value);
} else {
StorageSlot.getStringSlot(store).value = value;
return ShortString.wrap(FALLBACK_SENTINEL);
}
}
/**
* @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*/
function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return toString(value);
} else {
return store;
}
}
/**
* @dev Return the length of a string that was encoded to `ShortString` or written to storage using
* {setWithFallback}.
*
* WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
* actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
*/
function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
if (ShortString.unwrap(value) != FALLBACK_SENTINEL) {
return byteLength(value);
} else {
return bytes(store).length;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC5267.sol)
pragma solidity ^0.8.20;
interface IERC5267 {
/**
* @dev MAY be emitted to signal that the domain could have changed.
*/
event EIP712DomainChanged();
/**
* @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
* signature.
*/
function eip712Domain()
external
view
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}{
"remappings": [
"frax-std/=node_modules/frax-standard-solidity/src/",
"@prb/test/=node_modules/@prb/test/",
"forge-std/=node_modules/forge-std/src/",
"ds-test/=node_modules/ds-test/src/",
"@openzeppelin/=node_modules/@openzeppelin/",
"@uniswap/=node_modules/@uniswap/",
"dev-fraxswap/=node_modules/dev-fraxswap/",
"frax-standard-solidity/=node_modules/frax-standard-solidity/",
"solidity-bytes-utils/=node_modules/solidity-bytes-utils/",
"solmate/=node_modules/solmate/"
],
"optimizer": {
"enabled": true,
"runs": 1000
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "none",
"appendCBOR": false
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "shanghai",
"viaIR": false,
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_bammUIHelper","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"OraclePriceDeviated","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"int256","name":"targetLTV","type":"int256"},{"internalType":"bool","name":"max","type":"bool"}],"name":"_calcRentForLTV","outputs":[{"internalType":"int256","name":"rent","type":"int256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"bamm","type":"address"},{"internalType":"int256","name":"token0Amount","type":"int256"},{"internalType":"int256","name":"token1Amount","type":"int256"},{"internalType":"int256","name":"targetLTV","type":"int256"},{"internalType":"uint256","name":"maxUtilRate","type":"uint256"},{"internalType":"bool","name":"maxRent","type":"bool"}],"name":"actionWithTargetLTV","outputs":[{"components":[{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"int256","name":"rented","type":"int256"}],"internalType":"struct IBAMM.Vault","name":"vault","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"bamm","type":"address"},{"internalType":"bool","name":"allowed","type":"bool"}],"name":"allowBAMM","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"allowedBAMMs","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"bammList","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"bammUIHelper","outputs":[{"internalType":"contract BAMMUIHelper","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"bamm","type":"address"}],"name":"closePosition","outputs":[{"components":[{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"int256","name":"rented","type":"int256"}],"internalType":"struct IBAMM.Vault","name":"vault","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"bamm","type":"address"},{"internalType":"int256","name":"token0Amount","type":"int256"},{"internalType":"int256","name":"token1Amount","type":"int256"}],"name":"depositWithdraw","outputs":[{"components":[{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"int256","name":"rented","type":"int256"}],"internalType":"struct IBAMM.Vault","name":"vault","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"},{"internalType":"bytes","name":"_data","type":"bytes"}],"name":"execute","outputs":[{"internalType":"bool","name":"","type":"bool"},{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"bamm","type":"address"},{"components":[{"internalType":"int256","name":"token0Amount","type":"int256"},{"internalType":"int256","name":"token1Amount","type":"int256"},{"internalType":"int256","name":"rent","type":"int256"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"token0AmountMin","type":"uint256"},{"internalType":"uint256","name":"token1AmountMin","type":"uint256"},{"internalType":"bool","name":"closePosition","type":"bool"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"uint256","name":"deadline","type":"uint256"}],"internalType":"struct IBAMM.Action","name":"action","type":"tuple"}],"name":"executeActions","outputs":[{"components":[{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"int256","name":"rented","type":"int256"}],"internalType":"struct IBAMM.Vault","name":"vault","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract BAMMFactory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isOperator","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"bamm","type":"address"},{"internalType":"int256","name":"targetLTV","type":"int256"},{"internalType":"uint256","name":"maxUtilRate","type":"uint256"}],"name":"rentMax","outputs":[{"components":[{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"int256","name":"rented","type":"int256"}],"internalType":"struct IBAMM.Vault","name":"vault","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_defaultMaxRent","type":"bool"}],"name":"setDefaultMaxRent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_defaultMaxUtilRate","type":"uint256"}],"name":"setDefaultMaxUtilRate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"int256","name":"_defaultTargetLTV","type":"int256"}],"name":"setDefaultTargetLTV","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_operator","type":"address"},{"internalType":"bool","name":"allowed","type":"bool"}],"name":"setOperator","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"bamm","type":"address"},{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountOutMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"bytes","name":"route","type":"bytes"}],"internalType":"struct IFraxswapRouterMultihop.FraxswapParams","name":"swapParams","type":"tuple"},{"internalType":"int256","name":"targetLTV","type":"int256"},{"internalType":"uint256","name":"maxUtilRate","type":"uint256"},{"internalType":"bool","name":"maxRent","type":"bool"}],"name":"swap","outputs":[{"components":[{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"int256","name":"rented","type":"int256"}],"internalType":"struct IBAMM.Vault","name":"vault","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"bamm","type":"address"},{"components":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountOutMinimum","type":"uint256"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"uint256","name":"deadline","type":"uint256"},{"internalType":"bool","name":"approveMax","type":"bool"},{"internalType":"uint8","name":"v","type":"uint8"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"bytes","name":"route","type":"bytes"}],"internalType":"struct IFraxswapRouterMultihop.FraxswapParams","name":"swapParams","type":"tuple"}],"name":"swap","outputs":[{"components":[{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"int256","name":"rented","type":"int256"}],"internalType":"struct IBAMM.Vault","name":"vault","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"bamm","type":"address"},{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"}],"name":"swapToken0","outputs":[{"components":[{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"int256","name":"rented","type":"int256"}],"internalType":"struct IBAMM.Vault","name":"vault","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"bamm","type":"address"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"}],"name":"swapToken1","outputs":[{"components":[{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"int256","name":"rented","type":"int256"}],"internalType":"struct IBAMM.Vault","name":"vault","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"bamm","type":"address"},{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"uint256","name":"amountOutMin","type":"uint256"},{"internalType":"int256","name":"targetLTV","type":"int256"},{"internalType":"uint256","name":"maxUtilRate","type":"uint256"},{"internalType":"bool","name":"maxRent","type":"bool"}],"name":"swapWithTargetLTV","outputs":[{"components":[{"internalType":"int256","name":"token0","type":"int256"},{"internalType":"int256","name":"token1","type":"int256"},{"internalType":"int256","name":"rented","type":"int256"}],"internalType":"struct IBAMM.Vault","name":"vault","type":"tuple"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20Metadata","name":"_token","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"withdrawERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"withdrawETH","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60c0604052670d999fb6796f6000600455670d2f0adf2a2c60006005556006805460ff1916905534801562000032575f80fd5b506040516200436f3803806200436f83398101604081905262000055916200010a565b33806200007b57604051631e4fbdf760e01b81525f600482015260240160405180910390fd5b62000086816200009f565b506001600160a01b039182166080521660a05262000140565b5f80546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b80516001600160a01b038116811462000105575f80fd5b919050565b5f80604083850312156200011c575f80fd5b6200012783620000ee565b91506200013760208401620000ee565b90509250929050565b60805160a0516141ce620001a15f395f81816101f301528181610534015281816105cb015281816114a50152818161153c01528181611ece01528181611f60015281816122ae015261234001525f81816104250152610c3401526141ce5ff3fe608060405234801561000f575f80fd5b50600436106101b0575f3560e01c80636cfdf208116100f35780638da5cb5b11610093578063aad5f07e1161006e578063aad5f07e146103ec578063b61d27f6146103ff578063c45a015514610420578063f2fde38b14610447575f80fd5b80638da5cb5b146103b6578063a44637be146103c6578063a59bbf68146103d9575f80fd5b80637173f22d116100ce5780637173f22d1461035b57806375b91dea1461036e5780637bd8711e1461038157806386e200c514610394575f80fd5b80636cfdf2081461030e5780636d70f7ae14610321578063715018a614610353575f80fd5b80633e27d0141161015e5780634d4354cb116101395780634d4354cb146102b4578063558a7297146102c75780636abc60ad146102da5780636c37651c146102ed575f80fd5b80633e27d0141461027b57806344004cc11461028e5780634782f779146102a1575f80fd5b80632f86e2dd1161018e5780632f86e2dd146102405780633140bad914610253578063398ea22b14610268575f80fd5b8063133e8aec146101b4578063178ca94f146101ee578063211b07491461022d575b5f80fd5b6101c76101c2366004613713565b61045a565b60408051825181526020808401519082015291810151908201526060015b60405180910390f35b6102157f000000000000000000000000000000000000000000000000000000000000000081565b6040516001600160a01b0390911681526020016101e5565b6101c761023b366004613786565b6109e6565b6101c761024e3660046137ea565b610ace565b610266610261366004613805565b610bf4565b005b6101c761027636600461383c565b611098565b6101c761028936600461383c565b6110d6565b61026661029c36600461386e565b611118565b6102666102af3660046138ac565b61112b565b6101c76102c23660046138d6565b6111d2565b6102666102d5366004613805565b611213565b6102666102e8366004613923565b611245565b6103006102fb36600461393a565b611252565b6040519081526020016101e5565b61026661031c366004613978565b611376565b61034361032f3660046137ea565b60016020525f908152604090205460ff1681565b60405190151581526020016101e5565b610266611391565b6101c761036936600461383c565b6113a4565b6101c761037c366004613993565b6113d0565b6101c761038f36600461383c565b6117f8565b6103436103a23660046137ea565b60026020525f908152604090205460ff1681565b5f546001600160a01b0316610215565b6101c76103d43660046139ed565b61183a565b6102666103e7366004613923565b611979565b6102156103fa366004613923565b611986565b61041261040d366004613acf565b6119ae565b6040516101e5929190613b9e565b6102157f000000000000000000000000000000000000000000000000000000000000000081565b6102666104553660046137ea565b611a25565b61047b60405180606001604052805f81526020015f81526020015f81525090565b335f9081526001602052604090205460ff16806104a157505f546001600160a01b031633145b806104aa575033155b6104b2575f80fd5b6001600160a01b0386165f90815260026020526040902054869060ff166105135760405162461bcd60e51b815260206004820152601060248201526f10905353481b9bdd08185b1b1bddd95960821b60448201526064015b60405180910390fd5b6040516306e847bf60e11b81526001600160a01b0388811660048301525f917f000000000000000000000000000000000000000000000000000000000000000090911690630dd08f7e906024016101a0604051808303815f875af115801561057d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105a19190613bb8565b604051631999908560e31b81526001600160a01b038a811660048301523060248301529192505f917f0000000000000000000000000000000000000000000000000000000000000000169063cccc8428906044016101a0604051808303815f875af1158015610612573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106369190613c6c565b90505f808a6001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610676573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061069a9190613d1e565b6001600160a01b03168a5f01516001600160a01b0316036106d1578960200151915089606001516106ca90613d4d565b9050610763565b8a6001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561070d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107319190613d1e565b6001600160a01b03168a5f01516001600160a01b0316036107635750602089015160608a015161076090613d4d565b91505b5f876107bd576107b8855f01518660200151858760800151885f01516107899190613d67565b6107939190613d67565b858860a0015189602001516107a89190613d67565b6107b29190613d67565b8e611a7b565b61080c565b61080c855f01518660200151858760800151885f01516107dd9190613d67565b6107e79190613d67565b858860a0015189602001516107fc9190613d67565b6108069190613d67565b8e611b67565b90505f670de0b6b3a76400008660600151866040015161082c9190613d8d565b6108369190613dd0565b6108409083613d67565b90505f81131561089c575f8660a00151670de0b6b3a76400008c8960a001518a6080015161086e9190613dfc565b6108789190613e0f565b6108829190613e26565b61088c9190613e39565b90508082131561089a578091505b505b60408051610180810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810191909152606087015161091383670de0b6b3a7640000613d8d565b61091d9190613dd0565b60408201819052620f423f1912801561093c5750620f42408160400151125b15610948575f60408201525b5f81604001511215610966576109668e885f01518960200151611c0d565b8d6001600160a01b031663a8747dc6828f6040518363ffffffff1660e01b8152600401610994929190613eeb565b6060604051808303815f875af11580156109b0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109d49190613fb2565b9e9d5050505050505050505050505050565b610a0760405180606001604052805f81526020015f81526020015f81525090565b335f9081526001602052604090205460ff1680610a2d57505f546001600160a01b031633145b80610a36575033155b610a3e575f80fd5b6001600160a01b0388165f90815260026020526040902054889060ff16610a9a5760405162461bcd60e51b815260206004820152601060248201526f10905353481b9bdd08185b1b1bddd95960821b604482015260640161050a565b8215610ab557610aae898989898989611e86565b9150610ac2565b610aae8989898989612266565b50979650505050505050565b610aef60405180606001604052805f81526020015f81526020015f81525090565b335f9081526001602052604090205460ff1680610b1557505f546001600160a01b031633145b80610b1e575033155b610b26575f80fd5b6001600160a01b0382165f90815260026020526040902054829060ff16610b825760405162461bcd60e51b815260206004820152601060248201526f10905353481b9bdd08185b1b1bddd95960821b604482015260640161050a565b60408051610180810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260e08101829052610100810182905261012081018290526101408101829052610160810191909152600160c0820152610bec848261183a565b949350505050565b610bfc6125cc565b6040517f89439acf0000000000000000000000000000000000000000000000000000000081526001600160a01b0383811660048301527f000000000000000000000000000000000000000000000000000000000000000016906389439acf90602401602060405180830381865afa158015610c79573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c9d919061400c565b610ce95760405162461bcd60e51b815260206004820152600860248201527f4e6f742042414d4d000000000000000000000000000000000000000000000000604482015260640161050a565b6001600160a01b0382165f908152600260205260409020805460ff19168215801591909117909155610f3057600380546001810182555f919091527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b01805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038416908117909155604080517f0dfe16810000000000000000000000000000000000000000000000000000000081529051630dfe1681916004808201926020929091908290030181865afa158015610dc1573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610de59190613d1e565b60405163095ea7b360e01b81526001600160a01b0384811660048301525f196024830152919091169063095ea7b3906044016020604051808303815f875af1158015610e33573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e57919061400c565b50816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e94573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610eb89190613d1e565b60405163095ea7b360e01b81526001600160a01b0384811660048301525f196024830152919091169063095ea7b3906044015b6020604051808303815f875af1158015610f07573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f2b919061400c565b505050565b816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f6c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f909190613d1e565b60405163095ea7b360e01b81526001600160a01b0384811660048301525f6024830152919091169063095ea7b3906044016020604051808303815f875af1158015610fdd573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611001919061400c565b50816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561103e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110629190613d1e565b60405163095ea7b360e01b81526001600160a01b0384811660048301525f6024830152919091169063095ea7b390604401610eeb565b6110b960405180606001604052805f81526020015f81526020015f81525090565b600454600554600654610bec92879287928792919060ff166113d0565b6110f760405180606001604052805f81526020015f81526020015f81525090565b610bec84845f8560045460055460065f9054906101000a900460ff166109e6565b6111206125cc565b610f2b838383612611565b6111336125cc565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f811461117c576040519150601f19603f3d011682016040523d82523d5f602084013e611181565b606091505b5050905080610f2b5760405162461bcd60e51b815260206004820152601460248201527f4661696c656420746f2073656e64204574686572000000000000000000000000604482015260640161050a565b6111f360405180606001604052805f81526020015f81526020015f81525090565b60045460055460065461120c928692869260ff1661045a565b9392505050565b61121b6125cc565b6001600160a01b03919091165f908152600160205260409020805460ff1916911515919091179055565b61124d6125cc565b600455565b5f620f424061126664e8d4a5100085613dd0565b93505f83611275576001611278565b5f195b90506112848280613d8d565b61128e8680613d8d565b6112989190613d67565b6112a3906002613d8d565b6112ad8789614027565b6112b78780613d8d565b6112c19190613d8d565b6113436112ce8580613d8d565b6112d88980613d8d565b6112e29190613d67565b896112ee8c6004613d8d565b6112f89190613d8d565b6113029190613d8d565b61130c8a8c614027565b6113168b8d614027565b6113208b80613d8d565b61132a9190613d8d565b6113349190613d8d565b61133e9190613d67565b612691565b61134d8885613d8d565b6113579190613d8d565b6113619190613d67565b61136b9190613dd0565b979650505050505050565b61137e6125cc565b6006805460ff1916911515919091179055565b6113996125cc565b6113a25f6126ff565b565b6113c560405180606001604052805f81526020015f81526020015f81525090565b610bec845f80868660015b6113f160405180606001604052805f81526020015f81526020015f81525090565b335f9081526001602052604090205460ff168061141757505f546001600160a01b031633145b80611420575033155b611428575f80fd5b6001600160a01b0387165f90815260026020526040902054879060ff166114845760405162461bcd60e51b815260206004820152601060248201526f10905353481b9bdd08185b1b1bddd95960821b604482015260640161050a565b6040516306e847bf60e11b81526001600160a01b0389811660048301525f917f000000000000000000000000000000000000000000000000000000000000000090911690630dd08f7e906024016101a0604051808303815f875af11580156114ee573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115129190613bb8565b604051631999908560e31b81526001600160a01b038b811660048301523060248301529192505f917f0000000000000000000000000000000000000000000000000000000000000000169063cccc8428906044016101a0604051808303815f875af1158015611583573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115a79190613c6c565b90505f898260800151835f01516115be9190613d67565b6115c89190614027565b90505f898360a0015184602001516115e09190613d67565b6115ea9190614027565b90505f8761160b57611606855f0151866020015185858e611a7b565b61161f565b61161f855f0151866020015185858e611b67565b90505f670de0b6b3a76400008660600151866040015161163f9190613d8d565b6116499190613dd0565b6116539083613d67565b90505f8113156116af575f8660a00151670de0b6b3a76400008c8960a001518a608001516116819190613dfc565b61168b9190613e0f565b6116959190613e26565b61169f9190613e39565b9050808213156116ad578091505b505b60408051610180810182525f91810182905260608082018390526080820183905260a0820183905260c0820183905260e082018390526101008201839052610120820183905261014082018390526101608201929092528e8152602081018e90529087015161172683670de0b6b3a7640000613d8d565b6117309190613dd0565b60408201819052620f423f1912801561174f5750620f42408160400151125b1561175b575f60408201525b5f81604001511215611779576117798f885f01518960200151611c0d565b8e6001600160a01b031663750c3a16826040518263ffffffff1660e01b81526004016117a5919061404e565b6060604051808303815f875af11580156117c1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117e59190613fb2565b9f9e505050505050505050505050505050565b61181960405180606001604052805f81526020015f81526020015f81525090565b610bec845f858560045460055460065f9054906101000a900460ff166109e6565b61185b60405180606001604052805f81526020015f81526020015f81525090565b335f9081526001602052604090205460ff168061188157505f546001600160a01b031633145b8061188a575033155b611892575f80fd5b6001600160a01b0383165f90815260026020526040902054839060ff166118ee5760405162461bcd60e51b815260206004820152601060248201526f10905353481b9bdd08185b1b1bddd95960821b604482015260640161050a565b3060608401526040517f750c3a160000000000000000000000000000000000000000000000000000000081526001600160a01b0385169063750c3a169061193990869060040161404e565b6060604051808303815f875af1158015611955573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610bec9190613fb2565b6119816125cc565b600555565b60038181548110611995575f80fd5b5f918252602090912001546001600160a01b0316905081565b5f60606119b96125cc565b5f80876001600160a01b03168787876040516119d692919061405d565b5f6040518083038185875af1925050503d805f8114611a10576040519150601f19603f3d011682016040523d82523d5f602084013e611a15565b606091505b5090999098509650505050505050565b611a2d6125cc565b6001600160a01b038116611a6f576040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081525f600482015260240161050a565b611a78816126ff565b50565b5f80611a8a61133e8789613e0f565b90505f851215611b0e5769021e19e0c9bab2400000611ade81868a611aaf8b8b613d8d565b611ab99190613dd0565b611acd9069021e19e0c9bab2400000613d8d565b611ad79190613dd0565b865f611252565b87611ae98488613d8d565b611af39190613dd0565b611afd9190613d8d565b611b079190613dd0565b9150611b5d565b5f841215611b5d5769021e19e0c9bab2400000611b31818789611aaf8c8a613d8d565b88611b3c8489613d8d565b611b469190613dd0565b611b509190613d8d565b611b5a9190613dd0565b91505b5095945050505050565b5f80611b7661133e8789613e0f565b90505f84138015611b9a57508486611b8e8987613d8d565b611b989190613dd0565b135b15611bea5769021e19e0c9bab2400000611ade81868a611bba8b8b613d8d565b611bc49190613dd0565b611bd89069021e19e0c9bab2400000613d8d565b611be29190613dd0565b866001611252565b5f851315611b5d5769021e19e0c9bab2400000611b31818789611bba8c8a613d8d565b5f80846001600160a01b031663395db9ec6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c4b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c6f9190613d1e565b6001600160a01b0316638f4bb32a866001600160a01b031663a8aa1b316040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cb9573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cdd9190613d1e565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b0390911660048201526107086024820152600a604482015261271060648201526084016040805180830381865afa158015611d4d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d71919061406c565b9092509050611d9d827c03b58e88c75313ec9d329eaaa18fb92f75215b17100000000000000000613e26565b91505f83611dba866e01ed09bead87c0378d8e6400000000613e0f565b611dc49190613e26565b90505f838211611ddd57611dd88285613e39565b611de7565b611de78483613e39565b90506101f484611df983612710613e0f565b611e039190613e26565b1115611e22576040516362f7964760e01b815260040160405180910390fd5b828211611e3857611e338284613e39565b611e42565b611e428383613e39565b90506101f483611e5483612710613e0f565b611e5e9190613e26565b1115611e7d576040516362f7964760e01b815260040160405180910390fd5b50505050505050565b611ea760405180606001604052805f81526020015f81526020015f81525090565b611eaf613338565b6040516306e847bf60e11b81526001600160a01b0389811660048301527f00000000000000000000000000000000000000000000000000000000000000001690630dd08f7e906024016101a0604051808303815f875af1158015611f15573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f399190613bb8565b8152604051631999908560e31b81526001600160a01b0389811660048301523060248301527f0000000000000000000000000000000000000000000000000000000000000000169063cccc8428906044016101a0604051808303815f875af1158015611fa7573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fcb9190613c6c565b60208201525f871315611fef57611fe5886001898861275b565b6040820152612009565b5f86131561200957612003885f888861275b565b60408201525b5f5b6003811015612189575f806120328b855f0151866020015187606001518860400151612d3f565b919650925090505f61204761133e8385613e0f565b90505f670de0b6b3a7640000865f015160600151886040015161206a9190613d8d565b6120749190613dd0565b90505f6120c18585856120878387613d8d565b6120919190613dd0565b8b5161209d9190613d67565b866120a88988613d8d565b6120b29190613dd0565b8c602001516108069190613d67565b9050865f015160600151876020015160600151826120df9190613d67565b6120f190670de0b6b3a7640000613d8d565b6120fb9190613dd0565b6060880180516040908101929092525101515f121561217957865160a08101516080909101515f9190670de0b6b3a7640000908c9061213b908490613dfc565b6121459190613e0f565b61214f9190613e26565b6121599190613e39565b90508088606001516040015113156121775760608801516040018190525b505b505050505080600101905061200b565b50620f423f198160600151604001511380156121af5750620f4240816060015160400151125b156121c15760608101515f6040909101525b5f81606001516040015112156121e657805180516020909101516121e6918a91611c0d565b6060810151604080830151905163543a3ee360e11b81526001600160a01b038b169263a8747dc69261221a92600401613eeb565b6060604051808303815f875af1158015612236573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061225a9190613fb2565b98975050505050505050565b61228760405180606001604052805f81526020015f81526020015f81525090565b61228f613338565b6040516306e847bf60e11b81526001600160a01b0388811660048301527f00000000000000000000000000000000000000000000000000000000000000001690630dd08f7e906024016101a0604051808303815f875af11580156122f5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123199190613bb8565b8152604051631999908560e31b81526001600160a01b0388811660048301523060248301527f0000000000000000000000000000000000000000000000000000000000000000169063cccc8428906044016101a0604051808303815f875af1158015612387573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123ab9190613c6c565b60208201525f8613156123cf576123c5876001888761275b565b60408201526123e9565b5f8513156123e9576123e3875f878761275b565b60408201525b5f5b60038110156124fb575f806124128a855f0151866020015187606001518860400151612d3f565b919650925090505f61242761133e8385613e0f565b90505f670de0b6b3a7640000865f015160600151886040015161244a9190613d8d565b6124549190613dd0565b90505f6124a78585856124678387613d8d565b6124719190613dd0565b8b5161247d9190613d67565b866124888988613d8d565b6124929190613dd0565b8c602001516124a19190613d67565b8d611a7b565b9050865f015160600151876020015160600151826124c59190613d67565b6124d790670de0b6b3a7640000613d8d565b6124e19190613dd0565b6060880151604001525050600190930192506123eb915050565b50620f423f198160600151604001511380156125215750620f4240816060015160400151125b156125335760608101515f6040909101525b5f81606001516040015112156125585780518051602090910151612558918991611c0d565b6060810151604080830151905163543a3ee360e11b81526001600160a01b038a169263a8747dc69261258c92600401613eeb565b6060604051808303815f875af11580156125a8573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b5a9190613fb2565b5f546001600160a01b031633146113a2576040517f118cdaa700000000000000000000000000000000000000000000000000000000815233600482015260240161050a565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052610f2b9084906130e2565b5f60038211156126f05750805f6126a9600283613e26565b6126b4906001613dfc565b90505b818110156126ea579050806002816126cf8186613e26565b6126d99190613dfc565b6126e39190613e26565b90506126b7565b50919050565b81156126fa575060015b919050565b5f80546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60408051610160810182525f8082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e0820183905261010082018390526101208201839052610140820152908461281c57856001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156127f3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128179190613d1e565b61287c565b856001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015612858573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061287c9190613d1e565b90505f856128e957866001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128c0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128e49190613d1e565b612949565b866001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015612925573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129499190613d1e565b90505f876001600160a01b03166370dcf1636040518163ffffffff1660e01b8152600401602060405180830381865afa158015612988573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129ac9190613d1e565b6040805160018082528183019092529192505f9190816020015b60608152602001906001900390816129c6579050509050816001600160a01b0316634a2649405f805f878e6001600160a01b031663a8aa1b316040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a2c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612a509190613d1e565b60018f612a5e576002612a61565b60015b60405160e089901b7fffffffff0000000000000000000000000000000000000000000000000000000016815260ff9788166004820152958716602487015293861660448601526001600160a01b0392831660648601529116608484015260a483015290911660c482015261271060e4820152610104015f60405180830381865afa158015612af1573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612b18919081019061408e565b815f81518110612b2a57612b2a6140f7565b60209081029190910101526040805160018082528183019092525f91816020015b6060815260200190600190039081612b4b5790505090506001600160a01b03831663b60650d785612710855f604051908082528060200260200182016040528015612baa57816020015b6060815260200190600190039081612b955790505b506040518563ffffffff1660e01b8152600401612bca9493929190614163565b5f60405180830381865afa158015612be4573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612c0b919081019061408e565b815f81518110612c1d57612c1d6140f7565b60209081029190910101525f6001600160a01b03841663b60650d78661271084604051908082528060200260200182016040528015612c7057816020015b6060815260200190600190039081612c5b5790505b50866040518563ffffffff1660e01b8152600401612c919493929190614163565b5f60405180830381865afa158015612cab573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612cd2919081019061408e565b60408051610160810182526001600160a01b039889168152602081019b909b529590961694890194909452505050506060840192909252503060808301524260a08301525f60c0830181905260e08301819052610100830181905261012083015261014082015292915050565b612d6060405180606001604052805f81526020015f81526020015f81525090565b845160208087015186518452868201519184019190915260408086015190870151612d8b9190614027565b8360400181815250505f670de0b6b3a764000088606001518760400151612db29190613d8d565b612dbc9190613dd0565b90505f86604001511315612e51575f612dd861133e8486613e0f565b90505f81612de68685613d8d565b612df09190613dd0565b90505f82612dfe8686613d8d565b612e089190613dd0565b9050612e148287613d67565b9550612e208186613d67565b945081875f01818151612e339190614027565b905250602087018051829190612e4a908390614027565b9052505050505b5f896001600160a01b031663a8aa1b316040518163ffffffff1660e01b8152600401602060405180830381865afa158015612e8e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612eb29190613d1e565b6001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015612eed573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f11919061419c565b90505f866020015190508a6001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f57573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f7b9190613d1e565b6001600160a01b0316875f01516001600160a01b031603612fef575f612fa38686848661315c565b9050612faf8287613dfc565b9550612fbb8186613e39565b945081875f01818151612fce9190613d67565b905250602087018051829190612fe5908390614027565b9052506130419050565b5f612ffc8586848661315c565b90506130088286613dfc565b94506130148187613e39565b955081876020018181516130289190613d67565b90525086518190889061303c908390614027565b905250505b50505f866040015112156130d6575f61305d61133e8486613e0f565b90505f8161306b8685613d8d565b6130759190613dd0565b90505f826130838686613d8d565b61308d9190613dd0565b90506130998287613d67565b95506130a58186613d67565b945081875f018181516130b89190614027565b9052506020870180518291906130cf908390614027565b9052505050505b50955095509592505050565b5f6130f66001600160a01b038416836131bc565b905080515f1415801561311a575080806020019051810190613118919061400c565b155b15610f2b576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b038416600482015260240161050a565b5f808311801561316b57505f85115b801561317657505f84115b61317e575f80fd5b5f6131898385613e0f565b90505f6131968683613e0f565b90505f826131a689612710613e0f565b6131b09190613dfc565b905061225a8183613e26565b606061120c83835f6131cf565b92915050565b60608147101561320d576040517fcd78605900000000000000000000000000000000000000000000000000000000815230600482015260240161050a565b5f80856001600160a01b0316848660405161322891906141b3565b5f6040518083038185875af1925050503d805f8114613262576040519150601f19603f3d011682016040523d82523d5f602084013e613267565b606091505b5091509150613277868383613281565b9695505050505050565b60608261329657613291826132f6565b61120c565b81511580156132ad57506001600160a01b0384163b155b156132ef576040517f9996b3150000000000000000000000000000000000000000000000000000000081526001600160a01b038516600482015260240161050a565b508061120c565b8051156133065780518082602001fd5b6040517f1425ea4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60405180608001604052806133a1604051806101a001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b8152602001613408604051806101a001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f151581526020015f151581525090565b815260408051610160810182525f808252602082810182905292820181905260608083018290526080830182905260a0830182905260c0830182905260e083018290526101008301829052610120830191909152610140820152910190815260408051610180810182525f8082526020828101829052928201819052606082018190526080820181905260a0820181905260c0820181905260e0820181905261010082018190526101208201819052610140820181905261016082015291015290565b6001600160a01b0381168114611a78575f80fd5b80356126fa816134cb565b634e487b7160e01b5f52604160045260245ffd5b604051610160810167ffffffffffffffff81118282101715613522576135226134ea565b60405290565b604051610180810167ffffffffffffffff81118282101715613522576135226134ea565b6040516101a0810167ffffffffffffffff81118282101715613522576135226134ea565b604051601f8201601f1916810167ffffffffffffffff81118282101715613599576135996134ea565b604052919050565b8015158114611a78575f80fd5b80356126fa816135a1565b803560ff811681146126fa575f80fd5b5f67ffffffffffffffff8211156135e2576135e26134ea565b50601f01601f191660200190565b5f82601f8301126135ff575f80fd5b813561361261360d826135c9565b613570565b818152846020838601011115613626575f80fd5b816020850160208301375f918101602001919091529392505050565b5f6101608284031215613653575f80fd5b61365b6134fe565b9050613666826134df565b81526020820135602082015261367e604083016134df565b604082015260608201356060820152613699608083016134df565b608082015260a082013560a08201526136b460c083016135ae565b60c08201526136c560e083016135b9565b60e0820152610100828101359082015261012080830135908201526101408083013567ffffffffffffffff8111156136fb575f80fd5b613707858286016135f0565b82840152505092915050565b5f805f805f60a08688031215613727575f80fd5b8535613732816134cb565b9450602086013567ffffffffffffffff81111561374d575f80fd5b61375988828901613642565b94505060408601359250606086013591506080860135613778816135a1565b809150509295509295909350565b5f805f805f805f60e0888a03121561379c575f80fd5b87356137a7816134cb565b96506020880135955060408801359450606088013593506080880135925060a0880135915060c08801356137da816135a1565b8091505092959891949750929550565b5f602082840312156137fa575f80fd5b813561120c816134cb565b5f8060408385031215613816575f80fd5b8235613821816134cb565b91506020830135613831816135a1565b809150509250929050565b5f805f6060848603121561384e575f80fd5b8335613859816134cb565b95602085013595506040909401359392505050565b5f805f60608486031215613880575f80fd5b833561388b816134cb565b9250602084013561389b816134cb565b929592945050506040919091013590565b5f80604083850312156138bd575f80fd5b82356138c8816134cb565b946020939093013593505050565b5f80604083850312156138e7575f80fd5b82356138f2816134cb565b9150602083013567ffffffffffffffff81111561390d575f80fd5b61391985828601613642565b9150509250929050565b5f60208284031215613933575f80fd5b5035919050565b5f805f806080858703121561394d575f80fd5b843593506020850135925060408501359150606085013561396d816135a1565b939692955090935050565b5f60208284031215613988575f80fd5b813561120c816135a1565b5f805f805f8060c087890312156139a8575f80fd5b86356139b3816134cb565b95506020870135945060408701359350606087013592506080870135915060a08701356139df816135a1565b809150509295509295509295565b5f808284036101a0811215613a00575f80fd5b8335613a0b816134cb565b9250610180601f198201811315613a20575f80fd5b613a28613528565b9150602085013582526040850135602083015260608501356040830152613a51608086016134df565b606083015260a0850135608083015260c085013560a0830152613a7660e086016135ae565b60c0830152610100613a898187016135ae565b60e0840152610120613a9c8188016135b9565b82850152610140915081870135818501525061016080870135828501528287013581850152505050809150509250929050565b5f805f8060608587031215613ae2575f80fd5b8435613aed816134cb565b935060208501359250604085013567ffffffffffffffff80821115613b10575f80fd5b818701915087601f830112613b23575f80fd5b813581811115613b31575f80fd5b886020828501011115613b42575f80fd5b95989497505060200194505050565b5f5b83811015613b6b578181015183820152602001613b53565b50505f910152565b5f8151808452613b8a816020860160208601613b51565b601f01601f19169290920160200192915050565b8215158152604060208201525f610bec6040830184613b73565b5f6101a08284031215613bc9575f80fd5b613bd161354c565b825181526020830151602082015260408301516040820152606083015160608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e08201526101008084015181830152506101208084015181830152506101408084015181830152506101608084015181830152506101808084015181830152508091505092915050565b80516126fa816135a1565b5f6101a08284031215613c7d575f80fd5b613c8561354c565b825181526020830151602082015260408301516040820152606083015160608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e0820152610100808401518183015250610120808401518183015250610140808401518183015250610160613d01818501613c61565b90820152610180613d13848201613c61565b908201529392505050565b5f60208284031215613d2e575f80fd5b815161120c816134cb565b634e487b7160e01b5f52601160045260245ffd5b5f600160ff1b8203613d6157613d61613d39565b505f0390565b8181035f831280158383131683831282161715613d8657613d86613d39565b5092915050565b8082025f8212600160ff1b84141615613da857613da8613d39565b81810583148215176131c9576131c9613d39565b634e487b7160e01b5f52601260045260245ffd5b5f82613dde57613dde613dbc565b600160ff1b82145f1984141615613df757613df7613d39565b500590565b808201808211156131c9576131c9613d39565b80820281158282048414176131c9576131c9613d39565b5f82613e3457613e34613dbc565b500490565b818103818111156131c9576131c9613d39565b8051825260208101516020830152604081015160408301526060810151613e7e60608401826001600160a01b03169052565b506080810151608083015260a081015160a083015260c0810151613ea660c084018215159052565b5060e0810151613eba60e084018215159052565b506101008181015160ff16908301526101208082015190830152610140808201519083015261016090810151910152565b5f6101a0613ef98386613e4c565b80610180840152613f1581840185516001600160a01b03169052565b5060208301516101c083015260408301516001600160a01b039081166101e0840152606084015161020084015260808401511661022083015260a083015161024083015260c0830151151561026083015260e083015160ff166102808301526101008301516102a08301526101208301516102c08301526101408301516101606102e0840152613fa9610300840182613b73565b95945050505050565b5f60608284031215613fc2575f80fd5b6040516060810181811067ffffffffffffffff82111715613fe557613fe56134ea565b80604052508251815260208301516020820152604083015160408201528091505092915050565b5f6020828403121561401c575f80fd5b815161120c816135a1565b8082018281125f83128015821682158216171561404657614046613d39565b505092915050565b61018081016131c98284613e4c565b818382375f9101908152919050565b5f806040838503121561407d575f80fd5b505080516020909101519092909150565b5f6020828403121561409e575f80fd5b815167ffffffffffffffff8111156140b4575f80fd5b8201601f810184136140c4575f80fd5b80516140d261360d826135c9565b8181528560208385010111156140e6575f80fd5b613fa9826020830160208601613b51565b634e487b7160e01b5f52603260045260245ffd5b5f8282518085526020808601955060208260051b840101602086015f5b8481101561415657601f19868403018952614144838351613b73565b98840198925090830190600101614128565b5090979650505050505050565b6001600160a01b0385168152836020820152608060408201525f61418a608083018561410b565b8281036060840152611b5a818561410b565b5f602082840312156141ac575f80fd5b5051919050565b5f82516141c4818460208701613b51565b91909101929150505600000000000000000000000019928170d739139bfbbb6614007f8eeed17db0ba000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd
Deployed Bytecode
0x608060405234801561000f575f80fd5b50600436106101b0575f3560e01c80636cfdf208116100f35780638da5cb5b11610093578063aad5f07e1161006e578063aad5f07e146103ec578063b61d27f6146103ff578063c45a015514610420578063f2fde38b14610447575f80fd5b80638da5cb5b146103b6578063a44637be146103c6578063a59bbf68146103d9575f80fd5b80637173f22d116100ce5780637173f22d1461035b57806375b91dea1461036e5780637bd8711e1461038157806386e200c514610394575f80fd5b80636cfdf2081461030e5780636d70f7ae14610321578063715018a614610353575f80fd5b80633e27d0141161015e5780634d4354cb116101395780634d4354cb146102b4578063558a7297146102c75780636abc60ad146102da5780636c37651c146102ed575f80fd5b80633e27d0141461027b57806344004cc11461028e5780634782f779146102a1575f80fd5b80632f86e2dd1161018e5780632f86e2dd146102405780633140bad914610253578063398ea22b14610268575f80fd5b8063133e8aec146101b4578063178ca94f146101ee578063211b07491461022d575b5f80fd5b6101c76101c2366004613713565b61045a565b60408051825181526020808401519082015291810151908201526060015b60405180910390f35b6102157f000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd81565b6040516001600160a01b0390911681526020016101e5565b6101c761023b366004613786565b6109e6565b6101c761024e3660046137ea565b610ace565b610266610261366004613805565b610bf4565b005b6101c761027636600461383c565b611098565b6101c761028936600461383c565b6110d6565b61026661029c36600461386e565b611118565b6102666102af3660046138ac565b61112b565b6101c76102c23660046138d6565b6111d2565b6102666102d5366004613805565b611213565b6102666102e8366004613923565b611245565b6103006102fb36600461393a565b611252565b6040519081526020016101e5565b61026661031c366004613978565b611376565b61034361032f3660046137ea565b60016020525f908152604090205460ff1681565b60405190151581526020016101e5565b610266611391565b6101c761036936600461383c565b6113a4565b6101c761037c366004613993565b6113d0565b6101c761038f36600461383c565b6117f8565b6103436103a23660046137ea565b60026020525f908152604090205460ff1681565b5f546001600160a01b0316610215565b6101c76103d43660046139ed565b61183a565b6102666103e7366004613923565b611979565b6102156103fa366004613923565b611986565b61041261040d366004613acf565b6119ae565b6040516101e5929190613b9e565b6102157f00000000000000000000000019928170d739139bfbbb6614007f8eeed17db0ba81565b6102666104553660046137ea565b611a25565b61047b60405180606001604052805f81526020015f81526020015f81525090565b335f9081526001602052604090205460ff16806104a157505f546001600160a01b031633145b806104aa575033155b6104b2575f80fd5b6001600160a01b0386165f90815260026020526040902054869060ff166105135760405162461bcd60e51b815260206004820152601060248201526f10905353481b9bdd08185b1b1bddd95960821b60448201526064015b60405180910390fd5b6040516306e847bf60e11b81526001600160a01b0388811660048301525f917f000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd90911690630dd08f7e906024016101a0604051808303815f875af115801561057d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105a19190613bb8565b604051631999908560e31b81526001600160a01b038a811660048301523060248301529192505f917f000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd169063cccc8428906044016101a0604051808303815f875af1158015610612573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906106369190613c6c565b90505f808a6001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610676573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061069a9190613d1e565b6001600160a01b03168a5f01516001600160a01b0316036106d1578960200151915089606001516106ca90613d4d565b9050610763565b8a6001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561070d573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906107319190613d1e565b6001600160a01b03168a5f01516001600160a01b0316036107635750602089015160608a015161076090613d4d565b91505b5f876107bd576107b8855f01518660200151858760800151885f01516107899190613d67565b6107939190613d67565b858860a0015189602001516107a89190613d67565b6107b29190613d67565b8e611a7b565b61080c565b61080c855f01518660200151858760800151885f01516107dd9190613d67565b6107e79190613d67565b858860a0015189602001516107fc9190613d67565b6108069190613d67565b8e611b67565b90505f670de0b6b3a76400008660600151866040015161082c9190613d8d565b6108369190613dd0565b6108409083613d67565b90505f81131561089c575f8660a00151670de0b6b3a76400008c8960a001518a6080015161086e9190613dfc565b6108789190613e0f565b6108829190613e26565b61088c9190613e39565b90508082131561089a578091505b505b60408051610180810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260c0810182905260e08101829052610100810182905261012081018290526101408101829052610160810191909152606087015161091383670de0b6b3a7640000613d8d565b61091d9190613dd0565b60408201819052620f423f1912801561093c5750620f42408160400151125b15610948575f60408201525b5f81604001511215610966576109668e885f01518960200151611c0d565b8d6001600160a01b031663a8747dc6828f6040518363ffffffff1660e01b8152600401610994929190613eeb565b6060604051808303815f875af11580156109b0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906109d49190613fb2565b9e9d5050505050505050505050505050565b610a0760405180606001604052805f81526020015f81526020015f81525090565b335f9081526001602052604090205460ff1680610a2d57505f546001600160a01b031633145b80610a36575033155b610a3e575f80fd5b6001600160a01b0388165f90815260026020526040902054889060ff16610a9a5760405162461bcd60e51b815260206004820152601060248201526f10905353481b9bdd08185b1b1bddd95960821b604482015260640161050a565b8215610ab557610aae898989898989611e86565b9150610ac2565b610aae8989898989612266565b50979650505050505050565b610aef60405180606001604052805f81526020015f81526020015f81525090565b335f9081526001602052604090205460ff1680610b1557505f546001600160a01b031633145b80610b1e575033155b610b26575f80fd5b6001600160a01b0382165f90815260026020526040902054829060ff16610b825760405162461bcd60e51b815260206004820152601060248201526f10905353481b9bdd08185b1b1bddd95960821b604482015260640161050a565b60408051610180810182525f80825260208201819052918101829052606081018290526080810182905260a0810182905260e08101829052610100810182905261012081018290526101408101829052610160810191909152600160c0820152610bec848261183a565b949350505050565b610bfc6125cc565b6040517f89439acf0000000000000000000000000000000000000000000000000000000081526001600160a01b0383811660048301527f00000000000000000000000019928170d739139bfbbb6614007f8eeed17db0ba16906389439acf90602401602060405180830381865afa158015610c79573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610c9d919061400c565b610ce95760405162461bcd60e51b815260206004820152600860248201527f4e6f742042414d4d000000000000000000000000000000000000000000000000604482015260640161050a565b6001600160a01b0382165f908152600260205260409020805460ff19168215801591909117909155610f3057600380546001810182555f919091527fc2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b01805473ffffffffffffffffffffffffffffffffffffffff19166001600160a01b038416908117909155604080517f0dfe16810000000000000000000000000000000000000000000000000000000081529051630dfe1681916004808201926020929091908290030181865afa158015610dc1573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610de59190613d1e565b60405163095ea7b360e01b81526001600160a01b0384811660048301525f196024830152919091169063095ea7b3906044016020604051808303815f875af1158015610e33573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610e57919061400c565b50816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015610e94573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610eb89190613d1e565b60405163095ea7b360e01b81526001600160a01b0384811660048301525f196024830152919091169063095ea7b3906044015b6020604051808303815f875af1158015610f07573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f2b919061400c565b505050565b816001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015610f6c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610f909190613d1e565b60405163095ea7b360e01b81526001600160a01b0384811660048301525f6024830152919091169063095ea7b3906044016020604051808303815f875af1158015610fdd573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611001919061400c565b50816001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa15801561103e573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906110629190613d1e565b60405163095ea7b360e01b81526001600160a01b0384811660048301525f6024830152919091169063095ea7b390604401610eeb565b6110b960405180606001604052805f81526020015f81526020015f81525090565b600454600554600654610bec92879287928792919060ff166113d0565b6110f760405180606001604052805f81526020015f81526020015f81525090565b610bec84845f8560045460055460065f9054906101000a900460ff166109e6565b6111206125cc565b610f2b838383612611565b6111336125cc565b5f826001600160a01b0316826040515f6040518083038185875af1925050503d805f811461117c576040519150601f19603f3d011682016040523d82523d5f602084013e611181565b606091505b5050905080610f2b5760405162461bcd60e51b815260206004820152601460248201527f4661696c656420746f2073656e64204574686572000000000000000000000000604482015260640161050a565b6111f360405180606001604052805f81526020015f81526020015f81525090565b60045460055460065461120c928692869260ff1661045a565b9392505050565b61121b6125cc565b6001600160a01b03919091165f908152600160205260409020805460ff1916911515919091179055565b61124d6125cc565b600455565b5f620f424061126664e8d4a5100085613dd0565b93505f83611275576001611278565b5f195b90506112848280613d8d565b61128e8680613d8d565b6112989190613d67565b6112a3906002613d8d565b6112ad8789614027565b6112b78780613d8d565b6112c19190613d8d565b6113436112ce8580613d8d565b6112d88980613d8d565b6112e29190613d67565b896112ee8c6004613d8d565b6112f89190613d8d565b6113029190613d8d565b61130c8a8c614027565b6113168b8d614027565b6113208b80613d8d565b61132a9190613d8d565b6113349190613d8d565b61133e9190613d67565b612691565b61134d8885613d8d565b6113579190613d8d565b6113619190613d67565b61136b9190613dd0565b979650505050505050565b61137e6125cc565b6006805460ff1916911515919091179055565b6113996125cc565b6113a25f6126ff565b565b6113c560405180606001604052805f81526020015f81526020015f81525090565b610bec845f80868660015b6113f160405180606001604052805f81526020015f81526020015f81525090565b335f9081526001602052604090205460ff168061141757505f546001600160a01b031633145b80611420575033155b611428575f80fd5b6001600160a01b0387165f90815260026020526040902054879060ff166114845760405162461bcd60e51b815260206004820152601060248201526f10905353481b9bdd08185b1b1bddd95960821b604482015260640161050a565b6040516306e847bf60e11b81526001600160a01b0389811660048301525f917f000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd90911690630dd08f7e906024016101a0604051808303815f875af11580156114ee573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115129190613bb8565b604051631999908560e31b81526001600160a01b038b811660048301523060248301529192505f917f000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd169063cccc8428906044016101a0604051808303815f875af1158015611583573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906115a79190613c6c565b90505f898260800151835f01516115be9190613d67565b6115c89190614027565b90505f898360a0015184602001516115e09190613d67565b6115ea9190614027565b90505f8761160b57611606855f0151866020015185858e611a7b565b61161f565b61161f855f0151866020015185858e611b67565b90505f670de0b6b3a76400008660600151866040015161163f9190613d8d565b6116499190613dd0565b6116539083613d67565b90505f8113156116af575f8660a00151670de0b6b3a76400008c8960a001518a608001516116819190613dfc565b61168b9190613e0f565b6116959190613e26565b61169f9190613e39565b9050808213156116ad578091505b505b60408051610180810182525f91810182905260608082018390526080820183905260a0820183905260c0820183905260e082018390526101008201839052610120820183905261014082018390526101608201929092528e8152602081018e90529087015161172683670de0b6b3a7640000613d8d565b6117309190613dd0565b60408201819052620f423f1912801561174f5750620f42408160400151125b1561175b575f60408201525b5f81604001511215611779576117798f885f01518960200151611c0d565b8e6001600160a01b031663750c3a16826040518263ffffffff1660e01b81526004016117a5919061404e565b6060604051808303815f875af11580156117c1573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906117e59190613fb2565b9f9e505050505050505050505050505050565b61181960405180606001604052805f81526020015f81526020015f81525090565b610bec845f858560045460055460065f9054906101000a900460ff166109e6565b61185b60405180606001604052805f81526020015f81526020015f81525090565b335f9081526001602052604090205460ff168061188157505f546001600160a01b031633145b8061188a575033155b611892575f80fd5b6001600160a01b0383165f90815260026020526040902054839060ff166118ee5760405162461bcd60e51b815260206004820152601060248201526f10905353481b9bdd08185b1b1bddd95960821b604482015260640161050a565b3060608401526040517f750c3a160000000000000000000000000000000000000000000000000000000081526001600160a01b0385169063750c3a169061193990869060040161404e565b6060604051808303815f875af1158015611955573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190610bec9190613fb2565b6119816125cc565b600555565b60038181548110611995575f80fd5b5f918252602090912001546001600160a01b0316905081565b5f60606119b96125cc565b5f80876001600160a01b03168787876040516119d692919061405d565b5f6040518083038185875af1925050503d805f8114611a10576040519150601f19603f3d011682016040523d82523d5f602084013e611a15565b606091505b5090999098509650505050505050565b611a2d6125cc565b6001600160a01b038116611a6f576040517f1e4fbdf70000000000000000000000000000000000000000000000000000000081525f600482015260240161050a565b611a78816126ff565b50565b5f80611a8a61133e8789613e0f565b90505f851215611b0e5769021e19e0c9bab2400000611ade81868a611aaf8b8b613d8d565b611ab99190613dd0565b611acd9069021e19e0c9bab2400000613d8d565b611ad79190613dd0565b865f611252565b87611ae98488613d8d565b611af39190613dd0565b611afd9190613d8d565b611b079190613dd0565b9150611b5d565b5f841215611b5d5769021e19e0c9bab2400000611b31818789611aaf8c8a613d8d565b88611b3c8489613d8d565b611b469190613dd0565b611b509190613d8d565b611b5a9190613dd0565b91505b5095945050505050565b5f80611b7661133e8789613e0f565b90505f84138015611b9a57508486611b8e8987613d8d565b611b989190613dd0565b135b15611bea5769021e19e0c9bab2400000611ade81868a611bba8b8b613d8d565b611bc49190613dd0565b611bd89069021e19e0c9bab2400000613d8d565b611be29190613dd0565b866001611252565b5f851315611b5d5769021e19e0c9bab2400000611b31818789611bba8c8a613d8d565b5f80846001600160a01b031663395db9ec6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611c4b573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611c6f9190613d1e565b6001600160a01b0316638f4bb32a866001600160a01b031663a8aa1b316040518163ffffffff1660e01b8152600401602060405180830381865afa158015611cb9573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611cdd9190613d1e565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b0390911660048201526107086024820152600a604482015261271060648201526084016040805180830381865afa158015611d4d573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611d71919061406c565b9092509050611d9d827c03b58e88c75313ec9d329eaaa18fb92f75215b17100000000000000000613e26565b91505f83611dba866e01ed09bead87c0378d8e6400000000613e0f565b611dc49190613e26565b90505f838211611ddd57611dd88285613e39565b611de7565b611de78483613e39565b90506101f484611df983612710613e0f565b611e039190613e26565b1115611e22576040516362f7964760e01b815260040160405180910390fd5b828211611e3857611e338284613e39565b611e42565b611e428383613e39565b90506101f483611e5483612710613e0f565b611e5e9190613e26565b1115611e7d576040516362f7964760e01b815260040160405180910390fd5b50505050505050565b611ea760405180606001604052805f81526020015f81526020015f81525090565b611eaf613338565b6040516306e847bf60e11b81526001600160a01b0389811660048301527f000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd1690630dd08f7e906024016101a0604051808303815f875af1158015611f15573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611f399190613bb8565b8152604051631999908560e31b81526001600160a01b0389811660048301523060248301527f000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd169063cccc8428906044016101a0604051808303815f875af1158015611fa7573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611fcb9190613c6c565b60208201525f871315611fef57611fe5886001898861275b565b6040820152612009565b5f86131561200957612003885f888861275b565b60408201525b5f5b6003811015612189575f806120328b855f0151866020015187606001518860400151612d3f565b919650925090505f61204761133e8385613e0f565b90505f670de0b6b3a7640000865f015160600151886040015161206a9190613d8d565b6120749190613dd0565b90505f6120c18585856120878387613d8d565b6120919190613dd0565b8b5161209d9190613d67565b866120a88988613d8d565b6120b29190613dd0565b8c602001516108069190613d67565b9050865f015160600151876020015160600151826120df9190613d67565b6120f190670de0b6b3a7640000613d8d565b6120fb9190613dd0565b6060880180516040908101929092525101515f121561217957865160a08101516080909101515f9190670de0b6b3a7640000908c9061213b908490613dfc565b6121459190613e0f565b61214f9190613e26565b6121599190613e39565b90508088606001516040015113156121775760608801516040018190525b505b505050505080600101905061200b565b50620f423f198160600151604001511380156121af5750620f4240816060015160400151125b156121c15760608101515f6040909101525b5f81606001516040015112156121e657805180516020909101516121e6918a91611c0d565b6060810151604080830151905163543a3ee360e11b81526001600160a01b038b169263a8747dc69261221a92600401613eeb565b6060604051808303815f875af1158015612236573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061225a9190613fb2565b98975050505050505050565b61228760405180606001604052805f81526020015f81526020015f81525090565b61228f613338565b6040516306e847bf60e11b81526001600160a01b0388811660048301527f000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd1690630dd08f7e906024016101a0604051808303815f875af11580156122f5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123199190613bb8565b8152604051631999908560e31b81526001600160a01b0388811660048301523060248301527f000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd169063cccc8428906044016101a0604051808303815f875af1158015612387573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906123ab9190613c6c565b60208201525f8613156123cf576123c5876001888761275b565b60408201526123e9565b5f8513156123e9576123e3875f878761275b565b60408201525b5f5b60038110156124fb575f806124128a855f0151866020015187606001518860400151612d3f565b919650925090505f61242761133e8385613e0f565b90505f670de0b6b3a7640000865f015160600151886040015161244a9190613d8d565b6124549190613dd0565b90505f6124a78585856124678387613d8d565b6124719190613dd0565b8b5161247d9190613d67565b866124888988613d8d565b6124929190613dd0565b8c602001516124a19190613d67565b8d611a7b565b9050865f015160600151876020015160600151826124c59190613d67565b6124d790670de0b6b3a7640000613d8d565b6124e19190613dd0565b6060880151604001525050600190930192506123eb915050565b50620f423f198160600151604001511380156125215750620f4240816060015160400151125b156125335760608101515f6040909101525b5f81606001516040015112156125585780518051602090910151612558918991611c0d565b6060810151604080830151905163543a3ee360e11b81526001600160a01b038a169263a8747dc69261258c92600401613eeb565b6060604051808303815f875af11580156125a8573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190611b5a9190613fb2565b5f546001600160a01b031633146113a2576040517f118cdaa700000000000000000000000000000000000000000000000000000000815233600482015260240161050a565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052610f2b9084906130e2565b5f60038211156126f05750805f6126a9600283613e26565b6126b4906001613dfc565b90505b818110156126ea579050806002816126cf8186613e26565b6126d99190613dfc565b6126e39190613e26565b90506126b7565b50919050565b81156126fa575060015b919050565b5f80546001600160a01b0383811673ffffffffffffffffffffffffffffffffffffffff19831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b60408051610160810182525f8082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e0820183905261010082018390526101208201839052610140820152908461281c57856001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa1580156127f3573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128179190613d1e565b61287c565b856001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015612858573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061287c9190613d1e565b90505f856128e957866001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa1580156128c0573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906128e49190613d1e565b612949565b866001600160a01b031663d21220a76040518163ffffffff1660e01b8152600401602060405180830381865afa158015612925573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129499190613d1e565b90505f876001600160a01b03166370dcf1636040518163ffffffff1660e01b8152600401602060405180830381865afa158015612988573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906129ac9190613d1e565b6040805160018082528183019092529192505f9190816020015b60608152602001906001900390816129c6579050509050816001600160a01b0316634a2649405f805f878e6001600160a01b031663a8aa1b316040518163ffffffff1660e01b8152600401602060405180830381865afa158015612a2c573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612a509190613d1e565b60018f612a5e576002612a61565b60015b60405160e089901b7fffffffff0000000000000000000000000000000000000000000000000000000016815260ff9788166004820152958716602487015293861660448601526001600160a01b0392831660648601529116608484015260a483015290911660c482015261271060e4820152610104015f60405180830381865afa158015612af1573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612b18919081019061408e565b815f81518110612b2a57612b2a6140f7565b60209081029190910101526040805160018082528183019092525f91816020015b6060815260200190600190039081612b4b5790505090506001600160a01b03831663b60650d785612710855f604051908082528060200260200182016040528015612baa57816020015b6060815260200190600190039081612b955790505b506040518563ffffffff1660e01b8152600401612bca9493929190614163565b5f60405180830381865afa158015612be4573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612c0b919081019061408e565b815f81518110612c1d57612c1d6140f7565b60209081029190910101525f6001600160a01b03841663b60650d78661271084604051908082528060200260200182016040528015612c7057816020015b6060815260200190600190039081612c5b5790505b50866040518563ffffffff1660e01b8152600401612c919493929190614163565b5f60405180830381865afa158015612cab573d5f803e3d5ffd5b505050506040513d5f823e601f3d908101601f19168201604052612cd2919081019061408e565b60408051610160810182526001600160a01b039889168152602081019b909b529590961694890194909452505050506060840192909252503060808301524260a08301525f60c0830181905260e08301819052610100830181905261012083015261014082015292915050565b612d6060405180606001604052805f81526020015f81526020015f81525090565b845160208087015186518452868201519184019190915260408086015190870151612d8b9190614027565b8360400181815250505f670de0b6b3a764000088606001518760400151612db29190613d8d565b612dbc9190613dd0565b90505f86604001511315612e51575f612dd861133e8486613e0f565b90505f81612de68685613d8d565b612df09190613dd0565b90505f82612dfe8686613d8d565b612e089190613dd0565b9050612e148287613d67565b9550612e208186613d67565b945081875f01818151612e339190614027565b905250602087018051829190612e4a908390614027565b9052505050505b5f896001600160a01b031663a8aa1b316040518163ffffffff1660e01b8152600401602060405180830381865afa158015612e8e573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612eb29190613d1e565b6001600160a01b031663ddca3f436040518163ffffffff1660e01b8152600401602060405180830381865afa158015612eed573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f11919061419c565b90505f866020015190508a6001600160a01b0316630dfe16816040518163ffffffff1660e01b8152600401602060405180830381865afa158015612f57573d5f803e3d5ffd5b505050506040513d601f19601f82011682018060405250810190612f7b9190613d1e565b6001600160a01b0316875f01516001600160a01b031603612fef575f612fa38686848661315c565b9050612faf8287613dfc565b9550612fbb8186613e39565b945081875f01818151612fce9190613d67565b905250602087018051829190612fe5908390614027565b9052506130419050565b5f612ffc8586848661315c565b90506130088286613dfc565b94506130148187613e39565b955081876020018181516130289190613d67565b90525086518190889061303c908390614027565b905250505b50505f866040015112156130d6575f61305d61133e8486613e0f565b90505f8161306b8685613d8d565b6130759190613dd0565b90505f826130838686613d8d565b61308d9190613dd0565b90506130998287613d67565b95506130a58186613d67565b945081875f018181516130b89190614027565b9052506020870180518291906130cf908390614027565b9052505050505b50955095509592505050565b5f6130f66001600160a01b038416836131bc565b905080515f1415801561311a575080806020019051810190613118919061400c565b155b15610f2b576040517f5274afe70000000000000000000000000000000000000000000000000000000081526001600160a01b038416600482015260240161050a565b5f808311801561316b57505f85115b801561317657505f84115b61317e575f80fd5b5f6131898385613e0f565b90505f6131968683613e0f565b90505f826131a689612710613e0f565b6131b09190613dfc565b905061225a8183613e26565b606061120c83835f6131cf565b92915050565b60608147101561320d576040517fcd78605900000000000000000000000000000000000000000000000000000000815230600482015260240161050a565b5f80856001600160a01b0316848660405161322891906141b3565b5f6040518083038185875af1925050503d805f8114613262576040519150601f19603f3d011682016040523d82523d5f602084013e613267565b606091505b5091509150613277868383613281565b9695505050505050565b60608261329657613291826132f6565b61120c565b81511580156132ad57506001600160a01b0384163b155b156132ef576040517f9996b3150000000000000000000000000000000000000000000000000000000081526001600160a01b038516600482015260240161050a565b508061120c565b8051156133065780518082602001fd5b6040517f1425ea4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60405180608001604052806133a1604051806101a001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81525090565b8152602001613408604051806101a001604052805f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f81526020015f151581526020015f151581525090565b815260408051610160810182525f808252602082810182905292820181905260608083018290526080830182905260a0830182905260c0830182905260e083018290526101008301829052610120830191909152610140820152910190815260408051610180810182525f8082526020828101829052928201819052606082018190526080820181905260a0820181905260c0820181905260e0820181905261010082018190526101208201819052610140820181905261016082015291015290565b6001600160a01b0381168114611a78575f80fd5b80356126fa816134cb565b634e487b7160e01b5f52604160045260245ffd5b604051610160810167ffffffffffffffff81118282101715613522576135226134ea565b60405290565b604051610180810167ffffffffffffffff81118282101715613522576135226134ea565b6040516101a0810167ffffffffffffffff81118282101715613522576135226134ea565b604051601f8201601f1916810167ffffffffffffffff81118282101715613599576135996134ea565b604052919050565b8015158114611a78575f80fd5b80356126fa816135a1565b803560ff811681146126fa575f80fd5b5f67ffffffffffffffff8211156135e2576135e26134ea565b50601f01601f191660200190565b5f82601f8301126135ff575f80fd5b813561361261360d826135c9565b613570565b818152846020838601011115613626575f80fd5b816020850160208301375f918101602001919091529392505050565b5f6101608284031215613653575f80fd5b61365b6134fe565b9050613666826134df565b81526020820135602082015261367e604083016134df565b604082015260608201356060820152613699608083016134df565b608082015260a082013560a08201526136b460c083016135ae565b60c08201526136c560e083016135b9565b60e0820152610100828101359082015261012080830135908201526101408083013567ffffffffffffffff8111156136fb575f80fd5b613707858286016135f0565b82840152505092915050565b5f805f805f60a08688031215613727575f80fd5b8535613732816134cb565b9450602086013567ffffffffffffffff81111561374d575f80fd5b61375988828901613642565b94505060408601359250606086013591506080860135613778816135a1565b809150509295509295909350565b5f805f805f805f60e0888a03121561379c575f80fd5b87356137a7816134cb565b96506020880135955060408801359450606088013593506080880135925060a0880135915060c08801356137da816135a1565b8091505092959891949750929550565b5f602082840312156137fa575f80fd5b813561120c816134cb565b5f8060408385031215613816575f80fd5b8235613821816134cb565b91506020830135613831816135a1565b809150509250929050565b5f805f6060848603121561384e575f80fd5b8335613859816134cb565b95602085013595506040909401359392505050565b5f805f60608486031215613880575f80fd5b833561388b816134cb565b9250602084013561389b816134cb565b929592945050506040919091013590565b5f80604083850312156138bd575f80fd5b82356138c8816134cb565b946020939093013593505050565b5f80604083850312156138e7575f80fd5b82356138f2816134cb565b9150602083013567ffffffffffffffff81111561390d575f80fd5b61391985828601613642565b9150509250929050565b5f60208284031215613933575f80fd5b5035919050565b5f805f806080858703121561394d575f80fd5b843593506020850135925060408501359150606085013561396d816135a1565b939692955090935050565b5f60208284031215613988575f80fd5b813561120c816135a1565b5f805f805f8060c087890312156139a8575f80fd5b86356139b3816134cb565b95506020870135945060408701359350606087013592506080870135915060a08701356139df816135a1565b809150509295509295509295565b5f808284036101a0811215613a00575f80fd5b8335613a0b816134cb565b9250610180601f198201811315613a20575f80fd5b613a28613528565b9150602085013582526040850135602083015260608501356040830152613a51608086016134df565b606083015260a0850135608083015260c085013560a0830152613a7660e086016135ae565b60c0830152610100613a898187016135ae565b60e0840152610120613a9c8188016135b9565b82850152610140915081870135818501525061016080870135828501528287013581850152505050809150509250929050565b5f805f8060608587031215613ae2575f80fd5b8435613aed816134cb565b935060208501359250604085013567ffffffffffffffff80821115613b10575f80fd5b818701915087601f830112613b23575f80fd5b813581811115613b31575f80fd5b886020828501011115613b42575f80fd5b95989497505060200194505050565b5f5b83811015613b6b578181015183820152602001613b53565b50505f910152565b5f8151808452613b8a816020860160208601613b51565b601f01601f19169290920160200192915050565b8215158152604060208201525f610bec6040830184613b73565b5f6101a08284031215613bc9575f80fd5b613bd161354c565b825181526020830151602082015260408301516040820152606083015160608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e08201526101008084015181830152506101208084015181830152506101408084015181830152506101608084015181830152506101808084015181830152508091505092915050565b80516126fa816135a1565b5f6101a08284031215613c7d575f80fd5b613c8561354c565b825181526020830151602082015260408301516040820152606083015160608201526080830151608082015260a083015160a082015260c083015160c082015260e083015160e0820152610100808401518183015250610120808401518183015250610140808401518183015250610160613d01818501613c61565b90820152610180613d13848201613c61565b908201529392505050565b5f60208284031215613d2e575f80fd5b815161120c816134cb565b634e487b7160e01b5f52601160045260245ffd5b5f600160ff1b8203613d6157613d61613d39565b505f0390565b8181035f831280158383131683831282161715613d8657613d86613d39565b5092915050565b8082025f8212600160ff1b84141615613da857613da8613d39565b81810583148215176131c9576131c9613d39565b634e487b7160e01b5f52601260045260245ffd5b5f82613dde57613dde613dbc565b600160ff1b82145f1984141615613df757613df7613d39565b500590565b808201808211156131c9576131c9613d39565b80820281158282048414176131c9576131c9613d39565b5f82613e3457613e34613dbc565b500490565b818103818111156131c9576131c9613d39565b8051825260208101516020830152604081015160408301526060810151613e7e60608401826001600160a01b03169052565b506080810151608083015260a081015160a083015260c0810151613ea660c084018215159052565b5060e0810151613eba60e084018215159052565b506101008181015160ff16908301526101208082015190830152610140808201519083015261016090810151910152565b5f6101a0613ef98386613e4c565b80610180840152613f1581840185516001600160a01b03169052565b5060208301516101c083015260408301516001600160a01b039081166101e0840152606084015161020084015260808401511661022083015260a083015161024083015260c0830151151561026083015260e083015160ff166102808301526101008301516102a08301526101208301516102c08301526101408301516101606102e0840152613fa9610300840182613b73565b95945050505050565b5f60608284031215613fc2575f80fd5b6040516060810181811067ffffffffffffffff82111715613fe557613fe56134ea565b80604052508251815260208301516020820152604083015160408201528091505092915050565b5f6020828403121561401c575f80fd5b815161120c816135a1565b8082018281125f83128015821682158216171561404657614046613d39565b505092915050565b61018081016131c98284613e4c565b818382375f9101908152919050565b5f806040838503121561407d575f80fd5b505080516020909101519092909150565b5f6020828403121561409e575f80fd5b815167ffffffffffffffff8111156140b4575f80fd5b8201601f810184136140c4575f80fd5b80516140d261360d826135c9565b8181528560208385010111156140e6575f80fd5b613fa9826020830160208601613b51565b634e487b7160e01b5f52603260045260245ffd5b5f8282518085526020808601955060208260051b840101602086015f5b8481101561415657601f19868403018952614144838351613b73565b98840198925090830190600101614128565b5090979650505050505050565b6001600160a01b0385168152836020820152608060408201525f61418a608083018561410b565b8281036060840152611b5a818561410b565b5f602082840312156141ac575f80fd5b5051919050565b5f82516141c4818460208701613b51565b919091019291505056
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000019928170d739139bfbbb6614007f8eeed17db0ba000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd
-----Decoded View---------------
Arg [0] : _factory (address): 0x19928170D739139bfbBb6614007F8EEeD17DB0Ba
Arg [1] : _bammUIHelper (address): 0x837e89a4b9e48C810867318198bf3560186988FD
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 00000000000000000000000019928170d739139bfbbb6614007f8eeed17db0ba
Arg [1] : 000000000000000000000000837e89a4b9e48c810867318198bf3560186988fd
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|---|---|---|---|---|
| FRAXTAL | 100.00% | $0.998955 | 212.3737 | $212.15 |
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.