@temple-digital-group/temple-canton-js 2.0.0-beta.8 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +457 -447
  2. package/dist/api/index.js +3 -1
  3. package/dist/api/types.d.ts +1 -0
  4. package/dist/canton/deposits.js +4 -1
  5. package/dist/canton/withdrawals.js +19 -3
  6. package/index.js +15 -15
  7. package/package.json +49 -49
  8. package/src/api/config.d.ts +20 -20
  9. package/src/api/index.ts +322 -321
  10. package/src/api/tokenStore.ts +30 -30
  11. package/src/api/types.ts +196 -195
  12. package/src/auth0/index.d.ts +1 -1
  13. package/src/auth0/index.js +50 -50
  14. package/src/canton/deposits.ts +5 -1
  15. package/src/canton/helpers.ts +266 -266
  16. package/src/canton/index.d.ts +41 -41
  17. package/src/canton/index.js +3295 -3294
  18. package/src/canton/instrumentCatalog.d.ts +6 -6
  19. package/src/canton/instrumentCatalog.js +183 -183
  20. package/src/canton/request_schemas/cancel_orders_amulet.json +77 -77
  21. package/src/canton/request_schemas/cancel_orders_utility.json +68 -68
  22. package/src/canton/request_schemas/create_order_proposal_amulet.json +94 -94
  23. package/src/canton/request_schemas/create_order_proposal_utility.json +121 -121
  24. package/src/canton/request_schemas/create_utility_credential.json +31 -31
  25. package/src/canton/request_schemas/execute_transfer_factory.json +43 -43
  26. package/src/canton/request_schemas/get_allocation_factory.json +21 -21
  27. package/src/canton/request_schemas/get_amulet_holdings.json +21 -21
  28. package/src/canton/request_schemas/get_instrument_configurations.json +21 -21
  29. package/src/canton/request_schemas/get_locked_amulet_holdings.json +21 -21
  30. package/src/canton/request_schemas/get_order_proposals.json +21 -21
  31. package/src/canton/request_schemas/get_orders.json +21 -21
  32. package/src/canton/request_schemas/get_sender_credentials.json +22 -22
  33. package/src/canton/request_schemas/get_transfer_factory.json +28 -28
  34. package/src/canton/request_schemas/get_utility_holdings.json +21 -21
  35. package/src/canton/request_schemas/unlock_amulet.json +38 -38
  36. package/src/canton/walletAdapter.d.ts +7 -6
  37. package/src/canton/walletAdapter.js +112 -89
  38. package/src/canton/withdrawals.ts +511 -489
  39. package/src/config/index.d.ts +63 -63
  40. package/src/config/index.js +188 -188
  41. package/src/websocket/index.ts +341 -341
  42. package/src/websocket/ws.d.ts +24 -24
package/dist/api/index.js CHANGED
@@ -196,12 +196,14 @@ export async function getDelegation() {
196
196
  * @param opts - Order parameters: symbol, side, quantity, price, order_type, expires_at
197
197
  */
198
198
  export async function createOrderRequest(opts) {
199
- const { symbol: rawSymbol, side, quantity, price, order_type = "limit", expires_at } = opts || {};
199
+ const { symbol: rawSymbol, side, quantity, price, order_type = "limit", order_subtype, expires_at } = opts || {};
200
200
  if (!rawSymbol || !side || quantity == null || price == null) {
201
201
  return { error: true, status: null, code: "INVALID_PARAMS", message: "symbol, side, quantity, and price are required." };
202
202
  }
203
203
  const symbol = normalizeSymbol(rawSymbol);
204
204
  const body = { symbol, side, quantity: Number(quantity), price: Number(price), order_type };
205
+ if (order_subtype)
206
+ body.order_subtype = order_subtype;
205
207
  if (expires_at)
206
208
  body.expires_at = expires_at;
207
209
  return authenticatedPost("/api/trading/orders", body);
@@ -96,6 +96,7 @@ export interface CreateOrderRequestOpts {
96
96
  quantity: number;
97
97
  price: number;
98
98
  order_type?: string;
99
+ order_subtype?: "post_only";
99
100
  expires_at?: string;
100
101
  }
101
102
  export interface CreateOrderRequestResponse {
@@ -2,7 +2,7 @@ import config from "../../src/config/index.js";
2
2
  import axios from "axios";
3
3
  import { getDisclosures } from "../api/index.js";
4
4
  import { getUserId } from "../api/tokenStore.js";
5
- import { getAdapterPartyId, getWalletAdapter, submitCommand } from "../../src/canton/walletAdapter.js";
5
+ import { getAdapterPartyId, getWalletAdapter, submitCommand, payDueGasIfAny } from "../../src/canton/walletAdapter.js";
6
6
  import { normalizeAssetId, instrumentCatalog } from "../../src/canton/instrumentCatalog.js";
7
7
  import { randomUUID, shouldUseLedgerForMetadata, normalizeContractId, resolveInstrumentDefinition, getInstrumentRegistrar, resolveProvider, dedupeDisclosedContracts, buildHeaders, DEFAULT_UTILITY_CONTEXT_KEYS, } from "./helpers.js";
8
8
  import { resolveAmuletContext, resolveUtilityInstrumentConfiguration, resolveUtilityAllocationFactory, getAmuletHoldingsForParty, getUtilityHoldingsForParty, getUtxoCount, } from "../../src/canton/index.js";
@@ -114,6 +114,8 @@ export async function deposit(amount, symbol) {
114
114
  if (!party) {
115
115
  return { error: "deposit: could not resolve party ID from wallet adapter." };
116
116
  }
117
+ // Pay any outstanding network gas first so the balance check below is accurate.
118
+ await payDueGasIfAny();
117
119
  const assetId = normalizeAssetId(symbol);
118
120
  if (!instrumentCatalog[assetId]) {
119
121
  return { error: `deposit: unsupported symbol "${symbol}"` };
@@ -442,6 +444,7 @@ export async function depositFunds(opts, returnCommand = false) {
442
444
  // Auto-submit via wallet adapter if available
443
445
  if (getWalletAdapter()) {
444
446
  try {
447
+ await payDueGasIfAny();
445
448
  return (await submitCommand(command));
446
449
  }
447
450
  catch (error) {
@@ -2,10 +2,12 @@ import config from "../../src/config/index.js";
2
2
  import axios from "axios";
3
3
  import { getDisclosures, createWithdrawalRequest, getWithdrawalRequestStatus, getDelegation, } from "../api/index.js";
4
4
  import { getUserId } from "../api/tokenStore.js";
5
- import { getAdapterPartyId, getWalletAdapter, submitCommand } from "../../src/canton/walletAdapter.js";
6
- import { randomUUID, shouldUseLedgerForMetadata, normalizeContractId, resolveInstrumentDefinition, getInstrumentRegistrar, dedupeDisclosedContracts, buildHeaders, DEFAULT_AMULET_CONTEXT_KEYS, DEFAULT_UTILITY_CONTEXT_KEYS, } from "./helpers.js";
7
- import { resolveAmuletContext, resolveUtilityInstrumentConfiguration, resolveUtilityAllocationFactory, } from "../../src/canton/index.js";
5
+ import { getAdapterPartyId, getWalletAdapter, submitCommand, payDueGasIfAny } from "../../src/canton/walletAdapter.js";
6
+ import { randomUUID, shouldUseLedgerForMetadata, normalizeContractId, resolveInstrumentDefinition, getInstrumentRegistrar, resolveProvider, dedupeDisclosedContracts, buildHeaders, DEFAULT_AMULET_CONTEXT_KEYS, DEFAULT_UTILITY_CONTEXT_KEYS, } from "./helpers.js";
7
+ import { resolveAmuletContext, resolveUtilityInstrumentConfiguration, resolveUtilityAllocationFactory, getUtxoCount, } from "../../src/canton/index.js";
8
8
  import { normalizeAssetId } from "../../src/canton/instrumentCatalog.js";
9
+ // ─── Constants ───────────────────────────────────────────────────────────────
10
+ const CC_FEE_RESERVE = 10;
9
11
  // ─── Withdrawal Functions ────────────────────────────────────────────────────
10
12
  /**
11
13
  * Finalize a withdrawal by exercising the Allocation_Withdraw choice.
@@ -233,6 +235,7 @@ export async function finalizeWithdrawFunds(opts, returnCommand = false) {
233
235
  // Auto-submit via wallet adapter if available
234
236
  if (getWalletAdapter()) {
235
237
  try {
238
+ await payDueGasIfAny();
236
239
  return (await submitCommand(command));
237
240
  }
238
241
  catch (error) {
@@ -270,6 +273,18 @@ export async function withdrawFunds(opts, returnCommand = false) {
270
273
  console.error(msg);
271
274
  return { error: msg };
272
275
  }
276
+ // Pay any outstanding network gas first so the fee-reserve check below is accurate.
277
+ await payDueGasIfAny();
278
+ // Ensure the user has enough CC unlocked to pay gas for the eventual Allocation_Withdraw.
279
+ const provider = resolveProvider(null);
280
+ const ccBalance = await getUtxoCount(sender, "Amulet", provider);
281
+ const availableCC = ccBalance.unlockedBalance || 0;
282
+ if (availableCC < CC_FEE_RESERVE) {
283
+ return {
284
+ error: `withdrawFunds: insufficient CC for fees. You have ${availableCC} CC but need at least ${CC_FEE_RESERVE} CC to cover transaction fees.`,
285
+ data: { ccBalance: availableCC, feeReserve: CC_FEE_RESERVE },
286
+ };
287
+ }
273
288
  // 1. Submit the withdrawal request
274
289
  const createResult = (await createWithdrawalRequest(asset_id, amount));
275
290
  if (createResult?.error) {
@@ -368,6 +383,7 @@ export async function withdrawDelegation(delegationId = null, user = null, retur
368
383
  // Auto-submit via wallet adapter if available
369
384
  if (getWalletAdapter()) {
370
385
  try {
386
+ await payDueGasIfAny();
371
387
  return (await submitCommand(command));
372
388
  }
373
389
  catch (error) {
package/index.js CHANGED
@@ -1,15 +1,15 @@
1
- // Export Canton client functions
2
- export * from './src/canton/index.js';
3
-
4
- // Export Auth0 utilities
5
- export { getJWTToken } from './src/auth0/index.js';
6
-
7
- // Export configuration
8
- export * from './src/config/index.js';
9
-
10
- // Export Temple REST API functions
11
- export * from './dist/api/index.js';
12
-
13
- // Export WebSocket client
14
- export * from './dist/websocket/index.js';
15
-
1
+ // Export Canton client functions
2
+ export * from './src/canton/index.js';
3
+
4
+ // Export Auth0 utilities
5
+ export { getJWTToken } from './src/auth0/index.js';
6
+
7
+ // Export configuration
8
+ export * from './src/config/index.js';
9
+
10
+ // Export Temple REST API functions
11
+ export * from './dist/api/index.js';
12
+
13
+ // Export WebSocket client
14
+ export * from './dist/websocket/index.js';
15
+
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "name": "@temple-digital-group/temple-canton-js",
3
- "version": "2.0.0-beta.8",
4
- "description": "JavaScript library for interacting with Temple Canton blockchain",
5
- "type": "module",
6
- "main": "index.js",
7
- "exports": {
8
- ".": "./index.js"
9
- },
10
- "files": [
11
- "index.js",
12
- "src/",
13
- "dist/"
14
- ],
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/Temple-Digital-Group/temple-canton-js.git"
18
- },
19
- "publishConfig": {
20
- "access": "public"
21
- },
22
- "author": "kakashigr <augegr@gmail.com>",
23
- "keywords": [
24
- "canton",
25
- "blockchain",
26
- "daml",
27
- "splice",
28
- "amulet",
29
- "ledger",
30
- "trading",
31
- "temple"
32
- ],
33
- "license": "MIT",
34
- "scripts": {
35
- "start": "node index.js",
36
- "build": "tsc",
37
- "prepublishOnly": "npm run build"
38
- },
39
- "dependencies": {
40
- "axios": "^1.13.1",
41
- "dotenv": "^17.2.3",
42
- "ws": "^8.19.0"
43
- },
44
- "devDependencies": {
45
- "@types/node": "^25.3.3",
46
- "@types/ws": "^8.18.0",
47
- "typescript": "^5.9.3"
48
- }
49
- }
1
+ {
2
+ "name": "@temple-digital-group/temple-canton-js",
3
+ "version": "2.0.0",
4
+ "description": "JavaScript library for interacting with Temple Canton blockchain",
5
+ "type": "module",
6
+ "main": "index.js",
7
+ "exports": {
8
+ ".": "./index.js"
9
+ },
10
+ "files": [
11
+ "index.js",
12
+ "src/",
13
+ "dist/"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/Temple-Digital-Group/temple-canton-js.git"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "author": "kakashigr <augegr@gmail.com>",
23
+ "keywords": [
24
+ "canton",
25
+ "blockchain",
26
+ "daml",
27
+ "splice",
28
+ "amulet",
29
+ "ledger",
30
+ "trading",
31
+ "temple"
32
+ ],
33
+ "license": "MIT",
34
+ "scripts": {
35
+ "start": "node index.js",
36
+ "build": "tsc",
37
+ "prepublishOnly": "npm run build"
38
+ },
39
+ "dependencies": {
40
+ "axios": "^1.13.1",
41
+ "dotenv": "^17.2.3",
42
+ "ws": "^8.19.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^25.3.3",
46
+ "@types/ws": "^8.18.0",
47
+ "typescript": "^5.9.3"
48
+ }
49
+ }
@@ -1,20 +1,20 @@
1
- declare module "../../src/config/index.js" {
2
- const config: {
3
- readonly API_BASE_URL: string;
4
- readonly API_EMAIL?: string;
5
- readonly API_PASSWORD?: string;
6
- readonly API_KEY?: string;
7
- readonly NETWORK: string;
8
- readonly VALIDATOR_API_URL: string;
9
- readonly VALIDATOR_SCAN_API_URL: string;
10
- readonly JWT_TOKEN: string;
11
- [key: string]: unknown;
12
- };
13
- export default config;
14
- export function initializeConfig(config: Record<string, unknown>): void;
15
- export function setJWTToken(token: string): void;
16
- export function getConfigValue(key: string): string | undefined;
17
- export function setWalletAdapter(adapter: unknown): void;
18
- export function getWalletAdapter(): unknown;
19
- export function getAdapterProvider(): unknown;
20
- }
1
+ declare module "../../src/config/index.js" {
2
+ const config: {
3
+ readonly API_BASE_URL: string;
4
+ readonly API_EMAIL?: string;
5
+ readonly API_PASSWORD?: string;
6
+ readonly API_KEY?: string;
7
+ readonly NETWORK: string;
8
+ readonly VALIDATOR_API_URL: string;
9
+ readonly VALIDATOR_SCAN_API_URL: string;
10
+ readonly JWT_TOKEN: string;
11
+ [key: string]: unknown;
12
+ };
13
+ export default config;
14
+ export function initializeConfig(config: Record<string, unknown>): void;
15
+ export function setJWTToken(token: string): void;
16
+ export function getConfigValue(key: string): string | undefined;
17
+ export function setWalletAdapter(adapter: unknown): void;
18
+ export function getWalletAdapter(): unknown;
19
+ export function getAdapterProvider(): unknown;
20
+ }