@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
|
@@ -3,6 +3,9 @@ import network from "../../../network";
|
|
|
3
3
|
import { getEnv } from "../../../env";
|
|
4
4
|
import { Operation, OperationType } from "@ledgerhq/types-live";
|
|
5
5
|
import { encodeOperationId } from "../../../operation";
|
|
6
|
+
import { CeloValidatorGroup, FigmentIndexerTransaction } from "../types";
|
|
7
|
+
import { isDefaultValidatorGroup } from "../logic";
|
|
8
|
+
import { celoKit } from "./sdk";
|
|
6
9
|
|
|
7
10
|
const DEFAULT_TRANSACTIONS_LIMIT = 200;
|
|
8
11
|
const getUrl = (route): string => `${getEnv("API_CELO_INDEXER")}${route || ""}`;
|
|
@@ -28,12 +31,36 @@ const fetchStatus = async () => {
|
|
|
28
31
|
return data;
|
|
29
32
|
};
|
|
30
33
|
|
|
34
|
+
const fetchValidatorGroups = async () => {
|
|
35
|
+
const { data } = await network({
|
|
36
|
+
method: "GET",
|
|
37
|
+
url: getUrl(`/validator_groups`),
|
|
38
|
+
});
|
|
39
|
+
return data.items;
|
|
40
|
+
};
|
|
41
|
+
|
|
31
42
|
const getOperationType = (type: string): OperationType => {
|
|
32
43
|
switch (type) {
|
|
33
44
|
case "InternalTransferSent":
|
|
34
45
|
return "OUT";
|
|
35
46
|
case "InternalTransferReceived":
|
|
36
47
|
return "IN";
|
|
48
|
+
case "GoldLocked":
|
|
49
|
+
return "LOCK";
|
|
50
|
+
case "GoldUnlocked":
|
|
51
|
+
return "UNLOCK";
|
|
52
|
+
case "GoldWithdrawn":
|
|
53
|
+
return "WITHDRAW";
|
|
54
|
+
case "ValidatorGroupVoteCastSent":
|
|
55
|
+
return "VOTE";
|
|
56
|
+
case "ValidatorGroupActiveVoteRevokedSent":
|
|
57
|
+
return "REVOKE";
|
|
58
|
+
case "ValidatorGroupPendingVoteRevokedSent":
|
|
59
|
+
return "REVOKE";
|
|
60
|
+
case "ValidatorGroupVoteActivatedSent":
|
|
61
|
+
return "ACTIVATE";
|
|
62
|
+
case "AccountCreated":
|
|
63
|
+
return "REGISTER";
|
|
37
64
|
case "AccountSlashed":
|
|
38
65
|
return "SLASH";
|
|
39
66
|
default:
|
|
@@ -44,44 +71,87 @@ const getOperationType = (type: string): OperationType => {
|
|
|
44
71
|
const transactionToOperation = (
|
|
45
72
|
address: string,
|
|
46
73
|
accountId: string,
|
|
47
|
-
transaction
|
|
74
|
+
transaction: FigmentIndexerTransaction
|
|
48
75
|
): Operation => {
|
|
49
76
|
const type: OperationType = getOperationType(transaction.kind);
|
|
50
|
-
const hasFailed = transaction.data
|
|
51
|
-
? !transaction.data
|
|
77
|
+
const hasFailed = transaction.data?.success
|
|
78
|
+
? !transaction.data?.success
|
|
52
79
|
: false;
|
|
53
|
-
const
|
|
54
|
-
const
|
|
80
|
+
const data = transaction.data;
|
|
81
|
+
const sender = data?.Account || data?.from;
|
|
82
|
+
const recipient = data?.Group || data?.to || data?.Raw?.address;
|
|
83
|
+
const fee = new BigNumber(transaction.data?.gas_used || 0).times(
|
|
84
|
+
new BigNumber(transaction.data?.gas_price || 0)
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const value = [
|
|
88
|
+
"LOCK",
|
|
89
|
+
"UNLOCK",
|
|
90
|
+
"ACTIVATE",
|
|
91
|
+
"VOTE",
|
|
92
|
+
"REVOKE",
|
|
93
|
+
"REGISTER",
|
|
94
|
+
].includes(type)
|
|
95
|
+
? new BigNumber(fee)
|
|
96
|
+
: new BigNumber(transaction.amount);
|
|
55
97
|
|
|
56
98
|
return {
|
|
57
99
|
id: encodeOperationId(accountId, transaction.transaction_hash, type),
|
|
58
100
|
hash: transaction.transaction_hash,
|
|
59
101
|
accountId,
|
|
60
|
-
fee
|
|
61
|
-
value
|
|
102
|
+
fee,
|
|
103
|
+
value,
|
|
62
104
|
type,
|
|
63
105
|
blockHeight: transaction.height,
|
|
64
106
|
date: new Date(transaction.time),
|
|
65
|
-
senders,
|
|
66
|
-
recipients,
|
|
107
|
+
senders: sender ? [sender] : [],
|
|
108
|
+
recipients: recipient ? [recipient] : [],
|
|
67
109
|
hasFailed,
|
|
68
110
|
blockHash: null,
|
|
69
|
-
extra: {
|
|
111
|
+
extra: {
|
|
112
|
+
celoOperationValue: new BigNumber(transaction.amount),
|
|
113
|
+
...(["ACTIVATE", "VOTE", "REVOKE"].includes(type)
|
|
114
|
+
? {
|
|
115
|
+
celoSourceValidator: recipient,
|
|
116
|
+
}
|
|
117
|
+
: {}),
|
|
118
|
+
},
|
|
70
119
|
};
|
|
71
120
|
};
|
|
72
121
|
|
|
73
|
-
export const getAccountDetails = async (
|
|
122
|
+
export const getAccountDetails = async (
|
|
123
|
+
address: string,
|
|
124
|
+
accountId: string
|
|
125
|
+
): Promise<{
|
|
126
|
+
blockHeight: any;
|
|
127
|
+
balance: BigNumber;
|
|
128
|
+
spendableBalance: BigNumber;
|
|
129
|
+
operations: Operation[];
|
|
130
|
+
lockedBalance: BigNumber;
|
|
131
|
+
nonvotingLockedBalance: BigNumber;
|
|
132
|
+
}> => {
|
|
74
133
|
const accountDetails = await fetchAccountDetails(address);
|
|
75
134
|
const spendableBalance = new BigNumber(accountDetails.gold_balance);
|
|
76
135
|
const lockedBalance = new BigNumber(accountDetails.total_locked_gold);
|
|
136
|
+
const nonvotingLockedBalance = new BigNumber(
|
|
137
|
+
accountDetails.total_nonvoting_locked_gold
|
|
138
|
+
);
|
|
77
139
|
const balance = spendableBalance.plus(lockedBalance);
|
|
78
140
|
const indexerStatus = await fetchStatus();
|
|
141
|
+
const kit = celoKit();
|
|
142
|
+
const lockedGold = await kit.contracts.getLockedGold();
|
|
79
143
|
|
|
80
|
-
const allTransactions = accountDetails.internal_transfers
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
144
|
+
const allTransactions = accountDetails.internal_transfers
|
|
145
|
+
.filter(
|
|
146
|
+
(transfer) =>
|
|
147
|
+
transfer.data?.to != lockedGold.address &&
|
|
148
|
+
transfer.data?.from != lockedGold.address
|
|
149
|
+
)
|
|
150
|
+
.concat(accountDetails.transactions);
|
|
151
|
+
|
|
152
|
+
const operations: Operation[] = allTransactions.map(
|
|
153
|
+
(transaction: FigmentIndexerTransaction) =>
|
|
154
|
+
transactionToOperation(address, accountId, transaction)
|
|
85
155
|
);
|
|
86
156
|
|
|
87
157
|
return {
|
|
@@ -89,5 +159,32 @@ export const getAccountDetails = async (address: string, accountId: string) => {
|
|
|
89
159
|
balance,
|
|
90
160
|
spendableBalance,
|
|
91
161
|
operations,
|
|
162
|
+
lockedBalance,
|
|
163
|
+
nonvotingLockedBalance,
|
|
92
164
|
};
|
|
93
165
|
};
|
|
166
|
+
|
|
167
|
+
export const getValidatorGroups = async (): Promise<CeloValidatorGroup[]> => {
|
|
168
|
+
const validatorGroups = await fetchValidatorGroups();
|
|
169
|
+
|
|
170
|
+
const result = validatorGroups.map((validatorGroup) => ({
|
|
171
|
+
address: validatorGroup.address,
|
|
172
|
+
name: validatorGroup.name || validatorGroup.address,
|
|
173
|
+
votes: new BigNumber(validatorGroup.active_votes).plus(
|
|
174
|
+
new BigNumber(validatorGroup.pending_votes)
|
|
175
|
+
),
|
|
176
|
+
}));
|
|
177
|
+
return customValidatorGroupsOrder(result);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const customValidatorGroupsOrder = (validatorGroups): CeloValidatorGroup[] => {
|
|
181
|
+
const defaultValidatorGroup = validatorGroups.find(isDefaultValidatorGroup);
|
|
182
|
+
|
|
183
|
+
const sortedValidatorGroups = [...validatorGroups]
|
|
184
|
+
.sort((a, b) => b.votes.minus(a.votes))
|
|
185
|
+
.filter((group) => !isDefaultValidatorGroup(group));
|
|
186
|
+
|
|
187
|
+
return defaultValidatorGroup
|
|
188
|
+
? [defaultValidatorGroup, ...sortedValidatorGroups]
|
|
189
|
+
: sortedValidatorGroups;
|
|
190
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { getAccountDetails } from "./hubble";
|
|
1
|
+
export { getAccountDetails, getValidatorGroups } from "./hubble";
|
|
@@ -1,8 +1,96 @@
|
|
|
1
1
|
import { ContractKit, newKit } from "@celo/contractkit";
|
|
2
2
|
import { getEnv } from "../../../env";
|
|
3
|
+
import { CeloVote } from "../types";
|
|
4
|
+
import { makeLRUCache } from "../../../cache";
|
|
3
5
|
|
|
4
6
|
let kit: ContractKit;
|
|
5
7
|
export const celoKit = () => {
|
|
6
8
|
if (!kit) kit = newKit(getEnv("API_CELO_NODE"));
|
|
7
9
|
return kit;
|
|
8
10
|
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Fetch account registered status. To lock any Celo, account needs to be registered first
|
|
14
|
+
*/
|
|
15
|
+
export const getAccountRegistrationStatus = async (
|
|
16
|
+
address: string
|
|
17
|
+
): Promise<boolean> => {
|
|
18
|
+
const accounts = await celoKit().contracts.getAccounts();
|
|
19
|
+
return await accounts.isAccount(address);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Fetch pending withdrawals, with an index
|
|
24
|
+
*/
|
|
25
|
+
export const getPendingWithdrawals = async (address: string) => {
|
|
26
|
+
const lockedGold = await celoKit().contracts.getLockedGold();
|
|
27
|
+
const pendingWithdrawals = await lockedGold.getPendingWithdrawals(address);
|
|
28
|
+
const pendingWithdrawalsWithIndexes = pendingWithdrawals
|
|
29
|
+
.map((withdrawal, index) => ({
|
|
30
|
+
...withdrawal,
|
|
31
|
+
index,
|
|
32
|
+
}))
|
|
33
|
+
.sort((a, b) => a.time.minus(b.time).toNumber());
|
|
34
|
+
return pendingWithdrawalsWithIndexes;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Fetch all votes
|
|
39
|
+
*/
|
|
40
|
+
export const getVotes = async (address: string): Promise<CeloVote[]> => {
|
|
41
|
+
const election = await celoKit().contracts.getElection();
|
|
42
|
+
const voter = await election.getVoter(await voteSignerAccount(address));
|
|
43
|
+
const activates = await getActivateTransactionObjects(address);
|
|
44
|
+
const activatableValidatorGroups = activates.map(
|
|
45
|
+
(activate) => activate.txo.arguments[0]
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const votes: CeloVote[] = [];
|
|
49
|
+
voter.votes.forEach((vote) => {
|
|
50
|
+
let activeVoteRevokable = true;
|
|
51
|
+
if (vote.pending.gt(0)) {
|
|
52
|
+
// If there's a pending vote, it has to be revoked first
|
|
53
|
+
activeVoteRevokable = false;
|
|
54
|
+
votes.push({
|
|
55
|
+
validatorGroup: vote.group,
|
|
56
|
+
amount: vote.pending,
|
|
57
|
+
// Not all pending votes can be activated, 24h has to pass
|
|
58
|
+
activatable: activatableValidatorGroups.includes(vote.group),
|
|
59
|
+
revokable: true,
|
|
60
|
+
index: 0,
|
|
61
|
+
type: "pending",
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
if (vote.active.gt(0))
|
|
65
|
+
votes.push({
|
|
66
|
+
validatorGroup: vote.group,
|
|
67
|
+
amount: vote.active,
|
|
68
|
+
activatable: false,
|
|
69
|
+
revokable: activeVoteRevokable,
|
|
70
|
+
index: 1,
|
|
71
|
+
type: "active",
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return votes;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const getActivateTransactionObjects = async (address: string) => {
|
|
79
|
+
const election = await celoKit().contracts.getElection();
|
|
80
|
+
return await election.activate(await voteSignerAccount(address));
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Fetch and cache address of a vote signer account
|
|
85
|
+
* Cache it for 1h since vote signer is usually the same account as our address
|
|
86
|
+
*/
|
|
87
|
+
export const voteSignerAccount = makeLRUCache(
|
|
88
|
+
async (address: string): Promise<string> => {
|
|
89
|
+
const accounts = await celoKit().contracts.getAccounts();
|
|
90
|
+
return await accounts.voteSignerToAccount(address);
|
|
91
|
+
},
|
|
92
|
+
(address) => address,
|
|
93
|
+
{
|
|
94
|
+
maxAge: 60 * 60 * 1000, // 1 hour
|
|
95
|
+
}
|
|
96
|
+
);
|
|
@@ -2,6 +2,7 @@ import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
|
2
2
|
import type { Transaction } from "../types";
|
|
3
3
|
import { makeAccountBridgeReceive } from "../../../bridge/jsHelpers";
|
|
4
4
|
import { sync, scanAccounts } from "../js-synchronisation";
|
|
5
|
+
import { getPreloadStrategy, preload, hydrate } from "../preload";
|
|
5
6
|
import signOperation from "../js-signOperation";
|
|
6
7
|
import getTransactionStatus from "../js-getTransactionStatus";
|
|
7
8
|
import broadcast from "../js-broadcast";
|
|
@@ -13,10 +14,8 @@ const updateTransaction = (t, patch) => ({ ...t, ...patch });
|
|
|
13
14
|
|
|
14
15
|
const receive = makeAccountBridgeReceive();
|
|
15
16
|
|
|
16
|
-
const preload = async () => Promise.resolve({});
|
|
17
|
-
const hydrate = (): void => {};
|
|
18
|
-
|
|
19
17
|
const currencyBridge: CurrencyBridge = {
|
|
18
|
+
getPreloadStrategy,
|
|
20
19
|
preload,
|
|
21
20
|
hydrate,
|
|
22
21
|
scanAccounts,
|
|
@@ -3,11 +3,26 @@ import type {
|
|
|
3
3
|
AccountLike,
|
|
4
4
|
AccountLikeArray,
|
|
5
5
|
} from "@ledgerhq/types-live";
|
|
6
|
+
|
|
7
|
+
import { from } from "rxjs";
|
|
8
|
+
import { map } from "rxjs/operators";
|
|
9
|
+
import { getValidatorGroups } from "../celo/api";
|
|
6
10
|
import invariant from "invariant";
|
|
7
11
|
import flatMap from "lodash/flatMap";
|
|
8
12
|
import type { Transaction } from "../celo/types";
|
|
9
13
|
|
|
10
|
-
const options = [
|
|
14
|
+
const options = [
|
|
15
|
+
{
|
|
16
|
+
name: "mode",
|
|
17
|
+
type: String,
|
|
18
|
+
desc: "mode of transaction: send, lock, unlock, withdraw, vote, revoke, activate, register",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "transactionIndex",
|
|
22
|
+
type: String,
|
|
23
|
+
desc: "transaction index of a pending withdraw in case of withdraw mode",
|
|
24
|
+
},
|
|
25
|
+
];
|
|
11
26
|
|
|
12
27
|
function inferAccounts(account: Account): AccountLikeArray {
|
|
13
28
|
invariant(account.currency.family === "celo", "celo family");
|
|
@@ -21,20 +36,49 @@ function inferTransactions(
|
|
|
21
36
|
account: AccountLike;
|
|
22
37
|
transaction: Transaction;
|
|
23
38
|
mainAccount: Account;
|
|
24
|
-
}
|
|
39
|
+
}>,
|
|
40
|
+
opts: Record<string, any>
|
|
25
41
|
): Transaction[] {
|
|
42
|
+
const mode = opts.mode || "send";
|
|
43
|
+
invariant(
|
|
44
|
+
[
|
|
45
|
+
"send",
|
|
46
|
+
"lock",
|
|
47
|
+
"unlock",
|
|
48
|
+
"withdraw",
|
|
49
|
+
"vote",
|
|
50
|
+
"revoke",
|
|
51
|
+
"activate",
|
|
52
|
+
"register",
|
|
53
|
+
].includes(mode),
|
|
54
|
+
`Unexpected mode: ${mode}`
|
|
55
|
+
);
|
|
56
|
+
|
|
26
57
|
return flatMap(transactions, ({ transaction }) => {
|
|
27
58
|
invariant(transaction.family === "celo", "celo family");
|
|
28
59
|
|
|
29
60
|
return {
|
|
30
61
|
...transaction,
|
|
31
62
|
family: "celo",
|
|
63
|
+
mode,
|
|
64
|
+
index: opts.transactionIndex || null,
|
|
32
65
|
} as Transaction;
|
|
33
66
|
});
|
|
34
67
|
}
|
|
35
68
|
|
|
69
|
+
const celoValidatorGroups = {
|
|
70
|
+
args: [],
|
|
71
|
+
job: () =>
|
|
72
|
+
from(getValidatorGroups()).pipe(
|
|
73
|
+
map((validatorGroup) => JSON.stringify(validatorGroup))
|
|
74
|
+
),
|
|
75
|
+
};
|
|
76
|
+
|
|
36
77
|
export default {
|
|
37
78
|
options,
|
|
38
79
|
inferAccounts,
|
|
39
80
|
inferTransactions,
|
|
81
|
+
commands: {
|
|
82
|
+
celoValidatorGroups,
|
|
83
|
+
},
|
|
40
84
|
};
|