@ledgerhq/live-common 21.33.1-cosmos.2 → 21.34.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.
- package/lib/account/support.js +1 -1
- package/lib/account/support.js.map +1 -1
- package/lib/env.js +1 -1
- package/lib/env.js.map +1 -1
- package/lib/families/bitcoin/bridge/js.d.ts.map +1 -1
- package/lib/families/bitcoin/bridge/js.js.map +1 -1
- package/lib/families/cosmos/libcore-buildTransaction.d.ts.map +1 -1
- package/lib/families/cosmos/libcore-buildTransaction.js +1 -5
- package/lib/families/cosmos/libcore-buildTransaction.js.map +1 -1
- package/lib/families/cosmos/specs.d.ts.map +1 -1
- package/lib/families/cosmos/specs.js +37 -37
- package/lib/families/cosmos/specs.js.map +1 -1
- package/lib/families/cosmos/test-dataset.js +2 -2
- package/lib/families/cosmos/test-dataset.js.map +1 -1
- package/lib/families/cosmos/validators.d.ts.map +1 -1
- package/lib/families/cosmos/validators.js +15 -61
- package/lib/families/cosmos/validators.js.map +1 -1
- package/lib/families/filecoin/account.d.ts +8 -0
- package/lib/families/filecoin/account.d.ts.map +1 -0
- package/lib/families/filecoin/account.js +49 -0
- package/lib/families/filecoin/account.js.map +1 -0
- package/lib/families/filecoin/bridge/account.d.ts.map +1 -1
- package/lib/families/filecoin/bridge/account.js +30 -17
- package/lib/families/filecoin/bridge/account.js.map +1 -1
- package/lib/families/filecoin/bridge/utils/utils.d.ts +1 -2
- package/lib/families/filecoin/bridge/utils/utils.d.ts.map +1 -1
- package/lib/families/filecoin/bridge/utils/utils.js +7 -7
- package/lib/families/filecoin/bridge/utils/utils.js.map +1 -1
- package/lib/families/filecoin/deviceTransactionConfig.d.ts +28 -0
- package/lib/families/filecoin/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/families/filecoin/deviceTransactionConfig.js +41 -0
- package/lib/families/filecoin/deviceTransactionConfig.js.map +1 -0
- package/lib/families/filecoin/transaction.d.ts +2 -2
- package/lib/families/filecoin/transaction.d.ts.map +1 -1
- package/lib/families/filecoin/transaction.js +12 -4
- package/lib/families/filecoin/transaction.js.map +1 -1
- package/lib/families/filecoin/utils.d.ts +1 -0
- package/lib/families/filecoin/utils.d.ts.map +1 -1
- package/lib/families/filecoin/utils.js +10 -1
- package/lib/families/filecoin/utils.js.map +1 -1
- package/lib/generated/account.d.ts +4 -0
- package/lib/generated/account.d.ts.map +1 -1
- package/lib/generated/account.js +4 -2
- package/lib/generated/account.js.map +1 -1
- package/lib/generated/bridge/js.d.ts +0 -4
- package/lib/generated/bridge/js.d.ts.map +1 -1
- package/lib/generated/bridge/js.js +22 -24
- package/lib/generated/bridge/js.js.map +1 -1
- package/lib/generated/deviceTransactionConfig.d.ts +4 -1
- package/lib/generated/deviceTransactionConfig.d.ts.map +1 -1
- package/lib/generated/deviceTransactionConfig.js +14 -12
- package/lib/generated/deviceTransactionConfig.js.map +1 -1
- package/lib/generated/transaction.d.ts +1 -1
- package/package.json +1 -5
- package/src/__tests__/__snapshots__/all.libcore.ts.snap +0 -875
- package/src/account/support.ts +1 -1
- package/src/env.ts +1 -1
- package/src/families/bitcoin/bridge/js.ts +0 -1
- package/src/families/cosmos/libcore-buildTransaction.ts +1 -4
- package/src/families/cosmos/specs.ts +43 -45
- package/src/families/cosmos/test-dataset.ts +2 -2
- package/src/families/cosmos/validators.ts +77 -98
- package/src/families/filecoin/account.ts +44 -0
- package/src/families/filecoin/bridge/account.ts +34 -18
- package/src/families/filecoin/bridge/utils/utils.ts +8 -11
- package/src/families/filecoin/deviceTransactionConfig.ts +73 -0
- package/src/families/filecoin/transaction.ts +16 -6
- package/src/families/filecoin/utils.ts +9 -0
- package/src/generated/account.ts +3 -0
- package/src/generated/bridge/js.ts +0 -3
- package/src/generated/deviceTransactionConfig.ts +5 -0
- package/lib/families/cosmos/api/Cosmos.d.ts +0 -24
- package/lib/families/cosmos/api/Cosmos.d.ts.map +0 -1
- package/lib/families/cosmos/api/Cosmos.js +0 -524
- package/lib/families/cosmos/api/Cosmos.js.map +0 -1
- package/lib/families/cosmos/bridge/js.d.ts +0 -8
- package/lib/families/cosmos/bridge/js.d.ts.map +0 -1
- package/lib/families/cosmos/bridge/js.js +0 -103
- package/lib/families/cosmos/bridge/js.js.map +0 -1
- package/lib/families/cosmos/js-buildTransaction.d.ts +0 -6
- package/lib/families/cosmos/js-buildTransaction.d.ts.map +0 -1
- package/lib/families/cosmos/js-buildTransaction.js +0 -239
- package/lib/families/cosmos/js-buildTransaction.js.map +0 -1
- package/lib/families/cosmos/js-createTransaction.d.ts +0 -9
- package/lib/families/cosmos/js-createTransaction.d.ts.map +0 -1
- package/lib/families/cosmos/js-createTransaction.js +0 -23
- package/lib/families/cosmos/js-createTransaction.js.map +0 -1
- package/lib/families/cosmos/js-estimateMaxSpendable.d.ts +0 -10
- package/lib/families/cosmos/js-estimateMaxSpendable.d.ts.map +0 -1
- package/lib/families/cosmos/js-estimateMaxSpendable.js +0 -78
- package/lib/families/cosmos/js-estimateMaxSpendable.js.map +0 -1
- package/lib/families/cosmos/js-getTransactionStatus.d.ts +0 -5
- package/lib/families/cosmos/js-getTransactionStatus.d.ts.map +0 -1
- package/lib/families/cosmos/js-getTransactionStatus.js +0 -267
- package/lib/families/cosmos/js-getTransactionStatus.js.map +0 -1
- package/lib/families/cosmos/js-prepareTransaction.d.ts +0 -14
- package/lib/families/cosmos/js-prepareTransaction.d.ts.map +0 -1
- package/lib/families/cosmos/js-prepareTransaction.js +0 -149
- package/lib/families/cosmos/js-prepareTransaction.js.map +0 -1
- package/lib/families/cosmos/js-signOperation.d.ts +0 -10
- package/lib/families/cosmos/js-signOperation.d.ts.map +0 -1
- package/lib/families/cosmos/js-signOperation.js +0 -171
- package/lib/families/cosmos/js-signOperation.js.map +0 -1
- package/lib/families/cosmos/js-synchronisation.d.ts +0 -5
- package/lib/families/cosmos/js-synchronisation.d.ts.map +0 -1
- package/lib/families/cosmos/js-synchronisation.js +0 -277
- package/lib/families/cosmos/js-synchronisation.js.map +0 -1
- package/lib/families/cosmos/js-updateTransaction.d.ts +0 -4
- package/lib/families/cosmos/js-updateTransaction.d.ts.map +0 -1
- package/lib/families/cosmos/js-updateTransaction.js +0 -26
- package/lib/families/cosmos/js-updateTransaction.js.map +0 -1
- package/src/.DS_Store +0 -0
- package/src/__tests__/.DS_Store +0 -0
- package/src/families/cosmos/api/Cosmos.ts +0 -346
- package/src/families/cosmos/bridge/js.ts +0 -68
- package/src/families/cosmos/js-buildTransaction.ts +0 -233
- package/src/families/cosmos/js-createTransaction.ts +0 -23
- package/src/families/cosmos/js-estimateMaxSpendable.ts +0 -33
- package/src/families/cosmos/js-getTransactionStatus.ts +0 -292
- package/src/families/cosmos/js-prepareTransaction.ts +0 -131
- package/src/families/cosmos/js-signOperation.ts +0 -167
- package/src/families/cosmos/js-synchronisation.ts +0 -223
- package/src/families/cosmos/js-updateTransaction.ts +0 -21
package/src/account/support.ts
CHANGED
|
@@ -20,7 +20,7 @@ import { getMainAccount } from "../account";
|
|
|
20
20
|
import { getAccountBridge } from "../bridge";
|
|
21
21
|
import jsBridges from "../generated/bridge/js";
|
|
22
22
|
|
|
23
|
-
const experimentalIntegrations = ["tezos
|
|
23
|
+
const experimentalIntegrations = ["tezos"];
|
|
24
24
|
|
|
25
25
|
export function shouldUseJS(currency: CryptoCurrency) {
|
|
26
26
|
const jsBridge = jsBridges[currency.family];
|
package/src/env.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { calculateFees } from "./../cache";
|
|
|
11
11
|
import { perCoinLogic } from "../logic";
|
|
12
12
|
import { makeAccountBridgeReceive } from "../../../bridge/jsHelpers";
|
|
13
13
|
import * as explorerConfigAPI from "../../../api/explorerConfig";
|
|
14
|
-
|
|
15
14
|
const receive = makeAccountBridgeReceive({
|
|
16
15
|
injectGetAddressParams: (account) => {
|
|
17
16
|
const perCoin = perCoinLogic[account.currency.id];
|
|
@@ -136,10 +136,7 @@ export async function cosmosBuildTransaction({
|
|
|
136
136
|
const gasRequest = await core.CosmosGasLimitRequest.init(
|
|
137
137
|
memoTransaction,
|
|
138
138
|
messages,
|
|
139
|
-
|
|
140
|
-
// Set as 4 int in order to not break libcore implementation
|
|
141
|
-
// String(getEnv("COSMOS_GAS_AMPLIFIER"))
|
|
142
|
-
String(4)
|
|
139
|
+
String(getEnv("COSMOS_GAS_AMPLIFIER"))
|
|
143
140
|
);
|
|
144
141
|
estimatedGas = await libcoreBigIntToBigNumber(
|
|
145
142
|
// NOTE: With new cosmos code, this call might fail if the account hasn't been synchronized
|
|
@@ -16,6 +16,7 @@ import { pickSiblings } from "../../bot/specs";
|
|
|
16
16
|
import type { AppSpec } from "../../bot/types";
|
|
17
17
|
import { toOperationRaw } from "../../account";
|
|
18
18
|
import {
|
|
19
|
+
COSMOS_MIN_SAFE,
|
|
19
20
|
canClaimRewards,
|
|
20
21
|
canDelegate,
|
|
21
22
|
canUndelegate,
|
|
@@ -23,21 +24,16 @@ import {
|
|
|
23
24
|
getMaxDelegationAvailable,
|
|
24
25
|
} from "./logic";
|
|
25
26
|
import { DeviceModelId } from "@ledgerhq/devices";
|
|
26
|
-
|
|
27
|
-
const minAmount = new BigNumber(50000);
|
|
28
|
-
const maxAccounts = 12;
|
|
29
|
-
|
|
30
27
|
const cosmos: AppSpec<Transaction> = {
|
|
31
28
|
name: "Cosmos",
|
|
32
29
|
currency: getCryptoCurrencyById("cosmos"),
|
|
33
30
|
appQuery: {
|
|
34
31
|
model: DeviceModelId.nanoS,
|
|
35
|
-
firmware: "2
|
|
32
|
+
firmware: "<2",
|
|
36
33
|
appName: "Cosmos",
|
|
37
34
|
},
|
|
38
|
-
testTimeout: 2 * 60 * 1000,
|
|
39
35
|
transactionCheck: ({ maxSpendable }) => {
|
|
40
|
-
invariant(maxSpendable.gt(
|
|
36
|
+
invariant(maxSpendable.gt(COSMOS_MIN_SAFE), "balance is too low");
|
|
41
37
|
},
|
|
42
38
|
test: ({ operation, optimisticOperation }) => {
|
|
43
39
|
const opExpected: Record<string, any> = toOperationRaw({
|
|
@@ -49,28 +45,29 @@ const cosmos: AppSpec<Transaction> = {
|
|
|
49
45
|
delete opExpected.blockHash;
|
|
50
46
|
delete opExpected.blockHeight;
|
|
51
47
|
expect(toOperationRaw(operation)).toMatchObject(opExpected); // TODO check it is between operation.value-fees (excluded) and operation.value
|
|
48
|
+
|
|
49
|
+
/*
|
|
50
|
+
// balance move
|
|
51
|
+
expect(account.balance.toString()).toBe(
|
|
52
|
+
accountBeforeTransaction.balance.minus(operation.value).toString()
|
|
53
|
+
);
|
|
54
|
+
*/
|
|
52
55
|
},
|
|
53
56
|
mutations: [
|
|
54
57
|
{
|
|
55
58
|
name: "send some",
|
|
56
|
-
|
|
57
|
-
expect(account.balance.toString()).toBe(
|
|
58
|
-
accountBeforeTransaction.balance.minus(operation.value).toString()
|
|
59
|
-
);
|
|
60
|
-
},
|
|
59
|
+
maxRun: 2,
|
|
61
60
|
transaction: ({ account, siblings, bridge, maxSpendable }) => {
|
|
62
|
-
const amount = maxSpendable
|
|
63
|
-
.times(0.3 + 0.4 * Math.random())
|
|
64
|
-
.integerValue();
|
|
65
|
-
invariant(amount.gt(0), "random amount to be positive");
|
|
66
61
|
return {
|
|
67
62
|
transaction: bridge.createTransaction(account),
|
|
68
63
|
updates: [
|
|
69
64
|
{
|
|
70
|
-
recipient: pickSiblings(siblings,
|
|
65
|
+
recipient: pickSiblings(siblings, 7).freshAddress,
|
|
71
66
|
},
|
|
72
67
|
{
|
|
73
|
-
amount
|
|
68
|
+
amount: maxSpendable
|
|
69
|
+
.times(0.3 + 0.4 * Math.random())
|
|
70
|
+
.integerValue(),
|
|
74
71
|
},
|
|
75
72
|
Math.random() < 0.5
|
|
76
73
|
? {
|
|
@@ -89,7 +86,7 @@ const cosmos: AppSpec<Transaction> = {
|
|
|
89
86
|
transaction: bridge.createTransaction(account),
|
|
90
87
|
updates: [
|
|
91
88
|
{
|
|
92
|
-
recipient: pickSiblings(siblings,
|
|
89
|
+
recipient: pickSiblings(siblings, 7).freshAddress,
|
|
93
90
|
},
|
|
94
91
|
{
|
|
95
92
|
useAllAmount: true,
|
|
@@ -103,23 +100,23 @@ const cosmos: AppSpec<Transaction> = {
|
|
|
103
100
|
},
|
|
104
101
|
{
|
|
105
102
|
name: "delegate new validators",
|
|
106
|
-
maxRun:
|
|
103
|
+
maxRun: 2,
|
|
107
104
|
transaction: ({ account, bridge }) => {
|
|
108
105
|
invariant(
|
|
109
|
-
account.index %
|
|
110
|
-
"
|
|
106
|
+
account.index % 10 > 0,
|
|
107
|
+
"one out of 10 accounts is not going to delegate"
|
|
111
108
|
);
|
|
112
109
|
invariant(canDelegate(account), "can delegate");
|
|
113
110
|
const { cosmosResources } = account;
|
|
114
111
|
invariant(cosmosResources, "cosmos");
|
|
115
112
|
invariant(
|
|
116
|
-
(cosmosResources as CosmosResources).delegations.length <
|
|
113
|
+
(cosmosResources as CosmosResources).delegations.length < 10,
|
|
117
114
|
"already enough delegations"
|
|
118
115
|
);
|
|
119
116
|
const data = getCurrentCosmosPreloadData();
|
|
120
|
-
const count = 1 + Math.floor(
|
|
117
|
+
const count = 1 + Math.floor(5 * Math.random());
|
|
121
118
|
let remaining = getMaxDelegationAvailable(account, count).times(
|
|
122
|
-
|
|
119
|
+
Math.random()
|
|
123
120
|
);
|
|
124
121
|
const all = data.validators.filter(
|
|
125
122
|
(v) =>
|
|
@@ -205,12 +202,6 @@ const cosmos: AppSpec<Transaction> = {
|
|
|
205
202
|
)
|
|
206
203
|
);
|
|
207
204
|
invariant(undelegateCandidate, "already pending");
|
|
208
|
-
|
|
209
|
-
const amount = (undelegateCandidate as CosmosDelegation).amount // most of the time, undelegate all
|
|
210
|
-
.times(Math.random() > 0.3 ? 1 : Math.random())
|
|
211
|
-
.integerValue();
|
|
212
|
-
invariant(amount.gt(0), "random amount to be positive");
|
|
213
|
-
|
|
214
205
|
return {
|
|
215
206
|
transaction: bridge.createTransaction(account),
|
|
216
207
|
updates: [
|
|
@@ -223,7 +214,9 @@ const cosmos: AppSpec<Transaction> = {
|
|
|
223
214
|
{
|
|
224
215
|
address: (undelegateCandidate as CosmosDelegation)
|
|
225
216
|
.validatorAddress,
|
|
226
|
-
amount,
|
|
217
|
+
amount: (undelegateCandidate as CosmosDelegation).amount // most of the time, undelegate all
|
|
218
|
+
.times(Math.random() > 0.3 ? 1 : Math.random())
|
|
219
|
+
.integerValue(),
|
|
227
220
|
},
|
|
228
221
|
],
|
|
229
222
|
},
|
|
@@ -274,13 +267,6 @@ const cosmos: AppSpec<Transaction> = {
|
|
|
274
267
|
(sourceDelegation as CosmosDelegation).validatorAddress
|
|
275
268
|
)
|
|
276
269
|
);
|
|
277
|
-
const amount = (sourceDelegation as CosmosDelegation).amount
|
|
278
|
-
.times(
|
|
279
|
-
// most of the time redelegate all
|
|
280
|
-
Math.random() > 0.3 ? 1 : Math.random()
|
|
281
|
-
)
|
|
282
|
-
.integerValue();
|
|
283
|
-
invariant(amount.gt(0), "random amount to be positive");
|
|
284
270
|
return {
|
|
285
271
|
transaction: bridge.createTransaction(account),
|
|
286
272
|
updates: [
|
|
@@ -292,7 +278,12 @@ const cosmos: AppSpec<Transaction> = {
|
|
|
292
278
|
validators: [
|
|
293
279
|
{
|
|
294
280
|
address: (delegation as CosmosDelegation).validatorAddress,
|
|
295
|
-
amount
|
|
281
|
+
amount: (sourceDelegation as CosmosDelegation).amount
|
|
282
|
+
.times(
|
|
283
|
+
// most of the time redelegate all
|
|
284
|
+
Math.random() > 0.3 ? 1 : Math.random()
|
|
285
|
+
)
|
|
286
|
+
.integerValue(),
|
|
296
287
|
},
|
|
297
288
|
],
|
|
298
289
|
},
|
|
@@ -339,10 +330,12 @@ const cosmos: AppSpec<Transaction> = {
|
|
|
339
330
|
const { cosmosResources } = account;
|
|
340
331
|
invariant(cosmosResources, "cosmos");
|
|
341
332
|
const delegation = sample(
|
|
342
|
-
(cosmosResources as CosmosResources).delegations.filter(
|
|
343
|
-
|
|
333
|
+
(cosmosResources as CosmosResources).delegations.filter(
|
|
334
|
+
// FIXME
|
|
335
|
+
// (d) => canClaimRewards(account, d) && d.pendingRewards.gt(2000)
|
|
336
|
+
(d) => d.pendingRewards.gt(2000)
|
|
344
337
|
)
|
|
345
|
-
)
|
|
338
|
+
);
|
|
346
339
|
invariant(delegation, "no delegation to claim");
|
|
347
340
|
return {
|
|
348
341
|
transaction: bridge.createTransaction(account),
|
|
@@ -352,8 +345,13 @@ const cosmos: AppSpec<Transaction> = {
|
|
|
352
345
|
memo: "LedgerLiveBot",
|
|
353
346
|
validators: [
|
|
354
347
|
{
|
|
355
|
-
address: delegation.validatorAddress,
|
|
356
|
-
|
|
348
|
+
address: (delegation as CosmosDelegation).validatorAddress,
|
|
349
|
+
// TODO: the test should be
|
|
350
|
+
// amount: delegation.pendingRewards,
|
|
351
|
+
// but it won't work until COIN-665 is fixed until then,
|
|
352
|
+
// amount is set to 0 in
|
|
353
|
+
// src/families/cosmos/libcore-buildOperation in the REWARD case
|
|
354
|
+
amount: new BigNumber(0),
|
|
357
355
|
},
|
|
358
356
|
],
|
|
359
357
|
},
|
|
@@ -455,9 +455,9 @@ const cosmos: CurrenciesData<Transaction> = {
|
|
|
455
455
|
],
|
|
456
456
|
};
|
|
457
457
|
const dataset: DatasetTest<Transaction> = {
|
|
458
|
-
implementations: ["
|
|
458
|
+
implementations: ["libcore"],
|
|
459
459
|
currencies: {
|
|
460
|
-
cosmos,
|
|
460
|
+
// cosmos, // LL-7872
|
|
461
461
|
},
|
|
462
462
|
};
|
|
463
463
|
export default dataset;
|
|
@@ -181,8 +181,8 @@ const getRewardsState = makeLRUCache(
|
|
|
181
181
|
);
|
|
182
182
|
|
|
183
183
|
const getStargateRewardsState = makeLRUCache(
|
|
184
|
-
async (
|
|
185
|
-
|
|
184
|
+
async (_currency: CryptoCurrency) => {
|
|
185
|
+
// Fake numbers until Gaia fixes its endpoints
|
|
186
186
|
return {
|
|
187
187
|
targetBondedRatio: 0.01,
|
|
188
188
|
communityPoolCommission: 0.0,
|
|
@@ -196,102 +196,81 @@ const getStargateRewardsState = makeLRUCache(
|
|
|
196
196
|
averageDailyFees: 0,
|
|
197
197
|
currentValueInflation: 0.01,
|
|
198
198
|
};
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
parseUatomStrAsAtomNumber(ratioData.pool.bonded_tokens) / totalSupply;
|
|
275
|
-
|
|
276
|
-
// Arbitrary value in ATOM.
|
|
277
|
-
const averageDailyFees = 20;
|
|
278
|
-
|
|
279
|
-
// Arbitrary value in seconds
|
|
280
|
-
const averageTimePerBlock = 7.5;
|
|
281
|
-
|
|
282
|
-
return {
|
|
283
|
-
targetBondedRatio,
|
|
284
|
-
communityPoolCommission,
|
|
285
|
-
assumedTimePerBlock,
|
|
286
|
-
inflationRateChange,
|
|
287
|
-
inflationMaxRate,
|
|
288
|
-
inflationMinRate,
|
|
289
|
-
actualBondedRatio,
|
|
290
|
-
averageTimePerBlock,
|
|
291
|
-
totalSupply,
|
|
292
|
-
averageDailyFees,
|
|
293
|
-
currentValueInflation,
|
|
294
|
-
};
|
|
199
|
+
/*
|
|
200
|
+
// All obtained values are strings ; so sometimes we will need to parse them as numbers
|
|
201
|
+
const inflationUrl = `${getBaseApiUrl(
|
|
202
|
+
currency
|
|
203
|
+
)}/cosmos/mint/v1beta1/inflation`;
|
|
204
|
+
const { data: inflationData } = await network({
|
|
205
|
+
url: inflationUrl,
|
|
206
|
+
method: "GET",
|
|
207
|
+
});
|
|
208
|
+
const currentValueInflation = parseFloat(inflationData.inflation);
|
|
209
|
+
const inflationParametersUrl = `${getBaseApiUrl(
|
|
210
|
+
currency
|
|
211
|
+
)}/cosmos/mint/v1beta1/params`;
|
|
212
|
+
const { data: inflationParametersData } = await network({
|
|
213
|
+
url: inflationParametersUrl,
|
|
214
|
+
method: "GET",
|
|
215
|
+
});
|
|
216
|
+
const inflationRateChange = parseFloat(
|
|
217
|
+
inflationParametersData.params.inflation_rate_change
|
|
218
|
+
);
|
|
219
|
+
const inflationMaxRate = parseFloat(
|
|
220
|
+
inflationParametersData.params.inflation_max
|
|
221
|
+
);
|
|
222
|
+
const inflationMinRate = parseFloat(
|
|
223
|
+
inflationParametersData.params.inflation_min
|
|
224
|
+
);
|
|
225
|
+
const targetBondedRatio = parseFloat(
|
|
226
|
+
inflationParametersData.params.goal_bonded
|
|
227
|
+
);
|
|
228
|
+
// Source for seconds per year : https://github.com/gavinly/CosmosParametersWiki/blob/master/Mint.md#notes-3
|
|
229
|
+
// 365.24 (days) * 24 (hours) * 60 (minutes) * 60 (seconds) = 31556736 seconds
|
|
230
|
+
const assumedTimePerBlock =
|
|
231
|
+
31556736.0 / parseFloat(inflationParametersData.params.blocks_per_year);
|
|
232
|
+
const communityTaxUrl = `${getBaseApiUrl(
|
|
233
|
+
currency
|
|
234
|
+
)}/cosmos/distribution/v1beta1/params`;
|
|
235
|
+
const { data: communityTax } = await network({
|
|
236
|
+
url: communityTaxUrl,
|
|
237
|
+
method: "GET",
|
|
238
|
+
});
|
|
239
|
+
const communityPoolCommission = parseFloat(
|
|
240
|
+
communityTax.params.community_tax
|
|
241
|
+
);
|
|
242
|
+
const supplyUrl = `${getBaseApiUrl(currency)}/cosmos/bank/v1beta1/supply/${
|
|
243
|
+
currency.id == "cosmos_testnet" ? "umuon" : "uatom"
|
|
244
|
+
}`;
|
|
245
|
+
const { data: totalSupplyData } = await network({
|
|
246
|
+
url: supplyUrl,
|
|
247
|
+
method: "GET",
|
|
248
|
+
});
|
|
249
|
+
const totalSupply = parseUatomStrAsAtomNumber(
|
|
250
|
+
totalSupplyData.amount.amount
|
|
251
|
+
);
|
|
252
|
+
const ratioUrl = `${getBaseApiUrl(currency)}/cosmos/staking/v1beta1/pool`;
|
|
253
|
+
const { data: ratioData } = await network({ url: ratioUrl, method: "GET" });
|
|
254
|
+
const actualBondedRatio =
|
|
255
|
+
parseUatomStrAsAtomNumber(ratioData.pool.bonded_tokens) / totalSupply;
|
|
256
|
+
// Arbitrary value in ATOM.
|
|
257
|
+
const averageDailyFees = 20;
|
|
258
|
+
// Arbitrary value in seconds
|
|
259
|
+
const averageTimePerBlock = 7.5;
|
|
260
|
+
return {
|
|
261
|
+
targetBondedRatio,
|
|
262
|
+
communityPoolCommission,
|
|
263
|
+
assumedTimePerBlock,
|
|
264
|
+
inflationRateChange,
|
|
265
|
+
inflationMaxRate,
|
|
266
|
+
inflationMinRate,
|
|
267
|
+
actualBondedRatio,
|
|
268
|
+
averageTimePerBlock,
|
|
269
|
+
totalSupply,
|
|
270
|
+
averageDailyFees,
|
|
271
|
+
currentValueInflation,
|
|
272
|
+
};
|
|
273
|
+
*/
|
|
295
274
|
},
|
|
296
275
|
(currency: CryptoCurrency) => currency.id
|
|
297
276
|
);
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
|
|
3
|
+
export function fromOperationExtraRaw(
|
|
4
|
+
extra: Record<string, any> | null | undefined
|
|
5
|
+
): Record<string, any> | null | undefined {
|
|
6
|
+
if (!extra) return extra;
|
|
7
|
+
|
|
8
|
+
const { gasLimit, gasPremium, gasFeeCap } = extra;
|
|
9
|
+
|
|
10
|
+
if (gasLimit !== undefined)
|
|
11
|
+
extra = { ...extra, gasLimit: new BigNumber(gasLimit) };
|
|
12
|
+
|
|
13
|
+
if (gasPremium !== undefined)
|
|
14
|
+
extra = { ...extra, gasPremium: new BigNumber(gasPremium) };
|
|
15
|
+
|
|
16
|
+
if (gasFeeCap !== undefined)
|
|
17
|
+
extra = { ...extra, gasFeeCap: new BigNumber(gasFeeCap) };
|
|
18
|
+
|
|
19
|
+
return extra;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function toOperationExtraRaw(
|
|
23
|
+
extra: Record<string, any> | null | undefined
|
|
24
|
+
): Record<string, any> | null | undefined {
|
|
25
|
+
if (!extra) return extra;
|
|
26
|
+
|
|
27
|
+
const { gasLimit, gasPremium, gasFeeCap } = extra;
|
|
28
|
+
|
|
29
|
+
if (gasLimit !== undefined)
|
|
30
|
+
extra = { ...extra, gasLimit: gasLimit.toNumber() };
|
|
31
|
+
|
|
32
|
+
if (gasPremium !== undefined)
|
|
33
|
+
extra = { ...extra, gasPremium: gasPremium.toFixed() };
|
|
34
|
+
|
|
35
|
+
if (gasFeeCap !== undefined)
|
|
36
|
+
extra = { ...extra, gasFeeCap: gasFeeCap.toFixed() };
|
|
37
|
+
|
|
38
|
+
return extra;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default {
|
|
42
|
+
fromOperationExtraRaw,
|
|
43
|
+
toOperationExtraRaw,
|
|
44
|
+
};
|
|
@@ -66,8 +66,10 @@ const getTransactionStatus = async (
|
|
|
66
66
|
const errors: TransactionStatus["errors"] = {};
|
|
67
67
|
const warnings: TransactionStatus["warnings"] = {};
|
|
68
68
|
|
|
69
|
+
const { balance } = a;
|
|
69
70
|
const { address } = getAddress(a);
|
|
70
|
-
const { recipient,
|
|
71
|
+
const { recipient, useAllAmount, gasPremium, gasFeeCap, gasLimit } = t;
|
|
72
|
+
let { amount } = t;
|
|
71
73
|
|
|
72
74
|
if (!recipient) errors.recipient = new RecipientRequired();
|
|
73
75
|
else if (!validateAddress(recipient).isValid)
|
|
@@ -81,8 +83,8 @@ const getTransactionStatus = async (
|
|
|
81
83
|
// This is the worst case scenario (the tx won't cost more than this value)
|
|
82
84
|
const estimatedFees = calculateEstimatedFees(gasFeeCap, gasLimit);
|
|
83
85
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
+
const totalSpent = useAllAmount ? balance : amount.plus(estimatedFees);
|
|
87
|
+
amount = useAllAmount ? balance.minus(estimatedFees) : amount;
|
|
86
88
|
|
|
87
89
|
if (amount.lte(0)) errors.amount = new AmountRequired();
|
|
88
90
|
if (totalSpent.gt(a.spendableBalance)) errors.amount = new NotEnoughBalance();
|
|
@@ -174,11 +176,13 @@ const prepareTransaction = async (
|
|
|
174
176
|
const sync = makeSync(getAccountShape);
|
|
175
177
|
|
|
176
178
|
const broadcast: BroadcastFnSignature = async ({
|
|
177
|
-
signedOperation: { operation },
|
|
179
|
+
signedOperation: { operation, signature },
|
|
178
180
|
}) => {
|
|
179
181
|
// log("debug", "[broadcast] start fn");
|
|
180
182
|
|
|
181
|
-
const
|
|
183
|
+
const tx = getTxToBroadcast(operation, signature);
|
|
184
|
+
|
|
185
|
+
const resp = await broadcastTx(tx);
|
|
182
186
|
const { hash } = resp;
|
|
183
187
|
|
|
184
188
|
const result = patchOperationWithHash(operation, hash);
|
|
@@ -199,8 +203,18 @@ const signOperation: SignOperationFnSignature<Transaction> = ({
|
|
|
199
203
|
async function main() {
|
|
200
204
|
// log("debug", "[signOperation] start fn");
|
|
201
205
|
|
|
202
|
-
const {
|
|
203
|
-
|
|
206
|
+
const {
|
|
207
|
+
recipient,
|
|
208
|
+
method,
|
|
209
|
+
version,
|
|
210
|
+
nonce,
|
|
211
|
+
gasFeeCap,
|
|
212
|
+
gasLimit,
|
|
213
|
+
gasPremium,
|
|
214
|
+
useAllAmount,
|
|
215
|
+
} = transaction;
|
|
216
|
+
let { amount } = transaction;
|
|
217
|
+
const { id: accountId, balance } = account;
|
|
204
218
|
const { address, derivationPath } = getAddress(account);
|
|
205
219
|
|
|
206
220
|
if (!gasFeeCap.gt(0) || !gasLimit.gt(0)) {
|
|
@@ -218,6 +232,11 @@ const signOperation: SignOperationFnSignature<Transaction> = ({
|
|
|
218
232
|
type: "device-signature-requested",
|
|
219
233
|
});
|
|
220
234
|
|
|
235
|
+
const fee = calculateEstimatedFees(gasFeeCap, gasLimit);
|
|
236
|
+
if (useAllAmount) amount = balance.minus(fee);
|
|
237
|
+
|
|
238
|
+
transaction = { ...transaction, amount };
|
|
239
|
+
|
|
221
240
|
// Serialize tx
|
|
222
241
|
const serializedTx = toCBOR(
|
|
223
242
|
getAddressRaw(address),
|
|
@@ -243,21 +262,12 @@ const signOperation: SignOperationFnSignature<Transaction> = ({
|
|
|
243
262
|
type: "device-signature-granted",
|
|
244
263
|
});
|
|
245
264
|
|
|
246
|
-
const fee = calculateEstimatedFees(gasFeeCap, gasLimit);
|
|
247
|
-
const value = amount.plus(fee);
|
|
248
|
-
|
|
249
265
|
// resolved at broadcast time
|
|
250
266
|
const txHash = "";
|
|
251
267
|
|
|
252
268
|
// build signature on the correct format
|
|
253
269
|
const signature = `${result.signature_compact.toString("base64")}`;
|
|
254
270
|
|
|
255
|
-
const reqToBroadcast = getTxToBroadcast(
|
|
256
|
-
account,
|
|
257
|
-
transaction,
|
|
258
|
-
signature
|
|
259
|
-
);
|
|
260
|
-
|
|
261
271
|
const operation: Operation = {
|
|
262
272
|
id: `${accountId}-${txHash}-OUT`,
|
|
263
273
|
hash: txHash,
|
|
@@ -265,13 +275,19 @@ const signOperation: SignOperationFnSignature<Transaction> = ({
|
|
|
265
275
|
senders: [address],
|
|
266
276
|
recipients: [recipient],
|
|
267
277
|
accountId,
|
|
268
|
-
value,
|
|
278
|
+
value: amount,
|
|
269
279
|
fee,
|
|
270
280
|
blockHash: null,
|
|
271
281
|
blockHeight: null,
|
|
272
282
|
date: new Date(),
|
|
273
283
|
extra: {
|
|
274
|
-
|
|
284
|
+
gasLimit,
|
|
285
|
+
gasFeeCap,
|
|
286
|
+
gasPremium,
|
|
287
|
+
method,
|
|
288
|
+
version,
|
|
289
|
+
nonce,
|
|
290
|
+
signatureType: 1,
|
|
275
291
|
},
|
|
276
292
|
};
|
|
277
293
|
|
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
import { fetchBalances, fetchBlockHeight, fetchTxs } from "./api";
|
|
13
13
|
import { encodeAccountId } from "../../../../account";
|
|
14
14
|
import flatMap from "lodash/flatMap";
|
|
15
|
-
import { Transaction } from "../../types";
|
|
16
15
|
|
|
17
16
|
type TxsById = {
|
|
18
17
|
[id: string]: {
|
|
@@ -103,21 +102,19 @@ export const getAddress = (a: Account): Address =>
|
|
|
103
102
|
: { address: a.freshAddress, derivationPath: a.freshAddressPath };
|
|
104
103
|
|
|
105
104
|
export const getTxToBroadcast = (
|
|
106
|
-
|
|
107
|
-
transaction: Transaction,
|
|
105
|
+
operation: Operation,
|
|
108
106
|
signature: string
|
|
109
107
|
): BroadcastTransactionRequest => {
|
|
110
|
-
const {
|
|
108
|
+
const { extra, senders, recipients, value } = operation;
|
|
111
109
|
const {
|
|
112
|
-
recipient,
|
|
113
|
-
amount,
|
|
114
110
|
gasLimit,
|
|
115
111
|
gasFeeCap,
|
|
116
112
|
gasPremium,
|
|
117
113
|
method,
|
|
118
114
|
version,
|
|
119
115
|
nonce,
|
|
120
|
-
|
|
116
|
+
signatureType,
|
|
117
|
+
} = extra;
|
|
121
118
|
|
|
122
119
|
return {
|
|
123
120
|
message: {
|
|
@@ -125,15 +122,15 @@ export const getTxToBroadcast = (
|
|
|
125
122
|
method,
|
|
126
123
|
nonce,
|
|
127
124
|
params: "",
|
|
128
|
-
to:
|
|
129
|
-
from:
|
|
125
|
+
to: recipients[0],
|
|
126
|
+
from: senders[0],
|
|
130
127
|
gaslimit: gasLimit.toNumber(),
|
|
131
128
|
gaspremium: gasPremium.toString(),
|
|
132
129
|
gasfeecap: gasFeeCap.toString(),
|
|
133
|
-
value:
|
|
130
|
+
value: value.toFixed(),
|
|
134
131
|
},
|
|
135
132
|
signature: {
|
|
136
|
-
type:
|
|
133
|
+
type: signatureType,
|
|
137
134
|
data: signature,
|
|
138
135
|
},
|
|
139
136
|
};
|