Skip to content

Conversation

@gibson042
Copy link
Member

@gibson042 gibson042 commented Oct 8, 2025

Ref Agoric/agoric-private#433

Description

  • Improve comments
  • Define an applyHaircut helper function

@gibson042 gibson042 requested review from dckc and dtribble October 8, 2025 20:07
@gibson042 gibson042 requested a review from a team as a code owner October 8, 2025 20:07
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 8, 2025

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2d620ea
Status: ✅  Deploy successful!
Preview URL: https://e2107ca1.agoric-sdk.pages.dev
Branch Preview URL: https://gibson-2025-10-ymax-subtract.agoric-sdk.pages.dev

View logs

Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we'd land this outside a more substantive change.

I can approve if it's important.

* reduces it by a full unit).
*/
export const subtractBasisPoints = (n: bigint, bps: bigint) =>
(n * (10000n - bps)) / 10000n;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider something like:

const PERCENT = 100n;
const BASIS_POINT = PERCENT * PERCENT;

I think that might already be in ERTP somewhere.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, "subtract" seems like an odd name. We're multiplying by a ratio, right?

Is there a particular reason we're not using ERTP amounts and ratios?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't find suitable code in ERTP, but if you know of some then a pointer would be valuable regardless of this PR's fate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... a pointer would be valuable ...

ERTP/src/ratio.js has, for example, floorMultiplyBy.

It also has const PERCENT = 100n; though it's not exported.

Copy link
Member

@dckc dckc Oct 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As to BASIS_POINT, we seem to use a constant but not bother importing it from a common source:

$ ack 'const BASIS_POINTS = 10000n;'
packages/inter-protocol/test/interest.test.js
17:const BASIS_POINTS = 10000n;

packages/inter-protocol/test/provisionPool.test.js
45:const BASIS_POINTS = 10000n;

packages/inter-protocol/test/vaultFactory/vaultFactoryUtils.js
25:export const BASIS_POINTS = 10000n;

packages/inter-protocol/test/vaultFactory/vault-contract-wrapper.js
28:const BASIS_POINTS = 10000n;

packages/inter-protocol/test/vaultFactory/driver.js
43:export const BASIS_POINTS = 10000n;

packages/inter-protocol/test/psm/psm.test.js
46:const BASIS_POINTS = 10000n;

packages/inter-protocol/test/interest-labeled.test.js
19:const BASIS_POINTS = 10000n;

packages/inter-protocol/src/proposals/startPSM.js
31:const BASIS_POINTS = 10000n;

packages/zoe/test/unitTests/contracts/loan/borrow.test.js
30:const BASIS_POINTS = 10000n;

packages/zoe/src/contractSupport/bondingCurves.js
9:const BASIS_POINTS = 10000n; // TODO change to 10_000n once tooling copes.

packages/zoe/src/contracts/callSpread/percent.js
5:const BASIS_POINTS = 10000n;

packages/zoe/src/contracts/callSpread/pricedCallSpread.js
23:const BASIS_POINTS = 10000n;

and

$ ack 'const BASIS_POINTS = 10_000n;'
packages/inter-protocol/src/auction/auctioneer.js
45:const BASIS_POINTS = 10_000n;

Copy link
Member Author

@gibson042 gibson042 Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ERTP/src/ratio.js has, for example, floorMultiplyBy.

Thanks. floorMultiplyBy is definitely correct, but the domain being Amounts rather than Nats makes it far too cumbersome here. We could consider extending packages/ERTP/src/safeMath.js, but honestly applyHaircut is so straightforward that it seems fine as an isolated one-off, and would continue to exist here even if there were a nat-based floorMultiplyBy (because applyHaircut(flow, feeInBasisPoints) is much more clear than floorMultiplyBy(flow, makeRatio(BASIS_POINTS - feeInBasisPoints, BASIS_POINTS))).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applyHaircut is so straightforward that it seems fine as an isolated one-off

ok...

I'm just uneasy about reviewing / maintaining more of this code.

// https://github.com/Agoric/agoric-private/issues/415
const usdnOut =
(BigInt(flow) * (10000n - BigInt(edge.variableFee))) / 10000n - 1n;
subtractBasisPoints(BigInt(flow), BigInt(edge.variableFee)) - 1n;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since the change is invisible to tests, it's a refactor, right?

(not that the difference between "chore" and "refactor" matters much)

@gibson042 gibson042 force-pushed the gibson-2025-10-ymax-subtract-bps branch from ad684d4 to 2d620ea Compare October 9, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants