Skip to content

formfunction-hq/formfunction-campaign-treasury-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

โš ๏ธ Work in progress This program was not completed, and has not been tested in production.


Formfunction Campaign Treasury Manager

Overview ย ย โ€ขย ย  Repo Structure ย ย โ€ขย ย  Initial Environment Setup ย ย โ€ขย ย  Getting Started ย ย โ€ขย ย  Testing ย ย โ€ขย ย  Releases ย ย โ€ขย ย  Tips

Overview

This repo contains the Formfunction campaign treasury manager program and SDK. The goals of this program are as follows:

  1. A campaignโ€™s treasury can be funded by a generative mint sale and/or auction house sales (e.g. auctions, instant sales, editions, offers). The treasury mint will be either SOL or USDC, but we will not have mixed treasuries.

    If a creator wants to keep a treasury in part SOL and part USDC, the recommendation will be to tune the initial payout to an appropriate level (assuming this is configurable) and then set the treasury to their preferred token. They can then swap the initial payout to the other token, once the initial payout occurs.

  2. If a campaign does not meet its goal within the specified time period, NFTs holders can claim a full refund (minus Solana transaction fees).

    Supporter must burn their NFT to claim a refund.

    1. This applies to all kinds of NFTs (1/1s, editions, gacha mints, etc.).
    2. There would be a limited time window during which burning is allowed.

    Refunds are denominated in the treasury mint.

    If an NFT is not burned, the buyer keeps the NFT, and the creator keeps the funds.

  3. If the campaign does meet its goalโ€ฆ

    1. Some initial payout percentage of the funds will be immediately given to the creator. This number should be configurable.
    2. The rest of the funds will be released in phases. We (Formfunction) can veto the phases, in which case users will get partially refunded. The number of phases and the payout percentage for each phase should be configurable. A future follow-up may allow campaign supporters to veto payout phases.

๐Ÿ’ก Note that in our product, we will probably start with hardcoded phases and not expose the configuration logic to creators. E.g. by default, 50% would be paid out immediately, then 25% after 3 months, and then 25% after 6 months.

Repo Structure

โ”œโ”€โ”€ artifacts                      # 3rd party program binaries (from solana program dump command)
โ”œโ”€โ”€ keys                           # Program keypairs for devnet and testnet deployments
โ”œโ”€โ”€ programs                       # Rust program source code
โ”‚   โ””โ”€โ”€ campaign-treasury-manager  # Program code
โ”œโ”€โ”€ scripts                        # Some helper bash scripts for the repo
โ”œโ”€โ”€ src                            # TypeScript source folder
โ”‚   โ”œโ”€โ”€ scripts                    # SDK specific scripts
โ”‚   โ”œโ”€โ”€ sdk                        # SDK source folder
โ”‚   โ”œโ”€โ”€ tests                      # Tests and test related code
โ”‚   โ””โ”€โ”€ index.ts                   # SDK library exports
โ”œโ”€โ”€ ...                            # Other project config files and folders
โ””โ”€โ”€ README.md

Initial Environment Setup

Complete the following to setup your environment:

  1. Install Node.js (and nvm if you want).
  2. Follow the Anchor setup instructions. After this you should have Rust, Solana, Yarn and Anchor installed on your system.

Getting Started

Once you have your environment setup you can run the following:

# Install dependencies
$ yarn

# Run setup steps
$ yarn setup

The following commands are also available:

# Run prettier checks
$ yarn prettier

# Run eslint checks
$ yarn eslint

# Run prettier and eslint with auto-fix flag
$ yarn lint

# Compile the program
$ yarn build-program

# Compile TypeScript code
$ yarn tsc

# Build the TS SDK
$ yarn build-sdk

# Build everything
$ yarn build

# Run all tests (see more on testing below)
$ yarn test

Testing

There are several different tests included in the repo. To explain them and how to run them it's easier to just look at the npm scripts which are available (note: keep this in sync with package.json):

# Run unit tests for TS SDK utils and helper functions.
$ yarn test-unit

# Run cargo tests
$ yarn test-cargo
$ yarn test-cargo-debug

# Run program tests using SDK client with a local validator.
$ yarn test-program
$ yarn test-program-debug

# Run all the tests in one go.
$ yarn test

Releases

Releases are based on git tags. There is a GitHub Action which is responsible for running releases.

The Solana program and TS SDK are versioned separately.

Crate

To publish a new version of this crate, follow the steps here.

Solana Program

For the Solana program we build a binary using Anchor. To publish a new binary:

  1. Increment the version in the program Cargo.toml file.
  2. Push a commit to the main branch in GitHub.

Note that if the Anchor version is upgraded you should update the anchor version in the GitHub action as well.

Devnet Deployment

Run the following to deploy or upgrade the program on devnet or testnet:

# Set your CLI to the appropriate cluster.
$ solana config set -u devnet|testnet

# Get the deployer account address.
$ solana-keygen pubkey keys/devnet/deployer-keypair.json

# Ensure you have enough SOL. Repeat the following until you have ~10 SOL or more.
$ solana airdrop 1 G1K5YZmhg1LqaYUC9VXWK7YLCdwqJcVPLpgBt5tmUWVf

# Test, build and deploy the program. Pass argument for network.
$ yarn deploy-program devnet|testnet

To deploy the program from scratch to a new program address, do the following:

  • Update the DEPLOY_PROGRAM_ID in deploy-program.sh.
  • Add the new program address in Anchor.toml and all of the Anchor configs in scripts/anchor-configs.
  • Add the new program and config keypairs for devnet/testnet in keys/.
  • Update the address in keys/README.
  • Run the above deploy steps.

Mainnet Deployment

The program is not yet deployed on mainnet.

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.

Tips

Feel free to run cargo clippy (Clippy) once in a while to see if there are any recommended improvements for the Rust code.

About

Campaign treasury manager Solana program and client SDK ๐Ÿงฎ

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published