Upgrade Solana to v2 and SPL to the latest (#3219)

This commit is contained in:
acheron 2024-09-17 19:02:09 +02:00 committed by GitHub
parent 8d52c1c244
commit 020a304658
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
31 changed files with 683 additions and 870 deletions

View File

@ -19,19 +19,7 @@ runs:
max_attempts: 10
retry_on: error
shell: bash
command: sh -c "$(curl -sSfL https://release.solana.com/v${{ env.SOLANA_CLI_VERSION }}/install)"
- uses: nick-fields/retry@v2
if: steps.cache-solana.outputs.cache-hit != 'true'
with:
retry_wait_seconds: 300
timeout_minutes: 2
max_attempts: 10
retry_on: error
shell: bash
command: |
curl -sSL -o /home/runner/.local/share/solana/install/active_release/bin/solang \
https://github.com/hyperledger/solang/releases/download/v${{ env.SOLANG_VERSION }}/solang-linux-x86-64
chmod 755 /home/runner/.local/share/solana/install/active_release/bin/solang
command: sh -c "$(curl -sSfL https://release.anza.xyz/v${{ env.SOLANA_CLI_VERSION }}/install)"
- run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
shell: bash
- run: solana-keygen new --no-bip39-passphrase

View File

@ -11,8 +11,7 @@ jobs:
uses: ./.github/workflows/reusable-tests.yaml
with:
cache: false
solana_cli_version: 1.18.17
solang_version: 0.3.2
solana_cli_version: 2.0.8
node_version: 20.16.0
cargo_profile: release
anchor_binary_name: anchor-binary-no-caching

View File

@ -9,9 +9,6 @@ on:
solana_cli_version:
required: true
type: string
solang_version:
required: true
type: string
node_version:
required: true
type: string
@ -24,7 +21,6 @@ on:
env:
CACHE: inputs.cache
SOLANA_CLI_VERSION: ${{ inputs.solana_cli_version }}
SOLANG_VERSION: ${{ inputs.solang_version }}
NODE_VERSION: ${{ inputs.node_version }}
CARGO_PROFILE: ${{ inputs.cargo_profile }}
ANCHOR_BINARY_NAME: ${{ inputs.anchor_binary_name }}
@ -396,7 +392,7 @@ jobs:
# - cmd: cd tests/lockup && anchor test --skip-lint
# path: tests/lockup
# TODO: Re-enable after making it work with Solana v2
# - cmd: cd tests/swap/deps/openbook-dex/dex && solana-install init 1.14.18 && cargo build-bpf -- --locked && cd ../../../ && solana-install init $SOLANA_CLI_VERSION && anchor test --skip-lint
# - cmd: cd tests/swap && anchor test --skip-lint
# path: tests/swap
- cmd: cd tests/escrow && anchor test --skip-lint && npx tsc --noEmit
path: tests/escrow

View File

@ -14,8 +14,7 @@ jobs:
uses: ./.github/workflows/reusable-tests.yaml
with:
cache: true
solana_cli_version: 1.18.17
solang_version: 0.3.2
solana_cli_version: 2.0.8
node_version: 20.16.0
cargo_profile: debug
anchor_binary_name: anchor-binary

3
.gitmodules vendored
View File

@ -1,6 +1,3 @@
[submodule "examples/swap/deps/openbook-dex"]
path = tests/swap/deps/openbook-dex
url = https://github.com/openbook-dex/program
[submodule "examples/cfo/deps/openbook-dex"]
path = tests/cfo/deps/openbook-dex
url = https://github.com/openbook-dex/program

View File

@ -95,6 +95,7 @@ The minor version will be incremented upon a breaking change and the patch versi
- cli: Accept integers for `warp_slot` ([#3235](https://github.com/coral-xyz/anchor/pull/3235)).
- lang: Remove `EventIndex` ([#3244](https://github.com/coral-xyz/anchor/pull/3244)).
- spl: Remove `dex` feature ([#3257](https://github.com/coral-xyz/anchor/pull/3257)).
- client, lang, spl: Upgrade Solana to v2 and SPL to the latest ([#3219](https://github.com/coral-xyz/anchor/pull/3219)).
## [0.30.1] - 2024-06-20

1360
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -36,11 +36,11 @@ semver = "1.0.4"
serde = { version = "1.0.122", features = ["derive"] }
serde_json = "1.0"
shellexpand = "2.1.0"
solana-client = "1.17.3"
solana-cli-config = "1.17.3"
solana-faucet = "1.17.3"
solana-program = "1.17.3"
solana-sdk = "1.17.3"
solana-client = "2"
solana-cli-config = "2"
solana-faucet = "2"
solana-program = "2"
solana-sdk = "2"
# Pin solang-parser because it may break in a backwards incompatible way in minor versions
solang-parser = "=0.3.3"
syn = { version = "1.0.60", features = ["full", "extra-traits"] }

View File

@ -21,9 +21,9 @@ anyhow = "1"
futures = "0.3"
regex = "1"
serde = { version = "1", features = ["derive"] }
solana-account-decoder = "1.17.3"
solana-client = "1.17.3"
solana-sdk = "1.17.3"
solana-account-decoder = "2"
solana-client = "2"
solana-sdk = "2"
thiserror = "1"
tokio = { version = "1", features = ["rt", "sync"] }
url = "2"

View File

@ -19,5 +19,5 @@ events = { path = "../../tests/events/programs/events", features = ["no-entrypoi
anyhow = "1.0.32"
clap = { version = "4.2.4", features = ["derive"] }
shellexpand = "2.1.0"
solana-sdk = "1.17.3"
solana-sdk = "2"
tokio = { version = "1", features = ["full"] }

View File

@ -6,7 +6,7 @@ ANCHOR_CLI=v0.30.1
#
# Solana toolchain.
#
SOLANA_CLI=v1.18.17
SOLANA_CLI=v2.0.8
#
# Build version should match the Anchor cli version.
#

View File

@ -38,7 +38,7 @@ RUN . $NVM_DIR/nvm.sh && \
npm install -g yarn
# Install Solana tools.
RUN sh -c "$(curl -sSfL https://release.solana.com/${SOLANA_CLI}/install)"
RUN sh -c "$(curl -sSfL https://release.anza.xyz/${SOLANA_CLI}/install)"
# Install anchor.
RUN cargo install --git https://github.com/coral-xyz/anchor --tag ${ANCHOR_CLI} anchor-cli --locked

View File

@ -56,5 +56,5 @@ base64 = "0.21"
bincode = "1"
borsh = "0.10.3"
bytemuck = "1"
solana-program = "1.17.3"
solana-program = "2"
thiserror = "1"

View File

@ -1,8 +1,8 @@
#!/bin/bash
active_version=$(solana -V | awk '{print $2}')
if [ "$active_version" != "1.18.17" ]; then
solana-install init 1.18.17
if [ "$active_version" != "2.0.8" ]; then
agave-install init 2.0.8
fi
git submodule update --init --recursive --depth 1

View File

@ -27,11 +27,11 @@ token_2022_extensions = ["spl-token-2022", "spl-token-group-interface", "spl-tok
[dependencies]
anchor-lang = { path = "../lang", version = "0.30.1", features = ["derive"] }
borsh = { version = "0.10.3", optional = true }
mpl-token-metadata = { version = "4", optional = true }
spl-associated-token-account = { version = "3", features = ["no-entrypoint"], optional = true }
spl-memo = { version = "4", features = ["no-entrypoint"], optional = true }
spl-token = { version = "4", features = ["no-entrypoint"], optional = true }
spl-token-2022 = { version = "3", features = ["no-entrypoint"], optional = true }
spl-token-group-interface = { version = "0.2.3", optional = true }
spl-token-metadata-interface = { version = "0.3.3", optional = true }
spl-pod = { version = "0.2.2", optional = true }
mpl-token-metadata = { version = "5.0.0-beta.0", optional = true }
spl-associated-token-account = { version = "5", features = ["no-entrypoint"], optional = true }
spl-memo = { version = "5", features = ["no-entrypoint"], optional = true }
spl-token = { version = "6", features = ["no-entrypoint"], optional = true }
spl-token-2022 = { version = "5.0.1", features = ["no-entrypoint"], optional = true }
spl-token-group-interface = { version = "0.4.1", optional = true }
spl-token-metadata-interface = { version = "0.5", optional = true }
spl-pod = { version = "0.4", optional = true }

View File

@ -6,7 +6,7 @@ use anchor_lang::{context::CpiContext, Accounts};
pub fn token_group_initialize<'info>(
ctx: CpiContext<'_, '_, '_, 'info, TokenGroupInitialize<'info>>,
update_authority: Option<Pubkey>,
max_size: u32,
max_size: u64,
) -> Result<()> {
let ix = spl_token_group_interface::instruction::initialize_group(
ctx.accounts.program_id.key,

View File

@ -1,10 +1,8 @@
use anchor_lang::__private::bytemuck::Pod;
use anchor_lang::solana_program::program_pack::Pack;
use anchor_lang::solana_program::pubkey::Pubkey;
use spl_token_2022::extension::ExtensionType;
use spl_token_2022::{
extension::{BaseStateWithExtensions, Extension, StateWithExtensions},
solana_zk_token_sdk::instruction::Pod,
};
use spl_token_2022::extension::{BaseStateWithExtensions, Extension, StateWithExtensions};
use std::ops::Deref;
pub use crate::token_2022::*;

View File

@ -19,7 +19,5 @@ idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]
[dependencies]
anchor-lang = { path = "../../../../lang" }
anchor-spl = { path = "../../../../spl", features = ["metadata"] }
spl-token = { version = "3.2", features = ["no-entrypoint"] }
spl-associated-token-account = { version = "1.1.1", features = ["no-entrypoint"] }
thiserror = "1.0"
arrayref = "0.3.6"

View File

@ -8,17 +8,21 @@ use {
program::{invoke, invoke_signed},
system_instruction,
},
AnchorDeserialize, AnchorSerialize,
},
anchor_spl::{
associated_token::AssociatedToken,
associated_token::{spl_associated_token_account, AssociatedToken},
metadata::mpl_token_metadata,
token::{Mint, Token, TokenAccount},
token::{
spl_token::{
self,
instruction::{approve, revoke},
},
Mint, Token, TokenAccount,
},
},
spl_token::instruction::{approve, revoke},
};
anchor_lang::declare_id!("hausS13jsjafwWwGqZTUQRmWyvyxn9EQpqMwV1PBBmk");
declare_id!("hausS13jsjafwWwGqZTUQRmWyvyxn9EQpqMwV1PBBmk");
const PREFIX: &str = "auction_house";
const FEE_PAYER: &str = "fee_payer";

View File

@ -10,12 +10,16 @@ use {
},
},
anchor_spl::{
associated_token::spl_associated_token_account::{
create_associated_token_account, get_associated_token_address,
},
metadata::mpl_token_metadata,
token::{Mint, Token, TokenAccount},
token::{
spl_token::{self, instruction::initialize_account2, state::Account},
Mint, Token, TokenAccount,
},
},
arrayref::array_ref,
spl_associated_token_account::get_associated_token_address,
spl_token::{instruction::initialize_account2, state::Account},
std::{convert::TryInto, slice::Iter},
};
pub fn assert_is_ata(ata: &AccountInfo, wallet: &Pubkey, mint: &Pubkey) -> Result<Account> {
@ -46,11 +50,7 @@ pub fn make_ata<'a>(
}
invoke_signed(
&spl_associated_token_account::create_associated_token_account(
&fee_payer.key,
&wallet.key,
&mint.key,
),
&create_associated_token_account(&fee_payer.key, &wallet.key, &mint.key),
&[
ata,
wallet,

View File

@ -7,33 +7,27 @@ import { Errors } from "../target/types/errors";
const withLogTest = async (callback, expectedLogs) => {
let logTestOk = false;
const listener = anchor.getProvider().connection.onLogs(
"all",
(logs) => {
const index = logs.logs.findIndex(
(logLine) => logLine === expectedLogs[0]
);
if (index === -1) {
console.log("Expected: ");
console.log(expectedLogs);
console.log("Actual: ");
console.log(logs);
} else {
const actualLogs = logs.logs.slice(index, index + expectedLogs.length);
for (let i = 0; i < expectedLogs.length; i++) {
if (actualLogs[i] !== expectedLogs[i]) {
console.log("Expected: ");
console.log(expectedLogs);
console.log("Actual: ");
console.log(logs);
return;
}
const listener = anchor.getProvider().connection.onLogs("all", (logs) => {
const index = logs.logs.findIndex((logLine) => logLine === expectedLogs[0]);
if (index === -1) {
console.log("Expected: ");
console.log(expectedLogs);
console.log("Actual: ");
console.log(logs);
} else {
const actualLogs = logs.logs.slice(index, index + expectedLogs.length);
for (let i = 0; i < expectedLogs.length; i++) {
if (actualLogs[i] !== expectedLogs[i]) {
console.log("Expected: ");
console.log(expectedLogs);
console.log("Actual: ");
console.log(logs);
return;
}
logTestOk = true;
}
},
"recent"
);
logTestOk = true;
}
});
try {
await callback();
} catch (err) {

View File

@ -18,5 +18,4 @@ idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]
[dependencies]
anchor-lang = { path = "../../../../lang", features = ["init-if-needed"] }
anchor-spl = { path = "../../../../spl" }
spl-associated-token-account = { version = "1.1.1", features = ["no-entrypoint"] }
bytemuck = { version = "1.4.0", features = ["derive", "min_const_generics"] }

View File

@ -19,5 +19,4 @@ my-feature = []
[dependencies]
anchor-lang = { path = "../../../../lang", features = ["init-if-needed"] }
anchor-spl = { path = "../../../../spl" }
spl-associated-token-account = { version = "1.1.1", features = ["no-entrypoint"] }
bytemuck = { version = "1.4.0", features = ["derive", "min_const_generics"] }

View File

@ -18,7 +18,7 @@ idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]
[dependencies]
anchor-lang = { path = "../../../../../lang", features = ["init-if-needed"] }
anchor-spl = { path = "../../../../../spl" }
spl-tlv-account-resolution = "0.6.3"
spl-transfer-hook-interface = "0.6.3"
spl-type-length-value = "0.4.3"
spl-pod = "0.2.2"
spl-tlv-account-resolution = "0.8.0"
spl-transfer-hook-interface = "0.8.1"
spl-type-length-value = "0.6"
spl-pod = "0.4"

View File

@ -8,14 +8,14 @@ use anchor_spl::{
transfer_hook::TransferHook,
},
token_interface::{
spl_token_metadata_interface::state::TokenMetadata, token_metadata_initialize, Mint,
Token2022, TokenAccount, TokenMetadataInitialize,
get_mint_extension_data, spl_token_metadata_interface::state::TokenMetadata,
token_metadata_initialize, Mint, Token2022, TokenAccount, TokenMetadataInitialize,
},
};
use spl_pod::optional_keys::OptionalNonZeroPubkey;
use crate::{
get_meta_list_size, get_mint_extensible_extension_data, get_mint_extension_data,
get_meta_list_size, get_mint_extensible_extension_data,
update_account_lamports_to_minimum_balance, META_LIST_ACCOUNT_SEED,
};

View File

@ -13,7 +13,6 @@ use anchor_lang::{
};
use anchor_spl::token_interface::spl_token_2022::{
extension::{BaseStateWithExtensions, Extension, StateWithExtensions},
solana_zk_token_sdk::zk_token_proof_instruction::Pod,
state::Mint,
};
use spl_tlv_account_resolution::{account::ExtraAccountMeta, state::ExtraAccountMetaList};
@ -46,13 +45,6 @@ pub fn get_mint_extensible_extension_data<T: Extension + VariableLenPack>(
Ok(extension_data)
}
pub fn get_mint_extension_data<T: Extension + Pod>(account: &mut AccountInfo) -> Result<T> {
let mint_data = account.data.borrow();
let mint_with_extension = StateWithExtensions::<Mint>::unpack(&mint_data)?;
let extension_data = *mint_with_extension.get_extension::<T>()?;
Ok(extension_data)
}
pub fn get_extra_meta_list_account_pda(mint: Pubkey) -> Pubkey {
Pubkey::find_program_address(&[META_LIST_ACCOUNT_SEED, mint.as_ref()], &crate::id()).0
}

View File

@ -18,6 +18,6 @@ idl-build = ["anchor-lang/idl-build", "anchor-spl/idl-build"]
[dependencies]
anchor-lang = { path = "../../../../../lang", features = ["interface-instructions"] }
anchor-spl = { path = "../../../../../spl" }
spl-discriminator = "0.2.5"
spl-tlv-account-resolution = "0.6.5"
spl-transfer-hook-interface = "0.6.5"
spl-discriminator = "0.3"
spl-tlv-account-resolution = "0.8"
spl-transfer-hook-interface = "0.8.1"

View File

@ -7,7 +7,7 @@ swap = "Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
[[test.genesis]]
address = "srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX"
program = "./deps/openbook-dex/dex/target/deploy/serum_dex.so"
program = "prebuilt-programs/openbook_dex.so"
[scripts]
test = "yarn run mocha -t 1000000 tests/"

@ -1 +0,0 @@
Subproject commit 5420646709df6edaaea90162d4f7476328077293

Binary file not shown.

View File

@ -22,4 +22,4 @@ bytemuck = {version = "1.4.0", features = ["derive", "min_const_generics"]}
[dev-dependencies]
anchor-client = { path = "../../../../client", features = ["debug", "async"] }
solana-program-test = "1.17.3"
solana-program-test = "2"