Overview
POL Balance
POL Value
$0.00More Info
Private Name Tags
ContractCreator
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
Swaps
Compiler Version
v0.8.21+commit.d9974bed
Optimization Enabled:
Yes with 200 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity ^0.8.13; pragma experimental ABIEncoderV2; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./Structs.sol"; import "./Assimilators.sol"; import "./Storage.sol"; import "./CurveMath.sol"; import "./lib/UnsafeMath64x64.sol"; import "./lib/ABDKMath64x64.sol"; library Swaps { using ABDKMath64x64 for int128; using ABDKMath64x64 for int256; using UnsafeMath64x64 for int128; using ABDKMath64x64 for uint256; using SafeMath for uint256; event Trade( address indexed trader, address indexed origin, address indexed target, uint256 originAmount, uint256 targetAmount, int128 rawProtocolFee ); int128 public constant ONE = 0x10000000000000000; function getOriginAndTarget(Storage.Curve storage curve, address _o, address _t) private view returns (Storage.Assimilator memory, Storage.Assimilator memory) { Storage.Assimilator memory o_ = curve.assimilators[_o]; Storage.Assimilator memory t_ = curve.assimilators[_t]; require(o_.addr != address(0), "Curve/origin-not-supported"); require(t_.addr != address(0), "Curve/target-not-supported"); return (o_, t_); } function originSwap(Storage.Curve storage curve, OriginSwapData memory _swapData, bool toETH) external returns (uint256 tAmt_) { (Storage.Assimilator memory _o, Storage.Assimilator memory _t) = getOriginAndTarget(curve, _swapData._origin, _swapData._target); require(_swapData._origin != _swapData._target, "swap/same-origin-target"); if (_o.ix == _t.ix) { return Assimilators.outputNumeraire( _t.addr, _swapData._recipient, Assimilators.intakeRaw(_o.addr, _swapData._originAmount), toETH ); } SwapInfo memory _swapInfo; (int128 _amt, int128 _oGLiq, int128 _nGLiq, int128[] memory _oBals, int128[] memory _nBals) = getOriginSwapData(curve, _o.ix, _t.ix, _o.addr, _swapData._originAmount); _swapInfo.totalAmount = _amt; _amt = CurveMath.calculateTrade(curve, _oGLiq, _nGLiq, _oBals, _nBals, _amt, _t.ix); _swapInfo.curveFactory = ICurveFactory(_swapData._curveFactory); _swapInfo.amountToUser = _amt.us_mul(ONE - curve.epsilon); _swapInfo.totalFee = _swapInfo.amountToUser - _amt; _swapInfo.protocolFeePercentage = _swapInfo.curveFactory.getProtocolFee(); _swapInfo.treasury = _swapInfo.curveFactory.getProtocolTreasury(); _swapInfo.amountToTreasury = _swapInfo.totalFee.muli(_swapInfo.protocolFeePercentage).divi(100000); Assimilators.transferFee(_t.addr, _swapInfo.amountToTreasury, _swapInfo.treasury); tAmt_ = Assimilators.outputNumeraire(_t.addr, _swapData._recipient, _swapInfo.amountToUser, toETH); emit Trade( msg.sender, _swapData._origin, _swapData._target, _swapData._originAmount, tAmt_, _swapInfo.amountToTreasury ); } function viewOriginSwap(Storage.Curve storage curve, address _origin, address _target, uint256 _originAmount) external view returns (uint256 tAmt_) { (Storage.Assimilator memory _o, Storage.Assimilator memory _t) = getOriginAndTarget(curve, _origin, _target); if (_o.ix == _t.ix) { return Assimilators.viewRawAmount(_t.addr, Assimilators.viewNumeraireAmount(_o.addr, _originAmount)); } (int128 _amt, int128 _oGLiq, int128 _nGLiq, int128[] memory _nBals, int128[] memory _oBals) = viewOriginSwapData(curve, _o.ix, _t.ix, _originAmount, _o.addr); _amt = CurveMath.calculateTrade(curve, _oGLiq, _nGLiq, _oBals, _nBals, _amt, _t.ix); _amt = _amt.us_mul(ONE - curve.epsilon); tAmt_ = Assimilators.viewRawAmount(_t.addr, _amt.abs()); } function targetSwap(Storage.Curve storage curve, TargetSwapData memory _swapData) external returns (uint256 oAmt_) { (Storage.Assimilator memory _o, Storage.Assimilator memory _t) = getOriginAndTarget(curve, _swapData._origin, _swapData._target); require(_swapData._origin != _swapData._target, "swap/same-origin-target"); if (_o.ix == _t.ix) { return Assimilators.intakeNumeraire( _o.addr, Assimilators.outputRaw(_t.addr, _swapData._recipient, _swapData._targetAmount) ); } (int128 _amt, int128 _oGLiq, int128 _nGLiq, int128[] memory _oBals, int128[] memory _nBals) = getTargetSwapData(curve, _t.ix, _o.ix, _t.addr, _swapData._recipient, _swapData._targetAmount); _amt = CurveMath.calculateTrade(curve, _oGLiq, _nGLiq, _oBals, _nBals, _amt, _o.ix); SwapInfo memory _swapInfo; _swapInfo.totalAmount = _amt; _swapInfo.curveFactory = ICurveFactory(_swapData._curveFactory); _swapInfo.amountToUser = _amt.us_mul(ONE + curve.epsilon); _swapInfo.totalFee = _swapInfo.amountToUser - _amt; _swapInfo.protocolFeePercentage = _swapInfo.curveFactory.getProtocolFee(); _swapInfo.treasury = _swapInfo.curveFactory.getProtocolTreasury(); _swapInfo.amountToTreasury = _swapInfo.totalFee.muli(_swapInfo.protocolFeePercentage).divi(100000); Assimilators.transferFee(_o.addr, _swapInfo.amountToTreasury, _swapInfo.treasury); oAmt_ = Assimilators.intakeNumeraire(_o.addr, _swapInfo.amountToUser); emit Trade( msg.sender, _swapData._origin, _swapData._target, oAmt_, _swapData._targetAmount, _swapInfo.amountToTreasury ); } function viewTargetSwap(Storage.Curve storage curve, address _origin, address _target, uint256 _targetAmount) external view returns (uint256 oAmt_) { (Storage.Assimilator memory _o, Storage.Assimilator memory _t) = getOriginAndTarget(curve, _origin, _target); if (_o.ix == _t.ix) { return Assimilators.viewRawAmount(_o.addr, Assimilators.viewNumeraireAmount(_t.addr, _targetAmount)); } (int128 _amt, int128 _oGLiq, int128 _nGLiq, int128[] memory _nBals, int128[] memory _oBals) = viewTargetSwapData(curve, _t.ix, _o.ix, _targetAmount, _t.addr); _amt = CurveMath.calculateTrade(curve, _oGLiq, _nGLiq, _oBals, _nBals, _amt, _o.ix); _amt = _amt.us_mul(ONE + curve.epsilon); oAmt_ = Assimilators.viewRawAmount(_o.addr, _amt); } function getOriginSwapData( Storage.Curve storage curve, uint256 _inputIx, uint256 _outputIx, address _assim, uint256 _amt ) private returns (int128 amt_, int128 oGLiq_, int128 nGLiq_, int128[] memory, int128[] memory) { uint256 _length = curve.assets.length; int128[] memory oBals_ = new int128[](_length); int128[] memory nBals_ = new int128[](_length); Storage.Assimilator[] memory _reserves = curve.assets; for (uint256 i = 0; i < _length; i++) { if (i != _inputIx) { nBals_[i] = oBals_[i] = Assimilators.viewNumeraireBalance(_reserves[i].addr); } else { int128 _bal; (amt_, _bal) = Assimilators.intakeRawAndGetBalance(_assim, _amt); oBals_[i] = _bal.sub(amt_); nBals_[i] = _bal; } oGLiq_ += oBals_[i]; nGLiq_ += nBals_[i]; } nGLiq_ = nGLiq_.sub(amt_); nBals_[_outputIx] = ABDKMath64x64.sub(nBals_[_outputIx], amt_); return (amt_, oGLiq_, nGLiq_, oBals_, nBals_); } function getTargetSwapData( Storage.Curve storage curve, uint256 _inputIx, uint256 _outputIx, address _assim, address _recipient, uint256 _amt ) private returns (int128 amt_, int128 oGLiq_, int128 nGLiq_, int128[] memory, int128[] memory) { uint256 _length = curve.assets.length; int128[] memory oBals_ = new int128[](_length); int128[] memory nBals_ = new int128[](_length); Storage.Assimilator[] memory _reserves = curve.assets; for (uint256 i = 0; i < _length; i++) { if (i != _inputIx) { nBals_[i] = oBals_[i] = Assimilators.viewNumeraireBalance(_reserves[i].addr); } else { int128 _bal; (amt_, _bal) = Assimilators.outputRawAndGetBalance(_assim, _recipient, _amt); oBals_[i] = _bal.sub(amt_); nBals_[i] = _bal; } oGLiq_ += oBals_[i]; nGLiq_ += nBals_[i]; } nGLiq_ = nGLiq_.sub(amt_); nBals_[_outputIx] = ABDKMath64x64.sub(nBals_[_outputIx], amt_); return (amt_, oGLiq_, nGLiq_, oBals_, nBals_); } function viewOriginSwapData( Storage.Curve storage curve, uint256 _inputIx, uint256 _outputIx, uint256 _amt, address _assim ) private view returns (int128 amt_, int128 oGLiq_, int128 nGLiq_, int128[] memory, int128[] memory) { uint256 _length = curve.assets.length; int128[] memory nBals_ = new int128[](_length); int128[] memory oBals_ = new int128[](_length); for (uint256 i = 0; i < _length; i++) { if (i != _inputIx) { nBals_[i] = oBals_[i] = Assimilators.viewNumeraireBalance(curve.assets[i].addr); } else { int128 _bal; (amt_, _bal) = Assimilators.viewNumeraireAmountAndBalance(_assim, _amt); oBals_[i] = _bal; nBals_[i] = _bal.add(amt_); } oGLiq_ += oBals_[i]; nGLiq_ += nBals_[i]; } nGLiq_ = nGLiq_.sub(amt_); nBals_[_outputIx] = ABDKMath64x64.sub(nBals_[_outputIx], amt_); return (amt_, oGLiq_, nGLiq_, nBals_, oBals_); } function viewTargetSwapData( Storage.Curve storage curve, uint256 _inputIx, uint256 _outputIx, uint256 _amt, address _assim ) private view returns (int128 amt_, int128 oGLiq_, int128 nGLiq_, int128[] memory, int128[] memory) { uint256 _length = curve.assets.length; int128[] memory nBals_ = new int128[](_length); int128[] memory oBals_ = new int128[](_length); for (uint256 i = 0; i < _length; i++) { if (i != _inputIx) { nBals_[i] = oBals_[i] = Assimilators.viewNumeraireBalance(curve.assets[i].addr); } else { int128 _bal; (amt_, _bal) = Assimilators.viewNumeraireAmountAndBalance(_assim, _amt); amt_ = amt_.neg(); oBals_[i] = _bal; nBals_[i] = _bal.add(amt_); } oGLiq_ += oBals_[i]; nGLiq_ += nBals_[i]; } nGLiq_ = nGLiq_.sub(amt_); nBals_[_outputIx] = ABDKMath64x64.sub(nBals_[_outputIx], amt_); return (amt_, oGLiq_, nGLiq_, nBals_, oBals_); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ 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. * * _Available since v3.4._ */ 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. * * _Available since v3.4._ */ 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. * * _Available since v3.4._ */ 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. * * _Available since v3.4._ */ 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 addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @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 amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` 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 amount) 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 `amount` 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 amount) external returns (bool); /** * @dev Moves `amount` tokens from `from` to `to` using the * allowance mechanism. `amount` 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 amount) external returns (bool); }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.13; import "./interfaces/ICurveFactory.sol"; import "./interfaces/IOracle.sol"; struct OriginSwapData { address _origin; address _target; uint256 _originAmount; address _recipient; address _curveFactory; } struct TargetSwapData { address _origin; address _target; uint256 _targetAmount; address _recipient; address _curveFactory; } struct SwapInfo { int128 totalAmount; int128 totalFee; int128 amountToUser; int128 amountToTreasury; int128 protocolFeePercentage; address treasury; ICurveFactory curveFactory; } struct DepositData { uint256 deposits; uint256 minQuote; uint256 minBase; uint256 quoteAmt; uint256 maxQuote; uint256 maxBase; uint256 baseAmt; address token0; uint256 token0Bal; uint256 token1Bal; } struct IntakeNumLpRatioInfo { uint256 baseWeight; uint256 minBase; uint256 maxBase; uint256 baseAmt; uint256 quoteWeight; uint256 minQuote; uint256 maxQuote; uint256 quoteAmt; int128 amount; address token0; uint256 token0Bal; uint256 token1Bal; }
// SPDX-License-Identifier: MIT // 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.8.13; import "@openzeppelin/contracts/utils/Address.sol"; import "./interfaces/IAssimilator.sol"; import "./lib/ABDKMath64x64.sol"; import "./Structs.sol"; library Assimilators { using ABDKMath64x64 for int128; using Address for address; IAssimilator public constant iAsmltr = IAssimilator(address(0)); function delegate(address _callee, bytes memory _data) internal returns (bytes memory) { require(_callee.isContract(), "Assimilators/callee-is-not-a-contract"); // solhint-disable-next-line (bool _success, bytes memory returnData_) = _callee.delegatecall(_data); // solhint-disable-next-line assembly { if eq(_success, 0) { revert(add(returnData_, 0x20), returndatasize()) } } return returnData_; } function getRate(address _assim) internal view returns (uint256 amount_) { amount_ = IAssimilator(_assim).getRate(); } function viewRawAmount(address _assim, int128 _amt) internal view returns (uint256 amount_) { amount_ = IAssimilator(_assim).viewRawAmount(_amt); } function viewRawAmountLPRatio(address _assim, uint256 _baseWeight, uint256 _quoteWeight, int128 _amount) internal view returns (uint256 amount_) { amount_ = IAssimilator(_assim).viewRawAmountLPRatio(_baseWeight, _quoteWeight, address(this), _amount); } function viewNumeraireAmount(address _assim, uint256 _amt) internal view returns (int128 amt_) { amt_ = IAssimilator(_assim).viewNumeraireAmount(_amt); } function viewNumeraireAmountAndBalance(address _assim, uint256 _amt) internal view returns (int128 amt_, int128 bal_) { (amt_, bal_) = IAssimilator(_assim).viewNumeraireAmountAndBalance(address(this), _amt); } function viewNumeraireBalance(address _assim) internal view returns (int128 bal_) { bal_ = IAssimilator(_assim).viewNumeraireBalance(address(this)); } function viewNumeraireBalanceLPRatio(uint256 _baseWeight, uint256 _quoteWeight, address _assim) internal view returns (int128 bal_) { bal_ = IAssimilator(_assim).viewNumeraireBalanceLPRatio(_baseWeight, _quoteWeight, address(this)); } function intakeRaw(address _assim, uint256 _amt) internal returns (int128 amt_) { bytes memory data = abi.encodeWithSelector(iAsmltr.intakeRaw.selector, _amt); amt_ = abi.decode(delegate(_assim, data), (int128)); } function intakeRawAndGetBalance(address _assim, uint256 _amt) internal returns (int128 amt_, int128 bal_) { bytes memory data = abi.encodeWithSelector(iAsmltr.intakeRawAndGetBalance.selector, _amt); (amt_, bal_) = abi.decode(delegate(_assim, data), (int128, int128)); } function intakeNumeraire(address _assim, int128 _amt) internal returns (uint256 amt_) { bytes memory data = abi.encodeWithSelector(iAsmltr.intakeNumeraire.selector, _amt); amt_ = abi.decode(delegate(_assim, data), (uint256)); } function intakeNumeraireLPRatio(address _assim, IntakeNumLpRatioInfo memory info) internal returns (uint256 amt_) { bytes memory data = abi.encodeWithSelector( iAsmltr.intakeNumeraireLPRatio.selector, info.minBase, info.maxBase, info.baseAmt, info.minQuote, info.maxQuote, info.quoteAmt, info.token0 ); amt_ = abi.decode(delegate(_assim, data), (uint256)); } function outputRaw(address _assim, address _dst, uint256 _amt) internal returns (int128 amt_) { bytes memory data = abi.encodeWithSelector(iAsmltr.outputRaw.selector, _dst, _amt); amt_ = abi.decode(delegate(_assim, data), (int128)); amt_ = amt_.neg(); } function outputRawAndGetBalance(address _assim, address _dst, uint256 _amt) internal returns (int128 amt_, int128 bal_) { bytes memory data = abi.encodeWithSelector(iAsmltr.outputRawAndGetBalance.selector, _dst, _amt); (amt_, bal_) = abi.decode(delegate(_assim, data), (int128, int128)); amt_ = amt_.neg(); } function outputNumeraire(address _assim, address _dst, int128 _amt, bool _toETH) internal returns (uint256 amt_) { bytes memory data = abi.encodeWithSelector(iAsmltr.outputNumeraire.selector, _dst, _amt.abs(), _toETH); amt_ = abi.decode(delegate(_assim, data), (uint256)); } function transferFee(address _assim, int128 _amt, address _treasury) internal { bytes memory data = abi.encodeWithSelector(iAsmltr.transferFee.selector, _amt, _treasury); delegate(_assim, data); } }
// SPDX-License-Identifier: MIT // 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.8.13; import "./interfaces/IOracle.sol"; import "./Assimilators.sol"; contract Storage { struct Curve { // Curve parameters int128 alpha; int128 beta; int128 delta; int128 epsilon; int128 lambda; int128[] weights; // Assets and their assimilators Assimilator[] assets; mapping(address => Assimilator) assimilators; // Oracles to determine the price // Note that 0'th index should always be USDC 1e18 // Oracle's pricing should be denominated in Currency/USDC mapping(address => IOracle) oracles; // ERC20 Interface uint256 totalSupply; mapping(address => uint256) balances; mapping(address => mapping(address => uint256)) allowances; } struct Assimilator { address addr; uint8 ix; } // Curve parameters Curve public curve; // Ownable address public owner; string public name; string public symbol; uint8 public constant decimals = 18; address[] public derivatives; address[] public numeraires; address[] public reserves; // Curve operational state bool public frozen = false; bool public emergency = false; bool public notEntered = true; }
// SPDX-License-Identifier: MIT // 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.8.13; import "./Storage.sol"; import "./lib/UnsafeMath64x64.sol"; import "./lib/ABDKMath64x64.sol"; library CurveMath { int128 private constant ONE = 0x10000000000000000; int128 private constant MAX = 0x4000000000000000; // .25 in layman's terms int128 private constant MAX_DIFF = -0x10C6F7A0B5EE; int128 private constant ONE_WEI = 0x12; using ABDKMath64x64 for int128; using UnsafeMath64x64 for int128; using ABDKMath64x64 for uint256; // This is used to prevent stack too deep errors function calculateFee(int128 _gLiq, int128[] memory _bals, Storage.Curve storage curve, int128[] memory _weights) internal view returns (int128 psi_) { int128 _beta = curve.beta; int128 _delta = curve.delta; psi_ = calculateFee(_gLiq, _bals, _beta, _delta, _weights); } function calculateFee(int128 _gLiq, int128[] memory _bals, int128 _beta, int128 _delta, int128[] memory _weights) internal pure returns (int128 psi_) { uint256 _length = _bals.length; for (uint256 i = 0; i < _length; i++) { int128 _ideal = _gLiq.mul(_weights[i]); psi_ += calculateMicroFee(_bals[i], _ideal, _beta, _delta); } } function calculateMicroFee(int128 _bal, int128 _ideal, int128 _beta, int128 _delta) private pure returns (int128 fee_) { if (_bal < _ideal) { int128 _threshold = _ideal.mul(ONE - _beta); if (_bal < _threshold) { int128 _feeMargin = _threshold - _bal; fee_ = _feeMargin.mul(_delta); fee_ = fee_.div(_ideal); if (fee_ > MAX) fee_ = MAX; fee_ = fee_.mul(_feeMargin); } else { fee_ = 0; } } else { int128 _threshold = _ideal.mul(ONE + _beta); if (_bal > _threshold) { int128 _feeMargin = _bal - _threshold; fee_ = _feeMargin.mul(_delta); fee_ = fee_.div(_ideal); if (fee_ > MAX) fee_ = MAX; fee_ = fee_.mul(_feeMargin); } else { fee_ = 0; } } } function calculateTrade( Storage.Curve storage curve, int128 _oGLiq, int128 _nGLiq, int128[] memory _oBals, int128[] memory _nBals, int128 _inputAmt, uint256 _outputIndex ) internal view returns (int128 outputAmt_) { outputAmt_ = -_inputAmt; int128 _lambda = curve.lambda; int128[] memory _weights = curve.weights; int128 _omega = calculateFee(_oGLiq, _oBals, curve, _weights); int128 _psi; for (uint256 i = 0; i < 32; i++) { _psi = calculateFee(_nGLiq, _nBals, curve, _weights); int128 prevAmount; { prevAmount = outputAmt_; outputAmt_ = _omega < _psi ? -(_inputAmt + _omega - _psi) : -(_inputAmt + _lambda.mul(_omega - _psi)); } if (outputAmt_ / 1e13 == prevAmount / 1e13) { _nGLiq = _oGLiq + _inputAmt + outputAmt_; _nBals[_outputIndex] = _oBals[_outputIndex] + outputAmt_; enforceHalts(curve, _oGLiq, _nGLiq, _oBals, _nBals, _weights); enforceSwapInvariant(_oGLiq, _omega, _nGLiq, _psi); return outputAmt_; } else { _nGLiq = _oGLiq + _inputAmt + outputAmt_; _nBals[_outputIndex] = _oBals[_outputIndex].add(outputAmt_); } } revert("Curve/swap-convergence-failed"); } function calculateLiquidityMembrane( Storage.Curve storage curve, int128 _oGLiq, int128 _nGLiq, int128[] memory _oBals, int128[] memory _nBals ) internal view returns (int128 curves_) { enforceHalts(curve, _oGLiq, _nGLiq, _oBals, _nBals, curve.weights); int128 _omega; int128 _psi; { int128 _beta = curve.beta; int128 _delta = curve.delta; int128[] memory _weights = curve.weights; _omega = calculateFee(_oGLiq, _oBals, _beta, _delta, _weights); _psi = calculateFee(_nGLiq, _nBals, _beta, _delta, _weights); } int128 _feeDiff = _psi.sub(_omega); int128 _liqDiff = _nGLiq.sub(_oGLiq); int128 _oUtil = _oGLiq.sub(_omega); int128 _totalShells = curve.totalSupply.divu(1e18); int128 _curveMultiplier; if (_totalShells == 0) { curves_ = _nGLiq.sub(_psi); } else if (_feeDiff >= 0) { _curveMultiplier = _liqDiff.sub(_feeDiff).div(_oUtil); } else { _curveMultiplier = _liqDiff.sub(curve.lambda.mul(_feeDiff)); _curveMultiplier = _curveMultiplier.div(_oUtil); } if (_totalShells != 0) { curves_ = _totalShells.mul(_curveMultiplier); } } function enforceSwapInvariant(int128 _oGLiq, int128 _omega, int128 _nGLiq, int128 _psi) private pure { int128 _nextUtil = _nGLiq - _psi; int128 _prevUtil = _oGLiq - _omega; int128 _diff = _nextUtil - _prevUtil; require(0 < _diff || _diff >= MAX_DIFF, "Curve/swap-invariant-violation"); } function enforceHalts( Storage.Curve storage curve, int128 _oGLiq, int128 _nGLiq, int128[] memory _oBals, int128[] memory _nBals, int128[] memory _weights ) private view { uint256 _length = _nBals.length; int128 _alpha = curve.alpha; for (uint256 i = 0; i < _length; i++) { int128 _nIdeal = _nGLiq.mul(_weights[i]); if (_nBals[i] > _nIdeal) { int128 _upperAlpha = ONE + _alpha; int128 _nHalt = _nIdeal.mul(_upperAlpha); if (_nBals[i] > _nHalt) { int128 _oHalt = _oGLiq.mul(_weights[i]).mul(_upperAlpha); if (_oBals[i] < _oHalt) revert("Curve/upper-halt-1"); if (_nBals[i] - _nHalt > _oBals[i] - _oHalt) { revert("Curve/upper-halt-2"); } } } else { int128 _lowerAlpha = ONE - _alpha; int128 _nHalt = _nIdeal.mul(_lowerAlpha); if (_nBals[i] < _nHalt) { int128 _oHalt = _oGLiq.mul(_weights[i]); _oHalt = _oHalt.mul(_lowerAlpha); if (_oBals[i] > _oHalt) revert("Curve/lower-halt"); if (_nHalt - _nBals[i] > _oHalt - _oBals[i]) { revert("Curve/lower-halt"); } } } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.13; library UnsafeMath64x64 { /** * Calculate x * y rounding down. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function us_mul(int128 x, int128 y) internal pure returns (int128) { int256 result = int256(x) * y >> 64; return int128(result); } /** * Calculate x / y rounding towards zero. Revert on overflow or when y is * zero. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function us_div(int128 x, int128 y) internal pure returns (int128) { int256 result = (int256(x) << 64) / y; return int128(result); } }
// SPDX-License-Identifier: BSD-4-Clause /* * ABDK Math 64.64 Smart Contract Library. Copyright © 2019 by ABDK Consulting. * Author: Mikhail Vladimirov <[email protected]> */ pragma solidity ^0.8.13; /** * Smart contract library of mathematical functions operating with signed * 64.64-bit fixed point numbers. Signed 64.64-bit fixed point number is * basically a simple fraction whose numerator is signed 128-bit integer and * denominator is 2^64. As long as denominator is always the same, there is no * need to store it, thus in Solidity signed 64.64-bit fixed point numbers are * represented by int128 type holding only the numerator. */ library ABDKMath64x64 { /* * Minimum value signed 64.64-bit fixed point number may have. */ int128 private constant MIN_64x64 = -0x80000000000000000000000000000000; /* * Maximum value signed 64.64-bit fixed point number may have. */ int128 private constant MAX_64x64 = 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF; /** * Convert signed 256-bit integer number into signed 64.64-bit fixed point * number. Revert on overflow. * * @param x signed 256-bit integer number * @return signed 64.64-bit fixed point number */ function fromInt(int256 x) internal pure returns (int128) { unchecked { require(x >= -0x8000000000000000 && x <= 0x7FFFFFFFFFFFFFFF); return int128(x << 64); } } /** * Convert signed 64.64 fixed point number into signed 64-bit integer number * rounding down. * * @param x signed 64.64-bit fixed point number * @return signed 64-bit integer number */ function toInt(int128 x) internal pure returns (int64) { unchecked { return int64(x >> 64); } } /** * Convert unsigned 256-bit integer number into signed 64.64-bit fixed point * number. Revert on overflow. * * @param x unsigned 256-bit integer number * @return signed 64.64-bit fixed point number */ function fromUInt(uint256 x) internal pure returns (int128) { unchecked { require(x <= 0x7FFFFFFFFFFFFFFF); return int128(int256(x << 64)); } } /** * Convert signed 64.64 fixed point number into unsigned 64-bit integer * number rounding down. Revert on underflow. * * @param x signed 64.64-bit fixed point number * @return unsigned 64-bit integer number */ function toUInt(int128 x) internal pure returns (uint64) { unchecked { require(x >= 0); return uint64(uint128(x >> 64)); } } /** * Convert signed 128.128 fixed point number into signed 64.64-bit fixed point * number rounding down. Revert on overflow. * * @param x signed 128.128-bin fixed point number * @return signed 64.64-bit fixed point number */ function from128x128(int256 x) internal pure returns (int128) { unchecked { int256 result = x >> 64; require(result >= MIN_64x64 && result <= MAX_64x64); return int128(result); } } /** * Convert signed 64.64 fixed point number into signed 128.128 fixed point * number. * * @param x signed 64.64-bit fixed point number * @return signed 128.128 fixed point number */ function to128x128(int128 x) internal pure returns (int256) { unchecked { return int256(x) << 64; } } /** * Calculate x + y. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function add(int128 x, int128 y) internal pure returns (int128) { unchecked { int256 result = int256(x) + y; require(result >= MIN_64x64 && result <= MAX_64x64); return int128(result); } } /** * Calculate x - y. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function sub(int128 x, int128 y) internal pure returns (int128) { unchecked { int256 result = int256(x) - y; require(result >= MIN_64x64 && result <= MAX_64x64); return int128(result); } } /** * Calculate x * y rounding down. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function mul(int128 x, int128 y) internal pure returns (int128) { unchecked { int256 result = int256(x) * y >> 64; require(result >= MIN_64x64 && result <= MAX_64x64); return int128(result); } } /** * Calculate x * y rounding towards zero, where x is signed 64.64 fixed point * number and y is signed 256-bit integer number. Revert on overflow. * * @param x signed 64.64 fixed point number * @param y signed 256-bit integer number * @return signed 256-bit integer number */ function muli(int128 x, int256 y) internal pure returns (int256) { unchecked { if (x == MIN_64x64) { require( y >= -0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF && y <= 0x1000000000000000000000000000000000000000000000000 ); return -y << 63; } else { bool negativeResult = false; if (x < 0) { x = -x; negativeResult = true; } if (y < 0) { y = -y; // We rely on overflow behavior here negativeResult = !negativeResult; } uint256 absoluteResult = mulu(x, uint256(y)); if (negativeResult) { require(absoluteResult <= 0x8000000000000000000000000000000000000000000000000000000000000000); return -int256(absoluteResult); // We rely on overflow behavior here } else { require(absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); return int256(absoluteResult); } } } } /** * Calculate x * y rounding down, where x is signed 64.64 fixed point number * and y is unsigned 256-bit integer number. Revert on overflow. * * @param x signed 64.64 fixed point number * @param y unsigned 256-bit integer number * @return unsigned 256-bit integer number */ function mulu(int128 x, uint256 y) internal pure returns (uint256) { unchecked { if (y == 0) return 0; require(x >= 0); uint256 lo = (uint256(int256(x)) * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)) >> 64; uint256 hi = uint256(int256(x)) * (y >> 128); require(hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); hi <<= 64; require(hi <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF - lo); return hi + lo; } } /** * Calculate x / y rounding towards zero. Revert on overflow or when y is * zero. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function div(int128 x, int128 y) internal pure returns (int128) { unchecked { require(y != 0); int256 result = (int256(x) << 64) / y; require(result >= MIN_64x64 && result <= MAX_64x64); return int128(result); } } /** * Calculate x / y rounding towards zero, where x and y are signed 256-bit * integer numbers. Revert on overflow or when y is zero. * * @param x signed 256-bit integer number * @param y signed 256-bit integer number * @return signed 64.64-bit fixed point number */ function divi(int256 x, int256 y) internal pure returns (int128) { unchecked { require(y != 0); bool negativeResult = false; if (x < 0) { x = -x; // We rely on overflow behavior here negativeResult = true; } if (y < 0) { y = -y; // We rely on overflow behavior here negativeResult = !negativeResult; } uint128 absoluteResult = divuu(uint256(x), uint256(y)); if (negativeResult) { require(absoluteResult <= 0x80000000000000000000000000000000); return -int128(absoluteResult); // We rely on overflow behavior here } else { require(absoluteResult <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); return int128(absoluteResult); // We rely on overflow behavior here } } } /** * Calculate x / y rounding towards zero, where x and y are unsigned 256-bit * integer numbers. Revert on overflow or when y is zero. * * @param x unsigned 256-bit integer number * @param y unsigned 256-bit integer number * @return signed 64.64-bit fixed point number */ function divu(uint256 x, uint256 y) internal pure returns (int128) { unchecked { require(y != 0); uint128 result = divuu(x, y); require(result <= uint128(MAX_64x64)); return int128(result); } } /** * Calculate -x. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function neg(int128 x) internal pure returns (int128) { unchecked { require(x != MIN_64x64); return -x; } } /** * Calculate |x|. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function abs(int128 x) internal pure returns (int128) { unchecked { require(x != MIN_64x64); return x < 0 ? -x : x; } } /** * Calculate 1 / x rounding towards zero. Revert on overflow or when x is * zero. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function inv(int128 x) internal pure returns (int128) { unchecked { require(x != 0); int256 result = int256(0x100000000000000000000000000000000) / x; require(result >= MIN_64x64 && result <= MAX_64x64); return int128(result); } } /** * Calculate arithmetics average of x and y, i.e. (x + y) / 2 rounding down. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function avg(int128 x, int128 y) internal pure returns (int128) { unchecked { return int128((int256(x) + int256(y)) >> 1); } } /** * Calculate geometric average of x and y, i.e. sqrt (x * y) rounding down. * Revert on overflow or in case x * y is negative. * * @param x signed 64.64-bit fixed point number * @param y signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function gavg(int128 x, int128 y) internal pure returns (int128) { unchecked { int256 m = int256(x) * int256(y); require(m >= 0); require(m < 0x4000000000000000000000000000000000000000000000000000000000000000); return int128(sqrtu(uint256(m))); } } /** * Calculate x^y assuming 0^0 is 1, where x is signed 64.64 fixed point number * and y is unsigned 256-bit integer number. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @param y uint256 value * @return signed 64.64-bit fixed point number */ function pow(int128 x, uint256 y) internal pure returns (int128) { unchecked { bool negative = x < 0 && y & 1 == 1; uint256 absX = uint128(x < 0 ? -x : x); uint256 absResult; absResult = 0x100000000000000000000000000000000; if (absX <= 0x10000000000000000) { absX <<= 63; while (y != 0) { if (y & 0x1 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; if (y & 0x2 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; if (y & 0x4 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; if (y & 0x8 != 0) { absResult = absResult * absX >> 127; } absX = absX * absX >> 127; y >>= 4; } absResult >>= 64; } else { uint256 absXShift = 63; if (absX < 0x1000000000000000000000000) { absX <<= 32; absXShift -= 32; } if (absX < 0x10000000000000000000000000000) { absX <<= 16; absXShift -= 16; } if (absX < 0x1000000000000000000000000000000) { absX <<= 8; absXShift -= 8; } if (absX < 0x10000000000000000000000000000000) { absX <<= 4; absXShift -= 4; } if (absX < 0x40000000000000000000000000000000) { absX <<= 2; absXShift -= 2; } if (absX < 0x80000000000000000000000000000000) { absX <<= 1; absXShift -= 1; } uint256 resultShift = 0; while (y != 0) { require(absXShift < 64); if (y & 0x1 != 0) { absResult = absResult * absX >> 127; resultShift += absXShift; if (absResult > 0x100000000000000000000000000000000) { absResult >>= 1; resultShift += 1; } } absX = absX * absX >> 127; absXShift <<= 1; if (absX >= 0x100000000000000000000000000000000) { absX >>= 1; absXShift += 1; } y >>= 1; } require(resultShift < 64); absResult >>= 64 - resultShift; } int256 result = negative ? -int256(absResult) : int256(absResult); require(result >= MIN_64x64 && result <= MAX_64x64); return int128(result); } } /** * Calculate sqrt (x) rounding down. Revert if x < 0. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function sqrt(int128 x) internal pure returns (int128) { unchecked { require(x >= 0); return int128(sqrtu(uint256(int256(x)) << 64)); } } /** * Calculate binary logarithm of x. Revert if x <= 0. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function log_2(int128 x) internal pure returns (int128) { unchecked { require(x > 0); int256 msb = 0; int256 xc = x; if (xc >= 0x10000000000000000) { xc >>= 64; msb += 64; } if (xc >= 0x100000000) { xc >>= 32; msb += 32; } if (xc >= 0x10000) { xc >>= 16; msb += 16; } if (xc >= 0x100) { xc >>= 8; msb += 8; } if (xc >= 0x10) { xc >>= 4; msb += 4; } if (xc >= 0x4) { xc >>= 2; msb += 2; } if (xc >= 0x2) msb += 1; // No need to shift xc anymore int256 result = msb - 64 << 64; uint256 ux = uint256(int256(x)) << uint256(127 - msb); for (int256 bit = 0x8000000000000000; bit > 0; bit >>= 1) { ux *= ux; uint256 b = ux >> 255; ux >>= 127 + b; result += bit * int256(b); } return int128(result); } } /** * Calculate natural logarithm of x. Revert if x <= 0. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function ln(int128 x) internal pure returns (int128) { unchecked { require(x > 0); return int128(int256(uint256(int256(log_2(x))) * 0xB17217F7D1CF79ABC9E3B39803F2F6AF >> 128)); } } /** * Calculate binary exponent of x. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function exp_2(int128 x) internal pure returns (int128) { unchecked { require(x < 0x400000000000000000); // Overflow if (x < -0x400000000000000000) return 0; // Underflow uint256 result = 0x80000000000000000000000000000000; if (x & 0x8000000000000000 > 0) { result = result * 0x16A09E667F3BCC908B2FB1366EA957D3E >> 128; } if (x & 0x4000000000000000 > 0) { result = result * 0x1306FE0A31B7152DE8D5A46305C85EDEC >> 128; } if (x & 0x2000000000000000 > 0) { result = result * 0x1172B83C7D517ADCDF7C8C50EB14A791F >> 128; } if (x & 0x1000000000000000 > 0) { result = result * 0x10B5586CF9890F6298B92B71842A98363 >> 128; } if (x & 0x800000000000000 > 0) { result = result * 0x1059B0D31585743AE7C548EB68CA417FD >> 128; } if (x & 0x400000000000000 > 0) { result = result * 0x102C9A3E778060EE6F7CACA4F7A29BDE8 >> 128; } if (x & 0x200000000000000 > 0) { result = result * 0x10163DA9FB33356D84A66AE336DCDFA3F >> 128; } if (x & 0x100000000000000 > 0) { result = result * 0x100B1AFA5ABCBED6129AB13EC11DC9543 >> 128; } if (x & 0x80000000000000 > 0) { result = result * 0x10058C86DA1C09EA1FF19D294CF2F679B >> 128; } if (x & 0x40000000000000 > 0) { result = result * 0x1002C605E2E8CEC506D21BFC89A23A00F >> 128; } if (x & 0x20000000000000 > 0) { result = result * 0x100162F3904051FA128BCA9C55C31E5DF >> 128; } if (x & 0x10000000000000 > 0) { result = result * 0x1000B175EFFDC76BA38E31671CA939725 >> 128; } if (x & 0x8000000000000 > 0) { result = result * 0x100058BA01FB9F96D6CACD4B180917C3D >> 128; } if (x & 0x4000000000000 > 0) { result = result * 0x10002C5CC37DA9491D0985C348C68E7B3 >> 128; } if (x & 0x2000000000000 > 0) { result = result * 0x1000162E525EE054754457D5995292026 >> 128; } if (x & 0x1000000000000 > 0) { result = result * 0x10000B17255775C040618BF4A4ADE83FC >> 128; } if (x & 0x800000000000 > 0) { result = result * 0x1000058B91B5BC9AE2EED81E9B7D4CFAB >> 128; } if (x & 0x400000000000 > 0) { result = result * 0x100002C5C89D5EC6CA4D7C8ACC017B7C9 >> 128; } if (x & 0x200000000000 > 0) { result = result * 0x10000162E43F4F831060E02D839A9D16D >> 128; } if (x & 0x100000000000 > 0) { result = result * 0x100000B1721BCFC99D9F890EA06911763 >> 128; } if (x & 0x80000000000 > 0) { result = result * 0x10000058B90CF1E6D97F9CA14DBCC1628 >> 128; } if (x & 0x40000000000 > 0) { result = result * 0x1000002C5C863B73F016468F6BAC5CA2B >> 128; } if (x & 0x20000000000 > 0) { result = result * 0x100000162E430E5A18F6119E3C02282A5 >> 128; } if (x & 0x10000000000 > 0) { result = result * 0x1000000B1721835514B86E6D96EFD1BFE >> 128; } if (x & 0x8000000000 > 0) { result = result * 0x100000058B90C0B48C6BE5DF846C5B2EF >> 128; } if (x & 0x4000000000 > 0) { result = result * 0x10000002C5C8601CC6B9E94213C72737A >> 128; } if (x & 0x2000000000 > 0) { result = result * 0x1000000162E42FFF037DF38AA2B219F06 >> 128; } if (x & 0x1000000000 > 0) { result = result * 0x10000000B17217FBA9C739AA5819F44F9 >> 128; } if (x & 0x800000000 > 0) { result = result * 0x1000000058B90BFCDEE5ACD3C1CEDC823 >> 128; } if (x & 0x400000000 > 0) { result = result * 0x100000002C5C85FE31F35A6A30DA1BE50 >> 128; } if (x & 0x200000000 > 0) { result = result * 0x10000000162E42FF0999CE3541B9FFFCF >> 128; } if (x & 0x100000000 > 0) { result = result * 0x100000000B17217F80F4EF5AADDA45554 >> 128; } if (x & 0x80000000 > 0) { result = result * 0x10000000058B90BFBF8479BD5A81B51AD >> 128; } if (x & 0x40000000 > 0) { result = result * 0x1000000002C5C85FDF84BD62AE30A74CC >> 128; } if (x & 0x20000000 > 0) { result = result * 0x100000000162E42FEFB2FED257559BDAA >> 128; } if (x & 0x10000000 > 0) { result = result * 0x1000000000B17217F7D5A7716BBA4A9AE >> 128; } if (x & 0x8000000 > 0) { result = result * 0x100000000058B90BFBE9DDBAC5E109CCE >> 128; } if (x & 0x4000000 > 0) { result = result * 0x10000000002C5C85FDF4B15DE6F17EB0D >> 128; } if (x & 0x2000000 > 0) { result = result * 0x1000000000162E42FEFA494F1478FDE05 >> 128; } if (x & 0x1000000 > 0) { result = result * 0x10000000000B17217F7D20CF927C8E94C >> 128; } if (x & 0x800000 > 0) { result = result * 0x1000000000058B90BFBE8F71CB4E4B33D >> 128; } if (x & 0x400000 > 0) { result = result * 0x100000000002C5C85FDF477B662B26945 >> 128; } if (x & 0x200000 > 0) { result = result * 0x10000000000162E42FEFA3AE53369388C >> 128; } if (x & 0x100000 > 0) { result = result * 0x100000000000B17217F7D1D351A389D40 >> 128; } if (x & 0x80000 > 0) { result = result * 0x10000000000058B90BFBE8E8B2D3D4EDE >> 128; } if (x & 0x40000 > 0) { result = result * 0x1000000000002C5C85FDF4741BEA6E77E >> 128; } if (x & 0x20000 > 0) { result = result * 0x100000000000162E42FEFA39FE95583C2 >> 128; } if (x & 0x10000 > 0) { result = result * 0x1000000000000B17217F7D1CFB72B45E1 >> 128; } if (x & 0x8000 > 0) { result = result * 0x100000000000058B90BFBE8E7CC35C3F0 >> 128; } if (x & 0x4000 > 0) { result = result * 0x10000000000002C5C85FDF473E242EA38 >> 128; } if (x & 0x2000 > 0) { result = result * 0x1000000000000162E42FEFA39F02B772C >> 128; } if (x & 0x1000 > 0) { result = result * 0x10000000000000B17217F7D1CF7D83C1A >> 128; } if (x & 0x800 > 0) { result = result * 0x1000000000000058B90BFBE8E7BDCBE2E >> 128; } if (x & 0x400 > 0) { result = result * 0x100000000000002C5C85FDF473DEA871F >> 128; } if (x & 0x200 > 0) { result = result * 0x10000000000000162E42FEFA39EF44D91 >> 128; } if (x & 0x100 > 0) { result = result * 0x100000000000000B17217F7D1CF79E949 >> 128; } if (x & 0x80 > 0) { result = result * 0x10000000000000058B90BFBE8E7BCE544 >> 128; } if (x & 0x40 > 0) { result = result * 0x1000000000000002C5C85FDF473DE6ECA >> 128; } if (x & 0x20 > 0) { result = result * 0x100000000000000162E42FEFA39EF366F >> 128; } if (x & 0x10 > 0) { result = result * 0x1000000000000000B17217F7D1CF79AFA >> 128; } if (x & 0x8 > 0) { result = result * 0x100000000000000058B90BFBE8E7BCD6D >> 128; } if (x & 0x4 > 0) { result = result * 0x10000000000000002C5C85FDF473DE6B2 >> 128; } if (x & 0x2 > 0) { result = result * 0x1000000000000000162E42FEFA39EF358 >> 128; } if (x & 0x1 > 0) { result = result * 0x10000000000000000B17217F7D1CF79AB >> 128; } result >>= uint256(int256(63 - (x >> 64))); require(result <= uint256(int256(MAX_64x64))); return int128(int256(result)); } } /** * Calculate natural exponent of x. Revert on overflow. * * @param x signed 64.64-bit fixed point number * @return signed 64.64-bit fixed point number */ function exp(int128 x) internal pure returns (int128) { unchecked { require(x < 0x400000000000000000); // Overflow if (x < -0x400000000000000000) return 0; // Underflow return exp_2(int128(int256(x) * 0x171547652B82FE1777D0FFDA0D23A7D12 >> 128)); } } /** * Calculate x / y rounding towards zero, where x and y are unsigned 256-bit * integer numbers. Revert on overflow or when y is zero. * * @param x unsigned 256-bit integer number * @param y unsigned 256-bit integer number * @return unsigned 64.64-bit fixed point number */ function divuu(uint256 x, uint256 y) private pure returns (uint128) { unchecked { require(y != 0); uint256 result; if (x <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF) { result = (x << 64) / y; } else { uint256 msb = 192; uint256 xc = x >> 192; if (xc >= 0x100000000) { xc >>= 32; msb += 32; } if (xc >= 0x10000) { xc >>= 16; msb += 16; } if (xc >= 0x100) { xc >>= 8; msb += 8; } if (xc >= 0x10) { xc >>= 4; msb += 4; } if (xc >= 0x4) { xc >>= 2; msb += 2; } if (xc >= 0x2) msb += 1; // No need to shift xc anymore result = (x << 255 - msb) / ((y - 1 >> msb - 191) + 1); require(result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); uint256 hi = result * (y >> 128); uint256 lo = result * (y & 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); uint256 xh = x >> 192; uint256 xl = x << 64; if (xl < lo) xh -= 1; xl -= lo; // We rely on overflow behavior here lo = hi << 128; if (xl < lo) xh -= 1; xl -= lo; // We rely on overflow behavior here assert(xh == hi >> 128); result += xl / y; } require(result <= 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); return uint128(result); } } /** * Calculate sqrt (x) rounding down, where x is unsigned 256-bit integer * number. * * @param x unsigned 256-bit integer number * @return unsigned 128-bit integer number */ function sqrtu(uint256 x) private pure returns (uint128) { unchecked { if (x == 0) { return 0; } else { uint256 xx = x; uint256 r = 1; if (xx >= 0x100000000000000000000000000000000) { xx >>= 128; r <<= 64; } if (xx >= 0x10000000000000000) { xx >>= 64; r <<= 32; } if (xx >= 0x100000000) { xx >>= 32; r <<= 16; } if (xx >= 0x10000) { xx >>= 16; r <<= 8; } if (xx >= 0x100) { xx >>= 8; r <<= 4; } if (xx >= 0x10) { xx >>= 4; r <<= 2; } if (xx >= 0x8) r <<= 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; r = (r + x / r) >> 1; // Seven iterations should be enough uint256 r1 = x / r; return uint128(r < r1 ? r : r1); } } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.13; import "./IAssimilatorFactory.sol"; interface ICurveFactory { function getProtocolFee() external view returns (int128); function getProtocolTreasury() external view returns (address); function assimilatorFactory() external view returns (IAssimilatorFactory); function wETH() external view returns (address); function isDFXCurve(address) external view returns (bool); }
// SPDX-License-Identifier: MIT // 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.8.13; interface IOracle { function acceptOwnership() external; function accessController() external view returns (address); function aggregator() external view returns (address); function confirmAggregator(address _aggregator) external; function decimals() external view returns (uint8); function description() external view returns (string memory); function getAnswer(uint256 _roundId) external view returns (int256); function getRoundData(uint80 _roundId) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); function getTimestamp(uint256 _roundId) external view returns (uint256); function latestAnswer() external view returns (int256); function latestRound() external view returns (uint256); function latestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); function latestTimestamp() external view returns (uint256); function owner() external view returns (address); function phaseAggregators(uint16) external view returns (address); function phaseId() external view returns (uint16); function proposeAggregator(address _aggregator) external; function proposedAggregator() external view returns (address); function proposedGetRoundData(uint80 _roundId) external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); function proposedLatestRoundData() external view returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound); function setController(address _accessController) external; function transferOwnership(address _to) external; function version() external view returns (uint256); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require(address(this).balance >= amount, "Address: insufficient balance"); (bool success, ) = recipient.call{value: amount}(""); require(success, "Address: unable to send value, recipient may have reverted"); } /** * @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, it is bubbled up by this * function (like regular Solidity function calls). * * 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. * * _Available since v3.1._ */ function functionCall(address target, bytes memory data) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @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`. * * _Available since v3.1._ */ function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) { return functionDelegateCall(target, data, "Address: low-level delegate call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) 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(errorMessage); } } }
// SPDX-License-Identifier: MIT // 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.8.13; interface IAssimilator { function oracleDecimals() external view returns (uint256); function underlyingToken() external view returns (address); function getWeth() external view returns (address); function tokenDecimals() external view returns (uint256); function getRate() external view returns (uint256); function intakeRaw(uint256 amount) external payable returns (int128); function intakeRawAndGetBalance(uint256 amount) external payable returns (int128, int128); function intakeNumeraire(int128 amount) external payable returns (uint256); function intakeNumeraireLPRatio(uint256, uint256, uint256, uint256, uint256, uint256, address) external payable returns (uint256); function outputRaw(address dst, uint256 amount) external returns (int128); function outputRawAndGetBalance(address dst, uint256 amount) external returns (int128, int128); function outputNumeraire(address dst, int128 amount, bool toETH) external payable returns (uint256); function viewRawAmount(int128) external view returns (uint256); function viewRawAmountLPRatio(uint256, uint256, address, int128) external view returns (uint256); function viewNumeraireAmount(uint256) external view returns (int128); function viewNumeraireBalanceLPRatio(uint256, uint256, address) external view returns (int128); function viewNumeraireBalance(address) external view returns (int128); function viewNumeraireAmountAndBalance(address, uint256) external view returns (int128, int128); function transferFee(int128, address) external payable; }
// SPDX-License-Identifier: MIT // 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.8.13; import "../assimilators/AssimilatorV3.sol"; import "../interfaces/IOracle.sol"; interface IAssimilatorFactory { function getAssimilator(address _token, address _quote) external view returns (AssimilatorV3); function newAssimilator(address _quote, IOracle _oracle, address _token, uint256 _tokenDecimals) external returns (AssimilatorV3); }
// SPDX-License-Identifier: MIT // 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.8.13; import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol"; import "@openzeppelin/contracts/utils/math/SafeMath.sol"; import "@openzeppelin/contracts/utils/math/Math.sol"; import "../lib/ABDKMath64x64.sol"; import "../interfaces/IAssimilator.sol"; import "../interfaces/IOracle.sol"; import "../interfaces/IWeth.sol"; contract AssimilatorV3 is IAssimilator { using ABDKMath64x64 for int128; using ABDKMath64x64 for uint256; using SafeMath for uint256; using SafeERC20 for IERC20Metadata; IERC20Metadata public immutable pairToken; IOracle public immutable oracle; IERC20Metadata public immutable token; uint256 public immutable oracleDecimals; uint256 public immutable tokenDecimals; uint256 public immutable pairTokenDecimals; address public immutable wETH; // solhint-disable-next-line constructor( address _wETH, address _pairToken, IOracle _oracle, address _token, uint256 _tokenDecimals, uint256 _oracleDecimals ) { wETH = _wETH; oracle = _oracle; token = IERC20Metadata(_token); oracleDecimals = _oracleDecimals; tokenDecimals = _tokenDecimals; pairToken = IERC20Metadata(_pairToken); pairTokenDecimals = pairToken.decimals(); } function underlyingToken() external view override returns (address) { return address(token); } function getWeth() external view override returns (address) { return wETH; } function getRate() public view override returns (uint256) { (, int256 price,,,) = oracle.latestRoundData(); require(price >= 0, "invalid price oracle"); return uint256(price); } // takes raw eurs amount, transfers it in, calculates corresponding numeraire amount and returns it function intakeRawAndGetBalance(uint256 _amount) external payable override returns (int128 amount_, int128 balance_) { require(_amount > 0, "zero amount!"); uint256 balanceBefore = token.balanceOf(address(this)); token.safeTransferFrom(msg.sender, address(this), _amount); uint256 balanceAfter = token.balanceOf(address(this)); uint256 diff = _amount - (balanceAfter - balanceBefore); if (diff > 0) { intakeMoreFromFoT(_amount, diff); } uint256 _balance = token.balanceOf(address(this)); uint256 _rate = getRate(); balance_ = ((_balance * _rate) / 10 ** oracleDecimals).divu(10 ** tokenDecimals); amount_ = ((_amount * _rate) / 10 ** oracleDecimals).divu(10 ** tokenDecimals); } // takes raw eurs amount, transfers it in, calculates corresponding numeraire amount and returns it function intakeRaw(uint256 _amount) external payable override returns (int128 amount_) { require(_amount > 0, "zero amount!"); uint256 balanceBefore = token.balanceOf(address(this)); token.safeTransferFrom(msg.sender, address(this), _amount); uint256 balanceAfter = token.balanceOf(address(this)); uint256 diff = _amount - (balanceAfter - balanceBefore); if (diff > 0) { intakeMoreFromFoT(_amount, diff); } uint256 _rate = getRate(); amount_ = ((_amount * _rate) / 10 ** oracleDecimals).divu(10 ** tokenDecimals); } // takes a numeraire amount, calculates the raw amount of eurs, tr ansfers it in and returns the corresponding raw amount function intakeNumeraire(int128 _amount) external payable override returns (uint256 amount_) { uint256 _rate = getRate(); // improve precision amount_ = Math.ceilDiv(_amount.mulu(10 ** (tokenDecimals + oracleDecimals + 18)), _rate * 1e18); require(amount_ > 0, "zero amount!"); uint256 balanceBefore = token.balanceOf(address(this)); token.safeTransferFrom(msg.sender, address(this), amount_); uint256 balanceAfter = token.balanceOf(address(this)); uint256 diff = amount_ - (balanceAfter - balanceBefore); if (diff > 0) intakeMoreFromFoT(amount_, diff); } // takes a numeraire amount, calculates the raw amount of eurs, transfers it in and returns the corresponding raw amount function intakeNumeraireLPRatio( uint256 _minBaseAmount, uint256 _maxBaseAmount, uint256 _baseAmount, uint256 _minpairTokenAmount, uint256 _maxpairTokenAmount, uint256 _quoteAmount, address token0 ) external payable override returns (uint256 amount_) { if (token0 == address(token)) { amount_ = _baseAmount; } else { amount_ = _quoteAmount; } require(amount_ > 0, "zero amount!"); if (token0 == address(token)) { require(amount_ > _minBaseAmount && amount_ <= _maxBaseAmount, "Assimilator/LP Ratio imbalanced!"); } else { require(amount_ > _minpairTokenAmount && amount_ <= _maxpairTokenAmount, "Assimilator/LP Ratio imbalanced!"); } uint256 balanceBefore = token.balanceOf(address(this)); token.safeTransferFrom(msg.sender, address(this), amount_); uint256 balanceAfter = token.balanceOf(address(this)); uint256 diff = amount_ - (balanceAfter - balanceBefore); if (diff > 0) intakeMoreFromFoT(amount_, diff); } function intakeMoreFromFoT(uint256 amount_, uint256 diff) internal { require(amount_ > 0, "zero amount!"); // handle FoT token uint256 feePercentage = diff.mul(1e5).div(amount_).add(1); uint256 additionalIntakeAmt = (diff * 1e5) / (1e5 - feePercentage); token.safeTransferFrom(msg.sender, address(this), additionalIntakeAmt); } // takes a raw amount of eurs and transfers it out, returns numeraire value of the raw amount function outputRawAndGetBalance(address _dst, uint256 _amount) external override returns (int128 amount_, int128 balance_) { require(_amount > 0, "zero amount!"); uint256 _rate = getRate(); token.safeTransfer(_dst, _amount); uint256 _balance = token.balanceOf(address(this)); amount_ = ((_amount * _rate)).divu(10 ** (tokenDecimals + oracleDecimals)); balance_ = ((_balance * _rate)).divu(10 ** (tokenDecimals + oracleDecimals)); } // takes a raw amount of eurs and transfers it out, returns numeraire value of the raw amount function outputRaw(address _dst, uint256 _amount) external override returns (int128 amount_) { require(_amount > 0, "zero amount!"); uint256 _rate = getRate(); token.safeTransfer(_dst, _amount); amount_ = ((_amount * _rate)).divu(10 ** (tokenDecimals + oracleDecimals)); } // takes a numeraire value of eurs, figures out the raw amount, transfers raw amount out, and returns raw amount function outputNumeraire(address _dst, int128 _amount, bool _toETH) external payable override returns (uint256 amount_) { uint256 _rate = getRate(); amount_ = Math.ceilDiv(_amount.mulu(10 ** (tokenDecimals + oracleDecimals + 18)), _rate * 1e18); require(amount_ > 0, "zero amount!"); if (_toETH) { IWETH(wETH).withdraw(amount_); (bool success,) = payable(_dst).call{value: amount_}(""); require(success, "Assimilator/Transfer ETH Failed"); } else { token.safeTransfer(_dst, amount_); } } // takes a numeraire amount and returns the raw amount function viewRawAmount(int128 _amount) external view override returns (uint256 amount_) { uint256 _rate = getRate(); // improve precision amount_ = Math.ceilDiv(_amount.mulu(10 ** (tokenDecimals + oracleDecimals + 18)), _rate * 1e18); } function viewRawAmountLPRatio(uint256 _baseWeight, uint256 _pairTokenWeight, address _addr, int128 _amount) external view override returns (uint256 amount_) { uint256 _tokenBal = token.balanceOf(_addr); if (_tokenBal <= 0) return 0; _tokenBal = _tokenBal.mul(10 ** (18 + pairTokenDecimals)).div(_baseWeight); uint256 _pairTokenBal = pairToken.balanceOf(_addr).mul(10 ** (18 + tokenDecimals)).div(_pairTokenWeight); // Rate is in pair token decimals uint256 _rate = _pairTokenBal.mul(1e6).div(_tokenBal); amount_ = Math.ceilDiv(_amount.mulu(10 ** tokenDecimals * 1e6 * 1e18), _rate * 1e18); } // takes a raw amount and returns the numeraire amount function viewNumeraireAmount(uint256 _amount) external view override returns (int128 amount_) { uint256 _rate = getRate(); amount_ = ((_amount * _rate) / 10 ** oracleDecimals).divu(10 ** tokenDecimals); } // views the numeraire value of the current balance of the reserve, in this case eurs function viewNumeraireBalance(address _addr) external view override returns (int128 balance_) { uint256 _rate = getRate(); uint256 _balance = token.balanceOf(_addr); if (_balance <= 0) return ABDKMath64x64.fromUInt(0); balance_ = ((_balance * _rate) / 10 ** oracleDecimals).divu(10 ** tokenDecimals); } // views the numeraire value of the current balance of the reserve, in this case eurs function viewNumeraireAmountAndBalance(address _addr, uint256 _amount) external view override returns (int128 amount_, int128 balance_) { uint256 _rate = getRate(); amount_ = ((_amount * _rate) / 10 ** oracleDecimals).divu(10 ** tokenDecimals); uint256 _balance = token.balanceOf(_addr); balance_ = ((_balance * _rate) / 10 ** oracleDecimals).divu(10 ** tokenDecimals); } // views the numeraire value of the current balance of the reserve, in this case eurs // instead of calculating with chainlink's "rate" it'll be determined by the existing // token ratio. This is in here to prevent LPs from losing out on future oracle price updates function viewNumeraireBalanceLPRatio(uint256 _baseWeight, uint256 _pairTokenWeight, address _addr) external view override returns (int128 balance_) { uint256 _tokenBal = token.balanceOf(_addr); if (_tokenBal <= 0) return ABDKMath64x64.fromUInt(0); uint256 _pairTokenBal = pairToken.balanceOf(_addr).mul(1e18).div(_pairTokenWeight); // Rate is in 1e6 uint256 _rate = _pairTokenBal.mul(1e18).div(_tokenBal.mul(1e18).div(_baseWeight)); balance_ = ((_tokenBal * _rate) / 10 ** pairTokenDecimals).divu(1e18); } function transferFee(int128 _amount, address _treasury) external payable override { uint256 _rate = getRate(); if (_amount < 0) _amount = -(_amount); uint256 amount = _amount.mulu(10 ** (tokenDecimals + oracleDecimals + 18)) / (_rate * 1e18); token.safeTransfer(_treasury, amount); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; import "../extensions/IERC20Permit.sol"; import "../../../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; function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value)); } function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal { _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value)); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove(IERC20 token, address spender, uint256 value) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value)); } function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal { uint256 newAllowance = token.allowance(address(this), spender) + value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require(oldAllowance >= value, "SafeERC20: decreased allowance below zero"); uint256 newAllowance = oldAllowance - value; _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance)); } } function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed"); } /** * @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, "SafeERC20: low-level call failed"); if (returndata.length > 0) { // Return data is optional require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed"); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ 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: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @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 up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (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; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 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. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); 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 (rounding == Rounding.Up && 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 down. * * 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 + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * 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 + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * 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 + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * 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 + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.13; interface IWETH { function deposit() external payable; function transfer(address to, uint256 value) external returns (bool); function withdraw(uint256) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @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. */ 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]. */ 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); }
{ "remappings": [ "@openzeppelin/=lib/openzeppelin-contracts/", "@forge-std/=lib/forge-std/src/", "ds-test/=lib/forge-std/lib/ds-test/src/", "forge-std/=lib/forge-std/src/", "openzeppelin-contracts/=lib/openzeppelin-contracts/" ], "optimizer": { "enabled": true, "runs": 200 }, "metadata": { "useLiteralContent": false, "bytecodeHash": "ipfs", "appendCBOR": true }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "evmVersion": "paris", "libraries": { "src/Curve.sol": { "Curves": "0xeb60919ac3b66d2fee0d53bf4cdd6a5f9a91a077" }, "src/Orchestrator.sol": { "Orchestrator": "0x11654bb1e4bc79894e4447545af6c1630b56921f" }, "src/ProportionalLiquidity.sol": { "ProportionalLiquidity": "0x3a2f9e9cdc6791c52dbb79dd271bd02817082379" }, "src/Swaps.sol": { "Swaps": "0xa49bf76606a82e75b9d6769ced0aa1b4cd8e5ecd" }, "src/ViewLiquidity.sol": { "ViewLiquidity": "0xd6af8d8bf04104f9b0f9f20b863e60d8f9b3e6f0" } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"trader","type":"address"},{"indexed":true,"internalType":"address","name":"origin","type":"address"},{"indexed":true,"internalType":"address","name":"target","type":"address"},{"indexed":false,"internalType":"uint256","name":"originAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"targetAmount","type":"uint256"},{"indexed":false,"internalType":"int128","name":"rawProtocolFee","type":"int128"}],"name":"Trade","type":"event"},{"inputs":[],"name":"ONE","outputs":[{"internalType":"int128","name":"","type":"int128"}],"stateMutability":"view","type":"function"}]
Contract Creation Code
612bc961003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600436106100615760003560e01c806356fa0ba414610066578063931c544a1461008c578063c2ee3a08146100ac578063fb7455da146100ca578063fd17568b146100dd575b600080fd5b6100796100743660046127fd565b6100fd565b6040519081526020015b60405180910390f35b81801561009857600080fd5b506100796100a73660046128f7565b6101df565b6100b7600160401b81565b604051600f9190910b8152602001610083565b6100796100d83660046127fd565b610570565b8180156100e957600080fd5b506100796100f8366004612924565b61062d565b600080600061010d8787876109b2565b91509150806020015160ff16826020015160ff1603610147578151815161013e91906101399087610af2565b610b5e565b925050506101d7565b600080600080600061016e8c876020015160ff16896020015160ff168c8a60000151610bcd565b9450945094509450945061018e8c858584868a8d6020015160ff16610e43565b60018d01549095506101bd906101b290600160801b9004600f0b600160401b612980565b600f87900b906110e5565b94506101cd876000015186610b5e565b9750505050505050505b949350505050565b60008060006101f785856000015186602001516109b2565b9150915083602001516001600160a01b031684600001516001600160a01b0316036102635760405162461bcd60e51b81526020600482015260176024820152761cddd85c0bdcd85b594b5bdc9a59da5b8b5d185c99d95d604a1b60448201526064015b60405180910390fd5b806020015160ff16826020015160ff16036102a55761029c8260000151610297836000015187606001518860400151611106565b611184565b9250505061056a565b60008060008060006102d58a876020015160ff16896020015160ff1689600001518d606001518e604001516111e1565b945094509450945094506102f58a858585858a8d6020015160ff16610e43565b94506103366040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c081019190915290565b600f86810b825260808b01516001600160a01b031660c083015260018c015461037b9161037091600160801b9004900b600160401b612980565b600f88900b906110e5565b600f0b604082018190526103909087906129ad565b8160200190600f0b9081600f0b815250508060c001516001600160a01b031663a5a410316040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103e3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061040791906129ec565b8160800190600f0b9081600f0b815250508060c001516001600160a01b0316639611f3d96040518163ffffffff1660e01b8152600401602060405180830381865afa15801561045a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061047e9190612a07565b6001600160a01b031660a0820152608081015160208201516104b591620186a0916104af91600f91820b910b6114b9565b90611575565b600f0b60608201819052885160a08301516104d092906115f6565b6104e288600001518260400151611184565b985089602001516001600160a01b03168a600001516001600160a01b0316336001600160a01b03167f887adc1b38cfb756ed025ea6acd9382fbd376ede6c34bc6fa738284b092754688c8e604001518660600151604051610559939291909283526020830191909152600f0b604082015260600190565b60405180910390a450505050505050505b92915050565b60008060006105808787876109b2565b91509150806020015160ff16826020015160ff16036105ac578051825161013e91906101399087610af2565b60008060008060006105d38c886020015160ff16886020015160ff168c8b60000151611654565b945094509450945094506105f38c858584868a8c6020015160ff16610e43565b60018d0154909550610617906101b290600160801b9004600f0b600160401b6129ad565b94506101cd866000015161013987600f0b611838565b600080600061064586866000015187602001516109b2565b9150915084602001516001600160a01b031685600001516001600160a01b0316036106ac5760405162461bcd60e51b81526020600482015260176024820152761cddd85c0bdcd85b594b5bdc9a59da5b8b5d185c99d95d604a1b604482015260640161025a565b806020015160ff16826020015160ff16036106ef576106e6816000015186606001516106e085600001518960400151611866565b876118d5565b925050506109ab565b6040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c081019190915260008060008060006107538c896020015160ff16896020015160ff168b600001518f6040015161196f565b94509450945094509450848660000190600f0b9081600f0b815250506107858c858585858a8d6020015160ff16610e43565b60808c01516001600160a01b031660c088015260018d01549095506107bc906101b290600160801b9004600f0b600160401b6129ad565b600f0b604087018190526107d19086906129ad565b8660200190600f0b9081600f0b815250508560c001516001600160a01b031663a5a410316040518163ffffffff1660e01b8152600401602060405180830381865afa158015610824573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061084891906129ec565b8660800190600f0b9081600f0b815250508560c001516001600160a01b0316639611f3d96040518163ffffffff1660e01b8152600401602060405180830381865afa15801561089b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108bf9190612a07565b6001600160a01b031660a0870152608086015160208701516108f091620186a0916104af91600f91820b910b6114b9565b600f0b60608701819052875160a088015161090b92906115f6565b61092387600001518c6060015188604001518d6118d5565b98508a602001516001600160a01b03168b600001516001600160a01b0316336001600160a01b03167f887adc1b38cfb756ed025ea6acd9382fbd376ede6c34bc6fa738284b092754688e604001518d8b6060015160405161099a939291909283526020830191909152600f0b604082015260600190565b60405180910390a450505050505050505b9392505050565b604080518082019091526000808252602082015260408051808201909152600080825260208201526001600160a01b0380851660009081526005870160208181526040808420815180830183529054808716825260ff600160a01b918290048116838601528a88168752948452948290208251808401909352548087168352949094049092169082015281519192909116610a8f5760405162461bcd60e51b815260206004820152601a60248201527f43757276652f6f726967696e2d6e6f742d737570706f72746564000000000000604482015260640161025a565b80516001600160a01b0316610ae65760405162461bcd60e51b815260206004820152601a60248201527f43757276652f7461726765742d6e6f742d737570706f72746564000000000000604482015260640161025a565b90969095509350505050565b604051637af3606560e11b8152600481018290526000906001600160a01b0384169063f5e6c0ca90602401602060405180830381865afa158015610b3a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109ab91906129ec565b604051636b677a8f60e01b8152600f82900b60048201526000906001600160a01b03841690636b677a8f90602401602060405180830381865afa158015610ba9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109ab9190612a24565b6004850154600090819081906060908190838167ffffffffffffffff811115610bf857610bf8612845565b604051908082528060200260200182016040528015610c21578160200160208202803683370190505b50905060008267ffffffffffffffff811115610c3f57610c3f612845565b604051908082528060200260200182016040528015610c68578160200160208202803683370190505b50905060005b83811015610dd7578c8114610cff57610caf8e6004018281548110610c9557610c95612a3d565b6000918252602090912001546001600160a01b0316611c26565b828281518110610cc157610cc1612a3d565b6020026020010190600f0b9081600f0b815250838281518110610ce657610ce6612a3d565b6020026020010190600f0b9081600f0b81525050610d77565b6000610d0b8b8d611c91565b909a509050610d1d600f8b900b611d0f565b995080838381518110610d3257610d32612a3d565b600f92830b6020918202929092010152610d4f9082900b8b611d25565b848381518110610d6157610d61612a3d565b6020026020010190600f0b9081600f0b81525050505b818181518110610d8957610d89612a3d565b602002602001015188610d9c9190612980565b9750828181518110610db057610db0612a3d565b602002602001015187610dc39190612980565b965080610dcf81612a53565b915050610c6e565b50610de6600f87900b89611d59565b9550610e0b828c81518110610dfd57610dfd612a3d565b602002602001015189611d59565b828c81518110610e1d57610e1d612a3d565b600f9290920b602092830291909101909101529093509150509550955095509550959050565b6000610e4e83612a6c565b600289015460038a01805460408051602080840282018101909252828152949550600f9390930b9360009390929190830182828015610ecf57602002820191906000526020600020906000905b825461010083900a9004600f0b81526020601f8301819004938401936001036010909301929092029101808411610e9b5790505b505050505090506000610ee48a898d85611d8c565b90506000805b602081101561109157610eff8b8a8f87611d8c565b915085600f83810b9085900b12610f4057610f28610f1d84866129ad565b600f88900b90611db2565b610f32908a612980565b610f3b90612a6c565b610f5e565b82610f4b858b612980565b610f5591906129ad565b610f5e90612a6c565b9650610f706509184e72a00082612aa8565b600f0b610f836509184e72a00089612aa8565b600f0b036110125786610f968a8f612980565b610fa09190612980565b9b50868b8981518110610fb557610fb5612a3d565b6020026020010151610fc79190612980565b8a8981518110610fd957610fd9612a3d565b6020026020010190600f0b9081600f0b81525050610ffb8e8e8e8e8e8a611de8565b6110078d858e86612183565b5050505050506110da565b8661101d8a8f612980565b6110279190612980565b9b50611058878c8a8151811061103f5761103f612a3d565b6020026020010151600f0b611d2590919063ffffffff16565b8a898151811061106a5761106a612a3d565b6020026020010190600f0b9081600f0b81525050508061108981612a53565b915050610eea565b5060405162461bcd60e51b815260206004820152601d60248201527f43757276652f737761702d636f6e76657267656e63652d6661696c6564000000604482015260640161025a565b979650505050505050565b600080604083600f0b85600f0b6110fc9190612af4565b901d949350505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663f09a3fc360e01b17905260009061115a858261221f565b80602001905181019061116d91906129ec565b915061117b82600f0b611d0f565b95945050505050565b60408051600f83900b6024808301919091528251808303909101815260449091019091526020810180516001600160e01b0316624e387960e31b1790526000906111ce848261221f565b8060200190518101906101d79190612a24565b6004860154600090819081906060908190838167ffffffffffffffff81111561120c5761120c612845565b604051908082528060200260200182016040528015611235578160200160208202803683370190505b50905060008267ffffffffffffffff81111561125357611253612845565b60405190808252806020026020018201604052801561127c578160200160208202803683370190505b50905060008e600401805480602002602001604051908101604052809291908181526020016000905b828210156112ee57600084815260209081902060408051808201909152908401546001600160a01b0381168252600160a01b900460ff16818301528252600190920191016112a5565b50505050905060005b8481101561144b578e811461137c5761132c82828151811061131b5761131b612a3d565b602002602001015160000151611c26565b84828151811061133e5761133e612a3d565b6020026020010190600f0b9081600f0b81525083828151811061136357611363612a3d565b6020026020010190600f0b9081600f0b815250506113eb565b60006113898e8e8e6122f3565b909b50905061139c600f82900b8c611d59565b8583815181106113ae576113ae612a3d565b6020026020010190600f0b9081600f0b81525050808483815181106113d5576113d5612a3d565b6020026020010190600f0b9081600f0b81525050505b8381815181106113fd576113fd612a3d565b6020026020010151896114109190612980565b985082818151811061142457611424612a3d565b6020026020010151886114379190612980565b97508061144381612a53565b9150506112f7565b5061145a600f88900b8a611d59565b965061147f828e8151811061147157611471612a3d565b60200260200101518a611d59565b828e8151811061149157611491612a3d565b600f9290920b6020928302919091019091015250909350915050965096509650965096915050565b60006001607f1b600f84900b016114fd576002600160c01b031982121580156114e65750600160c01b8213155b6114ef57600080fd5b506000819003603f1b61056a565b60008084600f0b121561151557836000039350600190505b60008312156115275760009290920391155b60006115338585612379565b9050811561155857600160ff1b81111561154c57600080fd5b600003915061056a9050565b6001600160ff1b0381111561156c57600080fd5b915061056a9050565b60008160000361158457600080fd5b60008084121561159957836000039350600190505b60008312156115ab5760009290920391155b60006115b785856123e4565b905081156115d9576001607f1b816001600160801b0316111561154c57600080fd5b60016001607f1b03816001600160801b0316111561156c57600080fd5b60408051600f84900b60248201526001600160a01b0383166044808301919091528251808303909101815260649091019091526020810180516001600160e01b03166322cead0360e11b17905261164d848261221f565b5050505050565b6004850154600090819081906060908190838167ffffffffffffffff81111561167f5761167f612845565b6040519080825280602002602001820160405280156116a8578160200160208202803683370190505b50905060008267ffffffffffffffff8111156116c6576116c6612845565b6040519080825280602002602001820160405280156116ef578160200160208202803683370190505b50905060005b83811015610dd7578c811461176c5761171c8e6004018281548110610c9557610c95612a3d565b82828151811061172e5761172e612a3d565b6020026020010190600f0b9081600f0b81525083828151811061175357611753612a3d565b6020026020010190600f0b9081600f0b815250506117d8565b60006117788b8d611c91565b809250819b5050508083838151811061179357611793612a3d565b600f92830b60209182029290920101526117b09082900b8b611d25565b8483815181106117c2576117c2612a3d565b6020026020010190600f0b9081600f0b81525050505b8181815181106117ea576117ea612a3d565b6020026020010151886117fd9190612980565b975082818151811061181157611811612a3d565b6020026020010151876118249190612980565b96508061183081612a53565b9150506116f5565b60006001607f1b600f83900b0161184e57600080fd5b600082600f0b1261185f578161056a565b5060000390565b60008063fa00102a60e01b8360405160240161188491815260200190565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290506118c2848261221f565b8060200190518101906101d791906129ec565b600080630c374e5d60e11b856118ee600f87900b611838565b6040516001600160a01b039092166024830152600f0b6044820152841515606482015260840160408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091529050611952868261221f565b8060200190518101906119659190612a24565b9695505050505050565b6004850154600090819081906060908190838167ffffffffffffffff81111561199a5761199a612845565b6040519080825280602002602001820160405280156119c3578160200160208202803683370190505b50905060008267ffffffffffffffff8111156119e1576119e1612845565b604051908082528060200260200182016040528015611a0a578160200160208202803683370190505b50905060008d600401805480602002602001604051908101604052809291908181526020016000905b82821015611a7c57600084815260209081902060408051808201909152908401546001600160a01b0381168252600160a01b900460ff1681830152825260019092019101611a33565b50505050905060005b84811015611bc7578d8114611af957611aa982828151811061131b5761131b612a3d565b848281518110611abb57611abb612a3d565b6020026020010190600f0b9081600f0b815250838281518110611ae057611ae0612a3d565b6020026020010190600f0b9081600f0b81525050611b67565b6000611b058d8d612549565b909b509050611b18600f82900b8c611d59565b858381518110611b2a57611b2a612a3d565b6020026020010190600f0b9081600f0b8152505080848381518110611b5157611b51612a3d565b6020026020010190600f0b9081600f0b81525050505b838181518110611b7957611b79612a3d565b602002602001015189611b8c9190612980565b9850828181518110611ba057611ba0612a3d565b602002602001015188611bb39190612980565b975080611bbf81612a53565b915050611a85565b50611bd6600f88900b8a611d59565b9650611bed828d8151811061147157611471612a3d565b828d81518110611bff57611bff612a3d565b600f9290920b60209283029190910190910152509093509150509550955095509550959050565b60405163ac969a7360e01b81523060048201526000906001600160a01b0383169063ac969a7390602401602060405180830381865afa158015611c6d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061056a91906129ec565b604051630f4d965d60e11b81523060048201526024810182905260009081906001600160a01b03851690631e9b2cba906044016040805180830381865afa158015611ce0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d049190612b24565b909590945092505050565b60006001607f1b600f83900b0161185f57600080fd5b6000600f83810b9083900b0160016001607f1b03198112801590611d50575060016001607f1b038113155b6109ab57600080fd5b6000600f82810b9084900b0360016001607f1b03198112801590611d50575060016001607f1b038113156109ab57600080fd5b81546001830154600091600160801b9004600f90810b91900b6110da87878484886125ba565b6000600f83810b9083900b0260401d60016001607f1b03198112801590611d50575060016001607f1b038113156109ab57600080fd5b81518654600f0b60005b82811015612178576000611e2b858381518110611e1157611e11612a3d565b602002602001015189600f0b611db290919063ffffffff16565b905080600f0b868381518110611e4357611e43612a3d565b6020026020010151600f0b1315611fdf576000611e6484600160401b612980565b90506000611e76600f84900b83611db2565b905080600f0b888581518110611e8e57611e8e612a3d565b6020026020010151600f0b1315611fd8576000611edd83611ed48a8881518110611eba57611eba612a3d565b60200260200101518f600f0b611db290919063ffffffff16565b600f0b90611db2565b905080600f0b8a8681518110611ef557611ef5612a3d565b6020026020010151600f0b1215611f435760405162461bcd60e51b815260206004820152601260248201527143757276652f75707065722d68616c742d3160701b604482015260640161025a565b808a8681518110611f5657611f56612a3d565b6020026020010151611f6891906129ad565b600f0b828a8781518110611f7e57611f7e612a3d565b6020026020010151611f9091906129ad565b600f0b1315611fd65760405162461bcd60e51b815260206004820152601260248201527121bab93b3297bab83832b916b430b63a169960711b604482015260640161025a565b505b5050612165565b6000611fef84600160401b6129ad565b90506000612001600f84900b83611db2565b905080600f0b88858151811061201957612019612a3d565b6020026020010151600f0b121561216257600061205b88868151811061204157612041612a3d565b60200260200101518d600f0b611db290919063ffffffff16565b905061206b600f82900b84611db2565b905080600f0b8a868151811061208357612083612a3d565b6020026020010151600f0b13156120cf5760405162461bcd60e51b815260206004820152601060248201526f10dd5c9d994bdb1bddd95c8b5a185b1d60821b604482015260640161025a565b8985815181106120e1576120e1612a3d565b6020026020010151816120f491906129ad565b600f0b89868151811061210957612109612a3d565b60200260200101518361211c91906129ad565b600f0b13156121605760405162461bcd60e51b815260206004820152601060248201526f10dd5c9d994bdb1bddd95c8b5a185b1d60821b604482015260640161025a565b505b50505b508061217081612a53565b915050611df2565b505050505050505050565b600061218f82846129ad565b9050600061219d85876129ad565b905060006121ab82846129ad565b905080600f0b600012806121ca57506510c6f7a0b5ed19600f82900b12155b6122165760405162461bcd60e51b815260206004820152601e60248201527f43757276652f737761702d696e76617269616e742d76696f6c6174696f6e0000604482015260640161025a565b50505050505050565b60606001600160a01b0383163b6122865760405162461bcd60e51b815260206004820152602560248201527f417373696d696c61746f72732f63616c6c65652d69732d6e6f742d612d636f6e6044820152641d1c9858dd60da1b606482015260840161025a565b600080846001600160a01b0316846040516122a19190612b4e565b600060405180830381855af49150503d80600081146122dc576040519150601f19603f3d011682016040523d82523d6000602084013e6122e1565b606091505b509092509050816101d7573d60208201fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663523bf25760e01b1790526000908190612349868261221f565b80602001905181019061235c9190612b24565b909350915061236e600f84900b611d0f565b925050935093915050565b60008160000361238b5750600061056a565b600083600f0b121561239c57600080fd5b600f83900b6001600160801b038316810260401c90608084901c026001600160c01b038111156123cb57600080fd5b60401b81198111156123dc57600080fd5b019392505050565b6000816000036123f357600080fd5b60006001600160c01b03841161241e5782604085901b8161241657612416612a92565b049050612535565b60c084811c6401000000008110612437576020918201911c5b620100008110612449576010918201911c5b610100811061245a576008918201911c5b6010811061246a576004918201911c5b6004811061247a576002918201911c5b60028110612489576001820191505b60bf820360018603901c6001018260ff0387901b816124aa576124aa612a92565b0492506001600160801b038311156124c157600080fd5b608085901c83026001600160801b038616840260c088901c604089901b828110156124ed576001820391505b608084901b92900382811015612504576001820391505b829003608084901c821461251a5761251a612b7d565b88818161252957612529612a92565b04870196505050505050505b6001600160801b038111156109ab57600080fd5b6000806000637f328ecc60e01b8460405160240161256991815260200190565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290506125a7858261221f565b806020019051810190610ae69190612b24565b8351600090815b818110156126415760006125fa8583815181106125e0576125e0612a3d565b60200260200101518a600f0b611db290919063ffffffff16565b905061262188838151811061261157612611612a3d565b602002602001015182898961264c565b61262b9085612980565b935050808061263990612a53565b9150506125c1565b505095945050505050565b600083600f0b85600f0b12156126f157600061267a61266f85600160401b6129ad565b600f87900b90611db2565b905080600f0b86600f0b12156126e657600061269687836129ad565b90506126a6600f82900b85611db2565b92506126b6600f84900b8761277e565b92506001603e1b600f84900b13156126d0576001603e1b92505b6126de600f84900b82611db2565b9250506126eb565b600091505b506101d7565b600061270461266f85600160401b612980565b905080600f0b86600f0b131561277057600061272082886129ad565b9050612730600f82900b85611db2565b9250612740600f84900b8761277e565b92506001603e1b600f84900b131561275a576001603e1b92505b612768600f84900b82611db2565b925050612775565b600091505b50949350505050565b600081600f0b60000361279057600080fd5b600082600f0b604085600f0b901b816127ab576127ab612a92565b05905060016001607f1b03198112801590611d50575060016001607f1b038113156109ab57600080fd5b6001600160a01b03811681146127ea57600080fd5b50565b80356127f8816127d5565b919050565b6000806000806080858703121561281357600080fd5b843593506020850135612825816127d5565b92506040850135612835816127d5565b9396929550929360600135925050565b634e487b7160e01b600052604160045260246000fd5b600060a0828403121561286d57600080fd5b60405160a0810181811067ffffffffffffffff8211171561289e57634e487b7160e01b600052604160045260246000fd5b60405290508082356128af816127d5565b815260208301356128bf816127d5565b6020820152604083810135908201526128da606084016127ed565b60608201526128eb608084016127ed565b60808201525092915050565b60008060c0838503121561290a57600080fd5b8235915061291b846020850161285b565b90509250929050565b600080600060e0848603121561293957600080fd5b8335925061294a856020860161285b565b915060c0840135801515811461295f57600080fd5b809150509250925092565b634e487b7160e01b600052601160045260246000fd5b600f81810b9083900b0160016001607f1b03811360016001607f1b03198212171561056a5761056a61296a565b600f82810b9082900b0360016001607f1b0319811260016001607f1b038213171561056a5761056a61296a565b8051600f81900b81146127f857600080fd5b6000602082840312156129fe57600080fd5b6109ab826129da565b600060208284031215612a1957600080fd5b81516109ab816127d5565b600060208284031215612a3657600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b600060018201612a6557612a6561296a565b5060010190565b600081600f0b60016001607f1b03198103612a8957612a8961296a565b60000392915050565b634e487b7160e01b600052601260045260246000fd5b600081600f0b83600f0b80612acd57634e487b7160e01b600052601260045260246000fd5b60016001607f1b0319821460001982141615612aeb57612aeb61296a565b90059392505050565b80820260008212600160ff1b84141615612b1057612b1061296a565b818105831482151761056a5761056a61296a565b60008060408385031215612b3757600080fd5b612b40836129da565b915061291b602084016129da565b6000825160005b81811015612b6f5760208186018101518583015201612b55565b506000920191825250919050565b634e487b7160e01b600052600160045260246000fdfea2646970667358221220d30cb12b2d94aa834e84ef4dc32292b3d4d0af89578a9edcf0ce59b0463d07e064736f6c63430008150033
Deployed Bytecode
0x73a49bf76606a82e75b9d6769ced0aa1b4cd8e5ecd30146080604052600436106100615760003560e01c806356fa0ba414610066578063931c544a1461008c578063c2ee3a08146100ac578063fb7455da146100ca578063fd17568b146100dd575b600080fd5b6100796100743660046127fd565b6100fd565b6040519081526020015b60405180910390f35b81801561009857600080fd5b506100796100a73660046128f7565b6101df565b6100b7600160401b81565b604051600f9190910b8152602001610083565b6100796100d83660046127fd565b610570565b8180156100e957600080fd5b506100796100f8366004612924565b61062d565b600080600061010d8787876109b2565b91509150806020015160ff16826020015160ff1603610147578151815161013e91906101399087610af2565b610b5e565b925050506101d7565b600080600080600061016e8c876020015160ff16896020015160ff168c8a60000151610bcd565b9450945094509450945061018e8c858584868a8d6020015160ff16610e43565b60018d01549095506101bd906101b290600160801b9004600f0b600160401b612980565b600f87900b906110e5565b94506101cd876000015186610b5e565b9750505050505050505b949350505050565b60008060006101f785856000015186602001516109b2565b9150915083602001516001600160a01b031684600001516001600160a01b0316036102635760405162461bcd60e51b81526020600482015260176024820152761cddd85c0bdcd85b594b5bdc9a59da5b8b5d185c99d95d604a1b60448201526064015b60405180910390fd5b806020015160ff16826020015160ff16036102a55761029c8260000151610297836000015187606001518860400151611106565b611184565b9250505061056a565b60008060008060006102d58a876020015160ff16896020015160ff1689600001518d606001518e604001516111e1565b945094509450945094506102f58a858585858a8d6020015160ff16610e43565b94506103366040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c081019190915290565b600f86810b825260808b01516001600160a01b031660c083015260018c015461037b9161037091600160801b9004900b600160401b612980565b600f88900b906110e5565b600f0b604082018190526103909087906129ad565b8160200190600f0b9081600f0b815250508060c001516001600160a01b031663a5a410316040518163ffffffff1660e01b8152600401602060405180830381865afa1580156103e3573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061040791906129ec565b8160800190600f0b9081600f0b815250508060c001516001600160a01b0316639611f3d96040518163ffffffff1660e01b8152600401602060405180830381865afa15801561045a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061047e9190612a07565b6001600160a01b031660a0820152608081015160208201516104b591620186a0916104af91600f91820b910b6114b9565b90611575565b600f0b60608201819052885160a08301516104d092906115f6565b6104e288600001518260400151611184565b985089602001516001600160a01b03168a600001516001600160a01b0316336001600160a01b03167f887adc1b38cfb756ed025ea6acd9382fbd376ede6c34bc6fa738284b092754688c8e604001518660600151604051610559939291909283526020830191909152600f0b604082015260600190565b60405180910390a450505050505050505b92915050565b60008060006105808787876109b2565b91509150806020015160ff16826020015160ff16036105ac578051825161013e91906101399087610af2565b60008060008060006105d38c886020015160ff16886020015160ff168c8b60000151611654565b945094509450945094506105f38c858584868a8c6020015160ff16610e43565b60018d0154909550610617906101b290600160801b9004600f0b600160401b6129ad565b94506101cd866000015161013987600f0b611838565b600080600061064586866000015187602001516109b2565b9150915084602001516001600160a01b031685600001516001600160a01b0316036106ac5760405162461bcd60e51b81526020600482015260176024820152761cddd85c0bdcd85b594b5bdc9a59da5b8b5d185c99d95d604a1b604482015260640161025a565b806020015160ff16826020015160ff16036106ef576106e6816000015186606001516106e085600001518960400151611866565b876118d5565b925050506109ab565b6040805160e081018252600080825260208201819052918101829052606081018290526080810182905260a0810182905260c081019190915260008060008060006107538c896020015160ff16896020015160ff168b600001518f6040015161196f565b94509450945094509450848660000190600f0b9081600f0b815250506107858c858585858a8d6020015160ff16610e43565b60808c01516001600160a01b031660c088015260018d01549095506107bc906101b290600160801b9004600f0b600160401b6129ad565b600f0b604087018190526107d19086906129ad565b8660200190600f0b9081600f0b815250508560c001516001600160a01b031663a5a410316040518163ffffffff1660e01b8152600401602060405180830381865afa158015610824573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061084891906129ec565b8660800190600f0b9081600f0b815250508560c001516001600160a01b0316639611f3d96040518163ffffffff1660e01b8152600401602060405180830381865afa15801561089b573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108bf9190612a07565b6001600160a01b031660a0870152608086015160208701516108f091620186a0916104af91600f91820b910b6114b9565b600f0b60608701819052875160a088015161090b92906115f6565b61092387600001518c6060015188604001518d6118d5565b98508a602001516001600160a01b03168b600001516001600160a01b0316336001600160a01b03167f887adc1b38cfb756ed025ea6acd9382fbd376ede6c34bc6fa738284b092754688e604001518d8b6060015160405161099a939291909283526020830191909152600f0b604082015260600190565b60405180910390a450505050505050505b9392505050565b604080518082019091526000808252602082015260408051808201909152600080825260208201526001600160a01b0380851660009081526005870160208181526040808420815180830183529054808716825260ff600160a01b918290048116838601528a88168752948452948290208251808401909352548087168352949094049092169082015281519192909116610a8f5760405162461bcd60e51b815260206004820152601a60248201527f43757276652f6f726967696e2d6e6f742d737570706f72746564000000000000604482015260640161025a565b80516001600160a01b0316610ae65760405162461bcd60e51b815260206004820152601a60248201527f43757276652f7461726765742d6e6f742d737570706f72746564000000000000604482015260640161025a565b90969095509350505050565b604051637af3606560e11b8152600481018290526000906001600160a01b0384169063f5e6c0ca90602401602060405180830381865afa158015610b3a573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109ab91906129ec565b604051636b677a8f60e01b8152600f82900b60048201526000906001600160a01b03841690636b677a8f90602401602060405180830381865afa158015610ba9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906109ab9190612a24565b6004850154600090819081906060908190838167ffffffffffffffff811115610bf857610bf8612845565b604051908082528060200260200182016040528015610c21578160200160208202803683370190505b50905060008267ffffffffffffffff811115610c3f57610c3f612845565b604051908082528060200260200182016040528015610c68578160200160208202803683370190505b50905060005b83811015610dd7578c8114610cff57610caf8e6004018281548110610c9557610c95612a3d565b6000918252602090912001546001600160a01b0316611c26565b828281518110610cc157610cc1612a3d565b6020026020010190600f0b9081600f0b815250838281518110610ce657610ce6612a3d565b6020026020010190600f0b9081600f0b81525050610d77565b6000610d0b8b8d611c91565b909a509050610d1d600f8b900b611d0f565b995080838381518110610d3257610d32612a3d565b600f92830b6020918202929092010152610d4f9082900b8b611d25565b848381518110610d6157610d61612a3d565b6020026020010190600f0b9081600f0b81525050505b818181518110610d8957610d89612a3d565b602002602001015188610d9c9190612980565b9750828181518110610db057610db0612a3d565b602002602001015187610dc39190612980565b965080610dcf81612a53565b915050610c6e565b50610de6600f87900b89611d59565b9550610e0b828c81518110610dfd57610dfd612a3d565b602002602001015189611d59565b828c81518110610e1d57610e1d612a3d565b600f9290920b602092830291909101909101529093509150509550955095509550959050565b6000610e4e83612a6c565b600289015460038a01805460408051602080840282018101909252828152949550600f9390930b9360009390929190830182828015610ecf57602002820191906000526020600020906000905b825461010083900a9004600f0b81526020601f8301819004938401936001036010909301929092029101808411610e9b5790505b505050505090506000610ee48a898d85611d8c565b90506000805b602081101561109157610eff8b8a8f87611d8c565b915085600f83810b9085900b12610f4057610f28610f1d84866129ad565b600f88900b90611db2565b610f32908a612980565b610f3b90612a6c565b610f5e565b82610f4b858b612980565b610f5591906129ad565b610f5e90612a6c565b9650610f706509184e72a00082612aa8565b600f0b610f836509184e72a00089612aa8565b600f0b036110125786610f968a8f612980565b610fa09190612980565b9b50868b8981518110610fb557610fb5612a3d565b6020026020010151610fc79190612980565b8a8981518110610fd957610fd9612a3d565b6020026020010190600f0b9081600f0b81525050610ffb8e8e8e8e8e8a611de8565b6110078d858e86612183565b5050505050506110da565b8661101d8a8f612980565b6110279190612980565b9b50611058878c8a8151811061103f5761103f612a3d565b6020026020010151600f0b611d2590919063ffffffff16565b8a898151811061106a5761106a612a3d565b6020026020010190600f0b9081600f0b81525050508061108981612a53565b915050610eea565b5060405162461bcd60e51b815260206004820152601d60248201527f43757276652f737761702d636f6e76657267656e63652d6661696c6564000000604482015260640161025a565b979650505050505050565b600080604083600f0b85600f0b6110fc9190612af4565b901d949350505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663f09a3fc360e01b17905260009061115a858261221f565b80602001905181019061116d91906129ec565b915061117b82600f0b611d0f565b95945050505050565b60408051600f83900b6024808301919091528251808303909101815260449091019091526020810180516001600160e01b0316624e387960e31b1790526000906111ce848261221f565b8060200190518101906101d79190612a24565b6004860154600090819081906060908190838167ffffffffffffffff81111561120c5761120c612845565b604051908082528060200260200182016040528015611235578160200160208202803683370190505b50905060008267ffffffffffffffff81111561125357611253612845565b60405190808252806020026020018201604052801561127c578160200160208202803683370190505b50905060008e600401805480602002602001604051908101604052809291908181526020016000905b828210156112ee57600084815260209081902060408051808201909152908401546001600160a01b0381168252600160a01b900460ff16818301528252600190920191016112a5565b50505050905060005b8481101561144b578e811461137c5761132c82828151811061131b5761131b612a3d565b602002602001015160000151611c26565b84828151811061133e5761133e612a3d565b6020026020010190600f0b9081600f0b81525083828151811061136357611363612a3d565b6020026020010190600f0b9081600f0b815250506113eb565b60006113898e8e8e6122f3565b909b50905061139c600f82900b8c611d59565b8583815181106113ae576113ae612a3d565b6020026020010190600f0b9081600f0b81525050808483815181106113d5576113d5612a3d565b6020026020010190600f0b9081600f0b81525050505b8381815181106113fd576113fd612a3d565b6020026020010151896114109190612980565b985082818151811061142457611424612a3d565b6020026020010151886114379190612980565b97508061144381612a53565b9150506112f7565b5061145a600f88900b8a611d59565b965061147f828e8151811061147157611471612a3d565b60200260200101518a611d59565b828e8151811061149157611491612a3d565b600f9290920b6020928302919091019091015250909350915050965096509650965096915050565b60006001607f1b600f84900b016114fd576002600160c01b031982121580156114e65750600160c01b8213155b6114ef57600080fd5b506000819003603f1b61056a565b60008084600f0b121561151557836000039350600190505b60008312156115275760009290920391155b60006115338585612379565b9050811561155857600160ff1b81111561154c57600080fd5b600003915061056a9050565b6001600160ff1b0381111561156c57600080fd5b915061056a9050565b60008160000361158457600080fd5b60008084121561159957836000039350600190505b60008312156115ab5760009290920391155b60006115b785856123e4565b905081156115d9576001607f1b816001600160801b0316111561154c57600080fd5b60016001607f1b03816001600160801b0316111561156c57600080fd5b60408051600f84900b60248201526001600160a01b0383166044808301919091528251808303909101815260649091019091526020810180516001600160e01b03166322cead0360e11b17905261164d848261221f565b5050505050565b6004850154600090819081906060908190838167ffffffffffffffff81111561167f5761167f612845565b6040519080825280602002602001820160405280156116a8578160200160208202803683370190505b50905060008267ffffffffffffffff8111156116c6576116c6612845565b6040519080825280602002602001820160405280156116ef578160200160208202803683370190505b50905060005b83811015610dd7578c811461176c5761171c8e6004018281548110610c9557610c95612a3d565b82828151811061172e5761172e612a3d565b6020026020010190600f0b9081600f0b81525083828151811061175357611753612a3d565b6020026020010190600f0b9081600f0b815250506117d8565b60006117788b8d611c91565b809250819b5050508083838151811061179357611793612a3d565b600f92830b60209182029290920101526117b09082900b8b611d25565b8483815181106117c2576117c2612a3d565b6020026020010190600f0b9081600f0b81525050505b8181815181106117ea576117ea612a3d565b6020026020010151886117fd9190612980565b975082818151811061181157611811612a3d565b6020026020010151876118249190612980565b96508061183081612a53565b9150506116f5565b60006001607f1b600f83900b0161184e57600080fd5b600082600f0b1261185f578161056a565b5060000390565b60008063fa00102a60e01b8360405160240161188491815260200190565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290506118c2848261221f565b8060200190518101906101d791906129ec565b600080630c374e5d60e11b856118ee600f87900b611838565b6040516001600160a01b039092166024830152600f0b6044820152841515606482015260840160408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091529050611952868261221f565b8060200190518101906119659190612a24565b9695505050505050565b6004850154600090819081906060908190838167ffffffffffffffff81111561199a5761199a612845565b6040519080825280602002602001820160405280156119c3578160200160208202803683370190505b50905060008267ffffffffffffffff8111156119e1576119e1612845565b604051908082528060200260200182016040528015611a0a578160200160208202803683370190505b50905060008d600401805480602002602001604051908101604052809291908181526020016000905b82821015611a7c57600084815260209081902060408051808201909152908401546001600160a01b0381168252600160a01b900460ff1681830152825260019092019101611a33565b50505050905060005b84811015611bc7578d8114611af957611aa982828151811061131b5761131b612a3d565b848281518110611abb57611abb612a3d565b6020026020010190600f0b9081600f0b815250838281518110611ae057611ae0612a3d565b6020026020010190600f0b9081600f0b81525050611b67565b6000611b058d8d612549565b909b509050611b18600f82900b8c611d59565b858381518110611b2a57611b2a612a3d565b6020026020010190600f0b9081600f0b8152505080848381518110611b5157611b51612a3d565b6020026020010190600f0b9081600f0b81525050505b838181518110611b7957611b79612a3d565b602002602001015189611b8c9190612980565b9850828181518110611ba057611ba0612a3d565b602002602001015188611bb39190612980565b975080611bbf81612a53565b915050611a85565b50611bd6600f88900b8a611d59565b9650611bed828d8151811061147157611471612a3d565b828d81518110611bff57611bff612a3d565b600f9290920b60209283029190910190910152509093509150509550955095509550959050565b60405163ac969a7360e01b81523060048201526000906001600160a01b0383169063ac969a7390602401602060405180830381865afa158015611c6d573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061056a91906129ec565b604051630f4d965d60e11b81523060048201526024810182905260009081906001600160a01b03851690631e9b2cba906044016040805180830381865afa158015611ce0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611d049190612b24565b909590945092505050565b60006001607f1b600f83900b0161185f57600080fd5b6000600f83810b9083900b0160016001607f1b03198112801590611d50575060016001607f1b038113155b6109ab57600080fd5b6000600f82810b9084900b0360016001607f1b03198112801590611d50575060016001607f1b038113156109ab57600080fd5b81546001830154600091600160801b9004600f90810b91900b6110da87878484886125ba565b6000600f83810b9083900b0260401d60016001607f1b03198112801590611d50575060016001607f1b038113156109ab57600080fd5b81518654600f0b60005b82811015612178576000611e2b858381518110611e1157611e11612a3d565b602002602001015189600f0b611db290919063ffffffff16565b905080600f0b868381518110611e4357611e43612a3d565b6020026020010151600f0b1315611fdf576000611e6484600160401b612980565b90506000611e76600f84900b83611db2565b905080600f0b888581518110611e8e57611e8e612a3d565b6020026020010151600f0b1315611fd8576000611edd83611ed48a8881518110611eba57611eba612a3d565b60200260200101518f600f0b611db290919063ffffffff16565b600f0b90611db2565b905080600f0b8a8681518110611ef557611ef5612a3d565b6020026020010151600f0b1215611f435760405162461bcd60e51b815260206004820152601260248201527143757276652f75707065722d68616c742d3160701b604482015260640161025a565b808a8681518110611f5657611f56612a3d565b6020026020010151611f6891906129ad565b600f0b828a8781518110611f7e57611f7e612a3d565b6020026020010151611f9091906129ad565b600f0b1315611fd65760405162461bcd60e51b815260206004820152601260248201527121bab93b3297bab83832b916b430b63a169960711b604482015260640161025a565b505b5050612165565b6000611fef84600160401b6129ad565b90506000612001600f84900b83611db2565b905080600f0b88858151811061201957612019612a3d565b6020026020010151600f0b121561216257600061205b88868151811061204157612041612a3d565b60200260200101518d600f0b611db290919063ffffffff16565b905061206b600f82900b84611db2565b905080600f0b8a868151811061208357612083612a3d565b6020026020010151600f0b13156120cf5760405162461bcd60e51b815260206004820152601060248201526f10dd5c9d994bdb1bddd95c8b5a185b1d60821b604482015260640161025a565b8985815181106120e1576120e1612a3d565b6020026020010151816120f491906129ad565b600f0b89868151811061210957612109612a3d565b60200260200101518361211c91906129ad565b600f0b13156121605760405162461bcd60e51b815260206004820152601060248201526f10dd5c9d994bdb1bddd95c8b5a185b1d60821b604482015260640161025a565b505b50505b508061217081612a53565b915050611df2565b505050505050505050565b600061218f82846129ad565b9050600061219d85876129ad565b905060006121ab82846129ad565b905080600f0b600012806121ca57506510c6f7a0b5ed19600f82900b12155b6122165760405162461bcd60e51b815260206004820152601e60248201527f43757276652f737761702d696e76617269616e742d76696f6c6174696f6e0000604482015260640161025a565b50505050505050565b60606001600160a01b0383163b6122865760405162461bcd60e51b815260206004820152602560248201527f417373696d696c61746f72732f63616c6c65652d69732d6e6f742d612d636f6e6044820152641d1c9858dd60da1b606482015260840161025a565b600080846001600160a01b0316846040516122a19190612b4e565b600060405180830381855af49150503d80600081146122dc576040519150601f19603f3d011682016040523d82523d6000602084013e6122e1565b606091505b509092509050816101d7573d60208201fd5b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180516001600160e01b031663523bf25760e01b1790526000908190612349868261221f565b80602001905181019061235c9190612b24565b909350915061236e600f84900b611d0f565b925050935093915050565b60008160000361238b5750600061056a565b600083600f0b121561239c57600080fd5b600f83900b6001600160801b038316810260401c90608084901c026001600160c01b038111156123cb57600080fd5b60401b81198111156123dc57600080fd5b019392505050565b6000816000036123f357600080fd5b60006001600160c01b03841161241e5782604085901b8161241657612416612a92565b049050612535565b60c084811c6401000000008110612437576020918201911c5b620100008110612449576010918201911c5b610100811061245a576008918201911c5b6010811061246a576004918201911c5b6004811061247a576002918201911c5b60028110612489576001820191505b60bf820360018603901c6001018260ff0387901b816124aa576124aa612a92565b0492506001600160801b038311156124c157600080fd5b608085901c83026001600160801b038616840260c088901c604089901b828110156124ed576001820391505b608084901b92900382811015612504576001820391505b829003608084901c821461251a5761251a612b7d565b88818161252957612529612a92565b04870196505050505050505b6001600160801b038111156109ab57600080fd5b6000806000637f328ecc60e01b8460405160240161256991815260200190565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b03199093169290921790915290506125a7858261221f565b806020019051810190610ae69190612b24565b8351600090815b818110156126415760006125fa8583815181106125e0576125e0612a3d565b60200260200101518a600f0b611db290919063ffffffff16565b905061262188838151811061261157612611612a3d565b602002602001015182898961264c565b61262b9085612980565b935050808061263990612a53565b9150506125c1565b505095945050505050565b600083600f0b85600f0b12156126f157600061267a61266f85600160401b6129ad565b600f87900b90611db2565b905080600f0b86600f0b12156126e657600061269687836129ad565b90506126a6600f82900b85611db2565b92506126b6600f84900b8761277e565b92506001603e1b600f84900b13156126d0576001603e1b92505b6126de600f84900b82611db2565b9250506126eb565b600091505b506101d7565b600061270461266f85600160401b612980565b905080600f0b86600f0b131561277057600061272082886129ad565b9050612730600f82900b85611db2565b9250612740600f84900b8761277e565b92506001603e1b600f84900b131561275a576001603e1b92505b612768600f84900b82611db2565b925050612775565b600091505b50949350505050565b600081600f0b60000361279057600080fd5b600082600f0b604085600f0b901b816127ab576127ab612a92565b05905060016001607f1b03198112801590611d50575060016001607f1b038113156109ab57600080fd5b6001600160a01b03811681146127ea57600080fd5b50565b80356127f8816127d5565b919050565b6000806000806080858703121561281357600080fd5b843593506020850135612825816127d5565b92506040850135612835816127d5565b9396929550929360600135925050565b634e487b7160e01b600052604160045260246000fd5b600060a0828403121561286d57600080fd5b60405160a0810181811067ffffffffffffffff8211171561289e57634e487b7160e01b600052604160045260246000fd5b60405290508082356128af816127d5565b815260208301356128bf816127d5565b6020820152604083810135908201526128da606084016127ed565b60608201526128eb608084016127ed565b60808201525092915050565b60008060c0838503121561290a57600080fd5b8235915061291b846020850161285b565b90509250929050565b600080600060e0848603121561293957600080fd5b8335925061294a856020860161285b565b915060c0840135801515811461295f57600080fd5b809150509250925092565b634e487b7160e01b600052601160045260246000fd5b600f81810b9083900b0160016001607f1b03811360016001607f1b03198212171561056a5761056a61296a565b600f82810b9082900b0360016001607f1b0319811260016001607f1b038213171561056a5761056a61296a565b8051600f81900b81146127f857600080fd5b6000602082840312156129fe57600080fd5b6109ab826129da565b600060208284031215612a1957600080fd5b81516109ab816127d5565b600060208284031215612a3657600080fd5b5051919050565b634e487b7160e01b600052603260045260246000fd5b600060018201612a6557612a6561296a565b5060010190565b600081600f0b60016001607f1b03198103612a8957612a8961296a565b60000392915050565b634e487b7160e01b600052601260045260246000fd5b600081600f0b83600f0b80612acd57634e487b7160e01b600052601260045260246000fd5b60016001607f1b0319821460001982141615612aeb57612aeb61296a565b90059392505050565b80820260008212600160ff1b84141615612b1057612b1061296a565b818105831482151761056a5761056a61296a565b60008060408385031215612b3757600080fd5b612b40836129da565b915061291b602084016129da565b6000825160005b81811015612b6f5760208186018101518583015201612b55565b506000920191825250919050565b634e487b7160e01b600052600160045260246000fdfea2646970667358221220d30cb12b2d94aa834e84ef4dc32292b3d4d0af89578a9edcf0ce59b0463d07e064736f6c63430008150033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
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.