@temple-digital-group/temple-canton-js 1.0.39-beta.2 → 1.0.39-beta.3
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.
- package/README.md +1 -42
- package/package.json +1 -1
- package/src/canton/index.js +35 -9
package/README.md
CHANGED
|
@@ -245,21 +245,7 @@ const result = await withdrawFunds({
|
|
|
245
245
|
});
|
|
246
246
|
```
|
|
247
247
|
|
|
248
|
-
### 7.
|
|
249
|
-
|
|
250
|
-
Cancels ALL orders, rolls back pending settlements, and withdraws everything immediately.
|
|
251
|
-
|
|
252
|
-
```javascript
|
|
253
|
-
import { emergencyWithdrawFunds } from "@temple-digital-group/temple-canton-js";
|
|
254
|
-
|
|
255
|
-
const result = await emergencyWithdrawFunds({
|
|
256
|
-
allocationId: "allocation-contract-id",
|
|
257
|
-
sender: partyId,
|
|
258
|
-
assetId: "USDCx",
|
|
259
|
-
});
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
### 8. Withdraw Delegation
|
|
248
|
+
### 7. Withdraw Delegation
|
|
263
249
|
|
|
264
250
|
Archives the user's delegation contract. The user must re-onboard to trade again.
|
|
265
251
|
|
|
@@ -273,8 +259,6 @@ await withdrawDelegation();
|
|
|
273
259
|
await withdrawDelegation(delegationContractId, partyId);
|
|
274
260
|
```
|
|
275
261
|
|
|
276
|
-
## Wallet Balances
|
|
277
|
-
|
|
278
262
|
### Get User Balances
|
|
279
263
|
|
|
280
264
|
```javascript
|
|
@@ -307,24 +291,7 @@ Each entry in the returned array contains:
|
|
|
307
291
|
}
|
|
308
292
|
```
|
|
309
293
|
|
|
310
|
-
## Legacy Order Creation
|
|
311
294
|
|
|
312
|
-
> `createOrderProposal` is the legacy on-ledger order creation method. For v2 trading, use `createOrderRequest` instead.
|
|
313
|
-
|
|
314
|
-
```javascript
|
|
315
|
-
import { createOrderProposal } from "@temple-digital-group/temple-canton-js";
|
|
316
|
-
|
|
317
|
-
const result = await createOrderProposal({
|
|
318
|
-
party: partyId,
|
|
319
|
-
symbol: "CC/USDCx",
|
|
320
|
-
side: "Buy",
|
|
321
|
-
quantity: "100",
|
|
322
|
-
pricePerUnit: "1.5",
|
|
323
|
-
expiration: new Date(Date.now() + 3600000).toISOString(),
|
|
324
|
-
userId: auth0UserId,
|
|
325
|
-
orderType: "limit",
|
|
326
|
-
});
|
|
327
|
-
```
|
|
328
295
|
|
|
329
296
|
### Merge Holdings
|
|
330
297
|
|
|
@@ -403,14 +370,6 @@ const counts = await getUtxoCount(partyId, "USDCx", walletProvider);
|
|
|
403
370
|
| `splitAmuletHoldingForParty(party, outputQuantity)` | | Split an Amulet holding |
|
|
404
371
|
| `unlockLockedAmulets(party)` | | Unlock locked Amulet holdings |
|
|
405
372
|
|
|
406
|
-
### Legacy Orders (On-Ledger)
|
|
407
|
-
|
|
408
|
-
| Function | Provider | Description |
|
|
409
|
-
| ------------------------------------- | -------- | --------------------------- |
|
|
410
|
-
| `createOrderProposal(orderArguments)` | **W** | Create an order proposal |
|
|
411
|
-
| `getOrderProposalsForParty(party)` | | Get pending order proposals |
|
|
412
|
-
| `getOrdersForParty(party)` | | Get active orders |
|
|
413
|
-
|
|
414
373
|
### Temple REST API
|
|
415
374
|
|
|
416
375
|
> These functions call the Temple REST API. Pass `API_EMAIL`/`API_PASSWORD` in `initialize()`, or call `login()` directly — tokens are stored and auto-refreshed.
|
package/package.json
CHANGED
package/src/canton/index.js
CHANGED
|
@@ -3454,17 +3454,26 @@ export async function emergencyWithdrawFunds(opts, returnCommand = false) {
|
|
|
3454
3454
|
* High-level withdrawal flow:
|
|
3455
3455
|
* 1. Creates a withdrawal request via the backend API.
|
|
3456
3456
|
* 2. Polls the request status until it is no longer "pending".
|
|
3457
|
+
* 3. Exercises Allocation_Withdraw on the allocation contract to release holdings back to the user.
|
|
3457
3458
|
*
|
|
3458
3459
|
* @param {Object} opts
|
|
3459
3460
|
* @param {string} opts.asset_id - Asset identifier (e.g. "USDCx", "Amulet").
|
|
3460
3461
|
* @param {string|number} opts.amount - Amount to withdraw.
|
|
3461
3462
|
* @param {number} [opts.pollIntervalMs=2000] - How often to poll (ms).
|
|
3462
3463
|
* @param {number} [opts.maxPollAttempts=30] - Max polling attempts before giving up.
|
|
3463
|
-
* @
|
|
3464
|
+
* @param {boolean} [returnCommand=false] - If true, returns { command, endpoint } for the Allocation_Withdraw step instead of executing.
|
|
3465
|
+
* @returns {Promise<Object>} Allocation_Withdraw result, or { error }.
|
|
3464
3466
|
*/
|
|
3465
|
-
export async function withdrawFunds(opts) {
|
|
3467
|
+
export async function withdrawFunds(opts, returnCommand = false) {
|
|
3466
3468
|
const { asset_id, amount, pollIntervalMs = 2000, maxPollAttempts = 30 } = opts || {};
|
|
3467
3469
|
|
|
3470
|
+
const sender = getAdapterPartyId() ?? config.VALIDATOR_USER_PARTY_ID;
|
|
3471
|
+
if (!sender) {
|
|
3472
|
+
const msg = "withdrawFunds: sender party is required. Connect a wallet adapter or configure VALIDATOR_USER_PARTY_ID.";
|
|
3473
|
+
console.error(msg);
|
|
3474
|
+
return { error: msg };
|
|
3475
|
+
}
|
|
3476
|
+
|
|
3468
3477
|
// 1. Submit the withdrawal request
|
|
3469
3478
|
const createResult = await createWithdrawalRequest(asset_id, amount);
|
|
3470
3479
|
if (createResult?.error) {
|
|
@@ -3481,6 +3490,7 @@ export async function withdrawFunds(opts) {
|
|
|
3481
3490
|
console.log(`withdrawFunds: withdrawal request ${requestId} submitted, polling for status...`);
|
|
3482
3491
|
|
|
3483
3492
|
// 2. Poll until status is "ready" and allocation_cid is available
|
|
3493
|
+
let allocationCid = null;
|
|
3484
3494
|
for (let attempt = 1; attempt <= maxPollAttempts; attempt++) {
|
|
3485
3495
|
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
3486
3496
|
|
|
@@ -3495,10 +3505,11 @@ export async function withdrawFunds(opts) {
|
|
|
3495
3505
|
return status;
|
|
3496
3506
|
}
|
|
3497
3507
|
|
|
3498
|
-
// Ready with an allocation_cid
|
|
3508
|
+
// Ready with an allocation_cid — proceed to withdraw
|
|
3499
3509
|
if (status.status === "ready" && status.allocation_cid) {
|
|
3500
3510
|
console.log(`withdrawFunds: request ${requestId} ready — allocation_cid: ${status.allocation_cid}`);
|
|
3501
|
-
|
|
3511
|
+
allocationCid = status.allocation_cid;
|
|
3512
|
+
break;
|
|
3502
3513
|
}
|
|
3503
3514
|
|
|
3504
3515
|
if (attempt % 5 === 0) {
|
|
@@ -3506,9 +3517,24 @@ export async function withdrawFunds(opts) {
|
|
|
3506
3517
|
}
|
|
3507
3518
|
}
|
|
3508
3519
|
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3520
|
+
if (!allocationCid) {
|
|
3521
|
+
const msg = `withdrawFunds: request ${requestId} not ready after ${maxPollAttempts} attempts`;
|
|
3522
|
+
console.error(msg);
|
|
3523
|
+
return { error: msg, request_id: requestId };
|
|
3524
|
+
}
|
|
3525
|
+
|
|
3526
|
+
// 3. Exercise Allocation_Withdraw to release held funds back to the user
|
|
3527
|
+
console.log(`withdrawFunds: exercising Allocation_Withdraw on ${allocationCid}...`);
|
|
3528
|
+
const assetId = asset_id === "CC" ? "Amulet" : asset_id;
|
|
3529
|
+
const withdrawResult = await emergencyWithdrawFunds({ allocationId: allocationCid, sender, assetId }, returnCommand);
|
|
3530
|
+
|
|
3531
|
+
if (withdrawResult?.error) {
|
|
3532
|
+
console.error(`withdrawFunds: Allocation_Withdraw failed for request ${requestId}: ${withdrawResult.error}`);
|
|
3533
|
+
return { error: withdrawResult.error, request_id: requestId, allocation_cid: allocationCid };
|
|
3534
|
+
}
|
|
3535
|
+
|
|
3536
|
+
console.log(`withdrawFunds: withdrawal complete for request ${requestId}`);
|
|
3537
|
+
return { ...withdrawResult, request_id: requestId, allocation_cid: allocationCid };
|
|
3512
3538
|
}
|
|
3513
3539
|
|
|
3514
3540
|
// ─── Onboarding & Delegation ─────────────────────────────────────────────────
|
|
@@ -3561,6 +3587,8 @@ export async function onboardUser(user = {}, returnCommand = false) {
|
|
|
3561
3587
|
actAs: [user.partyId],
|
|
3562
3588
|
};
|
|
3563
3589
|
|
|
3590
|
+
const endpoint = `${config.VALIDATOR_API_URL}/v2/commands/submit-and-wait`;
|
|
3591
|
+
|
|
3564
3592
|
if (returnCommand) {
|
|
3565
3593
|
return { command, endpoint };
|
|
3566
3594
|
}
|
|
@@ -3575,8 +3603,6 @@ export async function onboardUser(user = {}, returnCommand = false) {
|
|
|
3575
3603
|
return { error: msg };
|
|
3576
3604
|
}
|
|
3577
3605
|
}
|
|
3578
|
-
|
|
3579
|
-
const endpoint = `${config.VALIDATOR_API_URL}/v2/commands/submit-and-wait`;
|
|
3580
3606
|
const headers = await buildHeaders();
|
|
3581
3607
|
try {
|
|
3582
3608
|
const response = await axios.post(endpoint, command, { headers });
|