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
8 changes: 0 additions & 8 deletions docs/developer-guide/sdk-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,6 @@ Both wrap the lower-level `ContractError` thrown by the RPC layer. The numeric
`code` is the contract's `#[contracterror]` discriminant, parsed from Soroban's
`Error(Contract, #N)` message.

> **Known drift.** The SDK's own `TreasuryError` / `FactoryError` enums in
> `packages/sdk/src/types.ts` do not currently line up one-for-one with the
> contract's `errors.rs`. When you need the authoritative code-to-meaning
> mapping, use the contract source and the tables on the
> [treasury](../smart-contracts/treasury.md) and
> [factory](../smart-contracts/factory.md) pages, not the SDK enum. This is a
> tracked bug, not a documentation gap.

## Reads for display come from the indexer, not the SDK

The SDK's view functions read live contract state by simulation. The web app
Expand Down
4 changes: 0 additions & 4 deletions docs/smart-contracts/treasury.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,6 @@ The treasury error enum, with its on-chain discriminants:
| `NotRequester` | 10 | Cancel attempted by someone other than the requester. |
| `InvalidAmount` | 11 | Non-positive amount/cap, missing category, or cap below spent. |

Note that the SDK's `TreasuryError` enum in `packages/sdk/src/types.ts` does not
currently match this list one-for-one. When you need the authoritative mapping,
use `errors.rs` and this table, not the SDK enum.

## Events

The treasury emits an event on every state change. The indexer reads these:
Expand Down
84 changes: 42 additions & 42 deletions packages/sdk/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,66 +66,66 @@ export interface OrgRecord {
/**
* Numeric `#[contracterror]` discriminants for the `treasury` contract.
*
* NOTE: the app build spec restates the contract's method/type interface but
* not its error enum, and forbids reading the contract repo. These variants and
* their ordering mirror `charter-contract`'s declared `#[contracterror]` for
* this domain; any discriminant that ever drifts is caught by the graceful
* fallback in {@link treasuryErrorMessage}, so a raw error string is never
* shown to a user regardless.
* Mirrors `charter-contract/contracts/treasury/src/errors.rs` exactly — names,
* discriminants, and order. Update both together. Any unknown code still falls
* back gracefully in {@link treasuryErrorMessage}.
*/
export enum TreasuryError {
AlreadyInitialized = 1,
NotAuthorized = 2,
NotAnApprover = 3,
InvalidThreshold = 4,
CategoryNotFound = 5,
CategoryInactive = 6,
CapExceeded = 7,
InsufficientBalance = 8,
RequestNotFound = 9,
RequestNotPending = 10,
AlreadyApproved = 11,
InvalidAmount = 12,
DuplicateApprover = 13,
ApproverNotFound = 14,
NotInitialized = 2,
NotAdmin = 3,
NotApprover = 4,
CategoryInactive = 5,
CapExceeded = 6,
RequestNotPending = 7,
InvalidThreshold = 8,
AlreadyApproved = 9,
NotRequester = 10,
InvalidAmount = 11,
}

/** Numeric `#[contracterror]` discriminants for the `factory` contract. */
/**
* Numeric `#[contracterror]` discriminants for the `factory` contract.
*
* Mirrors `charter-contract/contracts/factory/src/errors.rs` exactly. Note the
* first two discriminants are the reverse of the treasury enum.
*/
export enum FactoryError {
AlreadyInitialized = 1,
NotAuthorized = 2,
InvalidThreshold = 3,
InvalidWasmHash = 4,
OrgNotFound = 5,
NotInitialized = 1,
AlreadyInitialized = 2,
NotDeployer = 3,
OrgNotFound = 4,
/** Wraps any failure of the new treasury's `initialize`; treasury codes never surface as factory codes. */
TreasuryInitFailed = 5,
}

const TREASURY_ERROR_MESSAGES: Readonly<Record<TreasuryError, string>> = {
[TreasuryError.AlreadyInitialized]: 'This treasury has already been set up.',
[TreasuryError.NotAuthorized]: 'You do not have permission to do this.',
[TreasuryError.NotAnApprover]: 'Only a designated approver can act on this request.',
[TreasuryError.InvalidThreshold]:
'The approval threshold must be at least 1 and no greater than the number of approvers.',
[TreasuryError.CategoryNotFound]: 'That budget category no longer exists.',
[TreasuryError.NotInitialized]: 'This treasury has not been set up yet.',
[TreasuryError.NotAdmin]: 'Only the treasury admin can do this.',
[TreasuryError.NotApprover]: 'Only a designated approver can act on this request.',
[TreasuryError.CategoryInactive]: 'This budget category is inactive and cannot be spent from.',
[TreasuryError.CapExceeded]: 'This request would exceed the category’s remaining budget.',
[TreasuryError.InsufficientBalance]:
'The treasury does not hold enough funds to cover this request.',
[TreasuryError.RequestNotFound]: 'That request no longer exists.',
[TreasuryError.CapExceeded]: 'This would exceed the category’s budget cap.',
// The contract also raises this for a request id that does not exist.
[TreasuryError.RequestNotPending]:
'This request has already been executed, rejected, or cancelled.',
'This request no longer exists or has already been executed, rejected, or cancelled.',
[TreasuryError.InvalidThreshold]:
'The approval threshold must be at least 1 and no greater than the number of approvers.',
[TreasuryError.AlreadyApproved]: 'You have already approved this request.',
[TreasuryError.InvalidAmount]: 'The amount must be greater than zero.',
[TreasuryError.DuplicateApprover]: 'That address is already an approver.',
[TreasuryError.ApproverNotFound]: 'That address is not currently an approver.',
[TreasuryError.NotRequester]: 'Only the person who submitted this request can cancel it.',
// The contract also raises this for a missing category or a cap below spent.
[TreasuryError.InvalidAmount]:
'The amount is invalid, or the budget category does not exist. Amounts must be greater than zero, and a cap cannot be set below what has already been spent.',
};

const FACTORY_ERROR_MESSAGES: Readonly<Record<FactoryError, string>> = {
[FactoryError.NotInitialized]: 'The factory has not been initialized yet.',
[FactoryError.AlreadyInitialized]: 'The factory has already been initialized.',
[FactoryError.NotAuthorized]: 'You do not have permission to deploy a treasury.',
[FactoryError.InvalidThreshold]:
'The approval threshold must be at least 1 and no greater than the number of approvers.',
[FactoryError.InvalidWasmHash]: 'The treasury program reference is invalid.',
[FactoryError.NotDeployer]: 'You do not have permission to deploy a treasury.',
[FactoryError.OrgNotFound]: 'That organization could not be found.',
// The contract reverts the whole deploy, so neither the org nor the treasury exists.
[FactoryError.TreasuryInitFailed]:
'The treasury for this organization could not be set up, so no organization was created.',
};

const GENERIC_CONTRACT_ERROR = 'The contract rejected this action. Please review your input and try again.';
Expand Down
Loading