@ledgerhq/coin-filecoin 1.14.1-nightly.20251114023758 → 1.15.0-nightly.20251115023630
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/.unimportedrc.json +2 -0
- package/CHANGELOG.md +11 -7
- package/lib/api/api.d.ts +5 -3
- package/lib/api/api.d.ts.map +1 -1
- package/lib/api/api.js +66 -21
- package/lib/api/api.js.map +1 -1
- package/lib/common-logic/index.d.ts +1 -1
- package/lib/common-logic/index.d.ts.map +1 -1
- package/lib/common-logic/index.js +1 -3
- package/lib/common-logic/index.js.map +1 -1
- package/lib/common-logic/utils.d.ts +0 -2
- package/lib/common-logic/utils.d.ts.map +1 -1
- package/lib/common-logic/utils.js +16 -68
- package/lib/common-logic/utils.js.map +1 -1
- package/lib/erc20/tokenAccounts.d.ts +2 -3
- package/lib/erc20/tokenAccounts.d.ts.map +1 -1
- package/lib/erc20/tokenAccounts.js +46 -32
- package/lib/erc20/tokenAccounts.js.map +1 -1
- package/lib/test/fixtures.d.ts +87 -0
- package/lib/test/fixtures.d.ts.map +1 -0
- package/lib/test/fixtures.js +311 -0
- package/lib/test/fixtures.js.map +1 -0
- package/lib/types/common.d.ts +22 -2
- package/lib/types/common.d.ts.map +1 -1
- package/lib-es/api/api.d.ts +5 -3
- package/lib-es/api/api.d.ts.map +1 -1
- package/lib-es/api/api.js +61 -18
- package/lib-es/api/api.js.map +1 -1
- package/lib-es/common-logic/index.d.ts +1 -1
- package/lib-es/common-logic/index.d.ts.map +1 -1
- package/lib-es/common-logic/index.js +1 -1
- package/lib-es/common-logic/index.js.map +1 -1
- package/lib-es/common-logic/utils.d.ts +0 -2
- package/lib-es/common-logic/utils.d.ts.map +1 -1
- package/lib-es/common-logic/utils.js +16 -66
- package/lib-es/common-logic/utils.js.map +1 -1
- package/lib-es/erc20/tokenAccounts.d.ts +2 -3
- package/lib-es/erc20/tokenAccounts.d.ts.map +1 -1
- package/lib-es/erc20/tokenAccounts.js +47 -33
- package/lib-es/erc20/tokenAccounts.js.map +1 -1
- package/lib-es/test/fixtures.d.ts +87 -0
- package/lib-es/test/fixtures.d.ts.map +1 -0
- package/lib-es/test/fixtures.js +297 -0
- package/lib-es/test/fixtures.js.map +1 -0
- package/lib-es/types/common.d.ts +22 -2
- package/lib-es/types/common.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/api/api.ts +107 -26
- package/src/api/api.unit.test.ts +217 -0
- package/src/common-logic/index.ts +0 -2
- package/src/common-logic/utils.ts +19 -90
- package/src/common-logic/utils.unit.test.ts +429 -0
- package/src/erc20/tokenAccounts.ts +59 -34
- package/src/erc20/tokenAccounts.unit.test.ts +73 -0
- package/src/test/fixtures.ts +342 -0
- package/src/types/common.ts +24 -2
package/.unimportedrc.json
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
"proxy-from-env"
|
|
6
6
|
],
|
|
7
7
|
"ignoreUnused": [
|
|
8
|
+
"@ledgerhq/cryptoassets",
|
|
8
9
|
"@ledgerhq/devices",
|
|
9
10
|
"expect"
|
|
10
11
|
],
|
|
@@ -15,6 +16,7 @@
|
|
|
15
16
|
"src/test/bot-specs.ts",
|
|
16
17
|
"src/test/bridgeDatasetTest.ts",
|
|
17
18
|
"src/test/cli.ts",
|
|
19
|
+
"src/test/fixtures.ts",
|
|
18
20
|
"src/test/index.ts",
|
|
19
21
|
"src/test/speculos-deviceActions.ts"
|
|
20
22
|
]
|
package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
# @ledgerhq/coin-filecoin
|
|
2
2
|
|
|
3
|
-
## 1.
|
|
3
|
+
## 1.15.0-nightly.20251115023630
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#12304](https://github.com/LedgerHQ/ledger-live/pull/12304) [`bb5420d`](https://github.com/LedgerHQ/ledger-live/commit/bb5420df34ae3020f3c9e6270e85dda230922612) Thanks [@scavassa-yld](https://github.com/scavassa-yld)! - Add incremental sync and network api upgrade
|
|
4
8
|
|
|
5
9
|
### Patch Changes
|
|
6
10
|
|
|
7
|
-
- Updated dependencies [[`74a340b`](https://github.com/LedgerHQ/ledger-live/commit/74a340b258589c9c37476103029eb036b930616c), [`a6bc24e`](https://github.com/LedgerHQ/ledger-live/commit/a6bc24ee988b98bf82f807ac5ce731ba79813901), [`b69c97d`](https://github.com/LedgerHQ/ledger-live/commit/b69c97d979ba97154c9abfda6abfc2a36becee4f), [`544721d`](https://github.com/LedgerHQ/ledger-live/commit/544721d198454526ef83516619d59c881ba34eb9), [`1c6f5f5`](https://github.com/LedgerHQ/ledger-live/commit/1c6f5f5843349b1955f7ca466f98cbe4ffcdaddf), [`d5d838a`](https://github.com/LedgerHQ/ledger-live/commit/d5d838a23e00edd53293843781c559c41db4e854), [`9f61dcf`](https://github.com/LedgerHQ/ledger-live/commit/9f61dcf6163fd66657e5be732c28bea623a40515), [`938b970`](https://github.com/LedgerHQ/ledger-live/commit/938b970e15118dc706c759a3bec27dc01c3dd268), [`c40e9da`](https://github.com/LedgerHQ/ledger-live/commit/c40e9da68452fe9827b9435ff2d162291186be73), [`02ef98f`](https://github.com/LedgerHQ/ledger-live/commit/02ef98faeb13c182ef255e06a43c39abeb55ecc7), [`c0b5b9f`](https://github.com/LedgerHQ/ledger-live/commit/c0b5b9f4cdcb2ea3e15419cbf3d1a14f725c3e6a), [`70049be`](https://github.com/LedgerHQ/ledger-live/commit/70049bed0cd0a8c7a9e4947a63af82061dad46c0), [`0d33751`](https://github.com/LedgerHQ/ledger-live/commit/0d33751bb2ae599d0d26ce6a8efdbe01757f12fb), [`5b41dd5`](https://github.com/LedgerHQ/ledger-live/commit/5b41dd56e024a5d03ba0e49084113c04887395db), [`eb5a17e`](https://github.com/LedgerHQ/ledger-live/commit/eb5a17e4db336eaa871eaeb52ffa5248e0f78bec), [`9659a34`](https://github.com/LedgerHQ/ledger-live/commit/9659a34d9998d5c4dff8618bf6cef7d16403680d), [`c70f6a8`](https://github.com/LedgerHQ/ledger-live/commit/c70f6a8370056b6fd8f236205471359d6f9b846f)]:
|
|
8
|
-
- @ledgerhq/types-live@6.89.0-nightly.
|
|
9
|
-
- @ledgerhq/cryptoassets@13.33.0-nightly.
|
|
10
|
-
- @ledgerhq/coin-framework@6.9.0-nightly.
|
|
11
|
-
- @ledgerhq/live-env@2.21.0-nightly.
|
|
12
|
-
- @ledgerhq/live-network@2.1.1-nightly.
|
|
11
|
+
- Updated dependencies [[`74a340b`](https://github.com/LedgerHQ/ledger-live/commit/74a340b258589c9c37476103029eb036b930616c), [`a6bc24e`](https://github.com/LedgerHQ/ledger-live/commit/a6bc24ee988b98bf82f807ac5ce731ba79813901), [`b69c97d`](https://github.com/LedgerHQ/ledger-live/commit/b69c97d979ba97154c9abfda6abfc2a36becee4f), [`544721d`](https://github.com/LedgerHQ/ledger-live/commit/544721d198454526ef83516619d59c881ba34eb9), [`fe81926`](https://github.com/LedgerHQ/ledger-live/commit/fe81926afeb2df8e917e6bd1e4cbab13f09647fd), [`1c6f5f5`](https://github.com/LedgerHQ/ledger-live/commit/1c6f5f5843349b1955f7ca466f98cbe4ffcdaddf), [`d5d838a`](https://github.com/LedgerHQ/ledger-live/commit/d5d838a23e00edd53293843781c559c41db4e854), [`9f61dcf`](https://github.com/LedgerHQ/ledger-live/commit/9f61dcf6163fd66657e5be732c28bea623a40515), [`903ea9c`](https://github.com/LedgerHQ/ledger-live/commit/903ea9cdacf704a0119de2803a4f409b775391a5), [`938b970`](https://github.com/LedgerHQ/ledger-live/commit/938b970e15118dc706c759a3bec27dc01c3dd268), [`c40e9da`](https://github.com/LedgerHQ/ledger-live/commit/c40e9da68452fe9827b9435ff2d162291186be73), [`02ef98f`](https://github.com/LedgerHQ/ledger-live/commit/02ef98faeb13c182ef255e06a43c39abeb55ecc7), [`c0b5b9f`](https://github.com/LedgerHQ/ledger-live/commit/c0b5b9f4cdcb2ea3e15419cbf3d1a14f725c3e6a), [`70049be`](https://github.com/LedgerHQ/ledger-live/commit/70049bed0cd0a8c7a9e4947a63af82061dad46c0), [`0d33751`](https://github.com/LedgerHQ/ledger-live/commit/0d33751bb2ae599d0d26ce6a8efdbe01757f12fb), [`5b41dd5`](https://github.com/LedgerHQ/ledger-live/commit/5b41dd56e024a5d03ba0e49084113c04887395db), [`eb5a17e`](https://github.com/LedgerHQ/ledger-live/commit/eb5a17e4db336eaa871eaeb52ffa5248e0f78bec), [`9659a34`](https://github.com/LedgerHQ/ledger-live/commit/9659a34d9998d5c4dff8618bf6cef7d16403680d), [`c70f6a8`](https://github.com/LedgerHQ/ledger-live/commit/c70f6a8370056b6fd8f236205471359d6f9b846f)]:
|
|
12
|
+
- @ledgerhq/types-live@6.89.0-nightly.20251115023630
|
|
13
|
+
- @ledgerhq/cryptoassets@13.33.0-nightly.20251115023630
|
|
14
|
+
- @ledgerhq/coin-framework@6.9.0-nightly.20251115023630
|
|
15
|
+
- @ledgerhq/live-env@2.21.0-nightly.20251115023630
|
|
16
|
+
- @ledgerhq/live-network@2.1.1-nightly.20251115023630
|
|
13
17
|
|
|
14
18
|
## 1.14.0
|
|
15
19
|
|
package/lib/api/api.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { BalanceResponse, BroadcastTransactionRequest, BroadcastTransactionResponse, EstimatedFeesRequest, EstimatedFeesResponse, NetworkStatusResponse, TransactionResponse, ERC20Transfer } from "../types";
|
|
1
|
+
import { BalanceResponse, BroadcastTransactionRequest, BroadcastTransactionResponse, EstimatedFeesRequest, EstimatedFeesResponse, NetworkStatusResponse, TransactionResponse, TransactionsResponse, FetchERC20TransactionsResponse, ERC20Transfer } from "../types";
|
|
2
2
|
export declare const fetchBalances: (addr: string) => Promise<BalanceResponse>;
|
|
3
3
|
export declare const fetchEstimatedFees: import("@ledgerhq/live-network/cache").CacheRes<[request: EstimatedFeesRequest], EstimatedFeesResponse>;
|
|
4
4
|
export declare const fetchBlockHeight: () => Promise<NetworkStatusResponse>;
|
|
5
|
-
export declare const fetchTxs: (addr: string) => Promise<
|
|
5
|
+
export declare const fetchTxs: (addr: string, lastHeight: number, offset?: number, limit?: number) => Promise<TransactionsResponse>;
|
|
6
|
+
export declare const fetchTxsWithPages: (addr: string, lastHeight: number) => Promise<TransactionResponse[]>;
|
|
6
7
|
export declare const broadcastTx: (message: BroadcastTransactionRequest) => Promise<BroadcastTransactionResponse>;
|
|
7
8
|
export declare const fetchERC20TokenBalance: (ethAddr: string, contractAddr: string) => Promise<string>;
|
|
8
|
-
export declare const fetchERC20Transactions: (ethAddr: string) => Promise<
|
|
9
|
+
export declare const fetchERC20Transactions: (ethAddr: string, lastHeight: number, offset?: number, limit?: number) => Promise<FetchERC20TransactionsResponse>;
|
|
10
|
+
export declare const fetchERC20TransactionsWithPages: (addr: string, lastHeight: number) => Promise<ERC20Transfer[]>;
|
|
9
11
|
//# sourceMappingURL=api.d.ts.map
|
package/lib/api/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api/api.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/api/api.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,eAAe,EACf,2BAA2B,EAC3B,4BAA4B,EAC5B,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,EACnB,oBAAoB,EACpB,8BAA8B,EAC9B,aAAa,EAEd,MAAM,UAAU,CAAC;AA4DlB,eAAO,MAAM,aAAa,SAAgB,MAAM,KAAG,QAAQ,eAAe,CAKzE,CAAC;AAEF,eAAO,MAAM,kBAAkB,yGAiB9B,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAa,QAAQ,qBAAqB,CAKtE,CAAC;AAEF,eAAO,MAAM,QAAQ,SACb,MAAM,cACA,MAAM,WACV,MAAM,UACP,MAAM,KACZ,QAAQ,oBAAoB,CAQ9B,CAAC;AAEF,eAAO,MAAM,iBAAiB,SACtB,MAAM,cACA,MAAM,KACjB,QAAQ,mBAAmB,EAAE,CAc/B,CAAC;AAEF,eAAO,MAAM,WAAW,YACb,2BAA2B,KACnC,QAAQ,4BAA4B,CAMtC,CAAC;AAEF,eAAO,MAAM,sBAAsB,YACxB,MAAM,gBACD,MAAM,KACnB,QAAQ,MAAM,CAahB,CAAC;AAEF,eAAO,MAAM,sBAAsB,YACxB,MAAM,cACH,MAAM,WACV,MAAM,UACP,MAAM,KACZ,QAAQ,8BAA8B,CAQxC,CAAC;AAEF,eAAO,MAAM,+BAA+B,SACpC,MAAM,cACA,MAAM,KACjB,QAAQ,aAAa,EAAE,CAczB,CAAC"}
|
package/lib/api/api.js
CHANGED
|
@@ -3,53 +3,61 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.fetchERC20Transactions = exports.fetchERC20TokenBalance = exports.broadcastTx = exports.fetchTxs = exports.fetchBlockHeight = exports.fetchEstimatedFees = exports.fetchBalances = void 0;
|
|
6
|
+
exports.fetchERC20TransactionsWithPages = exports.fetchERC20Transactions = exports.fetchERC20TokenBalance = exports.broadcastTx = exports.fetchTxsWithPages = exports.fetchTxs = exports.fetchBlockHeight = exports.fetchEstimatedFees = exports.fetchBalances = void 0;
|
|
7
7
|
const logs_1 = require("@ledgerhq/logs");
|
|
8
|
-
const
|
|
8
|
+
const live_network_1 = __importDefault(require("@ledgerhq/live-network"));
|
|
9
9
|
const cache_1 = require("@ledgerhq/live-network/cache");
|
|
10
10
|
const live_env_1 = require("@ledgerhq/live-env");
|
|
11
11
|
const errors_1 = require("../errors");
|
|
12
|
-
const
|
|
12
|
+
const txsPerPageLimit = 1000;
|
|
13
|
+
const currentVersion = "/v2";
|
|
14
|
+
const fromHeightQueryParam = "from_height";
|
|
15
|
+
const getFilecoinURL = (version = currentVersion, path) => {
|
|
13
16
|
const baseUrl = (0, live_env_1.getEnv)("API_FILECOIN_ENDPOINT");
|
|
14
17
|
if (!baseUrl)
|
|
15
18
|
throw new Error("API base URL not available");
|
|
16
|
-
return `${baseUrl}${path ? path : ""}`;
|
|
19
|
+
return `${baseUrl}${version ? version : ""}${path ? path : ""}`;
|
|
17
20
|
};
|
|
18
|
-
const fetch = async (path) => {
|
|
19
|
-
const url = getFilecoinURL(path);
|
|
21
|
+
const fetch = async (path, { version }) => {
|
|
22
|
+
const url = getFilecoinURL(version, path);
|
|
20
23
|
// We force data to this way as network func is not using the correct param type. Changing that func will generate errors in other implementations
|
|
21
24
|
const opts = {
|
|
22
25
|
method: "GET",
|
|
23
26
|
url,
|
|
24
27
|
};
|
|
25
|
-
const rawResponse = await (0,
|
|
28
|
+
const rawResponse = await (0, live_network_1.default)(opts);
|
|
26
29
|
// We force data to this way as network func is not using the correct param type. Changing that func will generate errors in other implementations
|
|
27
30
|
const { data } = rawResponse;
|
|
28
31
|
(0, logs_1.log)("http", url);
|
|
29
32
|
return data;
|
|
30
33
|
};
|
|
31
|
-
const send = async (path, data) => {
|
|
32
|
-
const url = getFilecoinURL(path);
|
|
34
|
+
const send = async (path, { version, data }) => {
|
|
35
|
+
const url = getFilecoinURL(version, path);
|
|
33
36
|
const opts = {
|
|
34
37
|
method: "POST",
|
|
35
38
|
url,
|
|
36
39
|
data: JSON.stringify(data),
|
|
37
40
|
headers: { "Content-Type": "application/json" },
|
|
38
41
|
};
|
|
39
|
-
const rawResponse = await (0,
|
|
42
|
+
const rawResponse = await (0, live_network_1.default)(opts);
|
|
40
43
|
// We force data to this way as network func is not using generics. Changing that func will generate errors in other implementations
|
|
41
44
|
const { data: responseData } = rawResponse;
|
|
42
45
|
(0, logs_1.log)("http", url);
|
|
43
46
|
return responseData;
|
|
44
47
|
};
|
|
45
48
|
const fetchBalances = async (addr) => {
|
|
46
|
-
const data = await fetch(`/addresses/${addr}/balance
|
|
49
|
+
const data = await fetch(`/addresses/${addr}/balance`, {
|
|
50
|
+
version: currentVersion,
|
|
51
|
+
});
|
|
47
52
|
return data; // TODO Validate if the response fits this interface
|
|
48
53
|
};
|
|
49
54
|
exports.fetchBalances = fetchBalances;
|
|
50
55
|
exports.fetchEstimatedFees = (0, cache_1.makeLRUCache)(async (request) => {
|
|
51
56
|
try {
|
|
52
|
-
const data = await send(`/fees/estimate`,
|
|
57
|
+
const data = await send(`/fees/estimate`, {
|
|
58
|
+
version: currentVersion,
|
|
59
|
+
data: request,
|
|
60
|
+
});
|
|
53
61
|
return data; // TODO Validate if the response fits this interface
|
|
54
62
|
}
|
|
55
63
|
catch (e) {
|
|
@@ -60,31 +68,68 @@ exports.fetchEstimatedFees = (0, cache_1.makeLRUCache)(async (request) => {
|
|
|
60
68
|
ttl: 5 * 1000, // 5 seconds
|
|
61
69
|
});
|
|
62
70
|
const fetchBlockHeight = async () => {
|
|
63
|
-
const data = await fetch("/network/status"
|
|
71
|
+
const data = await fetch("/network/status", {
|
|
72
|
+
version: currentVersion,
|
|
73
|
+
});
|
|
64
74
|
return data; // TODO Validate if the response fits this interface
|
|
65
75
|
};
|
|
66
76
|
exports.fetchBlockHeight = fetchBlockHeight;
|
|
67
|
-
const fetchTxs = async (addr) => {
|
|
68
|
-
const response = await fetch(`/addresses/${addr}/transactions
|
|
69
|
-
|
|
77
|
+
const fetchTxs = async (addr, lastHeight, offset = 0, limit = 0) => {
|
|
78
|
+
const response = await fetch(`/addresses/${addr}/transactions?${fromHeightQueryParam}=${lastHeight}&offset=${offset}&limit=${limit}`, {
|
|
79
|
+
version: currentVersion,
|
|
80
|
+
});
|
|
81
|
+
return response; // TODO Validate if the response fits this interface
|
|
70
82
|
};
|
|
71
83
|
exports.fetchTxs = fetchTxs;
|
|
84
|
+
const fetchTxsWithPages = async (addr, lastHeight) => {
|
|
85
|
+
let result = [];
|
|
86
|
+
let offset = 0;
|
|
87
|
+
let txsLen = txsPerPageLimit;
|
|
88
|
+
while (txsLen === txsPerPageLimit) {
|
|
89
|
+
const { txs } = await (0, exports.fetchTxs)(addr, lastHeight, offset, txsPerPageLimit);
|
|
90
|
+
result = result.concat(txs);
|
|
91
|
+
txsLen = txs.length;
|
|
92
|
+
offset += txsLen;
|
|
93
|
+
}
|
|
94
|
+
return result;
|
|
95
|
+
};
|
|
96
|
+
exports.fetchTxsWithPages = fetchTxsWithPages;
|
|
72
97
|
const broadcastTx = async (message) => {
|
|
73
|
-
const response = await send(`/transaction/broadcast`,
|
|
98
|
+
const response = await send(`/transaction/broadcast`, {
|
|
99
|
+
version: currentVersion,
|
|
100
|
+
data: message,
|
|
101
|
+
});
|
|
74
102
|
return response; // TODO Validate if the response fits this interface
|
|
75
103
|
};
|
|
76
104
|
exports.broadcastTx = broadcastTx;
|
|
77
105
|
const fetchERC20TokenBalance = async (ethAddr, contractAddr) => {
|
|
78
|
-
const res = await fetch(`/contract/${contractAddr}/address/${ethAddr}/balance/erc20
|
|
106
|
+
const res = await fetch(`/contract/${contractAddr}/address/${ethAddr}/balance/erc20`, {
|
|
107
|
+
version: currentVersion,
|
|
108
|
+
});
|
|
79
109
|
if (res.data.length) {
|
|
80
110
|
return res.data[0].balance;
|
|
81
111
|
}
|
|
82
112
|
return "0";
|
|
83
113
|
};
|
|
84
114
|
exports.fetchERC20TokenBalance = fetchERC20TokenBalance;
|
|
85
|
-
const fetchERC20Transactions = async (ethAddr) => {
|
|
86
|
-
const res = await fetch(`/addresses/${ethAddr}/transactions/erc20
|
|
87
|
-
|
|
115
|
+
const fetchERC20Transactions = async (ethAddr, lastHeight, offset = 0, limit = 0) => {
|
|
116
|
+
const res = await fetch(`/addresses/${ethAddr}/transactions/erc20?${fromHeightQueryParam}=${lastHeight}&offset=${offset}&limit=${limit}`, {
|
|
117
|
+
version: currentVersion,
|
|
118
|
+
});
|
|
119
|
+
return res;
|
|
88
120
|
};
|
|
89
121
|
exports.fetchERC20Transactions = fetchERC20Transactions;
|
|
122
|
+
const fetchERC20TransactionsWithPages = async (addr, lastHeight) => {
|
|
123
|
+
let result = [];
|
|
124
|
+
let offset = 0;
|
|
125
|
+
let txsLen = txsPerPageLimit;
|
|
126
|
+
while (txsLen === txsPerPageLimit) {
|
|
127
|
+
const { txs } = await (0, exports.fetchERC20Transactions)(addr, lastHeight, offset, txsPerPageLimit);
|
|
128
|
+
result = result.concat(txs);
|
|
129
|
+
txsLen = txs.length;
|
|
130
|
+
offset += txsLen;
|
|
131
|
+
}
|
|
132
|
+
return result.sort((a, b) => b.timestamp - a.timestamp);
|
|
133
|
+
};
|
|
134
|
+
exports.fetchERC20TransactionsWithPages = fetchERC20TransactionsWithPages;
|
|
90
135
|
//# sourceMappingURL=api.js.map
|
package/lib/api/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api/api.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAqC;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api/api.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAqC;AAErC,0EAA6C;AAC7C,wDAA4D;AAC5D,iDAA4C;AAe5C,sCAAwD;AAGxD,MAAM,eAAe,GAAG,IAAI,CAAC;AAC7B,MAAM,cAAc,GAAG,KAAK,CAAC;AAC7B,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAE3C,MAAM,cAAc,GAAG,CAAC,UAAkB,cAAc,EAAE,IAAa,EAAU,EAAE;IACjF,MAAM,OAAO,GAAG,IAAA,iBAAM,EAAC,uBAAuB,CAAC,CAAC;IAChD,IAAI,CAAC,OAAO;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAE5D,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;AAClE,CAAC,CAAC;AAKF,MAAM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,EACf,UAAkB,EAClB,SAAiB,CAAC,EAClB,QAAgB,CAAC,EACwB,EAAE;IAC3C,MAAM,GAAG,GAAG,MAAM,KAAK,CACrB,cAAc,OAAO,uBAAuB,oBAAoB,IAAI,UAAU,WAAW,MAAM,UAAU,KAAK,EAAE,EAChH;QACE,OAAO,EAAE,cAAc;KACxB,CACF,CAAC;IACF,OAAO,GAAG,CAAC;AACb,CAAC,CAAC;AAbW,QAAA,sBAAsB,0BAajC;AAEK,MAAM,+BAA+B,GAAG,KAAK,EAClD,IAAY,EACZ,UAAkB,EACQ,EAAE;IAC5B,IAAI,MAAM,GAAoB,EAAE,CAAC;IACjC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,MAAM,GAAG,eAAe,CAAC;IAE7B,OAAO,MAAM,KAAK,eAAe,EAAE,CAAC;QAClC,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,IAAA,8BAAsB,EAAC,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;QACxF,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAE5B,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;QACpB,MAAM,IAAI,MAAM,CAAC;IACnB,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC;AAC1D,CAAC,CAAC;AAjBW,QAAA,+BAA+B,mCAiB1C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { mapTxToOps, getAddress, getTxToBroadcast, getAccountShape, getSubAccount, valueFromUnit, } from "./utils";
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common-logic/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/common-logic/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,aAAa,GACd,MAAM,SAAS,CAAC"}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.valueFromUnit = exports.getSubAccount = exports.getAccountShape = exports.getTxToBroadcast = exports.getAddress = exports.mapTxToOps =
|
|
3
|
+
exports.valueFromUnit = exports.getSubAccount = exports.getAccountShape = exports.getTxToBroadcast = exports.getAddress = exports.mapTxToOps = void 0;
|
|
4
4
|
var utils_1 = require("./utils");
|
|
5
|
-
Object.defineProperty(exports, "getUnit", { enumerable: true, get: function () { return utils_1.getUnit; } });
|
|
6
|
-
Object.defineProperty(exports, "processTxs", { enumerable: true, get: function () { return utils_1.processTxs; } });
|
|
7
5
|
Object.defineProperty(exports, "mapTxToOps", { enumerable: true, get: function () { return utils_1.mapTxToOps; } });
|
|
8
6
|
Object.defineProperty(exports, "getAddress", { enumerable: true, get: function () { return utils_1.getAddress; } });
|
|
9
7
|
Object.defineProperty(exports, "getTxToBroadcast", { enumerable: true, get: function () { return utils_1.getTxToBroadcast; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common-logic/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/common-logic/index.ts"],"names":[],"mappings":";;;AAAA,iCAOiB;AANf,mGAAA,UAAU,OAAA;AACV,mGAAA,UAAU,OAAA;AACV,yGAAA,gBAAgB,OAAA;AAChB,wGAAA,eAAe,OAAA;AACf,sGAAA,aAAa,OAAA;AACb,sGAAA,aAAa,OAAA"}
|
|
@@ -3,8 +3,6 @@ import type { Unit } from "@ledgerhq/types-cryptoassets";
|
|
|
3
3
|
import { BigNumber } from "bignumber.js";
|
|
4
4
|
import { BroadcastTransactionRequest, TransactionResponse, Transaction } from "../types";
|
|
5
5
|
import { GetAccountShape, AccountShapeInfo } from "@ledgerhq/coin-framework/bridge/jsHelpers";
|
|
6
|
-
export declare const getUnit: () => Unit;
|
|
7
|
-
export declare const processTxs: (txs: TransactionResponse[]) => TransactionResponse[];
|
|
8
6
|
export declare const mapTxToOps: (accountId: string, { address }: AccountShapeInfo) => (tx: TransactionResponse) => Operation[];
|
|
9
7
|
export declare const getAddress: (a: Account) => {
|
|
10
8
|
address: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/common-logic/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/common-logic/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,2BAA2B,EAAE,mBAAmB,EAAY,WAAW,EAAE,MAAM,UAAU,CAAC;AACnG,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,2CAA2C,CAAC;AAO9F,eAAO,MAAM,UAAU,cACT,MAAM,eAAe,gBAAgB,UAC5C,mBAAmB,KAAG,SAAS,EAmDnC,CAAC;AAEJ,eAAO,MAAM,UAAU,MAClB,OAAO,KACT;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;CAC6C,CAAC;AAEvE,eAAO,MAAM,gBAAgB,cAChB,SAAS,aACT,MAAM,WACR,OAAO,MAAM,EAAE,GAAG,CAAC,KAC3B,2BAiCF,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,eAiC7B,CAAC;AAEF,eAAO,MAAM,aAAa,YAAa,OAAO,MAAM,WAAW,mEAO9D,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,aAAa,gBAAiB,SAAS,QAAQ,IAAI,cACN,CAAC"}
|
|
@@ -3,10 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.valueFromUnit = exports.getSubAccount = exports.getAccountShape = exports.getTxToBroadcast = exports.getAddress = exports.mapTxToOps =
|
|
7
|
-
const logs_1 = require("@ledgerhq/logs");
|
|
8
|
-
const currencies_1 = require("@ledgerhq/coin-framework/currencies");
|
|
9
|
-
const cryptoassets_1 = require("@ledgerhq/cryptoassets");
|
|
6
|
+
exports.valueFromUnit = exports.getSubAccount = exports.getAccountShape = exports.getTxToBroadcast = exports.getAddress = exports.mapTxToOps = void 0;
|
|
10
7
|
const bignumber_js_1 = require("bignumber.js");
|
|
11
8
|
const types_1 = require("../types");
|
|
12
9
|
const api_1 = require("../api/api");
|
|
@@ -14,65 +11,12 @@ const account_1 = require("@ledgerhq/coin-framework/account");
|
|
|
14
11
|
const operation_1 = require("@ledgerhq/coin-framework/operation");
|
|
15
12
|
const flatMap_1 = __importDefault(require("lodash/flatMap"));
|
|
16
13
|
const tokenAccounts_1 = require("../erc20/tokenAccounts");
|
|
17
|
-
const getUnit = () => (0, cryptoassets_1.getCryptoCurrencyById)("filecoin").units[0];
|
|
18
|
-
exports.getUnit = getUnit;
|
|
19
|
-
const processTxs = (txs) => {
|
|
20
|
-
// Group all tx types related to same tx cid into the same object
|
|
21
|
-
const txsByTxCid = txs.reduce((txsByTxCidResult, currentTx) => {
|
|
22
|
-
const { hash: txCid, type: txType } = currentTx;
|
|
23
|
-
const txByType = txsByTxCidResult[txCid] || {};
|
|
24
|
-
switch (txType) {
|
|
25
|
-
case "Send":
|
|
26
|
-
txByType.Send = currentTx;
|
|
27
|
-
break;
|
|
28
|
-
case "InvokeContract":
|
|
29
|
-
txByType.InvokeContract = currentTx;
|
|
30
|
-
break;
|
|
31
|
-
case "Fee":
|
|
32
|
-
txByType.Fee = currentTx;
|
|
33
|
-
break;
|
|
34
|
-
default:
|
|
35
|
-
(0, logs_1.log)("warn", `tx type [${txType}] on tx cid [${txCid}] was not recognized.`);
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
txsByTxCidResult[txCid] = txByType;
|
|
39
|
-
return txsByTxCidResult;
|
|
40
|
-
}, {});
|
|
41
|
-
// Once all tx types have been grouped, we want to find
|
|
42
|
-
const processedTxs = [];
|
|
43
|
-
for (const txCid in txsByTxCid) {
|
|
44
|
-
const item = txsByTxCid[txCid];
|
|
45
|
-
const feeTx = item.Fee;
|
|
46
|
-
let mainTx;
|
|
47
|
-
if ("Send" in item) {
|
|
48
|
-
mainTx = item.Send;
|
|
49
|
-
}
|
|
50
|
-
else if ("InvokeContract" in item) {
|
|
51
|
-
mainTx = item.InvokeContract;
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
(0, logs_1.log)("warn", `unexpected tx type, tx with cid [${txCid}] and payload [${JSON.stringify(item)}]`);
|
|
55
|
-
}
|
|
56
|
-
if (!mainTx) {
|
|
57
|
-
if (feeTx) {
|
|
58
|
-
(0, logs_1.log)("warn", `feeTx [${feeTx.hash}] found without a mainTx linked to it.`);
|
|
59
|
-
}
|
|
60
|
-
continue;
|
|
61
|
-
}
|
|
62
|
-
if (feeTx) {
|
|
63
|
-
mainTx.fee = feeTx.amount;
|
|
64
|
-
}
|
|
65
|
-
processedTxs.push(mainTx);
|
|
66
|
-
}
|
|
67
|
-
return processedTxs;
|
|
68
|
-
};
|
|
69
|
-
exports.processTxs = processTxs;
|
|
70
14
|
const mapTxToOps = (accountId, { address }) => (tx) => {
|
|
71
|
-
const { to, from, hash, timestamp, amount,
|
|
15
|
+
const { to, from, hash, timestamp, amount, fee_data, status } = tx;
|
|
72
16
|
const ops = [];
|
|
73
17
|
const date = new Date(timestamp * 1000);
|
|
74
|
-
const value =
|
|
75
|
-
const feeToUse =
|
|
18
|
+
const value = new bignumber_js_1.BigNumber(amount);
|
|
19
|
+
const feeToUse = new bignumber_js_1.BigNumber(fee_data?.TotalCost || 0);
|
|
76
20
|
const isSending = address === from;
|
|
77
21
|
const isReceiving = address === to;
|
|
78
22
|
const hasFailed = status !== types_1.TxStatus.Ok;
|
|
@@ -140,7 +84,11 @@ const getTxToBroadcast = (operation, signature, rawData) => {
|
|
|
140
84
|
};
|
|
141
85
|
exports.getTxToBroadcast = getTxToBroadcast;
|
|
142
86
|
const getAccountShape = async (info) => {
|
|
143
|
-
const { address, currency, derivationMode } = info;
|
|
87
|
+
const { address, currency, derivationMode, initialAccount } = info;
|
|
88
|
+
const blockSafeDelta = 1200;
|
|
89
|
+
let lastHeight = (initialAccount?.blockHeight ?? 0) - blockSafeDelta;
|
|
90
|
+
if (lastHeight < 0)
|
|
91
|
+
lastHeight = 0;
|
|
144
92
|
const accountId = (0, account_1.encodeAccountId)({
|
|
145
93
|
type: "js",
|
|
146
94
|
version: "2",
|
|
@@ -148,18 +96,18 @@ const getAccountShape = async (info) => {
|
|
|
148
96
|
xpubOrAddress: address,
|
|
149
97
|
derivationMode,
|
|
150
98
|
});
|
|
151
|
-
const blockHeight = await
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
99
|
+
const [blockHeight, balance, rawTxs, tokenAccounts] = await Promise.all([
|
|
100
|
+
(0, api_1.fetchBlockHeight)(),
|
|
101
|
+
(0, api_1.fetchBalances)(address),
|
|
102
|
+
(0, api_1.fetchTxsWithPages)(address, lastHeight),
|
|
103
|
+
(0, tokenAccounts_1.buildTokenAccounts)(address, lastHeight, accountId, info.initialAccount),
|
|
104
|
+
]);
|
|
156
105
|
const result = {
|
|
157
106
|
id: accountId,
|
|
158
107
|
subAccounts: tokenAccounts,
|
|
159
108
|
balance: new bignumber_js_1.BigNumber(balance.total_balance),
|
|
160
109
|
spendableBalance: new bignumber_js_1.BigNumber(balance.spendable_balance),
|
|
161
|
-
operations,
|
|
162
|
-
operationsCount: operations.length,
|
|
110
|
+
operations: (0, flatMap_1.default)(rawTxs, (0, exports.mapTxToOps)(accountId, info)).sort((a, b) => b.date.getTime() - a.date.getTime()),
|
|
163
111
|
blockHeight: blockHeight.current_block_identifier.index,
|
|
164
112
|
};
|
|
165
113
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/common-logic/utils.ts"],"names":[],"mappings":";;;;;;AAEA
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/common-logic/utils.ts"],"names":[],"mappings":";;;;;;AAEA,+CAAyC;AACzC,oCAAmG;AAEnG,oCAAgF;AAChF,8DAAmE;AACnE,kEAAuE;AACvE,6DAAqC;AACrC,0DAA4D;AAErD,MAAM,UAAU,GACrB,CAAC,SAAiB,EAAE,EAAE,OAAO,EAAoB,EAAE,EAAE,CACrD,CAAC,EAAuB,EAAe,EAAE;IACvC,MAAM,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;IAEnE,MAAM,GAAG,GAAgB,EAAE,CAAC;IAC5B,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,CAAC;IACxC,MAAM,KAAK,GAAG,IAAI,wBAAS,CAAC,MAAM,CAAC,CAAC;IACpC,MAAM,QAAQ,GAAG,IAAI,wBAAS,CAAC,QAAQ,EAAE,SAAS,IAAI,CAAC,CAAC,CAAC;IAEzD,MAAM,SAAS,GA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,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,YAAY,CAAC;QAC3D,CAAC,CAAC,IAAI,CAAC;IAEX,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAPW,QAAA,aAAa,iBAOxB;AAEF;;;;GAIG;AACI,MAAM,aAAa,GAAG,CAAC,WAAsB,EAAE,IAAU,EAAE,EAAE,CAClE,WAAW,CAAC,KAAK,CAAC,IAAI,wBAAS,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;AAD9C,QAAA,aAAa,iBACiC"}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { Account, Operation, TokenAccount } from "@ledgerhq/types-live";
|
|
2
2
|
import { ERC20Transfer } from "../types";
|
|
3
3
|
import BigNumber from "bignumber.js";
|
|
4
|
-
|
|
5
|
-
export declare
|
|
6
|
-
export declare function buildTokenAccounts(filAddr: string, parentAccountId: string, initialAccount?: Account): Promise<TokenAccount[]>;
|
|
4
|
+
export declare const erc20TxnToOperation: (tx: ERC20Transfer, address: string, accountId: string) => Operation[];
|
|
5
|
+
export declare function buildTokenAccounts(filAddr: string, lastHeight: number, parentAccountId: string, initialAccount?: Account): Promise<TokenAccount[]>;
|
|
7
6
|
export declare const encodeTxnParams: (abiEncodedParams: string) => string;
|
|
8
7
|
export declare const abiEncodeTransferParams: (recipient: string, amount: string) => string;
|
|
9
8
|
export declare const generateTokenTxnParams: (recipient: string, amount: BigNumber) => string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tokenAccounts.d.ts","sourceRoot":"","sources":["../../src/erc20/tokenAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGxE,OAAO,EAAE,aAAa,EAAY,MAAM,UAAU,CAAC;AAInD,OAAO,SAAS,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"tokenAccounts.d.ts","sourceRoot":"","sources":["../../src/erc20/tokenAccounts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGxE,OAAO,EAAE,aAAa,EAAY,MAAM,UAAU,CAAC;AAInD,OAAO,SAAS,MAAM,cAAc,CAAC;AASrC,eAAO,MAAM,mBAAmB,OAC1B,aAAa,WACR,MAAM,aACJ,MAAM,KAChB,SAAS,EA0DX,CAAC;AAEF,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,eAAe,EAAE,MAAM,EACvB,cAAc,CAAC,EAAE,OAAO,GACvB,OAAO,CAAC,YAAY,EAAE,CAAC,CA2FzB;AAED,eAAO,MAAM,eAAe,qBAAsB,MAAM,WAUvD,CAAC;AAEF,eAAO,MAAM,uBAAuB,cAAe,MAAM,UAAU,MAAM,WAIxE,CAAC;AAEF,eAAO,MAAM,sBAAsB,cAAe,MAAM,UAAU,SAAS,WAU1E,CAAC"}
|
|
@@ -18,11 +18,11 @@ const ethers_1 = require("ethers");
|
|
|
18
18
|
const ERC20_json_1 = __importDefault(require("./ERC20.json"));
|
|
19
19
|
const errors_1 = require("@ledgerhq/errors");
|
|
20
20
|
const utils_1 = require("../bridge/utils");
|
|
21
|
-
const
|
|
22
|
-
const erc20TxnToOperation = (tx, address, accountId
|
|
21
|
+
const jsHelpers_1 = require("@ledgerhq/coin-framework/bridge/jsHelpers");
|
|
22
|
+
const erc20TxnToOperation = (tx, address, accountId) => {
|
|
23
23
|
try {
|
|
24
24
|
const { to, from, timestamp, tx_hash, tx_cid, amount, height, status } = tx;
|
|
25
|
-
const
|
|
25
|
+
const txAmount = new bignumber_js_1.default(amount);
|
|
26
26
|
const isSending = address.toLowerCase() === from.toLowerCase();
|
|
27
27
|
const isReceiving = address.toLowerCase() === to.toLowerCase();
|
|
28
28
|
const fee = new bignumber_js_1.default(0);
|
|
@@ -35,7 +35,7 @@ const erc20TxnToOperation = (tx, address, accountId, unit) => {
|
|
|
35
35
|
id: (0, operation_1.encodeOperationId)(accountId, hash, "OUT"),
|
|
36
36
|
hash,
|
|
37
37
|
type: "OUT",
|
|
38
|
-
value:
|
|
38
|
+
value: txAmount,
|
|
39
39
|
fee,
|
|
40
40
|
blockHeight: height,
|
|
41
41
|
blockHash: "",
|
|
@@ -52,7 +52,7 @@ const erc20TxnToOperation = (tx, address, accountId, unit) => {
|
|
|
52
52
|
id: (0, operation_1.encodeOperationId)(accountId, hash, "IN"),
|
|
53
53
|
hash,
|
|
54
54
|
type: "IN",
|
|
55
|
-
value,
|
|
55
|
+
value: txAmount,
|
|
56
56
|
fee,
|
|
57
57
|
blockHeight: height,
|
|
58
58
|
blockHash: "",
|
|
@@ -73,40 +73,48 @@ const erc20TxnToOperation = (tx, address, accountId, unit) => {
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
exports.erc20TxnToOperation = erc20TxnToOperation;
|
|
76
|
-
async function buildTokenAccounts(filAddr, parentAccountId, initialAccount) {
|
|
76
|
+
async function buildTokenAccounts(filAddr, lastHeight, parentAccountId, initialAccount) {
|
|
77
77
|
try {
|
|
78
|
-
const transfers = await (0, api_1.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
78
|
+
const transfers = await (0, api_1.fetchERC20TransactionsWithPages)(filAddr, lastHeight);
|
|
79
|
+
if (!transfers.length) {
|
|
80
|
+
return initialAccount?.subAccounts ?? [];
|
|
81
|
+
}
|
|
82
|
+
// Group transfers by contract address (normalized to lowercase)
|
|
83
|
+
const transfersByContract = transfers.reduce((acc, transfer) => {
|
|
84
|
+
const contractAddr = transfer.contract_address.toLowerCase();
|
|
85
|
+
transfer.contract_address = contractAddr;
|
|
86
|
+
if (!acc[contractAddr]) {
|
|
87
|
+
acc[contractAddr] = [];
|
|
86
88
|
}
|
|
87
|
-
|
|
89
|
+
acc[contractAddr].push(transfer);
|
|
90
|
+
return acc;
|
|
88
91
|
}, {});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
+
// Create lookup map for existing sub-accounts
|
|
93
|
+
const existingSubAccounts = new Map(initialAccount?.subAccounts?.map(sa => [sa.token.contractAddress.toLowerCase(), sa]) ?? []);
|
|
94
|
+
// Track which existing accounts we've processed
|
|
95
|
+
const processedContracts = new Set();
|
|
96
|
+
const tokenAccounts = [];
|
|
97
|
+
// Process accounts with new transfers
|
|
98
|
+
for (const [contractAddr, txns] of Object.entries(transfersByContract)) {
|
|
99
|
+
processedContracts.add(contractAddr);
|
|
100
|
+
const token = await (0, index_2.getCryptoAssetsStore)().findTokenByAddressInCurrency(contractAddr, "filecoin");
|
|
92
101
|
if (!token) {
|
|
93
|
-
(0, logs_1.log)("error", `filecoin token not found, addr: ${
|
|
102
|
+
(0, logs_1.log)("error", `filecoin token not found, addr: ${contractAddr}`);
|
|
94
103
|
continue;
|
|
95
104
|
}
|
|
96
|
-
const balance = await (0, api_1.fetchERC20TokenBalance)(filAddr,
|
|
97
|
-
const bnBalance = new bignumber_js_1.default(balance
|
|
105
|
+
const balance = await (0, api_1.fetchERC20TokenBalance)(filAddr, contractAddr);
|
|
106
|
+
const bnBalance = new bignumber_js_1.default(balance);
|
|
98
107
|
const tokenAccountId = (0, index_1.encodeTokenAccountId)(parentAccountId, token);
|
|
99
108
|
const operations = txns
|
|
100
|
-
.flatMap(txn => (0, exports.erc20TxnToOperation)(txn, filAddr, tokenAccountId
|
|
109
|
+
.flatMap(txn => (0, exports.erc20TxnToOperation)(txn, filAddr, tokenAccountId))
|
|
101
110
|
.flat()
|
|
102
111
|
.sort((a, b) => b.date.getTime() - a.date.getTime());
|
|
112
|
+
// Skip if no operations and zero balance
|
|
103
113
|
if (operations.length === 0 && bnBalance.isZero()) {
|
|
104
114
|
continue;
|
|
105
115
|
}
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
initialAccount.subAccounts.find(a => a.id === tokenAccountId);
|
|
109
|
-
const sub = {
|
|
116
|
+
const existingAccount = existingSubAccounts.get(contractAddr);
|
|
117
|
+
const tokenAccount = {
|
|
110
118
|
type: utils_1.AccountType.TokenAccount,
|
|
111
119
|
id: tokenAccountId,
|
|
112
120
|
parentId: parentAccountId,
|
|
@@ -114,15 +122,21 @@ async function buildTokenAccounts(filAddr, parentAccountId, initialAccount) {
|
|
|
114
122
|
balance: bnBalance,
|
|
115
123
|
spendableBalance: bnBalance,
|
|
116
124
|
operationsCount: txns.length,
|
|
117
|
-
operations,
|
|
118
|
-
pendingOperations:
|
|
119
|
-
creationDate: operations.length
|
|
120
|
-
swapHistory:
|
|
125
|
+
operations: (0, jsHelpers_1.mergeOps)(existingAccount?.operations ?? [], operations),
|
|
126
|
+
pendingOperations: existingAccount?.pendingOperations ?? [],
|
|
127
|
+
creationDate: operations[operations.length - 1]?.date ?? new Date(),
|
|
128
|
+
swapHistory: existingAccount?.swapHistory ?? [],
|
|
121
129
|
balanceHistoryCache: index_1.emptyHistoryCache, // calculated in the jsHelpers
|
|
122
130
|
};
|
|
123
|
-
|
|
131
|
+
tokenAccounts.push(tokenAccount);
|
|
132
|
+
}
|
|
133
|
+
// Add existing accounts that didn't have new transfers
|
|
134
|
+
for (const [contractAddr, existingAccount] of existingSubAccounts) {
|
|
135
|
+
if (!processedContracts.has(contractAddr)) {
|
|
136
|
+
tokenAccounts.push(existingAccount);
|
|
137
|
+
}
|
|
124
138
|
}
|
|
125
|
-
return
|
|
139
|
+
return tokenAccounts;
|
|
126
140
|
}
|
|
127
141
|
catch (e) {
|
|
128
142
|
(0, logs_1.log)("error", "filecoin error building token accounts", e);
|