@ledgerhq/coin-canton 0.9.0-nightly.3 → 0.9.0-nightly.5
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/.turbo/turbo-build.log +1 -1
- package/.unimportedrc.json +2 -1
- package/CHANGELOG.md +29 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +2 -2
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib/bridge/estimateMaxSpendable.js +2 -3
- package/lib/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib/bridge/getTransactionStatus.d.ts +5 -3
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib/bridge/getTransactionStatus.js +26 -5
- package/lib/bridge/getTransactionStatus.js.map +1 -1
- package/lib/bridge/index.d.ts +2 -2
- package/lib/bridge/index.d.ts.map +1 -1
- package/lib/bridge/index.js +3 -3
- package/lib/bridge/index.js.map +1 -1
- package/lib/bridge/prepareTransaction.js +1 -1
- package/lib/bridge/prepareTransaction.js.map +1 -1
- package/lib/bridge/serialization.d.ts +4 -0
- package/lib/bridge/serialization.d.ts.map +1 -0
- package/lib/bridge/serialization.js +36 -0
- package/lib/bridge/serialization.js.map +1 -0
- package/lib/bridge/sync.d.ts.map +1 -1
- package/lib/bridge/sync.js +13 -5
- package/lib/bridge/sync.js.map +1 -1
- package/lib/bridge/transaction.js +1 -1
- package/lib/bridge/transaction.js.map +1 -1
- package/lib/common-logic/account/getBalance.d.ts +5 -1
- package/lib/common-logic/account/getBalance.d.ts.map +1 -1
- package/lib/common-logic/account/getBalance.js +2 -0
- package/lib/common-logic/account/getBalance.js.map +1 -1
- package/lib/common-logic/transaction/craftTransaction.js +1 -1
- package/lib/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib/network/gateway.d.ts +1 -0
- package/lib/network/gateway.d.ts.map +1 -1
- package/lib/network/gateway.js.map +1 -1
- package/lib/test/fixtures.d.ts +5 -0
- package/lib/test/fixtures.d.ts.map +1 -0
- package/lib/test/fixtures.js +57 -0
- package/lib/test/fixtures.js.map +1 -0
- package/lib/types/bridge.d.ts +14 -2
- package/lib/types/bridge.d.ts.map +1 -1
- package/lib/types/errors.d.ts +6 -0
- package/lib/types/errors.d.ts.map +1 -1
- package/lib/types/errors.js +3 -1
- package/lib/types/errors.js.map +1 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +1 -0
- package/lib/types/index.js.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.d.ts +2 -2
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
- package/lib-es/bridge/estimateMaxSpendable.js +2 -3
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
- package/lib-es/bridge/getTransactionStatus.d.ts +5 -3
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
- package/lib-es/bridge/getTransactionStatus.js +26 -5
- package/lib-es/bridge/getTransactionStatus.js.map +1 -1
- package/lib-es/bridge/index.d.ts +2 -2
- package/lib-es/bridge/index.d.ts.map +1 -1
- package/lib-es/bridge/index.js +3 -3
- package/lib-es/bridge/index.js.map +1 -1
- package/lib-es/bridge/prepareTransaction.js +1 -1
- package/lib-es/bridge/prepareTransaction.js.map +1 -1
- package/lib-es/bridge/serialization.d.ts +4 -0
- package/lib-es/bridge/serialization.d.ts.map +1 -0
- package/lib-es/bridge/serialization.js +32 -0
- package/lib-es/bridge/serialization.js.map +1 -0
- package/lib-es/bridge/sync.d.ts.map +1 -1
- package/lib-es/bridge/sync.js +13 -5
- package/lib-es/bridge/sync.js.map +1 -1
- package/lib-es/bridge/transaction.js +1 -1
- package/lib-es/bridge/transaction.js.map +1 -1
- package/lib-es/common-logic/account/getBalance.d.ts +5 -1
- package/lib-es/common-logic/account/getBalance.d.ts.map +1 -1
- package/lib-es/common-logic/account/getBalance.js +2 -0
- package/lib-es/common-logic/account/getBalance.js.map +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.js +1 -1
- package/lib-es/common-logic/transaction/craftTransaction.js.map +1 -1
- package/lib-es/network/gateway.d.ts +1 -0
- package/lib-es/network/gateway.d.ts.map +1 -1
- package/lib-es/network/gateway.js.map +1 -1
- package/lib-es/test/fixtures.d.ts +5 -0
- package/lib-es/test/fixtures.d.ts.map +1 -0
- package/lib-es/test/fixtures.js +49 -0
- package/lib-es/test/fixtures.js.map +1 -0
- package/lib-es/types/bridge.d.ts +14 -2
- package/lib-es/types/bridge.d.ts.map +1 -1
- package/lib-es/types/errors.d.ts +6 -0
- package/lib-es/types/errors.d.ts.map +1 -1
- package/lib-es/types/errors.js +2 -0
- package/lib-es/types/errors.js.map +1 -1
- package/lib-es/types/index.d.ts +1 -0
- package/lib-es/types/index.d.ts.map +1 -1
- package/lib-es/types/index.js +1 -0
- package/lib-es/types/index.js.map +1 -1
- package/package.json +7 -7
- package/src/bridge/estimateMaxSpendable.ts +6 -8
- package/src/bridge/getTransactionStatus.test.ts +84 -146
- package/src/bridge/getTransactionStatus.ts +42 -7
- package/src/bridge/index.ts +6 -5
- package/src/bridge/onboard.integ.test.ts +8 -31
- package/src/bridge/prepareTransaction.ts +1 -1
- package/src/bridge/serialization.ts +44 -0
- package/src/bridge/signOperation.test.ts +3 -9
- package/src/bridge/sync.test.ts +4 -0
- package/src/bridge/sync.ts +17 -6
- package/src/bridge/transaction.ts +1 -1
- package/src/common-logic/account/getBalance.ts +12 -2
- package/src/common-logic/account/getBalance.unit.test.ts +7 -1
- package/src/common-logic/transaction/craftTransaction.ts +1 -1
- package/src/network/gateway.ts +1 -0
- package/src/test/fixtures.ts +53 -0
- package/src/types/bridge.ts +15 -2
- package/src/types/errors.ts +3 -0
- package/src/types/index.ts +1 -0
package/src/bridge/sync.ts
CHANGED
|
@@ -4,7 +4,8 @@ import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
|
4
4
|
import { GetAccountShape, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
5
5
|
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
6
6
|
import { SignerContext } from "@ledgerhq/coin-framework/signer";
|
|
7
|
-
import {
|
|
7
|
+
import { getLedgerEnd, getOperations, type OperationInfo } from "../network/gateway";
|
|
8
|
+
import { getBalance, type CantonBalance } from "../common-logic/account/getBalance";
|
|
8
9
|
import coinConfig from "../config";
|
|
9
10
|
import resolver from "../signer";
|
|
10
11
|
import { CantonAccount, CantonSigner } from "../types";
|
|
@@ -108,19 +109,26 @@ export function makeGetAccountShape(
|
|
|
108
109
|
const balances = xpubOrAddress ? await getBalance(currency, xpubOrAddress) : [];
|
|
109
110
|
|
|
110
111
|
const balancesData = (balances || []).reduce(
|
|
111
|
-
(acc,
|
|
112
|
-
acc[
|
|
112
|
+
(acc, balance) => {
|
|
113
|
+
acc[balance.instrumentId] = balance;
|
|
113
114
|
return acc;
|
|
114
115
|
},
|
|
115
|
-
{} as Record<string,
|
|
116
|
+
{} as Record<string, CantonBalance>,
|
|
116
117
|
);
|
|
117
118
|
|
|
118
|
-
const unlockedAmount = new BigNumber(balancesData[nativeInstrumentId]?.
|
|
119
|
-
const lockedAmount = new BigNumber(
|
|
119
|
+
const unlockedAmount = new BigNumber(balancesData[nativeInstrumentId]?.value.toString() || "0");
|
|
120
|
+
const lockedAmount = new BigNumber(
|
|
121
|
+
balancesData[`Locked${nativeInstrumentId}`]?.value.toString() || "0",
|
|
122
|
+
);
|
|
120
123
|
const totalBalance = unlockedAmount.plus(lockedAmount);
|
|
121
124
|
const reserveMin = new BigNumber(coinConfig.getCoinConfig(currency).minReserve || 0);
|
|
122
125
|
const spendableBalance = BigNumber.max(0, unlockedAmount.minus(reserveMin));
|
|
123
126
|
|
|
127
|
+
const instrumentUtxoCounts: Record<string, number> = {};
|
|
128
|
+
for (const [instrumentId, balance] of Object.entries(balancesData)) {
|
|
129
|
+
instrumentUtxoCounts[instrumentId] = balance.utxoCount;
|
|
130
|
+
}
|
|
131
|
+
|
|
124
132
|
let operations: Operation[] = [];
|
|
125
133
|
if (xpubOrAddress) {
|
|
126
134
|
const oldOperations = initialAccount?.operations || [];
|
|
@@ -159,6 +167,9 @@ export function makeGetAccountShape(
|
|
|
159
167
|
spendableBalance,
|
|
160
168
|
xpub: xpubOrAddress,
|
|
161
169
|
used,
|
|
170
|
+
cantonResources: {
|
|
171
|
+
instrumentUtxoCounts,
|
|
172
|
+
},
|
|
162
173
|
};
|
|
163
174
|
|
|
164
175
|
return shape;
|
|
@@ -3,12 +3,17 @@ import { getBalance as gatewayGetBalance, type InstrumentBalance } from "../../n
|
|
|
3
3
|
import coinConfig from "../../config";
|
|
4
4
|
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
5
5
|
|
|
6
|
+
export type CantonBalance = Balance & {
|
|
7
|
+
utxoCount: number;
|
|
8
|
+
instrumentId: string;
|
|
9
|
+
};
|
|
10
|
+
|
|
6
11
|
const useGateway = (currency: CryptoCurrency) =>
|
|
7
12
|
coinConfig.getCoinConfig(currency).useGateway === true;
|
|
8
13
|
const getNativeId = (currency: CryptoCurrency) =>
|
|
9
14
|
coinConfig.getCoinConfig(currency).nativeInstrumentId;
|
|
10
15
|
|
|
11
|
-
function adaptInstrument(currency: CryptoCurrency, instrument: InstrumentBalance):
|
|
16
|
+
function adaptInstrument(currency: CryptoCurrency, instrument: InstrumentBalance): CantonBalance {
|
|
12
17
|
return {
|
|
13
18
|
value: BigInt(instrument.amount),
|
|
14
19
|
locked: instrument.locked === true ? BigInt(instrument.amount) : BigInt(0),
|
|
@@ -16,10 +21,15 @@ function adaptInstrument(currency: CryptoCurrency, instrument: InstrumentBalance
|
|
|
16
21
|
getNativeId(currency) === instrument.instrument_id
|
|
17
22
|
? { type: "native" }
|
|
18
23
|
: { type: "token", assetReference: instrument.instrument_id },
|
|
24
|
+
utxoCount: instrument.utxo_count,
|
|
25
|
+
instrumentId: instrument.instrument_id,
|
|
19
26
|
};
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
export async function getBalance(
|
|
29
|
+
export async function getBalance(
|
|
30
|
+
currency: CryptoCurrency,
|
|
31
|
+
partyId: string,
|
|
32
|
+
): Promise<CantonBalance[]> {
|
|
23
33
|
if (useGateway(currency))
|
|
24
34
|
return (await gatewayGetBalance(currency, partyId)).map(instrument =>
|
|
25
35
|
adaptInstrument(currency, instrument),
|
|
@@ -29,11 +29,13 @@ describe("getBalance", () => {
|
|
|
29
29
|
{
|
|
30
30
|
instrument_id: "native-id",
|
|
31
31
|
amount: "1000",
|
|
32
|
+
utxo_count: 1,
|
|
32
33
|
locked: false,
|
|
33
34
|
},
|
|
34
35
|
{
|
|
35
36
|
instrument_id: "token-123",
|
|
36
37
|
amount: "5000",
|
|
38
|
+
utxo_count: 1,
|
|
37
39
|
locked: true,
|
|
38
40
|
},
|
|
39
41
|
];
|
|
@@ -43,16 +45,20 @@ describe("getBalance", () => {
|
|
|
43
45
|
const result = await getBalance(mockCurrency, "party-id");
|
|
44
46
|
|
|
45
47
|
expect(getBalanceFromNetwork).toHaveBeenCalledWith(mockCurrency, "party-id");
|
|
46
|
-
expect(result).toEqual
|
|
48
|
+
expect(result).toEqual([
|
|
47
49
|
{
|
|
48
50
|
value: BigInt(1000),
|
|
49
51
|
locked: BigInt(0),
|
|
50
52
|
asset: { type: "native" },
|
|
53
|
+
utxoCount: 1,
|
|
54
|
+
instrumentId: "native-id",
|
|
51
55
|
},
|
|
52
56
|
{
|
|
53
57
|
value: BigInt(5000),
|
|
54
58
|
locked: BigInt(5000),
|
|
55
59
|
asset: { type: "token", assetReference: "token-123" },
|
|
60
|
+
utxoCount: 1,
|
|
61
|
+
instrumentId: "token-123",
|
|
56
62
|
},
|
|
57
63
|
]);
|
|
58
64
|
});
|
|
@@ -27,7 +27,7 @@ export async function craftTransaction(
|
|
|
27
27
|
}> {
|
|
28
28
|
const params: PrepareTransferRequest = {
|
|
29
29
|
recipient: transaction.recipient || "",
|
|
30
|
-
amount: transaction.amount.
|
|
30
|
+
amount: transaction.amount.toFixed(),
|
|
31
31
|
type: "token-transfer-request" as const,
|
|
32
32
|
execute_before_secs: transaction.expireInSeconds,
|
|
33
33
|
instrument_id: transaction.tokenId,
|
package/src/network/gateway.ts
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { Account } from "@ledgerhq/types-live";
|
|
3
|
+
import { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
|
|
4
|
+
import { getDerivationScheme, runDerivationScheme } from "@ledgerhq/coin-framework/derivation";
|
|
5
|
+
import { createEmptyHistoryCache } from "@ledgerhq/coin-framework/account";
|
|
6
|
+
|
|
7
|
+
export const createMockCantonCurrency = (): CryptoCurrency => {
|
|
8
|
+
const mockCurrency = {
|
|
9
|
+
id: "canton_network",
|
|
10
|
+
name: "Canton",
|
|
11
|
+
type: "CryptoCurrency",
|
|
12
|
+
family: "canton",
|
|
13
|
+
units: [{ name: "Canton", code: "CANTON", magnitude: 38 }],
|
|
14
|
+
ticker: "CANTON",
|
|
15
|
+
scheme: "canton",
|
|
16
|
+
color: "#000000",
|
|
17
|
+
managerAppName: "Canton",
|
|
18
|
+
coinType: 6767,
|
|
19
|
+
explorerViews: [],
|
|
20
|
+
} satisfies CryptoCurrency;
|
|
21
|
+
return mockCurrency;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const createMockAccount = (overrides: Partial<Account> = {}): Account => {
|
|
25
|
+
const currency = createMockCantonCurrency();
|
|
26
|
+
const derivationMode = "canton" as const;
|
|
27
|
+
const scheme = getDerivationScheme({ derivationMode, currency });
|
|
28
|
+
const freshAddressPath = runDerivationScheme(scheme, currency, { account: 0 });
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
id: "js:2:canton_network:test-address:canton",
|
|
32
|
+
type: "Account",
|
|
33
|
+
used: true,
|
|
34
|
+
currency,
|
|
35
|
+
derivationMode,
|
|
36
|
+
index: 0,
|
|
37
|
+
freshAddress: "test_address",
|
|
38
|
+
freshAddressPath,
|
|
39
|
+
creationDate: new Date(),
|
|
40
|
+
lastSyncDate: new Date(),
|
|
41
|
+
balance: new BigNumber(0),
|
|
42
|
+
spendableBalance: new BigNumber(0),
|
|
43
|
+
seedIdentifier: "test_seed",
|
|
44
|
+
blockHeight: 0,
|
|
45
|
+
operationsCount: 0,
|
|
46
|
+
operations: [],
|
|
47
|
+
pendingOperations: [],
|
|
48
|
+
balanceHistoryCache: createEmptyHistoryCache(),
|
|
49
|
+
swapHistory: [],
|
|
50
|
+
subAccounts: [],
|
|
51
|
+
...overrides,
|
|
52
|
+
};
|
|
53
|
+
};
|
package/src/types/bridge.ts
CHANGED
|
@@ -48,6 +48,7 @@ export type Transaction = TransactionCommon & {
|
|
|
48
48
|
fee: BigNumber | null | undefined;
|
|
49
49
|
memo?: string;
|
|
50
50
|
tokenId: string;
|
|
51
|
+
expireInSeconds?: number;
|
|
51
52
|
};
|
|
52
53
|
|
|
53
54
|
export type TransactionRaw = TransactionCommonRaw & {
|
|
@@ -55,10 +56,22 @@ export type TransactionRaw = TransactionCommonRaw & {
|
|
|
55
56
|
fee: string | null | undefined;
|
|
56
57
|
memo?: string;
|
|
57
58
|
tokenId: string;
|
|
59
|
+
expireInSeconds?: number;
|
|
58
60
|
};
|
|
59
61
|
|
|
60
62
|
export type TransactionStatus = TransactionStatusCommon;
|
|
61
63
|
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|
|
62
64
|
|
|
63
|
-
export type
|
|
64
|
-
|
|
65
|
+
export type CantonResources = {
|
|
66
|
+
instrumentUtxoCounts: Record<string, number>;
|
|
67
|
+
};
|
|
68
|
+
export type CantonResourcesRaw = {
|
|
69
|
+
instrumentUtxoCounts: Record<string, number>;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export type CantonAccount = Account & {
|
|
73
|
+
cantonResources: CantonResources;
|
|
74
|
+
};
|
|
75
|
+
export type CantonAccountRaw = AccountRaw & {
|
|
76
|
+
cantonResources: CantonResourcesRaw;
|
|
77
|
+
};
|
package/src/types/errors.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { createCustomErrorClass } from "@ledgerhq/errors";
|
|
2
2
|
|
|
3
3
|
export const SimulationError = createCustomErrorClass("SimulationError");
|
|
4
|
+
|
|
5
|
+
export const TooManyUtxosCritical = createCustomErrorClass("TooManyUtxosCritical");
|
|
6
|
+
export const TooManyUtxosWarning = createCustomErrorClass("TooManyUtxosWarning");
|
package/src/types/index.ts
CHANGED