Skip to content

Releases: NFhbar/smart-contract-faucet

Avocado Network Smart Contract Faucet

15 May 20:17
Compare
Choose a tag to compare

Avocado Network - Smart Contract Faucet

Build Status
Coverage Status

AVO Faucet

Smart contract faucet for Avocado Network.

v2.0.0

Version 2.0.0 implements a generic ERC20Basic token instance set by the constructor, allowing the Faucet to be deployed and used by any standard token contract.

AVO Rinkeby Instance here.

Gist available here.

The Faucet contract allows senders to send and receive ERC20Basic tokens.

The constructor sets the initial token instance, faucet name, and turns the faucet on:

constructor(address _tokenInstance, string _faucetName)
  public
{
    tokenInstance = ERC20Basic(_tokenInstance);
    faucetName = _faucetName;
    faucetStatus = true;

    emit FaucetOn(faucetStatus);
}

The Faucet can only be turned on and off by the owner of the contract as set by Ownable.sol.

Drip Tokens

The Faucet has 3 methods for dripping 1000, 2000, or 5000 tokens to senders:

function drip1000Token()
function drip2000Token()
function drip5000Token()

The time lock period for each function is 1 hour, 2 hours, and 5 hours respectively.

All functions follow the same logic:

function drip1000Token()
  public
  faucetOn()
{
    if(checkStatus(msg.sender)) {
        revert();
    }
    tokenInstance.transfer(msg.sender, oneKToken);
    updateStatus(msg.sender, oneHours);

    emit OneKTokenSent(msg.sender);
}

First the function requires the faucet is turned on. Then the status of the sender is checked for lock or unlocked depending on their previous state:

function checkStatus(address _address)
  internal
  view
  returns (bool)
{
    //check if first time address is requesting
    if(status[_address] == 0) {
        return false;
    }
    //if not first time check the timeLock
    else {
        // solium-disable-next-line security/no-block-members
        if(block.timestamp >= status[_address]) {
            return false;
        }
        else {
            return true;
        }
    }
}

If the status is locked the drip function reverts:

if(checkStatus(msg.sender)) {
    revert();
}

Otherwise the sender receives tokens:

tokenInstance.transfer(msg.sender, oneKToken);
updateStatus(msg.sender, oneHours);

emit OneKTokenSent(msg.sender);

The status of the sender is then updated with the corresponding locked time period using block.timestamp:

function updateStatus(address _address, uint256 _timelock)
  internal
{   // solium-disable-next-line security/no-block-members
    status[_address] = block.timestamp + _timelock;
}

Install

ethpm

Install as ethpm:

$ truffle install avo-token-faucet@2.0.0

Clone

Clone repo:

git clone git@github.com:NFhbar/smart-contract-faucet.git

Create a new .env file in root directory and add your private key:

RINKEBY_PRIVATE_KEY="MyPrivateKeyHere..."
ROPSTEN_PRIVATE_KEY="MyPrivateKeyHere..."

If you don't have a private key, you can use one provided by Ganache (for development only!):

RINKEBY_PRIVATE_KEY="c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3"
ROPSTEN_PRIVATE_KEY="c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3"

then:

npm install

To enter Truffle:

truffle develop

To compile:

truffle(develop)> compile

To migrate:

truffle(develop)> migrate

To test:

truffle(develop)> test

License

MIT

Avocado Network - Smart Contract Faucet

12 May 21:37
Compare
Choose a tag to compare

Avocado Network - Smart Contract Faucet

Build Status
Coverage Status

AVO Faucet

Smart contract faucet for Avocado Network.

Rinkeby Instance here.

Gist available here.

The Faucet contract allows senders to send and receive AVO tokens.

The constructor sets the initial token instance and turns the faucet on:

constructor(address _avoInstance)
  public
{
    avoInstance = AvocadoToken(_avoInstance);
    faucetStatus = true;

    emit FaucetOn(faucetStatus);
}

The Faucet can only be turned on and off by the owner of the contract as set by Ownable.sol.

Drip AVO

The Faucet has 3 methods for dripping 1000, 2000, or 5000 AVO tokens to senders:

function drip1000AVO()
function drip2000AVO()
function drip5000AVO()

The time lock period for each function is 1 hour, 2 hours, and 5 hours respectively.

All functions follow the same logic:

function drip1000AVO()
  public
  faucetOn()
{
    checkStatus(msg.sender);
    if(status[msg.sender].locked) {
        revert();
    }
    avoInstance.transfer(msg.sender, oneKAVO);
    updateStatus(msg.sender, oneHours);

    emit OneKAVOSent(msg.sender);
}

First the function requires the faucet is turned on. Then the status of the sender is checked for lock or unlocked depending on their previous state:

function checkStatus(address _address)
  internal
{
    //check if first time address is requesting
    if(status[_address].timeLock == 0) {
        status[_address].locked = false;
    }
    //if not first time check the timeLock
    else {
        // solium-disable-next-line security/no-block-members
        if(block.timestamp >= status[_address].timeLock) {
            status[_address].locked = false;
        }
        else {
            status[_address].locked = true;
        }
    }
}

If the status is locked the drip function reverts:

if(status[msg.sender].locked) {
    revert();
}

Otherwise the sender receives AVO tokens:

avoInstance.transfer(msg.sender, oneKAVO);
updateStatus(msg.sender, oneHours);

The status of the sender is then updated with the corresponding locked time period using block.timestamp:

function updateStatus(address _address, uint256 _timelock)
  internal
{   // solium-disable-next-line security/no-block-members
    status[_address].timeLock = block.timestamp + _timelock;
}

Install

ethpm

Install as ethpm:

$ truffle install avo-token-faucet@1.0.1

Clone

Clone repo:

git clone git@github.com:NFhbar/smart-contract-faucet.git

then:

npm install

To enter Truffle:

truffle develop

To compile:

truffle(develop)> compile

To migrate:

truffle(develop)> migrate

To test:

truffle(develop)> test

License

MIT