In this tutorial we are going to walkthrough the Wings integration process.
- Make a call to method createCustomCrowdsale in DAO contract
- Find crowdsaleController address
- Start crowdsale
- Nodejs v10.2.1
- Truffle v4.1.8
- Ganache-cli v6.1.0
Clone this repository.
git clone https://github.com/wingsdao/wings-light-bridge.git NOTE: Before deployment of Bridge contract you may already have deployed token contract. In this case just head to paragraph b) and assign your deployed token address to token variable.
a) Prepare these variables for DefaultToken contract:
name- name of your tokensymbol- symbol of your tokendecimals- token decimals
b) Prepare these variables for Bridge contract:
minimalGoal- soft cap of your crowdfunding campaign (this argument is currently not used in wings light bridge, use default value which is set to 1)hardCap- hard cap of your crowdfunding campaign (this argument is currently not used in wings light bridge, use default value which is set to 1)token- address of your ERC20-compliant token
Deploy contracts to mainnet using truffle, parity, etc.
NOTE: Before deployment of Bridge contract you may already have deployed token contract. In this case you only need to deploy Bridge contract.
Deployment process:
During deployment of DefaultToken pass name, symbol and decimals as arguments to constructor.
During deployment of Bridge pass minimalGoal, hardCap, token as arguments to constructor.
Create project on Wings platform as custom contract and provide address of bridge contract.
Now we need to create project on Wings platform. We go to Wings, fill project details, and in Smart contract tab we need to select Custom Contract and put Bridge Contract Address to Contract address field.
Like on image:
After this step you can start your project's forecasting.
To do it, just take URL of your project, like:
https://wings.ai/project/0x28e7f296570498f1182cf148034e818df723798a
As you see - 0x28e7f296570498f1182cf148034e818df723798a, it's your DAO contract address. You can check it via parity or some other ethereum client/tool. Account that you used during project creation on wings.ai is owner of this smart contract.
Initiate DAO contract with the address we just retrieved:
Here are ABI for contracts and we recommend to use truffle contract library to make calls.
Here are interfaces for contracts.
constdao=awaitDAO.at('0x28e7f296570498f1182cf148034e818df723798a')// change with your DAO addressDuring forecasting period transfer manager to DAO contract.
Interface:
function transferManager(address _newManager) public;Example:
awaitbridge.transferManager(dao.address,{from: yourAccount})// change with your DAO addressWhen the forecasting finish you have 45 days to start your project's crowdsale.
To start crowdsale, complete the following steps.
Make a call to method DAO.createCustomCrowdsale().
Interface:
function createCustomCrowdsale() public onlyOwner() hasntStopped() requireStage(Stage.ForecastingClosed);Example:
awaitdao.createCustomCrowdsale()Make a call to getter method DAO.crowdsaleController().
Interface:
function crowdsaleController() public view returns (address);Example:
constccAddress=awaitdao.crowdsaleController.call()constcrowdsaleController=awaitCrowdsaleController.at(ccAddress)To start your project's crowdsale (Bridge) you need to make a call to crowdsaleController's method start.
Interface:
function start( uint256 _startTimestamp, uint256 _endTimestamp, address _fundingAddress ) public;Parameters:
_startTimestamp- timestamp of the start of your crowdsale._endTimestamp- timestamp of the end of your crowdsale._fundingAddress- the address, which will receive funds
Example:
awaitcrowdsaleController.start(0,0,'0x0')IMPORTANT: values like 0, 0, '0x0' for start works fine only if you are using bridge. If you've done full integration, you have to do it in another way.
After this step your crowdsale is taking place and you come back right before the end of crowdfunding to complete few final steps.
If you need to check address of token contract which you specified during Bridge deploy, use getToken method.
function getToken() public view returns (address){return address(token)}Returns:
- address of token contract
Please note that if you used DefaultToken you must change token address to the address of your real token contract which stores your project token rewards.
To change token address use changeToken method.
function changeToken(address _newToken) public onlyOwner(){token =IERC20(_newToken)}Parameters:
_newToken- address of new token contract
When crowdsale is over, make a call to this method and pass as arguments collected ETH amount and how many tokens were sold.
function notifySale(uint256 _ethAmount, uint256 _tokensAmount) public hasBeenStarted() hasntStopped() whenCrowdsaleAlive() onlyOwner(){totalCollected = totalCollected.add(_ethAmount); totalSold = totalSold.add(_tokensAmount)}Parameters:
_ethAmount- the amount of funds raised (in Wei)_tokensAmount- the amount of tokens sold
Communicates with CrowdsaleController (aka IWingsController) and calculates rewards.
function calculateRewards() public view returns (uint256, uint256){uint256 tokenRewardPart =IWingsController(manager).tokenRewardPart(); uint256 ethRewardPart =IWingsController(manager).ethRewardPart(); uint256 tokenReward = totalSold.mul(tokenRewardPart) /1000000; uint256 ethReward = (ethRewardPart ==0) ?0: (totalCollected.mul(ethRewardPart) /1000000); return (ethReward, tokenReward)}Returns:
ethReward- ETH reward amount (in Wei)tokenReward- token reward amount
And now, before making a call to finish method, make a call to method calculateRewards to find out the amount of rewards.
Important: Send token and ETH rewards to Bridge contract.
Call this method to stop Bridge. Changes the state of crowdsale to completed.
function finish() public hasntStopped() hasBeenStarted() whenCrowdsaleAlive() onlyOwner(){completed =true}That's it. Crowdsale is finished.
We recommend to make pull requests to current repository. Each pull request should be covered with tests.
Fetch current repository, install dependencies:
npm install We strongly recommend to develop using ganache-cli to save time and cost.
To run tests fetch current repository, install dependencies and run:
truffle test Wings Stiftung
See in license file.
