@ledgerhq/coin-multiversx 0.2.0-next.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/.eslintrc.js +23 -0
- package/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +31 -0
- package/CHANGELOG.md +400 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/api/apiCalls.d.ts +22 -0
- package/lib/api/apiCalls.d.ts.map +1 -0
- package/lib/api/apiCalls.js +153 -0
- package/lib/api/apiCalls.js.map +1 -0
- package/lib/api/dtos/multiversx-account.d.ts +9 -0
- package/lib/api/dtos/multiversx-account.d.ts.map +1 -0
- package/lib/api/dtos/multiversx-account.js +17 -0
- package/lib/api/dtos/multiversx-account.js.map +1 -0
- package/lib/api/index.d.ts +2 -0
- package/lib/api/index.d.ts.map +1 -0
- package/lib/api/index.js +16 -0
- package/lib/api/index.js.map +1 -0
- package/lib/api/sdk.d.ts +29 -0
- package/lib/api/sdk.d.ts.map +1 -0
- package/lib/api/sdk.js +281 -0
- package/lib/api/sdk.js.map +1 -0
- package/lib/bridge/js.d.ts +11 -0
- package/lib/bridge/js.d.ts.map +1 -0
- package/lib/bridge/js.js +62 -0
- package/lib/bridge/js.js.map +1 -0
- package/lib/bridge.integration.test.d.ts +4 -0
- package/lib/bridge.integration.test.d.ts.map +1 -0
- package/lib/bridge.integration.test.js +142 -0
- package/lib/bridge.integration.test.js.map +1 -0
- package/lib/broadcast.d.ts +9 -0
- package/lib/broadcast.d.ts.map +1 -0
- package/lib/broadcast.js +16 -0
- package/lib/broadcast.js.map +1 -0
- package/lib/buildOptimisticOperation.d.ts +4 -0
- package/lib/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/buildOptimisticOperation.js +100 -0
- package/lib/buildOptimisticOperation.js.map +1 -0
- package/lib/buildOptimisticOperation.test.d.ts +2 -0
- package/lib/buildOptimisticOperation.test.d.ts.map +1 -0
- package/lib/buildOptimisticOperation.test.js +78 -0
- package/lib/buildOptimisticOperation.test.js.map +1 -0
- package/lib/buildSubAccounts.d.ts +11 -0
- package/lib/buildSubAccounts.d.ts.map +1 -0
- package/lib/buildSubAccounts.js +117 -0
- package/lib/buildSubAccounts.js.map +1 -0
- package/lib/buildTransaction.d.ts +19 -0
- package/lib/buildTransaction.d.ts.map +1 -0
- package/lib/buildTransaction.js +49 -0
- package/lib/buildTransaction.js.map +1 -0
- package/lib/buildTransaction.unit.test.d.ts +2 -0
- package/lib/buildTransaction.unit.test.d.ts.map +1 -0
- package/lib/buildTransaction.unit.test.js +47 -0
- package/lib/buildTransaction.unit.test.js.map +1 -0
- package/lib/cli-transaction.d.ts +16 -0
- package/lib/cli-transaction.d.ts.map +1 -0
- package/lib/cli-transaction.js +35 -0
- package/lib/cli-transaction.js.map +1 -0
- package/lib/config.d.ts +14 -0
- package/lib/config.d.ts.map +1 -0
- package/lib/config.js +16 -0
- package/lib/config.js.map +1 -0
- package/lib/constants.d.ts +21 -0
- package/lib/constants.d.ts.map +1 -0
- package/lib/constants.js +27 -0
- package/lib/constants.js.map +1 -0
- package/lib/createTransaction.d.ts +9 -0
- package/lib/createTransaction.d.ts.map +1 -0
- package/lib/createTransaction.js +26 -0
- package/lib/createTransaction.js.map +1 -0
- package/lib/datasets/multiversx1.d.ts +3 -0
- package/lib/datasets/multiversx1.d.ts.map +1 -0
- package/lib/datasets/multiversx1.js +21 -0
- package/lib/datasets/multiversx1.js.map +1 -0
- package/lib/deviceTransactionConfig.d.ts +10 -0
- package/lib/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/deviceTransactionConfig.js +60 -0
- package/lib/deviceTransactionConfig.js.map +1 -0
- package/lib/encode.d.ts +11 -0
- package/lib/encode.d.ts.map +1 -0
- package/lib/encode.js +39 -0
- package/lib/encode.js.map +1 -0
- package/lib/errors.d.ts +16 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +10 -0
- package/lib/errors.js.map +1 -0
- package/lib/estimateMaxSpendable.d.ts +10 -0
- package/lib/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/estimateMaxSpendable.js +35 -0
- package/lib/estimateMaxSpendable.js.map +1 -0
- package/lib/formatters.d.ts +11 -0
- package/lib/formatters.d.ts.map +1 -0
- package/lib/formatters.js +65 -0
- package/lib/formatters.js.map +1 -0
- package/lib/getTransactionStatus.d.ts +5 -0
- package/lib/getTransactionStatus.d.ts.map +1 -0
- package/lib/getTransactionStatus.js +107 -0
- package/lib/getTransactionStatus.js.map +1 -0
- package/lib/helpers/denominate.d.ts +9 -0
- package/lib/helpers/denominate.d.ts.map +1 -0
- package/lib/helpers/denominate.js +75 -0
- package/lib/helpers/denominate.js.map +1 -0
- package/lib/helpers/handleTransactionStatus.d.ts +7 -0
- package/lib/helpers/handleTransactionStatus.d.ts.map +1 -0
- package/lib/helpers/handleTransactionStatus.js +18 -0
- package/lib/helpers/handleTransactionStatus.js.map +1 -0
- package/lib/helpers/hasMinimumDelegableBalance.d.ts +3 -0
- package/lib/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
- package/lib/helpers/hasMinimumDelegableBalance.js +7 -0
- package/lib/helpers/hasMinimumDelegableBalance.js.map +1 -0
- package/lib/helpers/randomizeProviders.d.ts +7 -0
- package/lib/helpers/randomizeProviders.d.ts.map +1 -0
- package/lib/helpers/randomizeProviders.js +12 -0
- package/lib/helpers/randomizeProviders.js.map +1 -0
- package/lib/hw-getAddress.d.ts +6 -0
- package/lib/hw-getAddress.d.ts.map +1 -0
- package/lib/hw-getAddress.js +14 -0
- package/lib/hw-getAddress.js.map +1 -0
- package/lib/logic.d.ts +15 -0
- package/lib/logic.d.ts.map +1 -0
- package/lib/logic.js +77 -0
- package/lib/logic.js.map +1 -0
- package/lib/preload.d.ts +11 -0
- package/lib/preload.d.ts.map +1 -0
- package/lib/preload.js +94 -0
- package/lib/preload.js.map +1 -0
- package/lib/prepareTransaction.d.ts +10 -0
- package/lib/prepareTransaction.d.ts.map +1 -0
- package/lib/prepareTransaction.js +72 -0
- package/lib/prepareTransaction.js.map +1 -0
- package/lib/reconciliation.d.ts +3 -0
- package/lib/reconciliation.d.ts.map +1 -0
- package/lib/reconciliation.js +56 -0
- package/lib/reconciliation.js.map +1 -0
- package/lib/serialization.d.ts +9 -0
- package/lib/serialization.d.ts.map +1 -0
- package/lib/serialization.js +65 -0
- package/lib/serialization.js.map +1 -0
- package/lib/signOperation.d.ts +10 -0
- package/lib/signOperation.d.ts.map +1 -0
- package/lib/signOperation.js +65 -0
- package/lib/signOperation.js.map +1 -0
- package/lib/signer.d.ts +16 -0
- package/lib/signer.d.ts.map +1 -0
- package/lib/signer.js +3 -0
- package/lib/signer.js.map +1 -0
- package/lib/specs.d.ts +7 -0
- package/lib/specs.d.ts.map +1 -0
- package/lib/specs.js +286 -0
- package/lib/specs.js.map +1 -0
- package/lib/speculos-deviceActions.d.ts +16 -0
- package/lib/speculos-deviceActions.d.ts.map +1 -0
- package/lib/speculos-deviceActions.js +250 -0
- package/lib/speculos-deviceActions.js.map +1 -0
- package/lib/synchronisation.d.ts +5 -0
- package/lib/synchronisation.d.ts.map +1 -0
- package/lib/synchronisation.js +69 -0
- package/lib/synchronisation.js.map +1 -0
- package/lib/transaction.d.ts +15 -0
- package/lib/transaction.d.ts.map +1 -0
- package/lib/transaction.js +62 -0
- package/lib/transaction.js.map +1 -0
- package/lib/types.d.ts +188 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +17 -0
- package/lib/types.js.map +1 -0
- package/lib/utils/binary.utils.d.ts +5 -0
- package/lib/utils/binary.utils.d.ts.map +1 -0
- package/lib/utils/binary.utils.js +16 -0
- package/lib/utils/binary.utils.js.map +1 -0
- package/lib-es/api/apiCalls.d.ts +22 -0
- package/lib-es/api/apiCalls.d.ts.map +1 -0
- package/lib-es/api/apiCalls.js +147 -0
- package/lib-es/api/apiCalls.js.map +1 -0
- package/lib-es/api/dtos/multiversx-account.d.ts +9 -0
- package/lib-es/api/dtos/multiversx-account.d.ts.map +1 -0
- package/lib-es/api/dtos/multiversx-account.js +13 -0
- package/lib-es/api/dtos/multiversx-account.js.map +1 -0
- package/lib-es/api/index.d.ts +2 -0
- package/lib-es/api/index.d.ts.map +1 -0
- package/lib-es/api/index.js +2 -0
- package/lib-es/api/index.js.map +1 -0
- package/lib-es/api/sdk.d.ts +29 -0
- package/lib-es/api/sdk.d.ts.map +1 -0
- package/lib-es/api/sdk.js +264 -0
- package/lib-es/api/sdk.js.map +1 -0
- package/lib-es/bridge/js.d.ts +11 -0
- package/lib-es/bridge/js.d.ts.map +1 -0
- package/lib-es/bridge/js.js +53 -0
- package/lib-es/bridge/js.js.map +1 -0
- package/lib-es/bridge.integration.test.d.ts +4 -0
- package/lib-es/bridge.integration.test.d.ts.map +1 -0
- package/lib-es/bridge.integration.test.js +139 -0
- package/lib-es/bridge.integration.test.js.map +1 -0
- package/lib-es/broadcast.d.ts +9 -0
- package/lib-es/broadcast.d.ts.map +1 -0
- package/lib-es/broadcast.js +12 -0
- package/lib-es/broadcast.js.map +1 -0
- package/lib-es/buildOptimisticOperation.d.ts +4 -0
- package/lib-es/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/buildOptimisticOperation.js +93 -0
- package/lib-es/buildOptimisticOperation.js.map +1 -0
- package/lib-es/buildOptimisticOperation.test.d.ts +2 -0
- package/lib-es/buildOptimisticOperation.test.d.ts.map +1 -0
- package/lib-es/buildOptimisticOperation.test.js +73 -0
- package/lib-es/buildOptimisticOperation.test.js.map +1 -0
- package/lib-es/buildSubAccounts.d.ts +11 -0
- package/lib-es/buildSubAccounts.d.ts.map +1 -0
- package/lib-es/buildSubAccounts.js +112 -0
- package/lib-es/buildSubAccounts.js.map +1 -0
- package/lib-es/buildTransaction.d.ts +19 -0
- package/lib-es/buildTransaction.d.ts.map +1 -0
- package/lib-es/buildTransaction.js +44 -0
- package/lib-es/buildTransaction.js.map +1 -0
- package/lib-es/buildTransaction.unit.test.d.ts +2 -0
- package/lib-es/buildTransaction.unit.test.d.ts.map +1 -0
- package/lib-es/buildTransaction.unit.test.js +42 -0
- package/lib-es/buildTransaction.unit.test.js.map +1 -0
- package/lib-es/cli-transaction.d.ts +16 -0
- package/lib-es/cli-transaction.d.ts.map +1 -0
- package/lib-es/cli-transaction.js +29 -0
- package/lib-es/cli-transaction.js.map +1 -0
- package/lib-es/config.d.ts +14 -0
- package/lib-es/config.d.ts.map +1 -0
- package/lib-es/config.js +11 -0
- package/lib-es/config.js.map +1 -0
- package/lib-es/constants.d.ts +21 -0
- package/lib-es/constants.d.ts.map +1 -0
- package/lib-es/constants.js +21 -0
- package/lib-es/constants.js.map +1 -0
- package/lib-es/createTransaction.d.ts +9 -0
- package/lib-es/createTransaction.d.ts.map +1 -0
- package/lib-es/createTransaction.js +19 -0
- package/lib-es/createTransaction.js.map +1 -0
- package/lib-es/datasets/multiversx1.d.ts +3 -0
- package/lib-es/datasets/multiversx1.d.ts.map +1 -0
- package/lib-es/datasets/multiversx1.js +18 -0
- package/lib-es/datasets/multiversx1.js.map +1 -0
- package/lib-es/deviceTransactionConfig.d.ts +10 -0
- package/lib-es/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/deviceTransactionConfig.js +55 -0
- package/lib-es/deviceTransactionConfig.js.map +1 -0
- package/lib-es/encode.d.ts +11 -0
- package/lib-es/encode.d.ts.map +1 -0
- package/lib-es/encode.js +35 -0
- package/lib-es/encode.js.map +1 -0
- package/lib-es/errors.d.ts +16 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +7 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/estimateMaxSpendable.d.ts +10 -0
- package/lib-es/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/estimateMaxSpendable.js +31 -0
- package/lib-es/estimateMaxSpendable.js.map +1 -0
- package/lib-es/formatters.d.ts +11 -0
- package/lib-es/formatters.d.ts.map +1 -0
- package/lib-es/formatters.js +60 -0
- package/lib-es/formatters.js.map +1 -0
- package/lib-es/getTransactionStatus.d.ts +5 -0
- package/lib-es/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/getTransactionStatus.js +100 -0
- package/lib-es/getTransactionStatus.js.map +1 -0
- package/lib-es/helpers/denominate.d.ts +9 -0
- package/lib-es/helpers/denominate.d.ts.map +1 -0
- package/lib-es/helpers/denominate.js +71 -0
- package/lib-es/helpers/denominate.js.map +1 -0
- package/lib-es/helpers/handleTransactionStatus.d.ts +7 -0
- package/lib-es/helpers/handleTransactionStatus.d.ts.map +1 -0
- package/lib-es/helpers/handleTransactionStatus.js +14 -0
- package/lib-es/helpers/handleTransactionStatus.js.map +1 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.d.ts +3 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.d.ts.map +1 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.js +3 -0
- package/lib-es/helpers/hasMinimumDelegableBalance.js.map +1 -0
- package/lib-es/helpers/randomizeProviders.d.ts +7 -0
- package/lib-es/helpers/randomizeProviders.d.ts.map +1 -0
- package/lib-es/helpers/randomizeProviders.js +8 -0
- package/lib-es/helpers/randomizeProviders.js.map +1 -0
- package/lib-es/hw-getAddress.d.ts +6 -0
- package/lib-es/hw-getAddress.d.ts.map +1 -0
- package/lib-es/hw-getAddress.js +12 -0
- package/lib-es/hw-getAddress.js.map +1 -0
- package/lib-es/logic.d.ts +15 -0
- package/lib-es/logic.d.ts.map +1 -0
- package/lib-es/logic.js +65 -0
- package/lib-es/logic.js.map +1 -0
- package/lib-es/preload.d.ts +11 -0
- package/lib-es/preload.d.ts.map +1 -0
- package/lib-es/preload.js +85 -0
- package/lib-es/preload.js.map +1 -0
- package/lib-es/prepareTransaction.d.ts +10 -0
- package/lib-es/prepareTransaction.d.ts.map +1 -0
- package/lib-es/prepareTransaction.js +68 -0
- package/lib-es/prepareTransaction.js.map +1 -0
- package/lib-es/reconciliation.d.ts +3 -0
- package/lib-es/reconciliation.d.ts.map +1 -0
- package/lib-es/reconciliation.js +52 -0
- package/lib-es/reconciliation.js.map +1 -0
- package/lib-es/serialization.d.ts +9 -0
- package/lib-es/serialization.d.ts.map +1 -0
- package/lib-es/serialization.js +53 -0
- package/lib-es/serialization.js.map +1 -0
- package/lib-es/signOperation.d.ts +10 -0
- package/lib-es/signOperation.d.ts.map +1 -0
- package/lib-es/signOperation.js +61 -0
- package/lib-es/signOperation.js.map +1 -0
- package/lib-es/signer.d.ts +16 -0
- package/lib-es/signer.d.ts.map +1 -0
- package/lib-es/signer.js +2 -0
- package/lib-es/signer.js.map +1 -0
- package/lib-es/specs.d.ts +7 -0
- package/lib-es/specs.d.ts.map +1 -0
- package/lib-es/specs.js +281 -0
- package/lib-es/specs.js.map +1 -0
- package/lib-es/speculos-deviceActions.d.ts +16 -0
- package/lib-es/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/speculos-deviceActions.js +244 -0
- package/lib-es/speculos-deviceActions.js.map +1 -0
- package/lib-es/synchronisation.d.ts +5 -0
- package/lib-es/synchronisation.d.ts.map +1 -0
- package/lib-es/synchronisation.js +62 -0
- package/lib-es/synchronisation.js.map +1 -0
- package/lib-es/transaction.d.ts +15 -0
- package/lib-es/transaction.d.ts.map +1 -0
- package/lib-es/transaction.js +56 -0
- package/lib-es/transaction.js.map +1 -0
- package/lib-es/types.d.ts +188 -0
- package/lib-es/types.d.ts.map +1 -0
- package/lib-es/types.js +12 -0
- package/lib-es/types.js.map +1 -0
- package/lib-es/utils/binary.utils.d.ts +5 -0
- package/lib-es/utils/binary.utils.d.ts.map +1 -0
- package/lib-es/utils/binary.utils.js +12 -0
- package/lib-es/utils/binary.utils.js.map +1 -0
- package/package.json +86 -0
- package/src/__snapshots__/bridge.integration.test.ts.snap +181 -0
- package/src/api/apiCalls.ts +243 -0
- package/src/api/dtos/multiversx-account.ts +20 -0
- package/src/api/index.ts +13 -0
- package/src/api/sdk.ts +368 -0
- package/src/bridge/js.ts +77 -0
- package/src/bridge.integration.test.ts +147 -0
- package/src/broadcast.ts +16 -0
- package/src/buildOptimisticOperation.test.ts +88 -0
- package/src/buildOptimisticOperation.ts +120 -0
- package/src/buildSubAccounts.ts +153 -0
- package/src/buildTransaction.ts +67 -0
- package/src/buildTransaction.unit.test.ts +49 -0
- package/src/cli-transaction.ts +41 -0
- package/src/config.ts +26 -0
- package/src/constants.ts +24 -0
- package/src/createTransaction.ts +21 -0
- package/src/datasets/multiversx1.ts +19 -0
- package/src/deviceTransactionConfig.ts +74 -0
- package/src/encode.ts +46 -0
- package/src/errors.ts +19 -0
- package/src/estimateMaxSpendable.ts +43 -0
- package/src/formatters.ts +76 -0
- package/src/getTransactionStatus.ts +151 -0
- package/src/helpers/denominate.ts +95 -0
- package/src/helpers/handleTransactionStatus.ts +26 -0
- package/src/helpers/hasMinimumDelegableBalance.ts +6 -0
- package/src/helpers/randomizeProviders.ts +20 -0
- package/src/hw-getAddress.ts +19 -0
- package/src/logic.ts +83 -0
- package/src/preload.ts +95 -0
- package/src/prepareTransaction.ts +78 -0
- package/src/reconciliation.ts +64 -0
- package/src/serialization.ts +72 -0
- package/src/signOperation.ts +99 -0
- package/src/signer.ts +21 -0
- package/src/specs.ts +387 -0
- package/src/speculos-deviceActions.ts +269 -0
- package/src/synchronisation.ts +74 -0
- package/src/transaction.ts +76 -0
- package/src/types.ts +235 -0
- package/src/utils/binary.utils.ts +13 -0
- package/tsconfig.json +13 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { TokenAccount } from "@ledgerhq/types-live";
|
|
2
|
+
import type { GetAccountShape } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
3
|
+
import { encodeAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
4
|
+
import { makeSync, mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
5
|
+
import { inferSubOperations } from "@ledgerhq/coin-framework/serialization/index";
|
|
6
|
+
import { getAccount, getAccountDelegations, getEGLDOperations, hasESDTTokens } from "./api";
|
|
7
|
+
import MultiversXBuildESDTTokenAccounts from "./buildSubAccounts";
|
|
8
|
+
import { reconciliateSubAccounts } from "./reconciliation";
|
|
9
|
+
import { computeDelegationBalance } from "./logic";
|
|
10
|
+
import { MultiversXAccount } from "./types";
|
|
11
|
+
|
|
12
|
+
export const getAccountShape: GetAccountShape<MultiversXAccount> = async (info, syncConfig) => {
|
|
13
|
+
const { address, initialAccount, currency, derivationMode } = info;
|
|
14
|
+
const accountId = encodeAccountId({
|
|
15
|
+
type: "js",
|
|
16
|
+
version: "2",
|
|
17
|
+
currencyId: currency.id,
|
|
18
|
+
xpubOrAddress: address,
|
|
19
|
+
derivationMode,
|
|
20
|
+
});
|
|
21
|
+
const oldOperations = initialAccount?.operations || [];
|
|
22
|
+
// Needed for incremental synchronisation
|
|
23
|
+
const startAt = oldOperations.length ? Math.floor(oldOperations[0].date.valueOf() / 1000) : 0;
|
|
24
|
+
|
|
25
|
+
const account = await getAccount(address);
|
|
26
|
+
|
|
27
|
+
const delegations = await getAccountDelegations(address);
|
|
28
|
+
|
|
29
|
+
let subAccounts: TokenAccount[] = [];
|
|
30
|
+
const hasTokens = await hasESDTTokens(address);
|
|
31
|
+
if (hasTokens) {
|
|
32
|
+
const tokenAccounts = await MultiversXBuildESDTTokenAccounts({
|
|
33
|
+
currency,
|
|
34
|
+
accountId: accountId,
|
|
35
|
+
accountAddress: address,
|
|
36
|
+
existingAccount: initialAccount,
|
|
37
|
+
syncConfig,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (tokenAccounts) {
|
|
41
|
+
subAccounts = reconciliateSubAccounts(tokenAccounts, initialAccount);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const delegationBalance = computeDelegationBalance(delegations);
|
|
46
|
+
|
|
47
|
+
// Merge new operations with the previously synced ones
|
|
48
|
+
const newOperations = await getEGLDOperations(accountId, address, startAt, subAccounts);
|
|
49
|
+
const operations = mergeOps(oldOperations, newOperations);
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
id: accountId,
|
|
53
|
+
balance: account.balance.plus(delegationBalance),
|
|
54
|
+
spendableBalance: account.balance,
|
|
55
|
+
operationsCount: operations.length,
|
|
56
|
+
blockHeight: account.blockHeight,
|
|
57
|
+
multiversxResources: {
|
|
58
|
+
nonce: account.nonce,
|
|
59
|
+
delegations,
|
|
60
|
+
isGuarded: account.isGuarded,
|
|
61
|
+
},
|
|
62
|
+
subAccounts,
|
|
63
|
+
operations: operations.map(op => {
|
|
64
|
+
const subOperations = inferSubOperations(op.hash, subAccounts);
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
...op,
|
|
68
|
+
subOperations,
|
|
69
|
+
};
|
|
70
|
+
}),
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const sync = makeSync({ getAccountShape });
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { Transaction, TransactionRaw } from "./types";
|
|
2
|
+
import { BigNumber } from "bignumber.js";
|
|
3
|
+
import { formatTransactionStatus } from "@ledgerhq/coin-framework/formatters";
|
|
4
|
+
import {
|
|
5
|
+
fromTransactionCommonRaw,
|
|
6
|
+
fromTransactionStatusRawCommon as fromTransactionStatusRaw,
|
|
7
|
+
toTransactionCommonRaw,
|
|
8
|
+
toTransactionStatusRawCommon as toTransactionStatusRaw,
|
|
9
|
+
} from "@ledgerhq/coin-framework/serialization";
|
|
10
|
+
import type { Account } from "@ledgerhq/types-live";
|
|
11
|
+
import { getAccountCurrency } from "@ledgerhq/coin-framework/account";
|
|
12
|
+
import { formatCurrencyUnit } from "@ledgerhq/coin-framework/currencies";
|
|
13
|
+
|
|
14
|
+
export const formatTransaction = (
|
|
15
|
+
{ mode, amount, recipient, useAllAmount, subAccountId }: Transaction,
|
|
16
|
+
mainAccount: Account,
|
|
17
|
+
): string => {
|
|
18
|
+
const account =
|
|
19
|
+
(subAccountId && (mainAccount.subAccounts || []).find(a => a.id === subAccountId)) ||
|
|
20
|
+
mainAccount;
|
|
21
|
+
return `
|
|
22
|
+
${mode.toUpperCase()} ${
|
|
23
|
+
useAllAmount
|
|
24
|
+
? "MAX"
|
|
25
|
+
: amount.isZero()
|
|
26
|
+
? ""
|
|
27
|
+
: " " +
|
|
28
|
+
formatCurrencyUnit(getAccountCurrency(account).units[0], amount, {
|
|
29
|
+
showCode: true,
|
|
30
|
+
disableRounding: true,
|
|
31
|
+
})
|
|
32
|
+
}${recipient ? `\nTO ${recipient}` : ""}`;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const fromTransactionRaw = (tr: TransactionRaw): Transaction => {
|
|
36
|
+
const common = fromTransactionCommonRaw(tr);
|
|
37
|
+
const tx: Transaction = {
|
|
38
|
+
...common,
|
|
39
|
+
family: tr.family,
|
|
40
|
+
mode: tr.mode,
|
|
41
|
+
fees: tr.fees ? new BigNumber(tr.fees) : null,
|
|
42
|
+
gasLimit: tr.gasLimit,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
if (tr.data) {
|
|
46
|
+
tx.data = tr.data;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return tx;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const toTransactionRaw = (t: Transaction): TransactionRaw => {
|
|
53
|
+
const common = toTransactionCommonRaw(t);
|
|
54
|
+
const tx: TransactionRaw = {
|
|
55
|
+
...common,
|
|
56
|
+
family: t.family,
|
|
57
|
+
mode: t.mode,
|
|
58
|
+
fees: t.fees?.toString() || null,
|
|
59
|
+
gasLimit: t.gasLimit,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
if (t.data) {
|
|
63
|
+
tx.data = t.data;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return tx;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default {
|
|
70
|
+
formatTransaction,
|
|
71
|
+
fromTransactionRaw,
|
|
72
|
+
toTransactionRaw,
|
|
73
|
+
fromTransactionStatusRaw,
|
|
74
|
+
toTransactionStatusRaw,
|
|
75
|
+
formatTransactionStatus,
|
|
76
|
+
};
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Account,
|
|
3
|
+
AccountRaw,
|
|
4
|
+
Operation,
|
|
5
|
+
OperationExtra,
|
|
6
|
+
OperationExtraRaw,
|
|
7
|
+
OperationRaw,
|
|
8
|
+
TransactionCommon,
|
|
9
|
+
TransactionCommonRaw,
|
|
10
|
+
TransactionStatusCommon,
|
|
11
|
+
TransactionStatusCommonRaw,
|
|
12
|
+
} from "@ledgerhq/types-live";
|
|
13
|
+
import BigNumber from "bignumber.js";
|
|
14
|
+
|
|
15
|
+
export type MultiversXAccount = Account & { multiversxResources: MultiversXResources };
|
|
16
|
+
|
|
17
|
+
export type MultiversXAccountRaw = AccountRaw & {
|
|
18
|
+
multiversxResources: MultiversXResourcesRaw;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type MultiversXResources = {
|
|
22
|
+
nonce: number;
|
|
23
|
+
delegations: MultiversXDelegation[];
|
|
24
|
+
isGuarded: boolean;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type MultiversXResourcesRaw = {
|
|
28
|
+
nonce: number;
|
|
29
|
+
delegations: MultiversXDelegation[];
|
|
30
|
+
isGuarded: boolean;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type MultiversXDelegation = {
|
|
34
|
+
address: string;
|
|
35
|
+
contract: string;
|
|
36
|
+
userUnBondable: string;
|
|
37
|
+
userActiveStake: string;
|
|
38
|
+
claimableRewards: string;
|
|
39
|
+
userUndelegatedList: UserUndelegated[];
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type UserUndelegated = {
|
|
43
|
+
amount: string;
|
|
44
|
+
seconds: number;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* MultiversX transaction
|
|
49
|
+
*/
|
|
50
|
+
export type Transaction = TransactionCommon & {
|
|
51
|
+
family: "multiversx";
|
|
52
|
+
mode: MultiversXTransactionMode;
|
|
53
|
+
fees: BigNumber | null | undefined;
|
|
54
|
+
data?: string;
|
|
55
|
+
gasLimit: number;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export type TransactionRaw = TransactionCommonRaw & {
|
|
59
|
+
family: "multiversx";
|
|
60
|
+
mode: MultiversXTransactionMode;
|
|
61
|
+
fees: string | null | undefined;
|
|
62
|
+
data?: string;
|
|
63
|
+
gasLimit: number;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export type TransactionStatus = TransactionStatusCommon;
|
|
67
|
+
|
|
68
|
+
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|
|
69
|
+
|
|
70
|
+
export type MultiversXTransactionMode =
|
|
71
|
+
| "send"
|
|
72
|
+
| "delegate"
|
|
73
|
+
| "reDelegateRewards"
|
|
74
|
+
| "unDelegate"
|
|
75
|
+
| "claimRewards"
|
|
76
|
+
| "withdraw";
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* MultiversX transaction payload to sign
|
|
80
|
+
*/
|
|
81
|
+
export type MultiversXProtocolTransaction = {
|
|
82
|
+
nonce: number;
|
|
83
|
+
value: string;
|
|
84
|
+
receiver: string;
|
|
85
|
+
sender: string;
|
|
86
|
+
gasPrice: number;
|
|
87
|
+
gasLimit: number;
|
|
88
|
+
chainID: string;
|
|
89
|
+
signature?: string;
|
|
90
|
+
data?: string; //for ESDT or stake transactions
|
|
91
|
+
version: number;
|
|
92
|
+
options: number;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* MultiversX transaction as received from explorer
|
|
97
|
+
*/
|
|
98
|
+
export type MultiversXApiTransaction = {
|
|
99
|
+
mode: MultiversXTransactionMode;
|
|
100
|
+
fees: BigNumber | null | undefined;
|
|
101
|
+
transfer?: MultiversXTransferOptions;
|
|
102
|
+
txHash?: string;
|
|
103
|
+
sender?: string;
|
|
104
|
+
receiver?: string;
|
|
105
|
+
value?: BigNumber;
|
|
106
|
+
blockHash?: string;
|
|
107
|
+
blockHeight?: number;
|
|
108
|
+
timestamp?: number;
|
|
109
|
+
nonce?: number;
|
|
110
|
+
gasLimit: number;
|
|
111
|
+
status?: string;
|
|
112
|
+
fee?: BigNumber;
|
|
113
|
+
round?: number;
|
|
114
|
+
miniBlockHash?: string;
|
|
115
|
+
data?: string;
|
|
116
|
+
tokenIdentifier?: string;
|
|
117
|
+
tokenValue?: string;
|
|
118
|
+
action?: MultiversXTransactionAction;
|
|
119
|
+
operations?: MultiversXTransactionOperation[];
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export enum MultiversXTransferOptions {
|
|
123
|
+
egld = "egld",
|
|
124
|
+
esdt = "esdt",
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export type MultiversXTransactionOperation = {
|
|
128
|
+
action: string;
|
|
129
|
+
type: string;
|
|
130
|
+
sender: string;
|
|
131
|
+
receiver: string;
|
|
132
|
+
value: string;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export type MultiversXTransactionAction = {
|
|
136
|
+
category: string;
|
|
137
|
+
name: string;
|
|
138
|
+
arguments: MultiversXTransactionActionArguments;
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export type MultiversXTransactionActionArguments = {
|
|
142
|
+
transfers: MultiversXTransactionActionArgumentsTransfers[];
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export type MultiversXTransactionActionArgumentsTransfers = {
|
|
146
|
+
token: string;
|
|
147
|
+
value: string;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export type ESDTToken = {
|
|
151
|
+
identifier: string;
|
|
152
|
+
name: string;
|
|
153
|
+
balance: string;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
export type NetworkInfo = {
|
|
157
|
+
family?: "multiversx";
|
|
158
|
+
chainID: string;
|
|
159
|
+
denomination: number;
|
|
160
|
+
gasLimit: number;
|
|
161
|
+
gasPrice: number;
|
|
162
|
+
gasPerByte: number;
|
|
163
|
+
gasPriceModifier: string;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
export type NetworkInfoRaw = {
|
|
167
|
+
family?: "multiversx";
|
|
168
|
+
chainID: string;
|
|
169
|
+
denomination: number;
|
|
170
|
+
gasLimit: number;
|
|
171
|
+
gasPrice: number;
|
|
172
|
+
gasPerByte: number;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export type MultiversXPreloadData = {
|
|
176
|
+
validators: MultiversXProvider[];
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* MultiversX validator
|
|
181
|
+
*/
|
|
182
|
+
export type MultiversXProvider = {
|
|
183
|
+
contract: string;
|
|
184
|
+
owner: string;
|
|
185
|
+
serviceFee: string;
|
|
186
|
+
maxDelegationCap: string;
|
|
187
|
+
initialOwnerFunds: string;
|
|
188
|
+
totalActiveStake: string;
|
|
189
|
+
totalUnstaked: string;
|
|
190
|
+
maxDelegateAmountAllowed: string;
|
|
191
|
+
apr: string;
|
|
192
|
+
explorerURL: string;
|
|
193
|
+
address: string;
|
|
194
|
+
aprValue: number;
|
|
195
|
+
automaticActivation: boolean;
|
|
196
|
+
changeableServiceFee: boolean;
|
|
197
|
+
checkCapOnRedelegate: boolean;
|
|
198
|
+
createdNonce: number;
|
|
199
|
+
featured: boolean;
|
|
200
|
+
numNodes: number;
|
|
201
|
+
numUsers: number;
|
|
202
|
+
ownerBelowRequiredBalanceThreshold: boolean;
|
|
203
|
+
unBondPeriod: number;
|
|
204
|
+
withDelegationCap: boolean;
|
|
205
|
+
disabled?: boolean;
|
|
206
|
+
identity: {
|
|
207
|
+
key: string;
|
|
208
|
+
name: string;
|
|
209
|
+
avatar: string;
|
|
210
|
+
description: string;
|
|
211
|
+
location?: string;
|
|
212
|
+
twitter: string;
|
|
213
|
+
url: string;
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
export type MultiversXOperation = Operation<MultiversXOperationExtra>;
|
|
218
|
+
export type MultiversXOperationRaw = OperationRaw<MultiversXOperationExtraRaw>;
|
|
219
|
+
|
|
220
|
+
export type MultiversXOperationExtra = {
|
|
221
|
+
amount?: BigNumber;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
export function isMultiversXOperationExtra(op: OperationExtra): op is MultiversXOperationExtra {
|
|
225
|
+
return op !== null && typeof op === "object" && "amount" in op;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export type MultiversXOperationExtraRaw = {
|
|
229
|
+
amount?: string;
|
|
230
|
+
};
|
|
231
|
+
export function isMultiversXOperationExtraRaw(
|
|
232
|
+
op: OperationExtraRaw,
|
|
233
|
+
): op is MultiversXOperationExtraRaw {
|
|
234
|
+
return op !== null && typeof op === "object" && "amount" in op;
|
|
235
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
function base64DecodeBinary(str: string): Buffer {
|
|
2
|
+
return Buffer.from(str, "base64");
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export class BinaryUtils {
|
|
6
|
+
static base64Encode(str: string): string {
|
|
7
|
+
return Buffer.from(str).toString("base64");
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
static base64Decode(str: string): string {
|
|
11
|
+
return base64DecodeBinary(str).toString("binary");
|
|
12
|
+
}
|
|
13
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../tsconfig.base",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"declarationMap": true,
|
|
6
|
+
"downlevelIteration": true,
|
|
7
|
+
"lib": ["es2020", "dom"],
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"outDir": "lib",
|
|
10
|
+
"exactOptionalPropertyTypes": true
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*"]
|
|
13
|
+
}
|