From de86b69e1a0c2aef3a7d1c907ddf9cb2c0fe8769 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 6 Jul 2022 09:56:14 +0200 Subject: [PATCH] Client/program interface changes - rearrange structs to have gPA data in front and add comments about the offsets being relevant - add insuranceMint to group creation in client - drop quoteTokenIndex storage on PerpMarket - fixes to editAccount in example1-user and client --- client/src/client.rs | 18 +- .../src/instructions/perp_create_market.rs | 4 +- .../instructions/serum3_register_market.rs | 1 + .../src/instructions/token_register.rs | 1 + programs/mango-v4/src/lib.rs | 2 - programs/mango-v4/src/state/bank.rs | 4 +- programs/mango-v4/src/state/group.rs | 13 +- programs/mango-v4/src/state/health.rs | 2 - programs/mango-v4/src/state/mango_account.rs | 7 +- programs/mango-v4/src/state/mint_info.rs | 13 +- programs/mango-v4/src/state/oracle.rs | 2 + programs/mango-v4/src/state/perp_market.rs | 24 +- programs/mango-v4/src/state/serum3_market.rs | 17 +- .../tests/program_test/mango_client.rs | 2 - .../mango-v4/tests/test_health_compute.rs | 1 - programs/mango-v4/tests/test_perp.rs | 1 - release-to-devnet.sh | 2 +- release-to-mainnet.sh | 4 +- ts/client/src/client.ts | 37 +-- ts/client/src/mango_v4.ts | 286 +++++++++++------- ts/client/src/scripts/example1-admin.ts | 18 +- ts/client/src/scripts/example1-user.ts | 4 +- update-local-idl.sh | 2 +- 23 files changed, 274 insertions(+), 191 deletions(-) diff --git a/client/src/client.rs b/client/src/client.rs index 349dbce04..7f92cef49 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -78,12 +78,12 @@ impl MangoClient { // Mango Account let mut mango_account_tuples = program.accounts::(vec![ RpcFilterType::Memcmp(Memcmp { - offset: 40, + offset: 8, bytes: MemcmpEncodedBytes::Base58(group.to_string()), encoding: None, }), RpcFilterType::Memcmp(Memcmp { - offset: 72, + offset: 40, bytes: MemcmpEncodedBytes::Base58(payer.pubkey().to_string()), encoding: None, }), @@ -135,12 +135,12 @@ impl MangoClient { } let mango_account_tuples = program.accounts::(vec![ RpcFilterType::Memcmp(Memcmp { - offset: 40, + offset: 8, bytes: MemcmpEncodedBytes::Base58(group.to_string()), encoding: None, }), RpcFilterType::Memcmp(Memcmp { - offset: 72, + offset: 40, bytes: MemcmpEncodedBytes::Base58(payer.pubkey().to_string()), encoding: None, }), @@ -155,7 +155,7 @@ impl MangoClient { let mut banks_cache = HashMap::new(); let mut banks_cache_by_token_index = HashMap::new(); let bank_tuples = program.accounts::(vec![RpcFilterType::Memcmp(Memcmp { - offset: 24, + offset: 8, bytes: MemcmpEncodedBytes::Base58(group.to_string()), encoding: None, })])?; @@ -197,7 +197,7 @@ impl MangoClient { let mut serum3_external_markets_cache = HashMap::new(); let serum3_market_tuples = program.accounts::(vec![RpcFilterType::Memcmp(Memcmp { - offset: 24, + offset: 8, bytes: MemcmpEncodedBytes::Base58(group.to_string()), encoding: None, })])?; @@ -221,7 +221,7 @@ impl MangoClient { let mut perp_markets_cache_by_perp_market_index = HashMap::new(); let perp_market_tuples = program.accounts::(vec![RpcFilterType::Memcmp(Memcmp { - offset: 24, + offset: 8, bytes: MemcmpEncodedBytes::Base58(group.to_string()), encoding: None, })])?; @@ -279,12 +279,12 @@ impl MangoClient { pub fn get_account(&self) -> Result<(Pubkey, MangoAccount), anchor_client::ClientError> { let mango_accounts = self.program().accounts::(vec![ RpcFilterType::Memcmp(Memcmp { - offset: 40, + offset: 8, bytes: MemcmpEncodedBytes::Base58(self.group().to_string()), encoding: None, }), RpcFilterType::Memcmp(Memcmp { - offset: 72, + offset: 40, bytes: MemcmpEncodedBytes::Base58(self.payer().to_string()), encoding: None, }), diff --git a/programs/mango-v4/src/instructions/perp_create_market.rs b/programs/mango-v4/src/instructions/perp_create_market.rs index 679dad2d3..8abc21dd2 100644 --- a/programs/mango-v4/src/instructions/perp_create_market.rs +++ b/programs/mango-v4/src/instructions/perp_create_market.rs @@ -50,7 +50,6 @@ pub fn perp_create_market( oracle_config: OracleConfig, base_token_index_opt: Option, base_token_decimals: u8, - quote_token_index: TokenIndex, quote_lot_size: i64, base_lot_size: i64, maint_asset_weight: f32, @@ -96,7 +95,8 @@ pub fn perp_create_market( base_token_decimals, perp_market_index, base_token_index: base_token_index_opt.ok_or(TokenIndex::MAX).unwrap(), - quote_token_index, + padding: Default::default(), + reserved: Default::default(), }; let mut bids = ctx.accounts.bids.load_init()?; diff --git a/programs/mango-v4/src/instructions/serum3_register_market.rs b/programs/mango-v4/src/instructions/serum3_register_market.rs index 11a9d9427..8523527f5 100644 --- a/programs/mango-v4/src/instructions/serum3_register_market.rs +++ b/programs/mango-v4/src/instructions/serum3_register_market.rs @@ -74,6 +74,7 @@ pub fn serum3_register_market( base_token_index: base_bank.token_index, quote_token_index: quote_bank.token_index, bump: *ctx.bumps.get("serum_market").ok_or(MangoError::SomeError)?, + padding: Default::default(), reserved: Default::default(), }; diff --git a/programs/mango-v4/src/instructions/token_register.rs b/programs/mango-v4/src/instructions/token_register.rs index 5c1c42a1f..c3cb13c74 100644 --- a/programs/mango-v4/src/instructions/token_register.rs +++ b/programs/mango-v4/src/instructions/token_register.rs @@ -170,6 +170,7 @@ pub fn token_register( token_index, address_lookup_table_bank_index: alt_previous_size as u8, address_lookup_table_oracle_index: alt_previous_size as u8 + 1, + padding: Default::default(), reserved: Default::default(), }; diff --git a/programs/mango-v4/src/lib.rs b/programs/mango-v4/src/lib.rs index fa706efcb..4a39d28bb 100644 --- a/programs/mango-v4/src/lib.rs +++ b/programs/mango-v4/src/lib.rs @@ -322,7 +322,6 @@ pub mod mango_v4 { oracle_config: OracleConfig, base_token_index_opt: Option, base_token_decimals: u8, - quote_token_index: TokenIndex, quote_lot_size: i64, base_lot_size: i64, maint_asset_weight: f32, @@ -343,7 +342,6 @@ pub mod mango_v4 { oracle_config, base_token_index_opt, base_token_decimals, - quote_token_index, quote_lot_size, base_lot_size, maint_asset_weight, diff --git a/programs/mango-v4/src/state/bank.rs b/programs/mango-v4/src/state/bank.rs index a7e40c1ab..cbcf61733 100644 --- a/programs/mango-v4/src/state/bank.rs +++ b/programs/mango-v4/src/state/bank.rs @@ -13,9 +13,11 @@ pub const YEAR: I80F48 = I80F48!(31536000); #[account(zero_copy)] pub struct Bank { + // ABI: Clients rely on this being at offset 8 + pub group: Pubkey, + pub name: [u8; 16], - pub group: Pubkey, pub mint: Pubkey, pub vault: Pubkey, pub oracle: Pubkey, diff --git a/programs/mango-v4/src/state/group.rs b/programs/mango-v4/src/state/group.rs index fdf46c648..bff800706 100644 --- a/programs/mango-v4/src/state/group.rs +++ b/programs/mango-v4/src/state/group.rs @@ -9,22 +9,25 @@ pub const QUOTE_TOKEN_INDEX: TokenIndex = 0; #[account(zero_copy)] #[derive(Debug)] pub struct Group { - // Relying on Anchor's discriminator be sufficient for our versioning needs? - // pub meta_data: MetaData, + // ABI: Clients rely on this being at offset 8 pub admin: Pubkey, + // ABI: Clients rely on this being at offset 40 + pub group_num: u32, + + pub padding: [u8; 4], + pub insurance_vault: Pubkey, pub insurance_mint: Pubkey, - pub group_num: u32, pub bump: u8, // Only support closing/deregistering groups, stub oracles, tokens, and markets // if testing == 1 pub testing: u8, - pub padding2: [u8; 2], + pub padding2: [u8; 6], pub reserved: [u8; 8], } -const_assert_eq!(size_of::(), 32 * 3 + 4 + 1 * 2 + 10); +const_assert_eq!(size_of::(), 32 * 3 + 4 + 4 + 1 * 2 + 6 + 8); const_assert_eq!(size_of::() % 8, 0); #[macro_export] diff --git a/programs/mango-v4/src/state/health.rs b/programs/mango-v4/src/state/health.rs index c154db383..9f0081f19 100644 --- a/programs/mango-v4/src/state/health.rs +++ b/programs/mango-v4/src/state/health.rs @@ -869,7 +869,6 @@ mod tests { perp1.data().group = group; perp1.data().perp_market_index = 9; perp1.data().base_token_index = 4; - perp1.data().quote_token_index = 1; perp1.data().init_asset_weight = I80F48::from_num(1.0 - 0.2f64); perp1.data().init_liab_weight = I80F48::from_num(1.0 + 0.2f64); perp1.data().maint_asset_weight = I80F48::from_num(1.0 - 0.1f64); @@ -1044,7 +1043,6 @@ mod tests { perp1.data().group = group; perp1.data().perp_market_index = 9; perp1.data().base_token_index = 4; - perp1.data().quote_token_index = 1; perp1.data().init_asset_weight = I80F48::from_num(1.0 - 0.2f64); perp1.data().init_liab_weight = I80F48::from_num(1.0 + 0.2f64); perp1.data().maint_asset_weight = I80F48::from_num(1.0 - 0.1f64); diff --git a/programs/mango-v4/src/state/mango_account.rs b/programs/mango-v4/src/state/mango_account.rs index 51ec072de..34ea6acdb 100644 --- a/programs/mango-v4/src/state/mango_account.rs +++ b/programs/mango-v4/src/state/mango_account.rs @@ -704,11 +704,14 @@ impl Default for MangoAccountPerpPositions { #[account(zero_copy)] pub struct MangoAccount { - pub name: [u8; 32], - + // ABI: Clients rely on this being at offset 8 pub group: Pubkey, + + // ABI: Clients rely on this being at offset 40 pub owner: Pubkey, + pub name: [u8; 32], + // Alternative authority/signer of transactions for a mango account pub delegate: Pubkey, diff --git a/programs/mango-v4/src/state/mint_info.rs b/programs/mango-v4/src/state/mint_info.rs index b1b4327ca..6c6022d30 100644 --- a/programs/mango-v4/src/state/mint_info.rs +++ b/programs/mango-v4/src/state/mint_info.rs @@ -15,25 +15,28 @@ pub const MAX_BANKS: usize = 6; #[account(zero_copy)] #[derive(Debug)] pub struct MintInfo { - // TODO: none of these pubkeys are needed, remove? + // ABI: Clients rely on this being at offset 8 pub group: Pubkey, + + // ABI: Clients rely on this being at offset 40 + pub token_index: TokenIndex, + + pub padding: [u8; 6], pub mint: Pubkey, pub banks: [Pubkey; MAX_BANKS], pub vaults: [Pubkey; MAX_BANKS], pub oracle: Pubkey, pub address_lookup_table: Pubkey, - pub token_index: TokenIndex, - // describe what address map relevant accounts are found on pub address_lookup_table_bank_index: u8, pub address_lookup_table_oracle_index: u8, - pub reserved: [u8; 4], + pub reserved: [u8; 6], } const_assert_eq!( size_of::(), - MAX_BANKS * 2 * 32 + 4 * 32 + 2 + 2 + 4 + MAX_BANKS * 2 * 32 + 4 * 32 + 2 + 6 + 2 + 6 ); const_assert_eq!(size_of::() % 8, 0); diff --git a/programs/mango-v4/src/state/oracle.rs b/programs/mango-v4/src/state/oracle.rs index b32816aca..94c30a045 100644 --- a/programs/mango-v4/src/state/oracle.rs +++ b/programs/mango-v4/src/state/oracle.rs @@ -71,7 +71,9 @@ pub enum OracleType { #[account(zero_copy)] pub struct StubOracle { + // ABI: Clients rely on this being at offset 8 pub group: Pubkey, + // ABI: Clients rely on this being at offset 40 pub mint: Pubkey, pub price: I80F48, pub last_updated: i64, diff --git a/programs/mango-v4/src/state/perp_market.rs b/programs/mango-v4/src/state/perp_market.rs index ff2762a02..9f067b6dd 100644 --- a/programs/mango-v4/src/state/perp_market.rs +++ b/programs/mango-v4/src/state/perp_market.rs @@ -16,10 +16,20 @@ pub type PerpMarketIndex = u16; #[account(zero_copy)] #[derive(Debug)] pub struct PerpMarket { - pub name: [u8; 16], - + // ABI: Clients rely on this being at offset 8 pub group: Pubkey, + // TODO: Remove! + // ABI: Clients rely on this being at offset 40 + pub base_token_index: TokenIndex, + + /// Lookup indices + pub perp_market_index: PerpMarketIndex, + + pub padding: [u8; 4], + + pub name: [u8; 16], + pub oracle: Pubkey, pub oracle_config: OracleConfig, @@ -76,18 +86,12 @@ pub struct PerpMarket { pub base_token_decimals: u8, - /// Lookup indices - pub perp_market_index: PerpMarketIndex, - - pub base_token_index: TokenIndex, - - /// Cannot be chosen freely, must be the health-reference token, same for all PerpMarkets - pub quote_token_index: TokenIndex, + pub reserved: [u8; 6], } const_assert_eq!( size_of::(), - 16 + 32 * 2 + 16 + 32 * 3 + 8 * 2 + 16 * 11 + 8 * 2 + 8 * 2 + 16 + 8 + 32 + 2 + 2 + 4 + 16 + 32 + 16 + 32 * 3 + 8 * 2 + 16 * 11 + 8 * 2 + 8 * 2 + 16 + 2 + 6 ); const_assert_eq!(size_of::() % 8, 0); diff --git a/programs/mango-v4/src/state/serum3_market.rs b/programs/mango-v4/src/state/serum3_market.rs index 7204f25a7..dd861f01d 100644 --- a/programs/mango-v4/src/state/serum3_market.rs +++ b/programs/mango-v4/src/state/serum3_market.rs @@ -9,19 +9,26 @@ pub type Serum3MarketIndex = u16; #[account(zero_copy)] #[derive(Debug)] pub struct Serum3Market { - pub name: [u8; 16], + // ABI: Clients rely on this being at offset 8 pub group: Pubkey, + // ABI: Clients rely on this being at offset 40 + pub base_token_index: TokenIndex, + // ABI: Clients rely on this being at offset 42 + pub quote_token_index: TokenIndex, + pub padding: [u8; 4], + pub name: [u8; 16], pub serum_program: Pubkey, pub serum_market_external: Pubkey, pub market_index: Serum3MarketIndex, - pub base_token_index: TokenIndex, - pub quote_token_index: TokenIndex, pub bump: u8, - pub reserved: [u8; 1], + pub reserved: [u8; 5], } -const_assert_eq!(size_of::(), 16 + 32 * 3 + 3 * 2 + 1 + 1); +const_assert_eq!( + size_of::(), + 32 + 2 + 2 + 4 + 16 + 2 * 32 + 2 + 1 + 5 +); const_assert_eq!(size_of::() % 8, 0); impl Serum3Market { diff --git a/programs/mango-v4/tests/program_test/mango_client.rs b/programs/mango-v4/tests/program_test/mango_client.rs index e6095254e..5c7276cee 100644 --- a/programs/mango-v4/tests/program_test/mango_client.rs +++ b/programs/mango-v4/tests/program_test/mango_client.rs @@ -2160,7 +2160,6 @@ pub struct PerpCreateMarketInstruction<'keypair> { pub perp_market_index: PerpMarketIndex, pub base_token_index: TokenIndex, pub base_token_decimals: u8, - pub quote_token_index: TokenIndex, pub quote_lot_size: i64, pub base_lot_size: i64, pub maint_asset_weight: f32, @@ -2187,7 +2186,6 @@ impl<'keypair> ClientInstruction for PerpCreateMarketInstruction<'keypair> { }, perp_market_index: self.perp_market_index, base_token_index_opt: Option::from(self.base_token_index), - quote_token_index: self.quote_token_index, quote_lot_size: self.quote_lot_size, base_lot_size: self.base_lot_size, maint_asset_weight: self.maint_asset_weight, diff --git a/programs/mango-v4/tests/test_health_compute.rs b/programs/mango-v4/tests/test_health_compute.rs index 80bd2ae48..1bb6a7d62 100644 --- a/programs/mango-v4/tests/test_health_compute.rs +++ b/programs/mango-v4/tests/test_health_compute.rs @@ -271,7 +271,6 @@ async fn test_health_compute_perp() -> Result<(), TransportError> { perp_market_index: perp_market_index as PerpMarketIndex, base_token_index: quote_token.index, base_token_decimals: quote_token.mint.decimals, - quote_token_index: token.index, quote_lot_size: 10, base_lot_size: 100, maint_asset_weight: 0.975, diff --git a/programs/mango-v4/tests/test_perp.rs b/programs/mango-v4/tests/test_perp.rs index 2fa60d5cd..02d86271f 100644 --- a/programs/mango-v4/tests/test_perp.rs +++ b/programs/mango-v4/tests/test_perp.rs @@ -154,7 +154,6 @@ async fn test_perp() -> Result<(), TransportError> { perp_market_index: 0, base_token_index: tokens[0].index, base_token_decimals: tokens[0].mint.decimals, - quote_token_index: tokens[1].index, quote_lot_size: 10, base_lot_size: 100, maint_asset_weight: 0.975, diff --git a/release-to-devnet.sh b/release-to-devnet.sh index a9befdb63..16c34be42 100755 --- a/release-to-devnet.sh +++ b/release-to-devnet.sh @@ -15,7 +15,7 @@ anchor build --skip-lint # update types in ts client package cp -v ./target/types/mango_v4.ts ./ts/client/src/mango_v4.ts -(cd ./ts/client && tsc) +(cd ./ts/client && yarn tsc) if [[ -z "${NO_DEPLOY}" ]]; then # publish program diff --git a/release-to-mainnet.sh b/release-to-mainnet.sh index 98aadc306..21bd30650 100755 --- a/release-to-mainnet.sh +++ b/release-to-mainnet.sh @@ -15,7 +15,7 @@ anchor build --skip-lint # update types in ts client package cp -v ./target/types/mango_v4.ts ./ts/client/src/mango_v4.ts -(cd ./ts/client && tsc) +(cd ./ts/client && yarn tsc) if [[ -z "${NO_DEPLOY}" ]]; then # publish program @@ -31,4 +31,4 @@ fi # build npm package -(cd ./ts/client && tsc) +(cd ./ts/client && yarn tsc) diff --git a/ts/client/src/client.ts b/ts/client/src/client.ts index a33318006..682169f37 100644 --- a/ts/client/src/client.ts +++ b/ts/client/src/client.ts @@ -67,6 +67,7 @@ export class MangoClient { public async createGroup( groupNum: number, testing: boolean, + insuranceMintPk: PublicKey, ): Promise { const adminPk = (this.program.provider as AnchorProvider).wallet.publicKey; return await this.program.methods @@ -74,6 +75,7 @@ export class MangoClient { .accounts({ admin: adminPk, payer: adminPk, + insuranceMint: insuranceMintPk, }) .rpc(); } @@ -117,7 +119,7 @@ export class MangoClient { filters.push({ memcmp: { bytes: bs58.encode(bbuf), - offset: 44, + offset: 40, }, }); } @@ -286,7 +288,7 @@ export class MangoClient { { memcmp: { bytes: group.publicKey.toBase58(), - offset: 24, + offset: 8, }, }, ]) @@ -325,7 +327,7 @@ export class MangoClient { { memcmp: { bytes: bs58.encode(tokenIndexBuf), - offset: 200, + offset: 40, }, }, ]) @@ -443,6 +445,7 @@ export class MangoClient { public async editMangoAccount( group: Group, + mangoAccount: MangoAccount, name?: string, delegate?: PublicKey, ): Promise { @@ -450,6 +453,7 @@ export class MangoClient { .editAccount(name, delegate) .accounts({ group: group.publicKey, + account: mangoAccount.publicKey, owner: (this.program.provider as AnchorProvider).wallet.publicKey, }) .rpc(); @@ -471,13 +475,13 @@ export class MangoClient { { memcmp: { bytes: group.publicKey.toBase58(), - offset: 40, + offset: 8, }, }, { memcmp: { bytes: ownerPk.toBase58(), - offset: 72, + offset: 40, }, }, ]) @@ -724,7 +728,7 @@ export class MangoClient { { memcmp: { bytes: group.publicKey.toBase58(), - offset: 24, + offset: 8, }, }, ]; @@ -735,7 +739,7 @@ export class MangoClient { filters.push({ memcmp: { bytes: bs58.encode(bbuf), - offset: 122, + offset: 40, }, }); } @@ -746,7 +750,7 @@ export class MangoClient { filters.push({ memcmp: { bytes: bs58.encode(qbuf), - offset: 124, + offset: 42, }, }); } @@ -1052,7 +1056,6 @@ export class MangoClient { } as any, // future: nested custom types dont typecheck, fix if possible? baseTokenIndex, baseTokenDecimals, - quoteTokenIndex, new BN(quoteLotSize), new BN(baseLotSize), maintAssetWeight, @@ -1188,7 +1191,6 @@ export class MangoClient { public async perpGetMarkets( group: Group, baseTokenIndex?: number, - quoteTokenIndex?: number, ): Promise { const bumpfbuf = Buffer.alloc(1); bumpfbuf.writeUInt8(255); @@ -1197,7 +1199,7 @@ export class MangoClient { { memcmp: { bytes: group.publicKey.toBase58(), - offset: 24, + offset: 8, }, }, ]; @@ -1208,18 +1210,7 @@ export class MangoClient { filters.push({ memcmp: { bytes: bs58.encode(bbuf), - offset: 444, - }, - }); - } - - if (quoteTokenIndex) { - const qbuf = Buffer.alloc(2); - qbuf.writeUInt16LE(quoteTokenIndex); - filters.push({ - memcmp: { - bytes: bs58.encode(qbuf), - offset: 446, + offset: 40, }, }); } diff --git a/ts/client/src/mango_v4.ts b/ts/client/src/mango_v4.ts index 83164c12b..5cdfe892a 100644 --- a/ts/client/src/mango_v4.ts +++ b/ts/client/src/mango_v4.ts @@ -1953,10 +1953,6 @@ export type MangoV4 = { "name": "baseTokenDecimals", "type": "u8" }, - { - "name": "quoteTokenIndex", - "type": "u16" - }, { "name": "quoteLotSize", "type": "i64" @@ -2496,6 +2492,10 @@ export type MangoV4 = { "type": { "kind": "struct", "fields": [ + { + "name": "group", + "type": "publicKey" + }, { "name": "name", "type": { @@ -2505,10 +2505,6 @@ export type MangoV4 = { ] } }, - { - "name": "group", - "type": "publicKey" - }, { "name": "mint", "type": "publicKey" @@ -2696,6 +2692,19 @@ export type MangoV4 = { "name": "admin", "type": "publicKey" }, + { + "name": "groupNum", + "type": "u32" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 4 + ] + } + }, { "name": "insuranceVault", "type": "publicKey" @@ -2704,10 +2713,6 @@ export type MangoV4 = { "name": "insuranceMint", "type": "publicKey" }, - { - "name": "groupNum", - "type": "u32" - }, { "name": "bump", "type": "u8" @@ -2721,7 +2726,7 @@ export type MangoV4 = { "type": { "array": [ "u8", - 2 + 6 ] } }, @@ -2742,6 +2747,14 @@ export type MangoV4 = { "type": { "kind": "struct", "fields": [ + { + "name": "group", + "type": "publicKey" + }, + { + "name": "owner", + "type": "publicKey" + }, { "name": "name", "type": { @@ -2751,14 +2764,6 @@ export type MangoV4 = { ] } }, - { - "name": "group", - "type": "publicKey" - }, - { - "name": "owner", - "type": "publicKey" - }, { "name": "delegate", "type": "publicKey" @@ -2818,6 +2823,19 @@ export type MangoV4 = { "name": "group", "type": "publicKey" }, + { + "name": "tokenIndex", + "type": "u16" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 6 + ] + } + }, { "name": "mint", "type": "publicKey" @@ -2848,10 +2866,6 @@ export type MangoV4 = { "name": "addressLookupTable", "type": "publicKey" }, - { - "name": "tokenIndex", - "type": "u16" - }, { "name": "addressLookupTableBankIndex", "type": "u8" @@ -2865,7 +2879,7 @@ export type MangoV4 = { "type": { "array": [ "u8", - 4 + 6 ] } } @@ -2991,6 +3005,27 @@ export type MangoV4 = { "type": { "kind": "struct", "fields": [ + { + "name": "group", + "type": "publicKey" + }, + { + "name": "baseTokenIndex", + "type": "u16" + }, + { + "name": "perpMarketIndex", + "type": "u16" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 4 + ] + } + }, { "name": "name", "type": { @@ -3000,10 +3035,6 @@ export type MangoV4 = { ] } }, - { - "name": "group", - "type": "publicKey" - }, { "name": "oracle", "type": "publicKey" @@ -3131,16 +3162,13 @@ export type MangoV4 = { "type": "u8" }, { - "name": "perpMarketIndex", - "type": "u16" - }, - { - "name": "baseTokenIndex", - "type": "u16" - }, - { - "name": "quoteTokenIndex", - "type": "u16" + "name": "reserved", + "type": { + "array": [ + "u8", + 6 + ] + } } ] } @@ -3150,6 +3178,27 @@ export type MangoV4 = { "type": { "kind": "struct", "fields": [ + { + "name": "group", + "type": "publicKey" + }, + { + "name": "baseTokenIndex", + "type": "u16" + }, + { + "name": "quoteTokenIndex", + "type": "u16" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 4 + ] + } + }, { "name": "name", "type": { @@ -3159,10 +3208,6 @@ export type MangoV4 = { ] } }, - { - "name": "group", - "type": "publicKey" - }, { "name": "serumProgram", "type": "publicKey" @@ -3175,14 +3220,6 @@ export type MangoV4 = { "name": "marketIndex", "type": "u16" }, - { - "name": "baseTokenIndex", - "type": "u16" - }, - { - "name": "quoteTokenIndex", - "type": "u16" - }, { "name": "bump", "type": "u8" @@ -3192,7 +3229,7 @@ export type MangoV4 = { "type": { "array": [ "u8", - 1 + 5 ] } } @@ -6444,10 +6481,6 @@ export const IDL: MangoV4 = { "name": "baseTokenDecimals", "type": "u8" }, - { - "name": "quoteTokenIndex", - "type": "u16" - }, { "name": "quoteLotSize", "type": "i64" @@ -6987,6 +7020,10 @@ export const IDL: MangoV4 = { "type": { "kind": "struct", "fields": [ + { + "name": "group", + "type": "publicKey" + }, { "name": "name", "type": { @@ -6996,10 +7033,6 @@ export const IDL: MangoV4 = { ] } }, - { - "name": "group", - "type": "publicKey" - }, { "name": "mint", "type": "publicKey" @@ -7187,6 +7220,19 @@ export const IDL: MangoV4 = { "name": "admin", "type": "publicKey" }, + { + "name": "groupNum", + "type": "u32" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 4 + ] + } + }, { "name": "insuranceVault", "type": "publicKey" @@ -7195,10 +7241,6 @@ export const IDL: MangoV4 = { "name": "insuranceMint", "type": "publicKey" }, - { - "name": "groupNum", - "type": "u32" - }, { "name": "bump", "type": "u8" @@ -7212,7 +7254,7 @@ export const IDL: MangoV4 = { "type": { "array": [ "u8", - 2 + 6 ] } }, @@ -7233,6 +7275,14 @@ export const IDL: MangoV4 = { "type": { "kind": "struct", "fields": [ + { + "name": "group", + "type": "publicKey" + }, + { + "name": "owner", + "type": "publicKey" + }, { "name": "name", "type": { @@ -7242,14 +7292,6 @@ export const IDL: MangoV4 = { ] } }, - { - "name": "group", - "type": "publicKey" - }, - { - "name": "owner", - "type": "publicKey" - }, { "name": "delegate", "type": "publicKey" @@ -7309,6 +7351,19 @@ export const IDL: MangoV4 = { "name": "group", "type": "publicKey" }, + { + "name": "tokenIndex", + "type": "u16" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 6 + ] + } + }, { "name": "mint", "type": "publicKey" @@ -7339,10 +7394,6 @@ export const IDL: MangoV4 = { "name": "addressLookupTable", "type": "publicKey" }, - { - "name": "tokenIndex", - "type": "u16" - }, { "name": "addressLookupTableBankIndex", "type": "u8" @@ -7356,7 +7407,7 @@ export const IDL: MangoV4 = { "type": { "array": [ "u8", - 4 + 6 ] } } @@ -7482,6 +7533,27 @@ export const IDL: MangoV4 = { "type": { "kind": "struct", "fields": [ + { + "name": "group", + "type": "publicKey" + }, + { + "name": "baseTokenIndex", + "type": "u16" + }, + { + "name": "perpMarketIndex", + "type": "u16" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 4 + ] + } + }, { "name": "name", "type": { @@ -7491,10 +7563,6 @@ export const IDL: MangoV4 = { ] } }, - { - "name": "group", - "type": "publicKey" - }, { "name": "oracle", "type": "publicKey" @@ -7622,16 +7690,13 @@ export const IDL: MangoV4 = { "type": "u8" }, { - "name": "perpMarketIndex", - "type": "u16" - }, - { - "name": "baseTokenIndex", - "type": "u16" - }, - { - "name": "quoteTokenIndex", - "type": "u16" + "name": "reserved", + "type": { + "array": [ + "u8", + 6 + ] + } } ] } @@ -7641,6 +7706,27 @@ export const IDL: MangoV4 = { "type": { "kind": "struct", "fields": [ + { + "name": "group", + "type": "publicKey" + }, + { + "name": "baseTokenIndex", + "type": "u16" + }, + { + "name": "quoteTokenIndex", + "type": "u16" + }, + { + "name": "padding", + "type": { + "array": [ + "u8", + 4 + ] + } + }, { "name": "name", "type": { @@ -7650,10 +7736,6 @@ export const IDL: MangoV4 = { ] } }, - { - "name": "group", - "type": "publicKey" - }, { "name": "serumProgram", "type": "publicKey" @@ -7666,14 +7748,6 @@ export const IDL: MangoV4 = { "name": "marketIndex", "type": "u16" }, - { - "name": "baseTokenIndex", - "type": "u16" - }, - { - "name": "quoteTokenIndex", - "type": "u16" - }, { "name": "bump", "type": "u8" @@ -7683,7 +7757,7 @@ export const IDL: MangoV4 = { "type": { "array": [ "u8", - 1 + 5 ] } } diff --git a/ts/client/src/scripts/example1-admin.ts b/ts/client/src/scripts/example1-admin.ts index 6dcf5c258..bbf293213 100644 --- a/ts/client/src/scripts/example1-admin.ts +++ b/ts/client/src/scripts/example1-admin.ts @@ -53,15 +53,16 @@ async function main() { // group console.log(`Creating Group...`); + const insuranceMint = new PublicKey(DEVNET_MINTS.get('USDC')!); try { - await client.createGroup(0, true); + await client.createGroup(0, true, insuranceMint); } catch (error) { console.log(error); } const group = await client.getGroupForAdmin(admin.publicKey); console.log(`...registered group ${group.publicKey}`); - // register token 0 + // register token 1 console.log(`Registering BTC...`); const btcDevnetMint = new PublicKey(DEVNET_MINTS.get('BTC')!); const btcDevnetOracle = new PublicKey(DEVNET_ORACLES.get('BTC')!); @@ -71,7 +72,7 @@ async function main() { btcDevnetMint, btcDevnetOracle, 0.1, - 0, + 1, // tokenIndex 'BTC', 0.4, 0.07, @@ -91,7 +92,7 @@ async function main() { console.log(error); } - // stub oracle + register token 1 + // stub oracle + register token 0 console.log(`Registering USDC...`); const usdcDevnetMint = new PublicKey(DEVNET_MINTS.get('USDC')!); try { @@ -109,7 +110,7 @@ async function main() { usdcDevnetMint, usdcDevnetOracle.publicKey, 0.1, - 1, + 0, // tokenIndex 'USDC', 0.4, 0.07, @@ -228,7 +229,7 @@ async function main() { 0, 'BTC-PERP', 0.1, - 0, + 1, 6, 1, 10, @@ -251,7 +252,6 @@ async function main() { const perpMarkets = await client.perpGetMarkets( group, group.banksMap.get('BTC')?.tokenIndex, - group.banksMap.get('USDC')?.tokenIndex, ); console.log(`...created perp market ${perpMarkets[0].publicKey}`); @@ -319,7 +319,7 @@ async function main() { 'BTC-PERP', btcDevnetOracle, 0.2, - 1, + 0, 6, 0.9, 0.9, @@ -345,7 +345,7 @@ async function main() { 'BTC-PERP', btcDevnetOracle, 0.1, - 0, + 1, 6, 1, 0.95, diff --git a/ts/client/src/scripts/example1-user.ts b/ts/client/src/scripts/example1-user.ts index b6bb0c8e3..d7a8634cd 100644 --- a/ts/client/src/scripts/example1-user.ts +++ b/ts/client/src/scripts/example1-user.ts @@ -67,12 +67,12 @@ async function main() { const randomKey = new PublicKey( '4ZkS7ZZkxfsC3GtvvsHP3DFcUeByU9zzZELS4r8HCELo', ); - await client.editMangoAccount(group, 'my_changed_name', randomKey); + await client.editMangoAccount(group, mangoAccount, 'my_changed_name', randomKey); await mangoAccount.reload(client, group); console.log(mangoAccount.toString()); console.log(`...resetting mango account name, and re-setting a delegate`); - await client.editMangoAccount(group, 'my_mango_account', PublicKey.default); + await client.editMangoAccount(group, mangoAccount, 'my_mango_account', PublicKey.default); await mangoAccount.reload(client, group); console.log(mangoAccount.toString()); } diff --git a/update-local-idl.sh b/update-local-idl.sh index 22274462c..941624d15 100755 --- a/update-local-idl.sh +++ b/update-local-idl.sh @@ -12,4 +12,4 @@ anchor build --skip-lint # update types in ts client package cp -v ./target/types/mango_v4.ts ./ts/client/src/mango_v4.ts -(cd ./ts/client && tsc) +(cd ./ts/client && yarn tsc)