Overview
ETH Balance
0 ETH
Eth Value
$0.00More Info
Private Name Tags
ContractCreator
Latest 1 from a total of 1 transactions
Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
---|---|---|---|---|---|---|---|---|---|
Transfer Ownersh... | 7575733 | 2125 days ago | IN | 0 ETH | 0.00030369 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
Expiry
Compiler Version
v0.5.7+commit.6da8b019
Optimization Enabled:
Yes with 10000 runs
Other Settings:
byzantium EvmVersion
Contract Source Code (Solidity)
/** *Submitted for verification at Etherscan.io on 2019-05-07 */ /* Copyright 2019 dYdX Trading Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ pragma solidity 0.5.7; pragma experimental ABIEncoderV2; // File: openzeppelin-solidity/contracts/math/SafeMath.sol /** * @title SafeMath * @dev Unsigned math operations with safety checks that revert on error */ library SafeMath { /** * @dev Multiplies two unsigned integers, reverts on overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // 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-solidity/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b); return c; } /** * @dev Integer division of two unsigned integers truncating the quotient, reverts on division by zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Subtracts two unsigned integers, reverts on overflow (i.e. if subtrahend is greater than minuend). */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a); uint256 c = a - b; return c; } /** * @dev Adds two unsigned integers, reverts on overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a); return c; } /** * @dev Divides two unsigned integers and returns the remainder (unsigned integer modulo), * reverts when dividing by zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0); return a % b; } } // File: openzeppelin-solidity/contracts/ownership/Ownable.sol /** * @title Ownable * @dev The Ownable contract has an owner address, and provides basic authorization control * functions, this simplifies the implementation of "user permissions". */ contract Ownable { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev The Ownable constructor sets the original `owner` of the contract to the sender * account. */ constructor () internal { _owner = msg.sender; emit OwnershipTransferred(address(0), _owner); } /** * @return the address of the owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(isOwner()); _; } /** * @return true if `msg.sender` is the owner of the contract. */ function isOwner() public view returns (bool) { return msg.sender == _owner; } /** * @dev Allows the current owner to relinquish control of the contract. * @notice Renouncing to ownership will leave the contract without an owner. * It will not be possible to call the functions with the `onlyOwner` * modifier anymore. */ function renounceOwnership() public onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Allows the current owner to transfer control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function transferOwnership(address newOwner) public onlyOwner { _transferOwnership(newOwner); } /** * @dev Transfers control of the contract to a newOwner. * @param newOwner The address to transfer ownership to. */ function _transferOwnership(address newOwner) internal { require(newOwner != address(0)); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } } // File: contracts/protocol/lib/Require.sol /** * @title Require * @author dYdX * * Stringifies parameters to pretty-print revert messages. Costs more gas than regular require() */ library Require { // ============ Constants ============ uint256 constant ASCII_ZERO = 48; // '0' uint256 constant ASCII_RELATIVE_ZERO = 87; // 'a' - 10 uint256 constant ASCII_LOWER_EX = 120; // 'x' bytes2 constant COLON = 0x3a20; // ': ' bytes2 constant COMMA = 0x2c20; // ', ' bytes2 constant LPAREN = 0x203c; // ' <' byte constant RPAREN = 0x3e; // '>' uint256 constant FOUR_BIT_MASK = 0xf; // ============ Library Functions ============ function that( bool must, bytes32 file, bytes32 reason ) internal pure { if (!must) { revert( string( abi.encodePacked( stringify(file), COLON, stringify(reason) ) ) ); } } function that( bool must, bytes32 file, bytes32 reason, uint256 payloadA ) internal pure { if (!must) { revert( string( abi.encodePacked( stringify(file), COLON, stringify(reason), LPAREN, stringify(payloadA), RPAREN ) ) ); } } function that( bool must, bytes32 file, bytes32 reason, uint256 payloadA, uint256 payloadB ) internal pure { if (!must) { revert( string( abi.encodePacked( stringify(file), COLON, stringify(reason), LPAREN, stringify(payloadA), COMMA, stringify(payloadB), RPAREN ) ) ); } } function that( bool must, bytes32 file, bytes32 reason, address payloadA ) internal pure { if (!must) { revert( string( abi.encodePacked( stringify(file), COLON, stringify(reason), LPAREN, stringify(payloadA), RPAREN ) ) ); } } function that( bool must, bytes32 file, bytes32 reason, address payloadA, uint256 payloadB ) internal pure { if (!must) { revert( string( abi.encodePacked( stringify(file), COLON, stringify(reason), LPAREN, stringify(payloadA), COMMA, stringify(payloadB), RPAREN ) ) ); } } function that( bool must, bytes32 file, bytes32 reason, address payloadA, uint256 payloadB, uint256 payloadC ) internal pure { if (!must) { revert( string( abi.encodePacked( stringify(file), COLON, stringify(reason), LPAREN, stringify(payloadA), COMMA, stringify(payloadB), COMMA, stringify(payloadC), RPAREN ) ) ); } } // ============ Private Functions ============ function stringify( bytes32 input ) private pure returns (bytes memory) { // put the input bytes into the result bytes memory result = abi.encodePacked(input); // determine the length of the input by finding the location of the last non-zero byte for (uint256 i = 32; i > 0; ) { // reverse-for-loops with unsigned integer /* solium-disable-next-line security/no-modify-for-iter-var */ i--; // find the last non-zero byte in order to determine the length if (result[i] != 0) { uint256 length = i + 1; /* solium-disable-next-line security/no-inline-assembly */ assembly { mstore(result, length) // r.length = length; } return result; } } // all bytes are zero return new bytes(0); } function stringify( uint256 input ) private pure returns (bytes memory) { if (input == 0) { return "0"; } // get the final string length uint256 j = input; uint256 length; while (j != 0) { length++; j /= 10; } // allocate the string bytes memory bstr = new bytes(length); // populate the string starting with the least-significant character j = input; for (uint256 i = length; i > 0; ) { // reverse-for-loops with unsigned integer /* solium-disable-next-line security/no-modify-for-iter-var */ i--; // take last decimal digit bstr[i] = byte(uint8(ASCII_ZERO + (j % 10))); // remove the last decimal digit j /= 10; } return bstr; } function stringify( address input ) private pure returns (bytes memory) { uint256 z = uint256(input); // addresses are "0x" followed by 20 bytes of data which take up 2 characters each bytes memory result = new bytes(42); // populate the result with "0x" result[0] = byte(uint8(ASCII_ZERO)); result[1] = byte(uint8(ASCII_LOWER_EX)); // for each byte (starting from the lowest byte), populate the result with two characters for (uint256 i = 0; i < 20; i++) { // each byte takes two characters uint256 shift = i * 2; // populate the least-significant character result[41 - shift] = char(z & FOUR_BIT_MASK); z = z >> 4; // populate the most-significant character result[40 - shift] = char(z & FOUR_BIT_MASK); z = z >> 4; } return result; } function char( uint256 input ) private pure returns (byte) { // return ASCII digit (0-9) if (input < 10) { return byte(uint8(input + ASCII_ZERO)); } // return ASCII letter (a-f) return byte(uint8(input + ASCII_RELATIVE_ZERO)); } } // File: contracts/protocol/lib/Math.sol /** * @title Math * @author dYdX * * Library for non-standard Math functions */ library Math { using SafeMath for uint256; // ============ Constants ============ bytes32 constant FILE = "Math"; // ============ Library Functions ============ /* * Return target * (numerator / denominator). */ function getPartial( uint256 target, uint256 numerator, uint256 denominator ) internal pure returns (uint256) { return target.mul(numerator).div(denominator); } /* * Return target * (numerator / denominator), but rounded up. */ function getPartialRoundUp( uint256 target, uint256 numerator, uint256 denominator ) internal pure returns (uint256) { if (target == 0 || numerator == 0) { // SafeMath will check for zero denominator return SafeMath.div(0, denominator); } return target.mul(numerator).sub(1).div(denominator).add(1); } function to128( uint256 number ) internal pure returns (uint128) { uint128 result = uint128(number); Require.that( result == number, FILE, "Unsafe cast to uint128" ); return result; } function to96( uint256 number ) internal pure returns (uint96) { uint96 result = uint96(number); Require.that( result == number, FILE, "Unsafe cast to uint96" ); return result; } function to32( uint256 number ) internal pure returns (uint32) { uint32 result = uint32(number); Require.that( result == number, FILE, "Unsafe cast to uint32" ); return result; } function min( uint256 a, uint256 b ) internal pure returns (uint256) { return a < b ? a : b; } function max( uint256 a, uint256 b ) internal pure returns (uint256) { return a > b ? a : b; } } // File: contracts/protocol/lib/Types.sol /** * @title Types * @author dYdX * * Library for interacting with the basic structs used in Solo */ library Types { using Math for uint256; // ============ AssetAmount ============ enum AssetDenomination { Wei, // the amount is denominated in wei Par // the amount is denominated in par } enum AssetReference { Delta, // the amount is given as a delta from the current value Target // the amount is given as an exact number to end up at } struct AssetAmount { bool sign; // true if positive AssetDenomination denomination; AssetReference ref; uint256 value; } // ============ Par (Principal Amount) ============ // Total borrow and supply values for a market struct TotalPar { uint128 borrow; uint128 supply; } // Individual principal amount for an account struct Par { bool sign; // true if positive uint128 value; } function zeroPar() internal pure returns (Par memory) { return Par({ sign: false, value: 0 }); } function sub( Par memory a, Par memory b ) internal pure returns (Par memory) { return add(a, negative(b)); } function add( Par memory a, Par memory b ) internal pure returns (Par memory) { Par memory result; if (a.sign == b.sign) { result.sign = a.sign; result.value = SafeMath.add(a.value, b.value).to128(); } else { if (a.value >= b.value) { result.sign = a.sign; result.value = SafeMath.sub(a.value, b.value).to128(); } else { result.sign = b.sign; result.value = SafeMath.sub(b.value, a.value).to128(); } } return result; } function equals( Par memory a, Par memory b ) internal pure returns (bool) { if (a.value == b.value) { if (a.value == 0) { return true; } return a.sign == b.sign; } return false; } function negative( Par memory a ) internal pure returns (Par memory) { return Par({ sign: !a.sign, value: a.value }); } function isNegative( Par memory a ) internal pure returns (bool) { return !a.sign && a.value > 0; } function isPositive( Par memory a ) internal pure returns (bool) { return a.sign && a.value > 0; } function isZero( Par memory a ) internal pure returns (bool) { return a.value == 0; } // ============ Wei (Token Amount) ============ // Individual token amount for an account struct Wei { bool sign; // true if positive uint256 value; } function zeroWei() internal pure returns (Wei memory) { return Wei({ sign: false, value: 0 }); } function sub( Wei memory a, Wei memory b ) internal pure returns (Wei memory) { return add(a, negative(b)); } function add( Wei memory a, Wei memory b ) internal pure returns (Wei memory) { Wei memory result; if (a.sign == b.sign) { result.sign = a.sign; result.value = SafeMath.add(a.value, b.value); } else { if (a.value >= b.value) { result.sign = a.sign; result.value = SafeMath.sub(a.value, b.value); } else { result.sign = b.sign; result.value = SafeMath.sub(b.value, a.value); } } return result; } function equals( Wei memory a, Wei memory b ) internal pure returns (bool) { if (a.value == b.value) { if (a.value == 0) { return true; } return a.sign == b.sign; } return false; } function negative( Wei memory a ) internal pure returns (Wei memory) { return Wei({ sign: !a.sign, value: a.value }); } function isNegative( Wei memory a ) internal pure returns (bool) { return !a.sign && a.value > 0; } function isPositive( Wei memory a ) internal pure returns (bool) { return a.sign && a.value > 0; } function isZero( Wei memory a ) internal pure returns (bool) { return a.value == 0; } } // File: contracts/protocol/lib/Account.sol /** * @title Account * @author dYdX * * Library of structs and functions that represent an account */ library Account { // ============ Enums ============ /* * Most-recently-cached account status. * * Normal: Can only be liquidated if the account values are violating the global margin-ratio. * Liquid: Can be liquidated no matter the account values. * Can be vaporized if there are no more positive account values. * Vapor: Has only negative (or zeroed) account values. Can be vaporized. * */ enum Status { Normal, Liquid, Vapor } // ============ Structs ============ // Represents the unique key that specifies an account struct Info { address owner; // The address that owns the account uint256 number; // A nonce that allows a single address to control many accounts } // The complete storage for any account struct Storage { mapping (uint256 => Types.Par) balances; // Mapping from marketId to principal Status status; } // ============ Library Functions ============ function equals( Info memory a, Info memory b ) internal pure returns (bool) { return a.owner == b.owner && a.number == b.number; } } // File: contracts/protocol/interfaces/IAutoTrader.sol /** * @title IAutoTrader * @author dYdX * * Interface that Auto-Traders for Solo must implement in order to approve trades. */ contract IAutoTrader { // ============ Public Functions ============ /** * Allows traders to make trades approved by this smart contract. The active trader's account is * the takerAccount and the passive account (for which this contract approves trades * on-behalf-of) is the makerAccount. * * @param inputMarketId The market for which the trader specified the original amount * @param outputMarketId The market for which the trader wants the resulting amount specified * @param makerAccount The account for which this contract is making trades * @param takerAccount The account requesting the trade * @param oldInputPar The old principal amount for the makerAccount for the inputMarketId * @param newInputPar The new principal amount for the makerAccount for the inputMarketId * @param inputWei The change in token amount for the makerAccount for the inputMarketId * @param data Arbitrary data passed in by the trader * @return The AssetAmount for the makerAccount for the outputMarketId */ function getTradeCost( uint256 inputMarketId, uint256 outputMarketId, Account.Info memory makerAccount, Account.Info memory takerAccount, Types.Par memory oldInputPar, Types.Par memory newInputPar, Types.Wei memory inputWei, bytes memory data ) public returns (Types.AssetAmount memory); } // File: contracts/protocol/interfaces/ICallee.sol /** * @title ICallee * @author dYdX * * Interface that Callees for Solo must implement in order to ingest data. */ contract ICallee { // ============ Public Functions ============ /** * Allows users to send this contract arbitrary data. * * @param sender The msg.sender to Solo * @param accountInfo The account from which the data is being sent * @param data Arbitrary data given by the sender */ function callFunction( address sender, Account.Info memory accountInfo, bytes memory data ) public; } // File: contracts/protocol/lib/Decimal.sol /** * @title Decimal * @author dYdX * * Library that defines a fixed-point number with 18 decimal places. */ library Decimal { using SafeMath for uint256; // ============ Constants ============ uint256 constant BASE = 10**18; // ============ Structs ============ struct D256 { uint256 value; } // ============ Functions ============ function one() internal pure returns (D256 memory) { return D256({ value: BASE }); } function onePlus( D256 memory d ) internal pure returns (D256 memory) { return D256({ value: d.value.add(BASE) }); } function mul( uint256 target, D256 memory d ) internal pure returns (uint256) { return Math.getPartial(target, d.value, BASE); } function div( uint256 target, D256 memory d ) internal pure returns (uint256) { return Math.getPartial(target, BASE, d.value); } } // File: contracts/protocol/lib/Monetary.sol /** * @title Monetary * @author dYdX * * Library for types involving money */ library Monetary { /* * The price of a base-unit of an asset. */ struct Price { uint256 value; } /* * Total value of an some amount of an asset. Equal to (price * amount). */ struct Value { uint256 value; } } // File: contracts/protocol/lib/Time.sol /** * @title Time * @author dYdX * * Library for dealing with time, assuming timestamps fit within 32 bits (valid until year 2106) */ library Time { // ============ Library Functions ============ function currentTime() internal view returns (uint32) { return Math.to32(block.timestamp); } } // File: openzeppelin-solidity/contracts/utils/ReentrancyGuard.sol /** * @title Helps contracts guard against reentrancy attacks. * @author Remco Bloemen <remco@2π.com>, Eenae <[email protected]> * @dev If you mark a function `nonReentrant`, you should also * mark it `external`. */ contract ReentrancyGuard { /// @dev counter to allow mutex lock with only one SSTORE operation uint256 private _guardCounter; constructor () internal { // The counter starts at one to prevent changing it from zero to a non-zero // value, which is a more expensive operation. _guardCounter = 1; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { _guardCounter += 1; uint256 localCounter = _guardCounter; _; require(localCounter == _guardCounter); } } // File: contracts/protocol/lib/Cache.sol /** * @title Cache * @author dYdX * * Library for caching information about markets */ library Cache { using Cache for MarketCache; using Storage for Storage.State; // ============ Structs ============ struct MarketInfo { bool isClosing; uint128 borrowPar; Monetary.Price price; } struct MarketCache { MarketInfo[] markets; } // ============ Setter Functions ============ /** * Initialize an empty cache for some given number of total markets. */ function create( uint256 numMarkets ) internal pure returns (MarketCache memory) { return MarketCache({ markets: new MarketInfo[](numMarkets) }); } /** * Add market information (price and total borrowed par if the market is closing) to the cache. * Return true if the market information did not previously exist in the cache. */ function addMarket( MarketCache memory cache, Storage.State storage state, uint256 marketId ) internal view returns (bool) { if (cache.hasMarket(marketId)) { return false; } cache.markets[marketId].price = state.fetchPrice(marketId); if (state.markets[marketId].isClosing) { cache.markets[marketId].isClosing = true; cache.markets[marketId].borrowPar = state.getTotalPar(marketId).borrow; } return true; } // ============ Getter Functions ============ function getNumMarkets( MarketCache memory cache ) internal pure returns (uint256) { return cache.markets.length; } function hasMarket( MarketCache memory cache, uint256 marketId ) internal pure returns (bool) { return cache.markets[marketId].price.value != 0; } function getIsClosing( MarketCache memory cache, uint256 marketId ) internal pure returns (bool) { return cache.markets[marketId].isClosing; } function getPrice( MarketCache memory cache, uint256 marketId ) internal pure returns (Monetary.Price memory) { return cache.markets[marketId].price; } function getBorrowPar( MarketCache memory cache, uint256 marketId ) internal pure returns (uint128) { return cache.markets[marketId].borrowPar; } } // File: contracts/protocol/lib/Interest.sol /** * @title Interest * @author dYdX * * Library for managing the interest rate and interest indexes of Solo */ library Interest { using Math for uint256; using SafeMath for uint256; // ============ Constants ============ bytes32 constant FILE = "Interest"; uint64 constant BASE = 10**18; // ============ Structs ============ struct Rate { uint256 value; } struct Index { uint96 borrow; uint96 supply; uint32 lastUpdate; } // ============ Library Functions ============ /** * Get a new market Index based on the old index and market interest rate. * Calculate interest for borrowers by using the formula rate * time. Approximates * continuously-compounded interest when called frequently, but is much more * gas-efficient to calculate. For suppliers, the interest rate is adjusted by the earningsRate, * then prorated the across all suppliers. * * @param index The old index for a market * @param rate The current interest rate of the market * @param totalPar The total supply and borrow par values of the market * @param earningsRate The portion of the interest that is forwarded to the suppliers * @return The updated index for a market */ function calculateNewIndex( Index memory index, Rate memory rate, Types.TotalPar memory totalPar, Decimal.D256 memory earningsRate ) internal view returns (Index memory) { ( Types.Wei memory supplyWei, Types.Wei memory borrowWei ) = totalParToWei(totalPar, index); // get interest increase for borrowers uint32 currentTime = Time.currentTime(); uint256 borrowInterest = rate.value.mul(uint256(currentTime).sub(index.lastUpdate)); // get interest increase for suppliers uint256 supplyInterest; if (Types.isZero(supplyWei)) { supplyInterest = 0; } else { supplyInterest = Decimal.mul(borrowInterest, earningsRate); if (borrowWei.value < supplyWei.value) { supplyInterest = Math.getPartial(supplyInterest, borrowWei.value, supplyWei.value); } } assert(supplyInterest <= borrowInterest); return Index({ borrow: Math.getPartial(index.borrow, borrowInterest, BASE).add(index.borrow).to96(), supply: Math.getPartial(index.supply, supplyInterest, BASE).add(index.supply).to96(), lastUpdate: currentTime }); } function newIndex() internal view returns (Index memory) { return Index({ borrow: BASE, supply: BASE, lastUpdate: Time.currentTime() }); } /* * Convert a principal amount to a token amount given an index. */ function parToWei( Types.Par memory input, Index memory index ) internal pure returns (Types.Wei memory) { uint256 inputValue = uint256(input.value); if (input.sign) { return Types.Wei({ sign: true, value: inputValue.getPartial(index.supply, BASE) }); } else { return Types.Wei({ sign: false, value: inputValue.getPartialRoundUp(index.borrow, BASE) }); } } /* * Convert a token amount to a principal amount given an index. */ function weiToPar( Types.Wei memory input, Index memory index ) internal pure returns (Types.Par memory) { if (input.sign) { return Types.Par({ sign: true, value: input.value.getPartial(BASE, index.supply).to128() }); } else { return Types.Par({ sign: false, value: input.value.getPartialRoundUp(BASE, index.borrow).to128() }); } } /* * Convert the total supply and borrow principal amounts of a market to total supply and borrow * token amounts. */ function totalParToWei( Types.TotalPar memory totalPar, Index memory index ) internal pure returns (Types.Wei memory, Types.Wei memory) { Types.Par memory supplyPar = Types.Par({ sign: true, value: totalPar.supply }); Types.Par memory borrowPar = Types.Par({ sign: false, value: totalPar.borrow }); Types.Wei memory supplyWei = parToWei(supplyPar, index); Types.Wei memory borrowWei = parToWei(borrowPar, index); return (supplyWei, borrowWei); } } // File: contracts/protocol/interfaces/IErc20.sol /** * @title IErc20 * @author dYdX * * Interface for using ERC20 Tokens. We have to use a special interface to call ERC20 functions so * that we don't automatically revert when calling non-compliant tokens that have no return value for * transfer(), transferFrom(), or approve(). */ interface IErc20 { event Transfer( address indexed from, address indexed to, uint256 value ); event Approval( address indexed owner, address indexed spender, uint256 value ); function totalSupply( ) external view returns (uint256); function balanceOf( address who ) external view returns (uint256); function allowance( address owner, address spender ) external view returns (uint256); function transfer( address to, uint256 value ) external; function transferFrom( address from, address to, uint256 value ) external; function approve( address spender, uint256 value ) external; function name() external view returns (string memory); function symbol() external view returns (string memory); function decimals() external view returns (uint8); } // File: contracts/protocol/lib/Token.sol /** * @title Token * @author dYdX * * This library contains basic functions for interacting with ERC20 tokens. Modified to work with * tokens that don't adhere strictly to the ERC20 standard (for example tokens that don't return a * boolean value on success). */ library Token { // ============ Constants ============ bytes32 constant FILE = "Token"; // ============ Library Functions ============ function balanceOf( address token, address owner ) internal view returns (uint256) { return IErc20(token).balanceOf(owner); } function allowance( address token, address owner, address spender ) internal view returns (uint256) { return IErc20(token).allowance(owner, spender); } function approve( address token, address spender, uint256 amount ) internal { IErc20(token).approve(spender, amount); Require.that( checkSuccess(), FILE, "Approve failed" ); } function approveMax( address token, address spender ) internal { approve( token, spender, uint256(-1) ); } function transfer( address token, address to, uint256 amount ) internal { if (amount == 0 || to == address(this)) { return; } IErc20(token).transfer(to, amount); Require.that( checkSuccess(), FILE, "Transfer failed" ); } function transferFrom( address token, address from, address to, uint256 amount ) internal { if (amount == 0 || to == from) { return; } IErc20(token).transferFrom(from, to, amount); Require.that( checkSuccess(), FILE, "TransferFrom failed" ); } // ============ Private Functions ============ /** * Check the return value of the previous function up to 32 bytes. Return true if the previous * function returned 0 bytes or 32 bytes that are not all-zero. */ function checkSuccess( ) private pure returns (bool) { uint256 returnValue = 0; /* solium-disable-next-line security/no-inline-assembly */ assembly { // check number of bytes returned from last function call switch returndatasize // no bytes returned: assume success case 0x0 { returnValue := 1 } // 32 bytes returned: check if non-zero case 0x20 { // copy 32 bytes into scratch space returndatacopy(0x0, 0x0, 0x20) // load those bytes into returnValue returnValue := mload(0x0) } // not sure what was returned: don't mark as success default { } } return returnValue != 0; } } // File: contracts/protocol/interfaces/IInterestSetter.sol /** * @title IInterestSetter * @author dYdX * * Interface that Interest Setters for Solo must implement in order to report interest rates. */ interface IInterestSetter { // ============ Public Functions ============ /** * Get the interest rate of a token given some borrowed and supplied amounts * * @param token The address of the ERC20 token for the market * @param borrowWei The total borrowed token amount for the market * @param supplyWei The total supplied token amount for the market * @return The interest rate per second */ function getInterestRate( address token, uint256 borrowWei, uint256 supplyWei ) external view returns (Interest.Rate memory); } // File: contracts/protocol/interfaces/IPriceOracle.sol /** * @title IPriceOracle * @author dYdX * * Interface that Price Oracles for Solo must implement in order to report prices. */ contract IPriceOracle { // ============ Constants ============ uint256 public constant ONE_DOLLAR = 10 ** 36; // ============ Public Functions ============ /** * Get the price of a token * * @param token The ERC20 token address of the market * @return The USD price of a base unit of the token, then multiplied by 10^36. * So a USD-stable coin with 18 decimal places would return 10^18. * This is the price of the base unit rather than the price of a "human-readable" * token amount. Every ERC20 may have a different number of decimals. */ function getPrice( address token ) public view returns (Monetary.Price memory); } // File: contracts/protocol/lib/Storage.sol /** * @title Storage * @author dYdX * * Functions for reading, writing, and verifying state in Solo */ library Storage { using Cache for Cache.MarketCache; using Storage for Storage.State; using Math for uint256; using Types for Types.Par; using Types for Types.Wei; using SafeMath for uint256; // ============ Constants ============ bytes32 constant FILE = "Storage"; // ============ Structs ============ // All information necessary for tracking a market struct Market { // Contract address of the associated ERC20 token address token; // Total aggregated supply and borrow amount of the entire market Types.TotalPar totalPar; // Interest index of the market Interest.Index index; // Contract address of the price oracle for this market IPriceOracle priceOracle; // Contract address of the interest setter for this market IInterestSetter interestSetter; // Multiplier on the marginRatio for this market Decimal.D256 marginPremium; // Multiplier on the liquidationSpread for this market Decimal.D256 spreadPremium; // Whether additional borrows are allowed for this market bool isClosing; } // The global risk parameters that govern the health and security of the system struct RiskParams { // Required ratio of over-collateralization Decimal.D256 marginRatio; // Percentage penalty incurred by liquidated accounts Decimal.D256 liquidationSpread; // Percentage of the borrower's interest fee that gets passed to the suppliers Decimal.D256 earningsRate; // The minimum absolute borrow value of an account // There must be sufficient incentivize to liquidate undercollateralized accounts Monetary.Value minBorrowedValue; } // The maximum RiskParam values that can be set struct RiskLimits { uint64 marginRatioMax; uint64 liquidationSpreadMax; uint64 earningsRateMax; uint64 marginPremiumMax; uint64 spreadPremiumMax; uint128 minBorrowedValueMax; } // The entire storage state of Solo struct State { // number of markets uint256 numMarkets; // marketId => Market mapping (uint256 => Market) markets; // owner => account number => Account mapping (address => mapping (uint256 => Account.Storage)) accounts; // Addresses that can control other users accounts mapping (address => mapping (address => bool)) operators; // Addresses that can control all users accounts mapping (address => bool) globalOperators; // mutable risk parameters of the system RiskParams riskParams; // immutable risk limits of the system RiskLimits riskLimits; } // ============ Functions ============ function getToken( Storage.State storage state, uint256 marketId ) internal view returns (address) { return state.markets[marketId].token; } function getTotalPar( Storage.State storage state, uint256 marketId ) internal view returns (Types.TotalPar memory) { return state.markets[marketId].totalPar; } function getIndex( Storage.State storage state, uint256 marketId ) internal view returns (Interest.Index memory) { return state.markets[marketId].index; } function getNumExcessTokens( Storage.State storage state, uint256 marketId ) internal view returns (Types.Wei memory) { Interest.Index memory index = state.getIndex(marketId); Types.TotalPar memory totalPar = state.getTotalPar(marketId); address token = state.getToken(marketId); Types.Wei memory balanceWei = Types.Wei({ sign: true, value: Token.balanceOf(token, address(this)) }); ( Types.Wei memory supplyWei, Types.Wei memory borrowWei ) = Interest.totalParToWei(totalPar, index); // borrowWei is negative, so subtracting it makes the value more positive return balanceWei.sub(borrowWei).sub(supplyWei); } function getStatus( Storage.State storage state, Account.Info memory account ) internal view returns (Account.Status) { return state.accounts[account.owner][account.number].status; } function getPar( Storage.State storage state, Account.Info memory account, uint256 marketId ) internal view returns (Types.Par memory) { return state.accounts[account.owner][account.number].balances[marketId]; } function getWei( Storage.State storage state, Account.Info memory account, uint256 marketId ) internal view returns (Types.Wei memory) { Types.Par memory par = state.getPar(account, marketId); if (par.isZero()) { return Types.zeroWei(); } Interest.Index memory index = state.getIndex(marketId); return Interest.parToWei(par, index); } function getLiquidationSpreadForPair( Storage.State storage state, uint256 heldMarketId, uint256 owedMarketId ) internal view returns (Decimal.D256 memory) { uint256 result = state.riskParams.liquidationSpread.value; result = Decimal.mul(result, Decimal.onePlus(state.markets[heldMarketId].spreadPremium)); result = Decimal.mul(result, Decimal.onePlus(state.markets[owedMarketId].spreadPremium)); return Decimal.D256({ value: result }); } function fetchNewIndex( Storage.State storage state, uint256 marketId, Interest.Index memory index ) internal view returns (Interest.Index memory) { Interest.Rate memory rate = state.fetchInterestRate(marketId, index); return Interest.calculateNewIndex( index, rate, state.getTotalPar(marketId), state.riskParams.earningsRate ); } function fetchInterestRate( Storage.State storage state, uint256 marketId, Interest.Index memory index ) internal view returns (Interest.Rate memory) { Types.TotalPar memory totalPar = state.getTotalPar(marketId); ( Types.Wei memory supplyWei, Types.Wei memory borrowWei ) = Interest.totalParToWei(totalPar, index); Interest.Rate memory rate = state.markets[marketId].interestSetter.getInterestRate( state.getToken(marketId), borrowWei.value, supplyWei.value ); return rate; } function fetchPrice( Storage.State storage state, uint256 marketId ) internal view returns (Monetary.Price memory) { IPriceOracle oracle = IPriceOracle(state.markets[marketId].priceOracle); Monetary.Price memory price = oracle.getPrice(state.getToken(marketId)); Require.that( price.value != 0, FILE, "Price cannot be zero", marketId ); return price; } function getAccountValues( Storage.State storage state, Account.Info memory account, Cache.MarketCache memory cache, bool adjustForLiquidity ) internal view returns (Monetary.Value memory, Monetary.Value memory) { Monetary.Value memory supplyValue; Monetary.Value memory borrowValue; uint256 numMarkets = cache.getNumMarkets(); for (uint256 m = 0; m < numMarkets; m++) { if (!cache.hasMarket(m)) { continue; } Types.Wei memory userWei = state.getWei(account, m); if (userWei.isZero()) { continue; } uint256 assetValue = userWei.value.mul(cache.getPrice(m).value); Decimal.D256 memory adjust = Decimal.one(); if (adjustForLiquidity) { adjust = Decimal.onePlus(state.markets[m].marginPremium); } if (userWei.sign) { supplyValue.value = supplyValue.value.add(Decimal.div(assetValue, adjust)); } else { borrowValue.value = borrowValue.value.add(Decimal.mul(assetValue, adjust)); } } return (supplyValue, borrowValue); } function isCollateralized( Storage.State storage state, Account.Info memory account, Cache.MarketCache memory cache, bool requireMinBorrow ) internal view returns (bool) { // get account values (adjusted for liquidity) ( Monetary.Value memory supplyValue, Monetary.Value memory borrowValue ) = state.getAccountValues(account, cache, /* adjustForLiquidity = */ true); if (borrowValue.value == 0) { return true; } if (requireMinBorrow) { Require.that( borrowValue.value >= state.riskParams.minBorrowedValue.value, FILE, "Borrow value too low", account.owner, account.number, borrowValue.value ); } uint256 requiredMargin = Decimal.mul(borrowValue.value, state.riskParams.marginRatio); return supplyValue.value >= borrowValue.value.add(requiredMargin); } function isGlobalOperator( Storage.State storage state, address operator ) internal view returns (bool) { return state.globalOperators[operator]; } function isLocalOperator( Storage.State storage state, address owner, address operator ) internal view returns (bool) { return state.operators[owner][operator]; } function requireIsOperator( Storage.State storage state, Account.Info memory account, address operator ) internal view { bool isValidOperator = operator == account.owner || state.isGlobalOperator(operator) || state.isLocalOperator(account.owner, operator); Require.that( isValidOperator, FILE, "Unpermissioned operator", operator ); } /** * Determine and set an account's balance based on the intended balance change. Return the * equivalent amount in wei */ function getNewParAndDeltaWei( Storage.State storage state, Account.Info memory account, uint256 marketId, Types.AssetAmount memory amount ) internal view returns (Types.Par memory, Types.Wei memory) { Types.Par memory oldPar = state.getPar(account, marketId); if (amount.value == 0 && amount.ref == Types.AssetReference.Delta) { return (oldPar, Types.zeroWei()); } Interest.Index memory index = state.getIndex(marketId); Types.Wei memory oldWei = Interest.parToWei(oldPar, index); Types.Par memory newPar; Types.Wei memory deltaWei; if (amount.denomination == Types.AssetDenomination.Wei) { deltaWei = Types.Wei({ sign: amount.sign, value: amount.value }); if (amount.ref == Types.AssetReference.Target) { deltaWei = deltaWei.sub(oldWei); } newPar = Interest.weiToPar(oldWei.add(deltaWei), index); } else { // AssetDenomination.Par newPar = Types.Par({ sign: amount.sign, value: amount.value.to128() }); if (amount.ref == Types.AssetReference.Delta) { newPar = oldPar.add(newPar); } deltaWei = Interest.parToWei(newPar, index).sub(oldWei); } return (newPar, deltaWei); } function getNewParAndDeltaWeiForLiquidation( Storage.State storage state, Account.Info memory account, uint256 marketId, Types.AssetAmount memory amount ) internal view returns (Types.Par memory, Types.Wei memory) { Types.Par memory oldPar = state.getPar(account, marketId); Require.that( !oldPar.isPositive(), FILE, "Owed balance cannot be positive", account.owner, account.number, marketId ); ( Types.Par memory newPar, Types.Wei memory deltaWei ) = state.getNewParAndDeltaWei( account, marketId, amount ); // if attempting to over-repay the owed asset, bound it by the maximum if (newPar.isPositive()) { newPar = Types.zeroPar(); deltaWei = state.getWei(account, marketId).negative(); } Require.that( !deltaWei.isNegative() && oldPar.value >= newPar.value, FILE, "Owed balance cannot increase", account.owner, account.number, marketId ); // if not paying back enough wei to repay any par, then bound wei to zero if (oldPar.equals(newPar)) { deltaWei = Types.zeroWei(); } return (newPar, deltaWei); } function isVaporizable( Storage.State storage state, Account.Info memory account, Cache.MarketCache memory cache ) internal view returns (bool) { bool hasNegative = false; uint256 numMarkets = cache.getNumMarkets(); for (uint256 m = 0; m < numMarkets; m++) { if (!cache.hasMarket(m)) { continue; } Types.Par memory par = state.getPar(account, m); if (par.isZero()) { continue; } else if (par.sign) { return false; } else { hasNegative = true; } } return hasNegative; } // =============== Setter Functions =============== function updateIndex( Storage.State storage state, uint256 marketId ) internal returns (Interest.Index memory) { Interest.Index memory index = state.getIndex(marketId); if (index.lastUpdate == Time.currentTime()) { return index; } return state.markets[marketId].index = state.fetchNewIndex(marketId, index); } function setStatus( Storage.State storage state, Account.Info memory account, Account.Status status ) internal { state.accounts[account.owner][account.number].status = status; } function setPar( Storage.State storage state, Account.Info memory account, uint256 marketId, Types.Par memory newPar ) internal { Types.Par memory oldPar = state.getPar(account, marketId); if (Types.equals(oldPar, newPar)) { return; } // updateTotalPar Types.TotalPar memory totalPar = state.getTotalPar(marketId); // roll-back oldPar if (oldPar.sign) { totalPar.supply = uint256(totalPar.supply).sub(oldPar.value).to128(); } else { totalPar.borrow = uint256(totalPar.borrow).sub(oldPar.value).to128(); } // roll-forward newPar if (newPar.sign) { totalPar.supply = uint256(totalPar.supply).add(newPar.value).to128(); } else { totalPar.borrow = uint256(totalPar.borrow).add(newPar.value).to128(); } state.markets[marketId].totalPar = totalPar; state.accounts[account.owner][account.number].balances[marketId] = newPar; } /** * Determine and set an account's balance based on a change in wei */ function setParFromDeltaWei( Storage.State storage state, Account.Info memory account, uint256 marketId, Types.Wei memory deltaWei ) internal { if (deltaWei.isZero()) { return; } Interest.Index memory index = state.getIndex(marketId); Types.Wei memory oldWei = state.getWei(account, marketId); Types.Wei memory newWei = oldWei.add(deltaWei); Types.Par memory newPar = Interest.weiToPar(newWei, index); state.setPar( account, marketId, newPar ); } } // File: contracts/protocol/State.sol /** * @title State * @author dYdX * * Base-level contract that holds the state of Solo */ contract State { Storage.State g_state; } // File: contracts/protocol/impl/AdminImpl.sol /** * @title AdminImpl * @author dYdX * * Administrative functions to keep the protocol updated */ library AdminImpl { using Storage for Storage.State; using Token for address; using Types for Types.Wei; // ============ Constants ============ bytes32 constant FILE = "AdminImpl"; // ============ Events ============ event LogWithdrawExcessTokens( address token, uint256 amount ); event LogAddMarket( uint256 marketId, address token ); event LogSetIsClosing( uint256 marketId, bool isClosing ); event LogSetPriceOracle( uint256 marketId, address priceOracle ); event LogSetInterestSetter( uint256 marketId, address interestSetter ); event LogSetMarginPremium( uint256 marketId, Decimal.D256 marginPremium ); event LogSetSpreadPremium( uint256 marketId, Decimal.D256 spreadPremium ); event LogSetMarginRatio( Decimal.D256 marginRatio ); event LogSetLiquidationSpread( Decimal.D256 liquidationSpread ); event LogSetEarningsRate( Decimal.D256 earningsRate ); event LogSetMinBorrowedValue( Monetary.Value minBorrowedValue ); event LogSetGlobalOperator( address operator, bool approved ); // ============ Token Functions ============ function ownerWithdrawExcessTokens( Storage.State storage state, uint256 marketId, address recipient ) public returns (uint256) { _validateMarketId(state, marketId); Types.Wei memory excessWei = state.getNumExcessTokens(marketId); Require.that( !excessWei.isNegative(), FILE, "Negative excess" ); address token = state.getToken(marketId); uint256 actualBalance = token.balanceOf(address(this)); if (excessWei.value > actualBalance) { excessWei.value = actualBalance; } token.transfer(recipient, excessWei.value); emit LogWithdrawExcessTokens(token, excessWei.value); return excessWei.value; } function ownerWithdrawUnsupportedTokens( Storage.State storage state, address token, address recipient ) public returns (uint256) { _requireNoMarket(state, token); uint256 balance = token.balanceOf(address(this)); token.transfer(recipient, balance); emit LogWithdrawExcessTokens(token, balance); return balance; } // ============ Market Functions ============ function ownerAddMarket( Storage.State storage state, address token, IPriceOracle priceOracle, IInterestSetter interestSetter, Decimal.D256 memory marginPremium, Decimal.D256 memory spreadPremium ) public { _requireNoMarket(state, token); uint256 marketId = state.numMarkets; state.numMarkets++; state.markets[marketId].token = token; state.markets[marketId].index = Interest.newIndex(); emit LogAddMarket(marketId, token); _setPriceOracle(state, marketId, priceOracle); _setInterestSetter(state, marketId, interestSetter); _setMarginPremium(state, marketId, marginPremium); _setSpreadPremium(state, marketId, spreadPremium); } function ownerSetIsClosing( Storage.State storage state, uint256 marketId, bool isClosing ) public { _validateMarketId(state, marketId); state.markets[marketId].isClosing = isClosing; emit LogSetIsClosing(marketId, isClosing); } function ownerSetPriceOracle( Storage.State storage state, uint256 marketId, IPriceOracle priceOracle ) public { _validateMarketId(state, marketId); _setPriceOracle(state, marketId, priceOracle); } function ownerSetInterestSetter( Storage.State storage state, uint256 marketId, IInterestSetter interestSetter ) public { _validateMarketId(state, marketId); _setInterestSetter(state, marketId, interestSetter); } function ownerSetMarginPremium( Storage.State storage state, uint256 marketId, Decimal.D256 memory marginPremium ) public { _validateMarketId(state, marketId); _setMarginPremium(state, marketId, marginPremium); } function ownerSetSpreadPremium( Storage.State storage state, uint256 marketId, Decimal.D256 memory spreadPremium ) public { _validateMarketId(state, marketId); _setSpreadPremium(state, marketId, spreadPremium); } // ============ Risk Functions ============ function ownerSetMarginRatio( Storage.State storage state, Decimal.D256 memory ratio ) public { Require.that( ratio.value <= state.riskLimits.marginRatioMax, FILE, "Ratio too high" ); Require.that( ratio.value > state.riskParams.liquidationSpread.value, FILE, "Ratio cannot be <= spread" ); state.riskParams.marginRatio = ratio; emit LogSetMarginRatio(ratio); } function ownerSetLiquidationSpread( Storage.State storage state, Decimal.D256 memory spread ) public { Require.that( spread.value <= state.riskLimits.liquidationSpreadMax, FILE, "Spread too high" ); Require.that( spread.value < state.riskParams.marginRatio.value, FILE, "Spread cannot be >= ratio" ); state.riskParams.liquidationSpread = spread; emit LogSetLiquidationSpread(spread); } function ownerSetEarningsRate( Storage.State storage state, Decimal.D256 memory earningsRate ) public { Require.that( earningsRate.value <= state.riskLimits.earningsRateMax, FILE, "Rate too high" ); state.riskParams.earningsRate = earningsRate; emit LogSetEarningsRate(earningsRate); } function ownerSetMinBorrowedValue( Storage.State storage state, Monetary.Value memory minBorrowedValue ) public { Require.that( minBorrowedValue.value <= state.riskLimits.minBorrowedValueMax, FILE, "Value too high" ); state.riskParams.minBorrowedValue = minBorrowedValue; emit LogSetMinBorrowedValue(minBorrowedValue); } // ============ Global Operator Functions ============ function ownerSetGlobalOperator( Storage.State storage state, address operator, bool approved ) public { state.globalOperators[operator] = approved; emit LogSetGlobalOperator(operator, approved); } // ============ Private Functions ============ function _setPriceOracle( Storage.State storage state, uint256 marketId, IPriceOracle priceOracle ) private { // require oracle can return non-zero price address token = state.markets[marketId].token; Require.that( priceOracle.getPrice(token).value != 0, FILE, "Invalid oracle price" ); state.markets[marketId].priceOracle = priceOracle; emit LogSetPriceOracle(marketId, address(priceOracle)); } function _setInterestSetter( Storage.State storage state, uint256 marketId, IInterestSetter interestSetter ) private { // ensure interestSetter can return a value without reverting address token = state.markets[marketId].token; interestSetter.getInterestRate(token, 0, 0); state.markets[marketId].interestSetter = interestSetter; emit LogSetInterestSetter(marketId, address(interestSetter)); } function _setMarginPremium( Storage.State storage state, uint256 marketId, Decimal.D256 memory marginPremium ) private { Require.that( marginPremium.value <= state.riskLimits.marginPremiumMax, FILE, "Margin premium too high" ); state.markets[marketId].marginPremium = marginPremium; emit LogSetMarginPremium(marketId, marginPremium); } function _setSpreadPremium( Storage.State storage state, uint256 marketId, Decimal.D256 memory spreadPremium ) private { Require.that( spreadPremium.value <= state.riskLimits.spreadPremiumMax, FILE, "Spread premium too high" ); state.markets[marketId].spreadPremium = spreadPremium; emit LogSetSpreadPremium(marketId, spreadPremium); } function _requireNoMarket( Storage.State storage state, address token ) private view { uint256 numMarkets = state.numMarkets; bool marketExists = false; for (uint256 m = 0; m < numMarkets; m++) { if (state.markets[m].token == token) { marketExists = true; break; } } Require.that( !marketExists, FILE, "Market exists" ); } function _validateMarketId( Storage.State storage state, uint256 marketId ) private view { Require.that( marketId < state.numMarkets, FILE, "Market OOB", marketId ); } } // File: contracts/protocol/Admin.sol /** * @title Admin * @author dYdX * * Public functions that allow the privileged owner address to manage Solo */ contract Admin is State, Ownable, ReentrancyGuard { // ============ Token Functions ============ /** * Withdraw an ERC20 token for which there is an associated market. Only excess tokens can be * withdrawn. The number of excess tokens is calculated by taking the current number of tokens * held in Solo, adding the number of tokens owed to Solo by borrowers, and subtracting the * number of tokens owed to suppliers by Solo. */ function ownerWithdrawExcessTokens( uint256 marketId, address recipient ) public onlyOwner nonReentrant returns (uint256) { return AdminImpl.ownerWithdrawExcessTokens( g_state, marketId, recipient ); } /** * Withdraw an ERC20 token for which there is no associated market. */ function ownerWithdrawUnsupportedTokens( address token, address recipient ) public onlyOwner nonReentrant returns (uint256) { return AdminImpl.ownerWithdrawUnsupportedTokens( g_state, token, recipient ); } // ============ Market Functions ============ /** * Add a new market to Solo. Must be for a previously-unsupported ERC20 token. */ function ownerAddMarket( address token, IPriceOracle priceOracle, IInterestSetter interestSetter, Decimal.D256 memory marginPremium, Decimal.D256 memory spreadPremium ) public onlyOwner nonReentrant { AdminImpl.ownerAddMarket( g_state, token, priceOracle, interestSetter, marginPremium, spreadPremium ); } /** * Set (or unset) the status of a market to "closing". The borrowedValue of a market cannot * increase while its status is "closing". */ function ownerSetIsClosing( uint256 marketId, bool isClosing ) public onlyOwner nonReentrant { AdminImpl.ownerSetIsClosing( g_state, marketId, isClosing ); } /** * Set the price oracle for a market. */ function ownerSetPriceOracle( uint256 marketId, IPriceOracle priceOracle ) public onlyOwner nonReentrant { AdminImpl.ownerSetPriceOracle( g_state, marketId, priceOracle ); } /** * Set the interest-setter for a market. */ function ownerSetInterestSetter( uint256 marketId, IInterestSetter interestSetter ) public onlyOwner nonReentrant { AdminImpl.ownerSetInterestSetter( g_state, marketId, interestSetter ); } /** * Set a premium on the minimum margin-ratio for a market. This makes it so that any positions * that include this market require a higher collateralization to avoid being liquidated. */ function ownerSetMarginPremium( uint256 marketId, Decimal.D256 memory marginPremium ) public onlyOwner nonReentrant { AdminImpl.ownerSetMarginPremium( g_state, marketId, marginPremium ); } /** * Set a premium on the liquidation spread for a market. This makes it so that any liquidations * that include this market have a higher spread than the global default. */ function ownerSetSpreadPremium( uint256 marketId, Decimal.D256 memory spreadPremium ) public onlyOwner nonReentrant { AdminImpl.ownerSetSpreadPremium( g_state, marketId, spreadPremium ); } // ============ Risk Functions ============ /** * Set the global minimum margin-ratio that every position must maintain to prevent being * liquidated. */ function ownerSetMarginRatio( Decimal.D256 memory ratio ) public onlyOwner nonReentrant { AdminImpl.ownerSetMarginRatio( g_state, ratio ); } /** * Set the global liquidation spread. This is the spread between oracle prices that incentivizes * the liquidation of risky positions. */ function ownerSetLiquidationSpread( Decimal.D256 memory spread ) public onlyOwner nonReentrant { AdminImpl.ownerSetLiquidationSpread( g_state, spread ); } /** * Set the global earnings-rate variable that determines what percentage of the interest paid * by borrowers gets passed-on to suppliers. */ function ownerSetEarningsRate( Decimal.D256 memory earningsRate ) public onlyOwner nonReentrant { AdminImpl.ownerSetEarningsRate( g_state, earningsRate ); } /** * Set the global minimum-borrow value which is the minimum value of any new borrow on Solo. */ function ownerSetMinBorrowedValue( Monetary.Value memory minBorrowedValue ) public onlyOwner nonReentrant { AdminImpl.ownerSetMinBorrowedValue( g_state, minBorrowedValue ); } // ============ Global Operator Functions ============ /** * Approve (or disapprove) an address that is permissioned to be an operator for all accounts in * Solo. Intended only to approve smart-contracts. */ function ownerSetGlobalOperator( address operator, bool approved ) public onlyOwner nonReentrant { AdminImpl.ownerSetGlobalOperator( g_state, operator, approved ); } } // File: contracts/protocol/Getters.sol /** * @title Getters * @author dYdX * * Public read-only functions that allow transparency into the state of Solo */ contract Getters is State { using Cache for Cache.MarketCache; using Storage for Storage.State; using Types for Types.Par; // ============ Constants ============ bytes32 FILE = "Getters"; // ============ Getters for Risk ============ /** * Get the global minimum margin-ratio that every position must maintain to prevent being * liquidated. * * @return The global margin-ratio */ function getMarginRatio() public view returns (Decimal.D256 memory) { return g_state.riskParams.marginRatio; } /** * Get the global liquidation spread. This is the spread between oracle prices that incentivizes * the liquidation of risky positions. * * @return The global liquidation spread */ function getLiquidationSpread() public view returns (Decimal.D256 memory) { return g_state.riskParams.liquidationSpread; } /** * Get the global earnings-rate variable that determines what percentage of the interest paid * by borrowers gets passed-on to suppliers. * * @return The global earnings rate */ function getEarningsRate() public view returns (Decimal.D256 memory) { return g_state.riskParams.earningsRate; } /** * Get the global minimum-borrow value which is the minimum value of any new borrow on Solo. * * @return The global minimum borrow value */ function getMinBorrowedValue() public view returns (Monetary.Value memory) { return g_state.riskParams.minBorrowedValue; } /** * Get all risk parameters in a single struct. * * @return All global risk parameters */ function getRiskParams() public view returns (Storage.RiskParams memory) { return g_state.riskParams; } /** * Get all risk parameter limits in a single struct. These are the maximum limits at which the * risk parameters can be set by the admin of Solo. * * @return All global risk parameter limnits */ function getRiskLimits() public view returns (Storage.RiskLimits memory) { return g_state.riskLimits; } // ============ Getters for Markets ============ /** * Get the total number of markets. * * @return The number of markets */ function getNumMarkets() public view returns (uint256) { return g_state.numMarkets; } /** * Get the ERC20 token address for a market. * * @param marketId The market to query * @return The token address */ function getMarketTokenAddress( uint256 marketId ) public view returns (address) { _requireValidMarket(marketId); return g_state.getToken(marketId); } /** * Get the total principal amounts (borrowed and supplied) for a market. * * @param marketId The market to query * @return The total principal amounts */ function getMarketTotalPar( uint256 marketId ) public view returns (Types.TotalPar memory) { _requireValidMarket(marketId); return g_state.getTotalPar(marketId); } /** * Get the most recently cached interest index for a market. * * @param marketId The market to query * @return The most recent index */ function getMarketCachedIndex( uint256 marketId ) public view returns (Interest.Index memory) { _requireValidMarket(marketId); return g_state.getIndex(marketId); } /** * Get the interest index for a market if it were to be updated right now. * * @param marketId The market to query * @return The estimated current index */ function getMarketCurrentIndex( uint256 marketId ) public view returns (Interest.Index memory) { _requireValidMarket(marketId); return g_state.fetchNewIndex(marketId, g_state.getIndex(marketId)); } /** * Get the price oracle address for a market. * * @param marketId The market to query * @return The price oracle address */ function getMarketPriceOracle( uint256 marketId ) public view returns (IPriceOracle) { _requireValidMarket(marketId); return g_state.markets[marketId].priceOracle; } /** * Get the interest-setter address for a market. * * @param marketId The market to query * @return The interest-setter address */ function getMarketInterestSetter( uint256 marketId ) public view returns (IInterestSetter) { _requireValidMarket(marketId); return g_state.markets[marketId].interestSetter; } /** * Get the margin premium for a market. A margin premium makes it so that any positions that * include the market require a higher collateralization to avoid being liquidated. * * @param marketId The market to query * @return The market's margin premium */ function getMarketMarginPremium( uint256 marketId ) public view returns (Decimal.D256 memory) { _requireValidMarket(marketId); return g_state.markets[marketId].marginPremium; } /** * Get the spread premium for a market. A spread premium makes it so that any liquidations * that include the market have a higher spread than the global default. * * @param marketId The market to query * @return The market's spread premium */ function getMarketSpreadPremium( uint256 marketId ) public view returns (Decimal.D256 memory) { _requireValidMarket(marketId); return g_state.markets[marketId].spreadPremium; } /** * Return true if a particular market is in closing mode. Additional borrows cannot be taken * from a market that is closing. * * @param marketId The market to query * @return True if the market is closing */ function getMarketIsClosing( uint256 marketId ) public view returns (bool) { _requireValidMarket(marketId); return g_state.markets[marketId].isClosing; } /** * Get the price of the token for a market. * * @param marketId The market to query * @return The price of each atomic unit of the token */ function getMarketPrice( uint256 marketId ) public view returns (Monetary.Price memory) { _requireValidMarket(marketId); return g_state.fetchPrice(marketId); } /** * Get the current borrower interest rate for a market. * * @param marketId The market to query * @return The current interest rate */ function getMarketInterestRate( uint256 marketId ) public view returns (Interest.Rate memory) { _requireValidMarket(marketId); return g_state.fetchInterestRate( marketId, g_state.getIndex(marketId) ); } /** * Get the adjusted liquidation spread for some market pair. This is equal to the global * liquidation spread multiplied by (1 + spreadPremium) for each of the two markets. * * @param heldMarketId The market for which the account has collateral * @param owedMarketId The market for which the account has borrowed tokens * @return The adjusted liquidation spread */ function getLiquidationSpreadForPair( uint256 heldMarketId, uint256 owedMarketId ) public view returns (Decimal.D256 memory) { _requireValidMarket(heldMarketId); _requireValidMarket(owedMarketId); return g_state.getLiquidationSpreadForPair(heldMarketId, owedMarketId); } /** * Get basic information about a particular market. * * @param marketId The market to query * @return A Storage.Market struct with the current state of the market */ function getMarket( uint256 marketId ) public view returns (Storage.Market memory) { _requireValidMarket(marketId); return g_state.markets[marketId]; } /** * Get comprehensive information about a particular market. * * @param marketId The market to query * @return A tuple containing the values: * - A Storage.Market struct with the current state of the market * - The current estimated interest index * - The current token price * - The current market interest rate */ function getMarketWithInfo( uint256 marketId ) public view returns ( Storage.Market memory, Interest.Index memory, Monetary.Price memory, Interest.Rate memory ) { _requireValidMarket(marketId); return ( getMarket(marketId), getMarketCurrentIndex(marketId), getMarketPrice(marketId), getMarketInterestRate(marketId) ); } /** * Get the number of excess tokens for a market. The number of excess tokens is calculated * by taking the current number of tokens held in Solo, adding the number of tokens owed to Solo * by borrowers, and subtracting the number of tokens owed to suppliers by Solo. * * @param marketId The market to query * @return The number of excess tokens */ function getNumExcessTokens( uint256 marketId ) public view returns (Types.Wei memory) { _requireValidMarket(marketId); return g_state.getNumExcessTokens(marketId); } // ============ Getters for Accounts ============ /** * Get the principal value for a particular account and market. * * @param account The account to query * @param marketId The market to query * @return The principal value */ function getAccountPar( Account.Info memory account, uint256 marketId ) public view returns (Types.Par memory) { _requireValidMarket(marketId); return g_state.getPar(account, marketId); } /** * Get the token balance for a particular account and market. * * @param account The account to query * @param marketId The market to query * @return The token amount */ function getAccountWei( Account.Info memory account, uint256 marketId ) public view returns (Types.Wei memory) { _requireValidMarket(marketId); return Interest.parToWei( g_state.getPar(account, marketId), g_state.fetchNewIndex(marketId, g_state.getIndex(marketId)) ); } /** * Get the status of an account (Normal, Liquidating, or Vaporizing). * * @param account The account to query * @return The account's status */ function getAccountStatus( Account.Info memory account ) public view returns (Account.Status) { return g_state.getStatus(account); } /** * Get the total supplied and total borrowed value of an account. * * @param account The account to query * @return The following values: * - The supplied value of the account * - The borrowed value of the account */ function getAccountValues( Account.Info memory account ) public view returns (Monetary.Value memory, Monetary.Value memory) { return getAccountValuesInternal(account, /* adjustForLiquidity = */ false); } /** * Get the total supplied and total borrowed values of an account adjusted by the marginPremium * of each market. Supplied values are divided by (1 + marginPremium) for each market and * borrowed values are multiplied by (1 + marginPremium) for each market. Comparing these * adjusted values gives the margin-ratio of the account which will be compared to the global * margin-ratio when determining if the account can be liquidated. * * @param account The account to query * @return The following values: * - The supplied value of the account (adjusted for marginPremium) * - The borrowed value of the account (adjusted for marginPremium) */ function getAdjustedAccountValues( Account.Info memory account ) public view returns (Monetary.Value memory, Monetary.Value memory) { return getAccountValuesInternal(account, /* adjustForLiquidity = */ true); } /** * Get an account's summary for each market. * * @param account The account to query * @return The following values: * - The ERC20 token address for each market * - The account's principal value for each market * - The account's (supplied or borrowed) number of tokens for each market */ function getAccountBalances( Account.Info memory account ) public view returns ( address[] memory, Types.Par[] memory, Types.Wei[] memory ) { uint256 numMarkets = g_state.numMarkets; address[] memory tokens = new address[](numMarkets); Types.Par[] memory pars = new Types.Par[](numMarkets); Types.Wei[] memory weis = new Types.Wei[](numMarkets); for (uint256 m = 0; m < numMarkets; m++) { tokens[m] = getMarketTokenAddress(m); pars[m] = getAccountPar(account, m); weis[m] = getAccountWei(account, m); } return ( tokens, pars, weis ); } // ============ Getters for Permissions ============ /** * Return true if a particular address is approved as an operator for an owner's accounts. * Approved operators can act on the accounts of the owner as if it were the operator's own. * * @param owner The owner of the accounts * @param operator The possible operator * @return True if operator is approved for owner's accounts */ function getIsLocalOperator( address owner, address operator ) public view returns (bool) { return g_state.isLocalOperator(owner, operator); } /** * Return true if a particular address is approved as a global operator. Such an address can * act on any account as if it were the operator's own. * * @param operator The address to query * @return True if operator is a global operator */ function getIsGlobalOperator( address operator ) public view returns (bool) { return g_state.isGlobalOperator(operator); } // ============ Private Helper Functions ============ /** * Revert if marketId is invalid. */ function _requireValidMarket( uint256 marketId ) private view { Require.that( marketId < g_state.numMarkets, FILE, "Market OOB" ); } /** * Private helper for getting the monetary values of an account. */ function getAccountValuesInternal( Account.Info memory account, bool adjustForLiquidity ) private view returns (Monetary.Value memory, Monetary.Value memory) { uint256 numMarkets = g_state.numMarkets; // populate cache Cache.MarketCache memory cache = Cache.create(numMarkets); for (uint256 m = 0; m < numMarkets; m++) { if (!g_state.getPar(account, m).isZero()) { cache.addMarket(g_state, m); } } return g_state.getAccountValues(account, cache, adjustForLiquidity); } } // File: contracts/protocol/lib/Actions.sol /** * @title Actions * @author dYdX * * Library that defines and parses valid Actions */ library Actions { // ============ Constants ============ bytes32 constant FILE = "Actions"; // ============ Enums ============ enum ActionType { Deposit, // supply tokens Withdraw, // borrow tokens Transfer, // transfer balance between accounts Buy, // buy an amount of some token (externally) Sell, // sell an amount of some token (externally) Trade, // trade tokens against another account Liquidate, // liquidate an undercollateralized or expiring account Vaporize, // use excess tokens to zero-out a completely negative account Call // send arbitrary data to an address } enum AccountLayout { OnePrimary, TwoPrimary, PrimaryAndSecondary } enum MarketLayout { ZeroMarkets, OneMarket, TwoMarkets } // ============ Structs ============ /* * Arguments that are passed to Solo in an ordered list as part of a single operation. * Each ActionArgs has an actionType which specifies which action struct that this data will be * parsed into before being processed. */ struct ActionArgs { ActionType actionType; uint256 accountId; Types.AssetAmount amount; uint256 primaryMarketId; uint256 secondaryMarketId; address otherAddress; uint256 otherAccountId; bytes data; } // ============ Action Types ============ /* * Moves tokens from an address to Solo. Can either repay a borrow or provide additional supply. */ struct DepositArgs { Types.AssetAmount amount; Account.Info account; uint256 market; address from; } /* * Moves tokens from Solo to another address. Can either borrow tokens or reduce the amount * previously supplied. */ struct WithdrawArgs { Types.AssetAmount amount; Account.Info account; uint256 market; address to; } /* * Transfers balance between two accounts. The msg.sender must be an operator for both accounts. * The amount field applies to accountOne. * This action does not require any token movement since the trade is done internally to Solo. */ struct TransferArgs { Types.AssetAmount amount; Account.Info accountOne; Account.Info accountTwo; uint256 market; } /* * Acquires a certain amount of tokens by spending other tokens. Sends takerMarket tokens to the * specified exchangeWrapper contract and expects makerMarket tokens in return. The amount field * applies to the makerMarket. */ struct BuyArgs { Types.AssetAmount amount; Account.Info account; uint256 makerMarket; uint256 takerMarket; address exchangeWrapper; bytes orderData; } /* * Spends a certain amount of tokens to acquire other tokens. Sends takerMarket tokens to the * specified exchangeWrapper and expects makerMarket tokens in return. The amount field applies * to the takerMarket. */ struct SellArgs { Types.AssetAmount amount; Account.Info account; uint256 takerMarket; uint256 makerMarket; address exchangeWrapper; bytes orderData; } /* * Trades balances between two accounts using any external contract that implements the * AutoTrader interface. The AutoTrader contract must be an operator for the makerAccount (for * which it is trading on-behalf-of). The amount field applies to the makerAccount and the * inputMarket. This proposed change to the makerAccount is passed to the AutoTrader which will * quote a change for the makerAccount in the outputMarket (or will disallow the trade). * This action does not require any token movement since the trade is done internally to Solo. */ struct TradeArgs { Types.AssetAmount amount; Account.Info takerAccount; Account.Info makerAccount; uint256 inputMarket; uint256 outputMarket; address autoTrader; bytes tradeData; } /* * Each account must maintain a certain margin-ratio (specified globally). If the account falls * below this margin-ratio, it can be liquidated by any other account. This allows anyone else * (arbitrageurs) to repay any borrowed asset (owedMarket) of the liquidating account in * exchange for any collateral asset (heldMarket) of the liquidAccount. The ratio is determined * by the price ratio (given by the oracles) plus a spread (specified globally). Liquidating an * account also sets a flag on the account that the account is being liquidated. This allows * anyone to continue liquidating the account until there are no more borrows being taken by the * liquidating account. Liquidators do not have to liquidate the entire account all at once but * can liquidate as much as they choose. The liquidating flag allows liquidators to continue * liquidating the account even if it becomes collateralized through partial liquidation or * price movement. */ struct LiquidateArgs { Types.AssetAmount amount; Account.Info solidAccount; Account.Info liquidAccount; uint256 owedMarket; uint256 heldMarket; } /* * Similar to liquidate, but vaporAccounts are accounts that have only negative balances * remaining. The arbitrageur pays back the negative asset (owedMarket) of the vaporAccount in * exchange for a collateral asset (heldMarket) at a favorable spread. However, since the * liquidAccount has no collateral assets, the collateral must come from Solo's excess tokens. */ struct VaporizeArgs { Types.AssetAmount amount; Account.Info solidAccount; Account.Info vaporAccount; uint256 owedMarket; uint256 heldMarket; } /* * Passes arbitrary bytes of data to an external contract that implements the Callee interface. * Does not change any asset amounts. This function may be useful for setting certain variables * on layer-two contracts for certain accounts without having to make a separate Ethereum * transaction for doing so. Also, the second-layer contracts can ensure that the call is coming * from an operator of the particular account. */ struct CallArgs { Account.Info account; address callee; bytes data; } // ============ Helper Functions ============ function getMarketLayout( ActionType actionType ) internal pure returns (MarketLayout) { if ( actionType == Actions.ActionType.Deposit || actionType == Actions.ActionType.Withdraw || actionType == Actions.ActionType.Transfer ) { return MarketLayout.OneMarket; } else if (actionType == Actions.ActionType.Call) { return MarketLayout.ZeroMarkets; } return MarketLayout.TwoMarkets; } function getAccountLayout( ActionType actionType ) internal pure returns (AccountLayout) { if ( actionType == Actions.ActionType.Transfer || actionType == Actions.ActionType.Trade ) { return AccountLayout.TwoPrimary; } else if ( actionType == Actions.ActionType.Liquidate || actionType == Actions.ActionType.Vaporize ) { return AccountLayout.PrimaryAndSecondary; } return AccountLayout.OnePrimary; } // ============ Parsing Functions ============ function parseDepositArgs( Account.Info[] memory accounts, ActionArgs memory args ) internal pure returns (DepositArgs memory) { assert(args.actionType == ActionType.Deposit); return DepositArgs({ amount: args.amount, account: accounts[args.accountId], market: args.primaryMarketId, from: args.otherAddress }); } function parseWithdrawArgs( Account.Info[] memory accounts, ActionArgs memory args ) internal pure returns (WithdrawArgs memory) { assert(args.actionType == ActionType.Withdraw); return WithdrawArgs({ amount: args.amount, account: accounts[args.accountId], market: args.primaryMarketId, to: args.otherAddress }); } function parseTransferArgs( Account.Info[] memory accounts, ActionArgs memory args ) internal pure returns (TransferArgs memory) { assert(args.actionType == ActionType.Transfer); return TransferArgs({ amount: args.amount, accountOne: accounts[args.accountId], accountTwo: accounts[args.otherAccountId], market: args.primaryMarketId }); } function parseBuyArgs( Account.Info[] memory accounts, ActionArgs memory args ) internal pure returns (BuyArgs memory) { assert(args.actionType == ActionType.Buy); return BuyArgs({ amount: args.amount, account: accounts[args.accountId], makerMarket: args.primaryMarketId, takerMarket: args.secondaryMarketId, exchangeWrapper: args.otherAddress, orderData: args.data }); } function parseSellArgs( Account.Info[] memory accounts, ActionArgs memory args ) internal pure returns (SellArgs memory) { assert(args.actionType == ActionType.Sell); return SellArgs({ amount: args.amount, account: accounts[args.accountId], takerMarket: args.primaryMarketId, makerMarket: args.secondaryMarketId, exchangeWrapper: args.otherAddress, orderData: args.data }); } function parseTradeArgs( Account.Info[] memory accounts, ActionArgs memory args ) internal pure returns (TradeArgs memory) { assert(args.actionType == ActionType.Trade); return TradeArgs({ amount: args.amount, takerAccount: accounts[args.accountId], makerAccount: accounts[args.otherAccountId], inputMarket: args.primaryMarketId, outputMarket: args.secondaryMarketId, autoTrader: args.otherAddress, tradeData: args.data }); } function parseLiquidateArgs( Account.Info[] memory accounts, ActionArgs memory args ) internal pure returns (LiquidateArgs memory) { assert(args.actionType == ActionType.Liquidate); return LiquidateArgs({ amount: args.amount, solidAccount: accounts[args.accountId], liquidAccount: accounts[args.otherAccountId], owedMarket: args.primaryMarketId, heldMarket: args.secondaryMarketId }); } function parseVaporizeArgs( Account.Info[] memory accounts, ActionArgs memory args ) internal pure returns (VaporizeArgs memory) { assert(args.actionType == ActionType.Vaporize); return VaporizeArgs({ amount: args.amount, solidAccount: accounts[args.accountId], vaporAccount: accounts[args.otherAccountId], owedMarket: args.primaryMarketId, heldMarket: args.secondaryMarketId }); } function parseCallArgs( Account.Info[] memory accounts, ActionArgs memory args ) internal pure returns (CallArgs memory) { assert(args.actionType == ActionType.Call); return CallArgs({ account: accounts[args.accountId], callee: args.otherAddress, data: args.data }); } } // File: contracts/protocol/lib/Events.sol /** * @title Events * @author dYdX * * Library to parse and emit logs from which the state of all accounts and indexes can be followed */ library Events { using Types for Types.Wei; using Storage for Storage.State; // ============ Events ============ event LogIndexUpdate( uint256 indexed market, Interest.Index index ); event LogOperation( address sender ); event LogDeposit( address indexed accountOwner, uint256 accountNumber, uint256 market, BalanceUpdate update, address from ); event LogWithdraw( address indexed accountOwner, uint256 accountNumber, uint256 market, BalanceUpdate update, address to ); event LogTransfer( address indexed accountOneOwner, uint256 accountOneNumber, address indexed accountTwoOwner, uint256 accountTwoNumber, uint256 market, BalanceUpdate updateOne, BalanceUpdate updateTwo ); event LogBuy( address indexed accountOwner, uint256 accountNumber, uint256 takerMarket, uint256 makerMarket, BalanceUpdate takerUpdate, BalanceUpdate makerUpdate, address exchangeWrapper ); event LogSell( address indexed accountOwner, uint256 accountNumber, uint256 takerMarket, uint256 makerMarket, BalanceUpdate takerUpdate, BalanceUpdate makerUpdate, address exchangeWrapper ); event LogTrade( address indexed takerAccountOwner, uint256 takerAccountNumber, address indexed makerAccountOwner, uint256 makerAccountNumber, uint256 inputMarket, uint256 outputMarket, BalanceUpdate takerInputUpdate, BalanceUpdate takerOutputUpdate, BalanceUpdate makerInputUpdate, BalanceUpdate makerOutputUpdate, address autoTrader ); event LogCall( address indexed accountOwner, uint256 accountNumber, address callee ); event LogLiquidate( address indexed solidAccountOwner, uint256 solidAccountNumber, address indexed liquidAccountOwner, uint256 liquidAccountNumber, uint256 heldMarket, uint256 owedMarket, BalanceUpdate solidHeldUpdate, BalanceUpdate solidOwedUpdate, BalanceUpdate liquidHeldUpdate, BalanceUpdate liquidOwedUpdate ); event LogVaporize( address indexed solidAccountOwner, uint256 solidAccountNumber, address indexed vaporAccountOwner, uint256 vaporAccountNumber, uint256 heldMarket, uint256 owedMarket, BalanceUpdate solidHeldUpdate, BalanceUpdate solidOwedUpdate, BalanceUpdate vaporOwedUpdate ); // ============ Structs ============ struct BalanceUpdate { Types.Wei deltaWei; Types.Par newPar; } // ============ Internal Functions ============ function logIndexUpdate( uint256 marketId, Interest.Index memory index ) internal { emit LogIndexUpdate( marketId, index ); } function logOperation() internal { emit LogOperation(msg.sender); } function logDeposit( Storage.State storage state, Actions.DepositArgs memory args, Types.Wei memory deltaWei ) internal { emit LogDeposit( args.account.owner, args.account.number, args.market, getBalanceUpdate( state, args.account, args.market, deltaWei ), args.from ); } function logWithdraw( Storage.State storage state, Actions.WithdrawArgs memory args, Types.Wei memory deltaWei ) internal { emit LogWithdraw( args.account.owner, args.account.number, args.market, getBalanceUpdate( state, args.account, args.market, deltaWei ), args.to ); } function logTransfer( Storage.State storage state, Actions.TransferArgs memory args, Types.Wei memory deltaWei ) internal { emit LogTransfer( args.accountOne.owner, args.accountOne.number, args.accountTwo.owner, args.accountTwo.number, args.market, getBalanceUpdate( state, args.accountOne, args.market, deltaWei ), getBalanceUpdate( state, args.accountTwo, args.market, deltaWei.negative() ) ); } function logBuy( Storage.State storage state, Actions.BuyArgs memory args, Types.Wei memory takerWei, Types.Wei memory makerWei ) internal { emit LogBuy( args.account.owner, args.account.number, args.takerMarket, args.makerMarket, getBalanceUpdate( state, args.account, args.takerMarket, takerWei ), getBalanceUpdate( state, args.account, args.makerMarket, makerWei ), args.exchangeWrapper ); } function logSell( Storage.State storage state, Actions.SellArgs memory args, Types.Wei memory takerWei, Types.Wei memory makerWei ) internal { emit LogSell( args.account.owner, args.account.number, args.takerMarket, args.makerMarket, getBalanceUpdate( state, args.account, args.takerMarket, takerWei ), getBalanceUpdate( state, args.account, args.makerMarket, makerWei ), args.exchangeWrapper ); } function logTrade( Storage.State storage state, Actions.TradeArgs memory args, Types.Wei memory inputWei, Types.Wei memory outputWei ) internal { BalanceUpdate[4] memory updates = [ getBalanceUpdate( state, args.takerAccount, args.inputMarket, inputWei.negative() ), getBalanceUpdate( state, args.takerAccount, args.outputMarket, outputWei.negative() ), getBalanceUpdate( state, args.makerAccount, args.inputMarket, inputWei ), getBalanceUpdate( state, args.makerAccount, args.outputMarket, outputWei ) ]; emit LogTrade( args.takerAccount.owner, args.takerAccount.number, args.makerAccount.owner, args.makerAccount.number, args.inputMarket, args.outputMarket, updates[0], updates[1], updates[2], updates[3], args.autoTrader ); } function logCall( Actions.CallArgs memory args ) internal { emit LogCall( args.account.owner, args.account.number, args.callee ); } function logLiquidate( Storage.State storage state, Actions.LiquidateArgs memory args, Types.Wei memory heldWei, Types.Wei memory owedWei ) internal { BalanceUpdate memory solidHeldUpdate = getBalanceUpdate( state, args.solidAccount, args.heldMarket, heldWei.negative() ); BalanceUpdate memory solidOwedUpdate = getBalanceUpdate( state, args.solidAccount, args.owedMarket, owedWei.negative() ); BalanceUpdate memory liquidHeldUpdate = getBalanceUpdate( state, args.liquidAccount, args.heldMarket, heldWei ); BalanceUpdate memory liquidOwedUpdate = getBalanceUpdate( state, args.liquidAccount, args.owedMarket, owedWei ); emit LogLiquidate( args.solidAccount.owner, args.solidAccount.number, args.liquidAccount.owner, args.liquidAccount.number, args.heldMarket, args.owedMarket, solidHeldUpdate, solidOwedUpdate, liquidHeldUpdate, liquidOwedUpdate ); } function logVaporize( Storage.State storage state, Actions.VaporizeArgs memory args, Types.Wei memory heldWei, Types.Wei memory owedWei, Types.Wei memory excessWei ) internal { BalanceUpdate memory solidHeldUpdate = getBalanceUpdate( state, args.solidAccount, args.heldMarket, heldWei.negative() ); BalanceUpdate memory solidOwedUpdate = getBalanceUpdate( state, args.solidAccount, args.owedMarket, owedWei.negative() ); BalanceUpdate memory vaporOwedUpdate = getBalanceUpdate( state, args.vaporAccount, args.owedMarket, owedWei.add(excessWei) ); emit LogVaporize( args.solidAccount.owner, args.solidAccount.number, args.vaporAccount.owner, args.vaporAccount.number, args.heldMarket, args.owedMarket, solidHeldUpdate, solidOwedUpdate, vaporOwedUpdate ); } // ============ Private Functions ============ function getBalanceUpdate( Storage.State storage state, Account.Info memory account, uint256 market, Types.Wei memory deltaWei ) private view returns (BalanceUpdate memory) { return BalanceUpdate({ deltaWei: deltaWei, newPar: state.getPar(account, market) }); } } // File: contracts/protocol/interfaces/IExchangeWrapper.sol /** * @title IExchangeWrapper * @author dYdX * * Interface that Exchange Wrappers for Solo must implement in order to trade ERC20 tokens. */ interface IExchangeWrapper { // ============ Public Functions ============ /** * Exchange some amount of takerToken for makerToken. * * @param tradeOriginator Address of the initiator of the trade (however, this value * cannot always be trusted as it is set at the discretion of the * msg.sender) * @param receiver Address to set allowance on once the trade has completed * @param makerToken Address of makerToken, the token to receive * @param takerToken Address of takerToken, the token to pay * @param requestedFillAmount Amount of takerToken being paid * @param orderData Arbitrary bytes data for any information to pass to the exchange * @return The amount of makerToken received */ function exchange( address tradeOriginator, address receiver, address makerToken, address takerToken, uint256 requestedFillAmount, bytes calldata orderData ) external returns (uint256); /** * Get amount of takerToken required to buy a certain amount of makerToken for a given trade. * Should match the takerToken amount used in exchangeForAmount. If the order cannot provide * exactly desiredMakerToken, then it must return the price to buy the minimum amount greater * than desiredMakerToken * * @param makerToken Address of makerToken, the token to receive * @param takerToken Address of takerToken, the token to pay * @param desiredMakerToken Amount of makerToken requested * @param orderData Arbitrary bytes data for any information to pass to the exchange * @return Amount of takerToken the needed to complete the exchange */ function getExchangeCost( address makerToken, address takerToken, uint256 desiredMakerToken, bytes calldata orderData ) external view returns (uint256); } // File: contracts/protocol/lib/Exchange.sol /** * @title Exchange * @author dYdX * * Library for transferring tokens and interacting with ExchangeWrappers by using the Wei struct */ library Exchange { using Types for Types.Wei; // ============ Constants ============ bytes32 constant FILE = "Exchange"; // ============ Library Functions ============ function transferOut( address token, address to, Types.Wei memory deltaWei ) internal { Require.that( !deltaWei.isPositive(), FILE, "Cannot transferOut positive", deltaWei.value ); Token.transfer( token, to, deltaWei.value ); } function transferIn( address token, address from, Types.Wei memory deltaWei ) internal { Require.that( !deltaWei.isNegative(), FILE, "Cannot transferIn negative", deltaWei.value ); Token.transferFrom( token, from, address(this), deltaWei.value ); } function getCost( address exchangeWrapper, address supplyToken, address borrowToken, Types.Wei memory desiredAmount, bytes memory orderData ) internal view returns (Types.Wei memory) { Require.that( !desiredAmount.isNegative(), FILE, "Cannot getCost negative", desiredAmount.value ); Types.Wei memory result; result.sign = false; result.value = IExchangeWrapper(exchangeWrapper).getExchangeCost( supplyToken, borrowToken, desiredAmount.value, orderData ); return result; } function exchange( address exchangeWrapper, address accountOwner, address supplyToken, address borrowToken, Types.Wei memory requestedFillAmount, bytes memory orderData ) internal returns (Types.Wei memory) { Require.that( !requestedFillAmount.isPositive(), FILE, "Cannot exchange positive", requestedFillAmount.value ); transferOut(borrowToken, exchangeWrapper, requestedFillAmount); Types.Wei memory result; result.sign = true; result.value = IExchangeWrapper(exchangeWrapper).exchange( accountOwner, address(this), supplyToken, borrowToken, requestedFillAmount.value, orderData ); transferIn(supplyToken, exchangeWrapper, result); return result; } } // File: contracts/protocol/impl/OperationImpl.sol /** * @title OperationImpl * @author dYdX * * Logic for processing actions */ library OperationImpl { using Cache for Cache.MarketCache; using SafeMath for uint256; using Storage for Storage.State; using Types for Types.Par; using Types for Types.Wei; // ============ Constants ============ bytes32 constant FILE = "OperationImpl"; // ============ Public Functions ============ function operate( Storage.State storage state, Account.Info[] memory accounts, Actions.ActionArgs[] memory actions ) public { Events.logOperation(); _verifyInputs(accounts, actions); ( bool[] memory primaryAccounts, Cache.MarketCache memory cache ) = _runPreprocessing( state, accounts, actions ); _runActions( state, accounts, actions, cache ); _verifyFinalState( state, accounts, primaryAccounts, cache ); } // ============ Helper Functions ============ function _verifyInputs( Account.Info[] memory accounts, Actions.ActionArgs[] memory actions ) private pure { Require.that( actions.length != 0, FILE, "Cannot have zero actions" ); Require.that( accounts.length != 0, FILE, "Cannot have zero accounts" ); for (uint256 a = 0; a < accounts.length; a++) { for (uint256 b = a + 1; b < accounts.length; b++) { Require.that( !Account.equals(accounts[a], accounts[b]), FILE, "Cannot duplicate accounts", a, b ); } } } function _runPreprocessing( Storage.State storage state, Account.Info[] memory accounts, Actions.ActionArgs[] memory actions ) private returns ( bool[] memory, Cache.MarketCache memory ) { uint256 numMarkets = state.numMarkets; bool[] memory primaryAccounts = new bool[](accounts.length); Cache.MarketCache memory cache = Cache.create(numMarkets); // keep track of primary accounts and indexes that need updating for (uint256 i = 0; i < actions.length; i++) { Actions.ActionArgs memory arg = actions[i]; Actions.ActionType actionType = arg.actionType; Actions.MarketLayout marketLayout = Actions.getMarketLayout(actionType); Actions.AccountLayout accountLayout = Actions.getAccountLayout(actionType); // parse out primary accounts if (accountLayout != Actions.AccountLayout.OnePrimary) { Require.that( arg.accountId != arg.otherAccountId, FILE, "Duplicate accounts in action", i ); if (accountLayout == Actions.AccountLayout.TwoPrimary) { primaryAccounts[arg.otherAccountId] = true; } else { assert(accountLayout == Actions.AccountLayout.PrimaryAndSecondary); Require.that( !primaryAccounts[arg.otherAccountId], FILE, "Requires non-primary account", arg.otherAccountId ); } } primaryAccounts[arg.accountId] = true; // keep track of indexes to update if (marketLayout == Actions.MarketLayout.OneMarket) { _updateMarket(state, cache, arg.primaryMarketId); } else if (marketLayout == Actions.MarketLayout.TwoMarkets) { Require.that( arg.primaryMarketId != arg.secondaryMarketId, FILE, "Duplicate markets in action", i ); _updateMarket(state, cache, arg.primaryMarketId); _updateMarket(state, cache, arg.secondaryMarketId); } else { assert(marketLayout == Actions.MarketLayout.ZeroMarkets); } } // get any other markets for which an account has a balance for (uint256 m = 0; m < numMarkets; m++) { if (cache.hasMarket(m)) { continue; } for (uint256 a = 0; a < accounts.length; a++) { if (!state.getPar(accounts[a], m).isZero()) { _updateMarket(state, cache, m); break; } } } return (primaryAccounts, cache); } function _updateMarket( Storage.State storage state, Cache.MarketCache memory cache, uint256 marketId ) private { bool updated = cache.addMarket(state, marketId); if (updated) { Events.logIndexUpdate(marketId, state.updateIndex(marketId)); } } function _runActions( Storage.State storage state, Account.Info[] memory accounts, Actions.ActionArgs[] memory actions, Cache.MarketCache memory cache ) private { for (uint256 i = 0; i < actions.length; i++) { Actions.ActionArgs memory action = actions[i]; Actions.ActionType actionType = action.actionType; if (actionType == Actions.ActionType.Deposit) { _deposit(state, Actions.parseDepositArgs(accounts, action)); } else if (actionType == Actions.ActionType.Withdraw) { _withdraw(state, Actions.parseWithdrawArgs(accounts, action)); } else if (actionType == Actions.ActionType.Transfer) { _transfer(state, Actions.parseTransferArgs(accounts, action)); } else if (actionType == Actions.ActionType.Buy) { _buy(state, Actions.parseBuyArgs(accounts, action)); } else if (actionType == Actions.ActionType.Sell) { _sell(state, Actions.parseSellArgs(accounts, action)); } else if (actionType == Actions.ActionType.Trade) { _trade(state, Actions.parseTradeArgs(accounts, action)); } else if (actionType == Actions.ActionType.Liquidate) { _liquidate(state, Actions.parseLiquidateArgs(accounts, action), cache); } else if (actionType == Actions.ActionType.Vaporize) { _vaporize(state, Actions.parseVaporizeArgs(accounts, action), cache); } else { assert(actionType == Actions.ActionType.Call); _call(state, Actions.parseCallArgs(accounts, action)); } } } function _verifyFinalState( Storage.State storage state, Account.Info[] memory accounts, bool[] memory primaryAccounts, Cache.MarketCache memory cache ) private { // verify no increase in borrowPar for closing markets uint256 numMarkets = cache.getNumMarkets(); for (uint256 m = 0; m < numMarkets; m++) { if (cache.getIsClosing(m)) { Require.that( state.getTotalPar(m).borrow <= cache.getBorrowPar(m), FILE, "Market is closing", m ); } } // verify account collateralization for (uint256 a = 0; a < accounts.length; a++) { Account.Info memory account = accounts[a]; // validate minBorrowedValue bool collateralized = state.isCollateralized(account, cache, true); // don't check collateralization for non-primary accounts if (!primaryAccounts[a]) { continue; } // check collateralization for primary accounts Require.that( collateralized, FILE, "Undercollateralized account", account.owner, account.number ); // ensure status is normal for primary accounts if (state.getStatus(account) != Account.Status.Normal) { state.setStatus(account, Account.Status.Normal); } } } // ============ Action Functions ============ function _deposit( Storage.State storage state, Actions.DepositArgs memory args ) private { state.requireIsOperator(args.account, msg.sender); Require.that( args.from == msg.sender || args.from == args.account.owner, FILE, "Invalid deposit source", args.from ); ( Types.Par memory newPar, Types.Wei memory deltaWei ) = state.getNewParAndDeltaWei( args.account, args.market, args.amount ); state.setPar( args.account, args.market, newPar ); // requires a positive deltaWei Exchange.transferIn( state.getToken(args.market), args.from, deltaWei ); Events.logDeposit( state, args, deltaWei ); } function _withdraw( Storage.State storage state, Actions.WithdrawArgs memory args ) private { state.requireIsOperator(args.account, msg.sender); ( Types.Par memory newPar, Types.Wei memory deltaWei ) = state.getNewParAndDeltaWei( args.account, args.market, args.amount ); state.setPar( args.account, args.market, newPar ); // requires a negative deltaWei Exchange.transferOut( state.getToken(args.market), args.to, deltaWei ); Events.logWithdraw( state, args, deltaWei ); } function _transfer( Storage.State storage state, Actions.TransferArgs memory args ) private { state.requireIsOperator(args.accountOne, msg.sender); state.requireIsOperator(args.accountTwo, msg.sender); ( Types.Par memory newPar, Types.Wei memory deltaWei ) = state.getNewParAndDeltaWei( args.accountOne, args.market, args.amount ); state.setPar( args.accountOne, args.market, newPar ); state.setParFromDeltaWei( args.accountTwo, args.market, deltaWei.negative() ); Events.logTransfer( state, args, deltaWei ); } function _buy( Storage.State storage state, Actions.BuyArgs memory args ) private { state.requireIsOperator(args.account, msg.sender); address takerToken = state.getToken(args.takerMarket); address makerToken = state.getToken(args.makerMarket); ( Types.Par memory makerPar, Types.Wei memory makerWei ) = state.getNewParAndDeltaWei( args.account, args.makerMarket, args.amount ); Types.Wei memory takerWei = Exchange.getCost( args.exchangeWrapper, makerToken, takerToken, makerWei, args.orderData ); Types.Wei memory tokensReceived = Exchange.exchange( args.exchangeWrapper, args.account.owner, makerToken, takerToken, takerWei, args.orderData ); Require.that( tokensReceived.value >= makerWei.value, FILE, "Buy amount less than promised", tokensReceived.value, makerWei.value ); state.setPar( args.account, args.makerMarket, makerPar ); state.setParFromDeltaWei( args.account, args.takerMarket, takerWei ); Events.logBuy( state, args, takerWei, makerWei ); } function _sell( Storage.State storage state, Actions.SellArgs memory args ) private { state.requireIsOperator(args.account, msg.sender); address takerToken = state.getToken(args.takerMarket); address makerToken = state.getToken(args.makerMarket); ( Types.Par memory takerPar, Types.Wei memory takerWei ) = state.getNewParAndDeltaWei( args.account, args.takerMarket, args.amount ); Types.Wei memory makerWei = Exchange.exchange( args.exchangeWrapper, args.account.owner, makerToken, takerToken, takerWei, args.orderData ); state.setPar( args.account, args.takerMarket, takerPar ); state.setParFromDeltaWei( args.account, args.makerMarket, makerWei ); Events.logSell( state, args, takerWei, makerWei ); } function _trade( Storage.State storage state, Actions.TradeArgs memory args ) private { state.requireIsOperator(args.takerAccount, msg.sender); state.requireIsOperator(args.makerAccount, args.autoTrader); Types.Par memory oldInputPar = state.getPar( args.makerAccount, args.inputMarket ); ( Types.Par memory newInputPar, Types.Wei memory inputWei ) = state.getNewParAndDeltaWei( args.makerAccount, args.inputMarket, args.amount ); Types.AssetAmount memory outputAmount = IAutoTrader(args.autoTrader).getTradeCost( args.inputMarket, args.outputMarket, args.makerAccount, args.takerAccount, oldInputPar, newInputPar, inputWei, args.tradeData ); ( Types.Par memory newOutputPar, Types.Wei memory outputWei ) = state.getNewParAndDeltaWei( args.makerAccount, args.outputMarket, outputAmount ); Require.that( outputWei.isZero() || inputWei.isZero() || outputWei.sign != inputWei.sign, FILE, "Trades cannot be one-sided" ); // set the balance for the maker state.setPar( args.makerAccount, args.inputMarket, newInputPar ); state.setPar( args.makerAccount, args.outputMarket, newOutputPar ); // set the balance for the taker state.setParFromDeltaWei( args.takerAccount, args.inputMarket, inputWei.negative() ); state.setParFromDeltaWei( args.takerAccount, args.outputMarket, outputWei.negative() ); Events.logTrade( state, args, inputWei, outputWei ); } function _liquidate( Storage.State storage state, Actions.LiquidateArgs memory args, Cache.MarketCache memory cache ) private { state.requireIsOperator(args.solidAccount, msg.sender); // verify liquidatable if (Account.Status.Liquid != state.getStatus(args.liquidAccount)) { Require.that( !state.isCollateralized(args.liquidAccount, cache, /* requireMinBorrow = */ false), FILE, "Unliquidatable account", args.liquidAccount.owner, args.liquidAccount.number ); state.setStatus(args.liquidAccount, Account.Status.Liquid); } Types.Wei memory maxHeldWei = state.getWei( args.liquidAccount, args.heldMarket ); Require.that( !maxHeldWei.isNegative(), FILE, "Collateral cannot be negative", args.liquidAccount.owner, args.liquidAccount.number, args.heldMarket ); ( Types.Par memory owedPar, Types.Wei memory owedWei ) = state.getNewParAndDeltaWeiForLiquidation( args.liquidAccount, args.owedMarket, args.amount ); ( Monetary.Price memory heldPrice, Monetary.Price memory owedPrice ) = _getLiquidationPrices( state, cache, args.heldMarket, args.owedMarket ); Types.Wei memory heldWei = _owedWeiToHeldWei(owedWei, heldPrice, owedPrice); // if attempting to over-borrow the held asset, bound it by the maximum if (heldWei.value > maxHeldWei.value) { heldWei = maxHeldWei.negative(); owedWei = _heldWeiToOwedWei(heldWei, heldPrice, owedPrice); state.setPar( args.liquidAccount, args.heldMarket, Types.zeroPar() ); state.setParFromDeltaWei( args.liquidAccount, args.owedMarket, owedWei ); } else { state.setPar( args.liquidAccount, args.owedMarket, owedPar ); state.setParFromDeltaWei( args.liquidAccount, args.heldMarket, heldWei ); } // set the balances for the solid account state.setParFromDeltaWei( args.solidAccount, args.owedMarket, owedWei.negative() ); state.setParFromDeltaWei( args.solidAccount, args.heldMarket, heldWei.negative() ); Events.logLiquidate( state, args, heldWei, owedWei ); } function _vaporize( Storage.State storage state, Actions.VaporizeArgs memory args, Cache.MarketCache memory cache ) private { state.requireIsOperator(args.solidAccount, msg.sender); // verify vaporizable if (Account.Status.Vapor != state.getStatus(args.vaporAccount)) { Require.that( state.isVaporizable(args.vaporAccount, cache), FILE, "Unvaporizable account", args.vaporAccount.owner, args.vaporAccount.number ); state.setStatus(args.vaporAccount, Account.Status.Vapor); } // First, attempt to refund using the same token ( bool fullyRepaid, Types.Wei memory excessWei ) = _vaporizeUsingExcess(state, args); if (fullyRepaid) { Events.logVaporize( state, args, Types.zeroWei(), Types.zeroWei(), excessWei ); return; } Types.Wei memory maxHeldWei = state.getNumExcessTokens(args.heldMarket); Require.that( !maxHeldWei.isNegative(), FILE, "Excess cannot be negative", args.heldMarket ); ( Types.Par memory owedPar, Types.Wei memory owedWei ) = state.getNewParAndDeltaWeiForLiquidation( args.vaporAccount, args.owedMarket, args.amount ); ( Monetary.Price memory heldPrice, Monetary.Price memory owedPrice ) = _getLiquidationPrices( state, cache, args.heldMarket, args.owedMarket ); Types.Wei memory heldWei = _owedWeiToHeldWei(owedWei, heldPrice, owedPrice); // if attempting to over-borrow the held asset, bound it by the maximum if (heldWei.value > maxHeldWei.value) { heldWei = maxHeldWei.negative(); owedWei = _heldWeiToOwedWei(heldWei, heldPrice, owedPrice); state.setParFromDeltaWei( args.vaporAccount, args.owedMarket, owedWei ); } else { state.setPar( args.vaporAccount, args.owedMarket, owedPar ); } // set the balances for the solid account state.setParFromDeltaWei( args.solidAccount, args.owedMarket, owedWei.negative() ); state.setParFromDeltaWei( args.solidAccount, args.heldMarket, heldWei.negative() ); Events.logVaporize( state, args, heldWei, owedWei, excessWei ); } function _call( Storage.State storage state, Actions.CallArgs memory args ) private { state.requireIsOperator(args.account, msg.sender); ICallee(args.callee).callFunction( msg.sender, args.account, args.data ); Events.logCall(args); } // ============ Private Functions ============ /** * For the purposes of liquidation or vaporization, get the value-equivalent amount of heldWei * given owedWei and the (spread-adjusted) prices of each asset. */ function _owedWeiToHeldWei( Types.Wei memory owedWei, Monetary.Price memory heldPrice, Monetary.Price memory owedPrice ) private pure returns (Types.Wei memory) { return Types.Wei({ sign: false, value: Math.getPartial(owedWei.value, owedPrice.value, heldPrice.value) }); } /** * For the purposes of liquidation or vaporization, get the value-equivalent amount of owedWei * given heldWei and the (spread-adjusted) prices of each asset. */ function _heldWeiToOwedWei( Types.Wei memory heldWei, Monetary.Price memory heldPrice, Monetary.Price memory owedPrice ) private pure returns (Types.Wei memory) { return Types.Wei({ sign: true, value: Math.getPartialRoundUp(heldWei.value, heldPrice.value, owedPrice.value) }); } /** * Attempt to vaporize an account's balance using the excess tokens in the protocol. Return a * bool and a wei value. The boolean is true if and only if the balance was fully vaporized. The * Wei value is how many excess tokens were used to partially or fully vaporize the account's * negative balance. */ function _vaporizeUsingExcess( Storage.State storage state, Actions.VaporizeArgs memory args ) internal returns (bool, Types.Wei memory) { Types.Wei memory excessWei = state.getNumExcessTokens(args.owedMarket); // There are no excess funds, return zero if (!excessWei.isPositive()) { return (false, Types.zeroWei()); } Types.Wei memory maxRefundWei = state.getWei(args.vaporAccount, args.owedMarket); maxRefundWei.sign = true; // The account is fully vaporizable using excess funds if (excessWei.value >= maxRefundWei.value) { state.setPar( args.vaporAccount, args.owedMarket, Types.zeroPar() ); return (true, maxRefundWei); } // The account is only partially vaporizable using excess funds else { state.setParFromDeltaWei( args.vaporAccount, args.owedMarket, excessWei ); return (false, excessWei); } } /** * Return the (spread-adjusted) prices of two assets for the purposes of liquidation or * vaporization. */ function _getLiquidationPrices( Storage.State storage state, Cache.MarketCache memory cache, uint256 heldMarketId, uint256 owedMarketId ) internal view returns ( Monetary.Price memory, Monetary.Price memory ) { uint256 originalPrice = cache.getPrice(owedMarketId).value; Decimal.D256 memory spread = state.getLiquidationSpreadForPair( heldMarketId, owedMarketId ); Monetary.Price memory owedPrice = Monetary.Price({ value: originalPrice.add(Decimal.mul(originalPrice, spread)) }); return (cache.getPrice(heldMarketId), owedPrice); } } // File: contracts/protocol/Operation.sol /** * @title Operation * @author dYdX * * Primary public function for allowing users and contracts to manage accounts within Solo */ contract Operation is State, ReentrancyGuard { // ============ Public Functions ============ /** * The main entry-point to Solo that allows users and contracts to manage accounts. * Take one or more actions on one or more accounts. The msg.sender must be the owner or * operator of all accounts except for those being liquidated, vaporized, or traded with. * One call to operate() is considered a singular "operation". Account collateralization is * ensured only after the completion of the entire operation. * * @param accounts A list of all accounts that will be used in this operation. Cannot contain * duplicates. In each action, the relevant account will be referred-to by its * index in the list. * @param actions An ordered list of all actions that will be taken in this operation. The * actions will be processed in order. */ function operate( Account.Info[] memory accounts, Actions.ActionArgs[] memory actions ) public nonReentrant { OperationImpl.operate( g_state, accounts, actions ); } } // File: contracts/protocol/Permission.sol /** * @title Permission * @author dYdX * * Public function that allows other addresses to manage accounts */ contract Permission is State { // ============ Events ============ event LogOperatorSet( address indexed owner, address operator, bool trusted ); // ============ Structs ============ struct OperatorArg { address operator; bool trusted; } // ============ Public Functions ============ /** * Approves/disapproves any number of operators. An operator is an external address that has the * same permissions to manipulate an account as the owner of the account. Operators are simply * addresses and therefore may either be externally-owned Ethereum accounts OR smart contracts. * * Operators are also able to act as AutoTrader contracts on behalf of the account owner if the * operator is a smart contract and implements the IAutoTrader interface. * * @param args A list of OperatorArgs which have an address and a boolean. The boolean value * denotes whether to approve (true) or revoke approval (false) for that address. */ function setOperators( OperatorArg[] memory args ) public { for (uint256 i = 0; i < args.length; i++) { address operator = args[i].operator; bool trusted = args[i].trusted; g_state.operators[msg.sender][operator] = trusted; emit LogOperatorSet(msg.sender, operator, trusted); } } } // File: contracts/protocol/SoloMargin.sol /** * @title SoloMargin * @author dYdX * * Main contract that inherits from other contracts */ contract SoloMargin is State, Admin, Getters, Operation, Permission { // ============ Constructor ============ constructor( Storage.RiskParams memory riskParams, Storage.RiskLimits memory riskLimits ) public { g_state.riskParams = riskParams; g_state.riskLimits = riskLimits; } } // File: contracts/external/helpers/OnlySolo.sol /** * @title OnlySolo * @author dYdX * * Inheritable contract that restricts the calling of certain functions to Solo only */ contract OnlySolo { // ============ Constants ============ bytes32 constant FILE = "OnlySolo"; // ============ Storage ============ SoloMargin public SOLO_MARGIN; // ============ Constructor ============ constructor ( address soloMargin ) public { SOLO_MARGIN = SoloMargin(soloMargin); } // ============ Modifiers ============ modifier onlySolo(address from) { Require.that( from == address(SOLO_MARGIN), FILE, "Only Solo can call function", from ); _; } } // File: contracts/external/traders/Expiry.sol /** * @title Expiry * @author dYdX * * Sets the negative balance for an account to expire at a certain time. This allows any other * account to repay that negative balance after expiry using any positive balance in the same * account. The arbitrage incentive is the same as liquidation in the base protocol. */ contract Expiry is Ownable, OnlySolo, ICallee, IAutoTrader { using SafeMath for uint32; using SafeMath for uint256; using Types for Types.Par; using Types for Types.Wei; // ============ Constants ============ bytes32 constant FILE = "Expiry"; // ============ Events ============ event ExpirySet( address owner, uint256 number, uint256 marketId, uint32 time ); event LogExpiryRampTimeSet( uint256 expiryRampTime ); // ============ Storage ============ // owner => number => market => time mapping (address => mapping (uint256 => mapping (uint256 => uint32))) g_expiries; // time over which the liquidation ratio goes from zero to maximum uint256 public g_expiryRampTime; // ============ Constructor ============ constructor ( address soloMargin, uint256 expiryRampTime ) public OnlySolo(soloMargin) { g_expiryRampTime = expiryRampTime; } // ============ Owner Functions ============ function ownerSetExpiryRampTime( uint256 newExpiryRampTime ) external onlyOwner { emit LogExpiryRampTimeSet(newExpiryRampTime); g_expiryRampTime = newExpiryRampTime; } // ============ Getters ============ function getExpiry( Account.Info memory account, uint256 marketId ) public view returns (uint32) { return g_expiries[account.owner][account.number][marketId]; } function getSpreadAdjustedPrices( uint256 heldMarketId, uint256 owedMarketId, uint32 expiry ) public view returns ( Monetary.Price memory, Monetary.Price memory ) { Decimal.D256 memory spread = SOLO_MARGIN.getLiquidationSpreadForPair( heldMarketId, owedMarketId ); uint256 expiryAge = Time.currentTime().sub(expiry); if (expiryAge < g_expiryRampTime) { spread.value = Math.getPartial(spread.value, expiryAge, g_expiryRampTime); } Monetary.Price memory heldPrice = SOLO_MARGIN.getMarketPrice(heldMarketId); Monetary.Price memory owedPrice = SOLO_MARGIN.getMarketPrice(owedMarketId); owedPrice.value = owedPrice.value.add(Decimal.mul(owedPrice.value, spread)); return (heldPrice, owedPrice); } // ============ Only-Solo Functions ============ function callFunction( address /* sender */, Account.Info memory account, bytes memory data ) public onlySolo(msg.sender) { ( uint256 marketId, uint32 expiryTime ) = parseCallArgs(data); // don't set expiry time for accounts with positive balance if (expiryTime != 0 && !SOLO_MARGIN.getAccountPar(account, marketId).isNegative()) { return; } setExpiry(account, marketId, expiryTime); } function getTradeCost( uint256 inputMarketId, uint256 outputMarketId, Account.Info memory makerAccount, Account.Info memory /* takerAccount */, Types.Par memory oldInputPar, Types.Par memory newInputPar, Types.Wei memory inputWei, bytes memory data ) public onlySolo(msg.sender) returns (Types.AssetAmount memory) { // return zero if input amount is zero if (inputWei.isZero()) { return Types.AssetAmount({ sign: true, denomination: Types.AssetDenomination.Par, ref: Types.AssetReference.Delta, value: 0 }); } ( uint256 owedMarketId, uint32 maxExpiry ) = parseTradeArgs(data); uint32 expiry = getExpiry(makerAccount, owedMarketId); // validate expiry Require.that( expiry != 0, FILE, "Expiry not set", makerAccount.owner, makerAccount.number, owedMarketId ); Require.that( expiry <= Time.currentTime(), FILE, "Borrow not yet expired", expiry ); Require.that( expiry <= maxExpiry, FILE, "Expiry past maxExpiry", expiry ); return getTradeCostInternal( inputMarketId, outputMarketId, makerAccount, oldInputPar, newInputPar, inputWei, owedMarketId, expiry ); } // ============ Private Functions ============ function getTradeCostInternal( uint256 inputMarketId, uint256 outputMarketId, Account.Info memory makerAccount, Types.Par memory oldInputPar, Types.Par memory newInputPar, Types.Wei memory inputWei, uint256 owedMarketId, uint32 expiry ) private returns (Types.AssetAmount memory) { Types.AssetAmount memory output; Types.Wei memory maxOutputWei = SOLO_MARGIN.getAccountWei(makerAccount, outputMarketId); if (inputWei.isPositive()) { Require.that( inputMarketId == owedMarketId, FILE, "inputMarket mismatch", inputMarketId ); Require.that( !newInputPar.isPositive(), FILE, "Borrows cannot be overpaid", newInputPar.value ); assert(oldInputPar.isNegative()); Require.that( maxOutputWei.isPositive(), FILE, "Collateral must be positive", outputMarketId, maxOutputWei.value ); output = owedWeiToHeldWei( inputWei, outputMarketId, inputMarketId, expiry ); // clear expiry if borrow is fully repaid if (newInputPar.isZero()) { setExpiry(makerAccount, owedMarketId, 0); } } else { Require.that( outputMarketId == owedMarketId, FILE, "outputMarket mismatch", outputMarketId ); Require.that( !newInputPar.isNegative(), FILE, "Collateral cannot be overused", newInputPar.value ); assert(oldInputPar.isPositive()); Require.that( maxOutputWei.isNegative(), FILE, "Borrows must be negative", outputMarketId, maxOutputWei.value ); output = heldWeiToOwedWei( inputWei, inputMarketId, outputMarketId, expiry ); // clear expiry if borrow is fully repaid if (output.value == maxOutputWei.value) { setExpiry(makerAccount, owedMarketId, 0); } } Require.that( output.value <= maxOutputWei.value, FILE, "outputMarket too small", output.value, maxOutputWei.value ); assert(output.sign != maxOutputWei.sign); return output; } function setExpiry( Account.Info memory account, uint256 marketId, uint32 time ) private { g_expiries[account.owner][account.number][marketId] = time; emit ExpirySet( account.owner, account.number, marketId, time ); } function heldWeiToOwedWei( Types.Wei memory heldWei, uint256 heldMarketId, uint256 owedMarketId, uint32 expiry ) private view returns (Types.AssetAmount memory) { ( Monetary.Price memory heldPrice, Monetary.Price memory owedPrice ) = getSpreadAdjustedPrices( heldMarketId, owedMarketId, expiry ); uint256 owedAmount = Math.getPartialRoundUp( heldWei.value, heldPrice.value, owedPrice.value ); return Types.AssetAmount({ sign: true, denomination: Types.AssetDenomination.Wei, ref: Types.AssetReference.Delta, value: owedAmount }); } function owedWeiToHeldWei( Types.Wei memory owedWei, uint256 heldMarketId, uint256 owedMarketId, uint32 expiry ) private view returns (Types.AssetAmount memory) { ( Monetary.Price memory heldPrice, Monetary.Price memory owedPrice ) = getSpreadAdjustedPrices( heldMarketId, owedMarketId, expiry ); uint256 heldAmount = Math.getPartial( owedWei.value, owedPrice.value, heldPrice.value ); return Types.AssetAmount({ sign: false, denomination: Types.AssetDenomination.Wei, ref: Types.AssetReference.Delta, value: heldAmount }); } function parseCallArgs( bytes memory data ) private pure returns ( uint256, uint32 ) { Require.that( data.length == 64, FILE, "Call data invalid length", data.length ); uint256 marketId; uint256 rawExpiry; /* solium-disable-next-line security/no-inline-assembly */ assembly { marketId := mload(add(data, 32)) rawExpiry := mload(add(data, 64)) } return ( marketId, Math.to32(rawExpiry) ); } function parseTradeArgs( bytes memory data ) private pure returns ( uint256, uint32 ) { Require.that( data.length == 64, FILE, "Trade data invalid length", data.length ); uint256 owedMarketId; uint256 rawExpiry; /* solium-disable-next-line security/no-inline-assembly */ assembly { owedMarketId := mload(add(data, 32)) rawExpiry := mload(add(data, 64)) } return ( owedMarketId, Math.to32(rawExpiry) ); } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"constant":true,"inputs":[],"name":"SOLO_MARGIN","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"components":[{"name":"owner","type":"address"},{"name":"number","type":"uint256"}],"name":"account","type":"tuple"},{"name":"marketId","type":"uint256"}],"name":"getExpiry","outputs":[{"name":"","type":"uint32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"inputMarketId","type":"uint256"},{"name":"outputMarketId","type":"uint256"},{"components":[{"name":"owner","type":"address"},{"name":"number","type":"uint256"}],"name":"makerAccount","type":"tuple"},{"components":[{"name":"owner","type":"address"},{"name":"number","type":"uint256"}],"name":"","type":"tuple"},{"components":[{"name":"sign","type":"bool"},{"name":"value","type":"uint128"}],"name":"oldInputPar","type":"tuple"},{"components":[{"name":"sign","type":"bool"},{"name":"value","type":"uint128"}],"name":"newInputPar","type":"tuple"},{"components":[{"name":"sign","type":"bool"},{"name":"value","type":"uint256"}],"name":"inputWei","type":"tuple"},{"name":"data","type":"bytes"}],"name":"getTradeCost","outputs":[{"components":[{"name":"sign","type":"bool"},{"name":"denomination","type":"uint8"},{"name":"ref","type":"uint8"},{"name":"value","type":"uint256"}],"name":"","type":"tuple"}],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"","type":"address"},{"components":[{"name":"owner","type":"address"},{"name":"number","type":"uint256"}],"name":"account","type":"tuple"},{"name":"data","type":"bytes"}],"name":"callFunction","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"heldMarketId","type":"uint256"},{"name":"owedMarketId","type":"uint256"},{"name":"expiry","type":"uint32"}],"name":"getSpreadAdjustedPrices","outputs":[{"components":[{"name":"value","type":"uint256"}],"name":"","type":"tuple"},{"components":[{"name":"value","type":"uint256"}],"name":"","type":"tuple"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"g_expiryRampTime","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"newExpiryRampTime","type":"uint256"}],"name":"ownerSetExpiryRampTime","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"soloMargin","type":"address"},{"name":"expiryRampTime","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"owner","type":"address"},{"indexed":false,"name":"number","type":"uint256"},{"indexed":false,"name":"marketId","type":"uint256"},{"indexed":false,"name":"time","type":"uint32"}],"name":"ExpirySet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"expiryRampTime","type":"uint256"}],"name":"LogExpiryRampTimeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"}]
Contract Creation Code
60806040523480156200001157600080fd5b50604051604080620025c08339810180604052620000339190810190620000cb565b60008054600160a060020a03191633178082556040518492600160a060020a039290921691907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a360018054600160a060020a031916600160a060020a0392909216919091179055600355506200012c565b6000620000b682516200010a565b9392505050565b6000620000b6825162000129565b60008060408385031215620000df57600080fd5b6000620000ed8585620000a8565b92505060206200010085828601620000bd565b9150509250929050565b600062000117826200011d565b92915050565b600160a060020a031690565b90565b612484806200013c6000396000f3fe608060405234801561001057600080fd5b50600436106100e6576000357c0100000000000000000000000000000000000000000000000000000000900480638da5cb5b1161009e578063d886248411610078578063d8862484146101b1578063f2fde38b146101c6578063f64e654c146101d9576100e6565b80638da5cb5b146101665780638f32d59b1461017b578063b139654214610190576100e6565b8063448f7065116100cf578063448f706514610129578063715018a6146101495780638b41871314610153576100e6565b80631b1fe68a146100eb5780631be7dd8314610109575b600080fd5b6100f36101ec565b604051610100919061221c565b60405180910390f35b61011c610117366004611d28565b610208565b60405161010091906122a8565b61013c610137366004611dbc565b610252565b604051610100919061223b565b610151610468565b005b610151610161366004611ca5565b6104e8565b61016e610643565b60405161010091906121cb565b61018361065f565b604051610100919061220e565b6101a361019e366004611e87565b61067d565b604051610100929190612264565b6101b9610916565b604051610100919061227f565b6101516101d4366004611c7f565b61091c565b6101516101e7366004611d9e565b610939565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b815173ffffffffffffffffffffffffffffffffffffffff166000908152600260209081526040808320828601518452825280832084845290915290205463ffffffff165b92915050565b61025a611a23565b60015433906102c39073ffffffffffffffffffffffffffffffffffffffff1682147f4f6e6c79536f6c6f0000000000000000000000000000000000000000000000007f4f6e6c7920536f6c6f2063616e2063616c6c2066756e6374696f6e000000000084610986565b6102cc84610a85565b156102fe576040805160808101909152600180825260208201908152602001600081526020016000815250915061045b565b60008061030a85610a91565b91509150600061031a8b84610208565b905061037c8163ffffffff16600014157f45787069727900000000000000000000000000000000000000000000000000007f457870697279206e6f74207365740000000000000000000000000000000000008e600001518f6020015188610b04565b6103e4610387610bf4565b63ffffffff168263ffffffff1611157f45787069727900000000000000000000000000000000000000000000000000007f426f72726f77206e6f74207965742065787069726564000000000000000000008463ffffffff16610c04565b6104458263ffffffff168263ffffffff1611157f45787069727900000000000000000000000000000000000000000000000000007f4578706972792070617374206d617845787069727900000000000000000000008463ffffffff16610c04565b6104558d8d8d8c8c8c8988610c66565b94505050505b5098975050505050505050565b61047061065f565b61047957600080fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b60015433906105519073ffffffffffffffffffffffffffffffffffffffff1682147f4f6e6c79536f6c6f0000000000000000000000000000000000000000000000007f4f6e6c7920536f6c6f2063616e2063616c6c2066756e6374696f6e000000000084610986565b60008061055d8461104a565b915091508063ffffffff1660001415801561062357506001546040517f47d1b53c0000000000000000000000000000000000000000000000000000000081526106219173ffffffffffffffffffffffffffffffffffffffff16906347d1b53c906105cd9089908790600401612249565b604080518083038186803b1580156105e457600080fd5b505afa1580156105f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061061c9190810190611d62565b61109e565b155b1561062f57505061063d565b61063a8583836110c7565b50505b50505050565b60005473ffffffffffffffffffffffffffffffffffffffff1690565b60005473ffffffffffffffffffffffffffffffffffffffff16331490565b610685611a4c565b61068d611a4c565b610695611a4c565b6001546040517fd24c48bc00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091169063d24c48bc906106ed908990899060040161228d565b60206040518083038186803b15801561070557600080fd5b505afa158015610719573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061073d9190810190611d0a565b905060006107678563ffffffff16610753610bf4565b63ffffffff1661117790919063ffffffff16565b90506003548110156107875761078482600001518260035461118c565b82525b61078f611a4c565b6001546040517f8928378e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690638928378e906107e5908b9060040161227f565b60206040518083038186803b1580156107fd57600080fd5b505afa158015610811573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506108359190810190611d0a565b905061083f611a4c565b6001546040517f8928378e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690638928378e90610895908b9060040161227f565b60206040518083038186803b1580156108ad57600080fd5b505afa1580156108c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506108e59190810190611d0a565b90506109066108f88260000151866111b8565b82519063ffffffff6111d116565b8152909890975095505050505050565b60035481565b61092461065f565b61092d57600080fd5b610936816111e3565b50565b61094161065f565b61094a57600080fd5b7fd08f204a092297d87c6a408c8d66cb1b189734e8284e655f896717b45a93a53681604051610979919061227f565b60405180910390a1600355565b8361063d5761099483611290565b7f3a200000000000000000000000000000000000000000000000000000000000006109be84611290565b7f203c0000000000000000000000000000000000000000000000000000000000006109e88561138f565b604051610a1e9594939291907f3e0000000000000000000000000000000000000000000000000000000000000090602001612057565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290527f08c379a0000000000000000000000000000000000000000000000000000000008252610a7c9160040161222a565b60405180910390fd5b6020810151155b919050565b600080610ae583516040147f45787069727900000000000000000000000000000000000000000000000000007f5472616465206461746120696e76616c6964206c656e677468000000000000008651610c04565b6020830151604084015181610af982611542565b935093505050915091565b8561063a57610b1285611290565b7f3a20000000000000000000000000000000000000000000000000000000000000610b3c86611290565b7f203c000000000000000000000000000000000000000000000000000000000000610b668761138f565b7f2c20000000000000000000000000000000000000000000000000000000000000610b9088611598565b7f2c20000000000000000000000000000000000000000000000000000000000000610bba89611598565b604051610a1e999897969594939291907f3e0000000000000000000000000000000000000000000000000000000000000090602001612131565b6000610bff42611542565b905090565b8361063d57610c1283611290565b7f3a20000000000000000000000000000000000000000000000000000000000000610c3c84611290565b7f203c0000000000000000000000000000000000000000000000000000000000006109e885611598565b610c6e611a23565b610c76611a23565b610c7e611a5f565b6001546040517fc190c2ec00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091169063c190c2ec90610cd6908c908e90600401612249565b604080518083038186803b158015610ced57600080fd5b505afa158015610d01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610d259190810190611d80565b9050610d30866116c6565b15610e8357610d83858c147f45787069727900000000000000000000000000000000000000000000000000007f696e7075744d61726b6574206d69736d617463680000000000000000000000008e610c04565b610dee610d8f886116dc565b157f45787069727900000000000000000000000000000000000000000000000000007f426f72726f77732063616e6e6f74206265206f766572706169640000000000008a602001516fffffffffffffffffffffffffffffffff16610c04565b610df78861109e565b610dfd57fe5b610e56610e09826116c6565b7f45787069727900000000000000000000000000000000000000000000000000007f436f6c6c61746572616c206d75737420626520706f73697469766500000000008d8560200151611704565b610e62868b8d876117cf565b9150610e6d87611844565b15610e7e57610e7e898660006110c7565b610fce565b610ed1858b147f45787069727900000000000000000000000000000000000000000000000000007f6f75747075744d61726b6574206d69736d6174636800000000000000000000008d610c04565b610f3c610edd8861109e565b157f45787069727900000000000000000000000000000000000000000000000000007f436f6c6c61746572616c2063616e6e6f74206265206f766572757365640000008a602001516fffffffffffffffffffffffffffffffff16610c04565b610f45886116dc565b610f4b57fe5b610fa4610f578261185e565b7f45787069727900000000000000000000000000000000000000000000000000007f426f72726f7773206d757374206265206e6567617469766500000000000000008d8560200151611704565b610fb0868c8c87611875565b9150806020015182606001511415610fce57610fce898660006110c7565b6020810151606083015161102b9180821115917f4578706972790000000000000000000000000000000000000000000000000000917f6f75747075744d61726b657420746f6f20736d616c6c000000000000000000009190611704565b805182511515901515141561103c57fe5b509998505050505050505050565b600080610ae583516040147f45787069727900000000000000000000000000000000000000000000000000007f43616c6c206461746120696e76616c6964206c656e67746800000000000000008651610c04565b805160009015801561024c575050602001516fffffffffffffffffffffffffffffffff16151590565b825173ffffffffffffffffffffffffffffffffffffffff166000908152600260209081526040808320828701805185529083528184208685529092529182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff85161790558451905191517ecee2201664da23900ada76f5e96bcae576e5d7253b36f10dc1b379597d521b9261116a9291869086906121d9565b60405180910390a1505050565b60008282111561118657600080fd5b50900390565b60006111ae826111a2868663ffffffff6118d216565b9063ffffffff6118f916565b90505b9392505050565b60006111b1838360000151670de0b6b3a764000061118c565b6000828201838110156111b157600080fd5b73ffffffffffffffffffffffffffffffffffffffff811661120357600080fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b606080826040516020016112a49190612011565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152919052905060205b80156113745781517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9091019082908290811061131057fe5b6020910101517f010000000000000000000000000000000000000000000000000000000000000090819004027fff00000000000000000000000000000000000000000000000000000000000000161561136f5760010181529050610a8c565b6112d7565b5060408051600080825260208201909252905b509392505050565b60408051602a808252606082810190935273ffffffffffffffffffffffffffffffffffffffff841691839160208201818038833901905050905060307f010000000000000000000000000000000000000000000000000000000000000002816000815181106113fa57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060787f0100000000000000000000000000000000000000000000000000000000000000028160018151811061145a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060005b601481101561138757600281026114a5600f851661191b565b8382602903815181106114b457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506010909304926114f5600f851661191b565b83826028038151811061150457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053505060109092049160010161148c565b60008161024c63ffffffff821682147f4d617468000000000000000000000000000000000000000000000000000000007f556e73616665206361737420746f2075696e743332000000000000000000000061197b565b6060816115d9575060408051808201909152600181527f30000000000000000000000000000000000000000000000000000000000000006020820152610a8c565b8160005b81156115f157600101600a820491506115dd565b6060816040519080825280601f01601f19166020018201604052801561161e576020820181803883390190505b508593509050815b80156116bd577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600a84066030017f01000000000000000000000000000000000000000000000000000000000000000282828151811061168357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a84049350611626565b50949350505050565b8051600090801561024c57505060200151151590565b8051600090801561024c575050602001516fffffffffffffffffffffffffffffffff16151590565b846117c85761171284611290565b7f3a2000000000000000000000000000000000000000000000000000000000000061173c85611290565b7f203c00000000000000000000000000000000000000000000000000000000000061176686611598565b7f2c2000000000000000000000000000000000000000000000000000000000000061179087611598565b604051610a1e97969594939291907f3e00000000000000000000000000000000000000000000000000000000000000906020016120b5565b5050505050565b6117d7611a23565b6117df611a4c565b6117e7611a4c565b6117f286868661067d565b91509150600061180f88602001518360000151856000015161118c565b604080516080810190915260008082529192509060208201905b81526020016000815260200191909152979650505050505050565b602001516fffffffffffffffffffffffffffffffff161590565b805160009015801561024c57505060200151151590565b61187d611a23565b611885611a4c565b61188d611a4c565b61189886868661067d565b9150915060006118b58860200151846000015184600001516119ca565b604080516080810190915260018152909150602081016000611829565b6000826118e15750600061024c565b828202828482816118ee57fe5b04146111b157600080fd5b600080821161190757600080fd5b600082848161191257fe5b04949350505050565b6000600a82101561195257507f01000000000000000000000000000000000000000000000000000000000000006030820102610a8c565b506057017f01000000000000000000000000000000000000000000000000000000000000000290565b826119c55761198982611290565b7f3a200000000000000000000000000000000000000000000000000000000000006119b383611290565b604051602001610a1e93929190612026565b505050565b60008315806119d7575082155b156119ee576119e76000836118f9565b90506111b1565b6111ae6001611a17846111a283611a0b8a8a63ffffffff6118d216565b9063ffffffff61117716565b9063ffffffff6111d116565b604080516080810190915260008082526020820190815260200160008152602001600081525090565b6040518060200160405280600081525090565b604080518082019091526000808252602082015290565b60006111b18235612330565b60006111b1823561233b565b60006111b1825161233b565b600082601f830112611aab57600080fd5b8135611abe611ab9826122dd565b6122b6565b91508082526020830160208301858383011115611ada57600080fd5b611ae58382846123ea565b50505092915050565b600060208284031215611b0057600080fd5b611b0a60206122b6565b90506000611b188484611c67565b82525092915050565b600060408284031215611b3357600080fd5b611b3d60406122b6565b90506000611b4b8484611a76565b8252506020611b5c84848301611c5b565b60208301525092915050565b600060408284031215611b7a57600080fd5b611b8460406122b6565b90506000611b928484611a82565b8252506020611b5c84848301611c43565b600060408284031215611bb557600080fd5b611bbf60406122b6565b90506000611bcd8484611a8e565b8252506020611b5c84848301611c4f565b600060408284031215611bf057600080fd5b611bfa60406122b6565b90506000611b4b8484611a82565b600060408284031215611c1a57600080fd5b611c2460406122b6565b90506000611c328484611a8e565b8252506020611b5c84848301611c67565b60006111b182356123bf565b60006111b182516123bf565b60006111b1823561238a565b60006111b1825161238a565b60006111b182356123b6565b600060208284031215611c9157600080fd5b6000611c9d8484611a76565b949350505050565b600080600060808486031215611cba57600080fd5b6000611cc68686611a76565b9350506020611cd786828701611b21565b925050606084013567ffffffffffffffff811115611cf457600080fd5b611d0086828701611a9a565b9150509250925092565b600060208284031215611d1c57600080fd5b6000611c9d8484611aee565b60008060608385031215611d3b57600080fd5b6000611d478585611b21565b9250506040611d5885828601611c5b565b9150509250929050565b600060408284031215611d7457600080fd5b6000611c9d8484611ba3565b600060408284031215611d9257600080fd5b6000611c9d8484611c08565b600060208284031215611db057600080fd5b6000611c9d8484611c5b565b6000806000806000806000806101a0898b031215611dd957600080fd5b6000611de58b8b611c5b565b9850506020611df68b828c01611c5b565b9750506040611e078b828c01611b21565b9650506080611e188b828c01611b21565b95505060c0611e298b828c01611b68565b945050610100611e3b8b828c01611b68565b935050610140611e4d8b828c01611bde565b92505061018089013567ffffffffffffffff811115611e6b57600080fd5b611e778b828c01611a9a565b9150509295985092959890939650565b600080600060608486031215611e9c57600080fd5b6000611ea88686611c5b565b9350506020611eb986828701611c5b565b9250506040611d0086828701611c73565b611ed381612330565b82525050565b611ed38161233b565b611ed3611eee82612340565b61238a565b611ed3611eee82612365565b611ed3611eee8261238a565b6000611f1682612323565b611f208185610a8c565b9350611f308185602086016123f6565b9290920192915050565b611ed3816123d4565b611ed3816123df565b6000611f5782612323565b611f618185612327565b9350611f718185602086016123f6565b611f7a81612422565b9093019392505050565b80516080830190611f958482611ed9565b506020820151611fa86020850182611f43565b506040820151611fbb6040850182611f43565b50606082015161063d6060850182611fff565b80516040830190611fdf8482611eca565b50602082015161063d6020850182611fff565b8051602083019061063d84825b611ed38161238a565b611ed3816123b6565b600061201d8284611eff565b50602001919050565b60006120328286611f0b565b915061203e8285611ef3565b60028201915061204e8284611f0b565b95945050505050565b60006120638289611f0b565b915061206f8288611ef3565b60028201915061207f8287611f0b565b915061208b8286611ef3565b60028201915061209b8285611f0b565b91506120a78284611ee2565b506001019695505050505050565b60006120c1828b611f0b565b91506120cd828a611ef3565b6002820191506120dd8289611f0b565b91506120e98288611ef3565b6002820191506120f98287611f0b565b91506121058286611ef3565b6002820191506121158285611f0b565b91506121218284611ee2565b5060010198975050505050505050565b600061213d828d611f0b565b9150612149828c611ef3565b600282019150612159828b611f0b565b9150612165828a611ef3565b6002820191506121758289611f0b565b91506121818288611ef3565b6002820191506121918287611f0b565b915061219d8286611ef3565b6002820191506121ad8285611f0b565b91506121b98284611ee2565b506001019a9950505050505050505050565b6020810161024c8284611eca565b608081016121e78287611eca565b6121f46020830186611fff565b6122016040830185611fff565b61204e6060830184612008565b6020810161024c8284611ed9565b6020810161024c8284611f3a565b602080825281016111b18184611f4c565b6080810161024c8284611f84565b606081016122578285611fce565b6111b16040830184611fff565b604081016122728285611ff2565b6111b16020830184611ff2565b6020810161024c8284611fff565b6040810161229b8285611fff565b6111b16020830184611fff565b6020810161024c8284612008565b60405181810167ffffffffffffffff811182821017156122d557600080fd5b604052919050565b600067ffffffffffffffff8211156122f457600080fd5b506020601f919091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0160190565b5190565b90815260200190565b600061024c8261239d565b151590565b7fff000000000000000000000000000000000000000000000000000000000000001690565b7fffff0000000000000000000000000000000000000000000000000000000000001690565b90565b60006002821061239957fe5b5090565b73ffffffffffffffffffffffffffffffffffffffff1690565b63ffffffff1690565b6fffffffffffffffffffffffffffffffff1690565b600061024c82612330565b600061024c8261238d565b82818337506000910152565b60005b838110156124115781810151838201526020016123f9565b8381111561063d5750506000910152565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169056fea265627a7a72305820f213e5dd9a9897c2f350dca3ef16986b17119dd0405f1ea89af25e495c6452876c6578706572696d656e74616cf500370000000000000000000000001e0447b19bb6ecfdae1e4ae1694b0c3659614e4e0000000000000000000000000000000000000000000000000000000000000e10
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100e6576000357c0100000000000000000000000000000000000000000000000000000000900480638da5cb5b1161009e578063d886248411610078578063d8862484146101b1578063f2fde38b146101c6578063f64e654c146101d9576100e6565b80638da5cb5b146101665780638f32d59b1461017b578063b139654214610190576100e6565b8063448f7065116100cf578063448f706514610129578063715018a6146101495780638b41871314610153576100e6565b80631b1fe68a146100eb5780631be7dd8314610109575b600080fd5b6100f36101ec565b604051610100919061221c565b60405180910390f35b61011c610117366004611d28565b610208565b60405161010091906122a8565b61013c610137366004611dbc565b610252565b604051610100919061223b565b610151610468565b005b610151610161366004611ca5565b6104e8565b61016e610643565b60405161010091906121cb565b61018361065f565b604051610100919061220e565b6101a361019e366004611e87565b61067d565b604051610100929190612264565b6101b9610916565b604051610100919061227f565b6101516101d4366004611c7f565b61091c565b6101516101e7366004611d9e565b610939565b60015473ffffffffffffffffffffffffffffffffffffffff1681565b815173ffffffffffffffffffffffffffffffffffffffff166000908152600260209081526040808320828601518452825280832084845290915290205463ffffffff165b92915050565b61025a611a23565b60015433906102c39073ffffffffffffffffffffffffffffffffffffffff1682147f4f6e6c79536f6c6f0000000000000000000000000000000000000000000000007f4f6e6c7920536f6c6f2063616e2063616c6c2066756e6374696f6e000000000084610986565b6102cc84610a85565b156102fe576040805160808101909152600180825260208201908152602001600081526020016000815250915061045b565b60008061030a85610a91565b91509150600061031a8b84610208565b905061037c8163ffffffff16600014157f45787069727900000000000000000000000000000000000000000000000000007f457870697279206e6f74207365740000000000000000000000000000000000008e600001518f6020015188610b04565b6103e4610387610bf4565b63ffffffff168263ffffffff1611157f45787069727900000000000000000000000000000000000000000000000000007f426f72726f77206e6f74207965742065787069726564000000000000000000008463ffffffff16610c04565b6104458263ffffffff168263ffffffff1611157f45787069727900000000000000000000000000000000000000000000000000007f4578706972792070617374206d617845787069727900000000000000000000008463ffffffff16610c04565b6104558d8d8d8c8c8c8988610c66565b94505050505b5098975050505050505050565b61047061065f565b61047957600080fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff909116907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000169055565b60015433906105519073ffffffffffffffffffffffffffffffffffffffff1682147f4f6e6c79536f6c6f0000000000000000000000000000000000000000000000007f4f6e6c7920536f6c6f2063616e2063616c6c2066756e6374696f6e000000000084610986565b60008061055d8461104a565b915091508063ffffffff1660001415801561062357506001546040517f47d1b53c0000000000000000000000000000000000000000000000000000000081526106219173ffffffffffffffffffffffffffffffffffffffff16906347d1b53c906105cd9089908790600401612249565b604080518083038186803b1580156105e457600080fd5b505afa1580156105f8573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061061c9190810190611d62565b61109e565b155b1561062f57505061063d565b61063a8583836110c7565b50505b50505050565b60005473ffffffffffffffffffffffffffffffffffffffff1690565b60005473ffffffffffffffffffffffffffffffffffffffff16331490565b610685611a4c565b61068d611a4c565b610695611a4c565b6001546040517fd24c48bc00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091169063d24c48bc906106ed908990899060040161228d565b60206040518083038186803b15801561070557600080fd5b505afa158015610719573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525061073d9190810190611d0a565b905060006107678563ffffffff16610753610bf4565b63ffffffff1661117790919063ffffffff16565b90506003548110156107875761078482600001518260035461118c565b82525b61078f611a4c565b6001546040517f8928378e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690638928378e906107e5908b9060040161227f565b60206040518083038186803b1580156107fd57600080fd5b505afa158015610811573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506108359190810190611d0a565b905061083f611a4c565b6001546040517f8928378e00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff90911690638928378e90610895908b9060040161227f565b60206040518083038186803b1580156108ad57600080fd5b505afa1580156108c1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052506108e59190810190611d0a565b90506109066108f88260000151866111b8565b82519063ffffffff6111d116565b8152909890975095505050505050565b60035481565b61092461065f565b61092d57600080fd5b610936816111e3565b50565b61094161065f565b61094a57600080fd5b7fd08f204a092297d87c6a408c8d66cb1b189734e8284e655f896717b45a93a53681604051610979919061227f565b60405180910390a1600355565b8361063d5761099483611290565b7f3a200000000000000000000000000000000000000000000000000000000000006109be84611290565b7f203c0000000000000000000000000000000000000000000000000000000000006109e88561138f565b604051610a1e9594939291907f3e0000000000000000000000000000000000000000000000000000000000000090602001612057565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290527f08c379a0000000000000000000000000000000000000000000000000000000008252610a7c9160040161222a565b60405180910390fd5b6020810151155b919050565b600080610ae583516040147f45787069727900000000000000000000000000000000000000000000000000007f5472616465206461746120696e76616c6964206c656e677468000000000000008651610c04565b6020830151604084015181610af982611542565b935093505050915091565b8561063a57610b1285611290565b7f3a20000000000000000000000000000000000000000000000000000000000000610b3c86611290565b7f203c000000000000000000000000000000000000000000000000000000000000610b668761138f565b7f2c20000000000000000000000000000000000000000000000000000000000000610b9088611598565b7f2c20000000000000000000000000000000000000000000000000000000000000610bba89611598565b604051610a1e999897969594939291907f3e0000000000000000000000000000000000000000000000000000000000000090602001612131565b6000610bff42611542565b905090565b8361063d57610c1283611290565b7f3a20000000000000000000000000000000000000000000000000000000000000610c3c84611290565b7f203c0000000000000000000000000000000000000000000000000000000000006109e885611598565b610c6e611a23565b610c76611a23565b610c7e611a5f565b6001546040517fc190c2ec00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091169063c190c2ec90610cd6908c908e90600401612249565b604080518083038186803b158015610ced57600080fd5b505afa158015610d01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250610d259190810190611d80565b9050610d30866116c6565b15610e8357610d83858c147f45787069727900000000000000000000000000000000000000000000000000007f696e7075744d61726b6574206d69736d617463680000000000000000000000008e610c04565b610dee610d8f886116dc565b157f45787069727900000000000000000000000000000000000000000000000000007f426f72726f77732063616e6e6f74206265206f766572706169640000000000008a602001516fffffffffffffffffffffffffffffffff16610c04565b610df78861109e565b610dfd57fe5b610e56610e09826116c6565b7f45787069727900000000000000000000000000000000000000000000000000007f436f6c6c61746572616c206d75737420626520706f73697469766500000000008d8560200151611704565b610e62868b8d876117cf565b9150610e6d87611844565b15610e7e57610e7e898660006110c7565b610fce565b610ed1858b147f45787069727900000000000000000000000000000000000000000000000000007f6f75747075744d61726b6574206d69736d6174636800000000000000000000008d610c04565b610f3c610edd8861109e565b157f45787069727900000000000000000000000000000000000000000000000000007f436f6c6c61746572616c2063616e6e6f74206265206f766572757365640000008a602001516fffffffffffffffffffffffffffffffff16610c04565b610f45886116dc565b610f4b57fe5b610fa4610f578261185e565b7f45787069727900000000000000000000000000000000000000000000000000007f426f72726f7773206d757374206265206e6567617469766500000000000000008d8560200151611704565b610fb0868c8c87611875565b9150806020015182606001511415610fce57610fce898660006110c7565b6020810151606083015161102b9180821115917f4578706972790000000000000000000000000000000000000000000000000000917f6f75747075744d61726b657420746f6f20736d616c6c000000000000000000009190611704565b805182511515901515141561103c57fe5b509998505050505050505050565b600080610ae583516040147f45787069727900000000000000000000000000000000000000000000000000007f43616c6c206461746120696e76616c6964206c656e67746800000000000000008651610c04565b805160009015801561024c575050602001516fffffffffffffffffffffffffffffffff16151590565b825173ffffffffffffffffffffffffffffffffffffffff166000908152600260209081526040808320828701805185529083528184208685529092529182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000001663ffffffff85161790558451905191517ecee2201664da23900ada76f5e96bcae576e5d7253b36f10dc1b379597d521b9261116a9291869086906121d9565b60405180910390a1505050565b60008282111561118657600080fd5b50900390565b60006111ae826111a2868663ffffffff6118d216565b9063ffffffff6118f916565b90505b9392505050565b60006111b1838360000151670de0b6b3a764000061118c565b6000828201838110156111b157600080fd5b73ffffffffffffffffffffffffffffffffffffffff811661120357600080fd5b6000805460405173ffffffffffffffffffffffffffffffffffffffff808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff92909216919091179055565b606080826040516020016112a49190612011565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152919052905060205b80156113745781517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff9091019082908290811061131057fe5b6020910101517f010000000000000000000000000000000000000000000000000000000000000090819004027fff00000000000000000000000000000000000000000000000000000000000000161561136f5760010181529050610a8c565b6112d7565b5060408051600080825260208201909252905b509392505050565b60408051602a808252606082810190935273ffffffffffffffffffffffffffffffffffffffff841691839160208201818038833901905050905060307f010000000000000000000000000000000000000000000000000000000000000002816000815181106113fa57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060787f0100000000000000000000000000000000000000000000000000000000000000028160018151811061145a57fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060005b601481101561138757600281026114a5600f851661191b565b8382602903815181106114b457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506010909304926114f5600f851661191b565b83826028038151811061150457fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053505060109092049160010161148c565b60008161024c63ffffffff821682147f4d617468000000000000000000000000000000000000000000000000000000007f556e73616665206361737420746f2075696e743332000000000000000000000061197b565b6060816115d9575060408051808201909152600181527f30000000000000000000000000000000000000000000000000000000000000006020820152610a8c565b8160005b81156115f157600101600a820491506115dd565b6060816040519080825280601f01601f19166020018201604052801561161e576020820181803883390190505b508593509050815b80156116bd577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff01600a84066030017f01000000000000000000000000000000000000000000000000000000000000000282828151811061168357fe5b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600a84049350611626565b50949350505050565b8051600090801561024c57505060200151151590565b8051600090801561024c575050602001516fffffffffffffffffffffffffffffffff16151590565b846117c85761171284611290565b7f3a2000000000000000000000000000000000000000000000000000000000000061173c85611290565b7f203c00000000000000000000000000000000000000000000000000000000000061176686611598565b7f2c2000000000000000000000000000000000000000000000000000000000000061179087611598565b604051610a1e97969594939291907f3e00000000000000000000000000000000000000000000000000000000000000906020016120b5565b5050505050565b6117d7611a23565b6117df611a4c565b6117e7611a4c565b6117f286868661067d565b91509150600061180f88602001518360000151856000015161118c565b604080516080810190915260008082529192509060208201905b81526020016000815260200191909152979650505050505050565b602001516fffffffffffffffffffffffffffffffff161590565b805160009015801561024c57505060200151151590565b61187d611a23565b611885611a4c565b61188d611a4c565b61189886868661067d565b9150915060006118b58860200151846000015184600001516119ca565b604080516080810190915260018152909150602081016000611829565b6000826118e15750600061024c565b828202828482816118ee57fe5b04146111b157600080fd5b600080821161190757600080fd5b600082848161191257fe5b04949350505050565b6000600a82101561195257507f01000000000000000000000000000000000000000000000000000000000000006030820102610a8c565b506057017f01000000000000000000000000000000000000000000000000000000000000000290565b826119c55761198982611290565b7f3a200000000000000000000000000000000000000000000000000000000000006119b383611290565b604051602001610a1e93929190612026565b505050565b60008315806119d7575082155b156119ee576119e76000836118f9565b90506111b1565b6111ae6001611a17846111a283611a0b8a8a63ffffffff6118d216565b9063ffffffff61117716565b9063ffffffff6111d116565b604080516080810190915260008082526020820190815260200160008152602001600081525090565b6040518060200160405280600081525090565b604080518082019091526000808252602082015290565b60006111b18235612330565b60006111b1823561233b565b60006111b1825161233b565b600082601f830112611aab57600080fd5b8135611abe611ab9826122dd565b6122b6565b91508082526020830160208301858383011115611ada57600080fd5b611ae58382846123ea565b50505092915050565b600060208284031215611b0057600080fd5b611b0a60206122b6565b90506000611b188484611c67565b82525092915050565b600060408284031215611b3357600080fd5b611b3d60406122b6565b90506000611b4b8484611a76565b8252506020611b5c84848301611c5b565b60208301525092915050565b600060408284031215611b7a57600080fd5b611b8460406122b6565b90506000611b928484611a82565b8252506020611b5c84848301611c43565b600060408284031215611bb557600080fd5b611bbf60406122b6565b90506000611bcd8484611a8e565b8252506020611b5c84848301611c4f565b600060408284031215611bf057600080fd5b611bfa60406122b6565b90506000611b4b8484611a82565b600060408284031215611c1a57600080fd5b611c2460406122b6565b90506000611c328484611a8e565b8252506020611b5c84848301611c67565b60006111b182356123bf565b60006111b182516123bf565b60006111b1823561238a565b60006111b1825161238a565b60006111b182356123b6565b600060208284031215611c9157600080fd5b6000611c9d8484611a76565b949350505050565b600080600060808486031215611cba57600080fd5b6000611cc68686611a76565b9350506020611cd786828701611b21565b925050606084013567ffffffffffffffff811115611cf457600080fd5b611d0086828701611a9a565b9150509250925092565b600060208284031215611d1c57600080fd5b6000611c9d8484611aee565b60008060608385031215611d3b57600080fd5b6000611d478585611b21565b9250506040611d5885828601611c5b565b9150509250929050565b600060408284031215611d7457600080fd5b6000611c9d8484611ba3565b600060408284031215611d9257600080fd5b6000611c9d8484611c08565b600060208284031215611db057600080fd5b6000611c9d8484611c5b565b6000806000806000806000806101a0898b031215611dd957600080fd5b6000611de58b8b611c5b565b9850506020611df68b828c01611c5b565b9750506040611e078b828c01611b21565b9650506080611e188b828c01611b21565b95505060c0611e298b828c01611b68565b945050610100611e3b8b828c01611b68565b935050610140611e4d8b828c01611bde565b92505061018089013567ffffffffffffffff811115611e6b57600080fd5b611e778b828c01611a9a565b9150509295985092959890939650565b600080600060608486031215611e9c57600080fd5b6000611ea88686611c5b565b9350506020611eb986828701611c5b565b9250506040611d0086828701611c73565b611ed381612330565b82525050565b611ed38161233b565b611ed3611eee82612340565b61238a565b611ed3611eee82612365565b611ed3611eee8261238a565b6000611f1682612323565b611f208185610a8c565b9350611f308185602086016123f6565b9290920192915050565b611ed3816123d4565b611ed3816123df565b6000611f5782612323565b611f618185612327565b9350611f718185602086016123f6565b611f7a81612422565b9093019392505050565b80516080830190611f958482611ed9565b506020820151611fa86020850182611f43565b506040820151611fbb6040850182611f43565b50606082015161063d6060850182611fff565b80516040830190611fdf8482611eca565b50602082015161063d6020850182611fff565b8051602083019061063d84825b611ed38161238a565b611ed3816123b6565b600061201d8284611eff565b50602001919050565b60006120328286611f0b565b915061203e8285611ef3565b60028201915061204e8284611f0b565b95945050505050565b60006120638289611f0b565b915061206f8288611ef3565b60028201915061207f8287611f0b565b915061208b8286611ef3565b60028201915061209b8285611f0b565b91506120a78284611ee2565b506001019695505050505050565b60006120c1828b611f0b565b91506120cd828a611ef3565b6002820191506120dd8289611f0b565b91506120e98288611ef3565b6002820191506120f98287611f0b565b91506121058286611ef3565b6002820191506121158285611f0b565b91506121218284611ee2565b5060010198975050505050505050565b600061213d828d611f0b565b9150612149828c611ef3565b600282019150612159828b611f0b565b9150612165828a611ef3565b6002820191506121758289611f0b565b91506121818288611ef3565b6002820191506121918287611f0b565b915061219d8286611ef3565b6002820191506121ad8285611f0b565b91506121b98284611ee2565b506001019a9950505050505050505050565b6020810161024c8284611eca565b608081016121e78287611eca565b6121f46020830186611fff565b6122016040830185611fff565b61204e6060830184612008565b6020810161024c8284611ed9565b6020810161024c8284611f3a565b602080825281016111b18184611f4c565b6080810161024c8284611f84565b606081016122578285611fce565b6111b16040830184611fff565b604081016122728285611ff2565b6111b16020830184611ff2565b6020810161024c8284611fff565b6040810161229b8285611fff565b6111b16020830184611fff565b6020810161024c8284612008565b60405181810167ffffffffffffffff811182821017156122d557600080fd5b604052919050565b600067ffffffffffffffff8211156122f457600080fd5b506020601f919091017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0160190565b5190565b90815260200190565b600061024c8261239d565b151590565b7fff000000000000000000000000000000000000000000000000000000000000001690565b7fffff0000000000000000000000000000000000000000000000000000000000001690565b90565b60006002821061239957fe5b5090565b73ffffffffffffffffffffffffffffffffffffffff1690565b63ffffffff1690565b6fffffffffffffffffffffffffffffffff1690565b600061024c82612330565b600061024c8261238d565b82818337506000910152565b60005b838110156124115781810151838201526020016123f9565b8381111561063d5750506000910152565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169056fea265627a7a72305820f213e5dd9a9897c2f350dca3ef16986b17119dd0405f1ea89af25e495c6452876c6578706572696d656e74616cf50037
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000001e0447b19bb6ecfdae1e4ae1694b0c3659614e4e0000000000000000000000000000000000000000000000000000000000000e10
-----Decoded View---------------
Arg [0] : soloMargin (address): 0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e
Arg [1] : expiryRampTime (uint256): 3600
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000001e0447b19bb6ecfdae1e4ae1694b0c3659614e4e
Arg [1] : 0000000000000000000000000000000000000000000000000000000000000e10
Deployed Bytecode Sourcemap
155405:11248:0:-;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;155405:11248:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;154546:29;;;:::i;:::-;;;;;;;;;;;;;;;;156816:229;;;;;;;;;:::i;:::-;;;;;;;;158590:1719;;;;;;;;;:::i;:::-;;;;;;;;4071:140;;;:::i;:::-;;158040:542;;;;;;;;;:::i;3358:79::-;;;:::i;:::-;;;;;;;;3693:92;;;:::i;:::-;;;;;;;;157053:923;;;;;;;;;:::i;:::-;;;;;;;;;156204:31;;;:::i;:::-;;;;;;;;4388:109;;;;;;;;;:::i;156537:227::-;;;;;;;;;:::i;154546:29::-;;;;;;:::o;156816:229::-;156997:13;;156986:25;;156955:6;156986:25;;;:10;:25;;;;;;;;157012:14;;;;156986:41;;;;;;;:51;;;;;;;;;;;156816:229;;;;;:::o;158590:1719::-;158982:24;;:::i;:::-;154897:11;;158952:10;;154854:148;;154897:11;;154881:28;;154924:4;154854:148;158952:10;154854:12;:148::i;:::-;159076:17;:8;:15;:17::i;:::-;159072:257;;;159117:200;;;;;;;;;159160:4;159117:200;;;;;;;;;;;159248:26;159117:200;;;;159300:1;159117:200;;;159110:207;;;;159072:257;159356:20;159391:16;159421:20;159436:4;159421:14;:20::i;:::-;159341:100;;;;159454:13;159470:37;159480:12;159494;159470:9;:37::i;:::-;159454:53;;159548:193;159575:6;:11;;159585:1;159575:11;;159601:4;159548:193;159651:12;:18;;;159684:12;:19;;;159718:12;159548;:193::i;:::-;159752:145;159789:18;:16;:18::i;:::-;159779:28;;:6;:28;;;;159822:4;159752:145;159880:6;159752:145;;:12;:145::i;:::-;159908:135;159945:9;159935:19;;:6;:19;;;;159969:4;159908:135;160026:6;159908:135;;:12;:135::i;:::-;160063:238;160098:13;160126:14;160155:12;160182:11;160208;160234:8;160257:12;160284:6;160063:20;:238::i;:::-;160056:245;;;;;155013:1;158590:1719;;;;;;;;;;;:::o;4071:140::-;3570:9;:7;:9::i;:::-;3562:18;;;;;;4170:1;4154:6;;4133:40;;;4154:6;;;;4133:40;;4170:1;;4133:40;4201:1;4184:19;;;;;;4071:140::o;158040:542::-;154897:11;;158200:10;;154854:148;;154897:11;;154881:28;;154924:4;154854:148;158200:10;154854:12;:148::i;:::-;158243:16;158274:17;158305:19;158319:4;158305:13;:19::i;:::-;158228:96;;;;158410:10;:15;;158424:1;158410:15;;:77;;;;-1:-1:-1;158430:11:0;;:44;;;;;:57;;:11;;;:25;;:44;;158456:7;;158465:8;;158430:44;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;158430:44:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;158430:44:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;158430:44:0;;;;;;;;;:55;:57::i;:::-;158429:58;158410:77;158406:116;;;158504:7;;;;158406:116;158534:40;158544:7;158553:8;158563:10;158534:9;:40::i;:::-;155013:1;;;158040:542;;;;:::o;3358:79::-;3396:7;3423:6;;;3358:79;:::o;3693:92::-;3733:4;3771:6;;;3757:10;:20;;3693:92::o;157053:923::-;157241:21;;:::i;:::-;157277;;:::i;:::-;157326:26;;:::i;:::-;157355:11;;:104;;;;;:11;;;;;:39;;:104;;157409:12;;157436;;157355:104;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;157355:104:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;157355:104:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;157355:104:0;;;;;;;;;157326:133;;157472:17;157492:30;157515:6;157492:30;;:18;:16;:18::i;:::-;:22;;;;:30;;;;:::i;:::-;157472:50;;157551:16;;157539:9;:28;157535:134;;;157599:58;157615:6;:12;;;157629:9;157640:16;;157599:15;:58::i;:::-;157584:73;;157535:134;157681:31;;:::i;:::-;157715:11;;:40;;;;;:11;;;;;:26;;:40;;157742:12;;157715:40;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;157715:40:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;157715:40:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;157715:40:0;;;;;;;;;157681:74;;157766:31;;:::i;:::-;157800:11;;:40;;;;;:11;;;;;:26;;:40;;157827:12;;157800:40;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;157800:40:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;157800:40:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;157800:40:0;;;;;;;;;157766:74;;157869:57;157889:36;157901:9;:15;;;157918:6;157889:11;:36::i;:::-;157869:15;;;:57;:19;:57;:::i;:::-;157851:75;;157947:9;;157851:75;;-1:-1:-1;157053:923:0;-1:-1:-1;;;;;;157053:923:0:o;156204:31::-;;;;:::o;4388:109::-;3570:9;:7;:9::i;:::-;3562:18;;;;;;4461:28;4480:8;4461:18;:28::i;:::-;4388:109;:::o;156537:227::-;3570:9;:7;:9::i;:::-;3562:18;;;;;;156670:39;156691:17;156670:39;;;;;;;;;;;;;;;156720:16;:36;156537:227::o;7228:566::-;7397:4;7392:395;;7515:15;7525:4;7515:9;:15::i;:::-;7557:5;7589:17;7599:6;7589:9;:17::i;:::-;7633:6;7666:19;7676:8;7666:9;:19::i;:::-;7472:269;;;;;;;;;7712:6;;7472:269;;;;;;;;22:32:-1;26:21;;;22:32;6:49;;7472:269:0;;;;7418:357;;;;;;;;;;;;;;;;;20303:145;20428:7;;;;:12;20303:145;;;;:::o;165970:680::-;166092:7;166114:6;166148:142;166175:4;:11;166190:2;166175:17;166207:4;166148:142;166268:4;:11;166148:12;:142::i;:::-;166488:2;166478:13;;166472:20;166535:2;166525:13;;166519:20;166472;166611;166519;166611:9;:20::i;:::-;166562:80;;;;;;165970:680;;;:::o;8481:776::-;8704:4;8699:551;;8822:15;8832:4;8822:9;:15::i;:::-;8864:5;8896:17;8906:6;8896:9;:17::i;:::-;8940:6;8973:19;8983:8;8973:9;:19::i;:::-;9019:5;9051:19;9061:8;9051:9;:19::i;:::-;9097:5;9129:19;9139:8;9129:9;:19::i;:::-;8779:425;;;;;;;;;;;;;9175:6;;8779:425;;;;26186:138;26259:6;26290:26;26300:15;26290:9;:26::i;:::-;26283:33;;26186:138;:::o;5975:566::-;6144:4;6139:395;;6262:15;6272:4;6262:9;:15::i;:::-;6304:5;6336:17;6346:6;6336:9;:17::i;:::-;6380:6;6413:19;6423:8;6413:9;:19::i;160371:2886::-;160720:24;;:::i;:::-;160762:31;;:::i;:::-;160804:29;;:::i;:::-;160836:11;;:55;;;;;:11;;;;;:25;;:55;;160862:12;;160876:14;;160836:55;;;;;;;;;;;;;;;;8:9:-1;5:2;;;30:1;27;20:12;5:2;160836:55:0;;;;8:9:-1;5:2;;;45:16;42:1;39;24:38;77:16;74:1;67:27;5:2;160836:55:0;;;;;;;101:4:-1;97:9;90:4;84;80:15;76:31;69:5;65:43;126:6;120:4;113:20;0:138;160836:55:0;;;;;;;;;160804:87;;160908:21;:8;:19;:21::i;:::-;160904:2066;;;160946:171;160994:12;160977:13;:29;161025:4;160946:171;161089:13;160946:12;:171::i;:::-;161132:177;161164:24;:11;:22;:24::i;:::-;161163:25;161207:4;161132:177;161277:11;:17;;;161132:177;;:12;:177::i;:::-;161331:24;:11;:22;:24::i;:::-;161324:32;;;;161371:212;161402:25;:12;:23;:25::i;:::-;161446:4;161371:212;161517:14;161550:12;:18;;;161371:12;:212::i;:::-;161607:148;161642:8;161669:14;161702:13;161734:6;161607:16;:148::i;:::-;161598:157;;161831:20;:11;:18;:20::i;:::-;161827:101;;;161872:40;161882:12;161896;161910:1;161872:9;:40::i;:::-;160904:2066;;;161960:174;162009:12;161991:14;:30;162040:4;161960:174;162105:14;161960:12;:174::i;:::-;162149:180;162181:24;:11;:22;:24::i;:::-;162180:25;162224:4;162149:180;162297:11;:17;;;162149:180;;:12;:180::i;:::-;162351:24;:11;:22;:24::i;:::-;162344:32;;;;162391:209;162422:25;:12;:23;:25::i;:::-;162466:4;162391:209;162534:14;162567:12;:18;;;162391:12;:209::i;:::-;162624:148;162659:8;162686:13;162718:14;162751:6;162624:16;:148::i;:::-;162615:157;;162864:12;:18;;;162848:6;:12;;;:34;162844:115;;;162903:40;162913:12;162927;162941:1;162903:9;:40::i;:::-;163025:18;;;;163009:12;;;;162982:190;;163009:34;;;;;163058:4;;162982:190;;163009:12;162982;:190::i;:::-;163205:17;;163190:11;;:32;;;;;;;163183:40;;;;-1:-1:-1;163243:6:0;160371:2886;-1:-1:-1;;;;;;;;;160371:2886:0:o;165296:666::-;165417:7;165439:6;165473:141;165500:4;:11;165515:2;165500:17;165532:4;165473:141;165592:4;:11;165473:12;:141::i;17727:159::-;17857:6;;17827:4;;17856:7;:22;;;;-1:-1:-1;;17867:7:0;;;:11;;;;;17727:159::o;163265:349::-;163422:13;;163411:25;;;;;;:10;:25;;;;;;;;163437:14;;;;;163411:41;;;;;;;;:51;;;;;;;;;;:58;;;;;;;;;;163511:13;;163539:14;;163487:119;;;;;;163511:13;163411:51;;:58;;163487:119;;;;;;;;;;163265:349;;;:::o;1961:150::-;2019:7;2052:1;2047;:6;;2039:15;;;;;;-1:-1:-1;2077:5:0;;;1961:150::o;13016:238::-;13176:7;13208:38;13234:11;13208:21;:6;13219:9;13208:21;:10;:21;:::i;:::-;:25;:38;:25;:38;:::i;:::-;13201:45;;13016:238;;;;;;:::o;25086:197::-;25205:7;25237:38;25253:6;25261:1;:7;;;24607:6;25237:15;:38::i;2197:150::-;2255:7;2287:5;;;2311:6;;;;2303:15;;;;;4647:187;4721:22;;;4713:31;;;;;;4781:6;;;4760:38;;;;;;;4781:6;;;4760:38;;;4809:6;:17;;;;;;;;;;;;;;;4647:187::o;9319:988::-;9418:12;9496:19;9535:5;9518:23;;;;;;;;;;;;;22:32:-1;26:21;;;22:32;6:49;;9518:23:0;;;;-1:-1:-1;49:4;9650:587:0;9671:5;;9650:587;;9928:9;;9827:3;;;;;9928:6;;9827:3;;9928:9;;;;;;;;;;;;;;;;;:14;;;9924:302;;9984:1;9980:5;10114:22;;10121:6;-1:-1:-1;10197:13:0;;9924:302;9650:587;;;-1:-1:-1;10287:12:0;;;10297:1;10287:12;;;;;;;;;;;-1:-1:-1;10280:19:0;9319:988;-1:-1:-1;;;9319:988:0:o;11272:993::-;11554:13;;;11564:2;11554:13;;;11371:12;11554:13;;;;;;11413:14;;;;11371:12;;11554:13;;;21:6:-1;;104:10;11554:13:0;87:34:-1;135:17;;-1:-1;11554:13:0;11532:35;;5137:2;11634:23;;11622:6;11629:1;11622:9;;;;;;;;;;;:35;;;;;;;;;;;5247:3;11680:27;;11668:6;11675:1;11668:9;;;;;;;;;;;:39;;;;;;;;;;-1:-1:-1;11824:9:0;11819:413;11843:2;11839:1;:6;11819:413;;;11934:1;11930:5;;12030:23;5474:3;12035:17;;12030:4;:23::i;:::-;12009:6;12021:5;12016:2;:10;12009:18;;;;;;;;;;;:44;;;;;;;;;;-1:-1:-1;45:20;25:41;;;;12172:23:0;5474:3;12177:17;;12172:4;:23::i;:::-;12151:6;12163:5;12158:2;:10;12151:18;;;;;;;;;;;:44;;;;;;;;;;-1:-1:-1;;45:20;25:41;;;;11847:3:0;;11819:413;;14406:304;14502:6;14549;14567:111;14594:16;;;;;14625:4;14567:111;:12;:111::i;10315:949::-;10414:12;10448:10;10444:53;;-1:-1:-1;10475:10:0;;;;;;;;;;;;;;;;;;;10444:53;10561:5;10549:9;10602:72;10609:6;;10602:72;;10632:8;;10660:2;10655:7;;;;10602:72;;;10718:17;10748:6;10738:17;;;;;;;;;;;;;;;;;;;;;;;;;21:6:-1;;104:10;10738:17:0;87:34:-1;135:17;;-1:-1;10738:17:0;-1:-1:-1;10850:5:0;;-1:-1:-1;10718:37:0;-1:-1:-1;10883:6:0;10866:367;10891:5;;10866:367;;11047:3;;11146:2;11142:1;:6;5137:2;11128:21;11117:34;;11107:4;11112:1;11107:7;;;;;;;;;;;:44;;;;;;;;;;-1:-1:-1;11219:2:0;11214:7;;;;10866:367;;;-1:-1:-1;11252:4:0;10315:949;-1:-1:-1;;;;10315:949:0:o;20137:158::-;20266:6;;20237:4;;20266:21;;;;-1:-1:-1;;20276:7:0;;;:11;;;20137:158::o;17894:::-;18023:6;;17994:4;;18023:21;;;;-1:-1:-1;;18033:7:0;;;:11;;;;;17894:158::o;6549:671::-;6745:4;6740:473;;6863:15;6873:4;6863:9;:15::i;:::-;6905:5;6937:17;6947:6;6937:9;:17::i;:::-;6981:6;7014:19;7024:8;7014:9;:19::i;:::-;7060:5;7092:19;7102:8;7092:9;:19::i;:::-;6820:347;;;;;;;;;;;7138:6;;6820:347;;;;6740:473;6549:671;;;;;:::o;164462:826::-;164665:24;;:::i;:::-;164722:31;;:::i;:::-;164768;;:::i;:::-;164813:109;164851:12;164878;164905:6;164813:23;:109::i;:::-;164707:215;;;;164935:18;164956:114;164986:7;:13;;;165014:9;:15;;;165044:9;:15;;;164956;:114::i;:::-;165090:190;;;;;;;;;-1:-1:-1;165090:190:0;;;164935:135;;-1:-1:-1;165090:190:0;;;;;;;;;;165210:26;165090:190;;;;;;;;;164462:826;-1:-1:-1;;;;;;;164462:826:0:o;18060:145::-;18185:7;;;:12;;;;18060:145::o;19970:159::-;20100:6;;20070:4;;20099:7;:22;;;;-1:-1:-1;;20110:7:0;;;:11;;;19970:159::o;163622:832::-;163825:24;;:::i;:::-;163882:31;;:::i;:::-;163928;;:::i;:::-;163973:109;164011:12;164038;164065:6;163973:23;:109::i;:::-;163867:215;;;;164095:18;164116:121;164153:7;:13;;;164181:9;:15;;;164211:9;:15;;;164116:22;:121::i;:::-;164257:189;;;;;;;;;164296:4;164257:189;;164095:142;;-1:-1:-1;164257:189:0;;;-1:-1:-1;164257:189:0;;956:433;1014:7;1258:6;1254:47;;-1:-1:-1;1288:1:0;1281:8;;1254:47;1325:5;;;1329:1;1325;:5;:1;1349:5;;;;;:10;1341:19;;;;;1522:303;1580:7;1679:1;1675;:5;1667:14;;;;;;1692:9;1708:1;1704;:5;;;;;;;1522:303;-1:-1:-1;;;;1522:303:0:o;12273:339::-;12367:4;12438:2;12430:5;:10;12426:81;;;-1:-1:-1;12464:31:0;5137:2;12475:18;;12464:31;12457:38;;12426:81;-1:-1:-1;5192:2:0;12575:27;12564:40;;;12273:339::o;5540:427::-;5682:4;5677:283;;5800:15;5810:4;5800:9;:15::i;:::-;5842:5;5874:17;5884:6;5874:9;:17::i;:::-;5757:157;;;;;;;;;;;5677:283;5540:427;;;:::o;13346:423::-;13513:7;13542:11;;;:29;;-1:-1:-1;13557:14:0;;13542:29;13538:154;;;13652:28;13665:1;13668:11;13652:12;:28::i;:::-;13645:35;;;;13538:154;13709:52;13759:1;13709:45;13742:11;13709:28;13759:1;13709:21;:6;13720:9;13709:21;:10;:21;:::i;:::-;:25;:28;:25;:28;:::i;:45::-;:49;:52;:49;:52;:::i;155405:11248::-;;;;;;;;;;-1:-1:-1;155405:11248:0;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;-1:-1:-1;155405:11248:0;;;;;;;;:::o;5:118:-1:-;;72:46;110:6;97:20;72:46;;130:112;;194:43;229:6;216:20;194:43;;249:116;;324:36;352:6;346:13;324:36;;373:440;;474:3;467:4;459:6;455:17;451:27;441:2;;492:1;489;482:12;441:2;529:6;516:20;551:64;566:48;607:6;566:48;;;551:64;;;542:73;;635:6;628:5;621:21;671:4;663:6;659:17;704:4;697:5;693:16;739:3;730:6;725:3;721:16;718:25;715:2;;;756:1;753;746:12;715:2;766:41;800:6;795:3;790;766:41;;;434:379;;;;;;;;847:342;;969:4;957:9;952:3;948:19;944:30;941:2;;;987:1;984;977:12;941:2;1005:20;1020:4;1005:20;;;996:29;-1:-1;1076:1;1107:60;1163:3;1143:9;1107:60;;;1083:85;;-1:-1;1094:5;935:254;-1:-1;;935:254;1222:466;;1333:4;1321:9;1316:3;1312:19;1308:30;1305:2;;;1351:1;1348;1341:12;1305:2;1369:20;1384:4;1369:20;;;1360:29;-1:-1;1440:1;1471:49;1516:3;1496:9;1471:49;;;1447:74;;-1:-1;1584:2;1617:49;1662:3;1638:22;;;1617:49;;;1610:4;1603:5;1599:16;1592:75;1542:136;1299:389;;;;;1718:459;;1827:4;1815:9;1810:3;1806:19;1802:30;1799:2;;;1845:1;1842;1835:12;1799:2;1863:20;1878:4;1863:20;;;1854:29;-1:-1;1933:1;1964:46;2006:3;1986:9;1964:46;;;1940:71;;-1:-1;2073:2;2106:49;2151:3;2127:22;;;2106:49;;2207:492;;2327:4;2315:9;2310:3;2306:19;2302:30;2299:2;;;2345:1;2342;2335:12;2299:2;2363:20;2378:4;2363:20;;;2354:29;-1:-1;2433:1;2464:57;2517:3;2497:9;2464:57;;;2440:82;;-1:-1;2584:2;2617:60;2673:3;2649:22;;;2617:60;;3107:460;;3217:4;3205:9;3200:3;3196:19;3192:30;3189:2;;;3235:1;3232;3225:12;3189:2;3253:20;3268:4;3253:20;;;3244:29;-1:-1;3323:1;3354:46;3396:3;3376:9;3354:46;;3597:493;;3718:4;3706:9;3701:3;3697:19;3693:30;3690:2;;;3736:1;3733;3726:12;3690:2;3754:20;3769:4;3754:20;;;3745:29;-1:-1;3824:1;3855:57;3908:3;3888:9;3855:57;;;3831:82;;-1:-1;3975:2;4008:60;4064:3;4040:22;;;4008:60;;4097:118;;4164:46;4202:6;4189:20;4164:46;;4222:122;;4300:39;4331:6;4325:13;4300:39;;4351:118;;4418:46;4456:6;4443:20;4418:46;;4476:122;;4554:39;4585:6;4579:13;4554:39;;4605:116;;4671:45;4708:6;4695:20;4671:45;;4728:241;;4832:2;4820:9;4811:7;4807:23;4803:32;4800:2;;;4848:1;4845;4838:12;4800:2;4883:1;4900:53;4945:7;4925:9;4900:53;;;4890:63;4794:175;-1:-1;;;;4794:175;4976:640;;;;5145:3;5133:9;5124:7;5120:23;5116:33;5113:2;;;5162:1;5159;5152:12;5113:2;5197:1;5214:53;5259:7;5239:9;5214:53;;;5204:63;;5176:97;5304:2;5322:75;5389:7;5380:6;5369:9;5365:22;5322:75;;;5312:85;;5283:120;5462:2;5451:9;5447:18;5434:32;5486:18;5478:6;5475:30;5472:2;;;5518:1;5515;5508:12;5472:2;5538:62;5592:7;5583:6;5572:9;5568:22;5538:62;;;5528:72;;5413:193;5107:509;;;;;;5623:307;;5760:2;5748:9;5739:7;5735:23;5731:32;5728:2;;;5776:1;5773;5766:12;5728:2;5811:1;5828:86;5906:7;5886:9;5828:86;;5937:410;;;6080:2;6068:9;6059:7;6055:23;6051:32;6048:2;;;6096:1;6093;6086:12;6048:2;6131:1;6148:75;6215:7;6195:9;6148:75;;;6138:85;;6110:119;6260:2;6278:53;6323:7;6314:6;6303:9;6299:22;6278:53;;;6268:63;;6239:98;6042:305;;;;;;6354:303;;6489:2;6477:9;6468:7;6464:23;6460:32;6457:2;;;6505:1;6502;6495:12;6457:2;6540:1;6557:84;6633:7;6613:9;6557:84;;6980:305;;7116:2;7104:9;7095:7;7091:23;7087:32;7084:2;;;7132:1;7129;7122:12;7084:2;7167:1;7184:85;7261:7;7241:9;7184:85;;7292:241;;7396:2;7384:9;7375:7;7371:23;7367:32;7364:2;;;7412:1;7409;7402:12;7364:2;7447:1;7464:53;7509:7;7489:9;7464:53;;7540:1436;;;;;;;;;7877:3;7865:9;7856:7;7852:23;7848:33;7845:2;;;7894:1;7891;7884:12;7845:2;7929:1;7946:53;7991:7;7971:9;7946:53;;;7936:63;;7908:97;8036:2;8054:53;8099:7;8090:6;8079:9;8075:22;8054:53;;;8044:63;;8015:98;8144:2;8162:75;8229:7;8220:6;8209:9;8205:22;8162:75;;;8152:85;;8123:120;8274:3;8293:75;8360:7;8351:6;8340:9;8336:22;8293:75;;;8283:85;;8253:121;8405:3;8424:73;8489:7;8480:6;8469:9;8465:22;8424:73;;;8414:83;;8384:119;8534:3;8553:73;8618:7;8609:6;8598:9;8594:22;8553:73;;;8543:83;;8513:119;8663:3;8682:74;8748:7;8739:6;8728:9;8724:22;8682:74;;;8672:84;;8642:120;8821:3;8810:9;8806:19;8793:33;8846:18;8838:6;8835:30;8832:2;;;8878:1;8875;8868:12;8832:2;8898:62;8952:7;8943:6;8932:9;8928:22;8898:62;;;8888:72;;8772:194;7839:1137;;;;;;;;;;;;8983:489;;;;9120:2;9108:9;9099:7;9095:23;9091:32;9088:2;;;9136:1;9133;9126:12;9088:2;9171:1;9188:53;9233:7;9213:9;9188:53;;;9178:63;;9150:97;9278:2;9296:53;9341:7;9332:6;9321:9;9317:22;9296:53;;;9286:63;;9257:98;9386:2;9404:52;9448:7;9439:6;9428:9;9424:22;9404:52;;9479:110;9552:31;9577:5;9552:31;;;9547:3;9540:44;9534:55;;;9723:101;9790:28;9812:5;9790:28;;9949:155;10048:50;10067:30;10091:5;10067:30;;;10048:50;;10111:155;10210:50;10229:30;10253:5;10229:30;;10273:159;10374:52;10394:31;10419:5;10394:31;;10439:356;;10567:38;10599:5;10567:38;;;10617:88;10698:6;10693:3;10617:88;;;10610:95;;10710:52;10755:6;10750:3;10743:4;10736:5;10732:16;10710:52;;;10774:16;;;;;10547:248;-1:-1;;10547:248;10802:164;10904:56;10954:5;10904:56;;10973:154;11065:56;11115:5;11065:56;;11289:347;;11401:39;11434:5;11401:39;;;11452:71;11516:6;11511:3;11452:71;;;11445:78;;11528:52;11573:6;11568:3;11561:4;11554:5;11550:16;11528:52;;;11601:29;11623:6;11601:29;;;11592:39;;;;11381:255;-1:-1;;;11381:255;11702:817;11916:22;;11851:4;11842:14;;;11944:55;11846:3;11916:22;11944:55;;;11871:134;12085:4;12078:5;12074:16;12068:23;12097:81;12172:4;12167:3;12163:14;12150:11;12097:81;;;12015:169;12255:4;12248:5;12244:16;12238:23;12267:78;12339:4;12334:3;12330:14;12317:11;12267:78;;;12194:157;12424:4;12417:5;12413:16;12407:23;12436:62;12492:4;12487:3;12483:14;12470:11;12436:62;;12575:467;12778:22;;12712:4;12703:14;;;12806:61;12707:3;12778:22;12806:61;;;12732:141;12947:4;12940:5;12936:16;12930:23;12959:62;13015:4;13010:3;13006:14;12993:11;12959:62;;13102:315;13307:22;;13241:4;13232:14;;;13335:61;13236:3;13307:22;13424:110;13497:31;13522:5;13497:31;;13668:117;13749:30;13773:5;13749:30;;13792:244;;13911:75;13982:3;13973:6;13911:75;;;-1:-1;14008:2;13999:12;;13899:137;-1:-1;13899:137;14043:553;;14259:93;14348:3;14339:6;14259:93;;;14252:100;;14363:73;14432:3;14423:6;14363:73;;;14458:1;14453:3;14449:11;14442:18;;14478:93;14567:3;14558:6;14478:93;;;14471:100;14240:356;-1:-1;;;;;14240:356;14603:978;;14917:93;15006:3;14997:6;14917:93;;;14910:100;;15021:73;15090:3;15081:6;15021:73;;;15116:1;15111:3;15107:11;15100:18;;15136:93;15225:3;15216:6;15136:93;;;15129:100;;15240:73;15309:3;15300:6;15240:73;;;15335:1;15330:3;15326:11;15319:18;;15355:93;15444:3;15435:6;15355:93;;;15348:100;;15459:73;15528:3;15519:6;15459:73;;;-1:-1;15554:1;15545:11;;14898:683;-1:-1;;;;;;14898:683;15588:1269;;15974:93;16063:3;16054:6;15974:93;;;15967:100;;16078:73;16147:3;16138:6;16078:73;;;16173:1;16168:3;16164:11;16157:18;;16193:93;16282:3;16273:6;16193:93;;;16186:100;;16297:73;16366:3;16357:6;16297:73;;;16392:1;16387:3;16383:11;16376:18;;16412:93;16501:3;16492:6;16412:93;;;16405:100;;16516:73;16585:3;16576:6;16516:73;;;16611:1;16606:3;16602:11;16595:18;;16631:93;16720:3;16711:6;16631:93;;;16624:100;;16735:73;16804:3;16795:6;16735:73;;;-1:-1;16830:1;16821:11;;15955:902;-1:-1;;;;;;;;15955:902;16864:1560;;17322:93;17411:3;17402:6;17322:93;;;17315:100;;17426:73;17495:3;17486:6;17426:73;;;17521:1;17516:3;17512:11;17505:18;;17541:93;17630:3;17621:6;17541:93;;;17534:100;;17645:73;17714:3;17705:6;17645:73;;;17740:1;17735:3;17731:11;17724:18;;17760:93;17849:3;17840:6;17760:93;;;17753:100;;17864:73;17933:3;17924:6;17864:73;;;17959:1;17954:3;17950:11;17943:18;;17979:93;18068:3;18059:6;17979:93;;;17972:100;;18083:73;18152:3;18143:6;18083:73;;;18178:1;18173:3;18169:11;18162:18;;18198:93;18287:3;18278:6;18198:93;;;18191:100;;18302:73;18371:3;18362:6;18302:73;;;-1:-1;18397:1;18388:11;;17303:1121;-1:-1;;;;;;;;;;17303:1121;18431:213;18549:2;18534:18;;18563:71;18538:9;18607:6;18563:71;;18651:543;18851:3;18836:19;;18866:71;18840:9;18910:6;18866:71;;;18948:72;19016:2;19005:9;19001:18;18992:6;18948:72;;;19031;19099:2;19088:9;19084:18;19075:6;19031:72;;;19114:70;19180:2;19169:9;19165:18;19156:6;19114:70;;19201:201;19313:2;19298:18;;19327:65;19302:9;19365:6;19327:65;;19409:251;19546:2;19531:18;;19560:90;19535:9;19623:6;19560:90;;19667:301;19805:2;19819:47;;;19790:18;;19880:78;19790:18;19944:6;19880:78;;19975:326;20149:3;20134:19;;20164:127;20138:9;20264:6;20164:127;;20308:412;20498:2;20483:18;;20512:115;20487:9;20600:6;20512:115;;;20638:72;20706:2;20695:9;20691:18;20682:6;20638:72;;20727:508;20965:2;20950:18;;20979:117;20954:9;21069:6;20979:117;;;21107:118;21221:2;21210:9;21206:18;21197:6;21107:118;;21242:213;21360:2;21345:18;;21374:71;21349:9;21418:6;21374:71;;21462:324;21608:2;21593:18;;21622:71;21597:9;21666:6;21622:71;;;21704:72;21772:2;21761:9;21757:18;21748:6;21704:72;;21793:209;21909:2;21894:18;;21923:69;21898:9;21965:6;21923:69;;22009:256;22071:2;22065:9;22097:17;;;22172:18;22157:34;;22193:22;;;22154:62;22151:2;;;22229:1;22226;22219:12;22151:2;22245;22238:22;22049:216;;-1:-1;22049:216;22272:258;;22415:18;22407:6;22404:30;22401:2;;;22447:1;22444;22437:12;22401:2;-1:-1;22520:4;22491;22468:17;;;;22487:9;22464:33;22510:15;;22338:192;22537:91;22611:12;;22595:33;22888:163;22991:19;;;23040:4;23031:14;;22984:67;23059:105;;23128:31;23153:5;23128:31;;23171:92;23244:13;23237:21;;23220:43;23270:151;23349:66;23338:78;;23321:100;23428:151;23507:66;23496:78;;23479:100;23586:79;23655:5;23638:27;23672:138;;23771:1;23764:5;23761:12;23751:2;;23777:9;23751:2;-1:-1;23800:5;23745:65;23959:128;24039:42;24028:54;;24011:76;24180:95;24259:10;24248:22;;24231:44;24493:120;24573:34;24562:46;;24545:68;24943:159;;25041:56;25091:5;25041:56;;25250:155;;25348:52;25394:5;25348:52;;25569:145;25650:6;25645:3;25640;25627:30;-1:-1;25706:1;25688:16;;25681:27;25620:94;25723:268;25788:1;25795:101;25809:6;25806:1;25803:13;25795:101;;;25876:11;;;25870:18;25857:11;;;25850:39;25831:2;25824:10;25795:101;;;25911:6;25908:1;25905:13;25902:2;;;-1:-1;;25976:1;25958:16;;25951:27;25772:219;26240:97;26328:2;26308:14;26324:7;26304:28;;26288:49
Swarm Source
bzzr://f213e5dd9a9897c2f350dca3ef16986b17119dd0405f1ea89af25e495c645287
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 30 Chains
Chain | Token | Portfolio % | Price | Amount | Value |
---|
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.