@ledgerhq/live-common 25.0.0-next.4 → 25.0.0-next.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/lib/apps/support.d.ts.map +1 -1
- package/lib/apps/support.js +2 -1
- package/lib/apps/support.js.map +1 -1
- package/lib/families/cardano/bridge.integration.test.d.ts.map +1 -1
- package/lib/families/cardano/bridge.integration.test.js +36 -2
- package/lib/families/cardano/bridge.integration.test.js.map +1 -1
- package/lib/families/cardano/buildSubAccounts.d.ts.map +1 -1
- package/lib/families/cardano/buildSubAccounts.js +5 -3
- package/lib/families/cardano/buildSubAccounts.js.map +1 -1
- package/lib/families/cardano/deviceTransactionConfig.d.ts +11 -0
- package/lib/families/cardano/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/families/cardano/deviceTransactionConfig.js +91 -0
- package/lib/families/cardano/deviceTransactionConfig.js.map +1 -0
- package/lib/families/cardano/errors.d.ts +4 -0
- package/lib/families/cardano/errors.d.ts.map +1 -1
- package/lib/families/cardano/errors.js +5 -1
- package/lib/families/cardano/errors.js.map +1 -1
- package/lib/families/cardano/js-estimateMaxSpendable.d.ts.map +1 -1
- package/lib/families/cardano/js-estimateMaxSpendable.js +3 -2
- package/lib/families/cardano/js-estimateMaxSpendable.js.map +1 -1
- package/lib/families/cardano/js-getTransactionStatus.d.ts.map +1 -1
- package/lib/families/cardano/js-getTransactionStatus.js +6 -5
- package/lib/families/cardano/js-getTransactionStatus.js.map +1 -1
- package/lib/families/cardano/js-signOperation.d.ts.map +1 -1
- package/lib/families/cardano/js-signOperation.js +10 -5
- package/lib/families/cardano/js-signOperation.js.map +1 -1
- package/lib/families/cardano/js-synchronisation.d.ts.map +1 -1
- package/lib/families/cardano/js-synchronisation.js +126 -98
- package/lib/families/cardano/js-synchronisation.js.map +1 -1
- package/lib/families/cardano/js-transaction.js +1 -1
- package/lib/families/cardano/js-transaction.js.map +1 -1
- package/lib/families/cardano/logic.d.ts +1 -0
- package/lib/families/cardano/logic.d.ts.map +1 -1
- package/lib/families/cardano/logic.js +11 -1
- package/lib/families/cardano/logic.js.map +1 -1
- package/lib/families/cardano/specs.d.ts.map +1 -1
- package/lib/families/cardano/specs.js +39 -1
- package/lib/families/cardano/specs.js.map +1 -1
- package/lib/families/cardano/speculos-deviceActions.d.ts.map +1 -1
- package/lib/families/cardano/speculos-deviceActions.js +15 -0
- package/lib/families/cardano/speculos-deviceActions.js.map +1 -1
- package/lib/generated/deviceTransactionConfig.d.ts +2 -0
- package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/generated/deviceTransactionConfig.js +28 -26
- package/lib/generated/deviceTransactionConfig.js.map +1 -1
- package/package.json +3 -3
- package/src/apps/support.ts +1 -0
- package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +101 -0
- package/src/families/cardano/__snapshots__/bridge.integration.test.ts.snap +41 -1
- package/src/families/cardano/bridge.integration.test.ts +38 -0
- package/src/families/cardano/buildSubAccounts.ts +5 -3
- package/src/families/cardano/deviceTransactionConfig.ts +109 -0
- package/src/families/cardano/errors.ts +7 -0
- package/src/families/cardano/js-estimateMaxSpendable.ts +4 -1
- package/src/families/cardano/js-getTransactionStatus.ts +7 -7
- package/src/families/cardano/js-signOperation.ts +10 -5
- package/src/families/cardano/js-synchronisation.ts +52 -21
- package/src/families/cardano/js-transaction.ts +1 -1
- package/src/families/cardano/logic.ts +10 -0
- package/src/families/cardano/specs.ts +53 -1
- package/src/families/cardano/speculos-deviceActions.ts +15 -0
- package/src/generated/deviceTransactionConfig.ts +3 -0
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
getMemoFromTx,
|
|
22
22
|
getOperationType,
|
|
23
23
|
isHexString,
|
|
24
|
+
mergeTokens,
|
|
24
25
|
} from "./logic";
|
|
25
26
|
import { encodeOperationId } from "../../operation";
|
|
26
27
|
import { getNetworkParameters } from "./networks";
|
|
@@ -28,6 +29,9 @@ import { getNetworkInfo } from "./api/getNetworkInfo";
|
|
|
28
29
|
import uniqBy from "lodash/uniqBy";
|
|
29
30
|
import postSyncPatch from "./postSyncPatch";
|
|
30
31
|
import { getTransactions } from "./api/getTransactions";
|
|
32
|
+
import { buildSubAccounts } from "./buildSubAccounts";
|
|
33
|
+
import { calculateMinUtxoAmount } from "@stricahq/typhonjs/dist/utils/utils";
|
|
34
|
+
import { listTokensForCryptoCurrency } from "../../currencies";
|
|
31
35
|
|
|
32
36
|
function mapTxToAccountOperation(
|
|
33
37
|
tx: APITransaction,
|
|
@@ -43,6 +47,10 @@ function mapTxToAccountOperation(
|
|
|
43
47
|
|
|
44
48
|
const subOperations = inferSubOperations(tx.hash, subAccounts);
|
|
45
49
|
const memo = getMemoFromTx(tx);
|
|
50
|
+
const extra = {};
|
|
51
|
+
if (memo) {
|
|
52
|
+
extra["memo"] = memo;
|
|
53
|
+
}
|
|
46
54
|
|
|
47
55
|
return {
|
|
48
56
|
accountId,
|
|
@@ -64,14 +72,12 @@ function mapTxToAccountOperation(
|
|
|
64
72
|
subOperations,
|
|
65
73
|
blockHeight: tx.blockHeight,
|
|
66
74
|
date: new Date(tx.timestamp),
|
|
67
|
-
extra:
|
|
68
|
-
memo,
|
|
69
|
-
},
|
|
75
|
+
extra: extra,
|
|
70
76
|
blockHash: undefined,
|
|
71
77
|
};
|
|
72
78
|
}
|
|
73
79
|
|
|
74
|
-
function
|
|
80
|
+
function prepareUtxos(
|
|
75
81
|
newTransactions: Array<APITransaction>,
|
|
76
82
|
stableUtxos: Array<CardanoOutput>,
|
|
77
83
|
accountCredentialsMap: Record<string, PaymentCredential>
|
|
@@ -116,7 +122,10 @@ function syncUtxos(
|
|
|
116
122
|
return utxos;
|
|
117
123
|
}
|
|
118
124
|
|
|
119
|
-
export const getAccountShape: GetAccountShape = async (
|
|
125
|
+
export const getAccountShape: GetAccountShape = async (
|
|
126
|
+
info,
|
|
127
|
+
{ blacklistedTokenIds }
|
|
128
|
+
) => {
|
|
120
129
|
const {
|
|
121
130
|
transport,
|
|
122
131
|
currency,
|
|
@@ -152,16 +161,27 @@ export const getAccountShape: GetAccountShape = async (info) => {
|
|
|
152
161
|
derivationMode,
|
|
153
162
|
});
|
|
154
163
|
|
|
164
|
+
// when new tokens are added / blacklist changes, we need to sync again because we need to go through all operations again
|
|
165
|
+
const syncHash =
|
|
166
|
+
JSON.stringify(blacklistedTokenIds || []) +
|
|
167
|
+
"_" +
|
|
168
|
+
listTokensForCryptoCurrency(currency, {
|
|
169
|
+
withDelisted: true,
|
|
170
|
+
}).length;
|
|
171
|
+
const outdatedSyncHash = initialAccount?.syncHash !== syncHash;
|
|
172
|
+
|
|
155
173
|
const requiredConfirmations = 90;
|
|
156
174
|
|
|
157
175
|
const oldOperations = initialAccount?.operations || [];
|
|
158
176
|
const lastBlockHeight = oldOperations.length
|
|
159
177
|
? (oldOperations[0].blockHeight || 0) + 1
|
|
160
178
|
: 0;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
179
|
+
|
|
180
|
+
const syncFromBlockHeight = outdatedSyncHash
|
|
181
|
+
? 0
|
|
182
|
+
: lastBlockHeight > requiredConfirmations
|
|
183
|
+
? lastBlockHeight - requiredConfirmations
|
|
184
|
+
: 0;
|
|
165
185
|
|
|
166
186
|
const {
|
|
167
187
|
transactions: newTransactions,
|
|
@@ -195,21 +215,24 @@ export const getAccountShape: GetAccountShape = async (info) => {
|
|
|
195
215
|
(u) => stableOperationsByIds[u.hash]
|
|
196
216
|
);
|
|
197
217
|
|
|
198
|
-
const utxos =
|
|
218
|
+
const utxos = prepareUtxos(
|
|
219
|
+
newTransactions,
|
|
220
|
+
stableUtxos,
|
|
221
|
+
accountCredentialsMap
|
|
222
|
+
);
|
|
199
223
|
const accountBalance = utxos.reduce(
|
|
200
224
|
(total, u) => total.plus(u.amount),
|
|
201
225
|
new BigNumber(0)
|
|
202
226
|
);
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const subAccounts = [];
|
|
227
|
+
const tokenBalance = mergeTokens(utxos.map((u) => u.tokens).flat());
|
|
228
|
+
const subAccounts = buildSubAccounts({
|
|
229
|
+
initialAccount,
|
|
230
|
+
parentAccountId: accountId,
|
|
231
|
+
parentCurrency: currency,
|
|
232
|
+
newTransactions,
|
|
233
|
+
tokens: tokenBalance,
|
|
234
|
+
accountCredentialsMap,
|
|
235
|
+
});
|
|
213
236
|
|
|
214
237
|
const newOperations = newTransactions.map((t) =>
|
|
215
238
|
mapTxToAccountOperation(t, accountId, accountCredentialsMap, subAccounts)
|
|
@@ -233,13 +256,21 @@ export const getAccountShape: GetAccountShape = async (info) => {
|
|
|
233
256
|
}).getBech32(),
|
|
234
257
|
}));
|
|
235
258
|
const cardanoNetworkInfo = await getNetworkInfo(initialAccount, currency);
|
|
259
|
+
const minAdaBalanceForTokens = tokenBalance.length
|
|
260
|
+
? calculateMinUtxoAmount(
|
|
261
|
+
tokenBalance,
|
|
262
|
+
new BigNumber(cardanoNetworkInfo.protocolParams.lovelacePerUtxoWord),
|
|
263
|
+
false
|
|
264
|
+
)
|
|
265
|
+
: new BigNumber(0);
|
|
236
266
|
|
|
237
267
|
return {
|
|
238
268
|
id: accountId,
|
|
239
269
|
xpub,
|
|
240
270
|
balance: accountBalance,
|
|
241
|
-
spendableBalance: accountBalance,
|
|
271
|
+
spendableBalance: accountBalance.minus(minAdaBalanceForTokens),
|
|
242
272
|
operations: operations,
|
|
273
|
+
syncHash,
|
|
243
274
|
subAccounts,
|
|
244
275
|
freshAddresses,
|
|
245
276
|
freshAddress: freshAddresses[0].address,
|
|
@@ -47,7 +47,7 @@ export const prepareTransaction = async (
|
|
|
47
47
|
try {
|
|
48
48
|
transaction = await buildTransaction(a, t);
|
|
49
49
|
} catch (error) {
|
|
50
|
-
return { ...t, fees: new BigNumber(0), amount:
|
|
50
|
+
return { ...t, fees: new BigNumber(0), amount: t.amount };
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
const transactionFees = transaction.getFee();
|
|
@@ -448,3 +448,13 @@ export function isHexString(value: string): boolean {
|
|
|
448
448
|
const regExp = /^[0-9a-fA-F]+$/;
|
|
449
449
|
return regExp.test(value);
|
|
450
450
|
}
|
|
451
|
+
|
|
452
|
+
export function decodeTokenName(assetName: string): string {
|
|
453
|
+
if (assetName.length > 0) {
|
|
454
|
+
const bytes = [...Buffer.from(assetName, "hex")];
|
|
455
|
+
if (bytes.filter((byte) => byte <= 32 || byte >= 127).length === 0) {
|
|
456
|
+
return String.fromCharCode(...bytes);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return assetName;
|
|
460
|
+
}
|
|
@@ -9,10 +9,15 @@ import invariant from "invariant";
|
|
|
9
9
|
import { utils as TyphonUtils } from "@stricahq/typhonjs";
|
|
10
10
|
import { mergeTokens } from "./logic";
|
|
11
11
|
import { parseCurrencyUnit } from "../../currencies";
|
|
12
|
+
import { SubAccount } from "../../types";
|
|
12
13
|
|
|
13
14
|
const currency = getCryptoCurrencyById("cardano");
|
|
14
15
|
const minBalanceRequired = parseCurrencyUnit(currency.units[0], "2.2");
|
|
15
16
|
const minBalanceRequiredForMaxSend = parseCurrencyUnit(currency.units[0], "1");
|
|
17
|
+
const minSpendableRequiredForTokenTx = parseCurrencyUnit(
|
|
18
|
+
currency.units[0],
|
|
19
|
+
"3"
|
|
20
|
+
);
|
|
16
21
|
|
|
17
22
|
const cardano: AppSpec<Transaction> = {
|
|
18
23
|
name: "cardano",
|
|
@@ -34,7 +39,12 @@ const cardano: AppSpec<Transaction> = {
|
|
|
34
39
|
|
|
35
40
|
const updates = [
|
|
36
41
|
{ recipient },
|
|
37
|
-
{
|
|
42
|
+
{
|
|
43
|
+
amount: new BigNumber(account.balance.dividedBy(2)).dp(
|
|
44
|
+
0,
|
|
45
|
+
BigNumber.ROUND_CEIL
|
|
46
|
+
),
|
|
47
|
+
},
|
|
38
48
|
{ memo: "LedgerLiveBot" },
|
|
39
49
|
];
|
|
40
50
|
|
|
@@ -90,6 +100,48 @@ const cardano: AppSpec<Transaction> = {
|
|
|
90
100
|
);
|
|
91
101
|
},
|
|
92
102
|
},
|
|
103
|
+
{
|
|
104
|
+
name: "move ~10% token",
|
|
105
|
+
maxRun: 1,
|
|
106
|
+
transaction: ({ account, siblings, bridge, maxSpendable }) => {
|
|
107
|
+
invariant(
|
|
108
|
+
maxSpendable.gte(minSpendableRequiredForTokenTx),
|
|
109
|
+
"balance is too low"
|
|
110
|
+
);
|
|
111
|
+
const sibling = pickSiblings(siblings, 3);
|
|
112
|
+
const recipient = sibling.freshAddress;
|
|
113
|
+
const transaction = bridge.createTransaction(account);
|
|
114
|
+
|
|
115
|
+
const subAccount = account.subAccounts?.find((subAccount) =>
|
|
116
|
+
subAccount.balance.gt(1)
|
|
117
|
+
) as SubAccount;
|
|
118
|
+
invariant(subAccount, "No token account with balance");
|
|
119
|
+
|
|
120
|
+
const updates = [
|
|
121
|
+
{ subAccountId: subAccount.id },
|
|
122
|
+
{ recipient },
|
|
123
|
+
{
|
|
124
|
+
amount: new BigNumber(subAccount.balance.dividedBy(10)).dp(
|
|
125
|
+
0,
|
|
126
|
+
BigNumber.ROUND_CEIL
|
|
127
|
+
),
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
transaction,
|
|
133
|
+
updates,
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
test: ({ operation, transaction }): void => {
|
|
137
|
+
expect(operation.subOperations).toBeTruthy();
|
|
138
|
+
expect(operation.subOperations?.length).toEqual(1);
|
|
139
|
+
|
|
140
|
+
const subOperation =
|
|
141
|
+
operation.subOperations && operation.subOperations[0];
|
|
142
|
+
expect(subOperation?.value).toEqual(transaction.amount);
|
|
143
|
+
},
|
|
144
|
+
},
|
|
93
145
|
],
|
|
94
146
|
};
|
|
95
147
|
|
|
@@ -39,6 +39,21 @@ const acceptTransaction: DeviceAction<Transaction, any> = deviceActionFlow({
|
|
|
39
39
|
expectedValue: ({ account, status }) =>
|
|
40
40
|
expectedValue(account.unit, status.amount),
|
|
41
41
|
},
|
|
42
|
+
{
|
|
43
|
+
title: "Asset fingerprint",
|
|
44
|
+
button: "LRlr",
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
title: "Token amount",
|
|
48
|
+
button: "LRlr",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
title: "Confirm",
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
title: "output?",
|
|
55
|
+
button: "Rr",
|
|
56
|
+
},
|
|
42
57
|
{
|
|
43
58
|
title: "Transaction fee",
|
|
44
59
|
button: "LRlr",
|
|
@@ -2,6 +2,8 @@ import algorand from "../families/algorand/deviceTransactionConfig";
|
|
|
2
2
|
|
|
3
3
|
import bitcoin from "../families/bitcoin/deviceTransactionConfig";
|
|
4
4
|
|
|
5
|
+
import cardano from "../families/cardano/deviceTransactionConfig";
|
|
6
|
+
|
|
5
7
|
import celo from "../families/celo/deviceTransactionConfig";
|
|
6
8
|
|
|
7
9
|
import cosmos from "../families/cosmos/deviceTransactionConfig";
|
|
@@ -32,6 +34,7 @@ import tron from "../families/tron/deviceTransactionConfig";
|
|
|
32
34
|
export default {
|
|
33
35
|
algorand,
|
|
34
36
|
bitcoin,
|
|
37
|
+
cardano,
|
|
35
38
|
celo,
|
|
36
39
|
cosmos,
|
|
37
40
|
crypto_org,
|