@ledgerhq/coin-filecoin 1.3.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/.turbo/turbo-build.log +4 -0
- package/.unimportedrc.json +21 -0
- package/CHANGELOG.md +19 -0
- package/LICENSE.txt +21 -0
- package/jest.config.js +8 -0
- package/lib/api/api.d.ts +9 -0
- package/lib/api/api.d.ts.map +1 -0
- package/lib/api/api.js +99 -0
- package/lib/api/api.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 +18 -0
- package/lib/api/index.js.map +1 -0
- package/lib/bridge/broadcast.d.ts +4 -0
- package/lib/bridge/broadcast.d.ts.map +1 -0
- package/lib/bridge/broadcast.js +27 -0
- package/lib/bridge/broadcast.js.map +1 -0
- package/lib/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib/bridge/buildOptimisticOperation.js +62 -0
- package/lib/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib/bridge/createTransaction.d.ts +4 -0
- package/lib/bridge/createTransaction.d.ts.map +1 -0
- package/lib/bridge/createTransaction.js +24 -0
- package/lib/bridge/createTransaction.js.map +1 -0
- package/lib/bridge/deviceTransactionConfig.d.ts +33 -0
- package/lib/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib/bridge/deviceTransactionConfig.js +71 -0
- package/lib/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib/bridge/estimateMaxSpendable.d.ts +4 -0
- package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib/bridge/estimateMaxSpendable.js +100 -0
- package/lib/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib/bridge/getTransactionStatus.d.ts +4 -0
- package/lib/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib/bridge/getTransactionStatus.js +84 -0
- package/lib/bridge/getTransactionStatus.js.map +1 -0
- package/lib/bridge/index.d.ts +8 -0
- package/lib/bridge/index.d.ts.map +1 -0
- package/lib/bridge/index.js +54 -0
- package/lib/bridge/index.js.map +1 -0
- package/lib/bridge/prepareTransaction.d.ts +4 -0
- package/lib/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib/bridge/prepareTransaction.js +75 -0
- package/lib/bridge/prepareTransaction.js.map +1 -0
- package/lib/bridge/serializer.d.ts +13 -0
- package/lib/bridge/serializer.d.ts.map +1 -0
- package/lib/bridge/serializer.js +65 -0
- package/lib/bridge/serializer.js.map +1 -0
- package/lib/bridge/signOperation.d.ts +5 -0
- package/lib/bridge/signOperation.d.ts.map +1 -0
- package/lib/bridge/signOperation.js +80 -0
- package/lib/bridge/signOperation.js.map +1 -0
- package/lib/bridge/transaction.d.ts +14 -0
- package/lib/bridge/transaction.d.ts.map +1 -0
- package/lib/bridge/transaction.js +41 -0
- package/lib/bridge/transaction.js.map +1 -0
- package/lib/bridge/utils.d.ts +26 -0
- package/lib/bridge/utils.d.ts.map +1 -0
- package/lib/bridge/utils.js +67 -0
- package/lib/bridge/utils.js.map +1 -0
- package/lib/bridge/utils.unit.test.d.ts +2 -0
- package/lib/bridge/utils.unit.test.d.ts.map +1 -0
- package/lib/bridge/utils.unit.test.js +23 -0
- package/lib/bridge/utils.unit.test.js.map +1 -0
- package/lib/common-logic/index.d.ts +2 -0
- package/lib/common-logic/index.d.ts.map +1 -0
- package/lib/common-logic/index.js +13 -0
- package/lib/common-logic/index.js.map +1 -0
- package/lib/common-logic/utils.d.ts +22 -0
- package/lib/common-logic/utils.d.ts.map +1 -0
- package/lib/common-logic/utils.js +189 -0
- package/lib/common-logic/utils.js.map +1 -0
- package/lib/erc20/ERC20.json +12 -0
- package/lib/erc20/tokenAccounts.d.ts +10 -0
- package/lib/erc20/tokenAccounts.d.ts.map +1 -0
- package/lib/erc20/tokenAccounts.js +169 -0
- package/lib/erc20/tokenAccounts.js.map +1 -0
- package/lib/errors.d.ts +7 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/errors.js +13 -0
- package/lib/errors.js.map +1 -0
- package/lib/hw-signMessage.d.ts +12 -0
- package/lib/hw-signMessage.d.ts.map +1 -0
- package/lib/hw-signMessage.js +32 -0
- package/lib/hw-signMessage.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/network/addresses.d.ts +16 -0
- package/lib/network/addresses.d.ts.map +1 -0
- package/lib/network/addresses.js +75 -0
- package/lib/network/addresses.js.map +1 -0
- package/lib/network/index.d.ts +2 -0
- package/lib/network/index.d.ts.map +1 -0
- package/lib/network/index.js +18 -0
- package/lib/network/index.js.map +1 -0
- package/lib/signer/getAddress.d.ts +6 -0
- package/lib/signer/getAddress.d.ts.map +1 -0
- package/lib/signer/getAddress.js +30 -0
- package/lib/signer/getAddress.js.map +1 -0
- package/lib/signer/index.d.ts +3 -0
- package/lib/signer/index.d.ts.map +1 -0
- package/lib/signer/index.js +8 -0
- package/lib/signer/index.js.map +1 -0
- package/lib/test/bot-specs.d.ts +7 -0
- package/lib/test/bot-specs.d.ts.map +1 -0
- package/lib/test/bot-specs.js +151 -0
- package/lib/test/bot-specs.js.map +1 -0
- package/lib/test/bridgeDatasetTest.d.ts +4 -0
- package/lib/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib/test/bridgeDatasetTest.js +401 -0
- package/lib/test/bridgeDatasetTest.js.map +1 -0
- package/lib/test/cli.d.ts +19 -0
- package/lib/test/cli.d.ts.map +1 -0
- package/lib/test/cli.js +59 -0
- package/lib/test/cli.js.map +1 -0
- package/lib/test/index.d.ts +6 -0
- package/lib/test/index.d.ts.map +1 -0
- package/lib/test/index.js +26 -0
- package/lib/test/index.js.map +1 -0
- package/lib/test/speculos-deviceActions.d.ts +5 -0
- package/lib/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib/test/speculos-deviceActions.js +159 -0
- package/lib/test/speculos-deviceActions.js.map +1 -0
- package/lib/types/bridge.d.ts +35 -0
- package/lib/types/bridge.d.ts.map +1 -0
- package/lib/types/bridge.js +3 -0
- package/lib/types/bridge.js.map +1 -0
- package/lib/types/common.d.ts +96 -0
- package/lib/types/common.d.ts.map +1 -0
- package/lib/types/common.js +10 -0
- package/lib/types/common.js.map +1 -0
- package/lib/types/index.d.ts +4 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/index.js +20 -0
- package/lib/types/index.js.map +1 -0
- package/lib/types/signer.d.ts +19 -0
- package/lib/types/signer.d.ts.map +1 -0
- package/lib/types/signer.js +3 -0
- package/lib/types/signer.js.map +1 -0
- package/lib-es/api/api.d.ts +9 -0
- package/lib-es/api/api.d.ts.map +1 -0
- package/lib-es/api/api.js +87 -0
- package/lib-es/api/api.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/bridge/broadcast.d.ts +4 -0
- package/lib-es/bridge/broadcast.d.ts.map +1 -0
- package/lib-es/bridge/broadcast.js +23 -0
- package/lib-es/bridge/broadcast.js.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts +5 -0
- package/lib-es/bridge/buildOptimisticOperation.d.ts.map +1 -0
- package/lib-es/bridge/buildOptimisticOperation.js +58 -0
- package/lib-es/bridge/buildOptimisticOperation.js.map +1 -0
- package/lib-es/bridge/createTransaction.d.ts +4 -0
- package/lib-es/bridge/createTransaction.d.ts.map +1 -0
- package/lib-es/bridge/createTransaction.js +17 -0
- package/lib-es/bridge/createTransaction.js.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts +33 -0
- package/lib-es/bridge/deviceTransactionConfig.d.ts.map +1 -0
- package/lib-es/bridge/deviceTransactionConfig.js +69 -0
- package/lib-es/bridge/deviceTransactionConfig.js.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts +4 -0
- package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -0
- package/lib-es/bridge/estimateMaxSpendable.js +93 -0
- package/lib-es/bridge/estimateMaxSpendable.js.map +1 -0
- package/lib-es/bridge/getTransactionStatus.d.ts +4 -0
- package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -0
- package/lib-es/bridge/getTransactionStatus.js +80 -0
- package/lib-es/bridge/getTransactionStatus.js.map +1 -0
- package/lib-es/bridge/index.d.ts +8 -0
- package/lib-es/bridge/index.d.ts.map +1 -0
- package/lib-es/bridge/index.js +47 -0
- package/lib-es/bridge/index.js.map +1 -0
- package/lib-es/bridge/prepareTransaction.d.ts +4 -0
- package/lib-es/bridge/prepareTransaction.d.ts.map +1 -0
- package/lib-es/bridge/prepareTransaction.js +68 -0
- package/lib-es/bridge/prepareTransaction.js.map +1 -0
- package/lib-es/bridge/serializer.d.ts +13 -0
- package/lib-es/bridge/serializer.d.ts.map +1 -0
- package/lib-es/bridge/serializer.js +58 -0
- package/lib-es/bridge/serializer.js.map +1 -0
- package/lib-es/bridge/signOperation.d.ts +5 -0
- package/lib-es/bridge/signOperation.d.ts.map +1 -0
- package/lib-es/bridge/signOperation.js +76 -0
- package/lib-es/bridge/signOperation.js.map +1 -0
- package/lib-es/bridge/transaction.d.ts +14 -0
- package/lib-es/bridge/transaction.d.ts.map +1 -0
- package/lib-es/bridge/transaction.js +33 -0
- package/lib-es/bridge/transaction.js.map +1 -0
- package/lib-es/bridge/utils.d.ts +26 -0
- package/lib-es/bridge/utils.d.ts.map +1 -0
- package/lib-es/bridge/utils.js +57 -0
- package/lib-es/bridge/utils.js.map +1 -0
- package/lib-es/bridge/utils.unit.test.d.ts +2 -0
- package/lib-es/bridge/utils.unit.test.d.ts.map +1 -0
- package/lib-es/bridge/utils.unit.test.js +21 -0
- package/lib-es/bridge/utils.unit.test.js.map +1 -0
- package/lib-es/common-logic/index.d.ts +2 -0
- package/lib-es/common-logic/index.d.ts.map +1 -0
- package/lib-es/common-logic/index.js +2 -0
- package/lib-es/common-logic/index.js.map +1 -0
- package/lib-es/common-logic/utils.d.ts +22 -0
- package/lib-es/common-logic/utils.d.ts.map +1 -0
- package/lib-es/common-logic/utils.js +175 -0
- package/lib-es/common-logic/utils.js.map +1 -0
- package/lib-es/erc20/ERC20.json +12 -0
- package/lib-es/erc20/tokenAccounts.d.ts +10 -0
- package/lib-es/erc20/tokenAccounts.d.ts.map +1 -0
- package/lib-es/erc20/tokenAccounts.js +158 -0
- package/lib-es/erc20/tokenAccounts.js.map +1 -0
- package/lib-es/errors.d.ts +7 -0
- package/lib-es/errors.d.ts.map +1 -0
- package/lib-es/errors.js +10 -0
- package/lib-es/errors.js.map +1 -0
- package/lib-es/hw-signMessage.d.ts +12 -0
- package/lib-es/hw-signMessage.d.ts.map +1 -0
- package/lib-es/hw-signMessage.js +28 -0
- package/lib-es/hw-signMessage.js.map +1 -0
- package/lib-es/index.d.ts +2 -0
- package/lib-es/index.d.ts.map +1 -0
- package/lib-es/index.js +2 -0
- package/lib-es/index.js.map +1 -0
- package/lib-es/network/addresses.d.ts +16 -0
- package/lib-es/network/addresses.d.ts.map +1 -0
- package/lib-es/network/addresses.js +64 -0
- package/lib-es/network/addresses.js.map +1 -0
- package/lib-es/network/index.d.ts +2 -0
- package/lib-es/network/index.d.ts.map +1 -0
- package/lib-es/network/index.js +2 -0
- package/lib-es/network/index.js.map +1 -0
- package/lib-es/signer/getAddress.d.ts +6 -0
- package/lib-es/signer/getAddress.d.ts.map +1 -0
- package/lib-es/signer/getAddress.js +28 -0
- package/lib-es/signer/getAddress.js.map +1 -0
- package/lib-es/signer/index.d.ts +3 -0
- package/lib-es/signer/index.d.ts.map +1 -0
- package/lib-es/signer/index.js +3 -0
- package/lib-es/signer/index.js.map +1 -0
- package/lib-es/test/bot-specs.d.ts +7 -0
- package/lib-es/test/bot-specs.d.ts.map +1 -0
- package/lib-es/test/bot-specs.js +146 -0
- package/lib-es/test/bot-specs.js.map +1 -0
- package/lib-es/test/bridgeDatasetTest.d.ts +4 -0
- package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -0
- package/lib-es/test/bridgeDatasetTest.js +395 -0
- package/lib-es/test/bridgeDatasetTest.js.map +1 -0
- package/lib-es/test/cli.d.ts +19 -0
- package/lib-es/test/cli.d.ts.map +1 -0
- package/lib-es/test/cli.js +53 -0
- package/lib-es/test/cli.js.map +1 -0
- package/lib-es/test/index.d.ts +6 -0
- package/lib-es/test/index.d.ts.map +1 -0
- package/lib-es/test/index.js +6 -0
- package/lib-es/test/index.js.map +1 -0
- package/lib-es/test/speculos-deviceActions.d.ts +5 -0
- package/lib-es/test/speculos-deviceActions.d.ts.map +1 -0
- package/lib-es/test/speculos-deviceActions.js +152 -0
- package/lib-es/test/speculos-deviceActions.js.map +1 -0
- package/lib-es/types/bridge.d.ts +35 -0
- package/lib-es/types/bridge.d.ts.map +1 -0
- package/lib-es/types/bridge.js +2 -0
- package/lib-es/types/bridge.js.map +1 -0
- package/lib-es/types/common.d.ts +96 -0
- package/lib-es/types/common.d.ts.map +1 -0
- package/lib-es/types/common.js +7 -0
- package/lib-es/types/common.js.map +1 -0
- package/lib-es/types/index.d.ts +4 -0
- package/lib-es/types/index.d.ts.map +1 -0
- package/lib-es/types/index.js +4 -0
- package/lib-es/types/index.js.map +1 -0
- package/lib-es/types/signer.d.ts +19 -0
- package/lib-es/types/signer.d.ts.map +1 -0
- package/lib-es/types/signer.js +2 -0
- package/lib-es/types/signer.js.map +1 -0
- package/package.json +135 -0
- package/src/api/api.ts +125 -0
- package/src/api/index.ts +1 -0
- package/src/bridge/broadcast.ts +20 -0
- package/src/bridge/buildOptimisticOperation.ts +58 -0
- package/src/bridge/createTransaction.ts +20 -0
- package/src/bridge/deviceTransactionConfig.ts +119 -0
- package/src/bridge/estimateMaxSpendable.ts +120 -0
- package/src/bridge/getTransactionStatus.ts +80 -0
- package/src/bridge/index.ts +63 -0
- package/src/bridge/prepareTransaction.ts +82 -0
- package/src/bridge/serializer.ts +63 -0
- package/src/bridge/signOperation.ts +97 -0
- package/src/bridge/transaction.ts +69 -0
- package/src/bridge/utils.ts +73 -0
- package/src/bridge/utils.unit.test.ts +27 -0
- package/src/common-logic/index.ts +10 -0
- package/src/common-logic/utils.ts +232 -0
- package/src/erc20/ERC20.json +12 -0
- package/src/erc20/tokenAccounts.ts +183 -0
- package/src/errors.ts +13 -0
- package/src/hw-signMessage.ts +27 -0
- package/src/index.ts +1 -0
- package/src/network/addresses.ts +93 -0
- package/src/network/index.ts +1 -0
- package/src/signer/getAddress.ts +28 -0
- package/src/signer/index.ts +3 -0
- package/src/test/bot-specs.ts +163 -0
- package/src/test/bridgeDatasetTest.ts +403 -0
- package/src/test/cli.ts +80 -0
- package/src/test/index.ts +6 -0
- package/src/test/speculos-deviceActions.ts +166 -0
- package/src/types/bridge.ts +42 -0
- package/src/types/common.ts +105 -0
- package/src/types/index.ts +3 -0
- package/src/types/signer.ts +19 -0
- package/tsconfig.json +14 -0
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { InvalidAddress, NotEnoughBalance, AmountRequired } from "@ledgerhq/errors";
|
|
2
|
+
import type { DatasetTest, CurrenciesData } from "@ledgerhq/types-live";
|
|
3
|
+
import type { Transaction } from "../types";
|
|
4
|
+
import { fromTransactionRaw } from "../bridge/transaction";
|
|
5
|
+
import { InvalidRecipientForTokenTransfer } from "../errors";
|
|
6
|
+
import { getSubAccount } from "../common-logic";
|
|
7
|
+
import BigNumber from "bignumber.js";
|
|
8
|
+
|
|
9
|
+
const SEED_IDENTIFIER = "f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia";
|
|
10
|
+
const ACCOUNT_1 = "f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia";
|
|
11
|
+
const ACCOUNT_2 = "f410fncojwmrseefktoco6rcnb3zv2eiqfli7muhvqma";
|
|
12
|
+
const ACCOUNT_3 = "0x689c9b3232210aa9b84ef444d0ef35d11102ad1f";
|
|
13
|
+
const ACCOUNT_4 = "f01840380";
|
|
14
|
+
|
|
15
|
+
const filecoin: CurrenciesData<Transaction> = {
|
|
16
|
+
scanAccounts: [
|
|
17
|
+
{
|
|
18
|
+
name: "filecoin seed 1",
|
|
19
|
+
apdus: `
|
|
20
|
+
=> 0600000000
|
|
21
|
+
<= 0000180100331000049000
|
|
22
|
+
=> 06010000142c000080cd010080000000800000000000000000
|
|
23
|
+
<= 04ca7b02cafdf36e8b4caaf530a96b949764af71b956b2a3328b7a10940794c860f574a9199be98bde3c261887fec8e5fd94bc5f104908bf5f992f52ef2a89abb015017ff83e316c2605c018ab3a6126d5d8ce0a3023e529663170373464346d6c6d657963346167666c686a71736e766f797a796664616937666d6b79736f32619000
|
|
24
|
+
=> 0600000000
|
|
25
|
+
<= 0000180100331000049000
|
|
26
|
+
=> 06010000142c00008001000080000000800000000000000000
|
|
27
|
+
<= 04d493dab3ff63d6f0673454f8f6d6adec08db19e8c0298c65cfcace76a10757774afdee518b15a8b82452531bcb7860eefce02a89ef9051037646f5d4d6bd74171501eac14c6468ac13f66f0e0ee3766472c7e98394ab297431356c6175797a646976716a376d33796f623372786d7a6473793775796866666c777968657572699000
|
|
28
|
+
=> 0600000000
|
|
29
|
+
<= 0000180100331000049000
|
|
30
|
+
=> 06010000142c00008001000080000000800000000001000000
|
|
31
|
+
<= 040cbb57791d797268e34340565393f8a014ae754026159973fbe46bdcef3b6d28d155f4923256a2beb9bcff3bd39e5066d1c778306f28a2d4faa3a66dbf70453e150148c9b66fef1fce116652099bec6301ced31e56472974316a6465336d33377064376862637a737362676e36797979627a336a7234767368676370696b32619000
|
|
32
|
+
=> 0600000000
|
|
33
|
+
<= 0000180100331000049000
|
|
34
|
+
=> 06010000142c00008001000080000000800000000002000000
|
|
35
|
+
<= 04b5d3766bcfe150e887fe08355d8801901957d4f940ac33086b211cbd2879ccdb475765391f6bdc93329670c899e82ec212e9c90912117d002e5f8d4a25d6c6d01501917d45c3017ba05f783d3ff6c88921273a73daac297431736636756c717962706f7166363662356837336d72636a62653435686877766d6f737a6d7a71719000
|
|
36
|
+
=> 0600000000
|
|
37
|
+
<= 0000180100331000049000
|
|
38
|
+
=> 06010000142c00008001000080000000800000000003000000
|
|
39
|
+
<= 041e039416e7b916778a6a6fbcb7b3bce298fb46f084ba27b3f584f7fac52410140cbc275974f9dcb03dde23d39940833fca8d2998710323102e87e04a15e249a215019948a798f70a807872e490d53b50bb0315d494632974317466656b70676878626b61687134786573646b7477756633616d6b356a66646468346b613776699000
|
|
40
|
+
=> 0600000000
|
|
41
|
+
<= 0000180100331000049000
|
|
42
|
+
=> 06010000142c00008001000080000000800000000004000000
|
|
43
|
+
<= 04eb83d066b4cb200f1632379f73b1ca6bff0fff17111f7e82a89c8433c6226b34139531f184499b333f31dc9937987a5536953eace7d8ba288aadd42d69d78dc01501d42efce0327edbdf975dcadf472de1d97b5003d1297431327178707a79627370336e35376632357a6c70756f6c7062336635766161367261796f68716a719000
|
|
44
|
+
=> 0600000000
|
|
45
|
+
<= 0000180100331000049000
|
|
46
|
+
=> 06010000142c00008001000080000000800000000005000000
|
|
47
|
+
<= 0407230f40bade572d4feeec0e3768789860227986e85b01bb4d462c1b517cd2cc5af4ce2097b06fda52176a542ecce4482291b4f6ece48d59fb9b2a1247f2418d1501d981129d32078f65537f1061f28cd00f005fb4832974313367617266686a73613668776b753337636271376664677162346166376e65647272737a6561619000
|
|
48
|
+
=> 0600000000
|
|
49
|
+
<= 0000180100331000049000
|
|
50
|
+
=> 06010000142c00008001000080000000800000000006000000
|
|
51
|
+
<= 0466a53388d30f8323cb39ca62cd261a63d43b6f1bbf05250ea7bef8077037ae74bfa6a42f5ef9757e53e713a9695c2de82cad06472385292c63337db0cbd80daa150144b33ed6e4940cce710c70146b8cfd18eb97f85929743169737a74357678657371676d3434696d6f616b67786468356464767a7036637a6b61756f377a799000
|
|
52
|
+
=> 0600000000
|
|
53
|
+
<= 0000180100331000049000
|
|
54
|
+
=> 06010000142c000080cd010080010000800000000000000000
|
|
55
|
+
<= 0463c18e9a3c08ecffab4fa384f977e5d380d2b252dbbd96875df9cc91c44c81e82639fd659a3eeeaed96901696d8c7832b03befafd0af6ab2bee634ea8141e52a15016f62da10a416f416e80ec32866b91f01f7746af82966316e35726e75656665633332626e32616f796d75676e6f693761683378693278796e766c746e71699000
|
|
56
|
+
=> 0600000000
|
|
57
|
+
<= 0000180100331000049000
|
|
58
|
+
=> 06010000142c000080cd010080020000800000000000000000
|
|
59
|
+
<= 04f838a8b60e8c8ddaa40b164c458b32094be15606c261008fbb4a38d9d7fd63d0b3343f1e0b861b142774fa242234185f79d95e180609bf6c56ad38f36197bf3715010b485688119885d1fa4a27d026c7f30531a62936296631626e65666e636172746363356436736b653769636e723774617579326d6b6a7732796e676275799000
|
|
60
|
+
=> 0600000000
|
|
61
|
+
<= 0000180100331000049000
|
|
62
|
+
=> 06010000142c000080cd010080030000800000000000000000
|
|
63
|
+
<= 04e3493fab64823760f42c5fca00dc27a3eb9cb8ba0b52c498b940a7ec82bad70f8b68bd2c7d6cc4074eb08d24187d925fab1fa54dbe7c26f544fd53b454ebcacd1501188ac818a6471dc0c43deef4cc4fb3594a85885d2966316463666d7167666769346f34627262353533326d797435746c6666696c6363353236637a7578699000
|
|
64
|
+
=> 0600000000
|
|
65
|
+
<= 0000180100331000049000
|
|
66
|
+
=> 06010000142c000080cd010080040000800000000000000000
|
|
67
|
+
<= 04851093dcfb51ae7eb3a085003c50a2f6ee635cc7192b713bd5d89301c1ce38d6ee44ec601b0c67218f502dfd7bc8bc96014e1db2f3754552507a5c313ebe0e2c1501ac247d637e126ed294b6761bf3877bda8f04d9002966317671736832793336636a786e666666776f796e3768623333336b68716a7769616b7a63616e32799000
|
|
68
|
+
=> 0600000000
|
|
69
|
+
<= 0000180100331000049000
|
|
70
|
+
=> 06010000142c000080cd010080050000800000000000000000
|
|
71
|
+
<= 04368d7fe53c84f52574cb0f9b0a78dcddf37d1b1e09e9c8a7bfab2e9bf06ce71a7ab0f453b938ffa093d1c8028b159bad8727b71a6508acbc2d530eb45ff9dab51501ec13e2bf751dd038dceb18db8447699bc67a3d6c29663135716a3666703376647869647278686c64646e796972336a7470646875706c6d6f656f717463699000
|
|
72
|
+
=> 0600000000
|
|
73
|
+
<= 0000180100331000049000
|
|
74
|
+
=> 06010000142c000080cd010080060000800000000000000000
|
|
75
|
+
<= 0418de25cee71d38de134e9fede2c42c28c5a8b06a4643527fe61ac272e45e562d957b18d85364da0cce8ffb470a30dba6e1d56f68cbaffc25f2332932731227991501a223f50f49d9804314bd96636ae7f5267360aeb2296631756972376b64326a3367616567666635737a7277767a3776657a7a77626c7673776669347974699000
|
|
76
|
+
=> 0600000000
|
|
77
|
+
<= 0000180100331000049000
|
|
78
|
+
=> 06010000142c000080cd010080000000800000000001000000
|
|
79
|
+
<= 0419d91b4f9c3015637f5aa6b601b337f2770b1dcf93ba896d64627cd2aa67493ba924decd3024643478a84e06486b0a6b10d9f7607b6e92b0545bb3c998d4d75d15017ad86da94bab1ae1942e43050edb5f634b2d1ec9296631706c6d67336b6b6c766d6e6f6466626f696d6371357732376d6e66733268776a746173366769619000
|
|
80
|
+
=> 0600000000
|
|
81
|
+
<= 0000180100331000049000
|
|
82
|
+
=> 06010000142c000080cd010080000000800000000002000000
|
|
83
|
+
<= 047fc6dc24f9c4bb243023b760637fc604c492da6406824f22592d96a4f435767c975d675b5aef0e160f87d2950860c50e2ab691f197033d234ce7af61fcded4b01501eb4fc162c42bfcf0572941424d3a2c603fc60176296631356e6834637977656670367061767a6a69666265326f726d6d6137346d616c77647979357266719000
|
|
84
|
+
=> 0600000000
|
|
85
|
+
<= 0000180100331000049000
|
|
86
|
+
=> 06010000142c000080cd010080000000800000000003000000
|
|
87
|
+
<= 04b5a4495a2edc7d6e121715332fcac13a28e1167c702d0a3ddbb5a5ff9027182db0a4c94387ee5c9cdd53fb7474b968a9f1310225c02c375d10189b4fc5e1f24a150159b7be7dd3ba42bb42fe7b60d83b3c142c0943bf2966316c67333334376f74786a626c77717836706e716e716f7a346371776173713537796f32627863799000
|
|
88
|
+
=> 0600000000
|
|
89
|
+
<= 0000180100331000049000
|
|
90
|
+
=> 06010000142c000080cd010080000000800000000004000000
|
|
91
|
+
<= 04b479cb2a3d8fe60534943f3bfad0e55ba4283d31974581e8d348623aeb4a3e15c8167a003c92dcf52e12ee253126faebc7d445bce8e347bdd26d8a2e53a46b3315014ea8e251c8a4987d19c35e3854547e33988f024c2966316a32756f65756f6975736d6832676f646c79346669766436676f6d693661736d7a6b6434376c699000
|
|
92
|
+
=> 0600000000
|
|
93
|
+
<= 0000180100331000049000
|
|
94
|
+
=> 06010000142c000080cd010080000000800000000005000000
|
|
95
|
+
<= 04a2dc85c8669642342c476dfd7a85f23309c7c06df209ed6846815786a6740ab35f8b9024b1616780a39dea7a9e7a05b8e808539688f70ad1ad814889546e738815015fcfe6d5c16405f00e1f7ae60ea9bfb8173bf95e2966316c3768366e766f626d71633761647137706c7461356b6e3778616c7478366b366c3770617173719000
|
|
96
|
+
=> 0600000000
|
|
97
|
+
<= 0000180100331000049000
|
|
98
|
+
=> 06010000142c000080cd010080000000800000000006000000
|
|
99
|
+
<= 045d4460005b5218e70aac7e6d1d8980b24fae39c743fa50b2cfd0dd062b5f88ea27ea5fe614ff059e0a62691bb91774dea71f5b8c0bf57703688a05e1bb0b436a150146871b490baefaf7ffa3a8fba2357b71e005501a296631693264727773696c763335707037356476643532656e6c336f6871616b7561326d7368663566799000
|
|
100
|
+
=> 0600000000
|
|
101
|
+
<= 0000180100331000049000
|
|
102
|
+
=> 06010000142c000080cd010080000000800000000007000000
|
|
103
|
+
<= 0453fd3f49647650ba84cf7016e370a7f26a2b19684fc90c0e669ea1f7120ef4fb812c6b8e9e8fc9bf9d20b02109064482742c478e275851a181eb1bb24ac0b1ae1501df3f92e7e94676e250afd2e2115ad3d7ba44ab7a2966313334377a667a376a697a336f65756670326c726263777774323635656a6b33326e327771726c619000
|
|
104
|
+
|
|
105
|
+
`,
|
|
106
|
+
},
|
|
107
|
+
],
|
|
108
|
+
accounts: [
|
|
109
|
+
{
|
|
110
|
+
raw: {
|
|
111
|
+
id: `js:2:filecoin:${SEED_IDENTIFIER}:glif`,
|
|
112
|
+
seedIdentifier: SEED_IDENTIFIER,
|
|
113
|
+
name: "Filecoin 1",
|
|
114
|
+
derivationMode: "" as const,
|
|
115
|
+
index: 0,
|
|
116
|
+
freshAddress: SEED_IDENTIFIER,
|
|
117
|
+
freshAddressPath: "44'/461'/0'/0/0",
|
|
118
|
+
blockHeight: 0,
|
|
119
|
+
operations: [],
|
|
120
|
+
pendingOperations: [],
|
|
121
|
+
currencyId: "filecoin",
|
|
122
|
+
lastSyncDate: "",
|
|
123
|
+
balance: "1000",
|
|
124
|
+
},
|
|
125
|
+
transactions: [
|
|
126
|
+
{
|
|
127
|
+
name: "Not a valid address (fil)",
|
|
128
|
+
transaction: fromTransactionRaw({
|
|
129
|
+
family: "filecoin",
|
|
130
|
+
method: 1,
|
|
131
|
+
version: 1,
|
|
132
|
+
nonce: 100,
|
|
133
|
+
gasFeeCap: "1000",
|
|
134
|
+
gasLimit: 100,
|
|
135
|
+
gasPremium: "200",
|
|
136
|
+
recipient: "novalidaddress",
|
|
137
|
+
amount: "100000000",
|
|
138
|
+
}),
|
|
139
|
+
expectedStatus: {
|
|
140
|
+
errors: {
|
|
141
|
+
recipient: new InvalidAddress(),
|
|
142
|
+
},
|
|
143
|
+
warnings: {},
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "Not a valid address (eth)",
|
|
148
|
+
transaction: fromTransactionRaw({
|
|
149
|
+
family: "filecoin",
|
|
150
|
+
method: 1,
|
|
151
|
+
version: 1,
|
|
152
|
+
nonce: 100,
|
|
153
|
+
gasFeeCap: "1000",
|
|
154
|
+
gasLimit: 100,
|
|
155
|
+
gasPremium: "200",
|
|
156
|
+
recipient: "0x689c9b3232210tt9b84ef444d0ef35d11102adjj",
|
|
157
|
+
amount: "100000000",
|
|
158
|
+
}),
|
|
159
|
+
expectedStatus: {
|
|
160
|
+
errors: {
|
|
161
|
+
recipient: new InvalidAddress(),
|
|
162
|
+
},
|
|
163
|
+
warnings: {},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: "Not enough balance",
|
|
168
|
+
transaction: fromTransactionRaw({
|
|
169
|
+
family: "filecoin",
|
|
170
|
+
method: 1,
|
|
171
|
+
version: 1,
|
|
172
|
+
nonce: 100,
|
|
173
|
+
gasFeeCap: "1000",
|
|
174
|
+
gasLimit: 10,
|
|
175
|
+
gasPremium: "10000",
|
|
176
|
+
recipient: ACCOUNT_1,
|
|
177
|
+
amount: "100000000000000000000",
|
|
178
|
+
}),
|
|
179
|
+
expectedStatus: {
|
|
180
|
+
errors: {
|
|
181
|
+
amount: new NotEnoughBalance(),
|
|
182
|
+
},
|
|
183
|
+
warnings: {},
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: "Amount Required",
|
|
188
|
+
transaction: fromTransactionRaw({
|
|
189
|
+
family: "filecoin",
|
|
190
|
+
method: 1,
|
|
191
|
+
version: 1,
|
|
192
|
+
nonce: 100,
|
|
193
|
+
gasFeeCap: "10",
|
|
194
|
+
gasLimit: 10,
|
|
195
|
+
gasPremium: "10000",
|
|
196
|
+
recipient: ACCOUNT_1,
|
|
197
|
+
amount: "0",
|
|
198
|
+
}),
|
|
199
|
+
expectedStatus: {
|
|
200
|
+
errors: {
|
|
201
|
+
amount: new AmountRequired(),
|
|
202
|
+
},
|
|
203
|
+
warnings: {},
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: "New account and sufficient amount (f1)",
|
|
208
|
+
transaction: fromTransactionRaw({
|
|
209
|
+
family: "filecoin",
|
|
210
|
+
method: 1,
|
|
211
|
+
version: 1,
|
|
212
|
+
nonce: 100,
|
|
213
|
+
gasFeeCap: "1000",
|
|
214
|
+
gasLimit: 10,
|
|
215
|
+
gasPremium: "10000",
|
|
216
|
+
recipient: ACCOUNT_1,
|
|
217
|
+
amount: "1",
|
|
218
|
+
}),
|
|
219
|
+
expectedStatus: {
|
|
220
|
+
amount: new BigNumber("1"),
|
|
221
|
+
errors: {},
|
|
222
|
+
warnings: {},
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
name: "New account and sufficient amount (f0)",
|
|
227
|
+
transaction: fromTransactionRaw({
|
|
228
|
+
family: "filecoin",
|
|
229
|
+
method: 1,
|
|
230
|
+
version: 1,
|
|
231
|
+
nonce: 100,
|
|
232
|
+
gasFeeCap: "1000",
|
|
233
|
+
gasLimit: 10,
|
|
234
|
+
gasPremium: "10000",
|
|
235
|
+
recipient: ACCOUNT_4,
|
|
236
|
+
amount: "1",
|
|
237
|
+
}),
|
|
238
|
+
expectedStatus: {
|
|
239
|
+
amount: new BigNumber("1"),
|
|
240
|
+
errors: {},
|
|
241
|
+
warnings: {},
|
|
242
|
+
},
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
name: "New account and sufficient amount (0x eth)",
|
|
246
|
+
transaction: fromTransactionRaw({
|
|
247
|
+
family: "filecoin",
|
|
248
|
+
method: 1,
|
|
249
|
+
version: 1,
|
|
250
|
+
nonce: 100,
|
|
251
|
+
gasFeeCap: "1000",
|
|
252
|
+
gasLimit: 10,
|
|
253
|
+
gasPremium: "10000",
|
|
254
|
+
recipient: ACCOUNT_3,
|
|
255
|
+
amount: "1",
|
|
256
|
+
}),
|
|
257
|
+
expectedStatus: {
|
|
258
|
+
amount: new BigNumber("1"),
|
|
259
|
+
errors: {},
|
|
260
|
+
warnings: {},
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
{
|
|
264
|
+
name: "New account and sufficient amount (f4)",
|
|
265
|
+
transaction: fromTransactionRaw({
|
|
266
|
+
family: "filecoin",
|
|
267
|
+
method: 1,
|
|
268
|
+
version: 1,
|
|
269
|
+
nonce: 100,
|
|
270
|
+
gasFeeCap: "1000",
|
|
271
|
+
gasLimit: 10,
|
|
272
|
+
gasPremium: "10000",
|
|
273
|
+
recipient: ACCOUNT_2,
|
|
274
|
+
amount: "1",
|
|
275
|
+
}),
|
|
276
|
+
expectedStatus: {
|
|
277
|
+
amount: new BigNumber("1"),
|
|
278
|
+
errors: {},
|
|
279
|
+
warnings: {},
|
|
280
|
+
},
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: "Send max",
|
|
284
|
+
transaction: fromTransactionRaw({
|
|
285
|
+
family: "filecoin",
|
|
286
|
+
method: 1,
|
|
287
|
+
version: 1,
|
|
288
|
+
nonce: 100,
|
|
289
|
+
gasFeeCap: "1000",
|
|
290
|
+
gasLimit: 10,
|
|
291
|
+
gasPremium: "10000",
|
|
292
|
+
recipient: ACCOUNT_1,
|
|
293
|
+
amount: "1",
|
|
294
|
+
useAllAmount: true,
|
|
295
|
+
}),
|
|
296
|
+
expectedStatus: (account, tx, status) => {
|
|
297
|
+
return {
|
|
298
|
+
amount: account.spendableBalance.minus(status.estimatedFees),
|
|
299
|
+
errors: {},
|
|
300
|
+
warnings: {},
|
|
301
|
+
};
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
// Subaccout tests
|
|
305
|
+
{
|
|
306
|
+
name: "Subaccount erc20 transfer",
|
|
307
|
+
transaction: fromTransactionRaw({
|
|
308
|
+
family: "filecoin",
|
|
309
|
+
method: 1,
|
|
310
|
+
version: 1,
|
|
311
|
+
nonce: 100,
|
|
312
|
+
gasFeeCap: "1000",
|
|
313
|
+
gasLimit: 10,
|
|
314
|
+
gasPremium: "10000",
|
|
315
|
+
recipient: ACCOUNT_4,
|
|
316
|
+
amount: "10",
|
|
317
|
+
subAccountId:
|
|
318
|
+
"js:2:filecoin:f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia:+filecoin%2Ferc20%2Fwrapped~!underscore!~fil",
|
|
319
|
+
}),
|
|
320
|
+
expectedStatus: {
|
|
321
|
+
errors: {},
|
|
322
|
+
warnings: {},
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
name: "Subaccount Send to unsupported address",
|
|
327
|
+
transaction: fromTransactionRaw({
|
|
328
|
+
family: "filecoin",
|
|
329
|
+
method: 1,
|
|
330
|
+
version: 1,
|
|
331
|
+
nonce: 100,
|
|
332
|
+
gasFeeCap: "1000",
|
|
333
|
+
gasLimit: 10,
|
|
334
|
+
gasPremium: "10000",
|
|
335
|
+
recipient: ACCOUNT_1,
|
|
336
|
+
amount: "10000",
|
|
337
|
+
subAccountId:
|
|
338
|
+
"js:2:filecoin:f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia:+filecoin%2Ferc20%2Fwrapped~!underscore!~fil",
|
|
339
|
+
}),
|
|
340
|
+
expectedStatus: {
|
|
341
|
+
errors: {
|
|
342
|
+
recipient: new InvalidRecipientForTokenTransfer(),
|
|
343
|
+
},
|
|
344
|
+
},
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: "Subaccount Send max",
|
|
348
|
+
transaction: fromTransactionRaw({
|
|
349
|
+
family: "filecoin",
|
|
350
|
+
method: 1,
|
|
351
|
+
version: 1,
|
|
352
|
+
nonce: 100,
|
|
353
|
+
gasFeeCap: "1000",
|
|
354
|
+
gasLimit: 10,
|
|
355
|
+
gasPremium: "10000",
|
|
356
|
+
recipient: ACCOUNT_2,
|
|
357
|
+
amount: "1",
|
|
358
|
+
useAllAmount: true,
|
|
359
|
+
subAccountId:
|
|
360
|
+
"js:2:filecoin:f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia:+filecoin%2Ferc20%2Fwrapped~!underscore!~fil",
|
|
361
|
+
}),
|
|
362
|
+
expectedStatus: (account, tx) => {
|
|
363
|
+
const subAccount = getSubAccount(account, tx);
|
|
364
|
+
return {
|
|
365
|
+
amount: subAccount?.spendableBalance || new BigNumber(0),
|
|
366
|
+
errors: {},
|
|
367
|
+
warnings: {},
|
|
368
|
+
};
|
|
369
|
+
},
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
name: "Subaccount not enough balance",
|
|
373
|
+
transaction: fromTransactionRaw({
|
|
374
|
+
family: "filecoin",
|
|
375
|
+
method: 1,
|
|
376
|
+
version: 1,
|
|
377
|
+
nonce: 100,
|
|
378
|
+
gasFeeCap: "1000",
|
|
379
|
+
gasLimit: 10,
|
|
380
|
+
gasPremium: "10000",
|
|
381
|
+
recipient: ACCOUNT_3,
|
|
382
|
+
amount: "123400000000000000",
|
|
383
|
+
subAccountId:
|
|
384
|
+
"js:2:filecoin:f1plmg3kklvmnodfboimcq5w27mnfs2hwjtas6gia:+filecoin%2Ferc20%2Fwrapped~!underscore!~fil",
|
|
385
|
+
}),
|
|
386
|
+
expectedStatus: {
|
|
387
|
+
errors: {
|
|
388
|
+
amount: new NotEnoughBalance(),
|
|
389
|
+
},
|
|
390
|
+
warnings: {},
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
],
|
|
394
|
+
},
|
|
395
|
+
],
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
export const dataset: DatasetTest<Transaction> = {
|
|
399
|
+
implementations: ["js"],
|
|
400
|
+
currencies: {
|
|
401
|
+
filecoin,
|
|
402
|
+
},
|
|
403
|
+
};
|
package/src/test/cli.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Account, AccountLike, AccountLikeArray } from "@ledgerhq/types-live";
|
|
2
|
+
import invariant from "invariant";
|
|
3
|
+
import flatMap from "lodash/flatMap";
|
|
4
|
+
import type { Transaction } from "../types";
|
|
5
|
+
import { getAccountCurrency } from "@ledgerhq/coin-framework/account/index";
|
|
6
|
+
import { AccountType } from "../bridge/utils";
|
|
7
|
+
|
|
8
|
+
const options = [
|
|
9
|
+
{
|
|
10
|
+
name: "token",
|
|
11
|
+
alias: "t",
|
|
12
|
+
type: String,
|
|
13
|
+
desc: "use an token account children of the account",
|
|
14
|
+
},
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
function inferAccounts(account: Account, opts: Record<string, any>): AccountLikeArray {
|
|
18
|
+
invariant(account.currency.family === "filecoin", "filecoin family");
|
|
19
|
+
|
|
20
|
+
if (!opts.token) {
|
|
21
|
+
const accounts: Account[] = [account];
|
|
22
|
+
return accounts;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const token = opts.token;
|
|
26
|
+
|
|
27
|
+
const subAccounts = account.subAccounts || [];
|
|
28
|
+
|
|
29
|
+
if (token) {
|
|
30
|
+
const subAccount = subAccounts.find(t => {
|
|
31
|
+
const currency = getAccountCurrency(t);
|
|
32
|
+
return (
|
|
33
|
+
token.toLowerCase() === currency.ticker.toLowerCase() || token.toLowerCase() === currency.id
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
if (!subAccount) {
|
|
38
|
+
throw new Error(
|
|
39
|
+
"token account '" +
|
|
40
|
+
token +
|
|
41
|
+
"' not found. Available: " +
|
|
42
|
+
subAccounts.map(t => getAccountCurrency(t).ticker).join(", "),
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return [subAccount];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return [];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function inferTransactions(
|
|
53
|
+
transactions: Array<{
|
|
54
|
+
account: AccountLike;
|
|
55
|
+
transaction: Transaction;
|
|
56
|
+
}>,
|
|
57
|
+
): Transaction[] {
|
|
58
|
+
return flatMap(transactions, ({ transaction, account }) => {
|
|
59
|
+
invariant(transaction.family === "filecoin", "filecoin family");
|
|
60
|
+
|
|
61
|
+
if (account.type === AccountType.TokenAccount) {
|
|
62
|
+
const isDelisted = account.token.delisted === true;
|
|
63
|
+
invariant(!isDelisted, "token is delisted");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
...transaction,
|
|
68
|
+
family: "filecoin",
|
|
69
|
+
subAccountId: account.type === AccountType.TokenAccount ? account.id : null,
|
|
70
|
+
} as Transaction;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export default function makeCliTools() {
|
|
75
|
+
return {
|
|
76
|
+
options,
|
|
77
|
+
inferAccounts,
|
|
78
|
+
inferTransactions,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import type { DeviceAction } from "@ledgerhq/coin-framework/bot/types";
|
|
2
|
+
import type { Transaction } from "../types";
|
|
3
|
+
import {
|
|
4
|
+
deviceActionFlow,
|
|
5
|
+
formatDeviceAmount,
|
|
6
|
+
SpeculosButton,
|
|
7
|
+
} from "@ledgerhq/coin-framework/bot/specs";
|
|
8
|
+
import {
|
|
9
|
+
BotScenario,
|
|
10
|
+
expectedToFieldForTokenTransfer,
|
|
11
|
+
Methods,
|
|
12
|
+
methodToString,
|
|
13
|
+
} from "../bridge/utils";
|
|
14
|
+
import { isFilEthAddress } from "../network";
|
|
15
|
+
import { fromEthAddress, fromString, toEthAddress } from "iso-filecoin/address";
|
|
16
|
+
import { getSubAccount } from "../common-logic";
|
|
17
|
+
import invariant from "invariant";
|
|
18
|
+
|
|
19
|
+
export const generateDeviceActionFlow = (scenario: BotScenario): DeviceAction<Transaction, any> => {
|
|
20
|
+
const data: Parameters<typeof deviceActionFlow<Transaction>>[0] = { steps: [] };
|
|
21
|
+
data.steps = data.steps.concat([
|
|
22
|
+
{
|
|
23
|
+
title: "Please",
|
|
24
|
+
button: SpeculosButton.RIGHT,
|
|
25
|
+
},
|
|
26
|
+
]);
|
|
27
|
+
if (scenario == BotScenario.F4_RECIPIENT) {
|
|
28
|
+
data.steps.push({
|
|
29
|
+
title: "To",
|
|
30
|
+
button: SpeculosButton.RIGHT,
|
|
31
|
+
expectedValue: ({ transaction }) => {
|
|
32
|
+
const addr = fromString(transaction.recipient);
|
|
33
|
+
if (isFilEthAddress(addr)) {
|
|
34
|
+
return toEthAddress(addr) + transaction.recipient;
|
|
35
|
+
}
|
|
36
|
+
return "unexpected flow... address should be eth type";
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
} else if (scenario == BotScenario.ETH_RECIPIENT) {
|
|
40
|
+
data.steps.push({
|
|
41
|
+
title: "To",
|
|
42
|
+
button: SpeculosButton.RIGHT,
|
|
43
|
+
expectedValue: ({ transaction }) => {
|
|
44
|
+
const addr = fromEthAddress(transaction.recipient, "mainnet");
|
|
45
|
+
return transaction.recipient + addr.toString();
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
} else if (scenario == BotScenario.TOKEN_TRANSFER) {
|
|
49
|
+
data.steps.push({
|
|
50
|
+
title: "To",
|
|
51
|
+
button: SpeculosButton.RIGHT,
|
|
52
|
+
expectedValue: ({ transaction }) => {
|
|
53
|
+
return expectedToFieldForTokenTransfer(transaction.recipient);
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
data.steps.push({
|
|
58
|
+
title: "To",
|
|
59
|
+
button: SpeculosButton.RIGHT,
|
|
60
|
+
expectedValue: ({ transaction }) => transaction.recipient,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
data.steps = data.steps.concat([
|
|
65
|
+
{
|
|
66
|
+
title: "From",
|
|
67
|
+
button: SpeculosButton.RIGHT,
|
|
68
|
+
expectedValue: ({ account }) => account.freshAddress,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
title: "Nonce",
|
|
72
|
+
button: SpeculosButton.RIGHT,
|
|
73
|
+
expectedValue: ({ transaction }) => transaction.nonce.toString(),
|
|
74
|
+
},
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
if (scenario == BotScenario.TOKEN_TRANSFER) {
|
|
78
|
+
data.steps.push({
|
|
79
|
+
title: "Value",
|
|
80
|
+
button: SpeculosButton.RIGHT,
|
|
81
|
+
expectedValue: ({ account, transaction }) => {
|
|
82
|
+
const subAccount = getSubAccount(account, transaction);
|
|
83
|
+
invariant(subAccount, "subAccount is required for token transfer");
|
|
84
|
+
|
|
85
|
+
return formatDeviceAmount(subAccount.token, transaction.amount, {
|
|
86
|
+
hideCode: false,
|
|
87
|
+
showAllDigits: true,
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
} else {
|
|
92
|
+
data.steps.push({
|
|
93
|
+
title: "Value",
|
|
94
|
+
button: SpeculosButton.RIGHT,
|
|
95
|
+
expectedValue: ({ account, status }) =>
|
|
96
|
+
formatDeviceAmount(account.currency, status.amount, {
|
|
97
|
+
hideCode: true,
|
|
98
|
+
showAllDigits: true,
|
|
99
|
+
}),
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (scenario === BotScenario.TOKEN_TRANSFER) {
|
|
104
|
+
data.steps.push({
|
|
105
|
+
title: "Gas Limit",
|
|
106
|
+
button: SpeculosButton.RIGHT,
|
|
107
|
+
expectedValue: ({ transaction, account }) =>
|
|
108
|
+
formatDeviceAmount(account.currency, transaction.gasLimit, {
|
|
109
|
+
hideCode: false,
|
|
110
|
+
showAllDigits: true,
|
|
111
|
+
}),
|
|
112
|
+
});
|
|
113
|
+
} else {
|
|
114
|
+
data.steps = data.steps.concat([
|
|
115
|
+
{
|
|
116
|
+
title: "Gas Limit",
|
|
117
|
+
button: SpeculosButton.RIGHT,
|
|
118
|
+
expectedValue: ({ transaction }) => transaction.gasLimit.toFixed(),
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
title: "Gas Premium",
|
|
122
|
+
button: SpeculosButton.RIGHT,
|
|
123
|
+
expectedValue: ({ account, transaction }) =>
|
|
124
|
+
formatDeviceAmount(account.currency, transaction.gasPremium, {
|
|
125
|
+
hideCode: true,
|
|
126
|
+
showAllDigits: true,
|
|
127
|
+
}),
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
title: "Gas Fee Cap",
|
|
131
|
+
button: SpeculosButton.RIGHT,
|
|
132
|
+
expectedValue: ({ account, transaction }) =>
|
|
133
|
+
formatDeviceAmount(account.currency, transaction.gasFeeCap, {
|
|
134
|
+
hideCode: true,
|
|
135
|
+
showAllDigits: true,
|
|
136
|
+
}),
|
|
137
|
+
},
|
|
138
|
+
]);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (scenario == BotScenario.ETH_RECIPIENT || scenario == BotScenario.F4_RECIPIENT) {
|
|
142
|
+
data.steps.push({
|
|
143
|
+
title: "Method",
|
|
144
|
+
button: SpeculosButton.RIGHT,
|
|
145
|
+
expectedValue: () => Methods.InvokeEVM.toString(),
|
|
146
|
+
});
|
|
147
|
+
} else if (scenario == BotScenario.TOKEN_TRANSFER) {
|
|
148
|
+
data.steps.push({
|
|
149
|
+
title: "Method",
|
|
150
|
+
button: SpeculosButton.RIGHT,
|
|
151
|
+
expectedValue: () => methodToString(Methods.ERC20Transfer),
|
|
152
|
+
});
|
|
153
|
+
} else {
|
|
154
|
+
data.steps.push({
|
|
155
|
+
title: "Method",
|
|
156
|
+
button: SpeculosButton.RIGHT,
|
|
157
|
+
expectedValue: () => "Transfer",
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
data.steps.push({
|
|
162
|
+
title: "APPROVE",
|
|
163
|
+
button: SpeculosButton.BOTH,
|
|
164
|
+
});
|
|
165
|
+
return deviceActionFlow(data);
|
|
166
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
TransactionCommon,
|
|
3
|
+
TransactionCommonRaw,
|
|
4
|
+
TransactionStatusCommon,
|
|
5
|
+
TransactionStatusCommonRaw,
|
|
6
|
+
} from "@ledgerhq/types-live";
|
|
7
|
+
import { BigNumber } from "bignumber.js";
|
|
8
|
+
|
|
9
|
+
type FamilyType = "filecoin";
|
|
10
|
+
|
|
11
|
+
export type NetworkInfo = {
|
|
12
|
+
family: FamilyType;
|
|
13
|
+
};
|
|
14
|
+
export type NetworkInfoRaw = {
|
|
15
|
+
family: FamilyType;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type Transaction = TransactionCommon & {
|
|
19
|
+
family: FamilyType;
|
|
20
|
+
nonce: number;
|
|
21
|
+
data?: Buffer;
|
|
22
|
+
method: number;
|
|
23
|
+
version: number;
|
|
24
|
+
params?: string | undefined;
|
|
25
|
+
gasLimit: BigNumber;
|
|
26
|
+
gasFeeCap: BigNumber;
|
|
27
|
+
gasPremium: BigNumber;
|
|
28
|
+
};
|
|
29
|
+
export type TransactionRaw = TransactionCommonRaw & {
|
|
30
|
+
family: FamilyType;
|
|
31
|
+
version: number;
|
|
32
|
+
nonce: number;
|
|
33
|
+
data?: string;
|
|
34
|
+
method: number;
|
|
35
|
+
gasLimit: number;
|
|
36
|
+
gasFeeCap: string;
|
|
37
|
+
gasPremium: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export type TransactionStatus = TransactionStatusCommon;
|
|
41
|
+
|
|
42
|
+
export type TransactionStatusRaw = TransactionStatusCommonRaw;
|