Code Monkey home page Code Monkey logo

solana-lottery-program's Introduction

no-loss-lottery

Solana Riptide Hackathon

Basic App Walkthrough

# set config to localhost to test against a local validator
solana config set -u devnet 

# define wallet to use for transactions
# copy path from 'Keypair Path'
export ANCHOR_WALLET=$(solana config get | grep 'Keypair Path' | cut -d ' ' -f3)

# add phantom wallet pubkey used to connect to dapp through browser
export PHANTOM_WALLET="phantom-wallet-pubkey"

# initialize vrf
mkdir secrets
# Create and seed payer account
solana-keygen new --no-bip39-passphrase --outfile secrets/payer-keypair.json
solana airdrop 2 secrets/payer-keypair.json
solana airdrop 2 secrets/payer-keypair.json
solana airdrop 2 secrets/payer-keypair.json
solana airdrop 2 secrets/payer-keypair.json
spl-token wrap 4 secrets/payer-keypair.json

# initialize writes pubkeys to 'clientaccounts.env'
# other funcs read from 'clientaccounts.env'
# required for further commands
# will read $PHANTOM_WALLET to mint dummy tokens
ts-node ./sdk/scripts/initialize.ts init --queueKey F8ce7MsckeZAbAGmxjJNetxYXQa9mKr9nnrC3qKubyYy --userAddress $PHANTOM_WALLET

# run app in a new terminal
cd app/ && yarn run dev

# navigate to webapp with a browser at http://localhost:3000

# connect to webapp with Phantom and airdrop some SOL for transaction fees
solana airdrop 100 $PHANTOM_WALLET

# stake deposit tokens
ts-node ./sdk/scripts/stake.ts

# draw winning ticket numbers
ts-node ./sdk/scripts/request.ts request 8uZLtNzRM5dH3K4VN4wdw4QRs5EEuovGrSkzfmfyGYxZ --payer secrets/payer-keypair.json --rpcUrl https://api.devnet.solana.com --cluster devnet

# dispense prize to winner
ts-node ./sdk/scripts/dispense.ts

test

anchor test

lottery flow

  • users choose numbers, creates PDA numbers and vault pubkey as seed
  • users calls buy adds in their PDA, receives ticket
  • cranks call draw, draw selects 6 random numbers and sets these in vault manager config. draw locks buy until find is called
  • cranks call dispense, pass in PDA derived from winning numbers generated by draw
  • if winning numbers PDA passed to dispense is an already initialized account, send the prize to the owner
  • if winning numbers PDA passed to dispense is not initialized, unlock buy, zero out winning numbers, no error

invest flow

  • crank calls stake periodically to exchange tokens deposit tokens in deposit_vault for yield tokens in yield_vault via an AMM
  • user calls redeem, first look in deposit_vault to see if we have enough liquidity.
  • if enough liquidity, transfer deposit tokens back to user`
  • if not call swap_tokens to get enough liquidity and transfer deposit tokens back to user.
  • if dispense finds winner, calculate prize amount and call swap_tokens to swap all yield tokens for deposit tokens, calculate prize and send to winner.

Transform Steps

  1. Convert from PDA only to PDA + NFT
  2. Use Orca in Dev, SOL_ORCA
  3. Split lottery and integration programs

solana-lottery-program's People

Contributors

jackrieck avatar idelgado avatar

Watchers

 avatar  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.