Skip to content

OpenSourceUniversity/wings-light-bridge

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

52 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wings Light Bridge

In this tutorial we are going to walkthrough the Wings integration process.

Content

Initial setup

During forecasting

Crowdsale start

Bridge methods

Finishing Bridge

Requirements

  • Nodejs v10.2.1
  • Truffle v4.1.8
  • Ganache-cli v6.1.0

Step by step guide

1. Setup

Clone this repository.

git clone https://github.com/wingsdao/wings-light-bridge.git

2. Prepare constructor arguments

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 token
  • symbol - symbol of your token
  • decimals - 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

3. Deploy

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.

4. Create project

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:

contract address


After this step you can start your project's forecasting.


During forecasting

1. Find DAO address from url

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.

const dao = await DAO.at('0x28e7f296570498f1182cf148034e818df723798a') // change with your DAO address

2. Transfer management to DAO

During forecasting period transfer manager to DAO contract.

Interface:

function transferManager(address _newManager) public;

Example:

await bridge.transferManager(dao.address, { from: yourAccount }) // change with your DAO address

When the forecasting finish you have 45 days to start your project's crowdsale.


Crowdsale start

To start crowdsale, complete the following steps.

1. Make a call to method createCustomCrowdsale in DAO contract

Make a call to method DAO.createCustomCrowdsale().

Interface:

function createCustomCrowdsale() public onlyOwner() hasntStopped() requireStage(Stage.ForecastingClosed);

Example:

await dao.createCustomCrowdsale()

2. Find crowdsaleController address

Make a call to getter method DAO.crowdsaleController().

Interface:

function crowdsaleController() public view returns (address);

Example:

const ccAddress = await dao.crowdsaleController.call()
const crowdsaleController = await CrowdsaleController.at(ccAddress)

3. Start crowdsale

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:

await crowdsaleController.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.


When crowdsale is about to end

getToken

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

changeToken

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

notifySale

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

calculateRewards

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

Transferring rewards

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.

finish

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.


Developing

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.

Testing

To run tests fetch current repository, install dependencies and run:

truffle test

Authors

Wings Stiftung

License

See in license file.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Solidity 55.9%
  • JavaScript 44.1%