@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
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import network from "@ledgerhq/live-network";
|
|
2
|
+
import { SignedOperation } from "@ledgerhq/types-live/src";
|
|
3
|
+
import { MAX_PAGINATION_SIZE, METACHAIN_SHARD } from "../constants";
|
|
4
|
+
import {
|
|
5
|
+
ESDTToken,
|
|
6
|
+
MultiversXApiTransaction,
|
|
7
|
+
MultiversXDelegation,
|
|
8
|
+
MultiversXProvider,
|
|
9
|
+
MultiversXTransactionAction,
|
|
10
|
+
MultiversXTransactionMode,
|
|
11
|
+
MultiversXTransferOptions,
|
|
12
|
+
NetworkInfo,
|
|
13
|
+
} from "../types";
|
|
14
|
+
import { MultiversXAccount } from "./dtos/multiversx-account";
|
|
15
|
+
|
|
16
|
+
interface NetworkInfoResponse {
|
|
17
|
+
data: {
|
|
18
|
+
config: {
|
|
19
|
+
erd_chain_id: string;
|
|
20
|
+
erd_denomination: number;
|
|
21
|
+
erd_min_gas_limit: number;
|
|
22
|
+
erd_min_gas_price: number;
|
|
23
|
+
erd_gas_per_data_byte: number;
|
|
24
|
+
erd_gas_price_modifier: string;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface SubmitTransactionResponse {
|
|
30
|
+
data: {
|
|
31
|
+
txHash: string;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
interface BlockRoundResponse {
|
|
36
|
+
round: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const decodeTransactionMode = (action?: MultiversXTransactionAction): string => {
|
|
40
|
+
if (!action) {
|
|
41
|
+
return "send";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!action.category) {
|
|
45
|
+
return "send";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (action.category !== "stake") {
|
|
49
|
+
return "send";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const mode = action.name;
|
|
53
|
+
|
|
54
|
+
return mode;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default class MultiversXApi {
|
|
58
|
+
private API_URL: string;
|
|
59
|
+
private DELEGATION_API_URL: string;
|
|
60
|
+
|
|
61
|
+
constructor(API_URL: string, DELEGATION_API_URL: string) {
|
|
62
|
+
this.API_URL = API_URL;
|
|
63
|
+
this.DELEGATION_API_URL = DELEGATION_API_URL;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async getAccountDetails(addr: string) {
|
|
67
|
+
const {
|
|
68
|
+
data: { balance, nonce, isGuarded },
|
|
69
|
+
} = await network<MultiversXAccount>({
|
|
70
|
+
method: "GET",
|
|
71
|
+
url: `${this.API_URL}/accounts/${addr}?withGuardianInfo=true`,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
balance,
|
|
76
|
+
nonce,
|
|
77
|
+
isGuarded,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async getProviders(): Promise<MultiversXProvider[]> {
|
|
82
|
+
const { data: providers } = await network<MultiversXProvider[]>({
|
|
83
|
+
method: "GET",
|
|
84
|
+
url: `${this.DELEGATION_API_URL}/providers`,
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
return providers;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async getNetworkConfig(): Promise<NetworkInfo> {
|
|
91
|
+
const {
|
|
92
|
+
data: {
|
|
93
|
+
data: {
|
|
94
|
+
config: {
|
|
95
|
+
erd_chain_id: chainId,
|
|
96
|
+
erd_denomination: denomination,
|
|
97
|
+
erd_min_gas_limit: gasLimit,
|
|
98
|
+
erd_min_gas_price: gasPrice,
|
|
99
|
+
erd_gas_per_data_byte: gasPerByte,
|
|
100
|
+
erd_gas_price_modifier: gasPriceModifier,
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
} = await network<NetworkInfoResponse>({
|
|
105
|
+
method: "GET",
|
|
106
|
+
url: `${this.API_URL}/network/config`,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
return {
|
|
110
|
+
chainID: chainId,
|
|
111
|
+
denomination,
|
|
112
|
+
gasLimit,
|
|
113
|
+
gasPrice,
|
|
114
|
+
gasPerByte,
|
|
115
|
+
gasPriceModifier,
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async submit(signedOperation: SignedOperation): Promise<string> {
|
|
120
|
+
const transaction = {
|
|
121
|
+
...signedOperation.rawData,
|
|
122
|
+
signature: signedOperation.signature,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
const {
|
|
126
|
+
data: {
|
|
127
|
+
data: { txHash: hash },
|
|
128
|
+
},
|
|
129
|
+
} = await network<SubmitTransactionResponse>({
|
|
130
|
+
method: "POST",
|
|
131
|
+
url: `${this.API_URL}/transaction/send`,
|
|
132
|
+
data: transaction,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
return hash;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
async getHistory(addr: string, startAt: number): Promise<MultiversXApiTransaction[]> {
|
|
139
|
+
const { data: transactionsCount } = await network<number>({
|
|
140
|
+
method: "GET",
|
|
141
|
+
url: `${this.API_URL}/accounts/${addr}/transactions/count?after=${startAt}`,
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
let allTransactions: MultiversXApiTransaction[] = [];
|
|
145
|
+
let from = 0;
|
|
146
|
+
while (from < transactionsCount) {
|
|
147
|
+
const { data: transactions } = await network<MultiversXApiTransaction[]>({
|
|
148
|
+
method: "GET",
|
|
149
|
+
url: `${this.API_URL}/accounts/${addr}/transactions?after=${startAt}&from=${from}&size=${MAX_PAGINATION_SIZE}&withOperations=true&withScResults=true`,
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
for (const transaction of transactions) {
|
|
153
|
+
transaction.mode = decodeTransactionMode(transaction.action) as MultiversXTransactionMode;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
allTransactions = [...allTransactions, ...transactions];
|
|
157
|
+
|
|
158
|
+
from = from + MAX_PAGINATION_SIZE;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return allTransactions;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
async getAccountDelegations(addr: string): Promise<MultiversXDelegation[]> {
|
|
165
|
+
const { data: delegations } = await network<MultiversXDelegation[]>({
|
|
166
|
+
method: "GET",
|
|
167
|
+
url: `${this.DELEGATION_API_URL}/accounts/${addr}/delegations`,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
return delegations;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async getESDTTransactionsForAddress(
|
|
174
|
+
addr: string,
|
|
175
|
+
token: string,
|
|
176
|
+
startAt: number,
|
|
177
|
+
): Promise<MultiversXApiTransaction[]> {
|
|
178
|
+
const { data: tokenTransactionsCount } = await network<number>({
|
|
179
|
+
method: "GET",
|
|
180
|
+
url: `${this.API_URL}/accounts/${addr}/transactions/count?token=${token}&after=${startAt}`,
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
let allTokenTransactions: MultiversXApiTransaction[] = [];
|
|
184
|
+
let from = 0;
|
|
185
|
+
while (from < tokenTransactionsCount) {
|
|
186
|
+
const { data: tokenTransactions } = await network<MultiversXApiTransaction[]>({
|
|
187
|
+
method: "GET",
|
|
188
|
+
url: `${this.API_URL}/accounts/${addr}/transactions?token=${token}&from=${from}&after=${startAt}&size=${MAX_PAGINATION_SIZE}`,
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
allTokenTransactions = [...allTokenTransactions, ...tokenTransactions];
|
|
192
|
+
|
|
193
|
+
from = from + MAX_PAGINATION_SIZE;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
for (const esdtTransaction of allTokenTransactions) {
|
|
197
|
+
esdtTransaction.transfer = MultiversXTransferOptions.esdt;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return allTokenTransactions;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async getESDTTokensForAddress(addr: string): Promise<ESDTToken[]> {
|
|
204
|
+
const { data: tokensCount } = await network<number>({
|
|
205
|
+
method: "GET",
|
|
206
|
+
url: `${this.API_URL}/accounts/${addr}/tokens/count`,
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
let allTokens: ESDTToken[] = [];
|
|
210
|
+
let from = 0;
|
|
211
|
+
while (from < tokensCount) {
|
|
212
|
+
const { data: tokens } = await network<ESDTToken[]>({
|
|
213
|
+
method: "GET",
|
|
214
|
+
url: `${this.API_URL}/accounts/${addr}/tokens?from=${from}&size=${MAX_PAGINATION_SIZE}`,
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
allTokens = [...allTokens, ...tokens];
|
|
218
|
+
|
|
219
|
+
from = from + MAX_PAGINATION_SIZE;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return allTokens;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async getESDTTokensCountForAddress(addr: string): Promise<number> {
|
|
226
|
+
const { data: tokensCount } = await network<number>({
|
|
227
|
+
method: "GET",
|
|
228
|
+
url: `${this.API_URL}/accounts/${addr}/tokens/count`,
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
return tokensCount;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async getBlockchainBlockHeight(): Promise<number> {
|
|
235
|
+
const {
|
|
236
|
+
data: [{ round: blockHeight }],
|
|
237
|
+
} = await network<BlockRoundResponse[]>({
|
|
238
|
+
method: "GET",
|
|
239
|
+
url: `${this.API_URL}/blocks?shard=${METACHAIN_SHARD}&fields=round`,
|
|
240
|
+
});
|
|
241
|
+
return blockHeight;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import BigNumber from "bignumber.js";
|
|
2
|
+
|
|
3
|
+
export class MultiversXAccount {
|
|
4
|
+
balance: BigNumber;
|
|
5
|
+
nonce: number;
|
|
6
|
+
isGuarded: boolean;
|
|
7
|
+
blockHeight: number;
|
|
8
|
+
|
|
9
|
+
constructor(
|
|
10
|
+
balance: BigNumber,
|
|
11
|
+
nonce: number,
|
|
12
|
+
isGuarded: boolean | null | undefined,
|
|
13
|
+
blockHeight: number,
|
|
14
|
+
) {
|
|
15
|
+
this.balance = balance;
|
|
16
|
+
this.nonce = nonce;
|
|
17
|
+
this.isGuarded = isGuarded ? true : false;
|
|
18
|
+
this.blockHeight = blockHeight;
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/api/index.ts
ADDED
package/src/api/sdk.ts
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
import { encodeOperationId } from "@ledgerhq/coin-framework/operation";
|
|
2
|
+
import { inferSubOperations } from "@ledgerhq/coin-framework/serialization/index";
|
|
3
|
+
import { getAbandonSeedAddress } from "@ledgerhq/cryptoassets";
|
|
4
|
+
import { getEnv } from "@ledgerhq/live-env";
|
|
5
|
+
import type { OperationType, SignedOperation, TokenAccount } from "@ledgerhq/types-live";
|
|
6
|
+
import {
|
|
7
|
+
Address,
|
|
8
|
+
ApiNetworkProvider,
|
|
9
|
+
INetworkConfig,
|
|
10
|
+
INonce,
|
|
11
|
+
Transaction as MultiversXSdkTransaction,
|
|
12
|
+
TransactionPayload,
|
|
13
|
+
} from "@multiversx/sdk-core";
|
|
14
|
+
import { BigNumber } from "bignumber.js";
|
|
15
|
+
import {
|
|
16
|
+
CHAIN_ID,
|
|
17
|
+
GAS_PER_DATA_BYTE,
|
|
18
|
+
GAS_PRICE,
|
|
19
|
+
GAS_PRICE_MODIFIER,
|
|
20
|
+
MIN_GAS_LIMIT,
|
|
21
|
+
MULTIVERSX_STAKING_POOL,
|
|
22
|
+
} from "../constants";
|
|
23
|
+
import {
|
|
24
|
+
ESDTToken,
|
|
25
|
+
MultiversXApiTransaction,
|
|
26
|
+
MultiversXDelegation,
|
|
27
|
+
MultiversXOperation,
|
|
28
|
+
MultiversXProvider,
|
|
29
|
+
MultiversXTransactionOperation,
|
|
30
|
+
MultiversXTransferOptions,
|
|
31
|
+
Transaction,
|
|
32
|
+
} from "../types";
|
|
33
|
+
import { BinaryUtils } from "../utils/binary.utils";
|
|
34
|
+
import MultiversXApi from "./apiCalls";
|
|
35
|
+
import { MultiversXAccount } from "./dtos/multiversx-account";
|
|
36
|
+
const api = new MultiversXApi(
|
|
37
|
+
getEnv("MULTIVERSX_API_ENDPOINT"),
|
|
38
|
+
getEnv("MULTIVERSX_DELEGATION_API_ENDPOINT"),
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const networkConfig = { clientName: "ledger-live" };
|
|
42
|
+
const proxy = new ApiNetworkProvider(getEnv("MULTIVERSX_API_ENDPOINT"), networkConfig);
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Get account balances and nonce
|
|
46
|
+
*/
|
|
47
|
+
export const getAccount = async (addr: string): Promise<MultiversXAccount> => {
|
|
48
|
+
const { balance, nonce, isGuarded } = await api.getAccountDetails(addr);
|
|
49
|
+
const blockHeight = await api.getBlockchainBlockHeight();
|
|
50
|
+
|
|
51
|
+
const account = new MultiversXAccount(new BigNumber(balance), nonce, isGuarded, blockHeight);
|
|
52
|
+
return account;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const getProviders = async (): Promise<MultiversXProvider[]> => {
|
|
56
|
+
const providers = await api.getProviders();
|
|
57
|
+
return providers;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export const getNetworkConfig = async (): Promise<INetworkConfig> => {
|
|
61
|
+
return await proxy.getNetworkConfig();
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const getAccountNonce = async (addr: string): Promise<INonce> => {
|
|
65
|
+
const address = new Address(addr);
|
|
66
|
+
|
|
67
|
+
const account = await proxy.getAccount(address);
|
|
68
|
+
|
|
69
|
+
return account.nonce;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Returns true if account is the signer
|
|
74
|
+
*/
|
|
75
|
+
function isSender(transaction: MultiversXApiTransaction, addr: string): boolean {
|
|
76
|
+
return transaction.sender === addr;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function isSelfSend(transaction: MultiversXApiTransaction): boolean {
|
|
80
|
+
return (
|
|
81
|
+
!!transaction.sender && !!transaction.receiver && transaction.sender === transaction.receiver
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Map transaction to an Operation Type
|
|
87
|
+
*/
|
|
88
|
+
function getEGLDOperationType(transaction: MultiversXApiTransaction, addr: string): OperationType {
|
|
89
|
+
if (transaction.action && transaction.action.category == "stake") {
|
|
90
|
+
const stakeAction = transaction.action.name;
|
|
91
|
+
switch (stakeAction) {
|
|
92
|
+
case "delegate":
|
|
93
|
+
return "DELEGATE";
|
|
94
|
+
case "unDelegate":
|
|
95
|
+
return "UNDELEGATE";
|
|
96
|
+
case "withdraw":
|
|
97
|
+
return "WITHDRAW_UNBONDED";
|
|
98
|
+
case "claimRewards":
|
|
99
|
+
return "REWARD";
|
|
100
|
+
case "reDelegateRewards":
|
|
101
|
+
return "DELEGATE";
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return isSender(transaction, addr)
|
|
105
|
+
? transaction.transfer === MultiversXTransferOptions.esdt
|
|
106
|
+
? "FEES"
|
|
107
|
+
: "OUT"
|
|
108
|
+
: "IN";
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function getESDTOperationValue(
|
|
112
|
+
transaction: MultiversXApiTransaction,
|
|
113
|
+
tokenIdentifier?: string,
|
|
114
|
+
): BigNumber {
|
|
115
|
+
const hasFailed =
|
|
116
|
+
!transaction.status || transaction.status === "fail" || transaction.status === "invalid";
|
|
117
|
+
|
|
118
|
+
if (!transaction.action || hasFailed) {
|
|
119
|
+
return new BigNumber(0);
|
|
120
|
+
}
|
|
121
|
+
let token1, token2;
|
|
122
|
+
switch (transaction.action.name) {
|
|
123
|
+
case "transfer":
|
|
124
|
+
return new BigNumber(transaction.action.arguments.transfers[0].value ?? 0);
|
|
125
|
+
case "swap":
|
|
126
|
+
token1 = transaction.action.arguments.transfers[0];
|
|
127
|
+
token2 = transaction.action.arguments.transfers[1];
|
|
128
|
+
if (token1.token === tokenIdentifier) {
|
|
129
|
+
return new BigNumber(token1.value);
|
|
130
|
+
} else {
|
|
131
|
+
return new BigNumber(token2.value);
|
|
132
|
+
}
|
|
133
|
+
default:
|
|
134
|
+
return new BigNumber(transaction.tokenValue ?? 0);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
function getStakingAmount(transaction: MultiversXApiTransaction, address: string): BigNumber {
|
|
139
|
+
const operation: MultiversXTransactionOperation | undefined = transaction.operations?.find(
|
|
140
|
+
({ sender, receiver, action, type }) =>
|
|
141
|
+
action == "transfer" &&
|
|
142
|
+
type == "egld" &&
|
|
143
|
+
sender == transaction.receiver &&
|
|
144
|
+
(receiver == address || receiver == MULTIVERSX_STAKING_POOL),
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
let dataDecoded;
|
|
148
|
+
switch (transaction.mode) {
|
|
149
|
+
case "send":
|
|
150
|
+
return new BigNumber(0);
|
|
151
|
+
case "delegate":
|
|
152
|
+
return new BigNumber(transaction.value ?? 0);
|
|
153
|
+
case "unDelegate":
|
|
154
|
+
dataDecoded = BinaryUtils.base64Decode(transaction.data ?? "");
|
|
155
|
+
return new BigNumber(`0x${dataDecoded.split("@")[1]}`);
|
|
156
|
+
case "reDelegateRewards":
|
|
157
|
+
case "claimRewards":
|
|
158
|
+
case "withdraw":
|
|
159
|
+
default:
|
|
160
|
+
return new BigNumber(operation?.value ?? new BigNumber(0));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Map transaction to a correct Operation Value (affecting account balance)
|
|
166
|
+
*/
|
|
167
|
+
function getEGLDOperationValue(transaction: MultiversXApiTransaction, address: string): BigNumber {
|
|
168
|
+
if (transaction.mode === "send") {
|
|
169
|
+
if (transaction.transfer === MultiversXTransferOptions.esdt) {
|
|
170
|
+
// Only fees paid in EGLD for token transactions
|
|
171
|
+
return isSender(transaction, address) && transaction.fee
|
|
172
|
+
? new BigNumber(transaction.fee)
|
|
173
|
+
: new BigNumber(0);
|
|
174
|
+
} else {
|
|
175
|
+
return isSender(transaction, address)
|
|
176
|
+
? isSelfSend(transaction)
|
|
177
|
+
? new BigNumber(transaction.fee ?? 0) // Self-send, only fees are paid
|
|
178
|
+
: new BigNumber(transaction.value ?? 0).plus(transaction.fee ?? 0) // The sender pays the amount and the fees
|
|
179
|
+
: new BigNumber(transaction.value ?? 0); // The recipient gets the amount
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
// Operation value for staking transactions are just the fees, plus possible rewards
|
|
183
|
+
// Other amounts are put in extra.amount
|
|
184
|
+
return new BigNumber(transaction.fee ?? 0);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Map the MultiversX history transaction to a Ledger Live Operation
|
|
190
|
+
*/
|
|
191
|
+
function transactionToEGLDOperation(
|
|
192
|
+
accountId: string,
|
|
193
|
+
addr: string,
|
|
194
|
+
transaction: MultiversXApiTransaction,
|
|
195
|
+
subAccounts: TokenAccount[],
|
|
196
|
+
): MultiversXOperation {
|
|
197
|
+
const type = getEGLDOperationType(transaction, addr);
|
|
198
|
+
const fee = new BigNumber(transaction.fee ?? 0);
|
|
199
|
+
const hasFailed =
|
|
200
|
+
!transaction.status || transaction.status === "fail" || transaction.status === "invalid";
|
|
201
|
+
|
|
202
|
+
const delegationAmount = getStakingAmount(transaction, addr);
|
|
203
|
+
|
|
204
|
+
const value = hasFailed
|
|
205
|
+
? isSender(transaction, addr)
|
|
206
|
+
? fee
|
|
207
|
+
: new BigNumber(0)
|
|
208
|
+
: transaction.mode === "claimRewards"
|
|
209
|
+
? delegationAmount.minus(fee)
|
|
210
|
+
: getEGLDOperationValue(transaction, addr);
|
|
211
|
+
|
|
212
|
+
const operation: MultiversXOperation = {
|
|
213
|
+
id: encodeOperationId(accountId, transaction.txHash ?? "", type),
|
|
214
|
+
accountId,
|
|
215
|
+
fee,
|
|
216
|
+
value,
|
|
217
|
+
type,
|
|
218
|
+
hash: transaction.txHash ?? "",
|
|
219
|
+
blockHash: transaction.miniBlockHash,
|
|
220
|
+
blockHeight: transaction.round,
|
|
221
|
+
date: new Date(transaction.timestamp ? transaction.timestamp * 1000 : 0),
|
|
222
|
+
extra: {
|
|
223
|
+
amount: delegationAmount,
|
|
224
|
+
},
|
|
225
|
+
senders: (type == "OUT" || type == "IN") && transaction.sender ? [transaction.sender] : [],
|
|
226
|
+
recipients:
|
|
227
|
+
(type == "OUT" || type == "IN") && transaction.receiver ? [transaction.receiver] : [],
|
|
228
|
+
transactionSequenceNumber: isSender(transaction, addr) ? transaction.nonce : undefined,
|
|
229
|
+
hasFailed,
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
const subOperations = subAccounts
|
|
233
|
+
? inferSubOperations(transaction.txHash ?? "", subAccounts)
|
|
234
|
+
: undefined;
|
|
235
|
+
|
|
236
|
+
if (subOperations) {
|
|
237
|
+
operation.subOperations = subOperations;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
let contract: string | undefined = undefined;
|
|
241
|
+
if (transaction.receiver) {
|
|
242
|
+
const isReceiverSmartContract = Address.newFromBech32(transaction.receiver).isSmartContract();
|
|
243
|
+
|
|
244
|
+
contract = isReceiverSmartContract ? transaction.receiver : undefined;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
if (contract) {
|
|
248
|
+
operation.contract = contract;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return operation;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
const getESDTOperationType = (
|
|
255
|
+
transaction: MultiversXApiTransaction,
|
|
256
|
+
address: string,
|
|
257
|
+
): OperationType => {
|
|
258
|
+
return isSender(transaction, address) ? "OUT" : "IN";
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const transactionToESDTOperation = (
|
|
262
|
+
tokenAccountId: string,
|
|
263
|
+
addr: string,
|
|
264
|
+
transaction: MultiversXApiTransaction,
|
|
265
|
+
tokenIdentifier?: string,
|
|
266
|
+
): MultiversXOperation => {
|
|
267
|
+
const type = getESDTOperationType(transaction, addr);
|
|
268
|
+
const value = getESDTOperationValue(transaction, tokenIdentifier);
|
|
269
|
+
const fee = new BigNumber(transaction.fee ?? 0);
|
|
270
|
+
const senders: string[] = transaction.sender ? [transaction.sender] : [];
|
|
271
|
+
const recipients: string[] = transaction.receiver ? [transaction.receiver] : [];
|
|
272
|
+
const hash = transaction.txHash ?? "";
|
|
273
|
+
const blockHeight = transaction.round;
|
|
274
|
+
const date = new Date(transaction.timestamp ? transaction.timestamp * 1000 : 0);
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
id: encodeOperationId(tokenAccountId, hash, type),
|
|
278
|
+
accountId: tokenAccountId,
|
|
279
|
+
hash,
|
|
280
|
+
date,
|
|
281
|
+
type,
|
|
282
|
+
value,
|
|
283
|
+
fee,
|
|
284
|
+
senders,
|
|
285
|
+
recipients,
|
|
286
|
+
blockHeight,
|
|
287
|
+
blockHash: transaction.miniBlockHash,
|
|
288
|
+
extra: {},
|
|
289
|
+
};
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Fetch operation list
|
|
294
|
+
*/
|
|
295
|
+
export const getEGLDOperations = async (
|
|
296
|
+
accountId: string,
|
|
297
|
+
addr: string,
|
|
298
|
+
startAt: number,
|
|
299
|
+
subAccounts: TokenAccount[],
|
|
300
|
+
): Promise<MultiversXOperation[]> => {
|
|
301
|
+
const rawTransactions = await api.getHistory(addr, startAt);
|
|
302
|
+
if (!rawTransactions) return rawTransactions;
|
|
303
|
+
return rawTransactions.map(transaction =>
|
|
304
|
+
transactionToEGLDOperation(accountId, addr, transaction, subAccounts),
|
|
305
|
+
);
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
export const getAccountESDTTokens = async (address: string): Promise<ESDTToken[]> => {
|
|
309
|
+
return await api.getESDTTokensForAddress(address);
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
export const getAccountDelegations = async (address: string): Promise<MultiversXDelegation[]> => {
|
|
313
|
+
return await api.getAccountDelegations(address);
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
export const hasESDTTokens = async (address: string): Promise<boolean> => {
|
|
317
|
+
const tokensCount = await api.getESDTTokensCountForAddress(address);
|
|
318
|
+
return tokensCount > 0;
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
export const getESDTOperations = async (
|
|
322
|
+
tokenAccountId: string,
|
|
323
|
+
address: string,
|
|
324
|
+
tokenIdentifier: string,
|
|
325
|
+
startAt: number,
|
|
326
|
+
): Promise<MultiversXOperation[]> => {
|
|
327
|
+
const accountESDTTransactions = await api.getESDTTransactionsForAddress(
|
|
328
|
+
address,
|
|
329
|
+
tokenIdentifier,
|
|
330
|
+
startAt,
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
return accountESDTTransactions.map(transaction =>
|
|
334
|
+
transactionToESDTOperation(tokenAccountId, address, transaction, tokenIdentifier),
|
|
335
|
+
);
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Obtain fees from blockchain
|
|
340
|
+
*/
|
|
341
|
+
export const getFees = async (t: Transaction): Promise<BigNumber> => {
|
|
342
|
+
const networkConfig: INetworkConfig = {
|
|
343
|
+
MinGasLimit: MIN_GAS_LIMIT,
|
|
344
|
+
GasPerDataByte: GAS_PER_DATA_BYTE,
|
|
345
|
+
GasPriceModifier: GAS_PRICE_MODIFIER,
|
|
346
|
+
ChainID: CHAIN_ID,
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const transaction = new MultiversXSdkTransaction({
|
|
350
|
+
data: TransactionPayload.fromEncoded(t.data?.trim()),
|
|
351
|
+
receiver: new Address(getAbandonSeedAddress("elrond")),
|
|
352
|
+
chainID: CHAIN_ID,
|
|
353
|
+
gasPrice: GAS_PRICE,
|
|
354
|
+
gasLimit: t.gasLimit ?? networkConfig.MinGasLimit,
|
|
355
|
+
sender: Address.empty(),
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
const feesStr = transaction.computeFee(networkConfig).toFixed();
|
|
359
|
+
|
|
360
|
+
return new BigNumber(feesStr);
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Broadcast blob to blockchain
|
|
365
|
+
*/
|
|
366
|
+
export const broadcastTransaction = async (signedOperation: SignedOperation): Promise<string> => {
|
|
367
|
+
return await api.submit(signedOperation);
|
|
368
|
+
};
|