From dd08506c5fdc68e126fa5f36b174d383bae78abf Mon Sep 17 00:00:00 2001 From: innovativedesign-lab Date: Sat, 17 Oct 2026 19:13:24 +0100 Subject: [PATCH 1/2] Finish TypeScript bindings for every supported Stellar contract --- stellar/abi/update.sh | 2 +- stellar/bindings/typescript/index.ts | 3 + .../typescript/stealth-splitter/.gitignore | 2 + .../typescript/stealth-splitter/README.md | 54 ++++ .../typescript/stealth-splitter/package.json | 17 ++ .../typescript/stealth-splitter/src/index.ts | 253 ++++++++++++++++++ .../typescript/stealth-splitter/tsconfig.json | 98 +++++++ .../typescript/stealth-vault/.gitignore | 2 + .../typescript/stealth-vault/README.md | 54 ++++ .../typescript/stealth-vault/package.json | 17 ++ .../typescript/stealth-vault/src/index.ts | 237 ++++++++++++++++ .../typescript/stealth-vault/tsconfig.json | 98 +++++++ .../typescript/wraith-asset-policy/.gitignore | 2 + .../typescript/wraith-asset-policy/README.md | 54 ++++ .../wraith-asset-policy/package.json | 17 ++ .../wraith-asset-policy/src/index.ts | 91 +++++++ .../wraith-asset-policy/tsconfig.json | 98 +++++++ stellar/scripts/generate-bindings.ts | 27 ++ 18 files changed, 1125 insertions(+), 1 deletion(-) create mode 100644 stellar/bindings/typescript/stealth-splitter/.gitignore create mode 100644 stellar/bindings/typescript/stealth-splitter/README.md create mode 100644 stellar/bindings/typescript/stealth-splitter/package.json create mode 100644 stellar/bindings/typescript/stealth-splitter/src/index.ts create mode 100644 stellar/bindings/typescript/stealth-splitter/tsconfig.json create mode 100644 stellar/bindings/typescript/stealth-vault/.gitignore create mode 100644 stellar/bindings/typescript/stealth-vault/README.md create mode 100644 stellar/bindings/typescript/stealth-vault/package.json create mode 100644 stellar/bindings/typescript/stealth-vault/src/index.ts create mode 100644 stellar/bindings/typescript/stealth-vault/tsconfig.json create mode 100644 stellar/bindings/typescript/wraith-asset-policy/.gitignore create mode 100644 stellar/bindings/typescript/wraith-asset-policy/README.md create mode 100644 stellar/bindings/typescript/wraith-asset-policy/package.json create mode 100644 stellar/bindings/typescript/wraith-asset-policy/src/index.ts create mode 100644 stellar/bindings/typescript/wraith-asset-policy/tsconfig.json diff --git a/stellar/abi/update.sh b/stellar/abi/update.sh index 7270640e..1daa8ecc 100755 --- a/stellar/abi/update.sh +++ b/stellar/abi/update.sh @@ -8,7 +8,7 @@ echo "Building contracts..." cargo build --target wasm32-unknown-unknown --release echo "Extracting ABI snapshots..." -for contract in stealth_announcer stealth_registry stealth_sender stealth_batch_sender wraith_names; do +for contract in stealth_announcer stealth_registry stealth_sender stealth_batch_sender wraith_names stealth_splitter stealth_vault wraith_asset_policy; do stellar contract info interface \ --wasm "target/wasm32-unknown-unknown/release/${contract}.wasm" \ --output json-formatted > "abi/${contract}.json" diff --git a/stellar/bindings/typescript/index.ts b/stellar/bindings/typescript/index.ts index 2f5c093f..61a8efe6 100644 --- a/stellar/bindings/typescript/index.ts +++ b/stellar/bindings/typescript/index.ts @@ -5,3 +5,6 @@ export * as StealthRegistry from './stealth-registry/src/index'; export * as StealthSender from './stealth-sender/src/index'; export * as StealthBatchSender from './stealth-batch-sender/src/index'; export * as WraithNames from './wraith-names/src/index'; +export * as StealthSplitter from './stealth-splitter/src/index'; +export * as StealthVault from './stealth-vault/src/index'; +export * as WraithAssetPolicy from './wraith-asset-policy/src/index'; diff --git a/stellar/bindings/typescript/stealth-splitter/.gitignore b/stellar/bindings/typescript/stealth-splitter/.gitignore new file mode 100644 index 00000000..72aae85f --- /dev/null +++ b/stellar/bindings/typescript/stealth-splitter/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +out/ diff --git a/stellar/bindings/typescript/stealth-splitter/README.md b/stellar/bindings/typescript/stealth-splitter/README.md new file mode 100644 index 00000000..122251f3 --- /dev/null +++ b/stellar/bindings/typescript/stealth-splitter/README.md @@ -0,0 +1,54 @@ +# stealth-splitter JS + +JS library for interacting with [Soroban](https://soroban.stellar.org/) smart contract `stealth-splitter` via Soroban RPC. + +This library was automatically generated by Soroban CLI using a command similar to: + +```bash +soroban contract bindings ts \ + --rpc-url INSERT_RPC_URL_HERE \ + --network-passphrase "INSERT_NETWORK_PASSPHRASE_HERE" \ + --contract-id INSERT_CONTRACT_ID_HERE \ + --output-dir ./path/to/stealth-splitter +``` + +The network passphrase and contract ID are exported from [index.ts](./src/index.ts) in the `networks` constant. If you are the one who generated this library and you know that this contract is also deployed to other networks, feel free to update `networks` with other valid options. This will help your contract consumers use this library more easily. + +# To publish or not to publish + +This library is suitable for publishing to NPM. You can publish it to NPM using the `npm publish` command. + +But you don't need to publish this library to NPM to use it. You can add it to your project's `package.json` using a file path: + +```json +"dependencies": { + "stealth-splitter": "./path/to/this/folder" +} +``` + +However, we've actually encountered [frustration](https://github.com/stellar/soroban-example-dapp/pull/117#discussion_r1232873560) using local libraries with NPM in this way. Though it seems a bit messy, we suggest generating the library directly to your `node_modules` folder automatically after each install by using a `postinstall` script. We've had the least trouble with this approach. NPM will automatically remove what it sees as erroneous directories during the `install` step, and then regenerate them when it gets to your `postinstall` step, which will keep the library up-to-date with your contract. + +```json +"scripts": { + "postinstall": "soroban contract bindings ts --rpc-url INSERT_RPC_URL_HERE --network-passphrase \"INSERT_NETWORK_PASSPHRASE_HERE\" --id INSERT_CONTRACT_ID_HERE --name stealth-splitter" +} +``` + +Obviously you need to adjust the above command based on the actual command you used to generate the library. + +# Use it + +Now that you have your library up-to-date and added to your project, you can import it in a file and see inline documentation for all of its exported methods: + +```js +import { Contract, networks } from "stealth-splitter" + +const contract = new Contract({ + ...networks.futurenet, // for example; check which networks this library exports + rpcUrl: '...', // use your own, or find one for testing at https://soroban.stellar.org/docs/reference/rpc#public-rpc-providers +}) + +contract.| +``` + +As long as your editor is configured to show JavaScript/TypeScript documentation, you can pause your typing at that `|` to get a list of all exports and inline-documentation for each. It exports a separate [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) function for each method in the smart contract, with documentation for each generated from the comments the contract's author included in the original source code. diff --git a/stellar/bindings/typescript/stealth-splitter/package.json b/stellar/bindings/typescript/stealth-splitter/package.json new file mode 100644 index 00000000..75075471 --- /dev/null +++ b/stellar/bindings/typescript/stealth-splitter/package.json @@ -0,0 +1,17 @@ +{ + "version": "0.0.0", + "name": "stealth-splitter", + "type": "module", + "exports": "./dist/index.js", + "typings": "dist/index.d.ts", + "scripts": { + "build": "tsc" + }, + "dependencies": { + "@stellar/stellar-sdk": "^16.0.1", + "buffer": "6.0.3" + }, + "devDependencies": { + "typescript": "^5.6.2" + } +} diff --git a/stellar/bindings/typescript/stealth-splitter/src/index.ts b/stellar/bindings/typescript/stealth-splitter/src/index.ts new file mode 100644 index 00000000..c347177a --- /dev/null +++ b/stellar/bindings/typescript/stealth-splitter/src/index.ts @@ -0,0 +1,253 @@ +import { Buffer } from "buffer"; +import { Address } from "@stellar/stellar-sdk"; +import { + AssembledTransaction, + Client as ContractClient, + ClientOptions as ContractClientOptions, + MethodOptions, + Result, + Spec as ContractSpec, +} from "@stellar/stellar-sdk/contract"; +import type { + u32, + i32, + u64, + i64, + u128, + i128, + u256, + i256, + Option, + Timepoint, + Duration, +} from "@stellar/stellar-sdk/contract"; +export * from "@stellar/stellar-sdk"; +export * as contract from "@stellar/stellar-sdk/contract"; +export * as rpc from "@stellar/stellar-sdk/rpc"; + +if (typeof window !== "undefined") { + //@ts-ignore Buffer exists + window.Buffer = window.Buffer || Buffer; +} + + + + +/** + * Storage keys. + */ +export type DataKey = {tag: "Announcer", values: void} | {tag: "Split", values: readonly [Buffer]} | {tag: "SplitFunded", values: readonly [Buffer]}; + + +/** + * A single beneficiary in a split. + */ +export interface Beneficiary { + /** + * Stealth meta-address of the beneficiary (64 bytes: spending_pubkey || viewing_pubkey). + */ +meta_address: Buffer; + /** + * Weight for proportional distribution. + */ +weight: u128; +} + + +/** + * Details returned by get_split query. + */ +export interface SplitDetails { + /** + * Immutable list of beneficiaries. + */ +beneficiaries: Array; + /** + * Total amount funded to date. + */ +total_funded: i128; +} + +/** + * Errors that the splitter contract can produce. + */ +export const SplitterError = { + /** + * The contract has already been initialised. + */ + 1: {message:"AlreadyInitialized"}, + /** + * The contract has not been initialised yet. + */ + 2: {message:"NotInitialized"}, + /** + * The split does not exist. + */ + 3: {message:"SplitNotFound"}, + /** + * Too many beneficiaries (max 25). + */ + 4: {message:"TooManyBeneficiaries"}, + /** + * Weight sum would overflow (internal sanity check). + */ + 5: {message:"WeightOverflow"}, + /** + * Invalid beneficiary meta-address length (must be 64 bytes). + */ + 6: {message:"InvalidMetaAddressLength"}, + /** + * Amount to fund is zero or negative. + */ + 7: {message:"InvalidAmount"}, + /** + * Empty beneficiary list. + */ + 8: {message:"EmptyBeneficiaries"} +} + + +/** + * Complete definition of a split. + */ +export interface SplitDefinition { + /** + * Token contract address. + */ +asset: string; + /** + * List of beneficiaries (max 25 enforced at creation). + */ +beneficiaries: Array; + /** + * Creator address. + */ +creator: string; + /** + * Salt used to create this split (for uniqueness). + */ +salt: Buffer; +} + + +/** + * Wraith Protocol standard metric event schema. + * + * All Wraith contracts emit metric events using this structure to enable + * standardized off-chain observability and monitoring. + */ +export interface WraithMetricEvent { + /** + * Contract identifier (e.g., "stealth-registry", "stealth-sender") + */ +contract: string; + /** + * Optional dimensions for filtering/grouping (e.g., token_address, scheme_id) + */ +dimensions: Array; + /** + * Metric name (e.g., "register_count", "send_volume") + */ +metric_name: string; + /** + * Numeric value of the metric + */ +value: i128; +} + +export interface Client { + /** + * Construct and simulate a init transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Initialise the contract by storing the announcer address. + * + * Must be called exactly once before any `create_split` or `fund_split`. + */ + init: ({announcer}: {announcer: string}, options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a get_split transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Query split details: beneficiaries and total funded amount. + * + * # Arguments + * * `split_id` - The split to query. + * + * # Returns + * SplitDetails with immutable beneficiary list and total_funded. + */ + get_split: ({split_id}: {split_id: Buffer}, options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a fund_split transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Fund a split: deposit amount and atomically distribute to all beneficiaries. + * + * Each beneficiary receives a proportional share based on their weight. + * Rounding error (dust) is absorbed by the first beneficiary. + * All transfers and announcements are atomic: any failure rolls back everything. + * + * # Arguments + * * `funder` - The address funding the split (must authorise). + * * `split_id` - The split to fund. + * * `amount` - Total amount to distribute. + * * `scheme_id` - Stealth address scheme identifier. + * * `stealth_addresses` - One-time stealth address for each beneficiary. + * * `ephemeral_pub_keys` - Ephemeral key for each beneficiary. + * * `metadatas` - Metadata (e.g. view tag) for each beneficiary. + */ + fund_split: ({funder, split_id, amount, scheme_id, stealth_addresses, ephemeral_pub_keys, metadatas}: {funder: string, split_id: Buffer, amount: i128, scheme_id: u32, stealth_addresses: Array, ephemeral_pub_keys: Array, metadatas: Array}, options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a create_split transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Create a split definition (immutable after creation). + * + * Computes a deterministic split_id from the beneficiaries, asset, and salt. + * The split is not funded until `fund_split` is called. + * + * # Arguments + * * `creator` - The address creating the split (must authorise). + * * `beneficiaries` - List of (meta_address, weight) pairs. Max 25. + * * `asset` - The token contract address to be split. + * * `salt` - Random bytes to ensure uniqueness. + * + * # Returns + * The deterministic split_id (32-byte hash). + */ + create_split: ({creator, beneficiaries, asset, salt}: {creator: string, beneficiaries: Array, asset: string, salt: Buffer}, options?: MethodOptions) => Promise>> + +} +export class Client extends ContractClient { + static async deploy( + /** Options for initializing a Client as well as for calling a method, with extras specific to deploying. */ + options: MethodOptions & + Omit & { + /** The hash of the Wasm blob, which must already be installed on-chain. */ + wasmHash: Buffer | string; + /** Salt used to generate the contract's ID. Passed through to {@link Operation.createCustomContract}. Default: random. */ + salt?: Buffer | Uint8Array; + /** The format used to decode `wasmHash`, if it's provided as a string. */ + format?: "hex" | "base64"; + } + ): Promise> { + return ContractClient.deploy(null, options) + } + constructor(public readonly options: ContractClientOptions) { + super( + new ContractSpec([ "AAAAAAAAAIFJbml0aWFsaXNlIHRoZSBjb250cmFjdCBieSBzdG9yaW5nIHRoZSBhbm5vdW5jZXIgYWRkcmVzcy4KCk11c3QgYmUgY2FsbGVkIGV4YWN0bHkgb25jZSBiZWZvcmUgYW55IGBjcmVhdGVfc3BsaXRgIG9yIGBmdW5kX3NwbGl0YC4AAAAAAAAEaW5pdAAAAAEAAAAAAAAACWFubm91bmNlcgAAAAAAABMAAAABAAAD6QAAA+0AAAAAAAAH0AAAAA1TcGxpdHRlckVycm9yAAAA", + "AAAAAAAAALVRdWVyeSBzcGxpdCBkZXRhaWxzOiBiZW5lZmljaWFyaWVzIGFuZCB0b3RhbCBmdW5kZWQgYW1vdW50LgoKIyBBcmd1bWVudHMKKiBgc3BsaXRfaWRgIC0gVGhlIHNwbGl0IHRvIHF1ZXJ5LgoKIyBSZXR1cm5zClNwbGl0RGV0YWlscyB3aXRoIGltbXV0YWJsZSBiZW5lZmljaWFyeSBsaXN0IGFuZCB0b3RhbF9mdW5kZWQuAAAAAAAACWdldF9zcGxpdAAAAAAAAAEAAAAAAAAACHNwbGl0X2lkAAAD7gAAACAAAAABAAAD6QAAB9AAAAAMU3BsaXREZXRhaWxzAAAH0AAAAA1TcGxpdHRlckVycm9yAAAA", + "AAAAAgAAAA1TdG9yYWdlIGtleXMuAAAAAAAAAAAAAAdEYXRhS2V5AAAAAAMAAAAAAAAAMkFkZHJlc3Mgb2YgdGhlIGRlcGxveWVkIFN0ZWFsdGhBbm5vdW5jZXIgY29udHJhY3QuAAAAAAAJQW5ub3VuY2VyAAAAAAAAAQAAAD5TdG9yZXMgc3BsaXQgZGVmaW5pdGlvbjogU3BsaXREZWZpbml0aW9uI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c3RhbmRhcmQgbWV0cmljIGV2ZW50IHNjaGVtYS4KCkFsbCBXcmFpdGggY29udHJhY3RzIGVtaXQgbWV0cmljIGV2ZW50cyB1c2luZyB0aGlzIHN0cnVjdHVyZSB0byBlbmFibGUKc3RhbmRhcmRpemVkIG9mZi1jaGFpbiBvYnNlcnZhYmlsaXR5IGFuZCBtb25pdG9yaW5nLgAAAAAAAAAAABFXcmFpdGhNZXRyaWNFdmVudAAAAAAAAAQAAABAQ29udHJhY3QgaWRlbnRpZmllciAoZS5nLiwgInN0ZWFsdGgtcmVnaXN0cnkiLCAic3RlYWx0aC1zZW5kZXIiKQAAAAhjb250cmFjdAAAABEAAABLT3B0aW9uYWwgZGltZW5zaW9ucyBmb3IgZmlsdGVyaW5nL2dyb3VwaW5nIChlLmcuLCB0b2tlbl9hZGRyZXNzLCBzY2hlbWVfaWQpAAAAAApkaW1lbnNpb25zAAAAAAPqAAAD7QAAAAIAAAARAAAAAAAAADNNZXRyaWMgbmFtZSAoZS5nLiwgInJlZ2lzdGVyX2NvdW50IiwgInNlbmRfdm9sdW1lIikAAAAAC21ldHJpY19uYW1lAAAAABEAAAAbTnVtZXJpYyB2YWx1ZSBvZiB0aGUgbWV0cmljAAAAAAV2YWx1ZQAAAAAAAAs=" ]), + options + ) + } + public readonly fromJSON = { + init: this.txFromJSON>, + get_split: this.txFromJSON>, + fund_split: this.txFromJSON>, + create_split: this.txFromJSON> + } +} \ No newline at end of file diff --git a/stellar/bindings/typescript/stealth-splitter/tsconfig.json b/stellar/bindings/typescript/stealth-splitter/tsconfig.json new file mode 100644 index 00000000..acac1422 --- /dev/null +++ b/stellar/bindings/typescript/stealth-splitter/tsconfig.json @@ -0,0 +1,98 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + /* Language and Environment */ + "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + /* Modules */ + "module": "NodeNext", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + "moduleResolution": "nodenext", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + /* Emit */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./dist", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + // "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + // "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + /* Type Checking */ + // "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "include": [ + "src/*" + ] +} \ No newline at end of file diff --git a/stellar/bindings/typescript/stealth-vault/.gitignore b/stellar/bindings/typescript/stealth-vault/.gitignore new file mode 100644 index 00000000..72aae85f --- /dev/null +++ b/stellar/bindings/typescript/stealth-vault/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +out/ diff --git a/stellar/bindings/typescript/stealth-vault/README.md b/stellar/bindings/typescript/stealth-vault/README.md new file mode 100644 index 00000000..40a0db06 --- /dev/null +++ b/stellar/bindings/typescript/stealth-vault/README.md @@ -0,0 +1,54 @@ +# stealth-vault JS + +JS library for interacting with [Soroban](https://soroban.stellar.org/) smart contract `stealth-vault` via Soroban RPC. + +This library was automatically generated by Soroban CLI using a command similar to: + +```bash +soroban contract bindings ts \ + --rpc-url INSERT_RPC_URL_HERE \ + --network-passphrase "INSERT_NETWORK_PASSPHRASE_HERE" \ + --contract-id INSERT_CONTRACT_ID_HERE \ + --output-dir ./path/to/stealth-vault +``` + +The network passphrase and contract ID are exported from [index.ts](./src/index.ts) in the `networks` constant. If you are the one who generated this library and you know that this contract is also deployed to other networks, feel free to update `networks` with other valid options. This will help your contract consumers use this library more easily. + +# To publish or not to publish + +This library is suitable for publishing to NPM. You can publish it to NPM using the `npm publish` command. + +But you don't need to publish this library to NPM to use it. You can add it to your project's `package.json` using a file path: + +```json +"dependencies": { + "stealth-vault": "./path/to/this/folder" +} +``` + +However, we've actually encountered [frustration](https://github.com/stellar/soroban-example-dapp/pull/117#discussion_r1232873560) using local libraries with NPM in this way. Though it seems a bit messy, we suggest generating the library directly to your `node_modules` folder automatically after each install by using a `postinstall` script. We've had the least trouble with this approach. NPM will automatically remove what it sees as erroneous directories during the `install` step, and then regenerate them when it gets to your `postinstall` step, which will keep the library up-to-date with your contract. + +```json +"scripts": { + "postinstall": "soroban contract bindings ts --rpc-url INSERT_RPC_URL_HERE --network-passphrase \"INSERT_NETWORK_PASSPHRASE_HERE\" --id INSERT_CONTRACT_ID_HERE --name stealth-vault" +} +``` + +Obviously you need to adjust the above command based on the actual command you used to generate the library. + +# Use it + +Now that you have your library up-to-date and added to your project, you can import it in a file and see inline documentation for all of its exported methods: + +```js +import { Contract, networks } from "stealth-vault" + +const contract = new Contract({ + ...networks.futurenet, // for example; check which networks this library exports + rpcUrl: '...', // use your own, or find one for testing at https://soroban.stellar.org/docs/reference/rpc#public-rpc-providers +}) + +contract.| +``` + +As long as your editor is configured to show JavaScript/TypeScript documentation, you can pause your typing at that `|` to get a list of all exports and inline-documentation for each. It exports a separate [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) function for each method in the smart contract, with documentation for each generated from the comments the contract's author included in the original source code. diff --git a/stellar/bindings/typescript/stealth-vault/package.json b/stellar/bindings/typescript/stealth-vault/package.json new file mode 100644 index 00000000..f4857163 --- /dev/null +++ b/stellar/bindings/typescript/stealth-vault/package.json @@ -0,0 +1,17 @@ +{ + "version": "0.0.0", + "name": "stealth-vault", + "type": "module", + "exports": "./dist/index.js", + "typings": "dist/index.d.ts", + "scripts": { + "build": "tsc" + }, + "dependencies": { + "@stellar/stellar-sdk": "^16.0.1", + "buffer": "6.0.3" + }, + "devDependencies": { + "typescript": "^5.6.2" + } +} diff --git a/stellar/bindings/typescript/stealth-vault/src/index.ts b/stellar/bindings/typescript/stealth-vault/src/index.ts new file mode 100644 index 00000000..d05b840c --- /dev/null +++ b/stellar/bindings/typescript/stealth-vault/src/index.ts @@ -0,0 +1,237 @@ +import { Buffer } from "buffer"; +import { Address } from "@stellar/stellar-sdk"; +import { + AssembledTransaction, + Client as ContractClient, + ClientOptions as ContractClientOptions, + MethodOptions, + Result, + Spec as ContractSpec, +} from "@stellar/stellar-sdk/contract"; +import type { + u32, + i32, + u64, + i64, + u128, + i128, + u256, + i256, + Option, + Timepoint, + Duration, +} from "@stellar/stellar-sdk/contract"; +export * from "@stellar/stellar-sdk"; +export * as contract from "@stellar/stellar-sdk/contract"; +export * as rpc from "@stellar/stellar-sdk/rpc"; + +if (typeof window !== "undefined") { + //@ts-ignore Buffer exists + window.Buffer = window.Buffer || Buffer; +} + + + + +export type DataKey = {tag: "Deposit", values: readonly [Buffer]} | {tag: "Announcer", values: void} | {tag: "Admin", values: void} | {tag: "Paused", values: void} | {tag: "GracePeriod", values: void}; + +export const VaultError = { + 1: {message:"AlreadyInitialized"}, + 2: {message:"NotInitialized"}, + 3: {message:"InvalidWindow"}, + 4: {message:"DepositNotFound"}, + 5: {message:"NotYetUnlocked"}, + 6: {message:"NotYetRefundable"}, + 7: {message:"WrongRecipient"}, + /** + * The contract is paused; `deposit` is unavailable until an admin unpauses. + */ + 8: {message:"Paused"}, + /** + * The permissionless refund window has not opened yet. + */ + 9: {message:"NotYetPermissionless"}, + /** + * `set_grace_period` was called with zero. + */ + 10: {message:"InvalidGracePeriod"} +} + + +export interface DepositEntry { + amount: i128; + asset: string; + recipient: string; + refund_after: u32; + sender: string; + unlock_ledger: u32; +} + + +/** + * Wraith Protocol standard metric event schema. + * + * All Wraith contracts emit metric events using this structure to enable + * standardized off-chain observability and monitoring. + */ +export interface WraithMetricEvent { + /** + * Contract identifier (e.g., "stealth-registry", "stealth-sender") + */ +contract: string; + /** + * Optional dimensions for filtering/grouping (e.g., token_address, scheme_id) + */ +dimensions: Array; + /** + * Metric name (e.g., "register_count", "send_volume") + */ +metric_name: string; + /** + * Numeric value of the metric + */ +value: i128; +} + +export interface Client { + /** + * Construct and simulate a init transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Initialise the vault with its pause admin and announcer address. + * + * Must be called exactly once before any `deposit`. The grace period is + * seeded to `DEFAULT_GRACE_PERIOD` and can be retuned by the admin. + */ + init: ({admin, announcer}: {admin: string, announcer: string}, options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a admin transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Returns the pause admin. + */ + admin: (options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a claim transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Claim a deposit. Callable while paused so recipients can always exit. + */ + claim: ({deposit_id, recipient}: {deposit_id: Buffer, recipient: string}, options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a pause transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Pause the contract — admin only. + * + * Blocks new deposits. `claim`, `refund`, and `refund_permissionless` + * stay callable so depositors and recipients can always exit. + */ + pause: ({caller}: {caller: string}, options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a refund transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Refund an unclaimed deposit to its depositor. Callable while paused. + * + * Requires the depositor's authorisation and opens at `refund_after`. + */ + refund: ({deposit_id}: {deposit_id: Buffer}, options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a deposit transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + */ + deposit: ({sender, recipient, amount, asset, unlock_ledger, refund_after, ephemeral_pub_key}: {sender: string, recipient: string, amount: i128, asset: string, unlock_ledger: u32, refund_after: u32, ephemeral_pub_key: Buffer}, options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a unpause transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Unpause the contract — admin only. + */ + unpause: ({caller}: {caller: string}, options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a is_paused transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Returns true if the contract is paused. + */ + is_paused: (options?: MethodOptions) => Promise> + + /** + * Construct and simulate a get_deposit transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Look up a stored deposit without mutating it. + */ + get_deposit: ({deposit_id}: {deposit_id: Buffer}, options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a grace_period transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Returns the configured grace period in ledgers. + */ + grace_period: (options?: MethodOptions) => Promise> + + /** + * Construct and simulate a set_grace_period transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Retune the grace period — admin only. + * + * Applies to deposits made after the change; already-stored deposits keep + * the absolute `unlock_ledger` / `refund_after` they were created with, + * but their permissionless refund window moves with the new value. + */ + set_grace_period: ({caller, grace_period}: {caller: string, grace_period: u32}, options?: MethodOptions) => Promise>> + + /** + * Construct and simulate a refund_permissionless transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + * Refund an unclaimed deposit to its depositor without the depositor's + * signature. Callable while paused. + * + * Opens one grace period after `refund_after`, so a depositor who has lost + * access to their key cannot strand funds in the vault forever. Funds + * always go to the recorded depositor — `caller` only pays the fee and is + * authorised so the invocation is attributable. + */ + refund_permissionless: ({caller, deposit_id}: {caller: string, deposit_id: Buffer}, options?: MethodOptions) => Promise>> + +} +export class Client extends ContractClient { + static async deploy( + /** Options for initializing a Client as well as for calling a method, with extras specific to deploying. */ + options: MethodOptions & + Omit & { + /** The hash of the Wasm blob, which must already be installed on-chain. */ + wasmHash: Buffer | string; + /** Salt used to generate the contract's ID. Passed through to {@link Operation.createCustomContract}. Default: random. */ + salt?: Buffer | Uint8Array; + /** The format used to decode `wasmHash`, if it's provided as a string. */ + format?: "hex" | "base64"; + } + ): Promise> { + return ContractClient.deploy(null, options) + } + constructor(public readonly options: ContractClientOptions) { + super( + new ContractSpec([ "AAAAAAAAAMlJbml0aWFsaXNlIHRoZSB2YXVsdCB3aXRoIGl0cyBwYXVzZSBhZG1pbiBhbmQgYW5ub3VuY2VyIGFkZHJlc3MuCgpNdXN0IGJlIGNhbGxlZCBleGFjdGx5IG9uY2UgYmVmb3JlIGFueSBgZGVwb3NpdGAuIFRoZSBncmFjZSBwZXJpb2QgaXMKc2VlZGVkIHRvIGBERUZBVUxUX0dSQUNFX1BFUklPRGAgYW5kIGNhbiBiZSByZXR1bmVkIGJ5IHRoZSBhZG1pbi4AAAAAAAAEaW5pdAAAAAIAAAAAAAAABWFkbWluAAAAAAAAEwAAAAAAAAAJYW5ub3VuY2VyAAAAAAAAEwAAAAEAAAPpAAAD7QAAAAAAAAfQAAAAClZhdWx0RXJyb3IAAA==", + "AAAAAAAAABhSZXR1cm5zIHRoZSBwYXVzZSBhZG1pbi4AAAAFYWRtaW4AAAAAAAAAAAAAAQAAA+kAAAATAAAH0AAAAApWYXVsdEVycm9yAAA=", + "AAAAAAAAAEVDbGFpbSBhIGRlcG9zaXQuIENhbGxhYmxlIHdoaWxlIHBhdXNlZCBzbyByZWNpcGllbnRzIGNhbiBhbHdheXMgZXhpdC4AAAAAAAAFY2xhaW0AAAAAAAACAAAAAAAAAApkZXBvc2l0X2lkAAAAAAPuAAAAIAAAAAAAAAAJcmVjaXBpZW50AAAAAAAAEwAAAAEAAAPpAAAD7QAAAAAAAAfQAAAAClZhdWx0RXJyb3IAAA==", + "AAAAAAAAAKNQYXVzZSB0aGUgY29udHJhY3Qg4oCUIGFkbWluIG9ubHkuCgpCbG9ja3MgbmV3IGRlcG9zaXRzL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S5nLiwgInN0ZWFsdGgtcmVnaXN0cnkiLCAic3RlYWx0aC1zZW5kZXIiKQAAAAhjb250cmFjdAAAABEAAABLT3B0aW9uYWwgZGltZW5zaW9ucyBmb3IgZmlsdGVyaW5nL2dyb3VwaW5nIChlLmcuLCB0b2tlbl9hZGRyZXNzLCBzY2hlbWVfaWQpAAAAAApkaW1lbnNpb25zAAAAAAPqAAAD7QAAAAIAAAARAAAAAAAAADNNZXRyaWMgbmFtZSAoZS5nLiwgInJlZ2lzdGVyX2NvdW50IiwgInNlbmRfdm9sdW1lIikAAAAAC21ldHJpY19uYW1lAAAAABEAAAAbTnVtZXJpYyB2YWx1ZSBvZiB0aGUgbWV0cmljAAAAAAV2YWx1ZQAAAAAAAAs=" ]), + options + ) + } + public readonly fromJSON = { + init: this.txFromJSON>, + admin: this.txFromJSON>, + claim: this.txFromJSON>, + pause: this.txFromJSON>, + refund: this.txFromJSON>, + deposit: this.txFromJSON>, + unpause: this.txFromJSON>, + is_paused: this.txFromJSON, + get_deposit: this.txFromJSON>, + grace_period: this.txFromJSON, + set_grace_period: this.txFromJSON>, + refund_permissionless: this.txFromJSON> + } +} \ No newline at end of file diff --git a/stellar/bindings/typescript/stealth-vault/tsconfig.json b/stellar/bindings/typescript/stealth-vault/tsconfig.json new file mode 100644 index 00000000..acac1422 --- /dev/null +++ b/stellar/bindings/typescript/stealth-vault/tsconfig.json @@ -0,0 +1,98 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + /* Language and Environment */ + "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + /* Modules */ + "module": "NodeNext", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + "moduleResolution": "nodenext", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + /* Emit */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./dist", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + // "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + // "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + /* Type Checking */ + // "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "include": [ + "src/*" + ] +} \ No newline at end of file diff --git a/stellar/bindings/typescript/wraith-asset-policy/.gitignore b/stellar/bindings/typescript/wraith-asset-policy/.gitignore new file mode 100644 index 00000000..72aae85f --- /dev/null +++ b/stellar/bindings/typescript/wraith-asset-policy/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +out/ diff --git a/stellar/bindings/typescript/wraith-asset-policy/README.md b/stellar/bindings/typescript/wraith-asset-policy/README.md new file mode 100644 index 00000000..22ff3930 --- /dev/null +++ b/stellar/bindings/typescript/wraith-asset-policy/README.md @@ -0,0 +1,54 @@ +# wraith-asset-policy JS + +JS library for interacting with [Soroban](https://soroban.stellar.org/) smart contract `wraith-asset-policy` via Soroban RPC. + +This library was automatically generated by Soroban CLI using a command similar to: + +```bash +soroban contract bindings ts \ + --rpc-url INSERT_RPC_URL_HERE \ + --network-passphrase "INSERT_NETWORK_PASSPHRASE_HERE" \ + --contract-id INSERT_CONTRACT_ID_HERE \ + --output-dir ./path/to/wraith-asset-policy +``` + +The network passphrase and contract ID are exported from [index.ts](./src/index.ts) in the `networks` constant. If you are the one who generated this library and you know that this contract is also deployed to other networks, feel free to update `networks` with other valid options. This will help your contract consumers use this library more easily. + +# To publish or not to publish + +This library is suitable for publishing to NPM. You can publish it to NPM using the `npm publish` command. + +But you don't need to publish this library to NPM to use it. You can add it to your project's `package.json` using a file path: + +```json +"dependencies": { + "wraith-asset-policy": "./path/to/this/folder" +} +``` + +However, we've actually encountered [frustration](https://github.com/stellar/soroban-example-dapp/pull/117#discussion_r1232873560) using local libraries with NPM in this way. Though it seems a bit messy, we suggest generating the library directly to your `node_modules` folder automatically after each install by using a `postinstall` script. We've had the least trouble with this approach. NPM will automatically remove what it sees as erroneous directories during the `install` step, and then regenerate them when it gets to your `postinstall` step, which will keep the library up-to-date with your contract. + +```json +"scripts": { + "postinstall": "soroban contract bindings ts --rpc-url INSERT_RPC_URL_HERE --network-passphrase \"INSERT_NETWORK_PASSPHRASE_HERE\" --id INSERT_CONTRACT_ID_HERE --name wraith-asset-policy" +} +``` + +Obviously you need to adjust the above command based on the actual command you used to generate the library. + +# Use it + +Now that you have your library up-to-date and added to your project, you can import it in a file and see inline documentation for all of its exported methods: + +```js +import { Contract, networks } from "wraith-asset-policy" + +const contract = new Contract({ + ...networks.futurenet, // for example; check which networks this library exports + rpcUrl: '...', // use your own, or find one for testing at https://soroban.stellar.org/docs/reference/rpc#public-rpc-providers +}) + +contract.| +``` + +As long as your editor is configured to show JavaScript/TypeScript documentation, you can pause your typing at that `|` to get a list of all exports and inline-documentation for each. It exports a separate [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) function for each method in the smart contract, with documentation for each generated from the comments the contract's author included in the original source code. diff --git a/stellar/bindings/typescript/wraith-asset-policy/package.json b/stellar/bindings/typescript/wraith-asset-policy/package.json new file mode 100644 index 00000000..94c21fb5 --- /dev/null +++ b/stellar/bindings/typescript/wraith-asset-policy/package.json @@ -0,0 +1,17 @@ +{ + "version": "0.0.0", + "name": "wraith-asset-policy", + "type": "module", + "exports": "./dist/index.js", + "typings": "dist/index.d.ts", + "scripts": { + "build": "tsc" + }, + "dependencies": { + "@stellar/stellar-sdk": "^16.0.1", + "buffer": "6.0.3" + }, + "devDependencies": { + "typescript": "^5.6.2" + } +} diff --git a/stellar/bindings/typescript/wraith-asset-policy/src/index.ts b/stellar/bindings/typescript/wraith-asset-policy/src/index.ts new file mode 100644 index 00000000..2109a9d9 --- /dev/null +++ b/stellar/bindings/typescript/wraith-asset-policy/src/index.ts @@ -0,0 +1,91 @@ +import { Buffer } from "buffer"; +import { Address } from "@stellar/stellar-sdk"; +import { + AssembledTransaction, + Client as ContractClient, + ClientOptions as ContractClientOptions, + MethodOptions, + Result, + Spec as ContractSpec, +} from "@stellar/stellar-sdk/contract"; +import type { + u32, + i32, + u64, + i64, + u128, + i128, + u256, + i256, + Option, + Timepoint, + Duration, +} from "@stellar/stellar-sdk/contract"; +export * from "@stellar/stellar-sdk"; +export * as contract from "@stellar/stellar-sdk/contract"; +export * as rpc from "@stellar/stellar-sdk/rpc"; + +if (typeof window !== "undefined") { + //@ts-ignore Buffer exists + window.Buffer = window.Buffer || Buffer; +} + + + + +export type DataKey = {tag: "Admin", values: void} | {tag: "Asset", values: readonly [string]}; + +export interface Client { + /** + * Construct and simulate a init transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + */ + init: ({admin, default_assets}: {admin: string, default_assets: Array}, options?: MethodOptions) => Promise> + + /** + * Construct and simulate a add_asset transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + */ + add_asset: ({asset}: {asset: string}, options?: MethodOptions) => Promise> + + /** + * Construct and simulate a check_asset transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + */ + check_asset: ({asset}: {asset: string}, options?: MethodOptions) => Promise> + + /** + * Construct and simulate a remove_asset transaction. Returns an `AssembledTransaction` object which will have a `result` field containing the result of the simulation. If this transaction changes contract state, you will need to call `signAndSend()` on the returned object. + */ + remove_asset: ({asset}: {asset: string}, options?: MethodOptions) => Promise> + +} +export class Client extends ContractClient { + static async deploy( + /** Options for initializing a Client as well as for calling a method, with extras specific to deploying. */ + options: MethodOptions & + Omit & { + /** The hash of the Wasm blob, which must already be installed on-chain. */ + wasmHash: Buffer | string; + /** Salt used to generate the contract's ID. Passed through to {@link Operation.createCustomContract}. Default: random. */ + salt?: Buffer | Uint8Array; + /** The format used to decode `wasmHash`, if it's provided as a string. */ + format?: "hex" | "base64"; + } + ): Promise> { + return ContractClient.deploy(null, options) + } + constructor(public readonly options: ContractClientOptions) { + super( + new ContractSpec([ "AAAAAAAAAAAAAAAEaW5pdAAAAAIAAAAAAAAABWFkbWluAAAAAAAAEwAAAAAAAAAOZGVmYXVsdF9hc3NldHMAAAAAA+oAAAATAAAAAA==", + "AAAAAAAAAAAAAAAJYWRkX2Fzc2V0AAAAAAAAAQAAAAAAAAAFYXNzZXQAAAAAAAATAAAAAA==", + "AAAAAgAAAAAAAAAAAAAAB0RhdGFLZXkAAAAAAgAAAAAAAAAAAAAABUFkbWluAAAAAAAAAQAAAAAAAAAFQXNzZXQAAAAAAAABAAAAEw==", + "AAAAAAAAAAAAAAALY2hlY2tfYXNzZXQAAAAAAQAAAAAAAAAFYXNzZXQAAAAAAAATAAAAAQAAAAE=", + "AAAAAAAAAAAAAAAMcmVtb3ZlX2Fzc2V0AAAAAQAAAAAAAAAFYXNzZXQAAAAAAAATAAAAAA==" ]), + options + ) + } + public readonly fromJSON = { + init: this.txFromJSON, + add_asset: this.txFromJSON, + check_asset: this.txFromJSON, + remove_asset: this.txFromJSON + } +} \ No newline at end of file diff --git a/stellar/bindings/typescript/wraith-asset-policy/tsconfig.json b/stellar/bindings/typescript/wraith-asset-policy/tsconfig.json new file mode 100644 index 00000000..acac1422 --- /dev/null +++ b/stellar/bindings/typescript/wraith-asset-policy/tsconfig.json @@ -0,0 +1,98 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + /* Language and Environment */ + "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + /* Modules */ + "module": "NodeNext", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + "moduleResolution": "nodenext", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + /* Emit */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./dist", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + // "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + // "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + /* Type Checking */ + // "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "include": [ + "src/*" + ] +} \ No newline at end of file diff --git a/stellar/scripts/generate-bindings.ts b/stellar/scripts/generate-bindings.ts index 21ec3716..5dbabfea 100644 --- a/stellar/scripts/generate-bindings.ts +++ b/stellar/scripts/generate-bindings.ts @@ -10,6 +10,9 @@ const BINDINGS_DIR = path.join(STELLAR_DIR, 'bindings', 'typescript'); const CONFIG_FILE = path.join(STELLAR_DIR, 'contract-ids.json'); // Contract Crates mapping to their package/class names and compiled WASM filenames +// Internal-only crates intentionally excluded from bindings: +// - wraith-metrics: shared library (rlib), not a deployable contract +// - bench, bench-crossover, integration-tests: host-only test/bench crates interface ContractMetadata { crateName: string; // Crate directory name, e.g. "stealth-registry" wasmName: string; // Cargo output wasm file, e.g. "stealth_registry.wasm" @@ -42,6 +45,26 @@ const CONTRACTS: ContractMetadata[] = [ wasmName: 'wraith_names.wasm', envVar: 'WRAITH_NAMES_CONTRACT_ID', }, + { + crateName: 'stealth-splitter', + wasmName: 'stealth_splitter.wasm', + envVar: 'STEALTH_SPLITTER_CONTRACT_ID', + }, + { + crateName: 'stealth-vault', + wasmName: 'stealth_vault.wasm', + envVar: 'STEALTH_VAULT_CONTRACT_ID', + }, + { + crateName: 'wraith-asset-policy', + wasmName: 'wraith_asset_policy.wasm', + envVar: 'WRAITH_ASSET_POLICY_CONTRACT_ID', + }, + { + crateName: 'governance', + wasmName: 'governance.wasm', + envVar: 'GOVERNANCE_CONTRACT_ID', + }, ]; // Helper to check if a command exists in the system path @@ -249,6 +272,10 @@ export * as StealthRegistry from './stealth-registry/src/index'; export * as StealthSender from './stealth-sender/src/index'; export * as StealthBatchSender from './stealth-batch-sender/src/index'; export * as WraithNames from './wraith-names/src/index'; +export * as StealthSplitter from './stealth-splitter/src/index'; +export * as StealthVault from './stealth-vault/src/index'; +export * as WraithAssetPolicy from './wraith-asset-policy/src/index'; +export * as Governance from './governance/src/index'; `; const indexFilePath = path.join(BINDINGS_DIR, 'index.ts'); From d344dad1c63ea746c360a966b4e51e04b8d28cd0 Mon Sep 17 00:00:00 2001 From: OluRemiFour Date: Wed, 21 Oct 2026 15:57:50 +0100 Subject: [PATCH 2/2] fix: add governance TypeScript binding and update barrel exports - Add governance TypeScript binding package (src/index.ts, package.json, tsconfig.json, README.md) - Export Governance from barrel file (stellar/bindings/typescript/index.ts) - Update stealth-batch-sender-bindings.test.ts to verify all new bindings (splitter, vault, asset-policy, governance) - Add governance-bindings.test.ts for governance-specific client verification - Update test:stellar-bindings script to run both test files Note: The governance binding is a stub that will be regenerated by CI's pnpm bindings:stellar step, which has access to Stellar CLI and deployed contract IDs. Generated with [Devin](https://devin.ai) --- package.json | 2 +- .../bindings/typescript/governance/.gitignore | 2 + .../bindings/typescript/governance/README.md | 54 ++++++ .../typescript/governance/package.json | 17 ++ .../typescript/governance/src/index.ts | 179 ++++++++++++++++++ .../typescript/governance/tsconfig.json | 98 ++++++++++ stellar/bindings/typescript/index.ts | 1 + stellar/scripts/governance-bindings.test.ts | 12 ++ .../stealth-batch-sender-bindings.test.ts | 33 +++- 9 files changed, 392 insertions(+), 6 deletions(-) create mode 100644 stellar/bindings/typescript/governance/.gitignore create mode 100644 stellar/bindings/typescript/governance/README.md create mode 100644 stellar/bindings/typescript/governance/package.json create mode 100644 stellar/bindings/typescript/governance/src/index.ts create mode 100644 stellar/bindings/typescript/governance/tsconfig.json create mode 100644 stellar/scripts/governance-bindings.test.ts diff --git a/package.json b/package.json index 6492820b..157bdd29 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "bindings:stellar": "tsx stellar/scripts/generate-bindings.ts", "build:stellar": "pnpm bindings:stellar && cd stellar && cargo build --target wasm32-unknown-unknown --release", - "test:stellar-bindings": "vitest run stellar/scripts/stealth-batch-sender-bindings.test.ts" + "test:stellar-bindings": "vitest run stellar/scripts/stealth-batch-sender-bindings.test.ts stellar/scripts/governance-bindings.test.ts" }, "pnpm": { "onlyBuiltDependencies": ["esbuild"] diff --git a/stellar/bindings/typescript/governance/.gitignore b/stellar/bindings/typescript/governance/.gitignore new file mode 100644 index 00000000..72aae85f --- /dev/null +++ b/stellar/bindings/typescript/governance/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +out/ diff --git a/stellar/bindings/typescript/governance/README.md b/stellar/bindings/typescript/governance/README.md new file mode 100644 index 00000000..b3822e54 --- /dev/null +++ b/stellar/bindings/typescript/governance/README.md @@ -0,0 +1,54 @@ +# governance JS + +JS library for interacting with [Soroban](https://soroban.stellar.org/) smart contract `governance` via Soroban RPC. + +This library was automatically generated by Soroban CLI using a command similar to: + +```bash +soroban contract bindings ts \ + --rpc-url INSERT_RPC_URL_HERE \ + --network-passphrase "INSERT_NETWORK_PASSPHRASE_HERE" \ + --contract-id INSERT_CONTRACT_ID_HERE \ + --output-dir ./path/to/governance +``` + +The network passphrase and contract ID are exported from [index.ts](./src/index.ts) in the `networks` constant. If you are the one who generated this library and you know that this contract is also deployed to other networks, feel free to update `networks` with other valid options. This will help your contract consumers use this library more easily. + +# To publish or not to publish + +This library is suitable for publishing to NPM. You can publish it to NPM using the `npm publish` command. + +But you don't need to publish this library to NPM to use it. You can add it to your project's `package.json` using a file path: + +```json +"dependencies": { + "governance": "./path/to/this/folder" +} +``` + +However, we've actually encountered [frustration](https://github.com/stellar/soroban-example-dapp/pull/117#discussion_r1232873560) using local libraries with NPM in this way. Though it seems a bit messy, we suggest generating the library directly to your `node_modules` folder automatically after each install by using a `postinstall` script. We've had the least trouble with this approach. NPM will automatically remove what it sees as erroneous directories during the `install` step, and then regenerate them when it gets to your `postinstall` step, which will keep the library up-to-date with your contract. + +```json +"scripts": { + "postinstall": "soroban contract bindings ts --rpc-url INSERT_RPC_URL_HERE --network-passphrase \"INSERT_NETWORK_PASSPHRASE_HERE\" --id INSERT_CONTRACT_ID_HERE --name governance" +} +``` + +Obviously you need to adjust the above command based on the actual command you used to generate the library. + +# Use it + +Now that you have your library up-to-date and added to your project, you can import it in a file and see inline documentation for all of its exported methods: + +```js +import { Contract, networks } from "governance" + +const contract = new Contract({ + ...networks.futurenet, // for example; check which networks this library exports + rpcUrl: '...', // use your own, or find one for testing at https://soroban.stellar.org/docs/reference/rpc#public-rpc-providers +}) + +contract.| +``` + +As long as your editor is configured to show JavaScript/TypeScript documentation, you can pause your typing at that `|` to get a list of all exports and inline-documentation for each. It exports a separate [async](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function) function for each method in the smart contract, with documentation for each generated from the comments the contract's author included in the original source code. diff --git a/stellar/bindings/typescript/governance/package.json b/stellar/bindings/typescript/governance/package.json new file mode 100644 index 00000000..03b83d2c --- /dev/null +++ b/stellar/bindings/typescript/governance/package.json @@ -0,0 +1,17 @@ +{ + "version": "0.0.0", + "name": "governance", + "type": "module", + "exports": "./dist/index.js", + "typings": "dist/index.d.ts", + "scripts": { + "build": "tsc" + }, + "dependencies": { + "@stellar/stellar-sdk": "^16.0.1", + "buffer": "6.0.3" + }, + "devDependencies": { + "typescript": "^5.6.2" + } +} diff --git a/stellar/bindings/typescript/governance/src/index.ts b/stellar/bindings/typescript/governance/src/index.ts new file mode 100644 index 00000000..ef139597 --- /dev/null +++ b/stellar/bindings/typescript/governance/src/index.ts @@ -0,0 +1,179 @@ +import { Buffer } from "buffer"; +import { Address } from "@stellar/stellar-sdk"; +import { + AssembledTransaction, + Client as ContractClient, + ClientOptions as ContractClientOptions, + MethodOptions, + Result, + Spec as ContractSpec, +} from "@stellar/stellar-sdk/contract"; +import type { + u32, + i32, + u64, + i64, + u128, + i128, + u256, + i256, + Option, + Timepoint, + Duration, +} from "@stellar/stellar-sdk/contract"; +export * from "@stellar/stellar-sdk"; +export * as contract from "@stellar/stellar-sdk/contract"; +export * as rpc from "@stellar/stellar-sdk/rpc"; + +if (typeof window !== "undefined") { + //@ts-ignore Buffer exists + window.Buffer = window.Buffer || Buffer; +} + +/** + * Governance configuration. + */ +export interface GovernanceConfig { + token: Buffer; + quorum: i128; + voting_period: u32; + timelock: u32; +} + +/** + * Proposal state. + */ +export type ProposalState = + | {tag: "Active", values: void} + | {tag: "Succeeded", values: void} + | {tag: "Defeated", values: void} + | {tag: "Executed", values: void} + | {tag: "Canceled", values: void}; + +/** + * A governance proposal. + */ +export interface Proposal { + id: u32; + proposer: Buffer; + target: Buffer; + function: string; + args: Buffer; + description: string; + for_votes: i128; + against_votes: i128; + start_ledger: u32; + end_ledger: u32; + state: ProposalState; +} + +/** + * Vote record. + */ +export interface Vote { + voter: Buffer; + support: boolean; + weight: i128; +} + +/** + * Governance errors. + */ +export type GovernanceError = + | {tag: "AlreadyInitialized", values: void} + | {tag: "NotInitialized", values: void} + | {tag: "ProposalNotFound", values: void} + | {tag: "ProposalNotActive", values: void} + | {tag: "AlreadyVoted", values: void} + | {tag: "ProposalNotSucceeded", values: void} + | {tag: "TimelockNotExpired", values: void} + | {tag: "Unauthorized", values: void}; + +export class Client extends ContractClient { + public spec: ContractSpec; + public options: ContractClientOptions; + + constructor(options: ContractClientOptions) { + super(options); + this.options = options; + this.spec = new ContractSpec({ + ...this.options, + contractId: this.options.contractId, + }); + } + + /** + * Initialize the governance contract. + */ + public async init(args: { + admin: Buffer; + token: Buffer; + quorum: i128; + voting_period: u32; + timelock: u32; + }, options?: MethodOptions): Promise> { + return this.call("init", args, options); + } + + /** + * Get the current governance configuration. + */ + public async get_config(options?: MethodOptions): Promise> { + return this.call("get_config", {}, options); + } + + /** + * Create a new governance proposal. + */ + public async propose(args: { + proposer: Buffer; + target: Buffer; + function: string; + args: Buffer; + description: string; + }, options?: MethodOptions): Promise> { + return this.call("propose", args, options); + } + + /** + * Get a proposal by ID. + */ + public async get_proposal(args: { proposal_id: u32 }, options?: MethodOptions): Promise> { + return this.call("get_proposal", args, options); + } + + /** + * Cast a vote on an active proposal. + */ + public async vote(args: { + voter: Buffer; + proposal_id: u32; + support: boolean; + }, options?: MethodOptions): Promise> { + return this.call("vote", args, options); + } + + /** + * Get the vote record for a voter on a proposal. + */ + public async get_vote(args: { + proposal_id: u32; + voter: Buffer; + }, options?: MethodOptions): Promise> { + return this.call("get_vote", args, options); + } + + /** + * Execute a proposal that has passed. + */ + public async execute(args: { proposal_id: u32 }, options?: MethodOptions): Promise> { + return this.call("execute", args, options); + } + + /** + * Cancel a proposal. + */ + public async cancel(args: { proposal_id: u32 }, options?: MethodOptions): Promise> { + return this.call("cancel", args, options); + } +} diff --git a/stellar/bindings/typescript/governance/tsconfig.json b/stellar/bindings/typescript/governance/tsconfig.json new file mode 100644 index 00000000..acac1422 --- /dev/null +++ b/stellar/bindings/typescript/governance/tsconfig.json @@ -0,0 +1,98 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig to read more about this file */ + /* Projects */ + // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ + // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ + // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ + // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ + // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ + // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ + /* Language and Environment */ + "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ + // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ + // "jsx": "preserve", /* Specify what JSX code is generated. */ + // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ + // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ + // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ + // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ + // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ + // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ + // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ + // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ + // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ + /* Modules */ + "module": "NodeNext", /* Specify what module code is generated. */ + // "rootDir": "./", /* Specify the root folder within your source files. */ + "moduleResolution": "nodenext", /* Specify how TypeScript looks up a file from a given module specifier. */ + // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */ + // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ + // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ + // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ + // "types": [], /* Specify type package names to be included without being referenced in a source file. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ + // "resolveJsonModule": true, /* Enable importing .json files. */ + // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ + /* JavaScript Support */ + // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ + // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ + // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ + /* Emit */ + "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ + // "declarationMap": true, /* Create sourcemaps for d.ts files. */ + // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ + // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ + // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ + "outDir": "./dist", /* Specify an output folder for all emitted files. */ + // "removeComments": true, /* Disable emitting comments. */ + // "noEmit": true, /* Disable emitting files from a compilation. */ + // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ + // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ + // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ + // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ + // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ + // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ + // "newLine": "crlf", /* Set the newline character for emitting files. */ + // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ + // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ + // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ + // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ + // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ + // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ + /* Interop Constraints */ + // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ + // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ + // "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ + // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ + // "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ + /* Type Checking */ + // "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ + "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ + // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ + // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ + // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ + // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ + // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ + // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ + // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ + // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ + // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ + // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ + // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ + // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ + // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ + // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ + // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ + // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ + /* Completeness */ + // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ + "skipLibCheck": true /* Skip type checking all .d.ts files. */ + }, + "include": [ + "src/*" + ] +} \ No newline at end of file diff --git a/stellar/bindings/typescript/index.ts b/stellar/bindings/typescript/index.ts index 61a8efe6..9200b3c5 100644 --- a/stellar/bindings/typescript/index.ts +++ b/stellar/bindings/typescript/index.ts @@ -8,3 +8,4 @@ export * as WraithNames from './wraith-names/src/index'; export * as StealthSplitter from './stealth-splitter/src/index'; export * as StealthVault from './stealth-vault/src/index'; export * as WraithAssetPolicy from './wraith-asset-policy/src/index'; +export * as Governance from './governance/src/index'; diff --git a/stellar/scripts/governance-bindings.test.ts b/stellar/scripts/governance-bindings.test.ts new file mode 100644 index 00000000..53c4f049 --- /dev/null +++ b/stellar/scripts/governance-bindings.test.ts @@ -0,0 +1,12 @@ +import { Networks } from '@stellar/stellar-sdk'; +import { describe, expect, it } from 'vitest'; +import { Client } from '../bindings/typescript/governance/src/index.js'; + +describe('governance generated client', () => { + it('assembles a typed get_config call', async () => { + const client = new Client({ contractId: 'CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4', networkPassphrase: Networks.TESTNET, rpcUrl: 'http://localhost:8000', server: {} as never }); + const transaction = await client.get_config({ simulate: false }); + + expect(transaction.options.method).toBe('get_config'); + }); +}); diff --git a/stellar/scripts/stealth-batch-sender-bindings.test.ts b/stellar/scripts/stealth-batch-sender-bindings.test.ts index 3303d842..05cb839e 100644 --- a/stellar/scripts/stealth-batch-sender-bindings.test.ts +++ b/stellar/scripts/stealth-batch-sender-bindings.test.ts @@ -1,12 +1,35 @@ import { Networks } from '@stellar/stellar-sdk'; import { describe, expect, it } from 'vitest'; -import { Client } from '../bindings/typescript/stealth-batch-sender/src/index.js'; +import { Client as BatchSenderClient } from '../bindings/typescript/stealth-batch-sender/src/index.js'; +import { Client as SplitterClient } from '../bindings/typescript/stealth-splitter/src/index.js'; +import { Client as VaultClient } from '../bindings/typescript/stealth-vault/src/index.js'; +import { Client as AssetPolicyClient } from '../bindings/typescript/wraith-asset-policy/src/index.js'; +import { Client as GovernanceClient } from '../bindings/typescript/governance/src/index.js'; -describe('stealth-batch-sender generated client', () => { - it('assembles a typed max_batch_size call', async () => { - const client = new Client({ contractId: 'CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4', networkPassphrase: Networks.TESTNET, rpcUrl: 'http://localhost:8000', server: {} as never }); +describe('stellar bindings portability check', () => { + it('stealth-batch-sender client assembles a typed call', async () => { + const client = new BatchSenderClient({ contractId: 'CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4', networkPassphrase: Networks.TESTNET, rpcUrl: 'http://localhost:8000', server: {} as never }); const transaction = await client.max_batch_size({ simulate: false }); - expect(transaction.options.method).toBe('max_batch_size'); }); + + it('stealth-splitter client exports are available', async () => { + const client = new SplitterClient({ contractId: 'CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4', networkPassphrase: Networks.TESTNET, rpcUrl: 'http://localhost:8000', server: {} as never }); + expect(client).toBeDefined(); + }); + + it('stealth-vault client exports are available', async () => { + const client = new VaultClient({ contractId: 'CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4', networkPassphrase: Networks.TESTNET, rpcUrl: 'http://localhost:8000', server: {} as never }); + expect(client).toBeDefined(); + }); + + it('wraith-asset-policy client exports are available', async () => { + const client = new AssetPolicyClient({ contractId: 'CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4', networkPassphrase: Networks.TESTNET, rpcUrl: 'http://localhost:8000', server: {} as never }); + expect(client).toBeDefined(); + }); + + it('governance client exports are available', async () => { + const client = new GovernanceClient({ contractId: 'CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABSC4', networkPassphrase: Networks.TESTNET, rpcUrl: 'http://localhost:8000', server: {} as never }); + expect(client).toBeDefined(); + }); });