Skip to content
MultiAgencyPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

NEAR Extents

Companion contracts to the NEAR Intents Verifier (intents.near). The Verifier settles economic intents: transfers, withdrawals and token_diff swaps. Extents extends this to social outcomes that need commitments from multiple parties, e.g. "I have USDC on NEAR, I want an event organized in NYC."

Each objective is its own contract at a predictable address (NEP-616), holds resources as balances on the Verifier, and settles through standard Verifier transfers. Agencies are Sputnik DAOs, which fund and judge objectives through ordinary proposals. The Verifier is not modified.

In the code, sponsor is the customer funding an objective.

Rust dependencies on NEAR Intents are pinned to Git revision dbad9c8a4659e8bd7f42c152ec79448a8e9d281c in Cargo.toml. The sandbox fetches its NEP-141 test token from the same revision, pinned by sha256.

Contracts

extents-objective

One objective: a sponsor's resources, released to committed contributors only if an evaluator attests that the objective was achieved.

Concern Mechanism
Objective spec_hash commits to the off-chain spec the evaluator judges against
Authority evaluator alone judges, once, before the last moment to attest; it cannot also be a contributor. The sponsor can only release
Resources a single NEP-245 token on the Verifier, funded by sponsor via mt_transfer_call
Commitment each contributor commits with ob_commit, or its named backup after commit_by; an achieved verdict needs every slot delivered
Delivery each committed contributor records what it delivered, by hash, with ob_deliver
Accountability payout follows the verdict; without one, acceptance_window_secs decides

The sponsor may also be the evaluator, as a DAO judging its own grants would be. Contributors then trust the sponsor's own verdict on whether to pay them.

Release: a sponsor that is not the evaluator can still concede, with its own ob_attest achieved (rule). It needs nobody's word but the sponsor's, so two parties who agree settle without the evaluator, who is then only called on when they disagree. Taking the funding back is a judgement on the work, so failed stays the evaluator's.

Like escrow-swap, which it follows closely, the account id is derived from Params (NEP-616), so the address is known before deployment. Only the params hash is stored, and every call passes Params in full.

             mt_transfer_call(fund)             ob_attest(achieved) ───────┐ contributors by share,
sponsor ───────────────────────────▶ objective ─┤   (all delivered)         ├ remainder to sponsor
                                      (0s…)     ├ ob_close(), no verdict,  ─┘
contributors ── ob_commit ──────────▶           │   window set, all delivered
             ── ob_deliver ─────────▶           ├ ob_attest(failed)        ─┐
                                                └ ob_close(), no verdict,   ├ sponsor
                                                    otherwise              ─┘

Interface: ob_view, ob_commit(params), ob_withdraw(params), ob_deliver(params, delivery), ob_attest(params, attestation), ob_cancel(params), ob_close(params), and mt_on_transfer with msg = {"params": …, "action": {"action": "fund"}}. __fastdata_kv accepts document publication as a no-op. An attestation is {"verdict": "achieved" | "failed", "review_hash"?: <hex>}; the optional review_hash commits to the evaluator's review and is published in the resolved event, so a verdict can be checked later. A delivery is {"hash": <hex>}, published in the delivered event with the last moment to attest after it (attest_by). Contributors, the evaluator and the sponsor can also act through a signed auth_call intent on the Verifier (on_auth with msg = {"params": …, "action": {"action": "commit"}}, {"action": "withdraw"}, {"action": "deliver", "data": <delivery>}, {"action": "attest", "data": <attestation>} or {"action": "cancel"}), provided params.auth_caller names the Verifier. Params with any other auth_caller are refused: the contract trusts the signer its caller names.

Addresses: derive an objective's address from its Params and the code hash, never accept one, and check that Params.token names the real Verifier: any contract named there can emit a history of funding and verdicts for its own fake token. Funding checks the address itself: it is refused unless the account runs code fixed by hash (not by an account id, whose code can be replaced) at exactly the address that code and the fresh state of these Params derive. Code deployed with a hand-built state lands elsewhere and can never be funded.

Events: count only events from receipts that succeeded. A receipt that fails after logging keeps its logs: an mt_on_transfer that runs out of gas after emitting funded is reverted and refunded, but its funded log remains, as does a resolved logged by an attest or close that then ran out of gas. Stop at an objective's first cleanup: anyone can redeploy the same StateInit afterwards, and closing that copy emits a second resolved (expired, nothing allocated).

Funding from another chain: a sponsor holding tokens elsewhere names its own Verifier account as sponsor, for example the 0x… account the Verifier derives from its EVM key (PublicKey::to_implicit_account_id). It then:

  1. bridges into that account with a 1Click quote whose recipientType is INTENTS and whose refundType is ORIGIN_CHAIN, with refundTo its own address there (not an ANY_INPUT quote, which never refunds);
  2. polls /v0/status by deposit address until SUCCESS, REFUNDED or FAILED, and never pays again while the outcome is unknown;
  3. signs a transfer intent to the objective whose notification msg is the fund message (the notification field of Transfer in Verifier v0.4.5), which reaches mt_on_transfer like mt_transfer_call.

1Click itself delivers to an INTENTS recipient as a plain balance credit with no notification, so tokens it delivers straight to the objective are never counted as funding (see Settlement). A dry-run quote (dry: true, no deposit address, no funds) to a 0x… recipient with recipientType INTENTS was tried on 2026-11-24 from Arbitrum USDC: a lowercase address was quoted, and the same address in mixed case (EIP-55 checksum) was refused with 400 recipient is not valid. Account ids are lowercase, so name the sponsor's account that way. Not yet tried: a real deposit and delivery, so whether the credit lands on that Verifier balance is unobserved.

Commitment and delivery: see the rules a contributor commits before the deadline and a delivery is final. Funding does not wait for commitments, so contributors can see the resources before agreeing. A failed verdict or expiry needs no commitments.

Withdrawal: whoever holds a slot can give it back with ob_withdraw (rule), and the slot is then empty, as if nobody had committed to it. A commitment is therefore a public statement of intent, not a lock: nothing ever forced a committed contributor to deliver, and withdrawing says so on the record (withdrawn) rather than by silence until the deadline.

Cancel: until someone commits, the sponsor can take its funding back with ob_cancel (rule). Withdrawals that empty every slot unlock it again, so a contributor who cannot do the work and a sponsor who agrees can unwind before the deadline. Commit before starting work: until then the sponsor can cancel.

Backups: Params.backups names a backup for some contributors' slots, with a Params.commit_by (rule). Whoever commits first after commit_by holds an empty slot: its share, its delivery and its payout (rule). Only its holder can give a slot up (rule), so nobody is replaced mid-job. State.taken marks the slots a backup holds, and payouts name whoever holds each slot.

Silence: Params.acceptance_window_secs is part of the deal both sides see before committing, and decides what happens when the evaluator does not attest.

The rule is silence fails closed unless the terms say otherwise: by default contributors rely on the evaluator they agreed to, and a window lets contributors who all delivered be paid, with no review, if the evaluator stays silent.

Funding, commitment and delivery end at Params.deadline either way; only the time to attest moves. Within it the evaluator can still attest achieved or failed, the sponsor can still release, and a failed verdict is final: there is no dispute path.

Settlement: the outcome moves the funded balance into owed (rule), and the contract sends each amount with mt_transfer on the Verifier. Failed transfers go back into owed (rule). After the last moment to attest, once nothing is funded, owed or in flight, ob_close reads the objective's own balance on the Verifier (rule). Anything else is retained, never sent: a balance cannot tell a plain transfer from a refused deposit whose refund has not executed, and nothing bounds how long that refund takes. Always fund through mt_transfer_call with the fund message. Payout callbacks never delete on their own. Deletion waits for the last moment to attest so that redeploying the same StateInit cannot reopen a settled objective.

What it does not prove:

  • Achievement. The verdict is the evaluator's. The contract checks roles, timing and hashes, never the work.
  • Authorship or quality. A delivery hash proves what was committed and when, not who made it or whether it is good.
  • Honest judging. A bribed or captured evaluator, DAO majority included, is recorded like any other, and the contract sees no payment made off chain.
  • Privacy. Params, specs, reports and reviews are public, and so is the money: an objective is an account on the public Verifier, and its funding, balance and payouts are public by design. It has only been run against the public Verifier. An account that keeps a confidential NEAR Intents balance funds an objective from, and is paid on, its public one.
  • Independence from the Verifier's operators. Its DAO and UnrestrictedWithdrawer roles can force-transfer any balance on it, an objective's included, and can lock accounts.
  • Safety. No independent audit yet. Use testnet funds only.

Known limits:

  • A lost payout callback. Payouts leave owed before they are sent, and only their callback (ob_resolve_transfers, 10 Tgas fixed) puts failures back. If that callback itself failed, the objective could not tell which transfers in the batch succeeded: it would neither retry nor delete (it is never settled with a callback outstanding), and the failed amounts would stay on its Verifier balance. With ten contributors the callback burns 1.8 of its 10 Tgas, and no way to make it fail has been found. A unit test pins this behaviour.
  • Plain transfers. A plain mt_transfer to an objective is lost. Before deletion it is retained; after deletion it stays on the Verifier under an account no code controls, since the Verifier does not check that an account exists. Nobody else can claim that NEP-616 id, and nobody can move the balance.
  • Payout gas has a ceiling. Each payout is reserved 15 Tgas, and the balance read before deletion 5 Tgas; both share any gas the caller attaches beyond what the call reserves. A retry sends everything owed in one batch. Params::close_gas (250 Tgas with ten contributors) covers each payout's 15 Tgas; a caller who attaches the 300 Tgas maximum gives each payout at most roughly (300 Tgas minus the batch callback and the call's own execution) divided by the number of payouts owed, about 21–25 Tgas with eleven. Should a Verifier upgrade make mt_transfer cost more than that, those payouts could not be sent.
  • Deletion can be blocked. An objective deletes itself only at a zero balance, so anyone can keep one alive by sending it a unit. Deletion protects no funds or rights; it only clears state.

Before committing, a contributor checks what the contract can't, about the sponsor and the evaluator:

  • A Sputnik DAO with auto_update: true can have its code replaced by its factory without a vote. A FactoryInfoUpdate proposal turns that off.
  • Keys registered on the Verifier (public_keys_of) can sign any intent for the account without its owner acting: an attestation, or a transfer of its whole Verifier balance. A DAO or MPC-derived account should have none beyond the one its signer derives.
  • A DAO acts by proposal, which must pass within the DAO's proposal period and before the last moment to attest. With an acceptance window shorter than that period, silence decides instead of the vote.
  • Backups are part of the terms. A commit_by already past at launch lets a backup take an empty slot at once, and the sponsor may name itself a backup.
  • Signed intents: a refused auth_call still uses up the intent, since the Verifier doesn't wait for the callee, so a new one must be signed. Removing a key voids every outstanding intent it signed, including verdicts not yet submitted.

contracts/objective/tests/vectors/params.json pins the JSON and borsh encodings of Params, their hash, the initial state and the NEP-616 account id for four cases, so implementations in other languages can check against the contract rather than against a deployment.

Limits: at most 10 contributors, with shares in pips summing to exactly 100%. A unit test checks that the worst-case state fits the 770-byte zero-balance-account limit, assuming a global contract id of up to 64 characters.

Formats

extents-spec

The contract does not interpret spec_hash or review_hash. crates/spec defines the documents they commit to, so that a verdict can be checked by anyone holding the spec and the deliverables.

  • Spec: the objective's statement and its criteria. Each criterion is one of contains, schema, numeric_match, files, live_url, sources, media or llm_judge. All but llm_judge are meant to be checked by a script. A spec has at most two llm_judge criteria and at least one other, so a model's answer is never the only gate. Each llm_judge names its models, one or three, and its outcome is their majority answer. A spec with an llm_judge states max_report_bytes, the most UTF-8 bytes one contributor's report may have; a longer report fails. A spec may pin evaluator_build, the hash of an attested evaluator program. Contributors see spec_hash in Params before they commit, so they agree to be judged against exactly these criteria.
  • Judge requests: the crate builds the exact request body each model call sends (judge_request): a fixed system message, the question, and the deliverables between two fence lines derived from their own hash, which text inside them cannot contain. Anyone holding the deliverables rebuilds the request and checks its hash. Nothing stops an evaluator from calling again and keeping the answer it prefers; only an attested evaluator removes that.
  • Review: the objective's account, the spec's hash, each contributor's deliverable by hash, one result per criterion (pass, fail or skipped), and each model call: its criterion, model, answer, request and response hashes, and the provider's signature. A judged llm_judge outcome needs one call per named model and must follow their majority; the one exception is a fail with no calls at all, for a report over max_report_bytes that no model was asked about. A review of a spec that pins evaluator_build records the same build. A review validates only if its verdict follows from its results: achieved only when every criterion passed and no report is missing, failed only when at least one criterion failed or a contributor's report was never published (listed in missing). skipped is for the evaluator's own side failing (its model or network, or a host that never answered); what the contributor controls, such as a report over its limit or a cited host answering with an error, fails after a retry. Results with something skipped and nothing failed or missing support neither, so the evaluator doesn't attest. A consumer checks objective against the account the verdict was attested on, so a review cannot be reused for another objective with the same spec and contributors.
  • Evidence: each result lists what was fetched to reach it, by URL and SHA-256 of the response body. A live_url, sources or media result that passed must have some, so a later check can run against the same bytes rather than a page that may have changed since. One that failed may have none (nothing to fetch, or nothing loaded), with its detail saying why. A sources criterion's min counts distinct pages: links that differ only by #fragment, or whose responses are the same bytes, count once.
  • Hash: SHA-256 of the document's RFC 8785 canonical JSON. A document is accepted only in normal form (no unknown fields, no null for an optional field left out), so one meaning has one hash. The vectors in crates/spec/tests/vectors pin the hashes for other languages. Their expected hashes were computed independently with Python's standard library.

An evaluator that cannot check anything writes no review and does not attest, so an outage is never recorded as a failed verdict. What the silence then does to the money is set by acceptance_window_secs: without a window, the sponsor is refunded just as a failed verdict would refund them.

The crate defines and validates the formats. It does not run any check.

Status

The protocol is specified in docs/spec.md (draft for review).

What the contract and extents-spec enforce is listed as rules in docs/spec.md §7. Every rule is cited by the tests that check it: unit tests under near-sdk mocking and the pinned vectors (cargo test), the Docker sandbox (sandbox/), and the TypeScript mirror of the vectors (app/test/vectors.test.ts). app/test/rules.test.ts fails on a rule that no test cites, and bun scripts/rules-changed.ts <commit> (from app/) lists the rules a change adds, removes or rewords, with everything that cites them.

Tested beyond the rules: the events for commitments and allocations, including the review hash; committing, withdrawing, delivering, attesting and cancelling through on_auth; the worst-case state size; and that a lost payout callback leaves no recovery path (the known limit above).

Established on testnet against Tidepool's Verifier, the same v0.4.5 build as mainnet intents.near, by e2e/ (2026-11-20). The contract is published as global code 4GxG7Nyek6NcaKqkGfDoXrBwspYPE7gA1ADigd3JoiTF (SHA-256 30a94195…), the reproducible build of commit c50d0bb, which passed the full sandbox suite on that exact file first. All ten scenarios pass, 170 of 170 checks. Every transaction and balance was written to e2e/results/30a94195…/RESULTS.md by extents-e2e. Generated result directories are ignored by Git (see e2e/results/RESULTS.md), so re-run e2e/ to reproduce them.

Release, cancel and withdrawal are in a later build, published on 2026-11-23 as global code FPkPcDq1zMgkWXtdH98F1uR292PTMSF6mSjDiUXnVXyB (SHA-256 d5d774ac…), the reproducible build of commit 541a4e8, which passed the 31 sandbox tests on that exact file first. On it, all thirteen scenarios pass, 207 of 207 checks (2026-11-23): the ten above, and release, cancel and withdraw. The sponsor's release is refused until both contributors deliver, then resolves as released and pays the split. A commitment blocks the sponsor's cancel until it is withdrawn, and the cancel then refunds everything as cancelled. A contributor withdraws before commit_by, its backup takes the empty slot after it, and the verdict pays the backup that slot's share. Publishing cost 33.18 NEAR (331,773 bytes), and the results are in e2e/results/d5d774ac…/RESULTS.md.

  • Deployment. Publishing by code hash cost 32.48 NEAR (10× storage for 324,728 bytes). StateInit deploys at the account id derived from init_state, and the instance needs no NEAR: a StateInit deposit is refunded in full.
  • Funding and resolution.
    • Funding by the sponsor's mt_transfer_call.
    • An achieved verdict is refused until every contributor has delivered (not all contributors have delivered), then pays each share exactly, with the remainder to the sponsor.
    • Commitment, delivery and attestation by signed auth_call intent.
    • A failed verdict returns everything. ob_close is refused before the deadline; after it, it resolves as expired and returns everything.
    • With an acceptance window, the evaluator's silence after full delivery resolves as accepted and pays the split.
  • Payouts from a zero balance. Each mt_transfer attaches 1 yoctoNEAR. At protocol 88 (one_yocto_on_promise, nearcore 2.14), that is not deducted while the contract's balance is zero, so an instance needs no NEAR at all. The contract relies on this.
  • Gas. 10 contributors and 11 payouts settle in one ob_attest with exactly Params::attest_gas, 210 Tgas, burning 53.7 Tgas. Each transfer gets its 15 Tgas plus a share of the unused gas and burns at most 3.97; the callback burns 1.8 of its 10. By signed intent, the Verifier forwards 295.6 Tgas to on_auth, and the settlement burns 58.5 Tgas in total.
  • Deletion. After the deadline, ob_close reads the objective's Verifier balance and, at zero, deletes the account in the same transaction, paying any NEAR it holds to the closer.
  • A DAO as sponsor and evaluator. A Sputnik DAO (e2e-agency.sputnikv2.testnet) funds and attests by FunctionCall proposals, and the DAO's MPC-derived account (aa59f4f8…) funds and attests by intents its council signs by vote. Each proposal is verified against its payload before the vote.

Established in a local sandbox by sandbox/, against the Verifier binary deployed at mainnet intents.near (code hash BtA1BEFNS619KkvXFsgcpQ21Tb5yMm32aaUkn7xNothk), with the test holding the Verifier's operator roles:

  • A failed payout and its retry. With the objective's account locked by the Verifier's operator, the Verifier rejects every payout (account '0s…' is locked). The lost event reports them, and the amounts go back into owed exactly while the Verifier balance stays intact. Retrying with ob_close while still locked loses nothing. After unlocking, ob_close pays every share exactly. Past the deadline, ob_close then deletes the account.
  • The testnet scenarios, as a regression suite. Achieved (refused until all have delivered), failed, expired (with the StateInit refund and deletion paying the closer), commitment and attestation by signed intent, and ten contributors settling in one transaction, directly and by signed intent. Deadlines are reached by producing blocks, so the suite needs no faucet or real waiting.
  • Stray funds (sandbox/tests/stranded.rs). A plain mt_transfer lands on the objective's Verifier balance but never in funded, and stays there: closing after the deadline neither sends it nor deletes the objective. A funding deposit whose mt_on_transfer runs out of gas is refunded in full and never counted.
  • A backup taking a slot (sandbox/tests/backups.rs). Before commit_by the backup is refused; after it, with the listed contributor absent, the backup commits, the contributor's late commit is refused, and the achieved verdict pays the backup that slot's share through the Verifier.

Established on testnet by e2e/ (2026-11-20), independently of the objective contract:

  • A DAO signing intents by vote. A Sputnik DAO acts on the Verifier as the implicit account of the key the MPC signer (v1.signer-prod.testnet) derives for it on path agent-owner.
    • The council approved a FunctionCall proposal to the signer's sign. The signature arrived in the executing transaction, and a relayed execute_intents moved the DAO's balance on the Verifier.
    • No key was delegated or registered with add_public_key. A registered key could sign any intent for the account, including a transfer of the whole balance.
    • Each proposal carries the payload beside its hash. extents-e2e dao verify recomputes the hash and checks the signer, the Verifier and the deadline before anyone votes.
    • A Trezu template (e2e/trezu/sign-intents.json) files exactly those args.

Not yet established:

  • Filing through Trezu's UI. The template's output is checked against the CLI's by a unit test, but it hasn't been loaded into Trezu.
  • Funding and deploying in one step. StateInit on Verifier transfers and auth_call is commented out on Intents main (pending UniversalStateInit), so deployment is a separate state_init action for now.

Development

cargo test
cargo clippy --all-targets --features abi
RUSTFLAGS='--cfg=near' cargo clippy -p extents-objective --target wasm32-unknown-unknown --features contract
cargo fmt --all -- --check

Build the contract with the pinned flags, then run the sandbox (Docker, all local) against that exact file:

(cd contracts/objective && cargo near build non-reproducible-wasm --locked --features=contract --abi-features=abi,contract)
EXTENTS_OBJECTIVE_WASM="$PWD/target/near/extents_objective/extents_objective.wasm" cargo nextest run -p extents-sandbox --run-ignored only

A build to publish comes from cargo near build reproducible-wasm, in the image [package.metadata.near.reproducible_build] pins, from a committed tree. Publish only the file the sandbox ran against. The app's release manifest is described in docs/app.md.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages