Skip to content

Commit

Permalink
ts client: add sequence check instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
farnyser committed Mar 7, 2024
1 parent b7f6cb1 commit 5fc7294
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 6 deletions.
55 changes: 53 additions & 2 deletions mango_v4.json
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,36 @@
}
]
},
{
"name": "sequenceCheck",
"accounts": [
{
"name": "group",
"isMut": false,
"isSigner": false
},
{
"name": "account",
"isMut": true,
"isSigner": false,
"relations": [
"group",
"owner"
]
},
{
"name": "owner",
"isMut": false,
"isSigner": true
}
],
"args": [
{
"name": "expectedSequenceNumber",
"type": "u64"
}
]
},
{
"name": "stubOracleCreate",
"accounts": [
Expand Down Expand Up @@ -7942,12 +7972,16 @@
],
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
152
144
]
}
},
Expand Down Expand Up @@ -9721,12 +9755,16 @@
"name": "lastCollateralFeeCharge",
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
152
144
]
}
}
Expand Down Expand Up @@ -11008,6 +11046,9 @@
},
{
"name": "TokenForceWithdraw"
},
{
"name": "SequenceCheck"
}
]
}
Expand Down Expand Up @@ -14350,6 +14391,16 @@
"code": 6069,
"name": "TokenAssetLiquidationDisabled",
"msg": "the asset does not allow liquidation"
},
{
"code": 6070,
"name": "BorrowsRequireHealthAccountBank",
"msg": "for borrows the bank must be in the health account list"
},
{
"code": 6071,
"name": "InvalidSequenceNumber",
"msg": "invalid sequence number"
}
]
}
1 change: 1 addition & 0 deletions ts/client/src/accounts/mangoAccount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ describe('Mango Account', () => {
new BN(0),
new BN(0),
new BN(0),
new BN(0),
0,
[],
[],
Expand Down
3 changes: 3 additions & 0 deletions ts/client/src/accounts/mangoAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class MangoAccount {
buybackFeesAccruedCurrent: BN;
buybackFeesAccruedPrevious: BN;
buybackFeesExpiryTimestamp: BN;
sequenceNumber: BN;
headerVersion: number;
tokens: unknown;
serum3: unknown;
Expand All @@ -68,6 +69,7 @@ export class MangoAccount {
obj.buybackFeesAccruedCurrent,
obj.buybackFeesAccruedPrevious,
obj.buybackFeesExpiryTimestamp,
obj.sequenceNumber,
obj.headerVersion,
obj.tokens as TokenPositionDto[],
obj.serum3 as Serum3PositionDto[],
Expand All @@ -94,6 +96,7 @@ export class MangoAccount {
public buybackFeesAccruedCurrent: BN,
public buybackFeesAccruedPrevious: BN,
public buybackFeesExpiryTimestamp: BN,
public sequenceNumber: BN,
public headerVersion: number,
tokens: TokenPositionDto[],
serum3: Serum3PositionDto[],
Expand Down
16 changes: 16 additions & 0 deletions ts/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,22 @@ export class MangoClient {
return await this.sendAndConfirmTransactionForGroup(group, [ix]);
}

public async sequenceCheck(
group: Group,
mangoAccount: MangoAccount,
): Promise<MangoSignatureStatus> {
const ix = await this.program.methods
.sequenceCheck(mangoAccount.sequenceNumber)
.accounts({
group: group.publicKey,
account: mangoAccount.publicKey,
owner: (this.program.provider as AnchorProvider).wallet.publicKey,
})
.instruction();

return await this.sendAndConfirmTransactionForGroup(group, [ix]);
}

public async getMangoAccount(
mangoAccountPk: PublicKey,
loadSerum3Oo = false,
Expand Down
110 changes: 106 additions & 4 deletions ts/client/src/mango_v4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,36 @@ export type MangoV4 = {
}
]
},
{
"name": "sequenceCheck",
"accounts": [
{
"name": "group",
"isMut": false,
"isSigner": false
},
{
"name": "account",
"isMut": true,
"isSigner": false,
"relations": [
"group",
"owner"
]
},
{
"name": "owner",
"isMut": false,
"isSigner": true
}
],
"args": [
{
"name": "expectedSequenceNumber",
"type": "u64"
}
]
},
{
"name": "stubOracleCreate",
"accounts": [
Expand Down Expand Up @@ -7942,12 +7972,16 @@ export type MangoV4 = {
],
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
152
144
]
}
},
Expand Down Expand Up @@ -9721,12 +9755,16 @@ export type MangoV4 = {
"name": "lastCollateralFeeCharge",
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
152
144
]
}
}
Expand Down Expand Up @@ -11008,6 +11046,9 @@ export type MangoV4 = {
},
{
"name": "TokenForceWithdraw"
},
{
"name": "SequenceCheck"
}
]
}
Expand Down Expand Up @@ -14350,6 +14391,16 @@ export type MangoV4 = {
"code": 6069,
"name": "TokenAssetLiquidationDisabled",
"msg": "the asset does not allow liquidation"
},
{
"code": 6070,
"name": "BorrowsRequireHealthAccountBank",
"msg": "for borrows the bank must be in the health account list"
},
{
"code": 6071,
"name": "InvalidSequenceNumber",
"msg": "invalid sequence number"
}
]
};
Expand Down Expand Up @@ -16116,6 +16167,36 @@ export const IDL: MangoV4 = {
}
]
},
{
"name": "sequenceCheck",
"accounts": [
{
"name": "group",
"isMut": false,
"isSigner": false
},
{
"name": "account",
"isMut": true,
"isSigner": false,
"relations": [
"group",
"owner"
]
},
{
"name": "owner",
"isMut": false,
"isSigner": true
}
],
"args": [
{
"name": "expectedSequenceNumber",
"type": "u64"
}
]
},
{
"name": "stubOracleCreate",
"accounts": [
Expand Down Expand Up @@ -22298,12 +22379,16 @@ export const IDL: MangoV4 = {
],
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
152
144
]
}
},
Expand Down Expand Up @@ -24077,12 +24162,16 @@ export const IDL: MangoV4 = {
"name": "lastCollateralFeeCharge",
"type": "u64"
},
{
"name": "sequenceNumber",
"type": "u64"
},
{
"name": "reserved",
"type": {
"array": [
"u8",
152
144
]
}
}
Expand Down Expand Up @@ -25364,6 +25453,9 @@ export const IDL: MangoV4 = {
},
{
"name": "TokenForceWithdraw"
},
{
"name": "SequenceCheck"
}
]
}
Expand Down Expand Up @@ -28706,6 +28798,16 @@ export const IDL: MangoV4 = {
"code": 6069,
"name": "TokenAssetLiquidationDisabled",
"msg": "the asset does not allow liquidation"
},
{
"code": 6070,
"name": "BorrowsRequireHealthAccountBank",
"msg": "for borrows the bank must be in the health account list"
},
{
"code": 6071,
"name": "InvalidSequenceNumber",
"msg": "invalid sequence number"
}
]
};

0 comments on commit 5fc7294

Please sign in to comment.