Skip to content

feat(sdk): let apps that build document creates by hand state the contest fund - #5163

Merged
QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/contest-fund-helper-604d64
Sep 29, 2026
Merged

QuantumExplorer merged 1 commit into
v4.2-devfrom
claude/contest-fund-helper-604d64

Conversation

@QuantumExplorer

Copy link
Copy Markdown
Member

Basic explanation

What this does: Some documents join a contest when they are created, for example a short DPNS name or a moderation charter. The create has to say how much it will pay into that contest's fund, and which of the type's indexes holds the contest. sdk.documents.create works this out on its own, but an app that builds the create transition itself with the wasm-dpp2 classes got no help. This PR gives it two ways: an SDK call that looks up the current price and returns the value to put on the transition, and new options on the transition builder that fill in the contest's base price from the contract without any network call.

Value: A contested create that states no fund, or too little, is refused with error 40114 and still pays its fees. Apps no longer need to reimplement the pricing (the base fund, doubling past 250 contenders from protocol version 14) or the index keying in JavaScript to avoid that.

Risks: Low. Client-side only, no consensus change. Every addition is new and optional: existing calls behave as before, and Sdk::contest_fund_to_join keeps its signature. The price the helper returns can go stale if contenders join between the read and the submit; the docs say how to leave headroom from protocol version 14, and that before 14 the amount must be exact.

Issue being fixed or feature implemented

Since 4.2.0-beta.5 a contested create states the most it pays into the vote poll fund (prefundedVotingBalance), and from protocol version 14 that fund doubles once a contest holds 250 contenders and again for every 50 more. sdk.documents.create states the current join price, but apps that build the create transition themselves through wasm-dpp2 would have had to rebuild the pricing and the index keying in JS. This exposes both.

What was done?

  • rs-sdk: Sdk::prefunded_voting_balance_to_join(document_type, document) returns the contested index name with the fund to join now (counted with proved vote state queries, as before). contest_fund_to_join now delegates to it and returns only the credits, unchanged for callers.
  • wasm-sdk: getContestFundToJoin(document): Promise<PrefundedVotingBalance | undefined>. It resolves the document's contract through the contract cache, and copies the Document before the first await so the caller's object is not borrowed during the read.
  • evo-sdk: sdk.documents.contestFundToJoin(document), plus a README paragraph in "Building a document create transition by hand".
  • wasm-dpp2: new DocumentCreateTransition(...) takes two optional fields:
    • dataContract: when given and prefundedVotingBalance is not, a contested document states the contest's fund on its contested index, the same amount rs-dpp's from_document states (what joining costs below 250 contenders). A contract that is not the document's is refused.
    • contestFund: replaces the stated amount, like rs-dpp's apply_contest_fund. Without dataContract or prefundedVotingBalance there is no index to attach it to, so the build is refused.
    • The fund is resolved before the builder rewrites the document's id, so a refused build leaves the caller's document untouched. The contest is resolved with generatedFrom properties regenerated, as the platform does; the transition keeps the document's own values.
  • Doc comments on prefundedVotingBalance and the new calls say what differs before protocol version 14 (the amount must equal the contest's fund exactly).

Before / after

A hand-built create of a contested DPNS name:

// Before: the app had to know the index name and the price itself
const transition = new DocumentCreateTransition({
  document,
  identityContractNonce: nonce,
  prefundedVotingBalance: new PrefundedVotingBalance({
    indexName: 'parentNameAndLabel',   // read from the contract by hand
    credits: 10000000000n,             // 0.1 Dash, wrong past 250 contenders
  }),
});
// Leaving prefundedVotingBalance out: refused with 40114, fees charged
// After, with the SDK: the current price, read from the contest
const prefundedVotingBalance = await sdk.documents.contestFundToJoin(document);
// -> PrefundedVotingBalance { indexName: 'parentNameAndLabel', credits: 10000000000n }
//    (20000000000n once the contest holds 250 contenders; undefined if the name is not contested)
const transition = new DocumentCreateTransition({ document, identityContractNonce: nonce, prefundedVotingBalance });

// After, without the SDK: the contest's base fund keyed from the contract
const transition2 = new DocumentCreateTransition({ document, identityContractNonce: nonce, dataContract });
// transition2.prefundedVotingBalance -> { indexName: 'parentNameAndLabel', credits: 10000000000n }
const transition3 = new DocumentCreateTransition({ document, identityContractNonce: nonce, dataContract, contestFund: 30000000000n });
// transition3.prefundedVotingBalance -> { indexName: 'parentNameAndLabel', credits: 30000000000n }

How Has This Been Tested?

  • cargo test -p dash-sdk --features mocks --lib contest_fund: 2 passed. The page-by-page test now also checks the index name at 250 contenders; the no-read test covers a type with no contested index and a contested type whose label matches no contested index (20 characters, or a digit other than 0 and 1).
  • wasm-dpp2 unit suite: 1363 passing, including 5 new tests (base fund on the contested index, contestFund replacing it, no fund for a non-matching document, refusal of contestFund without an index source, refusal of a foreign contract).
  • wasm-sdk unit suite: 455 passing, including a new spec that a non-Document argument is refused before any read.
  • evo-sdk unit suite: 268 passing, including 2 new facade tests.
  • New functional tests in wasm-sdk/tests/functional/voting.spec.ts (contested DPNS name returns parentNameAndLabel with the fund documentCreateCost reports at the network's version; an uncontested name returns undefined). Not run locally: they need the local dashmate network and will first run in CI.
  • cargo clippy (dash-sdk, wasm-sdk, wasm-dpp2 on wasm32), cargo fmt --check and eslint on the changed files are clean.

Breaking Changes

None. All additions are optional, and Sdk::contest_fund_to_join keeps its signature and behaviour.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have added "!" to the title and described breaking changes in the corresponding section if my code contains any
  • I have made corresponding changes to the documentation if needed
  • If I added or changed GroveDB structure, I described it in the area's structure.rs, regenerated grovedb-structure.json, and checked the structure viewer link posted on this pull request

For repository code-owners and collaborators only

  • I have assigned this pull request to a milestone

🤖 Generated with Claude Code

…test fund

A create in a contested index (a DPNS name, a moderation charter) must
state its prefunded voting balance: the contested index and the most it
pays into the contest. Without it, or stating too little, Platform
refuses it with 40114 and still charges its fees. sdk.documents.create
fills it in, but an app building the transition through wasm-dpp2 had to
reimplement the pricing and the index keying in JS.

- rs-sdk: Sdk::prefunded_voting_balance_to_join returns the contested
  index with the fund to join; contest_fund_to_join delegates to it.
- wasm-sdk / evo-sdk: getContestFundToJoin(document) and
  sdk.documents.contestFundToJoin(document) return the
  PrefundedVotingBalance to pass to new DocumentCreateTransition, or
  undefined for a document that joins no contest.
- wasm-dpp2: DocumentCreateTransition takes an optional dataContract, so
  a contested document states the contest's fund on its contested index
  as the Rust builder does, and an optional contestFund that replaces the
  amount, like apply_contest_fund.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 20 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository: dashpay/platform/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 62d2f4aa-87d4-4383-8501-002aedcc9891

📥 Commits

Reviewing files that changed from the base of the PR and between fcacc64 and 0e70058.

📒 Files selected for processing (9)
  • packages/js-evo-sdk/README.md
  • packages/js-evo-sdk/src/documents/facade.ts
  • packages/js-evo-sdk/tests/unit/facades/documents.spec.ts
  • packages/rs-sdk/src/platform/documents/contest_fund.rs
  • packages/wasm-dpp2/src/state_transitions/batch/document_transitions/create.rs
  • packages/wasm-dpp2/tests/unit/DocumentsTransitions.spec.ts
  • packages/wasm-sdk/src/state_transitions/document.rs
  • packages/wasm-sdk/tests/functional/voting.spec.ts
  • packages/wasm-sdk/tests/unit/contest-fund-to-join.spec.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@QuantumExplorer
QuantumExplorer merged commit eefca92 into v4.2-dev Sep 29, 2026
7 of 8 checks passed
@QuantumExplorer
QuantumExplorer deleted the claude/contest-fund-helper-604d64 branch September 29, 2026 00:44
@github-actions github-actions Bot added this to the v4.2.0 milestone Sep 29, 2026
PastaPastaPasta added a commit that referenced this pull request Sep 29, 2026
Pick up #5163 (let apps that build document creates by hand state the
contest fund).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@PastaPastaPasta PastaPastaPasta mentioned this pull request Sep 29, 2026
2 of 24 tasks
QuantumExplorer added a commit that referenced this pull request Sep 29, 2026
…nywhere

Conflicts:
- v14.rs: #5158 took changelog item 57 (moderator abilities); the
  skipIfAbsent item becomes 58, and names the review's new refusals
  (coverage index without a timeRange, stored ranking sharing a level with
  a null-layout index, byte array skip needs minItems >= 1)
- book index-only rules: keep the skip rules, take `moderatorAbilities.delete`

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

1 participant