comment stringlengths 11 2.99k | function_code stringlengths 165 3.15k | version stringclasses 80
values |
|---|---|---|
/**
* @dev Get list of publicKeys of a Name
* @param _id The ID of the Name
* @param _from The starting index
* @param _to The ending index
* @return list of publicKeys
*/ | function getKeys(address _id, uint256 _from, uint256 _to) public isName(_id) view returns (address[] memory) {
require (isExist(_id));
require (_from >= 0 && _to >= _from);
PublicKey memory _publicKey = publicKeys[_id];
require (_publicKey.keys.length > 0);
if (_to > _publicKey.keys.length.sub(1)) {... | 0.5.4 |
/**
* @dev Remove publicKey from the list
* @param _id The ID of the Name
* @param _key The publicKey to be removed
*/ | function removeKey(address _id, address _key) public isName(_id) onlyAdvocate(_id) senderNameNotCompromised {
require (this.isKeyExist(_id, _key));
PublicKey storage _publicKey = publicKeys[_id];
// Can't remove default key
require (_key != _publicKey.defaultKey);
// Can't remove writer key
requir... | 0.5.4 |
/**
* @dev Set a publicKey as the default for a Name
* @param _id The ID of the Name
* @param _defaultKey The defaultKey to be set
* @param _signatureV The V part of the signature for this update
* @param _signatureR The R part of the signature for this update
* @param _signatureS The S part of ... | function setDefaultKey(address _id, address _defaultKey, uint8 _signatureV, bytes32 _signatureR, bytes32 _signatureS) public isName(_id) onlyAdvocate(_id) senderNameNotCompromised {
require (this.isKeyExist(_id, _defaultKey));
bytes32 _hash = keccak256(abi.encodePacked(address(this), _id, _defaultKey));
requ... | 0.5.4 |
/**
* @dev Set a publicKey as the writer for a Name
* @param _id The ID of the Name
* @param _writerKey The writerKey to be set
* @param _signatureV The V part of the signature for this update
* @param _signatureR The R part of the signature for this update
* @param _signatureS The S part of the... | function setWriterKey(address _id, address _writerKey, uint8 _signatureV, bytes32 _signatureR, bytes32 _signatureS) public isName(_id) onlyAdvocate(_id) senderNameNotCompromised {
bytes32 _hash = keccak256(abi.encodePacked(address(this), _id, _writerKey));
require (ecrecover(_hash, _signatureV, _signatureR, _sign... | 0.5.4 |
/**
* @dev Actual adding the publicKey to list for a Name
* @param _id The ID of the Name
* @param _key The publicKey to be added
* @return true on success
*/ | function _addKey(address _id, address _key) internal returns (bool) {
require (!this.isKeyExist(_id, _key));
keyToNameId[_key] = _id;
PublicKey storage _publicKey = publicKeys[_id];
_publicKey.keys.push(_key);
uint256 _nonce = _nameFactory.incrementNonce(_id);
require (_nonce > 0);
emit Add... | 0.5.4 |
/**
* @dev Actual setting the writerKey for a Name
* @param _id The ID of the Name
* @param _writerKey The writerKey to be set
* @return true on success
*/ | function _setWriterKey(address _id, address _writerKey) internal returns (bool) {
require (this.isKeyExist(_id, _writerKey));
PublicKey storage _publicKey = publicKeys[_id];
_publicKey.writerKey = _writerKey;
uint256 _nonce = _nameFactory.incrementNonce(_id);
require (_nonce > 0);
emit SetWriterKe... | 0.5.4 |
/**
* @notice initializes bond parameters
* @param _controlVariable uint
* @param _vestingTerm uint
* @param _minimumPrice uint
* @param _maxPayout uint
* @param _fee uint
* @param _maxDebt uint
* @param _initialDebt uint
*/ | function initializeBondTerms(
uint _controlVariable,
uint _vestingTerm,
uint _minimumPrice,
uint _maxPayout,
uint _fee,
uint _maxDebt,
uint _initialDebt
) external onlyPolicy() {
require( terms.controlVariable == 0, "Bonds must be initialize... | 0.7.5 |
/**
* @notice set parameters for new bonds
* @param _parameter PARAMETER
* @param _input uint
*/ | function setBondTerms ( PARAMETER _parameter, uint _input ) external onlyPolicy() {
if ( _parameter == PARAMETER.VESTING ) { // 0
require( _input >= 10000, "Vesting must be longer than 36 hours" );
terms.vestingTerm = _input;
} else if ( _parameter == PARAMETER.PAYOUT ) { // ... | 0.7.5 |
/**
* @notice set control variable adjustment
* @param _addition bool
* @param _increment uint
* @param _target uint
* @param _buffer uint
*/ | function setAdjustment (
bool _addition,
uint _increment,
uint _target,
uint _buffer
) external onlyPolicy() {
require( _increment <= terms.controlVariable.mul( 25 ).div( 1000 ), "Increment too large" );
adjustment = Adjust({
add: _addition,
... | 0.7.5 |
/**
* @notice set contract for auto stake
* @param _staking address
* @param _helper bool
*/ | function setStaking( address _staking, bool _helper ) external onlyPolicy() {
require( _staking != address(0) );
if ( _helper ) {
useHelper = true;
stakingHelper = _staking;
} else {
useHelper = false;
staking = _staking;
}
} | 0.7.5 |
/**
* @notice redeem bond for user
* @param _recipient address
* @param _stake bool
* @return uint
*/ | function redeem( address _recipient, bool _stake ) external returns ( uint ) {
Bond memory info = bondInfo[ _recipient ];
uint percentVested = percentVestedFor( _recipient ); // (blocks since last interaction / vesting term remaining)
if ( percentVested >= 10000 ) { // if fully vest... | 0.7.5 |
/**
* @notice allow user to stake payout automatically
* @param _stake bool
* @param _amount uint
* @return uint
*/ | function stakeOrSend( address _recipient, bool _stake, uint _amount ) internal returns ( uint ) {
if ( !_stake ) { // if user does not want to stake
IERC20( OHM ).transfer( _recipient, _amount ); // send payout
} else { // if user wants to stake
if ( useHelper ) { // use if s... | 0.7.5 |
/**
* @notice makes incremental adjustment to control variable
*/ | function adjust() internal {
uint blockCanAdjust = adjustment.lastBlock.add( adjustment.buffer );
if( adjustment.rate != 0 && block.number >= blockCanAdjust ) {
uint initial = terms.controlVariable;
if ( adjustment.add ) {
terms.controlVariable = terms.contro... | 0.7.5 |
/**
* @notice calculate current bond premium
* @return price_ uint
*/ | function bondPrice() public view returns ( uint price_ ) {
price_ = terms.controlVariable.mul( debtRatio() ).add( 1000000000 ).div( 1e7 );
if ( price_ < terms.minimumPrice ) {
price_ = terms.minimumPrice;
}
} | 0.7.5 |
/**
* @notice calculate current bond price and remove floor if above
* @return price_ uint
*/ | function _bondPrice() internal returns ( uint price_ ) {
price_ = terms.controlVariable.mul( debtRatio() ).add( 1000000000 ).div( 1e7 );
if ( price_ < terms.minimumPrice ) {
price_ = terms.minimumPrice;
} else if ( terms.minimumPrice != 0 ) {
terms.minimumPri... | 0.7.5 |
/**
* @notice converts bond price to DAI value
* @return price_ uint
*/ | function bondPriceInUSD() public view returns ( uint price_ ) {
if( isLiquidityBond ) {
price_ = bondPrice().mul( IBondCalculator( bondCalculator ).markdown( principle ) ).div( 100 );
} else {
price_ = bondPrice().mul( 10 ** IERC20( principle ).decimals() ).div( 100 );
... | 0.7.5 |
/**
* @notice debt ratio in same terms for reserve or liquidity bonds
* @return uint
*/ | function standardizedDebtRatio() external view returns ( uint ) {
if ( isLiquidityBond ) {
return debtRatio().mul( IBondCalculator( bondCalculator ).markdown( principle ) ).div( 1e9 );
} else {
return debtRatio();
}
} | 0.7.5 |
/**
* @notice amount to decay total debt by
* @return decay_ uint
*/ | function debtDecay() public view returns ( uint decay_ ) {
uint blocksSinceLast = block.number.sub( lastDecay );
decay_ = totalDebt.mul( blocksSinceLast ).div( terms.vestingTerm );
if ( decay_ > totalDebt ) {
decay_ = totalDebt;
}
} | 0.7.5 |
/**
* @notice calculate how far into vesting a depositor is
* @param _depositor address
* @return percentVested_ uint
*/ | function percentVestedFor( address _depositor ) public view returns ( uint percentVested_ ) {
Bond memory bond = bondInfo[ _depositor ];
uint blocksSinceLast = block.number.sub( bond.lastBlock );
uint vesting = bond.vesting;
if ( vesting > 0 ) {
percentVested_ = blocks... | 0.7.5 |
/**
* @notice calculate amount of OHM available for claim by depositor
* @param _depositor address
* @return pendingPayout_ uint
*/ | function pendingPayoutFor( address _depositor ) external view returns ( uint pendingPayout_ ) {
uint percentVested = percentVestedFor( _depositor );
uint payout = bondInfo[ _depositor ].payout;
if ( percentVested >= 10000 ) {
pendingPayout_ = payout;
} else {
... | 0.7.5 |
/**
* @notice allow anyone to send lost tokens (excluding principle or OHM) to the DAO
* @return bool
*/ | function recoverLostToken( address _token ) external returns ( bool ) {
require( _token != OHM );
require( _token != principle );
IERC20( _token ).safeTransfer( DAO, IERC20( _token ).balanceOf( address(this) ) );
return true;
} | 0.7.5 |
/**
* Anyone can call the function to deploy a new payment handler.
* The new contract will be created, added to the list, and an event fired.
*/ | function deployNewHandler() public {
// Deploy the new contract
PaymentHandler createdHandler = new PaymentHandler(this);
// Add it to the list and the mapping
handlerList.push(address(createdHandler));
handlerMap[address(createdHandler)] = true;
// Emit event to let watchers know that a new handl... | 0.5.16 |
/**
* This function is called by handlers when they receive ETH payments.
*/ | function firePaymentReceivedEvent(address to, address from, uint256 amount) public {
// Verify the call is coming from a handler
require(handlerMap[msg.sender], "Only payment handlers are allowed to trigger payment events.");
// Emit the event
emit EthPaymentReceived(to, from, amount);
} | 0.5.16 |
/**
* Allows a caller to sweep multiple handlers in one transaction
*/ | function multiHandlerSweep(address[] memory handlers, IERC20 tokenContract) public {
for (uint i = 0; i < handlers.length; i++) {
// Whitelist calls to only handlers
require(handlerMap[handlers[i]], "Only payment handlers are valid sweep targets.");
// Trigger sweep
PaymentHandler(address(uint160... | 0.5.16 |
/* Transfers based on an offline signed transfer instruction. */ | function delegatedTransfer(address from, address to, uint amount, string narrative,
uint maxExecutorFeeInToken, /* client provided max fee for executing the tx */
bytes32 nonce, /* random nonce generated by client */
... | 0.4.24 |
/* transferAndNotify based on an instruction signed offline */ | function delegatedTransferAndNotify(address from, TokenReceiver target, uint amount, uint data,
uint maxExecutorFeeInToken, /* client provided max fee for executing the tx */
bytes32 nonce, /* random nonce generated by client */
... | 0.4.24 |
/**
* @dev Selling tokens back to the bonding curve for collateral.
* @param _numTokens: The number of tokens that you want to burn.
*/ | function burn(uint256 _numTokens) external onlyActive() returns(bool) {
require(
balances[msg.sender] >= _numTokens,
"Not enough tokens available"
);
uint256 reward = rewardForBurn(_numTokens);
totalSupply_ = totalSupply_.sub(_numTokens);
balanc... | 0.5.10 |
/**
* @notice This function returns the amount of tokens one can receive for a
* specified amount of collateral token.
* @param _collateralTokenOffered : Amount of reserve token offered for
* purchase.
* @return uint256 : The amount of tokens once can purchase with the
* specified c... | function collateralToTokenBuying(
uint256 _collateralTokenOffered
)
external
view
returns(uint256)
{
// Works out the amount of collateral for fee
uint256 fee = _collateralTokenOffered.mul(feeRate_).div(100);
// Removes the fee amount from the col... | 0.5.10 |
/**
* @dev Allows token holders to withdraw collateral in return for tokens
* after the market has been finalised.
* @param _amount: The amount of tokens they want to withdraw
*/ | function withdraw(uint256 _amount) public returns(bool) {
// Ensures withdraw can only be called in an inactive market
require(!active_, "Market not finalised");
// Ensures the sender has enough tokens
require(_amount <= balances[msg.sender], "Insufficient funds");
// Ensure... | 0.5.10 |
/**
* @dev Returns the required collateral amount for a volume of bonding
* curve tokens.
* @notice The curve intergral code will reject any values that are too
* small or large, that could result in over/under flows.
* @param _numTokens: The number of tokens to calculate the price of
* @... | function priceToMint(uint256 _numTokens) public view returns(uint256) {
// Gets the balance of the market
uint256 balance = collateralToken_.balanceOf(address(this));
// Performs the curve intergral with the relavant vaules
uint256 collateral = _curveIntegral(
totalS... | 0.5.10 |
/**
* @dev Returns the required collateral amount for a volume of bonding
* curve tokens
* @param _numTokens: The number of tokens to work out the collateral
* vaule of
* @return uint256: The required collateral amount for a volume of bonding
* curve tokens
*/ | function rewardForBurn(uint256 _numTokens) public view returns(uint256) {
// Gets the curent balance of the market
uint256 poolBalanceFetched = collateralToken_.balanceOf(address(this));
// Returns the pool balance minus the curve intergral of the removed
// tokens
return po... | 0.5.10 |
/**
* @notice Transfer ownership token from msg.sender to a specified address.
* @param _to : The address to transfer to.
* @param _value : The amount to be transferred.
*/ | function transfer(address _to, uint256 _value) public returns (bool) {
require(_value <= balances[msg.sender], "Insufficient funds");
require(_to != address(0), "Target account invalid");
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(_va... | 0.5.10 |
/**
* @dev Initialized the contract, sets up owners and gets the market
* address. This function exists because the Vault does not have
* an address until the constructor has finished running. The
* cumulative funding threshold is set here because of gas issues
* within the ... | function initialize(
address _market
)
external
onlyWhitelistAdmin()
returns(bool)
{
require(_market != address(0), "Contracts initialized");
// Stores the market in storage
market_ = IMarket(_market);
// Removes the market factory cont... | 0.5.10 |
/**
* @dev This function sends the vaults funds to the market, and sets the
* outstanding withdraw to 0.
* @notice If this function is called before the end of all phases, all
* unclaimed (outstanding) funding will be sent to the market to be
* redistributed.
*/ | function terminateMarket()
public
isActive()
onlyWhitelistAdmin()
{
uint256 remainingBalance = collateralToken_.balanceOf(address(this));
// This ensures that if the creator has any outstanding funds, that
// those funds do not get sent to the market.
... | 0.5.10 |
/**
* @notice This function allows for the creation of a new market,
* consisting of a curve and vault. If the creator address is the
* same as the deploying address the market the initialization of
* the market will fail.
* @dev Vyper cannot handle arrays of unknown length, and thu... | function deployMarket(
uint256[] calldata _fundingGoals,
uint256[] calldata _phaseDurations,
address _creator,
uint256 _curveType,
uint256 _feeRate
)
external
onlyAnAdmin()
{
// Breaks down the return of the curve data
(address c... | 0.5.10 |
/**
* @dev Execute single-hop swaps for swapExactIn trade type. Used for swaps
* returned from viewSplit function and legacy off-chain SOR.
*
* @param swaps Array of single-hop swaps.
* @param tokenIn Input token.
* @param tokenOut Output token.
* @param totalAmountIn Total amount of tokenIn.
* @param minTotalA... | function batchSwapExactIn(
Swap[] memory swaps,
IXToken tokenIn,
IXToken tokenOut,
uint256 totalAmountIn,
uint256 minTotalAmountOut,
bool useUtilityToken
) public returns (uint256 totalAmountOut) {
transferFrom(tokenIn, totalAmountIn);
for (uint256 i ... | 0.7.4 |
/**
* @dev Execute multi-hop swaps returned from off-chain SOR for swapExactIn trade type.
*
* @param swapSequences multi-hop swaps sequence.
* @param tokenIn Input token.
* @param tokenOut Output token.
* @param totalAmountIn Total amount of tokenIn.
* @param minTotalAmountOut Minumum amount of tokenOut.
* @pa... | function multihopBatchSwapExactIn(
Swap[][] memory swapSequences,
IXToken tokenIn,
IXToken tokenOut,
uint256 totalAmountIn,
uint256 minTotalAmountOut,
bool useUtilityToken
) external returns (uint256 totalAmountOut) {
transferFrom(tokenIn, totalAmountIn);
... | 0.7.4 |
/**
* @dev Used for swaps returned from viewSplit function.
*
* @param tokenIn Input token.
* @param tokenOut Output token.
* @param totalAmountIn Total amount of tokenIn.
* @param minTotalAmountOut Minumum amount of tokenOut.
* @param nPools Maximum mumber of pools.
* @param useUtilityToken Flag to determine i... | function smartSwapExactIn(
IXToken tokenIn,
IXToken tokenOut,
uint256 totalAmountIn,
uint256 minTotalAmountOut,
uint256 nPools,
bool useUtilityToken
) external returns (uint256 totalAmountOut) {
Swap[] memory swaps;
uint256 totalOutput;
(swaps,... | 0.7.4 |
/**
* @dev Join the `pool`, getting `poolAmountOut` pool tokens. This will pull some of each of the currently
* trading tokens in the pool, meaning you must have called approve for each token for this pool. These
* values are limited by the array of `maxAmountsIn` in the order of the pool tokens.
*
* @param pool P... | function joinPool(
address pool,
uint256 poolAmountOut,
uint256[] calldata maxAmountsIn
) external {
address[] memory tokens = IBPool(pool).getCurrentTokens();
// pull xTokens
for (uint256 i = 0; i < tokens.length; i++) {
transferFrom(IXToken(tokens[i]), ... | 0.7.4 |
/**
* @dev Exit the pool, paying poolAmountIn pool tokens and getting some of each of the currently trading
* tokens in return. These values are limited by the array of minAmountsOut in the order of the pool tokens.
*
* @param pool Pool address.
* @param poolAmountIn Exact pool amount int.
* @param minAmountsOut ... | function exitPool(
address pool,
uint256 poolAmountIn,
uint256[] calldata minAmountsOut
) external {
address wrappedLPT = xTokenWrapper.tokenToXToken(pool);
// pull wrapped liquitity tokens
transferFrom(IXToken(wrappedLPT), poolAmountIn);
// unwrap wrapped l... | 0.7.4 |
/**
* @dev Pay `tokenAmountIn` of token `tokenIn` to join the pool, getting `poolAmountOut` of the pool shares.
*
* @param pool Pool address.
* @param tokenIn Input token.
* @param tokenAmountIn Exact amount of tokenIn to pay.
* @param minPoolAmountOut Minumum amount of pool shares to get.
*/ | function joinswapExternAmountIn(
address pool,
address tokenIn,
uint256 tokenAmountIn,
uint256 minPoolAmountOut
) external returns (uint256 poolAmountOut) {
// pull xToken
transferFrom(IXToken(tokenIn), tokenAmountIn);
IXToken(tokenIn).approve(pool, tokenAmoun... | 0.7.4 |
/**
* @dev Specify `poolAmountOut` pool shares that you want to get, and a token `tokenIn` to pay with.
* This costs `tokenAmountIn` tokens (these went into the pool).
*
* @param pool Pool address.
* @param tokenIn Input token.
* @param poolAmountOut Exact amount of pool shares to get.
* @param maxAmountIn Minum... | function joinswapPoolAmountOut(
address pool,
address tokenIn,
uint256 poolAmountOut,
uint256 maxAmountIn
) external returns (uint256 tokenAmountIn) {
// pull xToken
transferFrom(IXToken(tokenIn), maxAmountIn);
IXToken(tokenIn).approve(pool, maxAmountIn);
... | 0.7.4 |
/**
* @dev Pay `poolAmountIn` pool shares into the pool, getting `tokenAmountOut` of the given
* token `tokenOut` out of the pool.
*
* @param pool Pool address.
* @param tokenOut Input token.
* @param poolAmountIn Exact amount of pool shares to pay.
* @param minAmountOut Minumum amount of tokenIn to get.
*/ | function exitswapPoolAmountIn(
address pool,
address tokenOut,
uint256 poolAmountIn,
uint256 minAmountOut
) external returns (uint256 tokenAmountOut) {
address wrappedLPT = xTokenWrapper.tokenToXToken(pool);
// pull wrapped liquitity tokens
transferFrom(IXTok... | 0.7.4 |
/**
* @dev Specify tokenAmountOut of token tokenOut that you want to get out of the pool.
* This costs poolAmountIn pool shares (these went into the pool).
*
* @param pool Pool address.
* @param tokenOut Input token.
* @param tokenAmountOut Exact amount of of tokenIn to get.
* @param maxPoolAmountIn Maximum amou... | function exitswapExternAmountOut(
address pool,
address tokenOut,
uint256 tokenAmountOut,
uint256 maxPoolAmountIn
) external returns (uint256 poolAmountIn) {
address wrappedLPT = xTokenWrapper.tokenToXToken(pool);
// pull wrapped liquitity tokens
transferFrom... | 0.7.4 |
/**
* @dev View function that calculates most optimal swaps (exactIn swap type) across a max of nPools.
* Returns an array of `Swaps` and the total amount out for swap.
*
* @param tokenIn Input token.
* @param tokenOut Output token.
* @param swapAmount Amount of tokenIn.
* @param nPools Maximum mumber of pools.
... | function viewSplitExactIn(
address tokenIn,
address tokenOut,
uint256 swapAmount,
uint256 nPools
) public view returns (Swap[] memory swaps, uint256 totalOutput) {
address[] memory poolAddresses = registry.getBestPoolsWithLimit(tokenIn, tokenOut, nPools);
Pool[] memo... | 0.7.4 |
/**
* @dev Trtansfers protocol swap fee from the sender to this `feeReceiver`.
*
*/ | function transferFeeFrom(
IXToken token,
uint256 amount,
bool useUtitlityToken
) internal {
if (useUtitlityToken && utilityToken != address(0) && address(utilityTokenFeed) != address(0)) {
uint256 discountedFee = utilityTokenFeed.calculateAmount(address(token), amount.div... | 0.7.4 |
// Saftey Checks for Divison Tasks | function div(uint256 a, uint256 b) internal constant returns (uint256) {
assert(b > 0);
uint256 c = a / b;
assert(a == b * c + a % b);
return c;
} | 0.4.19 |
/**
* @dev Transfer tokens. Make sure that both participants have no open dividends left.
* @param to The address to transfer to.
* @param value The amount to be transferred.
*/ | function _transfer(address payable from, address payable to, uint256 value) internal
{
require(value > 0, "Transferred value has to be grater than 0.");
require(to != address(0), "0x00 address not allowed.");
require(value <= balanceOf[from], "Not enough funds on sender address.");
... | 0.5.7 |
// --- Init --- | function initialize() public {
require(!initialized, "initialize: Already initialized!");
_governance = msg.sender;
_pID = 0;
_totalReferReward = 0;
_totalRegisterCount = 0;
_refer1RewardRate = 700; //7%
_refer2RewardRate = 300; //3%
_baseRate = ... | 0.5.5 |
/**
* resolve the refer's reward from a player
*/ | function settleReward(address from, uint256 amount)
isRegisteredPool()
validAddress(from)
external
returns (uint256)
{
// set up our tx event data and determine if player is new or not
_determinePID(from);
uint256 pID = _pIDxAddr[from];
... | 0.5.5 |
/**
* claim all of the refer reward.
*/ | function claim()
public
{
address addr = msg.sender;
uint256 pid = _pIDxAddr[addr];
uint256 reward = _plyr[pid].rreward;
require(reward > 0,"only have reward");
//reset
_plyr[pid].allReward = _plyr[pid].allReward.add(reward);
_plyr... | 0.5.5 |
/**
* @dev add a default player
*/ | function addDefaultPlayer(address addr, bytes32 name)
private
{
_pID++;
_plyr[_pID].addr = addr;
_plyr[_pID].name = name;
_plyr[_pID].nameCount = 1;
_pIDxAddr[addr] = _pID;
_pIDxName[name] = _pID;
_plyrNames[_pID][name] = true;
... | 0.5.5 |
/**
* @dev bind a refer,if affcode invalid, use default refer
*/ | function bindRefer( address from, string calldata affCode )
isRegisteredPool()
external
returns (bool)
{
bytes memory tempCode = bytes(affCode);
bytes32 affName = 0x0;
if (tempCode.length >= 0) {
assembly {
affName := mload(add(... | 0.5.5 |
// get total count tokens (to calculate profit for one token) | function get_CountProfitsToken() constant returns(uint256){
uint256 countProfitsTokens = 0;
mapping(address => bool) uniqueHolders;
uint256 countHolders = smartToken.getCountHolders();
for(uint256 i=0; i<countHolders; i++)
{
address holder = smartToken.getItemHolders(i);
if(holder!=address(0x... | 0.4.8 |
// get holders addresses to make payment each of them | function get_Holders(uint256 position) constant returns(address[64] listHolders, uint256 nextPosition)
{
uint8 n = 0;
uint256 countHolders = smartToken.getCountHolders();
for(; position < countHolders; position++){
address holder = smartToken.getItemHolders(position);
if(holder!=address(0x0)){
... | 0.4.8 |
// Get profit for specified token holder
// Function should be executed in blockDividend ! (see struct DividendInfo)
// Don't call this function via etherescan.io
// Example how to call via JavaScript and web3
// var abiDividend = [...];
// var holderAddress = "0xdd94ddf50485f41491c415e7133100e670cd4ef3";
// var divide... | function get_HoldersProfit(uint256 dividendPaymentNum, address holder) constant returns(uint256){
uint256 profit = 0;
if(holder != address(0x0) && dividendHistory.length > 0 && dividendPaymentNum < dividendHistory.length){
uint256 count_tokens = smartToken.balanceOf(holder) + smartToken.tempTokensBalanceOf(ho... | 0.4.8 |
//CONSTANT HELPER FUNCTIONS | function getBankroll()
constant
returns(uint) {
if ((invested < investorsProfit) ||
(invested + investorsProfit < invested) ||
(invested + investorsProfit < investorsLosses)) {
return 0;
}
else {
return invested + investo... | 0.4.19 |
/* Allocate Tokens for MAR */ | function allocateMARTokens() public {
require(msg.sender==tokenIssuer);
uint tokens = 0;
if(block.timestamp > month6Unlock && !month6Allocated)
{
month6Allocated = true;
tokens = safeDiv(totalTokensMAR, 5);
balances[tokenIssuer] = safeAdd... | 0.4.25 |
/* Allocate Tokens for DAPP */ | function allocateDAPPTokens() public {
require(msg.sender==tokenIssuer);
uint tokens = 0;
if(block.timestamp > month9Unlock && !month9Allocated)
{
month9Allocated = true;
tokens = safeDiv(totalTokensDAPP, 5);
balances[tokenIssuer] = safeA... | 0.4.25 |
/* Mint Token */ | function mintTokens(address tokenHolder, uint256 amountToken) public
returns (bool success)
{
require(msg.sender==tokenIssuer);
if(totalTokenSaled + amountToken <= totalTokensCrowdSale + totalTokensReward)
{
balances[tokenHolder] = safeAdd(balances[tokenHolder... | 0.4.25 |
/**
* @dev Approves the token to the spender address with allowance amount.
* @notice Approves the token to the spender address with allowance amount.
* @param token_ token for which allowance is to be given.
* @param spender_ the address to which the allowance is to be given.
* @param amount_ amount of token.
*/ | function approve(
address token_,
address spender_,
uint256 amount_
) internal {
TokenInterface tokenContract_ = TokenInterface(token_);
try tokenContract_.approve(spender_, amount_) {} catch {
IERC20 token = IERC20(token_);
token.safeApprove(spender_,... | 0.8.4 |
/**
* @dev Approves the tokens to the receiver address with allowance (amount + fee).
* @notice Approves the tokens to the receiver address with allowance (amount + fee).
* @param _instaLoanVariables struct which includes list of token addresses and amounts.
* @param _fees list of premiums/fees for the correspondin... | function safeApprove(
FlashloanVariables memory _instaLoanVariables,
uint256[] memory _fees,
address _receiver
) internal {
uint256 length_ = _instaLoanVariables._tokens.length;
require(
length_ == _instaLoanVariables._amounts.length,
"Lengths of param... | 0.8.4 |
/**
* @dev Transfers the tokens to the receiver address.
* @notice Transfers the tokens to the receiver address.
* @param _instaLoanVariables struct which includes list of token addresses and amounts.
* @param _receiver address to which tokens have to be transferred.
*/ | function safeTransfer(
FlashloanVariables memory _instaLoanVariables,
address _receiver
) internal {
uint256 length_ = _instaLoanVariables._tokens.length;
require(
length_ == _instaLoanVariables._amounts.length,
"Lengths of parameters not same"
);
... | 0.8.4 |
/**
* @dev Calculates the balances..
* @notice Calculates the balances of the account passed for the tokens.
* @param _tokens list of token addresses to calculate balance for.
* @param _account account to calculate balance for.
*/ | function calculateBalances(address[] memory _tokens, address _account)
internal
view
returns (uint256[] memory)
{
uint256 _length = _tokens.length;
uint256[] memory balances_ = new uint256[](_length);
for (uint256 i = 0; i < _length; i++) {
IERC20 token = ... | 0.8.4 |
/**
* @dev Supply tokens for the amounts to compound.
* @notice Supply tokens for the amounts to compound.
* @param _tokens token addresses.
* @param _amounts amounts of tokens.
*/ | function compoundSupply(address[] memory _tokens, uint256[] memory _amounts)
internal
{
uint256 length_ = _tokens.length;
require(_amounts.length == length_, "array-lengths-not-same");
address[] memory cTokens_ = new address[](length_);
for (uint256 i = 0; i < length_; i++) {... | 0.8.4 |
/**
* @dev Withdraw tokens from compound.
* @notice Withdraw tokens from compound.
* @param _tokens token addresses.
* @param _amounts amounts of tokens.
*/ | function compoundWithdraw(
address[] memory _tokens,
uint256[] memory _amounts
) internal {
uint256 length_ = _tokens.length;
require(_amounts.length == length_, "array-lengths-not-same");
for (uint256 i = 0; i < length_; i++) {
if (_tokens[i] == address(wethToken... | 0.8.4 |
/**
* @dev Supply tokens to aave.
* @notice Supply tokens to aave.
* @param _tokens token addresses.
* @param _amounts amounts of tokens.
*/ | function aaveSupply(address[] memory _tokens, uint256[] memory _amounts)
internal
{
uint256 length_ = _tokens.length;
require(_amounts.length == length_, "array-lengths-not-same");
for (uint256 i = 0; i < length_; i++) {
approve(_tokens[i], address(aaveLending), _amounts[... | 0.8.4 |
/**
* @dev Borrow tokens from aave.
* @notice Borrow tokens from aave.
* @param _tokens list of token addresses.
* @param _amounts list of amounts for respective tokens.
*/ | function aaveBorrow(address[] memory _tokens, uint256[] memory _amounts)
internal
{
uint256 length_ = _tokens.length;
require(_amounts.length == length_, "array-lengths-not-same");
for (uint256 i = 0; i < length_; i++) {
aaveLending.borrow(_tokens[i], _amounts[i], 2, 3228... | 0.8.4 |
/**
* @dev Payback tokens to aave.
* @notice Payback tokens to aave.
* @param _tokens list of token addresses.
* @param _amounts list of amounts for respective tokens.
*/ | function aavePayback(address[] memory _tokens, uint256[] memory _amounts)
internal
{
uint256 length_ = _tokens.length;
require(_amounts.length == length_, "array-lengths-not-same");
for (uint256 i = 0; i < length_; i++) {
approve(_tokens[i], address(aaveLending), _amounts... | 0.8.4 |
/**
* @dev Withdraw tokens from aave.
* @notice Withdraw tokens from aave.
* @param _tokens token addresses.
* @param _amounts amounts of tokens.
*/ | function aaveWithdraw(address[] memory _tokens, uint256[] memory _amounts)
internal
{
uint256 length_ = _tokens.length;
require(_amounts.length == length_, "array-lengths-not-same");
for (uint256 i = 0; i < length_; i++) {
aaveLending.withdraw(_tokens[i], _amounts[i], add... | 0.8.4 |
/**
* @dev Returns fee for the passed route in BPS.
* @notice Returns fee for the passed route in BPS. 1 BPS == 0.01%.
* @param _route route number for flashloan.
*/ | function calculateFeeBPS(uint256 _route, address account_)
public
view
returns (uint256 BPS_)
{
if (_route == 1) {
BPS_ = aaveLending.FLASHLOAN_PREMIUM_TOTAL();
} else if (_route == 2 || _route == 3 || _route == 4) {
BPS_ = (makerLending.toll()) / (10*... | 0.8.4 |
/**
* @dev Calculate fees for the respective amounts and fee in BPS passed.
* @notice Calculate fees for the respective amounts and fee in BPS passed. 1 BPS == 0.01%.
* @param _amounts list of amounts.
* @param _BPS fee in BPS.
*/ | function calculateFees(uint256[] memory _amounts, uint256 _BPS)
internal
pure
returns (uint256[] memory)
{
uint256 length_ = _amounts.length;
uint256[] memory InstaFees = new uint256[](length_);
for (uint256 i = 0; i < length_; i++) {
InstaFees[i] = (_amou... | 0.8.4 |
/**
* @dev Sort the tokens and amounts arrays according to token addresses.
* @notice Sort the tokens and amounts arrays according to token addresses.
* @param _tokens list of token addresses.
* @param _amounts list of respective amounts.
*/ | function bubbleSort(address[] memory _tokens, uint256[] memory _amounts)
internal
pure
returns (address[] memory, uint256[] memory)
{
for (uint256 i = 0; i < _tokens.length - 1; i++) {
for (uint256 j = 0; j < _tokens.length - i - 1; j++) {
if (_tokens[j] >... | 0.8.4 |
/**
* Constructor - instantiates token supply and allocates balanace of
* to the owner (msg.sender).
*/ | function QuantstampToken(address _admin) {
// the owner is a custodian of tokens that can
// give an allowance of tokens for crowdsales
// or to the admin, but cannot itself transfer
// tokens; hence, this requirement
require(msg.sender != _admin);
totalSupply = I... | 0.4.18 |
/**
* Associates this token with a current crowdsale, giving the crowdsale
* an allowance of tokens from the crowdsale supply. This gives the
* crowdsale the ability to call transferFrom to transfer tokens to
* whomever has purchased them.
*
* Note that if _amountForSale is 0, then it is assumed that the fu... | function setCrowdsale(address _crowdSaleAddr, uint256 _amountForSale) external onlyOwner {
require(!transferEnabled);
require(_amountForSale <= crowdSaleAllowance);
// if 0, then full available crowdsale supply is assumed
uint amount = (_amountForSale == 0) ? crowdSaleAllowance : _... | 0.4.18 |
/**
* Overrides ERC20 transferFrom function with modifier that prevents the
* ability to transfer tokens until after transfers have been enabled.
*/ | function transferFrom(address _from, address _to, uint256 _value) public onlyWhenTransferEnabled validDestination(_to) returns (bool) {
bool result = super.transferFrom(_from, _to, _value);
if (result) {
if (msg.sender == crowdSaleAddr)
crowdSaleAllowance = crowdSaleAllow... | 0.4.18 |
/**
* @dev Overload of {ECDSA-recover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.2._
*/ | function recover(
bytes32 hash,
bytes32 r,
bytes32 vs
) internal pure returns (address) {
bytes32 s;
uint8 v;
assembly {
s := and(vs, 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
v := add(shr(255, vs), 27)
... | 0.8.4 |
// via https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI_0.5.sol MIT licence | function Concatenate(string memory a, string memory b) public pure returns (string memory concatenatedString) {
bytes memory bytesA = bytes(a);
bytes memory bytesB = bytes(b);
string memory concatenatedAB = new string(bytesA.length + bytesB.length);
bytes memory bytesAB = bytes(concatenatedAB);
... | 0.5.8 |
/**
* @dev Add to token to cToken mapping.
* @notice Add to token to cToken mapping.
* @param _cTokens list of cToken addresses to be added to the mapping.
*/ | function addTokenToCToken(address[] memory _cTokens) public {
for (uint256 i = 0; i < _cTokens.length; i++) {
(bool isMarket_, , ) = troller.markets(_cTokens[i]);
require(isMarket_, "unvalid-ctoken");
address token_ = CTokenInterface(_cTokens[i]).underlying();
req... | 0.8.4 |
/**
* @dev Callback function for aave flashloan.
* @notice Callback function for aave flashloan.
* @param _assets list of asset addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets for flashloan.
* @param _premiums list of premiums/fees for the corresponding addresses for flashlo... | function executeOperation(
address[] memory _assets,
uint256[] memory _amounts,
uint256[] memory _premiums,
address _initiator,
bytes memory _data
) external verifyDataHash(_data) returns (bool) {
require(_initiator == address(this), "not-same-sender");
requir... | 0.8.4 |
/**
* @dev Middle function for route 1.
* @notice Middle function for route 1.
* @param _tokens list of token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets or amount of ether to borrow as collateral for flashloan.
* @param _data extra data passed.
*/ | function routeAave(
address[] memory _tokens,
uint256[] memory _amounts,
bytes memory _data
) internal {
bytes memory data_ = abi.encode(msg.sender, _data);
uint256 length_ = _tokens.length;
uint256[] memory _modes = new uint256[](length_);
for (uint256 i = 0;... | 0.8.4 |
/**
* @dev Middle function for route 2.
* @notice Middle function for route 2.
* @param _token token address for flashloan(DAI).
* @param _amount DAI amount for flashloan.
* @param _data extra data passed.
*/ | function routeMaker(
address _token,
uint256 _amount,
bytes memory _data
) internal {
address[] memory tokens_ = new address[](1);
uint256[] memory amounts_ = new uint256[](1);
tokens_[0] = _token;
amounts_[0] = _amount;
bytes memory data_ = abi.encode... | 0.8.4 |
/**
* @dev Middle function for route 3.
* @notice Middle function for route 3.
* @param _tokens token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets.
* @param _data extra data passed.
*/ | function routeMakerCompound(
address[] memory _tokens,
uint256[] memory _amounts,
bytes memory _data
) internal {
bytes memory data_ = abi.encode(
3,
_tokens,
_amounts,
msg.sender,
_data
);
dataHash = bytes32... | 0.8.4 |
/**
* @dev Main function for flashloan for all routes. Calls the middle functions according to routes.
* @notice Main function for flashloan for all routes. Calls the middle functions according to routes.
* @param _tokens token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets.... | function flashLoan(
address[] memory _tokens,
uint256[] memory _amounts,
uint256 _route,
bytes calldata _data,
bytes calldata // kept for future use by instadapp. Currently not used anywhere.
) external reentrancy {
require(_tokens.length == _amounts.length, "array-le... | 0.8.4 |
/**
* @dev Function to get the list of available routes.
* @notice Function to get the list of available routes.
*/ | function getRoutes() public pure returns (uint16[] memory routes_) {
routes_ = new uint16[](7);
routes_[0] = 1;
routes_[1] = 2;
routes_[2] = 3;
routes_[3] = 4;
routes_[4] = 5;
routes_[5] = 6;
routes_[6] = 7;
} | 0.8.4 |
/**
* @dev Function to transfer fee to the treasury.
* @notice Function to transfer fee to the treasury. Will be called manually.
* @param _tokens token addresses for transferring fee to treasury.
*/ | function transferFeeToTreasury(address[] memory _tokens) public {
for (uint256 i = 0; i < _tokens.length; i++) {
IERC20 token_ = IERC20(_tokens[i]);
uint256 decimals_ = TokenInterface(_tokens[i]).decimals();
uint256 amtToSub_ = decimals_ == 18 ? 1e10 : decimals_ > 12
... | 0.8.4 |
/**
* @dev Calculates the amount of dTokens that will be minted when the given amount
* is deposited.
* used in the deposit() function to calculate the amount of dTokens that
* will be minted.
*
* @dev refer to keeperDao whose code is here:
https://etherscan.io/address/0x53463cd0b074e5fda... | function calculateMintAmount(uint256 _depositAmount) internal view returns (uint256) {
// The total balance includes the deposit amount, which is removed here.
uint256 initialBalance = dollar.balanceOf(address(this)).sub(_depositAmount);
if (totalSupply() == 0) {
// if ... | 0.6.12 |
/**
* @dev Function to get the required amount of collateral to be paid to Uniswap and the expected amount to exercise the ACO token.
* @param acoToken Address of the ACO token.
* @param tokenAmount Amount of tokens to be exercised.
* @param accounts The array of addresses to be exercised. Whether the array is ... | function getExerciseData(address acoToken, uint256 tokenAmount, address[] memory accounts) public view returns(uint256, uint256) {
if (tokenAmount > 0) {
address pair = getUniswapPair(acoToken);
if (pair != address(0)) {
address token0 = IUniswapV2Pair(pair).token0();... | 0.6.6 |
/**
* @dev Function to get the estimated collateral to be received through a flash exercise.
* @param acoToken Address of the ACO token.
* @param tokenAmount Amount of tokens to be exercised.
* @return The estimated collateral to be received through a flash exercise using the standard exercise function.
*/ | function getEstimatedReturn(address acoToken, uint256 tokenAmount) public view returns(uint256) {
(uint256 amountRequired,) = getExerciseData(acoToken, tokenAmount, new address[](0));
if (amountRequired > 0) {
(uint256 collateralAmount,) = IACOToken(acoToken).getCollateralOnExercise(token... | 0.6.6 |
/**
* @dev Internal function to get the ACO tokens exercise data.
* @param acoToken Address of the ACO token.
* @param tokenAmount Amount of tokens to be exercised.
* @param accounts The array of addresses to be exercised. Whether the array is empty the exercise will be executed using the standard method.
*... | function _getAcoExerciseData(address acoToken, uint256 tokenAmount, address[] memory accounts) internal view returns(address, uint256) {
(address exerciseAddress, uint256 expectedAmount) = IACOToken(acoToken).getBaseExerciseData(tokenAmount);
if (accounts.length == 0) {
expectedAmount = expectedAmount + IACOT... | 0.6.6 |
/**
* @dev Internal function to flash exercise ACO tokens.
* @param acoToken Address of the ACO token.
* @param tokenAmount Amount of tokens to be exercised.
* @param minimumCollateral The minimum amount of collateral accepted to be received on the flash exercise.
* @param salt Random number to calculate the ... | function _flashExercise(
address acoToken,
uint256 tokenAmount,
uint256 minimumCollateral,
uint256 salt,
address[] memory accounts
) internal {
address pair = getUniswapPair(acoToken);
require(pair != address(0), "ACOFlashExercise::_flashExercise: I... | 0.6.6 |
/// @notice Withdraw all
/// @param user User address
/// @param pwrd pwrd/gvt token
/// @param minAmount min amount of token to withdraw | function emergencyWithdrawAll(
address user,
bool pwrd,
uint256 minAmount
) external override {
// Only withdrawHandler can call this method
require(msg.sender == ctrl.withdrawHandler(), "EmergencyHandler: !WithdrawHandler");
IToken gt = IToken(gTokens(pwrd));
... | 0.6.12 |
/// @notice Withdraw partial
/// @param user User address
/// @param pwrd pwrd/gvt token
/// @param inAmount usd to witdraw
/// @param minAmount min amount of token to withdraw | function emergencyWithdrawal(
address user,
bool pwrd,
uint256 inAmount,
uint256 minAmount
) external override {
// Only withdrawHandler can call this method
require(msg.sender == ctrl.withdrawHandler(), "EmergencyHandler: !WithdrawHandler");
IToken gt... | 0.6.12 |
// Source : https://ethereum.stackexchange.com/questions/8086/logarithm-math-operation-in-solidity | function log(uint x) internal pure returns (uint y)
{
assembly
{
let arg := x
x := sub(x,1)
x := or(x, div(x, 0x02))
x := or(x, div(x, 0x04))
x := or(x, div(x, 0x10))
x := or(x, div(x, 0x100))
x := or(x, div(x, 0x10000))
x := or(x, div(x, 0x100000000))
x := or(x, div(x, 0x100... | 0.4.21 |
/*
* The RLC Token created with the time at which the crowdsale end
*/ | function RLC() {
// lock the transfer function during the crowdsale
locked = true;
//unlockBlock= now + 45 days; // (testnet) - for mainnet put the block number
initialSupply = 87000000000000000;
totalSupply = initialSupply;
balances[msg.sender] = initialSupply;// Give the creator all i... | 0.4.21 |
// Max potential payments | function private_getGameState() public view returns(uint256 _contractBalance,
bool _game_paused,
uint256 _minRoll,
uint256 _maxRoll,
uint256 _minBet,
uint256 _maxBet,
uint256 _houseEdge,
uint256 _totalUserProfit,
uint256 _totalWins,
uint25... | 0.4.24 |
// need to process any playerPendingWithdrawals
// Allow a user to withdraw any pending amount (That may of failed previously) | function player_withdrawPendingTransactions() public
returns (bool)
{
uint withdrawAmount = playerPendingWithdrawals[msg.sender];
playerPendingWithdrawals[msg.sender] = 0;
if (msg.sender.call.value(withdrawAmount)()) {
return true;
} else {
... | 0.4.24 |
/* Issue */ | function issueToken(uint256 _count) onlyAdmins() public {
uint256 l = tokenSize;
uint256 r = tokenSize + _count;
for (uint256 i = l; i < r; i++) {
ownerOfToken[i] = msg.sender;
}
tokenSize += _count;
} | 0.4.21 |
/**
* Mints Degenz
*/ | function mintDegen(uint numberOfTokens) public payable {
require(saleIsActive, "Sale must be active to mint Degen");
require(numberOfTokens <= maxDegenPurchase, "Can only mint 10 tokens at a time");
require(totalSupply().add(numberOfTokens) <= MAX_DEGENZ, "Purchase would exceed max supply of ... | 0.7.6 |
/**
* @dev Send token to multiple address
* @param _investors The addresses of EOA that can receive token from this contract.
* @param _tokenAmounts The values of token are sent from this contract.
*/ | function batchTransferFrom(address _tokenAddress, address[] _investors, uint256[] _tokenAmounts) public {
ERC20BasicInterface token = ERC20BasicInterface(_tokenAddress);
require(_investors.length == _tokenAmounts.length && _investors.length != 0);
for (uint i = 0; i < _investors.length; i++... | 0.4.23 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.