diff --git a/mango_v4.json b/mango_v4.json index df00c019d0..838a9c09e1 100644 --- a/mango_v4.json +++ b/mango_v4.json @@ -1786,7 +1786,7 @@ "args": [ { "name": "expectedSequenceNumber", - "type": "u64" + "type": "u8" } ] }, @@ -7901,13 +7901,8 @@ "type": "u8" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 1 - ] - } + "name": "sequenceNumber", + "type": "u8" }, { "name": "netDeposits", @@ -7972,16 +7967,12 @@ ], "type": "u64" }, - { - "name": "sequenceNumber", - "type": "u64" - }, { "name": "reserved", "type": { "array": [ "u8", - 144 + 152 ] } }, @@ -9703,13 +9694,8 @@ "type": "u8" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 1 - ] - } + "name": "sequenceNumber", + "type": "u8" }, { "name": "netDeposits", @@ -9755,16 +9741,12 @@ "name": "lastCollateralFeeCharge", "type": "u64" }, - { - "name": "sequenceNumber", - "type": "u64" - }, { "name": "reserved", "type": { "array": [ "u8", - 144 + 152 ] } } diff --git a/programs/mango-v4/src/instructions/sequence_check.rs b/programs/mango-v4/src/instructions/sequence_check.rs index e42d042ac0..1f59ca59a2 100644 --- a/programs/mango-v4/src/instructions/sequence_check.rs +++ b/programs/mango-v4/src/instructions/sequence_check.rs @@ -4,7 +4,7 @@ use crate::accounts_ix::*; use crate::error::MangoError; use crate::state::*; -pub fn sequence_check(ctx: Context, expected_sequence_number: u64) -> Result<()> { +pub fn sequence_check(ctx: Context, expected_sequence_number: u8) -> Result<()> { let mut account = ctx.accounts.account.load_full_mut()?; require_eq!( diff --git a/programs/mango-v4/src/lib.rs b/programs/mango-v4/src/lib.rs index 963ad0dbc1..9cd90db82c 100644 --- a/programs/mango-v4/src/lib.rs +++ b/programs/mango-v4/src/lib.rs @@ -458,10 +458,7 @@ pub mod mango_v4 { Ok(()) } - pub fn sequence_check( - ctx: Context, - expected_sequence_number: u64, - ) -> Result<()> { + pub fn sequence_check(ctx: Context, expected_sequence_number: u8) -> Result<()> { #[cfg(feature = "enable-gpl")] instructions::sequence_check(ctx, expected_sequence_number)?; Ok(()) diff --git a/programs/mango-v4/src/state/mango_account.rs b/programs/mango-v4/src/state/mango_account.rs index 0f62764919..d5b13c2aaf 100644 --- a/programs/mango-v4/src/state/mango_account.rs +++ b/programs/mango-v4/src/state/mango_account.rs @@ -123,8 +123,7 @@ pub struct MangoAccount { pub bump: u8, - #[derivative(Debug = "ignore")] - pub padding: [u8; 1], + pub sequence_number: u8, // (Display only) // Cumulative (deposits - withdraws) @@ -157,10 +156,8 @@ pub struct MangoAccount { /// Time at which the last collateral fee was charged pub last_collateral_fee_charge: u64, - pub sequence_number: u64, - #[derivative(Debug = "ignore")] - pub reserved: [u8; 144], + pub reserved: [u8; 152], // dynamic pub header_version: u8, @@ -202,7 +199,7 @@ impl MangoAccount { in_health_region: 0, account_num: 0, bump: 0, - padding: Default::default(), + sequence_number: 0, net_deposits: 0, perp_spot_transfers: 0, health_region_begin_init_health: 0, @@ -214,8 +211,7 @@ impl MangoAccount { temporary_delegate: Pubkey::default(), temporary_delegate_expiry: 0, last_collateral_fee_charge: 0, - sequence_number: 0, - reserved: [0; 144], + reserved: [0; 152], header_version: DEFAULT_MANGO_ACCOUNT_VERSION, padding3: Default::default(), padding4: Default::default(), @@ -328,7 +324,7 @@ pub struct MangoAccountFixed { being_liquidated: u8, in_health_region: u8, pub bump: u8, - pub padding: [u8; 1], + pub sequence_number: u8, pub net_deposits: i64, pub perp_spot_transfers: i64, pub health_region_begin_init_health: i64, @@ -340,12 +336,11 @@ pub struct MangoAccountFixed { pub temporary_delegate: Pubkey, pub temporary_delegate_expiry: u64, pub last_collateral_fee_charge: u64, - pub sequence_number: u64, - pub reserved: [u8; 144], + pub reserved: [u8; 152], } const_assert_eq!( size_of::(), - 32 * 4 + 8 + 8 * 8 + 32 + 8 + 8 + 8 + 144 + 32 * 4 + 8 + 8 * 8 + 32 + 8 + 8 + 152 ); const_assert_eq!(size_of::(), 400); const_assert_eq!(size_of::() % 8, 0); @@ -2901,7 +2896,7 @@ mod tests { being_liquidated: fixed.being_liquidated, in_health_region: fixed.in_health_region, bump: fixed.bump, - padding: Default::default(), + sequence_number: 0, net_deposits: fixed.net_deposits, perp_spot_transfers: fixed.perp_spot_transfers, health_region_begin_init_health: fixed.health_region_begin_init_health, @@ -2913,8 +2908,7 @@ mod tests { temporary_delegate: fixed.temporary_delegate, temporary_delegate_expiry: fixed.temporary_delegate_expiry, last_collateral_fee_charge: fixed.last_collateral_fee_charge, - sequence_number: 0, - reserved: [0u8; 144], + reserved: [0u8; 152], header_version: *zerocopy_reader.header_version(), padding3: Default::default(), diff --git a/programs/mango-v4/tests/program_test/mango_client.rs b/programs/mango-v4/tests/program_test/mango_client.rs index 6e2d29250d..3aff8bb811 100644 --- a/programs/mango-v4/tests/program_test/mango_client.rs +++ b/programs/mango-v4/tests/program_test/mango_client.rs @@ -5144,7 +5144,7 @@ impl ClientInstruction for TokenChargeCollateralFeesInstruction { pub struct SequenceCheckInstruction { pub account: Pubkey, pub owner: TestKeypair, - pub expected_sequence_number: u64, + pub expected_sequence_number: u8, } #[async_trait::async_trait(?Send)] impl ClientInstruction for SequenceCheckInstruction { diff --git a/ts/client/src/accounts/mangoAccount.spec.ts b/ts/client/src/accounts/mangoAccount.spec.ts index 6f92295b72..40510eca1f 100644 --- a/ts/client/src/accounts/mangoAccount.spec.ts +++ b/ts/client/src/accounts/mangoAccount.spec.ts @@ -23,7 +23,7 @@ describe('Mango Account', () => { new BN(0), new BN(0), new BN(0), - new BN(0), + 0, 0, [], [], diff --git a/ts/client/src/accounts/mangoAccount.ts b/ts/client/src/accounts/mangoAccount.ts index a0344e5212..2b81778f27 100644 --- a/ts/client/src/accounts/mangoAccount.ts +++ b/ts/client/src/accounts/mangoAccount.ts @@ -44,7 +44,7 @@ export class MangoAccount { buybackFeesAccruedCurrent: BN; buybackFeesAccruedPrevious: BN; buybackFeesExpiryTimestamp: BN; - sequenceNumber: BN; + sequenceNumber: number; headerVersion: number; tokens: unknown; serum3: unknown; @@ -96,7 +96,7 @@ export class MangoAccount { public buybackFeesAccruedCurrent: BN, public buybackFeesAccruedPrevious: BN, public buybackFeesExpiryTimestamp: BN, - public sequenceNumber: BN, + public sequenceNumber: number, public headerVersion: number, tokens: TokenPositionDto[], serum3: Serum3PositionDto[], diff --git a/ts/client/src/mango_v4.ts b/ts/client/src/mango_v4.ts index 49a37b2a3d..b56bc82b5a 100644 --- a/ts/client/src/mango_v4.ts +++ b/ts/client/src/mango_v4.ts @@ -1786,7 +1786,7 @@ export type MangoV4 = { "args": [ { "name": "expectedSequenceNumber", - "type": "u64" + "type": "u8" } ] }, @@ -7901,13 +7901,8 @@ export type MangoV4 = { "type": "u8" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 1 - ] - } + "name": "sequenceNumber", + "type": "u8" }, { "name": "netDeposits", @@ -7972,16 +7967,12 @@ export type MangoV4 = { ], "type": "u64" }, - { - "name": "sequenceNumber", - "type": "u64" - }, { "name": "reserved", "type": { "array": [ "u8", - 144 + 152 ] } }, @@ -9703,13 +9694,8 @@ export type MangoV4 = { "type": "u8" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 1 - ] - } + "name": "sequenceNumber", + "type": "u8" }, { "name": "netDeposits", @@ -9755,16 +9741,12 @@ export type MangoV4 = { "name": "lastCollateralFeeCharge", "type": "u64" }, - { - "name": "sequenceNumber", - "type": "u64" - }, { "name": "reserved", "type": { "array": [ "u8", - 144 + 152 ] } } @@ -16190,7 +16172,7 @@ export const IDL: MangoV4 = { "args": [ { "name": "expectedSequenceNumber", - "type": "u64" + "type": "u8" } ] }, @@ -22305,13 +22287,8 @@ export const IDL: MangoV4 = { "type": "u8" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 1 - ] - } + "name": "sequenceNumber", + "type": "u8" }, { "name": "netDeposits", @@ -22376,16 +22353,12 @@ export const IDL: MangoV4 = { ], "type": "u64" }, - { - "name": "sequenceNumber", - "type": "u64" - }, { "name": "reserved", "type": { "array": [ "u8", - 144 + 152 ] } }, @@ -24107,13 +24080,8 @@ export const IDL: MangoV4 = { "type": "u8" }, { - "name": "padding", - "type": { - "array": [ - "u8", - 1 - ] - } + "name": "sequenceNumber", + "type": "u8" }, { "name": "netDeposits", @@ -24159,16 +24127,12 @@ export const IDL: MangoV4 = { "name": "lastCollateralFeeCharge", "type": "u64" }, - { - "name": "sequenceNumber", - "type": "u64" - }, { "name": "reserved", "type": { "array": [ "u8", - 144 + 152 ] } }