Skip to content

shadow-syndicate/contracts

Repository files navigation

Roach Racing Club Contracts

RRC is a strategic racing game where you can breed and train your Roach runners. The results of each race are driven by real-world data and depend on your strategic and tactical decisions. The game introduces novel gameplay features and an evolutionary breeding model with deflationary mechanisms.

Contracts structure

RoachNFT

Base NFT storage. Stores token ownership, genomes, parents. Tokens are created during the Egg stage. This contract is non-upgradable.

/// Returns contract level metadata for roach
function getRoach(roachId) 
    returns (genome, parents, creationTime, revealTime, generation, resistance, memory name) 

Reveal

You should call reveal to finalize creating and give birth to the Roach token. There is a birth cooldown period (by default, 1 week).

/// Setups roach genome and give birth to it
function reveal(tokenId, genome, tokenSeed, sigV, sigR, sigS)

GensisSale

Operates limited token sale. There can be only 10k Gen0 Roach tokens sold.

/// Returns current sale status:
function getSaleStatus(address account) external view 
    returns (stage, leftToMint, nextStageTimestamp, price, allowedToMint) 
/// Takes donation and mints new roaches
function mint(desiredCount, limitForAccount, price, sigV, sigR, sigS)

GenomeProviderChainlink

Generates genome for each new Roach token using ChainLink VRF. TokenSeed is generated using formula sha3(tokenId, traitBonus, devSeed, vrfSeed)

Where:

  • tokenId - roach id.
  • devSeed - secret value, that is available only to developer team while genesis sale is not finished.
  • vrfSeed - random value that is generated by Chainlink VRF after sha3(devSeed) is published.

TokenSeed is unpredictable during the mint stage for all parties:

  • Developers can't predict vrfSeed
  • Miners can't predict devSeed
  • Buyers can't predict both devSeed

So TokenSeed is unpredictable but fixed and can be checked at any time after the reveal. Genome is generated using tokenSeed. For the same tokenSeed, there will be equal genomes. After the genesis sale is finished, the game will publish devSeed, and anyone will be able to check tokenSeeds and corresponding genomes.

Genome is signed by the secret private key and transferred from Polygon network to Ethereum as part of the reveal process.

/// Calculates genome for each roach using tokenSeed as seed
function calculateGenome(tokenSeed, traitBonus)

Metadata

An upgradeable contract that provides Metadata for Roach tokens. Full metadata will be available only after Roach is born.

/// Returns token metadata URI according to IERC721Metadata
function tokenURI(tokenId)

Deployment workflow

Environment setup

We use Brownie framework for testing and development.

pip install eth-brownie
brownie pm install OpenZeppelin/openzeppelin-contracts@4.8.3
brownie pm install smartcontractkit/chainlink@2.7.0
npm -g i ganache-cli

Testing

All tests can be launched using the command

brownie test

Testnet deployment

Setup environment variables:

export DEPLOYER_PRIVATE_KEY=<deployer_account_private_key>
export WEB3_INFURA_PROJECT_ID=<infura_project_id>
export ETHERSCAN_TOKEN=<etherscan_api_token>
export POLYGONSCAN_TOKEN=<polygoncan_api_token>

Add development network

brownie networks add Polygon polygon-test2 chainid=80001 host=https://polygon-mumbai.g.alchemy.com/v2/<ALCHEMY_API_KEY> explorer=https://api-testnet.polygonscan.com/api

Deploy command for Mainnet part:

brownie run ./deploy_eth.py --network=mainnet # prod
brownie run ./deploy_eth.py --network=goerli # testnet

Deploy command Polygon part:

brownie run ./deploy_polygon.py --network=polygon-main # prod
brownie run ./deploy_polygon.py --network=polygon-test2 # testnet

It is needed to request testnet LINK to GenomeProviderChainlink contract. After link token is transferred to GenomeProviderChainlink contract, you should call

function requestVrfSeed()

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors