Contract
0xDa2d8E113EB19d6644C07D8Ba9917d4Ab7E762f7
1
Contract Overview
My Name Tag:
Not Available, login to update
Txn Hash | Method |
Block
|
From
|
To
|
Value | [Txn Fee] | |||
---|---|---|---|---|---|---|---|---|---|
0x60cbef0e5859d37101eadd39193b76aa25e0c82ce14579a03a0d69c9d436deb0 | Set Trusted Remo... | 63148502 | 7 days 8 hrs ago | 0x3685606479ab3c6826564cf8ca0744cd96ae77b9 | IN | 0xda2d8e113eb19d6644c07d8ba9917d4ab7e762f7 | 0 FTM | 0.006031947056 | |
0x4cffa670489f38e5f21aeb9927b35d14875a7dc3781a1d971f1680a166c7684c | 0x60c06040 | 63144099 | 7 days 10 hrs ago | 0x3685606479ab3c6826564cf8ca0744cd96ae77b9 | IN | Create: StargateFeeLibraryV07 | 0 FTM | 0.263084624213 |
[ Download CSV Export ]
Latest 1 internal transaction
Parent Txn Hash | Block | From | To | Value | |||
---|---|---|---|---|---|---|---|
0x4cffa670489f38e5f21aeb9927b35d14875a7dc3781a1d971f1680a166c7684c | 63144099 | 7 days 10 hrs ago | 0x3685606479ab3c6826564cf8ca0744cd96ae77b9 | Contract Creation | 0 FTM |
[ Download CSV Export ]
Contract Name:
StargateFeeLibraryV07
Compiler Version
v0.7.6+commit.7338295f
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.7.6; pragma abicoder v2; import "../interfaces/IStargateFeeLibrary.sol"; import "../Pool.sol"; import "../Factory.sol"; import "../interfaces/IStargateLPStaking.sol"; import "../chainlink/interfaces/AggregatorV3Interface.sol"; import "../lzApp/LzApp.sol"; import "@openzeppelin/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; ///@notice Stargate fee library maintains the fees it costs to go from one pool to another across chains /// The price feeds are eagerly updated by off-chain actors who watch the shouldCallUpdateTokenPrices() and call updateTokenPrice() if required contract StargateFeeLibraryV07 is LzApp, IStargateFeeLibrary { using SafeMath for uint256; //--------------------------------------------------------------------------- // VARIABLES // equilibrium func params. all in BPs * 10 ^ 2, i.e. 1 % = 10 ^ 6 units uint256 public constant DENOMINATOR = 1e18; uint256 public constant DELTA_1 = 6000 * 1e14; uint256 public constant DELTA_2 = 500 * 1e14; uint256 public constant LAMBDA_1 = 40 * 1e14; uint256 public constant LAMBDA_2 = 9960 * 1e14; // fee/reward bps uint256 public constant LP_FEE = 1 * 1e14; uint256 public constant LP_FEE_WITH_EQ_REWARD = 34 * 1e12; uint256 public constant PROTOCOL_FEE = 9 * 1e14; uint256 public constant PROTOCOL_FEE_FOR_SAME_TOKEN = 5 * 1e14; uint256 public constant EQ_REWARD_CAP = 6 * 1e14; uint256 public constant EQ_REWARD_THRESHOLD = 6 * 1e14; uint256 public constant PROTOCOL_SUBSIDY = 3 * 1e13; uint256 public constant FIFTY_PERCENT = 5 * 1e17; uint256 public constant SIXTY_PERCENT = 6 * 1e17; // price and state thresholds, may be configurable in the future uint8 public constant PRICE_SHARED_DECIMALS = 8; // for price normalization uint256 public constant ONE_BPS_PRICE_CHANGE_THRESHOLD = 1 * 1e14; uint256 public constant TEN_BPS_PRICE_CHANGE_THRESHOLD = 10 * 1e14; uint256 public constant PRICE_DRIFT_THRESHOLD = 10 * 1e14; // 10 bps uint256 public constant PRICE_DEPEG_THRESHOLD = 150 * 1e14; // 150 bps mapping(address => bool) public whitelist; mapping(uint256 => uint256) public poolIdToLpId; // poolId -> index of the pool in the lpStaking contract Factory public immutable factory; // srcPoolId => dstPoolId => PricePair mapping(uint256 => mapping(uint256 => PricePair)) public srcPoolIdToDstPoolPrice; mapping(uint256 => mapping(uint256 => bool)) public sameToken; // only for protocol fee, poolId -> poolId -> bool mapping(uint16 => bytes) public defaultAdapterParams; // for price sync, chainId -> params mapping(uint256 => address) public stargatePoolIdToLPStaking; enum PriceDeviationState { Normal, Drift, Depeg } struct PricePair { PriceDeviationState state; // default is Normal address srcPriceFeedAddress; address dstPriceFeedAddress; // price feed address of the dstPoolId uint128 dstCurrentPriceSD; // price of the dstPoolId token in USD uint128 srcCurrentPriceSD; // price of the srcPoolId token in USD uint16[] remoteChainIds; // chainIds of the pools that are connected to the pool } event PriceUpdated(uint256 indexed srcPoolId, uint256 indexed dstPoolId, uint256 srcPriceSD, uint256 dstPriceSD, PriceDeviationState state); event PriceFeedUpdated(uint256 indexed srcPoolId, uint256 indexed dstPoolId, address srcPriceFeedAddress, address dstPriceFeedAddress, uint16[] remoteChainIds); modifier notDepeg(uint256 _srcPoolId, uint256 _dstPoolId) { if (_srcPoolId != _dstPoolId) { require(srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId].state != PriceDeviationState.Depeg, "FeeLibrary: _srcPoolId depeg"); } _; } constructor( address _factory, address _endpoint ) LzApp(_endpoint) { require(_factory != address(0x0), "FeeLibrary: Factory cannot be 0x0"); require(_endpoint != address(0x0), "FeeLibrary: Endpoint cannot be 0x0"); factory = Factory(_factory); } // --------------------- ONLY OWNER --------------------- function whiteList(address _from, bool _whiteListed) external onlyOwner { whitelist[_from] = _whiteListed; } function setPoolToLpId(uint256 _poolId, uint256 _lpId) external onlyOwner { poolIdToLpId[_poolId] = _lpId; } function setInitPrices(uint128 _srcPoolId, uint128 _dstPoolId, uint128 price) external onlyOwner { require(price > 0, "FeeLibrary: _basePriceSD cannot be 0"); // reset current price and state srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId].dstCurrentPriceSD = price; srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId].srcCurrentPriceSD = price; srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId].state = PriceDeviationState.Normal; } // for those chains where to get the price from oracle and sync to other chains function setTokenPriceFeeds( uint256 _srcPoolId, uint256 _dstPoolId, address _srcPriceFeedAddress, address _dstPriceFeedAddress, uint16[] calldata _remoteChainIds ) external onlyOwner { srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId].srcPriceFeedAddress = _srcPriceFeedAddress; srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId].dstPriceFeedAddress = _dstPriceFeedAddress; srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId].remoteChainIds = _remoteChainIds; emit PriceFeedUpdated(_srcPoolId, _dstPoolId, _srcPriceFeedAddress, _dstPriceFeedAddress, _remoteChainIds); } function setStargatePoolIdToLPStakingAddress(uint256 _poolId, address _lpStaking) external onlyOwner { stargatePoolIdToLPStaking[_poolId] = _lpStaking; } function setSameToken(uint256 _poolId1, uint256 _poolId2, bool _isSame) external onlyOwner { require(_poolId1 != _poolId2, "FeeLibrary: _poolId1 cannot be the same as _poolId2"); if (_poolId1 < _poolId2) { sameToken[_poolId1][_poolId2] = _isSame; } else { sameToken[_poolId2][_poolId1] = _isSame; } } function setDefaultAdapterParams(uint16 _remoteChainId, bytes calldata _adapterParams) external onlyOwner { defaultAdapterParams[_remoteChainId] = _adapterParams; } // Override the renounce ownership inherited by zeppelin ownable function renounceOwnership() public override onlyOwner {} // --------------------- PUBLIC FUNCTIONS --------------------- ///@notice update the stored token price pair for the associated pool pair ///@dev anyone can update and sync price at any time even though the price is not changed ///@param _srcPoolId the poolId of the source pool ///@param _dstPoolId the poolId of the destination pool function updateTokenPrice(uint256 _srcPoolId, uint256 _dstPoolId) external payable { PricePair storage currentSrcPriceObj = srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId]; // get new prices from price feed (uint256 updatedSrcCurrentPriceSD, uint256 updatedDstCurrentPriceSD) = _getLatestPriceSDFromPriceFeeds(currentSrcPriceObj); (PriceDeviationState newState,)= _getPriceDeviationStateAndDiff(updatedSrcCurrentPriceSD, updatedDstCurrentPriceSD); // update price and state _updatePricePair(_srcPoolId, _dstPoolId, updatedSrcCurrentPriceSD, updatedDstCurrentPriceSD, newState); // sync the price to remote pools uint16[] memory remoteChainIds = currentSrcPriceObj.remoteChainIds; bytes memory payload = abi.encode(_srcPoolId, _dstPoolId, updatedSrcCurrentPriceSD, updatedDstCurrentPriceSD, newState); for (uint256 i = 0; i < remoteChainIds.length; i++) { uint16 remoteChainId = remoteChainIds[i]; address refundAddress = i == remoteChainIds.length - 1? msg.sender : address(this); // refund to msg.sender only for the last call _lzSend(remoteChainId, payload, payable(refundAddress), address(0), defaultAdapterParams[remoteChainId], address(this).balance); } } // --------------------- VIEW FUNCTIONS --------------------- ///@notice get the fees for a swap. typically called from the router via the pool function getFees( uint256 _srcPoolId, uint256 _dstPoolId, uint16 _dstChainId, address _from, uint256 _amountSD ) external view override notDepeg(_srcPoolId, _dstPoolId) returns (Pool.SwapObj memory s) { // calculate the equilibrium reward bool whitelisted = whitelist[_from]; (s.eqReward, s.protocolFee) = getEqReward(_srcPoolId, _amountSD, whitelisted); // protocol fee is 0 if whitelisted // calculate the equilibrium fee bool hasEqReward = s.eqReward > 0; uint256 protocolSubsidy; (s.eqFee, protocolSubsidy) = getEquilibriumFee(_srcPoolId, _dstPoolId, _dstChainId, _amountSD, whitelisted, hasEqReward); // calculate protocol and lp fee (uint256 protocolFee, uint256 lpFee) = getProtocolAndLpFee(_srcPoolId, _dstPoolId, _dstChainId, _amountSD, protocolSubsidy, whitelisted, hasEqReward); s.protocolFee = s.protocolFee.add(protocolFee); s.lpFee = lpFee; // calculate drift fee s.protocolFee = s.protocolFee.add(getDriftFee(_srcPoolId, _dstPoolId, _amountSD, whitelisted)); if (_amountSD < s.lpFee.add(s.eqFee).add(s.protocolFee)) { s.protocolFee = _amountSD.sub(s.lpFee).sub(s.eqFee); } return s; } ///@notice quote fee for price update and sync to remote chains ///@dev call this for value to attach to call to update token prices function quoteFeeForPriceUpdate(uint256 _srcPoolId, uint256 _dstPoolId) external view returns (uint256) { uint256 total = 0; uint16[] memory remoteChainIds = srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId].remoteChainIds; bytes memory payload = abi.encode(_srcPoolId, uint256(0), uint256(0), uint256(0), PriceDeviationState.Normal); // mock the payload for (uint256 i = 0; i < remoteChainIds.length; i++) { uint16 remoteChainId = remoteChainIds[i]; (uint256 fee, ) = lzEndpoint.estimateFees(remoteChainId, address(this), payload, false, defaultAdapterParams[remoteChainId]); total = total.add(fee); } return total; } function getEqReward( uint256 _srcPoolId, uint256 _amountSD, bool _whitelisted ) public view returns (uint256 eqReward, uint256 protocolFee) { Pool pool = factory.getPool(_srcPoolId); uint256 currentAssetSD = _getPoolBalanceSD(pool); uint256 lpAsset = pool.totalLiquidity(); uint256 rewardPoolSize = pool.eqFeePool(); if (lpAsset <= currentAssetSD) { return (0, 0); } uint256 poolDeficit = lpAsset.sub(currentAssetSD); uint256 rate = rewardPoolSize.mul(DENOMINATOR).div(poolDeficit); if (rate <= EQ_REWARD_THRESHOLD && !_whitelisted) { return (0, 0); } eqReward = _amountSD.mul(rate).div(DENOMINATOR); eqReward = eqReward > rewardPoolSize ? rewardPoolSize : eqReward; if (_whitelisted) { return (eqReward, 0); } uint256 rewardBps = eqReward.mul(DENOMINATOR).div(_amountSD); if (rewardBps > EQ_REWARD_CAP) { uint256 cap = _amountSD.mul(EQ_REWARD_CAP).div(DENOMINATOR); protocolFee = eqReward.sub(cap); } else { protocolFee = 0; } } function getEquilibriumFee( uint256 srcPoolId, uint256 dstPoolId, uint16 dstChainId, uint256 amountSD, bool whitelisted, bool hasEqReward ) public view returns (uint256, uint256) { if (whitelisted) { return (0, 0); } Pool.ChainPath memory chainPath = factory.getPool(srcPoolId).getChainPath(dstChainId, dstPoolId); uint256 idealBalance = chainPath.idealBalance; uint256 beforeBalance = chainPath.balance; require(beforeBalance >= amountSD, "FeeLibrary: not enough balance"); uint256 afterBalance = beforeBalance.sub(amountSD); uint256 safeZoneMax = idealBalance.mul(DELTA_1).div(DENOMINATOR); uint256 safeZoneMin = idealBalance.mul(DELTA_2).div(DENOMINATOR); uint256 eqFee = 0; uint256 protocolSubsidy = 0; uint256 amountSD_ = amountSD; // stack too deep if (afterBalance >= safeZoneMax) { // no fee zone, protocol subsidize it. eqFee = amountSD_.mul(PROTOCOL_SUBSIDY).div(DENOMINATOR); // no subsidy if has eqReward if (!hasEqReward) { protocolSubsidy = eqFee; } } else if (afterBalance >= safeZoneMin) { // safe zone uint256 proxyBeforeBalance = beforeBalance < safeZoneMax ? beforeBalance : safeZoneMax; eqFee = _getTrapezoidArea(LAMBDA_1, 0, safeZoneMax, safeZoneMin, proxyBeforeBalance, afterBalance); } else { // danger zone if (beforeBalance >= safeZoneMin) { // across 2 or 3 zones // part 1 uint256 proxyBeforeBalance = beforeBalance < safeZoneMax ? beforeBalance : safeZoneMax; eqFee = eqFee.add(_getTrapezoidArea(LAMBDA_1, 0, safeZoneMax, safeZoneMin, proxyBeforeBalance, safeZoneMin)); // part 2 eqFee = eqFee.add(_getTrapezoidArea(LAMBDA_2, LAMBDA_1, safeZoneMin, 0, safeZoneMin, afterBalance)); } else { // only in danger zone // part 2 only uint256 beforeBalance_ = beforeBalance; // Stack too deep eqFee = eqFee.add(_getTrapezoidArea(LAMBDA_2, LAMBDA_1, safeZoneMin, 0, beforeBalance_, afterBalance)); } } return (eqFee, protocolSubsidy); } function getProtocolAndLpFee( uint256 _srcPoolId, uint256 _dstPoolId, uint16, // _dstChainId uint256 _amountSD, uint256 _protocolSubsidy, bool _whitelisted, bool _hasEqReward ) public view returns (uint256, uint256) { if (_whitelisted) { return (0, 0); } uint256 protocolFeeBps = isSameToken(_srcPoolId, _dstPoolId) ? PROTOCOL_FEE_FOR_SAME_TOKEN : PROTOCOL_FEE; uint256 lpFeeBps = _hasEqReward ? LP_FEE_WITH_EQ_REWARD : LP_FEE; uint256 amountSD = _amountSD; // Stack too deep uint256 srcPoolId = _srcPoolId; uint256 protocolFee = amountSD.mul(protocolFeeBps).div(DENOMINATOR).sub(_protocolSubsidy); uint256 lpFee = amountSD.mul(lpFeeBps).div(DENOMINATOR); // when there are active emissions, give the lp fee to the protocol // lookup LPStaking[Time] address. If it address lpStakingAddr = stargatePoolIdToLPStaking[srcPoolId]; if(lpStakingAddr != address(0x0)){ IStargateLPStaking lpStaking = IStargateLPStaking(lpStakingAddr); (, uint256 allocPoint, , ) = lpStaking.poolInfo(poolIdToLpId[srcPoolId]); if (allocPoint > 0) { protocolFee = protocolFee.add(lpFee); lpFee = 0; } } return (protocolFee, lpFee); } function getDriftFee( uint256 _srcPoolId, uint256 _dstPoolId, uint256 _amountSD, bool _whitelisted ) public view returns (uint256) { if (_srcPoolId == _dstPoolId || _whitelisted) { return 0; } PricePair memory priceObj = srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId]; if(priceObj.state == PriceDeviationState.Normal){ return 0; } uint256 srcPriceSD = priceObj.srcCurrentPriceSD; uint256 dstPriceSD = priceObj.dstCurrentPriceSD; // if going high to low price, then no drift fee if(srcPriceSD >= dstPriceSD){ return 0; } else { return _amountSD.mul(dstPriceSD).div(srcPriceSD).sub(_amountSD); } } ///@notice offchain function to check if update token prices should be called ///@dev typically called by an off-chain watcher and if returns turn updateTokenPrice is called ///@param _srcPoolId the source pool id ///@param _dstPoolId the destination pool id ///@return bool true if updateTokenPrice should be called, false otherwise function shouldCallUpdateTokenPrices(uint256 _srcPoolId, uint256 _dstPoolId) external view returns (bool){ PricePair storage currentSrcToDstPricePair = srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId]; (uint256 updatedSrcCurrentPriceSD, uint256 updatedDstCurrentPriceSD) = _getLatestPriceSDFromPriceFeeds(currentSrcToDstPricePair); (PriceDeviationState newState,) = _getPriceDeviationStateAndDiff(updatedSrcCurrentPriceSD, updatedDstCurrentPriceSD); return _priceUpdateRequired(currentSrcToDstPricePair, newState, updatedSrcCurrentPriceSD, updatedDstCurrentPriceSD); } function isSameToken(uint256 _poolId1, uint256 _poolId2) public view returns (bool) { if (_poolId1 == _poolId2) { return true; } return _poolId1 < _poolId2 ? sameToken[_poolId1][_poolId2] : sameToken[_poolId2][_poolId1]; } function getRemoteChainIds(uint256 _poolId, uint256 _dstPoolId) external view returns (uint16[] memory) { return srcPoolIdToDstPoolPrice[_poolId][_dstPoolId].remoteChainIds; } function getVersion() external pure override returns (string memory) { return "7.1.0"; } // --------------------- INTERNAL FUNCTIONS --------------------- function _getTrapezoidArea( uint256 lambda, uint256 yOffset, uint256 xUpperBound, uint256 xLowerBound, uint256 xStart, uint256 xEnd ) internal pure returns (uint256) { require(xEnd >= xLowerBound && xStart <= xUpperBound, "FeeLibrary: balance out of bound"); uint256 xBoundWidth = xUpperBound.sub(xLowerBound); // xStartDrift = xUpperBound.sub(xStart); uint256 yStart = xUpperBound.sub(xStart).mul(lambda).div(xBoundWidth).add(yOffset); // xEndDrift = xUpperBound.sub(xEnd) uint256 yEnd = xUpperBound.sub(xEnd).mul(lambda).div(xBoundWidth).add(yOffset); // compute the area uint256 deltaX = xStart.sub(xEnd); return yStart.add(yEnd).mul(deltaX).div(2).div(DENOMINATOR); } function _blockingLzReceive(uint16, bytes memory, uint64, bytes memory _payload) internal override { (uint256 _srcPoolId, uint256 _dstPoolId, uint256 newSrcCurrentPrice, uint256 newDstCurrentPrice, PriceDeviationState state) = abi.decode(_payload, (uint16, uint256, uint256, uint256, PriceDeviationState)); _updatePricePair(_dstPoolId, _srcPoolId, newDstCurrentPrice, newSrcCurrentPrice, state); // the switching of the ordering of newDstCurrentPrice and newSrcCurrentPrice here is intentional } ///@notice calls the price feed to get the latest prices for the price pair and returns their scaled values function _getLatestPriceSDFromPriceFeeds(PricePair storage _priceObj) internal view returns (uint256, uint256) { return (_callPriceFeed(_priceObj.srcPriceFeedAddress), _callPriceFeed(_priceObj.dstPriceFeedAddress)); } ///@notice does an external call to the price feed address supplied and returns the scaled price function _callPriceFeed(address priceFeedAddress) internal view returns(uint256){ // get the latest price from the oracle require(priceFeedAddress != address(0x0), "FeeLibrary: price feed not set"); uint8 decimals = AggregatorV3Interface(priceFeedAddress).decimals(); (, int256 price, , , ) = AggregatorV3Interface(priceFeedAddress).latestRoundData(); require(price >= 0, "FeeLibrary: price is negative"); return _scalePrice(uint256(price), decimals); } ///@notice indicates if the price deviation has changed so much to warrant a state update function _priceUpdateRequired(PricePair storage currentSrcToDstPricePair, PriceDeviationState newState, uint256 _newSrcPrice, uint256 _newDstPrice) internal view returns(bool) { // if price state is depegged no need to further update the oracle if (currentSrcToDstPricePair.state == PriceDeviationState.Depeg && newState == PriceDeviationState.Depeg) { return false; } // if state has changed then price update is required if(newState != currentSrcToDstPricePair.state){ return true; } uint256 newSrcDiff = _getAbsoluteDiffAsBps(currentSrcToDstPricePair.srcCurrentPriceSD, _newSrcPrice); uint256 newDstDiff = _getAbsoluteDiffAsBps(currentSrcToDstPricePair.dstCurrentPriceSD, _newDstPrice); uint256 threshold = newState == PriceDeviationState.Drift? ONE_BPS_PRICE_CHANGE_THRESHOLD : TEN_BPS_PRICE_CHANGE_THRESHOLD; uint256 maxNewAbsDiff = newSrcDiff > newDstDiff ? newSrcDiff : newDstDiff; return maxNewAbsDiff >= threshold ? true : false; } ///@notice simply storages the price pair state and emits an event function _updatePricePair(uint256 _srcPoolId, uint _dstPoolId, uint256 _srcPriceSD, uint256 _dstPriceSD, PriceDeviationState _newState) internal { PricePair storage priceObj = srcPoolIdToDstPoolPrice[_srcPoolId][_dstPoolId]; priceObj.srcCurrentPriceSD = uint128(_srcPriceSD); priceObj.dstCurrentPriceSD = uint128(_dstPriceSD); if (_newState != priceObj.state) { priceObj.state = _newState; } emit PriceUpdated(_srcPoolId, _dstPoolId, _srcPriceSD, _dstPriceSD, _newState); } ///@notice looks at the src and dst current prices and determines if the state of the pair is normal, depeg or drift function _getPriceDeviationStateAndDiff(uint256 _srcCurrentPriceSD, uint256 _dstCurrentPriceSD) internal pure returns (PriceDeviationState, uint256) { // get absolute difference between src current price and dst current price uint256 diff = _getAbsoluteDiffAsBps(_srcCurrentPriceSD, _dstCurrentPriceSD); if (diff <= PRICE_DRIFT_THRESHOLD) { return (PriceDeviationState.Normal, diff); } else if (diff >= PRICE_DEPEG_THRESHOLD) { return (PriceDeviationState.Depeg, diff); } else { return (PriceDeviationState.Drift, diff); } } function _scalePrice(uint256 _price, uint8 _decimals) internal pure returns (uint256) { if (_decimals == PRICE_SHARED_DECIMALS) { return _price; } uint256 rate = _scaleRate(_decimals, PRICE_SHARED_DECIMALS); return _decimals < PRICE_SHARED_DECIMALS ? _price.mul(rate) : _price.div(rate); } function _getAbsoluteDiffAsBps(uint256 _a, uint256 _b) internal pure returns (uint256) { if (_a > _b) { return _a.sub(_b).mul(DENOMINATOR).div(_a); } else if(_a == _b){ return 0; } else { return _b.sub(_a).mul(DENOMINATOR).div(_b); } } function _scaleRate(uint8 _decimals, uint8 _sharedDecimals) internal pure returns (uint256) { uint256 diff = _decimals > _sharedDecimals? _decimals - _sharedDecimals : _sharedDecimals - _decimals; require(diff <= 20, "FeeLibrary: diff of decimals is too large"); return 10 ** diff; } function _getPoolBalanceSD(Pool _pool) internal view returns (uint256) { return IERC20(_pool.token()).balanceOf(address(_pool)).div(_pool.convertRate()); } receive() external payable {} // receive ETH from lz endpoint }
// SPDX-License-Identifier: MIT pragma solidity >=0.6.0 <0.8.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; import "../utils/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ abstract contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view virtual returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(owner() == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity >=0.5.0; interface ILayerZeroReceiver { // @notice LayerZero endpoint will invoke this function to deliver the message on the destination // @param _srcChainId - the source endpoint identifier // @param _srcAddress - the source sending contract address from the source chain // @param _nonce - the ordered message nonce // @param _payload - the signed payload is the UA bytes has encoded to be sent function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) external; }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity >=0.5.0; import "./ILayerZeroUserApplicationConfig.sol"; interface ILayerZeroEndpoint is ILayerZeroUserApplicationConfig { // @notice send a LayerZero message to the specified address at a LayerZero endpoint. // @param _dstChainId - the destination chain identifier // @param _destination - the address on destination chain (in bytes). address length/format may vary by chains // @param _payload - a custom bytes payload to send to the destination contract // @param _refundAddress - if the source transaction is cheaper than the amount of value passed, refund the additional amount to this address // @param _zroPaymentAddress - the address of the ZRO token holder who would pay for the transaction // @param _adapterParams - parameters for custom functionality. e.g. receive airdropped native gas from the relayer on destination function send(uint16 _dstChainId, bytes calldata _destination, bytes calldata _payload, address payable _refundAddress, address _zroPaymentAddress, bytes calldata _adapterParams) external payable; // @notice used by the messaging library to publish verified payload // @param _srcChainId - the source chain identifier // @param _srcAddress - the source contract (as bytes) at the source chain // @param _dstAddress - the address on destination chain // @param _nonce - the unbound message ordering nonce // @param _gasLimit - the gas limit for external contract execution // @param _payload - verified payload to send to the destination contract function receivePayload(uint16 _srcChainId, bytes calldata _srcAddress, address _dstAddress, uint64 _nonce, uint _gasLimit, bytes calldata _payload) external; // @notice get the inboundNonce of a receiver from a source chain which could be EVM or non-EVM chain // @param _srcChainId - the source chain identifier // @param _srcAddress - the source chain contract address function getInboundNonce(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (uint64); // @notice get the outboundNonce from this source chain which, consequently, is always an EVM // @param _srcAddress - the source chain contract address function getOutboundNonce(uint16 _dstChainId, address _srcAddress) external view returns (uint64); // @notice gets a quote in source native gas, for the amount that send() requires to pay for message delivery // @param _dstChainId - the destination chain identifier // @param _userApplication - the user app address on this EVM chain // @param _payload - the custom message to send over LayerZero // @param _payInZRO - if false, user app pays the protocol fee in native token // @param _adapterParam - parameters for the adapter service, e.g. send some dust native token to dstChain function estimateFees(uint16 _dstChainId, address _userApplication, bytes calldata _payload, bool _payInZRO, bytes calldata _adapterParam) external view returns (uint nativeFee, uint zroFee); // @notice get this Endpoint's immutable source identifier function getChainId() external view returns (uint16); // @notice the interface to retry failed message on this Endpoint destination // @param _srcChainId - the source chain identifier // @param _srcAddress - the source chain contract address // @param _payload - the payload to be retried function retryPayload(uint16 _srcChainId, bytes calldata _srcAddress, bytes calldata _payload) external; // @notice query if any STORED payload (message blocking) at the endpoint. // @param _srcChainId - the source chain identifier // @param _srcAddress - the source chain contract address function hasStoredPayload(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (bool); // @notice query if the _libraryAddress is valid for sending msgs. // @param _userApplication - the user app address on this EVM chain function getSendLibraryAddress(address _userApplication) external view returns (address); // @notice query if the _libraryAddress is valid for receiving msgs. // @param _userApplication - the user app address on this EVM chain function getReceiveLibraryAddress(address _userApplication) external view returns (address); // @notice query if the non-reentrancy guard for send() is on // @return true if the guard is on. false otherwise function isSendingPayload() external view returns (bool); // @notice query if the non-reentrancy guard for receive() is on // @return true if the guard is on. false otherwise function isReceivingPayload() external view returns (bool); // @notice get the configuration of the LayerZero messaging library of the specified version // @param _version - messaging library version // @param _chainId - the chainId for the pending config change // @param _userApplication - the contract address of the user application // @param _configType - type of configuration. every messaging library has its own convention. function getConfig(uint16 _version, uint16 _chainId, address _userApplication, uint _configType) external view returns (bytes memory); // @notice get the send() LayerZero messaging library version // @param _userApplication - the contract address of the user application function getSendVersion(address _userApplication) external view returns (uint16); // @notice get the lzReceive() LayerZero messaging library version // @param _userApplication - the contract address of the user application function getReceiveVersion(address _userApplication) external view returns (uint16); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity >=0.5.0; interface ILayerZeroUserApplicationConfig { // @notice set the configuration of the LayerZero messaging library of the specified version // @param _version - messaging library version // @param _chainId - the chainId for the pending config change // @param _configType - type of configuration. every messaging library has its own convention. // @param _config - configuration in the bytes. can encode arbitrary content. function setConfig(uint16 _version, uint16 _chainId, uint _configType, bytes calldata _config) external; // @notice set the send() LayerZero messaging library version to _version // @param _version - new messaging library version function setSendVersion(uint16 _version) external; // @notice set the lzReceive() LayerZero messaging library version to _version // @param _version - new messaging library version function setReceiveVersion(uint16 _version) external; // @notice Only when the UA needs to resume the message flow in blocking mode and clear the stored payload // @param _srcChainId - the chainId of the source chain // @param _srcAddress - the contract address of the source contract at the source chain function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external; }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor () { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and make it call a * `private` function that does the actual work. */ modifier nonReentrant() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.7.6; // libraries import "@openzeppelin/contracts/math/SafeMath.sol"; contract LPTokenERC20 { using SafeMath for uint256; //--------------------------------------------------------------------------- // CONSTANTS string public name; string public symbol; bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; // set in constructor bytes32 public DOMAIN_SEPARATOR; //--------------------------------------------------------------------------- // VARIABLES uint256 public decimals; uint256 public totalSupply; mapping(address => uint256) public balanceOf; mapping(address => mapping(address => uint256)) public allowance; mapping(address => uint256) public nonces; //--------------------------------------------------------------------------- // EVENTS event Approval(address indexed owner, address indexed spender, uint256 value); event Transfer(address indexed from, address indexed to, uint256 value); constructor(string memory _name, string memory _symbol) { name = _name; symbol = _symbol; uint256 chainId; assembly { chainId := chainid() } DOMAIN_SEPARATOR = keccak256( abi.encode( keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), keccak256(bytes(name)), keccak256(bytes("1")), chainId, address(this) ) ); } function _mint(address to, uint256 value) internal { totalSupply = totalSupply.add(value); balanceOf[to] = balanceOf[to].add(value); emit Transfer(address(0), to, value); } function _burn(address from, uint256 value) internal { balanceOf[from] = balanceOf[from].sub(value); totalSupply = totalSupply.sub(value); emit Transfer(from, address(0), value); } function _approve( address owner, address spender, uint256 value ) private { allowance[owner][spender] = value; emit Approval(owner, spender, value); } function _transfer( address from, address to, uint256 value ) private { balanceOf[from] = balanceOf[from].sub(value); balanceOf[to] = balanceOf[to].add(value); emit Transfer(from, to, value); } function approve(address spender, uint256 value) external returns (bool) { _approve(msg.sender, spender, value); return true; } function transfer(address to, uint256 value) external returns (bool) { _transfer(msg.sender, to, value); return true; } function transferFrom( address from, address to, uint256 value ) external returns (bool) { if (allowance[from][msg.sender] != uint256(-1)) { allowance[from][msg.sender] = allowance[from][msg.sender].sub(value); } _transfer(from, to, value); return true; } function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { _approve(msg.sender, spender, allowance[msg.sender][spender].add(addedValue)); return true; } function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { _approve(msg.sender, spender, allowance[msg.sender][spender].sub(subtractedValue, "ERC20: decreased allowance below zero")); return true; } function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external { require(deadline >= block.timestamp, "Bridge: EXPIRED"); bytes32 digest = keccak256( abi.encodePacked( "\x19\x01", DOMAIN_SEPARATOR, keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, value, nonces[owner]++, deadline)) ) ); address recoveredAddress = ecrecover(digest, v, r, s); require(recoveredAddress != address(0) && recoveredAddress == owner, "Bridge: INVALID_SIGNATURE"); _approve(owner, spender, value); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.7.6; pragma abicoder v2; import "../Pool.sol"; interface IStargateFeeLibrary { function getFees( uint256 _srcPoolId, uint256 _dstPoolId, uint16 _dstChainId, address _from, uint256 _amountSD ) external returns (Pool.SwapObj memory s); function getVersion() external view returns (string memory); }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.7.6; pragma abicoder v2; // imports import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/ReentrancyGuard.sol"; import "./LPTokenERC20.sol"; import "./interfaces/IStargateFeeLibrary.sol"; // libraries import "@openzeppelin/contracts/math/SafeMath.sol"; /// Pool contracts on other chains and managed by the Stargate protocol. contract Pool is LPTokenERC20, ReentrancyGuard { using SafeMath for uint256; //--------------------------------------------------------------------------- // CONSTANTS bytes4 private constant SELECTOR = bytes4(keccak256(bytes("transfer(address,uint256)"))); uint256 public constant BP_DENOMINATOR = 10000; //--------------------------------------------------------------------------- // STRUCTS struct ChainPath { bool ready; // indicate if the counter chainPath has been created. uint16 dstChainId; uint256 dstPoolId; uint256 weight; uint256 balance; uint256 lkb; uint256 credits; uint256 idealBalance; } struct SwapObj { uint256 amount; uint256 eqFee; uint256 eqReward; uint256 lpFee; uint256 protocolFee; uint256 lkbRemove; } struct CreditObj { uint256 credits; uint256 idealBalance; } //--------------------------------------------------------------------------- // VARIABLES // chainPath ChainPath[] public chainPaths; // list of connected chains with shared pools mapping(uint16 => mapping(uint256 => uint256)) public chainPathIndexLookup; // lookup for chainPath by chainId => poolId =>index // metadata uint256 public immutable poolId; // shared id between chains to represent same pool uint256 public sharedDecimals; // the shared decimals (lowest common decimals between chains) uint256 public localDecimals; // the decimals for the token uint256 public immutable convertRate; // the decimals for the token address public immutable token; // the token for the pool address public immutable router; // the token for the pool bool public stopSwap; // flag to stop swapping in extreme cases // Fee and Liquidity uint256 public totalLiquidity; // the total amount of tokens added on this side of the chain (fees + deposits - withdrawals) uint256 public totalWeight; // total weight for pool percentages uint256 public mintFeeBP; // fee basis points for the mint/deposit uint256 public protocolFeeBalance; // fee balance created from dao fee uint256 public mintFeeBalance; // fee balance created from mint fee uint256 public eqFeePool; // pool rewards in Shared Decimal format. indicate the total budget for reverse swap incentive address public feeLibrary; // address for retrieving fee params for swaps // Delta related uint256 public deltaCredit; // credits accumulated from txn bool public batched; // flag to indicate if we want batch processing. bool public defaultSwapMode; // flag for the default mode for swap bool public defaultLPMode; // flag for the default mode for lp uint256 public swapDeltaBP; // basis points of poolCredits to activate Delta in swap uint256 public lpDeltaBP; // basis points of poolCredits to activate Delta in liquidity events //--------------------------------------------------------------------------- // EVENTS event Mint(address to, uint256 amountLP, uint256 amountSD, uint256 mintFeeAmountSD); event Burn(address from, uint256 amountLP, uint256 amountSD); event RedeemLocalCallback(address _to, uint256 _amountSD, uint256 _amountToMintSD); event Swap( uint16 chainId, uint256 dstPoolId, address from, uint256 amountSD, uint256 eqReward, uint256 eqFee, uint256 protocolFee, uint256 lpFee ); event SendCredits(uint16 dstChainId, uint256 dstPoolId, uint256 credits, uint256 idealBalance); event RedeemRemote(uint16 chainId, uint256 dstPoolId, address from, uint256 amountLP, uint256 amountSD); event RedeemLocal(address from, uint256 amountLP, uint256 amountSD, uint16 chainId, uint256 dstPoolId, bytes to); event InstantRedeemLocal(address from, uint256 amountLP, uint256 amountSD, address to); event CreditChainPath(uint16 chainId, uint256 srcPoolId, uint256 amountSD, uint256 idealBalance); event SwapRemote(address to, uint256 amountSD, uint256 protocolFee, uint256 dstFee); event WithdrawRemote(uint16 srcChainId, uint256 srcPoolId, uint256 swapAmount, uint256 mintAmount); event ChainPathUpdate(uint16 dstChainId, uint256 dstPoolId, uint256 weight); event FeesUpdated(uint256 mintFeeBP); event FeeLibraryUpdated(address feeLibraryAddr); event StopSwapUpdated(bool swapStop); event WithdrawProtocolFeeBalance(address to, uint256 amountSD); event WithdrawMintFeeBalance(address to, uint256 amountSD); event DeltaParamUpdated(bool batched, uint256 swapDeltaBP, uint256 lpDeltaBP, bool defaultSwapMode, bool defaultLPMode); //--------------------------------------------------------------------------- // MODIFIERS modifier onlyRouter() { require(msg.sender == router, "Stargate: only the router can call this method"); _; } constructor( uint256 _poolId, address _router, address _token, uint256 _sharedDecimals, uint256 _localDecimals, address _feeLibrary, string memory _name, string memory _symbol ) LPTokenERC20(_name, _symbol) { require(_token != address(0x0), "Stargate: _token cannot be 0x0"); require(_router != address(0x0), "Stargate: _router cannot be 0x0"); poolId = _poolId; router = _router; token = _token; sharedDecimals = _sharedDecimals; decimals = uint8(_sharedDecimals); localDecimals = _localDecimals; convertRate = 10**(uint256(localDecimals).sub(sharedDecimals)); totalWeight = 0; feeLibrary = _feeLibrary; //delta algo related batched = false; defaultSwapMode = true; defaultLPMode = true; } function getChainPathsLength() public view returns (uint256) { return chainPaths.length; } //--------------------------------------------------------------------------- // LOCAL CHAIN FUNCTIONS function mint(address _to, uint256 _amountLD) external nonReentrant onlyRouter returns (uint256) { return _mintLocal(_to, _amountLD, true, true); } // Local Remote // ------- --------- // swap -> swapRemote function swap( uint16 _dstChainId, uint256 _dstPoolId, address _from, uint256 _amountLD, uint256 _minAmountLD, bool newLiquidity ) external nonReentrant onlyRouter returns (SwapObj memory) { require(!stopSwap, "Stargate: swap func stopped"); ChainPath storage cp = getAndCheckCP(_dstChainId, _dstPoolId); require(cp.ready == true, "Stargate: counter chainPath is not ready"); uint256 amountSD = amountLDtoSD(_amountLD); uint256 minAmountSD = amountLDtoSD(_minAmountLD); // request fee params from library SwapObj memory s = IStargateFeeLibrary(feeLibrary).getFees(poolId, _dstPoolId, _dstChainId, _from, amountSD); // equilibrium fee and reward. note eqFee/eqReward are separated from swap liquidity eqFeePool = eqFeePool.sub(s.eqReward); // update the new amount the user gets minus the fees s.amount = amountSD.sub(s.eqFee).sub(s.protocolFee).sub(s.lpFee); // users will also get the eqReward require(s.amount.add(s.eqReward) >= minAmountSD, "Stargate: slippage too high"); // behaviours // - protocolFee: booked, stayed and withdrawn at remote. // - eqFee: booked, stayed and withdrawn at remote. // - lpFee: booked and stayed at remote, can be withdrawn anywhere s.lkbRemove = amountSD.sub(s.lpFee).add(s.eqReward); // check for transfer solvency. require(cp.balance >= s.lkbRemove, "Stargate: dst balance too low"); cp.balance = cp.balance.sub(s.lkbRemove); if (newLiquidity) { deltaCredit = deltaCredit.add(amountSD).add(s.eqReward); } else if (s.eqReward > 0) { deltaCredit = deltaCredit.add(s.eqReward); } // distribute credits on condition. if (!batched || deltaCredit >= totalLiquidity.mul(swapDeltaBP).div(BP_DENOMINATOR)) { _delta(defaultSwapMode); } emit Swap(_dstChainId, _dstPoolId, _from, s.amount, s.eqReward, s.eqFee, s.protocolFee, s.lpFee); return s; } // Local Remote // ------- --------- // sendCredits -> creditChainPath function sendCredits(uint16 _dstChainId, uint256 _dstPoolId) external nonReentrant onlyRouter returns (CreditObj memory c) { ChainPath storage cp = getAndCheckCP(_dstChainId, _dstPoolId); require(cp.ready == true, "Stargate: counter chainPath is not ready"); cp.lkb = cp.lkb.add(cp.credits); c.idealBalance = totalLiquidity.mul(cp.weight).div(totalWeight); c.credits = cp.credits; cp.credits = 0; emit SendCredits(_dstChainId, _dstPoolId, c.credits, c.idealBalance); } // Local Remote // ------- --------- // redeemRemote -> swapRemote function redeemRemote( uint16 _dstChainId, uint256 _dstPoolId, address _from, uint256 _amountLP ) external nonReentrant onlyRouter { require(_from != address(0x0), "Stargate: _from cannot be 0x0"); uint256 amountSD = _burnLocal(_from, _amountLP); //run Delta if (!batched || deltaCredit > totalLiquidity.mul(lpDeltaBP).div(BP_DENOMINATOR)) { _delta(defaultLPMode); } uint256 amountLD = amountSDtoLD(amountSD); emit RedeemRemote(_dstChainId, _dstPoolId, _from, _amountLP, amountLD); } function instantRedeemLocal( address _from, uint256 _amountLP, address _to ) external nonReentrant onlyRouter returns (uint256 amountSD) { require(_from != address(0x0), "Stargate: _from cannot be 0x0"); uint256 _deltaCredit = deltaCredit; // sload optimization. uint256 _capAmountLP = _amountSDtoLP(_deltaCredit); if (_amountLP > _capAmountLP) _amountLP = _capAmountLP; amountSD = _burnLocal(_from, _amountLP); deltaCredit = _deltaCredit.sub(amountSD); uint256 amountLD = amountSDtoLD(amountSD); _safeTransfer(token, _to, amountLD); emit InstantRedeemLocal(_from, _amountLP, amountSD, _to); } // Local Remote // ------- --------- // redeemLocal -> redeemLocalCheckOnRemote // redeemLocalCallback <- function redeemLocal( address _from, uint256 _amountLP, uint16 _dstChainId, uint256 _dstPoolId, bytes calldata _to ) external nonReentrant onlyRouter returns (uint256 amountSD) { require(_from != address(0x0), "Stargate: _from cannot be 0x0"); // safeguard. require(chainPaths[chainPathIndexLookup[_dstChainId][_dstPoolId]].ready == true, "Stargate: counter chainPath is not ready"); amountSD = _burnLocal(_from, _amountLP); // run Delta if (!batched || deltaCredit > totalLiquidity.mul(lpDeltaBP).div(BP_DENOMINATOR)) { _delta(false); } emit RedeemLocal(_from, _amountLP, amountSD, _dstChainId, _dstPoolId, _to); } //--------------------------------------------------------------------------- // REMOTE CHAIN FUNCTIONS // Local Remote // ------- --------- // sendCredits -> creditChainPath function creditChainPath( uint16 _dstChainId, uint256 _dstPoolId, CreditObj memory _c ) external nonReentrant onlyRouter { ChainPath storage cp = chainPaths[chainPathIndexLookup[_dstChainId][_dstPoolId]]; cp.balance = cp.balance.add(_c.credits); if (cp.idealBalance != _c.idealBalance) { cp.idealBalance = _c.idealBalance; } emit CreditChainPath(_dstChainId, _dstPoolId, _c.credits, _c.idealBalance); } // Local Remote // ------- --------- // swap -> swapRemote function swapRemote( uint16 _srcChainId, uint256 _srcPoolId, address _to, SwapObj memory _s ) external nonReentrant onlyRouter returns (uint256 amountLD) { // booking lpFee totalLiquidity = totalLiquidity.add(_s.lpFee); // booking eqFee eqFeePool = eqFeePool.add(_s.eqFee); // booking stargateFee protocolFeeBalance = protocolFeeBalance.add(_s.protocolFee); // update LKB uint256 chainPathIndex = chainPathIndexLookup[_srcChainId][_srcPoolId]; chainPaths[chainPathIndex].lkb = chainPaths[chainPathIndex].lkb.sub(_s.lkbRemove); // user receives the amount + the srcReward amountLD = amountSDtoLD(_s.amount.add(_s.eqReward)); _safeTransfer(token, _to, amountLD); emit SwapRemote(_to, _s.amount.add(_s.eqReward), _s.protocolFee, _s.eqFee); } // Local Remote // ------- --------- // redeemLocal -> redeemLocalCheckOnRemote // redeemLocalCallback <- function redeemLocalCallback( uint16 _srcChainId, uint256 _srcPoolId, address _to, uint256 _amountSD, uint256 _amountToMintSD ) external nonReentrant onlyRouter { if (_amountToMintSD > 0) { _mintLocal(_to, amountSDtoLD(_amountToMintSD), false, false); } ChainPath storage cp = getAndCheckCP(_srcChainId, _srcPoolId); cp.lkb = cp.lkb.sub(_amountSD); uint256 amountLD = amountSDtoLD(_amountSD); _safeTransfer(token, _to, amountLD); emit RedeemLocalCallback(_to, _amountSD, _amountToMintSD); } // Local Remote // ------- --------- // redeemLocal(amount) -> redeemLocalCheckOnRemote // redeemLocalCallback <- function redeemLocalCheckOnRemote( uint16 _srcChainId, uint256 _srcPoolId, uint256 _amountSD ) external nonReentrant onlyRouter returns (uint256 swapAmount, uint256 mintAmount) { ChainPath storage cp = getAndCheckCP(_srcChainId, _srcPoolId); if (_amountSD > cp.balance) { mintAmount = _amountSD - cp.balance; swapAmount = cp.balance; cp.balance = 0; } else { cp.balance = cp.balance.sub(_amountSD); swapAmount = _amountSD; mintAmount = 0; } emit WithdrawRemote(_srcChainId, _srcPoolId, swapAmount, mintAmount); } //--------------------------------------------------------------------------- // DAO Calls function createChainPath( uint16 _dstChainId, uint256 _dstPoolId, uint256 _weight ) external onlyRouter { for (uint256 i = 0; i < chainPaths.length; ++i) { ChainPath memory cp = chainPaths[i]; bool exists = cp.dstChainId == _dstChainId && cp.dstPoolId == _dstPoolId; require(!exists, "Stargate: cant createChainPath of existing dstChainId and _dstPoolId"); } totalWeight = totalWeight.add(_weight); chainPathIndexLookup[_dstChainId][_dstPoolId] = chainPaths.length; chainPaths.push(ChainPath(false, _dstChainId, _dstPoolId, _weight, 0, 0, 0, 0)); emit ChainPathUpdate(_dstChainId, _dstPoolId, _weight); } function setWeightForChainPath( uint16 _dstChainId, uint256 _dstPoolId, uint16 _weight ) external onlyRouter { ChainPath storage cp = getAndCheckCP(_dstChainId, _dstPoolId); totalWeight = totalWeight.sub(cp.weight).add(_weight); cp.weight = _weight; emit ChainPathUpdate(_dstChainId, _dstPoolId, _weight); } function setFee(uint256 _mintFeeBP) external onlyRouter { require(_mintFeeBP <= BP_DENOMINATOR, "Bridge: cum fees > 100%"); mintFeeBP = _mintFeeBP; emit FeesUpdated(mintFeeBP); } function setFeeLibrary(address _feeLibraryAddr) external onlyRouter { require(_feeLibraryAddr != address(0x0), "Stargate: fee library cant be 0x0"); feeLibrary = _feeLibraryAddr; emit FeeLibraryUpdated(_feeLibraryAddr); } function setSwapStop(bool _swapStop) external onlyRouter { stopSwap = _swapStop; emit StopSwapUpdated(_swapStop); } function setDeltaParam( bool _batched, uint256 _swapDeltaBP, uint256 _lpDeltaBP, bool _defaultSwapMode, bool _defaultLPMode ) external onlyRouter { require(_swapDeltaBP <= BP_DENOMINATOR && _lpDeltaBP <= BP_DENOMINATOR, "Stargate: wrong Delta param"); batched = _batched; swapDeltaBP = _swapDeltaBP; lpDeltaBP = _lpDeltaBP; defaultSwapMode = _defaultSwapMode; defaultLPMode = _defaultLPMode; emit DeltaParamUpdated(_batched, _swapDeltaBP, _lpDeltaBP, _defaultSwapMode, _defaultLPMode); } function callDelta(bool _fullMode) external onlyRouter { _delta(_fullMode); } function activateChainPath(uint16 _dstChainId, uint256 _dstPoolId) external onlyRouter { ChainPath storage cp = getAndCheckCP(_dstChainId, _dstPoolId); require(cp.ready == false, "Stargate: chainPath is already active"); // this func will only be called once cp.ready = true; } function withdrawProtocolFeeBalance(address _to) external onlyRouter { if (protocolFeeBalance > 0) { uint256 amountOfLD = amountSDtoLD(protocolFeeBalance); protocolFeeBalance = 0; _safeTransfer(token, _to, amountOfLD); emit WithdrawProtocolFeeBalance(_to, amountOfLD); } } function withdrawMintFeeBalance(address _to) external onlyRouter { if (mintFeeBalance > 0) { uint256 amountOfLD = amountSDtoLD(mintFeeBalance); mintFeeBalance = 0; _safeTransfer(token, _to, amountOfLD); emit WithdrawMintFeeBalance(_to, amountOfLD); } } //--------------------------------------------------------------------------- // INTERNAL // Conversion Helpers //--------------------------------------------------------------------------- function amountLPtoLD(uint256 _amountLP) external view returns (uint256) { return amountSDtoLD(_amountLPtoSD(_amountLP)); } function _amountLPtoSD(uint256 _amountLP) internal view returns (uint256) { require(totalSupply > 0, "Stargate: cant convert LPtoSD when totalSupply == 0"); return _amountLP.mul(totalLiquidity).div(totalSupply); } function _amountSDtoLP(uint256 _amountSD) internal view returns (uint256) { require(totalLiquidity > 0, "Stargate: cant convert SDtoLP when totalLiq == 0"); return _amountSD.mul(totalSupply).div(totalLiquidity); } function amountSDtoLD(uint256 _amount) internal view returns (uint256) { return _amount.mul(convertRate); } function amountLDtoSD(uint256 _amount) internal view returns (uint256) { return _amount.div(convertRate); } function getAndCheckCP(uint16 _dstChainId, uint256 _dstPoolId) internal view returns (ChainPath storage) { require(chainPaths.length > 0, "Stargate: no chainpaths exist"); ChainPath storage cp = chainPaths[chainPathIndexLookup[_dstChainId][_dstPoolId]]; require(cp.dstChainId == _dstChainId && cp.dstPoolId == _dstPoolId, "Stargate: local chainPath does not exist"); return cp; } function getChainPath(uint16 _dstChainId, uint256 _dstPoolId) external view returns (ChainPath memory) { ChainPath memory cp = chainPaths[chainPathIndexLookup[_dstChainId][_dstPoolId]]; require(cp.dstChainId == _dstChainId && cp.dstPoolId == _dstPoolId, "Stargate: local chainPath does not exist"); return cp; } function _burnLocal(address _from, uint256 _amountLP) internal returns (uint256) { require(totalSupply > 0, "Stargate: cant burn when totalSupply == 0"); uint256 amountOfLPTokens = balanceOf[_from]; require(amountOfLPTokens >= _amountLP, "Stargate: not enough LP tokens to burn"); uint256 amountSD = _amountLP.mul(totalLiquidity).div(totalSupply); //subtract totalLiquidity accordingly totalLiquidity = totalLiquidity.sub(amountSD); _burn(_from, _amountLP); emit Burn(_from, _amountLP, amountSD); return amountSD; } function _delta(bool fullMode) internal { if (deltaCredit > 0 && totalWeight > 0) { uint256 cpLength = chainPaths.length; uint256[] memory deficit = new uint256[](cpLength); uint256 totalDeficit = 0; // algorithm steps 6-9: calculate the total and the amounts required to get to balance state for (uint256 i = 0; i < cpLength; ++i) { ChainPath storage cp = chainPaths[i]; // (liquidity * (weight/totalWeight)) - (lkb+credits) uint256 balLiq = totalLiquidity.mul(cp.weight).div(totalWeight); uint256 currLiq = cp.lkb.add(cp.credits); if (balLiq > currLiq) { // save gas since we know balLiq > currLiq and we know deficit[i] > 0 deficit[i] = balLiq - currLiq; totalDeficit = totalDeficit.add(deficit[i]); } } // indicates how much delta credit is distributed uint256 spent; // handle credits with 2 tranches. the [ < totalDeficit] [excessCredit] // run full Delta, allocate all credits if (totalDeficit == 0) { // only fullMode delta will allocate excess credits if (fullMode && deltaCredit > 0) { // credit ChainPath by weights for (uint256 i = 0; i < cpLength; ++i) { ChainPath storage cp = chainPaths[i]; // credits = credits + toBalanceChange + remaining allocation based on weight uint256 amtToCredit = deltaCredit.mul(cp.weight).div(totalWeight); spent = spent.add(amtToCredit); cp.credits = cp.credits.add(amtToCredit); } } // else do nth } else if (totalDeficit <= deltaCredit) { if (fullMode) { // algorithm step 13: calculate amount to disperse to bring to balance state or as close as possible uint256 excessCredit = deltaCredit - totalDeficit; // algorithm steps 14-16: calculate credits for (uint256 i = 0; i < cpLength; ++i) { if (deficit[i] > 0) { ChainPath storage cp = chainPaths[i]; // credits = credits + deficit + remaining allocation based on weight uint256 amtToCredit = deficit[i].add(excessCredit.mul(cp.weight).div(totalWeight)); spent = spent.add(amtToCredit); cp.credits = cp.credits.add(amtToCredit); } } } else { // totalDeficit <= deltaCredit but not running fullMode // credit chainPaths as is if any deficit, not using all deltaCredit for (uint256 i = 0; i < cpLength; ++i) { if (deficit[i] > 0) { ChainPath storage cp = chainPaths[i]; uint256 amtToCredit = deficit[i]; spent = spent.add(amtToCredit); cp.credits = cp.credits.add(amtToCredit); } } } } else { // totalDeficit > deltaCredit, fullMode or not, normalize the deficit by deltaCredit for (uint256 i = 0; i < cpLength; ++i) { if (deficit[i] > 0) { ChainPath storage cp = chainPaths[i]; uint256 proportionalDeficit = deficit[i].mul(deltaCredit).div(totalDeficit); spent = spent.add(proportionalDeficit); cp.credits = cp.credits.add(proportionalDeficit); } } } // deduct the amount of credit sent deltaCredit = deltaCredit.sub(spent); } } function _mintLocal( address _to, uint256 _amountLD, bool _feesEnabled, bool _creditDelta ) internal returns (uint256 amountSD) { require(totalWeight > 0, "Stargate: No ChainPaths exist"); amountSD = amountLDtoSD(_amountLD); uint256 mintFeeSD = 0; if (_feesEnabled) { mintFeeSD = amountSD.mul(mintFeeBP).div(BP_DENOMINATOR); amountSD = amountSD.sub(mintFeeSD); mintFeeBalance = mintFeeBalance.add(mintFeeSD); } if (_creditDelta) { deltaCredit = deltaCredit.add(amountSD); } uint256 amountLPTokens = amountSD; if (totalSupply != 0) { amountLPTokens = amountSD.mul(totalSupply).div(totalLiquidity); } totalLiquidity = totalLiquidity.add(amountSD); _mint(_to, amountLPTokens); emit Mint(_to, amountLPTokens, amountSD, mintFeeSD); // add to credits and call delta. short circuit to save gas if (!batched || deltaCredit > totalLiquidity.mul(lpDeltaBP).div(BP_DENOMINATOR)) { _delta(defaultLPMode); } } function _safeTransfer( address _token, address _to, uint256 _value ) private { (bool success, bytes memory data) = _token.call(abi.encodeWithSelector(SELECTOR, _to, _value)); require(success && (data.length == 0 || abi.decode(data, (bool))), "Stargate: TRANSFER_FAILED"); } }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity 0.7.6; pragma abicoder v2; import "@openzeppelin/contracts/math/SafeMath.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "./Pool.sol"; contract Factory is Ownable { using SafeMath for uint256; //--------------------------------------------------------------------------- // VARIABLES mapping(uint256 => Pool) public getPool; // poolId -> PoolInfo address[] public allPools; address public immutable router; address public defaultFeeLibrary; // address for retrieving fee params for swaps //--------------------------------------------------------------------------- // MODIFIERS modifier onlyRouter() { require(msg.sender == router, "Stargate: caller must be Router."); _; } constructor(address _router) { require(_router != address(0x0), "Stargate: _router cant be 0x0"); // 1 time only router = _router; } function setDefaultFeeLibrary(address _defaultFeeLibrary) external onlyOwner { require(_defaultFeeLibrary != address(0x0), "Stargate: fee library cant be 0x0"); defaultFeeLibrary = _defaultFeeLibrary; } function allPoolsLength() external view returns (uint256) { return allPools.length; } function createPool( uint256 _poolId, address _token, uint8 _sharedDecimals, uint8 _localDecimals, string memory _name, string memory _symbol ) public onlyRouter returns (address poolAddress) { require(address(getPool[_poolId]) == address(0x0), "Stargate: Pool already created"); Pool pool = new Pool(_poolId, router, _token, _sharedDecimals, _localDecimals, defaultFeeLibrary, _name, _symbol); getPool[_poolId] = pool; poolAddress = address(pool); allPools.push(poolAddress); } function renounceOwnership() public override onlyOwner {} }
// SPDX-License-Identifier: BUSL-1.1 pragma solidity ^0.7.6; pragma abicoder v2; interface IStargateLPStaking { function poolInfo(uint256 _poolIndex) external view returns ( address, uint256, uint256, uint256 ); }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.6; interface AggregatorV3Interface { function decimals() external view returns (uint8); function description() external view returns (string memory); function version() external view returns (uint256); // getRoundData and latestRoundData should both raise "No data present" // if they do not have data to report, instead of returning unset values // which could be misinterpreted as actual reported values. function getRoundData(uint80 _roundId) external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); function latestRoundData() external view returns ( uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound ); }
// SPDX-License-Identifier: MIT pragma solidity 0.7.6; import "@openzeppelin/contracts/access/Ownable.sol"; import "@layerzerolabs/layerzero-core/contracts/interfaces/ILayerZeroReceiver.sol"; import "@layerzerolabs/layerzero-core/contracts/interfaces/ILayerZeroEndpoint.sol"; import "@layerzerolabs/layerzero-core/contracts/interfaces/ILayerZeroUserApplicationConfig.sol"; /* * a generic LzReceiver implementation */ abstract contract LzApp is Ownable, ILayerZeroReceiver, ILayerZeroUserApplicationConfig { ILayerZeroEndpoint public immutable lzEndpoint; mapping(uint16 => bytes) public trustedRemoteLookup; mapping(uint16 => mapping(uint16 => uint)) public minDstGasLookup; address public precrime; event SetPrecrime(address precrime); event SetTrustedRemote(uint16 _remoteChainId, bytes _path); event SetTrustedRemoteAddress(uint16 _remoteChainId, bytes _remoteAddress); event SetMinDstGas(uint16 _dstChainId, uint16 _type, uint _minDstGas); constructor(address _endpoint) { lzEndpoint = ILayerZeroEndpoint(_endpoint); } function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64 _nonce, bytes calldata _payload) public virtual override { // lzReceive must be called by the endpoint for security require(_msgSender() == address(lzEndpoint), "LzApp: invalid endpoint caller"); bytes memory trustedRemote = trustedRemoteLookup[_srcChainId]; // if will still block the message pathway from (srcChainId, srcAddress). should not receive message from untrusted remote. require(_srcAddress.length == trustedRemote.length && trustedRemote.length > 0 && keccak256(_srcAddress) == keccak256(trustedRemote), "LzApp: invalid source sending contract"); _blockingLzReceive(_srcChainId, _srcAddress, _nonce, _payload); } // abstract function - the default behaviour of LayerZero is blocking. See: NonblockingLzApp if you dont need to enforce ordered messaging function _blockingLzReceive(uint16 _srcChainId, bytes memory _srcAddress, uint64 _nonce, bytes memory _payload) internal virtual; function _lzSend(uint16 _dstChainId, bytes memory _payload, address payable _refundAddress, address _zroPaymentAddress, bytes memory _adapterParams, uint _nativeFee) internal virtual { bytes memory trustedRemote = trustedRemoteLookup[_dstChainId]; require(trustedRemote.length != 0, "LzApp: destination chain is not a trusted source"); lzEndpoint.send{value: _nativeFee}(_dstChainId, trustedRemote, _payload, _refundAddress, _zroPaymentAddress, _adapterParams); } function _checkGasLimit(uint16 _dstChainId, uint16 _type, bytes memory _adapterParams, uint _extraGas) internal view virtual { uint providedGasLimit = _getGasLimit(_adapterParams); uint minGasLimit = minDstGasLookup[_dstChainId][_type] + _extraGas; require(minGasLimit > 0, "LzApp: minGasLimit not set"); require(providedGasLimit >= minGasLimit, "LzApp: gas limit is too low"); } function _getGasLimit(bytes memory _adapterParams) internal pure virtual returns (uint gasLimit) { require(_adapterParams.length >= 34, "LzApp: invalid adapterParams"); assembly { gasLimit := mload(add(_adapterParams, 34)) } } //---------------------------UserApplication config---------------------------------------- function getConfig(uint16 _version, uint16 _chainId, address, uint _configType) external view returns (bytes memory) { return lzEndpoint.getConfig(_version, _chainId, address(this), _configType); } // generic config for LayerZero user Application function setConfig(uint16 _version, uint16 _chainId, uint _configType, bytes calldata _config) external override onlyOwner { lzEndpoint.setConfig(_version, _chainId, _configType, _config); } function setSendVersion(uint16 _version) external override onlyOwner { lzEndpoint.setSendVersion(_version); } function setReceiveVersion(uint16 _version) external override onlyOwner { lzEndpoint.setReceiveVersion(_version); } function forceResumeReceive(uint16 _srcChainId, bytes calldata _srcAddress) external override onlyOwner { lzEndpoint.forceResumeReceive(_srcChainId, _srcAddress); } // _path = abi.encodePacked(remoteAddress, localAddress) // this function set the trusted path for the cross-chain communication function setTrustedRemote(uint16 _srcChainId, bytes calldata _path) external onlyOwner { trustedRemoteLookup[_srcChainId] = _path; emit SetTrustedRemote(_srcChainId, _path); } function setPrecrime(address _precrime) external onlyOwner { precrime = _precrime; emit SetPrecrime(_precrime); } function setMinDstGas(uint16 _dstChainId, uint16 _packetType, uint _minGas) external onlyOwner { require(_minGas > 0, "LzApp: invalid minGas"); minDstGasLookup[_dstChainId][_packetType] = _minGas; emit SetMinDstGas(_dstChainId, _packetType, _minGas); } //--------------------------- VIEW FUNCTION ---------------------------------------- function isTrustedRemote(uint16 _srcChainId, bytes calldata _srcAddress) external view returns (bool) { bytes memory trustedSource = trustedRemoteLookup[_srcChainId]; return keccak256(trustedSource) == keccak256(_srcAddress); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } /** * @dev Returns the substraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b > a) return (false, 0); return (true, a - b); } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a / b); } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) { if (b == 0) return (false, 0); return (true, a % b); } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { if (a == 0) return 0; uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: division by zero"); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b > 0, "SafeMath: modulo by zero"); return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b <= a, errorMessage); return a - b; } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryDiv}. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) { require(b > 0, errorMessage); return a % b; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.7.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (uint256); /** * @dev Moves `amount` tokens from the caller's account to `recipient`. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transfer(address recipient, uint256 amount) external returns (bool); /** * @dev Returns the remaining number of tokens that `spender` will be * allowed to spend on behalf of `owner` through {transferFrom}. This is * zero by default. * * This value changes when {approve} or {transferFrom} are called. */ function allowance(address owner, address spender) external view returns (uint256); /** * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. * * Returns a boolean value indicating whether the operation succeeded. * * IMPORTANT: Beware that changing an allowance with this method brings the risk * that someone may use both the old and the new allowance by unfortunate * transaction ordering. One possible solution to mitigate this race * condition is to first reduce the spender's allowance to 0 and set the * desired value afterwards: * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 * * Emits an {Approval} event. */ function approve(address spender, uint256 amount) external returns (bool); /** * @dev Moves `amount` tokens from `sender` to `recipient` using the * allowance mechanism. `amount` is then deducted from the caller's * allowance. * * Returns a boolean value indicating whether the operation succeeded. * * Emits a {Transfer} event. */ function transferFrom(address sender, address recipient, uint256 amount) external returns (bool); /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed to, uint256 value); /** * @dev Emitted when the allowance of a `spender` for an `owner` is set by * a call to {approve}. `value` is the new allowance. */ event Approval(address indexed owner, address indexed spender, uint256 value); }
{ "optimizer": { "enabled": true, "runs": 200 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_factory","type":"address"},{"internalType":"address","name":"_endpoint","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"srcPoolId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"dstPoolId","type":"uint256"},{"indexed":false,"internalType":"address","name":"srcPriceFeedAddress","type":"address"},{"indexed":false,"internalType":"address","name":"dstPriceFeedAddress","type":"address"},{"indexed":false,"internalType":"uint16[]","name":"remoteChainIds","type":"uint16[]"}],"name":"PriceFeedUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"srcPoolId","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"dstPoolId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"srcPriceSD","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"dstPriceSD","type":"uint256"},{"indexed":false,"internalType":"enum StargateFeeLibraryV07.PriceDeviationState","name":"state","type":"uint8"}],"name":"PriceUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"_dstChainId","type":"uint16"},{"indexed":false,"internalType":"uint16","name":"_type","type":"uint16"},{"indexed":false,"internalType":"uint256","name":"_minDstGas","type":"uint256"}],"name":"SetMinDstGas","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"precrime","type":"address"}],"name":"SetPrecrime","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"_remoteChainId","type":"uint16"},{"indexed":false,"internalType":"bytes","name":"_path","type":"bytes"}],"name":"SetTrustedRemote","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint16","name":"_remoteChainId","type":"uint16"},{"indexed":false,"internalType":"bytes","name":"_remoteAddress","type":"bytes"}],"name":"SetTrustedRemoteAddress","type":"event"},{"inputs":[],"name":"DELTA_1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DELTA_2","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DENOMINATOR","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EQ_REWARD_CAP","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EQ_REWARD_THRESHOLD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FIFTY_PERCENT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LAMBDA_1","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LAMBDA_2","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LP_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"LP_FEE_WITH_EQ_REWARD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ONE_BPS_PRICE_CHANGE_THRESHOLD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRICE_DEPEG_THRESHOLD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRICE_DRIFT_THRESHOLD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PRICE_SHARED_DECIMALS","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PROTOCOL_FEE","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PROTOCOL_FEE_FOR_SAME_TOKEN","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PROTOCOL_SUBSIDY","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SIXTY_PERCENT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"TEN_BPS_PRICE_CHANGE_THRESHOLD","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"}],"name":"defaultAdapterParams","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"factory","outputs":[{"internalType":"contract Factory","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"internalType":"bytes","name":"_srcAddress","type":"bytes"}],"name":"forceResumeReceive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_version","type":"uint16"},{"internalType":"uint16","name":"_chainId","type":"uint16"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"_configType","type":"uint256"}],"name":"getConfig","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_srcPoolId","type":"uint256"},{"internalType":"uint256","name":"_dstPoolId","type":"uint256"},{"internalType":"uint256","name":"_amountSD","type":"uint256"},{"internalType":"bool","name":"_whitelisted","type":"bool"}],"name":"getDriftFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_srcPoolId","type":"uint256"},{"internalType":"uint256","name":"_amountSD","type":"uint256"},{"internalType":"bool","name":"_whitelisted","type":"bool"}],"name":"getEqReward","outputs":[{"internalType":"uint256","name":"eqReward","type":"uint256"},{"internalType":"uint256","name":"protocolFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"srcPoolId","type":"uint256"},{"internalType":"uint256","name":"dstPoolId","type":"uint256"},{"internalType":"uint16","name":"dstChainId","type":"uint16"},{"internalType":"uint256","name":"amountSD","type":"uint256"},{"internalType":"bool","name":"whitelisted","type":"bool"},{"internalType":"bool","name":"hasEqReward","type":"bool"}],"name":"getEquilibriumFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_srcPoolId","type":"uint256"},{"internalType":"uint256","name":"_dstPoolId","type":"uint256"},{"internalType":"uint16","name":"_dstChainId","type":"uint16"},{"internalType":"address","name":"_from","type":"address"},{"internalType":"uint256","name":"_amountSD","type":"uint256"}],"name":"getFees","outputs":[{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"eqFee","type":"uint256"},{"internalType":"uint256","name":"eqReward","type":"uint256"},{"internalType":"uint256","name":"lpFee","type":"uint256"},{"internalType":"uint256","name":"protocolFee","type":"uint256"},{"internalType":"uint256","name":"lkbRemove","type":"uint256"}],"internalType":"struct Pool.SwapObj","name":"s","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_srcPoolId","type":"uint256"},{"internalType":"uint256","name":"_dstPoolId","type":"uint256"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint256","name":"_amountSD","type":"uint256"},{"internalType":"uint256","name":"_protocolSubsidy","type":"uint256"},{"internalType":"bool","name":"_whitelisted","type":"bool"},{"internalType":"bool","name":"_hasEqReward","type":"bool"}],"name":"getProtocolAndLpFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_poolId","type":"uint256"},{"internalType":"uint256","name":"_dstPoolId","type":"uint256"}],"name":"getRemoteChainIds","outputs":[{"internalType":"uint16[]","name":"","type":"uint16[]"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getVersion","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"_poolId1","type":"uint256"},{"internalType":"uint256","name":"_poolId2","type":"uint256"}],"name":"isSameToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"internalType":"bytes","name":"_srcAddress","type":"bytes"}],"name":"isTrustedRemote","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lzEndpoint","outputs":[{"internalType":"contract ILayerZeroEndpoint","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"internalType":"bytes","name":"_srcAddress","type":"bytes"},{"internalType":"uint64","name":"_nonce","type":"uint64"},{"internalType":"bytes","name":"_payload","type":"bytes"}],"name":"lzReceive","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"}],"name":"minDstGasLookup","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"poolIdToLpId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"precrime","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_srcPoolId","type":"uint256"},{"internalType":"uint256","name":"_dstPoolId","type":"uint256"}],"name":"quoteFeeForPriceUpdate","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"sameToken","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_version","type":"uint16"},{"internalType":"uint16","name":"_chainId","type":"uint16"},{"internalType":"uint256","name":"_configType","type":"uint256"},{"internalType":"bytes","name":"_config","type":"bytes"}],"name":"setConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_remoteChainId","type":"uint16"},{"internalType":"bytes","name":"_adapterParams","type":"bytes"}],"name":"setDefaultAdapterParams","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint128","name":"_srcPoolId","type":"uint128"},{"internalType":"uint128","name":"_dstPoolId","type":"uint128"},{"internalType":"uint128","name":"price","type":"uint128"}],"name":"setInitPrices","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_dstChainId","type":"uint16"},{"internalType":"uint16","name":"_packetType","type":"uint16"},{"internalType":"uint256","name":"_minGas","type":"uint256"}],"name":"setMinDstGas","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_poolId","type":"uint256"},{"internalType":"uint256","name":"_lpId","type":"uint256"}],"name":"setPoolToLpId","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_precrime","type":"address"}],"name":"setPrecrime","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_version","type":"uint16"}],"name":"setReceiveVersion","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_poolId1","type":"uint256"},{"internalType":"uint256","name":"_poolId2","type":"uint256"},{"internalType":"bool","name":"_isSame","type":"bool"}],"name":"setSameToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_version","type":"uint16"}],"name":"setSendVersion","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_poolId","type":"uint256"},{"internalType":"address","name":"_lpStaking","type":"address"}],"name":"setStargatePoolIdToLPStakingAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_srcPoolId","type":"uint256"},{"internalType":"uint256","name":"_dstPoolId","type":"uint256"},{"internalType":"address","name":"_srcPriceFeedAddress","type":"address"},{"internalType":"address","name":"_dstPriceFeedAddress","type":"address"},{"internalType":"uint16[]","name":"_remoteChainIds","type":"uint16[]"}],"name":"setTokenPriceFeeds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_srcChainId","type":"uint16"},{"internalType":"bytes","name":"_path","type":"bytes"}],"name":"setTrustedRemote","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_srcPoolId","type":"uint256"},{"internalType":"uint256","name":"_dstPoolId","type":"uint256"}],"name":"shouldCallUpdateTokenPrices","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"name":"srcPoolIdToDstPoolPrice","outputs":[{"internalType":"enum StargateFeeLibraryV07.PriceDeviationState","name":"state","type":"uint8"},{"internalType":"address","name":"srcPriceFeedAddress","type":"address"},{"internalType":"address","name":"dstPriceFeedAddress","type":"address"},{"internalType":"uint128","name":"dstCurrentPriceSD","type":"uint128"},{"internalType":"uint128","name":"srcCurrentPriceSD","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"stargatePoolIdToLPStaking","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"}],"name":"trustedRemoteLookup","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_srcPoolId","type":"uint256"},{"internalType":"uint256","name":"_dstPoolId","type":"uint256"}],"name":"updateTokenPrice","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_from","type":"address"},{"internalType":"bool","name":"_whiteListed","type":"bool"}],"name":"whiteList","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelist","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]
Contract Creation Code
60c06040523480156200001157600080fd5b5060405162004a8338038062004a8383398101604081905262000034916200012e565b806000620000416200010d565b600080546001600160a01b0319166001600160a01b0383169081178255604051929350917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a35060601b6001600160601b0319166080526001600160a01b038216620000cd5760405162461bcd60e51b8152600401620000c49062000165565b60405180910390fd5b6001600160a01b038116620000f65760405162461bcd60e51b8152600401620000c490620001a6565b5060601b6001600160601b03191660a052620001e8565b3390565b80516001600160a01b03811681146200012957600080fd5b919050565b6000806040838503121562000141578182fd5b6200014c8362000111565b91506200015c6020840162000111565b90509250929050565b60208082526021908201527f4665654c6962726172793a20466163746f72792063616e6e6f742062652030786040820152600360fc1b606082015260800190565b60208082526022908201527f4665654c6962726172793a20456e64706f696e742063616e6e6f742062652030604082015261078360f41b606082015260800190565b60805160601c60a05160601c61483f62000244600039806117645280611e455280612451525080610a645280610cfd5280610e0e528061133852806120d3528061256d52806127d15280612bf152806132f6525061483f6000f3fe6080604052600436106103a55760003560e01c80637ba5c12f116101e7578063ba6afedf1161010d578063d7f6bde3116100a0578063eb8d72b71161006f578063eb8d72b7146109e2578063f2fde38b14610a02578063f5ecbdbc14610a22578063fc6834a114610a42576103ac565b8063d7f6bde31461058c578063df2a5b3b1461098d578063e18bce50146109ad578063e91e9b6f146109cd576103ac565b8063c5c2e4f8116100dc578063c5c2e4f814610900578063cbed8b9c1461092d578063d16baeb91461094d578063d2f68aec1461096d576103ac565b8063ba6afedf1461088b578063baf3292d146108ab578063bb05078d146108cb578063c45a0155146108eb576103ac565b8063950c8a7411610185578063a810de6c11610154578063a810de6c14610821578063ad7bbfc914610836578063b353aaa714610856578063b7f5ada31461086b576103ac565b8063950c8a74146107cc578063972883c4146107e15780639b19251a14610801578063a149863514610623576103ac565b8063897925f5116101c1578063897925f51461076f5780638cfd8f5c146107825780638da5cb5b146107a2578063918f8674146107b7576103ac565b80637ba5c12f1461075a57806380651ee2146106a2578063886a9c50146105ee576103ac565b80633c2c3065116102cc578063528637031161026a5780636ddc4561116102395780636ddc4561146106d7578063715018a6146106f75780637533d7881461070c5780637b35c2601461072c576103ac565b8063528637031461066d57806358cbb8ed146106825780635e3f2727146106a25780636548c4ac146106b7576103ac565b806342d65a8d116102a657806342d65a8d146106035780634e8f4fa81461062357806350a4ec9614610638578063518a9f9f14610658576103ac565b80633c2c3065146105a15780633d8b38f6146105ce5780633dad0dd5146105ee576103ac565b806313c6e380116103445780631ab62430116103135780631ab624301461051d5780631e04cbf31461054a57806327274e851461055f5780632b3ec8c91461058c576103ac565b806313c6e3801461049757806315b5b31a146104b75780631738fe38146104d757806319a6f7b8146104ec576103ac565b806307e0db171161038057806307e0db17146104205780630b4501fd146104405780630d8e6e2c1461045557806310ddb13714610477576103ac565b80621d3567146103b1578063012a1c2d146103d3578063040d5835146103fe576103ac565b366103ac57005b600080fd5b3480156103bd57600080fd5b506103d16103cc366004613ca9565b610a62565b005b3480156103df57600080fd5b506103e8610c88565b6040516103f591906146a0565b60405180910390f35b34801561040a57600080fd5b50610413610c94565b6040516103f591906146fc565b34801561042c57600080fd5b506103d161043b366004613c3a565b610c99565b34801561044c57600080fd5b506103e8610d80565b34801561046157600080fd5b5061046a610d8b565b6040516103f59190614341565b34801561048357600080fd5b506103d1610492366004613c3a565b610daa565b3480156104a357600080fd5b506103e86104b2366004613ec9565b610e76565b3480156104c357600080fd5b506103d16104d2366004613bf8565b610e88565b3480156104e357600080fd5b506103e8610f77565b3480156104f857600080fd5b5061050c610507366004613f1d565b610f82565b6040516103f5959493929190614354565b34801561052957600080fd5b5061053d610538366004614040565b610fd7565b6040516103f5919061458b565b34801561055657600080fd5b506103e8611133565b34801561056b57600080fd5b5061057f61057a366004613f1d565b61113f565b6040516103f59190614336565b34801561059857600080fd5b506103e86111a1565b3480156105ad57600080fd5b506105c16105bc366004613ec9565b6111ac565b6040516103f59190614271565b3480156105da57600080fd5b5061057f6105e9366004613c56565b6111c7565b3480156105fa57600080fd5b506103e8611298565b34801561060f57600080fd5b506103d161061e366004613c56565b6112a4565b34801561062f57600080fd5b506103e86113b9565b34801561064457600080fd5b506103d1610653366004613f61565b6113c4565b34801561066457600080fd5b506103e86114d3565b34801561067957600080fd5b506103e86114de565b34801561068e57600080fd5b5061046a61069d366004613c3a565b6114e9565b3480156106ae57600080fd5b506103e8611584565b3480156106c357600080fd5b506103d16106d2366004613f1d565b61158e565b3480156106e357600080fd5b506103d16106f2366004613ef9565b611602565b34801561070357600080fd5b506103d1611692565b34801561071857600080fd5b5061046a610727366004613c3a565b6116f6565b34801561073857600080fd5b5061074c610747366004614008565b61175d565b6040516103f59291906146a9565b34801561076657600080fd5b506103e8611a18565b6103d161077d366004613f1d565b611a22565b34801561078e57600080fd5b506103e861079d366004613d41565b611c0f565b3480156107ae57600080fd5b506105c1611c2c565b3480156107c357600080fd5b506103e8611c3b565b3480156107d857600080fd5b506105c1611c47565b3480156107ed57600080fd5b506103e86107fc366004614168565b611c56565b34801561080d57600080fd5b5061057f61081c366004613ab3565b611df7565b34801561082d57600080fd5b506103e8611e0c565b34801561084257600080fd5b5061074c610851366004614091565b611e17565b34801561086257600080fd5b506105c16120d1565b34801561087757600080fd5b5061057f610886366004613f1d565b6120f5565b34801561089757600080fd5b506103d16108a6366004614008565b612143565b3480156108b757600080fd5b506103d16108c6366004613ab3565b612222565b3480156108d757600080fd5b5061074c6108e63660046140f7565b6122d8565b3480156108f757600080fd5b506105c161244f565b34801561090c57600080fd5b5061092061091b366004613f1d565b612473565b6040516103f591906142ee565b34801561093957600080fd5b506103d1610948366004613dfe565b612509565b34801561095957600080fd5b506103d1610968366004613aeb565b612631565b34801561097957600080fd5b506103e8610988366004613f1d565b6126be565b34801561099957600080fd5b506103d16109a8366004613dbe565b61287f565b3480156109b957600080fd5b5061057f6109c8366004613f1d565b612997565b3480156109d957600080fd5b506103e86129b7565b3480156109ee57600080fd5b506103d16109fd366004613c56565b6129c1565b348015610a0e57600080fd5b506103d1610a1d366004613ab3565b612ab3565b348015610a2e57600080fd5b5061046a610a3d366004613d6e565b612bb5565b348015610a4e57600080fd5b506103d1610a5d366004613c56565b612d2f565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316610a94612db5565b6001600160a01b031614610aef576040805162461bcd60e51b815260206004820152601e60248201527f4c7a4170703a20696e76616c696420656e64706f696e742063616c6c65720000604482015290519081900360640190fd5b61ffff8616600090815260016020818152604080842080548251600295821615610100026000190190911694909404601f810184900484028501840190925281845291830182828015610b835780601f10610b5857610100808354040283529160200191610b83565b820191906000526020600020905b815481529060010190602001808311610b6657829003601f168201915b50505050509050805186869050148015610b9e575060008151115b8015610bce5750808051906020012086866040518083838082843780830192505050925050506040518091039020145b610c095760405162461bcd60e51b81526004018080602001828103825260268152602001806147e46026913960400191505060405180910390fd5b610c7f8787878080601f01602080910402602001604051908101604052809392919081815260200183838082843760009201919091525050604080516020601f8a018190048102820181019092528881528a935091508890889081908401838280828437600092019190915250612db992505050565b50505050505050565b670dd280b9144a000081565b600881565b610ca1612db5565b6001600160a01b0316610cb2611c2c565b6001600160a01b031614610cfb576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166307e0db17826040518263ffffffff1660e01b8152600401808261ffff168152602001915050600060405180830381600087803b158015610d6557600080fd5b505af1158015610d79573d6000803e3d6000fd5b5050505050565b6603328b944c400081565b6040805180820190915260058152640372e312e360dc1b602082015290565b610db2612db5565b6001600160a01b0316610dc3611c2c565b6001600160a01b031614610e0c576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03166310ddb137826040518263ffffffff1660e01b8152600401808261ffff168152602001915050600060405180830381600087803b158015610d6557600080fd5b60056020526000908152604090205481565b610e90612db5565b6001600160a01b0316610ea1611c2c565b6001600160a01b031614610eea576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b6000816001600160801b031611610f1c5760405162461bcd60e51b8152600401610f13906144d9565b60405180910390fd5b6001600160801b0392831660009081526006602090815260408083209486168352939052919091206002810180546001600160801b031916928416928317909316600160801b9290920291909117909155805460ff19169055565b66354a6ba7a1800081565b600660209081526000928352604080842090915290825290208054600182015460029092015460ff8216926001600160a01b0361010090930483169216906001600160801b0380821691600160801b90041685565b610fdf6138b8565b8585808214611030576002600083815260066020908152604080832085845290915290205460ff16600281111561101257fe5b14156110305760405162461bcd60e51b8152600401610f1390614554565b6001600160a01b03851660009081526004602052604090205460ff1661105789868361175d565b608086015260408501819052151560006110758b8b8b8a8787611e17565b602088019190915290506000806110918d8d8d8c878a8a6122d8565b60808a015191935091506110a59083612df0565b6080890152606088018190526110cb6110c08e8e8c89611c56565b60808a015190612df0565b60808901819052602089015160608a01516110f192916110eb9190612df0565b90612df0565b8910156111235761111d88602001516111178a606001518c612e4a90919063ffffffff16565b90612e4a565b60808901525b5050505050505095945050505050565b6706f05b59d3b2000081565b6000818314156111515750600161119b565b81831061117a57600082815260076020908152604080832086845290915290205460ff16611198565b600083815260076020908152604080832085845290915290205460ff165b90505b92915050565b66038d7ea4c6800081565b6009602052600090815260409020546001600160a01b031681565b61ffff8316600090815260016020818152604080842080548251600295821615610100026000190190911694909404601f81018490048402850184019092528184528493929091908301828280156112605780601f1061123557610100808354040283529160200191611260565b820191906000526020600020905b81548152906001019060200180831161124357829003601f168201915b505050505090508383604051808383808284376040519201829003909120855160209096019590952090941498975050505050505050565b670853a0d2313c000081565b6112ac612db5565b6001600160a01b03166112bd611c2c565b6001600160a01b031614611306576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b604080516342d65a8d60e01b815261ffff85166004820190815260248201928352604482018490526001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016926342d65a8d92879287928792606401848480828437600081840152601f19601f820116905080830192505050945050505050600060405180830381600087803b1580156113a557600080fd5b505af1158015610c7f573d6000803e3d6000fd5b660221b262dd800081565b6113cc612db5565b6001600160a01b03166113dd611c2c565b6001600160a01b031614611426576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b600086815260066020908152604080832088845290915290208054610100600160a81b0319166101006001600160a01b03878116919091029190911782556001820180546001600160a01b03191691861691909117905561148b9060030183836138ee565b5084867f1bad2a912586d33e3a40cd0943062ec4333b13b667383d874be2a10983d6a3ae868686866040516114c39493929190614285565b60405180910390a3505050505050565b66b1a2bc2ec5000081565b6601c6bf5263400081565b60086020908152600091825260409182902080548351601f60026000196101006001861615020190931692909204918201849004840281018401909452808452909183018282801561157c5780601f106115515761010080835404028352916020019161157c565b820191906000526020600020905b81548152906001019060200180831161155f57829003601f168201915b505050505081565b655af3107a400081565b611596612db5565b6001600160a01b03166115a7611c2c565b6001600160a01b0316146115f0576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b60009182526005602052604090912055565b61160a612db5565b6001600160a01b031661161b611c2c565b6001600160a01b031614611664576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b60009182526009602052604090912080546001600160a01b0319166001600160a01b03909216919091179055565b61169a612db5565b6001600160a01b03166116ab611c2c565b6001600160a01b0316146116f4576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b565b60016020818152600092835260409283902080548451600294821615610100026000190190911693909304601f810183900483028401830190945283835291929083018282801561157c5780601f106115515761010080835404028352916020019161157c565b60008060007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663068bcd8d876040518263ffffffff1660e01b81526004016117ae91906146a0565b60206040518083038186803b1580156117c657600080fd5b505afa1580156117da573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117fe9190613acf565b9050600061180b82612ea7565b90506000826001600160a01b03166315770f926040518163ffffffff1660e01b815260040160206040518083038186803b15801561184857600080fd5b505afa15801561185c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118809190613ee1565b90506000836001600160a01b0316639bb811196040518163ffffffff1660e01b815260040160206040518083038186803b1580156118bd57600080fd5b505afa1580156118d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118f59190613ee1565b905082821161190e576000809550955050505050611a10565b600061191a8385612e4a565b9050600061193a8261193485670de0b6b3a7640000613011565b9061306a565b9050660221b262dd80008111158015611951575088155b156119685760008097509750505050505050611a10565b61197e670de0b6b3a76400006119348c84613011565b975082881161198d578761198f565b825b975088156119a7575060009550611a10945050505050565b60006119bf8b6119348b670de0b6b3a7640000613011565b9050660221b262dd8000811115611a035760006119ef670de0b6b3a76400006119348e660221b262dd8000613011565b90506119fb8a82612e4a565b985050611a08565b600097505b505050505050505b935093915050565b651b48eb57e00081565b600082815260066020908152604080832084845290915281209080611a46836130d1565b915091506000611a56838361310f565b509050611a668686858585613160565b600084600301805480602002602001604051908101604052809291908181526020018280548015611ade57602002820191906000526020600020906000905b82829054906101000a900461ffff1661ffff1681526020019060020190602082600101049283019260010382029150808411611aa55790505b5050505050905060008787868686604051602001611b009594939291906146d2565b604051602081830303815290604052905060005b8251811015611c04576000838281518110611b2b57fe5b60200260200101519050600060018551038314611b485730611b4a565b335b61ffff831660009081526008602090815260408083208054825160026001831615610100026000190190921691909104601f8101859004850282018501909352828152949550611bfa9487948a94889491939190830182828015611bef5780601f10611bc457610100808354040283529160200191611bef565b820191906000526020600020905b815481529060010190602001808311611bd257829003601f168201915b505050505047613218565b5050600101611b14565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b6000546001600160a01b031690565b670de0b6b3a764000081565b6003546001600160a01b031681565b600083851480611c635750815b15611c7057506000611def565b6000858152600660209081526040808320878452909152808220815160c081019092528054829060ff166002811115611ca557fe5b6002811115611cb057fe5b815281546001600160a01b036101009091048116602080840191909152600184015490911660408084019190915260028401546001600160801b038082166060860152600160801b90910416608084015260038401805482518185028101850190935280835260a0909401939192909190830182828015611d7857602002820191906000526020600020906000905b82829054906101000a900461ffff1661ffff1681526020019060020190602082600101049283019260010382029150808411611d3f5790505b505050505081525050905060006002811115611d9057fe5b81516002811115611d9d57fe5b1415611dad576000915050611def565b608081015160608201516001600160801b039182169116808210611dd75760009350505050611def565b611de986611117846119348386613011565b93505050505b949350505050565b60046020526000908152604090205460ff1681565b660e35fa931a000081565b6000808315611e2b575060009050806120c6565b60405163068bcd8d60e01b81526000906001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063068bcd8d90611e7a908c906004016146a0565b60206040518083038186803b158015611e9257600080fd5b505afa158015611ea6573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611eca9190613acf565b6001600160a01b031663159f6add888a6040518363ffffffff1660e01b8152600401611ef792919061468c565b6101006040518083038186803b158015611f1057600080fd5b505afa158015611f24573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f489190613b61565b60e081015160808201519192509087811015611f765760405162461bcd60e51b8152600401610f139061451d565b6000611f82828a612e4a565b90506000611fa4670de0b6b3a764000061193486670853a0d2313c0000613011565b90506000611fc5670de0b6b3a76400006119348766b1a2bc2ec50000613011565b90506000808c848610611ffe57611fee670de0b6b3a764000061193483651b48eb57e000613011565b92508b611ff9578291505b6120b9565b8386106120365760008588106120145785612016565b875b905061202e660e35fa931a000060008888858c6134da565b9350506120b9565b83871061209357600085881061204c578561204e565b875b9050612070612069660e35fa931a000060008989868b6134da565b8590612df0565b935061202e612069670dd280b9144a0000660e35fa931a00008860008a8d6134da565b866120b5612069670dd280b9144a0000660e35fa931a0000886000868d6134da565b9350505b5090985096505050505050505b965096945050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b600082815260066020908152604080832084845290915281208180612119836130d1565b915091506000612129838361310f565b5090506121388482858561358c565b979650505050505050565b61214b612db5565b6001600160a01b031661215c611c2c565b6001600160a01b0316146121a5576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b818314156121c55760405162461bcd60e51b8152600401610f139061439a565b818310156121f75760008381526007602090815260408083208584529091529020805460ff191682151517905561221d565b60008281526007602090815260408083208684529091529020805460ff19168215151790555b505050565b61222a612db5565b6001600160a01b031661223b611c2c565b6001600160a01b031614612284576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b600380546001600160a01b0383166001600160a01b0319909116811790915560408051918252517f5db758e995a17ec1ad84bdef7e8c3293a0bd6179bcce400dff5d4c3d87db726b9181900360200190a150565b60008083156122ec57506000905080612443565b60006122f88a8a61113f565b612309576603328b944c4000612312565b6601c6bf526340005b905060008461232757655af3107a400061232f565b651eec3dec20005b9050878b600061234f8a611117670de0b6b3a7640000611934878a613011565b90506000612369670de0b6b3a76400006119348688613011565b6000848152600960205260409020549091506001600160a01b0316801561243857600084815260056020526040808220549051631526fe2760e01b81528392916001600160a01b03841691631526fe27916123c6916004016146a0565b60806040518083038186803b1580156123de57600080fd5b505afa1580156123f2573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906124169190613b23565b505091505060008111156124355761242e8585612df0565b9450600093505b50505b509096509450505050505b97509795505050505050565b7f000000000000000000000000000000000000000000000000000000000000000081565b60008281526006602090815260408083208484528252918290206003018054835181840281018401909452808452606093928301828280156124fc57602002820191906000526020600020906000905b82829054906101000a900461ffff1661ffff16815260200190600201906020826001010492830192600103820291508084116124c35790505b5050505050905092915050565b612511612db5565b6001600160a01b0316612522611c2c565b6001600160a01b03161461256b576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663cbed8b9c86868686866040518663ffffffff1660e01b8152600401808661ffff1681526020018561ffff168152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b15801561261d57600080fd5b505af1158015611c04573d6000803e3d6000fd5b612639612db5565b6001600160a01b031661264a611c2c565b6001600160a01b031614612693576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b6001600160a01b03919091166000908152600460205260409020805460ff1916911515919091179055565b6000828152600660209081526040808320848452825280832060030180548251818502810185019093528083528493849392919083018282801561274957602002820191906000526020600020906000905b82829054906101000a900461ffff1661ffff16815260200190600201906020826001010492830192600103820291508084116127105790505b5050505050905060008560008060008060405160200161276d9594939291906146d2565b604051602081830303815290604052905060005b825181101561287457600083828151811061279857fe5b60209081029190910181015161ffff8116600090815260089092526040808320905163040a7bb160e41b81529193506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916340a7bb109161280c91869130918a9188916004016145cf565b604080518083038186803b15801561282357600080fd5b505afa158015612837573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061285b9190613f3e565b5090506128688682612df0565b95505050600101612781565b509195945050505050565b612887612db5565b6001600160a01b0316612898611c2c565b6001600160a01b0316146128e1576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b6000811161292e576040805162461bcd60e51b81526020600482015260156024820152744c7a4170703a20696e76616c6964206d696e47617360581b604482015290519081900360640190fd5b61ffff808416600081815260026020908152604080832094871680845294825291829020859055815192835282019290925280820183905290517f9d5c7c0b934da8fefa9c7760c98383778a12dfbfc0c3b3106518f43fb9508ac09181900360600190a1505050565b600760209081526000928352604080842090915290825290205460ff1681565b651eec3dec200081565b6129c9612db5565b6001600160a01b03166129da611c2c565b6001600160a01b031614612a23576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b61ffff83166000908152600160205260409020612a4190838361399b565b507ffa41487ad5d6728f0b19276fa1eddc16558578f5109fc39d2dc33c3230470dab838383604051808461ffff168152602001806020018281038252848482818152602001925080828437600083820152604051601f909101601f1916909201829003965090945050505050a1505050565b612abb612db5565b6001600160a01b0316612acc611c2c565b6001600160a01b031614612b15576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b6001600160a01b038116612b5a5760405162461bcd60e51b815260040180806020018281038252602681526020018061474d6026913960400191505060405180910390fd5b600080546040516001600160a01b03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a3600080546001600160a01b0319166001600160a01b0392909216919091179055565b60408051633d7b2f6f60e21b815261ffff8087166004830152851660248201523060448201526064810183905290516060916001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169163f5ecbdbc91608480820192600092909190829003018186803b158015612c3857600080fd5b505afa158015612c4c573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526020811015612c7557600080fd5b8101908080516040519392919084640100000000821115612c9557600080fd5b908301906020820185811115612caa57600080fd5b8251640100000000811182820188101715612cc457600080fd5b82525081516020918201929091019080838360005b83811015612cf1578181015183820152602001612cd9565b50505050905090810190601f168015612d1e5780820380516001836020036101000a031916815260200191505b506040525050509050949350505050565b612d37612db5565b6001600160a01b0316612d48611c2c565b6001600160a01b031614612d91576040805162461bcd60e51b815260206004820181905260248201526000805160206147c4833981519152604482015290519081900360640190fd5b61ffff83166000908152600860205260409020612daf90838361399b565b50505050565b3390565b600080600080600085806020019051810190612dd59190613e6f565b945094509450945061ffff169450611c048486848685613160565b600082820183811015611198576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b600082821115612ea1576040805162461bcd60e51b815260206004820152601e60248201527f536166654d6174683a207375627472616374696f6e206f766572666c6f770000604482015290519081900360640190fd5b50900390565b6000613009826001600160a01b031663feb56b156040518163ffffffff1660e01b815260040160206040518083038186803b158015612ee557600080fd5b505afa158015612ef9573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f1d9190613ee1565b836001600160a01b031663fc0c546a6040518163ffffffff1660e01b815260040160206040518083038186803b158015612f5657600080fd5b505afa158015612f6a573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190612f8e9190613acf565b6001600160a01b03166370a08231856040518263ffffffff1660e01b8152600401612fb99190614271565b60206040518083038186803b158015612fd157600080fd5b505afa158015612fe5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119349190613ee1565b90505b919050565b6000826130205750600061119b565b8282028284828161302d57fe5b04146111985760405162461bcd60e51b81526004018080602001828103825260218152602001806147a36021913960400191505060405180910390fd5b60008082116130c0576040805162461bcd60e51b815260206004820152601a60248201527f536166654d6174683a206469766973696f6e206279207a65726f000000000000604482015290519081900360640190fd5b8183816130c957fe5b049392505050565b805460009081906130ef9061010090046001600160a01b031661368e565b6001840154613106906001600160a01b031661368e565b91509150915091565b600080600061311e85856137cf565b905066038d7ea4c68000811161313957600092509050613159565b66354a6ba7a18000811061315257600292509050613159565b6001925090505b9250929050565b60008581526006602090815260408083208784529091529020600280820180546001600160801b03196001600160801b03918216600160801b898416021716908616179055815460ff16908111156131b457fe5b8260028111156131c057fe5b146131e35780548290829060ff191660018360028111156131dd57fe5b02179055505b84867f0ee895fe87d4a9154a7ce225faa5c6fcf4b54a5f25114d0f4044d287a3e111e68686866040516114c3939291906146b7565b61ffff8616600090815260016020818152604080842080548251600295821615610100026000190190911694909404601f8101849004840285018401909252818452918301828280156132ac5780601f10613281576101008083540402835291602001916132ac565b820191906000526020600020905b81548152906001019060200180831161328f57829003601f168201915b505050505090508051600014156132f45760405162461bcd60e51b81526004018080602001828103825260308152602001806147736030913960400191505060405180910390fd5b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663c58031008389848a8a8a8a6040518863ffffffff1660e01b8152600401808761ffff1681526020018060200180602001866001600160a01b03168152602001856001600160a01b0316815260200180602001848103845289818151815260200191508051906020019080838360005b838110156133a657818101518382015260200161338e565b50505050905090810190601f1680156133d35780820380516001836020036101000a031916815260200191505b5084810383528851815288516020918201918a019080838360005b838110156134065781810151838201526020016133ee565b50505050905090810190601f1680156134335780820380516001836020036101000a031916815260200191505b50848103825285518152855160209182019187019080838360005b8381101561346657818101518382015260200161344e565b50505050905090810190601f1680156134935780820380516001836020036101000a031916815260200191505b5099505050505050505050506000604051808303818588803b1580156134b857600080fd5b505af11580156134cc573d6000803e3d6000fd5b505050505050505050505050565b60008382101580156134ec5750848311155b6135085760405162461bcd60e51b8152600401610f13906143ed565b60006135148686612e4a565b90506000613534886110eb846119348d61352e8d8c612e4a565b90613011565b9050600061354e896110eb856119348e61352e8e8c612e4a565b9050600061355c8787612e4a565b905061357b670de0b6b3a76400006119346002818561352e8989612df0565b9450505050505b9695505050505050565b60006002855460ff1660028111156135a057fe5b1480156135b8575060028460028111156135b657fe5b145b156135c557506000611def565b845460ff1660028111156135d557fe5b8460028111156135e157fe5b146135ee57506001611def565b600285015460009061361090600160801b90046001600160801b0316856137cf565b600287015490915060009061362e906001600160801b0316856137cf565b90506000600187600281111561364057fe5b146136525766038d7ea4c6800061365a565b655af3107a40005b9050600082841161366b578261366d565b835b90508181101561367e576000613681565b60015b9998505050505050505050565b60006001600160a01b0382166136b65760405162461bcd60e51b8152600401610f13906144a2565b6000826001600160a01b031663313ce5676040518163ffffffff1660e01b815260040160206040518083038186803b1580156136f157600080fd5b505afa158015613705573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061372991906141f7565b90506000836001600160a01b031663feaf968c6040518163ffffffff1660e01b815260040160a06040518083038186803b15801561376657600080fd5b505afa15801561377a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061379e91906141a8565b50505091505060008112156137c55760405162461bcd60e51b8152600401610f139061446b565b611def8183613824565b6000818311156137fa576137f383611934670de0b6b3a764000061352e8387612e4a565b905061119b565b8183141561380a5750600061119b565b6137f382611934670de0b6b3a764000061352e8388612e4a565b600060ff82166008141561383957508161119b565b600061384683600861386c565b9050600860ff8416106138625761385d848261306a565b611def565b611def8482613011565b6000808260ff168460ff161161388457838303613888565b8284035b60ff16905060148111156138ae5760405162461bcd60e51b8152600401610f1390614422565b600a0a9392505050565b6040518060c001604052806000815260200160008152602001600081526020016000815260200160008152602001600081525090565b82805482825590600052602060002090600f0160109004810192821561398b5791602002820160005b8382111561395b57833561ffff1683826101000a81548161ffff021916908361ffff1602179055509260200192600201602081600101049283019260010302613917565b80156139895782816101000a81549061ffff021916905560020160208160010104928301926001030261395b565b505b50613997929150613a17565b5090565b828054600181600116156101000203166002900490600052602060002090601f0160209004810192826139d1576000855561398b565b82601f106139ea5782800160ff1982351617855561398b565b8280016001018555821561398b579182015b8281111561398b5782358255916020019190600101906139fc565b5b808211156139975760008155600101613a18565b805161300c8161472e565b60008083601f840112613a48578182fd5b50813567ffffffffffffffff811115613a5f578182fd5b60208301915083602082850101111561315957600080fd5b80356001600160801b038116811461300c57600080fd5b805161300c8161473c565b805169ffffffffffffffffffff8116811461300c57600080fd5b600060208284031215613ac4578081fd5b813561119881614716565b600060208284031215613ae0578081fd5b815161119881614716565b60008060408385031215613afd578081fd5b8235613b0881614716565b91506020830135613b188161472e565b809150509250929050565b60008060008060808587031215613b38578182fd5b8451613b4381614716565b60208601516040870151606090970151919890975090945092505050565b6000610100808385031215613b74578182fd5b6040519081019067ffffffffffffffff82118183101715613b9157fe5b81604052613b9e84613a2c565b8152613bac60208501613a8e565b602082015260408401516040820152606084015160608201526080840151608082015260a084015160a082015260c084015160c082015260e084015160e0820152809250505092915050565b600080600060608486031215613c0c578283fd5b613c1584613a77565b9250613c2360208501613a77565b9150613c3160408501613a77565b90509250925092565b600060208284031215613c4b578081fd5b81356111988161473c565b600080600060408486031215613c6a578081fd5b8335613c758161473c565b9250602084013567ffffffffffffffff811115613c90578182fd5b613c9c86828701613a37565b9497909650939450505050565b60008060008060008060808789031215613cc1578384fd5b8635613ccc8161473c565b9550602087013567ffffffffffffffff80821115613ce8578586fd5b613cf48a838b01613a37565b9097509550604089013591508082168214613d0d578384fd5b90935060608801359080821115613d22578384fd5b50613d2f89828a01613a37565b979a9699509497509295939492505050565b60008060408385031215613d53578182fd5b8235613d5e8161473c565b91506020830135613b188161473c565b60008060008060808587031215613d83578182fd5b8435613d8e8161473c565b93506020850135613d9e8161473c565b92506040850135613dae81614716565b9396929550929360600135925050565b600080600060608486031215613dd2578081fd5b8335613ddd8161473c565b92506020840135613ded8161473c565b929592945050506040919091013590565b600080600080600060808688031215613e15578283fd5b8535613e208161473c565b94506020860135613e308161473c565b935060408601359250606086013567ffffffffffffffff811115613e52578182fd5b613e5e88828901613a37565b969995985093965092949392505050565b600080600080600060a08688031215613e86578283fd5b8551613e918161473c565b80955050602086015193506040860151925060608601519150608086015160038110613ebb578182fd5b809150509295509295909350565b600060208284031215613eda578081fd5b5035919050565b600060208284031215613ef2578081fd5b5051919050565b60008060408385031215613f0b578182fd5b823591506020830135613b1881614716565b60008060408385031215613f2f578182fd5b50508035926020909101359150565b60008060408385031215613f50578182fd5b505080516020909101519092909150565b60008060008060008060a08789031215613f79578384fd5b86359550602087013594506040870135613f9281614716565b93506060870135613fa281614716565b9250608087013567ffffffffffffffff80821115613fbe578384fd5b818901915089601f830112613fd1578384fd5b813581811115613fdf578485fd5b8a60208083028501011115613ff2578485fd5b6020830194508093505050509295509295509295565b60008060006060848603121561401c578081fd5b833592506020840135915060408401356140358161472e565b809150509250925092565b600080600080600060a08688031215614057578283fd5b853594506020860135935060408601356140708161473c565b9250606086013561408081614716565b949793965091946080013592915050565b60008060008060008060c087890312156140a9578384fd5b863595506020870135945060408701356140c28161473c565b93506060870135925060808701356140d98161472e565b915060a08701356140e98161472e565b809150509295509295509295565b600080600080600080600060e0888a031215614111578485fd5b8735965060208801359550604088013561412a8161473c565b9450606088013593506080880135925060a08801356141488161472e565b915060c08801356141588161472e565b8091505092959891949750929550565b6000806000806080858703121561417d578182fd5b843593506020850135925060408501359150606085013561419d8161472e565b939692955090935050565b600080600080600060a086880312156141bf578283fd5b6141c886613a99565b94506020860151935060408601519250606086015191506141eb60808701613a99565b90509295509295909350565b600060208284031215614208578081fd5b815160ff81168114611198578182fd5b60008151808452815b8181101561423d57602081850181015186830182015201614221565b8181111561424e5782602083870101525b50601f01601f19169290920160200192915050565b6003811061426d57fe5b9052565b6001600160a01b0391909116815260200190565b6001600160a01b0385811682528416602080830191909152606060408301819052820183905260009084906080840190835b868110156142e05783356142ca8161473c565b61ffff16835292810192918101916001016142b7565b509098975050505050505050565b6020808252825182820181905260009190848201906040850190845b8181101561432a57835161ffff168352928401929184019160010161430a565b50909695505050505050565b901515815260200190565b6000602082526111986020830184614218565b60a081016143628288614263565b6001600160a01b0395861660208301529390941660408501526001600160801b03918216606085015216608090920191909152919050565b60208082526033908201527f4665654c6962726172793a205f706f6f6c4964312063616e6e6f74206265207460408201527234329039b0b6b29030b9902fb837b7b624b21960691b606082015260800190565b6020808252818101527f4665654c6962726172793a2062616c616e6365206f7574206f6620626f756e64604082015260600190565b60208082526029908201527f4665654c6962726172793a2064696666206f6620646563696d616c7320697320604082015268746f6f206c6172676560b81b606082015260800190565b6020808252601d908201527f4665654c6962726172793a207072696365206973206e65676174697665000000604082015260600190565b6020808252601e908201527f4665654c6962726172793a2070726963652066656564206e6f74207365740000604082015260600190565b60208082526024908201527f4665654c6962726172793a205f62617365507269636553442063616e6e6f74206040820152630626520360e41b606082015260800190565b6020808252601e908201527f4665654c6962726172793a206e6f7420656e6f7567682062616c616e63650000604082015260600190565b6020808252601c908201527f4665654c6962726172793a205f737263506f6f6c496420646570656700000000604082015260600190565b600060c082019050825182526020830151602083015260408301516040830152606083015160608301526080830151608083015260a083015160a083015292915050565b600061ffff87168252602060018060a01b0387168184015260a060408401526145fb60a0840187614218565b8515156060850152838103608085015282855460018082166000811461462857600181146146455761467b565b60028304607f16855260ff1983168686015260408501935061467b565b600283048086526146558a61470a565b885b828110156146725781548882018a0152908401908801614657565b87018801955050505b50919b9a5050505050505050505050565b61ffff929092168252602082015260400190565b90815260200190565b918252602082015260400190565b8381526020810183905260608101611def6040830184614263565b600060a0820190508682528560208301528460408301528360608301526135826080830184614263565b60ff91909116815260200190565b60009081526020902090565b6001600160a01b038116811461472b57600080fd5b50565b801515811461472b57600080fd5b61ffff8116811461472b57600080fdfe4f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734c7a4170703a2064657374696e6174696f6e20636861696e206973206e6f742061207472757374656420736f75726365536166654d6174683a206d756c7469706c69636174696f6e206f766572666c6f774f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e65724c7a4170703a20696e76616c696420736f757263652073656e64696e6720636f6e7472616374a2646970667358221220349585faf69611c630acf1102208ada637cb9749db0c100c38d459ec12a762f264736f6c634300070600330000000000000000000000009d1b1669c73b033dfe47ae5a0164ab96df25b944000000000000000000000000b6319cc6c8c27a8f5daf0dd3df91ea35c4720dd7
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000009d1b1669c73b033dfe47ae5a0164ab96df25b944000000000000000000000000b6319cc6c8c27a8f5daf0dd3df91ea35c4720dd7
-----Decoded View---------------
Arg [0] : _factory (address): 0x9d1b1669c73b033dfe47ae5a0164ab96df25b944
Arg [1] : _endpoint (address): 0xb6319cc6c8c27a8f5daf0dd3df91ea35c4720dd7
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000009d1b1669c73b033dfe47ae5a0164ab96df25b944
Arg [1] : 000000000000000000000000b6319cc6c8c27a8f5daf0dd3df91ea35c4720dd7
Age | Block | Fee Address | BC Fee Address | Voting Power | Jailed | Incoming |
---|
Validator ID :
0 FTM
Amount Staked
0
Amount Delegated
0
Staking Total
0
Staking Start Epoch
0
Staking Start Time
0
Proof of Importance
0
Origination Score
0
Validation Score
0
Active
0
Online
0
Downtime
0 s
Address | Amount | claimed Rewards | Created On Epoch | Created On |
---|
Make sure to use the "Vote Down" button for any spammy posts, and the "Vote Up" for interesting conversations.