Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions .github/workflows/anchor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 3 additions & 30 deletions basics/cross-program-invocation/anchor/idls/lever.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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": [
Expand Down
11 changes: 9 additions & 2 deletions finance/lending/anchor/programs/lending/tests/test_reserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<BorshAccount<Position>>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SetFundingRateAccountConstraints>,
context: &mut Context<SetFundingRateAccountConstraints>,
funding_rate_per_slot: u64,
) -> Result<()> {
let pool = &mut context.accounts.pool;
Expand All @@ -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<Account<'info, Pool>>,
pub pool: Box<BorshAccount<Pool>>,
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<SetFundingRateAccountConstraints>,
context: &mut Context<SetFundingRateAccountConstraints>,
funding_rate_per_slot: u64,
) -> Result<()> {
instructions::handle_set_funding_rate(context, funding_rate_per_slot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading