This document details how to upgrade your Solana OFT program.
- 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
-
Ensure you have the updated source code for the OFT program.
- Pull the main branch from https://github.com/LayerZero-Labs/example-oft
- For context, this is the PR (merged and part of main) that fixes the refill issue: https://github.com/LayerZero-Labs/example-oft/pull/3
-
Navigate into the right folder, that has the Anchor.toml:
cd packages/solana/contracts
-
In
programs/oft/src/lib.rs
, replace the id indeclare_id
to match your current deployed OFT Program ID.
-
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)"
There are 2 different ways to deploy, depending on whether you are using a local keypair or using Squads.
-
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
-
When upgrading a Solana program that is currently owned by a Squads Vault, the process is broken down into the following steps:
- Writing the updated program bytecode to a buffer account.
- Creating the Upgrade program proposal on the Squads UI.
- Approving the proposal (must meet threshold before continuing)
- Executing the transaction
-
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 thewrite-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 anIncorrectAuthority
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
- 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.
-
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
- Run
-
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
- If successful you should see a message like
-