Skip to content

Commit

Permalink
Skip globals in balance checker
Browse files Browse the repository at this point in the history
  • Loading branch information
brittcyr committed Dec 11, 2024
1 parent 53f44b7 commit 2c8a044
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-balance-checker.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Balance Checker
on:
schedule:
- cron: "0 * * * *"
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
Expand Down
10 changes: 9 additions & 1 deletion client/ts/src/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,23 @@ export class Market {
const bids: RestingOrder[] = this.bids();

const quoteOpenOrdersBalanceAtoms: number = bids
.filter((restingOrder: RestingOrder) => {
return restingOrder.orderType != OrderType.Global

Check failure on line 255 in client/ts/src/market.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing semicolon
})
.map((restingOrder: RestingOrder) => {
return Math.ceil(
Number(restingOrder.numBaseTokens) *
restingOrder.tokenPrice *
10 ** this.data.quoteMintDecimals,
10 ** this.data.quoteMintDecimals
// Force float precision to not round up on an integer.
- .00001
);
})
.reduce((sum, current) => sum + current, 0);
const baseOpenOrdersBalanceAtoms: number = asks
.filter((restingOrder: RestingOrder) => {
return restingOrder.orderType != OrderType.Global

Check failure on line 269 in client/ts/src/market.ts

View workflow job for this annotation

GitHub Actions / Lint

Missing semicolon
})
.map((restingOrder: RestingOrder) => {
return (
Number(restingOrder.numBaseTokens) * 10 ** this.data.baseMintDecimals
Expand Down
14 changes: 12 additions & 2 deletions debug-ui/scripts/balance-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const run = async () => {
const marketPks: PublicKey[] =
await ManifestClient.listMarketPublicKeys(connection);

let foundMismatch: boolean = false;
for (const marketPk of marketPks) {
const client: ManifestClient = await ManifestClient.getClientReadOnly(
connection,
Expand Down Expand Up @@ -61,9 +62,10 @@ const run = async () => {
const quoteExpectedAtoms: number =
quoteWithdrawableBalanceAtoms + quoteOpenOrdersBalanceAtoms;

// Allow small difference because of javascript rounding.
if (
baseExpectedAtoms != baseVaultBalanceAtoms ||
quoteExpectedAtoms != quoteVaultBalanceAtoms
Math.abs(baseExpectedAtoms - baseVaultBalanceAtoms) > 1 ||
Math.abs(quoteExpectedAtoms - quoteVaultBalanceAtoms) > 1
) {
console.log('Market', marketPk.toBase58());
console.log(
Expand All @@ -83,9 +85,17 @@ const run = async () => {
'difference',
quoteVaultBalanceAtoms -
(quoteWithdrawableBalanceAtoms + quoteOpenOrdersBalanceAtoms),
'withdrawable',
quoteWithdrawableBalanceAtoms,
'open orders',
quoteOpenOrdersBalanceAtoms,
);
foundMismatch = true;
}
}
if (foundMismatch) {
throw new Error();
}
};

run().catch((e) => {
Expand Down

0 comments on commit 2c8a044

Please sign in to comment.