Skip to content

Instantly share code, notes, and snippets.

@nazreen
Last active April 9, 2025 12:48
Show Gist options
  • Save nazreen/37b73c8fc191223271995d8f48820e60 to your computer and use it in GitHub Desktop.
Save nazreen/37b73c8fc191223271995d8f48820e60 to your computer and use it in GitHub Desktop.
How to upgrade your Solana OFT program (previous version of Solana OFT)

This document details how to upgrade your Solana OFT program.

Notes

  • program ID == program address. The terms can be used interchangeably.
  • you will need the Squads Vault address which is the current OFT Program's Update Authority

Instructions

Prepare the updated code

Build

  • switch to Anchor v0.29.0

    • cargo install --git https://github.com/coral-xyz/anchor --tag v0.29.0 anchor-cli --locked
  • switch to Solana 1.17

    sh -c "$(curl -sSfL https://release.solana.com/v1.17.31/install)"
  • Build (using Solana 1.17):

    • anchor build --program-name oft --verifiable
  • temporarily switch to Solana 1.18 for submitting transactions

    sh -c "$(curl -sSfL https://release.solana.com/v1.18.26/install)" 
    

Deployment (Upgrading)

There are 2 different ways to deploy, depending on whether you are using a local keypair or using Squads.

Deployment using a local keypair

  • Deploy the upgraded program

    • solana program deploy --program-id <PROGRAM_ADDRESS> ./target/verifiable/oft.so

    • (if you are not using the default keypair at ~/.config/solana/id.json, then specify the --keypair flag <PATH_TO_KEYPAIR>)

  • If the deployment is not successful on the first try and you are presented with the option to recover the buffer account, do so.

    • Copy the 12-word recovery phrase

    • Run solana-keygen recover -o buffer.json

    • Resume the deployment: solana program deploy --program-id <PROGRAM_ADDRESS> ./target/verifiable/oft.so --buffer buffer.json

Deployment using Squads

When upgrading a Solana program that is currently owned by a Squads Vault, the process is broken down into the following steps:

  1. Writing the updated program bytecode to a buffer account.
  2. Creating the Upgrade program proposal on the Squads UI.
  3. Approving the proposal (must meet threshold before continuing)
  4. Executing the transaction

1. Writing the updated program bytecode to a buffer account.

  • Write to the buffer account. This step can be done by any funded keypair.

     solana program write-buffer target/verifiable/oft.so  
    • copy the buffer address printed by the above command.
  • If the operation is not successful on the first try and you are presented with the option to recover the buffer account, do so.

  • Copy the 12-word recovery phrase

  • Run solana-keygen recover -o buffer.json

  • Resume the deployment: solana program write-buffer ./target/verifiable/oft.so --buffer buffer.json

  • update the buffer account authority

     solana program set-buffer-authority <BUFFER_ADDRESS> --new-buffer-authority <SQUADS_VAULT_ADDRESS>
    • <BUFFER_ADDRESS> should be the buffer address printed by the write-buffer command
    • <SQUAD_VAULT_ADDRESS> must be the current Squad Vault address that is the current Upgrade Authority of your OFT Program. If not, you will face an IncorrectAuthority error when attempting to execute the transaction.
  • For steps 2, 3 and 4 (all 3 of which should be done via the Squads UI), refer to the Squads documentation: https://docs.squads.so/main/navigating-your-squad/developers-assets/programs#upgrade-a-program

Troubleshooting

  • If you run into account data too small for instruction, this means you need to extend the program size further. See 'Managing Program Size' in the Appendix section.

Appendix

Managing Program Size

  • Ensure there’s enough storage at the program address

    • Find out the size of the updated program

      • wc -c < target/verifiable/oft.so (this outputs the number of bytes of the updated program)
  • Find out the size of the existing program

    • Run solana program show <PROGRAM_ADDRESS> (where <PROGRAM_ADDRESS> is the existing program id/address) and note the bytes value
  • Updated program bytes - current program bytes = <BYTES_TO_ADD>

    • If non-zero, run solana program extend <PROGRAM_ADDRESS> <BYTES_TO_ADD>

      • If successful you should see a message like Extended Program Id <PROGRAM_ADDRESS> by 784 bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment