@ledgerhq/live-common 27.0.1-next.0 → 27.1.0-next.2
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/serialization.d.ts +2 -0
- package/lib/account/serialization.d.ts.map +1 -1
- package/lib/account/serialization.js +23 -8
- package/lib/account/serialization.js.map +1 -1
- package/lib/api/explorerConfig/index.js +1 -1
- package/lib/api/explorerConfig/index.js.map +1 -1
- package/lib/apps/support.d.ts.map +1 -1
- package/lib/apps/support.js +1 -0
- package/lib/apps/support.js.map +1 -1
- package/lib/families/celo/api/hubble.d.ts +6 -1
- package/lib/families/celo/api/hubble.d.ts.map +1 -1
- package/lib/families/celo/api/hubble.js +135 -13
- package/lib/families/celo/api/hubble.js.map +1 -1
- package/lib/families/celo/api/index.d.ts +1 -1
- package/lib/families/celo/api/index.d.ts.map +1 -1
- package/lib/families/celo/api/index.js +2 -1
- package/lib/families/celo/api/index.js.map +1 -1
- package/lib/families/celo/api/sdk.d.ts +22 -0
- package/lib/families/celo/api/sdk.d.ts.map +1 -1
- package/lib/families/celo/api/sdk.js +168 -1
- package/lib/families/celo/api/sdk.js.map +1 -1
- package/lib/families/celo/bridge/js.d.ts.map +1 -1
- package/lib/families/celo/bridge/js.js +4 -42
- package/lib/families/celo/bridge/js.js.map +1 -1
- package/lib/families/celo/cli-transaction.d.ts +12 -2
- package/lib/families/celo/cli-transaction.d.ts.map +1 -1
- package/lib/families/celo/cli-transaction.js +38 -4
- package/lib/families/celo/cli-transaction.js.map +1 -1
- package/lib/families/celo/datasets/celo.scanAccounts.1.d.ts +1 -0
- package/lib/families/celo/datasets/celo.scanAccounts.1.d.ts.map +1 -1
- package/lib/families/celo/datasets/celo.scanAccounts.1.js +298 -2
- package/lib/families/celo/datasets/celo.scanAccounts.1.js.map +1 -1
- package/lib/families/celo/errors.d.ts +2 -0
- package/lib/families/celo/errors.d.ts.map +1 -0
- package/lib/families/celo/errors.js +6 -0
- package/lib/families/celo/errors.js.map +1 -0
- package/lib/families/celo/js-buildTransaction.d.ts +2 -3
- package/lib/families/celo/js-buildTransaction.d.ts.map +1 -1
- package/lib/families/celo/js-buildTransaction.js +194 -19
- package/lib/families/celo/js-buildTransaction.js.map +1 -1
- package/lib/families/celo/js-createTransaction.d.ts.map +1 -1
- package/lib/families/celo/js-createTransaction.js +3 -1
- package/lib/families/celo/js-createTransaction.js.map +1 -1
- package/lib/families/celo/js-estimateMaxSpendable.d.ts.map +1 -1
- package/lib/families/celo/js-estimateMaxSpendable.js.map +1 -1
- package/lib/families/celo/js-getFeesForTransaction.d.ts +2 -3
- package/lib/families/celo/js-getFeesForTransaction.d.ts.map +1 -1
- package/lib/families/celo/js-getFeesForTransaction.js +137 -10
- package/lib/families/celo/js-getFeesForTransaction.js.map +1 -1
- package/lib/families/celo/js-getTransactionStatus.d.ts +2 -3
- package/lib/families/celo/js-getTransactionStatus.d.ts.map +1 -1
- package/lib/families/celo/js-getTransactionStatus.js +97 -41
- package/lib/families/celo/js-getTransactionStatus.js.map +1 -1
- package/lib/families/celo/js-prepareTransaction.d.ts +2 -3
- package/lib/families/celo/js-prepareTransaction.d.ts.map +1 -1
- package/lib/families/celo/js-prepareTransaction.js +8 -3
- package/lib/families/celo/js-prepareTransaction.js.map +1 -1
- package/lib/families/celo/js-signOperation.d.ts.map +1 -1
- package/lib/families/celo/js-signOperation.js +17 -3
- package/lib/families/celo/js-signOperation.js.map +1 -1
- package/lib/families/celo/js-synchronisation.d.ts.map +1 -1
- package/lib/families/celo/js-synchronisation.js +51 -6
- package/lib/families/celo/js-synchronisation.js.map +1 -1
- package/lib/families/celo/logic.d.ts +21 -0
- package/lib/families/celo/logic.d.ts.map +1 -0
- package/lib/families/celo/logic.js +132 -0
- package/lib/families/celo/logic.js.map +1 -0
- package/lib/families/celo/preload.d.ts +10 -0
- package/lib/families/celo/preload.d.ts.map +1 -0
- package/lib/families/celo/preload.js +118 -0
- package/lib/families/celo/preload.js.map +1 -0
- package/lib/families/celo/react.d.ts +4 -0
- package/lib/families/celo/react.d.ts.map +1 -0
- package/lib/families/celo/react.js +47 -0
- package/lib/families/celo/react.js.map +1 -0
- package/lib/families/celo/serialization.d.ts +4 -0
- package/lib/families/celo/serialization.d.ts.map +1 -0
- package/lib/families/celo/serialization.js +55 -0
- package/lib/families/celo/serialization.js.map +1 -0
- package/lib/families/celo/specs/createActivateVoteMutation.d.ts +4 -0
- package/lib/families/celo/specs/createActivateVoteMutation.d.ts.map +1 -0
- package/lib/families/celo/specs/createActivateVoteMutation.js +38 -0
- package/lib/families/celo/specs/createActivateVoteMutation.js.map +1 -0
- package/lib/families/celo/specs/createLockMutation.d.ts +4 -0
- package/lib/families/celo/specs/createLockMutation.d.ts.map +1 -0
- package/lib/families/celo/specs/createLockMutation.js +40 -0
- package/lib/families/celo/specs/createLockMutation.js.map +1 -0
- package/lib/families/celo/specs/createRegisterAccountMutation.d.ts +4 -0
- package/lib/families/celo/specs/createRegisterAccountMutation.d.ts.map +1 -0
- package/lib/families/celo/specs/createRegisterAccountMutation.js +31 -0
- package/lib/families/celo/specs/createRegisterAccountMutation.js.map +1 -0
- package/lib/families/celo/specs/createRevokeVoteMutation.d.ts +4 -0
- package/lib/families/celo/specs/createRevokeVoteMutation.d.ts.map +1 -0
- package/lib/families/celo/specs/createRevokeVoteMutation.js +39 -0
- package/lib/families/celo/specs/createRevokeVoteMutation.js.map +1 -0
- package/lib/families/celo/specs/createSendMutation.d.ts +5 -0
- package/lib/families/celo/specs/createSendMutation.d.ts.map +1 -0
- package/lib/families/celo/specs/createSendMutation.js +44 -0
- package/lib/families/celo/specs/createSendMutation.js.map +1 -0
- package/lib/families/celo/specs/createUnlockMutation.d.ts +4 -0
- package/lib/families/celo/specs/createUnlockMutation.d.ts.map +1 -0
- package/lib/families/celo/specs/createUnlockMutation.js +37 -0
- package/lib/families/celo/specs/createUnlockMutation.js.map +1 -0
- package/lib/families/celo/specs/createVoteMutation.d.ts +4 -0
- package/lib/families/celo/specs/createVoteMutation.d.ts.map +1 -0
- package/lib/families/celo/specs/createVoteMutation.js +51 -0
- package/lib/families/celo/specs/createVoteMutation.js.map +1 -0
- package/lib/families/celo/specs/createWithdrawMutation.d.ts +4 -0
- package/lib/families/celo/specs/createWithdrawMutation.d.ts.map +1 -0
- package/lib/families/celo/specs/createWithdrawMutation.js +36 -0
- package/lib/families/celo/specs/createWithdrawMutation.js.map +1 -0
- package/lib/families/celo/specs/index.d.ts +9 -0
- package/lib/families/celo/specs/index.d.ts.map +1 -0
- package/lib/families/celo/specs/index.js +25 -0
- package/lib/families/celo/specs/index.js.map +1 -0
- package/lib/families/celo/specs.d.ts +1 -1
- package/lib/families/celo/specs.d.ts.map +1 -1
- package/lib/families/celo/specs.js +20 -37
- package/lib/families/celo/specs.js.map +1 -1
- package/lib/families/celo/speculos-deviceActions.d.ts.map +1 -1
- package/lib/families/celo/speculos-deviceActions.js +22 -0
- package/lib/families/celo/speculos-deviceActions.js.map +1 -1
- package/lib/families/celo/transaction.d.ts.map +1 -1
- package/lib/families/celo/transaction.js +8 -6
- package/lib/families/celo/transaction.js.map +1 -1
- package/lib/families/celo/types.d.ts +102 -1
- package/lib/families/celo/types.d.ts.map +1 -1
- package/lib/families/celo/validators.d.ts +3 -0
- package/lib/families/celo/validators.d.ts.map +1 -0
- package/lib/families/celo/validators.js +6 -0
- package/lib/families/celo/validators.js.map +1 -0
- package/lib/families/cosmos/banner.d.ts +10 -0
- package/lib/families/cosmos/banner.d.ts.map +1 -0
- package/lib/families/cosmos/banner.js +133 -0
- package/lib/families/cosmos/banner.js.map +1 -0
- package/lib/families/cosmos/banner.test.d.ts +2 -0
- package/lib/families/cosmos/banner.test.d.ts.map +1 -0
- package/lib/families/cosmos/banner.test.js +233 -0
- package/lib/families/cosmos/banner.test.js.map +1 -0
- package/lib/families/solana/api/chain/instruction/token/types.d.ts +2 -2
- package/lib/generated/cli-transaction.d.ts +12 -2
- package/lib/generated/cli-transaction.d.ts.map +1 -1
- package/lib/operation.d.ts.map +1 -1
- package/lib/operation.js +6 -0
- package/lib/operation.js.map +1 -1
- package/lib/reconciliation.d.ts.map +1 -1
- package/lib/reconciliation.js +11 -0
- package/lib/reconciliation.js.map +1 -1
- package/package.json +3 -4
- package/src/account/serialization.ts +22 -2
- package/src/api/explorerConfig/index.ts +1 -1
- package/src/apps/support.ts +1 -0
- package/src/families/celo/__snapshots__/bridge.integration.test.ts.snap +134 -857
- package/src/families/celo/api/hubble.ts +113 -16
- package/src/families/celo/api/index.ts +1 -1
- package/src/families/celo/api/sdk.ts +88 -0
- package/src/families/celo/bridge/js.ts +2 -3
- package/src/families/celo/cli-transaction.ts +46 -2
- package/src/families/celo/datasets/celo.scanAccounts.1.ts +365 -5
- package/src/families/celo/errors.ts +5 -0
- package/src/families/celo/js-buildTransaction.ts +173 -20
- package/src/families/celo/js-createTransaction.ts +2 -0
- package/src/families/celo/js-estimateMaxSpendable.ts +2 -2
- package/src/families/celo/js-getFeesForTransaction.ts +118 -19
- package/src/families/celo/js-getTransactionStatus.ts +72 -17
- package/src/families/celo/js-prepareTransaction.ts +13 -7
- package/src/families/celo/js-signOperation.ts +22 -5
- package/src/families/celo/js-synchronisation.ts +32 -0
- package/src/families/celo/logic.ts +184 -0
- package/src/families/celo/preload.ts +78 -0
- package/src/families/celo/react.ts +35 -0
- package/src/families/celo/serialization.ts +61 -0
- package/src/families/celo/specs/createActivateVoteMutation.ts +44 -0
- package/src/families/celo/specs/createLockMutation.ts +46 -0
- package/src/families/celo/specs/createRegisterAccountMutation.ts +34 -0
- package/src/families/celo/specs/createRevokeVoteMutation.ts +43 -0
- package/src/families/celo/specs/createSendMutation.ts +44 -0
- package/src/families/celo/specs/createUnlockMutation.ts +44 -0
- package/src/families/celo/specs/createVoteMutation.ts +67 -0
- package/src/families/celo/specs/createWithdrawMutation.ts +44 -0
- package/src/families/celo/specs/index.ts +8 -0
- package/src/families/celo/specs.ts +32 -34
- package/src/families/celo/speculos-deviceActions.ts +21 -2
- package/src/families/celo/transaction.ts +12 -4
- package/src/families/celo/types.ts +113 -0
- package/src/families/celo/validators.ts +2 -0
- package/src/families/cosmos/banner.test.ts +160 -0
- package/src/families/cosmos/banner.ts +87 -0
- package/src/operation.ts +6 -0
- package/src/reconciliation.ts +22 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { BigNumber } from "bignumber.js";
|
|
2
|
+
import { Observable, Subject } from "rxjs";
|
|
3
|
+
import { log } from "@ledgerhq/logs";
|
|
4
|
+
import { PRELOAD_MAX_AGE } from "./logic";
|
|
5
|
+
import type { CeloPreloadData, CeloValidatorGroup } from "./types";
|
|
6
|
+
import { getValidatorGroups } from "./validators";
|
|
7
|
+
|
|
8
|
+
let currentCeloPreloadedData: CeloPreloadData = {
|
|
9
|
+
validatorGroups: [],
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function fromHydrateValidator(
|
|
13
|
+
validatorGroupRaw: Record<string, any>
|
|
14
|
+
): CeloValidatorGroup {
|
|
15
|
+
return {
|
|
16
|
+
address: validatorGroupRaw.address,
|
|
17
|
+
name: validatorGroupRaw.name,
|
|
18
|
+
votes: new BigNumber(validatorGroupRaw.votes),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function fromHydratePreloadData(data: any): CeloPreloadData {
|
|
23
|
+
let validatorGroups = [];
|
|
24
|
+
if (typeof data === "object" && data) {
|
|
25
|
+
if (Array.isArray(data.validatorGroups)) {
|
|
26
|
+
validatorGroups = data.validatorGroups.map(fromHydrateValidator);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
validatorGroups,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const updates = new Subject<CeloPreloadData>();
|
|
36
|
+
export function getCurrentCeloPreloadData(): CeloPreloadData {
|
|
37
|
+
return currentCeloPreloadedData;
|
|
38
|
+
}
|
|
39
|
+
function setCeloPreloadData(data: CeloPreloadData) {
|
|
40
|
+
if (data === currentCeloPreloadedData) return;
|
|
41
|
+
currentCeloPreloadedData = data;
|
|
42
|
+
updates.next(data);
|
|
43
|
+
}
|
|
44
|
+
export function getCeloPreloadDataUpdates(): Observable<CeloPreloadData> {
|
|
45
|
+
return updates.asObservable();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const getPreloadStrategy = () => ({
|
|
49
|
+
preloadMaxAge: PRELOAD_MAX_AGE,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
export const preload = async (): Promise<CeloPreloadData> => {
|
|
53
|
+
const { validatorGroups: previousValidatorGroups } = currentCeloPreloadedData;
|
|
54
|
+
let validatorGroups = previousValidatorGroups;
|
|
55
|
+
|
|
56
|
+
if (!validatorGroups || !validatorGroups.length) {
|
|
57
|
+
log("celo/preload", "refreshing celo validatorGroups...");
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
validatorGroups = await getValidatorGroups();
|
|
61
|
+
} catch (error) {
|
|
62
|
+
log("celo/preload", "failed to fetch validatorGroups", {
|
|
63
|
+
error,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { validatorGroups };
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export const hydrate = (data: unknown) => {
|
|
72
|
+
const hydrated = fromHydratePreloadData(data);
|
|
73
|
+
log(
|
|
74
|
+
"celo/preload",
|
|
75
|
+
"hydrate " + hydrated.validatorGroups.length + " celo validatorGroups"
|
|
76
|
+
);
|
|
77
|
+
setCeloPreloadData(hydrated);
|
|
78
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useState, useEffect, useMemo } from "react";
|
|
2
|
+
import {
|
|
3
|
+
getCurrentCeloPreloadData,
|
|
4
|
+
getCeloPreloadDataUpdates,
|
|
5
|
+
} from "./preload";
|
|
6
|
+
import type { CeloPreloadData, CeloValidatorGroup } from "./types";
|
|
7
|
+
|
|
8
|
+
export function useCeloPreloadData(): CeloPreloadData {
|
|
9
|
+
const [state, setState] = useState(getCurrentCeloPreloadData);
|
|
10
|
+
useEffect(() => {
|
|
11
|
+
const sub = getCeloPreloadDataUpdates().subscribe((data) => {
|
|
12
|
+
setState(data);
|
|
13
|
+
});
|
|
14
|
+
return () => sub.unsubscribe();
|
|
15
|
+
}, []);
|
|
16
|
+
return state;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function useValidatorGroups(search: string): CeloValidatorGroup[] {
|
|
20
|
+
const { validatorGroups } = useCeloPreloadData();
|
|
21
|
+
|
|
22
|
+
return useMemo(() => {
|
|
23
|
+
if (validatorGroups.length === 0 || !search) {
|
|
24
|
+
return validatorGroups;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const lowercaseSearch = search.toLowerCase();
|
|
28
|
+
|
|
29
|
+
return validatorGroups.filter(
|
|
30
|
+
(vg) =>
|
|
31
|
+
vg.name.toLowerCase().includes(lowercaseSearch) ||
|
|
32
|
+
vg.address.toLowerCase().includes(lowercaseSearch)
|
|
33
|
+
);
|
|
34
|
+
}, [validatorGroups, search]);
|
|
35
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
import type { CeloResources, CeloResourcesRaw } from "./types";
|
|
3
|
+
import { BigNumber } from "bignumber.js";
|
|
4
|
+
|
|
5
|
+
export function toCeloResourcesRaw(r: CeloResources): CeloResourcesRaw {
|
|
6
|
+
const {
|
|
7
|
+
registrationStatus,
|
|
8
|
+
lockedBalance,
|
|
9
|
+
nonvotingLockedBalance,
|
|
10
|
+
pendingWithdrawals,
|
|
11
|
+
votes,
|
|
12
|
+
electionAddress,
|
|
13
|
+
lockedGoldAddress,
|
|
14
|
+
maxNumGroupsVotedFor,
|
|
15
|
+
} = r ?? {};
|
|
16
|
+
return {
|
|
17
|
+
registrationStatus,
|
|
18
|
+
lockedBalance: lockedBalance?.toString(),
|
|
19
|
+
nonvotingLockedBalance: nonvotingLockedBalance?.toString(),
|
|
20
|
+
pendingWithdrawals: pendingWithdrawals?.map((withdrawal) => ({
|
|
21
|
+
value: withdrawal.value.toString(),
|
|
22
|
+
time: withdrawal.time.toString(),
|
|
23
|
+
index: withdrawal.index.toString(),
|
|
24
|
+
})),
|
|
25
|
+
votes: votes?.map((vote) => ({
|
|
26
|
+
validatorGroup: vote.validatorGroup.toString(),
|
|
27
|
+
amount: vote.amount.toString(),
|
|
28
|
+
activatable: vote.activatable,
|
|
29
|
+
revokable: vote.revokable,
|
|
30
|
+
type: vote.type,
|
|
31
|
+
index: vote.index,
|
|
32
|
+
})),
|
|
33
|
+
electionAddress,
|
|
34
|
+
lockedGoldAddress,
|
|
35
|
+
maxNumGroupsVotedFor: maxNumGroupsVotedFor?.toString(),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function fromCeloResourcesRaw(r: CeloResourcesRaw): CeloResources {
|
|
40
|
+
return {
|
|
41
|
+
registrationStatus: r.registrationStatus,
|
|
42
|
+
lockedBalance: new BigNumber(r.lockedBalance),
|
|
43
|
+
nonvotingLockedBalance: new BigNumber(r.nonvotingLockedBalance),
|
|
44
|
+
pendingWithdrawals: r.pendingWithdrawals?.map((u) => ({
|
|
45
|
+
value: new BigNumber(u.value),
|
|
46
|
+
time: new BigNumber(u.time),
|
|
47
|
+
index: Number(u.index),
|
|
48
|
+
})),
|
|
49
|
+
votes: r.votes?.map((vote) => ({
|
|
50
|
+
validatorGroup: vote.validatorGroup,
|
|
51
|
+
amount: new BigNumber(vote.amount),
|
|
52
|
+
activatable: vote.activatable,
|
|
53
|
+
revokable: vote.revokable,
|
|
54
|
+
type: vote.type,
|
|
55
|
+
index: vote.index,
|
|
56
|
+
})),
|
|
57
|
+
electionAddress: r.electionAddress,
|
|
58
|
+
lockedGoldAddress: r.lockedGoldAddress,
|
|
59
|
+
maxNumGroupsVotedFor: new BigNumber(r.maxNumGroupsVotedFor),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById, parseCurrencyUnit } from "../../../currencies";
|
|
3
|
+
import { MutationSpec } from "../../../bot/types";
|
|
4
|
+
import type { CeloAccount, Transaction } from "../types";
|
|
5
|
+
|
|
6
|
+
const currency = getCryptoCurrencyById("celo");
|
|
7
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
8
|
+
|
|
9
|
+
export const createActivateVoteMutation = (): MutationSpec<Transaction> => ({
|
|
10
|
+
name: "Celo: Activate Vote",
|
|
11
|
+
maxRun: 5,
|
|
12
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
13
|
+
const { celoResources } = account as CeloAccount;
|
|
14
|
+
invariant(
|
|
15
|
+
celoResources?.registrationStatus,
|
|
16
|
+
"Celo: Activate Vote | Account is not registered"
|
|
17
|
+
);
|
|
18
|
+
invariant(
|
|
19
|
+
maxSpendable.gt(minimalAmount),
|
|
20
|
+
"Celo: Activate Vote | balance is too low"
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const activatableVote = celoResources?.votes?.find(
|
|
24
|
+
(vote) => vote.activatable
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
invariant(!!activatableVote, "Celo: Activate Vote | No activatable votes");
|
|
28
|
+
|
|
29
|
+
const transaction = {
|
|
30
|
+
recipient: activatableVote!.validatorGroup,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
transaction: bridge.createTransaction(account),
|
|
35
|
+
updates: [
|
|
36
|
+
{
|
|
37
|
+
memo: "LedgerLiveBot",
|
|
38
|
+
mode: "activate",
|
|
39
|
+
},
|
|
40
|
+
transaction,
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById, parseCurrencyUnit } from "../../../currencies";
|
|
3
|
+
import { MutationSpec } from "../../../bot/types";
|
|
4
|
+
import type { CeloAccount, Transaction } from "../types";
|
|
5
|
+
|
|
6
|
+
const currency = getCryptoCurrencyById("celo");
|
|
7
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.005");
|
|
8
|
+
|
|
9
|
+
export const createLockMutation = (): MutationSpec<Transaction> => ({
|
|
10
|
+
name: "Celo: Lock",
|
|
11
|
+
maxRun: 1,
|
|
12
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
13
|
+
const { celoResources } = account as CeloAccount;
|
|
14
|
+
invariant(
|
|
15
|
+
celoResources?.registrationStatus,
|
|
16
|
+
"Celo: Lock Vote | Account is not registered"
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
invariant(
|
|
20
|
+
maxSpendable.gt(minimalAmount),
|
|
21
|
+
"Celo: Lock | balance is too low"
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const amount = minimalAmount
|
|
25
|
+
.times(Math.random())
|
|
26
|
+
.integerValue()
|
|
27
|
+
.precision(8);
|
|
28
|
+
|
|
29
|
+
invariant(amount.gt(0), "Celo: Lock | Not enough funds to lock tokens");
|
|
30
|
+
|
|
31
|
+
const transaction = {
|
|
32
|
+
amount,
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
transaction: bridge.createTransaction(account),
|
|
37
|
+
updates: [
|
|
38
|
+
{
|
|
39
|
+
memo: "LedgerLiveBot",
|
|
40
|
+
mode: "lock",
|
|
41
|
+
},
|
|
42
|
+
transaction,
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById, parseCurrencyUnit } from "../../../currencies";
|
|
3
|
+
import { MutationSpec } from "../../../bot/types";
|
|
4
|
+
import type { CeloAccount, Transaction } from "../types";
|
|
5
|
+
|
|
6
|
+
const currency = getCryptoCurrencyById("celo");
|
|
7
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
8
|
+
|
|
9
|
+
export const createRegisterAccountMutation = (): MutationSpec<Transaction> => ({
|
|
10
|
+
name: "Celo: Register Account",
|
|
11
|
+
maxRun: 1,
|
|
12
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
13
|
+
const { celoResources } = account as CeloAccount;
|
|
14
|
+
|
|
15
|
+
invariant(
|
|
16
|
+
!celoResources?.registrationStatus,
|
|
17
|
+
"Celo: Register Account | Celo account is already registered"
|
|
18
|
+
);
|
|
19
|
+
invariant(
|
|
20
|
+
maxSpendable.gt(minimalAmount),
|
|
21
|
+
"Celo: Register Account | Celo account balance is too low to register account"
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
transaction: bridge.createTransaction(account),
|
|
26
|
+
updates: [
|
|
27
|
+
{
|
|
28
|
+
memo: "LedgerLiveBot",
|
|
29
|
+
mode: "register",
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
},
|
|
34
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById, parseCurrencyUnit } from "../../../currencies";
|
|
3
|
+
import { MutationSpec } from "../../../bot/types";
|
|
4
|
+
import type { CeloAccount, Transaction } from "../types";
|
|
5
|
+
|
|
6
|
+
const currency = getCryptoCurrencyById("celo");
|
|
7
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
8
|
+
|
|
9
|
+
export const createRevokeVoteMutation = (): MutationSpec<Transaction> => ({
|
|
10
|
+
name: "Celo: RevokeVote",
|
|
11
|
+
maxRun: 5,
|
|
12
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
13
|
+
invariant(
|
|
14
|
+
maxSpendable.gt(minimalAmount),
|
|
15
|
+
"Celo: Revoke Vote | balance is too low"
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const { celoResources } = account as CeloAccount;
|
|
19
|
+
invariant(
|
|
20
|
+
celoResources?.registrationStatus,
|
|
21
|
+
"Celo: RevokeVote | Account is not registered"
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const revokableVote = celoResources?.votes?.find((vote) => vote.revokable);
|
|
25
|
+
|
|
26
|
+
invariant(!!revokableVote, "Celo: RevokeVote | Revokable vote not found");
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
transaction: bridge.createTransaction(account),
|
|
30
|
+
updates: [
|
|
31
|
+
{
|
|
32
|
+
memo: "LedgerLiveBot",
|
|
33
|
+
mode: "revoke",
|
|
34
|
+
recipient: revokableVote!.validatorGroup,
|
|
35
|
+
group: revokableVote!.validatorGroup,
|
|
36
|
+
address: (account as CeloAccount).celoResources?.electionAddress,
|
|
37
|
+
index: revokableVote!.index,
|
|
38
|
+
amount: revokableVote!.amount,
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById, parseCurrencyUnit } from "../../../currencies";
|
|
3
|
+
import { pickSiblings } from "../../../bot/specs";
|
|
4
|
+
import { MutationSpec } from "../../../bot/types";
|
|
5
|
+
import type { Transaction } from "../types";
|
|
6
|
+
|
|
7
|
+
const maxAccount = 3;
|
|
8
|
+
const currency = getCryptoCurrencyById("celo");
|
|
9
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
10
|
+
|
|
11
|
+
export const createSend50PercentMutation = (): MutationSpec<Transaction> => ({
|
|
12
|
+
name: "Celo: Move 50% to another account",
|
|
13
|
+
maxRun: 1,
|
|
14
|
+
transaction: ({ account, siblings, bridge, maxSpendable }) => {
|
|
15
|
+
invariant(
|
|
16
|
+
maxSpendable.gt(minimalAmount),
|
|
17
|
+
"Celo: Move 50% | balance is too low"
|
|
18
|
+
);
|
|
19
|
+
const sibling = pickSiblings(siblings, maxAccount);
|
|
20
|
+
const recipient = sibling.freshAddress;
|
|
21
|
+
const amount = maxSpendable.div(2).integerValue();
|
|
22
|
+
return {
|
|
23
|
+
transaction: bridge.createTransaction(account),
|
|
24
|
+
updates: [{ recipient }, { amount }],
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export const createSendMaxMutation = (): MutationSpec<Transaction> => ({
|
|
30
|
+
name: "Celo: Send max to another account",
|
|
31
|
+
maxRun: 1,
|
|
32
|
+
transaction: ({ account, siblings, bridge, maxSpendable }) => {
|
|
33
|
+
invariant(
|
|
34
|
+
maxSpendable.gt(minimalAmount),
|
|
35
|
+
"Celo: Send Max | Balance is too low"
|
|
36
|
+
);
|
|
37
|
+
const sibling = pickSiblings(siblings, maxAccount);
|
|
38
|
+
const recipient = sibling.freshAddress;
|
|
39
|
+
return {
|
|
40
|
+
transaction: bridge.createTransaction(account),
|
|
41
|
+
updates: [{ recipient }, { useAllAmount: true }],
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { getCryptoCurrencyById, parseCurrencyUnit } from "../../../currencies";
|
|
3
|
+
import { MutationSpec } from "../../../bot/types";
|
|
4
|
+
import type { CeloAccount, Transaction } from "../types";
|
|
5
|
+
import BigNumber from "bignumber.js";
|
|
6
|
+
|
|
7
|
+
const currency = getCryptoCurrencyById("celo");
|
|
8
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
9
|
+
|
|
10
|
+
export const createUnlockMutation = (): MutationSpec<Transaction> => ({
|
|
11
|
+
name: "Celo: Unlock",
|
|
12
|
+
maxRun: 1,
|
|
13
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
14
|
+
invariant(
|
|
15
|
+
maxSpendable.gt(minimalAmount),
|
|
16
|
+
"Celo: Unlock | balance is too low"
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
const { celoResources } = account as CeloAccount;
|
|
20
|
+
invariant(
|
|
21
|
+
celoResources?.registrationStatus,
|
|
22
|
+
"Celo: Unlock | Account is not registered"
|
|
23
|
+
);
|
|
24
|
+
const nonvotingLockedBalance =
|
|
25
|
+
celoResources?.nonvotingLockedBalance || new BigNumber(0);
|
|
26
|
+
invariant(
|
|
27
|
+
nonvotingLockedBalance.gt(0),
|
|
28
|
+
"Celo: Unlock | No non voting locked balance"
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
transaction: bridge.createTransaction(account),
|
|
33
|
+
updates: [
|
|
34
|
+
{
|
|
35
|
+
memo: "LedgerLiveBot",
|
|
36
|
+
mode: "unlock",
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
amount: nonvotingLockedBalance.dividedBy(2).integerValue(),
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import BigNumber from "bignumber.js";
|
|
3
|
+
import sampleSize from "lodash/sampleSize";
|
|
4
|
+
import { MutationSpec } from "../../../bot/types";
|
|
5
|
+
import { getCryptoCurrencyById, parseCurrencyUnit } from "../../../currencies";
|
|
6
|
+
import { getCurrentCeloPreloadData } from "../preload";
|
|
7
|
+
import { getValidatorGroupsWithoutVotes } from "../logic";
|
|
8
|
+
import type { CeloAccount, CeloResources, Transaction } from "../types";
|
|
9
|
+
|
|
10
|
+
const currency = getCryptoCurrencyById("celo");
|
|
11
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
12
|
+
|
|
13
|
+
export const createVoteMutation = (): MutationSpec<Transaction> => ({
|
|
14
|
+
name: "Celo: Vote",
|
|
15
|
+
maxRun: 1,
|
|
16
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
17
|
+
invariant(
|
|
18
|
+
maxSpendable.gt(minimalAmount),
|
|
19
|
+
"Celo: Vote | balance is too low"
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const { celoResources } = account as CeloAccount;
|
|
23
|
+
invariant(
|
|
24
|
+
celoResources?.registrationStatus,
|
|
25
|
+
"Celo: Vote | Account is not registered"
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
const nonvotingLockedBalance =
|
|
29
|
+
celoResources?.nonvotingLockedBalance || new BigNumber(0);
|
|
30
|
+
invariant(
|
|
31
|
+
nonvotingLockedBalance.gt(0),
|
|
32
|
+
"Celo: Vote | No non voting locked balance"
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const votes = (celoResources as CeloResources).votes || [];
|
|
36
|
+
const { validatorGroups } = getCurrentCeloPreloadData();
|
|
37
|
+
|
|
38
|
+
// Get a random validator group that the account does not have locked tokens for.
|
|
39
|
+
const validatorGroupWithoutVotes = sampleSize(
|
|
40
|
+
getValidatorGroupsWithoutVotes(validatorGroups, votes),
|
|
41
|
+
1
|
|
42
|
+
)[0];
|
|
43
|
+
|
|
44
|
+
const amount = nonvotingLockedBalance
|
|
45
|
+
.times(0.5)
|
|
46
|
+
.precision(8)
|
|
47
|
+
.integerValue();
|
|
48
|
+
|
|
49
|
+
invariant(amount.gt(0), "Celo: Vote | Not enough funds to vote");
|
|
50
|
+
|
|
51
|
+
const transaction = {
|
|
52
|
+
recipient: validatorGroupWithoutVotes.address,
|
|
53
|
+
amount,
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
transaction: bridge.createTransaction(account),
|
|
58
|
+
updates: [
|
|
59
|
+
{
|
|
60
|
+
memo: "LedgerLiveBot",
|
|
61
|
+
mode: "vote",
|
|
62
|
+
},
|
|
63
|
+
transaction,
|
|
64
|
+
],
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import invariant from "invariant";
|
|
2
|
+
import { MutationSpec } from "../../../bot/types";
|
|
3
|
+
import { getCryptoCurrencyById, parseCurrencyUnit } from "../../../currencies";
|
|
4
|
+
import { availablePendingWithdrawals } from "../logic";
|
|
5
|
+
import type { CeloAccount, Transaction } from "../types";
|
|
6
|
+
|
|
7
|
+
const currency = getCryptoCurrencyById("celo");
|
|
8
|
+
const minimalAmount = parseCurrencyUnit(currency.units[0], "0.001");
|
|
9
|
+
|
|
10
|
+
export const createWithdrawMutation = (): MutationSpec<Transaction> => ({
|
|
11
|
+
name: "Celo: Withdraw",
|
|
12
|
+
maxRun: 5,
|
|
13
|
+
transaction: ({ account, bridge, maxSpendable }) => {
|
|
14
|
+
const celoAccount = account as CeloAccount;
|
|
15
|
+
const { celoResources } = celoAccount;
|
|
16
|
+
invariant(
|
|
17
|
+
celoResources?.registrationStatus,
|
|
18
|
+
"Celo: Withdraw | Account is not registered"
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const pendingWithdrawals = availablePendingWithdrawals(celoAccount);
|
|
22
|
+
|
|
23
|
+
invariant(
|
|
24
|
+
pendingWithdrawals.length > 0,
|
|
25
|
+
"Celo: Withdraw | No withdrawable balance"
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
invariant(
|
|
29
|
+
maxSpendable.gt(minimalAmount),
|
|
30
|
+
"Celo: Withdraw Vote | balance is too low"
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
transaction: bridge.createTransaction(celoAccount),
|
|
35
|
+
updates: [
|
|
36
|
+
{
|
|
37
|
+
mode: "withdraw",
|
|
38
|
+
recipient: celoAccount.celoResources!.lockedGoldAddress!,
|
|
39
|
+
index: pendingWithdrawals[0].index,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
};
|
|
43
|
+
},
|
|
44
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./createSendMutation";
|
|
2
|
+
export * from "./createLockMutation";
|
|
3
|
+
export * from "./createUnlockMutation";
|
|
4
|
+
export * from "./createRegisterAccountMutation";
|
|
5
|
+
export * from "./createVoteMutation";
|
|
6
|
+
export * from "./createActivateVoteMutation";
|
|
7
|
+
export * from "./createRevokeVoteMutation";
|
|
8
|
+
export * from "./createWithdrawMutation";
|
|
@@ -1,14 +1,30 @@
|
|
|
1
|
-
import invariant from "invariant";
|
|
2
|
-
import type { Transaction } from "./types";
|
|
3
|
-
import { getCryptoCurrencyById, parseCurrencyUnit } from "../../currencies";
|
|
4
|
-
import { pickSiblings } from "../../bot/specs";
|
|
5
|
-
import type { AppSpec } from "../../bot/types";
|
|
6
1
|
import { DeviceModelId } from "@ledgerhq/devices";
|
|
2
|
+
import { getCryptoCurrencyById } from "../../currencies";
|
|
3
|
+
import {
|
|
4
|
+
createLockMutation,
|
|
5
|
+
createRegisterAccountMutation,
|
|
6
|
+
createSend50PercentMutation,
|
|
7
|
+
createSendMaxMutation,
|
|
8
|
+
createUnlockMutation,
|
|
9
|
+
createVoteMutation,
|
|
10
|
+
createActivateVoteMutation,
|
|
11
|
+
createRevokeVoteMutation,
|
|
12
|
+
createWithdrawMutation,
|
|
13
|
+
} from "./specs/index";
|
|
14
|
+
import type { AppSpec } from "../../bot/types";
|
|
15
|
+
import type { Transaction } from "./types";
|
|
7
16
|
import { acceptTransaction } from "./speculos-deviceActions";
|
|
8
17
|
|
|
9
18
|
const currency = getCryptoCurrencyById("celo");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
19
|
+
const send50PercentMutation = createSend50PercentMutation();
|
|
20
|
+
const sendMaxMutation = createSendMaxMutation();
|
|
21
|
+
const registerAccountMutation = createRegisterAccountMutation();
|
|
22
|
+
const unlockMutation = createUnlockMutation();
|
|
23
|
+
const lockMutation = createLockMutation();
|
|
24
|
+
const voteMutation = createVoteMutation();
|
|
25
|
+
const activateVoteMutation = createActivateVoteMutation();
|
|
26
|
+
const revokeVoteMutation = createRevokeVoteMutation();
|
|
27
|
+
const withdrawMutation = createWithdrawMutation();
|
|
12
28
|
|
|
13
29
|
const celo: AppSpec<Transaction> = {
|
|
14
30
|
name: "Celo",
|
|
@@ -20,33 +36,15 @@ const celo: AppSpec<Transaction> = {
|
|
|
20
36
|
testTimeout: 2 * 60 * 1000,
|
|
21
37
|
genericDeviceAction: acceptTransaction,
|
|
22
38
|
mutations: [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
transaction: bridge.createTransaction(account),
|
|
33
|
-
updates: [{ recipient }, { amount }],
|
|
34
|
-
};
|
|
35
|
-
},
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: "send max to another account",
|
|
39
|
-
maxRun: 1,
|
|
40
|
-
transaction: ({ account, siblings, bridge, maxSpendable }) => {
|
|
41
|
-
invariant(maxSpendable.gt(minimalAmount), "balance is too low");
|
|
42
|
-
const sibling = pickSiblings(siblings, maxAccount);
|
|
43
|
-
const recipient = sibling.freshAddress;
|
|
44
|
-
return {
|
|
45
|
-
transaction: bridge.createTransaction(account),
|
|
46
|
-
updates: [{ recipient }, { useAllAmount: true }],
|
|
47
|
-
};
|
|
48
|
-
},
|
|
49
|
-
},
|
|
39
|
+
send50PercentMutation,
|
|
40
|
+
sendMaxMutation,
|
|
41
|
+
registerAccountMutation,
|
|
42
|
+
unlockMutation,
|
|
43
|
+
lockMutation,
|
|
44
|
+
voteMutation,
|
|
45
|
+
activateVoteMutation,
|
|
46
|
+
revokeVoteMutation,
|
|
47
|
+
withdrawMutation,
|
|
50
48
|
],
|
|
51
49
|
};
|
|
52
50
|
|
|
@@ -2,6 +2,16 @@ import type { DeviceAction } from "../../bot/types";
|
|
|
2
2
|
import type { Transaction } from "./types";
|
|
3
3
|
import { deviceActionFlow } from "../../bot/specs";
|
|
4
4
|
import { formatCurrencyUnit } from "../../currencies";
|
|
5
|
+
const typeWording = {
|
|
6
|
+
send: "Send",
|
|
7
|
+
lock: "Lock",
|
|
8
|
+
unlock: "Unlock",
|
|
9
|
+
withdraw: "Withdraw",
|
|
10
|
+
vote: "Vote",
|
|
11
|
+
revoke: "Revoke",
|
|
12
|
+
activate: "Activate",
|
|
13
|
+
register: "Create Account",
|
|
14
|
+
};
|
|
5
15
|
|
|
6
16
|
export const acceptTransaction: DeviceAction<Transaction, any> =
|
|
7
17
|
deviceActionFlow({
|
|
@@ -19,12 +29,10 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
|
|
|
19
29
|
formatCurrencyUnit(account.unit, status.amount, {
|
|
20
30
|
disableRounding: true,
|
|
21
31
|
});
|
|
22
|
-
|
|
23
32
|
if (!formattedValue.includes(".")) {
|
|
24
33
|
// if the value is pure integer, in the app it will automatically add an .0
|
|
25
34
|
return formattedValue + ".0";
|
|
26
35
|
}
|
|
27
|
-
|
|
28
36
|
return formattedValue;
|
|
29
37
|
},
|
|
30
38
|
},
|
|
@@ -41,6 +49,17 @@ export const acceptTransaction: DeviceAction<Transaction, any> =
|
|
|
41
49
|
title: "No Gateway Fee",
|
|
42
50
|
button: "Rr",
|
|
43
51
|
},
|
|
52
|
+
{
|
|
53
|
+
title: "Validator",
|
|
54
|
+
button: "Rr",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
title: "Type",
|
|
58
|
+
button: "Rr",
|
|
59
|
+
expectedValue: ({ transaction }) => {
|
|
60
|
+
return typeWording[transaction.mode];
|
|
61
|
+
},
|
|
62
|
+
},
|
|
44
63
|
{
|
|
45
64
|
title: "Accept",
|
|
46
65
|
button: "LRlr",
|