Update anchor to v0.27.0, stop using submodule (#582)

This commit is contained in:
Christian Kamm 2023-05-12 13:54:53 +02:00 committed by GitHub
parent 9429d3991d
commit 5a05e9cb2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 2009 additions and 1002 deletions

7
.gitmodules vendored
View File

@ -1,10 +1,3 @@
[submodule "anchor"]
path = 3rdparty/anchor
url = https://github.com/blockworks-foundation/anchor.git
branch = v0.25.0-mangov4
[submodule "switchboard-v2"]
path = 3rdparty/switchboard-v2
url = https://github.com/blockworks-foundation/sbv2-solana.git
[submodule "3rdparty/fixed"]
path = 3rdparty/fixed
url = https://gitlab.com/ckamm/fixed.git

1
3rdparty/anchor vendored

@ -1 +0,0 @@
Subproject commit b3707b1faaf6816cb3dd600074c81a39d373e952

@ -1 +0,0 @@
Subproject commit 97ed7b12de198f9dca2637af0ce8f5823cc3a0e3

912
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,6 @@ members = [
"bin/*",
"programs/mango-v4",
"lib/*",
"3rdparty/anchor/cli",
]
[profile.release]
@ -12,8 +11,3 @@ overflow-checks = true
[patch.crates-io]
# for gzip encoded responses
jsonrpc-core-client = { git = "https://github.com/ckamm/jsonrpc.git", branch = "ckamm/http-with-gzip" }
# these patch anchor to use solana 1.14.9 in order to fix dependency conflicts in switchboard-v2
# downstream applications may need to copy these patches to their own workspace
anchor-spl = { path = "./3rdparty/anchor/spl/" }
anchor-lang = { path = "./3rdparty/anchor/lang/" }
switchboard-v2 = { path = "./3rdparty/switchboard-v2/rust/switchboard-v2/" }

View File

@ -27,6 +27,7 @@ See DEVELOPING.md
- rust version 1.65.0
- solana-cli 1.14.9
- anchor-cli 0.27.0
- npm 8.1.2
- node v16.13.1
@ -43,16 +44,7 @@ Consider setting the git option `submodule.recurse=true`.
### Release
Here are steps followed while performing a program deployment to mainnet-beta
- review diff of last deployed tag to mainnet-beta, e.g. https://github.com/blockworks-foundation/mango-v4/compare/program-v0.4.0..dev, pay special attention to account layout changes, backward compatibility of newly introduced account fields, etc.
- deploy to mainnet-beta
- update changelog with deploy timestamp and tx
- add a git tag e.g. `program-v0.0.1`, should match the version the program has
- reset `main` to currently deployed tag
- notify other contributors for bringing in changes from new release by merging `main` into their branch, e.g. `ts-client` and `deploy-mm`
- notify other contributors for appropriately handling offchain services e.g. scrapers, market makers, etc.
- bump program version in `Cargo.toml` on dev branch for next release
For program deployment, see RELEASING.md.
Here are steps followed while performing a npm package release
note: the UI currently uses code directly from github, pointing to the ts-client branch

View File

@ -23,7 +23,7 @@
- Do a verifiable build
cargo run -p anchor-cli -- build --verifiable --solana-version 1.14.13 -- --features enable-gpl
anchor build --verifiable --solana-version 1.14.13 -- --features enable-gpl
(or wait for github to finish and create the release)
@ -45,13 +45,13 @@
- Create IDL buffer
cargo run -p anchor-cli -- idl write-buffer --provider.cluster $RPC_URL --provider.wallet $KEY --filepath target/idl/mango_v4_no_docs.json 4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg
anchor idl write-buffer --provider.cluster $RPC_URL --provider.wallet $KEY --filepath target/idl/mango_v4_no_docs.json 4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg
Save the returned address as $IDL_BUFFER
- Set IDL buffer authority
cargo run -p anchor-cli -- idl set-authority --provider.cluster $RPC_URL --provider.wallet $KEY --program-id 4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg --new-authority FP4PxqHTVzeG2c6eZd7974F9WvKUSdBeduUK3rjYyvBw $IDL_BUFFER
anchor idl set-authority --provider.cluster $RPC_URL --provider.wallet $KEY --program-id 4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg --new-authority FP4PxqHTVzeG2c6eZd7974F9WvKUSdBeduUK3rjYyvBw $IDL_BUFFER
- Make a gist for the proposal description, ideally based on previous upgrade proposals

View File

@ -8,9 +8,9 @@ name = "cli"
path = "src/main.rs"
[dependencies]
anchor-client = { path = "../../3rdparty/anchor/client" }
anchor-lang = { path = "../../3rdparty/anchor/lang" }
anchor-spl = { path = "../../3rdparty/anchor/spl" }
anchor-client = "0.27.0"
anchor-lang = "0.27.0"
anchor-spl = "0.27.0"
anyhow = "1.0"
clap = { version = "3.1.8", features = ["derive", "env"] }
dotenv = "0.15.0"

View File

@ -8,9 +8,9 @@ name = "keeper"
path = "src/main.rs"
[dependencies]
anchor-client = { path = "../../3rdparty/anchor/client" }
anchor-lang = { path = "../../3rdparty/anchor/lang" }
anchor-spl = { path = "../../3rdparty/anchor/spl" }
anchor-client = "0.27.0"
anchor-lang = "0.27.0"
anchor-spl = "0.27.0"
anyhow = "1.0"
clap = { version = "3.1.8", features = ["derive", "env"] }
dotenv = "0.15.0"

View File

@ -8,8 +8,8 @@ name = "liquidator"
path = "src/main.rs"
[dependencies]
anchor-lang = { path = "../../3rdparty/anchor/lang" }
anchor-client = { path = "../../3rdparty/anchor/client" }
anchor-lang = "0.27.0"
anchor-client = "0.27.0"
anyhow = "1.0"
arrayref = "0.3.6"
async-channel = "1.6"

View File

@ -8,8 +8,8 @@ name = "settler"
path = "src/main.rs"
[dependencies]
anchor-lang = { path = "../../3rdparty/anchor/lang" }
anchor-client = { path = "../../3rdparty/anchor/client" }
anchor-lang = "0.27.0"
anchor-client = "0.27.0"
anyhow = "1.0"
arrayref = "0.3.6"
async-channel = "1.6"

View File

@ -7,9 +7,9 @@ edition = "2021"
doctest = false
[dependencies]
anchor-client = { path = "../../3rdparty/anchor/client" }
anchor-lang = { path = "../../3rdparty/anchor/lang" }
anchor-spl = { path = "../../3rdparty/anchor/spl" }
anchor-client = "0.27.0"
anchor-lang = "0.27.0"
anchor-spl = "0.27.0"
anyhow = "1.0"
async-channel = "1.6"
async-once-cell = { version = "0.4.2", features = ["unpin"] }

View File

@ -355,7 +355,8 @@ impl MangoGroupContext {
}
fn from_serum_style_pubkey(d: [u64; 4]) -> Pubkey {
Pubkey::new(bytemuck::cast_slice(&d as &[_]))
let b: [u8; 32] = bytemuck::cast(d);
Pubkey::from(b)
}
async fn fetch_raw_account(rpc: &RpcClientAsync, address: Pubkey) -> Result<Account, ClientError> {

File diff suppressed because it is too large Load Diff

View File

@ -23,8 +23,8 @@ enable-gpl = []
[dependencies]
# todo: when to fix, when to use caret? need a regular chore to bump dependencies
# note: possibly need init-if-needed feature
anchor-lang = { path = "../../3rdparty/anchor/lang" }
anchor-spl = { path = "../../3rdparty/anchor/spl" }
anchor-lang = "0.27.0"
anchor-spl = "0.27.0"
arrayref = "0.3.6"
bincode = "1.3.3"
borsh = { version = "0.9.3", features = ["const-generics"] }

View File

@ -124,7 +124,8 @@ pub fn load_open_orders_bytes(bytes: &[u8]) -> Result<&serum_dex::state::OpenOrd
}
pub fn pubkey_from_u64_array(d: [u64; 4]) -> Pubkey {
Pubkey::new(bytemuck::cast_slice(&d as &[_]))
let b: [u8; 32] = bytemuck::cast(d);
Pubkey::from(b)
}
pub struct InitOpenOrders<'info> {

View File

@ -21,7 +21,7 @@ pub const MINIMUM_MAX_RATE: I80F48 = I80F48::from_bits(I80F48::ONE.to_bits() / 2
#[derive(Derivative)]
#[derivative(Debug)]
#[account(zero_copy(safe_bytemuck_derives))]
#[account(zero_copy)]
pub struct Bank {
// ABI: Clients rely on this being at offset 8
pub group: Pubkey,

View File

@ -26,7 +26,7 @@ pub const PERP_SETTLE_TOKEN_INDEX: TokenIndex = 0;
/// The token index used in AccountBuybackFeesWithMngo to exchange for MNGO
pub const FEE_BUYBACK_QUOTE_TOKEN_INDEX: TokenIndex = 0;
#[account(zero_copy(safe_bytemuck_derives))]
#[account(zero_copy)]
#[derive(Debug)]
pub struct Group {
// ABI: Clients rely on this being at offset 8

View File

@ -325,9 +325,7 @@ impl Owner for MangoAccountFixed {
}
impl Discriminator for MangoAccountFixed {
fn discriminator() -> [u8; 8] {
MangoAccount::discriminator()
}
const DISCRIMINATOR: [u8; 8] = MangoAccount::DISCRIMINATOR;
}
impl anchor_lang::ZeroCopy for MangoAccountFixed {}

View File

@ -12,7 +12,7 @@ use crate::state::*;
pub const FREE_ORDER_SLOT: PerpMarketIndex = PerpMarketIndex::MAX;
#[zero_copy]
#[derive(AnchorDeserialize, AnchorSerialize, Derivative, bytemuck::Pod, bytemuck::Zeroable)]
#[derive(AnchorDeserialize, AnchorSerialize, Derivative, bytemuck::Pod)]
#[derivative(Debug)]
pub struct TokenPosition {
// TODO: Why did we have deposits and borrows as two different values
@ -102,7 +102,7 @@ impl TokenPosition {
}
#[zero_copy]
#[derive(AnchorSerialize, AnchorDeserialize, Derivative, bytemuck::Pod, bytemuck::Zeroable)]
#[derive(AnchorSerialize, AnchorDeserialize, Derivative, bytemuck::Pod)]
#[derivative(Debug)]
pub struct Serum3Orders {
pub open_orders: Pubkey,
@ -158,7 +158,7 @@ impl Default for Serum3Orders {
}
#[zero_copy]
#[derive(AnchorSerialize, AnchorDeserialize, Derivative, bytemuck::Pod, bytemuck::Zeroable)]
#[derive(AnchorSerialize, AnchorDeserialize, Derivative, bytemuck::Pod)]
#[derivative(Debug)]
pub struct PerpPosition {
pub market_index: PerpMarketIndex,
@ -782,7 +782,7 @@ impl PerpPosition {
}
#[zero_copy]
#[derive(AnchorSerialize, AnchorDeserialize, Debug, bytemuck::Pod, bytemuck::Zeroable)]
#[derive(AnchorSerialize, AnchorDeserialize, Debug, bytemuck::Pod)]
pub struct PerpOpenOrder {
pub side_and_tree: u8, // SideAndOrderTree -- enums aren't POD
pub padding1: [u8; 1],

View File

@ -12,7 +12,7 @@ pub const MAX_BANKS: usize = 6;
// the accounts that are relevant for this mint. The idea is that clients
// can load this account to figure out which address maps to use when calling
// instructions that need banks/oracles for all active positions.
#[account(zero_copy(safe_bytemuck_derives))]
#[account(zero_copy)]
#[derive(Debug)]
pub struct MintInfo {
// ABI: Clients rely on this being at offset 8

View File

@ -57,7 +57,7 @@ pub mod switchboard_v2_mainnet_oracle {
}
#[zero_copy]
#[derive(AnchorDeserialize, AnchorSerialize, Debug, bytemuck::Pod, bytemuck::Zeroable)]
#[derive(AnchorDeserialize, AnchorSerialize, Debug, bytemuck::Pod)]
pub struct OracleConfig {
pub conf_filter: I80F48,
pub max_staleness_slots: i64,
@ -97,7 +97,7 @@ pub struct OracleState {
pub oracle_type: OracleType,
}
#[account(zero_copy(safe_bytemuck_derives))]
#[account(zero_copy)]
pub struct StubOracle {
// ABI: Clients rely on this being at offset 8
pub group: Pubkey,

View File

@ -27,7 +27,7 @@ pub struct BookSideOrderHandle {
pub order_tree: BookSideOrderTree,
}
#[account(zero_copy(safe_bytemuck_derives))]
#[account(zero_copy)]
pub struct BookSide {
pub roots: [OrderTreeRoot; 2],
pub reserved_roots: [OrderTreeRoot; 4],

View File

@ -21,7 +21,7 @@ pub trait QueueHeader: bytemuck::Pod {
fn decr_event_id(&mut self, n: u64);
}
#[account(zero_copy(safe_bytemuck_derives))]
#[account(zero_copy)]
pub struct EventQueue {
pub header: EventQueueHeader,
pub buf: [AnyEvent; MAX_NUM_EVENTS as usize],

View File

@ -15,7 +15,7 @@ use super::{orderbook, OracleConfig, OracleState, Orderbook, StablePriceModel, D
pub type PerpMarketIndex = u16;
#[account(zero_copy(safe_bytemuck_derives))]
#[account(zero_copy)]
#[derive(Debug)]
pub struct PerpMarket {
// ABI: Clients rely on this being at offset 8

View File

@ -6,7 +6,7 @@ use crate::state::*;
pub type Serum3MarketIndex = u16;
#[account(zero_copy(safe_bytemuck_derives))]
#[account(zero_copy)]
#[derive(Debug)]
pub struct Serum3Market {
// ABI: Clients rely on this being at offset 8

View File

@ -18,6 +18,6 @@ default = []
test-bpf = []
[dependencies]
anchor-lang = { path = "../../3rdparty/anchor/lang" }
anchor-spl = { path = "../../3rdparty/anchor/spl" }
anchor-lang = "0.27.0"
anchor-spl = "0.27.0"
solana-program = "~1.14.9"

View File

@ -6,7 +6,7 @@ WALLET_WITH_FUNDS=~/.config/solana/mango-mainnet-1.json
PROGRAM_ID=4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg
# build program,
cargo run -p anchor-cli -- build -- --features enable-gpl
anchor build -- --features enable-gpl
# patch types, which we want in rust, but anchor client doesn't support
./idl-fixup.sh
@ -21,5 +21,5 @@ solana --url https://mango.devnet.rpcpool.com program deploy --program-id $PROGR
-k $WALLET_WITH_FUNDS target/deploy/mango_v4.so --skip-fee-check
# publish idl
cargo run -p anchor-cli -- idl upgrade --provider.cluster https://mango.devnet.rpcpool.com --provider.wallet $WALLET_WITH_FUNDS \
anchor idl upgrade --provider.cluster https://mango.devnet.rpcpool.com --provider.wallet $WALLET_WITH_FUNDS \
--filepath target/idl/mango_v4_no_docs.json $PROGRAM_ID

View File

@ -3,6 +3,6 @@
# WALLET_WITH_FUNDS=~/.config/solana/mango-devnet.json
# PROGRAM_ID=4MangoMjqJ2firMokCjjGgoK8d4MXcrgL7XJaL3w6fVg
cargo run -p anchor-cli -- build -- --features enable-gpl
anchor build -- --features enable-gpl
./idl-fixup.sh
RUST_BACKTRACE=full cargo run -p anchor-cli -- test --skip-build
RUST_BACKTRACE=full anchor test --skip-build

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
set -e pipefail
# build program,
cargo run -p anchor-cli -- build -- --features enable-gpl
anchor build -- --features enable-gpl
# patch types, which we want in rust, but anchor client doesn't support
./idl-fixup.sh