@fairmint/canton-node-sdk 0.0.289 → 0.0.291
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 +91 -5
- package/build/src/wallets/abort.d.ts +13 -0
- package/build/src/wallets/abort.d.ts.map +1 -1
- package/build/src/wallets/abort.js +66 -0
- package/build/src/wallets/abort.js.map +1 -1
- package/build/src/wallets/commands.d.ts +5 -0
- package/build/src/wallets/commands.d.ts.map +1 -1
- package/build/src/wallets/commands.js +23 -7
- package/build/src/wallets/commands.js.map +1 -1
- package/build/src/wallets/contracts.d.ts +24 -0
- package/build/src/wallets/contracts.d.ts.map +1 -1
- package/build/src/wallets/contracts.js +15 -0
- package/build/src/wallets/contracts.js.map +1 -1
- package/build/src/wallets/da-utilities/client.d.ts +10 -0
- package/build/src/wallets/da-utilities/client.d.ts.map +1 -1
- package/build/src/wallets/da-utilities/client.js +41 -13
- package/build/src/wallets/da-utilities/client.js.map +1 -1
- package/build/src/wallets/errors.d.ts +11 -2
- package/build/src/wallets/errors.d.ts.map +1 -1
- package/build/src/wallets/errors.js +41 -1
- package/build/src/wallets/errors.js.map +1 -1
- package/build/src/wallets/format.d.ts +54 -0
- package/build/src/wallets/format.d.ts.map +1 -0
- package/build/src/wallets/format.js +57 -0
- package/build/src/wallets/format.js.map +1 -0
- package/build/src/wallets/holdings.d.ts +21 -0
- package/build/src/wallets/holdings.d.ts.map +1 -1
- package/build/src/wallets/holdings.js +1 -0
- package/build/src/wallets/holdings.js.map +1 -1
- package/build/src/wallets/index.d.ts +17 -4
- package/build/src/wallets/index.d.ts.map +1 -1
- package/build/src/wallets/index.js +35 -1
- package/build/src/wallets/index.js.map +1 -1
- package/build/src/wallets/ownership.d.ts.map +1 -1
- package/build/src/wallets/ownership.js +2 -5
- package/build/src/wallets/ownership.js.map +1 -1
- package/build/src/wallets/sign-message.d.ts +43 -0
- package/build/src/wallets/sign-message.d.ts.map +1 -0
- package/build/src/wallets/sign-message.js +56 -0
- package/build/src/wallets/sign-message.js.map +1 -0
- package/build/src/wallets/store.d.ts +35 -1
- package/build/src/wallets/store.d.ts.map +1 -1
- package/build/src/wallets/store.js +89 -2
- package/build/src/wallets/store.js.map +1 -1
- package/build/src/wallets/tokens.d.ts +157 -0
- package/build/src/wallets/tokens.d.ts.map +1 -0
- package/build/src/wallets/tokens.js +187 -0
- package/build/src/wallets/tokens.js.map +1 -0
- package/build/src/wallets/wallet.d.ts +51 -1
- package/build/src/wallets/wallet.d.ts.map +1 -1
- package/build/src/wallets/wallet.js +127 -6
- package/build/src/wallets/wallet.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { BurnRequest, MintOffer, TransferOffer, TransferPreapproval } from './contracts';
|
|
2
|
+
import { type Holding, type InstrumentBalance, type InstrumentMetadata } from './holdings';
|
|
3
|
+
import type { InstrumentId } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Whether a transfer offer's `executeBefore` has passed at `atMs` (milliseconds since the epoch). The ledger decides by
|
|
6
|
+
* ledger time, which can differ from the clock by a little; an unreadable `executeBefore` is not expired.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isTransferOfferExpired(offer: Pick<TransferOffer, 'executeBefore'>, atMs: number): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Per instrument (by `instrumentKey`), the locked units that `offers` (the party's own expired outgoing offers) keep
|
|
11
|
+
* locked: an offer that names its locked holding (Canton Coin) counts that holding's amount while it is still a locked
|
|
12
|
+
* holding of the party, and nothing once it is gone (its lock was already released; withdrawing only archives the
|
|
13
|
+
* offer); an offer that names none (DA) counts its amount. Each instrument's total is capped at its locked total.
|
|
14
|
+
*/
|
|
15
|
+
export declare function lockedInExpiredOffers(holdings: readonly Holding[], offers: readonly TransferOffer[]): Map<string, bigint>;
|
|
16
|
+
/**
|
|
17
|
+
* The party's own Canton Coin locks that expired at `atMs` and that none of `offers` names (any direction): the offer
|
|
18
|
+
* that locked it is gone, or the lock was never an offer's. Splice lets the owner alone release such a lock
|
|
19
|
+
* (`LockedAmulet_OwnerExpireLockV2`). A lock with no absolute expiry (`lockExpiresAt` absent) is never counted, and an
|
|
20
|
+
* active offer's lock is left to withdrawing that offer. `holdings` are the party's own.
|
|
21
|
+
*/
|
|
22
|
+
export declare function expiredUnclaimedLocks(holdings: readonly Holding[], offers: ReadonlyArray<Pick<TransferOffer, 'lockedHoldingCid'>>, atMs: number): Holding[];
|
|
23
|
+
/** Per instrument (by `instrumentKey`), the units of `holdings`. */
|
|
24
|
+
export declare function unitsByInstrument(holdings: readonly Holding[]): Map<string, bigint>;
|
|
25
|
+
/** What the wallet can do with a token. Honest per token: Canton Coin's are what this wallet supports for it today. */
|
|
26
|
+
export interface TokenCapabilities {
|
|
27
|
+
/** Send it (`planTransfer`, `submitTransfer`). Not Canton Coin. */
|
|
28
|
+
readonly send: boolean;
|
|
29
|
+
/** Redeem it (`requestBurn`). Not Canton Coin. */
|
|
30
|
+
readonly burn: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Pre-approve incoming transfers of it (`createTransferPreapproval` with the token's admin and id). Not Canton Coin:
|
|
33
|
+
* Canton Coin's own preapproval is made through a validator, not this wallet.
|
|
34
|
+
*/
|
|
35
|
+
readonly preapprove: boolean;
|
|
36
|
+
/** Accept or reject incoming transfer offers of it (a faucet's Canton Coin offers included). */
|
|
37
|
+
readonly answerOffers: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Withdraw the party's own offers of it, expired ones included (`withdrawTransferOffer`,
|
|
40
|
+
* `withdrawExpiredTransferOffers`, `reclaimLockedTokens`).
|
|
41
|
+
*/
|
|
42
|
+
readonly withdrawOffers: boolean;
|
|
43
|
+
/** Accept or reject mint offers of it. Only DA Registry tokens have mint offers. */
|
|
44
|
+
readonly answerMintOffers: boolean;
|
|
45
|
+
}
|
|
46
|
+
/** Everything a page shows for one token, from one wallet state (see {@link walletTokens}). */
|
|
47
|
+
export interface WalletToken {
|
|
48
|
+
/** `instrumentKey(instrumentId)`: a React `key` and a picker value. Opaque: compare it, do not parse it. */
|
|
49
|
+
readonly key: string;
|
|
50
|
+
readonly instrumentId: InstrumentId;
|
|
51
|
+
/** The registry's symbol (`CC`, `CNTN`), else the instrument id. Label the picker with it. */
|
|
52
|
+
readonly symbol: string;
|
|
53
|
+
/** The registry's name (`Canton Coin`), else the instrument id. */
|
|
54
|
+
readonly name: string;
|
|
55
|
+
/** Decimal places to show and accept: the registry's, else 10. */
|
|
56
|
+
readonly decimals: number;
|
|
57
|
+
/** The registry's metadata, when it answered. */
|
|
58
|
+
readonly metadata?: InstrumentMetadata;
|
|
59
|
+
/** Spendable (unlocked) total, 10 decimal places. */
|
|
60
|
+
readonly available: string;
|
|
61
|
+
/** Locked total (offers, redemptions, allocations in flight), 10 decimal places. */
|
|
62
|
+
readonly locked: string;
|
|
63
|
+
/**
|
|
64
|
+
* The part of `locked` that `reclaimLockedTokens` would unlock (the party's expired offers, and its expired Canton
|
|
65
|
+
* Coin locks no offer names), 10 decimal places, capped at `locked`. Exact for Canton Coin; for a DA token an
|
|
66
|
+
* estimate (its offers name no locked holding, so each expired offer counts its amount).
|
|
67
|
+
*/
|
|
68
|
+
readonly lockedReclaimable: string;
|
|
69
|
+
/**
|
|
70
|
+
* Whether `reclaimLockedTokens` has something to do for this token: an expired outgoing offer to withdraw, or an
|
|
71
|
+
* expired Canton Coin lock to release. Show the Reclaim button on it, not on `lockedReclaimable`.
|
|
72
|
+
*/
|
|
73
|
+
readonly canReclaim: boolean;
|
|
74
|
+
readonly holdingCount: number;
|
|
75
|
+
readonly isCantonCoin: boolean;
|
|
76
|
+
readonly capabilities: TokenCapabilities;
|
|
77
|
+
/**
|
|
78
|
+
* Transfer offers of this token, each with `expired` set (see {@link WalletTokenOffer}). `expiredIncoming` is the part
|
|
79
|
+
* of `incoming` the party can no longer accept (the ledger refuses it; it can still reject them): hide Accept on
|
|
80
|
+
* them. `expiredOutgoing` is the part of `outgoing` no receiver can accept any more (`reclaimLockedTokens` withdraws
|
|
81
|
+
* them).
|
|
82
|
+
*/
|
|
83
|
+
readonly offers: {
|
|
84
|
+
readonly incoming: readonly WalletTokenOffer[];
|
|
85
|
+
readonly outgoing: readonly WalletTokenOffer[];
|
|
86
|
+
readonly expiredIncoming: readonly WalletTokenOffer[];
|
|
87
|
+
readonly expiredOutgoing: readonly WalletTokenOffer[];
|
|
88
|
+
};
|
|
89
|
+
readonly mintOffers: readonly MintOffer[];
|
|
90
|
+
readonly burnRequests: readonly BurnRequest[];
|
|
91
|
+
/**
|
|
92
|
+
* The party's DA preapproval that covers this token (issuer-wide, or naming it), or null. Always null for Canton
|
|
93
|
+
* Coin: read `preapprovalStatus`.
|
|
94
|
+
*/
|
|
95
|
+
readonly preapproval: TransferPreapproval | null;
|
|
96
|
+
/**
|
|
97
|
+
* Every DA preapproval of the party that applies to this token: issuer-wide ones of its admin, and ones naming it
|
|
98
|
+
* (list them to withdraw). `preapproval` is the one of them that covers the token, if any. Always empty for Canton
|
|
99
|
+
* Coin.
|
|
100
|
+
*/
|
|
101
|
+
readonly preapprovals: readonly TransferPreapproval[];
|
|
102
|
+
/**
|
|
103
|
+
* True on Canton Coin while the state could not confirm Canton Coin (`WalletState.cantonCoinUnavailable`: its DSO
|
|
104
|
+
* party is unknown, so its holdings and offers are left out). Such an entry exists only when `includeEmptyCantonCoin`
|
|
105
|
+
* added it; show why its balance is missing instead of a zero. False otherwise.
|
|
106
|
+
*/
|
|
107
|
+
readonly unavailable: boolean;
|
|
108
|
+
/**
|
|
109
|
+
* `covered` (`preapproval` is set) or `none` for a DA token. `unknown` for Canton Coin: its preapproval is a
|
|
110
|
+
* DSO-signed Splice `TransferPreapproval` made through the party's validator, which this wallet does not read, so a
|
|
111
|
+
* page must not say the party has none.
|
|
112
|
+
*/
|
|
113
|
+
readonly preapprovalStatus: 'covered' | 'none' | 'unknown';
|
|
114
|
+
}
|
|
115
|
+
/** The parts of a `WalletState` {@link walletTokens} reads. */
|
|
116
|
+
export interface WalletTokensInput {
|
|
117
|
+
readonly balances: readonly InstrumentBalance[];
|
|
118
|
+
readonly transferOffers: {
|
|
119
|
+
readonly incoming: readonly TransferOffer[];
|
|
120
|
+
readonly outgoing: readonly TransferOffer[];
|
|
121
|
+
};
|
|
122
|
+
readonly mintOffers: readonly MintOffer[];
|
|
123
|
+
readonly burnRequests: readonly BurnRequest[];
|
|
124
|
+
readonly transferPreapprovals: readonly TransferPreapproval[];
|
|
125
|
+
/** `WalletState.cantonCoinUnavailable`: absent reads as false. */
|
|
126
|
+
readonly cantonCoinUnavailable?: boolean;
|
|
127
|
+
}
|
|
128
|
+
/** A transfer offer as {@link WalletToken} lists it: `expired` is always set. */
|
|
129
|
+
export type WalletTokenOffer = TransferOffer & {
|
|
130
|
+
/** Whether `executeBefore` had passed when the state was read (`TransferOffer.expired`, absent read as false). */
|
|
131
|
+
readonly expired: boolean;
|
|
132
|
+
};
|
|
133
|
+
/** Options of {@link walletTokens}. */
|
|
134
|
+
export interface WalletTokensOptions {
|
|
135
|
+
/**
|
|
136
|
+
* When the state names no Canton Coin (no holding, no offer), add a Canton Coin entry with zero balances anyway, so a
|
|
137
|
+
* page can show Canton Coin (and its faucet or validator preapproval) before the party holds any. The state does not
|
|
138
|
+
* name the DSO party then, so that entry's `instrumentId.admin` is `''`: no wallet action can name it (all of its
|
|
139
|
+
* lists are empty). Its `unavailable` says whether Canton Coin could not be confirmed. Default false.
|
|
140
|
+
*/
|
|
141
|
+
readonly includeEmptyCantonCoin?: boolean;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* One {@link WalletToken} per token the state names: every balance, and every token of an offer, mint offer or burn
|
|
145
|
+
* request (a token offered to the party before it holds any is listed with zero balances), and Canton Coin with zero
|
|
146
|
+
* balances when `options.includeEmptyCantonCoin` asks for it. Sorted by symbol, then instrument id, then admin, by code
|
|
147
|
+
* unit. Canton Coin and DA Registry tokens share the shape; `capabilities` says which actions apply.
|
|
148
|
+
*/
|
|
149
|
+
export declare function walletTokens(state: WalletTokensInput, options?: WalletTokensOptions): WalletToken[];
|
|
150
|
+
/**
|
|
151
|
+
* The token a page opens on: the one whose `key` is `pickedKey` while it is still listed, else the first whose symbol
|
|
152
|
+
* is `prefer.symbol`, else the first token; null when `tokens` is empty.
|
|
153
|
+
*/
|
|
154
|
+
export declare function selectWalletToken(tokens: readonly WalletToken[], pickedKey: string | null, prefer?: {
|
|
155
|
+
readonly symbol: string;
|
|
156
|
+
}): WalletToken | null;
|
|
157
|
+
//# sourceMappingURL=tokens.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../../src/wallets/tokens.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAG9F,OAAO,EAA+B,KAAK,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,kBAAkB,EAAE,MAAM,YAAY,CAAC;AACxH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,eAAe,CAAC,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAGzG;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,MAAM,EAAE,SAAS,aAAa,EAAE,GAC/B,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CA2BrB;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,SAAS,OAAO,EAAE,EAC5B,MAAM,EAAE,aAAa,CAAC,IAAI,CAAC,aAAa,EAAE,kBAAkB,CAAC,CAAC,EAC9D,IAAI,EAAE,MAAM,GACX,OAAO,EAAE,CASX;AAED,oEAAoE;AACpE,wBAAgB,iBAAiB,CAAC,Q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gBAAgB,GAAG,aAAa,GAAG;IAC7C,kHAAkH;IAClH,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,uCAAuC;AACvC,MAAM,WAAW,mBAAmB;IAClC;;;;;OAKG;IACH,QAAQ,CAAC,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAC3C;AAMD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,EAAE,OAAO,GAAE,mBAAwB,GAAG,WAAW,EAAE,CA2FvG;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,WAAW,EAAE,EAC9B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,MAAM,CAAC,EAAE;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GACnC,WAAW,GAAG,IAAI,CAOpB"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTransferOfferExpired = isTransferOfferExpired;
|
|
4
|
+
exports.lockedInExpiredOffers = lockedInExpiredOffers;
|
|
5
|
+
exports.expiredUnclaimedLocks = expiredUnclaimedLocks;
|
|
6
|
+
exports.unitsByInstrument = unitsByInstrument;
|
|
7
|
+
exports.walletTokens = walletTokens;
|
|
8
|
+
exports.selectWalletToken = selectWalletToken;
|
|
9
|
+
/**
|
|
10
|
+
* One view per token of a wallet state, so a page renders Canton Coin and DA Registry tokens alike: one picker and one
|
|
11
|
+
* panel, whatever the token. Also the rule that decides which of the party's own transfer offers are expired, and how
|
|
12
|
+
* much of a token they keep locked.
|
|
13
|
+
*/
|
|
14
|
+
const constants_1 = require("./amulet/constants");
|
|
15
|
+
const contracts_1 = require("./contracts");
|
|
16
|
+
const decimal_1 = require("./decimal");
|
|
17
|
+
const holdings_1 = require("./holdings");
|
|
18
|
+
/**
|
|
19
|
+
* Whether a transfer offer's `executeBefore` has passed at `atMs` (milliseconds since the epoch). The ledger decides by
|
|
20
|
+
* ledger time, which can differ from the clock by a little; an unreadable `executeBefore` is not expired.
|
|
21
|
+
*/
|
|
22
|
+
function isTransferOfferExpired(offer, atMs) {
|
|
23
|
+
const deadline = Date.parse(offer.executeBefore);
|
|
24
|
+
return !Number.isNaN(deadline) && deadline <= atMs;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Per instrument (by `instrumentKey`), the locked units that `offers` (the party's own expired outgoing offers) keep
|
|
28
|
+
* locked: an offer that names its locked holding (Canton Coin) counts that holding's amount while it is still a locked
|
|
29
|
+
* holding of the party, and nothing once it is gone (its lock was already released; withdrawing only archives the
|
|
30
|
+
* offer); an offer that names none (DA) counts its amount. Each instrument's total is capped at its locked total.
|
|
31
|
+
*/
|
|
32
|
+
function lockedInExpiredOffers(holdings, offers) {
|
|
33
|
+
const lockedHoldings = new Map(holdings.filter((h) => h.locked).map((h) => [h.contractId, h]));
|
|
34
|
+
const lockedTotals = new Map();
|
|
35
|
+
for (const holding of lockedHoldings.values()) {
|
|
36
|
+
const key = (0, holdings_1.instrumentKey)(holding.instrumentId);
|
|
37
|
+
lockedTotals.set(key, (lockedTotals.get(key) ?? 0n) + ((0, decimal_1.parseDecimalUnits)(holding.amount) ?? 0n));
|
|
38
|
+
}
|
|
39
|
+
const counted = new Set();
|
|
40
|
+
const totals = new Map();
|
|
41
|
+
for (const offer of offers) {
|
|
42
|
+
const key = (0, holdings_1.instrumentKey)(offer.instrumentId);
|
|
43
|
+
let units;
|
|
44
|
+
if (offer.lockedHoldingCid !== undefined) {
|
|
45
|
+
const holding = lockedHoldings.get(offer.lockedHoldingCid);
|
|
46
|
+
if (holding === undefined || counted.has(holding.contractId))
|
|
47
|
+
continue;
|
|
48
|
+
counted.add(holding.contractId);
|
|
49
|
+
units = (0, decimal_1.parseDecimalUnits)(holding.amount) ?? 0n;
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
units = (0, decimal_1.parseDecimalUnits)(offer.amount) ?? 0n;
|
|
53
|
+
}
|
|
54
|
+
totals.set(key, (totals.get(key) ?? 0n) + units);
|
|
55
|
+
}
|
|
56
|
+
for (const [key, units] of totals) {
|
|
57
|
+
const cap = lockedTotals.get(key) ?? 0n;
|
|
58
|
+
if (units > cap)
|
|
59
|
+
totals.set(key, cap);
|
|
60
|
+
}
|
|
61
|
+
return totals;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The party's own Canton Coin locks that expired at `atMs` and that none of `offers` names (any direction): the offer
|
|
65
|
+
* that locked it is gone, or the lock was never an offer's. Splice lets the owner alone release such a lock
|
|
66
|
+
* (`LockedAmulet_OwnerExpireLockV2`). A lock with no absolute expiry (`lockExpiresAt` absent) is never counted, and an
|
|
67
|
+
* active offer's lock is left to withdrawing that offer. `holdings` are the party's own.
|
|
68
|
+
*/
|
|
69
|
+
function expiredUnclaimedLocks(holdings, offers, atMs) {
|
|
70
|
+
const named = new Set(offers.flatMap((offer) => (offer.lockedHoldingCid === undefined ? [] : [offer.lockedHoldingCid])));
|
|
71
|
+
return holdings.filter((holding) => {
|
|
72
|
+
if (!holding.locked || !(0, holdings_1.isCantonCoin)(holding) || holding.lockExpiresAt === undefined)
|
|
73
|
+
return false;
|
|
74
|
+
const expiry = Date.parse(holding.lockExpiresAt);
|
|
75
|
+
return !Number.isNaN(expiry) && expiry <= atMs && !named.has(holding.contractId);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/** Per instrument (by `instrumentKey`), the units of `holdings`. */
|
|
79
|
+
function unitsByInstrument(holdings) {
|
|
80
|
+
const totals = new Map();
|
|
81
|
+
for (const holding of holdings) {
|
|
82
|
+
const key = (0, holdings_1.instrumentKey)(holding.instrumentId);
|
|
83
|
+
totals.set(key, (totals.get(key) ?? 0n) + ((0, decimal_1.parseDecimalUnits)(holding.amount) ?? 0n));
|
|
84
|
+
}
|
|
85
|
+
return totals;
|
|
86
|
+
}
|
|
87
|
+
const ZERO = (0, decimal_1.formatDecimalUnits)(0n);
|
|
88
|
+
const units = (text) => (text === undefined ? 0n : ((0, decimal_1.parseDecimalUnits)(text) ?? 0n));
|
|
89
|
+
const compareText = (a, b) => (a < b ? -1 : a > b ? 1 : 0);
|
|
90
|
+
/**
|
|
91
|
+
* One {@link WalletToken} per token the state names: every balance, and every token of an offer, mint offer or burn
|
|
92
|
+
* request (a token offered to the party before it holds any is listed with zero balances), and Canton Coin with zero
|
|
93
|
+
* balances when `options.includeEmptyCantonCoin` asks for it. Sorted by symbol, then instrument id, then admin, by code
|
|
94
|
+
* unit. Canton Coin and DA Registry tokens share the shape; `capabilities` says which actions apply.
|
|
95
|
+
*/
|
|
96
|
+
function walletTokens(state, options = {}) {
|
|
97
|
+
const drafts = new Map();
|
|
98
|
+
const note = (instrumentId, cantonCoin, balance) => {
|
|
99
|
+
const key = (0, holdings_1.instrumentKey)(instrumentId);
|
|
100
|
+
const draft = drafts.get(key) ?? { instrumentId, cantonCoin: false };
|
|
101
|
+
draft.cantonCoin || (draft.cantonCoin = cantonCoin);
|
|
102
|
+
if (balance !== undefined)
|
|
103
|
+
draft.balance = balance;
|
|
104
|
+
drafts.set(key, draft);
|
|
105
|
+
};
|
|
106
|
+
for (const balance of state.balances)
|
|
107
|
+
note(balance.instrumentId, balance.source === 'amulet', balance);
|
|
108
|
+
for (const offer of [...state.transferOffers.incoming, ...state.transferOffers.outgoing]) {
|
|
109
|
+
note(offer.instrumentId, offer.registry === 'amulet');
|
|
110
|
+
}
|
|
111
|
+
for (const item of [...state.mintOffers, ...state.burnRequests])
|
|
112
|
+
note(item.instrumentId, false);
|
|
113
|
+
if (options.includeEmptyCantonCoin === true && ![...drafts.values()].some((draft) => draft.cantonCoin)) {
|
|
114
|
+
// The DSO party is not in the state: an empty admin, so nothing acts on this entry's instrument.
|
|
115
|
+
note({ admin: '', id: constants_1.AMULET_INSTRUMENT_ID }, true);
|
|
116
|
+
}
|
|
117
|
+
const cantonCoinUnavailable = state.cantonCoinUnavailable === true;
|
|
118
|
+
const withExpiry = (offer) => ({ ...offer, expired: offer.expired === true });
|
|
119
|
+
const of = (list, key) => list.filter((item) => (0, holdings_1.instrumentKey)(item.instrumentId) === key);
|
|
120
|
+
return [...drafts.entries()]
|
|
121
|
+
.map(([key, { instrumentId, balance, cantonCoin }]) => {
|
|
122
|
+
// Canton Coin offered before the party holds any has no balance to carry the registry's answer.
|
|
123
|
+
const metadata = balance?.metadata ?? (cantonCoin ? constants_1.CANTON_COIN_METADATA : undefined);
|
|
124
|
+
const incoming = of(state.transferOffers.incoming, key).map(withExpiry);
|
|
125
|
+
const outgoing = of(state.transferOffers.outgoing, key).map(withExpiry);
|
|
126
|
+
const expiredOutgoing = outgoing.filter((offer) => offer.expired);
|
|
127
|
+
const lockedUnits = units(balance?.locked);
|
|
128
|
+
const inLocks = units(balance?.lockedInExpiredLocks);
|
|
129
|
+
const reclaimable = units(balance?.lockedInExpiredOffers) + inLocks;
|
|
130
|
+
const preapprovals = cantonCoin
|
|
131
|
+
? []
|
|
132
|
+
: state.transferPreapprovals.filter((candidate) => candidate.instrumentAdmin === instrumentId.admin &&
|
|
133
|
+
(candidate.instrumentIds.length === 0 || candidate.instrumentIds.includes(instrumentId.id)));
|
|
134
|
+
const preapproval = (0, contracts_1.coveringPreapproval)(preapprovals, {
|
|
135
|
+
instrumentAdmin: instrumentId.admin,
|
|
136
|
+
instrumentIds: [instrumentId.id],
|
|
137
|
+
});
|
|
138
|
+
return {
|
|
139
|
+
key,
|
|
140
|
+
instrumentId,
|
|
141
|
+
symbol: metadata?.symbol ?? instrumentId.id,
|
|
142
|
+
name: metadata?.name ?? instrumentId.id,
|
|
143
|
+
decimals: metadata?.decimals ?? 10,
|
|
144
|
+
...(metadata !== undefined && { metadata }),
|
|
145
|
+
available: balance?.unlocked ?? ZERO,
|
|
146
|
+
locked: balance?.locked ?? ZERO,
|
|
147
|
+
lockedReclaimable: (0, decimal_1.formatDecimalUnits)(reclaimable > lockedUnits ? lockedUnits : reclaimable),
|
|
148
|
+
canReclaim: expiredOutgoing.length > 0 || inLocks > 0n,
|
|
149
|
+
holdingCount: balance?.holdingCount ?? 0,
|
|
150
|
+
isCantonCoin: cantonCoin,
|
|
151
|
+
capabilities: {
|
|
152
|
+
send: !cantonCoin,
|
|
153
|
+
burn: !cantonCoin,
|
|
154
|
+
preapprove: !cantonCoin,
|
|
155
|
+
answerOffers: true,
|
|
156
|
+
withdrawOffers: true,
|
|
157
|
+
answerMintOffers: !cantonCoin,
|
|
158
|
+
},
|
|
159
|
+
offers: {
|
|
160
|
+
incoming,
|
|
161
|
+
outgoing,
|
|
162
|
+
expiredIncoming: incoming.filter((offer) => offer.expired),
|
|
163
|
+
expiredOutgoing,
|
|
164
|
+
},
|
|
165
|
+
mintOffers: of(state.mintOffers, key),
|
|
166
|
+
burnRequests: of(state.burnRequests, key),
|
|
167
|
+
preapproval,
|
|
168
|
+
preapprovals,
|
|
169
|
+
preapprovalStatus: cantonCoin ? 'unknown' : preapproval === null ? 'none' : 'covered',
|
|
170
|
+
unavailable: cantonCoin && cantonCoinUnavailable,
|
|
171
|
+
};
|
|
172
|
+
})
|
|
173
|
+
.sort((a, b) => compareText(a.symbol, b.symbol) ||
|
|
174
|
+
compareText(a.instrumentId.id, b.instrumentId.id) ||
|
|
175
|
+
compareText(a.instrumentId.admin, b.instrumentId.admin));
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The token a page opens on: the one whose `key` is `pickedKey` while it is still listed, else the first whose symbol
|
|
179
|
+
* is `prefer.symbol`, else the first token; null when `tokens` is empty.
|
|
180
|
+
*/
|
|
181
|
+
function selectWalletToken(tokens, pickedKey, prefer) {
|
|
182
|
+
return (tokens.find((token) => token.key === pickedKey) ??
|
|
183
|
+
(prefer === undefined ? undefined : tokens.find((token) => token.symbol === prefer.symbol)) ??
|
|
184
|
+
tokens[0] ??
|
|
185
|
+
null);
|
|
186
|
+
}
|
|
187
|
+
//# sourceMappingURL=tokens.js.map
|
|
@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,CAAC,YAAY,CAAC,EAAE,CAAC;QACjD,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,CAAC,CAAC,YAAY,CAAC,KAAK,CAAC,CAC1D,CAAC;AACN,CAAC;AAED;;;GAGG;AACH,2BACE,MAA8B,EAC9B,SAAwB,EACxB,MAAoC;IAEpC,OAAO,CACL,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,KAAK,SAAS,CAAC;QAC/C,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3F,MAAM,CAAC,CAAC,CAAC;QACT,IAAI,CACL,CAAC;AACJ,CAAC"}
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* is unconfirmed, no Canton Coin is listed (`WalletState.cantonCoinUnavailable`).
|
|
18
18
|
*/
|
|
19
19
|
import { type Cip103Provider, type WalletReadRetryOptions } from './cip103';
|
|
20
|
-
import { type BurnRequest, type MintOffer, type TransferOffer, type TransferPreapproval } from './contracts';
|
|
20
|
+
import { type BurnRequest, type MintOffer, type TransferOffer, type TransferOfferRegistry, type TransferPreapproval } from './contracts';
|
|
21
21
|
import { type DaNetwork, type DaRegistryOptions, type TransferKind } from './da-utilities/client';
|
|
22
22
|
import { type CantonCoinOptions } from './amulet/registry';
|
|
23
23
|
import { type Holding, type InstrumentBalance } from './holdings';
|
|
@@ -151,6 +151,40 @@ export interface BurnRequestOptions {
|
|
|
151
151
|
export interface BurnRequestResult extends SubmitResult {
|
|
152
152
|
readonly reference: string;
|
|
153
153
|
}
|
|
154
|
+
/** One expired offer withdrawn: its submission, the offer and the amount it offered. */
|
|
155
|
+
export interface WithdrawnOffer extends SubmitResult {
|
|
156
|
+
readonly transferOfferCid: string;
|
|
157
|
+
readonly amount: string;
|
|
158
|
+
/** The registry that validated the offer: `'amulet'` for Canton Coin (its DSO confirmed by Scan), else `'da'`. */
|
|
159
|
+
readonly registry: TransferOfferRegistry;
|
|
160
|
+
}
|
|
161
|
+
/** One expired Canton Coin lock released (`LockedAmulet_OwnerExpireLockV2`): its submission, the holding and amount. */
|
|
162
|
+
export interface ReleasedLock extends SubmitResult {
|
|
163
|
+
readonly lockedHoldingCid: string;
|
|
164
|
+
readonly amount: string;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* What `reclaimLockedTokens` (or `withdrawExpiredTransferOffers`, whose `released` is always empty) did, in the order
|
|
168
|
+
* it did. When a submission after the first fails, or the call's `signal` aborts between submissions, the call resolves
|
|
169
|
+
* (it does not throw) with what already committed, the failure in `failed`, and the contract ids it did not get to in
|
|
170
|
+
* `notAttempted`; a failure before anything committed is thrown as usual.
|
|
171
|
+
*/
|
|
172
|
+
export interface WithdrawExpiredResult {
|
|
173
|
+
readonly withdrawn: readonly WithdrawnOffer[];
|
|
174
|
+
readonly released: readonly ReleasedLock[];
|
|
175
|
+
/**
|
|
176
|
+
* The submission that failed after others committed: the offer or locked holding it was for, and the error as thrown
|
|
177
|
+
* (pass it to `describeWalletError`; an `outcome-unknown` one may have committed).
|
|
178
|
+
*/
|
|
179
|
+
readonly failed?: {
|
|
180
|
+
readonly contractId: string;
|
|
181
|
+
readonly error: unknown;
|
|
182
|
+
};
|
|
183
|
+
/** Offers and locked holdings not submitted because of `failed`, in the order they would have been. */
|
|
184
|
+
readonly notAttempted: readonly string[];
|
|
185
|
+
}
|
|
186
|
+
/** {@link WithdrawExpiredResult} under the name of the call that usually returns it. */
|
|
187
|
+
export type ReclaimLockedTokensResult = WithdrawExpiredResult;
|
|
154
188
|
export interface TransferPreapprovalOptions {
|
|
155
189
|
readonly instrumentAdmin: string;
|
|
156
190
|
/** Up to 10 instrument ids of the admin; empty or omitted: every instrument of the admin. */
|
|
@@ -178,6 +212,22 @@ export interface Wallet {
|
|
|
178
212
|
rejectTransferOffer(transferOfferCid: string, options?: WalletCallOptions): Promise<SubmitResult>;
|
|
179
213
|
/** Withdraw one of the party's own transfer offers, which unlocks its tokens (also after the offer expired). */
|
|
180
214
|
withdrawTransferOffer(transferOfferCid: string, options?: WalletCallOptions): Promise<SubmitResult>;
|
|
215
|
+
/**
|
|
216
|
+
* Withdraw all of the party's own expired transfer offers of one token (`TransferOffer.expired`), so the tokens they
|
|
217
|
+
* keep locked (`InstrumentBalance.lockedInExpiredOffers`) are unlocked: one `TransferInstruction_Withdraw` per offer,
|
|
218
|
+
* each as `withdrawTransferOffer` sends it, through the offer's own registry. Refused with `not-found` when there is
|
|
219
|
+
* none. Stops at the first failure: thrown when nothing was withdrawn yet, else reported in the result's `failed`
|
|
220
|
+
* (see {@link WithdrawExpiredResult}).
|
|
221
|
+
*/
|
|
222
|
+
withdrawExpiredTransferOffers(instrumentId: InstrumentId, options?: WalletCallOptions): Promise<WithdrawExpiredResult>;
|
|
223
|
+
/**
|
|
224
|
+
* Unlock everything of one token that no longer needs to be locked: first withdraw the party's expired outgoing
|
|
225
|
+
* offers (as `withdrawExpiredTransferOffers`), then, for Canton Coin, release each of the party's own expired locks
|
|
226
|
+
* that no active offer names (`LockedAmulet_OwnerExpireLockV2`, which Splice lets the owner alone run once the lock
|
|
227
|
+
* expired), one submission each. `WalletToken.canReclaim` says whether there is anything to do; refused with
|
|
228
|
+
* `not-found` when there is nothing. Failures as `withdrawExpiredTransferOffers`.
|
|
229
|
+
*/
|
|
230
|
+
reclaimLockedTokens(instrumentId: InstrumentId, options?: WalletCallOptions): Promise<ReclaimLockedTokensResult>;
|
|
181
231
|
acceptMintOffer(mintOfferCid: string, options?: WalletCallOptions): Promise<SubmitResult>;
|
|
182
232
|
/** Reject a mint offer; the registrar sees {@link MINT_OFFER_REJECT_REASON}. */
|
|
183
233
|
rejectMintOffer(mintOfferCid: string, options?: WalletCallOptions): Promise<SubmitResult>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../src/wallets/wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAIL,KAAK,cAAc,EAEnB,KAAK,sBAAsB,EAC5B,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../src/wallets/wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,EAIL,KAAK,cAAc,EAEnB,KAAK,sBAAsB,EAC5B,MAAM,UAAU,CAAC;AAelB,OAAO,EAQL,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AACrB,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,iBAAiB,EAGtB,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAKL,KAAK,iBAAiB,EACvB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAKL,KAAK,OAAO,EACZ,KAAK,iBAAiB,EAEvB,MAAM,YAAY,CAAC;AAQpB,OAAO,KAAK,EAAkB,YAAY,EAAE,YAAY,EAAoB,MAAM,SAAS,CAAC;AAc5F,mFAAmF;AACnF,eAAO,MAAM,sBAAsB,QAAuC,CAAC;AAC3E,2GAA2G;AAC3G,eAAO,MAAM,wBAAwB,2BAA2B,CAAC;AAmBjE;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,IAAI,GAAG,MAAM,CAGlD;AAED,MAAM,WAAW,aAAa;IAC5B,+EAA+E;IAC/E,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,gDAAgD;IAChD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAC;IAC5B,QAA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ACzB,yDAAyD;IACzD,yBAAyB,CAAC,cAAc,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACvG;AAkFD,qFAAqF;AACrF,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,MAAM,CAotB3D"}
|
|
@@ -31,7 +31,11 @@ const registry_1 = require("./amulet/registry");
|
|
|
31
31
|
const errors_1 = require("./errors");
|
|
32
32
|
const holding_view_1 = require("./holding-view");
|
|
33
33
|
const holdings_1 = require("./holdings");
|
|
34
|
+
const decimal_1 = require("./decimal");
|
|
35
|
+
const instrument_1 = require("./instrument");
|
|
36
|
+
const json_1 = require("./json");
|
|
34
37
|
const templates_1 = require("./templates");
|
|
38
|
+
const tokens_1 = require("./tokens");
|
|
35
39
|
const templates_2 = require("../da-registry/templates");
|
|
36
40
|
const constants_2 = require("../utils/token-standard/v1/constants");
|
|
37
41
|
const SECOND_MS = 1000;
|
|
@@ -332,11 +336,21 @@ function createWallet(options) {
|
|
|
332
336
|
registry.operatorParty(),
|
|
333
337
|
balancesWithMetadata(holdings, cantonCoinMetadata),
|
|
334
338
|
]);
|
|
339
|
+
const at = now();
|
|
340
|
+
const withExpiry = (offers) => offers.map((offer) => ({ ...offer, expired: (0, tokens_1.isTransferOfferExpired)(offer, at) }));
|
|
341
|
+
const offers = transferOffers(contracts, operator, dso);
|
|
342
|
+
const outgoing = withExpiry(offers.outgoing);
|
|
343
|
+
const reclaimable = (0, tokens_1.lockedInExpiredOffers)(holdings, outgoing.filter((offer) => offer.expired === true));
|
|
344
|
+
const inExpiredLocks = (0, tokens_1.unitsByInstrument)((0, tokens_1.expiredUnclaimedLocks)(holdings, [...offers.incoming, ...offers.outgoing], at));
|
|
335
345
|
return {
|
|
336
346
|
offset,
|
|
337
347
|
holdings,
|
|
338
|
-
balances
|
|
339
|
-
|
|
348
|
+
balances: balances.map((balance) => ({
|
|
349
|
+
...balance,
|
|
350
|
+
lockedInExpiredOffers: (0, decimal_1.formatDecimalUnits)(reclaimable.get(balance.key) ?? 0n),
|
|
351
|
+
lockedInExpiredLocks: (0, decimal_1.formatDecimalUnits)(inExpiredLocks.get(balance.key) ?? 0n),
|
|
352
|
+
})),
|
|
353
|
+
transferOffers: { incoming: withExpiry(offers.incoming), outgoing },
|
|
340
354
|
mintOffers: ownMintOffers(contracts, operator),
|
|
341
355
|
burnRequests: ownBurnRequests(contracts, operator),
|
|
342
356
|
transferPreapprovals: ownPreapprovals(contracts, operator),
|
|
@@ -458,6 +472,11 @@ function createWallet(options) {
|
|
|
458
472
|
}
|
|
459
473
|
const { incoming, outgoing } = offers;
|
|
460
474
|
const offer = find(action === 'withdraw' ? outgoing : incoming, transferOfferCid, action === 'withdraw' ? 'Outgoing transfer offer' : 'Incoming transfer offer');
|
|
475
|
+
return submitOfferAnswer(offer, action, signal);
|
|
476
|
+
}
|
|
477
|
+
/** Exercise `action` on a transfer offer already read and validated, with its own registry's choice context. */
|
|
478
|
+
async function submitOfferAnswer(offer, action, signal) {
|
|
479
|
+
const transferOfferCid = offer.contractId;
|
|
461
480
|
const context = offer.registry === 'amulet' && cantonCoin !== null
|
|
462
481
|
? await cantonCoin.transferInstructionContext(transferOfferCid, action, signal)
|
|
463
482
|
: await registry.transferInstructionContext(offer.instrumentId.admin, transferOfferCid, action, signal);
|
|
@@ -466,6 +485,108 @@ function createWallet(options) {
|
|
|
466
485
|
disclosedContracts: context.disclosedContracts,
|
|
467
486
|
}, signal);
|
|
468
487
|
}
|
|
488
|
+
/**
|
|
489
|
+
* Withdraw every one of the party's own expired transfer offers of `instrumentId`, one submission each, oldest
|
|
490
|
+
* deadline first; with `releaseLocks`, then release each of the party's own expired Canton Coin locks of it that no
|
|
491
|
+
* active offer names (`LockedAmulet_OwnerExpireLockV2`), oldest expiry first. Read once; each offer is withdrawn
|
|
492
|
+
* through its own registry (Canton Coin's for a Canton Coin offer, DA's for a DA offer), exactly as
|
|
493
|
+
* `withdrawTransferOffer` does. Stops at the first failure: thrown when nothing committed yet, else reported in the
|
|
494
|
+
* result (what committed stays committed; a reload shows it).
|
|
495
|
+
*/
|
|
496
|
+
async function runReclaim(instrumentIdInput, releaseLocks, signal) {
|
|
497
|
+
const instrumentId = requireInstrumentId(instrumentIdInput);
|
|
498
|
+
// A known DSO decides: a registrar's own `Amulet` (another admin) goes straight to DA's path, never to Scan.
|
|
499
|
+
const knownDso = cantonCoin?.knownDsoParty();
|
|
500
|
+
const isAmuletId = cantonCoin !== null &&
|
|
501
|
+
instrumentId.id === constants_1.AMULET_INSTRUMENT_ID &&
|
|
502
|
+
(knownDso === undefined || instrumentId.admin === knownDso);
|
|
503
|
+
const readLocks = releaseLocks && isAmuletId;
|
|
504
|
+
const all = readLocks
|
|
505
|
+
? (await (0, abort_1.awaitWithAbort)(async () => ledger.readActiveContracts([...offerTemplates, ...CANTON_COIN_HOLDING_FILTERS]), signal)).contracts
|
|
506
|
+
: await read(offerTemplates, signal);
|
|
507
|
+
const contracts = all.filter((contract) => {
|
|
508
|
+
const transfer = contract.createArgument?.['transfer'];
|
|
509
|
+
return (0, json_1.isRecord)(transfer) && transfer['sender'] === partyId;
|
|
510
|
+
});
|
|
511
|
+
const candidates = [];
|
|
512
|
+
let cantonCoinUnconfirmed = false;
|
|
513
|
+
let expiredLocks = [];
|
|
514
|
+
if (isAmuletId &&
|
|
515
|
+
(readLocks ? anyOf(all, CANTON_COIN_TEMPLATES) : anyOf(contracts, [constants_1.AMULET_TEMPLATES.transferInstruction]))) {
|
|
516
|
+
const { dso, unavailable } = await cantonCoinDso(all, signal, registry_1.AMULET_REGISTRY_REQUEST_TIMEOUT_MS);
|
|
517
|
+
cantonCoinUnconfirmed = unavailable;
|
|
518
|
+
candidates.push(...amuletTransferOffers(contracts, dso));
|
|
519
|
+
if (readLocks && dso !== undefined) {
|
|
520
|
+
expiredLocks = (0, tokens_1.expiredUnclaimedLocks)(holdingsIn(all, dso), amuletTransferOffers(all, dso), now())
|
|
521
|
+
.filter((holding) => (0, instrument_1.sameInstrument)(holding.instrumentId, instrumentId))
|
|
522
|
+
.sort((a, b) => Date.parse(a.lockExpiresAt ?? '') - Date.parse(b.lockExpiresAt ?? '') ||
|
|
523
|
+
(a.contractId < b.contractId ? -1 : 1));
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
const cantonCoinUnconfirmedError = () => new errors_1.RegistryResponseError(`${registry_1.AMULET_REGISTRY_NAME} could not confirm Canton Coin's DSO party, so the wallet's Canton Coin offers cannot be checked; nothing was submitted. Try again later, or pin cantonCoin.dsoParty.`);
|
|
527
|
+
const isAmuletOf = candidates.some((offer) => (0, instrument_1.sameInstrument)(offer.instrumentId, instrumentId));
|
|
528
|
+
if (!isAmuletOf && expiredLocks.length === 0 && anyOf(contracts, [templates_2.DA_REGISTRY_TEMPLATES.transferOffer])) {
|
|
529
|
+
let operator;
|
|
530
|
+
try {
|
|
531
|
+
operator = await registry.operatorParty(signal);
|
|
532
|
+
}
|
|
533
|
+
catch (error) {
|
|
534
|
+
// Canton Coin's `Amulet` with an unconfirmed DSO: only Scan can validate its offers, so say that, not why DA's
|
|
535
|
+
// operator (asked in case a registrar issued an `Amulet` of its own) could not be read.
|
|
536
|
+
(0, abort_1.throwIfAborted)(signal);
|
|
537
|
+
if (cantonCoinUnconfirmed)
|
|
538
|
+
throw cantonCoinUnconfirmedError();
|
|
539
|
+
throw error;
|
|
540
|
+
}
|
|
541
|
+
candidates.push(...fromRegistry(contracts, contracts_1.parseTransferOffer, operator));
|
|
542
|
+
}
|
|
543
|
+
const at = now();
|
|
544
|
+
const expired = byDirection(candidates)
|
|
545
|
+
.outgoing.filter((offer) => (0, instrument_1.sameInstrument)(offer.instrumentId, instrumentId) && (0, tokens_1.isTransferOfferExpired)(offer, at))
|
|
546
|
+
.sort((a, b) => Date.parse(a.executeBefore) - Date.parse(b.executeBefore) || (a.contractId < b.contractId ? -1 : 1));
|
|
547
|
+
if (expired.length === 0 && expiredLocks.length === 0) {
|
|
548
|
+
if (cantonCoinUnconfirmed)
|
|
549
|
+
throw cantonCoinUnconfirmedError();
|
|
550
|
+
throw new errors_1.WalletError('not-found', releaseLocks
|
|
551
|
+
? `The wallet has no expired outgoing transfer offers or expired locks of ${instrumentId.id}; nothing was submitted`
|
|
552
|
+
: `The wallet has no expired outgoing transfer offers of ${instrumentId.id}; nothing was submitted`);
|
|
553
|
+
}
|
|
554
|
+
const steps = [
|
|
555
|
+
...expired.map((offer) => ({ kind: 'offer', offer })),
|
|
556
|
+
...expiredLocks.map((holding) => ({ kind: 'lock', holding })),
|
|
557
|
+
];
|
|
558
|
+
const contractIdOf = (step) => step.kind === 'offer' ? step.offer.contractId : step.holding.contractId;
|
|
559
|
+
const withdrawn = [];
|
|
560
|
+
const released = [];
|
|
561
|
+
for (const [index, step] of steps.entries()) {
|
|
562
|
+
try {
|
|
563
|
+
if (step.kind === 'offer') {
|
|
564
|
+
const result = await submitOfferAnswer(step.offer, 'withdraw', signal);
|
|
565
|
+
withdrawn.push({
|
|
566
|
+
...result,
|
|
567
|
+
transferOfferCid: step.offer.contractId,
|
|
568
|
+
amount: step.offer.amount,
|
|
569
|
+
registry: step.offer.registry ?? 'da',
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
const result = await submit({ commands: [(0, commands_1.ownerExpireLockCommand)(step.holding.contractId)] }, signal);
|
|
574
|
+
released.push({ ...result, lockedHoldingCid: step.holding.contractId, amount: step.holding.amount });
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
catch (error) {
|
|
578
|
+
if (index === 0)
|
|
579
|
+
throw error;
|
|
580
|
+
return {
|
|
581
|
+
withdrawn,
|
|
582
|
+
released,
|
|
583
|
+
failed: { contractId: contractIdOf(step), error },
|
|
584
|
+
notAttempted: steps.slice(index + 1).map(contractIdOf),
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
}
|
|
588
|
+
return { withdrawn, released, notAttempted: [] };
|
|
589
|
+
}
|
|
469
590
|
async function ownMintOffer(mintOfferCid, signal) {
|
|
470
591
|
const [contracts, operator] = await Promise.all([
|
|
471
592
|
read(templates_2.DA_REGISTRY_TEMPLATES.mintOffer, signal),
|
|
@@ -554,10 +675,8 @@ function createWallet(options) {
|
|
|
554
675
|
cantonCoin === null || knownDso !== undefined ? knownDso : cantonCoin.dsoParty(signal),
|
|
555
676
|
]);
|
|
556
677
|
refuseCantonCoinPreapproval(instrumentAdmin, dso);
|
|
557
|
-
const covering = ownPreapprovals(contracts, operator)
|
|
558
|
-
|
|
559
|
-
(instrumentIds.length > 0 && instrumentIds.every((id) => existing.instrumentIds.includes(id)))));
|
|
560
|
-
if (covering !== undefined) {
|
|
678
|
+
const covering = (0, contracts_1.coveringPreapproval)(ownPreapprovals(contracts, operator), { instrumentAdmin, instrumentIds });
|
|
679
|
+
if (covering !== null) {
|
|
561
680
|
throw new errors_1.WalletError('already-exists', `Transfer preapproval ${covering.contractId} already covers ${instrumentIds.length === 0 ? 'every instrument' : instrumentIds.join(', ')} of ${instrumentAdmin}; nothing was submitted`);
|
|
562
681
|
}
|
|
563
682
|
return submit({
|
|
@@ -580,6 +699,8 @@ function createWallet(options) {
|
|
|
580
699
|
acceptTransferOffer: async (cid, { signal } = {}) => exclusive(signal, async () => answerTransferOffer(cid, 'accept', signal)),
|
|
581
700
|
rejectTransferOffer: async (cid, { signal } = {}) => exclusive(signal, async () => answerTransferOffer(cid, 'reject', signal)),
|
|
582
701
|
withdrawTransferOffer: async (cid, { signal } = {}) => exclusive(signal, async () => answerTransferOffer(cid, 'withdraw', signal)),
|
|
702
|
+
withdrawExpiredTransferOffers: async (instrumentId, { signal } = {}) => exclusive(signal, async () => runReclaim(instrumentId, false, signal)),
|
|
703
|
+
reclaimLockedTokens: async (instrumentId, { signal } = {}) => exclusive(signal, async () => runReclaim(instrumentId, true, signal)),
|
|
583
704
|
acceptMintOffer: async (cid, { signal } = {}) => exclusive(signal, async () => {
|
|
584
705
|
await ownMintOffer(cid, signal);
|
|
585
706
|
const context = await registry.mintOfferAcceptContext(cid, signal);
|