@echohtp/flipper-sdk v0.0.17

Overview
This is the Solana program that powers hammyflip.com.
- Devnet address:
hamRNY1AjpqcjKqHHMi6ump7rSJafQSKKVKCFzC5oQ7 - Live website (uses devnet): hammyflip.com
- Frontend code for Hammyflip
- Backend code for Hammyflip
This Solana program implements a coin flipping app. Each coin flip is broken up into 2 transactions, and each transaction contains at most 2 instructions.
- Transaction 1
- Instruction 1 optional:
create_bettor_info. Creates aBettorInfoaccount, which is a PDA of[bettor,treasury_mint](so that arbitrary SPL tokens, and not just SOL, can be supported). If theBettorInfoaccount already exists, this instruction can be omitted. - Instruction 2:
place_bet. This modifies theBettorInfoaccount with the bettor's bet, and transfers funds from the bettor to an escrow account. - Signers:
bettor
- Instruction 1 optional:
- Transaction 2
- Instruction 1:
flip. This modifies theBettorInfoaccount with the result of the coin flip. Theresultsargument is calculated randomly off-chain (see here for more details). - Instruction 2:
payout. This will either transfer the escrowed amount to the bettor or the treasury account depending onBettorInfo.resultsandBettorInfo.bets. - Signers:
authority
- Instruction 1:
2 transactions are used instead of just 1 to prevent people from gaming the system. For example, if the same transaction was responsible for placing the bet, determining the result, and sending the payout, it would be possible for someone to simulate the transaction before sending it to determine if they would win or lose. While it's possible to mitigate this issue, separating the flow into 2 transactions is the most foolproof way to make things secure.
Accounts
AuctionHouse: This account stores settings that will be applied to all coinflips for a given currency, like the fee percentage and the treasury withdrawal destination. A newAuctionHouseaccount should be created for each supported currency. For example, if you only need to support SOL coin flips, you can create a single auction house whereAuctionHouse.treasury_mintis the native mint. If you want to support SPL token coin flips, you can create more auction houses whereAuctionHouse.treasury_mintis set to the SPL token mint.AuctionHouse.fee_basis_pointscontrols the fees taken for each flip. For example, ifAuctionHouse.fee_basis_pointsis300, then betting 1 SOL will charge the bettor an additional .03 SOL. Since each currency has a uniqueAuctionHouseaccount, each currency can charage a different fee.BettorInfo: This account stores information about a specific bettor—for example, when a bettor flips a coin,BettorInfo.betsis populated with their guess. A newBettorInfoaccount is created for each combination of bettor and treasury mint. For example, the first time a user does a SOL coin flip, aBettorInfoaccount will be created. If they do another SOL coin flip, the existingBettorInfoaccount will be used. The account's address is a PDA ofbettorandtreasury_mint.
Instructions
create_auction_house: This instruction creates a newAuctionHouseaccount.create_bettor_info: This instruction creates a newBettorInfoaccount.place_bet: This instruction modifies theBettorInfoaccount with the bettor's bet, and transfers funds from the bettor to an escrow account.flip: This instruction writes the results of a coin flip to theBettorInfoaccount.payout: This instruction will either transfer the escrowed amount to the bettor or the treasury account depending onBettorInfo.resultsandBettorInfo.bets.update_auction_house: This instruction updates the auction house account, e.g. with different fees.withdraw_from_treasury: This instruction withdraws from the program's treasury.
Repo Structure
This repo contains the Solana program source code and the source code for a TypeScript SDK, in addition to some client-side program tests written in TypeScript.
├── keys # Program keypairs
├── programs # Solana program source code
├── scripts # Some helper bash scripts
├── src # TypeScript source folder
│ ├── generated # Generated program IDL and type definitions
│ ├── sdk # Gumdrop program TypeScript SDK
│ └── tests # Program tests
├── ... # Other misc. project config files
└── README.mdDevelopment
Use the same version of Anchor CLI as .github/workflows/release-package.yml
I.e. run avm use 0.24.2
Prerequisites
- Install Rust, Solana, Anchor: https://book.anchor-lang.com/chapter_2/installation.html
- Install the Solana CLI
Setup Steps
- Run
yarn - Run
yarn test
If everything is set up correctly, all tests should pass and you should be ready to start developing!
Deployment
Solana Program
Run yarn deploy-program devnet.
TypeScript SDK
Follow the following steps to publish a new version of the TypeScript SDK:
- Run
yarn versionand enter a new appropriate semver version for the npm package. That will create a new tag and commit. - Run
git push origin NEW_TAG. git pushthe new commit as well.
This will push the new release tag to GitHub and trigger the release pipeline, after which clients can install the latest SDK with yarn add @hammyflip/flipper-sdk@latest.
3 years ago