Git Product home page Git Product logo

ecoverse-dao's Introduction

EcoSwap & DAO ๐Ÿ“ฎ

This Repo contains the codebase to mint, transfer, and use ECOV fungible tokens to pay for services on the Ecoverse dapp, developed by BalloonBox for Solana. As such, ECOV is the official utility token for Ecoverse. The major featured directories are

  • ecoswap
    a mechanism to swap SOL โ†’ ECOV unidirectionally
    completed - Milestone #1 deliverable โœ”๏ธ
  • ecov
    a minter of Ecoverse's fungible utility tokens, called ECOV
    completed - Milestone #1 deliverable โœ”๏ธ
  • dao
    a DAO to vote on future Ecoverse projects
    completed - Milestone #2 deliverable โœ”๏ธ

Interaction Diagram

Tree Diagram

The tree diagram of the major files in the current directory

.
โ”œโ”€โ”€ dao                             # hyperlink to realms.today DAO
โ”œโ”€โ”€ ecoswap                         # unidirectional 1:1 swap SOL -> ECOV
โ”‚   โ”œโ”€โ”€ _cicd                       # shell custom commands
โ”‚   โ”œโ”€โ”€ _dist                       # contains the outputs of the compiled Solana program 
โ”‚   โ”‚   โ””โ”€โ”€ program
โ”‚   โ””โ”€โ”€  accounts                   # a folder containing a few Solana file system wallets
โ”‚       โ”œโ”€โ”€ bathsheba.json          # keypairs for the file system wallet
โ”‚       โ”œโ”€โ”€ rahab.json
โ”‚       โ”œโ”€โ”€ ruth.json
โ”‚       โ””โ”€โ”€ tamar.json
โ”‚   โ”œโ”€โ”€ client                      # Typescript client that interacts with the Solana program
โ”‚   โ”‚   โ””โ”€โ”€ main.ts
โ”‚   โ”œโ”€โ”€ node_modules                # node.js dependencies
โ”‚   โ””โ”€โ”€ program                     # the actual Solana program
โ”‚       โ””โ”€โ”€ src
โ”‚           โ”œโ”€โ”€ lib.rs              # Rust codebase of the Solana program
โ”‚           โ”œโ”€โ”€ Cargo.lock          # auto-generated Rust dependencies file
โ”‚           โ””โ”€โ”€ Cargo.toml          # Rust manifest file
โ”‚       โ””โ”€โ”€ target                  # output of the compiled Solana program
โ”‚   โ”œโ”€โ”€ .env                        # environment variables
โ”‚   โ”œโ”€โ”€ .gitignore                  
โ”‚   โ”œโ”€โ”€ package-lock.json           # auto-generated Node project metadata
โ”‚   โ”œโ”€โ”€ package.json                # metadata of our Node project
|   โ””โ”€โ”€ README.md
โ”œโ”€โ”€ ecov                            # mint and transfer a utility token, called ECOV
โ”‚   โ”œโ”€โ”€ firstmint                   # first-time mint of ECOV
โ”‚       โ”œโ”€โ”€ node_modules
โ”‚       โ””โ”€โ”€  scripts
โ”‚           โ”œโ”€โ”€ firstmint.mjs       # mint ECOV (SPL-token)
โ”‚           โ””โ”€โ”€ transfer.mjs        # transfer ECOV
โ”‚       โ”œโ”€โ”€ .env
โ”‚       โ”œโ”€โ”€ package-lock.json
โ”‚       โ”œโ”€โ”€ package.json
โ”‚       โ””โ”€โ”€ README.md
โ”‚   โ””โ”€โ”€ remint                      # remint existing supply of ECOV
โ”‚       โ”œโ”€โ”€ node_modules
โ”‚       โ”œโ”€โ”€ .env
โ”‚       โ”œโ”€โ”€ .gitignore              
โ”‚       โ”œโ”€โ”€ package-lock.json
โ”‚       โ”œโ”€โ”€ package.json
โ”‚       โ”œโ”€โ”€ README.md
โ”‚       โ””โ”€โ”€ remint.mjs
โ”œโ”€โ”€ pix                             # images & diagrams
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ LICENCE
โ””โ”€โ”€ README.md

ecoverse-dao's People

Contributors

irene-bbox avatar

Watchers

 avatar

ecoverse-dao's Issues

Programs pruning

Description

Migrate, delete, or cleanup outdated custom-written Solana Programs which won't be invoked by the client side of the Ecoverse dapp. Some smart contract were developed as a one-off set up of Ecoverse or a s a learning practice.
Prune all Ecoverse Solana Programs that won't make their way to production and launch.

Papertrail

A copy of given Programs will remain available for lookup at this Git repo.

Create Associated Token Account (ATA)

Description

Send an SPL-token to a user that doesn't own an ATA account for that token yet.


Tasks

  • set up the spl-token transfer instruction in Rust
  • find an ATA for the receiver in TypeScript
    (the person funding the creation of the ATA is either the spl-token sender OR the ATA owner himself)
  • derive an ATA in the frontend using the web3.js Solana function get_associated_token_account()
  • pass the publicKey of the receiver's ATA account from the .ts frontend to the Rust contract
  • send an spl-token to the ATA account via the Rust smart contract
  • create an ATA programmatically in the Rust contract

Final Flow

Assume George is an Ecoverse user and the recipient of ECOV tokens

  • find George's ATA in TypeScript client - derive it from George's wallet and the ECOV token mint account
  • pass George's ATA to the Rust program's instructions via the TypeScript frontend client
  • read from the program instructions George's ATA and create/initialize it programmatically in Rust, so that it's active
    (use the Rust function spl_associated_token_account::instruction ::create_associated_token_account_idempotent() )

Ecoswap Contract - core logic

Description

Develop a contract to mint and exchange ECOV utility tokens for SOL.

Tasks

  • transfer SOL from user's wallet to a cash-in account
  • create idempotent user's ATA to receiver ECOV
  • transfer ECOV from vault's ATA to user's ATA

Transfer ECOV via ecoswap program

Description

Transfer an spl-token (ECOV) via a unified Rust program which orchestrates both the transfer of SOL & the transfer of ECOV concurrently.

Tasks

  • user the .ts client to feed the right PDA to the Rust program
  • hard code into the Rust program the correct seed (only the seed is enough - no bump)
  • re-create the PDA inside the Rust program from seed
  • ensure the program callers are authorized callers
  • multiply amount of SOL by 10E-9 to convert from SOL Lamports to ECOV units
  • send right amount of ECOV to whomever got deducted of SOL

transfer spl-tokens

Description

Build a standalone Rust program with corresponding TypeScript client to transfer spl-tokens from a sender's Associated Token Account to a receiver's Associated Token Account

Tasks

  • build Rust program to transfer tokens
  • build TypeScript client to invoke the program
  • perform token converstion (10E9) in the smart contract
  • transfer tokens from your Phantom wallet and back
  • perform transfer using system wallet โ†’ createKeypairfromFile("MY_PATH")
  • perform transfer using Phantom wallet โ†’ Keypair.fromSecretKey(bs58.decode("MY_SECRETKEY))

Dev Docs

Tasks

  • Docs for ECOSWAP contract

    • document the logic of the primary contract functions
    • doc all .env vars
  • Docs for ECOV client

    • document flow to mint and remint SPL-tokens

DAO Contract - core logic

Description

Create a ruleset for ecoverse users to cast votes and appoint the next project/initiative/dev priority to be financed via the ecoverse DAO. Eventually, we ended up using Solana's Realms.today to create a DAO. Realm is a UI for Solana DAO. Other options Solana offers for DAOs are squads.so, nation.io. All of these UIs run on the same Solana native program, called SPL-governance.

Flow

  • a Member drafts a proposal and publish it
  • users must deposit ECOV tokens into the DAO first for them to be able to cast a vote
  • you must be either a Community Member or a Council Member to cast a vote
  • the SPL-governance program already handles the logic to cast only one vote per wallet address
  • once the signing period expires, if quorum is met, then a transaction is executed (by someone)
  • a transaction can contain many instructions. The transaction must be executed for the DAO Proposal to be completed
  • anybody who deposited ECOV into the DAO can execute the DAO
  • after transaction execution the proposal is completed
  • a member can draft a new proposal anytime and the cycle repeats

Fix PDA derivation logic

Description

For the longest time, we were unable to derive a PDA. Fix the derivation logic to correctly derive a PDA.

Tasks

  • invoke these surrogate functions to derive a PDA:
    • in the Rust contract use Pubkey::create_program_address()?
    • in the TypeScript client use PublicKey.findProgramAddress()
  • hard code PDA seeds in both Rust and Typescript files (seeds must match up!)
  • the TypeScript client passes some program instruction, and the program instructions contain a ProgramId. That ProgramId is the address of the Rust smart contract (program) after being deployed to devnet. So, you must first deploy the Rust contract, secondly you must fetch the deployed ProgramId, and lastly you'll pass that ProgramId to the .ts client
  • the signer of the call to the TypeScript client, will be the signer of the blockchain transaction to derive the PDA, who will also be the funding account sponsoring the PDA derivation
  • whenever you derive a PDA, consol.log these 3 pieces of info, which you'll need to interact with the PDA later on:
    • PDA public key
    • PDA seeds
    • PDA bump

Mint ECOV via Solana web3.js

Description

Mint a batch of ECOV tokens (which are SPL-tokens) in JavaScript using Solana's web3.js

Solution

  • use thirdweb Solana JS SDK for token firstmint & initial transfer
  • mint, freeze, and update authorities are set authomatically by the thirdweb SDK. View them on Solscan.io
  • build a JS module to remint tokens after an initial mint, in case you're running out
  • pass the private key of the update authority to this newly developed JS module and remint a few tokens from an existing token_mint_account

'Find' a Solana Program Derive Address (PDA)

What we want to do

We want to transfer (using Program instructions) custom SPL token (namely ECOV) from BBox's liquidity pool account to an Ecoverse user's wallet?

How to

ECOV are a type of spl-token. Transferring programmatically spl-tokens requires the ECOV host wallet address to be owned by a program-derived address (PDA), derived from the program that minted ECOV in the first place. Hence, let's:

Tasks

  • generate/find a PDA for the ECOV program_id (you actually don't need to reference the program or origin to derive a PDA)
  • every PDA is identified by: an address, a seed, and a bump. Retrieve and save these 3 pieces of info
  • use a TypeScript client to interact with the Rust program and find a PDA

Learn Trdelnรญk

Description

Familiarize with the Trdelnรญk Rust crate

Tasks

  • run trial tests on a toy contract
  • doc commands to set up and execute testings

Lesson Learned

Trdelnรญk is a currently the only existing framework to perform unit tests on Rust smart contracts that got developed via Anchor. Sadly, examples are sparse, docs is limited, and tests still are NOT running.
I dumped Trdelnรญk, moved on, and decided to write either native Rust tests or TypeScript client tests instead.

DAO Contract - testing

Description

Build, run, pass Trdelnรญk Rust unit tests, validating the logic of the DAO contract

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.