fix(sdk): call deploy_treasury with contract arg order and org-id return - #7
Merged
K1NGD4VID merged 1 commit intoSep 15, 2026
Conversation
deployTreasury encoded its args as (admin, name, ...) but the contract
signature is deploy_treasury(name, admin, approvers, threshold, token)
-> u32 (charter-contract contracts/factory/src/lib.rs L87-94). Every
call trapped with Error(WasmVm, InvalidAction) before any contract
logic ran, so org creation was broken on every factory deployment.
The SDK also expected a treasury address string back, but the contract
returns the new org id, so a successful deploy would still have thrown.
Read the org record back with get_org (retrying once for testnet RPC
read-after-write lag) and return { hash, orgId, treasuryAddress }. A
failed read-back after a confirmed deploy is reported as such rather
than as a contract rejection.
Update the SDK reference docs for the return shape and argument order.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Org creation was broken:
factory.deployTreasurycouldn't create an org on any factory deployment.The contract signature (
charter-contract/contracts/factory/src/lib.rs:87-94) is:1. Wrong argument order. The SDK passed
(admin, name, …), so every call trapped withHostError: Error(WasmVm, InvalidAction)before any contract logic ran. The XDR args now follow the contract's order. The SDK function's own TypeScript parameters are unchanged, sonew-org-form.tsxneeds no change.2. Wrong return type. The contract returns the new org id (
u32), but the SDK required a treasury address string, so even a correctly ordered deploy would have thrown. The SDK now reads the org record back withget_organd returns{ hash, orgId, treasuryAddress }. The read is retried once because testnet RPC can briefly return stale data after a transaction. If it still fails after a confirmed deploy, the error says the org was created instead of claiming the contract rejected the deploy.Also updates
docs/developer-guide/sdk-reference.md, which repeated both bugs.No other call sites: in this repo,
deploy_treasuryis only called fromfactory.ts, vianew-org-form.tsx. The contract repo'sverify.shand Rust tests already use the correct order.Testing
npm run typecheckpasses for@charter/sdkand@charter/web.Live on the new testnet factory
CBLPNUIGY3RTZSLBRIAZPOSLJADUP3XSJF5ARULKZMODNT25WXYJ37CG, running the real SDK code:The deploy transaction was confirmed separately with RPC
getTransaction:status: SUCCESS, ledger 4695937.Known limitation (not fixed here)
deploy_treasuryrequires both the factory's stored deployer andadminto sign, but the SDK only signs the transaction envelope. A deploy therefore only works when the connected wallet is the deployer; the live test passed because admin was the deployer key. Any other wallet using the new-org form will still fail authorization. Fixing that needs a separate decision: change the contract's auth model or add a deployer co-signing step.NEXT_PUBLIC_FACTORY_CONTRACT_IDis intentionally unchanged; repointing the app at the new factory is a separate decision.🤖 Generated with Claude Code