Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(reputation): keep epochFraction exact instead of rounding a sliver to 9 decimals

nirholas9fb441bf1cb8
diff --git a/src/shared/reputation-staking.js b/src/shared/reputation-staking.js
index dba3639ad..79b1d7e6f 100644
--- a/src/shared/reputation-staking.js
+++ b/src/shared/reputation-staking.js
@@ -98,7 +98,10 @@ export function epochFraction(position, epoch, now) {
const from = Math.max(opened, start);
const to = Math.min(closed, end);
if (to <= from) return 0;
- return round((to - from) / EPOCH_SECONDS);
+ // Exact by design (spec section 4): overlap seconds over 86400, no rounding.
+ // The 9-decimal rounding rule covers the section 5 earnings intermediates;
+ // rounding here would credit a one-second sliver as a fatter slice than it is.
+ return (to - from) / EPOCH_SECONDS;
}
/**
diff --git a/tests/reputation-staking.test.js b/tests/reputation-staking.test.js
index f72bb069f..eb2d8ff2a 100644
--- a/tests/reputation-staking.test.js
+++ b/tests/reputation-staking.test.js
@@ -70,7 +70,9 @@ describe('epochs', () => {
it('never accrues past `now`, even for an open position', () => {
const now = E_START + 3_600;
- expect(epochFraction({ openedAt: E_START, closedAt: null }, E, now)).toBe(round9(3_600 / 86_400));
+ // Spec section 4: overlap seconds over 86400, exact. No 9-decimal rounding
+ // here; that rule belongs to the section 5 earnings intermediates.
+ expect(epochFraction({ openedAt: E_START, closedAt: null }, E, now)).toBe(3_600 / 86_400);
});
it('returns zero for an epoch the position did not overlap', () => {
@@ -348,7 +350,3 @@ describe('registry extension: threews.unstake.v1', () => {
expect(validatePayload({ v: 1, kind: 'threews.unstake.v1', agent: AGENT_A, principal: '1' })).toBe(false);
});
});
-
-function round9(n) {
- return Math.round(n * 1e9) / 1e9;
-}