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
This commit is contained in:
Christian Kamm 2022-07-06 09:56:14 +02:00
parent f2d8aceebe
commit de86b69e1a
23 changed files with 274 additions and 191 deletions

View File

@ -78,12 +78,12 @@ impl MangoClient {
// Mango Account // Mango Account
let mut mango_account_tuples = program.accounts::<MangoAccount>(vec![ let mut mango_account_tuples = program.accounts::<MangoAccount>(vec![
RpcFilterType::Memcmp(Memcmp { RpcFilterType::Memcmp(Memcmp {
offset: 40, offset: 8,
bytes: MemcmpEncodedBytes::Base58(group.to_string()), bytes: MemcmpEncodedBytes::Base58(group.to_string()),
encoding: None, encoding: None,
}), }),
RpcFilterType::Memcmp(Memcmp { RpcFilterType::Memcmp(Memcmp {
offset: 72, offset: 40,
bytes: MemcmpEncodedBytes::Base58(payer.pubkey().to_string()), bytes: MemcmpEncodedBytes::Base58(payer.pubkey().to_string()),
encoding: None, encoding: None,
}), }),
@ -135,12 +135,12 @@ impl MangoClient {
} }
let mango_account_tuples = program.accounts::<MangoAccount>(vec![ let mango_account_tuples = program.accounts::<MangoAccount>(vec![
RpcFilterType::Memcmp(Memcmp { RpcFilterType::Memcmp(Memcmp {
offset: 40, offset: 8,
bytes: MemcmpEncodedBytes::Base58(group.to_string()), bytes: MemcmpEncodedBytes::Base58(group.to_string()),
encoding: None, encoding: None,
}), }),
RpcFilterType::Memcmp(Memcmp { RpcFilterType::Memcmp(Memcmp {
offset: 72, offset: 40,
bytes: MemcmpEncodedBytes::Base58(payer.pubkey().to_string()), bytes: MemcmpEncodedBytes::Base58(payer.pubkey().to_string()),
encoding: None, encoding: None,
}), }),
@ -155,7 +155,7 @@ impl MangoClient {
let mut banks_cache = HashMap::new(); let mut banks_cache = HashMap::new();
let mut banks_cache_by_token_index = HashMap::new(); let mut banks_cache_by_token_index = HashMap::new();
let bank_tuples = program.accounts::<Bank>(vec![RpcFilterType::Memcmp(Memcmp { let bank_tuples = program.accounts::<Bank>(vec![RpcFilterType::Memcmp(Memcmp {
offset: 24, offset: 8,
bytes: MemcmpEncodedBytes::Base58(group.to_string()), bytes: MemcmpEncodedBytes::Base58(group.to_string()),
encoding: None, encoding: None,
})])?; })])?;
@ -197,7 +197,7 @@ impl MangoClient {
let mut serum3_external_markets_cache = HashMap::new(); let mut serum3_external_markets_cache = HashMap::new();
let serum3_market_tuples = let serum3_market_tuples =
program.accounts::<Serum3Market>(vec![RpcFilterType::Memcmp(Memcmp { program.accounts::<Serum3Market>(vec![RpcFilterType::Memcmp(Memcmp {
offset: 24, offset: 8,
bytes: MemcmpEncodedBytes::Base58(group.to_string()), bytes: MemcmpEncodedBytes::Base58(group.to_string()),
encoding: None, encoding: None,
})])?; })])?;
@ -221,7 +221,7 @@ impl MangoClient {
let mut perp_markets_cache_by_perp_market_index = HashMap::new(); let mut perp_markets_cache_by_perp_market_index = HashMap::new();
let perp_market_tuples = let perp_market_tuples =
program.accounts::<PerpMarket>(vec![RpcFilterType::Memcmp(Memcmp { program.accounts::<PerpMarket>(vec![RpcFilterType::Memcmp(Memcmp {
offset: 24, offset: 8,
bytes: MemcmpEncodedBytes::Base58(group.to_string()), bytes: MemcmpEncodedBytes::Base58(group.to_string()),
encoding: None, encoding: None,
})])?; })])?;
@ -279,12 +279,12 @@ impl MangoClient {
pub fn get_account(&self) -> Result<(Pubkey, MangoAccount), anchor_client::ClientError> { pub fn get_account(&self) -> Result<(Pubkey, MangoAccount), anchor_client::ClientError> {
let mango_accounts = self.program().accounts::<MangoAccount>(vec![ let mango_accounts = self.program().accounts::<MangoAccount>(vec![
RpcFilterType::Memcmp(Memcmp { RpcFilterType::Memcmp(Memcmp {
offset: 40, offset: 8,
bytes: MemcmpEncodedBytes::Base58(self.group().to_string()), bytes: MemcmpEncodedBytes::Base58(self.group().to_string()),
encoding: None, encoding: None,
}), }),
RpcFilterType::Memcmp(Memcmp { RpcFilterType::Memcmp(Memcmp {
offset: 72, offset: 40,
bytes: MemcmpEncodedBytes::Base58(self.payer().to_string()), bytes: MemcmpEncodedBytes::Base58(self.payer().to_string()),
encoding: None, encoding: None,
}), }),

View File

@ -50,7 +50,6 @@ pub fn perp_create_market(
oracle_config: OracleConfig, oracle_config: OracleConfig,
base_token_index_opt: Option<TokenIndex>, base_token_index_opt: Option<TokenIndex>,
base_token_decimals: u8, base_token_decimals: u8,
quote_token_index: TokenIndex,
quote_lot_size: i64, quote_lot_size: i64,
base_lot_size: i64, base_lot_size: i64,
maint_asset_weight: f32, maint_asset_weight: f32,
@ -96,7 +95,8 @@ pub fn perp_create_market(
base_token_decimals, base_token_decimals,
perp_market_index, perp_market_index,
base_token_index: base_token_index_opt.ok_or(TokenIndex::MAX).unwrap(), 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()?; let mut bids = ctx.accounts.bids.load_init()?;

View File

@ -74,6 +74,7 @@ pub fn serum3_register_market(
base_token_index: base_bank.token_index, base_token_index: base_bank.token_index,
quote_token_index: quote_bank.token_index, quote_token_index: quote_bank.token_index,
bump: *ctx.bumps.get("serum_market").ok_or(MangoError::SomeError)?, bump: *ctx.bumps.get("serum_market").ok_or(MangoError::SomeError)?,
padding: Default::default(),
reserved: Default::default(), reserved: Default::default(),
}; };

View File

@ -170,6 +170,7 @@ pub fn token_register(
token_index, token_index,
address_lookup_table_bank_index: alt_previous_size as u8, address_lookup_table_bank_index: alt_previous_size as u8,
address_lookup_table_oracle_index: alt_previous_size as u8 + 1, address_lookup_table_oracle_index: alt_previous_size as u8 + 1,
padding: Default::default(),
reserved: Default::default(), reserved: Default::default(),
}; };

View File

@ -322,7 +322,6 @@ pub mod mango_v4 {
oracle_config: OracleConfig, oracle_config: OracleConfig,
base_token_index_opt: Option<TokenIndex>, base_token_index_opt: Option<TokenIndex>,
base_token_decimals: u8, base_token_decimals: u8,
quote_token_index: TokenIndex,
quote_lot_size: i64, quote_lot_size: i64,
base_lot_size: i64, base_lot_size: i64,
maint_asset_weight: f32, maint_asset_weight: f32,
@ -343,7 +342,6 @@ pub mod mango_v4 {
oracle_config, oracle_config,
base_token_index_opt, base_token_index_opt,
base_token_decimals, base_token_decimals,
quote_token_index,
quote_lot_size, quote_lot_size,
base_lot_size, base_lot_size,
maint_asset_weight, maint_asset_weight,

View File

@ -13,9 +13,11 @@ pub const YEAR: I80F48 = I80F48!(31536000);
#[account(zero_copy)] #[account(zero_copy)]
pub struct Bank { pub struct Bank {
// ABI: Clients rely on this being at offset 8
pub group: Pubkey,
pub name: [u8; 16], pub name: [u8; 16],
pub group: Pubkey,
pub mint: Pubkey, pub mint: Pubkey,
pub vault: Pubkey, pub vault: Pubkey,
pub oracle: Pubkey, pub oracle: Pubkey,

View File

@ -9,22 +9,25 @@ pub const QUOTE_TOKEN_INDEX: TokenIndex = 0;
#[account(zero_copy)] #[account(zero_copy)]
#[derive(Debug)] #[derive(Debug)]
pub struct Group { pub struct Group {
// Relying on Anchor's discriminator be sufficient for our versioning needs? // ABI: Clients rely on this being at offset 8
// pub meta_data: MetaData,
pub admin: Pubkey, 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_vault: Pubkey,
pub insurance_mint: Pubkey, pub insurance_mint: Pubkey,
pub group_num: u32,
pub bump: u8, pub bump: u8,
// Only support closing/deregistering groups, stub oracles, tokens, and markets // Only support closing/deregistering groups, stub oracles, tokens, and markets
// if testing == 1 // if testing == 1
pub testing: u8, pub testing: u8,
pub padding2: [u8; 2], pub padding2: [u8; 6],
pub reserved: [u8; 8], pub reserved: [u8; 8],
} }
const_assert_eq!(size_of::<Group>(), 32 * 3 + 4 + 1 * 2 + 10); const_assert_eq!(size_of::<Group>(), 32 * 3 + 4 + 4 + 1 * 2 + 6 + 8);
const_assert_eq!(size_of::<Group>() % 8, 0); const_assert_eq!(size_of::<Group>() % 8, 0);
#[macro_export] #[macro_export]

View File

@ -869,7 +869,6 @@ mod tests {
perp1.data().group = group; perp1.data().group = group;
perp1.data().perp_market_index = 9; perp1.data().perp_market_index = 9;
perp1.data().base_token_index = 4; 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_asset_weight = I80F48::from_num(1.0 - 0.2f64);
perp1.data().init_liab_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); perp1.data().maint_asset_weight = I80F48::from_num(1.0 - 0.1f64);
@ -1044,7 +1043,6 @@ mod tests {
perp1.data().group = group; perp1.data().group = group;
perp1.data().perp_market_index = 9; perp1.data().perp_market_index = 9;
perp1.data().base_token_index = 4; 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_asset_weight = I80F48::from_num(1.0 - 0.2f64);
perp1.data().init_liab_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); perp1.data().maint_asset_weight = I80F48::from_num(1.0 - 0.1f64);

View File

@ -704,11 +704,14 @@ impl Default for MangoAccountPerpPositions {
#[account(zero_copy)] #[account(zero_copy)]
pub struct MangoAccount { pub struct MangoAccount {
pub name: [u8; 32], // ABI: Clients rely on this being at offset 8
pub group: Pubkey, pub group: Pubkey,
// ABI: Clients rely on this being at offset 40
pub owner: Pubkey, pub owner: Pubkey,
pub name: [u8; 32],
// Alternative authority/signer of transactions for a mango account // Alternative authority/signer of transactions for a mango account
pub delegate: Pubkey, pub delegate: Pubkey,

View File

@ -15,25 +15,28 @@ pub const MAX_BANKS: usize = 6;
#[account(zero_copy)] #[account(zero_copy)]
#[derive(Debug)] #[derive(Debug)]
pub struct MintInfo { pub struct MintInfo {
// TODO: none of these pubkeys are needed, remove? // ABI: Clients rely on this being at offset 8
pub group: Pubkey, pub group: Pubkey,
// ABI: Clients rely on this being at offset 40
pub token_index: TokenIndex,
pub padding: [u8; 6],
pub mint: Pubkey, pub mint: Pubkey,
pub banks: [Pubkey; MAX_BANKS], pub banks: [Pubkey; MAX_BANKS],
pub vaults: [Pubkey; MAX_BANKS], pub vaults: [Pubkey; MAX_BANKS],
pub oracle: Pubkey, pub oracle: Pubkey,
pub address_lookup_table: Pubkey, pub address_lookup_table: Pubkey,
pub token_index: TokenIndex,
// describe what address map relevant accounts are found on // describe what address map relevant accounts are found on
pub address_lookup_table_bank_index: u8, pub address_lookup_table_bank_index: u8,
pub address_lookup_table_oracle_index: u8, pub address_lookup_table_oracle_index: u8,
pub reserved: [u8; 4], pub reserved: [u8; 6],
} }
const_assert_eq!( const_assert_eq!(
size_of::<MintInfo>(), size_of::<MintInfo>(),
MAX_BANKS * 2 * 32 + 4 * 32 + 2 + 2 + 4 MAX_BANKS * 2 * 32 + 4 * 32 + 2 + 6 + 2 + 6
); );
const_assert_eq!(size_of::<MintInfo>() % 8, 0); const_assert_eq!(size_of::<MintInfo>() % 8, 0);

View File

@ -71,7 +71,9 @@ pub enum OracleType {
#[account(zero_copy)] #[account(zero_copy)]
pub struct StubOracle { pub struct StubOracle {
// ABI: Clients rely on this being at offset 8
pub group: Pubkey, pub group: Pubkey,
// ABI: Clients rely on this being at offset 40
pub mint: Pubkey, pub mint: Pubkey,
pub price: I80F48, pub price: I80F48,
pub last_updated: i64, pub last_updated: i64,

View File

@ -16,10 +16,20 @@ pub type PerpMarketIndex = u16;
#[account(zero_copy)] #[account(zero_copy)]
#[derive(Debug)] #[derive(Debug)]
pub struct PerpMarket { pub struct PerpMarket {
pub name: [u8; 16], // ABI: Clients rely on this being at offset 8
pub group: Pubkey, 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: Pubkey,
pub oracle_config: OracleConfig, pub oracle_config: OracleConfig,
@ -76,18 +86,12 @@ pub struct PerpMarket {
pub base_token_decimals: u8, pub base_token_decimals: u8,
/// Lookup indices pub reserved: [u8; 6],
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,
} }
const_assert_eq!( const_assert_eq!(
size_of::<PerpMarket>(), size_of::<PerpMarket>(),
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::<PerpMarket>() % 8, 0); const_assert_eq!(size_of::<PerpMarket>() % 8, 0);

View File

@ -9,19 +9,26 @@ pub type Serum3MarketIndex = u16;
#[account(zero_copy)] #[account(zero_copy)]
#[derive(Debug)] #[derive(Debug)]
pub struct Serum3Market { pub struct Serum3Market {
pub name: [u8; 16], // ABI: Clients rely on this being at offset 8
pub group: Pubkey, 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_program: Pubkey,
pub serum_market_external: Pubkey, pub serum_market_external: Pubkey,
pub market_index: Serum3MarketIndex, pub market_index: Serum3MarketIndex,
pub base_token_index: TokenIndex,
pub quote_token_index: TokenIndex,
pub bump: u8, pub bump: u8,
pub reserved: [u8; 1], pub reserved: [u8; 5],
} }
const_assert_eq!(size_of::<Serum3Market>(), 16 + 32 * 3 + 3 * 2 + 1 + 1); const_assert_eq!(
size_of::<Serum3Market>(),
32 + 2 + 2 + 4 + 16 + 2 * 32 + 2 + 1 + 5
);
const_assert_eq!(size_of::<Serum3Market>() % 8, 0); const_assert_eq!(size_of::<Serum3Market>() % 8, 0);
impl Serum3Market { impl Serum3Market {

View File

@ -2160,7 +2160,6 @@ pub struct PerpCreateMarketInstruction<'keypair> {
pub perp_market_index: PerpMarketIndex, pub perp_market_index: PerpMarketIndex,
pub base_token_index: TokenIndex, pub base_token_index: TokenIndex,
pub base_token_decimals: u8, pub base_token_decimals: u8,
pub quote_token_index: TokenIndex,
pub quote_lot_size: i64, pub quote_lot_size: i64,
pub base_lot_size: i64, pub base_lot_size: i64,
pub maint_asset_weight: f32, pub maint_asset_weight: f32,
@ -2187,7 +2186,6 @@ impl<'keypair> ClientInstruction for PerpCreateMarketInstruction<'keypair> {
}, },
perp_market_index: self.perp_market_index, perp_market_index: self.perp_market_index,
base_token_index_opt: Option::from(self.base_token_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, quote_lot_size: self.quote_lot_size,
base_lot_size: self.base_lot_size, base_lot_size: self.base_lot_size,
maint_asset_weight: self.maint_asset_weight, maint_asset_weight: self.maint_asset_weight,

View File

@ -271,7 +271,6 @@ async fn test_health_compute_perp() -> Result<(), TransportError> {
perp_market_index: perp_market_index as PerpMarketIndex, perp_market_index: perp_market_index as PerpMarketIndex,
base_token_index: quote_token.index, base_token_index: quote_token.index,
base_token_decimals: quote_token.mint.decimals, base_token_decimals: quote_token.mint.decimals,
quote_token_index: token.index,
quote_lot_size: 10, quote_lot_size: 10,
base_lot_size: 100, base_lot_size: 100,
maint_asset_weight: 0.975, maint_asset_weight: 0.975,

View File

@ -154,7 +154,6 @@ async fn test_perp() -> Result<(), TransportError> {
perp_market_index: 0, perp_market_index: 0,
base_token_index: tokens[0].index, base_token_index: tokens[0].index,
base_token_decimals: tokens[0].mint.decimals, base_token_decimals: tokens[0].mint.decimals,
quote_token_index: tokens[1].index,
quote_lot_size: 10, quote_lot_size: 10,
base_lot_size: 100, base_lot_size: 100,
maint_asset_weight: 0.975, maint_asset_weight: 0.975,

View File

@ -15,7 +15,7 @@ anchor build --skip-lint
# update types in ts client package # update types in ts client package
cp -v ./target/types/mango_v4.ts ./ts/client/src/mango_v4.ts 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 if [[ -z "${NO_DEPLOY}" ]]; then
# publish program # publish program

View File

@ -15,7 +15,7 @@ anchor build --skip-lint
# update types in ts client package # update types in ts client package
cp -v ./target/types/mango_v4.ts ./ts/client/src/mango_v4.ts 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 if [[ -z "${NO_DEPLOY}" ]]; then
# publish program # publish program
@ -31,4 +31,4 @@ fi
# build npm package # build npm package
(cd ./ts/client && tsc) (cd ./ts/client && yarn tsc)

View File

@ -67,6 +67,7 @@ export class MangoClient {
public async createGroup( public async createGroup(
groupNum: number, groupNum: number,
testing: boolean, testing: boolean,
insuranceMintPk: PublicKey,
): Promise<TransactionSignature> { ): Promise<TransactionSignature> {
const adminPk = (this.program.provider as AnchorProvider).wallet.publicKey; const adminPk = (this.program.provider as AnchorProvider).wallet.publicKey;
return await this.program.methods return await this.program.methods
@ -74,6 +75,7 @@ export class MangoClient {
.accounts({ .accounts({
admin: adminPk, admin: adminPk,
payer: adminPk, payer: adminPk,
insuranceMint: insuranceMintPk,
}) })
.rpc(); .rpc();
} }
@ -117,7 +119,7 @@ export class MangoClient {
filters.push({ filters.push({
memcmp: { memcmp: {
bytes: bs58.encode(bbuf), bytes: bs58.encode(bbuf),
offset: 44, offset: 40,
}, },
}); });
} }
@ -286,7 +288,7 @@ export class MangoClient {
{ {
memcmp: { memcmp: {
bytes: group.publicKey.toBase58(), bytes: group.publicKey.toBase58(),
offset: 24, offset: 8,
}, },
}, },
]) ])
@ -325,7 +327,7 @@ export class MangoClient {
{ {
memcmp: { memcmp: {
bytes: bs58.encode(tokenIndexBuf), bytes: bs58.encode(tokenIndexBuf),
offset: 200, offset: 40,
}, },
}, },
]) ])
@ -443,6 +445,7 @@ export class MangoClient {
public async editMangoAccount( public async editMangoAccount(
group: Group, group: Group,
mangoAccount: MangoAccount,
name?: string, name?: string,
delegate?: PublicKey, delegate?: PublicKey,
): Promise<TransactionSignature> { ): Promise<TransactionSignature> {
@ -450,6 +453,7 @@ export class MangoClient {
.editAccount(name, delegate) .editAccount(name, delegate)
.accounts({ .accounts({
group: group.publicKey, group: group.publicKey,
account: mangoAccount.publicKey,
owner: (this.program.provider as AnchorProvider).wallet.publicKey, owner: (this.program.provider as AnchorProvider).wallet.publicKey,
}) })
.rpc(); .rpc();
@ -471,13 +475,13 @@ export class MangoClient {
{ {
memcmp: { memcmp: {
bytes: group.publicKey.toBase58(), bytes: group.publicKey.toBase58(),
offset: 40, offset: 8,
}, },
}, },
{ {
memcmp: { memcmp: {
bytes: ownerPk.toBase58(), bytes: ownerPk.toBase58(),
offset: 72, offset: 40,
}, },
}, },
]) ])
@ -724,7 +728,7 @@ export class MangoClient {
{ {
memcmp: { memcmp: {
bytes: group.publicKey.toBase58(), bytes: group.publicKey.toBase58(),
offset: 24, offset: 8,
}, },
}, },
]; ];
@ -735,7 +739,7 @@ export class MangoClient {
filters.push({ filters.push({
memcmp: { memcmp: {
bytes: bs58.encode(bbuf), bytes: bs58.encode(bbuf),
offset: 122, offset: 40,
}, },
}); });
} }
@ -746,7 +750,7 @@ export class MangoClient {
filters.push({ filters.push({
memcmp: { memcmp: {
bytes: bs58.encode(qbuf), 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? } as any, // future: nested custom types dont typecheck, fix if possible?
baseTokenIndex, baseTokenIndex,
baseTokenDecimals, baseTokenDecimals,
quoteTokenIndex,
new BN(quoteLotSize), new BN(quoteLotSize),
new BN(baseLotSize), new BN(baseLotSize),
maintAssetWeight, maintAssetWeight,
@ -1188,7 +1191,6 @@ export class MangoClient {
public async perpGetMarkets( public async perpGetMarkets(
group: Group, group: Group,
baseTokenIndex?: number, baseTokenIndex?: number,
quoteTokenIndex?: number,
): Promise<PerpMarket[]> { ): Promise<PerpMarket[]> {
const bumpfbuf = Buffer.alloc(1); const bumpfbuf = Buffer.alloc(1);
bumpfbuf.writeUInt8(255); bumpfbuf.writeUInt8(255);
@ -1197,7 +1199,7 @@ export class MangoClient {
{ {
memcmp: { memcmp: {
bytes: group.publicKey.toBase58(), bytes: group.publicKey.toBase58(),
offset: 24, offset: 8,
}, },
}, },
]; ];
@ -1208,18 +1210,7 @@ export class MangoClient {
filters.push({ filters.push({
memcmp: { memcmp: {
bytes: bs58.encode(bbuf), bytes: bs58.encode(bbuf),
offset: 444, offset: 40,
},
});
}
if (quoteTokenIndex) {
const qbuf = Buffer.alloc(2);
qbuf.writeUInt16LE(quoteTokenIndex);
filters.push({
memcmp: {
bytes: bs58.encode(qbuf),
offset: 446,
}, },
}); });
} }

View File

@ -1953,10 +1953,6 @@ export type MangoV4 = {
"name": "baseTokenDecimals", "name": "baseTokenDecimals",
"type": "u8" "type": "u8"
}, },
{
"name": "quoteTokenIndex",
"type": "u16"
},
{ {
"name": "quoteLotSize", "name": "quoteLotSize",
"type": "i64" "type": "i64"
@ -2496,6 +2492,10 @@ export type MangoV4 = {
"type": { "type": {
"kind": "struct", "kind": "struct",
"fields": [ "fields": [
{
"name": "group",
"type": "publicKey"
},
{ {
"name": "name", "name": "name",
"type": { "type": {
@ -2505,10 +2505,6 @@ export type MangoV4 = {
] ]
} }
}, },
{
"name": "group",
"type": "publicKey"
},
{ {
"name": "mint", "name": "mint",
"type": "publicKey" "type": "publicKey"
@ -2696,6 +2692,19 @@ export type MangoV4 = {
"name": "admin", "name": "admin",
"type": "publicKey" "type": "publicKey"
}, },
{
"name": "groupNum",
"type": "u32"
},
{
"name": "padding",
"type": {
"array": [
"u8",
4
]
}
},
{ {
"name": "insuranceVault", "name": "insuranceVault",
"type": "publicKey" "type": "publicKey"
@ -2704,10 +2713,6 @@ export type MangoV4 = {
"name": "insuranceMint", "name": "insuranceMint",
"type": "publicKey" "type": "publicKey"
}, },
{
"name": "groupNum",
"type": "u32"
},
{ {
"name": "bump", "name": "bump",
"type": "u8" "type": "u8"
@ -2721,7 +2726,7 @@ export type MangoV4 = {
"type": { "type": {
"array": [ "array": [
"u8", "u8",
2 6
] ]
} }
}, },
@ -2742,6 +2747,14 @@ export type MangoV4 = {
"type": { "type": {
"kind": "struct", "kind": "struct",
"fields": [ "fields": [
{
"name": "group",
"type": "publicKey"
},
{
"name": "owner",
"type": "publicKey"
},
{ {
"name": "name", "name": "name",
"type": { "type": {
@ -2751,14 +2764,6 @@ export type MangoV4 = {
] ]
} }
}, },
{
"name": "group",
"type": "publicKey"
},
{
"name": "owner",
"type": "publicKey"
},
{ {
"name": "delegate", "name": "delegate",
"type": "publicKey" "type": "publicKey"
@ -2818,6 +2823,19 @@ export type MangoV4 = {
"name": "group", "name": "group",
"type": "publicKey" "type": "publicKey"
}, },
{
"name": "tokenIndex",
"type": "u16"
},
{
"name": "padding",
"type": {
"array": [
"u8",
6
]
}
},
{ {
"name": "mint", "name": "mint",
"type": "publicKey" "type": "publicKey"
@ -2848,10 +2866,6 @@ export type MangoV4 = {
"name": "addressLookupTable", "name": "addressLookupTable",
"type": "publicKey" "type": "publicKey"
}, },
{
"name": "tokenIndex",
"type": "u16"
},
{ {
"name": "addressLookupTableBankIndex", "name": "addressLookupTableBankIndex",
"type": "u8" "type": "u8"
@ -2865,7 +2879,7 @@ export type MangoV4 = {
"type": { "type": {
"array": [ "array": [
"u8", "u8",
4 6
] ]
} }
} }
@ -2991,6 +3005,27 @@ export type MangoV4 = {
"type": { "type": {
"kind": "struct", "kind": "struct",
"fields": [ "fields": [
{
"name": "group",
"type": "publicKey"
},
{
"name": "baseTokenIndex",
"type": "u16"
},
{
"name": "perpMarketIndex",
"type": "u16"
},
{
"name": "padding",
"type": {
"array": [
"u8",
4
]
}
},
{ {
"name": "name", "name": "name",
"type": { "type": {
@ -3000,10 +3035,6 @@ export type MangoV4 = {
] ]
} }
}, },
{
"name": "group",
"type": "publicKey"
},
{ {
"name": "oracle", "name": "oracle",
"type": "publicKey" "type": "publicKey"
@ -3131,16 +3162,13 @@ export type MangoV4 = {
"type": "u8" "type": "u8"
}, },
{ {
"name": "perpMarketIndex", "name": "reserved",
"type": "u16" "type": {
}, "array": [
{ "u8",
"name": "baseTokenIndex", 6
"type": "u16" ]
}, }
{
"name": "quoteTokenIndex",
"type": "u16"
} }
] ]
} }
@ -3150,6 +3178,27 @@ export type MangoV4 = {
"type": { "type": {
"kind": "struct", "kind": "struct",
"fields": [ "fields": [
{
"name": "group",
"type": "publicKey"
},
{
"name": "baseTokenIndex",
"type": "u16"
},
{
"name": "quoteTokenIndex",
"type": "u16"
},
{
"name": "padding",
"type": {
"array": [
"u8",
4
]
}
},
{ {
"name": "name", "name": "name",
"type": { "type": {
@ -3159,10 +3208,6 @@ export type MangoV4 = {
] ]
} }
}, },
{
"name": "group",
"type": "publicKey"
},
{ {
"name": "serumProgram", "name": "serumProgram",
"type": "publicKey" "type": "publicKey"
@ -3175,14 +3220,6 @@ export type MangoV4 = {
"name": "marketIndex", "name": "marketIndex",
"type": "u16" "type": "u16"
}, },
{
"name": "baseTokenIndex",
"type": "u16"
},
{
"name": "quoteTokenIndex",
"type": "u16"
},
{ {
"name": "bump", "name": "bump",
"type": "u8" "type": "u8"
@ -3192,7 +3229,7 @@ export type MangoV4 = {
"type": { "type": {
"array": [ "array": [
"u8", "u8",
1 5
] ]
} }
} }
@ -6444,10 +6481,6 @@ export const IDL: MangoV4 = {
"name": "baseTokenDecimals", "name": "baseTokenDecimals",
"type": "u8" "type": "u8"
}, },
{
"name": "quoteTokenIndex",
"type": "u16"
},
{ {
"name": "quoteLotSize", "name": "quoteLotSize",
"type": "i64" "type": "i64"
@ -6987,6 +7020,10 @@ export const IDL: MangoV4 = {
"type": { "type": {
"kind": "struct", "kind": "struct",
"fields": [ "fields": [
{
"name": "group",
"type": "publicKey"
},
{ {
"name": "name", "name": "name",
"type": { "type": {
@ -6996,10 +7033,6 @@ export const IDL: MangoV4 = {
] ]
} }
}, },
{
"name": "group",
"type": "publicKey"
},
{ {
"name": "mint", "name": "mint",
"type": "publicKey" "type": "publicKey"
@ -7187,6 +7220,19 @@ export const IDL: MangoV4 = {
"name": "admin", "name": "admin",
"type": "publicKey" "type": "publicKey"
}, },
{
"name": "groupNum",
"type": "u32"
},
{
"name": "padding",
"type": {
"array": [
"u8",
4
]
}
},
{ {
"name": "insuranceVault", "name": "insuranceVault",
"type": "publicKey" "type": "publicKey"
@ -7195,10 +7241,6 @@ export const IDL: MangoV4 = {
"name": "insuranceMint", "name": "insuranceMint",
"type": "publicKey" "type": "publicKey"
}, },
{
"name": "groupNum",
"type": "u32"
},
{ {
"name": "bump", "name": "bump",
"type": "u8" "type": "u8"
@ -7212,7 +7254,7 @@ export const IDL: MangoV4 = {
"type": { "type": {
"array": [ "array": [
"u8", "u8",
2 6
] ]
} }
}, },
@ -7233,6 +7275,14 @@ export const IDL: MangoV4 = {
"type": { "type": {
"kind": "struct", "kind": "struct",
"fields": [ "fields": [
{
"name": "group",
"type": "publicKey"
},
{
"name": "owner",
"type": "publicKey"
},
{ {
"name": "name", "name": "name",
"type": { "type": {
@ -7242,14 +7292,6 @@ export const IDL: MangoV4 = {
] ]
} }
}, },
{
"name": "group",
"type": "publicKey"
},
{
"name": "owner",
"type": "publicKey"
},
{ {
"name": "delegate", "name": "delegate",
"type": "publicKey" "type": "publicKey"
@ -7309,6 +7351,19 @@ export const IDL: MangoV4 = {
"name": "group", "name": "group",
"type": "publicKey" "type": "publicKey"
}, },
{
"name": "tokenIndex",
"type": "u16"
},
{
"name": "padding",
"type": {
"array": [
"u8",
6
]
}
},
{ {
"name": "mint", "name": "mint",
"type": "publicKey" "type": "publicKey"
@ -7339,10 +7394,6 @@ export const IDL: MangoV4 = {
"name": "addressLookupTable", "name": "addressLookupTable",
"type": "publicKey" "type": "publicKey"
}, },
{
"name": "tokenIndex",
"type": "u16"
},
{ {
"name": "addressLookupTableBankIndex", "name": "addressLookupTableBankIndex",
"type": "u8" "type": "u8"
@ -7356,7 +7407,7 @@ export const IDL: MangoV4 = {
"type": { "type": {
"array": [ "array": [
"u8", "u8",
4 6
] ]
} }
} }
@ -7482,6 +7533,27 @@ export const IDL: MangoV4 = {
"type": { "type": {
"kind": "struct", "kind": "struct",
"fields": [ "fields": [
{
"name": "group",
"type": "publicKey"
},
{
"name": "baseTokenIndex",
"type": "u16"
},
{
"name": "perpMarketIndex",
"type": "u16"
},
{
"name": "padding",
"type": {
"array": [
"u8",
4
]
}
},
{ {
"name": "name", "name": "name",
"type": { "type": {
@ -7491,10 +7563,6 @@ export const IDL: MangoV4 = {
] ]
} }
}, },
{
"name": "group",
"type": "publicKey"
},
{ {
"name": "oracle", "name": "oracle",
"type": "publicKey" "type": "publicKey"
@ -7622,16 +7690,13 @@ export const IDL: MangoV4 = {
"type": "u8" "type": "u8"
}, },
{ {
"name": "perpMarketIndex", "name": "reserved",
"type": "u16" "type": {
}, "array": [
{ "u8",
"name": "baseTokenIndex", 6
"type": "u16" ]
}, }
{
"name": "quoteTokenIndex",
"type": "u16"
} }
] ]
} }
@ -7641,6 +7706,27 @@ export const IDL: MangoV4 = {
"type": { "type": {
"kind": "struct", "kind": "struct",
"fields": [ "fields": [
{
"name": "group",
"type": "publicKey"
},
{
"name": "baseTokenIndex",
"type": "u16"
},
{
"name": "quoteTokenIndex",
"type": "u16"
},
{
"name": "padding",
"type": {
"array": [
"u8",
4
]
}
},
{ {
"name": "name", "name": "name",
"type": { "type": {
@ -7650,10 +7736,6 @@ export const IDL: MangoV4 = {
] ]
} }
}, },
{
"name": "group",
"type": "publicKey"
},
{ {
"name": "serumProgram", "name": "serumProgram",
"type": "publicKey" "type": "publicKey"
@ -7666,14 +7748,6 @@ export const IDL: MangoV4 = {
"name": "marketIndex", "name": "marketIndex",
"type": "u16" "type": "u16"
}, },
{
"name": "baseTokenIndex",
"type": "u16"
},
{
"name": "quoteTokenIndex",
"type": "u16"
},
{ {
"name": "bump", "name": "bump",
"type": "u8" "type": "u8"
@ -7683,7 +7757,7 @@ export const IDL: MangoV4 = {
"type": { "type": {
"array": [ "array": [
"u8", "u8",
1 5
] ]
} }
} }

View File

@ -53,15 +53,16 @@ async function main() {
// group // group
console.log(`Creating Group...`); console.log(`Creating Group...`);
const insuranceMint = new PublicKey(DEVNET_MINTS.get('USDC')!);
try { try {
await client.createGroup(0, true); await client.createGroup(0, true, insuranceMint);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
const group = await client.getGroupForAdmin(admin.publicKey); const group = await client.getGroupForAdmin(admin.publicKey);
console.log(`...registered group ${group.publicKey}`); console.log(`...registered group ${group.publicKey}`);
// register token 0 // register token 1
console.log(`Registering BTC...`); console.log(`Registering BTC...`);
const btcDevnetMint = new PublicKey(DEVNET_MINTS.get('BTC')!); const btcDevnetMint = new PublicKey(DEVNET_MINTS.get('BTC')!);
const btcDevnetOracle = new PublicKey(DEVNET_ORACLES.get('BTC')!); const btcDevnetOracle = new PublicKey(DEVNET_ORACLES.get('BTC')!);
@ -71,7 +72,7 @@ async function main() {
btcDevnetMint, btcDevnetMint,
btcDevnetOracle, btcDevnetOracle,
0.1, 0.1,
0, 1, // tokenIndex
'BTC', 'BTC',
0.4, 0.4,
0.07, 0.07,
@ -91,7 +92,7 @@ async function main() {
console.log(error); console.log(error);
} }
// stub oracle + register token 1 // stub oracle + register token 0
console.log(`Registering USDC...`); console.log(`Registering USDC...`);
const usdcDevnetMint = new PublicKey(DEVNET_MINTS.get('USDC')!); const usdcDevnetMint = new PublicKey(DEVNET_MINTS.get('USDC')!);
try { try {
@ -109,7 +110,7 @@ async function main() {
usdcDevnetMint, usdcDevnetMint,
usdcDevnetOracle.publicKey, usdcDevnetOracle.publicKey,
0.1, 0.1,
1, 0, // tokenIndex
'USDC', 'USDC',
0.4, 0.4,
0.07, 0.07,
@ -228,7 +229,7 @@ async function main() {
0, 0,
'BTC-PERP', 'BTC-PERP',
0.1, 0.1,
0, 1,
6, 6,
1, 1,
10, 10,
@ -251,7 +252,6 @@ async function main() {
const perpMarkets = await client.perpGetMarkets( const perpMarkets = await client.perpGetMarkets(
group, group,
group.banksMap.get('BTC')?.tokenIndex, group.banksMap.get('BTC')?.tokenIndex,
group.banksMap.get('USDC')?.tokenIndex,
); );
console.log(`...created perp market ${perpMarkets[0].publicKey}`); console.log(`...created perp market ${perpMarkets[0].publicKey}`);
@ -319,7 +319,7 @@ async function main() {
'BTC-PERP', 'BTC-PERP',
btcDevnetOracle, btcDevnetOracle,
0.2, 0.2,
1, 0,
6, 6,
0.9, 0.9,
0.9, 0.9,
@ -345,7 +345,7 @@ async function main() {
'BTC-PERP', 'BTC-PERP',
btcDevnetOracle, btcDevnetOracle,
0.1, 0.1,
0, 1,
6, 6,
1, 1,
0.95, 0.95,

View File

@ -67,12 +67,12 @@ async function main() {
const randomKey = new PublicKey( const randomKey = new PublicKey(
'4ZkS7ZZkxfsC3GtvvsHP3DFcUeByU9zzZELS4r8HCELo', '4ZkS7ZZkxfsC3GtvvsHP3DFcUeByU9zzZELS4r8HCELo',
); );
await client.editMangoAccount(group, 'my_changed_name', randomKey); await client.editMangoAccount(group, mangoAccount, 'my_changed_name', randomKey);
await mangoAccount.reload(client, group); await mangoAccount.reload(client, group);
console.log(mangoAccount.toString()); console.log(mangoAccount.toString());
console.log(`...resetting mango account name, and re-setting a delegate`); 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); await mangoAccount.reload(client, group);
console.log(mangoAccount.toString()); console.log(mangoAccount.toString());
} }

View File

@ -12,4 +12,4 @@ anchor build --skip-lint
# update types in ts client package # update types in ts client package
cp -v ./target/types/mango_v4.ts ./ts/client/src/mango_v4.ts cp -v ./target/types/mango_v4.ts ./ts/client/src/mango_v4.ts
(cd ./ts/client && tsc) (cd ./ts/client && yarn tsc)