Skip to content

Commit

Permalink
Add deploy guide (#264)
Browse files Browse the repository at this point in the history
* Add deploy guide, fix CI pipeline
  • Loading branch information
jgur-psyops authored Dec 19, 2024
1 parent f5cfba8 commit f8ca780
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-common/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ runs:
components: rustfmt, clippy
default: true

- run: cargo install cargo-nextest --locked
- run: cargo install cargo-nextest --version "0.9.81" --locked
shell: bash

- run: cargo nextest --version
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-program.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

env:
RUST_TOOLCHAIN: 1.75.0
SOLANA_CLI_VERSION: 1.18.15
SOLANA_CLI_VERSION: 1.18.17
ANCHOR_CLI_VERSION: 0.30.1
ANCHOR_SHA: e6d7dafe12da661a36ad1b4f3b5970e8986e5321
CARGO_TERM_COLOR: always
Expand Down
49 changes: 49 additions & 0 deletions DEPLOY_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
## MAINNET VERIFIED DEPLOY GUIDE

Marginfi program authority is managed by squads (https://v3.squads.so/dashboard/M05MQ1FNRDdmUTdCQjc2aTY0aGpMRUNYTEFFNHpmeFJ2UTdlYVREVEo2elo=) and uses verified builds.


First you will need:
* Solana tools 1.18.20 or later (`solana-install init 1.18.20`)
* solana-verify (`cargo install solana-verify`)
* Docker (https://docs.docker.com/engine/install/ubuntu/)
* A wallet with at least 10 SOL (this guide will assume your wallet is at `~/keys/mainnet-deploy.json`). Verify the pubkey of your wallet with `solana-keygen pubkey ~/keys/mainnet-deploy.json` and verify you have at least 10 SOL with `solana balance -k ~/keys/mainnet-deploy.json`
* An RPC provider connected to mainnet (`solana config set --url https://api.mainnet-beta.solana.com`). The solana public api is usually fine.


Steps:
* Make sure you are on the main branch and you have pulled latest.
* Run `./scripts/build-program-verifiable.sh marginfi mainnet`. Other people signing on the multisig should also run this and validate that the hash matches.
* Deploy the buffer with `./scripts/deploy-buffer.sh marginfi <YOUR_RPC_ENDPOINT> ~/keys/mainnet-deploy.json`
* Go to squads, developers, programs, pick marginfi. The buffer address is the output of the previous command. The buffer refund is the public key of the wallet you have used so far (`solana-keygen pubkey ~/keys/mainnet-deploy.json` if you don't know it). Click next.
* Go back to your cli and paste the command Squads gave you in step 2. If this key is not the one used in your solana CLI, make sure it pass it with -k, e.g.:
```
solana program set-buffer-authority <BUFFER> --new-buffer-authority <MULTISIG> -k ~/keys/mainnet-deploy.json
```
* Back up the current working program somewhere with `solana -um program dump MFv2hWf31Z9kbCa1snEPYctwafyhdvnV7FZnsebVacA mfi_backup.so`
* Click the pending upgrade to start a vote.
* Execute after the vote passes.

## DEPLOYING STAKED COLLATERAL TO STAGING

The Staked Collateral feature uses spl-single-pool, developed by the Solana Foundation (https://github.com/solana-labs/solana-program-library/tree/master/single-pool). This guide will show you how to deploy that program.

First you will need:
* Agave tools 2.1.0 or later (`sh -c "$(curl -sSfL https://release.anza.xyz/stable/install)"`) and possibly `agave-install init 2.1.0`
* A wallet with at least 2 SOL (this guide will assume your wallet is at `~/keys/staging-deploy.json`). Verify the pubkey of your wallet with `solana-keygen pubkey ~/keys/staging-deploy.json` and verify you have at least 2 SOL with `solana balance -k ~/keys/staging-deploy.json`
* An RPC provider connected to mainnet (`solana config set --url https://api.mainnet-beta.solana.com`). The solana public api is usually fine.

Steps:
* Clone https://github.com/solana-labs/solana-program-library/tree/master/single-pool and pull latest
* Navigate to programs/single-pool and run `cargo build-sbf`
* Navigate back up to root, then navigate to target. Verify that `solana-keygen pubkey deploy/spl_single_pool-keypair.json` matches the program's declared id. If you want to generate a new id, delete this file and build again to generate a new program keypair. Don't forget to update the declare_id in lib.rs as needed.
* Deploy the program with:
```
solana program deploy \
deploy/spl_single_pool.so \
--program-id deploy/spl_single_pool-keypair.json \
--keypair ~/keys/staging-deploy.json \
--fee-payer ~/keys/staging-deploy.json \
--url <your_rpc_url (optional, omit this line to use api.mainnet-beta)>
```
57 changes: 57 additions & 0 deletions DEPLOY_GUIDE_STAGING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
## DEPLOYING TO STAGING

Staging is different from mainnet only in that it uses a different key. Ensure that the key in lib.rs matches the intended staging key (typically stag8sTKds2h4KzjUw3zKTsxbqvT4XKHdaR9X9E6Rct)

### Requirements

* You have access to the staging program authority wallet (we will assume it is at `~/keys/staging-deploy.json` from here on)
* Anchor 0.30.1
* Solana 1.18.17

## Steps

### With Anchor

* Note: this rarely works, the program is probably too chonky.
* Build with `anchor build -p marginfi -- --no-default-features --features staging`
* If this is your first time deploying (to a new key), with `anchor build -p marginfi -- --no-default-features --features staging ignore-fee-deploy`
* Ensure anchor.toml is configured like this:
```
[provider]
cluster = "https://api.mainnet-beta.solana.com"
wallet = "~/keys/staging-deploy.json"
```
Adjust the cluster as needed if using a custom rpc.
* Deploy with `anchor upgrade target/deploy/marginfi.so --program-id stag8sTKds2h4KzjUw3zKTsxbqvT4XKHdaR9X9E6Rct`. Use deploy instead upgrade if this is your first deployment, and use the keypair.json in the target folder instead of the program's id for program-id.

### If Anchor is busted (for any number of reasons)

* Run:
```
solana program deploy --use-rpc \
target/deploy/marginfi.so \
--program-id stag8sTKds2h4KzjUw3zKTsxbqvT4XKHdaR9X9E6Rct \
--keypair ~/keys/staging-deploy.json \
--fee-payer ~/keys/staging-deploy.json \
--url <your rpc>
```
If this is your first time deploying, use the keypair.json in the target folder instead of the program's id for program-id
* Failed? That happens often. `solana program close --buffers -k ~/keys/staging-deploy.json` to recover the buffer funds and try again (Note: this costs you .02 SOL to try again)
* Still failing? That happens. Try to recover the buffer instead of closing it: `solana-keygen recover -o recovered-buffer.json` (then enter the buffer seed phrase). Then:
```
solana program deploy --use-rpc \
target/deploy/marginfi.so \
--program-id stag8sTKds2h4KzjUw3zKTsxbqvT4XKHdaR9X9E6Rct \
--keypair ~/keys/staging-deploy.json \
--fee-payer ~/keys/staging-deploy.json \
--url <your rpc (https://api.mainnet-beta.solana.com is usually fine)> \
--buffer recovered-buffer.json
```
* Program buffer full? Use:
```
solana program extend \
--url <RPC_URL> \
--keypair ~/keys/staging-deploy.json \
stag8sTKds2h4KzjUw3zKTsxbqvT4XKHdaR9X9E6Rct 10000
```
* If you changed your wallet config, make sure to remove the staging wallet from your Solana config to avoid sausage fingers errors in the future: `solana config set --keypair ~/.config/solana/id.json`
2 changes: 1 addition & 1 deletion scripts/deploy-buffer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ if [ -z "$program_lib_name" ] || [ -z "$rpc_url" ] || [ -z "$keypair" ]; then
exit 1
fi

cmd="solana --url $rpc_url program write-buffer "$ROOT/target/deploy/$program_lib_name.so" -k $keypair"
cmd="solana --url $rpc_url program write-buffer --use-rpc "$ROOT/target/deploy/$program_lib_name.so" -k $keypair"
echo "Running: $cmd"
eval "$cmd"

0 comments on commit f8ca780

Please sign in to comment.