Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/governance-spell-deployments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@reserve-protocol/sdk": patch
---

Decode proposals to every `GovernanceSpell_09_18_2026` deployment (the 2% and 1% threshold redeployments on Ethereum, Base and BSC) and OPEN's `GovernanceSpell_10_21_2026`, so a preview names them without the explorer ABI fallback.
11 changes: 11 additions & 0 deletions .changeset/vote-token-decimals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@reserve-protocol/sdk": patch
---

Index DTF governance amounts now use the decimals of the vote token. Before, the SDK formatted them with 18 decimals, so a DAO with a 6-decimal vote token (for example a vote-lock vault on USDC) showed a quorum of 0.00000000000003 instead of 0.03. Raw values did not change.

- Proposals, proposal lists and voting snapshots get a `voteTokenDecimals` field from the subgraph. `getProposalState` uses it for the threshold amounts and uses 18 when it is missing.
- `getVoterState`, `getProposalVoterState`, `getOptimisticProposalVoterState`, `getOptimisticVotes`, `getPastOptimisticVotes` and `getOptimisticProposalContext` read `decimals()` in the same multicall as their other reads.
- `getDelegates` reads the vote token decimals from the subgraph.
- The vote-lock state formats `optimisticVotingPower` with the vault decimals.
- `getProposalVotes`, `getProposerState` and `getOptimisticProposalContext` accept an optional `voteTokenDecimals`. Without it, `getProposalVotes` and `getProposerState` with a `timepoint` make one more `decimals()` call.
2 changes: 2 additions & 0 deletions apps/docs/src/pages/sdk/governance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ const proposal = await sdk.index.getProposal({

Proposal IDs can be extremely long decimal strings. Keep them as strings in routes and UI state.

Vote amounts (votes, quorum, thresholds, voting power, delegated votes) use the decimals of the vote token, not a fixed 18. A vote-lock vault on USDC has 6 decimals. Proposal reads set `voteTokenDecimals` on the proposal. `getProposalVotes` and `getProposerState` with a `timepoint` read the token `decimals()` in one more call; pass `voteTokenDecimals` to skip it.

## Voting And Account State

| Method | Use |
Expand Down
27 changes: 27 additions & 0 deletions packages/sdk/src/index-dtf/governance/contract-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,33 @@ const EXTRA_PROPOSAL_CONTRACTS: readonly {
abi: governanceSpell09182026Abi,
addresses: INDEX_DTF_GOVERNANCE_SPELL_09_18_2026_ADDRESS,
},
// Redeployments of the same spell with a 2% and then a 1% proposal threshold; proposals can target any of them.
{
contract: "Governance Spell 09_18_2026",
abi: governanceSpell09182026Abi,
addresses: {
1: "0xC72fD080F4CF5Ce6a3314192888419f45c562d87",
8453: "0x24a4B37F9c40fB0E80ec436Df2e9989FBAFa8bB7",
56: "0xE19ae8D1f3FFf987aaEaa65248BAB3A0d1FDC809",
},
},
{
contract: "Governance Spell 09_18_2026",
abi: governanceSpell09182026Abi,
addresses: {
1: "0xeE6066Df6E27F142b921FD38e6766a9D6aF35c2f",
8453: "0x971c890ACb9EeB084f292996Be667bB9A2889AE9",
56: "0x281EDD83b9b3C7cD05E260EF7E17A9734731A52B",
},
},
// OPEN's migration spell: other governance parameters, the same functions.
{
contract: "Governance Spell 10_21_2026",
abi: governanceSpell09182026Abi,
addresses: {
1: "0xaf029ad44Cc44fB2AefFF84029dd0c29D5Ea8D87",
},
},
{
contract: "Upgrade Spell 6.0.0",
abi: upgradeSpell600Abi,
Expand Down
47 changes: 47 additions & 0 deletions packages/sdk/src/index-dtf/governance/delegates.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("Index DTF governance delegates", () => {
currentOptimisticDelegates: "2",
token: {
totalSupply: "10000000000000000000",
decimals: 18,
},
delegates: [
{
Expand Down Expand Up @@ -153,4 +154,50 @@ describe("Index DTF governance delegates", () => {
},
});
});

it("formats delegated votes in the vote token decimals", async () => {
const client = {
subgraph: {
queryIndex: vi.fn(async () => ({
stakingToken: {
id: "0x0000000000000000000000000000000000000001",
totalDelegates: "1",
currentDelegates: "1",
totalOptimisticDelegates: "1",
currentOptimisticDelegates: "1",
token: {
totalSupply: "1000000",
decimals: 6,
},
delegates: [
{
address: "0x0000000000000000000000000000000000000002",
delegatedVotesRaw: "300000",
optimisticDelegatedVotesRaw: "200000",
numberVotes: 1,
numberOptimisticVotes: 1,
hasBeenStandardDelegate: true,
hasBeenOptimisticDelegate: true,
tokenHoldersRepresentedAmount: 1,
optimisticTokenHoldersRepresentedAmount: 1,
},
],
},
})),
},
} as unknown as DtfClient;

const delegates = await getDelegates(client, {
chainId: 8453,
stToken: "0x0000000000000000000000000000000000000001",
});

expect(delegates.delegates[0]).toMatchObject({
delegatedVotes: { raw: 300000n, formatted: "0.3" },
optimisticDelegatedVotes: { raw: 200000n, formatted: "0.2" },
weightedVotes: 30,
optimisticWeightedVotes: 20,
});
expect(delegates.voteSupply).toEqual({ raw: 1000000n, formatted: "1" });
});
});
7 changes: 4 additions & 3 deletions packages/sdk/src/index-dtf/governance/delegates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ export async function getDelegates(client: DtfClient, params: GetIndexDtfDelegat
}

const voteSupply = BigInt(stakingToken.token.totalSupply);
const decimals = stakingToken.token.decimals;
const delegates: IndexDtfDelegate[] = [];
const normalDelegates: IndexDtfDelegate[] = [];
const optimisticDelegates: IndexDtfDelegate[] = [];

for (const delegate of stakingToken.delegates) {
const delegatedVotes = mapAmount(delegate.delegatedVotesRaw);
const optimisticDelegatedVotes = mapAmount(delegate.optimisticDelegatedVotesRaw);
const delegatedVotes = mapAmount(delegate.delegatedVotesRaw, decimals);
const optimisticDelegatedVotes = mapAmount(delegate.optimisticDelegatedVotesRaw, decimals);
const mappedDelegate = {
address: getAddress(delegate.address),
delegatedVotes,
Expand Down Expand Up @@ -74,7 +75,7 @@ export async function getDelegates(client: DtfClient, params: GetIndexDtfDelegat
currentNormalDelegates: Number(stakingToken.currentDelegates),
totalOptimisticDelegates: Number(stakingToken.totalOptimisticDelegates),
currentOptimisticDelegates: Number(stakingToken.currentOptimisticDelegates),
voteSupply: mapAmount(voteSupply),
voteSupply: mapAmount(voteSupply, decimals),
};
}

Expand Down
2 changes: 2 additions & 0 deletions packages/sdk/src/index-dtf/governance/mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export function mapIndexDtfProposalSummary(
creationBlock: Number(proposal.creationBlock),
voteStart: Number(proposal.voteStart),
voteEnd: Number(proposal.voteEnd),
voteTokenDecimals: decimals,
quorumVotes: mapAmount(proposal.quorumVotes, decimals),
forWeightedVotes: mapAmount(proposal.forWeightedVotes, decimals),
againstWeightedVotes: mapAmount(proposal.againstWeightedVotes, decimals),
Expand Down Expand Up @@ -170,6 +171,7 @@ export function mapIndexDtfProposalVotingSnapshot(
...(optimistic === undefined ? {} : { optimistic }),
voteStart: Number(proposal.voteStart),
voteEnd: Number(proposal.voteEnd),
voteTokenDecimals: decimals,
quorumVotes: mapAmount(proposal.quorumVotes, decimals),
forWeightedVotes: mapAmount(proposal.forWeightedVotes, decimals),
againstWeightedVotes: mapAmount(proposal.againstWeightedVotes, decimals),
Expand Down
78 changes: 68 additions & 10 deletions packages/sdk/src/index-dtf/governance/optimistic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ const MAX_UINT256 = (1n << 256n) - 1n;

describe("Index DTF optimistic governance", () => {
it("reads optimistic proposal veto context", async () => {
const multicall = vi.fn(async () => [100n, "0x0000000000000000000000000000000000000002"]);
const readContract = vi.fn().mockResolvedValueOnce(true).mockResolvedValueOnce(100000000000000000000n);
const multicall = vi
.fn()
.mockResolvedValueOnce([100n, "0x0000000000000000000000000000000000000002"])
.mockResolvedValueOnce([100000000000000000000n, 18]);
const readContract = vi.fn().mockResolvedValueOnce(true);
const client = {
viem: {
getPublicClient: vi.fn(() => ({ multicall })),
Expand Down Expand Up @@ -60,6 +63,38 @@ describe("Index DTF optimistic governance", () => {
],
}),
);
expect(multicall).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
contracts: [
expect.objectContaining({ functionName: "getPastTotalSupply", args: [100n] }),
expect.objectContaining({ address: "0x0000000000000000000000000000000000000002", functionName: "decimals" }),
],
}),
);
});

it("formats optimistic proposal veto context in the vote token decimals", async () => {
const multicall = vi.fn().mockResolvedValueOnce([1000000n, 6]);
const client = {
viem: {
getPublicClient: vi.fn(() => ({ multicall })),
readContract: vi.fn(),
},
} as unknown as DtfClient;

const context = await getOptimisticProposalContext(client, {
chainId: 8453,
governance: "0x0000000000000000000000000000000000000001",
proposalId: "42",
isOptimistic: true,
voteToken: "0x0000000000000000000000000000000000000002",
snapshot: 100n,
vetoThreshold: 50000000000000000n,
});

expect(context?.snapshotSupply).toEqual({ raw: 1000000n, formatted: "1" });
expect(context?.vetoThresholdVotes).toEqual({ raw: 50000n, formatted: "0.05" });
});

it("does not infer proposal-specific veto threshold from current governor params", async () => {
Expand Down Expand Up @@ -100,6 +135,7 @@ describe("Index DTF optimistic governance", () => {
voteToken: "0x0000000000000000000000000000000000000002",
snapshot: 100n,
vetoThreshold: 200000000000000000n,
voteTokenDecimals: 18,
});

expect(getPublicClient).not.toHaveBeenCalled();
Expand Down Expand Up @@ -157,6 +193,7 @@ describe("Index DTF optimistic governance", () => {
voteToken: "0x0000000000000000000000000000000000000002",
snapshot: 100n,
vetoThreshold: 1n,
voteTokenDecimals: 18,
});

expect(context?.vetoThresholdVotes).toEqual({
Expand Down Expand Up @@ -615,14 +652,13 @@ describe("Index DTF optimistic governance", () => {

it("reads current and past optimistic voting power from the vote token", async () => {
const getBlock = vi.fn(async () => ({ timestamp: 1_000n }));
const readContract = vi
const multicall = vi
.fn()
.mockResolvedValueOnce(3000000000000000000n)
.mockResolvedValueOnce(2000000000000000000n);
.mockResolvedValueOnce([3000000000000000000n, 18])
.mockResolvedValueOnce([2000000000000000000n, 18]);
const client = {
viem: {
getPublicClient: vi.fn(() => ({ getBlock })),
readContract,
getPublicClient: vi.fn(() => ({ getBlock, multicall })),
},
} as unknown as DtfClient;
const params = {
Expand All @@ -639,12 +675,34 @@ describe("Index DTF optimistic governance", () => {
raw: 2000000000000000000n,
formatted: "2",
});
expect(readContract).toHaveBeenNthCalledWith(
expect(multicall).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
functionName: "getPastOptimisticVotes",
args: ["0x0000000000000000000000000000000000000002", 999n],
contracts: [
expect.objectContaining({
functionName: "getPastOptimisticVotes",
args: ["0x0000000000000000000000000000000000000002", 999n],
}),
expect.objectContaining({ functionName: "decimals" }),
],
}),
);
});

it("formats optimistic votes in the vote token decimals", async () => {
const multicall = vi.fn().mockResolvedValueOnce([300000n, 6]);
const client = {
viem: {
getPublicClient: vi.fn(() => ({ multicall })),
},
} as unknown as DtfClient;

await expect(
getOptimisticVotes(client, {
chainId: 8453,
voteToken: "0x0000000000000000000000000000000000000001",
account: "0x0000000000000000000000000000000000000002",
}),
).resolves.toEqual({ raw: 300000n, formatted: "0.3" });
});
});
Loading
Loading