npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@angganurf/flipper-sdk

v1.0.2

Published

Client SDK for the flipper program.

Downloads

1

Readme

Overview

This is the Solana program that powers hammyflip.com.

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 a BettorInfo account, which is a PDA of [bettor,treasury_mint] (so that arbitrary SPL tokens, and not just SOL, can be supported). If the BettorInfo account already exists, this instruction can be omitted.
    • Instruction 2: place_bet. This modifies the BettorInfo account with the bettor's bet, and transfers funds from the bettor to an escrow account.
    • Signers: bettor
  • Transaction 2
    • Instruction 1: flip. This modifies the BettorInfo account with the result of the coin flip. The results argument 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 on BettorInfo.results and BettorInfo.bets.
    • Signers: authority

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 new AuctionHouse account 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 where AuctionHouse.treasury_mint is the native mint. If you want to support SPL token coin flips, you can create more auction houses where AuctionHouse.treasury_mint is set to the SPL token mint. AuctionHouse.fee_basis_points controls the fees taken for each flip. For example, if AuctionHouse.fee_basis_points is 300, then betting 1 SOL will charge the bettor an additional .03 SOL. Since each currency has a unique AuctionHouse account, 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.bets is populated with their guess. A new BettorInfo account is created for each combination of bettor and treasury mint. For example, the first time a user does a SOL coin flip, a BettorInfo account will be created. If they do another SOL coin flip, the existing BettorInfo account will be used. The account's address is a PDA of bettor and treasury_mint.

Instructions

  • create_auction_house: This instruction creates a new AuctionHouse account.
  • create_bettor_info: This instruction creates a new BettorInfo account.
  • place_bet: This instruction modifies the BettorInfo account 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 the BettorInfo account.
  • payout: This instruction will either transfer the escrowed amount to the bettor or the treasury account depending on BettorInfo.results and BettorInfo.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.md

Development

Use the same version of Anchor CLI as .github/workflows/release-package.yml

I.e. run avm use 0.24.2

Prerequisites

Setup Steps

  1. Run yarn
  2. 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:

  1. Run yarn version and enter a new appropriate semver version for the npm package. That will create a new tag and commit.
  2. Run git push origin NEW_TAG.
  3. git push the 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.