contract_name
stringlengths 1
61
| file_path
stringlengths 5
50.4k
| contract_address
stringlengths 42
42
| language
stringclasses 1
value | class_name
stringlengths 1
61
| class_code
stringlengths 4
330k
| class_documentation
stringlengths 0
29.1k
| class_documentation_type
stringclasses 6
values | func_name
stringlengths 0
62
| func_code
stringlengths 1
303k
| func_documentation
stringlengths 2
14.9k
| func_documentation_type
stringclasses 4
values | compiler_version
stringlengths 15
42
| license_type
stringclasses 14
values | swarm_source
stringlengths 0
71
| meta
dict | __index_level_0__
int64 0
60.4k
|
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | getTokenIndexPlusOneByToken | function getTokenIndexPlusOneByToken(address token) external view returns (uint);
| /**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
5910,
5996
]
} | 2,407 |
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | approve | function approve(address spender, bool isTrusted) external;
| /**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
6269,
6333
]
} | 2,408 |
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | isApproved | function isApproved(address user, address spender) external view returns (bool);
| /**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
6443,
6528
]
} | 2,409 |
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | beginFarming | function beginFarming(address user, address funder, address token, uint amount) external;
| /**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
6888,
6982
]
} | 2,410 |
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | endFarmingByToken | function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
| /**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
7430,
7540
]
} | 2,411 |
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | withdrawAllWhenOutOfSeason | function withdrawAllWhenOutOfSeason(address user, address recipient) external;
| /**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
7785,
7868
]
} | 2,412 |
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | withdrawByTokenWhenOutOfSeason | function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
| /**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
8200,
8351
]
} | 2,413 |
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | getRewardBalanceByOwner | function getRewardBalanceByOwner(address owner) external view returns (uint);
| /**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
8529,
8611
]
} | 2,414 |
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | getRewardBalanceByOwnerAndToken | function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
| /**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
8811,
8916
]
} | 2,415 |
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | balanceOf | function balanceOf(address owner, address token) external view returns (uint);
| /**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
9256,
9339
]
} | 2,416 |
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | getMostRecentDepositTimestampByOwnerAndToken | function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
| /**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
9572,
9692
]
} | 2,417 |
DMGYieldFarmingRouter | contracts/external/farming/v1/IDMGYieldFarmingV1.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | IDMGYieldFarmingV1 | interface IDMGYieldFarmingV1 {
// ////////////////////
// Events
// ////////////////////
event GlobalProxySet(address indexed proxy, bool isTrusted);
event TokenAdded(address indexed token, address indexed underlyingToken, uint8 underlyingTokenDecimals, uint16 points);
event TokenRemoved(address indexed token);
event FarmSeasonBegun(uint indexed seasonIndex, uint dmgAmount);
event FarmSeasonEnd(uint indexed seasonIndex, address dustRecipient, uint dustyDmgAmount);
event DmgGrowthCoefficientSet(uint coefficient);
event RewardPointsSet(address indexed token, uint16 points);
event Approval(address indexed user, address indexed spender, bool isTrusted);
event BeginFarming(address indexed owner, address indexed token, uint depositedAmount);
event EndFarming(address indexed owner, address indexed token, uint withdrawnAmount, uint earnedDmgAmount);
event WithdrawOutOfSeason(address indexed owner, address indexed token, address indexed recipient, uint amount);
// ////////////////////
// Admin Functions
// ////////////////////
/**
* Sets the `proxy` as a trusted contract, allowing it to interact with the user, on the user's behalf.
*
* @param proxy The address that can interact on the user's behalf.
* @param isTrusted True if the proxy is trusted or false if it's not (should be removed).
*/
function approveGloballyTrustedProxy(address proxy, bool isTrusted) external;
/**
* @return true if the provided `proxy` is globally trusted and may interact with the yield farming contract on a
* user's behalf or false otherwise.
*/
function isGloballyTrustedProxy(address proxy) external view returns (bool);
/**
* @param token The address of the token to be supported for farming.
* @param underlyingToken The token to which this token is pegged. IE a Uniswap-V2 LP equity token for
* DAI-mDAI has an underlying token of DAI.
* @param underlyingTokenDecimals The number of decimals that the `underlyingToken` has.
* @param points The amount of reward points for the provided token.
*/
function addAllowableToken(address token, address underlyingToken, uint8 underlyingTokenDecimals, uint16 points) external;
/**
* @param token The address of the token that will be removed from farming.
*/
function removeAllowableToken(address token) external;
/**
* Changes the reward points for the provided token. Reward points are a weighting system that enables certain
* tokens to accrue DMG faster than others, allowing the protocol to prioritize certain deposits.
*/
function setRewardPointsByToken(address token, uint16 points) external;
/**
* Sets the DMG growth coefficient to use the new parameter provided. This variable is used to define how much
* DMG is earned every second, for each point accrued.
*/
function setDmgGrowthCoefficient(uint dmgGrowthCoefficient) external;
/**
* Begins the farming process so users that accumulate DMG by locking tokens can start for this rotation. Calling
* this function increments the currentSeasonIndex, starting a new season. This function reverts if there is
* already an active season.
*
* @param dmgAmount The amount of DMG that will be used to fund this campaign.
*/
function beginFarmingSeason(uint dmgAmount) external;
/**
* Ends the active farming process if the admin calls this function. Otherwise, anyone may call this function once
* all DMG have been drained from the contract.
*
* @param dustRecipient The recipient of any leftover DMG in this contract, when the campaign finishes.
*/
function endActiveFarmingSeason(address dustRecipient) external;
// ////////////////////
// Misc Functions
// ////////////////////
/**
* @return The tokens that the farm supports.
*/
function getFarmTokens() external view returns (address[] memory);
/**
* @return True if the provided token is supported for farming, or false if it's not.
*/
function isSupportedToken(address token) external view returns (bool);
/**
* @return True if there is an active season for farming, or false if there isn't one.
*/
function isFarmActive() external view returns (bool);
/**
* The address that acts as a "secondary" owner with quicker access to function calling than the owner. Typically,
* this is the DMMF.
*/
function guardian() external view returns (address);
/**
* @return The DMG token.
*/
function dmgToken() external view returns (address);
/**
* @return The growth coefficient for earning DMG while farming. Each unit represents how much DMG is earned per
* point
*/
function dmgGrowthCoefficient() external view returns (uint);
/**
* @return The amount of points that the provided token earns for each unit of token deposited. Defaults to `1`
* if the provided `token` does not exist or does not have a special weight. This number is `2` decimals.
*/
function getRewardPointsByToken(address token) external view returns (uint16);
/**
* @return The number of decimals that the underlying token has.
*/
function getTokenDecimalsByToken(address token) external view returns (uint8);
/**
* @return The index into the array returned from `getFarmTokens`, plus 1. 0 if the token isn't found. If the
* index returned is non-zero, subtract 1 from it to get the real index into the array.
*/
function getTokenIndexPlusOneByToken(address token) external view returns (uint);
// ////////////////////
// User Functions
// ////////////////////
/**
* Approves the spender from `msg.sender` to transfer funds into the contract on the user's behalf. If `isTrusted`
* is marked as false, removes the spender.
*/
function approve(address spender, bool isTrusted) external;
/**
* True if the `spender` can transfer tokens on the user's behalf to this contract.
*/
function isApproved(address user, address spender) external view returns (bool);
/**
* Begins a farm by transferring `amount` of `token` from `user` to this contract and adds it to the balance of
* `user`. `user` must be either 1) msg.sender or 2) a wallet who has approved msg.sender as a proxy; else this
* function reverts. `funder` must fit into the same criteria as `user`; else this function reverts
*/
function beginFarming(address user, address funder, address token, uint amount) external;
/**
* Ends a farm by transferring all of `token` deposited by `from` to `recipient`, from this contract, as well as
* all earned DMG for farming `token` to `recipient`. `from` must be either 1) msg.sender or 2) an approved
* proxy; else this function reverts.
*
* @return The amount of `token` withdrawn and the amount of DMG earned for farming. Both values are sent to
* `recipient`.
*/
function endFarmingByToken(address from, address recipient, address token) external returns (uint, uint);
/**
* Withdraws all of `msg.sender`'s tokens from the farm to `recipient`. This function reverts if there is an active
* farm. `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*/
function withdrawAllWhenOutOfSeason(address user, address recipient) external;
/**
* Withdraws all of `user` `token` from the farm to `recipient`. This function reverts if there is an active farm and the token is NOT removed.
* `user` must be either 1) msg.sender or 2) an approved proxy; else this function reverts.
*
* @return The amount of tokens sent to `recipient`
*/
function withdrawByTokenWhenOutOfSeason(
address user,
address recipient,
address token
) external returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm. If there are no active season, this
* function returns `0`.
*/
function getRewardBalanceByOwner(address owner) external view returns (uint);
/**
* @return The amount of DMG that this owner has earned in the active farm for the provided token. If there is no
* active season, this function returns `0`.
*/
function getRewardBalanceByOwnerAndToken(address owner, address token) external view returns (uint);
/**
* @return The amount of `token` that this owner has deposited into this contract. The user may withdraw this
* non-zero balance by invoking `endFarming` or `endFarmingByToken` if there is an active farm. If there is
* NO active farm, the user may withdraw his/her funds by invoking
*/
function balanceOf(address owner, address token) external view returns (uint);
/**
* @return The most recent timestamp at which the `owner` deposited `token` into the yield farming contract for
* the current season. If there is no active season, this function returns `0`.
*/
function getMostRecentDepositTimestampByOwnerAndToken(address owner, address token) external view returns (uint64);
/**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/
function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
} | /**
* The interface for DMG "Yield Farming" - A process through which users may earn DMG by locking up their mTokens in
* Uniswap pools, and staking the Uniswap pool's equity token in this contract.
*
* Yield farming in the DMM Ecosystem entails "rotation periods" in which a season is active, in order to incentivize
* deposits of underlying tokens into the protocol.
*/ | NatSpecMultiLine | getMostRecentIndexedDmgEarnedByOwnerAndToken | function getMostRecentIndexedDmgEarnedByOwnerAndToken(address owner, address token) external view returns (uint);
| /**
* @return The most recent indexed amount of DMG earned by the `owner` for the deposited `token` which is being
* farmed for the most-recent season. If there is no active season, this function returns `0`.
*/ | NatSpecMultiLine | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
9940,
10058
]
} | 2,418 |
DigiMarket | contracts/DigiMarket.sol | 0x75c45905e903a66c8a109baf3cf13a49b5f67778 | Solidity | DigiMarket | contract DigiMarket is Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeMath for uint8;
uint256 BIGNUMBER = 10 ** 18;
/******************
CONFIG
******************/
uint256 public purchaseFee = 1000; // 10%
uint256 public digiAmountRequired = 3000 * (BIGNUMBER);
/******************
EVENTS
******************/
event CreatedSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event CanceledSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event SaleBuyed(uint256 saleId, address indexed wallet, uint256 amount, uint256 indexed tokenId, address indexed tokenAddress, uint256 created);
/******************
INTERNAL ACCOUNTING
*******************/
address public stakeERC20;
address public digiERC721;
address public stableERC20;
address[] public feesDestinators;
uint256[] public feesPercentages;
uint256 public salesCount = 0;
mapping (uint256 => Sale) public sales;
mapping (address => mapping (uint256 => uint256)) public lastSaleByToken;
mapping (uint256 => Royalty) public royaltiesByToken;
struct Royalty {
uint256 fee;
address wallet;
}
struct Sale {
uint256 tokenId;
address tokenAddress;
address owner;
uint256 price;
bool royalty;
bool buyed;
uint256 endDate;
}
/******************
PUBLIC FUNCTIONS
*******************/
constructor(
address _stakeERC20,
address _stableERC20,
address _digiERC721
)
public
{
require(address(_stakeERC20) != address(0));
require(address(_stableERC20) != address(0));
require(address(_digiERC721) != address(0));
stakeERC20 = _stakeERC20;
stableERC20 = _stableERC20;
digiERC721 = _digiERC721;
}
function setRoyaltyForToken(uint256 _tokenId, address beneficiary, uint256 _fee) external {
require(msg.sender == IERC721(digiERC721).ownerOf(_tokenId), "DigiMarket: Not the owner");
require(AccessControl(digiERC721).hasRole(keccak256("MINTER"), msg.sender), "DigiMarker: Not minter");
require(lastSaleByToken[digiERC721][_tokenId] == 0, "DigiMarket: Auction already created");
require(royaltiesByToken[_tokenId].wallet == address(0), "DigiMarket: Royalty already setted");
royaltiesByToken[_tokenId] = Royalty({
wallet: beneficiary,
fee: _fee
});
}
/**
* @dev User creates sale for NFT.
*/
function createSale(
uint256 _tokenId,
address _tokenAddress,
uint256 _price,
uint256 _duration
)
public
requiredAmount(msg.sender, digiAmountRequired)
returns (uint256)
{
require(IERC721(_tokenAddress).ownerOf(_tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
require(IERC721(_tokenAddress).isApprovedForAll(msg.sender, address(this)), 'DigiMarket: DigiMarket contract address must be approved for transfer');
uint256 timeNow = _getTime();
uint256 newSaleId = salesCount;
salesCount += 1;
sales[newSaleId] = Sale({
tokenId: _tokenId,
tokenAddress: _tokenAddress,
owner: msg.sender,
price: _price,
royalty: _tokenAddress == digiERC721 && royaltiesByToken[_tokenId].wallet != address(0),
buyed: false,
endDate: timeNow + _duration
});
lastSaleByToken[_tokenAddress][_tokenId] = newSaleId;
emit CreatedSale(newSaleId, msg.sender, _tokenId, _tokenAddress, timeNow);
return newSaleId;
}
/**
* @dev User cancels sale for NFT.
*/
function cancelSale(
uint256 _saleId
)
public
inProgress(_saleId)
returns (uint256)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
uint256 timeNow = _getTime();
sales[_saleId].endDate = timeNow;
emit CanceledSale(_saleId, msg.sender, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev User buyes the NFT.
*/
function buy(uint256 _saleId)
public
inProgress(_saleId)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == sales[_saleId].owner, 'DigiMarket: Sale creator user is not longer NFT owner');
require(IERC20(stableERC20).balanceOf(msg.sender) >= sales[_saleId].price, 'DigiMarket: User does not have enough balance');
uint amount = sales[_saleId].price;
uint256 feeAmount = amount.mul(purchaseFee).div(10000);
uint256 royaltyFeeAmount = 0;
if (sales[_saleId].royalty) {
royaltyFeeAmount = amount.mul(royaltiesByToken[sales[_saleId].tokenId].fee).div(10000);
}
uint256 amountAfterFee = amount.sub(feeAmount).sub(royaltyFeeAmount);
IERC20(stableERC20).transferFrom(msg.sender, address(this), feeAmount);
IERC20(stableERC20).transferFrom(msg.sender, sales[_saleId].owner, amountAfterFee);
if (royaltyFeeAmount > 0) {
IERC20(stableERC20).transferFrom(msg.sender, royaltiesByToken[sales[_saleId].tokenId].wallet, royaltyFeeAmount);
}
IERC721(sales[_saleId].tokenAddress).transferFrom(sales[_saleId].owner, msg.sender, sales[_saleId].tokenId);
uint256 timeNow = _getTime();
sales[_saleId].buyed = true;
emit SaleBuyed(_saleId, msg.sender, sales[_saleId].price, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev Send all the acumulated fees for one token to the fee destinators.
*/
function withdrawAcumulatedFees() public {
uint256 total = IERC20(stableERC20).balanceOf(address(this));
for (uint8 i = 0; i < feesDestinators.length; i++) {
IERC20(stableERC20).transfer(
feesDestinators[i],
total.mul(feesPercentages[i]).div(100)
);
}
}
/**
* @dev Sets the purchaseFee for every withdraw.
*/
function setFee(uint256 _purchaseFee) public onlyOwner() {
require(_purchaseFee <= 3000, "DigiMarket: Max fee 30%");
purchaseFee = _purchaseFee;
}
/**
* @dev Configure how to distribute the fees for user's withdraws.
*/
function setFeesDestinatorsWithPercentages(
address[] memory _destinators,
uint256[] memory _percentages
)
public
onlyOwner()
{
require(_destinators.length == _percentages.length, "DigiMarket: Destinators and percentageslenght are not equals");
uint256 total = 0;
for (uint8 i = 0; i < _percentages.length; i++) {
total += _percentages[i];
}
require(total == 100, "DigiMarket: Percentages sum must be 100");
feesDestinators = _destinators;
feesPercentages = _percentages;
}
/******************
PRIVATE FUNCTIONS
*******************/
function _getTime() internal view returns (uint256) {
return block.timestamp;
}
/******************
MODIFIERS
*******************/
modifier requiredAmount(address _wallet, uint256 _amount) {
require(
IERC20(stakeERC20).balanceOf(_wallet) >= _amount,
'DigiMarket: User needs more token balance in order to do this action'
);
_;
}
modifier inProgress(uint256 _saleId) {
require(
(sales[_saleId].endDate > _getTime()) && sales[_saleId].buyed == false,
'DigiMarket: Sale ended'
);
_;
}
} | createSale | function createSale(
uint256 _tokenId,
address _tokenAddress,
uint256 _price,
uint256 _duration
)
public
requiredAmount(msg.sender, digiAmountRequired)
returns (uint256)
{
require(IERC721(_tokenAddress).ownerOf(_tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
require(IERC721(_tokenAddress).isApprovedForAll(msg.sender, address(this)), 'DigiMarket: DigiMarket contract address must be approved for transfer');
uint256 timeNow = _getTime();
uint256 newSaleId = salesCount;
salesCount += 1;
sales[newSaleId] = Sale({
tokenId: _tokenId,
tokenAddress: _tokenAddress,
owner: msg.sender,
price: _price,
royalty: _tokenAddress == digiERC721 && royaltiesByToken[_tokenId].wallet != address(0),
buyed: false,
endDate: timeNow + _duration
});
lastSaleByToken[_tokenAddress][_tokenId] = newSaleId;
emit CreatedSale(newSaleId, msg.sender, _tokenId, _tokenAddress, timeNow);
return newSaleId;
}
| /**
* @dev User creates sale for NFT.
*/ | NatSpecMultiLine | v0.6.5+commit.f956cc89 | None | ipfs://3b709d2dc8ce1599dbd3b3db10b7756a837d712c09c447638fc90ad5d43b07fd | {
"func_code_index": [
2735,
3908
]
} | 2,419 |
||
DigiMarket | contracts/DigiMarket.sol | 0x75c45905e903a66c8a109baf3cf13a49b5f67778 | Solidity | DigiMarket | contract DigiMarket is Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeMath for uint8;
uint256 BIGNUMBER = 10 ** 18;
/******************
CONFIG
******************/
uint256 public purchaseFee = 1000; // 10%
uint256 public digiAmountRequired = 3000 * (BIGNUMBER);
/******************
EVENTS
******************/
event CreatedSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event CanceledSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event SaleBuyed(uint256 saleId, address indexed wallet, uint256 amount, uint256 indexed tokenId, address indexed tokenAddress, uint256 created);
/******************
INTERNAL ACCOUNTING
*******************/
address public stakeERC20;
address public digiERC721;
address public stableERC20;
address[] public feesDestinators;
uint256[] public feesPercentages;
uint256 public salesCount = 0;
mapping (uint256 => Sale) public sales;
mapping (address => mapping (uint256 => uint256)) public lastSaleByToken;
mapping (uint256 => Royalty) public royaltiesByToken;
struct Royalty {
uint256 fee;
address wallet;
}
struct Sale {
uint256 tokenId;
address tokenAddress;
address owner;
uint256 price;
bool royalty;
bool buyed;
uint256 endDate;
}
/******************
PUBLIC FUNCTIONS
*******************/
constructor(
address _stakeERC20,
address _stableERC20,
address _digiERC721
)
public
{
require(address(_stakeERC20) != address(0));
require(address(_stableERC20) != address(0));
require(address(_digiERC721) != address(0));
stakeERC20 = _stakeERC20;
stableERC20 = _stableERC20;
digiERC721 = _digiERC721;
}
function setRoyaltyForToken(uint256 _tokenId, address beneficiary, uint256 _fee) external {
require(msg.sender == IERC721(digiERC721).ownerOf(_tokenId), "DigiMarket: Not the owner");
require(AccessControl(digiERC721).hasRole(keccak256("MINTER"), msg.sender), "DigiMarker: Not minter");
require(lastSaleByToken[digiERC721][_tokenId] == 0, "DigiMarket: Auction already created");
require(royaltiesByToken[_tokenId].wallet == address(0), "DigiMarket: Royalty already setted");
royaltiesByToken[_tokenId] = Royalty({
wallet: beneficiary,
fee: _fee
});
}
/**
* @dev User creates sale for NFT.
*/
function createSale(
uint256 _tokenId,
address _tokenAddress,
uint256 _price,
uint256 _duration
)
public
requiredAmount(msg.sender, digiAmountRequired)
returns (uint256)
{
require(IERC721(_tokenAddress).ownerOf(_tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
require(IERC721(_tokenAddress).isApprovedForAll(msg.sender, address(this)), 'DigiMarket: DigiMarket contract address must be approved for transfer');
uint256 timeNow = _getTime();
uint256 newSaleId = salesCount;
salesCount += 1;
sales[newSaleId] = Sale({
tokenId: _tokenId,
tokenAddress: _tokenAddress,
owner: msg.sender,
price: _price,
royalty: _tokenAddress == digiERC721 && royaltiesByToken[_tokenId].wallet != address(0),
buyed: false,
endDate: timeNow + _duration
});
lastSaleByToken[_tokenAddress][_tokenId] = newSaleId;
emit CreatedSale(newSaleId, msg.sender, _tokenId, _tokenAddress, timeNow);
return newSaleId;
}
/**
* @dev User cancels sale for NFT.
*/
function cancelSale(
uint256 _saleId
)
public
inProgress(_saleId)
returns (uint256)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
uint256 timeNow = _getTime();
sales[_saleId].endDate = timeNow;
emit CanceledSale(_saleId, msg.sender, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev User buyes the NFT.
*/
function buy(uint256 _saleId)
public
inProgress(_saleId)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == sales[_saleId].owner, 'DigiMarket: Sale creator user is not longer NFT owner');
require(IERC20(stableERC20).balanceOf(msg.sender) >= sales[_saleId].price, 'DigiMarket: User does not have enough balance');
uint amount = sales[_saleId].price;
uint256 feeAmount = amount.mul(purchaseFee).div(10000);
uint256 royaltyFeeAmount = 0;
if (sales[_saleId].royalty) {
royaltyFeeAmount = amount.mul(royaltiesByToken[sales[_saleId].tokenId].fee).div(10000);
}
uint256 amountAfterFee = amount.sub(feeAmount).sub(royaltyFeeAmount);
IERC20(stableERC20).transferFrom(msg.sender, address(this), feeAmount);
IERC20(stableERC20).transferFrom(msg.sender, sales[_saleId].owner, amountAfterFee);
if (royaltyFeeAmount > 0) {
IERC20(stableERC20).transferFrom(msg.sender, royaltiesByToken[sales[_saleId].tokenId].wallet, royaltyFeeAmount);
}
IERC721(sales[_saleId].tokenAddress).transferFrom(sales[_saleId].owner, msg.sender, sales[_saleId].tokenId);
uint256 timeNow = _getTime();
sales[_saleId].buyed = true;
emit SaleBuyed(_saleId, msg.sender, sales[_saleId].price, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev Send all the acumulated fees for one token to the fee destinators.
*/
function withdrawAcumulatedFees() public {
uint256 total = IERC20(stableERC20).balanceOf(address(this));
for (uint8 i = 0; i < feesDestinators.length; i++) {
IERC20(stableERC20).transfer(
feesDestinators[i],
total.mul(feesPercentages[i]).div(100)
);
}
}
/**
* @dev Sets the purchaseFee for every withdraw.
*/
function setFee(uint256 _purchaseFee) public onlyOwner() {
require(_purchaseFee <= 3000, "DigiMarket: Max fee 30%");
purchaseFee = _purchaseFee;
}
/**
* @dev Configure how to distribute the fees for user's withdraws.
*/
function setFeesDestinatorsWithPercentages(
address[] memory _destinators,
uint256[] memory _percentages
)
public
onlyOwner()
{
require(_destinators.length == _percentages.length, "DigiMarket: Destinators and percentageslenght are not equals");
uint256 total = 0;
for (uint8 i = 0; i < _percentages.length; i++) {
total += _percentages[i];
}
require(total == 100, "DigiMarket: Percentages sum must be 100");
feesDestinators = _destinators;
feesPercentages = _percentages;
}
/******************
PRIVATE FUNCTIONS
*******************/
function _getTime() internal view returns (uint256) {
return block.timestamp;
}
/******************
MODIFIERS
*******************/
modifier requiredAmount(address _wallet, uint256 _amount) {
require(
IERC20(stakeERC20).balanceOf(_wallet) >= _amount,
'DigiMarket: User needs more token balance in order to do this action'
);
_;
}
modifier inProgress(uint256 _saleId) {
require(
(sales[_saleId].endDate > _getTime()) && sales[_saleId].buyed == false,
'DigiMarket: Sale ended'
);
_;
}
} | cancelSale | function cancelSale(
uint256 _saleId
)
public
inProgress(_saleId)
returns (uint256)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
uint256 timeNow = _getTime();
sales[_saleId].endDate = timeNow;
emit CanceledSale(_saleId, msg.sender, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
| /**
* @dev User cancels sale for NFT.
*/ | NatSpecMultiLine | v0.6.5+commit.f956cc89 | None | ipfs://3b709d2dc8ce1599dbd3b3db10b7756a837d712c09c447638fc90ad5d43b07fd | {
"func_code_index": [
3967,
4452
]
} | 2,420 |
||
DigiMarket | contracts/DigiMarket.sol | 0x75c45905e903a66c8a109baf3cf13a49b5f67778 | Solidity | DigiMarket | contract DigiMarket is Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeMath for uint8;
uint256 BIGNUMBER = 10 ** 18;
/******************
CONFIG
******************/
uint256 public purchaseFee = 1000; // 10%
uint256 public digiAmountRequired = 3000 * (BIGNUMBER);
/******************
EVENTS
******************/
event CreatedSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event CanceledSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event SaleBuyed(uint256 saleId, address indexed wallet, uint256 amount, uint256 indexed tokenId, address indexed tokenAddress, uint256 created);
/******************
INTERNAL ACCOUNTING
*******************/
address public stakeERC20;
address public digiERC721;
address public stableERC20;
address[] public feesDestinators;
uint256[] public feesPercentages;
uint256 public salesCount = 0;
mapping (uint256 => Sale) public sales;
mapping (address => mapping (uint256 => uint256)) public lastSaleByToken;
mapping (uint256 => Royalty) public royaltiesByToken;
struct Royalty {
uint256 fee;
address wallet;
}
struct Sale {
uint256 tokenId;
address tokenAddress;
address owner;
uint256 price;
bool royalty;
bool buyed;
uint256 endDate;
}
/******************
PUBLIC FUNCTIONS
*******************/
constructor(
address _stakeERC20,
address _stableERC20,
address _digiERC721
)
public
{
require(address(_stakeERC20) != address(0));
require(address(_stableERC20) != address(0));
require(address(_digiERC721) != address(0));
stakeERC20 = _stakeERC20;
stableERC20 = _stableERC20;
digiERC721 = _digiERC721;
}
function setRoyaltyForToken(uint256 _tokenId, address beneficiary, uint256 _fee) external {
require(msg.sender == IERC721(digiERC721).ownerOf(_tokenId), "DigiMarket: Not the owner");
require(AccessControl(digiERC721).hasRole(keccak256("MINTER"), msg.sender), "DigiMarker: Not minter");
require(lastSaleByToken[digiERC721][_tokenId] == 0, "DigiMarket: Auction already created");
require(royaltiesByToken[_tokenId].wallet == address(0), "DigiMarket: Royalty already setted");
royaltiesByToken[_tokenId] = Royalty({
wallet: beneficiary,
fee: _fee
});
}
/**
* @dev User creates sale for NFT.
*/
function createSale(
uint256 _tokenId,
address _tokenAddress,
uint256 _price,
uint256 _duration
)
public
requiredAmount(msg.sender, digiAmountRequired)
returns (uint256)
{
require(IERC721(_tokenAddress).ownerOf(_tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
require(IERC721(_tokenAddress).isApprovedForAll(msg.sender, address(this)), 'DigiMarket: DigiMarket contract address must be approved for transfer');
uint256 timeNow = _getTime();
uint256 newSaleId = salesCount;
salesCount += 1;
sales[newSaleId] = Sale({
tokenId: _tokenId,
tokenAddress: _tokenAddress,
owner: msg.sender,
price: _price,
royalty: _tokenAddress == digiERC721 && royaltiesByToken[_tokenId].wallet != address(0),
buyed: false,
endDate: timeNow + _duration
});
lastSaleByToken[_tokenAddress][_tokenId] = newSaleId;
emit CreatedSale(newSaleId, msg.sender, _tokenId, _tokenAddress, timeNow);
return newSaleId;
}
/**
* @dev User cancels sale for NFT.
*/
function cancelSale(
uint256 _saleId
)
public
inProgress(_saleId)
returns (uint256)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
uint256 timeNow = _getTime();
sales[_saleId].endDate = timeNow;
emit CanceledSale(_saleId, msg.sender, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev User buyes the NFT.
*/
function buy(uint256 _saleId)
public
inProgress(_saleId)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == sales[_saleId].owner, 'DigiMarket: Sale creator user is not longer NFT owner');
require(IERC20(stableERC20).balanceOf(msg.sender) >= sales[_saleId].price, 'DigiMarket: User does not have enough balance');
uint amount = sales[_saleId].price;
uint256 feeAmount = amount.mul(purchaseFee).div(10000);
uint256 royaltyFeeAmount = 0;
if (sales[_saleId].royalty) {
royaltyFeeAmount = amount.mul(royaltiesByToken[sales[_saleId].tokenId].fee).div(10000);
}
uint256 amountAfterFee = amount.sub(feeAmount).sub(royaltyFeeAmount);
IERC20(stableERC20).transferFrom(msg.sender, address(this), feeAmount);
IERC20(stableERC20).transferFrom(msg.sender, sales[_saleId].owner, amountAfterFee);
if (royaltyFeeAmount > 0) {
IERC20(stableERC20).transferFrom(msg.sender, royaltiesByToken[sales[_saleId].tokenId].wallet, royaltyFeeAmount);
}
IERC721(sales[_saleId].tokenAddress).transferFrom(sales[_saleId].owner, msg.sender, sales[_saleId].tokenId);
uint256 timeNow = _getTime();
sales[_saleId].buyed = true;
emit SaleBuyed(_saleId, msg.sender, sales[_saleId].price, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev Send all the acumulated fees for one token to the fee destinators.
*/
function withdrawAcumulatedFees() public {
uint256 total = IERC20(stableERC20).balanceOf(address(this));
for (uint8 i = 0; i < feesDestinators.length; i++) {
IERC20(stableERC20).transfer(
feesDestinators[i],
total.mul(feesPercentages[i]).div(100)
);
}
}
/**
* @dev Sets the purchaseFee for every withdraw.
*/
function setFee(uint256 _purchaseFee) public onlyOwner() {
require(_purchaseFee <= 3000, "DigiMarket: Max fee 30%");
purchaseFee = _purchaseFee;
}
/**
* @dev Configure how to distribute the fees for user's withdraws.
*/
function setFeesDestinatorsWithPercentages(
address[] memory _destinators,
uint256[] memory _percentages
)
public
onlyOwner()
{
require(_destinators.length == _percentages.length, "DigiMarket: Destinators and percentageslenght are not equals");
uint256 total = 0;
for (uint8 i = 0; i < _percentages.length; i++) {
total += _percentages[i];
}
require(total == 100, "DigiMarket: Percentages sum must be 100");
feesDestinators = _destinators;
feesPercentages = _percentages;
}
/******************
PRIVATE FUNCTIONS
*******************/
function _getTime() internal view returns (uint256) {
return block.timestamp;
}
/******************
MODIFIERS
*******************/
modifier requiredAmount(address _wallet, uint256 _amount) {
require(
IERC20(stakeERC20).balanceOf(_wallet) >= _amount,
'DigiMarket: User needs more token balance in order to do this action'
);
_;
}
modifier inProgress(uint256 _saleId) {
require(
(sales[_saleId].endDate > _getTime()) && sales[_saleId].buyed == false,
'DigiMarket: Sale ended'
);
_;
}
} | buy | function buy(uint256 _saleId)
public
inProgress(_saleId)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == sales[_saleId].owner, 'DigiMarket: Sale creator user is not longer NFT owner');
require(IERC20(stableERC20).balanceOf(msg.sender) >= sales[_saleId].price, 'DigiMarket: User does not have enough balance');
uint amount = sales[_saleId].price;
uint256 feeAmount = amount.mul(purchaseFee).div(10000);
uint256 royaltyFeeAmount = 0;
if (sales[_saleId].royalty) {
royaltyFeeAmount = amount.mul(royaltiesByToken[sales[_saleId].tokenId].fee).div(10000);
}
uint256 amountAfterFee = amount.sub(feeAmount).sub(royaltyFeeAmount);
IERC20(stableERC20).transferFrom(msg.sender, address(this), feeAmount);
IERC20(stableERC20).transferFrom(msg.sender, sales[_saleId].owner, amountAfterFee);
if (royaltyFeeAmount > 0) {
IERC20(stableERC20).transferFrom(msg.sender, royaltiesByToken[sales[_saleId].tokenId].wallet, royaltyFeeAmount);
}
IERC721(sales[_saleId].tokenAddress).transferFrom(sales[_saleId].owner, msg.sender, sales[_saleId].tokenId);
uint256 timeNow = _getTime();
sales[_saleId].buyed = true;
emit SaleBuyed(_saleId, msg.sender, sales[_saleId].price, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
| /**
* @dev User buyes the NFT.
*/ | NatSpecMultiLine | v0.6.5+commit.f956cc89 | None | ipfs://3b709d2dc8ce1599dbd3b3db10b7756a837d712c09c447638fc90ad5d43b07fd | {
"func_code_index": [
4504,
5982
]
} | 2,421 |
||
DigiMarket | contracts/DigiMarket.sol | 0x75c45905e903a66c8a109baf3cf13a49b5f67778 | Solidity | DigiMarket | contract DigiMarket is Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeMath for uint8;
uint256 BIGNUMBER = 10 ** 18;
/******************
CONFIG
******************/
uint256 public purchaseFee = 1000; // 10%
uint256 public digiAmountRequired = 3000 * (BIGNUMBER);
/******************
EVENTS
******************/
event CreatedSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event CanceledSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event SaleBuyed(uint256 saleId, address indexed wallet, uint256 amount, uint256 indexed tokenId, address indexed tokenAddress, uint256 created);
/******************
INTERNAL ACCOUNTING
*******************/
address public stakeERC20;
address public digiERC721;
address public stableERC20;
address[] public feesDestinators;
uint256[] public feesPercentages;
uint256 public salesCount = 0;
mapping (uint256 => Sale) public sales;
mapping (address => mapping (uint256 => uint256)) public lastSaleByToken;
mapping (uint256 => Royalty) public royaltiesByToken;
struct Royalty {
uint256 fee;
address wallet;
}
struct Sale {
uint256 tokenId;
address tokenAddress;
address owner;
uint256 price;
bool royalty;
bool buyed;
uint256 endDate;
}
/******************
PUBLIC FUNCTIONS
*******************/
constructor(
address _stakeERC20,
address _stableERC20,
address _digiERC721
)
public
{
require(address(_stakeERC20) != address(0));
require(address(_stableERC20) != address(0));
require(address(_digiERC721) != address(0));
stakeERC20 = _stakeERC20;
stableERC20 = _stableERC20;
digiERC721 = _digiERC721;
}
function setRoyaltyForToken(uint256 _tokenId, address beneficiary, uint256 _fee) external {
require(msg.sender == IERC721(digiERC721).ownerOf(_tokenId), "DigiMarket: Not the owner");
require(AccessControl(digiERC721).hasRole(keccak256("MINTER"), msg.sender), "DigiMarker: Not minter");
require(lastSaleByToken[digiERC721][_tokenId] == 0, "DigiMarket: Auction already created");
require(royaltiesByToken[_tokenId].wallet == address(0), "DigiMarket: Royalty already setted");
royaltiesByToken[_tokenId] = Royalty({
wallet: beneficiary,
fee: _fee
});
}
/**
* @dev User creates sale for NFT.
*/
function createSale(
uint256 _tokenId,
address _tokenAddress,
uint256 _price,
uint256 _duration
)
public
requiredAmount(msg.sender, digiAmountRequired)
returns (uint256)
{
require(IERC721(_tokenAddress).ownerOf(_tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
require(IERC721(_tokenAddress).isApprovedForAll(msg.sender, address(this)), 'DigiMarket: DigiMarket contract address must be approved for transfer');
uint256 timeNow = _getTime();
uint256 newSaleId = salesCount;
salesCount += 1;
sales[newSaleId] = Sale({
tokenId: _tokenId,
tokenAddress: _tokenAddress,
owner: msg.sender,
price: _price,
royalty: _tokenAddress == digiERC721 && royaltiesByToken[_tokenId].wallet != address(0),
buyed: false,
endDate: timeNow + _duration
});
lastSaleByToken[_tokenAddress][_tokenId] = newSaleId;
emit CreatedSale(newSaleId, msg.sender, _tokenId, _tokenAddress, timeNow);
return newSaleId;
}
/**
* @dev User cancels sale for NFT.
*/
function cancelSale(
uint256 _saleId
)
public
inProgress(_saleId)
returns (uint256)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
uint256 timeNow = _getTime();
sales[_saleId].endDate = timeNow;
emit CanceledSale(_saleId, msg.sender, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev User buyes the NFT.
*/
function buy(uint256 _saleId)
public
inProgress(_saleId)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == sales[_saleId].owner, 'DigiMarket: Sale creator user is not longer NFT owner');
require(IERC20(stableERC20).balanceOf(msg.sender) >= sales[_saleId].price, 'DigiMarket: User does not have enough balance');
uint amount = sales[_saleId].price;
uint256 feeAmount = amount.mul(purchaseFee).div(10000);
uint256 royaltyFeeAmount = 0;
if (sales[_saleId].royalty) {
royaltyFeeAmount = amount.mul(royaltiesByToken[sales[_saleId].tokenId].fee).div(10000);
}
uint256 amountAfterFee = amount.sub(feeAmount).sub(royaltyFeeAmount);
IERC20(stableERC20).transferFrom(msg.sender, address(this), feeAmount);
IERC20(stableERC20).transferFrom(msg.sender, sales[_saleId].owner, amountAfterFee);
if (royaltyFeeAmount > 0) {
IERC20(stableERC20).transferFrom(msg.sender, royaltiesByToken[sales[_saleId].tokenId].wallet, royaltyFeeAmount);
}
IERC721(sales[_saleId].tokenAddress).transferFrom(sales[_saleId].owner, msg.sender, sales[_saleId].tokenId);
uint256 timeNow = _getTime();
sales[_saleId].buyed = true;
emit SaleBuyed(_saleId, msg.sender, sales[_saleId].price, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev Send all the acumulated fees for one token to the fee destinators.
*/
function withdrawAcumulatedFees() public {
uint256 total = IERC20(stableERC20).balanceOf(address(this));
for (uint8 i = 0; i < feesDestinators.length; i++) {
IERC20(stableERC20).transfer(
feesDestinators[i],
total.mul(feesPercentages[i]).div(100)
);
}
}
/**
* @dev Sets the purchaseFee for every withdraw.
*/
function setFee(uint256 _purchaseFee) public onlyOwner() {
require(_purchaseFee <= 3000, "DigiMarket: Max fee 30%");
purchaseFee = _purchaseFee;
}
/**
* @dev Configure how to distribute the fees for user's withdraws.
*/
function setFeesDestinatorsWithPercentages(
address[] memory _destinators,
uint256[] memory _percentages
)
public
onlyOwner()
{
require(_destinators.length == _percentages.length, "DigiMarket: Destinators and percentageslenght are not equals");
uint256 total = 0;
for (uint8 i = 0; i < _percentages.length; i++) {
total += _percentages[i];
}
require(total == 100, "DigiMarket: Percentages sum must be 100");
feesDestinators = _destinators;
feesPercentages = _percentages;
}
/******************
PRIVATE FUNCTIONS
*******************/
function _getTime() internal view returns (uint256) {
return block.timestamp;
}
/******************
MODIFIERS
*******************/
modifier requiredAmount(address _wallet, uint256 _amount) {
require(
IERC20(stakeERC20).balanceOf(_wallet) >= _amount,
'DigiMarket: User needs more token balance in order to do this action'
);
_;
}
modifier inProgress(uint256 _saleId) {
require(
(sales[_saleId].endDate > _getTime()) && sales[_saleId].buyed == false,
'DigiMarket: Sale ended'
);
_;
}
} | withdrawAcumulatedFees | function withdrawAcumulatedFees() public {
uint256 total = IERC20(stableERC20).balanceOf(address(this));
for (uint8 i = 0; i < feesDestinators.length; i++) {
IERC20(stableERC20).transfer(
feesDestinators[i],
total.mul(feesPercentages[i]).div(100)
);
}
}
| /**
* @dev Send all the acumulated fees for one token to the fee destinators.
*/ | NatSpecMultiLine | v0.6.5+commit.f956cc89 | None | ipfs://3b709d2dc8ce1599dbd3b3db10b7756a837d712c09c447638fc90ad5d43b07fd | {
"func_code_index": [
6081,
6441
]
} | 2,422 |
||
DigiMarket | contracts/DigiMarket.sol | 0x75c45905e903a66c8a109baf3cf13a49b5f67778 | Solidity | DigiMarket | contract DigiMarket is Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeMath for uint8;
uint256 BIGNUMBER = 10 ** 18;
/******************
CONFIG
******************/
uint256 public purchaseFee = 1000; // 10%
uint256 public digiAmountRequired = 3000 * (BIGNUMBER);
/******************
EVENTS
******************/
event CreatedSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event CanceledSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event SaleBuyed(uint256 saleId, address indexed wallet, uint256 amount, uint256 indexed tokenId, address indexed tokenAddress, uint256 created);
/******************
INTERNAL ACCOUNTING
*******************/
address public stakeERC20;
address public digiERC721;
address public stableERC20;
address[] public feesDestinators;
uint256[] public feesPercentages;
uint256 public salesCount = 0;
mapping (uint256 => Sale) public sales;
mapping (address => mapping (uint256 => uint256)) public lastSaleByToken;
mapping (uint256 => Royalty) public royaltiesByToken;
struct Royalty {
uint256 fee;
address wallet;
}
struct Sale {
uint256 tokenId;
address tokenAddress;
address owner;
uint256 price;
bool royalty;
bool buyed;
uint256 endDate;
}
/******************
PUBLIC FUNCTIONS
*******************/
constructor(
address _stakeERC20,
address _stableERC20,
address _digiERC721
)
public
{
require(address(_stakeERC20) != address(0));
require(address(_stableERC20) != address(0));
require(address(_digiERC721) != address(0));
stakeERC20 = _stakeERC20;
stableERC20 = _stableERC20;
digiERC721 = _digiERC721;
}
function setRoyaltyForToken(uint256 _tokenId, address beneficiary, uint256 _fee) external {
require(msg.sender == IERC721(digiERC721).ownerOf(_tokenId), "DigiMarket: Not the owner");
require(AccessControl(digiERC721).hasRole(keccak256("MINTER"), msg.sender), "DigiMarker: Not minter");
require(lastSaleByToken[digiERC721][_tokenId] == 0, "DigiMarket: Auction already created");
require(royaltiesByToken[_tokenId].wallet == address(0), "DigiMarket: Royalty already setted");
royaltiesByToken[_tokenId] = Royalty({
wallet: beneficiary,
fee: _fee
});
}
/**
* @dev User creates sale for NFT.
*/
function createSale(
uint256 _tokenId,
address _tokenAddress,
uint256 _price,
uint256 _duration
)
public
requiredAmount(msg.sender, digiAmountRequired)
returns (uint256)
{
require(IERC721(_tokenAddress).ownerOf(_tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
require(IERC721(_tokenAddress).isApprovedForAll(msg.sender, address(this)), 'DigiMarket: DigiMarket contract address must be approved for transfer');
uint256 timeNow = _getTime();
uint256 newSaleId = salesCount;
salesCount += 1;
sales[newSaleId] = Sale({
tokenId: _tokenId,
tokenAddress: _tokenAddress,
owner: msg.sender,
price: _price,
royalty: _tokenAddress == digiERC721 && royaltiesByToken[_tokenId].wallet != address(0),
buyed: false,
endDate: timeNow + _duration
});
lastSaleByToken[_tokenAddress][_tokenId] = newSaleId;
emit CreatedSale(newSaleId, msg.sender, _tokenId, _tokenAddress, timeNow);
return newSaleId;
}
/**
* @dev User cancels sale for NFT.
*/
function cancelSale(
uint256 _saleId
)
public
inProgress(_saleId)
returns (uint256)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
uint256 timeNow = _getTime();
sales[_saleId].endDate = timeNow;
emit CanceledSale(_saleId, msg.sender, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev User buyes the NFT.
*/
function buy(uint256 _saleId)
public
inProgress(_saleId)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == sales[_saleId].owner, 'DigiMarket: Sale creator user is not longer NFT owner');
require(IERC20(stableERC20).balanceOf(msg.sender) >= sales[_saleId].price, 'DigiMarket: User does not have enough balance');
uint amount = sales[_saleId].price;
uint256 feeAmount = amount.mul(purchaseFee).div(10000);
uint256 royaltyFeeAmount = 0;
if (sales[_saleId].royalty) {
royaltyFeeAmount = amount.mul(royaltiesByToken[sales[_saleId].tokenId].fee).div(10000);
}
uint256 amountAfterFee = amount.sub(feeAmount).sub(royaltyFeeAmount);
IERC20(stableERC20).transferFrom(msg.sender, address(this), feeAmount);
IERC20(stableERC20).transferFrom(msg.sender, sales[_saleId].owner, amountAfterFee);
if (royaltyFeeAmount > 0) {
IERC20(stableERC20).transferFrom(msg.sender, royaltiesByToken[sales[_saleId].tokenId].wallet, royaltyFeeAmount);
}
IERC721(sales[_saleId].tokenAddress).transferFrom(sales[_saleId].owner, msg.sender, sales[_saleId].tokenId);
uint256 timeNow = _getTime();
sales[_saleId].buyed = true;
emit SaleBuyed(_saleId, msg.sender, sales[_saleId].price, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev Send all the acumulated fees for one token to the fee destinators.
*/
function withdrawAcumulatedFees() public {
uint256 total = IERC20(stableERC20).balanceOf(address(this));
for (uint8 i = 0; i < feesDestinators.length; i++) {
IERC20(stableERC20).transfer(
feesDestinators[i],
total.mul(feesPercentages[i]).div(100)
);
}
}
/**
* @dev Sets the purchaseFee for every withdraw.
*/
function setFee(uint256 _purchaseFee) public onlyOwner() {
require(_purchaseFee <= 3000, "DigiMarket: Max fee 30%");
purchaseFee = _purchaseFee;
}
/**
* @dev Configure how to distribute the fees for user's withdraws.
*/
function setFeesDestinatorsWithPercentages(
address[] memory _destinators,
uint256[] memory _percentages
)
public
onlyOwner()
{
require(_destinators.length == _percentages.length, "DigiMarket: Destinators and percentageslenght are not equals");
uint256 total = 0;
for (uint8 i = 0; i < _percentages.length; i++) {
total += _percentages[i];
}
require(total == 100, "DigiMarket: Percentages sum must be 100");
feesDestinators = _destinators;
feesPercentages = _percentages;
}
/******************
PRIVATE FUNCTIONS
*******************/
function _getTime() internal view returns (uint256) {
return block.timestamp;
}
/******************
MODIFIERS
*******************/
modifier requiredAmount(address _wallet, uint256 _amount) {
require(
IERC20(stakeERC20).balanceOf(_wallet) >= _amount,
'DigiMarket: User needs more token balance in order to do this action'
);
_;
}
modifier inProgress(uint256 _saleId) {
require(
(sales[_saleId].endDate > _getTime()) && sales[_saleId].buyed == false,
'DigiMarket: Sale ended'
);
_;
}
} | setFee | function setFee(uint256 _purchaseFee) public onlyOwner() {
require(_purchaseFee <= 3000, "DigiMarket: Max fee 30%");
purchaseFee = _purchaseFee;
}
| /**
* @dev Sets the purchaseFee for every withdraw.
*/ | NatSpecMultiLine | v0.6.5+commit.f956cc89 | None | ipfs://3b709d2dc8ce1599dbd3b3db10b7756a837d712c09c447638fc90ad5d43b07fd | {
"func_code_index": [
6514,
6688
]
} | 2,423 |
||
DigiMarket | contracts/DigiMarket.sol | 0x75c45905e903a66c8a109baf3cf13a49b5f67778 | Solidity | DigiMarket | contract DigiMarket is Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeMath for uint8;
uint256 BIGNUMBER = 10 ** 18;
/******************
CONFIG
******************/
uint256 public purchaseFee = 1000; // 10%
uint256 public digiAmountRequired = 3000 * (BIGNUMBER);
/******************
EVENTS
******************/
event CreatedSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event CanceledSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event SaleBuyed(uint256 saleId, address indexed wallet, uint256 amount, uint256 indexed tokenId, address indexed tokenAddress, uint256 created);
/******************
INTERNAL ACCOUNTING
*******************/
address public stakeERC20;
address public digiERC721;
address public stableERC20;
address[] public feesDestinators;
uint256[] public feesPercentages;
uint256 public salesCount = 0;
mapping (uint256 => Sale) public sales;
mapping (address => mapping (uint256 => uint256)) public lastSaleByToken;
mapping (uint256 => Royalty) public royaltiesByToken;
struct Royalty {
uint256 fee;
address wallet;
}
struct Sale {
uint256 tokenId;
address tokenAddress;
address owner;
uint256 price;
bool royalty;
bool buyed;
uint256 endDate;
}
/******************
PUBLIC FUNCTIONS
*******************/
constructor(
address _stakeERC20,
address _stableERC20,
address _digiERC721
)
public
{
require(address(_stakeERC20) != address(0));
require(address(_stableERC20) != address(0));
require(address(_digiERC721) != address(0));
stakeERC20 = _stakeERC20;
stableERC20 = _stableERC20;
digiERC721 = _digiERC721;
}
function setRoyaltyForToken(uint256 _tokenId, address beneficiary, uint256 _fee) external {
require(msg.sender == IERC721(digiERC721).ownerOf(_tokenId), "DigiMarket: Not the owner");
require(AccessControl(digiERC721).hasRole(keccak256("MINTER"), msg.sender), "DigiMarker: Not minter");
require(lastSaleByToken[digiERC721][_tokenId] == 0, "DigiMarket: Auction already created");
require(royaltiesByToken[_tokenId].wallet == address(0), "DigiMarket: Royalty already setted");
royaltiesByToken[_tokenId] = Royalty({
wallet: beneficiary,
fee: _fee
});
}
/**
* @dev User creates sale for NFT.
*/
function createSale(
uint256 _tokenId,
address _tokenAddress,
uint256 _price,
uint256 _duration
)
public
requiredAmount(msg.sender, digiAmountRequired)
returns (uint256)
{
require(IERC721(_tokenAddress).ownerOf(_tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
require(IERC721(_tokenAddress).isApprovedForAll(msg.sender, address(this)), 'DigiMarket: DigiMarket contract address must be approved for transfer');
uint256 timeNow = _getTime();
uint256 newSaleId = salesCount;
salesCount += 1;
sales[newSaleId] = Sale({
tokenId: _tokenId,
tokenAddress: _tokenAddress,
owner: msg.sender,
price: _price,
royalty: _tokenAddress == digiERC721 && royaltiesByToken[_tokenId].wallet != address(0),
buyed: false,
endDate: timeNow + _duration
});
lastSaleByToken[_tokenAddress][_tokenId] = newSaleId;
emit CreatedSale(newSaleId, msg.sender, _tokenId, _tokenAddress, timeNow);
return newSaleId;
}
/**
* @dev User cancels sale for NFT.
*/
function cancelSale(
uint256 _saleId
)
public
inProgress(_saleId)
returns (uint256)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
uint256 timeNow = _getTime();
sales[_saleId].endDate = timeNow;
emit CanceledSale(_saleId, msg.sender, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev User buyes the NFT.
*/
function buy(uint256 _saleId)
public
inProgress(_saleId)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == sales[_saleId].owner, 'DigiMarket: Sale creator user is not longer NFT owner');
require(IERC20(stableERC20).balanceOf(msg.sender) >= sales[_saleId].price, 'DigiMarket: User does not have enough balance');
uint amount = sales[_saleId].price;
uint256 feeAmount = amount.mul(purchaseFee).div(10000);
uint256 royaltyFeeAmount = 0;
if (sales[_saleId].royalty) {
royaltyFeeAmount = amount.mul(royaltiesByToken[sales[_saleId].tokenId].fee).div(10000);
}
uint256 amountAfterFee = amount.sub(feeAmount).sub(royaltyFeeAmount);
IERC20(stableERC20).transferFrom(msg.sender, address(this), feeAmount);
IERC20(stableERC20).transferFrom(msg.sender, sales[_saleId].owner, amountAfterFee);
if (royaltyFeeAmount > 0) {
IERC20(stableERC20).transferFrom(msg.sender, royaltiesByToken[sales[_saleId].tokenId].wallet, royaltyFeeAmount);
}
IERC721(sales[_saleId].tokenAddress).transferFrom(sales[_saleId].owner, msg.sender, sales[_saleId].tokenId);
uint256 timeNow = _getTime();
sales[_saleId].buyed = true;
emit SaleBuyed(_saleId, msg.sender, sales[_saleId].price, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev Send all the acumulated fees for one token to the fee destinators.
*/
function withdrawAcumulatedFees() public {
uint256 total = IERC20(stableERC20).balanceOf(address(this));
for (uint8 i = 0; i < feesDestinators.length; i++) {
IERC20(stableERC20).transfer(
feesDestinators[i],
total.mul(feesPercentages[i]).div(100)
);
}
}
/**
* @dev Sets the purchaseFee for every withdraw.
*/
function setFee(uint256 _purchaseFee) public onlyOwner() {
require(_purchaseFee <= 3000, "DigiMarket: Max fee 30%");
purchaseFee = _purchaseFee;
}
/**
* @dev Configure how to distribute the fees for user's withdraws.
*/
function setFeesDestinatorsWithPercentages(
address[] memory _destinators,
uint256[] memory _percentages
)
public
onlyOwner()
{
require(_destinators.length == _percentages.length, "DigiMarket: Destinators and percentageslenght are not equals");
uint256 total = 0;
for (uint8 i = 0; i < _percentages.length; i++) {
total += _percentages[i];
}
require(total == 100, "DigiMarket: Percentages sum must be 100");
feesDestinators = _destinators;
feesPercentages = _percentages;
}
/******************
PRIVATE FUNCTIONS
*******************/
function _getTime() internal view returns (uint256) {
return block.timestamp;
}
/******************
MODIFIERS
*******************/
modifier requiredAmount(address _wallet, uint256 _amount) {
require(
IERC20(stakeERC20).balanceOf(_wallet) >= _amount,
'DigiMarket: User needs more token balance in order to do this action'
);
_;
}
modifier inProgress(uint256 _saleId) {
require(
(sales[_saleId].endDate > _getTime()) && sales[_saleId].buyed == false,
'DigiMarket: Sale ended'
);
_;
}
} | setFeesDestinatorsWithPercentages | function setFeesDestinatorsWithPercentages(
address[] memory _destinators,
uint256[] memory _percentages
)
public
onlyOwner()
{
require(_destinators.length == _percentages.length, "DigiMarket: Destinators and percentageslenght are not equals");
uint256 total = 0;
for (uint8 i = 0; i < _percentages.length; i++) {
total += _percentages[i];
}
require(total == 100, "DigiMarket: Percentages sum must be 100");
feesDestinators = _destinators;
feesPercentages = _percentages;
}
| /**
* @dev Configure how to distribute the fees for user's withdraws.
*/ | NatSpecMultiLine | v0.6.5+commit.f956cc89 | None | ipfs://3b709d2dc8ce1599dbd3b3db10b7756a837d712c09c447638fc90ad5d43b07fd | {
"func_code_index": [
6779,
7388
]
} | 2,424 |
||
DigiMarket | contracts/DigiMarket.sol | 0x75c45905e903a66c8a109baf3cf13a49b5f67778 | Solidity | DigiMarket | contract DigiMarket is Ownable, ReentrancyGuard {
using SafeMath for uint256;
using SafeMath for uint8;
uint256 BIGNUMBER = 10 ** 18;
/******************
CONFIG
******************/
uint256 public purchaseFee = 1000; // 10%
uint256 public digiAmountRequired = 3000 * (BIGNUMBER);
/******************
EVENTS
******************/
event CreatedSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event CanceledSale(uint256 saleId, address indexed wallet, uint256 tokenId, address tokenAddress, uint256 created);
event SaleBuyed(uint256 saleId, address indexed wallet, uint256 amount, uint256 indexed tokenId, address indexed tokenAddress, uint256 created);
/******************
INTERNAL ACCOUNTING
*******************/
address public stakeERC20;
address public digiERC721;
address public stableERC20;
address[] public feesDestinators;
uint256[] public feesPercentages;
uint256 public salesCount = 0;
mapping (uint256 => Sale) public sales;
mapping (address => mapping (uint256 => uint256)) public lastSaleByToken;
mapping (uint256 => Royalty) public royaltiesByToken;
struct Royalty {
uint256 fee;
address wallet;
}
struct Sale {
uint256 tokenId;
address tokenAddress;
address owner;
uint256 price;
bool royalty;
bool buyed;
uint256 endDate;
}
/******************
PUBLIC FUNCTIONS
*******************/
constructor(
address _stakeERC20,
address _stableERC20,
address _digiERC721
)
public
{
require(address(_stakeERC20) != address(0));
require(address(_stableERC20) != address(0));
require(address(_digiERC721) != address(0));
stakeERC20 = _stakeERC20;
stableERC20 = _stableERC20;
digiERC721 = _digiERC721;
}
function setRoyaltyForToken(uint256 _tokenId, address beneficiary, uint256 _fee) external {
require(msg.sender == IERC721(digiERC721).ownerOf(_tokenId), "DigiMarket: Not the owner");
require(AccessControl(digiERC721).hasRole(keccak256("MINTER"), msg.sender), "DigiMarker: Not minter");
require(lastSaleByToken[digiERC721][_tokenId] == 0, "DigiMarket: Auction already created");
require(royaltiesByToken[_tokenId].wallet == address(0), "DigiMarket: Royalty already setted");
royaltiesByToken[_tokenId] = Royalty({
wallet: beneficiary,
fee: _fee
});
}
/**
* @dev User creates sale for NFT.
*/
function createSale(
uint256 _tokenId,
address _tokenAddress,
uint256 _price,
uint256 _duration
)
public
requiredAmount(msg.sender, digiAmountRequired)
returns (uint256)
{
require(IERC721(_tokenAddress).ownerOf(_tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
require(IERC721(_tokenAddress).isApprovedForAll(msg.sender, address(this)), 'DigiMarket: DigiMarket contract address must be approved for transfer');
uint256 timeNow = _getTime();
uint256 newSaleId = salesCount;
salesCount += 1;
sales[newSaleId] = Sale({
tokenId: _tokenId,
tokenAddress: _tokenAddress,
owner: msg.sender,
price: _price,
royalty: _tokenAddress == digiERC721 && royaltiesByToken[_tokenId].wallet != address(0),
buyed: false,
endDate: timeNow + _duration
});
lastSaleByToken[_tokenAddress][_tokenId] = newSaleId;
emit CreatedSale(newSaleId, msg.sender, _tokenId, _tokenAddress, timeNow);
return newSaleId;
}
/**
* @dev User cancels sale for NFT.
*/
function cancelSale(
uint256 _saleId
)
public
inProgress(_saleId)
returns (uint256)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == msg.sender, 'DigiMarket: User is not the token owner');
uint256 timeNow = _getTime();
sales[_saleId].endDate = timeNow;
emit CanceledSale(_saleId, msg.sender, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev User buyes the NFT.
*/
function buy(uint256 _saleId)
public
inProgress(_saleId)
{
require(IERC721(sales[_saleId].tokenAddress).ownerOf(sales[_saleId].tokenId) == sales[_saleId].owner, 'DigiMarket: Sale creator user is not longer NFT owner');
require(IERC20(stableERC20).balanceOf(msg.sender) >= sales[_saleId].price, 'DigiMarket: User does not have enough balance');
uint amount = sales[_saleId].price;
uint256 feeAmount = amount.mul(purchaseFee).div(10000);
uint256 royaltyFeeAmount = 0;
if (sales[_saleId].royalty) {
royaltyFeeAmount = amount.mul(royaltiesByToken[sales[_saleId].tokenId].fee).div(10000);
}
uint256 amountAfterFee = amount.sub(feeAmount).sub(royaltyFeeAmount);
IERC20(stableERC20).transferFrom(msg.sender, address(this), feeAmount);
IERC20(stableERC20).transferFrom(msg.sender, sales[_saleId].owner, amountAfterFee);
if (royaltyFeeAmount > 0) {
IERC20(stableERC20).transferFrom(msg.sender, royaltiesByToken[sales[_saleId].tokenId].wallet, royaltyFeeAmount);
}
IERC721(sales[_saleId].tokenAddress).transferFrom(sales[_saleId].owner, msg.sender, sales[_saleId].tokenId);
uint256 timeNow = _getTime();
sales[_saleId].buyed = true;
emit SaleBuyed(_saleId, msg.sender, sales[_saleId].price, sales[_saleId].tokenId, sales[_saleId].tokenAddress, timeNow);
}
/**
* @dev Send all the acumulated fees for one token to the fee destinators.
*/
function withdrawAcumulatedFees() public {
uint256 total = IERC20(stableERC20).balanceOf(address(this));
for (uint8 i = 0; i < feesDestinators.length; i++) {
IERC20(stableERC20).transfer(
feesDestinators[i],
total.mul(feesPercentages[i]).div(100)
);
}
}
/**
* @dev Sets the purchaseFee for every withdraw.
*/
function setFee(uint256 _purchaseFee) public onlyOwner() {
require(_purchaseFee <= 3000, "DigiMarket: Max fee 30%");
purchaseFee = _purchaseFee;
}
/**
* @dev Configure how to distribute the fees for user's withdraws.
*/
function setFeesDestinatorsWithPercentages(
address[] memory _destinators,
uint256[] memory _percentages
)
public
onlyOwner()
{
require(_destinators.length == _percentages.length, "DigiMarket: Destinators and percentageslenght are not equals");
uint256 total = 0;
for (uint8 i = 0; i < _percentages.length; i++) {
total += _percentages[i];
}
require(total == 100, "DigiMarket: Percentages sum must be 100");
feesDestinators = _destinators;
feesPercentages = _percentages;
}
/******************
PRIVATE FUNCTIONS
*******************/
function _getTime() internal view returns (uint256) {
return block.timestamp;
}
/******************
MODIFIERS
*******************/
modifier requiredAmount(address _wallet, uint256 _amount) {
require(
IERC20(stakeERC20).balanceOf(_wallet) >= _amount,
'DigiMarket: User needs more token balance in order to do this action'
);
_;
}
modifier inProgress(uint256 _saleId) {
require(
(sales[_saleId].endDate > _getTime()) && sales[_saleId].buyed == false,
'DigiMarket: Sale ended'
);
_;
}
} | _getTime | function _getTime() internal view returns (uint256) {
return block.timestamp;
}
| /******************
PRIVATE FUNCTIONS
*******************/ | NatSpecMultiLine | v0.6.5+commit.f956cc89 | None | ipfs://3b709d2dc8ce1599dbd3b3db10b7756a837d712c09c447638fc90ad5d43b07fd | {
"func_code_index": [
7465,
7563
]
} | 2,425 |
||
ReserveManager | contracts/saga/interfaces/IReserveManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | IReserveManager | interface IReserveManager {
/**
* @dev Get a deposit-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to deposit ETH into the token-contract.
* @return The amount that should be deposited in order for the balance to reach `mid` ETH.
*/
function getDepositParams(uint256 _balance) external view returns (address, uint256);
/**
* @dev Get a withdraw-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to withdraw ETH into the token-contract.
* @return The amount that should be withdrawn in order for the balance to reach `mid` ETH.
*/
function getWithdrawParams(uint256 _balance) external view returns (address, uint256);
} | /**
* @title Reserve Manager Interface.
*/ | NatSpecMultiLine | getDepositParams | function getDepositParams(uint256 _balance) external view returns (address, uint256);
| /**
* @dev Get a deposit-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to deposit ETH into the token-contract.
* @return The amount that should be deposited in order for the balance to reach `mid` ETH.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
331,
420
]
} | 2,426 |
ReserveManager | contracts/saga/interfaces/IReserveManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | IReserveManager | interface IReserveManager {
/**
* @dev Get a deposit-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to deposit ETH into the token-contract.
* @return The amount that should be deposited in order for the balance to reach `mid` ETH.
*/
function getDepositParams(uint256 _balance) external view returns (address, uint256);
/**
* @dev Get a withdraw-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to withdraw ETH into the token-contract.
* @return The amount that should be withdrawn in order for the balance to reach `mid` ETH.
*/
function getWithdrawParams(uint256 _balance) external view returns (address, uint256);
} | /**
* @title Reserve Manager Interface.
*/ | NatSpecMultiLine | getWithdrawParams | function getWithdrawParams(uint256 _balance) external view returns (address, uint256);
| /**
* @dev Get a withdraw-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to withdraw ETH into the token-contract.
* @return The amount that should be withdrawn in order for the balance to reach `mid` ETH.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
727,
817
]
} | 2,427 |
ReserveManager | contracts/saga/interfaces/IPaymentManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | IPaymentManager | interface IPaymentManager {
/**
* @dev Retrieve the current number of outstanding payments.
* @return The current number of outstanding payments.
*/
function getNumOfPayments() external view returns (uint256);
/**
* @dev Retrieve the sum of all outstanding payments.
* @return The sum of all outstanding payments.
*/
function getPaymentsSum() external view returns (uint256);
/**
* @dev Compute differ payment.
* @param _ethAmount The amount of ETH entitled by the client.
* @param _ethBalance The amount of ETH retained by the payment handler.
* @return The amount of differed ETH payment.
*/
function computeDifferPayment(uint256 _ethAmount, uint256 _ethBalance) external view returns (uint256);
/**
* @dev Register a differed payment.
* @param _wallet The payment wallet address.
* @param _ethAmount The payment amount in ETH.
*/
function registerDifferPayment(address _wallet, uint256 _ethAmount) external;
} | /**
* @title Payment Manager Interface.
*/ | NatSpecMultiLine | getNumOfPayments | function getNumOfPayments() external view returns (uint256);
| /**
* @dev Retrieve the current number of outstanding payments.
* @return The current number of outstanding payments.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
168,
232
]
} | 2,428 |
ReserveManager | contracts/saga/interfaces/IPaymentManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | IPaymentManager | interface IPaymentManager {
/**
* @dev Retrieve the current number of outstanding payments.
* @return The current number of outstanding payments.
*/
function getNumOfPayments() external view returns (uint256);
/**
* @dev Retrieve the sum of all outstanding payments.
* @return The sum of all outstanding payments.
*/
function getPaymentsSum() external view returns (uint256);
/**
* @dev Compute differ payment.
* @param _ethAmount The amount of ETH entitled by the client.
* @param _ethBalance The amount of ETH retained by the payment handler.
* @return The amount of differed ETH payment.
*/
function computeDifferPayment(uint256 _ethAmount, uint256 _ethBalance) external view returns (uint256);
/**
* @dev Register a differed payment.
* @param _wallet The payment wallet address.
* @param _ethAmount The payment amount in ETH.
*/
function registerDifferPayment(address _wallet, uint256 _ethAmount) external;
} | /**
* @title Payment Manager Interface.
*/ | NatSpecMultiLine | getPaymentsSum | function getPaymentsSum() external view returns (uint256);
| /**
* @dev Retrieve the sum of all outstanding payments.
* @return The sum of all outstanding payments.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
360,
422
]
} | 2,429 |
ReserveManager | contracts/saga/interfaces/IPaymentManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | IPaymentManager | interface IPaymentManager {
/**
* @dev Retrieve the current number of outstanding payments.
* @return The current number of outstanding payments.
*/
function getNumOfPayments() external view returns (uint256);
/**
* @dev Retrieve the sum of all outstanding payments.
* @return The sum of all outstanding payments.
*/
function getPaymentsSum() external view returns (uint256);
/**
* @dev Compute differ payment.
* @param _ethAmount The amount of ETH entitled by the client.
* @param _ethBalance The amount of ETH retained by the payment handler.
* @return The amount of differed ETH payment.
*/
function computeDifferPayment(uint256 _ethAmount, uint256 _ethBalance) external view returns (uint256);
/**
* @dev Register a differed payment.
* @param _wallet The payment wallet address.
* @param _ethAmount The payment amount in ETH.
*/
function registerDifferPayment(address _wallet, uint256 _ethAmount) external;
} | /**
* @title Payment Manager Interface.
*/ | NatSpecMultiLine | computeDifferPayment | function computeDifferPayment(uint256 _ethAmount, uint256 _ethBalance) external view returns (uint256);
| /**
* @dev Compute differ payment.
* @param _ethAmount The amount of ETH entitled by the client.
* @param _ethBalance The amount of ETH retained by the payment handler.
* @return The amount of differed ETH payment.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
671,
778
]
} | 2,430 |
ReserveManager | contracts/saga/interfaces/IPaymentManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | IPaymentManager | interface IPaymentManager {
/**
* @dev Retrieve the current number of outstanding payments.
* @return The current number of outstanding payments.
*/
function getNumOfPayments() external view returns (uint256);
/**
* @dev Retrieve the sum of all outstanding payments.
* @return The sum of all outstanding payments.
*/
function getPaymentsSum() external view returns (uint256);
/**
* @dev Compute differ payment.
* @param _ethAmount The amount of ETH entitled by the client.
* @param _ethBalance The amount of ETH retained by the payment handler.
* @return The amount of differed ETH payment.
*/
function computeDifferPayment(uint256 _ethAmount, uint256 _ethBalance) external view returns (uint256);
/**
* @dev Register a differed payment.
* @param _wallet The payment wallet address.
* @param _ethAmount The payment amount in ETH.
*/
function registerDifferPayment(address _wallet, uint256 _ethAmount) external;
} | /**
* @title Payment Manager Interface.
*/ | NatSpecMultiLine | registerDifferPayment | function registerDifferPayment(address _wallet, uint256 _ethAmount) external;
| /**
* @dev Register a differed payment.
* @param _wallet The payment wallet address.
* @param _ethAmount The payment amount in ETH.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
939,
1020
]
} | 2,431 |
ENSMigrationSubdomainRegistrar | @ensdomains/subdomain-registrar/contracts/AbstractSubdomainRegistrar.sol | 0xe65d8aaf34cb91087d1598e0a15b582f57f217d9 | Solidity | AbstractSubdomainRegistrar | contract AbstractSubdomainRegistrar is RegistrarInterface {
// namehash('eth')
bytes32 constant public TLD_NODE = 0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae;
bool public stopped = false;
address public registrarOwner;
address public migration;
address public registrar;
ENS public ens;
modifier owner_only(bytes32 label) {
require(owner(label) == msg.sender);
_;
}
modifier not_stopped() {
require(!stopped);
_;
}
modifier registrar_owner_only() {
require(msg.sender == registrarOwner);
_;
}
event DomainTransferred(bytes32 indexed label, string name);
constructor(ENS _ens) public {
ens = _ens;
registrar = ens.owner(TLD_NODE);
registrarOwner = msg.sender;
}
function doRegistration(bytes32 node, bytes32 label, address subdomainOwner, Resolver resolver) internal {
// Get the subdomain so we can configure it
ens.setSubnodeOwner(node, label, address(this));
bytes32 subnode = keccak256(abi.encodePacked(node, label));
// Set the subdomain's resolver
ens.setResolver(subnode, address(resolver));
// Set the address record on the resolver
resolver.setAddr(subnode, subdomainOwner);
// Pass ownership of the new subdomain to the registrant
ens.setOwner(subnode, subdomainOwner);
}
function supportsInterface(bytes4 interfaceID) public pure returns (bool) {
return (
(interfaceID == 0x01ffc9a7) // supportsInterface(bytes4)
|| (interfaceID == 0xc1b15f5a) // RegistrarInterface
);
}
function rentDue(bytes32 label, string calldata subdomain) external view returns (uint timestamp) {
return 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
}
/**
* @dev Sets the resolver record for a name in ENS.
* @param name The name to set the resolver for.
* @param resolver The address of the resolver
*/
function setResolver(string memory name, address resolver) public owner_only(keccak256(bytes(name))) {
bytes32 label = keccak256(bytes(name));
bytes32 node = keccak256(abi.encodePacked(TLD_NODE, label));
ens.setResolver(node, resolver);
}
/**
* @dev Configures a domain for sale.
* @param name The name to configure.
* @param price The price in wei to charge for subdomain registrations
* @param referralFeePPM The referral fee to offer, in parts per million
*/
function configureDomain(string memory name, uint price, uint referralFeePPM) public {
configureDomainFor(name, price, referralFeePPM, msg.sender, address(0x0));
}
/**
* @dev Stops the registrar, disabling configuring of new domains.
*/
function stop() public not_stopped registrar_owner_only {
stopped = true;
}
/**
* @dev Sets the address where domains are migrated to.
* @param _migration Address of the new registrar.
*/
function setMigrationAddress(address _migration) public registrar_owner_only {
require(stopped);
migration = _migration;
}
function transferOwnership(address newOwner) public registrar_owner_only {
registrarOwner = newOwner;
}
/**
* @dev Returns information about a subdomain.
* @param label The label hash for the domain.
* @param subdomain The label for the subdomain.
* @return domain The name of the domain, or an empty string if the subdomain
* is unavailable.
* @return price The price to register a subdomain, in wei.
* @return rent The rent to retain a subdomain, in wei per second.
* @return referralFeePPM The referral fee for the dapp, in ppm.
*/
function query(bytes32 label, string calldata subdomain) external view returns (string memory domain, uint price, uint rent, uint referralFeePPM);
function owner(bytes32 label) public view returns (address);
function configureDomainFor(string memory name, uint price, uint referralFeePPM, address payable _owner, address _transfer) public;
} | setResolver | function setResolver(string memory name, address resolver) public owner_only(keccak256(bytes(name))) {
bytes32 label = keccak256(bytes(name));
bytes32 node = keccak256(abi.encodePacked(TLD_NODE, label));
ens.setResolver(node, resolver);
}
| /**
* @dev Sets the resolver record for a name in ENS.
* @param name The name to set the resolver for.
* @param resolver The address of the resolver
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | None | bzzr://8751e27803ad5386d933139faf690ecb1e80c3045ffede7816138b0531f8d76b | {
"func_code_index": [
2120,
2395
]
} | 2,432 |
||
ENSMigrationSubdomainRegistrar | @ensdomains/subdomain-registrar/contracts/AbstractSubdomainRegistrar.sol | 0xe65d8aaf34cb91087d1598e0a15b582f57f217d9 | Solidity | AbstractSubdomainRegistrar | contract AbstractSubdomainRegistrar is RegistrarInterface {
// namehash('eth')
bytes32 constant public TLD_NODE = 0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae;
bool public stopped = false;
address public registrarOwner;
address public migration;
address public registrar;
ENS public ens;
modifier owner_only(bytes32 label) {
require(owner(label) == msg.sender);
_;
}
modifier not_stopped() {
require(!stopped);
_;
}
modifier registrar_owner_only() {
require(msg.sender == registrarOwner);
_;
}
event DomainTransferred(bytes32 indexed label, string name);
constructor(ENS _ens) public {
ens = _ens;
registrar = ens.owner(TLD_NODE);
registrarOwner = msg.sender;
}
function doRegistration(bytes32 node, bytes32 label, address subdomainOwner, Resolver resolver) internal {
// Get the subdomain so we can configure it
ens.setSubnodeOwner(node, label, address(this));
bytes32 subnode = keccak256(abi.encodePacked(node, label));
// Set the subdomain's resolver
ens.setResolver(subnode, address(resolver));
// Set the address record on the resolver
resolver.setAddr(subnode, subdomainOwner);
// Pass ownership of the new subdomain to the registrant
ens.setOwner(subnode, subdomainOwner);
}
function supportsInterface(bytes4 interfaceID) public pure returns (bool) {
return (
(interfaceID == 0x01ffc9a7) // supportsInterface(bytes4)
|| (interfaceID == 0xc1b15f5a) // RegistrarInterface
);
}
function rentDue(bytes32 label, string calldata subdomain) external view returns (uint timestamp) {
return 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
}
/**
* @dev Sets the resolver record for a name in ENS.
* @param name The name to set the resolver for.
* @param resolver The address of the resolver
*/
function setResolver(string memory name, address resolver) public owner_only(keccak256(bytes(name))) {
bytes32 label = keccak256(bytes(name));
bytes32 node = keccak256(abi.encodePacked(TLD_NODE, label));
ens.setResolver(node, resolver);
}
/**
* @dev Configures a domain for sale.
* @param name The name to configure.
* @param price The price in wei to charge for subdomain registrations
* @param referralFeePPM The referral fee to offer, in parts per million
*/
function configureDomain(string memory name, uint price, uint referralFeePPM) public {
configureDomainFor(name, price, referralFeePPM, msg.sender, address(0x0));
}
/**
* @dev Stops the registrar, disabling configuring of new domains.
*/
function stop() public not_stopped registrar_owner_only {
stopped = true;
}
/**
* @dev Sets the address where domains are migrated to.
* @param _migration Address of the new registrar.
*/
function setMigrationAddress(address _migration) public registrar_owner_only {
require(stopped);
migration = _migration;
}
function transferOwnership(address newOwner) public registrar_owner_only {
registrarOwner = newOwner;
}
/**
* @dev Returns information about a subdomain.
* @param label The label hash for the domain.
* @param subdomain The label for the subdomain.
* @return domain The name of the domain, or an empty string if the subdomain
* is unavailable.
* @return price The price to register a subdomain, in wei.
* @return rent The rent to retain a subdomain, in wei per second.
* @return referralFeePPM The referral fee for the dapp, in ppm.
*/
function query(bytes32 label, string calldata subdomain) external view returns (string memory domain, uint price, uint rent, uint referralFeePPM);
function owner(bytes32 label) public view returns (address);
function configureDomainFor(string memory name, uint price, uint referralFeePPM, address payable _owner, address _transfer) public;
} | configureDomain | function configureDomain(string memory name, uint price, uint referralFeePPM) public {
configureDomainFor(name, price, referralFeePPM, msg.sender, address(0x0));
}
| /**
* @dev Configures a domain for sale.
* @param name The name to configure.
* @param price The price in wei to charge for subdomain registrations
* @param referralFeePPM The referral fee to offer, in parts per million
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | None | bzzr://8751e27803ad5386d933139faf690ecb1e80c3045ffede7816138b0531f8d76b | {
"func_code_index": [
2656,
2838
]
} | 2,433 |
||
ENSMigrationSubdomainRegistrar | @ensdomains/subdomain-registrar/contracts/AbstractSubdomainRegistrar.sol | 0xe65d8aaf34cb91087d1598e0a15b582f57f217d9 | Solidity | AbstractSubdomainRegistrar | contract AbstractSubdomainRegistrar is RegistrarInterface {
// namehash('eth')
bytes32 constant public TLD_NODE = 0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae;
bool public stopped = false;
address public registrarOwner;
address public migration;
address public registrar;
ENS public ens;
modifier owner_only(bytes32 label) {
require(owner(label) == msg.sender);
_;
}
modifier not_stopped() {
require(!stopped);
_;
}
modifier registrar_owner_only() {
require(msg.sender == registrarOwner);
_;
}
event DomainTransferred(bytes32 indexed label, string name);
constructor(ENS _ens) public {
ens = _ens;
registrar = ens.owner(TLD_NODE);
registrarOwner = msg.sender;
}
function doRegistration(bytes32 node, bytes32 label, address subdomainOwner, Resolver resolver) internal {
// Get the subdomain so we can configure it
ens.setSubnodeOwner(node, label, address(this));
bytes32 subnode = keccak256(abi.encodePacked(node, label));
// Set the subdomain's resolver
ens.setResolver(subnode, address(resolver));
// Set the address record on the resolver
resolver.setAddr(subnode, subdomainOwner);
// Pass ownership of the new subdomain to the registrant
ens.setOwner(subnode, subdomainOwner);
}
function supportsInterface(bytes4 interfaceID) public pure returns (bool) {
return (
(interfaceID == 0x01ffc9a7) // supportsInterface(bytes4)
|| (interfaceID == 0xc1b15f5a) // RegistrarInterface
);
}
function rentDue(bytes32 label, string calldata subdomain) external view returns (uint timestamp) {
return 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
}
/**
* @dev Sets the resolver record for a name in ENS.
* @param name The name to set the resolver for.
* @param resolver The address of the resolver
*/
function setResolver(string memory name, address resolver) public owner_only(keccak256(bytes(name))) {
bytes32 label = keccak256(bytes(name));
bytes32 node = keccak256(abi.encodePacked(TLD_NODE, label));
ens.setResolver(node, resolver);
}
/**
* @dev Configures a domain for sale.
* @param name The name to configure.
* @param price The price in wei to charge for subdomain registrations
* @param referralFeePPM The referral fee to offer, in parts per million
*/
function configureDomain(string memory name, uint price, uint referralFeePPM) public {
configureDomainFor(name, price, referralFeePPM, msg.sender, address(0x0));
}
/**
* @dev Stops the registrar, disabling configuring of new domains.
*/
function stop() public not_stopped registrar_owner_only {
stopped = true;
}
/**
* @dev Sets the address where domains are migrated to.
* @param _migration Address of the new registrar.
*/
function setMigrationAddress(address _migration) public registrar_owner_only {
require(stopped);
migration = _migration;
}
function transferOwnership(address newOwner) public registrar_owner_only {
registrarOwner = newOwner;
}
/**
* @dev Returns information about a subdomain.
* @param label The label hash for the domain.
* @param subdomain The label for the subdomain.
* @return domain The name of the domain, or an empty string if the subdomain
* is unavailable.
* @return price The price to register a subdomain, in wei.
* @return rent The rent to retain a subdomain, in wei per second.
* @return referralFeePPM The referral fee for the dapp, in ppm.
*/
function query(bytes32 label, string calldata subdomain) external view returns (string memory domain, uint price, uint rent, uint referralFeePPM);
function owner(bytes32 label) public view returns (address);
function configureDomainFor(string memory name, uint price, uint referralFeePPM, address payable _owner, address _transfer) public;
} | stop | function stop() public not_stopped registrar_owner_only {
stopped = true;
}
| /**
* @dev Stops the registrar, disabling configuring of new domains.
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | None | bzzr://8751e27803ad5386d933139faf690ecb1e80c3045ffede7816138b0531f8d76b | {
"func_code_index": [
2931,
3025
]
} | 2,434 |
||
ENSMigrationSubdomainRegistrar | @ensdomains/subdomain-registrar/contracts/AbstractSubdomainRegistrar.sol | 0xe65d8aaf34cb91087d1598e0a15b582f57f217d9 | Solidity | AbstractSubdomainRegistrar | contract AbstractSubdomainRegistrar is RegistrarInterface {
// namehash('eth')
bytes32 constant public TLD_NODE = 0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae;
bool public stopped = false;
address public registrarOwner;
address public migration;
address public registrar;
ENS public ens;
modifier owner_only(bytes32 label) {
require(owner(label) == msg.sender);
_;
}
modifier not_stopped() {
require(!stopped);
_;
}
modifier registrar_owner_only() {
require(msg.sender == registrarOwner);
_;
}
event DomainTransferred(bytes32 indexed label, string name);
constructor(ENS _ens) public {
ens = _ens;
registrar = ens.owner(TLD_NODE);
registrarOwner = msg.sender;
}
function doRegistration(bytes32 node, bytes32 label, address subdomainOwner, Resolver resolver) internal {
// Get the subdomain so we can configure it
ens.setSubnodeOwner(node, label, address(this));
bytes32 subnode = keccak256(abi.encodePacked(node, label));
// Set the subdomain's resolver
ens.setResolver(subnode, address(resolver));
// Set the address record on the resolver
resolver.setAddr(subnode, subdomainOwner);
// Pass ownership of the new subdomain to the registrant
ens.setOwner(subnode, subdomainOwner);
}
function supportsInterface(bytes4 interfaceID) public pure returns (bool) {
return (
(interfaceID == 0x01ffc9a7) // supportsInterface(bytes4)
|| (interfaceID == 0xc1b15f5a) // RegistrarInterface
);
}
function rentDue(bytes32 label, string calldata subdomain) external view returns (uint timestamp) {
return 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
}
/**
* @dev Sets the resolver record for a name in ENS.
* @param name The name to set the resolver for.
* @param resolver The address of the resolver
*/
function setResolver(string memory name, address resolver) public owner_only(keccak256(bytes(name))) {
bytes32 label = keccak256(bytes(name));
bytes32 node = keccak256(abi.encodePacked(TLD_NODE, label));
ens.setResolver(node, resolver);
}
/**
* @dev Configures a domain for sale.
* @param name The name to configure.
* @param price The price in wei to charge for subdomain registrations
* @param referralFeePPM The referral fee to offer, in parts per million
*/
function configureDomain(string memory name, uint price, uint referralFeePPM) public {
configureDomainFor(name, price, referralFeePPM, msg.sender, address(0x0));
}
/**
* @dev Stops the registrar, disabling configuring of new domains.
*/
function stop() public not_stopped registrar_owner_only {
stopped = true;
}
/**
* @dev Sets the address where domains are migrated to.
* @param _migration Address of the new registrar.
*/
function setMigrationAddress(address _migration) public registrar_owner_only {
require(stopped);
migration = _migration;
}
function transferOwnership(address newOwner) public registrar_owner_only {
registrarOwner = newOwner;
}
/**
* @dev Returns information about a subdomain.
* @param label The label hash for the domain.
* @param subdomain The label for the subdomain.
* @return domain The name of the domain, or an empty string if the subdomain
* is unavailable.
* @return price The price to register a subdomain, in wei.
* @return rent The rent to retain a subdomain, in wei per second.
* @return referralFeePPM The referral fee for the dapp, in ppm.
*/
function query(bytes32 label, string calldata subdomain) external view returns (string memory domain, uint price, uint rent, uint referralFeePPM);
function owner(bytes32 label) public view returns (address);
function configureDomainFor(string memory name, uint price, uint referralFeePPM, address payable _owner, address _transfer) public;
} | setMigrationAddress | function setMigrationAddress(address _migration) public registrar_owner_only {
require(stopped);
migration = _migration;
}
| /**
* @dev Sets the address where domains are migrated to.
* @param _migration Address of the new registrar.
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | None | bzzr://8751e27803ad5386d933139faf690ecb1e80c3045ffede7816138b0531f8d76b | {
"func_code_index": [
3163,
3313
]
} | 2,435 |
||
ENSMigrationSubdomainRegistrar | @ensdomains/subdomain-registrar/contracts/AbstractSubdomainRegistrar.sol | 0xe65d8aaf34cb91087d1598e0a15b582f57f217d9 | Solidity | AbstractSubdomainRegistrar | contract AbstractSubdomainRegistrar is RegistrarInterface {
// namehash('eth')
bytes32 constant public TLD_NODE = 0x93cdeb708b7545dc668eb9280176169d1c33cfd8ed6f04690a0bcc88a93fc4ae;
bool public stopped = false;
address public registrarOwner;
address public migration;
address public registrar;
ENS public ens;
modifier owner_only(bytes32 label) {
require(owner(label) == msg.sender);
_;
}
modifier not_stopped() {
require(!stopped);
_;
}
modifier registrar_owner_only() {
require(msg.sender == registrarOwner);
_;
}
event DomainTransferred(bytes32 indexed label, string name);
constructor(ENS _ens) public {
ens = _ens;
registrar = ens.owner(TLD_NODE);
registrarOwner = msg.sender;
}
function doRegistration(bytes32 node, bytes32 label, address subdomainOwner, Resolver resolver) internal {
// Get the subdomain so we can configure it
ens.setSubnodeOwner(node, label, address(this));
bytes32 subnode = keccak256(abi.encodePacked(node, label));
// Set the subdomain's resolver
ens.setResolver(subnode, address(resolver));
// Set the address record on the resolver
resolver.setAddr(subnode, subdomainOwner);
// Pass ownership of the new subdomain to the registrant
ens.setOwner(subnode, subdomainOwner);
}
function supportsInterface(bytes4 interfaceID) public pure returns (bool) {
return (
(interfaceID == 0x01ffc9a7) // supportsInterface(bytes4)
|| (interfaceID == 0xc1b15f5a) // RegistrarInterface
);
}
function rentDue(bytes32 label, string calldata subdomain) external view returns (uint timestamp) {
return 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF;
}
/**
* @dev Sets the resolver record for a name in ENS.
* @param name The name to set the resolver for.
* @param resolver The address of the resolver
*/
function setResolver(string memory name, address resolver) public owner_only(keccak256(bytes(name))) {
bytes32 label = keccak256(bytes(name));
bytes32 node = keccak256(abi.encodePacked(TLD_NODE, label));
ens.setResolver(node, resolver);
}
/**
* @dev Configures a domain for sale.
* @param name The name to configure.
* @param price The price in wei to charge for subdomain registrations
* @param referralFeePPM The referral fee to offer, in parts per million
*/
function configureDomain(string memory name, uint price, uint referralFeePPM) public {
configureDomainFor(name, price, referralFeePPM, msg.sender, address(0x0));
}
/**
* @dev Stops the registrar, disabling configuring of new domains.
*/
function stop() public not_stopped registrar_owner_only {
stopped = true;
}
/**
* @dev Sets the address where domains are migrated to.
* @param _migration Address of the new registrar.
*/
function setMigrationAddress(address _migration) public registrar_owner_only {
require(stopped);
migration = _migration;
}
function transferOwnership(address newOwner) public registrar_owner_only {
registrarOwner = newOwner;
}
/**
* @dev Returns information about a subdomain.
* @param label The label hash for the domain.
* @param subdomain The label for the subdomain.
* @return domain The name of the domain, or an empty string if the subdomain
* is unavailable.
* @return price The price to register a subdomain, in wei.
* @return rent The rent to retain a subdomain, in wei per second.
* @return referralFeePPM The referral fee for the dapp, in ppm.
*/
function query(bytes32 label, string calldata subdomain) external view returns (string memory domain, uint price, uint rent, uint referralFeePPM);
function owner(bytes32 label) public view returns (address);
function configureDomainFor(string memory name, uint price, uint referralFeePPM, address payable _owner, address _transfer) public;
} | query | function query(bytes32 label, string calldata subdomain) external view returns (string memory domain, uint price, uint rent, uint referralFeePPM);
| /**
* @dev Returns information about a subdomain.
* @param label The label hash for the domain.
* @param subdomain The label for the subdomain.
* @return domain The name of the domain, or an empty string if the subdomain
* is unavailable.
* @return price The price to register a subdomain, in wei.
* @return rent The rent to retain a subdomain, in wei per second.
* @return referralFeePPM The referral fee for the dapp, in ppm.
*/ | NatSpecMultiLine | v0.5.16+commit.9c3226ce | None | bzzr://8751e27803ad5386d933139faf690ecb1e80c3045ffede7816138b0531f8d76b | {
"func_code_index": [
3946,
4097
]
} | 2,436 |
||
POTB | POTB.sol | 0xb1c96f736181fc1dc89577f752815f96f6ac92c5 | Solidity | POTB | contract POTB is SafeMath{
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
address public owner = 0x990a10058406E445feE83127d5eB0e2977C43126;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
mapping (address => uint256) public freezeOf;
mapping (address => mapping (address => uint256)) public allowance;
/* This generates a public event on the blockchain that will notify clients */
event Transfer(address indexed from, address indexed to, uint256 value);
/* This notifies clients about the amount burnt */
event Burn(address indexed from, uint256 value);
/* This notifies clients about the amount frozen */
event Freeze(address indexed from, uint256 value);
/* This notifies clients about the amount unfrozen */
event Unfreeze(address indexed from, uint256 value);
/* Initializes contract with initial supply tokens to the creator of the contract */
function POTB(
uint256 initialSupply,
string tokenName,
uint8 decimalUnits,
string tokenSymbol
) {
balanceOf[owner] = initialSupply; // Give the creator all initial tokens
totalSupply = initialSupply; // Update total supply
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
decimals = decimalUnits; // Amount of decimals for display purposes
Transfer(this, owner, initialSupply);
}
/* Send coins */
function transfer(address _to, uint256 _value) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
/* Allow another contract to spend some tokens in your behalf */
function approve(address _spender, uint256 _value)
returns (bool success) {
if (_value <= 0) throw;
allowance[msg.sender][_spender] = _value;
return true;
}
/* A contract attempts to get the coins */
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[_from] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
if (_value > allowance[_from][msg.sender]) throw; // Check allowance
balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
}
function burn(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
totalSupply = SafeMath.safeSub(totalSupply,_value); // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
function freeze(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
freezeOf[msg.sender] = SafeMath.safeAdd(freezeOf[msg.sender], _value); // Updates totalSupply
Freeze(msg.sender, _value);
return true;
}
function unfreeze(uint256 _value) returns (bool success) {
if (freezeOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
freezeOf[msg.sender] = SafeMath.safeSub(freezeOf[msg.sender], _value); // Subtract from the sender
balanceOf[msg.sender] = SafeMath.safeAdd(balanceOf[msg.sender], _value);
Unfreeze(msg.sender, _value);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) {
if(msg.sender != owner)throw;
owner.transfer(amount);
}
// can accept ether
function() payable {
}
} | POTB | function POTB(
uint256 initialSupply,
string tokenName,
uint8 decimalUnits,
string tokenSymbol
) {
balanceOf[owner] = initialSupply; // Give the creator all initial tokens
totalSupply = initialSupply; // Update total supply
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
decimals = decimalUnits; // Amount of decimals for display purposes
Transfer(this, owner, initialSupply);
}
| /* Initializes contract with initial supply tokens to the creator of the contract */ | Comment | v0.4.12+commit.194ff033 | bzzr://180f5f0cfe76cc9618b281bc632d2d29ecd9595f2670d47162d989a351ce711b | {
"func_code_index": [
1034,
1722
]
} | 2,437 |
|||
POTB | POTB.sol | 0xb1c96f736181fc1dc89577f752815f96f6ac92c5 | Solidity | POTB | contract POTB is SafeMath{
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
address public owner = 0x990a10058406E445feE83127d5eB0e2977C43126;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
mapping (address => uint256) public freezeOf;
mapping (address => mapping (address => uint256)) public allowance;
/* This generates a public event on the blockchain that will notify clients */
event Transfer(address indexed from, address indexed to, uint256 value);
/* This notifies clients about the amount burnt */
event Burn(address indexed from, uint256 value);
/* This notifies clients about the amount frozen */
event Freeze(address indexed from, uint256 value);
/* This notifies clients about the amount unfrozen */
event Unfreeze(address indexed from, uint256 value);
/* Initializes contract with initial supply tokens to the creator of the contract */
function POTB(
uint256 initialSupply,
string tokenName,
uint8 decimalUnits,
string tokenSymbol
) {
balanceOf[owner] = initialSupply; // Give the creator all initial tokens
totalSupply = initialSupply; // Update total supply
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
decimals = decimalUnits; // Amount of decimals for display purposes
Transfer(this, owner, initialSupply);
}
/* Send coins */
function transfer(address _to, uint256 _value) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
/* Allow another contract to spend some tokens in your behalf */
function approve(address _spender, uint256 _value)
returns (bool success) {
if (_value <= 0) throw;
allowance[msg.sender][_spender] = _value;
return true;
}
/* A contract attempts to get the coins */
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[_from] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
if (_value > allowance[_from][msg.sender]) throw; // Check allowance
balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
}
function burn(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
totalSupply = SafeMath.safeSub(totalSupply,_value); // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
function freeze(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
freezeOf[msg.sender] = SafeMath.safeAdd(freezeOf[msg.sender], _value); // Updates totalSupply
Freeze(msg.sender, _value);
return true;
}
function unfreeze(uint256 _value) returns (bool success) {
if (freezeOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
freezeOf[msg.sender] = SafeMath.safeSub(freezeOf[msg.sender], _value); // Subtract from the sender
balanceOf[msg.sender] = SafeMath.safeAdd(balanceOf[msg.sender], _value);
Unfreeze(msg.sender, _value);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) {
if(msg.sender != owner)throw;
owner.transfer(amount);
}
// can accept ether
function() payable {
}
} | transfer | function transfer(address _to, uint256 _value) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
(_value <= 0) throw;
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
| /* Send coins */ | Comment | v0.4.12+commit.194ff033 | bzzr://180f5f0cfe76cc9618b281bc632d2d29ecd9595f2670d47162d989a351ce711b | {
"func_code_index": [
1747,
2510
]
} | 2,438 |
|||
POTB | POTB.sol | 0xb1c96f736181fc1dc89577f752815f96f6ac92c5 | Solidity | POTB | contract POTB is SafeMath{
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
address public owner = 0x990a10058406E445feE83127d5eB0e2977C43126;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
mapping (address => uint256) public freezeOf;
mapping (address => mapping (address => uint256)) public allowance;
/* This generates a public event on the blockchain that will notify clients */
event Transfer(address indexed from, address indexed to, uint256 value);
/* This notifies clients about the amount burnt */
event Burn(address indexed from, uint256 value);
/* This notifies clients about the amount frozen */
event Freeze(address indexed from, uint256 value);
/* This notifies clients about the amount unfrozen */
event Unfreeze(address indexed from, uint256 value);
/* Initializes contract with initial supply tokens to the creator of the contract */
function POTB(
uint256 initialSupply,
string tokenName,
uint8 decimalUnits,
string tokenSymbol
) {
balanceOf[owner] = initialSupply; // Give the creator all initial tokens
totalSupply = initialSupply; // Update total supply
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
decimals = decimalUnits; // Amount of decimals for display purposes
Transfer(this, owner, initialSupply);
}
/* Send coins */
function transfer(address _to, uint256 _value) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
/* Allow another contract to spend some tokens in your behalf */
function approve(address _spender, uint256 _value)
returns (bool success) {
if (_value <= 0) throw;
allowance[msg.sender][_spender] = _value;
return true;
}
/* A contract attempts to get the coins */
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[_from] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
if (_value > allowance[_from][msg.sender]) throw; // Check allowance
balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
}
function burn(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
totalSupply = SafeMath.safeSub(totalSupply,_value); // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
function freeze(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
freezeOf[msg.sender] = SafeMath.safeAdd(freezeOf[msg.sender], _value); // Updates totalSupply
Freeze(msg.sender, _value);
return true;
}
function unfreeze(uint256 _value) returns (bool success) {
if (freezeOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
freezeOf[msg.sender] = SafeMath.safeSub(freezeOf[msg.sender], _value); // Subtract from the sender
balanceOf[msg.sender] = SafeMath.safeAdd(balanceOf[msg.sender], _value);
Unfreeze(msg.sender, _value);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) {
if(msg.sender != owner)throw;
owner.transfer(amount);
}
// can accept ether
function() payable {
}
} | approve | function approve(address _spender, uint256 _value)
returns (bool success) {
(_value <= 0) throw;
allowance[msg.sender][_spender] = _value;
return true;
}
| /* Allow another contract to spend some tokens in your behalf */ | Comment | v0.4.12+commit.194ff033 | bzzr://180f5f0cfe76cc9618b281bc632d2d29ecd9595f2670d47162d989a351ce711b | {
"func_code_index": [
2583,
2780
]
} | 2,439 |
|||
POTB | POTB.sol | 0xb1c96f736181fc1dc89577f752815f96f6ac92c5 | Solidity | POTB | contract POTB is SafeMath{
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
address public owner = 0x990a10058406E445feE83127d5eB0e2977C43126;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
mapping (address => uint256) public freezeOf;
mapping (address => mapping (address => uint256)) public allowance;
/* This generates a public event on the blockchain that will notify clients */
event Transfer(address indexed from, address indexed to, uint256 value);
/* This notifies clients about the amount burnt */
event Burn(address indexed from, uint256 value);
/* This notifies clients about the amount frozen */
event Freeze(address indexed from, uint256 value);
/* This notifies clients about the amount unfrozen */
event Unfreeze(address indexed from, uint256 value);
/* Initializes contract with initial supply tokens to the creator of the contract */
function POTB(
uint256 initialSupply,
string tokenName,
uint8 decimalUnits,
string tokenSymbol
) {
balanceOf[owner] = initialSupply; // Give the creator all initial tokens
totalSupply = initialSupply; // Update total supply
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
decimals = decimalUnits; // Amount of decimals for display purposes
Transfer(this, owner, initialSupply);
}
/* Send coins */
function transfer(address _to, uint256 _value) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
/* Allow another contract to spend some tokens in your behalf */
function approve(address _spender, uint256 _value)
returns (bool success) {
if (_value <= 0) throw;
allowance[msg.sender][_spender] = _value;
return true;
}
/* A contract attempts to get the coins */
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[_from] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
if (_value > allowance[_from][msg.sender]) throw; // Check allowance
balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
}
function burn(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
totalSupply = SafeMath.safeSub(totalSupply,_value); // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
function freeze(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
freezeOf[msg.sender] = SafeMath.safeAdd(freezeOf[msg.sender], _value); // Updates totalSupply
Freeze(msg.sender, _value);
return true;
}
function unfreeze(uint256 _value) returns (bool success) {
if (freezeOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
freezeOf[msg.sender] = SafeMath.safeSub(freezeOf[msg.sender], _value); // Subtract from the sender
balanceOf[msg.sender] = SafeMath.safeAdd(balanceOf[msg.sender], _value);
Unfreeze(msg.sender, _value);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) {
if(msg.sender != owner)throw;
owner.transfer(amount);
}
// can accept ether
function() payable {
}
} | transferFrom | function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
(_value <= 0) throw;
if (balanceOf[_from] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
if (_value > allowance[_from][msg.sender]) throw; // Check allowance
balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
}
| /* A contract attempts to get the coins */ | Comment | v0.4.12+commit.194ff033 | bzzr://180f5f0cfe76cc9618b281bc632d2d29ecd9595f2670d47162d989a351ce711b | {
"func_code_index": [
2840,
3765
]
} | 2,440 |
|||
POTB | POTB.sol | 0xb1c96f736181fc1dc89577f752815f96f6ac92c5 | Solidity | POTB | contract POTB is SafeMath{
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
address public owner = 0x990a10058406E445feE83127d5eB0e2977C43126;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
mapping (address => uint256) public freezeOf;
mapping (address => mapping (address => uint256)) public allowance;
/* This generates a public event on the blockchain that will notify clients */
event Transfer(address indexed from, address indexed to, uint256 value);
/* This notifies clients about the amount burnt */
event Burn(address indexed from, uint256 value);
/* This notifies clients about the amount frozen */
event Freeze(address indexed from, uint256 value);
/* This notifies clients about the amount unfrozen */
event Unfreeze(address indexed from, uint256 value);
/* Initializes contract with initial supply tokens to the creator of the contract */
function POTB(
uint256 initialSupply,
string tokenName,
uint8 decimalUnits,
string tokenSymbol
) {
balanceOf[owner] = initialSupply; // Give the creator all initial tokens
totalSupply = initialSupply; // Update total supply
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
decimals = decimalUnits; // Amount of decimals for display purposes
Transfer(this, owner, initialSupply);
}
/* Send coins */
function transfer(address _to, uint256 _value) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
/* Allow another contract to spend some tokens in your behalf */
function approve(address _spender, uint256 _value)
returns (bool success) {
if (_value <= 0) throw;
allowance[msg.sender][_spender] = _value;
return true;
}
/* A contract attempts to get the coins */
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[_from] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
if (_value > allowance[_from][msg.sender]) throw; // Check allowance
balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
}
function burn(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
totalSupply = SafeMath.safeSub(totalSupply,_value); // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
function freeze(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
freezeOf[msg.sender] = SafeMath.safeAdd(freezeOf[msg.sender], _value); // Updates totalSupply
Freeze(msg.sender, _value);
return true;
}
function unfreeze(uint256 _value) returns (bool success) {
if (freezeOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
freezeOf[msg.sender] = SafeMath.safeSub(freezeOf[msg.sender], _value); // Subtract from the sender
balanceOf[msg.sender] = SafeMath.safeAdd(balanceOf[msg.sender], _value);
Unfreeze(msg.sender, _value);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) {
if(msg.sender != owner)throw;
owner.transfer(amount);
}
// can accept ether
function() payable {
}
} | withdrawEther | function withdrawEther(uint256 amount) {
if(msg.sender != owner)throw;
owner.transfer(amount);
}
| // transfer balance to owner | LineComment | v0.4.12+commit.194ff033 | bzzr://180f5f0cfe76cc9618b281bc632d2d29ecd9595f2670d47162d989a351ce711b | {
"func_code_index": [
5276,
5382
]
} | 2,441 |
|||
POTB | POTB.sol | 0xb1c96f736181fc1dc89577f752815f96f6ac92c5 | Solidity | POTB | contract POTB is SafeMath{
string public name;
string public symbol;
uint8 public decimals;
uint256 public totalSupply;
address public owner = 0x990a10058406E445feE83127d5eB0e2977C43126;
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
mapping (address => uint256) public freezeOf;
mapping (address => mapping (address => uint256)) public allowance;
/* This generates a public event on the blockchain that will notify clients */
event Transfer(address indexed from, address indexed to, uint256 value);
/* This notifies clients about the amount burnt */
event Burn(address indexed from, uint256 value);
/* This notifies clients about the amount frozen */
event Freeze(address indexed from, uint256 value);
/* This notifies clients about the amount unfrozen */
event Unfreeze(address indexed from, uint256 value);
/* Initializes contract with initial supply tokens to the creator of the contract */
function POTB(
uint256 initialSupply,
string tokenName,
uint8 decimalUnits,
string tokenSymbol
) {
balanceOf[owner] = initialSupply; // Give the creator all initial tokens
totalSupply = initialSupply; // Update total supply
name = tokenName; // Set the name for display purposes
symbol = tokenSymbol; // Set the symbol for display purposes
decimals = decimalUnits; // Amount of decimals for display purposes
Transfer(this, owner, initialSupply);
}
/* Send coins */
function transfer(address _to, uint256 _value) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
Transfer(msg.sender, _to, _value); // Notify anyone listening that this transfer took place
}
/* Allow another contract to spend some tokens in your behalf */
function approve(address _spender, uint256 _value)
returns (bool success) {
if (_value <= 0) throw;
allowance[msg.sender][_spender] = _value;
return true;
}
/* A contract attempts to get the coins */
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {
if (_to == 0x0) throw; // Prevent transfer to 0x0 address. Use burn() instead
if (_value <= 0) throw;
if (balanceOf[_from] < _value) throw; // Check if the sender has enough
if (balanceOf[_to] + _value < balanceOf[_to]) throw; // Check for overflows
if (_value > allowance[_from][msg.sender]) throw; // Check allowance
balanceOf[_from] = SafeMath.safeSub(balanceOf[_from], _value); // Subtract from the sender
balanceOf[_to] = SafeMath.safeAdd(balanceOf[_to], _value); // Add the same to the recipient
allowance[_from][msg.sender] = SafeMath.safeSub(allowance[_from][msg.sender], _value);
Transfer(_from, _to, _value);
return true;
}
function burn(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
totalSupply = SafeMath.safeSub(totalSupply,_value); // Updates totalSupply
Burn(msg.sender, _value);
return true;
}
function freeze(uint256 _value) returns (bool success) {
if (balanceOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
balanceOf[msg.sender] = SafeMath.safeSub(balanceOf[msg.sender], _value); // Subtract from the sender
freezeOf[msg.sender] = SafeMath.safeAdd(freezeOf[msg.sender], _value); // Updates totalSupply
Freeze(msg.sender, _value);
return true;
}
function unfreeze(uint256 _value) returns (bool success) {
if (freezeOf[msg.sender] < _value) throw; // Check if the sender has enough
if (_value <= 0) throw;
freezeOf[msg.sender] = SafeMath.safeSub(freezeOf[msg.sender], _value); // Subtract from the sender
balanceOf[msg.sender] = SafeMath.safeAdd(balanceOf[msg.sender], _value);
Unfreeze(msg.sender, _value);
return true;
}
// transfer balance to owner
function withdrawEther(uint256 amount) {
if(msg.sender != owner)throw;
owner.transfer(amount);
}
// can accept ether
function() payable {
}
} | function() payable {
}
| // can accept ether | LineComment | v0.4.12+commit.194ff033 | bzzr://180f5f0cfe76cc9618b281bc632d2d29ecd9595f2670d47162d989a351ce711b | {
"func_code_index": [
5408,
5437
]
} | 2,442 |
||||
ReserveManager | contracts/contract_address_locator/ContractAddressLocatorHolder.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | ContractAddressLocatorHolder | contract ContractAddressLocatorHolder {
bytes32 internal constant _IAuthorizationDataSource_ = "IAuthorizationDataSource";
bytes32 internal constant _ISGNConversionManager_ = "ISGNConversionManager" ;
bytes32 internal constant _IModelDataSource_ = "IModelDataSource" ;
bytes32 internal constant _IPaymentHandler_ = "IPaymentHandler" ;
bytes32 internal constant _IPaymentManager_ = "IPaymentManager" ;
bytes32 internal constant _IPaymentQueue_ = "IPaymentQueue" ;
bytes32 internal constant _IReconciliationAdjuster_ = "IReconciliationAdjuster" ;
bytes32 internal constant _IIntervalIterator_ = "IIntervalIterator" ;
bytes32 internal constant _IMintHandler_ = "IMintHandler" ;
bytes32 internal constant _IMintListener_ = "IMintListener" ;
bytes32 internal constant _IMintManager_ = "IMintManager" ;
bytes32 internal constant _IPriceBandCalculator_ = "IPriceBandCalculator" ;
bytes32 internal constant _IModelCalculator_ = "IModelCalculator" ;
bytes32 internal constant _IRedButton_ = "IRedButton" ;
bytes32 internal constant _IReserveManager_ = "IReserveManager" ;
bytes32 internal constant _ISagaExchanger_ = "ISagaExchanger" ;
bytes32 internal constant _IMonetaryModel_ = "IMonetaryModel" ;
bytes32 internal constant _IMonetaryModelState_ = "IMonetaryModelState" ;
bytes32 internal constant _ISGAAuthorizationManager_ = "ISGAAuthorizationManager";
bytes32 internal constant _ISGAToken_ = "ISGAToken" ;
bytes32 internal constant _ISGATokenManager_ = "ISGATokenManager" ;
bytes32 internal constant _ISGNAuthorizationManager_ = "ISGNAuthorizationManager";
bytes32 internal constant _ISGNToken_ = "ISGNToken" ;
bytes32 internal constant _ISGNTokenManager_ = "ISGNTokenManager" ;
bytes32 internal constant _IMintingPointTimersManager_ = "IMintingPointTimersManager" ;
bytes32 internal constant _ITradingClasses_ = "ITradingClasses" ;
bytes32 internal constant _IWalletsTradingLimiterValueConverter_ = "IWalletsTLValueConverter" ;
bytes32 internal constant _IWalletsTradingDataSource_ = "IWalletsTradingDataSource" ;
bytes32 internal constant _WalletsTradingLimiter_SGNTokenManager_ = "WalletsTLSGNTokenManager" ;
bytes32 internal constant _WalletsTradingLimiter_SGATokenManager_ = "WalletsTLSGATokenManager" ;
bytes32 internal constant _IETHConverter_ = "IETHConverter" ;
bytes32 internal constant _ITransactionLimiter_ = "ITransactionLimiter" ;
bytes32 internal constant _ITransactionManager_ = "ITransactionManager" ;
bytes32 internal constant _IRateApprover_ = "IRateApprover" ;
IContractAddressLocator private contractAddressLocator;
/**
* @dev Create the contract.
* @param _contractAddressLocator The contract address locator.
*/
constructor(IContractAddressLocator _contractAddressLocator) internal {
require(_contractAddressLocator != address(0), "locator is illegal");
contractAddressLocator = _contractAddressLocator;
}
/**
* @dev Get the contract address locator.
* @return The contract address locator.
*/
function getContractAddressLocator() external view returns (IContractAddressLocator) {
return contractAddressLocator;
}
/**
* @dev Get the contract address mapped to a given identifier.
* @param _identifier The identifier.
* @return The contract address.
*/
function getContractAddress(bytes32 _identifier) internal view returns (address) {
return contractAddressLocator.getContractAddress(_identifier);
}
/**
* @dev Determine whether or not the sender relates to one of the identifiers.
* @param _identifiers The identifiers.
* @return A boolean indicating if the sender relates to one of the identifiers.
*/
function isSenderAddressRelates(bytes32[] _identifiers) internal view returns (bool) {
return contractAddressLocator.isContractAddressRelates(msg.sender, _identifiers);
}
/**
* @dev Verify that the caller is mapped to a given identifier.
* @param _identifier The identifier.
*/
modifier only(bytes32 _identifier) {
require(msg.sender == getContractAddress(_identifier), "caller is illegal");
_;
}
} | /**
* @title Contract Address Locator Holder.
* @dev Hold a contract address locator, which maps a unique identifier to every contract address in the system.
* @dev Any contract which inherits from this contract can retrieve the address of any contract in the system.
* @dev Thus, any contract can remain "oblivious" to the replacement of any other contract in the system.
* @dev In addition to that, any function in any contract can be restricted to a specific caller.
*/ | NatSpecMultiLine | getContractAddressLocator | function getContractAddressLocator() external view returns (IContractAddressLocator) {
return contractAddressLocator;
}
| /**
* @dev Get the contract address locator.
* @return The contract address locator.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
3650,
3785
]
} | 2,443 |
ReserveManager | contracts/contract_address_locator/ContractAddressLocatorHolder.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | ContractAddressLocatorHolder | contract ContractAddressLocatorHolder {
bytes32 internal constant _IAuthorizationDataSource_ = "IAuthorizationDataSource";
bytes32 internal constant _ISGNConversionManager_ = "ISGNConversionManager" ;
bytes32 internal constant _IModelDataSource_ = "IModelDataSource" ;
bytes32 internal constant _IPaymentHandler_ = "IPaymentHandler" ;
bytes32 internal constant _IPaymentManager_ = "IPaymentManager" ;
bytes32 internal constant _IPaymentQueue_ = "IPaymentQueue" ;
bytes32 internal constant _IReconciliationAdjuster_ = "IReconciliationAdjuster" ;
bytes32 internal constant _IIntervalIterator_ = "IIntervalIterator" ;
bytes32 internal constant _IMintHandler_ = "IMintHandler" ;
bytes32 internal constant _IMintListener_ = "IMintListener" ;
bytes32 internal constant _IMintManager_ = "IMintManager" ;
bytes32 internal constant _IPriceBandCalculator_ = "IPriceBandCalculator" ;
bytes32 internal constant _IModelCalculator_ = "IModelCalculator" ;
bytes32 internal constant _IRedButton_ = "IRedButton" ;
bytes32 internal constant _IReserveManager_ = "IReserveManager" ;
bytes32 internal constant _ISagaExchanger_ = "ISagaExchanger" ;
bytes32 internal constant _IMonetaryModel_ = "IMonetaryModel" ;
bytes32 internal constant _IMonetaryModelState_ = "IMonetaryModelState" ;
bytes32 internal constant _ISGAAuthorizationManager_ = "ISGAAuthorizationManager";
bytes32 internal constant _ISGAToken_ = "ISGAToken" ;
bytes32 internal constant _ISGATokenManager_ = "ISGATokenManager" ;
bytes32 internal constant _ISGNAuthorizationManager_ = "ISGNAuthorizationManager";
bytes32 internal constant _ISGNToken_ = "ISGNToken" ;
bytes32 internal constant _ISGNTokenManager_ = "ISGNTokenManager" ;
bytes32 internal constant _IMintingPointTimersManager_ = "IMintingPointTimersManager" ;
bytes32 internal constant _ITradingClasses_ = "ITradingClasses" ;
bytes32 internal constant _IWalletsTradingLimiterValueConverter_ = "IWalletsTLValueConverter" ;
bytes32 internal constant _IWalletsTradingDataSource_ = "IWalletsTradingDataSource" ;
bytes32 internal constant _WalletsTradingLimiter_SGNTokenManager_ = "WalletsTLSGNTokenManager" ;
bytes32 internal constant _WalletsTradingLimiter_SGATokenManager_ = "WalletsTLSGATokenManager" ;
bytes32 internal constant _IETHConverter_ = "IETHConverter" ;
bytes32 internal constant _ITransactionLimiter_ = "ITransactionLimiter" ;
bytes32 internal constant _ITransactionManager_ = "ITransactionManager" ;
bytes32 internal constant _IRateApprover_ = "IRateApprover" ;
IContractAddressLocator private contractAddressLocator;
/**
* @dev Create the contract.
* @param _contractAddressLocator The contract address locator.
*/
constructor(IContractAddressLocator _contractAddressLocator) internal {
require(_contractAddressLocator != address(0), "locator is illegal");
contractAddressLocator = _contractAddressLocator;
}
/**
* @dev Get the contract address locator.
* @return The contract address locator.
*/
function getContractAddressLocator() external view returns (IContractAddressLocator) {
return contractAddressLocator;
}
/**
* @dev Get the contract address mapped to a given identifier.
* @param _identifier The identifier.
* @return The contract address.
*/
function getContractAddress(bytes32 _identifier) internal view returns (address) {
return contractAddressLocator.getContractAddress(_identifier);
}
/**
* @dev Determine whether or not the sender relates to one of the identifiers.
* @param _identifiers The identifiers.
* @return A boolean indicating if the sender relates to one of the identifiers.
*/
function isSenderAddressRelates(bytes32[] _identifiers) internal view returns (bool) {
return contractAddressLocator.isContractAddressRelates(msg.sender, _identifiers);
}
/**
* @dev Verify that the caller is mapped to a given identifier.
* @param _identifier The identifier.
*/
modifier only(bytes32 _identifier) {
require(msg.sender == getContractAddress(_identifier), "caller is illegal");
_;
}
} | /**
* @title Contract Address Locator Holder.
* @dev Hold a contract address locator, which maps a unique identifier to every contract address in the system.
* @dev Any contract which inherits from this contract can retrieve the address of any contract in the system.
* @dev Thus, any contract can remain "oblivious" to the replacement of any other contract in the system.
* @dev In addition to that, any function in any contract can be restricted to a specific caller.
*/ | NatSpecMultiLine | getContractAddress | function getContractAddress(bytes32 _identifier) internal view returns (address) {
return contractAddressLocator.getContractAddress(_identifier);
}
| /**
* @dev Get the contract address mapped to a given identifier.
* @param _identifier The identifier.
* @return The contract address.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
3949,
4112
]
} | 2,444 |
ReserveManager | contracts/contract_address_locator/ContractAddressLocatorHolder.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | ContractAddressLocatorHolder | contract ContractAddressLocatorHolder {
bytes32 internal constant _IAuthorizationDataSource_ = "IAuthorizationDataSource";
bytes32 internal constant _ISGNConversionManager_ = "ISGNConversionManager" ;
bytes32 internal constant _IModelDataSource_ = "IModelDataSource" ;
bytes32 internal constant _IPaymentHandler_ = "IPaymentHandler" ;
bytes32 internal constant _IPaymentManager_ = "IPaymentManager" ;
bytes32 internal constant _IPaymentQueue_ = "IPaymentQueue" ;
bytes32 internal constant _IReconciliationAdjuster_ = "IReconciliationAdjuster" ;
bytes32 internal constant _IIntervalIterator_ = "IIntervalIterator" ;
bytes32 internal constant _IMintHandler_ = "IMintHandler" ;
bytes32 internal constant _IMintListener_ = "IMintListener" ;
bytes32 internal constant _IMintManager_ = "IMintManager" ;
bytes32 internal constant _IPriceBandCalculator_ = "IPriceBandCalculator" ;
bytes32 internal constant _IModelCalculator_ = "IModelCalculator" ;
bytes32 internal constant _IRedButton_ = "IRedButton" ;
bytes32 internal constant _IReserveManager_ = "IReserveManager" ;
bytes32 internal constant _ISagaExchanger_ = "ISagaExchanger" ;
bytes32 internal constant _IMonetaryModel_ = "IMonetaryModel" ;
bytes32 internal constant _IMonetaryModelState_ = "IMonetaryModelState" ;
bytes32 internal constant _ISGAAuthorizationManager_ = "ISGAAuthorizationManager";
bytes32 internal constant _ISGAToken_ = "ISGAToken" ;
bytes32 internal constant _ISGATokenManager_ = "ISGATokenManager" ;
bytes32 internal constant _ISGNAuthorizationManager_ = "ISGNAuthorizationManager";
bytes32 internal constant _ISGNToken_ = "ISGNToken" ;
bytes32 internal constant _ISGNTokenManager_ = "ISGNTokenManager" ;
bytes32 internal constant _IMintingPointTimersManager_ = "IMintingPointTimersManager" ;
bytes32 internal constant _ITradingClasses_ = "ITradingClasses" ;
bytes32 internal constant _IWalletsTradingLimiterValueConverter_ = "IWalletsTLValueConverter" ;
bytes32 internal constant _IWalletsTradingDataSource_ = "IWalletsTradingDataSource" ;
bytes32 internal constant _WalletsTradingLimiter_SGNTokenManager_ = "WalletsTLSGNTokenManager" ;
bytes32 internal constant _WalletsTradingLimiter_SGATokenManager_ = "WalletsTLSGATokenManager" ;
bytes32 internal constant _IETHConverter_ = "IETHConverter" ;
bytes32 internal constant _ITransactionLimiter_ = "ITransactionLimiter" ;
bytes32 internal constant _ITransactionManager_ = "ITransactionManager" ;
bytes32 internal constant _IRateApprover_ = "IRateApprover" ;
IContractAddressLocator private contractAddressLocator;
/**
* @dev Create the contract.
* @param _contractAddressLocator The contract address locator.
*/
constructor(IContractAddressLocator _contractAddressLocator) internal {
require(_contractAddressLocator != address(0), "locator is illegal");
contractAddressLocator = _contractAddressLocator;
}
/**
* @dev Get the contract address locator.
* @return The contract address locator.
*/
function getContractAddressLocator() external view returns (IContractAddressLocator) {
return contractAddressLocator;
}
/**
* @dev Get the contract address mapped to a given identifier.
* @param _identifier The identifier.
* @return The contract address.
*/
function getContractAddress(bytes32 _identifier) internal view returns (address) {
return contractAddressLocator.getContractAddress(_identifier);
}
/**
* @dev Determine whether or not the sender relates to one of the identifiers.
* @param _identifiers The identifiers.
* @return A boolean indicating if the sender relates to one of the identifiers.
*/
function isSenderAddressRelates(bytes32[] _identifiers) internal view returns (bool) {
return contractAddressLocator.isContractAddressRelates(msg.sender, _identifiers);
}
/**
* @dev Verify that the caller is mapped to a given identifier.
* @param _identifier The identifier.
*/
modifier only(bytes32 _identifier) {
require(msg.sender == getContractAddress(_identifier), "caller is illegal");
_;
}
} | /**
* @title Contract Address Locator Holder.
* @dev Hold a contract address locator, which maps a unique identifier to every contract address in the system.
* @dev Any contract which inherits from this contract can retrieve the address of any contract in the system.
* @dev Thus, any contract can remain "oblivious" to the replacement of any other contract in the system.
* @dev In addition to that, any function in any contract can be restricted to a specific caller.
*/ | NatSpecMultiLine | isSenderAddressRelates | function isSenderAddressRelates(bytes32[] _identifiers) internal view returns (bool) {
return contractAddressLocator.isContractAddressRelates(msg.sender, _identifiers);
}
| /**
* @dev Determine whether or not the sender relates to one of the identifiers.
* @param _identifiers The identifiers.
* @return A boolean indicating if the sender relates to one of the identifiers.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
4344,
4530
]
} | 2,445 |
KnightsOfChain | @openzeppelin/contracts/access/Ownable.sol | 0x0e116154d53c89803af778aed251103096b7a67d | Solidity | Ownable | 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() {
_setOwner(_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 {
_setOwner(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");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
} | /**
* @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.
*/ | NatSpecMultiLine | owner | function owner() public view virtual returns (address) {
return _owner;
}
| /**
* @dev Returns the address of the current owner.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://3f85fba9f91977800fe7afe140f075277492ffbd5e89bb4a30a95dc3d3138331 | {
"func_code_index": [
399,
491
]
} | 2,446 |
KnightsOfChain | @openzeppelin/contracts/access/Ownable.sol | 0x0e116154d53c89803af778aed251103096b7a67d | Solidity | Ownable | 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() {
_setOwner(_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 {
_setOwner(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");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
} | /**
* @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.
*/ | NatSpecMultiLine | renounceOwnership | function renounceOwnership() public virtual onlyOwner {
_setOwner(address(0));
}
| /**
* @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.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://3f85fba9f91977800fe7afe140f075277492ffbd5e89bb4a30a95dc3d3138331 | {
"func_code_index": [
1050,
1149
]
} | 2,447 |
KnightsOfChain | @openzeppelin/contracts/access/Ownable.sol | 0x0e116154d53c89803af778aed251103096b7a67d | Solidity | Ownable | 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() {
_setOwner(_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 {
_setOwner(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");
_setOwner(newOwner);
}
function _setOwner(address newOwner) private {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
} | /**
* @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.
*/ | NatSpecMultiLine | transferOwnership | function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_setOwner(newOwner);
}
| /**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/ | NatSpecMultiLine | v0.8.7+commit.e28d00a7 | MIT | ipfs://3f85fba9f91977800fe7afe140f075277492ffbd5e89bb4a30a95dc3d3138331 | {
"func_code_index": [
1299,
1496
]
} | 2,448 |
KnightsOfChain | @openzeppelin/contracts/access/Ownable.sol | 0x0e116154d53c89803af778aed251103096b7a67d | Solidity | KnightsOfChain | contract KnightsOfChain is ERC721Enumerable, Ownable {
using Strings for uint256;
using SafeMath for uint256;
string private baseURI;
uint256 public cost = 0.10 ether;
uint256 public maxSupply = 9999;
uint256 public maxMintAmount = 2;
uint256 public nftPerAddressLimit = 2;
uint256 public nftGiveawayLimit = 1;
bool public paused = false;
bool public revealed = false;
bool public onlyWhitelisted = true;
mapping(address => uint256) public addressMintedBalance;
mapping(address=>bool) public whitelistedAddresses;
mapping(address=>bool) public giveawayAddresses;
constructor(
string memory _name,
string memory _symbol
) ERC721(_name, _symbol) {
}
function _baseURI() internal view virtual override returns (string memory) {
return baseURI;
}
function mint(uint256 _mintAmount) external payable {
require(!paused, "the contract is paused");
uint256 supply = totalSupply();
uint256 differCost = cost;
require(_mintAmount > 0, "Need to mint at least 1 NFT");
require(_mintAmount <= maxMintAmount, "Maximum mint amount per session exceeded - please try again.");
require(supply.add(_mintAmount) <= maxSupply, "All NFTs have been minted.");
if (msg.sender != owner()) {
uint256 ownerMintedCount = addressMintedBalance[msg.sender];
require(ownerMintedCount.add(_mintAmount) <= nftPerAddressLimit, "You have reached the maximum number of NFTs allowed.");
if(onlyWhitelisted) {
require(isWhitelisted(msg.sender), "This wallet ID has not been whitelisted");
}
if(giveawayList(msg.sender) ){
require(_mintAmount <= nftGiveawayLimit, "We only offer 1 free giveaway per address.");
giveawayAddresses[msg.sender] = false;
differCost = 0;
}
uint256 totalCost = differCost.mul(_mintAmount);
require(msg.value >= totalCost, "insufficient funds");
//return dust eth to the sender
if(msg.value > totalCost){
uint256 dustEth = msg.value - totalCost;
(bool success,) = msg.sender.call{value: dustEth}("");
require(success);
}
}
addressMintedBalance[msg.sender] = addressMintedBalance[msg.sender].add(_mintAmount);
for (uint256 i = 1; i <= _mintAmount; i++) {
_safeMint(msg.sender, supply.add(i));
}
}
function isWhitelisted(address _user) public view returns (bool) {
return whitelistedAddresses[_user];
}
function giveawayList(address _user) public view returns (bool) {
return giveawayAddresses[_user];
}
function walletOfOwner(address _owner)
public
view
returns (uint256[] memory)
{
uint256 ownerTokenCount = balanceOf(_owner);
uint256[] memory tokenIds = new uint256[](ownerTokenCount);
for (uint256 i; i < ownerTokenCount; i++) {
tokenIds[i] = tokenOfOwnerByIndex(_owner, i);
}
return tokenIds;
}
function tokenURI(uint256 tokenId)
external
view
virtual
override
returns (string memory)
{
require(
_exists(tokenId),
"ERC721Metadata: URI query for nonexistent token"
);
if(revealed == false) {
return "ipfs://QmRrYSUH8TZUvkPqxXyMcpAcnLNb6sYtPLbmMp3TtnZMU9/hidden.json";
}
string memory currentBaseURI = _baseURI();
return bytes(currentBaseURI).length > 0
? string(abi.encodePacked(currentBaseURI, tokenId.toString(), ".json"))
: "";
}
//only owner
function reveal() external onlyOwner {
revealed = true;
}
function setNftPerAddressLimit(uint256 _limit) external onlyOwner {
nftPerAddressLimit = _limit;
}
function setCost(uint256 _newCost) external onlyOwner {
cost = _newCost;
}
function setmaxMintAmount(uint256 _newmaxMintAmount) external onlyOwner {
maxMintAmount = _newmaxMintAmount;
}
function setBaseURI(string memory _newBaseURI) public onlyOwner {
baseURI = _newBaseURI;
}
function pause() external onlyOwner {
paused = !paused;
}
function setOnlyWhitelisted() external onlyOwner {
onlyWhitelisted = !onlyWhitelisted;
}
function addWhitelistUsers(address[] calldata _users) external onlyOwner {
for(uint i=0; i<_users.length; i++){
whitelistedAddresses[_users[i]] = true;
}
}
function addGiveawayUsers(address[] calldata _users) external onlyOwner {
for (uint i = 0; i < _users.length; i++) {
giveawayAddresses[_users[i]] = true;
}
}
function withdraw() external payable onlyOwner {
(bool os, ) = payable(owner()).call{value: address(this).balance}("");
require(os);
}
} | reveal | function reveal() external onlyOwner {
revealed = true;
}
| //only owner | LineComment | v0.8.7+commit.e28d00a7 | MIT | ipfs://3f85fba9f91977800fe7afe140f075277492ffbd5e89bb4a30a95dc3d3138331 | {
"func_code_index": [
3644,
3714
]
} | 2,449 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | IERC20 | 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);
} | totalSupply | function totalSupply() external view returns (uint256);
| /**
* @dev Returns the amount of tokens in existence.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
94,
154
]
} | 2,450 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | IERC20 | 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);
} | balanceOf | function balanceOf(address account) external view returns (uint256);
| /**
* @dev Returns the amount of tokens owned by `account`.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
235,
308
]
} | 2,451 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | IERC20 | 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);
} | transfer | function transfer(address recipient, uint256 amount) external returns (bool);
| /**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
530,
612
]
} | 2,452 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | IERC20 | 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);
} | allowance | function allowance(address owner, address spender) external view returns (uint256);
| /**
* @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.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
889,
977
]
} | 2,453 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | IERC20 | 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);
} | approve | function approve(address spender, uint256 amount) external returns (bool);
| /**
* @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.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
1639,
1718
]
} | 2,454 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | IERC20 | 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);
} | transferFrom | function transferFrom(address sender, address recipient, 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.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
2029,
2131
]
} | 2,455 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* 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);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | add | 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 addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
259,
445
]
} | 2,456 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* 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);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | sub | function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
| /**
* @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.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
721,
862
]
} | 2,457 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* 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);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | sub | function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
| /**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
1158,
1353
]
} | 2,458 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* 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);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mul | function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
| /**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
1605,
2077
]
} | 2,459 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* 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);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | div | function div(uint256 a, uint256 b) internal pure returns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts 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.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
2546,
2683
]
} | 2,460 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* 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);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | div | function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
| /**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
3172,
3453
]
} | 2,461 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* 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);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mod | function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
| /**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts 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.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
3911,
4046
]
} | 2,462 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | SafeMath | library SafeMath {
/**
* @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) {
return sub(a, b, "SafeMath: subtraction overflow");
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* 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);
uint256 c = a - b;
return c;
}
/**
* @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) {
// 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 0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts 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) {
return div(a, b, "SafeMath: division by zero");
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts with custom message 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, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
return a % b;
}
} | mod | function mod(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),
* Reverts with custom message 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.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
4524,
4695
]
} | 2,463 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | isContract | function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
| /**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
606,
1230
]
} | 2,464 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | sendValue | function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
| /**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
2158,
2560
]
} | 2,465 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCall | function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
| /**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
3314,
3492
]
} | 2,466 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCall | function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
| /**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
3715,
3916
]
} | 2,467 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCallWithValue | function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
| /**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
4284,
4515
]
} | 2,468 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCallWithValue | function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
| /**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
4764,
5085
]
} | 2,469 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | Ownable | 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 () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view 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;
}
} | owner | function owner() public view returns (address) {
return _owner;
}
| /**
* @dev Returns the address of the current owner.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
493,
577
]
} | 2,470 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | Ownable | 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 () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view 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;
}
} | renounceOwnership | function renounceOwnership() public virtual onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
| /**
* @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.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
1131,
1284
]
} | 2,471 |
||
CZELON | CZELON.sol | 0x81991133f1f125677754e062da07880b1e1d8c83 | Solidity | Ownable | 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 () internal {
address msgSender = _msgSender();
_owner = msgSender;
emit OwnershipTransferred(address(0), msgSender);
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view 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;
}
} | transferOwnership | function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
| /**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | MIT | ipfs://218a732a73b81df30558be726a07e26bf715c0d3fd79687b16ae42e9867e48b0 | {
"func_code_index": [
1432,
1681
]
} | 2,472 |
||
DMGYieldFarmingRouter | contracts/external/farming/libs/UniswapV2Library.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | UniswapV2Library | library UniswapV2Library {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
// Taken from the UniswapV2Pair.json "bytecode" field
keccak256(hex'60806040526001600c5534801561001557600080fd5b5060405146908060526123868239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612281806101056000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a714610534578063d505accf1461053c578063dd62ed3e1461058d578063fff6cae9146105bb576101a9565b8063ba9a7a56146104fe578063bc25cf7714610506578063c45a01551461052c576101a9565b80637ecebe00116100d35780637ecebe001461046557806389afcb441461048b57806395d89b41146104ca578063a9059cbb146104d2576101a9565b80636a6278421461041157806370a08231146104375780637464fc3d1461045d576101a9565b806323b872dd116101665780633644e515116101405780633644e515146103cb578063485cc955146103d35780635909c0d5146104015780635a3d549314610409576101a9565b806323b872dd1461036f57806330adf81f146103a5578063313ce567146103ad576101a9565b8063022c0d9f146101ae57806306fdde031461023c5780630902f1ac146102b9578063095ea7b3146102f15780630dfe16811461033157806318160ddd14610355575b600080fd5b61023a600480360360808110156101c457600080fd5b8135916020810135916001600160a01b0360408301351691908101906080810160608201356401000000008111156101fb57600080fd5b82018360208201111561020d57600080fd5b8035906020019184600183028401116401000000008311171561022f57600080fd5b5090925090506105c3565b005b610244610afe565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561027e578181015183820152602001610266565b50505050905090810190601f1680156102ab5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102c1610b24565b604080516001600160701b03948516815292909316602083015263ffffffff168183015290519081900360600190f35b61031d6004803603604081101561030757600080fd5b506001600160a01b038135169060200135610b4e565b604080519115158252519081900360200190f35b610339610b65565b604080516001600160a01b039092168252519081900360200190f35b61035d610b74565b60408051918252519081900360200190f35b61031d6004803603606081101561038557600080fd5b506001600160a01b03813581169160208101359091169060400135610b7a565b61035d610c14565b6103b5610c38565b6040805160ff9092168252519081900360200190f35b61035d610c3d565b61023a600480360360408110156103e957600080fd5b506001600160a01b0381358116916020013516610c43565b61035d610cc7565b61035d610ccd565b61035d6004803603602081101561042757600080fd5b50356001600160a01b0316610cd3565b61035d6004803603602081101561044d57600080fd5b50356001600160a01b0316610fd3565b61035d610fe5565b61035d6004803603602081101561047b57600080fd5b50356001600160a01b0316610feb565b6104b1600480360360208110156104a157600080fd5b50356001600160a01b0316610ffd565b6040805192835260208301919091528051918290030190f35b6102446113a3565b61031d600480360360408110156104e857600080fd5b506001600160a01b0381351690602001356113c5565b61035d6113d2565b61023a6004803603602081101561051c57600080fd5b50356001600160a01b03166113d8565b610339611543565b610339611552565b61023a600480360360e081101561055257600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611561565b61035d600480360360408110156105a357600080fd5b506001600160a01b0381358116916020013516611763565b61023a611780565b600c5460011461060e576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55841515806106215750600084115b61065c5760405162461bcd60e51b81526004018080602001828103825260258152602001806121936025913960400191505060405180910390fd5b600080610667610b24565b5091509150816001600160701b03168710801561068c5750806001600160701b031686105b6106c75760405162461bcd60e51b81526004018080602001828103825260218152602001806121dc6021913960400191505060405180910390fd5b60065460075460009182916001600160a01b039182169190811690891682148015906107055750806001600160a01b0316896001600160a01b031614155b61074e576040805162461bcd60e51b8152602060048201526015602482015274556e697377617056323a20494e56414c49445f544f60581b604482015290519081900360640190fd5b8a1561075f5761075f828a8d6118e2565b891561077057610770818a8c6118e2565b861561082b57886001600160a01b03166310d1e85c338d8d8c8c6040518663ffffffff1660e01b815260040180866001600160a01b03166001600160a01b03168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b15801561081257600080fd5b505af1158015610826573d6000803e3d6000fd5b505050505b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561087157600080fd5b505afa158015610885573d6000803e3d6000fd5b505050506040513d602081101561089b57600080fd5b5051604080516370a0823160e01b815230600482015290519195506001600160a01b038316916370a0823191602480820192602092909190829003018186803b1580156108e757600080fd5b505afa1580156108fb573d6000803e3d6000fd5b505050506040513d602081101561091157600080fd5b5051925060009150506001600160701b0385168a90038311610934576000610943565b89856001600160701b03160383035b9050600089856001600160701b031603831161096057600061096f565b89856001600160701b03160383035b905060008211806109805750600081115b6109bb5760405162461bcd60e51b81526004018080602001828103825260248152602001806121b86024913960400191505060405180910390fd5b60006109ef6109d184600363ffffffff611a7c16565b6109e3876103e863ffffffff611a7c16565b9063ffffffff611adf16565b90506000610a076109d184600363ffffffff611a7c16565b9050610a38620f4240610a2c6001600160701b038b8116908b1663ffffffff611a7c16565b9063ffffffff611a7c16565b610a48838363ffffffff611a7c16565b1015610a8a576040805162461bcd60e51b815260206004820152600c60248201526b556e697377617056323a204b60a01b604482015290519081900360640190fd5b5050610a9884848888611b2f565b60408051838152602081018390528082018d9052606081018c905290516001600160a01b038b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a8152602001692ab734b9bbb0b8102b1960b11b81525081565b6008546001600160701b0380821692600160701b830490911691600160e01b900463ffffffff1690565b6000610b5b338484611cf4565b5060015b92915050565b6006546001600160a01b031681565b60005481565b6001600160a01b038316600090815260026020908152604080832033845290915281205460001914610bff576001600160a01b0384166000908152600260209081526040808320338452909152902054610bda908363ffffffff611adf16565b6001600160a01b03851660009081526002602090815260408083203384529091529020555b610c0a848484611d56565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b6005546001600160a01b03163314610c99576040805162461bcd60e51b81526020600482015260146024820152732ab734b9bbb0b82b191d102327a92124a22222a760611b604482015290519081900360640190fd5b600680546001600160a01b039384166001600160a01b03199182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c54600114610d20576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c81905580610d30610b24565b50600654604080516370a0823160e01b815230600482015290519395509193506000926001600160a01b03909116916370a08231916024808301926020929190829003018186803b158015610d8457600080fd5b505afa158015610d98573d6000803e3d6000fd5b505050506040513d6020811015610dae57600080fd5b5051600754604080516370a0823160e01b815230600482015290519293506000926001600160a01b03909216916370a0823191602480820192602092909190829003018186803b158015610e0157600080fd5b505afa158015610e15573d6000803e3d6000fd5b505050506040513d6020811015610e2b57600080fd5b505190506000610e4a836001600160701b03871663ffffffff611adf16565b90506000610e67836001600160701b03871663ffffffff611adf16565b90506000610e758787611e10565b60005490915080610eb257610e9e6103e86109e3610e99878763ffffffff611a7c16565b611f6e565b9850610ead60006103e8611fc0565b610f01565b610efe6001600160701b038916610ecf868463ffffffff611a7c16565b81610ed657fe5b046001600160701b038916610ef1868563ffffffff611a7c16565b81610ef857fe5b04612056565b98505b60008911610f405760405162461bcd60e51b81526004018080602001828103825260288152602001806122256028913960400191505060405180910390fd5b610f4a8a8a611fc0565b610f5686868a8a611b2f565b8115610f8657600854610f82906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461104b576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c8190558061105b610b24565b50600654600754604080516370a0823160e01b815230600482015290519496509294506001600160a01b039182169391169160009184916370a08231916024808301926020929190829003018186803b1580156110b757600080fd5b505afa1580156110cb573d6000803e3d6000fd5b505050506040513d60208110156110e157600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038516916370a08231916024808301926020929190829003018186803b15801561112f57600080fd5b505afa158015611143573d6000803e3d6000fd5b505050506040513d602081101561115957600080fd5b5051306000908152600160205260408120549192506111788888611e10565b6000549091508061118f848763ffffffff611a7c16565b8161119657fe5b049a50806111aa848663ffffffff611a7c16565b816111b157fe5b04995060008b1180156111c4575060008a115b6111ff5760405162461bcd60e51b81526004018080602001828103825260288152602001806121fd6028913960400191505060405180910390fd5b611209308461206e565b611214878d8d6118e2565b61121f868d8c6118e2565b604080516370a0823160e01b815230600482015290516001600160a01b038916916370a08231916024808301926020929190829003018186803b15801561126557600080fd5b505afa158015611279573d6000803e3d6000fd5b505050506040513d602081101561128f57600080fd5b5051604080516370a0823160e01b815230600482015290519196506001600160a01b038816916370a0823191602480820192602092909190829003018186803b1580156112db57600080fd5b505afa1580156112ef573d6000803e3d6000fd5b505050506040513d602081101561130557600080fd5b5051935061131585858b8b611b2f565b811561134557600854611341906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b604080518c8152602081018c905281516001600160a01b038f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b604051806040016040528060068152602001652aa72496ab1960d11b81525081565b6000610b5b338484611d56565b6103e881565b600c54600114611423576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654600754600854604080516370a0823160e01b815230600482015290516001600160a01b0394851694909316926114d292859287926114cd926001600160701b03169185916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b505afa1580156114a9573d6000803e3d6000fd5b505050506040513d60208110156114bf57600080fd5b50519063ffffffff611adf16565b6118e2565b600854604080516370a0823160e01b8152306004820152905161153992849287926114cd92600160701b90046001600160701b0316916001600160a01b038616916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b50506001600c5550565b6005546001600160a01b031681565b6007546001600160a01b031681565b428410156115ab576040805162461bcd60e51b8152602060048201526012602482015271155b9a5cddd85c158c8e881156141254915160721b604482015290519081900360640190fd5b6003546001600160a01b0380891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e08501825280519083012061190160f01b6101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e280820193601f1981019281900390910190855afa1580156116c6573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906116fc5750886001600160a01b0316816001600160a01b0316145b61174d576040805162461bcd60e51b815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611758898989611cf4565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c546001146117cb576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654604080516370a0823160e01b815230600482015290516118db926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561181c57600080fd5b505afa158015611830573d6000803e3d6000fd5b505050506040513d602081101561184657600080fd5b5051600754604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b15801561189357600080fd5b505afa1580156118a7573d6000803e3d6000fd5b505050506040513d60208110156118bd57600080fd5b50516008546001600160701b0380821691600160701b900416611b2f565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e74323536290000000000000060209182015281516001600160a01b0385811660248301526044808301869052845180840390910181526064909201845291810180516001600160e01b031663a9059cbb60e01b1781529251815160009460609489169392918291908083835b6020831061198f5780518252601f199092019160209182019101611970565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146119f1576040519150601f19603f3d011682016040523d82523d6000602084013e6119f6565b606091505b5091509150818015611a24575080511580611a245750808060200190516020811015611a2157600080fd5b50515b611a75576040805162461bcd60e51b815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b6000811580611a9757505080820282828281611a9457fe5b04145b610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820382811115610b5f576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6001600160701b038411801590611b4d57506001600160701b038311155b611b94576040805162461bcd60e51b8152602060048201526013602482015272556e697377617056323a204f564552464c4f5760681b604482015290519081900360640190fd5b60085463ffffffff42811691600160e01b90048116820390811615801590611bc457506001600160701b03841615155b8015611bd857506001600160701b03831615155b15611c49578063ffffffff16611c0685611bf18661210c565b6001600160e01b03169063ffffffff61211e16565b600980546001600160e01b03929092169290920201905563ffffffff8116611c3184611bf18761210c565b600a80546001600160e01b0392909216929092020190555b600880546dffffffffffffffffffffffffffff19166001600160701b03888116919091176dffffffffffffffffffffffffffff60701b1916600160701b8883168102919091176001600160e01b0316600160e01b63ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316600090815260016020526040902054611d7f908263ffffffff611adf16565b6001600160a01b038085166000908152600160205260408082209390935590841681522054611db4908263ffffffff61214316565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611e6157600080fd5b505afa158015611e75573d6000803e3d6000fd5b505050506040513d6020811015611e8b57600080fd5b5051600b546001600160a01b038216158015945091925090611f5a578015611f55576000611ece610e996001600160701b0388811690881663ffffffff611a7c16565b90506000611edb83611f6e565b905080821115611f52576000611f09611efa848463ffffffff611adf16565b6000549063ffffffff611a7c16565b90506000611f2e83611f2286600563ffffffff611a7c16565b9063ffffffff61214316565b90506000818381611f3b57fe5b0490508015611f4e57611f4e8782611fc0565b5050505b50505b611f66565b8015611f66576000600b555b505092915050565b60006003821115611fb1575080600160028204015b81811015611fab57809150600281828581611f9a57fe5b040181611fa357fe5b049050611f83565b50611fbb565b8115611fbb575060015b919050565b600054611fd3908263ffffffff61214316565b60009081556001600160a01b038316815260016020526040902054611ffe908263ffffffff61214316565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008183106120655781612067565b825b9392505050565b6001600160a01b038216600090815260016020526040902054612097908263ffffffff611adf16565b6001600160a01b038316600090815260016020526040812091909155546120c4908263ffffffff611adf16565b60009081556040805183815290516001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6001600160701b0316600160701b0290565b60006001600160701b0382166001600160e01b0384168161213b57fe5b049392505050565b80820182811015610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a7231582082fba8557d35ae5eca98219a61e967d398ed8eaafeafa5fe5af73dd6aad9ddfd64736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429') // init code hash
))));
}
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
} | sortTokens | function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
| // returns sorted token addresses, used to handle return values from pairs sorted in this order | LineComment | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
163,
517
]
} | 2,473 |
||
DMGYieldFarmingRouter | contracts/external/farming/libs/UniswapV2Library.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | UniswapV2Library | library UniswapV2Library {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
// Taken from the UniswapV2Pair.json "bytecode" field
keccak256(hex'60806040526001600c5534801561001557600080fd5b5060405146908060526123868239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612281806101056000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a714610534578063d505accf1461053c578063dd62ed3e1461058d578063fff6cae9146105bb576101a9565b8063ba9a7a56146104fe578063bc25cf7714610506578063c45a01551461052c576101a9565b80637ecebe00116100d35780637ecebe001461046557806389afcb441461048b57806395d89b41146104ca578063a9059cbb146104d2576101a9565b80636a6278421461041157806370a08231146104375780637464fc3d1461045d576101a9565b806323b872dd116101665780633644e515116101405780633644e515146103cb578063485cc955146103d35780635909c0d5146104015780635a3d549314610409576101a9565b806323b872dd1461036f57806330adf81f146103a5578063313ce567146103ad576101a9565b8063022c0d9f146101ae57806306fdde031461023c5780630902f1ac146102b9578063095ea7b3146102f15780630dfe16811461033157806318160ddd14610355575b600080fd5b61023a600480360360808110156101c457600080fd5b8135916020810135916001600160a01b0360408301351691908101906080810160608201356401000000008111156101fb57600080fd5b82018360208201111561020d57600080fd5b8035906020019184600183028401116401000000008311171561022f57600080fd5b5090925090506105c3565b005b610244610afe565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561027e578181015183820152602001610266565b50505050905090810190601f1680156102ab5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102c1610b24565b604080516001600160701b03948516815292909316602083015263ffffffff168183015290519081900360600190f35b61031d6004803603604081101561030757600080fd5b506001600160a01b038135169060200135610b4e565b604080519115158252519081900360200190f35b610339610b65565b604080516001600160a01b039092168252519081900360200190f35b61035d610b74565b60408051918252519081900360200190f35b61031d6004803603606081101561038557600080fd5b506001600160a01b03813581169160208101359091169060400135610b7a565b61035d610c14565b6103b5610c38565b6040805160ff9092168252519081900360200190f35b61035d610c3d565b61023a600480360360408110156103e957600080fd5b506001600160a01b0381358116916020013516610c43565b61035d610cc7565b61035d610ccd565b61035d6004803603602081101561042757600080fd5b50356001600160a01b0316610cd3565b61035d6004803603602081101561044d57600080fd5b50356001600160a01b0316610fd3565b61035d610fe5565b61035d6004803603602081101561047b57600080fd5b50356001600160a01b0316610feb565b6104b1600480360360208110156104a157600080fd5b50356001600160a01b0316610ffd565b6040805192835260208301919091528051918290030190f35b6102446113a3565b61031d600480360360408110156104e857600080fd5b506001600160a01b0381351690602001356113c5565b61035d6113d2565b61023a6004803603602081101561051c57600080fd5b50356001600160a01b03166113d8565b610339611543565b610339611552565b61023a600480360360e081101561055257600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611561565b61035d600480360360408110156105a357600080fd5b506001600160a01b0381358116916020013516611763565b61023a611780565b600c5460011461060e576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55841515806106215750600084115b61065c5760405162461bcd60e51b81526004018080602001828103825260258152602001806121936025913960400191505060405180910390fd5b600080610667610b24565b5091509150816001600160701b03168710801561068c5750806001600160701b031686105b6106c75760405162461bcd60e51b81526004018080602001828103825260218152602001806121dc6021913960400191505060405180910390fd5b60065460075460009182916001600160a01b039182169190811690891682148015906107055750806001600160a01b0316896001600160a01b031614155b61074e576040805162461bcd60e51b8152602060048201526015602482015274556e697377617056323a20494e56414c49445f544f60581b604482015290519081900360640190fd5b8a1561075f5761075f828a8d6118e2565b891561077057610770818a8c6118e2565b861561082b57886001600160a01b03166310d1e85c338d8d8c8c6040518663ffffffff1660e01b815260040180866001600160a01b03166001600160a01b03168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b15801561081257600080fd5b505af1158015610826573d6000803e3d6000fd5b505050505b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561087157600080fd5b505afa158015610885573d6000803e3d6000fd5b505050506040513d602081101561089b57600080fd5b5051604080516370a0823160e01b815230600482015290519195506001600160a01b038316916370a0823191602480820192602092909190829003018186803b1580156108e757600080fd5b505afa1580156108fb573d6000803e3d6000fd5b505050506040513d602081101561091157600080fd5b5051925060009150506001600160701b0385168a90038311610934576000610943565b89856001600160701b03160383035b9050600089856001600160701b031603831161096057600061096f565b89856001600160701b03160383035b905060008211806109805750600081115b6109bb5760405162461bcd60e51b81526004018080602001828103825260248152602001806121b86024913960400191505060405180910390fd5b60006109ef6109d184600363ffffffff611a7c16565b6109e3876103e863ffffffff611a7c16565b9063ffffffff611adf16565b90506000610a076109d184600363ffffffff611a7c16565b9050610a38620f4240610a2c6001600160701b038b8116908b1663ffffffff611a7c16565b9063ffffffff611a7c16565b610a48838363ffffffff611a7c16565b1015610a8a576040805162461bcd60e51b815260206004820152600c60248201526b556e697377617056323a204b60a01b604482015290519081900360640190fd5b5050610a9884848888611b2f565b60408051838152602081018390528082018d9052606081018c905290516001600160a01b038b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a8152602001692ab734b9bbb0b8102b1960b11b81525081565b6008546001600160701b0380821692600160701b830490911691600160e01b900463ffffffff1690565b6000610b5b338484611cf4565b5060015b92915050565b6006546001600160a01b031681565b60005481565b6001600160a01b038316600090815260026020908152604080832033845290915281205460001914610bff576001600160a01b0384166000908152600260209081526040808320338452909152902054610bda908363ffffffff611adf16565b6001600160a01b03851660009081526002602090815260408083203384529091529020555b610c0a848484611d56565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b6005546001600160a01b03163314610c99576040805162461bcd60e51b81526020600482015260146024820152732ab734b9bbb0b82b191d102327a92124a22222a760611b604482015290519081900360640190fd5b600680546001600160a01b039384166001600160a01b03199182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c54600114610d20576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c81905580610d30610b24565b50600654604080516370a0823160e01b815230600482015290519395509193506000926001600160a01b03909116916370a08231916024808301926020929190829003018186803b158015610d8457600080fd5b505afa158015610d98573d6000803e3d6000fd5b505050506040513d6020811015610dae57600080fd5b5051600754604080516370a0823160e01b815230600482015290519293506000926001600160a01b03909216916370a0823191602480820192602092909190829003018186803b158015610e0157600080fd5b505afa158015610e15573d6000803e3d6000fd5b505050506040513d6020811015610e2b57600080fd5b505190506000610e4a836001600160701b03871663ffffffff611adf16565b90506000610e67836001600160701b03871663ffffffff611adf16565b90506000610e758787611e10565b60005490915080610eb257610e9e6103e86109e3610e99878763ffffffff611a7c16565b611f6e565b9850610ead60006103e8611fc0565b610f01565b610efe6001600160701b038916610ecf868463ffffffff611a7c16565b81610ed657fe5b046001600160701b038916610ef1868563ffffffff611a7c16565b81610ef857fe5b04612056565b98505b60008911610f405760405162461bcd60e51b81526004018080602001828103825260288152602001806122256028913960400191505060405180910390fd5b610f4a8a8a611fc0565b610f5686868a8a611b2f565b8115610f8657600854610f82906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461104b576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c8190558061105b610b24565b50600654600754604080516370a0823160e01b815230600482015290519496509294506001600160a01b039182169391169160009184916370a08231916024808301926020929190829003018186803b1580156110b757600080fd5b505afa1580156110cb573d6000803e3d6000fd5b505050506040513d60208110156110e157600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038516916370a08231916024808301926020929190829003018186803b15801561112f57600080fd5b505afa158015611143573d6000803e3d6000fd5b505050506040513d602081101561115957600080fd5b5051306000908152600160205260408120549192506111788888611e10565b6000549091508061118f848763ffffffff611a7c16565b8161119657fe5b049a50806111aa848663ffffffff611a7c16565b816111b157fe5b04995060008b1180156111c4575060008a115b6111ff5760405162461bcd60e51b81526004018080602001828103825260288152602001806121fd6028913960400191505060405180910390fd5b611209308461206e565b611214878d8d6118e2565b61121f868d8c6118e2565b604080516370a0823160e01b815230600482015290516001600160a01b038916916370a08231916024808301926020929190829003018186803b15801561126557600080fd5b505afa158015611279573d6000803e3d6000fd5b505050506040513d602081101561128f57600080fd5b5051604080516370a0823160e01b815230600482015290519196506001600160a01b038816916370a0823191602480820192602092909190829003018186803b1580156112db57600080fd5b505afa1580156112ef573d6000803e3d6000fd5b505050506040513d602081101561130557600080fd5b5051935061131585858b8b611b2f565b811561134557600854611341906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b604080518c8152602081018c905281516001600160a01b038f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b604051806040016040528060068152602001652aa72496ab1960d11b81525081565b6000610b5b338484611d56565b6103e881565b600c54600114611423576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654600754600854604080516370a0823160e01b815230600482015290516001600160a01b0394851694909316926114d292859287926114cd926001600160701b03169185916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b505afa1580156114a9573d6000803e3d6000fd5b505050506040513d60208110156114bf57600080fd5b50519063ffffffff611adf16565b6118e2565b600854604080516370a0823160e01b8152306004820152905161153992849287926114cd92600160701b90046001600160701b0316916001600160a01b038616916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b50506001600c5550565b6005546001600160a01b031681565b6007546001600160a01b031681565b428410156115ab576040805162461bcd60e51b8152602060048201526012602482015271155b9a5cddd85c158c8e881156141254915160721b604482015290519081900360640190fd5b6003546001600160a01b0380891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e08501825280519083012061190160f01b6101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e280820193601f1981019281900390910190855afa1580156116c6573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906116fc5750886001600160a01b0316816001600160a01b0316145b61174d576040805162461bcd60e51b815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611758898989611cf4565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c546001146117cb576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654604080516370a0823160e01b815230600482015290516118db926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561181c57600080fd5b505afa158015611830573d6000803e3d6000fd5b505050506040513d602081101561184657600080fd5b5051600754604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b15801561189357600080fd5b505afa1580156118a7573d6000803e3d6000fd5b505050506040513d60208110156118bd57600080fd5b50516008546001600160701b0380821691600160701b900416611b2f565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e74323536290000000000000060209182015281516001600160a01b0385811660248301526044808301869052845180840390910181526064909201845291810180516001600160e01b031663a9059cbb60e01b1781529251815160009460609489169392918291908083835b6020831061198f5780518252601f199092019160209182019101611970565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146119f1576040519150601f19603f3d011682016040523d82523d6000602084013e6119f6565b606091505b5091509150818015611a24575080511580611a245750808060200190516020811015611a2157600080fd5b50515b611a75576040805162461bcd60e51b815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b6000811580611a9757505080820282828281611a9457fe5b04145b610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820382811115610b5f576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6001600160701b038411801590611b4d57506001600160701b038311155b611b94576040805162461bcd60e51b8152602060048201526013602482015272556e697377617056323a204f564552464c4f5760681b604482015290519081900360640190fd5b60085463ffffffff42811691600160e01b90048116820390811615801590611bc457506001600160701b03841615155b8015611bd857506001600160701b03831615155b15611c49578063ffffffff16611c0685611bf18661210c565b6001600160e01b03169063ffffffff61211e16565b600980546001600160e01b03929092169290920201905563ffffffff8116611c3184611bf18761210c565b600a80546001600160e01b0392909216929092020190555b600880546dffffffffffffffffffffffffffff19166001600160701b03888116919091176dffffffffffffffffffffffffffff60701b1916600160701b8883168102919091176001600160e01b0316600160e01b63ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316600090815260016020526040902054611d7f908263ffffffff611adf16565b6001600160a01b038085166000908152600160205260408082209390935590841681522054611db4908263ffffffff61214316565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611e6157600080fd5b505afa158015611e75573d6000803e3d6000fd5b505050506040513d6020811015611e8b57600080fd5b5051600b546001600160a01b038216158015945091925090611f5a578015611f55576000611ece610e996001600160701b0388811690881663ffffffff611a7c16565b90506000611edb83611f6e565b905080821115611f52576000611f09611efa848463ffffffff611adf16565b6000549063ffffffff611a7c16565b90506000611f2e83611f2286600563ffffffff611a7c16565b9063ffffffff61214316565b90506000818381611f3b57fe5b0490508015611f4e57611f4e8782611fc0565b5050505b50505b611f66565b8015611f66576000600b555b505092915050565b60006003821115611fb1575080600160028204015b81811015611fab57809150600281828581611f9a57fe5b040181611fa357fe5b049050611f83565b50611fbb565b8115611fbb575060015b919050565b600054611fd3908263ffffffff61214316565b60009081556001600160a01b038316815260016020526040902054611ffe908263ffffffff61214316565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008183106120655781612067565b825b9392505050565b6001600160a01b038216600090815260016020526040902054612097908263ffffffff611adf16565b6001600160a01b038316600090815260016020526040812091909155546120c4908263ffffffff611adf16565b60009081556040805183815290516001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6001600160701b0316600160701b0290565b60006001600160701b0382166001600160e01b0384168161213b57fe5b049392505050565b80820182811015610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a7231582082fba8557d35ae5eca98219a61e967d398ed8eaafeafa5fe5af73dd6aad9ddfd64736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429') // init code hash
))));
}
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
} | pairFor | function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
// Taken from the UniswapV2Pair.json "bytecode" field
keccak256(hex'60806040526001600c5534801561001557600080fd5b5060405146908060526123868239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612281806101056000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a714610534578063d505accf1461053c578063dd62ed3e1461058d578063fff6cae9146105bb576101a9565b8063ba9a7a56146104fe578063bc25cf7714610506578063c45a01551461052c576101a9565b80637ecebe00116100d35780637ecebe001461046557806389afcb441461048b57806395d89b41146104ca578063a9059cbb146104d2576101a9565b80636a6278421461041157806370a08231146104375780637464fc3d1461045d576101a9565b806323b872dd116101665780633644e515116101405780633644e515146103cb578063485cc955146103d35780635909c0d5146104015780635a3d549314610409576101a9565b806323b872dd1461036f57806330adf81f146103a5578063313ce567146103ad576101a9565b8063022c0d9f146101ae57806306fdde031461023c5780630902f1ac146102b9578063095ea7b3146102f15780630dfe16811461033157806318160ddd14610355575b600080fd5b61023a600480360360808110156101c457600080fd5b8135916020810135916001600160a01b0360408301351691908101906080810160608201356401000000008111156101fb57600080fd5b82018360208201111561020d57600080fd5b8035906020019184600183028401116401000000008311171561022f57600080fd5b5090925090506105c3565b005b610244610afe565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561027e578181015183820152602001610266565b50505050905090810190601f1680156102ab5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102c1610b24565b604080516001600160701b03948516815292909316602083015263ffffffff168183015290519081900360600190f35b61031d6004803603604081101561030757600080fd5b506001600160a01b038135169060200135610b4e565b604080519115158252519081900360200190f35b610339610b65565b604080516001600160a01b039092168252519081900360200190f35b61035d610b74565b60408051918252519081900360200190f35b61031d6004803603606081101561038557600080fd5b506001600160a01b03813581169160208101359091169060400135610b7a565b61035d610c14565b6103b5610c38565b6040805160ff9092168252519081900360200190f35b61035d610c3d565b61023a600480360360408110156103e957600080fd5b506001600160a01b0381358116916020013516610c43565b61035d610cc7565b61035d610ccd565b61035d6004803603602081101561042757600080fd5b50356001600160a01b0316610cd3565b61035d6004803603602081101561044d57600080fd5b50356001600160a01b0316610fd3565b61035d610fe5565b61035d6004803603602081101561047b57600080fd5b50356001600160a01b0316610feb565b6104b1600480360360208110156104a157600080fd5b50356001600160a01b0316610ffd565b6040805192835260208301919091528051918290030190f35b6102446113a3565b61031d600480360360408110156104e857600080fd5b506001600160a01b0381351690602001356113c5565b61035d6113d2565b61023a6004803603602081101561051c57600080fd5b50356001600160a01b03166113d8565b610339611543565b610339611552565b61023a600480360360e081101561055257600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611561565b61035d600480360360408110156105a357600080fd5b506001600160a01b0381358116916020013516611763565b61023a611780565b600c5460011461060e576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55841515806106215750600084115b61065c5760405162461bcd60e51b81526004018080602001828103825260258152602001806121936025913960400191505060405180910390fd5b600080610667610b24565b5091509150816001600160701b03168710801561068c5750806001600160701b031686105b6106c75760405162461bcd60e51b81526004018080602001828103825260218152602001806121dc6021913960400191505060405180910390fd5b60065460075460009182916001600160a01b039182169190811690891682148015906107055750806001600160a01b0316896001600160a01b031614155b61074e576040805162461bcd60e51b8152602060048201526015602482015274556e697377617056323a20494e56414c49445f544f60581b604482015290519081900360640190fd5b8a1561075f5761075f828a8d6118e2565b891561077057610770818a8c6118e2565b861561082b57886001600160a01b03166310d1e85c338d8d8c8c6040518663ffffffff1660e01b815260040180866001600160a01b03166001600160a01b03168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b15801561081257600080fd5b505af1158015610826573d6000803e3d6000fd5b505050505b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561087157600080fd5b505afa158015610885573d6000803e3d6000fd5b505050506040513d602081101561089b57600080fd5b5051604080516370a0823160e01b815230600482015290519195506001600160a01b038316916370a0823191602480820192602092909190829003018186803b1580156108e757600080fd5b505afa1580156108fb573d6000803e3d6000fd5b505050506040513d602081101561091157600080fd5b5051925060009150506001600160701b0385168a90038311610934576000610943565b89856001600160701b03160383035b9050600089856001600160701b031603831161096057600061096f565b89856001600160701b03160383035b905060008211806109805750600081115b6109bb5760405162461bcd60e51b81526004018080602001828103825260248152602001806121b86024913960400191505060405180910390fd5b60006109ef6109d184600363ffffffff611a7c16565b6109e3876103e863ffffffff611a7c16565b9063ffffffff611adf16565b90506000610a076109d184600363ffffffff611a7c16565b9050610a38620f4240610a2c6001600160701b038b8116908b1663ffffffff611a7c16565b9063ffffffff611a7c16565b610a48838363ffffffff611a7c16565b1015610a8a576040805162461bcd60e51b815260206004820152600c60248201526b556e697377617056323a204b60a01b604482015290519081900360640190fd5b5050610a9884848888611b2f565b60408051838152602081018390528082018d9052606081018c905290516001600160a01b038b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a8152602001692ab734b9bbb0b8102b1960b11b81525081565b6008546001600160701b0380821692600160701b830490911691600160e01b900463ffffffff1690565b6000610b5b338484611cf4565b5060015b92915050565b6006546001600160a01b031681565b60005481565b6001600160a01b038316600090815260026020908152604080832033845290915281205460001914610bff576001600160a01b0384166000908152600260209081526040808320338452909152902054610bda908363ffffffff611adf16565b6001600160a01b03851660009081526002602090815260408083203384529091529020555b610c0a848484611d56565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b6005546001600160a01b03163314610c99576040805162461bcd60e51b81526020600482015260146024820152732ab734b9bbb0b82b191d102327a92124a22222a760611b604482015290519081900360640190fd5b600680546001600160a01b039384166001600160a01b03199182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c54600114610d20576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c81905580610d30610b24565b50600654604080516370a0823160e01b815230600482015290519395509193506000926001600160a01b03909116916370a08231916024808301926020929190829003018186803b158015610d8457600080fd5b505afa158015610d98573d6000803e3d6000fd5b505050506040513d6020811015610dae57600080fd5b5051600754604080516370a0823160e01b815230600482015290519293506000926001600160a01b03909216916370a0823191602480820192602092909190829003018186803b158015610e0157600080fd5b505afa158015610e15573d6000803e3d6000fd5b505050506040513d6020811015610e2b57600080fd5b505190506000610e4a836001600160701b03871663ffffffff611adf16565b90506000610e67836001600160701b03871663ffffffff611adf16565b90506000610e758787611e10565b60005490915080610eb257610e9e6103e86109e3610e99878763ffffffff611a7c16565b611f6e565b9850610ead60006103e8611fc0565b610f01565b610efe6001600160701b038916610ecf868463ffffffff611a7c16565b81610ed657fe5b046001600160701b038916610ef1868563ffffffff611a7c16565b81610ef857fe5b04612056565b98505b60008911610f405760405162461bcd60e51b81526004018080602001828103825260288152602001806122256028913960400191505060405180910390fd5b610f4a8a8a611fc0565b610f5686868a8a611b2f565b8115610f8657600854610f82906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461104b576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c8190558061105b610b24565b50600654600754604080516370a0823160e01b815230600482015290519496509294506001600160a01b039182169391169160009184916370a08231916024808301926020929190829003018186803b1580156110b757600080fd5b505afa1580156110cb573d6000803e3d6000fd5b505050506040513d60208110156110e157600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038516916370a08231916024808301926020929190829003018186803b15801561112f57600080fd5b505afa158015611143573d6000803e3d6000fd5b505050506040513d602081101561115957600080fd5b5051306000908152600160205260408120549192506111788888611e10565b6000549091508061118f848763ffffffff611a7c16565b8161119657fe5b049a50806111aa848663ffffffff611a7c16565b816111b157fe5b04995060008b1180156111c4575060008a115b6111ff5760405162461bcd60e51b81526004018080602001828103825260288152602001806121fd6028913960400191505060405180910390fd5b611209308461206e565b611214878d8d6118e2565b61121f868d8c6118e2565b604080516370a0823160e01b815230600482015290516001600160a01b038916916370a08231916024808301926020929190829003018186803b15801561126557600080fd5b505afa158015611279573d6000803e3d6000fd5b505050506040513d602081101561128f57600080fd5b5051604080516370a0823160e01b815230600482015290519196506001600160a01b038816916370a0823191602480820192602092909190829003018186803b1580156112db57600080fd5b505afa1580156112ef573d6000803e3d6000fd5b505050506040513d602081101561130557600080fd5b5051935061131585858b8b611b2f565b811561134557600854611341906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b604080518c8152602081018c905281516001600160a01b038f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b604051806040016040528060068152602001652aa72496ab1960d11b81525081565b6000610b5b338484611d56565b6103e881565b600c54600114611423576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654600754600854604080516370a0823160e01b815230600482015290516001600160a01b0394851694909316926114d292859287926114cd926001600160701b03169185916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b505afa1580156114a9573d6000803e3d6000fd5b505050506040513d60208110156114bf57600080fd5b50519063ffffffff611adf16565b6118e2565b600854604080516370a0823160e01b8152306004820152905161153992849287926114cd92600160701b90046001600160701b0316916001600160a01b038616916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b50506001600c5550565b6005546001600160a01b031681565b6007546001600160a01b031681565b428410156115ab576040805162461bcd60e51b8152602060048201526012602482015271155b9a5cddd85c158c8e881156141254915160721b604482015290519081900360640190fd5b6003546001600160a01b0380891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e08501825280519083012061190160f01b6101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e280820193601f1981019281900390910190855afa1580156116c6573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906116fc5750886001600160a01b0316816001600160a01b0316145b61174d576040805162461bcd60e51b815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611758898989611cf4565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c546001146117cb576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654604080516370a0823160e01b815230600482015290516118db926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561181c57600080fd5b505afa158015611830573d6000803e3d6000fd5b505050506040513d602081101561184657600080fd5b5051600754604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b15801561189357600080fd5b505afa1580156118a7573d6000803e3d6000fd5b505050506040513d60208110156118bd57600080fd5b50516008546001600160701b0380821691600160701b900416611b2f565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e74323536290000000000000060209182015281516001600160a01b0385811660248301526044808301869052845180840390910181526064909201845291810180516001600160e01b031663a9059cbb60e01b1781529251815160009460609489169392918291908083835b6020831061198f5780518252601f199092019160209182019101611970565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146119f1576040519150601f19603f3d011682016040523d82523d6000602084013e6119f6565b606091505b5091509150818015611a24575080511580611a245750808060200190516020811015611a2157600080fd5b50515b611a75576040805162461bcd60e51b815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b6000811580611a9757505080820282828281611a9457fe5b04145b610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820382811115610b5f576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6001600160701b038411801590611b4d57506001600160701b038311155b611b94576040805162461bcd60e51b8152602060048201526013602482015272556e697377617056323a204f564552464c4f5760681b604482015290519081900360640190fd5b60085463ffffffff42811691600160e01b90048116820390811615801590611bc457506001600160701b03841615155b8015611bd857506001600160701b03831615155b15611c49578063ffffffff16611c0685611bf18661210c565b6001600160e01b03169063ffffffff61211e16565b600980546001600160e01b03929092169290920201905563ffffffff8116611c3184611bf18761210c565b600a80546001600160e01b0392909216929092020190555b600880546dffffffffffffffffffffffffffff19166001600160701b03888116919091176dffffffffffffffffffffffffffff60701b1916600160701b8883168102919091176001600160e01b0316600160e01b63ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316600090815260016020526040902054611d7f908263ffffffff611adf16565b6001600160a01b038085166000908152600160205260408082209390935590841681522054611db4908263ffffffff61214316565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611e6157600080fd5b505afa158015611e75573d6000803e3d6000fd5b505050506040513d6020811015611e8b57600080fd5b5051600b546001600160a01b038216158015945091925090611f5a578015611f55576000611ece610e996001600160701b0388811690881663ffffffff611a7c16565b90506000611edb83611f6e565b905080821115611f52576000611f09611efa848463ffffffff611adf16565b6000549063ffffffff611a7c16565b90506000611f2e83611f2286600563ffffffff611a7c16565b9063ffffffff61214316565b90506000818381611f3b57fe5b0490508015611f4e57611f4e8782611fc0565b5050505b50505b611f66565b8015611f66576000600b555b505092915050565b60006003821115611fb1575080600160028204015b81811015611fab57809150600281828581611f9a57fe5b040181611fa357fe5b049050611f83565b50611fbb565b8115611fbb575060015b919050565b600054611fd3908263ffffffff61214316565b60009081556001600160a01b038316815260016020526040902054611ffe908263ffffffff61214316565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008183106120655781612067565b825b9392505050565b6001600160a01b038216600090815260016020526040902054612097908263ffffffff611adf16565b6001600160a01b038316600090815260016020526040812091909155546120c4908263ffffffff611adf16565b60009081556040805183815290516001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6001600160701b0316600160701b0290565b60006001600160701b0382166001600160e01b0384168161213b57fe5b049392505050565b80820182811015610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a7231582082fba8557d35ae5eca98219a61e967d398ed8eaafeafa5fe5af73dd6aad9ddfd64736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429') // init code hash
))));
}
| // calculates the CREATE2 address for a pair without making any external calls | LineComment | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
604,
19457
]
} | 2,474 |
||
DMGYieldFarmingRouter | contracts/external/farming/libs/UniswapV2Library.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | UniswapV2Library | library UniswapV2Library {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
// Taken from the UniswapV2Pair.json "bytecode" field
keccak256(hex'60806040526001600c5534801561001557600080fd5b5060405146908060526123868239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612281806101056000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a714610534578063d505accf1461053c578063dd62ed3e1461058d578063fff6cae9146105bb576101a9565b8063ba9a7a56146104fe578063bc25cf7714610506578063c45a01551461052c576101a9565b80637ecebe00116100d35780637ecebe001461046557806389afcb441461048b57806395d89b41146104ca578063a9059cbb146104d2576101a9565b80636a6278421461041157806370a08231146104375780637464fc3d1461045d576101a9565b806323b872dd116101665780633644e515116101405780633644e515146103cb578063485cc955146103d35780635909c0d5146104015780635a3d549314610409576101a9565b806323b872dd1461036f57806330adf81f146103a5578063313ce567146103ad576101a9565b8063022c0d9f146101ae57806306fdde031461023c5780630902f1ac146102b9578063095ea7b3146102f15780630dfe16811461033157806318160ddd14610355575b600080fd5b61023a600480360360808110156101c457600080fd5b8135916020810135916001600160a01b0360408301351691908101906080810160608201356401000000008111156101fb57600080fd5b82018360208201111561020d57600080fd5b8035906020019184600183028401116401000000008311171561022f57600080fd5b5090925090506105c3565b005b610244610afe565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561027e578181015183820152602001610266565b50505050905090810190601f1680156102ab5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102c1610b24565b604080516001600160701b03948516815292909316602083015263ffffffff168183015290519081900360600190f35b61031d6004803603604081101561030757600080fd5b506001600160a01b038135169060200135610b4e565b604080519115158252519081900360200190f35b610339610b65565b604080516001600160a01b039092168252519081900360200190f35b61035d610b74565b60408051918252519081900360200190f35b61031d6004803603606081101561038557600080fd5b506001600160a01b03813581169160208101359091169060400135610b7a565b61035d610c14565b6103b5610c38565b6040805160ff9092168252519081900360200190f35b61035d610c3d565b61023a600480360360408110156103e957600080fd5b506001600160a01b0381358116916020013516610c43565b61035d610cc7565b61035d610ccd565b61035d6004803603602081101561042757600080fd5b50356001600160a01b0316610cd3565b61035d6004803603602081101561044d57600080fd5b50356001600160a01b0316610fd3565b61035d610fe5565b61035d6004803603602081101561047b57600080fd5b50356001600160a01b0316610feb565b6104b1600480360360208110156104a157600080fd5b50356001600160a01b0316610ffd565b6040805192835260208301919091528051918290030190f35b6102446113a3565b61031d600480360360408110156104e857600080fd5b506001600160a01b0381351690602001356113c5565b61035d6113d2565b61023a6004803603602081101561051c57600080fd5b50356001600160a01b03166113d8565b610339611543565b610339611552565b61023a600480360360e081101561055257600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611561565b61035d600480360360408110156105a357600080fd5b506001600160a01b0381358116916020013516611763565b61023a611780565b600c5460011461060e576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55841515806106215750600084115b61065c5760405162461bcd60e51b81526004018080602001828103825260258152602001806121936025913960400191505060405180910390fd5b600080610667610b24565b5091509150816001600160701b03168710801561068c5750806001600160701b031686105b6106c75760405162461bcd60e51b81526004018080602001828103825260218152602001806121dc6021913960400191505060405180910390fd5b60065460075460009182916001600160a01b039182169190811690891682148015906107055750806001600160a01b0316896001600160a01b031614155b61074e576040805162461bcd60e51b8152602060048201526015602482015274556e697377617056323a20494e56414c49445f544f60581b604482015290519081900360640190fd5b8a1561075f5761075f828a8d6118e2565b891561077057610770818a8c6118e2565b861561082b57886001600160a01b03166310d1e85c338d8d8c8c6040518663ffffffff1660e01b815260040180866001600160a01b03166001600160a01b03168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b15801561081257600080fd5b505af1158015610826573d6000803e3d6000fd5b505050505b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561087157600080fd5b505afa158015610885573d6000803e3d6000fd5b505050506040513d602081101561089b57600080fd5b5051604080516370a0823160e01b815230600482015290519195506001600160a01b038316916370a0823191602480820192602092909190829003018186803b1580156108e757600080fd5b505afa1580156108fb573d6000803e3d6000fd5b505050506040513d602081101561091157600080fd5b5051925060009150506001600160701b0385168a90038311610934576000610943565b89856001600160701b03160383035b9050600089856001600160701b031603831161096057600061096f565b89856001600160701b03160383035b905060008211806109805750600081115b6109bb5760405162461bcd60e51b81526004018080602001828103825260248152602001806121b86024913960400191505060405180910390fd5b60006109ef6109d184600363ffffffff611a7c16565b6109e3876103e863ffffffff611a7c16565b9063ffffffff611adf16565b90506000610a076109d184600363ffffffff611a7c16565b9050610a38620f4240610a2c6001600160701b038b8116908b1663ffffffff611a7c16565b9063ffffffff611a7c16565b610a48838363ffffffff611a7c16565b1015610a8a576040805162461bcd60e51b815260206004820152600c60248201526b556e697377617056323a204b60a01b604482015290519081900360640190fd5b5050610a9884848888611b2f565b60408051838152602081018390528082018d9052606081018c905290516001600160a01b038b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a8152602001692ab734b9bbb0b8102b1960b11b81525081565b6008546001600160701b0380821692600160701b830490911691600160e01b900463ffffffff1690565b6000610b5b338484611cf4565b5060015b92915050565b6006546001600160a01b031681565b60005481565b6001600160a01b038316600090815260026020908152604080832033845290915281205460001914610bff576001600160a01b0384166000908152600260209081526040808320338452909152902054610bda908363ffffffff611adf16565b6001600160a01b03851660009081526002602090815260408083203384529091529020555b610c0a848484611d56565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b6005546001600160a01b03163314610c99576040805162461bcd60e51b81526020600482015260146024820152732ab734b9bbb0b82b191d102327a92124a22222a760611b604482015290519081900360640190fd5b600680546001600160a01b039384166001600160a01b03199182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c54600114610d20576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c81905580610d30610b24565b50600654604080516370a0823160e01b815230600482015290519395509193506000926001600160a01b03909116916370a08231916024808301926020929190829003018186803b158015610d8457600080fd5b505afa158015610d98573d6000803e3d6000fd5b505050506040513d6020811015610dae57600080fd5b5051600754604080516370a0823160e01b815230600482015290519293506000926001600160a01b03909216916370a0823191602480820192602092909190829003018186803b158015610e0157600080fd5b505afa158015610e15573d6000803e3d6000fd5b505050506040513d6020811015610e2b57600080fd5b505190506000610e4a836001600160701b03871663ffffffff611adf16565b90506000610e67836001600160701b03871663ffffffff611adf16565b90506000610e758787611e10565b60005490915080610eb257610e9e6103e86109e3610e99878763ffffffff611a7c16565b611f6e565b9850610ead60006103e8611fc0565b610f01565b610efe6001600160701b038916610ecf868463ffffffff611a7c16565b81610ed657fe5b046001600160701b038916610ef1868563ffffffff611a7c16565b81610ef857fe5b04612056565b98505b60008911610f405760405162461bcd60e51b81526004018080602001828103825260288152602001806122256028913960400191505060405180910390fd5b610f4a8a8a611fc0565b610f5686868a8a611b2f565b8115610f8657600854610f82906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461104b576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c8190558061105b610b24565b50600654600754604080516370a0823160e01b815230600482015290519496509294506001600160a01b039182169391169160009184916370a08231916024808301926020929190829003018186803b1580156110b757600080fd5b505afa1580156110cb573d6000803e3d6000fd5b505050506040513d60208110156110e157600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038516916370a08231916024808301926020929190829003018186803b15801561112f57600080fd5b505afa158015611143573d6000803e3d6000fd5b505050506040513d602081101561115957600080fd5b5051306000908152600160205260408120549192506111788888611e10565b6000549091508061118f848763ffffffff611a7c16565b8161119657fe5b049a50806111aa848663ffffffff611a7c16565b816111b157fe5b04995060008b1180156111c4575060008a115b6111ff5760405162461bcd60e51b81526004018080602001828103825260288152602001806121fd6028913960400191505060405180910390fd5b611209308461206e565b611214878d8d6118e2565b61121f868d8c6118e2565b604080516370a0823160e01b815230600482015290516001600160a01b038916916370a08231916024808301926020929190829003018186803b15801561126557600080fd5b505afa158015611279573d6000803e3d6000fd5b505050506040513d602081101561128f57600080fd5b5051604080516370a0823160e01b815230600482015290519196506001600160a01b038816916370a0823191602480820192602092909190829003018186803b1580156112db57600080fd5b505afa1580156112ef573d6000803e3d6000fd5b505050506040513d602081101561130557600080fd5b5051935061131585858b8b611b2f565b811561134557600854611341906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b604080518c8152602081018c905281516001600160a01b038f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b604051806040016040528060068152602001652aa72496ab1960d11b81525081565b6000610b5b338484611d56565b6103e881565b600c54600114611423576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654600754600854604080516370a0823160e01b815230600482015290516001600160a01b0394851694909316926114d292859287926114cd926001600160701b03169185916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b505afa1580156114a9573d6000803e3d6000fd5b505050506040513d60208110156114bf57600080fd5b50519063ffffffff611adf16565b6118e2565b600854604080516370a0823160e01b8152306004820152905161153992849287926114cd92600160701b90046001600160701b0316916001600160a01b038616916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b50506001600c5550565b6005546001600160a01b031681565b6007546001600160a01b031681565b428410156115ab576040805162461bcd60e51b8152602060048201526012602482015271155b9a5cddd85c158c8e881156141254915160721b604482015290519081900360640190fd5b6003546001600160a01b0380891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e08501825280519083012061190160f01b6101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e280820193601f1981019281900390910190855afa1580156116c6573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906116fc5750886001600160a01b0316816001600160a01b0316145b61174d576040805162461bcd60e51b815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611758898989611cf4565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c546001146117cb576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654604080516370a0823160e01b815230600482015290516118db926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561181c57600080fd5b505afa158015611830573d6000803e3d6000fd5b505050506040513d602081101561184657600080fd5b5051600754604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b15801561189357600080fd5b505afa1580156118a7573d6000803e3d6000fd5b505050506040513d60208110156118bd57600080fd5b50516008546001600160701b0380821691600160701b900416611b2f565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e74323536290000000000000060209182015281516001600160a01b0385811660248301526044808301869052845180840390910181526064909201845291810180516001600160e01b031663a9059cbb60e01b1781529251815160009460609489169392918291908083835b6020831061198f5780518252601f199092019160209182019101611970565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146119f1576040519150601f19603f3d011682016040523d82523d6000602084013e6119f6565b606091505b5091509150818015611a24575080511580611a245750808060200190516020811015611a2157600080fd5b50515b611a75576040805162461bcd60e51b815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b6000811580611a9757505080820282828281611a9457fe5b04145b610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820382811115610b5f576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6001600160701b038411801590611b4d57506001600160701b038311155b611b94576040805162461bcd60e51b8152602060048201526013602482015272556e697377617056323a204f564552464c4f5760681b604482015290519081900360640190fd5b60085463ffffffff42811691600160e01b90048116820390811615801590611bc457506001600160701b03841615155b8015611bd857506001600160701b03831615155b15611c49578063ffffffff16611c0685611bf18661210c565b6001600160e01b03169063ffffffff61211e16565b600980546001600160e01b03929092169290920201905563ffffffff8116611c3184611bf18761210c565b600a80546001600160e01b0392909216929092020190555b600880546dffffffffffffffffffffffffffff19166001600160701b03888116919091176dffffffffffffffffffffffffffff60701b1916600160701b8883168102919091176001600160e01b0316600160e01b63ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316600090815260016020526040902054611d7f908263ffffffff611adf16565b6001600160a01b038085166000908152600160205260408082209390935590841681522054611db4908263ffffffff61214316565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611e6157600080fd5b505afa158015611e75573d6000803e3d6000fd5b505050506040513d6020811015611e8b57600080fd5b5051600b546001600160a01b038216158015945091925090611f5a578015611f55576000611ece610e996001600160701b0388811690881663ffffffff611a7c16565b90506000611edb83611f6e565b905080821115611f52576000611f09611efa848463ffffffff611adf16565b6000549063ffffffff611a7c16565b90506000611f2e83611f2286600563ffffffff611a7c16565b9063ffffffff61214316565b90506000818381611f3b57fe5b0490508015611f4e57611f4e8782611fc0565b5050505b50505b611f66565b8015611f66576000600b555b505092915050565b60006003821115611fb1575080600160028204015b81811015611fab57809150600281828581611f9a57fe5b040181611fa357fe5b049050611f83565b50611fbb565b8115611fbb575060015b919050565b600054611fd3908263ffffffff61214316565b60009081556001600160a01b038316815260016020526040902054611ffe908263ffffffff61214316565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008183106120655781612067565b825b9392505050565b6001600160a01b038216600090815260016020526040902054612097908263ffffffff611adf16565b6001600160a01b038316600090815260016020526040812091909155546120c4908263ffffffff611adf16565b60009081556040805183815290516001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6001600160701b0316600160701b0290565b60006001600160701b0382166001600160e01b0384168161213b57fe5b049392505050565b80820182811015610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a7231582082fba8557d35ae5eca98219a61e967d398ed8eaafeafa5fe5af73dd6aad9ddfd64736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429') // init code hash
))));
}
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
} | getReserves | function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
| // fetches and sorts the reserves for a pair | LineComment | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
19510,
19906
]
} | 2,475 |
||
DMGYieldFarmingRouter | contracts/external/farming/libs/UniswapV2Library.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | UniswapV2Library | library UniswapV2Library {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
// Taken from the UniswapV2Pair.json "bytecode" field
keccak256(hex'60806040526001600c5534801561001557600080fd5b5060405146908060526123868239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612281806101056000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a714610534578063d505accf1461053c578063dd62ed3e1461058d578063fff6cae9146105bb576101a9565b8063ba9a7a56146104fe578063bc25cf7714610506578063c45a01551461052c576101a9565b80637ecebe00116100d35780637ecebe001461046557806389afcb441461048b57806395d89b41146104ca578063a9059cbb146104d2576101a9565b80636a6278421461041157806370a08231146104375780637464fc3d1461045d576101a9565b806323b872dd116101665780633644e515116101405780633644e515146103cb578063485cc955146103d35780635909c0d5146104015780635a3d549314610409576101a9565b806323b872dd1461036f57806330adf81f146103a5578063313ce567146103ad576101a9565b8063022c0d9f146101ae57806306fdde031461023c5780630902f1ac146102b9578063095ea7b3146102f15780630dfe16811461033157806318160ddd14610355575b600080fd5b61023a600480360360808110156101c457600080fd5b8135916020810135916001600160a01b0360408301351691908101906080810160608201356401000000008111156101fb57600080fd5b82018360208201111561020d57600080fd5b8035906020019184600183028401116401000000008311171561022f57600080fd5b5090925090506105c3565b005b610244610afe565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561027e578181015183820152602001610266565b50505050905090810190601f1680156102ab5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102c1610b24565b604080516001600160701b03948516815292909316602083015263ffffffff168183015290519081900360600190f35b61031d6004803603604081101561030757600080fd5b506001600160a01b038135169060200135610b4e565b604080519115158252519081900360200190f35b610339610b65565b604080516001600160a01b039092168252519081900360200190f35b61035d610b74565b60408051918252519081900360200190f35b61031d6004803603606081101561038557600080fd5b506001600160a01b03813581169160208101359091169060400135610b7a565b61035d610c14565b6103b5610c38565b6040805160ff9092168252519081900360200190f35b61035d610c3d565b61023a600480360360408110156103e957600080fd5b506001600160a01b0381358116916020013516610c43565b61035d610cc7565b61035d610ccd565b61035d6004803603602081101561042757600080fd5b50356001600160a01b0316610cd3565b61035d6004803603602081101561044d57600080fd5b50356001600160a01b0316610fd3565b61035d610fe5565b61035d6004803603602081101561047b57600080fd5b50356001600160a01b0316610feb565b6104b1600480360360208110156104a157600080fd5b50356001600160a01b0316610ffd565b6040805192835260208301919091528051918290030190f35b6102446113a3565b61031d600480360360408110156104e857600080fd5b506001600160a01b0381351690602001356113c5565b61035d6113d2565b61023a6004803603602081101561051c57600080fd5b50356001600160a01b03166113d8565b610339611543565b610339611552565b61023a600480360360e081101561055257600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611561565b61035d600480360360408110156105a357600080fd5b506001600160a01b0381358116916020013516611763565b61023a611780565b600c5460011461060e576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55841515806106215750600084115b61065c5760405162461bcd60e51b81526004018080602001828103825260258152602001806121936025913960400191505060405180910390fd5b600080610667610b24565b5091509150816001600160701b03168710801561068c5750806001600160701b031686105b6106c75760405162461bcd60e51b81526004018080602001828103825260218152602001806121dc6021913960400191505060405180910390fd5b60065460075460009182916001600160a01b039182169190811690891682148015906107055750806001600160a01b0316896001600160a01b031614155b61074e576040805162461bcd60e51b8152602060048201526015602482015274556e697377617056323a20494e56414c49445f544f60581b604482015290519081900360640190fd5b8a1561075f5761075f828a8d6118e2565b891561077057610770818a8c6118e2565b861561082b57886001600160a01b03166310d1e85c338d8d8c8c6040518663ffffffff1660e01b815260040180866001600160a01b03166001600160a01b03168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b15801561081257600080fd5b505af1158015610826573d6000803e3d6000fd5b505050505b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561087157600080fd5b505afa158015610885573d6000803e3d6000fd5b505050506040513d602081101561089b57600080fd5b5051604080516370a0823160e01b815230600482015290519195506001600160a01b038316916370a0823191602480820192602092909190829003018186803b1580156108e757600080fd5b505afa1580156108fb573d6000803e3d6000fd5b505050506040513d602081101561091157600080fd5b5051925060009150506001600160701b0385168a90038311610934576000610943565b89856001600160701b03160383035b9050600089856001600160701b031603831161096057600061096f565b89856001600160701b03160383035b905060008211806109805750600081115b6109bb5760405162461bcd60e51b81526004018080602001828103825260248152602001806121b86024913960400191505060405180910390fd5b60006109ef6109d184600363ffffffff611a7c16565b6109e3876103e863ffffffff611a7c16565b9063ffffffff611adf16565b90506000610a076109d184600363ffffffff611a7c16565b9050610a38620f4240610a2c6001600160701b038b8116908b1663ffffffff611a7c16565b9063ffffffff611a7c16565b610a48838363ffffffff611a7c16565b1015610a8a576040805162461bcd60e51b815260206004820152600c60248201526b556e697377617056323a204b60a01b604482015290519081900360640190fd5b5050610a9884848888611b2f565b60408051838152602081018390528082018d9052606081018c905290516001600160a01b038b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a8152602001692ab734b9bbb0b8102b1960b11b81525081565b6008546001600160701b0380821692600160701b830490911691600160e01b900463ffffffff1690565b6000610b5b338484611cf4565b5060015b92915050565b6006546001600160a01b031681565b60005481565b6001600160a01b038316600090815260026020908152604080832033845290915281205460001914610bff576001600160a01b0384166000908152600260209081526040808320338452909152902054610bda908363ffffffff611adf16565b6001600160a01b03851660009081526002602090815260408083203384529091529020555b610c0a848484611d56565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b6005546001600160a01b03163314610c99576040805162461bcd60e51b81526020600482015260146024820152732ab734b9bbb0b82b191d102327a92124a22222a760611b604482015290519081900360640190fd5b600680546001600160a01b039384166001600160a01b03199182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c54600114610d20576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c81905580610d30610b24565b50600654604080516370a0823160e01b815230600482015290519395509193506000926001600160a01b03909116916370a08231916024808301926020929190829003018186803b158015610d8457600080fd5b505afa158015610d98573d6000803e3d6000fd5b505050506040513d6020811015610dae57600080fd5b5051600754604080516370a0823160e01b815230600482015290519293506000926001600160a01b03909216916370a0823191602480820192602092909190829003018186803b158015610e0157600080fd5b505afa158015610e15573d6000803e3d6000fd5b505050506040513d6020811015610e2b57600080fd5b505190506000610e4a836001600160701b03871663ffffffff611adf16565b90506000610e67836001600160701b03871663ffffffff611adf16565b90506000610e758787611e10565b60005490915080610eb257610e9e6103e86109e3610e99878763ffffffff611a7c16565b611f6e565b9850610ead60006103e8611fc0565b610f01565b610efe6001600160701b038916610ecf868463ffffffff611a7c16565b81610ed657fe5b046001600160701b038916610ef1868563ffffffff611a7c16565b81610ef857fe5b04612056565b98505b60008911610f405760405162461bcd60e51b81526004018080602001828103825260288152602001806122256028913960400191505060405180910390fd5b610f4a8a8a611fc0565b610f5686868a8a611b2f565b8115610f8657600854610f82906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461104b576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c8190558061105b610b24565b50600654600754604080516370a0823160e01b815230600482015290519496509294506001600160a01b039182169391169160009184916370a08231916024808301926020929190829003018186803b1580156110b757600080fd5b505afa1580156110cb573d6000803e3d6000fd5b505050506040513d60208110156110e157600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038516916370a08231916024808301926020929190829003018186803b15801561112f57600080fd5b505afa158015611143573d6000803e3d6000fd5b505050506040513d602081101561115957600080fd5b5051306000908152600160205260408120549192506111788888611e10565b6000549091508061118f848763ffffffff611a7c16565b8161119657fe5b049a50806111aa848663ffffffff611a7c16565b816111b157fe5b04995060008b1180156111c4575060008a115b6111ff5760405162461bcd60e51b81526004018080602001828103825260288152602001806121fd6028913960400191505060405180910390fd5b611209308461206e565b611214878d8d6118e2565b61121f868d8c6118e2565b604080516370a0823160e01b815230600482015290516001600160a01b038916916370a08231916024808301926020929190829003018186803b15801561126557600080fd5b505afa158015611279573d6000803e3d6000fd5b505050506040513d602081101561128f57600080fd5b5051604080516370a0823160e01b815230600482015290519196506001600160a01b038816916370a0823191602480820192602092909190829003018186803b1580156112db57600080fd5b505afa1580156112ef573d6000803e3d6000fd5b505050506040513d602081101561130557600080fd5b5051935061131585858b8b611b2f565b811561134557600854611341906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b604080518c8152602081018c905281516001600160a01b038f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b604051806040016040528060068152602001652aa72496ab1960d11b81525081565b6000610b5b338484611d56565b6103e881565b600c54600114611423576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654600754600854604080516370a0823160e01b815230600482015290516001600160a01b0394851694909316926114d292859287926114cd926001600160701b03169185916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b505afa1580156114a9573d6000803e3d6000fd5b505050506040513d60208110156114bf57600080fd5b50519063ffffffff611adf16565b6118e2565b600854604080516370a0823160e01b8152306004820152905161153992849287926114cd92600160701b90046001600160701b0316916001600160a01b038616916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b50506001600c5550565b6005546001600160a01b031681565b6007546001600160a01b031681565b428410156115ab576040805162461bcd60e51b8152602060048201526012602482015271155b9a5cddd85c158c8e881156141254915160721b604482015290519081900360640190fd5b6003546001600160a01b0380891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e08501825280519083012061190160f01b6101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e280820193601f1981019281900390910190855afa1580156116c6573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906116fc5750886001600160a01b0316816001600160a01b0316145b61174d576040805162461bcd60e51b815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611758898989611cf4565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c546001146117cb576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654604080516370a0823160e01b815230600482015290516118db926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561181c57600080fd5b505afa158015611830573d6000803e3d6000fd5b505050506040513d602081101561184657600080fd5b5051600754604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b15801561189357600080fd5b505afa1580156118a7573d6000803e3d6000fd5b505050506040513d60208110156118bd57600080fd5b50516008546001600160701b0380821691600160701b900416611b2f565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e74323536290000000000000060209182015281516001600160a01b0385811660248301526044808301869052845180840390910181526064909201845291810180516001600160e01b031663a9059cbb60e01b1781529251815160009460609489169392918291908083835b6020831061198f5780518252601f199092019160209182019101611970565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146119f1576040519150601f19603f3d011682016040523d82523d6000602084013e6119f6565b606091505b5091509150818015611a24575080511580611a245750808060200190516020811015611a2157600080fd5b50515b611a75576040805162461bcd60e51b815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b6000811580611a9757505080820282828281611a9457fe5b04145b610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820382811115610b5f576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6001600160701b038411801590611b4d57506001600160701b038311155b611b94576040805162461bcd60e51b8152602060048201526013602482015272556e697377617056323a204f564552464c4f5760681b604482015290519081900360640190fd5b60085463ffffffff42811691600160e01b90048116820390811615801590611bc457506001600160701b03841615155b8015611bd857506001600160701b03831615155b15611c49578063ffffffff16611c0685611bf18661210c565b6001600160e01b03169063ffffffff61211e16565b600980546001600160e01b03929092169290920201905563ffffffff8116611c3184611bf18761210c565b600a80546001600160e01b0392909216929092020190555b600880546dffffffffffffffffffffffffffff19166001600160701b03888116919091176dffffffffffffffffffffffffffff60701b1916600160701b8883168102919091176001600160e01b0316600160e01b63ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316600090815260016020526040902054611d7f908263ffffffff611adf16565b6001600160a01b038085166000908152600160205260408082209390935590841681522054611db4908263ffffffff61214316565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611e6157600080fd5b505afa158015611e75573d6000803e3d6000fd5b505050506040513d6020811015611e8b57600080fd5b5051600b546001600160a01b038216158015945091925090611f5a578015611f55576000611ece610e996001600160701b0388811690881663ffffffff611a7c16565b90506000611edb83611f6e565b905080821115611f52576000611f09611efa848463ffffffff611adf16565b6000549063ffffffff611a7c16565b90506000611f2e83611f2286600563ffffffff611a7c16565b9063ffffffff61214316565b90506000818381611f3b57fe5b0490508015611f4e57611f4e8782611fc0565b5050505b50505b611f66565b8015611f66576000600b555b505092915050565b60006003821115611fb1575080600160028204015b81811015611fab57809150600281828581611f9a57fe5b040181611fa357fe5b049050611f83565b50611fbb565b8115611fbb575060015b919050565b600054611fd3908263ffffffff61214316565b60009081556001600160a01b038316815260016020526040902054611ffe908263ffffffff61214316565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008183106120655781612067565b825b9392505050565b6001600160a01b038216600090815260016020526040902054612097908263ffffffff611adf16565b6001600160a01b038316600090815260016020526040812091909155546120c4908263ffffffff611adf16565b60009081556040805183815290516001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6001600160701b0316600160701b0290565b60006001600160701b0382166001600160e01b0384168161213b57fe5b049392505050565b80820182811015610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a7231582082fba8557d35ae5eca98219a61e967d398ed8eaafeafa5fe5af73dd6aad9ddfd64736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429') // init code hash
))));
}
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
} | quote | function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
| // given some amount of an asset and pair reserves, returns an equivalent amount of the other asset | LineComment | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
20014,
20340
]
} | 2,476 |
||
DMGYieldFarmingRouter | contracts/external/farming/libs/UniswapV2Library.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | UniswapV2Library | library UniswapV2Library {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
// Taken from the UniswapV2Pair.json "bytecode" field
keccak256(hex'60806040526001600c5534801561001557600080fd5b5060405146908060526123868239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612281806101056000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a714610534578063d505accf1461053c578063dd62ed3e1461058d578063fff6cae9146105bb576101a9565b8063ba9a7a56146104fe578063bc25cf7714610506578063c45a01551461052c576101a9565b80637ecebe00116100d35780637ecebe001461046557806389afcb441461048b57806395d89b41146104ca578063a9059cbb146104d2576101a9565b80636a6278421461041157806370a08231146104375780637464fc3d1461045d576101a9565b806323b872dd116101665780633644e515116101405780633644e515146103cb578063485cc955146103d35780635909c0d5146104015780635a3d549314610409576101a9565b806323b872dd1461036f57806330adf81f146103a5578063313ce567146103ad576101a9565b8063022c0d9f146101ae57806306fdde031461023c5780630902f1ac146102b9578063095ea7b3146102f15780630dfe16811461033157806318160ddd14610355575b600080fd5b61023a600480360360808110156101c457600080fd5b8135916020810135916001600160a01b0360408301351691908101906080810160608201356401000000008111156101fb57600080fd5b82018360208201111561020d57600080fd5b8035906020019184600183028401116401000000008311171561022f57600080fd5b5090925090506105c3565b005b610244610afe565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561027e578181015183820152602001610266565b50505050905090810190601f1680156102ab5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102c1610b24565b604080516001600160701b03948516815292909316602083015263ffffffff168183015290519081900360600190f35b61031d6004803603604081101561030757600080fd5b506001600160a01b038135169060200135610b4e565b604080519115158252519081900360200190f35b610339610b65565b604080516001600160a01b039092168252519081900360200190f35b61035d610b74565b60408051918252519081900360200190f35b61031d6004803603606081101561038557600080fd5b506001600160a01b03813581169160208101359091169060400135610b7a565b61035d610c14565b6103b5610c38565b6040805160ff9092168252519081900360200190f35b61035d610c3d565b61023a600480360360408110156103e957600080fd5b506001600160a01b0381358116916020013516610c43565b61035d610cc7565b61035d610ccd565b61035d6004803603602081101561042757600080fd5b50356001600160a01b0316610cd3565b61035d6004803603602081101561044d57600080fd5b50356001600160a01b0316610fd3565b61035d610fe5565b61035d6004803603602081101561047b57600080fd5b50356001600160a01b0316610feb565b6104b1600480360360208110156104a157600080fd5b50356001600160a01b0316610ffd565b6040805192835260208301919091528051918290030190f35b6102446113a3565b61031d600480360360408110156104e857600080fd5b506001600160a01b0381351690602001356113c5565b61035d6113d2565b61023a6004803603602081101561051c57600080fd5b50356001600160a01b03166113d8565b610339611543565b610339611552565b61023a600480360360e081101561055257600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611561565b61035d600480360360408110156105a357600080fd5b506001600160a01b0381358116916020013516611763565b61023a611780565b600c5460011461060e576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55841515806106215750600084115b61065c5760405162461bcd60e51b81526004018080602001828103825260258152602001806121936025913960400191505060405180910390fd5b600080610667610b24565b5091509150816001600160701b03168710801561068c5750806001600160701b031686105b6106c75760405162461bcd60e51b81526004018080602001828103825260218152602001806121dc6021913960400191505060405180910390fd5b60065460075460009182916001600160a01b039182169190811690891682148015906107055750806001600160a01b0316896001600160a01b031614155b61074e576040805162461bcd60e51b8152602060048201526015602482015274556e697377617056323a20494e56414c49445f544f60581b604482015290519081900360640190fd5b8a1561075f5761075f828a8d6118e2565b891561077057610770818a8c6118e2565b861561082b57886001600160a01b03166310d1e85c338d8d8c8c6040518663ffffffff1660e01b815260040180866001600160a01b03166001600160a01b03168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b15801561081257600080fd5b505af1158015610826573d6000803e3d6000fd5b505050505b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561087157600080fd5b505afa158015610885573d6000803e3d6000fd5b505050506040513d602081101561089b57600080fd5b5051604080516370a0823160e01b815230600482015290519195506001600160a01b038316916370a0823191602480820192602092909190829003018186803b1580156108e757600080fd5b505afa1580156108fb573d6000803e3d6000fd5b505050506040513d602081101561091157600080fd5b5051925060009150506001600160701b0385168a90038311610934576000610943565b89856001600160701b03160383035b9050600089856001600160701b031603831161096057600061096f565b89856001600160701b03160383035b905060008211806109805750600081115b6109bb5760405162461bcd60e51b81526004018080602001828103825260248152602001806121b86024913960400191505060405180910390fd5b60006109ef6109d184600363ffffffff611a7c16565b6109e3876103e863ffffffff611a7c16565b9063ffffffff611adf16565b90506000610a076109d184600363ffffffff611a7c16565b9050610a38620f4240610a2c6001600160701b038b8116908b1663ffffffff611a7c16565b9063ffffffff611a7c16565b610a48838363ffffffff611a7c16565b1015610a8a576040805162461bcd60e51b815260206004820152600c60248201526b556e697377617056323a204b60a01b604482015290519081900360640190fd5b5050610a9884848888611b2f565b60408051838152602081018390528082018d9052606081018c905290516001600160a01b038b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a8152602001692ab734b9bbb0b8102b1960b11b81525081565b6008546001600160701b0380821692600160701b830490911691600160e01b900463ffffffff1690565b6000610b5b338484611cf4565b5060015b92915050565b6006546001600160a01b031681565b60005481565b6001600160a01b038316600090815260026020908152604080832033845290915281205460001914610bff576001600160a01b0384166000908152600260209081526040808320338452909152902054610bda908363ffffffff611adf16565b6001600160a01b03851660009081526002602090815260408083203384529091529020555b610c0a848484611d56565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b6005546001600160a01b03163314610c99576040805162461bcd60e51b81526020600482015260146024820152732ab734b9bbb0b82b191d102327a92124a22222a760611b604482015290519081900360640190fd5b600680546001600160a01b039384166001600160a01b03199182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c54600114610d20576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c81905580610d30610b24565b50600654604080516370a0823160e01b815230600482015290519395509193506000926001600160a01b03909116916370a08231916024808301926020929190829003018186803b158015610d8457600080fd5b505afa158015610d98573d6000803e3d6000fd5b505050506040513d6020811015610dae57600080fd5b5051600754604080516370a0823160e01b815230600482015290519293506000926001600160a01b03909216916370a0823191602480820192602092909190829003018186803b158015610e0157600080fd5b505afa158015610e15573d6000803e3d6000fd5b505050506040513d6020811015610e2b57600080fd5b505190506000610e4a836001600160701b03871663ffffffff611adf16565b90506000610e67836001600160701b03871663ffffffff611adf16565b90506000610e758787611e10565b60005490915080610eb257610e9e6103e86109e3610e99878763ffffffff611a7c16565b611f6e565b9850610ead60006103e8611fc0565b610f01565b610efe6001600160701b038916610ecf868463ffffffff611a7c16565b81610ed657fe5b046001600160701b038916610ef1868563ffffffff611a7c16565b81610ef857fe5b04612056565b98505b60008911610f405760405162461bcd60e51b81526004018080602001828103825260288152602001806122256028913960400191505060405180910390fd5b610f4a8a8a611fc0565b610f5686868a8a611b2f565b8115610f8657600854610f82906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461104b576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c8190558061105b610b24565b50600654600754604080516370a0823160e01b815230600482015290519496509294506001600160a01b039182169391169160009184916370a08231916024808301926020929190829003018186803b1580156110b757600080fd5b505afa1580156110cb573d6000803e3d6000fd5b505050506040513d60208110156110e157600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038516916370a08231916024808301926020929190829003018186803b15801561112f57600080fd5b505afa158015611143573d6000803e3d6000fd5b505050506040513d602081101561115957600080fd5b5051306000908152600160205260408120549192506111788888611e10565b6000549091508061118f848763ffffffff611a7c16565b8161119657fe5b049a50806111aa848663ffffffff611a7c16565b816111b157fe5b04995060008b1180156111c4575060008a115b6111ff5760405162461bcd60e51b81526004018080602001828103825260288152602001806121fd6028913960400191505060405180910390fd5b611209308461206e565b611214878d8d6118e2565b61121f868d8c6118e2565b604080516370a0823160e01b815230600482015290516001600160a01b038916916370a08231916024808301926020929190829003018186803b15801561126557600080fd5b505afa158015611279573d6000803e3d6000fd5b505050506040513d602081101561128f57600080fd5b5051604080516370a0823160e01b815230600482015290519196506001600160a01b038816916370a0823191602480820192602092909190829003018186803b1580156112db57600080fd5b505afa1580156112ef573d6000803e3d6000fd5b505050506040513d602081101561130557600080fd5b5051935061131585858b8b611b2f565b811561134557600854611341906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b604080518c8152602081018c905281516001600160a01b038f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b604051806040016040528060068152602001652aa72496ab1960d11b81525081565b6000610b5b338484611d56565b6103e881565b600c54600114611423576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654600754600854604080516370a0823160e01b815230600482015290516001600160a01b0394851694909316926114d292859287926114cd926001600160701b03169185916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b505afa1580156114a9573d6000803e3d6000fd5b505050506040513d60208110156114bf57600080fd5b50519063ffffffff611adf16565b6118e2565b600854604080516370a0823160e01b8152306004820152905161153992849287926114cd92600160701b90046001600160701b0316916001600160a01b038616916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b50506001600c5550565b6005546001600160a01b031681565b6007546001600160a01b031681565b428410156115ab576040805162461bcd60e51b8152602060048201526012602482015271155b9a5cddd85c158c8e881156141254915160721b604482015290519081900360640190fd5b6003546001600160a01b0380891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e08501825280519083012061190160f01b6101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e280820193601f1981019281900390910190855afa1580156116c6573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906116fc5750886001600160a01b0316816001600160a01b0316145b61174d576040805162461bcd60e51b815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611758898989611cf4565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c546001146117cb576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654604080516370a0823160e01b815230600482015290516118db926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561181c57600080fd5b505afa158015611830573d6000803e3d6000fd5b505050506040513d602081101561184657600080fd5b5051600754604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b15801561189357600080fd5b505afa1580156118a7573d6000803e3d6000fd5b505050506040513d60208110156118bd57600080fd5b50516008546001600160701b0380821691600160701b900416611b2f565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e74323536290000000000000060209182015281516001600160a01b0385811660248301526044808301869052845180840390910181526064909201845291810180516001600160e01b031663a9059cbb60e01b1781529251815160009460609489169392918291908083835b6020831061198f5780518252601f199092019160209182019101611970565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146119f1576040519150601f19603f3d011682016040523d82523d6000602084013e6119f6565b606091505b5091509150818015611a24575080511580611a245750808060200190516020811015611a2157600080fd5b50515b611a75576040805162461bcd60e51b815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b6000811580611a9757505080820282828281611a9457fe5b04145b610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820382811115610b5f576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6001600160701b038411801590611b4d57506001600160701b038311155b611b94576040805162461bcd60e51b8152602060048201526013602482015272556e697377617056323a204f564552464c4f5760681b604482015290519081900360640190fd5b60085463ffffffff42811691600160e01b90048116820390811615801590611bc457506001600160701b03841615155b8015611bd857506001600160701b03831615155b15611c49578063ffffffff16611c0685611bf18661210c565b6001600160e01b03169063ffffffff61211e16565b600980546001600160e01b03929092169290920201905563ffffffff8116611c3184611bf18761210c565b600a80546001600160e01b0392909216929092020190555b600880546dffffffffffffffffffffffffffff19166001600160701b03888116919091176dffffffffffffffffffffffffffff60701b1916600160701b8883168102919091176001600160e01b0316600160e01b63ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316600090815260016020526040902054611d7f908263ffffffff611adf16565b6001600160a01b038085166000908152600160205260408082209390935590841681522054611db4908263ffffffff61214316565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611e6157600080fd5b505afa158015611e75573d6000803e3d6000fd5b505050506040513d6020811015611e8b57600080fd5b5051600b546001600160a01b038216158015945091925090611f5a578015611f55576000611ece610e996001600160701b0388811690881663ffffffff611a7c16565b90506000611edb83611f6e565b905080821115611f52576000611f09611efa848463ffffffff611adf16565b6000549063ffffffff611a7c16565b90506000611f2e83611f2286600563ffffffff611a7c16565b9063ffffffff61214316565b90506000818381611f3b57fe5b0490508015611f4e57611f4e8782611fc0565b5050505b50505b611f66565b8015611f66576000600b555b505092915050565b60006003821115611fb1575080600160028204015b81811015611fab57809150600281828581611f9a57fe5b040181611fa357fe5b049050611f83565b50611fbb565b8115611fbb575060015b919050565b600054611fd3908263ffffffff61214316565b60009081556001600160a01b038316815260016020526040902054611ffe908263ffffffff61214316565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008183106120655781612067565b825b9392505050565b6001600160a01b038216600090815260016020526040902054612097908263ffffffff611adf16565b6001600160a01b038316600090815260016020526040812091909155546120c4908263ffffffff611adf16565b60009081556040805183815290516001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6001600160701b0316600160701b0290565b60006001600160701b0382166001600160e01b0384168161213b57fe5b049392505050565b80820182811015610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a7231582082fba8557d35ae5eca98219a61e967d398ed8eaafeafa5fe5af73dd6aad9ddfd64736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429') // init code hash
))));
}
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
} | getAmountOut | function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
| // given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset | LineComment | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
20457,
20979
]
} | 2,477 |
||
DMGYieldFarmingRouter | contracts/external/farming/libs/UniswapV2Library.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | UniswapV2Library | library UniswapV2Library {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
// Taken from the UniswapV2Pair.json "bytecode" field
keccak256(hex'60806040526001600c5534801561001557600080fd5b5060405146908060526123868239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612281806101056000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a714610534578063d505accf1461053c578063dd62ed3e1461058d578063fff6cae9146105bb576101a9565b8063ba9a7a56146104fe578063bc25cf7714610506578063c45a01551461052c576101a9565b80637ecebe00116100d35780637ecebe001461046557806389afcb441461048b57806395d89b41146104ca578063a9059cbb146104d2576101a9565b80636a6278421461041157806370a08231146104375780637464fc3d1461045d576101a9565b806323b872dd116101665780633644e515116101405780633644e515146103cb578063485cc955146103d35780635909c0d5146104015780635a3d549314610409576101a9565b806323b872dd1461036f57806330adf81f146103a5578063313ce567146103ad576101a9565b8063022c0d9f146101ae57806306fdde031461023c5780630902f1ac146102b9578063095ea7b3146102f15780630dfe16811461033157806318160ddd14610355575b600080fd5b61023a600480360360808110156101c457600080fd5b8135916020810135916001600160a01b0360408301351691908101906080810160608201356401000000008111156101fb57600080fd5b82018360208201111561020d57600080fd5b8035906020019184600183028401116401000000008311171561022f57600080fd5b5090925090506105c3565b005b610244610afe565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561027e578181015183820152602001610266565b50505050905090810190601f1680156102ab5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102c1610b24565b604080516001600160701b03948516815292909316602083015263ffffffff168183015290519081900360600190f35b61031d6004803603604081101561030757600080fd5b506001600160a01b038135169060200135610b4e565b604080519115158252519081900360200190f35b610339610b65565b604080516001600160a01b039092168252519081900360200190f35b61035d610b74565b60408051918252519081900360200190f35b61031d6004803603606081101561038557600080fd5b506001600160a01b03813581169160208101359091169060400135610b7a565b61035d610c14565b6103b5610c38565b6040805160ff9092168252519081900360200190f35b61035d610c3d565b61023a600480360360408110156103e957600080fd5b506001600160a01b0381358116916020013516610c43565b61035d610cc7565b61035d610ccd565b61035d6004803603602081101561042757600080fd5b50356001600160a01b0316610cd3565b61035d6004803603602081101561044d57600080fd5b50356001600160a01b0316610fd3565b61035d610fe5565b61035d6004803603602081101561047b57600080fd5b50356001600160a01b0316610feb565b6104b1600480360360208110156104a157600080fd5b50356001600160a01b0316610ffd565b6040805192835260208301919091528051918290030190f35b6102446113a3565b61031d600480360360408110156104e857600080fd5b506001600160a01b0381351690602001356113c5565b61035d6113d2565b61023a6004803603602081101561051c57600080fd5b50356001600160a01b03166113d8565b610339611543565b610339611552565b61023a600480360360e081101561055257600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611561565b61035d600480360360408110156105a357600080fd5b506001600160a01b0381358116916020013516611763565b61023a611780565b600c5460011461060e576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55841515806106215750600084115b61065c5760405162461bcd60e51b81526004018080602001828103825260258152602001806121936025913960400191505060405180910390fd5b600080610667610b24565b5091509150816001600160701b03168710801561068c5750806001600160701b031686105b6106c75760405162461bcd60e51b81526004018080602001828103825260218152602001806121dc6021913960400191505060405180910390fd5b60065460075460009182916001600160a01b039182169190811690891682148015906107055750806001600160a01b0316896001600160a01b031614155b61074e576040805162461bcd60e51b8152602060048201526015602482015274556e697377617056323a20494e56414c49445f544f60581b604482015290519081900360640190fd5b8a1561075f5761075f828a8d6118e2565b891561077057610770818a8c6118e2565b861561082b57886001600160a01b03166310d1e85c338d8d8c8c6040518663ffffffff1660e01b815260040180866001600160a01b03166001600160a01b03168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b15801561081257600080fd5b505af1158015610826573d6000803e3d6000fd5b505050505b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561087157600080fd5b505afa158015610885573d6000803e3d6000fd5b505050506040513d602081101561089b57600080fd5b5051604080516370a0823160e01b815230600482015290519195506001600160a01b038316916370a0823191602480820192602092909190829003018186803b1580156108e757600080fd5b505afa1580156108fb573d6000803e3d6000fd5b505050506040513d602081101561091157600080fd5b5051925060009150506001600160701b0385168a90038311610934576000610943565b89856001600160701b03160383035b9050600089856001600160701b031603831161096057600061096f565b89856001600160701b03160383035b905060008211806109805750600081115b6109bb5760405162461bcd60e51b81526004018080602001828103825260248152602001806121b86024913960400191505060405180910390fd5b60006109ef6109d184600363ffffffff611a7c16565b6109e3876103e863ffffffff611a7c16565b9063ffffffff611adf16565b90506000610a076109d184600363ffffffff611a7c16565b9050610a38620f4240610a2c6001600160701b038b8116908b1663ffffffff611a7c16565b9063ffffffff611a7c16565b610a48838363ffffffff611a7c16565b1015610a8a576040805162461bcd60e51b815260206004820152600c60248201526b556e697377617056323a204b60a01b604482015290519081900360640190fd5b5050610a9884848888611b2f565b60408051838152602081018390528082018d9052606081018c905290516001600160a01b038b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a8152602001692ab734b9bbb0b8102b1960b11b81525081565b6008546001600160701b0380821692600160701b830490911691600160e01b900463ffffffff1690565b6000610b5b338484611cf4565b5060015b92915050565b6006546001600160a01b031681565b60005481565b6001600160a01b038316600090815260026020908152604080832033845290915281205460001914610bff576001600160a01b0384166000908152600260209081526040808320338452909152902054610bda908363ffffffff611adf16565b6001600160a01b03851660009081526002602090815260408083203384529091529020555b610c0a848484611d56565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b6005546001600160a01b03163314610c99576040805162461bcd60e51b81526020600482015260146024820152732ab734b9bbb0b82b191d102327a92124a22222a760611b604482015290519081900360640190fd5b600680546001600160a01b039384166001600160a01b03199182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c54600114610d20576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c81905580610d30610b24565b50600654604080516370a0823160e01b815230600482015290519395509193506000926001600160a01b03909116916370a08231916024808301926020929190829003018186803b158015610d8457600080fd5b505afa158015610d98573d6000803e3d6000fd5b505050506040513d6020811015610dae57600080fd5b5051600754604080516370a0823160e01b815230600482015290519293506000926001600160a01b03909216916370a0823191602480820192602092909190829003018186803b158015610e0157600080fd5b505afa158015610e15573d6000803e3d6000fd5b505050506040513d6020811015610e2b57600080fd5b505190506000610e4a836001600160701b03871663ffffffff611adf16565b90506000610e67836001600160701b03871663ffffffff611adf16565b90506000610e758787611e10565b60005490915080610eb257610e9e6103e86109e3610e99878763ffffffff611a7c16565b611f6e565b9850610ead60006103e8611fc0565b610f01565b610efe6001600160701b038916610ecf868463ffffffff611a7c16565b81610ed657fe5b046001600160701b038916610ef1868563ffffffff611a7c16565b81610ef857fe5b04612056565b98505b60008911610f405760405162461bcd60e51b81526004018080602001828103825260288152602001806122256028913960400191505060405180910390fd5b610f4a8a8a611fc0565b610f5686868a8a611b2f565b8115610f8657600854610f82906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461104b576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c8190558061105b610b24565b50600654600754604080516370a0823160e01b815230600482015290519496509294506001600160a01b039182169391169160009184916370a08231916024808301926020929190829003018186803b1580156110b757600080fd5b505afa1580156110cb573d6000803e3d6000fd5b505050506040513d60208110156110e157600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038516916370a08231916024808301926020929190829003018186803b15801561112f57600080fd5b505afa158015611143573d6000803e3d6000fd5b505050506040513d602081101561115957600080fd5b5051306000908152600160205260408120549192506111788888611e10565b6000549091508061118f848763ffffffff611a7c16565b8161119657fe5b049a50806111aa848663ffffffff611a7c16565b816111b157fe5b04995060008b1180156111c4575060008a115b6111ff5760405162461bcd60e51b81526004018080602001828103825260288152602001806121fd6028913960400191505060405180910390fd5b611209308461206e565b611214878d8d6118e2565b61121f868d8c6118e2565b604080516370a0823160e01b815230600482015290516001600160a01b038916916370a08231916024808301926020929190829003018186803b15801561126557600080fd5b505afa158015611279573d6000803e3d6000fd5b505050506040513d602081101561128f57600080fd5b5051604080516370a0823160e01b815230600482015290519196506001600160a01b038816916370a0823191602480820192602092909190829003018186803b1580156112db57600080fd5b505afa1580156112ef573d6000803e3d6000fd5b505050506040513d602081101561130557600080fd5b5051935061131585858b8b611b2f565b811561134557600854611341906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b604080518c8152602081018c905281516001600160a01b038f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b604051806040016040528060068152602001652aa72496ab1960d11b81525081565b6000610b5b338484611d56565b6103e881565b600c54600114611423576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654600754600854604080516370a0823160e01b815230600482015290516001600160a01b0394851694909316926114d292859287926114cd926001600160701b03169185916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b505afa1580156114a9573d6000803e3d6000fd5b505050506040513d60208110156114bf57600080fd5b50519063ffffffff611adf16565b6118e2565b600854604080516370a0823160e01b8152306004820152905161153992849287926114cd92600160701b90046001600160701b0316916001600160a01b038616916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b50506001600c5550565b6005546001600160a01b031681565b6007546001600160a01b031681565b428410156115ab576040805162461bcd60e51b8152602060048201526012602482015271155b9a5cddd85c158c8e881156141254915160721b604482015290519081900360640190fd5b6003546001600160a01b0380891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e08501825280519083012061190160f01b6101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e280820193601f1981019281900390910190855afa1580156116c6573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906116fc5750886001600160a01b0316816001600160a01b0316145b61174d576040805162461bcd60e51b815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611758898989611cf4565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c546001146117cb576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654604080516370a0823160e01b815230600482015290516118db926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561181c57600080fd5b505afa158015611830573d6000803e3d6000fd5b505050506040513d602081101561184657600080fd5b5051600754604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b15801561189357600080fd5b505afa1580156118a7573d6000803e3d6000fd5b505050506040513d60208110156118bd57600080fd5b50516008546001600160701b0380821691600160701b900416611b2f565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e74323536290000000000000060209182015281516001600160a01b0385811660248301526044808301869052845180840390910181526064909201845291810180516001600160e01b031663a9059cbb60e01b1781529251815160009460609489169392918291908083835b6020831061198f5780518252601f199092019160209182019101611970565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146119f1576040519150601f19603f3d011682016040523d82523d6000602084013e6119f6565b606091505b5091509150818015611a24575080511580611a245750808060200190516020811015611a2157600080fd5b50515b611a75576040805162461bcd60e51b815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b6000811580611a9757505080820282828281611a9457fe5b04145b610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820382811115610b5f576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6001600160701b038411801590611b4d57506001600160701b038311155b611b94576040805162461bcd60e51b8152602060048201526013602482015272556e697377617056323a204f564552464c4f5760681b604482015290519081900360640190fd5b60085463ffffffff42811691600160e01b90048116820390811615801590611bc457506001600160701b03841615155b8015611bd857506001600160701b03831615155b15611c49578063ffffffff16611c0685611bf18661210c565b6001600160e01b03169063ffffffff61211e16565b600980546001600160e01b03929092169290920201905563ffffffff8116611c3184611bf18761210c565b600a80546001600160e01b0392909216929092020190555b600880546dffffffffffffffffffffffffffff19166001600160701b03888116919091176dffffffffffffffffffffffffffff60701b1916600160701b8883168102919091176001600160e01b0316600160e01b63ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316600090815260016020526040902054611d7f908263ffffffff611adf16565b6001600160a01b038085166000908152600160205260408082209390935590841681522054611db4908263ffffffff61214316565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611e6157600080fd5b505afa158015611e75573d6000803e3d6000fd5b505050506040513d6020811015611e8b57600080fd5b5051600b546001600160a01b038216158015945091925090611f5a578015611f55576000611ece610e996001600160701b0388811690881663ffffffff611a7c16565b90506000611edb83611f6e565b905080821115611f52576000611f09611efa848463ffffffff611adf16565b6000549063ffffffff611a7c16565b90506000611f2e83611f2286600563ffffffff611a7c16565b9063ffffffff61214316565b90506000818381611f3b57fe5b0490508015611f4e57611f4e8782611fc0565b5050505b50505b611f66565b8015611f66576000600b555b505092915050565b60006003821115611fb1575080600160028204015b81811015611fab57809150600281828581611f9a57fe5b040181611fa357fe5b049050611f83565b50611fbb565b8115611fbb575060015b919050565b600054611fd3908263ffffffff61214316565b60009081556001600160a01b038316815260016020526040902054611ffe908263ffffffff61214316565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008183106120655781612067565b825b9392505050565b6001600160a01b038216600090815260016020526040902054612097908263ffffffff611adf16565b6001600160a01b038316600090815260016020526040812091909155546120c4908263ffffffff611adf16565b60009081556040805183815290516001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6001600160701b0316600160701b0290565b60006001600160701b0382166001600160e01b0384168161213b57fe5b049392505050565b80820182811015610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a7231582082fba8557d35ae5eca98219a61e967d398ed8eaafeafa5fe5af73dd6aad9ddfd64736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429') // init code hash
))));
}
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
} | getAmountIn | function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
| // given an output amount of an asset and pair reserves, returns a required input amount of the other asset | LineComment | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
21095,
21572
]
} | 2,478 |
||
DMGYieldFarmingRouter | contracts/external/farming/libs/UniswapV2Library.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | UniswapV2Library | library UniswapV2Library {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
// Taken from the UniswapV2Pair.json "bytecode" field
keccak256(hex'60806040526001600c5534801561001557600080fd5b5060405146908060526123868239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612281806101056000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a714610534578063d505accf1461053c578063dd62ed3e1461058d578063fff6cae9146105bb576101a9565b8063ba9a7a56146104fe578063bc25cf7714610506578063c45a01551461052c576101a9565b80637ecebe00116100d35780637ecebe001461046557806389afcb441461048b57806395d89b41146104ca578063a9059cbb146104d2576101a9565b80636a6278421461041157806370a08231146104375780637464fc3d1461045d576101a9565b806323b872dd116101665780633644e515116101405780633644e515146103cb578063485cc955146103d35780635909c0d5146104015780635a3d549314610409576101a9565b806323b872dd1461036f57806330adf81f146103a5578063313ce567146103ad576101a9565b8063022c0d9f146101ae57806306fdde031461023c5780630902f1ac146102b9578063095ea7b3146102f15780630dfe16811461033157806318160ddd14610355575b600080fd5b61023a600480360360808110156101c457600080fd5b8135916020810135916001600160a01b0360408301351691908101906080810160608201356401000000008111156101fb57600080fd5b82018360208201111561020d57600080fd5b8035906020019184600183028401116401000000008311171561022f57600080fd5b5090925090506105c3565b005b610244610afe565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561027e578181015183820152602001610266565b50505050905090810190601f1680156102ab5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102c1610b24565b604080516001600160701b03948516815292909316602083015263ffffffff168183015290519081900360600190f35b61031d6004803603604081101561030757600080fd5b506001600160a01b038135169060200135610b4e565b604080519115158252519081900360200190f35b610339610b65565b604080516001600160a01b039092168252519081900360200190f35b61035d610b74565b60408051918252519081900360200190f35b61031d6004803603606081101561038557600080fd5b506001600160a01b03813581169160208101359091169060400135610b7a565b61035d610c14565b6103b5610c38565b6040805160ff9092168252519081900360200190f35b61035d610c3d565b61023a600480360360408110156103e957600080fd5b506001600160a01b0381358116916020013516610c43565b61035d610cc7565b61035d610ccd565b61035d6004803603602081101561042757600080fd5b50356001600160a01b0316610cd3565b61035d6004803603602081101561044d57600080fd5b50356001600160a01b0316610fd3565b61035d610fe5565b61035d6004803603602081101561047b57600080fd5b50356001600160a01b0316610feb565b6104b1600480360360208110156104a157600080fd5b50356001600160a01b0316610ffd565b6040805192835260208301919091528051918290030190f35b6102446113a3565b61031d600480360360408110156104e857600080fd5b506001600160a01b0381351690602001356113c5565b61035d6113d2565b61023a6004803603602081101561051c57600080fd5b50356001600160a01b03166113d8565b610339611543565b610339611552565b61023a600480360360e081101561055257600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611561565b61035d600480360360408110156105a357600080fd5b506001600160a01b0381358116916020013516611763565b61023a611780565b600c5460011461060e576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55841515806106215750600084115b61065c5760405162461bcd60e51b81526004018080602001828103825260258152602001806121936025913960400191505060405180910390fd5b600080610667610b24565b5091509150816001600160701b03168710801561068c5750806001600160701b031686105b6106c75760405162461bcd60e51b81526004018080602001828103825260218152602001806121dc6021913960400191505060405180910390fd5b60065460075460009182916001600160a01b039182169190811690891682148015906107055750806001600160a01b0316896001600160a01b031614155b61074e576040805162461bcd60e51b8152602060048201526015602482015274556e697377617056323a20494e56414c49445f544f60581b604482015290519081900360640190fd5b8a1561075f5761075f828a8d6118e2565b891561077057610770818a8c6118e2565b861561082b57886001600160a01b03166310d1e85c338d8d8c8c6040518663ffffffff1660e01b815260040180866001600160a01b03166001600160a01b03168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b15801561081257600080fd5b505af1158015610826573d6000803e3d6000fd5b505050505b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561087157600080fd5b505afa158015610885573d6000803e3d6000fd5b505050506040513d602081101561089b57600080fd5b5051604080516370a0823160e01b815230600482015290519195506001600160a01b038316916370a0823191602480820192602092909190829003018186803b1580156108e757600080fd5b505afa1580156108fb573d6000803e3d6000fd5b505050506040513d602081101561091157600080fd5b5051925060009150506001600160701b0385168a90038311610934576000610943565b89856001600160701b03160383035b9050600089856001600160701b031603831161096057600061096f565b89856001600160701b03160383035b905060008211806109805750600081115b6109bb5760405162461bcd60e51b81526004018080602001828103825260248152602001806121b86024913960400191505060405180910390fd5b60006109ef6109d184600363ffffffff611a7c16565b6109e3876103e863ffffffff611a7c16565b9063ffffffff611adf16565b90506000610a076109d184600363ffffffff611a7c16565b9050610a38620f4240610a2c6001600160701b038b8116908b1663ffffffff611a7c16565b9063ffffffff611a7c16565b610a48838363ffffffff611a7c16565b1015610a8a576040805162461bcd60e51b815260206004820152600c60248201526b556e697377617056323a204b60a01b604482015290519081900360640190fd5b5050610a9884848888611b2f565b60408051838152602081018390528082018d9052606081018c905290516001600160a01b038b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a8152602001692ab734b9bbb0b8102b1960b11b81525081565b6008546001600160701b0380821692600160701b830490911691600160e01b900463ffffffff1690565b6000610b5b338484611cf4565b5060015b92915050565b6006546001600160a01b031681565b60005481565b6001600160a01b038316600090815260026020908152604080832033845290915281205460001914610bff576001600160a01b0384166000908152600260209081526040808320338452909152902054610bda908363ffffffff611adf16565b6001600160a01b03851660009081526002602090815260408083203384529091529020555b610c0a848484611d56565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b6005546001600160a01b03163314610c99576040805162461bcd60e51b81526020600482015260146024820152732ab734b9bbb0b82b191d102327a92124a22222a760611b604482015290519081900360640190fd5b600680546001600160a01b039384166001600160a01b03199182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c54600114610d20576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c81905580610d30610b24565b50600654604080516370a0823160e01b815230600482015290519395509193506000926001600160a01b03909116916370a08231916024808301926020929190829003018186803b158015610d8457600080fd5b505afa158015610d98573d6000803e3d6000fd5b505050506040513d6020811015610dae57600080fd5b5051600754604080516370a0823160e01b815230600482015290519293506000926001600160a01b03909216916370a0823191602480820192602092909190829003018186803b158015610e0157600080fd5b505afa158015610e15573d6000803e3d6000fd5b505050506040513d6020811015610e2b57600080fd5b505190506000610e4a836001600160701b03871663ffffffff611adf16565b90506000610e67836001600160701b03871663ffffffff611adf16565b90506000610e758787611e10565b60005490915080610eb257610e9e6103e86109e3610e99878763ffffffff611a7c16565b611f6e565b9850610ead60006103e8611fc0565b610f01565b610efe6001600160701b038916610ecf868463ffffffff611a7c16565b81610ed657fe5b046001600160701b038916610ef1868563ffffffff611a7c16565b81610ef857fe5b04612056565b98505b60008911610f405760405162461bcd60e51b81526004018080602001828103825260288152602001806122256028913960400191505060405180910390fd5b610f4a8a8a611fc0565b610f5686868a8a611b2f565b8115610f8657600854610f82906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461104b576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c8190558061105b610b24565b50600654600754604080516370a0823160e01b815230600482015290519496509294506001600160a01b039182169391169160009184916370a08231916024808301926020929190829003018186803b1580156110b757600080fd5b505afa1580156110cb573d6000803e3d6000fd5b505050506040513d60208110156110e157600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038516916370a08231916024808301926020929190829003018186803b15801561112f57600080fd5b505afa158015611143573d6000803e3d6000fd5b505050506040513d602081101561115957600080fd5b5051306000908152600160205260408120549192506111788888611e10565b6000549091508061118f848763ffffffff611a7c16565b8161119657fe5b049a50806111aa848663ffffffff611a7c16565b816111b157fe5b04995060008b1180156111c4575060008a115b6111ff5760405162461bcd60e51b81526004018080602001828103825260288152602001806121fd6028913960400191505060405180910390fd5b611209308461206e565b611214878d8d6118e2565b61121f868d8c6118e2565b604080516370a0823160e01b815230600482015290516001600160a01b038916916370a08231916024808301926020929190829003018186803b15801561126557600080fd5b505afa158015611279573d6000803e3d6000fd5b505050506040513d602081101561128f57600080fd5b5051604080516370a0823160e01b815230600482015290519196506001600160a01b038816916370a0823191602480820192602092909190829003018186803b1580156112db57600080fd5b505afa1580156112ef573d6000803e3d6000fd5b505050506040513d602081101561130557600080fd5b5051935061131585858b8b611b2f565b811561134557600854611341906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b604080518c8152602081018c905281516001600160a01b038f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b604051806040016040528060068152602001652aa72496ab1960d11b81525081565b6000610b5b338484611d56565b6103e881565b600c54600114611423576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654600754600854604080516370a0823160e01b815230600482015290516001600160a01b0394851694909316926114d292859287926114cd926001600160701b03169185916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b505afa1580156114a9573d6000803e3d6000fd5b505050506040513d60208110156114bf57600080fd5b50519063ffffffff611adf16565b6118e2565b600854604080516370a0823160e01b8152306004820152905161153992849287926114cd92600160701b90046001600160701b0316916001600160a01b038616916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b50506001600c5550565b6005546001600160a01b031681565b6007546001600160a01b031681565b428410156115ab576040805162461bcd60e51b8152602060048201526012602482015271155b9a5cddd85c158c8e881156141254915160721b604482015290519081900360640190fd5b6003546001600160a01b0380891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e08501825280519083012061190160f01b6101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e280820193601f1981019281900390910190855afa1580156116c6573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906116fc5750886001600160a01b0316816001600160a01b0316145b61174d576040805162461bcd60e51b815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611758898989611cf4565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c546001146117cb576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654604080516370a0823160e01b815230600482015290516118db926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561181c57600080fd5b505afa158015611830573d6000803e3d6000fd5b505050506040513d602081101561184657600080fd5b5051600754604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b15801561189357600080fd5b505afa1580156118a7573d6000803e3d6000fd5b505050506040513d60208110156118bd57600080fd5b50516008546001600160701b0380821691600160701b900416611b2f565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e74323536290000000000000060209182015281516001600160a01b0385811660248301526044808301869052845180840390910181526064909201845291810180516001600160e01b031663a9059cbb60e01b1781529251815160009460609489169392918291908083835b6020831061198f5780518252601f199092019160209182019101611970565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146119f1576040519150601f19603f3d011682016040523d82523d6000602084013e6119f6565b606091505b5091509150818015611a24575080511580611a245750808060200190516020811015611a2157600080fd5b50515b611a75576040805162461bcd60e51b815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b6000811580611a9757505080820282828281611a9457fe5b04145b610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820382811115610b5f576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6001600160701b038411801590611b4d57506001600160701b038311155b611b94576040805162461bcd60e51b8152602060048201526013602482015272556e697377617056323a204f564552464c4f5760681b604482015290519081900360640190fd5b60085463ffffffff42811691600160e01b90048116820390811615801590611bc457506001600160701b03841615155b8015611bd857506001600160701b03831615155b15611c49578063ffffffff16611c0685611bf18661210c565b6001600160e01b03169063ffffffff61211e16565b600980546001600160e01b03929092169290920201905563ffffffff8116611c3184611bf18761210c565b600a80546001600160e01b0392909216929092020190555b600880546dffffffffffffffffffffffffffff19166001600160701b03888116919091176dffffffffffffffffffffffffffff60701b1916600160701b8883168102919091176001600160e01b0316600160e01b63ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316600090815260016020526040902054611d7f908263ffffffff611adf16565b6001600160a01b038085166000908152600160205260408082209390935590841681522054611db4908263ffffffff61214316565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611e6157600080fd5b505afa158015611e75573d6000803e3d6000fd5b505050506040513d6020811015611e8b57600080fd5b5051600b546001600160a01b038216158015945091925090611f5a578015611f55576000611ece610e996001600160701b0388811690881663ffffffff611a7c16565b90506000611edb83611f6e565b905080821115611f52576000611f09611efa848463ffffffff611adf16565b6000549063ffffffff611a7c16565b90506000611f2e83611f2286600563ffffffff611a7c16565b9063ffffffff61214316565b90506000818381611f3b57fe5b0490508015611f4e57611f4e8782611fc0565b5050505b50505b611f66565b8015611f66576000600b555b505092915050565b60006003821115611fb1575080600160028204015b81811015611fab57809150600281828581611f9a57fe5b040181611fa357fe5b049050611f83565b50611fbb565b8115611fbb575060015b919050565b600054611fd3908263ffffffff61214316565b60009081556001600160a01b038316815260016020526040902054611ffe908263ffffffff61214316565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008183106120655781612067565b825b9392505050565b6001600160a01b038216600090815260016020526040902054612097908263ffffffff611adf16565b6001600160a01b038316600090815260016020526040812091909155546120c4908263ffffffff611adf16565b60009081556040805183815290516001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6001600160701b0316600160701b0290565b60006001600160701b0382166001600160e01b0384168161213b57fe5b049392505050565b80820182811015610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a7231582082fba8557d35ae5eca98219a61e967d398ed8eaafeafa5fe5af73dd6aad9ddfd64736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429') // init code hash
))));
}
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
} | getAmountsOut | function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
| // performs chained getAmountOut calculations on any number of pairs | LineComment | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
21649,
22165
]
} | 2,479 |
||
DMGYieldFarmingRouter | contracts/external/farming/libs/UniswapV2Library.sol | 0x85455fc1428ceee0072309f87a227d53783ba6a8 | Solidity | UniswapV2Library | library UniswapV2Library {
using SafeMath for uint;
// returns sorted token addresses, used to handle return values from pairs sorted in this order
function sortTokens(address tokenA, address tokenB) internal pure returns (address token0, address token1) {
require(tokenA != tokenB, 'UniswapV2Library: IDENTICAL_ADDRESSES');
(token0, token1) = tokenA < tokenB ? (tokenA, tokenB) : (tokenB, tokenA);
require(token0 != address(0), 'UniswapV2Library: ZERO_ADDRESS');
}
// calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(uint(keccak256(abi.encodePacked(
hex'ff',
factory,
keccak256(abi.encodePacked(token0, token1)),
// Taken from the UniswapV2Pair.json "bytecode" field
keccak256(hex'60806040526001600c5534801561001557600080fd5b5060405146908060526123868239604080519182900360520182208282018252600a8352692ab734b9bbb0b8102b1960b11b6020938401528151808301835260018152603160f81b908401528151808401919091527fbfcc8ef98ffbf7b6c3fec7bf5185b566b9863e35a9d83acd49ad6824b5969738818301527fc89efdaa54c0f20c7adf612882df0950f5a951637e0307cdcb4c672f298b8bc6606082015260808101949094523060a0808601919091528151808603909101815260c09094019052825192019190912060035550600580546001600160a01b03191633179055612281806101056000396000f3fe608060405234801561001057600080fd5b50600436106101a95760003560e01c80636a627842116100f9578063ba9a7a5611610097578063d21220a711610071578063d21220a714610534578063d505accf1461053c578063dd62ed3e1461058d578063fff6cae9146105bb576101a9565b8063ba9a7a56146104fe578063bc25cf7714610506578063c45a01551461052c576101a9565b80637ecebe00116100d35780637ecebe001461046557806389afcb441461048b57806395d89b41146104ca578063a9059cbb146104d2576101a9565b80636a6278421461041157806370a08231146104375780637464fc3d1461045d576101a9565b806323b872dd116101665780633644e515116101405780633644e515146103cb578063485cc955146103d35780635909c0d5146104015780635a3d549314610409576101a9565b806323b872dd1461036f57806330adf81f146103a5578063313ce567146103ad576101a9565b8063022c0d9f146101ae57806306fdde031461023c5780630902f1ac146102b9578063095ea7b3146102f15780630dfe16811461033157806318160ddd14610355575b600080fd5b61023a600480360360808110156101c457600080fd5b8135916020810135916001600160a01b0360408301351691908101906080810160608201356401000000008111156101fb57600080fd5b82018360208201111561020d57600080fd5b8035906020019184600183028401116401000000008311171561022f57600080fd5b5090925090506105c3565b005b610244610afe565b6040805160208082528351818301528351919283929083019185019080838360005b8381101561027e578181015183820152602001610266565b50505050905090810190601f1680156102ab5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6102c1610b24565b604080516001600160701b03948516815292909316602083015263ffffffff168183015290519081900360600190f35b61031d6004803603604081101561030757600080fd5b506001600160a01b038135169060200135610b4e565b604080519115158252519081900360200190f35b610339610b65565b604080516001600160a01b039092168252519081900360200190f35b61035d610b74565b60408051918252519081900360200190f35b61031d6004803603606081101561038557600080fd5b506001600160a01b03813581169160208101359091169060400135610b7a565b61035d610c14565b6103b5610c38565b6040805160ff9092168252519081900360200190f35b61035d610c3d565b61023a600480360360408110156103e957600080fd5b506001600160a01b0381358116916020013516610c43565b61035d610cc7565b61035d610ccd565b61035d6004803603602081101561042757600080fd5b50356001600160a01b0316610cd3565b61035d6004803603602081101561044d57600080fd5b50356001600160a01b0316610fd3565b61035d610fe5565b61035d6004803603602081101561047b57600080fd5b50356001600160a01b0316610feb565b6104b1600480360360208110156104a157600080fd5b50356001600160a01b0316610ffd565b6040805192835260208301919091528051918290030190f35b6102446113a3565b61031d600480360360408110156104e857600080fd5b506001600160a01b0381351690602001356113c5565b61035d6113d2565b61023a6004803603602081101561051c57600080fd5b50356001600160a01b03166113d8565b610339611543565b610339611552565b61023a600480360360e081101561055257600080fd5b506001600160a01b03813581169160208101359091169060408101359060608101359060ff6080820135169060a08101359060c00135611561565b61035d600480360360408110156105a357600080fd5b506001600160a01b0381358116916020013516611763565b61023a611780565b600c5460011461060e576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55841515806106215750600084115b61065c5760405162461bcd60e51b81526004018080602001828103825260258152602001806121936025913960400191505060405180910390fd5b600080610667610b24565b5091509150816001600160701b03168710801561068c5750806001600160701b031686105b6106c75760405162461bcd60e51b81526004018080602001828103825260218152602001806121dc6021913960400191505060405180910390fd5b60065460075460009182916001600160a01b039182169190811690891682148015906107055750806001600160a01b0316896001600160a01b031614155b61074e576040805162461bcd60e51b8152602060048201526015602482015274556e697377617056323a20494e56414c49445f544f60581b604482015290519081900360640190fd5b8a1561075f5761075f828a8d6118e2565b891561077057610770818a8c6118e2565b861561082b57886001600160a01b03166310d1e85c338d8d8c8c6040518663ffffffff1660e01b815260040180866001600160a01b03166001600160a01b03168152602001858152602001848152602001806020018281038252848482818152602001925080828437600081840152601f19601f8201169050808301925050509650505050505050600060405180830381600087803b15801561081257600080fd5b505af1158015610826573d6000803e3d6000fd5b505050505b604080516370a0823160e01b815230600482015290516001600160a01b038416916370a08231916024808301926020929190829003018186803b15801561087157600080fd5b505afa158015610885573d6000803e3d6000fd5b505050506040513d602081101561089b57600080fd5b5051604080516370a0823160e01b815230600482015290519195506001600160a01b038316916370a0823191602480820192602092909190829003018186803b1580156108e757600080fd5b505afa1580156108fb573d6000803e3d6000fd5b505050506040513d602081101561091157600080fd5b5051925060009150506001600160701b0385168a90038311610934576000610943565b89856001600160701b03160383035b9050600089856001600160701b031603831161096057600061096f565b89856001600160701b03160383035b905060008211806109805750600081115b6109bb5760405162461bcd60e51b81526004018080602001828103825260248152602001806121b86024913960400191505060405180910390fd5b60006109ef6109d184600363ffffffff611a7c16565b6109e3876103e863ffffffff611a7c16565b9063ffffffff611adf16565b90506000610a076109d184600363ffffffff611a7c16565b9050610a38620f4240610a2c6001600160701b038b8116908b1663ffffffff611a7c16565b9063ffffffff611a7c16565b610a48838363ffffffff611a7c16565b1015610a8a576040805162461bcd60e51b815260206004820152600c60248201526b556e697377617056323a204b60a01b604482015290519081900360640190fd5b5050610a9884848888611b2f565b60408051838152602081018390528082018d9052606081018c905290516001600160a01b038b169133917fd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d8229181900360800190a350506001600c55505050505050505050565b6040518060400160405280600a8152602001692ab734b9bbb0b8102b1960b11b81525081565b6008546001600160701b0380821692600160701b830490911691600160e01b900463ffffffff1690565b6000610b5b338484611cf4565b5060015b92915050565b6006546001600160a01b031681565b60005481565b6001600160a01b038316600090815260026020908152604080832033845290915281205460001914610bff576001600160a01b0384166000908152600260209081526040808320338452909152902054610bda908363ffffffff611adf16565b6001600160a01b03851660009081526002602090815260408083203384529091529020555b610c0a848484611d56565b5060019392505050565b7f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c981565b601281565b60035481565b6005546001600160a01b03163314610c99576040805162461bcd60e51b81526020600482015260146024820152732ab734b9bbb0b82b191d102327a92124a22222a760611b604482015290519081900360640190fd5b600680546001600160a01b039384166001600160a01b03199182161790915560078054929093169116179055565b60095481565b600a5481565b6000600c54600114610d20576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c81905580610d30610b24565b50600654604080516370a0823160e01b815230600482015290519395509193506000926001600160a01b03909116916370a08231916024808301926020929190829003018186803b158015610d8457600080fd5b505afa158015610d98573d6000803e3d6000fd5b505050506040513d6020811015610dae57600080fd5b5051600754604080516370a0823160e01b815230600482015290519293506000926001600160a01b03909216916370a0823191602480820192602092909190829003018186803b158015610e0157600080fd5b505afa158015610e15573d6000803e3d6000fd5b505050506040513d6020811015610e2b57600080fd5b505190506000610e4a836001600160701b03871663ffffffff611adf16565b90506000610e67836001600160701b03871663ffffffff611adf16565b90506000610e758787611e10565b60005490915080610eb257610e9e6103e86109e3610e99878763ffffffff611a7c16565b611f6e565b9850610ead60006103e8611fc0565b610f01565b610efe6001600160701b038916610ecf868463ffffffff611a7c16565b81610ed657fe5b046001600160701b038916610ef1868563ffffffff611a7c16565b81610ef857fe5b04612056565b98505b60008911610f405760405162461bcd60e51b81526004018080602001828103825260288152602001806122256028913960400191505060405180910390fd5b610f4a8a8a611fc0565b610f5686868a8a611b2f565b8115610f8657600854610f82906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b6040805185815260208101859052815133927f4c209b5fc8ad50758f13e2e1088ba56a560dff690a1c6fef26394f4c03821c4f928290030190a250506001600c5550949695505050505050565b60016020526000908152604090205481565b600b5481565b60046020526000908152604090205481565b600080600c5460011461104b576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c8190558061105b610b24565b50600654600754604080516370a0823160e01b815230600482015290519496509294506001600160a01b039182169391169160009184916370a08231916024808301926020929190829003018186803b1580156110b757600080fd5b505afa1580156110cb573d6000803e3d6000fd5b505050506040513d60208110156110e157600080fd5b5051604080516370a0823160e01b815230600482015290519192506000916001600160a01b038516916370a08231916024808301926020929190829003018186803b15801561112f57600080fd5b505afa158015611143573d6000803e3d6000fd5b505050506040513d602081101561115957600080fd5b5051306000908152600160205260408120549192506111788888611e10565b6000549091508061118f848763ffffffff611a7c16565b8161119657fe5b049a50806111aa848663ffffffff611a7c16565b816111b157fe5b04995060008b1180156111c4575060008a115b6111ff5760405162461bcd60e51b81526004018080602001828103825260288152602001806121fd6028913960400191505060405180910390fd5b611209308461206e565b611214878d8d6118e2565b61121f868d8c6118e2565b604080516370a0823160e01b815230600482015290516001600160a01b038916916370a08231916024808301926020929190829003018186803b15801561126557600080fd5b505afa158015611279573d6000803e3d6000fd5b505050506040513d602081101561128f57600080fd5b5051604080516370a0823160e01b815230600482015290519196506001600160a01b038816916370a0823191602480820192602092909190829003018186803b1580156112db57600080fd5b505afa1580156112ef573d6000803e3d6000fd5b505050506040513d602081101561130557600080fd5b5051935061131585858b8b611b2f565b811561134557600854611341906001600160701b0380821691600160701b90041663ffffffff611a7c16565b600b555b604080518c8152602081018c905281516001600160a01b038f169233927fdccd412f0b1252819cb1fd330b93224ca42612892bb3f4f789976e6d81936496929081900390910190a35050505050505050506001600c81905550915091565b604051806040016040528060068152602001652aa72496ab1960d11b81525081565b6000610b5b338484611d56565b6103e881565b600c54600114611423576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654600754600854604080516370a0823160e01b815230600482015290516001600160a01b0394851694909316926114d292859287926114cd926001600160701b03169185916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b505afa1580156114a9573d6000803e3d6000fd5b505050506040513d60208110156114bf57600080fd5b50519063ffffffff611adf16565b6118e2565b600854604080516370a0823160e01b8152306004820152905161153992849287926114cd92600160701b90046001600160701b0316916001600160a01b038616916370a0823191602480820192602092909190829003018186803b15801561149557600080fd5b50506001600c5550565b6005546001600160a01b031681565b6007546001600160a01b031681565b428410156115ab576040805162461bcd60e51b8152602060048201526012602482015271155b9a5cddd85c158c8e881156141254915160721b604482015290519081900360640190fd5b6003546001600160a01b0380891660008181526004602090815260408083208054600180820190925582517f6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c98186015280840196909652958d166060860152608085018c905260a085019590955260c08085018b90528151808603909101815260e08501825280519083012061190160f01b6101008601526101028501969096526101228085019690965280518085039096018652610142840180825286519683019690962095839052610162840180825286905260ff89166101828501526101a284018890526101c28401879052519193926101e280820193601f1981019281900390910190855afa1580156116c6573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906116fc5750886001600160a01b0316816001600160a01b0316145b61174d576040805162461bcd60e51b815260206004820152601c60248201527f556e697377617056323a20494e56414c49445f5349474e415455524500000000604482015290519081900360640190fd5b611758898989611cf4565b505050505050505050565b600260209081526000928352604080842090915290825290205481565b600c546001146117cb576040805162461bcd60e51b8152602060048201526011602482015270155b9a5cddd85c158c8e881313d0d2d151607a1b604482015290519081900360640190fd5b6000600c55600654604080516370a0823160e01b815230600482015290516118db926001600160a01b0316916370a08231916024808301926020929190829003018186803b15801561181c57600080fd5b505afa158015611830573d6000803e3d6000fd5b505050506040513d602081101561184657600080fd5b5051600754604080516370a0823160e01b815230600482015290516001600160a01b03909216916370a0823191602480820192602092909190829003018186803b15801561189357600080fd5b505afa1580156118a7573d6000803e3d6000fd5b505050506040513d60208110156118bd57600080fd5b50516008546001600160701b0380821691600160701b900416611b2f565b6001600c55565b604080518082018252601981527f7472616e7366657228616464726573732c75696e74323536290000000000000060209182015281516001600160a01b0385811660248301526044808301869052845180840390910181526064909201845291810180516001600160e01b031663a9059cbb60e01b1781529251815160009460609489169392918291908083835b6020831061198f5780518252601f199092019160209182019101611970565b6001836020036101000a0380198251168184511680821785525050505050509050019150506000604051808303816000865af19150503d80600081146119f1576040519150601f19603f3d011682016040523d82523d6000602084013e6119f6565b606091505b5091509150818015611a24575080511580611a245750808060200190516020811015611a2157600080fd5b50515b611a75576040805162461bcd60e51b815260206004820152601a60248201527f556e697377617056323a205452414e534645525f4641494c4544000000000000604482015290519081900360640190fd5b5050505050565b6000811580611a9757505080820282828281611a9457fe5b04145b610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6d756c2d6f766572666c6f7760601b604482015290519081900360640190fd5b80820382811115610b5f576040805162461bcd60e51b815260206004820152601560248201527464732d6d6174682d7375622d756e646572666c6f7760581b604482015290519081900360640190fd5b6001600160701b038411801590611b4d57506001600160701b038311155b611b94576040805162461bcd60e51b8152602060048201526013602482015272556e697377617056323a204f564552464c4f5760681b604482015290519081900360640190fd5b60085463ffffffff42811691600160e01b90048116820390811615801590611bc457506001600160701b03841615155b8015611bd857506001600160701b03831615155b15611c49578063ffffffff16611c0685611bf18661210c565b6001600160e01b03169063ffffffff61211e16565b600980546001600160e01b03929092169290920201905563ffffffff8116611c3184611bf18761210c565b600a80546001600160e01b0392909216929092020190555b600880546dffffffffffffffffffffffffffff19166001600160701b03888116919091176dffffffffffffffffffffffffffff60701b1916600160701b8883168102919091176001600160e01b0316600160e01b63ffffffff871602179283905560408051848416815291909304909116602082015281517f1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1929181900390910190a1505050505050565b6001600160a01b03808416600081815260026020908152604080832094871680845294825291829020859055815185815291517f8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b9259281900390910190a3505050565b6001600160a01b038316600090815260016020526040902054611d7f908263ffffffff611adf16565b6001600160a01b038085166000908152600160205260408082209390935590841681522054611db4908263ffffffff61214316565b6001600160a01b0380841660008181526001602090815260409182902094909455805185815290519193928716927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef92918290030190a3505050565b600080600560009054906101000a90046001600160a01b03166001600160a01b031663017e7e586040518163ffffffff1660e01b815260040160206040518083038186803b158015611e6157600080fd5b505afa158015611e75573d6000803e3d6000fd5b505050506040513d6020811015611e8b57600080fd5b5051600b546001600160a01b038216158015945091925090611f5a578015611f55576000611ece610e996001600160701b0388811690881663ffffffff611a7c16565b90506000611edb83611f6e565b905080821115611f52576000611f09611efa848463ffffffff611adf16565b6000549063ffffffff611a7c16565b90506000611f2e83611f2286600563ffffffff611a7c16565b9063ffffffff61214316565b90506000818381611f3b57fe5b0490508015611f4e57611f4e8782611fc0565b5050505b50505b611f66565b8015611f66576000600b555b505092915050565b60006003821115611fb1575080600160028204015b81811015611fab57809150600281828581611f9a57fe5b040181611fa357fe5b049050611f83565b50611fbb565b8115611fbb575060015b919050565b600054611fd3908263ffffffff61214316565b60009081556001600160a01b038316815260016020526040902054611ffe908263ffffffff61214316565b6001600160a01b03831660008181526001602090815260408083209490945583518581529351929391927fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef9281900390910190a35050565b60008183106120655781612067565b825b9392505050565b6001600160a01b038216600090815260016020526040902054612097908263ffffffff611adf16565b6001600160a01b038316600090815260016020526040812091909155546120c4908263ffffffff611adf16565b60009081556040805183815290516001600160a01b038516917fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef919081900360200190a35050565b6001600160701b0316600160701b0290565b60006001600160701b0382166001600160e01b0384168161213b57fe5b049392505050565b80820182811015610b5f576040805162461bcd60e51b815260206004820152601460248201527364732d6d6174682d6164642d6f766572666c6f7760601b604482015290519081900360640190fdfe556e697377617056323a20494e53554646494349454e545f4f55545055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f494e5055545f414d4f554e54556e697377617056323a20494e53554646494349454e545f4c4951554944495459556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4255524e4544556e697377617056323a20494e53554646494349454e545f4c49515549444954595f4d494e544544a265627a7a7231582082fba8557d35ae5eca98219a61e967d398ed8eaafeafa5fe5af73dd6aad9ddfd64736f6c63430005100032454950373132446f6d61696e28737472696e67206e616d652c737472696e672076657273696f6e2c75696e7432353620636861696e49642c6164647265737320766572696679696e67436f6e747261637429') // init code hash
))));
}
// fetches and sorts the reserves for a pair
function getReserves(address factory, address tokenA, address tokenB) internal view returns (uint reserveA, uint reserveB) {
(address token0,) = sortTokens(tokenA, tokenB);
(uint reserve0, uint reserve1,) = IUniswapV2Pair(pairFor(factory, tokenA, tokenB)).getReserves();
(reserveA, reserveB) = tokenA == token0 ? (reserve0, reserve1) : (reserve1, reserve0);
}
// given some amount of an asset and pair reserves, returns an equivalent amount of the other asset
function quote(uint amountA, uint reserveA, uint reserveB) internal pure returns (uint amountB) {
require(amountA > 0, 'UniswapV2Library: INSUFFICIENT_AMOUNT');
require(reserveA > 0 && reserveB > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
amountB = amountA.mul(reserveB) / reserveA;
}
// given an input amount of an asset and pair reserves, returns the maximum output amount of the other asset
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) internal pure returns (uint amountOut) {
require(amountIn > 0, 'UniswapV2Library: INSUFFICIENT_INPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint amountInWithFee = amountIn.mul(997);
uint numerator = amountInWithFee.mul(reserveOut);
uint denominator = reserveIn.mul(1000).add(amountInWithFee);
amountOut = numerator / denominator;
}
// given an output amount of an asset and pair reserves, returns a required input amount of the other asset
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) internal pure returns (uint amountIn) {
require(amountOut > 0, 'UniswapV2Library: INSUFFICIENT_OUTPUT_AMOUNT');
require(reserveIn > 0 && reserveOut > 0, 'UniswapV2Library: INSUFFICIENT_LIQUIDITY');
uint numerator = reserveIn.mul(amountOut).mul(1000);
uint denominator = reserveOut.sub(amountOut).mul(997);
amountIn = (numerator / denominator).add(1);
}
// performs chained getAmountOut calculations on any number of pairs
function getAmountsOut(address factory, uint amountIn, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[0] = amountIn;
for (uint i; i < path.length - 1; i++) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i], path[i + 1]);
amounts[i + 1] = getAmountOut(amounts[i], reserveIn, reserveOut);
}
}
// performs chained getAmountIn calculations on any number of pairs
function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
} | getAmountsIn | function getAmountsIn(address factory, uint amountOut, address[] memory path) internal view returns (uint[] memory amounts) {
require(path.length >= 2, 'UniswapV2Library: INVALID_PATH');
amounts = new uint[](path.length);
amounts[amounts.length - 1] = amountOut;
for (uint i = path.length - 1; i > 0; i--) {
(uint reserveIn, uint reserveOut) = getReserves(factory, path[i - 1], path[i]);
amounts[i - 1] = getAmountIn(amounts[i], reserveIn, reserveOut);
}
}
| // performs chained getAmountIn calculations on any number of pairs | LineComment | v0.5.13+commit.5b0b510c | Apache-2.0 | bzzr://109d8c35d03b8ade3d7a4b4f689a030d34e0cce256c34dbd0f4a6b95b7701a2e | {
"func_code_index": [
22241,
22778
]
} | 2,480 |
||
zsToken | contracts/zsToken.sol | 0x8e769eaa31375d13a1247de1e64987c28bed987e | Solidity | zsToken | contract zsToken is ERC20("Stabilize Strategy Multi-Token", "zs-USD"), Ownable, ReentrancyGuard {
using SafeERC20 for IERC20;
// Variables
uint256 constant divisionFactor = 100000;
StabilizePriceOracle private oracleContract; // A reference to the price oracle contract
// There are no fees to deposit and withdraw from the zs-Tokens
// Info of each user.
struct UserInfo {
uint256 depositTime; // The time the user made the last deposit
uint256 shareEstimate;
}
mapping(address => UserInfo) private userInfo;
// Token information
// This wrapped token accepts multiple stablecoins
// DAI, USDC, USDT, sUSD
struct TokenInfo {
IERC20 token; // Reference of token
uint256 decimals; // Decimals of token
uint256 price; // Last price of token in USD
}
TokenInfo[] private tokenList; // An array of tokens accepted as deposits
address private _underlyingPriceAsset; // Token from which the price is derived
bool public depositsOpen = true; // Governance can open or close deposits without timelock, cannot block withdrawals
// Strategy information
StabilizeStrategy private currentStrategy; // This will be the contract for the strategy
address private _pendingStrategy;
// Events
event Wrapped(address indexed user, uint256 amount);
event Unwrapped(address indexed user, uint256 amount);
constructor (address _priceAsset, StabilizePriceOracle _oracle) public {
_underlyingPriceAsset = _priceAsset;
oracleContract = _oracle;
setupTokens();
}
function setupTokens() internal {
// Start with DAI
IERC20 _token = IERC20(address(0x6B175474E89094C44Da98b954EedeAC495271d0F));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDC
_token = IERC20(address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDT
_token = IERC20(address(0xdAC17F958D2ee523a2206206994597C13D831ec7));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// sUSD
_token = IERC20(address(0x57Ab1ec28D129707052df4dF418D58a2D46d5f51));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
}
function getCurrentStrategy() external view returns (address) {
return address(currentStrategy);
}
function getPendingStrategy() external view returns (address) {
return _pendingStrategy;
}
function underlyingAsset() public view returns (address) {
// Can be used if staking in the STBZ pool
return address(_underlyingPriceAsset);
}
function underlyingDepositAssets() public view returns (address, address, address, address) {
// Returns all addresses accepted by this token vault
return (address(tokenList[0].token), address(tokenList[1].token), address(tokenList[2].token), address(tokenList[3].token));
}
function pricePerToken() public view returns (uint256) {
if(totalSupply() == 0){
return 1e18; // Shown in Wei units
}else{
return uint256(1e18).mul(valueOfVaultAndStrategy()).div(totalSupply());
}
}
function getNormalizedTotalBalance(address _address) public view returns (uint256) {
uint256 _balance = 0;
for(uint256 i = 0; i < tokenList.length; i++){
uint256 _bal = tokenList[i].token.balanceOf(_address);
_bal = _bal.mul(1e18).div(10**tokenList[i].decimals);
_balance = _balance.add(_bal); // This has been normalized to 1e18 decimals
}
return _balance;
}
function valueOfVaultAndStrategy() public view returns (uint256) { // The total value of the tokens
uint256 balance = getNormalizedTotalBalance(address(this)); // Get tokens stored in this contract
if(currentStrategy != StabilizeStrategy(address(0))){
balance += currentStrategy.balance(); // And tokens stored at the strategy
}
return balance;
}
function withdrawTokenReserves() public view returns (address, uint256) {
// This function will return the address and amount of the token with the lowest price
if(currentStrategy != StabilizeStrategy(address(0))){
return currentStrategy.withdrawTokenReserves();
}else{
uint256 length = tokenList.length;
uint256 targetID = 0;
uint256 targetPrice = 0;
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
uint256 _price = tokenList[i].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i;
}
}
}
if(targetPrice > 0){
return (address(tokenList[targetID].token), tokenList[targetID].token.balanceOf(address(this)));
}else{
return (address(0), 0); // No balance
}
}
}
function updateTokenPrices() internal {
for(uint256 i = 0; i < tokenList.length; i++){
uint256 price = oracleContract.getPrice(address(tokenList[i].token));
if(price > 0){
tokenList[i].price = price;
}
}
}
// Now handle deposits into the strategy
function deposit(uint256 amount, uint256 _tokenID) public nonReentrant {
uint256 total = valueOfVaultAndStrategy(); // Get token equivalent at strategy and here if applicable
require(depositsOpen == true, "Deposits have been suspended, but you can still withdraw");
require(currentStrategy != StabilizeStrategy(address(0)),"No strategy contract has been selected yet");
require(_tokenID < tokenList.length, "Token ID is outside range of tokens in contract");
IERC20 _token = tokenList[_tokenID].token; // Trusted tokens
uint256 _before = _token.balanceOf(address(this));
_token.safeTransferFrom(_msgSender(), address(this), amount); // Transfer token to this address
amount = _token.balanceOf(address(this)).sub(_before); // Some tokens lose amount (transfer fee) upon transfer
require(amount > 0, "Cannot deposit 0");
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}
uint256 _strategyBalance = currentStrategy.balance(); // Will get the balance of the value of the main tokens at the strategy
// Now call the strategy to deposit
pushTokensToStrategy(); // Push any strategy tokens here into the strategy
currentStrategy.deposit(nonContract); // Activate strategy deposit
require(currentStrategy.balance() > _strategyBalance, "No change in strategy balance"); // Balance should increase
uint256 normalizedAmount = amount.mul(1e18).div(10**tokenList[_tokenID].decimals); // Make sure everything is same units
uint256 mintAmount = normalizedAmount;
if(totalSupply() > 0){
// There is already a balance here, calculate our share
mintAmount = normalizedAmount.mul(totalSupply()).div(total); // Our share of the total
}
_mint(_msgSender(),mintAmount); // Now mint new zs-token to the depositor
// Add the user information
userInfo[_msgSender()].depositTime = now;
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.add(mintAmount);
emit Wrapped(_msgSender(), amount);
}
function redeem(uint256 share) public nonReentrant {
// Essentially withdraw our equivalent share of the pool based on share value
// Users cannot choose which stablecoin they get. They get the lowest valued coin up to the highest value
require(share > 0, "Cannot withdraw 0");
require(totalSupply() > 0, "No value redeemable");
uint256 tokenTotal = totalSupply();
// Now burn the token
_burn(_msgSender(),share); // Burn the amount, will fail if user doesn't have enough
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}else{
// This is a contract redeeming
require(userInfo[_msgSender()].depositTime < now && userInfo[_msgSender()].depositTime > 0, "Contract depositor cannot redeem in same transaction");
}
// Update user information
if(share <= userInfo[_msgSender()].shareEstimate){
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.sub(share);
}else{
// Share is greater than our share estimate, can happen if tokens are transferred
userInfo[_msgSender()].shareEstimate = 0;
require(nonContract == true, "Contract depositors cannot take out more than what they put in");
}
uint256 withdrawAmount = 0;
if(currentStrategy != StabilizeStrategy(address(0))){
withdrawAmount = currentStrategy.withdraw(_msgSender(), share, tokenTotal, nonContract); // Returns the amount of underlying removed
require(withdrawAmount > 0, "Failed to withdraw from the strategy");
}else{
// Pull directly from this contract the token amount in relation to the share if strategy not used
if(share < tokenTotal){
uint256 _balance = getNormalizedTotalBalance(address(this));
uint256 _myBalance = _balance.mul(share).div(tokenTotal);
withdrawPerPrice(_msgSender(), _myBalance, false); // This will withdraw based on token price
withdrawAmount = _myBalance;
}else{
// We are all shares, transfer all
uint256 _balance = getNormalizedTotalBalance(address(this));
withdrawPerPrice(_msgSender(), _balance, true);
withdrawAmount = _balance;
}
}
emit Unwrapped(_msgSender(), withdrawAmount);
}
// This will withdraw the tokens from the contract based on their price, from lowest price to highest
function withdrawPerPrice(address _receiver, uint256 _withdrawAmount, bool _takeAll) internal {
uint256 length = tokenList.length;
if(_takeAll == true){
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
tokenList[i].token.safeTransfer(_receiver, tokenList[i].token.balanceOf(address(this)));
}
}
return;
}
bool[4] memory done;
uint256 targetID = 0;
uint256 targetPrice = 0;
updateTokenPrices();
for(uint256 i = 0; i < length; i++){
targetPrice = 0; // Reset the target price
// Find the lowest priced token to withdraw
for(uint256 i2 = 0; i2 < length; i2++){
if(done[i2] == false){
uint256 _price = tokenList[i2].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i2;
}
}
}
done[targetID] = true;
// Determine the balance left
uint256 _normalizedBalance = tokenList[targetID].token.balanceOf(address(this)).mul(1e18).div(10**tokenList[targetID].decimals);
if(_normalizedBalance <= _withdrawAmount){
// Withdraw the entire balance of this token
if(_normalizedBalance > 0){
_withdrawAmount = _withdrawAmount.sub(_normalizedBalance);
tokenList[targetID].token.safeTransfer(_receiver, tokenList[targetID].token.balanceOf(address(this)));
}
}else{
// Withdraw a partial amount of this token
if(_withdrawAmount > 0){
// Convert the withdraw amount to the token's decimal amount
uint256 _balance = _withdrawAmount.mul(10**tokenList[targetID].decimals).div(1e18);
_withdrawAmount = 0;
tokenList[targetID].token.safeTransfer(_receiver, _balance);
}
break; // Nothing more to withdraw
}
}
}
// Governance functions
// Stop/start all deposits, no timelock required
// --------------------
function stopDeposits() external onlyGovernance {
depositsOpen = false;
}
function startDeposits() external onlyGovernance {
depositsOpen = true;
}
// A function used in case of strategy failure, possibly due to bug in theplatform our strategy is using, governance can stop using it quick
function emergencyStopStrategy() external onlyGovernance {
depositsOpen = false;
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(address(0));
_timelockType = 0; // Prevent governance from changing to new strategy without timelock
}
// --------------------
// Timelock variables
uint256 private _timelockStart; // The start of the timelock to change governance variables
uint256 private _timelockType; // The function that needs to be changed
uint256 constant _timelockDuration = 86400; // Timelock is 24 hours
// Reusable timelock variables
address private _timelock_address;
modifier timelockConditionsMet(uint256 _type) {
require(_timelockType == _type, "Timelock not acquired for this function");
_timelockType = 0; // Reset the type once the timelock is used
if(totalSupply() > 0){
// Timelock is only required after tokens exist
require(now >= _timelockStart + _timelockDuration, "Timelock time not met");
}
_;
}
// Change the owner of the token contract
// --------------------
function startGovernanceChange(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 1;
_timelock_address = _address;
}
function finishGovernanceChange() external onlyGovernance timelockConditionsMet(1) {
transferGovernance(_timelock_address);
}
// --------------------
// Change the treasury address
// --------------------
function startChangeStrategy(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 2;
_timelock_address = _address;
_pendingStrategy = _address;
if(totalSupply() == 0){
// Can change strategy with one call in this case
finishChangeStrategy();
}
}
function finishChangeStrategy() public onlyGovernance timelockConditionsMet(2) {
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(_timelock_address);
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
pushTokensToStrategy(); // It will push any strategy reward tokens here to the new strategy
currentStrategy.enter(); // Puts all the tokens and accessory tokens into the new strategy
}
_pendingStrategy = address(0);
}
function pushTokensToStrategy() internal {
uint256 tokenCount = currentStrategy.rewardTokensCount();
for(uint256 i = 0; i < tokenCount; i++){
IERC20 _token = IERC20(address(currentStrategy.rewardTokenAddress(i)));
uint256 _balance = _token.balanceOf(address(this));
if(_balance > 0){
_token.safeTransfer(address(currentStrategy), _balance);
}
}
}
// --------------------
// Change the price oracle contract used, in case of upgrades
// --------------------
function startChangePriceOracle(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 3;
_timelock_address = _address;
}
function finishChangePriceOracle() external onlyGovernance timelockConditionsMet(3) {
oracleContract = StabilizePriceOracle(_timelock_address);
}
// --------------------
} | deposit | function deposit(uint256 amount, uint256 _tokenID) public nonReentrant {
uint256 total = valueOfVaultAndStrategy(); // Get token equivalent at strategy and here if applicable
require(depositsOpen == true, "Deposits have been suspended, but you can still withdraw");
require(currentStrategy != StabilizeStrategy(address(0)),"No strategy contract has been selected yet");
require(_tokenID < tokenList.length, "Token ID is outside range of tokens in contract");
IERC20 _token = tokenList[_tokenID].token; // Trusted tokens
uint256 _before = _token.balanceOf(address(this));
_token.safeTransferFrom(_msgSender(), address(this), amount); // Transfer token to this address
amount = _token.balanceOf(address(this)).sub(_before); // Some tokens lose amount (transfer fee) upon transfer
require(amount > 0, "Cannot deposit 0");
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}
uint256 _strategyBalance = currentStrategy.balance(); // Will get the balance of the value of the main tokens at the strategy
// Now call the strategy to deposit
pushTokensToStrategy(); // Push any strategy tokens here into the strategy
currentStrategy.deposit(nonContract); // Activate strategy deposit
require(currentStrategy.balance() > _strategyBalance, "No change in strategy balance"); // Balance should increase
uint256 normalizedAmount = amount.mul(1e18).div(10**tokenList[_tokenID].decimals); // Make sure everything is same units
uint256 mintAmount = normalizedAmount;
if(totalSupply() > 0){
// There is already a balance here, calculate our share
mintAmount = normalizedAmount.mul(totalSupply()).div(total); // Our share of the total
}
_mint(_msgSender(),mintAmount); // Now mint new zs-token to the depositor
// Add the user information
userInfo[_msgSender()].depositTime = now;
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.add(mintAmount);
emit Wrapped(_msgSender(), amount);
}
| // Now handle deposits into the strategy | LineComment | v0.6.6+commit.6c089d02 | GNU GPLv3 | ipfs://8e948a2b0bcce26275886d6ae593ebc412e92063b525d6ad037caba99c13731c | {
"func_code_index": [
6209,
8512
]
} | 2,481 |
||
zsToken | contracts/zsToken.sol | 0x8e769eaa31375d13a1247de1e64987c28bed987e | Solidity | zsToken | contract zsToken is ERC20("Stabilize Strategy Multi-Token", "zs-USD"), Ownable, ReentrancyGuard {
using SafeERC20 for IERC20;
// Variables
uint256 constant divisionFactor = 100000;
StabilizePriceOracle private oracleContract; // A reference to the price oracle contract
// There are no fees to deposit and withdraw from the zs-Tokens
// Info of each user.
struct UserInfo {
uint256 depositTime; // The time the user made the last deposit
uint256 shareEstimate;
}
mapping(address => UserInfo) private userInfo;
// Token information
// This wrapped token accepts multiple stablecoins
// DAI, USDC, USDT, sUSD
struct TokenInfo {
IERC20 token; // Reference of token
uint256 decimals; // Decimals of token
uint256 price; // Last price of token in USD
}
TokenInfo[] private tokenList; // An array of tokens accepted as deposits
address private _underlyingPriceAsset; // Token from which the price is derived
bool public depositsOpen = true; // Governance can open or close deposits without timelock, cannot block withdrawals
// Strategy information
StabilizeStrategy private currentStrategy; // This will be the contract for the strategy
address private _pendingStrategy;
// Events
event Wrapped(address indexed user, uint256 amount);
event Unwrapped(address indexed user, uint256 amount);
constructor (address _priceAsset, StabilizePriceOracle _oracle) public {
_underlyingPriceAsset = _priceAsset;
oracleContract = _oracle;
setupTokens();
}
function setupTokens() internal {
// Start with DAI
IERC20 _token = IERC20(address(0x6B175474E89094C44Da98b954EedeAC495271d0F));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDC
_token = IERC20(address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDT
_token = IERC20(address(0xdAC17F958D2ee523a2206206994597C13D831ec7));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// sUSD
_token = IERC20(address(0x57Ab1ec28D129707052df4dF418D58a2D46d5f51));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
}
function getCurrentStrategy() external view returns (address) {
return address(currentStrategy);
}
function getPendingStrategy() external view returns (address) {
return _pendingStrategy;
}
function underlyingAsset() public view returns (address) {
// Can be used if staking in the STBZ pool
return address(_underlyingPriceAsset);
}
function underlyingDepositAssets() public view returns (address, address, address, address) {
// Returns all addresses accepted by this token vault
return (address(tokenList[0].token), address(tokenList[1].token), address(tokenList[2].token), address(tokenList[3].token));
}
function pricePerToken() public view returns (uint256) {
if(totalSupply() == 0){
return 1e18; // Shown in Wei units
}else{
return uint256(1e18).mul(valueOfVaultAndStrategy()).div(totalSupply());
}
}
function getNormalizedTotalBalance(address _address) public view returns (uint256) {
uint256 _balance = 0;
for(uint256 i = 0; i < tokenList.length; i++){
uint256 _bal = tokenList[i].token.balanceOf(_address);
_bal = _bal.mul(1e18).div(10**tokenList[i].decimals);
_balance = _balance.add(_bal); // This has been normalized to 1e18 decimals
}
return _balance;
}
function valueOfVaultAndStrategy() public view returns (uint256) { // The total value of the tokens
uint256 balance = getNormalizedTotalBalance(address(this)); // Get tokens stored in this contract
if(currentStrategy != StabilizeStrategy(address(0))){
balance += currentStrategy.balance(); // And tokens stored at the strategy
}
return balance;
}
function withdrawTokenReserves() public view returns (address, uint256) {
// This function will return the address and amount of the token with the lowest price
if(currentStrategy != StabilizeStrategy(address(0))){
return currentStrategy.withdrawTokenReserves();
}else{
uint256 length = tokenList.length;
uint256 targetID = 0;
uint256 targetPrice = 0;
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
uint256 _price = tokenList[i].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i;
}
}
}
if(targetPrice > 0){
return (address(tokenList[targetID].token), tokenList[targetID].token.balanceOf(address(this)));
}else{
return (address(0), 0); // No balance
}
}
}
function updateTokenPrices() internal {
for(uint256 i = 0; i < tokenList.length; i++){
uint256 price = oracleContract.getPrice(address(tokenList[i].token));
if(price > 0){
tokenList[i].price = price;
}
}
}
// Now handle deposits into the strategy
function deposit(uint256 amount, uint256 _tokenID) public nonReentrant {
uint256 total = valueOfVaultAndStrategy(); // Get token equivalent at strategy and here if applicable
require(depositsOpen == true, "Deposits have been suspended, but you can still withdraw");
require(currentStrategy != StabilizeStrategy(address(0)),"No strategy contract has been selected yet");
require(_tokenID < tokenList.length, "Token ID is outside range of tokens in contract");
IERC20 _token = tokenList[_tokenID].token; // Trusted tokens
uint256 _before = _token.balanceOf(address(this));
_token.safeTransferFrom(_msgSender(), address(this), amount); // Transfer token to this address
amount = _token.balanceOf(address(this)).sub(_before); // Some tokens lose amount (transfer fee) upon transfer
require(amount > 0, "Cannot deposit 0");
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}
uint256 _strategyBalance = currentStrategy.balance(); // Will get the balance of the value of the main tokens at the strategy
// Now call the strategy to deposit
pushTokensToStrategy(); // Push any strategy tokens here into the strategy
currentStrategy.deposit(nonContract); // Activate strategy deposit
require(currentStrategy.balance() > _strategyBalance, "No change in strategy balance"); // Balance should increase
uint256 normalizedAmount = amount.mul(1e18).div(10**tokenList[_tokenID].decimals); // Make sure everything is same units
uint256 mintAmount = normalizedAmount;
if(totalSupply() > 0){
// There is already a balance here, calculate our share
mintAmount = normalizedAmount.mul(totalSupply()).div(total); // Our share of the total
}
_mint(_msgSender(),mintAmount); // Now mint new zs-token to the depositor
// Add the user information
userInfo[_msgSender()].depositTime = now;
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.add(mintAmount);
emit Wrapped(_msgSender(), amount);
}
function redeem(uint256 share) public nonReentrant {
// Essentially withdraw our equivalent share of the pool based on share value
// Users cannot choose which stablecoin they get. They get the lowest valued coin up to the highest value
require(share > 0, "Cannot withdraw 0");
require(totalSupply() > 0, "No value redeemable");
uint256 tokenTotal = totalSupply();
// Now burn the token
_burn(_msgSender(),share); // Burn the amount, will fail if user doesn't have enough
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}else{
// This is a contract redeeming
require(userInfo[_msgSender()].depositTime < now && userInfo[_msgSender()].depositTime > 0, "Contract depositor cannot redeem in same transaction");
}
// Update user information
if(share <= userInfo[_msgSender()].shareEstimate){
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.sub(share);
}else{
// Share is greater than our share estimate, can happen if tokens are transferred
userInfo[_msgSender()].shareEstimate = 0;
require(nonContract == true, "Contract depositors cannot take out more than what they put in");
}
uint256 withdrawAmount = 0;
if(currentStrategy != StabilizeStrategy(address(0))){
withdrawAmount = currentStrategy.withdraw(_msgSender(), share, tokenTotal, nonContract); // Returns the amount of underlying removed
require(withdrawAmount > 0, "Failed to withdraw from the strategy");
}else{
// Pull directly from this contract the token amount in relation to the share if strategy not used
if(share < tokenTotal){
uint256 _balance = getNormalizedTotalBalance(address(this));
uint256 _myBalance = _balance.mul(share).div(tokenTotal);
withdrawPerPrice(_msgSender(), _myBalance, false); // This will withdraw based on token price
withdrawAmount = _myBalance;
}else{
// We are all shares, transfer all
uint256 _balance = getNormalizedTotalBalance(address(this));
withdrawPerPrice(_msgSender(), _balance, true);
withdrawAmount = _balance;
}
}
emit Unwrapped(_msgSender(), withdrawAmount);
}
// This will withdraw the tokens from the contract based on their price, from lowest price to highest
function withdrawPerPrice(address _receiver, uint256 _withdrawAmount, bool _takeAll) internal {
uint256 length = tokenList.length;
if(_takeAll == true){
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
tokenList[i].token.safeTransfer(_receiver, tokenList[i].token.balanceOf(address(this)));
}
}
return;
}
bool[4] memory done;
uint256 targetID = 0;
uint256 targetPrice = 0;
updateTokenPrices();
for(uint256 i = 0; i < length; i++){
targetPrice = 0; // Reset the target price
// Find the lowest priced token to withdraw
for(uint256 i2 = 0; i2 < length; i2++){
if(done[i2] == false){
uint256 _price = tokenList[i2].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i2;
}
}
}
done[targetID] = true;
// Determine the balance left
uint256 _normalizedBalance = tokenList[targetID].token.balanceOf(address(this)).mul(1e18).div(10**tokenList[targetID].decimals);
if(_normalizedBalance <= _withdrawAmount){
// Withdraw the entire balance of this token
if(_normalizedBalance > 0){
_withdrawAmount = _withdrawAmount.sub(_normalizedBalance);
tokenList[targetID].token.safeTransfer(_receiver, tokenList[targetID].token.balanceOf(address(this)));
}
}else{
// Withdraw a partial amount of this token
if(_withdrawAmount > 0){
// Convert the withdraw amount to the token's decimal amount
uint256 _balance = _withdrawAmount.mul(10**tokenList[targetID].decimals).div(1e18);
_withdrawAmount = 0;
tokenList[targetID].token.safeTransfer(_receiver, _balance);
}
break; // Nothing more to withdraw
}
}
}
// Governance functions
// Stop/start all deposits, no timelock required
// --------------------
function stopDeposits() external onlyGovernance {
depositsOpen = false;
}
function startDeposits() external onlyGovernance {
depositsOpen = true;
}
// A function used in case of strategy failure, possibly due to bug in theplatform our strategy is using, governance can stop using it quick
function emergencyStopStrategy() external onlyGovernance {
depositsOpen = false;
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(address(0));
_timelockType = 0; // Prevent governance from changing to new strategy without timelock
}
// --------------------
// Timelock variables
uint256 private _timelockStart; // The start of the timelock to change governance variables
uint256 private _timelockType; // The function that needs to be changed
uint256 constant _timelockDuration = 86400; // Timelock is 24 hours
// Reusable timelock variables
address private _timelock_address;
modifier timelockConditionsMet(uint256 _type) {
require(_timelockType == _type, "Timelock not acquired for this function");
_timelockType = 0; // Reset the type once the timelock is used
if(totalSupply() > 0){
// Timelock is only required after tokens exist
require(now >= _timelockStart + _timelockDuration, "Timelock time not met");
}
_;
}
// Change the owner of the token contract
// --------------------
function startGovernanceChange(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 1;
_timelock_address = _address;
}
function finishGovernanceChange() external onlyGovernance timelockConditionsMet(1) {
transferGovernance(_timelock_address);
}
// --------------------
// Change the treasury address
// --------------------
function startChangeStrategy(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 2;
_timelock_address = _address;
_pendingStrategy = _address;
if(totalSupply() == 0){
// Can change strategy with one call in this case
finishChangeStrategy();
}
}
function finishChangeStrategy() public onlyGovernance timelockConditionsMet(2) {
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(_timelock_address);
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
pushTokensToStrategy(); // It will push any strategy reward tokens here to the new strategy
currentStrategy.enter(); // Puts all the tokens and accessory tokens into the new strategy
}
_pendingStrategy = address(0);
}
function pushTokensToStrategy() internal {
uint256 tokenCount = currentStrategy.rewardTokensCount();
for(uint256 i = 0; i < tokenCount; i++){
IERC20 _token = IERC20(address(currentStrategy.rewardTokenAddress(i)));
uint256 _balance = _token.balanceOf(address(this));
if(_balance > 0){
_token.safeTransfer(address(currentStrategy), _balance);
}
}
}
// --------------------
// Change the price oracle contract used, in case of upgrades
// --------------------
function startChangePriceOracle(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 3;
_timelock_address = _address;
}
function finishChangePriceOracle() external onlyGovernance timelockConditionsMet(3) {
oracleContract = StabilizePriceOracle(_timelock_address);
}
// --------------------
} | withdrawPerPrice | function withdrawPerPrice(address _receiver, uint256 _withdrawAmount, bool _takeAll) internal {
uint256 length = tokenList.length;
if(_takeAll == true){
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
tokenList[i].token.safeTransfer(_receiver, tokenList[i].token.balanceOf(address(this)));
}
}
return;
}
bool[4] memory done;
uint256 targetID = 0;
uint256 targetPrice = 0;
updateTokenPrices();
for(uint256 i = 0; i < length; i++){
targetPrice = 0; // Reset the target price
// Find the lowest priced token to withdraw
for(uint256 i2 = 0; i2 < length; i2++){
if(done[i2] == false){
uint256 _price = tokenList[i2].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i2;
}
}
}
done[targetID] = true;
// Determine the balance left
uint256 _normalizedBalance = tokenList[targetID].token.balanceOf(address(this)).mul(1e18).div(10**tokenList[targetID].decimals);
if(_normalizedBalance <= _withdrawAmount){
// Withdraw the entire balance of this token
if(_normalizedBalance > 0){
_withdrawAmount = _withdrawAmount.sub(_normalizedBalance);
tokenList[targetID].token.safeTransfer(_receiver, tokenList[targetID].token.balanceOf(address(this)));
}
}else{
// Withdraw a partial amount of this token
if(_withdrawAmount > 0){
// Convert the withdraw amount to the token's decimal amount
uint256 _balance = _withdrawAmount.mul(10**tokenList[targetID].decimals).div(1e18);
_withdrawAmount = 0;
tokenList[targetID].token.safeTransfer(_receiver, _balance);
}
break; // Nothing more to withdraw
}
}
}
| // This will withdraw the tokens from the contract based on their price, from lowest price to highest | LineComment | v0.6.6+commit.6c089d02 | GNU GPLv3 | ipfs://8e948a2b0bcce26275886d6ae593ebc412e92063b525d6ad037caba99c13731c | {
"func_code_index": [
11248,
13559
]
} | 2,482 |
||
zsToken | contracts/zsToken.sol | 0x8e769eaa31375d13a1247de1e64987c28bed987e | Solidity | zsToken | contract zsToken is ERC20("Stabilize Strategy Multi-Token", "zs-USD"), Ownable, ReentrancyGuard {
using SafeERC20 for IERC20;
// Variables
uint256 constant divisionFactor = 100000;
StabilizePriceOracle private oracleContract; // A reference to the price oracle contract
// There are no fees to deposit and withdraw from the zs-Tokens
// Info of each user.
struct UserInfo {
uint256 depositTime; // The time the user made the last deposit
uint256 shareEstimate;
}
mapping(address => UserInfo) private userInfo;
// Token information
// This wrapped token accepts multiple stablecoins
// DAI, USDC, USDT, sUSD
struct TokenInfo {
IERC20 token; // Reference of token
uint256 decimals; // Decimals of token
uint256 price; // Last price of token in USD
}
TokenInfo[] private tokenList; // An array of tokens accepted as deposits
address private _underlyingPriceAsset; // Token from which the price is derived
bool public depositsOpen = true; // Governance can open or close deposits without timelock, cannot block withdrawals
// Strategy information
StabilizeStrategy private currentStrategy; // This will be the contract for the strategy
address private _pendingStrategy;
// Events
event Wrapped(address indexed user, uint256 amount);
event Unwrapped(address indexed user, uint256 amount);
constructor (address _priceAsset, StabilizePriceOracle _oracle) public {
_underlyingPriceAsset = _priceAsset;
oracleContract = _oracle;
setupTokens();
}
function setupTokens() internal {
// Start with DAI
IERC20 _token = IERC20(address(0x6B175474E89094C44Da98b954EedeAC495271d0F));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDC
_token = IERC20(address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDT
_token = IERC20(address(0xdAC17F958D2ee523a2206206994597C13D831ec7));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// sUSD
_token = IERC20(address(0x57Ab1ec28D129707052df4dF418D58a2D46d5f51));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
}
function getCurrentStrategy() external view returns (address) {
return address(currentStrategy);
}
function getPendingStrategy() external view returns (address) {
return _pendingStrategy;
}
function underlyingAsset() public view returns (address) {
// Can be used if staking in the STBZ pool
return address(_underlyingPriceAsset);
}
function underlyingDepositAssets() public view returns (address, address, address, address) {
// Returns all addresses accepted by this token vault
return (address(tokenList[0].token), address(tokenList[1].token), address(tokenList[2].token), address(tokenList[3].token));
}
function pricePerToken() public view returns (uint256) {
if(totalSupply() == 0){
return 1e18; // Shown in Wei units
}else{
return uint256(1e18).mul(valueOfVaultAndStrategy()).div(totalSupply());
}
}
function getNormalizedTotalBalance(address _address) public view returns (uint256) {
uint256 _balance = 0;
for(uint256 i = 0; i < tokenList.length; i++){
uint256 _bal = tokenList[i].token.balanceOf(_address);
_bal = _bal.mul(1e18).div(10**tokenList[i].decimals);
_balance = _balance.add(_bal); // This has been normalized to 1e18 decimals
}
return _balance;
}
function valueOfVaultAndStrategy() public view returns (uint256) { // The total value of the tokens
uint256 balance = getNormalizedTotalBalance(address(this)); // Get tokens stored in this contract
if(currentStrategy != StabilizeStrategy(address(0))){
balance += currentStrategy.balance(); // And tokens stored at the strategy
}
return balance;
}
function withdrawTokenReserves() public view returns (address, uint256) {
// This function will return the address and amount of the token with the lowest price
if(currentStrategy != StabilizeStrategy(address(0))){
return currentStrategy.withdrawTokenReserves();
}else{
uint256 length = tokenList.length;
uint256 targetID = 0;
uint256 targetPrice = 0;
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
uint256 _price = tokenList[i].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i;
}
}
}
if(targetPrice > 0){
return (address(tokenList[targetID].token), tokenList[targetID].token.balanceOf(address(this)));
}else{
return (address(0), 0); // No balance
}
}
}
function updateTokenPrices() internal {
for(uint256 i = 0; i < tokenList.length; i++){
uint256 price = oracleContract.getPrice(address(tokenList[i].token));
if(price > 0){
tokenList[i].price = price;
}
}
}
// Now handle deposits into the strategy
function deposit(uint256 amount, uint256 _tokenID) public nonReentrant {
uint256 total = valueOfVaultAndStrategy(); // Get token equivalent at strategy and here if applicable
require(depositsOpen == true, "Deposits have been suspended, but you can still withdraw");
require(currentStrategy != StabilizeStrategy(address(0)),"No strategy contract has been selected yet");
require(_tokenID < tokenList.length, "Token ID is outside range of tokens in contract");
IERC20 _token = tokenList[_tokenID].token; // Trusted tokens
uint256 _before = _token.balanceOf(address(this));
_token.safeTransferFrom(_msgSender(), address(this), amount); // Transfer token to this address
amount = _token.balanceOf(address(this)).sub(_before); // Some tokens lose amount (transfer fee) upon transfer
require(amount > 0, "Cannot deposit 0");
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}
uint256 _strategyBalance = currentStrategy.balance(); // Will get the balance of the value of the main tokens at the strategy
// Now call the strategy to deposit
pushTokensToStrategy(); // Push any strategy tokens here into the strategy
currentStrategy.deposit(nonContract); // Activate strategy deposit
require(currentStrategy.balance() > _strategyBalance, "No change in strategy balance"); // Balance should increase
uint256 normalizedAmount = amount.mul(1e18).div(10**tokenList[_tokenID].decimals); // Make sure everything is same units
uint256 mintAmount = normalizedAmount;
if(totalSupply() > 0){
// There is already a balance here, calculate our share
mintAmount = normalizedAmount.mul(totalSupply()).div(total); // Our share of the total
}
_mint(_msgSender(),mintAmount); // Now mint new zs-token to the depositor
// Add the user information
userInfo[_msgSender()].depositTime = now;
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.add(mintAmount);
emit Wrapped(_msgSender(), amount);
}
function redeem(uint256 share) public nonReentrant {
// Essentially withdraw our equivalent share of the pool based on share value
// Users cannot choose which stablecoin they get. They get the lowest valued coin up to the highest value
require(share > 0, "Cannot withdraw 0");
require(totalSupply() > 0, "No value redeemable");
uint256 tokenTotal = totalSupply();
// Now burn the token
_burn(_msgSender(),share); // Burn the amount, will fail if user doesn't have enough
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}else{
// This is a contract redeeming
require(userInfo[_msgSender()].depositTime < now && userInfo[_msgSender()].depositTime > 0, "Contract depositor cannot redeem in same transaction");
}
// Update user information
if(share <= userInfo[_msgSender()].shareEstimate){
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.sub(share);
}else{
// Share is greater than our share estimate, can happen if tokens are transferred
userInfo[_msgSender()].shareEstimate = 0;
require(nonContract == true, "Contract depositors cannot take out more than what they put in");
}
uint256 withdrawAmount = 0;
if(currentStrategy != StabilizeStrategy(address(0))){
withdrawAmount = currentStrategy.withdraw(_msgSender(), share, tokenTotal, nonContract); // Returns the amount of underlying removed
require(withdrawAmount > 0, "Failed to withdraw from the strategy");
}else{
// Pull directly from this contract the token amount in relation to the share if strategy not used
if(share < tokenTotal){
uint256 _balance = getNormalizedTotalBalance(address(this));
uint256 _myBalance = _balance.mul(share).div(tokenTotal);
withdrawPerPrice(_msgSender(), _myBalance, false); // This will withdraw based on token price
withdrawAmount = _myBalance;
}else{
// We are all shares, transfer all
uint256 _balance = getNormalizedTotalBalance(address(this));
withdrawPerPrice(_msgSender(), _balance, true);
withdrawAmount = _balance;
}
}
emit Unwrapped(_msgSender(), withdrawAmount);
}
// This will withdraw the tokens from the contract based on their price, from lowest price to highest
function withdrawPerPrice(address _receiver, uint256 _withdrawAmount, bool _takeAll) internal {
uint256 length = tokenList.length;
if(_takeAll == true){
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
tokenList[i].token.safeTransfer(_receiver, tokenList[i].token.balanceOf(address(this)));
}
}
return;
}
bool[4] memory done;
uint256 targetID = 0;
uint256 targetPrice = 0;
updateTokenPrices();
for(uint256 i = 0; i < length; i++){
targetPrice = 0; // Reset the target price
// Find the lowest priced token to withdraw
for(uint256 i2 = 0; i2 < length; i2++){
if(done[i2] == false){
uint256 _price = tokenList[i2].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i2;
}
}
}
done[targetID] = true;
// Determine the balance left
uint256 _normalizedBalance = tokenList[targetID].token.balanceOf(address(this)).mul(1e18).div(10**tokenList[targetID].decimals);
if(_normalizedBalance <= _withdrawAmount){
// Withdraw the entire balance of this token
if(_normalizedBalance > 0){
_withdrawAmount = _withdrawAmount.sub(_normalizedBalance);
tokenList[targetID].token.safeTransfer(_receiver, tokenList[targetID].token.balanceOf(address(this)));
}
}else{
// Withdraw a partial amount of this token
if(_withdrawAmount > 0){
// Convert the withdraw amount to the token's decimal amount
uint256 _balance = _withdrawAmount.mul(10**tokenList[targetID].decimals).div(1e18);
_withdrawAmount = 0;
tokenList[targetID].token.safeTransfer(_receiver, _balance);
}
break; // Nothing more to withdraw
}
}
}
// Governance functions
// Stop/start all deposits, no timelock required
// --------------------
function stopDeposits() external onlyGovernance {
depositsOpen = false;
}
function startDeposits() external onlyGovernance {
depositsOpen = true;
}
// A function used in case of strategy failure, possibly due to bug in theplatform our strategy is using, governance can stop using it quick
function emergencyStopStrategy() external onlyGovernance {
depositsOpen = false;
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(address(0));
_timelockType = 0; // Prevent governance from changing to new strategy without timelock
}
// --------------------
// Timelock variables
uint256 private _timelockStart; // The start of the timelock to change governance variables
uint256 private _timelockType; // The function that needs to be changed
uint256 constant _timelockDuration = 86400; // Timelock is 24 hours
// Reusable timelock variables
address private _timelock_address;
modifier timelockConditionsMet(uint256 _type) {
require(_timelockType == _type, "Timelock not acquired for this function");
_timelockType = 0; // Reset the type once the timelock is used
if(totalSupply() > 0){
// Timelock is only required after tokens exist
require(now >= _timelockStart + _timelockDuration, "Timelock time not met");
}
_;
}
// Change the owner of the token contract
// --------------------
function startGovernanceChange(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 1;
_timelock_address = _address;
}
function finishGovernanceChange() external onlyGovernance timelockConditionsMet(1) {
transferGovernance(_timelock_address);
}
// --------------------
// Change the treasury address
// --------------------
function startChangeStrategy(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 2;
_timelock_address = _address;
_pendingStrategy = _address;
if(totalSupply() == 0){
// Can change strategy with one call in this case
finishChangeStrategy();
}
}
function finishChangeStrategy() public onlyGovernance timelockConditionsMet(2) {
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(_timelock_address);
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
pushTokensToStrategy(); // It will push any strategy reward tokens here to the new strategy
currentStrategy.enter(); // Puts all the tokens and accessory tokens into the new strategy
}
_pendingStrategy = address(0);
}
function pushTokensToStrategy() internal {
uint256 tokenCount = currentStrategy.rewardTokensCount();
for(uint256 i = 0; i < tokenCount; i++){
IERC20 _token = IERC20(address(currentStrategy.rewardTokenAddress(i)));
uint256 _balance = _token.balanceOf(address(this));
if(_balance > 0){
_token.safeTransfer(address(currentStrategy), _balance);
}
}
}
// --------------------
// Change the price oracle contract used, in case of upgrades
// --------------------
function startChangePriceOracle(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 3;
_timelock_address = _address;
}
function finishChangePriceOracle() external onlyGovernance timelockConditionsMet(3) {
oracleContract = StabilizePriceOracle(_timelock_address);
}
// --------------------
} | stopDeposits | function stopDeposits() external onlyGovernance {
depositsOpen = false;
}
| // Governance functions
// Stop/start all deposits, no timelock required
// -------------------- | LineComment | v0.6.6+commit.6c089d02 | GNU GPLv3 | ipfs://8e948a2b0bcce26275886d6ae593ebc412e92063b525d6ad037caba99c13731c | {
"func_code_index": [
13684,
13776
]
} | 2,483 |
||
zsToken | contracts/zsToken.sol | 0x8e769eaa31375d13a1247de1e64987c28bed987e | Solidity | zsToken | contract zsToken is ERC20("Stabilize Strategy Multi-Token", "zs-USD"), Ownable, ReentrancyGuard {
using SafeERC20 for IERC20;
// Variables
uint256 constant divisionFactor = 100000;
StabilizePriceOracle private oracleContract; // A reference to the price oracle contract
// There are no fees to deposit and withdraw from the zs-Tokens
// Info of each user.
struct UserInfo {
uint256 depositTime; // The time the user made the last deposit
uint256 shareEstimate;
}
mapping(address => UserInfo) private userInfo;
// Token information
// This wrapped token accepts multiple stablecoins
// DAI, USDC, USDT, sUSD
struct TokenInfo {
IERC20 token; // Reference of token
uint256 decimals; // Decimals of token
uint256 price; // Last price of token in USD
}
TokenInfo[] private tokenList; // An array of tokens accepted as deposits
address private _underlyingPriceAsset; // Token from which the price is derived
bool public depositsOpen = true; // Governance can open or close deposits without timelock, cannot block withdrawals
// Strategy information
StabilizeStrategy private currentStrategy; // This will be the contract for the strategy
address private _pendingStrategy;
// Events
event Wrapped(address indexed user, uint256 amount);
event Unwrapped(address indexed user, uint256 amount);
constructor (address _priceAsset, StabilizePriceOracle _oracle) public {
_underlyingPriceAsset = _priceAsset;
oracleContract = _oracle;
setupTokens();
}
function setupTokens() internal {
// Start with DAI
IERC20 _token = IERC20(address(0x6B175474E89094C44Da98b954EedeAC495271d0F));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDC
_token = IERC20(address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDT
_token = IERC20(address(0xdAC17F958D2ee523a2206206994597C13D831ec7));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// sUSD
_token = IERC20(address(0x57Ab1ec28D129707052df4dF418D58a2D46d5f51));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
}
function getCurrentStrategy() external view returns (address) {
return address(currentStrategy);
}
function getPendingStrategy() external view returns (address) {
return _pendingStrategy;
}
function underlyingAsset() public view returns (address) {
// Can be used if staking in the STBZ pool
return address(_underlyingPriceAsset);
}
function underlyingDepositAssets() public view returns (address, address, address, address) {
// Returns all addresses accepted by this token vault
return (address(tokenList[0].token), address(tokenList[1].token), address(tokenList[2].token), address(tokenList[3].token));
}
function pricePerToken() public view returns (uint256) {
if(totalSupply() == 0){
return 1e18; // Shown in Wei units
}else{
return uint256(1e18).mul(valueOfVaultAndStrategy()).div(totalSupply());
}
}
function getNormalizedTotalBalance(address _address) public view returns (uint256) {
uint256 _balance = 0;
for(uint256 i = 0; i < tokenList.length; i++){
uint256 _bal = tokenList[i].token.balanceOf(_address);
_bal = _bal.mul(1e18).div(10**tokenList[i].decimals);
_balance = _balance.add(_bal); // This has been normalized to 1e18 decimals
}
return _balance;
}
function valueOfVaultAndStrategy() public view returns (uint256) { // The total value of the tokens
uint256 balance = getNormalizedTotalBalance(address(this)); // Get tokens stored in this contract
if(currentStrategy != StabilizeStrategy(address(0))){
balance += currentStrategy.balance(); // And tokens stored at the strategy
}
return balance;
}
function withdrawTokenReserves() public view returns (address, uint256) {
// This function will return the address and amount of the token with the lowest price
if(currentStrategy != StabilizeStrategy(address(0))){
return currentStrategy.withdrawTokenReserves();
}else{
uint256 length = tokenList.length;
uint256 targetID = 0;
uint256 targetPrice = 0;
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
uint256 _price = tokenList[i].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i;
}
}
}
if(targetPrice > 0){
return (address(tokenList[targetID].token), tokenList[targetID].token.balanceOf(address(this)));
}else{
return (address(0), 0); // No balance
}
}
}
function updateTokenPrices() internal {
for(uint256 i = 0; i < tokenList.length; i++){
uint256 price = oracleContract.getPrice(address(tokenList[i].token));
if(price > 0){
tokenList[i].price = price;
}
}
}
// Now handle deposits into the strategy
function deposit(uint256 amount, uint256 _tokenID) public nonReentrant {
uint256 total = valueOfVaultAndStrategy(); // Get token equivalent at strategy and here if applicable
require(depositsOpen == true, "Deposits have been suspended, but you can still withdraw");
require(currentStrategy != StabilizeStrategy(address(0)),"No strategy contract has been selected yet");
require(_tokenID < tokenList.length, "Token ID is outside range of tokens in contract");
IERC20 _token = tokenList[_tokenID].token; // Trusted tokens
uint256 _before = _token.balanceOf(address(this));
_token.safeTransferFrom(_msgSender(), address(this), amount); // Transfer token to this address
amount = _token.balanceOf(address(this)).sub(_before); // Some tokens lose amount (transfer fee) upon transfer
require(amount > 0, "Cannot deposit 0");
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}
uint256 _strategyBalance = currentStrategy.balance(); // Will get the balance of the value of the main tokens at the strategy
// Now call the strategy to deposit
pushTokensToStrategy(); // Push any strategy tokens here into the strategy
currentStrategy.deposit(nonContract); // Activate strategy deposit
require(currentStrategy.balance() > _strategyBalance, "No change in strategy balance"); // Balance should increase
uint256 normalizedAmount = amount.mul(1e18).div(10**tokenList[_tokenID].decimals); // Make sure everything is same units
uint256 mintAmount = normalizedAmount;
if(totalSupply() > 0){
// There is already a balance here, calculate our share
mintAmount = normalizedAmount.mul(totalSupply()).div(total); // Our share of the total
}
_mint(_msgSender(),mintAmount); // Now mint new zs-token to the depositor
// Add the user information
userInfo[_msgSender()].depositTime = now;
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.add(mintAmount);
emit Wrapped(_msgSender(), amount);
}
function redeem(uint256 share) public nonReentrant {
// Essentially withdraw our equivalent share of the pool based on share value
// Users cannot choose which stablecoin they get. They get the lowest valued coin up to the highest value
require(share > 0, "Cannot withdraw 0");
require(totalSupply() > 0, "No value redeemable");
uint256 tokenTotal = totalSupply();
// Now burn the token
_burn(_msgSender(),share); // Burn the amount, will fail if user doesn't have enough
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}else{
// This is a contract redeeming
require(userInfo[_msgSender()].depositTime < now && userInfo[_msgSender()].depositTime > 0, "Contract depositor cannot redeem in same transaction");
}
// Update user information
if(share <= userInfo[_msgSender()].shareEstimate){
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.sub(share);
}else{
// Share is greater than our share estimate, can happen if tokens are transferred
userInfo[_msgSender()].shareEstimate = 0;
require(nonContract == true, "Contract depositors cannot take out more than what they put in");
}
uint256 withdrawAmount = 0;
if(currentStrategy != StabilizeStrategy(address(0))){
withdrawAmount = currentStrategy.withdraw(_msgSender(), share, tokenTotal, nonContract); // Returns the amount of underlying removed
require(withdrawAmount > 0, "Failed to withdraw from the strategy");
}else{
// Pull directly from this contract the token amount in relation to the share if strategy not used
if(share < tokenTotal){
uint256 _balance = getNormalizedTotalBalance(address(this));
uint256 _myBalance = _balance.mul(share).div(tokenTotal);
withdrawPerPrice(_msgSender(), _myBalance, false); // This will withdraw based on token price
withdrawAmount = _myBalance;
}else{
// We are all shares, transfer all
uint256 _balance = getNormalizedTotalBalance(address(this));
withdrawPerPrice(_msgSender(), _balance, true);
withdrawAmount = _balance;
}
}
emit Unwrapped(_msgSender(), withdrawAmount);
}
// This will withdraw the tokens from the contract based on their price, from lowest price to highest
function withdrawPerPrice(address _receiver, uint256 _withdrawAmount, bool _takeAll) internal {
uint256 length = tokenList.length;
if(_takeAll == true){
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
tokenList[i].token.safeTransfer(_receiver, tokenList[i].token.balanceOf(address(this)));
}
}
return;
}
bool[4] memory done;
uint256 targetID = 0;
uint256 targetPrice = 0;
updateTokenPrices();
for(uint256 i = 0; i < length; i++){
targetPrice = 0; // Reset the target price
// Find the lowest priced token to withdraw
for(uint256 i2 = 0; i2 < length; i2++){
if(done[i2] == false){
uint256 _price = tokenList[i2].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i2;
}
}
}
done[targetID] = true;
// Determine the balance left
uint256 _normalizedBalance = tokenList[targetID].token.balanceOf(address(this)).mul(1e18).div(10**tokenList[targetID].decimals);
if(_normalizedBalance <= _withdrawAmount){
// Withdraw the entire balance of this token
if(_normalizedBalance > 0){
_withdrawAmount = _withdrawAmount.sub(_normalizedBalance);
tokenList[targetID].token.safeTransfer(_receiver, tokenList[targetID].token.balanceOf(address(this)));
}
}else{
// Withdraw a partial amount of this token
if(_withdrawAmount > 0){
// Convert the withdraw amount to the token's decimal amount
uint256 _balance = _withdrawAmount.mul(10**tokenList[targetID].decimals).div(1e18);
_withdrawAmount = 0;
tokenList[targetID].token.safeTransfer(_receiver, _balance);
}
break; // Nothing more to withdraw
}
}
}
// Governance functions
// Stop/start all deposits, no timelock required
// --------------------
function stopDeposits() external onlyGovernance {
depositsOpen = false;
}
function startDeposits() external onlyGovernance {
depositsOpen = true;
}
// A function used in case of strategy failure, possibly due to bug in theplatform our strategy is using, governance can stop using it quick
function emergencyStopStrategy() external onlyGovernance {
depositsOpen = false;
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(address(0));
_timelockType = 0; // Prevent governance from changing to new strategy without timelock
}
// --------------------
// Timelock variables
uint256 private _timelockStart; // The start of the timelock to change governance variables
uint256 private _timelockType; // The function that needs to be changed
uint256 constant _timelockDuration = 86400; // Timelock is 24 hours
// Reusable timelock variables
address private _timelock_address;
modifier timelockConditionsMet(uint256 _type) {
require(_timelockType == _type, "Timelock not acquired for this function");
_timelockType = 0; // Reset the type once the timelock is used
if(totalSupply() > 0){
// Timelock is only required after tokens exist
require(now >= _timelockStart + _timelockDuration, "Timelock time not met");
}
_;
}
// Change the owner of the token contract
// --------------------
function startGovernanceChange(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 1;
_timelock_address = _address;
}
function finishGovernanceChange() external onlyGovernance timelockConditionsMet(1) {
transferGovernance(_timelock_address);
}
// --------------------
// Change the treasury address
// --------------------
function startChangeStrategy(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 2;
_timelock_address = _address;
_pendingStrategy = _address;
if(totalSupply() == 0){
// Can change strategy with one call in this case
finishChangeStrategy();
}
}
function finishChangeStrategy() public onlyGovernance timelockConditionsMet(2) {
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(_timelock_address);
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
pushTokensToStrategy(); // It will push any strategy reward tokens here to the new strategy
currentStrategy.enter(); // Puts all the tokens and accessory tokens into the new strategy
}
_pendingStrategy = address(0);
}
function pushTokensToStrategy() internal {
uint256 tokenCount = currentStrategy.rewardTokensCount();
for(uint256 i = 0; i < tokenCount; i++){
IERC20 _token = IERC20(address(currentStrategy.rewardTokenAddress(i)));
uint256 _balance = _token.balanceOf(address(this));
if(_balance > 0){
_token.safeTransfer(address(currentStrategy), _balance);
}
}
}
// --------------------
// Change the price oracle contract used, in case of upgrades
// --------------------
function startChangePriceOracle(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 3;
_timelock_address = _address;
}
function finishChangePriceOracle() external onlyGovernance timelockConditionsMet(3) {
oracleContract = StabilizePriceOracle(_timelock_address);
}
// --------------------
} | emergencyStopStrategy | function emergencyStopStrategy() external onlyGovernance {
depositsOpen = false;
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(address(0));
_timelockType = 0; // Prevent governance from changing to new strategy without timelock
}
| // A function used in case of strategy failure, possibly due to bug in theplatform our strategy is using, governance can stop using it quick | LineComment | v0.6.6+commit.6c089d02 | GNU GPLv3 | ipfs://8e948a2b0bcce26275886d6ae593ebc412e92063b525d6ad037caba99c13731c | {
"func_code_index": [
14020,
14472
]
} | 2,484 |
||
zsToken | contracts/zsToken.sol | 0x8e769eaa31375d13a1247de1e64987c28bed987e | Solidity | zsToken | contract zsToken is ERC20("Stabilize Strategy Multi-Token", "zs-USD"), Ownable, ReentrancyGuard {
using SafeERC20 for IERC20;
// Variables
uint256 constant divisionFactor = 100000;
StabilizePriceOracle private oracleContract; // A reference to the price oracle contract
// There are no fees to deposit and withdraw from the zs-Tokens
// Info of each user.
struct UserInfo {
uint256 depositTime; // The time the user made the last deposit
uint256 shareEstimate;
}
mapping(address => UserInfo) private userInfo;
// Token information
// This wrapped token accepts multiple stablecoins
// DAI, USDC, USDT, sUSD
struct TokenInfo {
IERC20 token; // Reference of token
uint256 decimals; // Decimals of token
uint256 price; // Last price of token in USD
}
TokenInfo[] private tokenList; // An array of tokens accepted as deposits
address private _underlyingPriceAsset; // Token from which the price is derived
bool public depositsOpen = true; // Governance can open or close deposits without timelock, cannot block withdrawals
// Strategy information
StabilizeStrategy private currentStrategy; // This will be the contract for the strategy
address private _pendingStrategy;
// Events
event Wrapped(address indexed user, uint256 amount);
event Unwrapped(address indexed user, uint256 amount);
constructor (address _priceAsset, StabilizePriceOracle _oracle) public {
_underlyingPriceAsset = _priceAsset;
oracleContract = _oracle;
setupTokens();
}
function setupTokens() internal {
// Start with DAI
IERC20 _token = IERC20(address(0x6B175474E89094C44Da98b954EedeAC495271d0F));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDC
_token = IERC20(address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDT
_token = IERC20(address(0xdAC17F958D2ee523a2206206994597C13D831ec7));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// sUSD
_token = IERC20(address(0x57Ab1ec28D129707052df4dF418D58a2D46d5f51));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
}
function getCurrentStrategy() external view returns (address) {
return address(currentStrategy);
}
function getPendingStrategy() external view returns (address) {
return _pendingStrategy;
}
function underlyingAsset() public view returns (address) {
// Can be used if staking in the STBZ pool
return address(_underlyingPriceAsset);
}
function underlyingDepositAssets() public view returns (address, address, address, address) {
// Returns all addresses accepted by this token vault
return (address(tokenList[0].token), address(tokenList[1].token), address(tokenList[2].token), address(tokenList[3].token));
}
function pricePerToken() public view returns (uint256) {
if(totalSupply() == 0){
return 1e18; // Shown in Wei units
}else{
return uint256(1e18).mul(valueOfVaultAndStrategy()).div(totalSupply());
}
}
function getNormalizedTotalBalance(address _address) public view returns (uint256) {
uint256 _balance = 0;
for(uint256 i = 0; i < tokenList.length; i++){
uint256 _bal = tokenList[i].token.balanceOf(_address);
_bal = _bal.mul(1e18).div(10**tokenList[i].decimals);
_balance = _balance.add(_bal); // This has been normalized to 1e18 decimals
}
return _balance;
}
function valueOfVaultAndStrategy() public view returns (uint256) { // The total value of the tokens
uint256 balance = getNormalizedTotalBalance(address(this)); // Get tokens stored in this contract
if(currentStrategy != StabilizeStrategy(address(0))){
balance += currentStrategy.balance(); // And tokens stored at the strategy
}
return balance;
}
function withdrawTokenReserves() public view returns (address, uint256) {
// This function will return the address and amount of the token with the lowest price
if(currentStrategy != StabilizeStrategy(address(0))){
return currentStrategy.withdrawTokenReserves();
}else{
uint256 length = tokenList.length;
uint256 targetID = 0;
uint256 targetPrice = 0;
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
uint256 _price = tokenList[i].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i;
}
}
}
if(targetPrice > 0){
return (address(tokenList[targetID].token), tokenList[targetID].token.balanceOf(address(this)));
}else{
return (address(0), 0); // No balance
}
}
}
function updateTokenPrices() internal {
for(uint256 i = 0; i < tokenList.length; i++){
uint256 price = oracleContract.getPrice(address(tokenList[i].token));
if(price > 0){
tokenList[i].price = price;
}
}
}
// Now handle deposits into the strategy
function deposit(uint256 amount, uint256 _tokenID) public nonReentrant {
uint256 total = valueOfVaultAndStrategy(); // Get token equivalent at strategy and here if applicable
require(depositsOpen == true, "Deposits have been suspended, but you can still withdraw");
require(currentStrategy != StabilizeStrategy(address(0)),"No strategy contract has been selected yet");
require(_tokenID < tokenList.length, "Token ID is outside range of tokens in contract");
IERC20 _token = tokenList[_tokenID].token; // Trusted tokens
uint256 _before = _token.balanceOf(address(this));
_token.safeTransferFrom(_msgSender(), address(this), amount); // Transfer token to this address
amount = _token.balanceOf(address(this)).sub(_before); // Some tokens lose amount (transfer fee) upon transfer
require(amount > 0, "Cannot deposit 0");
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}
uint256 _strategyBalance = currentStrategy.balance(); // Will get the balance of the value of the main tokens at the strategy
// Now call the strategy to deposit
pushTokensToStrategy(); // Push any strategy tokens here into the strategy
currentStrategy.deposit(nonContract); // Activate strategy deposit
require(currentStrategy.balance() > _strategyBalance, "No change in strategy balance"); // Balance should increase
uint256 normalizedAmount = amount.mul(1e18).div(10**tokenList[_tokenID].decimals); // Make sure everything is same units
uint256 mintAmount = normalizedAmount;
if(totalSupply() > 0){
// There is already a balance here, calculate our share
mintAmount = normalizedAmount.mul(totalSupply()).div(total); // Our share of the total
}
_mint(_msgSender(),mintAmount); // Now mint new zs-token to the depositor
// Add the user information
userInfo[_msgSender()].depositTime = now;
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.add(mintAmount);
emit Wrapped(_msgSender(), amount);
}
function redeem(uint256 share) public nonReentrant {
// Essentially withdraw our equivalent share of the pool based on share value
// Users cannot choose which stablecoin they get. They get the lowest valued coin up to the highest value
require(share > 0, "Cannot withdraw 0");
require(totalSupply() > 0, "No value redeemable");
uint256 tokenTotal = totalSupply();
// Now burn the token
_burn(_msgSender(),share); // Burn the amount, will fail if user doesn't have enough
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}else{
// This is a contract redeeming
require(userInfo[_msgSender()].depositTime < now && userInfo[_msgSender()].depositTime > 0, "Contract depositor cannot redeem in same transaction");
}
// Update user information
if(share <= userInfo[_msgSender()].shareEstimate){
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.sub(share);
}else{
// Share is greater than our share estimate, can happen if tokens are transferred
userInfo[_msgSender()].shareEstimate = 0;
require(nonContract == true, "Contract depositors cannot take out more than what they put in");
}
uint256 withdrawAmount = 0;
if(currentStrategy != StabilizeStrategy(address(0))){
withdrawAmount = currentStrategy.withdraw(_msgSender(), share, tokenTotal, nonContract); // Returns the amount of underlying removed
require(withdrawAmount > 0, "Failed to withdraw from the strategy");
}else{
// Pull directly from this contract the token amount in relation to the share if strategy not used
if(share < tokenTotal){
uint256 _balance = getNormalizedTotalBalance(address(this));
uint256 _myBalance = _balance.mul(share).div(tokenTotal);
withdrawPerPrice(_msgSender(), _myBalance, false); // This will withdraw based on token price
withdrawAmount = _myBalance;
}else{
// We are all shares, transfer all
uint256 _balance = getNormalizedTotalBalance(address(this));
withdrawPerPrice(_msgSender(), _balance, true);
withdrawAmount = _balance;
}
}
emit Unwrapped(_msgSender(), withdrawAmount);
}
// This will withdraw the tokens from the contract based on their price, from lowest price to highest
function withdrawPerPrice(address _receiver, uint256 _withdrawAmount, bool _takeAll) internal {
uint256 length = tokenList.length;
if(_takeAll == true){
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
tokenList[i].token.safeTransfer(_receiver, tokenList[i].token.balanceOf(address(this)));
}
}
return;
}
bool[4] memory done;
uint256 targetID = 0;
uint256 targetPrice = 0;
updateTokenPrices();
for(uint256 i = 0; i < length; i++){
targetPrice = 0; // Reset the target price
// Find the lowest priced token to withdraw
for(uint256 i2 = 0; i2 < length; i2++){
if(done[i2] == false){
uint256 _price = tokenList[i2].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i2;
}
}
}
done[targetID] = true;
// Determine the balance left
uint256 _normalizedBalance = tokenList[targetID].token.balanceOf(address(this)).mul(1e18).div(10**tokenList[targetID].decimals);
if(_normalizedBalance <= _withdrawAmount){
// Withdraw the entire balance of this token
if(_normalizedBalance > 0){
_withdrawAmount = _withdrawAmount.sub(_normalizedBalance);
tokenList[targetID].token.safeTransfer(_receiver, tokenList[targetID].token.balanceOf(address(this)));
}
}else{
// Withdraw a partial amount of this token
if(_withdrawAmount > 0){
// Convert the withdraw amount to the token's decimal amount
uint256 _balance = _withdrawAmount.mul(10**tokenList[targetID].decimals).div(1e18);
_withdrawAmount = 0;
tokenList[targetID].token.safeTransfer(_receiver, _balance);
}
break; // Nothing more to withdraw
}
}
}
// Governance functions
// Stop/start all deposits, no timelock required
// --------------------
function stopDeposits() external onlyGovernance {
depositsOpen = false;
}
function startDeposits() external onlyGovernance {
depositsOpen = true;
}
// A function used in case of strategy failure, possibly due to bug in theplatform our strategy is using, governance can stop using it quick
function emergencyStopStrategy() external onlyGovernance {
depositsOpen = false;
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(address(0));
_timelockType = 0; // Prevent governance from changing to new strategy without timelock
}
// --------------------
// Timelock variables
uint256 private _timelockStart; // The start of the timelock to change governance variables
uint256 private _timelockType; // The function that needs to be changed
uint256 constant _timelockDuration = 86400; // Timelock is 24 hours
// Reusable timelock variables
address private _timelock_address;
modifier timelockConditionsMet(uint256 _type) {
require(_timelockType == _type, "Timelock not acquired for this function");
_timelockType = 0; // Reset the type once the timelock is used
if(totalSupply() > 0){
// Timelock is only required after tokens exist
require(now >= _timelockStart + _timelockDuration, "Timelock time not met");
}
_;
}
// Change the owner of the token contract
// --------------------
function startGovernanceChange(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 1;
_timelock_address = _address;
}
function finishGovernanceChange() external onlyGovernance timelockConditionsMet(1) {
transferGovernance(_timelock_address);
}
// --------------------
// Change the treasury address
// --------------------
function startChangeStrategy(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 2;
_timelock_address = _address;
_pendingStrategy = _address;
if(totalSupply() == 0){
// Can change strategy with one call in this case
finishChangeStrategy();
}
}
function finishChangeStrategy() public onlyGovernance timelockConditionsMet(2) {
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(_timelock_address);
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
pushTokensToStrategy(); // It will push any strategy reward tokens here to the new strategy
currentStrategy.enter(); // Puts all the tokens and accessory tokens into the new strategy
}
_pendingStrategy = address(0);
}
function pushTokensToStrategy() internal {
uint256 tokenCount = currentStrategy.rewardTokensCount();
for(uint256 i = 0; i < tokenCount; i++){
IERC20 _token = IERC20(address(currentStrategy.rewardTokenAddress(i)));
uint256 _balance = _token.balanceOf(address(this));
if(_balance > 0){
_token.safeTransfer(address(currentStrategy), _balance);
}
}
}
// --------------------
// Change the price oracle contract used, in case of upgrades
// --------------------
function startChangePriceOracle(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 3;
_timelock_address = _address;
}
function finishChangePriceOracle() external onlyGovernance timelockConditionsMet(3) {
oracleContract = StabilizePriceOracle(_timelock_address);
}
// --------------------
} | startGovernanceChange | function startGovernanceChange(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 1;
_timelock_address = _address;
}
| // Change the owner of the token contract
// -------------------- | LineComment | v0.6.6+commit.6c089d02 | GNU GPLv3 | ipfs://8e948a2b0bcce26275886d6ae593ebc412e92063b525d6ad037caba99c13731c | {
"func_code_index": [
15383,
15574
]
} | 2,485 |
||
zsToken | contracts/zsToken.sol | 0x8e769eaa31375d13a1247de1e64987c28bed987e | Solidity | zsToken | contract zsToken is ERC20("Stabilize Strategy Multi-Token", "zs-USD"), Ownable, ReentrancyGuard {
using SafeERC20 for IERC20;
// Variables
uint256 constant divisionFactor = 100000;
StabilizePriceOracle private oracleContract; // A reference to the price oracle contract
// There are no fees to deposit and withdraw from the zs-Tokens
// Info of each user.
struct UserInfo {
uint256 depositTime; // The time the user made the last deposit
uint256 shareEstimate;
}
mapping(address => UserInfo) private userInfo;
// Token information
// This wrapped token accepts multiple stablecoins
// DAI, USDC, USDT, sUSD
struct TokenInfo {
IERC20 token; // Reference of token
uint256 decimals; // Decimals of token
uint256 price; // Last price of token in USD
}
TokenInfo[] private tokenList; // An array of tokens accepted as deposits
address private _underlyingPriceAsset; // Token from which the price is derived
bool public depositsOpen = true; // Governance can open or close deposits without timelock, cannot block withdrawals
// Strategy information
StabilizeStrategy private currentStrategy; // This will be the contract for the strategy
address private _pendingStrategy;
// Events
event Wrapped(address indexed user, uint256 amount);
event Unwrapped(address indexed user, uint256 amount);
constructor (address _priceAsset, StabilizePriceOracle _oracle) public {
_underlyingPriceAsset = _priceAsset;
oracleContract = _oracle;
setupTokens();
}
function setupTokens() internal {
// Start with DAI
IERC20 _token = IERC20(address(0x6B175474E89094C44Da98b954EedeAC495271d0F));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDC
_token = IERC20(address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDT
_token = IERC20(address(0xdAC17F958D2ee523a2206206994597C13D831ec7));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// sUSD
_token = IERC20(address(0x57Ab1ec28D129707052df4dF418D58a2D46d5f51));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
}
function getCurrentStrategy() external view returns (address) {
return address(currentStrategy);
}
function getPendingStrategy() external view returns (address) {
return _pendingStrategy;
}
function underlyingAsset() public view returns (address) {
// Can be used if staking in the STBZ pool
return address(_underlyingPriceAsset);
}
function underlyingDepositAssets() public view returns (address, address, address, address) {
// Returns all addresses accepted by this token vault
return (address(tokenList[0].token), address(tokenList[1].token), address(tokenList[2].token), address(tokenList[3].token));
}
function pricePerToken() public view returns (uint256) {
if(totalSupply() == 0){
return 1e18; // Shown in Wei units
}else{
return uint256(1e18).mul(valueOfVaultAndStrategy()).div(totalSupply());
}
}
function getNormalizedTotalBalance(address _address) public view returns (uint256) {
uint256 _balance = 0;
for(uint256 i = 0; i < tokenList.length; i++){
uint256 _bal = tokenList[i].token.balanceOf(_address);
_bal = _bal.mul(1e18).div(10**tokenList[i].decimals);
_balance = _balance.add(_bal); // This has been normalized to 1e18 decimals
}
return _balance;
}
function valueOfVaultAndStrategy() public view returns (uint256) { // The total value of the tokens
uint256 balance = getNormalizedTotalBalance(address(this)); // Get tokens stored in this contract
if(currentStrategy != StabilizeStrategy(address(0))){
balance += currentStrategy.balance(); // And tokens stored at the strategy
}
return balance;
}
function withdrawTokenReserves() public view returns (address, uint256) {
// This function will return the address and amount of the token with the lowest price
if(currentStrategy != StabilizeStrategy(address(0))){
return currentStrategy.withdrawTokenReserves();
}else{
uint256 length = tokenList.length;
uint256 targetID = 0;
uint256 targetPrice = 0;
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
uint256 _price = tokenList[i].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i;
}
}
}
if(targetPrice > 0){
return (address(tokenList[targetID].token), tokenList[targetID].token.balanceOf(address(this)));
}else{
return (address(0), 0); // No balance
}
}
}
function updateTokenPrices() internal {
for(uint256 i = 0; i < tokenList.length; i++){
uint256 price = oracleContract.getPrice(address(tokenList[i].token));
if(price > 0){
tokenList[i].price = price;
}
}
}
// Now handle deposits into the strategy
function deposit(uint256 amount, uint256 _tokenID) public nonReentrant {
uint256 total = valueOfVaultAndStrategy(); // Get token equivalent at strategy and here if applicable
require(depositsOpen == true, "Deposits have been suspended, but you can still withdraw");
require(currentStrategy != StabilizeStrategy(address(0)),"No strategy contract has been selected yet");
require(_tokenID < tokenList.length, "Token ID is outside range of tokens in contract");
IERC20 _token = tokenList[_tokenID].token; // Trusted tokens
uint256 _before = _token.balanceOf(address(this));
_token.safeTransferFrom(_msgSender(), address(this), amount); // Transfer token to this address
amount = _token.balanceOf(address(this)).sub(_before); // Some tokens lose amount (transfer fee) upon transfer
require(amount > 0, "Cannot deposit 0");
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}
uint256 _strategyBalance = currentStrategy.balance(); // Will get the balance of the value of the main tokens at the strategy
// Now call the strategy to deposit
pushTokensToStrategy(); // Push any strategy tokens here into the strategy
currentStrategy.deposit(nonContract); // Activate strategy deposit
require(currentStrategy.balance() > _strategyBalance, "No change in strategy balance"); // Balance should increase
uint256 normalizedAmount = amount.mul(1e18).div(10**tokenList[_tokenID].decimals); // Make sure everything is same units
uint256 mintAmount = normalizedAmount;
if(totalSupply() > 0){
// There is already a balance here, calculate our share
mintAmount = normalizedAmount.mul(totalSupply()).div(total); // Our share of the total
}
_mint(_msgSender(),mintAmount); // Now mint new zs-token to the depositor
// Add the user information
userInfo[_msgSender()].depositTime = now;
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.add(mintAmount);
emit Wrapped(_msgSender(), amount);
}
function redeem(uint256 share) public nonReentrant {
// Essentially withdraw our equivalent share of the pool based on share value
// Users cannot choose which stablecoin they get. They get the lowest valued coin up to the highest value
require(share > 0, "Cannot withdraw 0");
require(totalSupply() > 0, "No value redeemable");
uint256 tokenTotal = totalSupply();
// Now burn the token
_burn(_msgSender(),share); // Burn the amount, will fail if user doesn't have enough
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}else{
// This is a contract redeeming
require(userInfo[_msgSender()].depositTime < now && userInfo[_msgSender()].depositTime > 0, "Contract depositor cannot redeem in same transaction");
}
// Update user information
if(share <= userInfo[_msgSender()].shareEstimate){
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.sub(share);
}else{
// Share is greater than our share estimate, can happen if tokens are transferred
userInfo[_msgSender()].shareEstimate = 0;
require(nonContract == true, "Contract depositors cannot take out more than what they put in");
}
uint256 withdrawAmount = 0;
if(currentStrategy != StabilizeStrategy(address(0))){
withdrawAmount = currentStrategy.withdraw(_msgSender(), share, tokenTotal, nonContract); // Returns the amount of underlying removed
require(withdrawAmount > 0, "Failed to withdraw from the strategy");
}else{
// Pull directly from this contract the token amount in relation to the share if strategy not used
if(share < tokenTotal){
uint256 _balance = getNormalizedTotalBalance(address(this));
uint256 _myBalance = _balance.mul(share).div(tokenTotal);
withdrawPerPrice(_msgSender(), _myBalance, false); // This will withdraw based on token price
withdrawAmount = _myBalance;
}else{
// We are all shares, transfer all
uint256 _balance = getNormalizedTotalBalance(address(this));
withdrawPerPrice(_msgSender(), _balance, true);
withdrawAmount = _balance;
}
}
emit Unwrapped(_msgSender(), withdrawAmount);
}
// This will withdraw the tokens from the contract based on their price, from lowest price to highest
function withdrawPerPrice(address _receiver, uint256 _withdrawAmount, bool _takeAll) internal {
uint256 length = tokenList.length;
if(_takeAll == true){
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
tokenList[i].token.safeTransfer(_receiver, tokenList[i].token.balanceOf(address(this)));
}
}
return;
}
bool[4] memory done;
uint256 targetID = 0;
uint256 targetPrice = 0;
updateTokenPrices();
for(uint256 i = 0; i < length; i++){
targetPrice = 0; // Reset the target price
// Find the lowest priced token to withdraw
for(uint256 i2 = 0; i2 < length; i2++){
if(done[i2] == false){
uint256 _price = tokenList[i2].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i2;
}
}
}
done[targetID] = true;
// Determine the balance left
uint256 _normalizedBalance = tokenList[targetID].token.balanceOf(address(this)).mul(1e18).div(10**tokenList[targetID].decimals);
if(_normalizedBalance <= _withdrawAmount){
// Withdraw the entire balance of this token
if(_normalizedBalance > 0){
_withdrawAmount = _withdrawAmount.sub(_normalizedBalance);
tokenList[targetID].token.safeTransfer(_receiver, tokenList[targetID].token.balanceOf(address(this)));
}
}else{
// Withdraw a partial amount of this token
if(_withdrawAmount > 0){
// Convert the withdraw amount to the token's decimal amount
uint256 _balance = _withdrawAmount.mul(10**tokenList[targetID].decimals).div(1e18);
_withdrawAmount = 0;
tokenList[targetID].token.safeTransfer(_receiver, _balance);
}
break; // Nothing more to withdraw
}
}
}
// Governance functions
// Stop/start all deposits, no timelock required
// --------------------
function stopDeposits() external onlyGovernance {
depositsOpen = false;
}
function startDeposits() external onlyGovernance {
depositsOpen = true;
}
// A function used in case of strategy failure, possibly due to bug in theplatform our strategy is using, governance can stop using it quick
function emergencyStopStrategy() external onlyGovernance {
depositsOpen = false;
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(address(0));
_timelockType = 0; // Prevent governance from changing to new strategy without timelock
}
// --------------------
// Timelock variables
uint256 private _timelockStart; // The start of the timelock to change governance variables
uint256 private _timelockType; // The function that needs to be changed
uint256 constant _timelockDuration = 86400; // Timelock is 24 hours
// Reusable timelock variables
address private _timelock_address;
modifier timelockConditionsMet(uint256 _type) {
require(_timelockType == _type, "Timelock not acquired for this function");
_timelockType = 0; // Reset the type once the timelock is used
if(totalSupply() > 0){
// Timelock is only required after tokens exist
require(now >= _timelockStart + _timelockDuration, "Timelock time not met");
}
_;
}
// Change the owner of the token contract
// --------------------
function startGovernanceChange(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 1;
_timelock_address = _address;
}
function finishGovernanceChange() external onlyGovernance timelockConditionsMet(1) {
transferGovernance(_timelock_address);
}
// --------------------
// Change the treasury address
// --------------------
function startChangeStrategy(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 2;
_timelock_address = _address;
_pendingStrategy = _address;
if(totalSupply() == 0){
// Can change strategy with one call in this case
finishChangeStrategy();
}
}
function finishChangeStrategy() public onlyGovernance timelockConditionsMet(2) {
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(_timelock_address);
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
pushTokensToStrategy(); // It will push any strategy reward tokens here to the new strategy
currentStrategy.enter(); // Puts all the tokens and accessory tokens into the new strategy
}
_pendingStrategy = address(0);
}
function pushTokensToStrategy() internal {
uint256 tokenCount = currentStrategy.rewardTokensCount();
for(uint256 i = 0; i < tokenCount; i++){
IERC20 _token = IERC20(address(currentStrategy.rewardTokenAddress(i)));
uint256 _balance = _token.balanceOf(address(this));
if(_balance > 0){
_token.safeTransfer(address(currentStrategy), _balance);
}
}
}
// --------------------
// Change the price oracle contract used, in case of upgrades
// --------------------
function startChangePriceOracle(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 3;
_timelock_address = _address;
}
function finishChangePriceOracle() external onlyGovernance timelockConditionsMet(3) {
oracleContract = StabilizePriceOracle(_timelock_address);
}
// --------------------
} | startChangeStrategy | function startChangeStrategy(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 2;
_timelock_address = _address;
_pendingStrategy = _address;
if(totalSupply() == 0){
// Can change strategy with one call in this case
finishChangeStrategy();
}
}
| // --------------------
// Change the treasury address
// -------------------- | LineComment | v0.6.6+commit.6c089d02 | GNU GPLv3 | ipfs://8e948a2b0bcce26275886d6ae593ebc412e92063b525d6ad037caba99c13731c | {
"func_code_index": [
15832,
16196
]
} | 2,486 |
||
zsToken | contracts/zsToken.sol | 0x8e769eaa31375d13a1247de1e64987c28bed987e | Solidity | zsToken | contract zsToken is ERC20("Stabilize Strategy Multi-Token", "zs-USD"), Ownable, ReentrancyGuard {
using SafeERC20 for IERC20;
// Variables
uint256 constant divisionFactor = 100000;
StabilizePriceOracle private oracleContract; // A reference to the price oracle contract
// There are no fees to deposit and withdraw from the zs-Tokens
// Info of each user.
struct UserInfo {
uint256 depositTime; // The time the user made the last deposit
uint256 shareEstimate;
}
mapping(address => UserInfo) private userInfo;
// Token information
// This wrapped token accepts multiple stablecoins
// DAI, USDC, USDT, sUSD
struct TokenInfo {
IERC20 token; // Reference of token
uint256 decimals; // Decimals of token
uint256 price; // Last price of token in USD
}
TokenInfo[] private tokenList; // An array of tokens accepted as deposits
address private _underlyingPriceAsset; // Token from which the price is derived
bool public depositsOpen = true; // Governance can open or close deposits without timelock, cannot block withdrawals
// Strategy information
StabilizeStrategy private currentStrategy; // This will be the contract for the strategy
address private _pendingStrategy;
// Events
event Wrapped(address indexed user, uint256 amount);
event Unwrapped(address indexed user, uint256 amount);
constructor (address _priceAsset, StabilizePriceOracle _oracle) public {
_underlyingPriceAsset = _priceAsset;
oracleContract = _oracle;
setupTokens();
}
function setupTokens() internal {
// Start with DAI
IERC20 _token = IERC20(address(0x6B175474E89094C44Da98b954EedeAC495271d0F));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDC
_token = IERC20(address(0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// USDT
_token = IERC20(address(0xdAC17F958D2ee523a2206206994597C13D831ec7));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
// sUSD
_token = IERC20(address(0x57Ab1ec28D129707052df4dF418D58a2D46d5f51));
tokenList.push(
TokenInfo({
token: _token,
decimals: _token.decimals(),
price: 1e18
})
);
}
function getCurrentStrategy() external view returns (address) {
return address(currentStrategy);
}
function getPendingStrategy() external view returns (address) {
return _pendingStrategy;
}
function underlyingAsset() public view returns (address) {
// Can be used if staking in the STBZ pool
return address(_underlyingPriceAsset);
}
function underlyingDepositAssets() public view returns (address, address, address, address) {
// Returns all addresses accepted by this token vault
return (address(tokenList[0].token), address(tokenList[1].token), address(tokenList[2].token), address(tokenList[3].token));
}
function pricePerToken() public view returns (uint256) {
if(totalSupply() == 0){
return 1e18; // Shown in Wei units
}else{
return uint256(1e18).mul(valueOfVaultAndStrategy()).div(totalSupply());
}
}
function getNormalizedTotalBalance(address _address) public view returns (uint256) {
uint256 _balance = 0;
for(uint256 i = 0; i < tokenList.length; i++){
uint256 _bal = tokenList[i].token.balanceOf(_address);
_bal = _bal.mul(1e18).div(10**tokenList[i].decimals);
_balance = _balance.add(_bal); // This has been normalized to 1e18 decimals
}
return _balance;
}
function valueOfVaultAndStrategy() public view returns (uint256) { // The total value of the tokens
uint256 balance = getNormalizedTotalBalance(address(this)); // Get tokens stored in this contract
if(currentStrategy != StabilizeStrategy(address(0))){
balance += currentStrategy.balance(); // And tokens stored at the strategy
}
return balance;
}
function withdrawTokenReserves() public view returns (address, uint256) {
// This function will return the address and amount of the token with the lowest price
if(currentStrategy != StabilizeStrategy(address(0))){
return currentStrategy.withdrawTokenReserves();
}else{
uint256 length = tokenList.length;
uint256 targetID = 0;
uint256 targetPrice = 0;
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
uint256 _price = tokenList[i].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i;
}
}
}
if(targetPrice > 0){
return (address(tokenList[targetID].token), tokenList[targetID].token.balanceOf(address(this)));
}else{
return (address(0), 0); // No balance
}
}
}
function updateTokenPrices() internal {
for(uint256 i = 0; i < tokenList.length; i++){
uint256 price = oracleContract.getPrice(address(tokenList[i].token));
if(price > 0){
tokenList[i].price = price;
}
}
}
// Now handle deposits into the strategy
function deposit(uint256 amount, uint256 _tokenID) public nonReentrant {
uint256 total = valueOfVaultAndStrategy(); // Get token equivalent at strategy and here if applicable
require(depositsOpen == true, "Deposits have been suspended, but you can still withdraw");
require(currentStrategy != StabilizeStrategy(address(0)),"No strategy contract has been selected yet");
require(_tokenID < tokenList.length, "Token ID is outside range of tokens in contract");
IERC20 _token = tokenList[_tokenID].token; // Trusted tokens
uint256 _before = _token.balanceOf(address(this));
_token.safeTransferFrom(_msgSender(), address(this), amount); // Transfer token to this address
amount = _token.balanceOf(address(this)).sub(_before); // Some tokens lose amount (transfer fee) upon transfer
require(amount > 0, "Cannot deposit 0");
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}
uint256 _strategyBalance = currentStrategy.balance(); // Will get the balance of the value of the main tokens at the strategy
// Now call the strategy to deposit
pushTokensToStrategy(); // Push any strategy tokens here into the strategy
currentStrategy.deposit(nonContract); // Activate strategy deposit
require(currentStrategy.balance() > _strategyBalance, "No change in strategy balance"); // Balance should increase
uint256 normalizedAmount = amount.mul(1e18).div(10**tokenList[_tokenID].decimals); // Make sure everything is same units
uint256 mintAmount = normalizedAmount;
if(totalSupply() > 0){
// There is already a balance here, calculate our share
mintAmount = normalizedAmount.mul(totalSupply()).div(total); // Our share of the total
}
_mint(_msgSender(),mintAmount); // Now mint new zs-token to the depositor
// Add the user information
userInfo[_msgSender()].depositTime = now;
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.add(mintAmount);
emit Wrapped(_msgSender(), amount);
}
function redeem(uint256 share) public nonReentrant {
// Essentially withdraw our equivalent share of the pool based on share value
// Users cannot choose which stablecoin they get. They get the lowest valued coin up to the highest value
require(share > 0, "Cannot withdraw 0");
require(totalSupply() > 0, "No value redeemable");
uint256 tokenTotal = totalSupply();
// Now burn the token
_burn(_msgSender(),share); // Burn the amount, will fail if user doesn't have enough
bool nonContract = false;
if(tx.origin == _msgSender()){
nonContract = true; // The sender is not a contract, we will allow market sells and buys
}else{
// This is a contract redeeming
require(userInfo[_msgSender()].depositTime < now && userInfo[_msgSender()].depositTime > 0, "Contract depositor cannot redeem in same transaction");
}
// Update user information
if(share <= userInfo[_msgSender()].shareEstimate){
userInfo[_msgSender()].shareEstimate = userInfo[_msgSender()].shareEstimate.sub(share);
}else{
// Share is greater than our share estimate, can happen if tokens are transferred
userInfo[_msgSender()].shareEstimate = 0;
require(nonContract == true, "Contract depositors cannot take out more than what they put in");
}
uint256 withdrawAmount = 0;
if(currentStrategy != StabilizeStrategy(address(0))){
withdrawAmount = currentStrategy.withdraw(_msgSender(), share, tokenTotal, nonContract); // Returns the amount of underlying removed
require(withdrawAmount > 0, "Failed to withdraw from the strategy");
}else{
// Pull directly from this contract the token amount in relation to the share if strategy not used
if(share < tokenTotal){
uint256 _balance = getNormalizedTotalBalance(address(this));
uint256 _myBalance = _balance.mul(share).div(tokenTotal);
withdrawPerPrice(_msgSender(), _myBalance, false); // This will withdraw based on token price
withdrawAmount = _myBalance;
}else{
// We are all shares, transfer all
uint256 _balance = getNormalizedTotalBalance(address(this));
withdrawPerPrice(_msgSender(), _balance, true);
withdrawAmount = _balance;
}
}
emit Unwrapped(_msgSender(), withdrawAmount);
}
// This will withdraw the tokens from the contract based on their price, from lowest price to highest
function withdrawPerPrice(address _receiver, uint256 _withdrawAmount, bool _takeAll) internal {
uint256 length = tokenList.length;
if(_takeAll == true){
for(uint256 i = 0; i < length; i++){
if(tokenList[i].token.balanceOf(address(this)) > 0){
tokenList[i].token.safeTransfer(_receiver, tokenList[i].token.balanceOf(address(this)));
}
}
return;
}
bool[4] memory done;
uint256 targetID = 0;
uint256 targetPrice = 0;
updateTokenPrices();
for(uint256 i = 0; i < length; i++){
targetPrice = 0; // Reset the target price
// Find the lowest priced token to withdraw
for(uint256 i2 = 0; i2 < length; i2++){
if(done[i2] == false){
uint256 _price = tokenList[i2].price;
if(targetPrice == 0 || _price <= targetPrice){
targetPrice = _price;
targetID = i2;
}
}
}
done[targetID] = true;
// Determine the balance left
uint256 _normalizedBalance = tokenList[targetID].token.balanceOf(address(this)).mul(1e18).div(10**tokenList[targetID].decimals);
if(_normalizedBalance <= _withdrawAmount){
// Withdraw the entire balance of this token
if(_normalizedBalance > 0){
_withdrawAmount = _withdrawAmount.sub(_normalizedBalance);
tokenList[targetID].token.safeTransfer(_receiver, tokenList[targetID].token.balanceOf(address(this)));
}
}else{
// Withdraw a partial amount of this token
if(_withdrawAmount > 0){
// Convert the withdraw amount to the token's decimal amount
uint256 _balance = _withdrawAmount.mul(10**tokenList[targetID].decimals).div(1e18);
_withdrawAmount = 0;
tokenList[targetID].token.safeTransfer(_receiver, _balance);
}
break; // Nothing more to withdraw
}
}
}
// Governance functions
// Stop/start all deposits, no timelock required
// --------------------
function stopDeposits() external onlyGovernance {
depositsOpen = false;
}
function startDeposits() external onlyGovernance {
depositsOpen = true;
}
// A function used in case of strategy failure, possibly due to bug in theplatform our strategy is using, governance can stop using it quick
function emergencyStopStrategy() external onlyGovernance {
depositsOpen = false;
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(address(0));
_timelockType = 0; // Prevent governance from changing to new strategy without timelock
}
// --------------------
// Timelock variables
uint256 private _timelockStart; // The start of the timelock to change governance variables
uint256 private _timelockType; // The function that needs to be changed
uint256 constant _timelockDuration = 86400; // Timelock is 24 hours
// Reusable timelock variables
address private _timelock_address;
modifier timelockConditionsMet(uint256 _type) {
require(_timelockType == _type, "Timelock not acquired for this function");
_timelockType = 0; // Reset the type once the timelock is used
if(totalSupply() > 0){
// Timelock is only required after tokens exist
require(now >= _timelockStart + _timelockDuration, "Timelock time not met");
}
_;
}
// Change the owner of the token contract
// --------------------
function startGovernanceChange(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 1;
_timelock_address = _address;
}
function finishGovernanceChange() external onlyGovernance timelockConditionsMet(1) {
transferGovernance(_timelock_address);
}
// --------------------
// Change the treasury address
// --------------------
function startChangeStrategy(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 2;
_timelock_address = _address;
_pendingStrategy = _address;
if(totalSupply() == 0){
// Can change strategy with one call in this case
finishChangeStrategy();
}
}
function finishChangeStrategy() public onlyGovernance timelockConditionsMet(2) {
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
currentStrategy.exit(); // Pulls all the tokens and accessory tokens from the strategy
}
currentStrategy = StabilizeStrategy(_timelock_address);
if(currentStrategy != StabilizeStrategy(address(0)) && totalSupply() > 0){
pushTokensToStrategy(); // It will push any strategy reward tokens here to the new strategy
currentStrategy.enter(); // Puts all the tokens and accessory tokens into the new strategy
}
_pendingStrategy = address(0);
}
function pushTokensToStrategy() internal {
uint256 tokenCount = currentStrategy.rewardTokensCount();
for(uint256 i = 0; i < tokenCount; i++){
IERC20 _token = IERC20(address(currentStrategy.rewardTokenAddress(i)));
uint256 _balance = _token.balanceOf(address(this));
if(_balance > 0){
_token.safeTransfer(address(currentStrategy), _balance);
}
}
}
// --------------------
// Change the price oracle contract used, in case of upgrades
// --------------------
function startChangePriceOracle(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 3;
_timelock_address = _address;
}
function finishChangePriceOracle() external onlyGovernance timelockConditionsMet(3) {
oracleContract = StabilizePriceOracle(_timelock_address);
}
// --------------------
} | startChangePriceOracle | function startChangePriceOracle(address _address) external onlyGovernance {
_timelockStart = now;
_timelockType = 3;
_timelock_address = _address;
}
| // --------------------
// Change the price oracle contract used, in case of upgrades
// -------------------- | LineComment | v0.6.6+commit.6c089d02 | GNU GPLv3 | ipfs://8e948a2b0bcce26275886d6ae593ebc412e92063b525d6ad037caba99c13731c | {
"func_code_index": [
17488,
17673
]
} | 2,487 |
||
VERANDEREN | VERANDEREN.sol | 0x4ccf916be7c11ea395c418b278f830a2b77f5f0f | Solidity | Context | contract Context {
constructor() internal {}
// solhint-disable-previous-line no-empty-blocks
function _msgSender() internal view returns(address payable) {
return msg.sender;
}
} | _msgSender | function _msgSender() internal view returns(address payable) {
return msg.sender;
}
| // solhint-disable-previous-line no-empty-blocks | LineComment | v0.5.17+commit.d19bba13 | MIT | bzzr://506616be013ce90ccfe60b3e05aec3ccdff899dd1e6e94c3c8d2fcb97c7ab543 | {
"func_code_index": [
105,
207
]
} | 2,488 |
||
ReserveManager | contracts/saga/ReserveManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | ReserveManager | contract ReserveManager is IReserveManager, ContractAddressLocatorHolder, Claimable {
string public constant VERSION = "1.0.0";
using SafeMath for uint256;
struct Wallets {
address deposit;
address withdraw;
}
struct Thresholds {
uint256 min;
uint256 max;
uint256 mid;
}
Wallets public wallets;
Thresholds public thresholds;
uint256 public walletsSequenceNum = 0;
uint256 public thresholdsSequenceNum = 0;
event ReserveWalletsSaved(address _deposit, address _withdraw);
event ReserveWalletsNotSaved(address _deposit, address _withdraw);
event ReserveThresholdsSaved(uint256 _min, uint256 _max, uint256 _mid);
event ReserveThresholdsNotSaved(uint256 _min, uint256 _max, uint256 _mid);
/**
* @dev Create the contract.
* @param _contractAddressLocator The contract address locator.
*/
constructor(IContractAddressLocator _contractAddressLocator) ContractAddressLocatorHolder(_contractAddressLocator) public {}
/**
* @dev Return the contract which implements the IETHConverter interface.
*/
function getETHConverter() public view returns (IETHConverter) {
return IETHConverter(getContractAddress(_IETHConverter_));
}
/**
* @dev Return the contract which implements the IPaymentManager interface.
*/
function getPaymentManager() public view returns (IPaymentManager) {
return IPaymentManager(getContractAddress(_IPaymentManager_));
}
/**
* @dev Set the reserve wallets.
* @param _walletsSequenceNum The sequence-number of the operation.
* @param _deposit The address of the wallet permitted to deposit ETH into the token-contract.
* @param _withdraw The address of the wallet permitted to withdraw ETH from the token-contract.
*/
function setWallets(uint256 _walletsSequenceNum, address _deposit, address _withdraw) external onlyOwner {
require(_deposit != address(0), "deposit-wallet is illegal");
require(_withdraw != address(0), "withdraw-wallet is illegal");
if (walletsSequenceNum < _walletsSequenceNum) {
walletsSequenceNum = _walletsSequenceNum;
wallets.deposit = _deposit;
wallets.withdraw = _withdraw;
emit ReserveWalletsSaved(_deposit, _withdraw);
}
else {
emit ReserveWalletsNotSaved(_deposit, _withdraw);
}
}
/**
* @dev Set the reserve thresholds.
* @param _thresholdsSequenceNum The sequence-number of the operation.
* @param _min The maximum balance which allows depositing ETH from the token-contract.
* @param _max The minimum balance which allows withdrawing ETH into the token-contract.
* @param _mid The balance that the deposit/withdraw recommendation functions will yield.
*/
function setThresholds(uint256 _thresholdsSequenceNum, uint256 _min, uint256 _max, uint256 _mid) external onlyOwner {
require(_min <= _mid, "min-threshold is greater than mid-threshold");
require(_max >= _mid, "max-threshold is smaller than mid-threshold");
if (thresholdsSequenceNum < _thresholdsSequenceNum) {
thresholdsSequenceNum = _thresholdsSequenceNum;
thresholds.min = _min;
thresholds.max = _max;
thresholds.mid = _mid;
emit ReserveThresholdsSaved(_min, _max, _mid);
}
else {
emit ReserveThresholdsNotSaved(_min, _max, _mid);
}
}
/**
* @dev Get a deposit-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to deposit ETH into the token-contract.
* @return The amount that should be deposited in order for the balance to reach `mid` ETH.
*/
function getDepositParams(uint256 _balance) external view returns (address, uint256) {
uint256 depositRecommendation = 0;
uint256 sdrPaymentsSum = getPaymentManager().getPaymentsSum();
uint256 ethPaymentsSum = getETHConverter().toEthAmount(sdrPaymentsSum);
if (ethPaymentsSum >= _balance || (_balance - ethPaymentsSum) <= thresholds.min){// first part of the condition
// prevents underflow in the second part
depositRecommendation = (thresholds.mid).add(ethPaymentsSum) - _balance;// will never underflow
}
return (wallets.deposit, depositRecommendation);
}
/**
* @dev Get a withdraw-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to withdraw ETH into the token-contract.
* @return The amount that should be withdrawn in order for the balance to reach `mid` ETH.
*/
function getWithdrawParams(uint256 _balance) external view returns (address, uint256) {
uint256 withdrawRecommendationAmount = 0;
if (_balance >= thresholds.max && getPaymentManager().getNumOfPayments() == 0){// _balance >= thresholds.max >= thresholds.mid
withdrawRecommendationAmount = _balance - thresholds.mid; // will never underflow
}
return (wallets.withdraw, withdrawRecommendationAmount);
}
} | /**
* @title Reserve Manager.
*/ | NatSpecMultiLine | getETHConverter | function getETHConverter() public view returns (IETHConverter) {
return IETHConverter(getContractAddress(_IETHConverter_));
}
| /**
* @dev Return the contract which implements the IETHConverter interface.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
1129,
1270
]
} | 2,489 |
ReserveManager | contracts/saga/ReserveManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | ReserveManager | contract ReserveManager is IReserveManager, ContractAddressLocatorHolder, Claimable {
string public constant VERSION = "1.0.0";
using SafeMath for uint256;
struct Wallets {
address deposit;
address withdraw;
}
struct Thresholds {
uint256 min;
uint256 max;
uint256 mid;
}
Wallets public wallets;
Thresholds public thresholds;
uint256 public walletsSequenceNum = 0;
uint256 public thresholdsSequenceNum = 0;
event ReserveWalletsSaved(address _deposit, address _withdraw);
event ReserveWalletsNotSaved(address _deposit, address _withdraw);
event ReserveThresholdsSaved(uint256 _min, uint256 _max, uint256 _mid);
event ReserveThresholdsNotSaved(uint256 _min, uint256 _max, uint256 _mid);
/**
* @dev Create the contract.
* @param _contractAddressLocator The contract address locator.
*/
constructor(IContractAddressLocator _contractAddressLocator) ContractAddressLocatorHolder(_contractAddressLocator) public {}
/**
* @dev Return the contract which implements the IETHConverter interface.
*/
function getETHConverter() public view returns (IETHConverter) {
return IETHConverter(getContractAddress(_IETHConverter_));
}
/**
* @dev Return the contract which implements the IPaymentManager interface.
*/
function getPaymentManager() public view returns (IPaymentManager) {
return IPaymentManager(getContractAddress(_IPaymentManager_));
}
/**
* @dev Set the reserve wallets.
* @param _walletsSequenceNum The sequence-number of the operation.
* @param _deposit The address of the wallet permitted to deposit ETH into the token-contract.
* @param _withdraw The address of the wallet permitted to withdraw ETH from the token-contract.
*/
function setWallets(uint256 _walletsSequenceNum, address _deposit, address _withdraw) external onlyOwner {
require(_deposit != address(0), "deposit-wallet is illegal");
require(_withdraw != address(0), "withdraw-wallet is illegal");
if (walletsSequenceNum < _walletsSequenceNum) {
walletsSequenceNum = _walletsSequenceNum;
wallets.deposit = _deposit;
wallets.withdraw = _withdraw;
emit ReserveWalletsSaved(_deposit, _withdraw);
}
else {
emit ReserveWalletsNotSaved(_deposit, _withdraw);
}
}
/**
* @dev Set the reserve thresholds.
* @param _thresholdsSequenceNum The sequence-number of the operation.
* @param _min The maximum balance which allows depositing ETH from the token-contract.
* @param _max The minimum balance which allows withdrawing ETH into the token-contract.
* @param _mid The balance that the deposit/withdraw recommendation functions will yield.
*/
function setThresholds(uint256 _thresholdsSequenceNum, uint256 _min, uint256 _max, uint256 _mid) external onlyOwner {
require(_min <= _mid, "min-threshold is greater than mid-threshold");
require(_max >= _mid, "max-threshold is smaller than mid-threshold");
if (thresholdsSequenceNum < _thresholdsSequenceNum) {
thresholdsSequenceNum = _thresholdsSequenceNum;
thresholds.min = _min;
thresholds.max = _max;
thresholds.mid = _mid;
emit ReserveThresholdsSaved(_min, _max, _mid);
}
else {
emit ReserveThresholdsNotSaved(_min, _max, _mid);
}
}
/**
* @dev Get a deposit-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to deposit ETH into the token-contract.
* @return The amount that should be deposited in order for the balance to reach `mid` ETH.
*/
function getDepositParams(uint256 _balance) external view returns (address, uint256) {
uint256 depositRecommendation = 0;
uint256 sdrPaymentsSum = getPaymentManager().getPaymentsSum();
uint256 ethPaymentsSum = getETHConverter().toEthAmount(sdrPaymentsSum);
if (ethPaymentsSum >= _balance || (_balance - ethPaymentsSum) <= thresholds.min){// first part of the condition
// prevents underflow in the second part
depositRecommendation = (thresholds.mid).add(ethPaymentsSum) - _balance;// will never underflow
}
return (wallets.deposit, depositRecommendation);
}
/**
* @dev Get a withdraw-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to withdraw ETH into the token-contract.
* @return The amount that should be withdrawn in order for the balance to reach `mid` ETH.
*/
function getWithdrawParams(uint256 _balance) external view returns (address, uint256) {
uint256 withdrawRecommendationAmount = 0;
if (_balance >= thresholds.max && getPaymentManager().getNumOfPayments() == 0){// _balance >= thresholds.max >= thresholds.mid
withdrawRecommendationAmount = _balance - thresholds.mid; // will never underflow
}
return (wallets.withdraw, withdrawRecommendationAmount);
}
} | /**
* @title Reserve Manager.
*/ | NatSpecMultiLine | getPaymentManager | function getPaymentManager() public view returns (IPaymentManager) {
return IPaymentManager(getContractAddress(_IPaymentManager_));
}
| /**
* @dev Return the contract which implements the IPaymentManager interface.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
1368,
1517
]
} | 2,490 |
ReserveManager | contracts/saga/ReserveManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | ReserveManager | contract ReserveManager is IReserveManager, ContractAddressLocatorHolder, Claimable {
string public constant VERSION = "1.0.0";
using SafeMath for uint256;
struct Wallets {
address deposit;
address withdraw;
}
struct Thresholds {
uint256 min;
uint256 max;
uint256 mid;
}
Wallets public wallets;
Thresholds public thresholds;
uint256 public walletsSequenceNum = 0;
uint256 public thresholdsSequenceNum = 0;
event ReserveWalletsSaved(address _deposit, address _withdraw);
event ReserveWalletsNotSaved(address _deposit, address _withdraw);
event ReserveThresholdsSaved(uint256 _min, uint256 _max, uint256 _mid);
event ReserveThresholdsNotSaved(uint256 _min, uint256 _max, uint256 _mid);
/**
* @dev Create the contract.
* @param _contractAddressLocator The contract address locator.
*/
constructor(IContractAddressLocator _contractAddressLocator) ContractAddressLocatorHolder(_contractAddressLocator) public {}
/**
* @dev Return the contract which implements the IETHConverter interface.
*/
function getETHConverter() public view returns (IETHConverter) {
return IETHConverter(getContractAddress(_IETHConverter_));
}
/**
* @dev Return the contract which implements the IPaymentManager interface.
*/
function getPaymentManager() public view returns (IPaymentManager) {
return IPaymentManager(getContractAddress(_IPaymentManager_));
}
/**
* @dev Set the reserve wallets.
* @param _walletsSequenceNum The sequence-number of the operation.
* @param _deposit The address of the wallet permitted to deposit ETH into the token-contract.
* @param _withdraw The address of the wallet permitted to withdraw ETH from the token-contract.
*/
function setWallets(uint256 _walletsSequenceNum, address _deposit, address _withdraw) external onlyOwner {
require(_deposit != address(0), "deposit-wallet is illegal");
require(_withdraw != address(0), "withdraw-wallet is illegal");
if (walletsSequenceNum < _walletsSequenceNum) {
walletsSequenceNum = _walletsSequenceNum;
wallets.deposit = _deposit;
wallets.withdraw = _withdraw;
emit ReserveWalletsSaved(_deposit, _withdraw);
}
else {
emit ReserveWalletsNotSaved(_deposit, _withdraw);
}
}
/**
* @dev Set the reserve thresholds.
* @param _thresholdsSequenceNum The sequence-number of the operation.
* @param _min The maximum balance which allows depositing ETH from the token-contract.
* @param _max The minimum balance which allows withdrawing ETH into the token-contract.
* @param _mid The balance that the deposit/withdraw recommendation functions will yield.
*/
function setThresholds(uint256 _thresholdsSequenceNum, uint256 _min, uint256 _max, uint256 _mid) external onlyOwner {
require(_min <= _mid, "min-threshold is greater than mid-threshold");
require(_max >= _mid, "max-threshold is smaller than mid-threshold");
if (thresholdsSequenceNum < _thresholdsSequenceNum) {
thresholdsSequenceNum = _thresholdsSequenceNum;
thresholds.min = _min;
thresholds.max = _max;
thresholds.mid = _mid;
emit ReserveThresholdsSaved(_min, _max, _mid);
}
else {
emit ReserveThresholdsNotSaved(_min, _max, _mid);
}
}
/**
* @dev Get a deposit-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to deposit ETH into the token-contract.
* @return The amount that should be deposited in order for the balance to reach `mid` ETH.
*/
function getDepositParams(uint256 _balance) external view returns (address, uint256) {
uint256 depositRecommendation = 0;
uint256 sdrPaymentsSum = getPaymentManager().getPaymentsSum();
uint256 ethPaymentsSum = getETHConverter().toEthAmount(sdrPaymentsSum);
if (ethPaymentsSum >= _balance || (_balance - ethPaymentsSum) <= thresholds.min){// first part of the condition
// prevents underflow in the second part
depositRecommendation = (thresholds.mid).add(ethPaymentsSum) - _balance;// will never underflow
}
return (wallets.deposit, depositRecommendation);
}
/**
* @dev Get a withdraw-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to withdraw ETH into the token-contract.
* @return The amount that should be withdrawn in order for the balance to reach `mid` ETH.
*/
function getWithdrawParams(uint256 _balance) external view returns (address, uint256) {
uint256 withdrawRecommendationAmount = 0;
if (_balance >= thresholds.max && getPaymentManager().getNumOfPayments() == 0){// _balance >= thresholds.max >= thresholds.mid
withdrawRecommendationAmount = _balance - thresholds.mid; // will never underflow
}
return (wallets.withdraw, withdrawRecommendationAmount);
}
} | /**
* @title Reserve Manager.
*/ | NatSpecMultiLine | setWallets | function setWallets(uint256 _walletsSequenceNum, address _deposit, address _withdraw) external onlyOwner {
require(_deposit != address(0), "deposit-wallet is illegal");
require(_withdraw != address(0), "withdraw-wallet is illegal");
if (walletsSequenceNum < _walletsSequenceNum) {
walletsSequenceNum = _walletsSequenceNum;
wallets.deposit = _deposit;
wallets.withdraw = _withdraw;
emit ReserveWalletsSaved(_deposit, _withdraw);
}
else {
emit ReserveWalletsNotSaved(_deposit, _withdraw);
}
}
| /**
* @dev Set the reserve wallets.
* @param _walletsSequenceNum The sequence-number of the operation.
* @param _deposit The address of the wallet permitted to deposit ETH into the token-contract.
* @param _withdraw The address of the wallet permitted to withdraw ETH from the token-contract.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
1844,
2452
]
} | 2,491 |
ReserveManager | contracts/saga/ReserveManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | ReserveManager | contract ReserveManager is IReserveManager, ContractAddressLocatorHolder, Claimable {
string public constant VERSION = "1.0.0";
using SafeMath for uint256;
struct Wallets {
address deposit;
address withdraw;
}
struct Thresholds {
uint256 min;
uint256 max;
uint256 mid;
}
Wallets public wallets;
Thresholds public thresholds;
uint256 public walletsSequenceNum = 0;
uint256 public thresholdsSequenceNum = 0;
event ReserveWalletsSaved(address _deposit, address _withdraw);
event ReserveWalletsNotSaved(address _deposit, address _withdraw);
event ReserveThresholdsSaved(uint256 _min, uint256 _max, uint256 _mid);
event ReserveThresholdsNotSaved(uint256 _min, uint256 _max, uint256 _mid);
/**
* @dev Create the contract.
* @param _contractAddressLocator The contract address locator.
*/
constructor(IContractAddressLocator _contractAddressLocator) ContractAddressLocatorHolder(_contractAddressLocator) public {}
/**
* @dev Return the contract which implements the IETHConverter interface.
*/
function getETHConverter() public view returns (IETHConverter) {
return IETHConverter(getContractAddress(_IETHConverter_));
}
/**
* @dev Return the contract which implements the IPaymentManager interface.
*/
function getPaymentManager() public view returns (IPaymentManager) {
return IPaymentManager(getContractAddress(_IPaymentManager_));
}
/**
* @dev Set the reserve wallets.
* @param _walletsSequenceNum The sequence-number of the operation.
* @param _deposit The address of the wallet permitted to deposit ETH into the token-contract.
* @param _withdraw The address of the wallet permitted to withdraw ETH from the token-contract.
*/
function setWallets(uint256 _walletsSequenceNum, address _deposit, address _withdraw) external onlyOwner {
require(_deposit != address(0), "deposit-wallet is illegal");
require(_withdraw != address(0), "withdraw-wallet is illegal");
if (walletsSequenceNum < _walletsSequenceNum) {
walletsSequenceNum = _walletsSequenceNum;
wallets.deposit = _deposit;
wallets.withdraw = _withdraw;
emit ReserveWalletsSaved(_deposit, _withdraw);
}
else {
emit ReserveWalletsNotSaved(_deposit, _withdraw);
}
}
/**
* @dev Set the reserve thresholds.
* @param _thresholdsSequenceNum The sequence-number of the operation.
* @param _min The maximum balance which allows depositing ETH from the token-contract.
* @param _max The minimum balance which allows withdrawing ETH into the token-contract.
* @param _mid The balance that the deposit/withdraw recommendation functions will yield.
*/
function setThresholds(uint256 _thresholdsSequenceNum, uint256 _min, uint256 _max, uint256 _mid) external onlyOwner {
require(_min <= _mid, "min-threshold is greater than mid-threshold");
require(_max >= _mid, "max-threshold is smaller than mid-threshold");
if (thresholdsSequenceNum < _thresholdsSequenceNum) {
thresholdsSequenceNum = _thresholdsSequenceNum;
thresholds.min = _min;
thresholds.max = _max;
thresholds.mid = _mid;
emit ReserveThresholdsSaved(_min, _max, _mid);
}
else {
emit ReserveThresholdsNotSaved(_min, _max, _mid);
}
}
/**
* @dev Get a deposit-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to deposit ETH into the token-contract.
* @return The amount that should be deposited in order for the balance to reach `mid` ETH.
*/
function getDepositParams(uint256 _balance) external view returns (address, uint256) {
uint256 depositRecommendation = 0;
uint256 sdrPaymentsSum = getPaymentManager().getPaymentsSum();
uint256 ethPaymentsSum = getETHConverter().toEthAmount(sdrPaymentsSum);
if (ethPaymentsSum >= _balance || (_balance - ethPaymentsSum) <= thresholds.min){// first part of the condition
// prevents underflow in the second part
depositRecommendation = (thresholds.mid).add(ethPaymentsSum) - _balance;// will never underflow
}
return (wallets.deposit, depositRecommendation);
}
/**
* @dev Get a withdraw-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to withdraw ETH into the token-contract.
* @return The amount that should be withdrawn in order for the balance to reach `mid` ETH.
*/
function getWithdrawParams(uint256 _balance) external view returns (address, uint256) {
uint256 withdrawRecommendationAmount = 0;
if (_balance >= thresholds.max && getPaymentManager().getNumOfPayments() == 0){// _balance >= thresholds.max >= thresholds.mid
withdrawRecommendationAmount = _balance - thresholds.mid; // will never underflow
}
return (wallets.withdraw, withdrawRecommendationAmount);
}
} | /**
* @title Reserve Manager.
*/ | NatSpecMultiLine | setThresholds | function setThresholds(uint256 _thresholdsSequenceNum, uint256 _min, uint256 _max, uint256 _mid) external onlyOwner {
require(_min <= _mid, "min-threshold is greater than mid-threshold");
require(_max >= _mid, "max-threshold is smaller than mid-threshold");
if (thresholdsSequenceNum < _thresholdsSequenceNum) {
thresholdsSequenceNum = _thresholdsSequenceNum;
thresholds.min = _min;
thresholds.max = _max;
thresholds.mid = _mid;
emit ReserveThresholdsSaved(_min, _max, _mid);
}
else {
emit ReserveThresholdsNotSaved(_min, _max, _mid);
}
}
| /**
* @dev Set the reserve thresholds.
* @param _thresholdsSequenceNum The sequence-number of the operation.
* @param _min The maximum balance which allows depositing ETH from the token-contract.
* @param _max The minimum balance which allows withdrawing ETH into the token-contract.
* @param _mid The balance that the deposit/withdraw recommendation functions will yield.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
2864,
3532
]
} | 2,492 |
ReserveManager | contracts/saga/ReserveManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | ReserveManager | contract ReserveManager is IReserveManager, ContractAddressLocatorHolder, Claimable {
string public constant VERSION = "1.0.0";
using SafeMath for uint256;
struct Wallets {
address deposit;
address withdraw;
}
struct Thresholds {
uint256 min;
uint256 max;
uint256 mid;
}
Wallets public wallets;
Thresholds public thresholds;
uint256 public walletsSequenceNum = 0;
uint256 public thresholdsSequenceNum = 0;
event ReserveWalletsSaved(address _deposit, address _withdraw);
event ReserveWalletsNotSaved(address _deposit, address _withdraw);
event ReserveThresholdsSaved(uint256 _min, uint256 _max, uint256 _mid);
event ReserveThresholdsNotSaved(uint256 _min, uint256 _max, uint256 _mid);
/**
* @dev Create the contract.
* @param _contractAddressLocator The contract address locator.
*/
constructor(IContractAddressLocator _contractAddressLocator) ContractAddressLocatorHolder(_contractAddressLocator) public {}
/**
* @dev Return the contract which implements the IETHConverter interface.
*/
function getETHConverter() public view returns (IETHConverter) {
return IETHConverter(getContractAddress(_IETHConverter_));
}
/**
* @dev Return the contract which implements the IPaymentManager interface.
*/
function getPaymentManager() public view returns (IPaymentManager) {
return IPaymentManager(getContractAddress(_IPaymentManager_));
}
/**
* @dev Set the reserve wallets.
* @param _walletsSequenceNum The sequence-number of the operation.
* @param _deposit The address of the wallet permitted to deposit ETH into the token-contract.
* @param _withdraw The address of the wallet permitted to withdraw ETH from the token-contract.
*/
function setWallets(uint256 _walletsSequenceNum, address _deposit, address _withdraw) external onlyOwner {
require(_deposit != address(0), "deposit-wallet is illegal");
require(_withdraw != address(0), "withdraw-wallet is illegal");
if (walletsSequenceNum < _walletsSequenceNum) {
walletsSequenceNum = _walletsSequenceNum;
wallets.deposit = _deposit;
wallets.withdraw = _withdraw;
emit ReserveWalletsSaved(_deposit, _withdraw);
}
else {
emit ReserveWalletsNotSaved(_deposit, _withdraw);
}
}
/**
* @dev Set the reserve thresholds.
* @param _thresholdsSequenceNum The sequence-number of the operation.
* @param _min The maximum balance which allows depositing ETH from the token-contract.
* @param _max The minimum balance which allows withdrawing ETH into the token-contract.
* @param _mid The balance that the deposit/withdraw recommendation functions will yield.
*/
function setThresholds(uint256 _thresholdsSequenceNum, uint256 _min, uint256 _max, uint256 _mid) external onlyOwner {
require(_min <= _mid, "min-threshold is greater than mid-threshold");
require(_max >= _mid, "max-threshold is smaller than mid-threshold");
if (thresholdsSequenceNum < _thresholdsSequenceNum) {
thresholdsSequenceNum = _thresholdsSequenceNum;
thresholds.min = _min;
thresholds.max = _max;
thresholds.mid = _mid;
emit ReserveThresholdsSaved(_min, _max, _mid);
}
else {
emit ReserveThresholdsNotSaved(_min, _max, _mid);
}
}
/**
* @dev Get a deposit-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to deposit ETH into the token-contract.
* @return The amount that should be deposited in order for the balance to reach `mid` ETH.
*/
function getDepositParams(uint256 _balance) external view returns (address, uint256) {
uint256 depositRecommendation = 0;
uint256 sdrPaymentsSum = getPaymentManager().getPaymentsSum();
uint256 ethPaymentsSum = getETHConverter().toEthAmount(sdrPaymentsSum);
if (ethPaymentsSum >= _balance || (_balance - ethPaymentsSum) <= thresholds.min){// first part of the condition
// prevents underflow in the second part
depositRecommendation = (thresholds.mid).add(ethPaymentsSum) - _balance;// will never underflow
}
return (wallets.deposit, depositRecommendation);
}
/**
* @dev Get a withdraw-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to withdraw ETH into the token-contract.
* @return The amount that should be withdrawn in order for the balance to reach `mid` ETH.
*/
function getWithdrawParams(uint256 _balance) external view returns (address, uint256) {
uint256 withdrawRecommendationAmount = 0;
if (_balance >= thresholds.max && getPaymentManager().getNumOfPayments() == 0){// _balance >= thresholds.max >= thresholds.mid
withdrawRecommendationAmount = _balance - thresholds.mid; // will never underflow
}
return (wallets.withdraw, withdrawRecommendationAmount);
}
} | /**
* @title Reserve Manager.
*/ | NatSpecMultiLine | getDepositParams | function getDepositParams(uint256 _balance) external view returns (address, uint256) {
uint256 depositRecommendation = 0;
uint256 sdrPaymentsSum = getPaymentManager().getPaymentsSum();
uint256 ethPaymentsSum = getETHConverter().toEthAmount(sdrPaymentsSum);
if (ethPaymentsSum >= _balance || (_balance - ethPaymentsSum) <= thresholds.min){// first part of the condition
// prevents underflow in the second part
depositRecommendation = (thresholds.mid).add(ethPaymentsSum) - _balance;// will never underflow
}
return (wallets.deposit, depositRecommendation);
}
| /**
* @dev Get a deposit-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to deposit ETH into the token-contract.
* @return The amount that should be deposited in order for the balance to reach `mid` ETH.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
3837,
4475
]
} | 2,493 |
ReserveManager | contracts/saga/ReserveManager.sol | 0xcd53a7cff0686eb6ee1b7157ff184f8fc8a6ac4f | Solidity | ReserveManager | contract ReserveManager is IReserveManager, ContractAddressLocatorHolder, Claimable {
string public constant VERSION = "1.0.0";
using SafeMath for uint256;
struct Wallets {
address deposit;
address withdraw;
}
struct Thresholds {
uint256 min;
uint256 max;
uint256 mid;
}
Wallets public wallets;
Thresholds public thresholds;
uint256 public walletsSequenceNum = 0;
uint256 public thresholdsSequenceNum = 0;
event ReserveWalletsSaved(address _deposit, address _withdraw);
event ReserveWalletsNotSaved(address _deposit, address _withdraw);
event ReserveThresholdsSaved(uint256 _min, uint256 _max, uint256 _mid);
event ReserveThresholdsNotSaved(uint256 _min, uint256 _max, uint256 _mid);
/**
* @dev Create the contract.
* @param _contractAddressLocator The contract address locator.
*/
constructor(IContractAddressLocator _contractAddressLocator) ContractAddressLocatorHolder(_contractAddressLocator) public {}
/**
* @dev Return the contract which implements the IETHConverter interface.
*/
function getETHConverter() public view returns (IETHConverter) {
return IETHConverter(getContractAddress(_IETHConverter_));
}
/**
* @dev Return the contract which implements the IPaymentManager interface.
*/
function getPaymentManager() public view returns (IPaymentManager) {
return IPaymentManager(getContractAddress(_IPaymentManager_));
}
/**
* @dev Set the reserve wallets.
* @param _walletsSequenceNum The sequence-number of the operation.
* @param _deposit The address of the wallet permitted to deposit ETH into the token-contract.
* @param _withdraw The address of the wallet permitted to withdraw ETH from the token-contract.
*/
function setWallets(uint256 _walletsSequenceNum, address _deposit, address _withdraw) external onlyOwner {
require(_deposit != address(0), "deposit-wallet is illegal");
require(_withdraw != address(0), "withdraw-wallet is illegal");
if (walletsSequenceNum < _walletsSequenceNum) {
walletsSequenceNum = _walletsSequenceNum;
wallets.deposit = _deposit;
wallets.withdraw = _withdraw;
emit ReserveWalletsSaved(_deposit, _withdraw);
}
else {
emit ReserveWalletsNotSaved(_deposit, _withdraw);
}
}
/**
* @dev Set the reserve thresholds.
* @param _thresholdsSequenceNum The sequence-number of the operation.
* @param _min The maximum balance which allows depositing ETH from the token-contract.
* @param _max The minimum balance which allows withdrawing ETH into the token-contract.
* @param _mid The balance that the deposit/withdraw recommendation functions will yield.
*/
function setThresholds(uint256 _thresholdsSequenceNum, uint256 _min, uint256 _max, uint256 _mid) external onlyOwner {
require(_min <= _mid, "min-threshold is greater than mid-threshold");
require(_max >= _mid, "max-threshold is smaller than mid-threshold");
if (thresholdsSequenceNum < _thresholdsSequenceNum) {
thresholdsSequenceNum = _thresholdsSequenceNum;
thresholds.min = _min;
thresholds.max = _max;
thresholds.mid = _mid;
emit ReserveThresholdsSaved(_min, _max, _mid);
}
else {
emit ReserveThresholdsNotSaved(_min, _max, _mid);
}
}
/**
* @dev Get a deposit-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to deposit ETH into the token-contract.
* @return The amount that should be deposited in order for the balance to reach `mid` ETH.
*/
function getDepositParams(uint256 _balance) external view returns (address, uint256) {
uint256 depositRecommendation = 0;
uint256 sdrPaymentsSum = getPaymentManager().getPaymentsSum();
uint256 ethPaymentsSum = getETHConverter().toEthAmount(sdrPaymentsSum);
if (ethPaymentsSum >= _balance || (_balance - ethPaymentsSum) <= thresholds.min){// first part of the condition
// prevents underflow in the second part
depositRecommendation = (thresholds.mid).add(ethPaymentsSum) - _balance;// will never underflow
}
return (wallets.deposit, depositRecommendation);
}
/**
* @dev Get a withdraw-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to withdraw ETH into the token-contract.
* @return The amount that should be withdrawn in order for the balance to reach `mid` ETH.
*/
function getWithdrawParams(uint256 _balance) external view returns (address, uint256) {
uint256 withdrawRecommendationAmount = 0;
if (_balance >= thresholds.max && getPaymentManager().getNumOfPayments() == 0){// _balance >= thresholds.max >= thresholds.mid
withdrawRecommendationAmount = _balance - thresholds.mid; // will never underflow
}
return (wallets.withdraw, withdrawRecommendationAmount);
}
} | /**
* @title Reserve Manager.
*/ | NatSpecMultiLine | getWithdrawParams | function getWithdrawParams(uint256 _balance) external view returns (address, uint256) {
uint256 withdrawRecommendationAmount = 0;
if (_balance >= thresholds.max && getPaymentManager().getNumOfPayments() == 0){// _balance >= thresholds.max >= thresholds.mid
withdrawRecommendationAmount = _balance - thresholds.mid; // will never underflow
}
return (wallets.withdraw, withdrawRecommendationAmount);
}
| /**
* @dev Get a withdraw-recommendation.
* @param _balance The balance of the token-contract.
* @return The address of the wallet permitted to withdraw ETH into the token-contract.
* @return The amount that should be withdrawn in order for the balance to reach `mid` ETH.
*/ | NatSpecMultiLine | v0.4.25+commit.59dbf8f1 | GNU GPLv3 | bzzr://09f67a8aedd0d5d09573ac20a817125fc59f5b0b9bfce5a823b677d752fd2ed6 | {
"func_code_index": [
4782,
5234
]
} | 2,494 |
FUR | FUR.sol | 0xd319bedd2994cc2b0cf18972236800648341f0b2 | Solidity | FUR | contract FUR is StandardToken {
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; //fancy name: eg Simon Bucks
uint8 public decimals; //How many decimals to show. ie. There could 1000 base units with 3 decimals. Meaning 0.980 SBX = 980 base units. It's like comparing 1 wei to 1 ether.
string public symbol; //An identifier: eg SBX
string public version = "P0.1"; // 0.1 standard. Just an arbitrary versioning scheme.
function FUR() {
balances[msg.sender] = 1000000000000000; // Give the creator all initial tokens
totalSupply = 1000000000000000; // Update total supply
name = "FUR"; // Set the name for display purposes
decimals = 6; // Amount of decimals for display purposes
symbol = "FUR"; // Set the symbol for display purposes
}
} | FUR | function FUR() {
balances[msg.sender] = 1000000000000000; // Give the creator all initial tokens
totalSupply = 1000000000000000; // Update total supply
name = "FUR"; // Set the name for display purposes
decimals = 6; // Amount of decimals for display purposes
symbol = "FUR"; // Set the symbol for display purposes
}
| // 0.1 standard. Just an arbitrary versioning scheme. | LineComment | v0.4.19+commit.c4cbbb05 | bzzr://c39feb7afc923587cd9d12b8f7b3c150d2f0ad069c5c9ca80232ff2a5644b1bd | {
"func_code_index": [
800,
1299
]
} | 2,495 |
|||
HelpCoin | HelpCoin.sol | 0x698797a625a833a287ee086bcf2b71aea184f070 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | totalSupply | function totalSupply() constant returns (uint256 supply) {}
| /// @return total amount of tokens | NatSpecSingleLine | v0.4.21+commit.dfe3193c | bzzr://4245e1e21419bd9c0ddd66c7410cf3b5dc0431726a4523e61765fe9c1d8cc585 | {
"func_code_index": [
60,
124
]
} | 2,496 |
|||
HelpCoin | HelpCoin.sol | 0x698797a625a833a287ee086bcf2b71aea184f070 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | balanceOf | function balanceOf(address _owner) constant returns (uint256 balance) {}
| /// @param _owner The address from which the balance will be retrieved
/// @return The balance | NatSpecSingleLine | v0.4.21+commit.dfe3193c | bzzr://4245e1e21419bd9c0ddd66c7410cf3b5dc0431726a4523e61765fe9c1d8cc585 | {
"func_code_index": [
232,
309
]
} | 2,497 |
|||
HelpCoin | HelpCoin.sol | 0x698797a625a833a287ee086bcf2b71aea184f070 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | transfer | function transfer(address _to, uint256 _value) returns (bool success) {}
| /// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not | NatSpecSingleLine | v0.4.21+commit.dfe3193c | bzzr://4245e1e21419bd9c0ddd66c7410cf3b5dc0431726a4523e61765fe9c1d8cc585 | {
"func_code_index": [
546,
623
]
} | 2,498 |
|||
HelpCoin | HelpCoin.sol | 0x698797a625a833a287ee086bcf2b71aea184f070 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | transferFrom | function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
| /// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not | NatSpecSingleLine | v0.4.21+commit.dfe3193c | bzzr://4245e1e21419bd9c0ddd66c7410cf3b5dc0431726a4523e61765fe9c1d8cc585 | {
"func_code_index": [
946,
1042
]
} | 2,499 |
|||
HelpCoin | HelpCoin.sol | 0x698797a625a833a287ee086bcf2b71aea184f070 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | approve | function approve(address _spender, uint256 _value) returns (bool success) {}
| /// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not | NatSpecSingleLine | v0.4.21+commit.dfe3193c | bzzr://4245e1e21419bd9c0ddd66c7410cf3b5dc0431726a4523e61765fe9c1d8cc585 | {
"func_code_index": [
1326,
1407
]
} | 2,500 |
|||
HelpCoin | HelpCoin.sol | 0x698797a625a833a287ee086bcf2b71aea184f070 | Solidity | Token | contract Token {
/// @return total amount of tokens
function totalSupply() constant returns (uint256 supply) {}
/// @param _owner The address from which the balance will be retrieved
/// @return The balance
function balanceOf(address _owner) constant returns (uint256 balance) {}
/// @notice send `_value` token to `_to` from `msg.sender`
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transfer(address _to, uint256 _value) returns (bool success) {}
/// @notice send `_value` token to `_to` from `_from` on the condition it is approved by `_from`
/// @param _from The address of the sender
/// @param _to The address of the recipient
/// @param _value The amount of token to be transferred
/// @return Whether the transfer was successful or not
function transferFrom(address _from, address _to, uint256 _value) returns (bool success) {}
/// @notice `msg.sender` approves `_addr` to spend `_value` tokens
/// @param _spender The address of the account able to transfer the tokens
/// @param _value The amount of wei to be approved for transfer
/// @return Whether the approval was successful or not
function approve(address _spender, uint256 _value) returns (bool success) {}
/// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent
function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
event Transfer(address indexed _from, address indexed _to, uint256 _value);
event Approval(address indexed _owner, address indexed _spender, uint256 _value);
} | allowance | function allowance(address _owner, address _spender) constant returns (uint256 remaining) {}
| /// @param _owner The address of the account owning tokens
/// @param _spender The address of the account able to transfer the tokens
/// @return Amount of remaining tokens allowed to spent | NatSpecSingleLine | v0.4.21+commit.dfe3193c | bzzr://4245e1e21419bd9c0ddd66c7410cf3b5dc0431726a4523e61765fe9c1d8cc585 | {
"func_code_index": [
1615,
1712
]
} | 2,501 |
|||
HelpCoin | HelpCoin.sol | 0x698797a625a833a287ee086bcf2b71aea184f070 | Solidity | HelpCoin | contract HelpCoin is StandardToken { // CHANGE THIS. Update the contract name.
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; // Token Name
uint8 public decimals; // How many decimals to show. To be standard complicant keep it 18
string public symbol; // An identifier: eg SBX, XPR etc..
string public version = 'H1.0';
uint256 public unitsOneEthCanBuy; // How many units of your coin can be bought by 1 ETH?
uint256 public totalEthInWei; // WEI is the smallest unit of ETH (the equivalent of cent in USD or satoshi in BTC). We'll store the total ETH raised via our ICO here.
address public fundsWallet; // Where should the raised ETH go?
// This is a constructor function
// which means the following function name has to match the contract name declared above
function HelpCoin() {
balances[msg.sender] = 200000000000000000000000000; // Give the creator all initial tokens. This is set to 1000 for example. If you want your initial tokens to be X and your decimal is 5, set this value to X * 100000. (CHANGE THIS)
totalSupply = 200000000000000000000000000; // Update total supply (1000 for example) (CHANGE THIS)
name = "HelpCoin"; // Set the name for display purposes (CHANGE THIS)
decimals = 18; // Amount of decimals for display purposes (CHANGE THIS)
symbol = "HELP"; // Set the symbol for display purposes (CHANGE THIS)
unitsOneEthCanBuy = 100000; // Set the price of your token for the ICO (CHANGE THIS)
fundsWallet = msg.sender; // The owner of the contract gets ETH
}
function() payable{
totalEthInWei = totalEthInWei + msg.value;
uint256 amount = msg.value * unitsOneEthCanBuy;
if (balances[fundsWallet] < amount) {
return;
}
balances[fundsWallet] = balances[fundsWallet] - amount;
balances[msg.sender] = balances[msg.sender] + amount;
Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the blockchain
//Transfer ether to fundsWallet
fundsWallet.transfer(msg.value);
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
} | HelpCoin | function HelpCoin() {
balances[msg.sender] = 200000000000000000000000000; // Give the creator all initial tokens. This is set to 1000 for example. If you want your initial tokens to be X and your decimal is 5, set this value to X * 100000. (CHANGE THIS)
totalSupply = 200000000000000000000000000; // Update total supply (1000 for example) (CHANGE THIS)
name = "HelpCoin"; // Set the name for display purposes (CHANGE THIS)
decimals = 18; // Amount of decimals for display purposes (CHANGE THIS)
symbol = "HELP"; // Set the symbol for display purposes (CHANGE THIS)
unitsOneEthCanBuy = 100000; // Set the price of your token for the ICO (CHANGE THIS)
fundsWallet = msg.sender; // The owner of the contract gets ETH
}
| // Where should the raised ETH go?
// This is a constructor function
// which means the following function name has to match the contract name declared above | LineComment | v0.4.21+commit.dfe3193c | bzzr://4245e1e21419bd9c0ddd66c7410cf3b5dc0431726a4523e61765fe9c1d8cc585 | {
"func_code_index": [
1196,
2217
]
} | 2,502 |
|||
HelpCoin | HelpCoin.sol | 0x698797a625a833a287ee086bcf2b71aea184f070 | Solidity | HelpCoin | contract HelpCoin is StandardToken { // CHANGE THIS. Update the contract name.
/* Public variables of the token */
/*
NOTE:
The following variables are OPTIONAL vanities. One does not have to include them.
They allow one to customise the token contract & in no way influences the core functionality.
Some wallets/interfaces might not even bother to look at this information.
*/
string public name; // Token Name
uint8 public decimals; // How many decimals to show. To be standard complicant keep it 18
string public symbol; // An identifier: eg SBX, XPR etc..
string public version = 'H1.0';
uint256 public unitsOneEthCanBuy; // How many units of your coin can be bought by 1 ETH?
uint256 public totalEthInWei; // WEI is the smallest unit of ETH (the equivalent of cent in USD or satoshi in BTC). We'll store the total ETH raised via our ICO here.
address public fundsWallet; // Where should the raised ETH go?
// This is a constructor function
// which means the following function name has to match the contract name declared above
function HelpCoin() {
balances[msg.sender] = 200000000000000000000000000; // Give the creator all initial tokens. This is set to 1000 for example. If you want your initial tokens to be X and your decimal is 5, set this value to X * 100000. (CHANGE THIS)
totalSupply = 200000000000000000000000000; // Update total supply (1000 for example) (CHANGE THIS)
name = "HelpCoin"; // Set the name for display purposes (CHANGE THIS)
decimals = 18; // Amount of decimals for display purposes (CHANGE THIS)
symbol = "HELP"; // Set the symbol for display purposes (CHANGE THIS)
unitsOneEthCanBuy = 100000; // Set the price of your token for the ICO (CHANGE THIS)
fundsWallet = msg.sender; // The owner of the contract gets ETH
}
function() payable{
totalEthInWei = totalEthInWei + msg.value;
uint256 amount = msg.value * unitsOneEthCanBuy;
if (balances[fundsWallet] < amount) {
return;
}
balances[fundsWallet] = balances[fundsWallet] - amount;
balances[msg.sender] = balances[msg.sender] + amount;
Transfer(fundsWallet, msg.sender, amount); // Broadcast a message to the blockchain
//Transfer ether to fundsWallet
fundsWallet.transfer(msg.value);
}
/* Approves and then calls the receiving contract */
function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
} | approveAndCall | function approveAndCall(address _spender, uint256 _value, bytes _extraData) returns (bool success) {
allowed[msg.sender][_spender] = _value;
Approval(msg.sender, _spender, _value);
//call the receiveApproval function on the contract you want to be notified. This crafts the function signature manually so one doesn't have to include a contract in here just for this.
//receiveApproval(address _from, uint256 _value, address _tokenContract, bytes _extraData)
//it is assumed that when does this that the call *should* succeed, otherwise one would use vanilla approve instead.
if(!_spender.call(bytes4(bytes32(sha3("receiveApproval(address,uint256,address,bytes)"))), msg.sender, _value, this, _extraData)) { throw; }
return true;
}
| /* Approves and then calls the receiving contract */ | Comment | v0.4.21+commit.dfe3193c | bzzr://4245e1e21419bd9c0ddd66c7410cf3b5dc0431726a4523e61765fe9c1d8cc585 | {
"func_code_index": [
2841,
3646
]
} | 2,503 |
|||
MetaCityGame | MetaCityGame.sol | 0xafcc9ec6652972d84708183e2d4cc5783270c549 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | isContract | function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
| /**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | BSD-3-Clause | ipfs://5dd2aac3ed36df599508f3134c0e37fd8230190881b91d5aac7412c679a35eb4 | {
"func_code_index": [
606,
1230
]
} | 2,504 |
||
MetaCityGame | MetaCityGame.sol | 0xafcc9ec6652972d84708183e2d4cc5783270c549 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | sendValue | function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
| /**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | BSD-3-Clause | ipfs://5dd2aac3ed36df599508f3134c0e37fd8230190881b91d5aac7412c679a35eb4 | {
"func_code_index": [
2160,
2562
]
} | 2,505 |
||
MetaCityGame | MetaCityGame.sol | 0xafcc9ec6652972d84708183e2d4cc5783270c549 | Solidity | Address | library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// According to EIP-1052, 0x0 is the value returned for not-yet created accounts
// and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned
// for accounts without code, i.e. `keccak256('')`
bytes32 codehash;
bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;
// solhint-disable-next-line no-inline-assembly
assembly { codehash := extcodehash(account) }
return (codehash != accountHash && codehash != 0x0);
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
// solhint-disable-next-line avoid-low-level-calls, avoid-call-value
(bool success, ) = recipient.call{ value: amount }("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data, string memory errorMessage) internal returns (bytes memory) {
return _functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value, string memory errorMessage) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
return _functionCallWithValue(target, data, value, errorMessage);
}
function _functionCallWithValue(address target, bytes memory data, uint256 weiValue, string memory errorMessage) private returns (bytes memory) {
require(isContract(target), "Address: call to non-contract");
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returndata) = target.call{ value: weiValue }(data);
if (success) {
return returndata;
} else {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
// solhint-disable-next-line no-inline-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
} | functionCall | function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
| /**
* @dev Performs a Solidity function call using a low level `call`. A
* plain`call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/ | NatSpecMultiLine | v0.6.12+commit.27d51765 | BSD-3-Clause | ipfs://5dd2aac3ed36df599508f3134c0e37fd8230190881b91d5aac7412c679a35eb4 | {
"func_code_index": [
3318,
3496
]
} | 2,506 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.