Skip to main content

Giveaway

The Giveaway.sol smart contract has been created to register the winners of a specific giveaway instantiate by the development team and can only be retreived when the Community IDO successfuly creates the liquidity Pool.

We created this smart contract to be able to manage the marketing giveaway without compromising the createion of the first liquidity pool. Users won't have to beleive in promises but will be able to interact with our smart contract right away.

Note : This smart contract life cycle ends when the liquidity has been deployed and all winners claimed back their tokens.

Inheritances​

This contract inherits from the Context.sol and ReentrancyGuard.sol implementations from Openzeppelin as well as the Democratic.sol[Abstracts/Democratic.md].

Interfaces​

This contract uses IERC20.sol to interact with an ERC20 token implementation. We are using the interface implementation from Openzeppelin.

This contract uses ICommunityIDO.sol to interact with the community IDO smart contract.

Libraries​

This contract uses the SafeERC20.sol library implemented by Openzeppelin.

State Variables​

address public tokenAdd : address of the ERC20 token givenaway.

address public cidoAdd : address of the Community IDO smart contract.

TokenGivenAway() (Struct)​

totalWon : amount of token won without decimals

TokenClaimed : boolean that indicates if the claim has been executed.

Mappings​

public giveaways that maps the calling address to the struct TokenGivenAway;

Events​

Claim(address winner, uint256 amount)​

The event is emited each time a claim is created and return the winner address and the decimal amount

Functions​

constructor(address _doscAddress) (public)​

To instantiate the smart contract, we provide the _doscAddress that represents the address of the DemocraticOwnership.sol smart contract.

setContractAddresses(address tokenAddress, address cidoAddress) (external)​

The authorized administrator can call this function to set the tokenAdd throught tokenAddress argument and the tokenAdd throught cidoAddress.

initiateGiveaway(address[] winners, uint256[] amountsToGive) (external)​

The authorized administrator can call this function to set all the giveaway's winners and their respective non decimals winning amount.

Note : Make sure that the 2 list are perfectly sorted.

    function initiateGiveaway(address [] memory winners, uint [] memory amountsToGive) external demokratia() {
require(winners.length == amountsToGive.length, 'arrays length not matching');

for(uint i=0; i < winners.length; i++){
TokenGivenAway memory winner = giveaways[winners[i]];
giveaways[winners[i]] = TokenGivenAway(amountsToGive[i] + winner.totalWon, false);
}
}

retreiveGiveaway() (external)​

we use nonReentrant() modifier from open-zeppelin to protect this function from possible reentrancy attack and it can only be called is liquidity pool is deployed from the community IDO.

    function retreiveGiveaway() external  nonReentrant() {
TokenGivenAway memory winner = giveaways[_msgSender()];
ICommunityIDO cido = ICommunityIDO(cidoAdd);
require(cido.getDeployment(), 'liquidity not yet deployed');
require(winner.totalWon > 0, 'You have to be a winner');
require(!winner.TokenClaimed, 'You already claimed your tokens');

IERC20 token = IERC20(tokenAdd);
uint decimalsAmount = winner.totalWon * 10 ** token.decimals();

giveaways[_msgSender()].TokenClaimed = true;

token.safeTransfer(_msgSender(), decimalsAmount);

emit Claim(_msgSender(), decimalsAmount);
}