Verified contractPartial
VDPool
Address0x4a9f0d12901c1005161daf85396d3c2b34ad5ca0
- Balance
0 ETH
- Transactions
4
- Compiler
solc 0.5.8
- Same code
1 more contract
Details
- Compiler
- solc 0.5.8+commit.23d335f2
- Language
- solidity
- Optimization
- No
- License
- Not stated
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 8,003,907
- Creation transaction
- 0x19a3f9e69b…654f8ee33b
2 files
- VDPool.solmain4.4 KB
- SafeMath.sol3.59 KB
VDPool.sol
// Recovered by EthereumHistory (ethereumhistory.com) -sw
pragma solidity ^0.5.8;
import './SafeMath.sol';
contract VDPoolBasic {
function price() external view returns(uint256);
function currentLevel() external view returns(uint256);
function currentLevelRemaining() external view returns(uint256);
}
contract VDPoolThrottler {
function getCooldownBlocks() external view returns(uint256);
}
contract VDPool is VDPoolBasic {
using SafeMath for uint256;
/*
* STATES
*/
address public master;
address public caller;
uint256 public ethCapacity = 0;
uint256 public basicExchangeRate = 0;
uint256 public currentLevel = 0;
uint256 public currentLevelStartBlock = 0;
uint256 public cooldownBlocks = 0; // by default wait 1 block before enterring next level
VDPoolThrottler throttlerContract;
uint256 public currentPrice = 0;
uint256 public currentLevelRemaining = 0;
bool public paused;
/*
* EVENTS
*/
event LevelDescend(uint256 level, uint256 price, uint256 startBlock, uint256 cooldownBlocks, uint256 currentBlock);
/*
* MODIFIERS
*/
/// only master can call the function
modifier onlyOwner {
require(master == msg.sender, "only owner can call");
_;
}
/// only master can call the function
modifier onlyCaller {
require(caller == msg.sender, "only caller can call");
_;
}
/// function not paused
modifier notPaused {
require(paused == false, "function is paused");
_;
}
constructor(uint256 _ethCapacity, uint256 _currentLevel, uint256 _basicExchangeRate) public {
master = msg.sender;
ethCapacity = _ethCapacity;
currentLevel = _currentLevel;
currentPrice = (currentLevel.sub(1)).mul(10).add(_basicExchangeRate);
currentLevelRemaining = _ethCapacity;
basicExchangeRate = _basicExchangeRate;
}
function setPause(bool value) external onlyOwner {
paused = value;
}
function setCaller(address who) external onlyOwner {
caller = who;
}
function setOwner(address who) external onlyOwner {
master = who;
}
function setCooldownBlocks(uint256 bn) external onlyOwner {
cooldownBlocks = bn;
}
function setThrottlerContract(address contractAddress) external onlyOwner {
throttlerContract = VDPoolThrottler(contractAddress);
}
function price() external view returns (uint256) {
uint256 tokens = computeTokenAmount(1 ether);
return tokens;
}
function computeTokenAmount(uint256 ethAmount) public view returns (uint256) {
uint256 tokens = ethAmount.mul(currentPrice);
return tokens;
}
function buyToken(uint256 ethAmount) external onlyCaller notPaused returns (uint256) {
require(currentLevelStartBlock <= block.number, "cooling down");
uint256 eth = ethAmount;
uint256 tokens = 0;
while (eth > 0) {
if (eth <= currentLevelRemaining) {
tokens = tokens + computeTokenAmount(eth);
currentLevelRemaining = currentLevelRemaining.sub(eth);
eth = 0;
}else {
tokens = tokens + computeTokenAmount(currentLevelRemaining);
eth = eth.sub(currentLevelRemaining);
currentLevelRemaining = 0;
}
if (currentLevelRemaining == 0){
currentLevel = currentLevel.sub(1);
require (currentLevel > 0, "end of levels");
currentPrice = (currentLevel.sub(1)).mul(10).add(basicExchangeRate);
currentLevelRemaining = ethCapacity;
if (address(throttlerContract) != address(0)) {
cooldownBlocks = throttlerContract.getCooldownBlocks();
}
if (currentLevelStartBlock > block.number ) {
// handling the case of desending multiple level in one tx
currentLevelStartBlock = currentLevelStartBlock + cooldownBlocks;
} else {
currentLevelStartBlock = block.number + cooldownBlocks;
}
emit LevelDescend(currentLevel, currentPrice, currentLevelStartBlock, cooldownBlocks, block.number);
}
}
return tokens;
}
}
SafeMath.sol
// Recovered by EthereumHistory (ethereumhistory.com) -sw
pragma solidity ^0.5.8;
/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
* checks.
*
* Arithmetic operations in Solidity wrap on overflow. This can easily result
* in bugs, because programmers usually assume that an overflow raises an
* error, which is the standard behavior in high level programming languages.
* `SafeMath` restores this intuition by reverting the transaction when an
* operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a, "SafeMath: subtraction overflow");
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-solidity/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) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
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) {
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": false
}
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.