@sonarwatch/portfolio-core 0.2.2 → 0.2.4
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/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/src/Fetcher.d.ts +12 -1
- package/src/Fetcher.js +55 -5
- package/src/Fetcher.js.map +1 -1
- package/src/utils/formatAddress.d.ts +3 -1
- package/src/utils/formatAddress.js +9 -5
- package/src/utils/formatAddress.js.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
|
|
4
4
|
|
|
5
|
+
## [0.2.4](https://github.com/sonarwatch/portfolio/compare/core-0.2.3...core-0.2.4) (2023-07-07)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## [0.2.3](https://github.com/sonarwatch/portfolio/compare/core-0.2.2...core-0.2.3) (2023-07-07)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
5
13
|
## [0.2.2](https://github.com/sonarwatch/portfolio/compare/core-0.2.1...core-0.2.2) (2023-07-06)
|
|
6
14
|
|
|
7
15
|
|
package/package.json
CHANGED
package/src/Fetcher.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AddressSystemType } from './Address';
|
|
1
2
|
import { Cache } from './Cache';
|
|
2
3
|
import { NetworkIdType } from './Network';
|
|
3
4
|
import { PortfolioElement } from './Portfolio';
|
|
@@ -7,4 +8,14 @@ export type Fetcher = {
|
|
|
7
8
|
networkId: NetworkIdType;
|
|
8
9
|
executor: FetcherExecutor;
|
|
9
10
|
};
|
|
10
|
-
export
|
|
11
|
+
export type FetcherResult = {
|
|
12
|
+
owner: string;
|
|
13
|
+
addressSystem: AddressSystemType;
|
|
14
|
+
fetcherIds: string[];
|
|
15
|
+
succeededFetcherIds: string[];
|
|
16
|
+
failedFetcherIds: string[];
|
|
17
|
+
elements: PortfolioElement[];
|
|
18
|
+
};
|
|
19
|
+
export declare function runFetchers(owner: string, addressSystem: AddressSystemType, fetchers: Fetcher[], cache: Cache): Promise<FetcherResult>;
|
|
20
|
+
export declare function runFetchersByNetworkId(owner: string, networkId: NetworkIdType, fetchers: Fetcher[], cache: Cache): Promise<FetcherResult>;
|
|
21
|
+
export declare function runFetcher(owner: string, fetcher: Fetcher, cache: Cache): Promise<FetcherResult>;
|
package/src/Fetcher.js
CHANGED
|
@@ -1,10 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
12
|
+
exports.runFetcher = exports.runFetchersByNetworkId = exports.runFetchers = void 0;
|
|
13
|
+
const constants_1 = require("./constants");
|
|
4
14
|
const utils_1 = require("./utils");
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
function runFetchers(owner, addressSystem, fetchers, cache) {
|
|
16
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
+
const fOwner = (0, utils_1.formatAddress)(owner, addressSystem);
|
|
18
|
+
const isFetchersValids = fetchers.every((f) => constants_1.networks[f.networkId].addressSystem === addressSystem);
|
|
19
|
+
if (!isFetchersValids)
|
|
20
|
+
throw new Error(`Not all fetchers have the right address system: ${addressSystem}`);
|
|
21
|
+
const promises = fetchers.map((f) => f.executor(fOwner, cache));
|
|
22
|
+
const result = yield Promise.allSettled(promises);
|
|
23
|
+
const failedFetcherIds = [];
|
|
24
|
+
const succeededFetcherIds = [];
|
|
25
|
+
const elements = result.flatMap((r, index) => {
|
|
26
|
+
const fetcherId = fetchers[index].id;
|
|
27
|
+
if (r.status === 'rejected') {
|
|
28
|
+
failedFetcherIds.push(fetcherId);
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
succeededFetcherIds.push(fetcherId);
|
|
32
|
+
return r.value;
|
|
33
|
+
});
|
|
34
|
+
const fetcherIds = failedFetcherIds.concat(succeededFetcherIds);
|
|
35
|
+
return {
|
|
36
|
+
owner: fOwner,
|
|
37
|
+
addressSystem,
|
|
38
|
+
fetcherIds,
|
|
39
|
+
succeededFetcherIds,
|
|
40
|
+
failedFetcherIds,
|
|
41
|
+
elements,
|
|
42
|
+
};
|
|
43
|
+
});
|
|
8
44
|
}
|
|
9
|
-
exports.
|
|
45
|
+
exports.runFetchers = runFetchers;
|
|
46
|
+
function runFetchersByNetworkId(owner, networkId, fetchers, cache) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const isFetchersValids = fetchers.every((f) => f.networkId === networkId);
|
|
49
|
+
if (!isFetchersValids)
|
|
50
|
+
throw new Error(`Not all fetchers have the right network id: ${networkId}`);
|
|
51
|
+
const { addressSystem } = constants_1.networks[networkId];
|
|
52
|
+
return runFetchers(owner, addressSystem, fetchers, cache);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.runFetchersByNetworkId = runFetchersByNetworkId;
|
|
56
|
+
function runFetcher(owner, fetcher, cache) {
|
|
57
|
+
return runFetchersByNetworkId(owner, fetcher.networkId, [fetcher], cache);
|
|
58
|
+
}
|
|
59
|
+
exports.runFetcher = runFetcher;
|
|
10
60
|
//# sourceMappingURL=Fetcher.js.map
|
package/src/Fetcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../../../../packages/core/src/Fetcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Fetcher.js","sourceRoot":"","sources":["../../../../packages/core/src/Fetcher.ts"],"names":[],"mappings":";;;;;;;;;;;;AAIA,2CAAuC;AACvC,mCAAwC;AAsBxC,SAAsB,WAAW,CAC/B,KAAa,EACb,aAAgC,EAChC,QAAmB,EACnB,KAAY;;QAEZ,MAAM,MAAM,GAAG,IAAA,qBAAa,EAAC,KAAK,EAAE,aAAa,CAAC,CAAC;QACnD,MAAM,gBAAgB,GAAG,QAAQ,CAAC,KAAK,CACrC,CAAC,CAAC,EAAE,EAAE,CAAC,oBAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,aAAa,KAAK,aAAa,CAC7D,CAAC;QACF,IAAI,CAAC,gBAAgB;YACnB,MAAM,IAAI,KAAK,CACb,mDAAmD,aAAa,EAAE,CACnE,CAAC;QAEJ,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAChE,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QAElD,MAAM,gBAAgB,GAAa,EAAE,CAAC;QACtC,MAAM,mBAAmB,GAAa,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE;YAC3C,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC,CAAC,MAAM,KAAK,UAAU,EAAE;gBAC3B,gBAAgB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;gBACjC,OAAO,EAAE,CAAC;aACX;YACD,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACpC,OAAO,CAAC,CAAC,KAAK,CAAC;QACjB,CAAC,CAAC,CAAC;QACH,MAAM,UAAU,GAAG,gBAAgB,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;QAChE,OAAO;YACL,KAAK,EAAE,MAAM;YACb,aAAa;YACb,UAAU;YACV,mBAAmB;YACnB,gBAAgB;YAChB,QAAQ;SACT,CAAC;IACJ,CAAC;CAAA;AAtCD,kCAsCC;AAED,SAAsB,sBAAsB,CAC1C,KAAa,EACb,SAAwB,EACxB,QAAmB,EACnB,KAAY;;QAEZ,MAAM,gBAAgB,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC;QAC1E,IAAI,CAAC,gBAAgB;YACnB,MAAM,IAAI,KAAK,CAAC,+CAA+C,SAAS,EAAE,CAAC,CAAC;QAE9E,MAAM,EAAE,aAAa,EAAE,GAAG,oBAAQ,CAAC,SAAS,CAAC,CAAC;QAC9C,OAAO,WAAW,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAC5D,CAAC;CAAA;AAZD,wDAYC;AAED,SAAgB,UAAU,CAAC,KAAa,EAAE,OAAgB,EAAE,KAAY;IACtE,OAAO,sBAAsB,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,CAAC;AAC5E,CAAC;AAFD,gCAEC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { NetworkIdType } from '../Network';
|
|
2
|
+
import { AddressSystemType } from '../Address';
|
|
2
3
|
export declare function formatBitcoinAddress(address: string): string;
|
|
3
4
|
export declare function formatMoveAddress(address: string): string;
|
|
4
5
|
export declare function formatEvmAddress(address: string): string;
|
|
5
6
|
export declare function formatSolanaAddress(address: string): string;
|
|
6
|
-
export declare function formatAddress(address: string,
|
|
7
|
+
export declare function formatAddress(address: string, addressSystem: AddressSystemType): string;
|
|
8
|
+
export declare function formatAddressByNetworkId(address: string, networkId: NetworkIdType): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatAddress = exports.formatSolanaAddress = exports.formatEvmAddress = exports.formatMoveAddress = exports.formatBitcoinAddress = void 0;
|
|
3
|
+
exports.formatAddressByNetworkId = exports.formatAddress = exports.formatSolanaAddress = exports.formatEvmAddress = exports.formatMoveAddress = exports.formatBitcoinAddress = void 0;
|
|
4
4
|
const address_1 = require("@ethersproject/address");
|
|
5
5
|
const addressValid_1 = require("./addressValid");
|
|
6
6
|
const Address_1 = require("../Address");
|
|
@@ -31,12 +31,16 @@ const formatters = {
|
|
|
31
31
|
[Address_1.AddressSystem.evm]: formatEvmAddress,
|
|
32
32
|
[Address_1.AddressSystem.move]: formatMoveAddress,
|
|
33
33
|
};
|
|
34
|
-
function formatAddress(address,
|
|
34
|
+
function formatAddress(address, addressSystem) {
|
|
35
|
+
const formatter = formatters[addressSystem];
|
|
36
|
+
return formatter(address);
|
|
37
|
+
}
|
|
38
|
+
exports.formatAddress = formatAddress;
|
|
39
|
+
function formatAddressByNetworkId(address, networkId) {
|
|
35
40
|
const network = constants_1.networks[networkId];
|
|
36
41
|
if (!network)
|
|
37
42
|
throw new Error(`NetworkId not supported: ${networkId}`);
|
|
38
|
-
|
|
39
|
-
return formatter(address);
|
|
43
|
+
return formatAddress(address, network.addressSystem);
|
|
40
44
|
}
|
|
41
|
-
exports.
|
|
45
|
+
exports.formatAddressByNetworkId = formatAddressByNetworkId;
|
|
42
46
|
//# sourceMappingURL=formatAddress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatAddress.js","sourceRoot":"","sources":["../../../../../packages/core/src/utils/formatAddress.ts"],"names":[],"mappings":";;;AAAA,oDAAoD;AACpD,iDAKwB;AAExB,wCAA8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