Giter Club home page Giter Club logo

nomodropmechanic's Introduction

LeagueDAO-NomoPlayersDropMechanic-contract

Prerequisites

  • ERC721 contact address which will be served
  • Contract which will act as an Escrow where the funds will be stored
  • This contract needs to be set as an operator in order to handle the transfer from the actual owner of the token to the msg.sender
  • fill in your .env file as per the example provided in env.example

Intro

This is a ERC721 compatible contract. It represents a contract, deployed on Polygon(MATIC) which accepts ERC20 tokens as a payment method and will take care for transferring ERC721 tokens to the msg.sender. NomoPlayersDropMechanic transfers 20% of the funds, in the form of ERC20 tokens, sent to DAO wallet address and 80% to Strategy contract. NomoPlayersDropMechanic contract possesses presale functionality, which gives the right to whitelisted users to purchase token in particular presale period of time, before the actual sale has started. The tokens array of ids passed into the constructor function in NomoPlayersDropMechanic contract, consists of n number of tokens, which are shuffled before the contract is deployed. The order of all token ids in the tokens array is intentionally hidden, in order the relation between index and id to be kept unclear in order to lower the change of malicious attack as much as possible.

In order the contract to be deployed properly, the contract will require:

  • an array of the token id's, shuffled before the contract is deployed.
  • erc721Address - address of the associated ERC721 contract instance.
  • tokens vault - As this contract is not meant to be an owner at any given time, it'll need the original owner which the NomoPlayersDropMechanic contract will transfer the tokens from.
  • token price - token price is intended to be paid from the user, in order to "buy" an NFT. The validation is something in top, but that's not the general purpose of the tokenPrice.
  • maximum quantity - will be used for the maximum quantity of tokens which is possible to be bought per transaction.

In order the contract functions to operate, the contract will require:

  • erc20 contract address to be set in setERC20Address - address of the associated ERC20 contract instance.
  • Strategy contract address to be set in setStrategyContractAddress - address where 80% of the funds are going be to sent to.
  • DAO wallet address to be set in setDaoWalletAddress - address where 20% of the funds are going be to sent to.

For more details refer to the white paper white paper.

In order the contract presale functionality to operate properly, the contract will require:

  • presaleStartDate to be set in setPresaleStartDate - uint256 representing the start date of the presale period.
  • presaleDuration to be set in setPresaleDuration - uint256 representing the duration of the presale.
  • whitelisted addresses to be set in setWhitelisted - address[] representing the users who will have the chance to redeem 1 token at most during the presale period.

Install Dependencies

It's as simple as running

npm install

Run

To deploy instances of the contracts for local development without prior knowledge to Hardhat, first copy .env.example to .env and run the following command:

npm run deploy

This command starts up built-in Hardhat Network and migrates all contracts to the Hardhat Network instance.

If preferred by those who are familiar with Hardhat, the standard Hardhat commands can be used. Ganache can be started up manually by configuring a local network to be run against or using the hardhat-ganache plugin or you could start a Hardhat Network using npx hardhat node. For more information on how this can be achieved refer to the official Hardhat documentation

In a separate terminal, contracts can be deployed using

  npx hardhat --network [customNetworkName] deploy

Testing

The NomoPlayersDropMechanic contract is thoroughly unit tested using Hardhat's testing framework support. To run the unit tests:

npx hardhat test

The unit tests encompass the happy path of transferring tokens as well as expected reverts. By default, the build system automates starting and stopping Hardhat Network on port http://localhost:8545 in the background ready for each test run.

Coverage

We use solidity-coverage to provide test coverage reports. In order to have our contract fully tested and prepared for Matic Mainnet we made sure that our line of the contract is covered with a test and lays on 100% coverage. In order this to be verified run:

npx hardhat coverage

Deployment

NomoPlayersDropMechanic.sol

  • Deploys the NomoPlayersDropMechanic contract
  • Initializes the contract with the provided:
    • tokens: uint256[]
    • erc721Address: address
    • tokensVault: address
    • tokenPrice: uint256
    • maxQuantity: uint256

The default network this will be deployed on is Mumbai Testnet. Once the below command is run, the contract address will be stored in ./contracts.json

npm run contracts:migrate:dev

Verify

The below command will take the contracts from ./contracts.json and will try to verify them on the default network.

npm run contracts:verify:dev

License

This project is licensed under the Apache License 2.0 license.

nomodropmechanic's People

Contributors

luboslavburdenski avatar hristiyang avatar nikitaberezhnoy avatar

Stargazers

RJ Catalano avatar

Watchers

George Spasov avatar Christian Veselinov avatar Vlad avatar Ilia Andreev avatar  avatar

Forkers

22388o parau

nomodropmechanic's Issues

Users with multisig can't use NomoPlayersDropMechanic

tx.origin == msg.sender require limits the usage of multisig wallets with the NomoPlayersDropMechanic contract. It's better to use ChainLink VRF random number. It will bring unpredictable randomness and also will protect contract from the try-revert vulnerability. Or use random number (future block hash) for the source of randomness paired with the simple back-end that will complete NFT purchase. For example:

  • User calls buyTokens function and contract sets the future block number as the source of randomness, e.g. target block = current block number + 100
  • Bot/Back-end sees buying event
  • Bot/Back-end calls finishing function (e.g. finishPurchase) when target block is mined. Contract takes the hash of the target block as the source of randomness and random token is transfered to the user.

Add nftSaleCallback call to the buyTokens function

In the NomoVault ( represented as the strategyContractAddress in the NomoPlayersDropMechanic) we have this fuction:

     * @notice Function that is called by sales contract as callback in order to deposit funds to strategy
     * @param tokensIds List of token IDs sold
     * @param prices Prices of sold tokens respectively (as wei)
     */
    function nftSaleCallback(
        uint256[] memory tokensIds,
        uint256[] memory prices
    ) external onlySales

This function is needed to know the exact amount of DAI paid to the NomoVault/Strategy per token + to know tokens league id, so we can divide DAI between leagues, so each will receive its own rewards which depend on the amount of sales. Also DAI must be approved to the NomoVault contract instead of transfering them, so we can avoid mistake with DAI amount.

You can look at the NomoVault contract here: https://github.com/LeagueDAO/nomo-strategy/blob/implement-strategy/contracts/NomoVault.sol

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.