diff --git a/.github/workflows/ci-balance-checker.yml b/.github/workflows/ci-balance-checker.yml index cdb850a32..11fb9a127 100644 --- a/.github/workflows/ci-balance-checker.yml +++ b/.github/workflows/ci-balance-checker.yml @@ -1,7 +1,7 @@ name: Balance Checker on: schedule: - - cron: "0 * * * *" + - cron: "0 0 * * *" workflow_dispatch: jobs: diff --git a/client/ts/src/market.ts b/client/ts/src/market.ts index b5eba3d37..d0497cc01 100644 --- a/client/ts/src/market.ts +++ b/client/ts/src/market.ts @@ -251,15 +251,23 @@ export class Market { const bids: RestingOrder[] = this.bids(); const quoteOpenOrdersBalanceAtoms: number = bids + .filter((restingOrder: RestingOrder) => { + return restingOrder.orderType != OrderType.Global + }) .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 + }) .map((restingOrder: RestingOrder) => { return ( Number(restingOrder.numBaseTokens) * 10 ** this.data.baseMintDecimals diff --git a/debug-ui/scripts/balance-checker.ts b/debug-ui/scripts/balance-checker.ts index bfadc3025..7e4b379d5 100644 --- a/debug-ui/scripts/balance-checker.ts +++ b/debug-ui/scripts/balance-checker.ts @@ -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, @@ -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( @@ -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) => {