aftermath-ts-sdk 1.1.86 → 1.1.87-bridge.0
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/dist/general/historicalData/historicalDataApi.d.ts +1 -3
- package/dist/general/historicalData/historicalDataApi.d.ts.map +1 -1
- package/dist/general/historicalData/historicalDataApi.js +2 -2
- package/dist/general/historicalData/historicalDataApiInterface.d.ts +4 -2
- package/dist/general/historicalData/historicalDataApiInterface.d.ts.map +1 -1
- package/dist/general/historicalData/placeholderHistoricalDataApi.d.ts +4 -2
- package/dist/general/historicalData/placeholderHistoricalDataApi.d.ts.map +1 -1
- package/dist/general/historicalData/placeholderHistoricalDataApi.js +6 -1
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts +11 -6
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.d.ts.map +1 -1
- package/dist/general/prices/coingecko/coinGeckoApiHelpers.js +113 -53
- package/dist/general/prices/coingecko/coinGeckoPricesApi.d.ts +2 -3
- package/dist/general/prices/coingecko/coinGeckoPricesApi.d.ts.map +1 -1
- package/dist/general/prices/coingecko/coinGeckoPricesApi.js +180 -49
- package/dist/general/prices/coingecko/coinGeckoTypes.d.ts +2 -0
- package/dist/general/prices/coingecko/coinGeckoTypes.d.ts.map +1 -1
- package/dist/general/providers/aftermathApi.d.ts +9 -5
- package/dist/general/providers/aftermathApi.d.ts.map +1 -1
- package/dist/general/providers/aftermathApi.js +20 -15
- package/dist/general/types/index.d.ts +1 -0
- package/dist/general/types/index.d.ts.map +1 -1
- package/dist/general/types/index.js +1 -0
- package/dist/general/utils/helpers.d.ts +6 -1
- package/dist/general/utils/helpers.d.ts.map +1 -1
- package/dist/general/utils/helpers.js +31 -3
- package/dist/packages/coin/api/coinApi.d.ts +4 -1
- package/dist/packages/coin/api/coinApi.d.ts.map +1 -1
- package/dist/packages/coin/api/coinApi.js +163 -31
- package/dist/packages/coin/coin.d.ts +5 -0
- package/dist/packages/coin/coin.d.ts.map +1 -1
- package/dist/packages/coin/coin.js +6 -1
- package/package.json +1 -1
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { CoinType } from "../../types";
|
|
2
1
|
import { CoinGeckoApiHelpers } from "../prices/coingecko/coinGeckoApiHelpers";
|
|
3
|
-
import { CoinGeckoCoinApiId } from "../prices/coingecko/coinGeckoTypes";
|
|
4
2
|
import { AftermathApi } from "../providers";
|
|
5
3
|
import { HistoricalDataApiInterface } from "./historicalDataApiInterface";
|
|
6
4
|
export declare class HistoricalDataApi extends CoinGeckoApiHelpers implements HistoricalDataApiInterface {
|
|
7
|
-
constructor(Provider: AftermathApi, coinGeckoApiKey: string
|
|
5
|
+
constructor(Provider: AftermathApi, coinGeckoApiKey: string);
|
|
8
6
|
}
|
|
9
7
|
//# sourceMappingURL=historicalDataApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"historicalDataApi.d.ts","sourceRoot":"","sources":["../../../src/general/historicalData/historicalDataApi.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"historicalDataApi.d.ts","sourceRoot":"","sources":["../../../src/general/historicalData/historicalDataApi.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,yCAAyC,CAAC;AAE9E,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAE1E,qBAAa,iBACZ,SAAQ,mBACR,YAAW,0BAA0B;gBAMzB,QAAQ,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM;CAG3D"}
|
|
@@ -6,8 +6,8 @@ class HistoricalDataApi extends coinGeckoApiHelpers_1.CoinGeckoApiHelpers {
|
|
|
6
6
|
// =========================================================================
|
|
7
7
|
// Constructor
|
|
8
8
|
// =========================================================================
|
|
9
|
-
constructor(Provider, coinGeckoApiKey
|
|
10
|
-
super(Provider, coinGeckoApiKey
|
|
9
|
+
constructor(Provider, coinGeckoApiKey) {
|
|
10
|
+
super(Provider, coinGeckoApiKey);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
exports.HistoricalDataApi = HistoricalDataApi;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { CoinSymbol, CoinType } from "../../types";
|
|
2
|
-
import { CoinGeckoCoinData, CoinGeckoCoinSymbolData } from "../prices/coingecko/coinGeckoTypes";
|
|
2
|
+
import { CoinGeckoChain, CoinGeckoCoinData, CoinGeckoCoinSymbolData } from "../prices/coingecko/coinGeckoTypes";
|
|
3
3
|
import { CoinHistoricalData } from "./historicalDataTypes";
|
|
4
4
|
export interface HistoricalDataApiInterface {
|
|
5
|
-
|
|
5
|
+
fetchAllCoinDataForChains: (inputs: {
|
|
6
|
+
chains: CoinGeckoChain[];
|
|
7
|
+
}) => Promise<Partial<Record<"ethereum" | "arbitrum" | "bsc" | "solana" | "sui", Record<CoinType, CoinGeckoCoinData>>>>;
|
|
6
8
|
fetchAllCoinData: () => Promise<Record<CoinSymbol, CoinGeckoCoinSymbolData>>;
|
|
7
9
|
fetchHistoricalData: (inputs: {
|
|
8
10
|
coinApiId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"historicalDataApiInterface.d.ts","sourceRoot":"","sources":["../../../src/general/historicalData/historicalDataApiInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACN,iBAAiB,EACjB,uBAAuB,EACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,WAAW,0BAA0B;
|
|
1
|
+
{"version":3,"file":"historicalDataApiInterface.d.ts","sourceRoot":"","sources":["../../../src/general/historicalData/historicalDataApiInterface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACN,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACvB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,WAAW,0BAA0B;IAG1C,yBAAyB,EAAE,CAAC,MAAM,EAAE;QACnC,MAAM,EAAE,cAAc,EAAE,CAAC;KACzB,KAAK,OAAO,CACZ,OAAO,CACN,MAAM,CACL,UAAU,GAAG,UAAU,GAAG,KAAK,GAAG,QAAQ,GAAG,KAAK,EAClD,MAAM,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CACnC,CACD,CACD,CAAC;IAEF,gBAAgB,EAAE,MAAM,OAAO,CAC9B,MAAM,CAAC,UAAU,EAAE,uBAAuB,CAAC,CAC3C,CAAC;IAEF,mBAAmB,EAAE,CAAC,MAAM,EAAE;QAC7B,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;KAChB,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC;CAClC"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { CoinType } from "../../types";
|
|
2
|
-
import { CoinGeckoCoinData } from "../prices/coingecko/coinGeckoTypes";
|
|
2
|
+
import { CoinGeckoChain, CoinGeckoCoinData } from "../prices/coingecko/coinGeckoTypes";
|
|
3
3
|
import { HistoricalDataApiInterface } from "./historicalDataApiInterface";
|
|
4
4
|
import { CoinHistoricalData } from "./historicalDataTypes";
|
|
5
5
|
export declare class PlaceholderHistoricalDataApi implements HistoricalDataApiInterface {
|
|
6
|
-
|
|
6
|
+
fetchAllCoinDataForChains: (inputs: {
|
|
7
|
+
chains: CoinGeckoChain[];
|
|
8
|
+
}) => Promise<Partial<Record<"ethereum" | "arbitrum" | "bsc" | "solana" | "sui", Record<CoinType, CoinGeckoCoinData>>>>;
|
|
7
9
|
fetchAllCoinData: () => Promise<Record<CoinType, CoinGeckoCoinData>>;
|
|
8
10
|
fetchHistoricalData: (inputs: {
|
|
9
11
|
coinApiId: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"placeholderHistoricalDataApi.d.ts","sourceRoot":"","sources":["../../../src/general/historicalData/placeholderHistoricalDataApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACN,iBAAiB,EAEjB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,qBAAa,4BACZ,YAAW,0BAA0B;
|
|
1
|
+
{"version":3,"file":"placeholderHistoricalDataApi.d.ts","sourceRoot":"","sources":["../../../src/general/historicalData/placeholderHistoricalDataApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,QAAQ,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EACN,cAAc,EACd,iBAAiB,EAEjB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,qBAAa,4BACZ,YAAW,0BAA0B;IAQ9B,yBAAyB,WAAkB;QACjD,MAAM,EAAE,cAAc,EAAE,CAAC;KACzB,KAAG,QACH,QACC,OACC,UAAU,GAAG,UAAU,GAAG,KAAK,GAAG,QAAQ,GAAG,KAAK,EAClD,OAAO,QAAQ,EAAE,iBAAiB,CAAC,CACnC,CACD,CACD,CAEC;IAEK,gBAAgB,QAAa,QACnC,OAAO,QAAQ,EAAE,iBAAiB,CAAC,CACnC,CAEC;IAEK,mBAAmB,WAAkB;QAC3C,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;KAChB,KAAG,QAAQ,kBAAkB,CAAC,CAE7B;CACF"}
|
|
@@ -12,7 +12,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.PlaceholderHistoricalDataApi = void 0;
|
|
13
13
|
class PlaceholderHistoricalDataApi {
|
|
14
14
|
constructor() {
|
|
15
|
-
|
|
15
|
+
// public fetchAllSuiCoinData = async (): Promise<
|
|
16
|
+
// Record<CoinType, CoinGeckoCoinData>
|
|
17
|
+
// > => {
|
|
18
|
+
// return {};
|
|
19
|
+
// };
|
|
20
|
+
this.fetchAllCoinDataForChains = (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
16
21
|
return {};
|
|
17
22
|
});
|
|
18
23
|
this.fetchAllCoinData = () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CoinMetadaWithInfo, CoinPriceInfo, CoinType } from "../../../types";
|
|
2
2
|
import { CoinHistoricalData } from "../../historicalData/historicalDataTypes";
|
|
3
3
|
import { AftermathApi } from "../../providers";
|
|
4
|
-
import { CoinGeckoCoinApiId, CoinGeckoCoinData, CoinGeckoCoinSymbolData } from "./coinGeckoTypes";
|
|
4
|
+
import { CoinGeckoChain, CoinGeckoCoinApiId, CoinGeckoCoinData, CoinGeckoCoinSymbolData } from "./coinGeckoTypes";
|
|
5
5
|
export declare class CoinGeckoApiHelpers {
|
|
6
6
|
protected readonly Provider: AftermathApi;
|
|
7
7
|
private readonly coinGeckoApiKey;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
constructor(Provider: AftermathApi, coinGeckoApiKey: string);
|
|
9
|
+
fetchAllCoinDataForChains: (...inputs: {
|
|
10
|
+
chains: CoinGeckoChain[];
|
|
11
|
+
}[]) => Promise<Partial<Record<"ethereum" | "arbitrum" | "bsc" | "solana" | "sui", Record<string, CoinGeckoCoinData>>>>;
|
|
12
|
+
fetchAllCoinData: (...inputs: never[]) => Promise<Record<string, CoinGeckoCoinSymbolData>>;
|
|
13
|
+
fetchCoinMetadata: (...inputs: {
|
|
14
|
+
coinType: CoinType;
|
|
15
|
+
chain: CoinGeckoChain;
|
|
16
|
+
}[]) => Promise<CoinMetadaWithInfo | undefined>;
|
|
12
17
|
fetchHistoricalData: (...inputs: {
|
|
13
18
|
coinApiId: CoinGeckoCoinApiId;
|
|
14
19
|
daysAgo: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coinGeckoApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/general/prices/coingecko/coinGeckoApiHelpers.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"coinGeckoApiHelpers.d.ts","sourceRoot":"","sources":["../../../../src/general/prices/coingecko/coinGeckoApiHelpers.ts"],"names":[],"mappings":"AACA,OAAO,EAEN,kBAAkB,EAClB,aAAa,EAEb,QAAQ,EAER,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EACN,cAAc,EACd,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACvB,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,mBAAmB;IAM9B,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,YAAY;IACzC,OAAO,CAAC,QAAQ,CAAC,eAAe;gBADb,QAAQ,EAAE,YAAY,EACxB,eAAe,EAAE,MAAM;IAYlC,yBAAyB;gBAItB,cAAc,EAAE;4HAyGvB;IAEI,gBAAgB,2EAkBpB;IAGI,iBAAiB;kBAIZ,QAAQ;eACX,cAAc;oDAiDpB;IAMI,mBAAmB;mBAIb,kBAAkB;iBACpB,MAAM;wCA2Bd;IAMI,6BAA6B;sBAIpB,OAAO,QAAQ,EAAE,kBAAkB,CAAC;mDAmFjD;IAUH,OAAO,CAAC,OAAO,CAeb;IAEF,OAAO,CAAC,gBAAgB,CAarB;CACH"}
|
|
@@ -16,73 +16,133 @@ class CoinGeckoApiHelpers {
|
|
|
16
16
|
// =========================================================================
|
|
17
17
|
// Constructor
|
|
18
18
|
// =========================================================================
|
|
19
|
-
constructor(Provider, coinGeckoApiKey
|
|
19
|
+
constructor(Provider, coinGeckoApiKey) {
|
|
20
20
|
this.Provider = Provider;
|
|
21
21
|
this.coinGeckoApiKey = coinGeckoApiKey;
|
|
22
|
-
this.coinApiIdsToCoinTypes = coinApiIdsToCoinTypes;
|
|
23
22
|
// =========================================================================
|
|
24
23
|
// Public
|
|
25
24
|
// =========================================================================
|
|
26
25
|
// =========================================================================
|
|
27
26
|
// Coin Data
|
|
28
27
|
// =========================================================================
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
28
|
+
// TODO: add cache by chain as well
|
|
29
|
+
this.fetchAllCoinDataForChains = this.Provider.withCache({
|
|
30
|
+
key: "coinGeckoApiHelpers.fetchAllCoinDataForChains",
|
|
31
|
+
expirationSeconds: 604800,
|
|
32
|
+
callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const { chains } = inputs;
|
|
34
|
+
if (chains.length <= 0)
|
|
35
|
+
return {};
|
|
36
|
+
const coinData = yield this.fetchRawCoinData();
|
|
37
|
+
const chainsCoinData = coinData
|
|
38
|
+
.filter((data) => chains.some((chain) => chain in data.platforms) ||
|
|
39
|
+
chains.some((chain) => chain === data.id))
|
|
40
|
+
.map((data) => chains.map((chain) => {
|
|
41
|
+
const coinType = chain === "sui" && data.id === "sui"
|
|
42
|
+
? packages_1.Coin.constants.suiCoinType
|
|
43
|
+
: data.platforms[chain];
|
|
38
44
|
if (!coinType)
|
|
39
|
-
|
|
45
|
+
return undefined;
|
|
40
46
|
return {
|
|
47
|
+
chain,
|
|
41
48
|
apiId: data.id,
|
|
42
49
|
name: data.name,
|
|
43
50
|
symbol: data.symbol,
|
|
44
|
-
coinType:
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
catch (e) {
|
|
48
|
-
return undefined;
|
|
49
|
-
}
|
|
50
|
-
})
|
|
51
|
-
.filter((data) => data !== undefined);
|
|
52
|
-
const partialCoinDataObject = suiCoinData.reduce((acc, data) => {
|
|
53
|
-
return Object.assign({ [data.coinType]: data }, acc);
|
|
54
|
-
}, {});
|
|
55
|
-
const coinDataObject = Object.entries(this.coinApiIdsToCoinTypes).reduce((acc, [coinApiId, coinTypes]) => {
|
|
56
|
-
const foundSuiData = Object.values(partialCoinDataObject).find((data) => data.apiId === coinApiId);
|
|
57
|
-
let foundData = foundSuiData;
|
|
58
|
-
if (!foundData) {
|
|
59
|
-
const foundCoinData = coinData.find((data) => data.id === coinApiId);
|
|
60
|
-
if (!foundCoinData)
|
|
61
|
-
return acc;
|
|
62
|
-
foundData = {
|
|
63
|
-
apiId: coinApiId,
|
|
64
|
-
name: foundCoinData.name,
|
|
65
|
-
symbol: foundCoinData.symbol,
|
|
66
|
-
coinType: "",
|
|
51
|
+
coinType: chain === "sui"
|
|
52
|
+
? utils_1.Helpers.addLeadingZeroesToType(coinType)
|
|
53
|
+
: coinType,
|
|
67
54
|
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
55
|
+
}))
|
|
56
|
+
.reduce((acc, data) => [...acc, ...data], [])
|
|
57
|
+
.filter((data) => data !== undefined);
|
|
58
|
+
// const partialCoinDataObject: Record<CoinType, CoinGeckoCoinData> =
|
|
59
|
+
const coinDataObject = chainsCoinData.reduce((acc, data) => {
|
|
60
|
+
return Object.assign({ [data.coinType]: data }, acc);
|
|
61
|
+
}, {});
|
|
62
|
+
// const coinDataObject = Object.entries(
|
|
63
|
+
// this.coinApiIdsToCoinTypes
|
|
64
|
+
// ).reduce((acc, [coinApiId, coinTypes]) => {
|
|
65
|
+
// const foundChainData = Object.values(
|
|
66
|
+
// partialCoinDataObject
|
|
67
|
+
// ).find((data) => data.apiId === coinApiId);
|
|
68
|
+
// let foundData = foundChainData;
|
|
69
|
+
// if (!foundData) {
|
|
70
|
+
// const foundCoinData = coinData.find(
|
|
71
|
+
// (data) => data.id === coinApiId
|
|
72
|
+
// );
|
|
73
|
+
// if (!foundCoinData) return acc;
|
|
74
|
+
// foundData = {
|
|
75
|
+
// apiId: coinApiId,
|
|
76
|
+
// name: foundCoinData.name,
|
|
77
|
+
// symbol: foundCoinData.symbol,
|
|
78
|
+
// coinType: "",
|
|
79
|
+
// chain: "",
|
|
80
|
+
// };
|
|
81
|
+
// }
|
|
82
|
+
// if (!foundData) return acc;
|
|
83
|
+
// const dataToDuplicate = foundData;
|
|
84
|
+
// const newData = coinTypes.reduce((acc, coinType) => {
|
|
85
|
+
// const chain: CoinGeckoChain = Helpers.isValidType(coinType)
|
|
86
|
+
// ? "sui"
|
|
87
|
+
// : Helpers.splitNonSuiCoinType(coinType).chain;
|
|
88
|
+
// return {
|
|
89
|
+
// [coinType]: {
|
|
90
|
+
// ...dataToDuplicate,
|
|
91
|
+
// coinType,
|
|
92
|
+
// chain,
|
|
93
|
+
// },
|
|
94
|
+
// ...acc,
|
|
95
|
+
// };
|
|
96
|
+
// }, acc);
|
|
97
|
+
// return newData;
|
|
98
|
+
// }, partialCoinDataObject);
|
|
99
|
+
return Object.entries(coinDataObject).reduce((acc, [coinType, data]) => {
|
|
100
|
+
var _a;
|
|
101
|
+
return data.chain === ""
|
|
102
|
+
? {}
|
|
103
|
+
: Object.assign(Object.assign({}, acc), { [data.chain]: Object.assign(Object.assign({}, ((_a = acc[data.chain]) !== null && _a !== void 0 ? _a : {})), { [coinType]: data }) });
|
|
104
|
+
}, {});
|
|
105
|
+
}),
|
|
76
106
|
});
|
|
77
|
-
this.fetchAllCoinData =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
107
|
+
this.fetchAllCoinData = this.Provider.withCache({
|
|
108
|
+
key: "coinGeckoApiHelpers.fetchAllCoinData",
|
|
109
|
+
expirationSeconds: 604800,
|
|
110
|
+
callback: () => __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const coinData = yield this.fetchRawCoinData();
|
|
112
|
+
return coinData.reduce((acc, data) => {
|
|
113
|
+
return Object.assign({ [data.symbol.toLowerCase()]: {
|
|
114
|
+
apiId: data.id,
|
|
115
|
+
name: data.name,
|
|
116
|
+
symbol: data.symbol.toLowerCase(),
|
|
117
|
+
} }, acc);
|
|
118
|
+
}, {});
|
|
119
|
+
}),
|
|
120
|
+
});
|
|
121
|
+
// TODO: handle multiple
|
|
122
|
+
this.fetchCoinMetadata = this.Provider.withCache({
|
|
123
|
+
key: "coinGeckoApiHelpers.fetchCoinMetadata",
|
|
124
|
+
expirationSeconds: -1,
|
|
125
|
+
callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
126
|
+
var _a, _b;
|
|
127
|
+
const { coinType, chain } = inputs;
|
|
128
|
+
// Fetch the list of coins and filter by token address
|
|
129
|
+
const coins = yield this.fetchRawCoinData();
|
|
130
|
+
const coin = coins.find((c) => { var _a; return ((_a = c.platforms[chain]) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === coinType.toLowerCase(); });
|
|
131
|
+
if (!coin)
|
|
132
|
+
return undefined;
|
|
133
|
+
// Fetch detailed coin metadata
|
|
134
|
+
const coinDetails = yield this.callApi(`coins/${coin.id}?tickers=false&market_data=false&community_data=false&developer_data=false&sparkline=false`);
|
|
135
|
+
const { detail_platforms, name, symbol, description, image } = coinDetails;
|
|
136
|
+
return {
|
|
137
|
+
id: null,
|
|
138
|
+
name,
|
|
139
|
+
symbol: symbol.toUpperCase(),
|
|
140
|
+
description: description.en,
|
|
141
|
+
iconUrl: image.small,
|
|
142
|
+
decimals: (_b = (_a = detail_platforms[inputs.chain]) === null || _a === void 0 ? void 0 : _a.decimal_place) !== null && _b !== void 0 ? _b : -1,
|
|
143
|
+
isGenerated: false,
|
|
144
|
+
};
|
|
145
|
+
}),
|
|
86
146
|
});
|
|
87
147
|
// =========================================================================
|
|
88
148
|
// Historical Data
|
|
@@ -168,7 +228,7 @@ class CoinGeckoApiHelpers {
|
|
|
168
228
|
return castedRes;
|
|
169
229
|
});
|
|
170
230
|
this.fetchRawCoinData = this.Provider.withCache({
|
|
171
|
-
key: "coinGeckoApiHelpers.
|
|
231
|
+
key: "coinGeckoApiHelpers.fetchRawCoinData",
|
|
172
232
|
expirationSeconds: 86400,
|
|
173
233
|
callback: () => {
|
|
174
234
|
return this.callApi("coins/list?include_platform=true");
|
|
@@ -4,15 +4,14 @@ import { PricesApiInterface } from "../pricesApiInterface";
|
|
|
4
4
|
import { CoinGeckoApiHelpers } from "./coinGeckoApiHelpers";
|
|
5
5
|
import { CoinGeckoCoinApiId } from "./coinGeckoTypes";
|
|
6
6
|
export declare class CoinGeckoPricesApi extends CoinGeckoApiHelpers implements PricesApiInterface {
|
|
7
|
+
private readonly coinApiIdsToCoinTypes;
|
|
7
8
|
constructor(Provider: AftermathApi, coinGeckoApiKey: string, coinApiIdsToCoinTypes: Record<CoinGeckoCoinApiId, CoinType[]>);
|
|
8
9
|
fetchPrice: (inputs: {
|
|
9
10
|
coin: CoinType;
|
|
10
11
|
}) => Promise<number>;
|
|
11
12
|
fetchCoinsToPrice: (...inputs: {
|
|
12
13
|
coins: CoinType[];
|
|
13
|
-
}[]) => Promise<
|
|
14
|
-
[x: string]: number;
|
|
15
|
-
}>;
|
|
14
|
+
}[]) => Promise<Record<string, number>>;
|
|
16
15
|
fetchCoinsToPriceInfo: (...inputs: {
|
|
17
16
|
coins: CoinType[];
|
|
18
17
|
}[]) => Promise<Record<string, CoinPriceInfo>>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coinGeckoPricesApi.d.ts","sourceRoot":"","sources":["../../../../src/general/prices/coingecko/coinGeckoPricesApi.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EAGb,QAAQ,EAGR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"coinGeckoPricesApi.d.ts","sourceRoot":"","sources":["../../../../src/general/prices/coingecko/coinGeckoPricesApi.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EAGb,QAAQ,EAGR,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAEN,kBAAkB,EAGlB,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,kBACZ,SAAQ,mBACR,YAAW,kBAAkB;IAS5B,OAAO,CAAC,QAAQ,CAAC,qBAAqB;gBAFtC,QAAQ,EAAE,YAAY,EACtB,eAAe,EAAE,MAAM,EACN,qBAAqB,EAAE,MAAM,CAC7C,kBAAkB,EAClB,QAAQ,EAAE,CACV;IAiBK,UAAU,WAAkB;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,KAAG,QAAQ,MAAM,CAAC,CAMrE;IAGK,iBAAiB;eAIf,QAAQ,EAAE;4CAkJhB;IAGI,qBAAqB;eAInB,QAAQ,EAAE;mDAwMhB;IAMI,4BAA4B,WAAkB;QACpD,YAAY,EAAE,OAAO,QAAQ,EAAE,kBAAkB,CAAC,CAAC;KACnD,KAAG,QAAQ,OAAO,QAAQ,EAAE,MAAM,CAAC,CAAC,CAcnC;CACF"}
|
|
@@ -18,7 +18,8 @@ class CoinGeckoPricesApi extends coinGeckoApiHelpers_1.CoinGeckoApiHelpers {
|
|
|
18
18
|
// Constructor
|
|
19
19
|
// =========================================================================
|
|
20
20
|
constructor(Provider, coinGeckoApiKey, coinApiIdsToCoinTypes) {
|
|
21
|
-
super(Provider, coinGeckoApiKey
|
|
21
|
+
super(Provider, coinGeckoApiKey);
|
|
22
|
+
this.coinApiIdsToCoinTypes = coinApiIdsToCoinTypes;
|
|
22
23
|
// =========================================================================
|
|
23
24
|
// Fetching
|
|
24
25
|
// =========================================================================
|
|
@@ -39,29 +40,86 @@ class CoinGeckoPricesApi extends coinGeckoApiHelpers_1.CoinGeckoApiHelpers {
|
|
|
39
40
|
expirationSeconds: 300,
|
|
40
41
|
callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
41
42
|
const { coins } = inputs;
|
|
42
|
-
|
|
43
|
-
const [
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
43
|
+
const [suiCoins, nonSuiCoins] = yield utils_1.Helpers.bifilter(coins, (coin) => utils_1.Helpers.isValidType(coin));
|
|
44
|
+
const [suiCoinsToPrice, nonSuiCoinsToPrice] = yield Promise.all([
|
|
45
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
if (suiCoins.length <= 0)
|
|
47
|
+
return {};
|
|
48
|
+
// filter regular vs LP coins
|
|
49
|
+
const [lpCoins, regularCoins] = yield utils_1.Helpers.bifilterAsync(suiCoins, (coin) => __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
return this.Provider.Pools().fetchIsLpCoinType({
|
|
51
|
+
lpCoinType: coin,
|
|
52
|
+
});
|
|
53
|
+
}));
|
|
54
|
+
// const allSuiCoinData: Record<
|
|
55
|
+
// CoinSymbol,
|
|
56
|
+
// CoinGeckoCoinSymbolData
|
|
57
|
+
// > =
|
|
58
|
+
// (
|
|
59
|
+
// await this.fetchAllCoinDataForChains({
|
|
60
|
+
// chains: ["sui"],
|
|
61
|
+
// })
|
|
62
|
+
// )["sui"] ?? {};
|
|
63
|
+
// const neededCoinData = Helpers.filterObject(
|
|
64
|
+
// allSuiCoinData,
|
|
65
|
+
// (coin) =>
|
|
66
|
+
// regularCoins
|
|
67
|
+
// .map(Helpers.addLeadingZeroesToType)
|
|
68
|
+
// .includes(Helpers.addLeadingZeroesToType(coin))
|
|
69
|
+
// );
|
|
70
|
+
// const coinsToApiId: Record<CoinType, CoinGeckoCoinApiId> =
|
|
71
|
+
// Object.entries(neededCoinData).reduce(
|
|
72
|
+
// (acc, [coin, data]) => ({
|
|
73
|
+
// ...acc,
|
|
74
|
+
// [coin]: data.apiId,
|
|
75
|
+
// }),
|
|
76
|
+
// {}
|
|
77
|
+
// );
|
|
78
|
+
const [
|
|
79
|
+
// coinsToPrice,
|
|
80
|
+
lpCoinsToPrice,
|
|
81
|
+
// missingCoinsToPrice,
|
|
82
|
+
coinsToPrice,] = yield Promise.all([
|
|
83
|
+
// this.fetchCoinsToPriceGivenApiIds({
|
|
84
|
+
// coinsToApiId,
|
|
85
|
+
// }),
|
|
86
|
+
this.Provider.Pools().fetchLpCoinsToPrice({
|
|
87
|
+
lpCoins,
|
|
88
|
+
}),
|
|
89
|
+
new routerPricesApi_1.RouterPricesApi(this.Provider).fetchCoinsToPrice({
|
|
90
|
+
coins: suiCoins.filter((coin) =>
|
|
91
|
+
// !Object.keys(neededCoinData)
|
|
92
|
+
regularCoins
|
|
93
|
+
.map(utils_1.Helpers.addLeadingZeroesToType)
|
|
94
|
+
.includes(utils_1.Helpers.addLeadingZeroesToType(coin))),
|
|
95
|
+
}),
|
|
96
|
+
]);
|
|
97
|
+
return Object.assign(Object.assign({}, coinsToPrice), lpCoinsToPrice);
|
|
98
|
+
}))(),
|
|
99
|
+
() => __awaiter(this, void 0, void 0, function* () {
|
|
100
|
+
var _a;
|
|
101
|
+
if (nonSuiCoins.length <= 0)
|
|
102
|
+
return {};
|
|
103
|
+
const chains = utils_1.Helpers.uniqueArray(nonSuiCoins.map((coin) => utils_1.Helpers.splitNonSuiCoinType(coin).chain));
|
|
104
|
+
const allNonSuiCoinData = (_a = (yield this.fetchAllCoinDataForChains({
|
|
105
|
+
// TODO: handle other chains
|
|
106
|
+
chains,
|
|
107
|
+
}))) !== null && _a !== void 0 ? _a : {};
|
|
108
|
+
const neededCoinData = Object.entries(allNonSuiCoinData)
|
|
109
|
+
.map(([chain, data]) => utils_1.Helpers.filterObject(Object.entries(data)
|
|
110
|
+
.map(([coinType, filteredData]) => ({
|
|
111
|
+
[coinType]: filteredData,
|
|
112
|
+
}))
|
|
113
|
+
.reduce((acc, curr) => (Object.assign(Object.assign({}, acc), curr)), {}), (coin) => nonSuiCoins.some((aCoin) => aCoin.toLowerCase() ===
|
|
114
|
+
coin.toLowerCase())))
|
|
115
|
+
.reduce((acc, curr) => (Object.assign(Object.assign({}, acc), curr)), {});
|
|
116
|
+
const coinsToApiId = Object.entries(neededCoinData).reduce((acc, [coin, data]) => (Object.assign(Object.assign({}, acc), { [coin]: data.apiId })), {});
|
|
117
|
+
return this.fetchCoinsToPriceGivenApiIds({
|
|
118
|
+
coinsToApiId,
|
|
119
|
+
});
|
|
62
120
|
}),
|
|
63
121
|
]);
|
|
64
|
-
return Object.assign(Object.assign(
|
|
122
|
+
return Object.assign(Object.assign({}, suiCoinsToPrice), nonSuiCoinsToPrice);
|
|
65
123
|
}),
|
|
66
124
|
});
|
|
67
125
|
// TODO: add single cache by coin type ?
|
|
@@ -70,34 +128,107 @@ class CoinGeckoPricesApi extends coinGeckoApiHelpers_1.CoinGeckoApiHelpers {
|
|
|
70
128
|
expirationSeconds: 300,
|
|
71
129
|
callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
72
130
|
const { coins } = inputs;
|
|
73
|
-
|
|
74
|
-
const [
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
131
|
+
const [suiCoins, nonSuiCoins] = yield utils_1.Helpers.bifilter(coins, (coin) => utils_1.Helpers.isValidType(coin));
|
|
132
|
+
const [suiCoinsPriceInfo, nonSuiCoinsPriceInfo] = yield Promise.all([
|
|
133
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
134
|
+
if (suiCoins.length <= 0)
|
|
135
|
+
return {};
|
|
136
|
+
// filter regular vs LP coins
|
|
137
|
+
const [lpCoins, regularCoins] = yield utils_1.Helpers.bifilterAsync(suiCoins, (coin) => __awaiter(this, void 0, void 0, function* () {
|
|
138
|
+
return this.Provider.Pools().fetchIsLpCoinType({
|
|
139
|
+
lpCoinType: coin,
|
|
140
|
+
});
|
|
141
|
+
}));
|
|
142
|
+
// const allSuiCoinData: Record<
|
|
143
|
+
// CoinType,
|
|
144
|
+
// CoinGeckoCoinSymbolData
|
|
145
|
+
// > =
|
|
146
|
+
// (
|
|
147
|
+
// await this.fetchAllCoinDataForChains({
|
|
148
|
+
// chains: ["sui"],
|
|
149
|
+
// })
|
|
150
|
+
// )["sui"] ?? {};
|
|
151
|
+
// const neededCoinData = Helpers.filterObject(
|
|
152
|
+
// allSuiCoinData,
|
|
153
|
+
// (coin) =>
|
|
154
|
+
// regularCoins
|
|
155
|
+
// .map(Helpers.addLeadingZeroesToType)
|
|
156
|
+
// .includes(
|
|
157
|
+
// Helpers.addLeadingZeroesToType(coin)
|
|
158
|
+
// )
|
|
159
|
+
// );
|
|
160
|
+
// const coinsToApiId: Record<
|
|
161
|
+
// CoinType,
|
|
162
|
+
// CoinGeckoCoinApiId
|
|
163
|
+
// > = Object.entries(neededCoinData).reduce(
|
|
164
|
+
// (acc, [coin, data]) => ({
|
|
165
|
+
// ...acc,
|
|
166
|
+
// [coin]: data.apiId,
|
|
167
|
+
// }),
|
|
168
|
+
// {}
|
|
169
|
+
// );
|
|
170
|
+
// get coin price info for regular coins and calc info for LP coins
|
|
171
|
+
const [
|
|
172
|
+
// regularCoinsToPriceInfo,
|
|
173
|
+
lpCoinsToPrice,
|
|
174
|
+
// missingRegularCoins,
|
|
175
|
+
regularCoinsToPriceInfo,] = yield Promise.all([
|
|
176
|
+
// this.fetchCoinsToPriceInfoInternal({
|
|
177
|
+
// coinsToApiId,
|
|
178
|
+
// }),
|
|
179
|
+
this.Provider.Pools().fetchLpCoinsToPrice({
|
|
180
|
+
lpCoins,
|
|
181
|
+
}),
|
|
182
|
+
new routerPricesApi_1.RouterPricesApi(this.Provider).fetchCoinsToPriceInfo({
|
|
183
|
+
coins: suiCoins.filter((coin) =>
|
|
184
|
+
// !Object.keys(neededCoinData)
|
|
185
|
+
regularCoins
|
|
186
|
+
.map(utils_1.Helpers.addLeadingZeroesToType)
|
|
187
|
+
.includes(utils_1.Helpers.addLeadingZeroesToType(coin))),
|
|
188
|
+
}),
|
|
189
|
+
]);
|
|
190
|
+
const lpCoinsToPriceInfo = Object.entries(lpCoinsToPrice).reduce((acc, [coin, price]) => (Object.assign(Object.assign({}, acc), { [coin]: {
|
|
191
|
+
price,
|
|
192
|
+
priceChange24HoursPercentage: 0,
|
|
193
|
+
} })), {});
|
|
194
|
+
// merge all collected data
|
|
195
|
+
const allInfo = Object.assign(Object.assign({}, lpCoinsToPriceInfo), regularCoinsToPriceInfo);
|
|
196
|
+
return allInfo;
|
|
197
|
+
}))(),
|
|
198
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
var _b;
|
|
200
|
+
if (nonSuiCoins.length <= 0)
|
|
201
|
+
return {};
|
|
202
|
+
if (nonSuiCoins.every((coin) => Object.values(this.coinApiIdsToCoinTypes)
|
|
203
|
+
.reduce((acc, coinTypes) => [
|
|
204
|
+
...acc,
|
|
205
|
+
...coinTypes,
|
|
206
|
+
], [])
|
|
207
|
+
.includes(coin))) {
|
|
208
|
+
return this.fetchCoinsToPriceInfoInternal({
|
|
209
|
+
coinsToApiId: nonSuiCoins.reduce((acc, coin) => (Object.assign(Object.assign({}, acc), { [coin]: Object.entries(this.coinApiIdsToCoinTypes).find(([, coinTypes]) => coinTypes.includes(coin))[0] })), {}),
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
const chains = utils_1.Helpers.uniqueArray(nonSuiCoins.map((coin) => utils_1.Helpers.splitNonSuiCoinType(coin).chain));
|
|
213
|
+
const allNonSuiCoinData = (_b = (yield this.fetchAllCoinDataForChains({
|
|
214
|
+
// TODO: handle other chains
|
|
215
|
+
chains,
|
|
216
|
+
}))) !== null && _b !== void 0 ? _b : {};
|
|
217
|
+
const neededCoinData = Object.entries(allNonSuiCoinData)
|
|
218
|
+
.map(([chain, data]) => utils_1.Helpers.filterObject(Object.entries(data)
|
|
219
|
+
.map(([coinType, filteredData]) => ({
|
|
220
|
+
[coinType]: filteredData,
|
|
221
|
+
}))
|
|
222
|
+
.reduce((acc, curr) => (Object.assign(Object.assign({}, acc), curr)), {}), (coin) => nonSuiCoins.some((aCoin) => aCoin.toLowerCase() ===
|
|
223
|
+
coin.toLowerCase())))
|
|
224
|
+
.reduce((acc, curr) => (Object.assign(Object.assign({}, acc), curr)), {});
|
|
225
|
+
const coinsToApiId = Object.entries(neededCoinData).reduce((acc, [coin, data]) => (Object.assign(Object.assign({}, acc), { [coin]: data.apiId })), {});
|
|
226
|
+
return this.fetchCoinsToPriceInfoInternal({
|
|
227
|
+
coinsToApiId,
|
|
228
|
+
});
|
|
229
|
+
}))(),
|
|
93
230
|
]);
|
|
94
|
-
|
|
95
|
-
price,
|
|
96
|
-
priceChange24HoursPercentage: 0,
|
|
97
|
-
} })), {});
|
|
98
|
-
// merge all collected data
|
|
99
|
-
const allInfo = Object.assign(Object.assign(Object.assign({}, missingRegularCoins), lpCoinsToPriceInfo), regularCoinsToPriceInfo);
|
|
100
|
-
return allInfo;
|
|
231
|
+
return Object.assign(Object.assign({}, suiCoinsPriceInfo), nonSuiCoinsPriceInfo);
|
|
101
232
|
}),
|
|
102
233
|
});
|
|
103
234
|
// =========================================================================
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { CoinSymbol, CoinType } from "../../../types";
|
|
2
|
+
export type CoinGeckoChain = Lowercase<"Ethereum" | "Arbitrum" | "Bsc" | "Solana" | "Sui">;
|
|
2
3
|
export type CoinGeckoCoinApiId = string;
|
|
3
4
|
export interface CoinGeckoCoinData {
|
|
5
|
+
chain: CoinGeckoChain | "";
|
|
4
6
|
apiId: CoinGeckoCoinApiId;
|
|
5
7
|
name: string;
|
|
6
8
|
symbol: CoinSymbol;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coinGeckoTypes.d.ts","sourceRoot":"","sources":["../../../../src/general/prices/coingecko/coinGeckoTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAc,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"coinGeckoTypes.d.ts","sourceRoot":"","sources":["../../../../src/general/prices/coingecko/coinGeckoTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAc,MAAM,gBAAgB,CAAC;AAOlE,MAAM,MAAM,cAAc,GAAG,SAAS,CACrC,UAAU,GAAG,UAAU,GAAG,KAAK,GAAG,QAAQ,GAAG,KAAK,CAoDlD,CAAC;AAMF,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAMxC,MAAM,WAAW,iBAAiB;IACjC,KAAK,EAAE,cAAc,GAAG,EAAE,CAAC;IAC3B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;CACnB;AAED,MAAM,WAAW,uBAAuB;IACvC,KAAK,EAAE,kBAAkB,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,UAAU,CAAC;CACnB"}
|
|
@@ -18,6 +18,7 @@ import { NftAmmApi } from "../../packages/nftAmm/api/nftAmmApi";
|
|
|
18
18
|
import { ReferralVaultApi } from "../../packages/referralVault/api/referralVaultApi";
|
|
19
19
|
import { ModuleName, MoveErrorCode, ObjectId, ScallopProviders } from "../../types";
|
|
20
20
|
import { HistoricalDataApi } from "../historicalData/historicalDataApi";
|
|
21
|
+
import { CoinGeckoPricesApi } from "../prices/coingecko/coinGeckoPricesApi";
|
|
21
22
|
import { PlaceholderHistoricalDataApi } from "../historicalData/placeholderHistoricalDataApi";
|
|
22
23
|
import { PerpetualsApi } from "../../packages/perpetuals/api/perpetualsApi";
|
|
23
24
|
import { OracleApi } from "../../packages/oracle/api/oracleApi";
|
|
@@ -30,7 +31,6 @@ import { DynamicGasApi } from "../dynamicGas/dynamicGasApi";
|
|
|
30
31
|
import { LeveragedStakingApi } from "../../packages/leveragedStaking/api/leveragedStakingApi";
|
|
31
32
|
import { NftsApi } from "../nfts/nftsApi";
|
|
32
33
|
import { MoveErrorsInterface } from "../types/moveErrorsInterface";
|
|
33
|
-
import { RouterPricesApi } from "../prices/router/routerPricesApi";
|
|
34
34
|
/**
|
|
35
35
|
* This class represents the Aftermath API and provides helper methods for various functionalities.
|
|
36
36
|
* @class
|
|
@@ -57,13 +57,17 @@ export declare class AftermathApi {
|
|
|
57
57
|
* @param provider - The SuiClient instance to use for interacting with the blockchain.
|
|
58
58
|
* @param addresses - The configuration addresses for the Aftermath protocol.
|
|
59
59
|
* @param indexerCaller - The IndexerCaller instance to use for querying the blockchain.
|
|
60
|
-
* @param
|
|
60
|
+
* @param apiKey - (Optional) The API key to use for querying CoinGecko for token prices.
|
|
61
61
|
*/
|
|
62
62
|
constructor(provider: SuiClient, addresses: ConfigAddresses, indexerCaller: IndexerCaller, config?: {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
coinGecko?: {
|
|
64
|
+
apiKey?: string | undefined;
|
|
65
65
|
coinApiIdsToCoinTypes?: Record<string, string[]> | undefined;
|
|
66
66
|
} | undefined;
|
|
67
|
+
infura?: {
|
|
68
|
+
projectId: string;
|
|
69
|
+
projectSecret: string;
|
|
70
|
+
} | undefined;
|
|
67
71
|
} | undefined, providerV0?: SuiClientV0 | undefined);
|
|
68
72
|
DynamicFields: () => DynamicFieldsApiHelpers;
|
|
69
73
|
Events: () => EventsApiHelpers;
|
|
@@ -73,7 +77,7 @@ export declare class AftermathApi {
|
|
|
73
77
|
Wallet: () => WalletApi;
|
|
74
78
|
DynamicGas: () => DynamicGasApi;
|
|
75
79
|
Nfts: () => NftsApi;
|
|
76
|
-
Prices: (() =>
|
|
80
|
+
Prices: (() => CoinGeckoPricesApi) | (() => PlaceholderPricesApi);
|
|
77
81
|
HistoricalData: (() => HistoricalDataApi) | (() => PlaceholderHistoricalDataApi);
|
|
78
82
|
Coin: () => CoinApi;
|
|
79
83
|
Sui: () => SuiApi;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aftermathApi.d.ts","sourceRoot":"","sources":["../../../src/general/providers/aftermathApi.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,mCAAmC,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,qCAAqC,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MA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AmmApi_1 = require("../../packages/nftAmm/api/nftAmmApi");
|
|
28
28
|
const referralVaultApi_1 = require("../../packages/referralVault/api/referralVaultApi");
|
|
29
29
|
const historicalDataApi_1 = require("../historicalData/historicalDataApi");
|
|
30
|
+
const coinGeckoPricesApi_1 = require("../prices/coingecko/coinGeckoPricesApi");
|
|
30
31
|
const placeholderHistoricalDataApi_1 = require("../historicalData/placeholderHistoricalDataApi");
|
|
31
32
|
const perpetualsApi_1 = require("../../packages/perpetuals/api/perpetualsApi");
|
|
32
33
|
const oracleApi_1 = require("../../packages/oracle/api/oracleApi");
|
|
@@ -37,8 +38,7 @@ const dcaApi_1 = require("../../packages/dca/api/dcaApi");
|
|
|
37
38
|
const dynamicGasApi_1 = require("../dynamicGas/dynamicGasApi");
|
|
38
39
|
const leveragedStakingApi_1 = require("../../packages/leveragedStaking/api/leveragedStakingApi");
|
|
39
40
|
const nftsApi_1 = require("../nfts/nftsApi");
|
|
40
|
-
|
|
41
|
-
// import { MultisigApi } from "../../packages/multisig/api/multisigApi";
|
|
41
|
+
// import { Networkish } from "ethers";
|
|
42
42
|
/**
|
|
43
43
|
* This class represents the Aftermath API and provides helper methods for various functionalities.
|
|
44
44
|
* @class
|
|
@@ -52,7 +52,7 @@ class AftermathApi {
|
|
|
52
52
|
* @param provider - The SuiClient instance to use for interacting with the blockchain.
|
|
53
53
|
* @param addresses - The configuration addresses for the Aftermath protocol.
|
|
54
54
|
* @param indexerCaller - The IndexerCaller instance to use for querying the blockchain.
|
|
55
|
-
* @param
|
|
55
|
+
* @param apiKey - (Optional) The API key to use for querying CoinGecko for token prices.
|
|
56
56
|
*/
|
|
57
57
|
constructor(provider, addresses, indexerCaller, config, providerV0) {
|
|
58
58
|
var _a, _b, _c, _d;
|
|
@@ -78,26 +78,31 @@ class AftermathApi {
|
|
|
78
78
|
this.Wallet = () => new walletApi_1.WalletApi(this);
|
|
79
79
|
this.DynamicGas = () => new dynamicGasApi_1.DynamicGasApi(this);
|
|
80
80
|
this.Nfts = () => new nftsApi_1.NftsApi(this);
|
|
81
|
-
this.Prices = ((_b = (_a = this === null || this === void 0 ? void 0 : this.config) === null || _a === void 0 ? void 0 : _a.
|
|
82
|
-
? // ? () =>
|
|
83
|
-
// new CoinGeckoPricesApi(
|
|
84
|
-
// this,
|
|
85
|
-
// this?.config?.prices?.coinGeckoApiKey ?? "",
|
|
86
|
-
// this?.config?.prices?.coinApiIdsToCoinTypes ?? {}
|
|
87
|
-
// )
|
|
88
|
-
() => new routerPricesApi_1.RouterPricesApi(this)
|
|
89
|
-
: () => new placeholderPricesApi_1.PlaceholderPricesApi();
|
|
90
|
-
this.HistoricalData = ((_d = (_c = this === null || this === void 0 ? void 0 : this.config) === null || _c === void 0 ? void 0 : _c.prices) === null || _d === void 0 ? void 0 : _d.coinGeckoApiKey)
|
|
81
|
+
this.Prices = ((_b = (_a = this === null || this === void 0 ? void 0 : this.config) === null || _a === void 0 ? void 0 : _a.coinGecko) === null || _b === void 0 ? void 0 : _b.apiKey)
|
|
91
82
|
? () => {
|
|
92
83
|
var _a, _b, _c, _d, _e, _f;
|
|
93
|
-
return new
|
|
84
|
+
return new coinGeckoPricesApi_1.CoinGeckoPricesApi(this, (_c = (_b = (_a = this === null || this === void 0 ? void 0 : this.config) === null || _a === void 0 ? void 0 : _a.coinGecko) === null || _b === void 0 ? void 0 : _b.apiKey) !== null && _c !== void 0 ? _c : "", (_f = (_e = (_d = this === null || this === void 0 ? void 0 : this.config) === null || _d === void 0 ? void 0 : _d.coinGecko) === null || _e === void 0 ? void 0 : _e.coinApiIdsToCoinTypes) !== null && _f !== void 0 ? _f : {});
|
|
85
|
+
}
|
|
86
|
+
: // () => new RouterPricesApi(this)
|
|
87
|
+
() => new placeholderPricesApi_1.PlaceholderPricesApi();
|
|
88
|
+
this.HistoricalData = ((_d = (_c = this === null || this === void 0 ? void 0 : this.config) === null || _c === void 0 ? void 0 : _c.coinGecko) === null || _d === void 0 ? void 0 : _d.apiKey)
|
|
89
|
+
? () => {
|
|
90
|
+
var _a, _b, _c;
|
|
91
|
+
return new historicalDataApi_1.HistoricalDataApi(this, (_c = (_b = (_a = this === null || this === void 0 ? void 0 : this.config) === null || _a === void 0 ? void 0 : _a.coinGecko) === null || _b === void 0 ? void 0 : _b.apiKey) !== null && _c !== void 0 ? _c : ""
|
|
92
|
+
// this?.config?.coinGecko?.coinApiIdsToCoinTypes ?? {}
|
|
93
|
+
);
|
|
94
94
|
}
|
|
95
95
|
: () => new placeholderHistoricalDataApi_1.PlaceholderHistoricalDataApi();
|
|
96
96
|
// public PriceFeeds = new PriceFeedsApi(this.pythPriceServiceEndpoint);
|
|
97
97
|
// =========================================================================
|
|
98
98
|
// General Packages
|
|
99
99
|
// =========================================================================
|
|
100
|
-
this.Coin = () =>
|
|
100
|
+
this.Coin = () => {
|
|
101
|
+
var _a, _b;
|
|
102
|
+
return new coinApi_1.CoinApi(this, (_b = (_a = this === null || this === void 0 ? void 0 : this.config) === null || _a === void 0 ? void 0 : _a.coinGecko) === null || _b === void 0 ? void 0 : _b.apiKey
|
|
103
|
+
// this?.config?.infura
|
|
104
|
+
);
|
|
105
|
+
};
|
|
101
106
|
this.Sui = () => new suiApi_1.SuiApi(this);
|
|
102
107
|
// =========================================================================
|
|
103
108
|
// Aftermath Packages
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/general/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/general/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,oCAAoC,CAAC"}
|
|
@@ -19,3 +19,4 @@ __exportStar(require("./generalTypes"), exports);
|
|
|
19
19
|
__exportStar(require("./suiTypes"), exports);
|
|
20
20
|
__exportStar(require("../nfts/nftsTypes"), exports);
|
|
21
21
|
__exportStar(require("../dynamicGas/dynamicGasTypes"), exports);
|
|
22
|
+
__exportStar(require("../prices/coingecko/coinGeckoTypes"), exports);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DisplayFieldsResponse, SuiObjectResponse } from "@mysten/sui/client";
|
|
2
|
-
import { AnyObjectType, Balance, ScallopProviders, SuiNetwork, CoinsToDecimals, CoinsToPrice, ObjectId, Slippage, ModuleName, MoveErrorCode, SuiAddress } from "../../types";
|
|
2
|
+
import { AnyObjectType, Balance, ScallopProviders, SuiNetwork, CoinsToDecimals, CoinsToPrice, ObjectId, Slippage, ModuleName, MoveErrorCode, SuiAddress, CoinType, CoinGeckoChain } from "../../types";
|
|
3
3
|
import { DynamicFieldsApiHelpers } from "../apiHelpers/dynamicFieldsApiHelpers";
|
|
4
4
|
import { EventsApiHelpers } from "../apiHelpers/eventsApiHelpers";
|
|
5
5
|
import { InspectionsApiHelpers } from "../apiHelpers/inspectionsApiHelpers";
|
|
@@ -31,6 +31,10 @@ export declare class Helpers {
|
|
|
31
31
|
* @throws An error if the input type has a length greater than 64.
|
|
32
32
|
*/
|
|
33
33
|
static addLeadingZeroesToType: (type: AnyObjectType) => AnyObjectType;
|
|
34
|
+
static splitNonSuiCoinType: (coin: CoinType) => {
|
|
35
|
+
chain: Exclude<CoinGeckoChain, "sui">;
|
|
36
|
+
coinType: CoinType;
|
|
37
|
+
};
|
|
34
38
|
static isNumber: (str: string) => boolean;
|
|
35
39
|
static sum: (arr: number[]) => number;
|
|
36
40
|
static sumBigInt: (arr: bigint[]) => bigint;
|
|
@@ -61,6 +65,7 @@ export declare class Helpers {
|
|
|
61
65
|
static applySlippageBigInt: (amount: Balance, slippage: Slippage) => bigint;
|
|
62
66
|
static applySlippage: (amount: number, slippage: Slippage) => number;
|
|
63
67
|
static zip<S1, S2>(firstCollection: Array<S1>, lastCollection: Array<S2>): Array<[S1, S2]>;
|
|
68
|
+
static removeCircularReferences<T>(obj: T, seen?: WeakSet<object>): T | undefined;
|
|
64
69
|
static isArrayOfStrings(value: unknown): value is string[];
|
|
65
70
|
static isValidType: (str: string) => boolean;
|
|
66
71
|
static isValidHex: (hexString: string) => boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/general/utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,qBAAqB,EAErB,iBAAiB,EACjB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACN,aAAa,EACb,OAAO,EACP,gBAAgB,EAChB,UAAU,EACV,eAAe,EACf,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,UAAU,EAEV,aAAa,EACb,UAAU,EACV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAChF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAC;AAE9E,OAAO,EACN,WAAW,EACX,yBAAyB,EACzB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAElE,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAC;AAG1D;;GAEG;AACH,qBAAa,OAAO;IAKnB,gBAAuB,aAAa,iCAA2B;IAC/D,gBAAuB,MAAM,0BAAoB;IACjD,gBAAuB,WAAW,+BAAyB;IAC3D,gBAAuB,OAAO,2BAAqB;IACnD,gBAAuB,YAAY,gC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E,MAAM,CAAA;KAAE,GACjE;QACA,SAAS,EAAE,aAAa,CAAC;QACzB,SAAS,EAAE,QAAQ,CAAC;QACpB,MAAM,EAAE,UAAU,CAAC;KAClB,GACD,SAAS;WAkGE,yBAAyB,CAAC,MAAM,EAAE;QAC/C,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,UAAU,CAAC;KACvB,GACE;QACA,SAAS,EAAE,aAAa,CAAC;QACzB,SAAS,EAAE,QAAQ,CAAC;QACpB,MAAM,EAAE,UAAU,CAAC;QACnB,KAAK,EAAE,MAAM,CAAC;KACb,GACD,SAAS;CAmBZ"}
|
|
@@ -32,6 +32,25 @@ class Helpers {
|
|
|
32
32
|
}
|
|
33
33
|
return zipped;
|
|
34
34
|
}
|
|
35
|
+
static removeCircularReferences(obj, seen = new WeakSet()) {
|
|
36
|
+
if (obj && typeof obj === "object") {
|
|
37
|
+
if (seen.has(obj)) {
|
|
38
|
+
return undefined; // Circular reference found, skip it
|
|
39
|
+
}
|
|
40
|
+
seen.add(obj);
|
|
41
|
+
if (Array.isArray(obj)) {
|
|
42
|
+
return obj.map((item) => this.removeCircularReferences(item, seen));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
const entries = Object.entries(obj).map(([key, value]) => [
|
|
46
|
+
key,
|
|
47
|
+
this.removeCircularReferences(value, seen),
|
|
48
|
+
]);
|
|
49
|
+
return Object.fromEntries(entries);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return obj;
|
|
53
|
+
}
|
|
35
54
|
// =========================================================================
|
|
36
55
|
// Type Checking
|
|
37
56
|
// =========================================================================
|
|
@@ -225,7 +244,9 @@ Helpers.stripLeadingZeroesFromType = (type) => type.replaceAll(/x0+/g, "x");
|
|
|
225
244
|
* @throws An error if the input type has a length greater than 64.
|
|
226
245
|
*/
|
|
227
246
|
Helpers.addLeadingZeroesToType = (type) => {
|
|
228
|
-
|
|
247
|
+
// NOTE: is this safe to add ?
|
|
248
|
+
// if (!Helpers.isValidType(type)) return type;
|
|
249
|
+
const EXPECTED_TYPE_LENGTH = 64;
|
|
229
250
|
let strippedType = type.replace("0x", "");
|
|
230
251
|
let typeSuffix = "";
|
|
231
252
|
if (strippedType.includes("::")) {
|
|
@@ -236,14 +257,21 @@ Helpers.addLeadingZeroesToType = (type) => {
|
|
|
236
257
|
strippedType = splitType[0];
|
|
237
258
|
}
|
|
238
259
|
const typeLength = strippedType.length;
|
|
239
|
-
if (typeLength >
|
|
260
|
+
if (typeLength > EXPECTED_TYPE_LENGTH)
|
|
240
261
|
throw new Error("invalid type length");
|
|
241
|
-
const zeros = Array(
|
|
262
|
+
const zeros = Array(EXPECTED_TYPE_LENGTH - typeLength)
|
|
242
263
|
.fill("0")
|
|
243
264
|
.reduce((acc, val) => acc + val, "");
|
|
244
265
|
const newType = "0x" + zeros + strippedType;
|
|
245
266
|
return newType + typeSuffix;
|
|
246
267
|
};
|
|
268
|
+
Helpers.splitNonSuiCoinType = (coin) => {
|
|
269
|
+
const [uncastChain, coinType] = coin.split(":");
|
|
270
|
+
if (!uncastChain || !coinType)
|
|
271
|
+
throw new Error("invalid coin type");
|
|
272
|
+
const chain = uncastChain;
|
|
273
|
+
return { chain, coinType };
|
|
274
|
+
};
|
|
247
275
|
// =========================================================================
|
|
248
276
|
// Numbers
|
|
249
277
|
// =========================================================================
|
|
@@ -5,7 +5,8 @@ import { CoinStruct } from "@mysten/sui/client";
|
|
|
5
5
|
import { TransactionBlock } from "@mysten/sui.js/transactions";
|
|
6
6
|
export declare class CoinApi {
|
|
7
7
|
private readonly Provider;
|
|
8
|
-
|
|
8
|
+
private readonly coinGeckoApiKey?;
|
|
9
|
+
constructor(Provider: AftermathApi, coinGeckoApiKey?: string | undefined);
|
|
9
10
|
fetchCoinMetadata: (...inputs: {
|
|
10
11
|
coin: CoinType;
|
|
11
12
|
}[]) => Promise<CoinMetadaWithInfo>;
|
|
@@ -32,6 +33,8 @@ export declare class CoinApi {
|
|
|
32
33
|
}) => Promise<CoinStruct[]>;
|
|
33
34
|
static formatCoinTypesForMoveCall: (coins: CoinType[]) => number[][];
|
|
34
35
|
private createLpCoinMetadata;
|
|
36
|
+
private fetchEvmCoinMetadata;
|
|
37
|
+
private fetchSvmCoinMetadata;
|
|
35
38
|
private static coinWithAmountTx;
|
|
36
39
|
}
|
|
37
40
|
//# sourceMappingURL=coinApi.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coinApi.d.ts","sourceRoot":"","sources":["../../../../src/packages/coin/api/coinApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,WAAW,EACX,yBAAyB,EACzB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EACN,OAAO,EAEP,kBAAkB,EAClB,QAAQ,EACR,eAAe,EAGf,UAAU,EACV,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"coinApi.d.ts","sourceRoot":"","sources":["../../../../src/packages/coin/api/coinApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,WAAW,EACX,yBAAyB,EACzB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EACN,OAAO,EAEP,kBAAkB,EAClB,QAAQ,EACR,eAAe,EAGf,UAAU,EACV,MAAM,gBAAgB,CAAC;AAIxB,OAAO,EAAE,UAAU,EAAkB,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAK/D,qBAAa,OAAO;IAMlB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAC;gBADhB,QAAQ,EAAE,YAAY,EACtB,eAAe,CAAC,oBAAQ;IASnC,iBAAiB;cAIhB,QAAQ;wCAmEb;IAEI,oBAAoB;eAIlB,QAAQ,EAAE;qCAmBhB;IAMI,qBAAqB,WAAkB;QAC7C,EAAE,EAAE,WAAW,GAAG,gBAAgB,CAAC;QACnC,aAAa,EAAE,UAAU,CAAC;QAC1B,QAAQ,EAAE,QAAQ,CAAC;QACnB,UAAU,EAAE,OAAO,CAAC;QACpB,aAAa,CAAC,EAAE,OAAO,CAAC;KACxB,KAAG,QAAQ,yBAAyB,CAAC,CAcpC;IAEK,sBAAsB,WAAkB;QAC9C,EAAE,EAAE,WAAW,CAAC;QAChB,aAAa,EAAE,UAAU,CAAC;QAC1B,SAAS,EAAE,QAAQ,EAAE,CAAC;QACtB,WAAW,EAAE,OAAO,EAAE,CAAC;QACvB,aAAa,CAAC,EAAE,OAAO,CAAC;KACxB,KAAG,QAAQ,yBAAyB,EAAE,CAAC,CA8BtC;IAGK,aAAa,WAAkB;QACrC,aAAa,EAAE,UAAU,CAAC;QAC1B,QAAQ,EAAE,QAAQ,CAAC;KAEnB,KAAG,QAAQ,UAAU,EAAE,CAAC,CAiCvB;IAMF,OAAc,0BAA0B,UAAW,QAAQ,EAAE,gBACG;IAWhE,OAAO,CAAC,oBAAoB,CAoD1B;IAEF,OAAO,CAAC,oBAAoB,CA4FzB;IAEH,OAAO,CAAC,oBAAoB,CAkDzB;IAMH,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAsE7B;CACF"}
|
|
@@ -15,12 +15,16 @@ const helpers_1 = require("../../../general/utils/helpers");
|
|
|
15
15
|
const pools_1 = require("../../pools/pools");
|
|
16
16
|
const utils_1 = require("../../../general/utils");
|
|
17
17
|
const transactionsApiHelpers_1 = require("../../../general/apiHelpers/transactionsApiHelpers");
|
|
18
|
+
const coinGeckoApiHelpers_1 = require("../../../general/prices/coingecko/coinGeckoApiHelpers");
|
|
19
|
+
// import { ethers, Networkish } from "ethers";
|
|
18
20
|
class CoinApi {
|
|
19
21
|
// =========================================================================
|
|
20
22
|
// Constructor
|
|
21
23
|
// =========================================================================
|
|
22
|
-
constructor(Provider
|
|
24
|
+
constructor(Provider, coinGeckoApiKey // private readonly infuraConfig?: { // network: Networkish; // projectId: string;
|
|
25
|
+
) {
|
|
23
26
|
this.Provider = Provider;
|
|
27
|
+
this.coinGeckoApiKey = coinGeckoApiKey;
|
|
24
28
|
// =========================================================================
|
|
25
29
|
// Inspections
|
|
26
30
|
// =========================================================================
|
|
@@ -29,38 +33,58 @@ class CoinApi {
|
|
|
29
33
|
expirationSeconds: -1,
|
|
30
34
|
callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
31
35
|
const { coin } = inputs;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
coinType: helpers_1.Helpers.stripLeadingZeroesFromType(coin),
|
|
35
|
-
});
|
|
36
|
-
if (coinMetadata === null)
|
|
37
|
-
throw new Error("coin metadata is null");
|
|
38
|
-
return Object.assign(Object.assign({}, coinMetadata), { isGenerated: false });
|
|
39
|
-
}
|
|
40
|
-
catch (error) {
|
|
36
|
+
if (helpers_1.Helpers.isValidType(coin)) {
|
|
37
|
+
// sui coin
|
|
41
38
|
try {
|
|
42
|
-
|
|
39
|
+
const coinMetadata = yield this.Provider.provider.getCoinMetadata({
|
|
40
|
+
coinType: helpers_1.Helpers.stripLeadingZeroesFromType(coin),
|
|
41
|
+
});
|
|
42
|
+
if (coinMetadata === null)
|
|
43
|
+
throw new Error("coin metadata is null");
|
|
44
|
+
return Object.assign(Object.assign({}, coinMetadata), { isGenerated: false });
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
try {
|
|
48
|
+
return this.createLpCoinMetadata({ lpCoinType: coin });
|
|
49
|
+
}
|
|
50
|
+
catch (e) { }
|
|
51
|
+
const maxSymbolLength = 10;
|
|
52
|
+
const maxPackageNameLength = 24;
|
|
53
|
+
const coinClass = new coin_1.Coin(coin);
|
|
54
|
+
const symbol = coinClass.coinTypeSymbol
|
|
55
|
+
.toUpperCase()
|
|
56
|
+
.slice(0, maxSymbolLength);
|
|
57
|
+
const packageName = coinClass.coinTypePackageName.slice(0, maxPackageNameLength);
|
|
58
|
+
return {
|
|
59
|
+
symbol,
|
|
60
|
+
id: null,
|
|
61
|
+
description: `${symbol} (${packageName})`,
|
|
62
|
+
name: symbol
|
|
63
|
+
.split("_")
|
|
64
|
+
.map((word) => helpers_1.Helpers.capitalizeOnlyFirstLetter(word))
|
|
65
|
+
.join(" "),
|
|
66
|
+
decimals: coin_1.Coin.constants.defaultCoinDecimals.sui,
|
|
67
|
+
iconUrl: null,
|
|
68
|
+
isGenerated: true,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
// non sui coin
|
|
74
|
+
const { coinType, chain } = helpers_1.Helpers.splitNonSuiCoinType(coin);
|
|
75
|
+
if (chain === "solana") {
|
|
76
|
+
// svm
|
|
77
|
+
return this.fetchSvmCoinMetadata({
|
|
78
|
+
coinType,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
// evm
|
|
83
|
+
return this.fetchEvmCoinMetadata({
|
|
84
|
+
coinType,
|
|
85
|
+
chain,
|
|
86
|
+
});
|
|
43
87
|
}
|
|
44
|
-
catch (e) { }
|
|
45
|
-
const maxSymbolLength = 10;
|
|
46
|
-
const maxPackageNameLength = 24;
|
|
47
|
-
const coinClass = new coin_1.Coin(coin);
|
|
48
|
-
const symbol = coinClass.coinTypeSymbol
|
|
49
|
-
.toUpperCase()
|
|
50
|
-
.slice(0, maxSymbolLength);
|
|
51
|
-
const packageName = coinClass.coinTypePackageName.slice(0, maxPackageNameLength);
|
|
52
|
-
return {
|
|
53
|
-
symbol,
|
|
54
|
-
id: null,
|
|
55
|
-
description: `${symbol} (${packageName})`,
|
|
56
|
-
name: symbol
|
|
57
|
-
.split("_")
|
|
58
|
-
.map((word) => helpers_1.Helpers.capitalizeOnlyFirstLetter(word))
|
|
59
|
-
.join(" "),
|
|
60
|
-
decimals: 9,
|
|
61
|
-
iconUrl: null,
|
|
62
|
-
isGenerated: true,
|
|
63
|
-
};
|
|
64
88
|
}
|
|
65
89
|
}),
|
|
66
90
|
});
|
|
@@ -183,6 +207,114 @@ class CoinApi {
|
|
|
183
207
|
};
|
|
184
208
|
}
|
|
185
209
|
});
|
|
210
|
+
this.fetchEvmCoinMetadata = this.Provider.withCache({
|
|
211
|
+
key: "fetchEvmCoinMetadata",
|
|
212
|
+
expirationSeconds: -1,
|
|
213
|
+
callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
// NOTE: do leading 0s need to be handled ?
|
|
215
|
+
const { coinType, chain } = inputs;
|
|
216
|
+
try {
|
|
217
|
+
if (!this.coinGeckoApiKey)
|
|
218
|
+
throw new Error("no coinGeckoApiKey provided");
|
|
219
|
+
// const ERC20_ABI = [
|
|
220
|
+
// "function name() view returns (string)",
|
|
221
|
+
// "function symbol() view returns (string)",
|
|
222
|
+
// "function decimals() view returns (uint8)",
|
|
223
|
+
// ];
|
|
224
|
+
// const infuraProvider = new ethers.InfuraProvider(
|
|
225
|
+
// // TODO: add more conversions, move to helpers ?
|
|
226
|
+
// chain === "ethereum"
|
|
227
|
+
// ? "mainnet"
|
|
228
|
+
// : chain === "bsc"
|
|
229
|
+
// ? "bnb"
|
|
230
|
+
// : // : chain === "polygon"
|
|
231
|
+
// // ? "matic"
|
|
232
|
+
// chain,
|
|
233
|
+
// this.infuraConfig?.projectId,
|
|
234
|
+
// this.infuraConfig?.projectSecret
|
|
235
|
+
// );
|
|
236
|
+
// const contract = new ethers.Contract(
|
|
237
|
+
// coinType,
|
|
238
|
+
// ERC20_ABI,
|
|
239
|
+
// infuraProvider
|
|
240
|
+
// );
|
|
241
|
+
const coingeckoApi = new coinGeckoApiHelpers_1.CoinGeckoApiHelpers(this.Provider, this.coinGeckoApiKey
|
|
242
|
+
// {}
|
|
243
|
+
);
|
|
244
|
+
let coinMetadata = yield coingeckoApi.fetchCoinMetadata(inputs);
|
|
245
|
+
// let decimals = coinMetadata?.decimals;
|
|
246
|
+
// if (decimals === undefined || decimals < 0) {
|
|
247
|
+
// decimals = (await contract.decimals()) as CoinDecimal;
|
|
248
|
+
// }
|
|
249
|
+
// if (!coinMetadata) {
|
|
250
|
+
// const [name, symbol]: [string, string] = await Promise.all([
|
|
251
|
+
// contract.name(),
|
|
252
|
+
// contract.symbol(),
|
|
253
|
+
// ]);
|
|
254
|
+
// coinMetadata = {
|
|
255
|
+
// symbol,
|
|
256
|
+
// name,
|
|
257
|
+
// description: `${name} (${chain})`,
|
|
258
|
+
// decimals,
|
|
259
|
+
// };
|
|
260
|
+
// }
|
|
261
|
+
return Object.assign(Object.assign({
|
|
262
|
+
// id: null,
|
|
263
|
+
// iconUrl: null,
|
|
264
|
+
// NOTE: should this be shortened ?
|
|
265
|
+
symbol: coinType, name: coinType, description: `${coinType} (${chain})`, decimals: coin_1.Coin.constants.defaultCoinDecimals.evm,
|
|
266
|
+
// isGenerated: true,
|
|
267
|
+
iconUrl: null }, (coinMetadata !== null && coinMetadata !== void 0 ? coinMetadata : {})), {
|
|
268
|
+
// decimals,
|
|
269
|
+
id: null, isGenerated: false });
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
console.error(error);
|
|
273
|
+
return {
|
|
274
|
+
id: null,
|
|
275
|
+
iconUrl: null,
|
|
276
|
+
// NOTE: should this be shortened ?
|
|
277
|
+
symbol: coinType,
|
|
278
|
+
name: coinType,
|
|
279
|
+
description: `${coinType} (${chain})`,
|
|
280
|
+
decimals: coin_1.Coin.constants.defaultCoinDecimals.evm,
|
|
281
|
+
isGenerated: true,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
}),
|
|
285
|
+
});
|
|
286
|
+
this.fetchSvmCoinMetadata = this.Provider.withCache({
|
|
287
|
+
key: "fetchSvmCoinMetadata",
|
|
288
|
+
expirationSeconds: -1,
|
|
289
|
+
callback: (inputs) => __awaiter(this, void 0, void 0, function* () {
|
|
290
|
+
// NOTE: do leading 0s need to be handled ?
|
|
291
|
+
const { coinType } = inputs;
|
|
292
|
+
const fallbackCoinMetadata = {
|
|
293
|
+
// NOTE: should this be shortened ?
|
|
294
|
+
symbol: coinType,
|
|
295
|
+
name: coinType,
|
|
296
|
+
description: `${coinType} (solana)`,
|
|
297
|
+
decimals: coin_1.Coin.constants.defaultCoinDecimals.svm,
|
|
298
|
+
};
|
|
299
|
+
try {
|
|
300
|
+
if (!this.coinGeckoApiKey)
|
|
301
|
+
throw new Error("no coinGeckoApiKey provided");
|
|
302
|
+
// TODO: handle missing coingecko data
|
|
303
|
+
const coingeckoApi = new coinGeckoApiHelpers_1.CoinGeckoApiHelpers(this.Provider, this.coinGeckoApiKey
|
|
304
|
+
// {}
|
|
305
|
+
);
|
|
306
|
+
const coinMetadata = yield coingeckoApi.fetchCoinMetadata({
|
|
307
|
+
coinType,
|
|
308
|
+
chain: "solana",
|
|
309
|
+
});
|
|
310
|
+
return Object.assign(Object.assign({ iconUrl: null }, (coinMetadata !== null && coinMetadata !== void 0 ? coinMetadata : fallbackCoinMetadata)), { id: null, isGenerated: !coinMetadata });
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
console.error(error);
|
|
314
|
+
return Object.assign(Object.assign({ id: null, iconUrl: null }, fallbackCoinMetadata), { isGenerated: true });
|
|
315
|
+
}
|
|
316
|
+
}),
|
|
317
|
+
});
|
|
186
318
|
}
|
|
187
319
|
}
|
|
188
320
|
exports.CoinApi = CoinApi;
|
|
@@ -10,6 +10,11 @@ export declare class Coin extends Caller {
|
|
|
10
10
|
suiCoinType: string;
|
|
11
11
|
suiCoinDecimals: number;
|
|
12
12
|
coinObjectType: string;
|
|
13
|
+
defaultCoinDecimals: {
|
|
14
|
+
sui: number;
|
|
15
|
+
evm: number;
|
|
16
|
+
svm: number;
|
|
17
|
+
};
|
|
13
18
|
};
|
|
14
19
|
readonly coinTypePackageName: string;
|
|
15
20
|
readonly coinTypeSymbol: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coin.d.ts","sourceRoot":"","sources":["../../../src/packages/coin/coin.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,OAAO,EACP,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,OAAO,EACP,UAAU,EAEV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAAa,IAAK,SAAQ,MAAM;
|
|
1
|
+
{"version":3,"file":"coin.d.ts","sourceRoot":"","sources":["../../../src/packages/coin/coin.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,aAAa,EACb,OAAO,EACP,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,eAAe,EACf,UAAU,EACV,qBAAqB,EACrB,QAAQ,EACR,OAAO,EACP,UAAU,EAEV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGpD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,qBAAa,IAAK,SAAQ,MAAM;aAmCd,QAAQ,CAAC;aACT,OAAO,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;IAhC3B,gBAAuB,SAAS;;;;;;;;;MAW9B;IAMF,SAAgB,mBAAmB,EAAE,MAAM,CAAC;IAC5C,SAAgB,cAAc,EAAE,MAAM,CAAC;IACvC,SAAgB,aAAa,EAAE,MAAM,CAAC;IAE/B,QAAQ,EAAE,kBAAkB,GAAG,SAAS,CAAC;IACzC,SAAS,EAAE,aAA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c,gBAAgB,YACpB,MAAM,YACL,WAAW,KACnB,OAAO,CAIP;IAEH,OAAc,mBAAmB,WACxB,MAAM,GAAG,MAAM,YACb,MAAM,YAIf;IAEF,OAAc,sBAAsB,WAC3B,MAAM,GAAG,MAAM,YACb,MAAM,SACT,MAAM,YAGZ;IAEF,OAAc,qBAAqB,WAAY;QAC9C,QAAQ,EAAE,QAAQ,CAAC;QACnB,qBAAqB,EAAE,qBAAqB,CAAC;KAC7C,KAAG,UAAU,GAAG,SAAS,CAgBxB;IAMF,OAAO,CAAC,WAAW,CAIjB;CACF"}
|
|
@@ -70,7 +70,7 @@ class Coin extends caller_1.Caller {
|
|
|
70
70
|
const coinType = (_a = this.coinType) !== null && _a !== void 0 ? _a : coin;
|
|
71
71
|
if (!coinType)
|
|
72
72
|
throw new Error("no valid coin type");
|
|
73
|
-
const [metadata] = yield this.
|
|
73
|
+
const [metadata] = yield this.getCoinMetadatas({ coins: [coinType] });
|
|
74
74
|
this.setCoinMetadata(metadata);
|
|
75
75
|
return metadata;
|
|
76
76
|
});
|
|
@@ -117,6 +117,11 @@ Coin.constants = {
|
|
|
117
117
|
suiCoinType: "0x0000000000000000000000000000000000000000000000000000000000000002::sui::SUI",
|
|
118
118
|
suiCoinDecimals: 9,
|
|
119
119
|
coinObjectType: "0x0000000000000000000000000000000000000000000000000000000000000002::coin::Coin",
|
|
120
|
+
defaultCoinDecimals: {
|
|
121
|
+
sui: 9,
|
|
122
|
+
evm: 18,
|
|
123
|
+
svm: 9,
|
|
124
|
+
},
|
|
120
125
|
};
|
|
121
126
|
// =========================================================================
|
|
122
127
|
// Public Static Methods
|