Skip to content

Commit

Permalink
chore(core): enforce non-negative 'volumeRemaining' (#3628)
Browse files Browse the repository at this point in the history
  • Loading branch information
vindard authored Nov 29, 2023
1 parent b695d2f commit a97b03b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions core/api/src/domain/accounts/limits-volume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ export const AccountTxVolumeRemaining = (
"txVolume.limitCheck": AccountLimitsType.IntraLedger,
})

return calc.sub(limitAmount, outgoingUsdVolumeAmount)
const rawVolumeRemaining = calc.sub(limitAmount, outgoingUsdVolumeAmount)
return calc.max(ZERO_CENTS, rawVolumeRemaining)
}

const withdrawal = async ({
Expand Down Expand Up @@ -110,7 +111,8 @@ export const AccountTxVolumeRemaining = (
})

const netVolumeAmount = calc.sub(outgoingUsdVolumeAmount, incomingUsdVolumeAmount)
return calc.sub(limitAmount, netVolumeAmount)
const rawVolumeRemaining = calc.sub(limitAmount, netVolumeAmount)
return calc.max(ZERO_CENTS, rawVolumeRemaining)
}

const tradeIntraAccount = async ({
Expand Down Expand Up @@ -138,7 +140,8 @@ export const AccountTxVolumeRemaining = (
"txVolume.limitCheck": AccountLimitsType.SelfTrade,
})

return calc.sub(limitAmount, outgoingUsdVolumeAmount)
const rawVolumeRemaining = calc.sub(limitAmount, outgoingUsdVolumeAmount)
return calc.max(ZERO_CENTS, rawVolumeRemaining)
}

return {
Expand Down
2 changes: 1 addition & 1 deletion core/api/test/unit/domain/accounts/limits-volume.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe("LimitsChecker", () => {
})
})

describe.skip("returns 0n for walletVolumes above limit", () => {
describe("returns 0n for walletVolumes above limit", () => {
it("intraLedger", async () => {
const remaining = await volumeRemainingCalc.intraLedger({
priceRatio,
Expand Down

0 comments on commit a97b03b

Please sign in to comment.