Coder Social home page Coder Social logo

contracts's Introduction

Sunflower Land Contracts

These contracts are for educational use only. Use at your own risk.

This repo includes the contracts used in Sunflower Land along with a suite of tests.

Prerequisites

  • make
  • solc (brew install solidity)
  • nodejs
  • docker-compose

Getting Started with this repo

Run make to see full list of commands.

Testing

  1. Open docker (if not already running)
  2. Start ganache - docker-compose up eth
  3. make test

Contract Addresses

FARM_CONTRACT="0x2B4A66557A79263275826AD31a4cDDc2789334bD" INVENTORY_CONTRACT="0x22d5f9B75c524Fec1D6619787e582644CD4D7422" TOKEN_CONTRACT="0xD1f9c58e33933a993A3891F8acFe05a68E1afC05" BETA_CONTRACT="0x48AfE14AE52987F6fE6E2F69aB74DC7Ac5a10fd2" SESSION_CONTRACT="0x49287922D4fe89D260C94F1a7Eb3c3FbBBc2788e"

WISHING_WELL_CONTRACT="0xBE403A6054af56629D7d591A8fBD8cce3dc66771"

Architecture

Sunflower Land uses an off-chain architecture to allow players to store data off-chain without the need to transact on the Blockchain after every action.

Data Storage Contracts that hold the core data in the game

  • Farm.sol - NFT that is minted when starting the game
  • Token.sol - SFL ERC20 token
  • Inventory.sol - ERC1155 inventory of game supplies

Orchestration Contracts that mint, burn and transfer from the data storage contracts above

  • Beta.sol - Mint Farm NFTs during beta stage
  • Session.sol - Session management + synchronisation of off chain data

Off-chain syncrhonisation

The synchronisation of data is managed with 2 key concepts:

  • Implicit Custody of assets
  • Session Management

When a user mints a farm (Farm.sol), their NFT is assigned a unique address on the Blockchain. All tokens earnt during gameplay are sent to that address, instead of their personal wallet. A user must explicitly 'withdraw' from their NFT to gain custody of their assets. See more here - https://docs.sunflower-land.com/fundamentals/depositing-and-custody

Validation

Session.sol performs the session management. While playing the game, a user is assigned a unique session ID (see getSessionId). Each time the user either syncs or withdraws the game validates:

  1. The session ID is the same (i.e. the user has not withdrawn any resources)
  2. The caller is the owner of the NFT that holds custody of the assets
  3. The transaction has been signed by our off-chain server using Open Zepellin ECDSA utilities.

Once a user has interacted with either sync or withdraw a new session is created.

contracts's People

Contributors

adamhannigan avatar fabioelizandro avatar

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.