diff --git a/.github/workflows/anchor.yml b/.github/workflows/anchor.yml index 24c1ab449..5b209e88b 100644 --- a/.github/workflows/anchor.yml +++ b/.github/workflows/anchor.yml @@ -190,24 +190,28 @@ jobs: with: path: | ~/.cargo/bin/anchor - ~/.cargo/bin/avm - ~/.avm # Pinned to match the anchor-lang/anchor-spl crate version the programs depend on. - key: anchor-toolchain-${{ runner.os }}-2.0.0-rc.1 + key: anchor-cli-crates-io-${{ runner.os }}-2.0.0-rc.1 - name: Install Anchor 2.0.0-rc.1 run: | - export PATH="$HOME/.cargo/bin:$HOME/.avm/bin:$PATH" + export PATH="$HOME/.cargo/bin:$PATH" # `anchor --version` can emit more than one line; read the first line only so # a multi-line value never reaches downstream parsing. current="$(anchor --version 2>/dev/null | head -n1 | awk '{print $2}' || true)" if [ "$current" != "2.0.0-rc.1" ]; then - cargo install --git https://github.com/solana-foundation/anchor avm --force - # 2.0.0-rc.1 is a pre-release, so avm needs it named explicitly. - avm install 2.0.0-rc.1 - avm use 2.0.0-rc.1 + # Install the CLI from crates.io rather than through avm. avm has no + # prebuilt binary for this pre-release (a plain `avm install` 404s), and + # its --from-source path builds the CLI from the git tag, which is not + # the same code as the published anchor-lang 2.0.0-rc.1 the programs + # compile against: `anchor idl build` then emits a shim referencing + # `anchor_lang::IdlBuild`, which that crate does not have, and writes + # IDL JSON the parser rejects with "missing field `variants`". + # Installing the CLI from crates.io keeps it and the library on one + # published release. --locked builds it against its own published + # lockfile so the result does not drift with the registry. + cargo install anchor-cli --version 2.0.0-rc.1 --locked --force fi echo "$HOME/.cargo/bin" >> "$GITHUB_PATH" - echo "$HOME/.avm/bin" >> "$GITHUB_PATH" - name: Install Surfpool run: curl -sL https://run.surfpool.run/ | bash - name: Display Versions diff --git a/basics/cross-program-invocation/anchor/idls/lever.json b/basics/cross-program-invocation/anchor/idls/lever.json index a8ace89ce..3ec862d79 100644 --- a/basics/cross-program-invocation/anchor/idls/lever.json +++ b/basics/cross-program-invocation/anchor/idls/lever.json @@ -9,16 +9,7 @@ "instructions": [ { "name": "initialize", - "discriminator": [ - 175, - 175, - 109, - 31, - 13, - 152, - 155, - 237 - ], + "discriminator": [175, 175, 109, 31, 13, 152, 155, 237], "accounts": [ { "name": "power", @@ -39,16 +30,7 @@ }, { "name": "switch_power", - "discriminator": [ - 226, - 238, - 56, - 172, - 191, - 45, - 122, - 87 - ], + "discriminator": [226, 238, 56, 172, 191, 45, 122, 87], "accounts": [ { "name": "power", @@ -66,16 +48,7 @@ "accounts": [ { "name": "PowerStatus", - "discriminator": [ - 145, - 147, - 198, - 35, - 253, - 101, - 231, - 26 - ] + "discriminator": [145, 147, 198, 35, 253, 101, 231, 26] } ], "types": [ diff --git a/finance/lending/anchor/programs/lending/tests/test_reserve.rs b/finance/lending/anchor/programs/lending/tests/test_reserve.rs index 396be7c80..c1cd2af92 100644 --- a/finance/lending/anchor/programs/lending/tests/test_reserve.rs +++ b/finance/lending/anchor/programs/lending/tests/test_reserve.rs @@ -98,8 +98,15 @@ fn slots_per_year_scales_the_per_slot_rate() { env.supply(&borrower, &collateral, 1_000_000_000); let obligation = env.initialize_obligation(&borrower); env.post_collateral(&borrower, obligation, &collateral, 1_000_000_000); - env.try_borrow(&borrower, obligation, &[&collateral], &[], reserve, 500_000_000) - .unwrap(); + env.try_borrow( + &borrower, + obligation, + &[&collateral], + &[], + reserve, + 500_000_000, + ) + .unwrap(); } let elapsed = SLOTS_PER_YEAR / 100; diff --git a/finance/perpetual-futures/anchor/programs/perpetual-futures/src/instructions/open_position.rs b/finance/perpetual-futures/anchor/programs/perpetual-futures/src/instructions/open_position.rs index 4c6d543bf..0a1d96507 100644 --- a/finance/perpetual-futures/anchor/programs/perpetual-futures/src/instructions/open_position.rs +++ b/finance/perpetual-futures/anchor/programs/perpetual-futures/src/instructions/open_position.rs @@ -126,7 +126,10 @@ pub fn handle_open_position( } #[derive(Accounts)] -#[instruction(side: Side)] +// The leading underscore is for rustc: `#[derive(Accounts)]` expands +// `_side` into a path that never reads it, so the plain name warns as +// unused. The `seeds` expression below is the real use. +#[instruction(_side: Side)] pub struct OpenPositionAccountConstraints { #[account(mut)] pub owner: Signer, @@ -142,7 +145,7 @@ pub struct OpenPositionAccountConstraints { init, payer = owner, space = Position::DISCRIMINATOR.len() + Position::INIT_SPACE, - seeds = [POSITION_SEED, pool.address().as_ref(), owner.address().as_ref(), side.as_seed()], + seeds = [POSITION_SEED, pool.address().as_ref(), owner.address().as_ref(), _side.as_seed()], bump, )] pub position: Box>, diff --git a/finance/perpetual-futures/anchor/programs/perpetual-futures/src/instructions/set_funding_rate.rs b/finance/perpetual-futures/anchor/programs/perpetual-futures/src/instructions/set_funding_rate.rs index 03a98fb05..80a3fc1cf 100644 --- a/finance/perpetual-futures/anchor/programs/perpetual-futures/src/instructions/set_funding_rate.rs +++ b/finance/perpetual-futures/anchor/programs/perpetual-futures/src/instructions/set_funding_rate.rs @@ -14,7 +14,7 @@ use crate::state::Pool; /// charged at the rate that was in force for them rather than repriced by the /// new one. pub fn handle_set_funding_rate( - context: Context, + context: &mut Context, funding_rate_per_slot: u64, ) -> Result<()> { let pool = &mut context.accounts.pool; @@ -24,14 +24,14 @@ pub fn handle_set_funding_rate( } #[derive(Accounts)] -pub struct SetFundingRateAccountConstraints<'info> { - pub authority: Signer<'info>, +pub struct SetFundingRateAccountConstraints { + #[account(address = pool.authority)] + pub authority: Signer, #[account( mut, seeds = [POOL_SEED, pool.collateral_mint.as_ref(), pool.oracle_feed.as_ref()], bump = pool.bump, - has_one = authority, )] - pub pool: Box>, + pub pool: Box>, } diff --git a/finance/perpetual-futures/anchor/programs/perpetual-futures/src/lib.rs b/finance/perpetual-futures/anchor/programs/perpetual-futures/src/lib.rs index 8d263a055..5dbaad5da 100644 --- a/finance/perpetual-futures/anchor/programs/perpetual-futures/src/lib.rs +++ b/finance/perpetual-futures/anchor/programs/perpetual-futures/src/lib.rs @@ -86,7 +86,7 @@ pub mod perpetual_futures { /// Pool authority retunes the per-slot funding rate, accruing at the old /// rate first. pub fn set_funding_rate( - context: Context, + context: &mut Context, funding_rate_per_slot: u64, ) -> Result<()> { instructions::handle_set_funding_rate(context, funding_rate_per_slot) diff --git a/finance/perpetual-futures/anchor/programs/perpetual-futures/tests/test_perpetual_futures.rs b/finance/perpetual-futures/anchor/programs/perpetual-futures/tests/test_perpetual_futures.rs index 6d7bf79c3..4aeb986f0 100644 --- a/finance/perpetual-futures/anchor/programs/perpetual-futures/tests/test_perpetual_futures.rs +++ b/finance/perpetual-futures/anchor/programs/perpetual-futures/tests/test_perpetual_futures.rs @@ -957,7 +957,10 @@ fn test_set_funding_rate_settles_at_the_old_rate_first() { let flat = funding_for(false); let retuned = funding_for(true); - assert!(flat > 0, "the flat run must pay some funding to compare against"); + assert!( + flat > 0, + "the flat run must pay some funding to compare against" + ); // Half the elapsed slots at 1x and half at 2x is 1.5x the flat run. Had the // handler skipped its accrual, the new rate would have applied to every