@ledgerhq/coin-multiversx 0.2.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/.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
package/src/bridge/js.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import getAddressWrapper from "@ledgerhq/coin-framework/bridge/getAddressWrapper";
|
|
2
|
+
import {
|
|
3
|
+
getSerializedAddressParameters,
|
|
4
|
+
updateTransaction,
|
|
5
|
+
makeAccountBridgeReceive,
|
|
6
|
+
makeScanAccounts,
|
|
7
|
+
} from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
8
|
+
import { SignerContext } from "@ledgerhq/coin-framework/lib/signer";
|
|
9
|
+
import type { AccountBridge, CurrencyBridge } from "@ledgerhq/types-live";
|
|
10
|
+
import { broadcast } from "../broadcast";
|
|
11
|
+
import { createTransaction } from "../createTransaction";
|
|
12
|
+
import { estimateMaxSpendable } from "../estimateMaxSpendable";
|
|
13
|
+
import { getTransactionStatus } from "../getTransactionStatus";
|
|
14
|
+
import resolver from "../hw-getAddress";
|
|
15
|
+
import { getPreloadStrategy, hydrate, preload } from "../preload";
|
|
16
|
+
import { prepareTransaction } from "../prepareTransaction";
|
|
17
|
+
import {
|
|
18
|
+
assignFromAccountRaw,
|
|
19
|
+
assignToAccountRaw,
|
|
20
|
+
fromOperationExtraRaw,
|
|
21
|
+
toOperationExtraRaw,
|
|
22
|
+
} from "../serialization";
|
|
23
|
+
import { MultiversXSigner } from "../signer";
|
|
24
|
+
import { buildSignOperation } from "../signOperation";
|
|
25
|
+
import { getAccountShape, sync } from "../synchronisation";
|
|
26
|
+
import type { MultiversXAccount, Transaction, TransactionStatus } from "../types";
|
|
27
|
+
|
|
28
|
+
export function buildCurrencyBridge(
|
|
29
|
+
signerContext: SignerContext<MultiversXSigner>,
|
|
30
|
+
): CurrencyBridge {
|
|
31
|
+
const getAddress = resolver(signerContext);
|
|
32
|
+
|
|
33
|
+
const scanAccounts = makeScanAccounts({
|
|
34
|
+
getAccountShape,
|
|
35
|
+
getAddressFn: getAddress,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
getPreloadStrategy,
|
|
40
|
+
preload,
|
|
41
|
+
hydrate,
|
|
42
|
+
scanAccounts,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function buildAccountBridge(
|
|
47
|
+
signerContext: SignerContext<MultiversXSigner>,
|
|
48
|
+
): AccountBridge<Transaction, MultiversXAccount, TransactionStatus> {
|
|
49
|
+
const getAddress = resolver(signerContext);
|
|
50
|
+
|
|
51
|
+
const receive = makeAccountBridgeReceive(getAddressWrapper(getAddress));
|
|
52
|
+
const signOperation = buildSignOperation(signerContext);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
estimateMaxSpendable,
|
|
56
|
+
createTransaction,
|
|
57
|
+
updateTransaction,
|
|
58
|
+
getTransactionStatus,
|
|
59
|
+
prepareTransaction,
|
|
60
|
+
sync,
|
|
61
|
+
receive,
|
|
62
|
+
signOperation,
|
|
63
|
+
broadcast,
|
|
64
|
+
assignFromAccountRaw,
|
|
65
|
+
assignToAccountRaw,
|
|
66
|
+
fromOperationExtraRaw,
|
|
67
|
+
toOperationExtraRaw,
|
|
68
|
+
getSerializedAddressParameters,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function createBridges(signerContext: SignerContext<MultiversXSigner>) {
|
|
73
|
+
return {
|
|
74
|
+
currencyBridge: buildCurrencyBridge(signerContext),
|
|
75
|
+
accountBridge: buildAccountBridge(signerContext),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { InvalidAddressBecauseDestinationIsAlsoSource, NotEnoughBalance } from "@ledgerhq/errors";
|
|
2
|
+
import type { CurrenciesData, DatasetTest } from "@ledgerhq/types-live";
|
|
3
|
+
import { BigNumber } from "bignumber.js";
|
|
4
|
+
|
|
5
|
+
import { fromTransactionRaw } from "./transaction";
|
|
6
|
+
import type { Transaction } from "./types";
|
|
7
|
+
|
|
8
|
+
const TEST_ADDRESS = "erd1vgfp3g7azqjx4wsmtt7067m0l62v3psmqzr24j6xvywj2tlz0gesvyzsq2";
|
|
9
|
+
|
|
10
|
+
const elrond: CurrenciesData<Transaction> = {
|
|
11
|
+
FIXME_ignorePreloadFields: [
|
|
12
|
+
"validators", // They are always changing
|
|
13
|
+
],
|
|
14
|
+
scanAccounts: [
|
|
15
|
+
{
|
|
16
|
+
name: "multiversx seed 1",
|
|
17
|
+
apdus: `
|
|
18
|
+
=> ed030000080000000080000000
|
|
19
|
+
<= 3e6572643176676670336737617a716a783477736d7474373036376d306c3632763370736d717a7232346a36787679776a32746c7a3067657376797a7371329000
|
|
20
|
+
=> ed030000080000000080000000
|
|
21
|
+
<= 3e6572643176676670336737617a716a783477736d7474373036376d306c3632763370736d717a7232346a36787679776a32746c7a3067657376797a7371329000
|
|
22
|
+
=> ed030000080000000080000001
|
|
23
|
+
<= 3e65726431706d33676a65326c6d643576796c6463767579366a7078676465347261706a70756a76756a6b65653661376a77327a6d6834747172653739367a9000
|
|
24
|
+
`,
|
|
25
|
+
},
|
|
26
|
+
],
|
|
27
|
+
accounts: [
|
|
28
|
+
{
|
|
29
|
+
raw: {
|
|
30
|
+
id: `js:2:multiversx:${TEST_ADDRESS}:`,
|
|
31
|
+
seedIdentifier: `${TEST_ADDRESS}`,
|
|
32
|
+
name: "MultiversX 1",
|
|
33
|
+
derivationMode: "",
|
|
34
|
+
index: 0,
|
|
35
|
+
freshAddress: `${TEST_ADDRESS}`,
|
|
36
|
+
freshAddressPath: "44'/508'/0'/0'/0'",
|
|
37
|
+
blockHeight: 0,
|
|
38
|
+
operations: [],
|
|
39
|
+
pendingOperations: [],
|
|
40
|
+
currencyId: "elrond",
|
|
41
|
+
lastSyncDate: "",
|
|
42
|
+
balance: "299569965",
|
|
43
|
+
subAccounts: [
|
|
44
|
+
{
|
|
45
|
+
// MEX account
|
|
46
|
+
id: `js:2:multiversx:${TEST_ADDRESS}:+4d45582d343535633537`,
|
|
47
|
+
balance: "100",
|
|
48
|
+
spendableBalance: "100",
|
|
49
|
+
type: "TokenAccountRaw",
|
|
50
|
+
tokenId: "multiversx/esdt/4d45582d343535633537",
|
|
51
|
+
parentId: `js:2:multiversx:${TEST_ADDRESS}:`,
|
|
52
|
+
operations: [],
|
|
53
|
+
pendingOperations: [],
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
transactions: [
|
|
58
|
+
{
|
|
59
|
+
name: "recipient and sender must not be the same",
|
|
60
|
+
transaction: fromTransactionRaw({
|
|
61
|
+
family: "multiversx",
|
|
62
|
+
recipient: `${TEST_ADDRESS}`,
|
|
63
|
+
amount: "100000000",
|
|
64
|
+
mode: "send",
|
|
65
|
+
fees: null,
|
|
66
|
+
gasLimit: 50000000,
|
|
67
|
+
}),
|
|
68
|
+
expectedStatus: {
|
|
69
|
+
amount: new BigNumber("100000000"),
|
|
70
|
+
errors: {
|
|
71
|
+
recipient: new InvalidAddressBecauseDestinationIsAlsoSource(),
|
|
72
|
+
},
|
|
73
|
+
warnings: {},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
{
|
|
77
|
+
name: "Not enough balance",
|
|
78
|
+
transaction: fromTransactionRaw({
|
|
79
|
+
family: "multiversx",
|
|
80
|
+
recipient: "erd1frj909pfums4m8aza596595l9pl56crwdj077vs2aqcw6ynl28wsfkw9rd",
|
|
81
|
+
amount: "1000000000000000000000000",
|
|
82
|
+
mode: "send",
|
|
83
|
+
fees: null,
|
|
84
|
+
gasLimit: 50000000,
|
|
85
|
+
}),
|
|
86
|
+
expectedStatus: {
|
|
87
|
+
errors: {
|
|
88
|
+
amount: new NotEnoughBalance(),
|
|
89
|
+
},
|
|
90
|
+
warnings: {},
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: "Not enough balance (ESDT transfer)",
|
|
95
|
+
transaction: fromTransactionRaw({
|
|
96
|
+
family: "multiversx",
|
|
97
|
+
recipient: "erd1frj909pfums4m8aza596595l9pl56crwdj077vs2aqcw6ynl28wsfkw9rd",
|
|
98
|
+
amount: "1000000000000000000000000",
|
|
99
|
+
mode: "send",
|
|
100
|
+
fees: null,
|
|
101
|
+
gasLimit: 50000000,
|
|
102
|
+
subAccountId: `js:2:multiversx:${TEST_ADDRESS}:+4d45582d343535633537`,
|
|
103
|
+
}),
|
|
104
|
+
expectedStatus: {
|
|
105
|
+
errors: {
|
|
106
|
+
amount: new NotEnoughBalance(),
|
|
107
|
+
},
|
|
108
|
+
warnings: {},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: "Send max",
|
|
113
|
+
transaction: fromTransactionRaw({
|
|
114
|
+
family: "multiversx",
|
|
115
|
+
recipient: "erd1frj909pfums4m8aza596595l9pl56crwdj077vs2aqcw6ynl28wsfkw9rd",
|
|
116
|
+
useAllAmount: true,
|
|
117
|
+
amount: "0",
|
|
118
|
+
mode: "send",
|
|
119
|
+
fees: null,
|
|
120
|
+
gasLimit: 50000000,
|
|
121
|
+
}),
|
|
122
|
+
expectedStatus: (account, _, status) => {
|
|
123
|
+
return {
|
|
124
|
+
amount: account.balance.minus(status.estimatedFees),
|
|
125
|
+
warnings: {},
|
|
126
|
+
errors: {},
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
},
|
|
132
|
+
],
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const dataset: DatasetTest<Transaction> = {
|
|
136
|
+
implementations: ["js"],
|
|
137
|
+
currencies: {
|
|
138
|
+
// multiversx,
|
|
139
|
+
elrond,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
describe("MultiversX bridge", () => {
|
|
144
|
+
test.todo(
|
|
145
|
+
"This is an empty test to make jest command pass. Remove it once there is a real test.",
|
|
146
|
+
);
|
|
147
|
+
});
|
package/src/broadcast.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AccountBridge } from "@ledgerhq/types-live";
|
|
2
|
+
import { patchOperationWithHash } from "@ledgerhq/coin-framework/operation";
|
|
3
|
+
import { broadcastTransaction } from "./api";
|
|
4
|
+
import { Transaction } from "./types";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Broadcast the signed transaction
|
|
8
|
+
* @param {signature: string, operation: string} signedOperation
|
|
9
|
+
*/
|
|
10
|
+
export const broadcast: AccountBridge<Transaction>["broadcast"] = async ({ signedOperation }) => {
|
|
11
|
+
const hash = await broadcastTransaction(signedOperation);
|
|
12
|
+
|
|
13
|
+
return patchOperationWithHash(signedOperation.operation, hash);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export default broadcast;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { buildOptimisticOperation } from "./buildOptimisticOperation";
|
|
3
|
+
import { MultiversXAccount, MultiversXProtocolTransaction, Transaction } from "./types";
|
|
4
|
+
|
|
5
|
+
describe("buildOptimisticOperation", () => {
|
|
6
|
+
it("should work with mode = send", async () => {
|
|
7
|
+
const account = {
|
|
8
|
+
freshAddress: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th",
|
|
9
|
+
} as MultiversXAccount;
|
|
10
|
+
|
|
11
|
+
const transaction = {
|
|
12
|
+
family: "multiversx",
|
|
13
|
+
mode: "send",
|
|
14
|
+
fees: new BigNumber("1"),
|
|
15
|
+
amount: new BigNumber("42"),
|
|
16
|
+
recipient: "erd1spyavw0956vq68xj8y4tenjpq2wd5a9p2c6j8gsz7ztyrnpxrruqzu66jx",
|
|
17
|
+
} as Transaction;
|
|
18
|
+
|
|
19
|
+
const notSignedTransaction: MultiversXProtocolTransaction = {
|
|
20
|
+
nonce: 7,
|
|
21
|
+
} as MultiversXProtocolTransaction;
|
|
22
|
+
|
|
23
|
+
const operation = buildOptimisticOperation(account, transaction, notSignedTransaction);
|
|
24
|
+
|
|
25
|
+
expect(operation.type).toEqual("OUT");
|
|
26
|
+
expect(operation.value).toEqual(new BigNumber("43"));
|
|
27
|
+
expect(operation.fee).toEqual(new BigNumber("1"));
|
|
28
|
+
expect(operation.extra).toEqual({
|
|
29
|
+
amount: new BigNumber("0"),
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should work with mode = delegate", async () => {
|
|
34
|
+
const account = {
|
|
35
|
+
freshAddress: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th",
|
|
36
|
+
} as MultiversXAccount;
|
|
37
|
+
|
|
38
|
+
const transaction = {
|
|
39
|
+
family: "multiversx",
|
|
40
|
+
mode: "delegate",
|
|
41
|
+
fees: new BigNumber("1"),
|
|
42
|
+
amount: new BigNumber("42"),
|
|
43
|
+
recipient: "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqppllllls9ftvxy",
|
|
44
|
+
data: "delegate",
|
|
45
|
+
} as Transaction;
|
|
46
|
+
|
|
47
|
+
const notSignedTransaction: MultiversXProtocolTransaction = {
|
|
48
|
+
nonce: 7,
|
|
49
|
+
} as MultiversXProtocolTransaction;
|
|
50
|
+
|
|
51
|
+
const operation = buildOptimisticOperation(account, transaction, notSignedTransaction);
|
|
52
|
+
|
|
53
|
+
expect(operation.type).toEqual("DELEGATE");
|
|
54
|
+
expect(operation.value).toEqual(new BigNumber("43"));
|
|
55
|
+
expect(operation.fee).toEqual(new BigNumber("1"));
|
|
56
|
+
expect(operation.extra).toEqual({
|
|
57
|
+
amount: new BigNumber("42"),
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it("should work with mode = claimRewards", async () => {
|
|
62
|
+
const account = {
|
|
63
|
+
freshAddress: "erd1qyu5wthldzr8wx5c9ucg8kjagg0jfs53s8nr3zpz3hypefsdd8ssycr6th",
|
|
64
|
+
} as MultiversXAccount;
|
|
65
|
+
|
|
66
|
+
const transaction = {
|
|
67
|
+
family: "multiversx",
|
|
68
|
+
mode: "claimRewards",
|
|
69
|
+
fees: new BigNumber("1"),
|
|
70
|
+
amount: new BigNumber("42"),
|
|
71
|
+
recipient: "erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqppllllls9ftvxy",
|
|
72
|
+
data: "claimRewards",
|
|
73
|
+
} as Transaction;
|
|
74
|
+
|
|
75
|
+
const notSignedTransaction: MultiversXProtocolTransaction = {
|
|
76
|
+
nonce: 7,
|
|
77
|
+
} as MultiversXProtocolTransaction;
|
|
78
|
+
|
|
79
|
+
const operation = buildOptimisticOperation(account, transaction, notSignedTransaction);
|
|
80
|
+
|
|
81
|
+
expect(operation.type).toEqual("REWARD");
|
|
82
|
+
expect(operation.value).toEqual(new BigNumber("1"));
|
|
83
|
+
expect(operation.fee).toEqual(new BigNumber("1"));
|
|
84
|
+
expect(operation.extra).toEqual({
|
|
85
|
+
amount: new BigNumber("0"),
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
import { FeeNotLoaded } from "@ledgerhq/errors";
|
|
3
|
+
import { Address } from "@multiversx/sdk-core";
|
|
4
|
+
import { Operation, OperationType } from "@ledgerhq/types-live";
|
|
5
|
+
import { BinaryUtils } from "./utils/binary.utils";
|
|
6
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
7
|
+
import {
|
|
8
|
+
MultiversXAccount,
|
|
9
|
+
MultiversXProtocolTransaction,
|
|
10
|
+
MultiversXTransactionMode,
|
|
11
|
+
Transaction,
|
|
12
|
+
} from "./types";
|
|
13
|
+
|
|
14
|
+
function getOptimisticOperationType(transactionMode: MultiversXTransactionMode): OperationType {
|
|
15
|
+
switch (transactionMode) {
|
|
16
|
+
case "delegate":
|
|
17
|
+
return "DELEGATE";
|
|
18
|
+
case "unDelegate":
|
|
19
|
+
return "UNDELEGATE";
|
|
20
|
+
case "withdraw":
|
|
21
|
+
return "WITHDRAW_UNBONDED";
|
|
22
|
+
case "claimRewards":
|
|
23
|
+
return "REWARD";
|
|
24
|
+
case "reDelegateRewards":
|
|
25
|
+
return "DELEGATE";
|
|
26
|
+
default:
|
|
27
|
+
return "OUT";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getOptimisticOperationDelegationAmount(transaction: Transaction): BigNumber | undefined {
|
|
32
|
+
let dataDecoded;
|
|
33
|
+
switch (transaction.mode) {
|
|
34
|
+
case "delegate":
|
|
35
|
+
return transaction.amount;
|
|
36
|
+
|
|
37
|
+
case "unDelegate":
|
|
38
|
+
dataDecoded = BinaryUtils.base64Decode(transaction.data ?? "");
|
|
39
|
+
return new BigNumber(`0x${dataDecoded.split("@")[1]}`);
|
|
40
|
+
|
|
41
|
+
default:
|
|
42
|
+
return new BigNumber(0);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const buildOptimisticOperation = (
|
|
47
|
+
account: MultiversXAccount,
|
|
48
|
+
transaction: Transaction,
|
|
49
|
+
unsignedTx: MultiversXProtocolTransaction,
|
|
50
|
+
): Operation => {
|
|
51
|
+
const senders = [account.freshAddress];
|
|
52
|
+
const recipients = [transaction.recipient];
|
|
53
|
+
const { subAccountId, fees } = transaction;
|
|
54
|
+
|
|
55
|
+
if (!fees) {
|
|
56
|
+
throw new FeeNotLoaded();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const type = getOptimisticOperationType(transaction.mode);
|
|
60
|
+
|
|
61
|
+
const tokenAccount =
|
|
62
|
+
(subAccountId &&
|
|
63
|
+
account.subAccounts &&
|
|
64
|
+
account.subAccounts.find(ta => ta.id === subAccountId)) ||
|
|
65
|
+
null;
|
|
66
|
+
|
|
67
|
+
const value =
|
|
68
|
+
tokenAccount || (transaction.mode !== "send" && transaction.mode != "delegate")
|
|
69
|
+
? fees
|
|
70
|
+
: transaction.amount.plus(transaction.fees || new BigNumber(0));
|
|
71
|
+
|
|
72
|
+
const delegationAmount = getOptimisticOperationDelegationAmount(transaction);
|
|
73
|
+
|
|
74
|
+
const operation: Operation = {
|
|
75
|
+
id: encodeOperationId(account.id, "", type),
|
|
76
|
+
hash: "",
|
|
77
|
+
type,
|
|
78
|
+
value,
|
|
79
|
+
fee: fees,
|
|
80
|
+
blockHash: null,
|
|
81
|
+
blockHeight: null,
|
|
82
|
+
senders,
|
|
83
|
+
recipients,
|
|
84
|
+
accountId: account.id,
|
|
85
|
+
transactionSequenceNumber: unsignedTx.nonce,
|
|
86
|
+
date: new Date(),
|
|
87
|
+
extra: {
|
|
88
|
+
amount: delegationAmount,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const contract = new Address(transaction.recipient).isContractAddress()
|
|
93
|
+
? transaction.recipient
|
|
94
|
+
: undefined;
|
|
95
|
+
|
|
96
|
+
if (contract) {
|
|
97
|
+
operation.contract = contract;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (tokenAccount && subAccountId) {
|
|
101
|
+
operation.subOperations = [
|
|
102
|
+
{
|
|
103
|
+
id: encodeOperationId(subAccountId, "", "OUT"),
|
|
104
|
+
hash: "",
|
|
105
|
+
type: "OUT",
|
|
106
|
+
value: transaction.amount,
|
|
107
|
+
fee: new BigNumber(0),
|
|
108
|
+
blockHash: null,
|
|
109
|
+
blockHeight: null,
|
|
110
|
+
senders,
|
|
111
|
+
recipients,
|
|
112
|
+
accountId: subAccountId,
|
|
113
|
+
date: new Date(),
|
|
114
|
+
extra: {},
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return operation;
|
|
120
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { findTokenById, listTokensForCryptoCurrency } from "@ledgerhq/cryptoassets";
|
|
2
|
+
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets";
|
|
3
|
+
import { Account, SyncConfig, TokenAccount } from "@ledgerhq/types-live";
|
|
4
|
+
import BigNumber from "bignumber.js";
|
|
5
|
+
import { emptyHistoryCache, encodeTokenAccountId } from "@ledgerhq/coin-framework/account/index";
|
|
6
|
+
import { mergeOps } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
7
|
+
import { getESDTOperations, getAccountESDTTokens } from "./api";
|
|
8
|
+
import { addPrefixToken, extractTokenId } from "./logic";
|
|
9
|
+
|
|
10
|
+
async function buildMultiversXESDTTokenAccount({
|
|
11
|
+
parentAccountId,
|
|
12
|
+
accountAddress,
|
|
13
|
+
token,
|
|
14
|
+
balance,
|
|
15
|
+
}: {
|
|
16
|
+
parentAccountId: string;
|
|
17
|
+
accountAddress: string;
|
|
18
|
+
token: TokenCurrency;
|
|
19
|
+
balance: BigNumber;
|
|
20
|
+
}) {
|
|
21
|
+
const tokenAccountId = encodeTokenAccountId(parentAccountId, token);
|
|
22
|
+
const tokenIdentifierHex = extractTokenId(token.id);
|
|
23
|
+
const tokenIdentifier = Buffer.from(tokenIdentifierHex, "hex").toString();
|
|
24
|
+
|
|
25
|
+
const operations = await getESDTOperations(tokenAccountId, accountAddress, tokenIdentifier, 0);
|
|
26
|
+
|
|
27
|
+
const tokenAccount: TokenAccount = {
|
|
28
|
+
type: "TokenAccount",
|
|
29
|
+
id: tokenAccountId,
|
|
30
|
+
parentId: parentAccountId,
|
|
31
|
+
token,
|
|
32
|
+
operationsCount: operations.length,
|
|
33
|
+
operations,
|
|
34
|
+
pendingOperations: [],
|
|
35
|
+
balance,
|
|
36
|
+
spendableBalance: balance,
|
|
37
|
+
swapHistory: [],
|
|
38
|
+
creationDate: operations.length > 0 ? operations[operations.length - 1].date : new Date(),
|
|
39
|
+
balanceHistoryCache: emptyHistoryCache, // calculated in the jsHelpers
|
|
40
|
+
};
|
|
41
|
+
return tokenAccount;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function syncESDTTokenAccountOperations(
|
|
45
|
+
tokenAccount: TokenAccount,
|
|
46
|
+
address: string,
|
|
47
|
+
): Promise<TokenAccount> {
|
|
48
|
+
const oldOperations = tokenAccount?.operations || [];
|
|
49
|
+
// Needed for incremental synchronisation
|
|
50
|
+
const startAt = oldOperations.length ? Math.floor(oldOperations[0].date.valueOf() / 1000) : 0;
|
|
51
|
+
|
|
52
|
+
const tokenIdentifierHex = extractTokenId(tokenAccount.token.id);
|
|
53
|
+
const tokenIdentifier = Buffer.from(tokenIdentifierHex, "hex").toString();
|
|
54
|
+
|
|
55
|
+
// Merge new operations with the previously synced ones
|
|
56
|
+
const newOperations = await getESDTOperations(tokenAccount.id, address, tokenIdentifier, startAt);
|
|
57
|
+
const operations = mergeOps(oldOperations, newOperations);
|
|
58
|
+
|
|
59
|
+
if (operations === oldOperations) return tokenAccount;
|
|
60
|
+
|
|
61
|
+
const copy = { ...tokenAccount };
|
|
62
|
+
copy.operations = operations;
|
|
63
|
+
copy.operationsCount = operations.length;
|
|
64
|
+
return copy;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function MultiversXBuildESDTTokenAccounts({
|
|
68
|
+
currency,
|
|
69
|
+
accountId,
|
|
70
|
+
accountAddress,
|
|
71
|
+
existingAccount,
|
|
72
|
+
syncConfig,
|
|
73
|
+
}: {
|
|
74
|
+
currency: CryptoCurrency;
|
|
75
|
+
accountId: string;
|
|
76
|
+
accountAddress: string;
|
|
77
|
+
existingAccount: Account | null | undefined;
|
|
78
|
+
syncConfig: SyncConfig;
|
|
79
|
+
}): Promise<TokenAccount[] | undefined> {
|
|
80
|
+
const { blacklistedTokenIds = [] } = syncConfig;
|
|
81
|
+
if (listTokensForCryptoCurrency(currency).length === 0) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const tokenAccounts: TokenAccount[] = [];
|
|
86
|
+
|
|
87
|
+
const existingAccountByTicker: { [key: string]: TokenAccount } = {}; // used for fast lookup
|
|
88
|
+
|
|
89
|
+
const existingAccountTickers: string[] = []; // used to keep track of ordering
|
|
90
|
+
|
|
91
|
+
if (existingAccount && existingAccount.subAccounts) {
|
|
92
|
+
for (const existingSubAccount of existingAccount.subAccounts) {
|
|
93
|
+
if (existingSubAccount.type === "TokenAccount") {
|
|
94
|
+
const { ticker, id } = existingSubAccount.token;
|
|
95
|
+
|
|
96
|
+
if (!blacklistedTokenIds.includes(id)) {
|
|
97
|
+
existingAccountTickers.push(ticker);
|
|
98
|
+
existingAccountByTicker[ticker] = existingSubAccount;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const accountESDTs = await getAccountESDTTokens(accountAddress);
|
|
105
|
+
for (const esdt of accountESDTs) {
|
|
106
|
+
const esdtIdentifierHex = Buffer.from(esdt.identifier).toString("hex");
|
|
107
|
+
const token = findTokenById(addPrefixToken(esdtIdentifierHex));
|
|
108
|
+
|
|
109
|
+
if (token && !blacklistedTokenIds.includes(token.id)) {
|
|
110
|
+
let tokenAccount = existingAccountByTicker[token.ticker];
|
|
111
|
+
if (!tokenAccount) {
|
|
112
|
+
tokenAccount = await buildMultiversXESDTTokenAccount({
|
|
113
|
+
parentAccountId: accountId,
|
|
114
|
+
accountAddress,
|
|
115
|
+
token,
|
|
116
|
+
balance: new BigNumber(esdt.balance),
|
|
117
|
+
});
|
|
118
|
+
} else {
|
|
119
|
+
const inputTokenAccount = tokenAccount;
|
|
120
|
+
tokenAccount = await syncESDTTokenAccountOperations(inputTokenAccount, accountAddress);
|
|
121
|
+
const balance = new BigNumber(esdt.balance);
|
|
122
|
+
if (!balance.eq(tokenAccount.balance)) {
|
|
123
|
+
// only recreate the object if balance changed
|
|
124
|
+
if (inputTokenAccount === tokenAccount) {
|
|
125
|
+
tokenAccount = { ...tokenAccount };
|
|
126
|
+
}
|
|
127
|
+
tokenAccount.balance = balance;
|
|
128
|
+
tokenAccount.spendableBalance = balance;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (tokenAccount) {
|
|
133
|
+
tokenAccounts.push(tokenAccount);
|
|
134
|
+
existingAccountTickers.push(token.ticker);
|
|
135
|
+
existingAccountByTicker[token.ticker] = tokenAccount;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Preserve order of tokenAccounts from the existing token accounts
|
|
141
|
+
tokenAccounts.sort((a, b) => {
|
|
142
|
+
const i = existingAccountTickers.indexOf(a.token.ticker);
|
|
143
|
+
const j = existingAccountTickers.indexOf(b.token.ticker);
|
|
144
|
+
if (i === j) return 0;
|
|
145
|
+
if (i < 0) return 1;
|
|
146
|
+
if (j < 0) return -1;
|
|
147
|
+
return i - j;
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return tokenAccounts;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export default MultiversXBuildESDTTokenAccounts;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { IGasLimit, INetworkConfig, INonce } from "@multiversx/sdk-core";
|
|
2
|
+
import { Account } from "@ledgerhq/types-live";
|
|
3
|
+
import { getAccountNonce, getNetworkConfig } from "./api";
|
|
4
|
+
import {
|
|
5
|
+
GAS_PRICE,
|
|
6
|
+
TRANSACTION_OPTIONS_TX_HASH_SIGN,
|
|
7
|
+
TRANSACTION_VERSION_DEFAULT,
|
|
8
|
+
} from "./constants";
|
|
9
|
+
import { isAmountSpentFromBalance } from "./logic";
|
|
10
|
+
import type { MultiversXProtocolTransaction, Transaction } from "./types";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
*
|
|
14
|
+
* @param {MultiversXAccount} account
|
|
15
|
+
* @param {SubAccount | null | undefined} tokenAccount
|
|
16
|
+
* @param {Transaction} transaction
|
|
17
|
+
*/
|
|
18
|
+
export const buildTransactionToSign = async (
|
|
19
|
+
account: Account,
|
|
20
|
+
transaction: Transaction,
|
|
21
|
+
): Promise<string> => {
|
|
22
|
+
const sender = account.freshAddress;
|
|
23
|
+
const nonce = await getAccountNonce(sender);
|
|
24
|
+
const networkConfig: INetworkConfig = await getNetworkConfig();
|
|
25
|
+
const chainID = networkConfig.ChainID.valueOf();
|
|
26
|
+
|
|
27
|
+
const isTokenAccount = account.subAccounts?.some(ta => ta.id === transaction.subAccountId);
|
|
28
|
+
const value =
|
|
29
|
+
!isTokenAccount && isAmountSpentFromBalance(transaction.mode)
|
|
30
|
+
? transaction.amount.toFixed()
|
|
31
|
+
: "0";
|
|
32
|
+
|
|
33
|
+
return doBuildTransactionToSign({
|
|
34
|
+
transaction,
|
|
35
|
+
sender: sender,
|
|
36
|
+
nonce,
|
|
37
|
+
value,
|
|
38
|
+
minGasLimit: networkConfig.MinGasLimit,
|
|
39
|
+
chainID,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const doBuildTransactionToSign = async (options: {
|
|
44
|
+
transaction: Transaction;
|
|
45
|
+
sender: string;
|
|
46
|
+
nonce: INonce;
|
|
47
|
+
value: string;
|
|
48
|
+
minGasLimit: IGasLimit;
|
|
49
|
+
chainID: string;
|
|
50
|
+
}): Promise<string> => {
|
|
51
|
+
const gasLimit = options.transaction.gasLimit || options.minGasLimit.valueOf();
|
|
52
|
+
|
|
53
|
+
const transaction: MultiversXProtocolTransaction = {
|
|
54
|
+
nonce: options.nonce.valueOf(),
|
|
55
|
+
value: options.value,
|
|
56
|
+
receiver: options.transaction.recipient,
|
|
57
|
+
sender: options.sender,
|
|
58
|
+
gasPrice: GAS_PRICE,
|
|
59
|
+
gasLimit: gasLimit,
|
|
60
|
+
...(options.transaction.data ? { data: options.transaction.data } : {}),
|
|
61
|
+
chainID: options.chainID,
|
|
62
|
+
version: TRANSACTION_VERSION_DEFAULT,
|
|
63
|
+
options: TRANSACTION_OPTIONS_TX_HASH_SIGN,
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
return JSON.stringify(transaction);
|
|
67
|
+
};
|