@defillama/sdk 2.3.46 → 2.3.49

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.
Files changed (64) hide show
  1. package/LICENSE +661 -661
  2. package/README.md +16 -16
  3. package/build/abi/cachedABIs.d.ts +4 -4
  4. package/build/abi/cachedABIs.js +70 -70
  5. package/build/abi/convertResults.d.ts +2 -2
  6. package/build/abi/convertResults.js +56 -56
  7. package/build/abi/index.d.ts +26 -26
  8. package/build/abi/index.js +185 -185
  9. package/build/abi/index.test.d.ts +1 -1
  10. package/build/abi/index.test.js +651 -651
  11. package/build/abi/multicall.d.ts +13 -13
  12. package/build/abi/multicall.js +210 -210
  13. package/build/api.d.ts +10 -10
  14. package/build/api.js +32 -32
  15. package/build/cdp/compoundTokens.d.ts +68 -68
  16. package/build/cdp/compoundTokens.js +69 -69
  17. package/build/cdp/index.d.ts +29 -29
  18. package/build/cdp/index.js +124 -124
  19. package/build/cdp/index.test.d.ts +1 -1
  20. package/build/cdp/index.test.js +82 -82
  21. package/build/cdp/makerTokens.d.ts +10 -10
  22. package/build/cdp/makerTokens.js +244 -244
  23. package/build/cli.d.ts +2 -2
  24. package/build/cli.js +95 -95
  25. package/build/computeTVL/blocks.d.ts +18 -18
  26. package/build/computeTVL/blocks.js +138 -138
  27. package/build/computeTVL/blocks.test.d.ts +1 -1
  28. package/build/computeTVL/blocks.test.js +56 -56
  29. package/build/computeTVL/humanizeNumber.d.ts +1 -1
  30. package/build/computeTVL/humanizeNumber.js +18 -18
  31. package/build/computeTVL/index.d.ts +55 -55
  32. package/build/computeTVL/index.js +366 -366
  33. package/build/computeTVL/index.test.d.ts +1 -1
  34. package/build/computeTVL/index.test.js +107 -107
  35. package/build/computeTVL/prices.d.ts +9 -9
  36. package/build/computeTVL/prices.js +163 -163
  37. package/build/erc20/index.d.ts +31 -31
  38. package/build/erc20/index.js +144 -144
  39. package/build/erc20/index.test.d.ts +1 -1
  40. package/build/erc20/index.test.js +124 -124
  41. package/build/eth/index.d.ts +21 -21
  42. package/build/eth/index.js +90 -90
  43. package/build/eth/index.test.d.ts +1 -1
  44. package/build/eth/index.test.js +122 -122
  45. package/build/general.d.ts +10 -10
  46. package/build/general.js +105 -104
  47. package/build/general.test.d.ts +1 -1
  48. package/build/general.test.js +73 -73
  49. package/build/generalUtil.d.ts +19 -19
  50. package/build/generalUtil.js +117 -117
  51. package/build/generalUtil.test.d.ts +1 -1
  52. package/build/generalUtil.test.js +59 -59
  53. package/build/index.d.ts +2 -2
  54. package/build/index.js +24 -24
  55. package/build/index.test.js +69 -69
  56. package/build/types.d.ts +5 -5
  57. package/build/types.js +2 -2
  58. package/build/util/index.d.ts +57 -57
  59. package/build/util/index.js +354 -354
  60. package/build/util/index.test.d.ts +1 -1
  61. package/build/util/index.test.js +314 -314
  62. package/build/util/tokenList.d.ts +14 -14
  63. package/build/util/tokenList.js +3631 -3631
  64. package/package.json +41 -41
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -1,107 +1,107 @@
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
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- var _1 = __importDefault(require("."));
43
- jest.setTimeout(10000);
44
- test("compute tvl of ethereum and bsc tokens", function () { return __awaiter(void 0, void 0, void 0, function () {
45
- var knownPrices, _a, _b, _c, _d, _e, _f;
46
- return __generator(this, function (_g) {
47
- switch (_g.label) {
48
- case 0:
49
- knownPrices = {};
50
- _a = expect;
51
- return [4 /*yield*/, _1.default({
52
- "0x6f259637dcd74c767781e37bc6133cd6a68aa161": "3193525665566784275723138",
53
- "heco:0xecb56cf772B5c9A6907FB7d32387Da2fCbfB63b4": "1047556118646987925068",
54
- "heco:0xA2c49cEe16a5E5bDEFDe931107dc1fae9f7773E3": "236654328014720960482935",
55
- "heco:0xae3a768f9aB104c69A7CD6041fE16fFa235d1810": "16569632182924952096418",
56
- "heco:0x9e004545c59D359F6B7BFB06a26390b087717b42": "961004175478694236526",
57
- "binance-eth": 27.06634107102854,
58
- "heco:0xa71EdC38d189767582C38A3145b5873052c3e47a": "31268806605177889114148968",
59
- "heco:0x25D2e80cB6B86881Fd7e07dd263Fb79f4AbE033c": "192506692195331535945631",
60
- "heco:0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047": "2158672533322793",
61
- "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": "11093082876512",
62
- "heco:0x66a79D23E58475D2738179Ca52cd0b41d73f0BEa": "996379172178921963142",
63
- "heco:0x22C54cE8321A4015740eE1109D9cBc25815C46E6": "23914657385695466323057",
64
- "0x6b175474e89094c44da98b954eedeac495271d0f": "7107526494042094908468667",
65
- "heco:0xE499Ef4616993730CEd0f31FA2703B92B50bB536": "137205675925769131064013486",
66
- "heco:0xB4F019bEAc758AbBEe2F906033AAa2f0F6Dacb35": "364494623629203573",
67
- "heco:0xeF3CEBD77E0C52cb6f60875d9306397B5Caca375": "3129531295952878112773",
68
- "heco:0x64FF637fB478863B7468bc97D30a5bF3A428a1fD": "9192054317393320446391",
69
- "heco:0x25d2e80cb6b86881fd7e07dd263fb79f4abe033c": "148911552859786953196071",
70
- "heco:0x64ff637fb478863b7468bc97d30a5bf3a428a1fd": "5894279017068474040638",
71
- "heco:0x66a79d23e58475d2738179ca52cd0b41d73f0bea": "612867016701208550102",
72
- "heco:0x0298c2b32eae4da002a15f36fdf7615bea3da047": "322847070254",
73
- "heco:0xa71edc38d189767582c38a3145b5873052c3e47a": "27261644010709722098844276",
74
- }, "now", true, knownPrices)];
75
- case 1:
76
- _a.apply(void 0, [_g.sent()]).toMatchInlineSnapshot("\n Object {\n \"tokenBalances\": Object {\n \"DAI\": 7107526.494042095,\n \"ETH\": 15086.333334461793,\n \"HBCH\": 3129.531295952878,\n \"HBTC\": 1609.2461888801304,\n \"HDOT\": 236654.32801472096,\n \"HFIL\": 16569.632182924954,\n \"HLTC\": 1047.556118646988,\n \"HPT\": 137205675.92576912,\n \"HT\": 3193525.6655667843,\n \"HUSD\": 21589953.80393047,\n \"LINK\": 961.0041754786943,\n \"MDX\": 341418.2450551185,\n \"UNI\": 23914.657385695464,\n \"USDC\": 11093082.876512,\n \"USDT\": 58530450.61588761,\n \"YFI\": 0.3644946236292036,\n \"binance-eth\": 27.06634107102854,\n },\n \"usdTokenBalances\": Object {\n \"DAI\": 7099743.752531119,\n \"ETH\": 68626674.2951333,\n \"HBCH\": 1917651.5969080853,\n \"HBTC\": 99816713.35766785,\n \"HDOT\": 12829031.121678023,\n \"HFIL\": 1028808.4622378105,\n \"HLTC\": 223234.20888367313,\n \"HPT\": 963452.7681237137,\n \"HT\": 35192652.83454596,\n \"HUSD\": 21805853.341969773,\n \"LINK\": 29781.519398084733,\n \"MDX\": 365317.5222089768,\n \"UNI\": 614606.6948123734,\n \"USDC\": 11086671.074609376,\n \"USDT\": 58530450.61588761,\n \"YFI\": 12421.247784036,\n \"binance-eth\": 112462.81245740927,\n },\n \"usdTvl\": 320255527.22683716,\n }\n ");
77
- return [2 /*return*/];
78
- case 2:
79
- _b.apply(void 0, [_g.sent()]).toBeGreaterThan(1e5);
80
- _c = expect;
81
- return [4 /*yield*/, _1.default({
82
- "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599": "200000000", // 2 WBTC
83
- }, "now")];
84
- case 3:
85
- _c.apply(void 0, [_g.sent()]).toBeGreaterThan(1e3);
86
- _d = expect;
87
- return [4 /*yield*/, _1.default({
88
- "pancakeswap-token": "1000.51", // 1000 CAKE
89
- }, "now")];
90
- case 4:
91
- _d.apply(void 0, [_g.sent()]).toBeGreaterThan(1e3);
92
- _e = expect;
93
- return [4 /*yield*/, _1.default({
94
- "bsc:0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82": "100000000000000000000",
95
- }, "now")];
96
- case 5:
97
- _e.apply(void 0, [_g.sent()]).toBeGreaterThan(1e3);
98
- _f = expect;
99
- return [4 /*yield*/, _1.default({
100
- "0x0000000000000000000000000000000000000000": "100000000000000000000", // 100 ETH
101
- }, "now", false, knownPrices)];
102
- case 6:
103
- _f.apply(void 0, [_g.sent()]).toBeGreaterThan(1e3);
104
- return [2 /*return*/];
105
- }
106
- });
107
- }); });
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
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ var _1 = __importDefault(require("."));
43
+ jest.setTimeout(10000);
44
+ test("compute tvl of ethereum and bsc tokens", function () { return __awaiter(void 0, void 0, void 0, function () {
45
+ var knownPrices, _a, _b, _c, _d, _e, _f;
46
+ return __generator(this, function (_g) {
47
+ switch (_g.label) {
48
+ case 0:
49
+ knownPrices = {};
50
+ _a = expect;
51
+ return [4 /*yield*/, _1.default({
52
+ "0x6f259637dcd74c767781e37bc6133cd6a68aa161": "3193525665566784275723138",
53
+ "heco:0xecb56cf772B5c9A6907FB7d32387Da2fCbfB63b4": "1047556118646987925068",
54
+ "heco:0xA2c49cEe16a5E5bDEFDe931107dc1fae9f7773E3": "236654328014720960482935",
55
+ "heco:0xae3a768f9aB104c69A7CD6041fE16fFa235d1810": "16569632182924952096418",
56
+ "heco:0x9e004545c59D359F6B7BFB06a26390b087717b42": "961004175478694236526",
57
+ "binance-eth": 27.06634107102854,
58
+ "heco:0xa71EdC38d189767582C38A3145b5873052c3e47a": "31268806605177889114148968",
59
+ "heco:0x25D2e80cB6B86881Fd7e07dd263Fb79f4AbE033c": "192506692195331535945631",
60
+ "heco:0x0298c2b32eaE4da002a15f36fdf7615BEa3DA047": "2158672533322793",
61
+ "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": "11093082876512",
62
+ "heco:0x66a79D23E58475D2738179Ca52cd0b41d73f0BEa": "996379172178921963142",
63
+ "heco:0x22C54cE8321A4015740eE1109D9cBc25815C46E6": "23914657385695466323057",
64
+ "0x6b175474e89094c44da98b954eedeac495271d0f": "7107526494042094908468667",
65
+ "heco:0xE499Ef4616993730CEd0f31FA2703B92B50bB536": "137205675925769131064013486",
66
+ "heco:0xB4F019bEAc758AbBEe2F906033AAa2f0F6Dacb35": "364494623629203573",
67
+ "heco:0xeF3CEBD77E0C52cb6f60875d9306397B5Caca375": "3129531295952878112773",
68
+ "heco:0x64FF637fB478863B7468bc97D30a5bF3A428a1fD": "9192054317393320446391",
69
+ "heco:0x25d2e80cb6b86881fd7e07dd263fb79f4abe033c": "148911552859786953196071",
70
+ "heco:0x64ff637fb478863b7468bc97d30a5bf3a428a1fd": "5894279017068474040638",
71
+ "heco:0x66a79d23e58475d2738179ca52cd0b41d73f0bea": "612867016701208550102",
72
+ "heco:0x0298c2b32eae4da002a15f36fdf7615bea3da047": "322847070254",
73
+ "heco:0xa71edc38d189767582c38a3145b5873052c3e47a": "27261644010709722098844276",
74
+ }, "now", true, knownPrices)];
75
+ case 1:
76
+ _a.apply(void 0, [_g.sent()]).toMatchInlineSnapshot("\n Object {\n \"tokenBalances\": Object {\n \"DAI\": 7107526.494042095,\n \"ETH\": 15086.333334461793,\n \"HBCH\": 3129.531295952878,\n \"HBTC\": 1609.2461888801304,\n \"HDOT\": 236654.32801472096,\n \"HFIL\": 16569.632182924954,\n \"HLTC\": 1047.556118646988,\n \"HPT\": 137205675.92576912,\n \"HT\": 3193525.6655667843,\n \"HUSD\": 21589953.80393047,\n \"LINK\": 961.0041754786943,\n \"MDX\": 341418.2450551185,\n \"UNI\": 23914.657385695464,\n \"USDC\": 11093082.876512,\n \"USDT\": 58530450.61588761,\n \"YFI\": 0.3644946236292036,\n \"binance-eth\": 27.06634107102854,\n },\n \"usdTokenBalances\": Object {\n \"DAI\": 7099743.752531119,\n \"ETH\": 68626674.2951333,\n \"HBCH\": 1917651.5969080853,\n \"HBTC\": 99816713.35766785,\n \"HDOT\": 12829031.121678023,\n \"HFIL\": 1028808.4622378105,\n \"HLTC\": 223234.20888367313,\n \"HPT\": 963452.7681237137,\n \"HT\": 35192652.83454596,\n \"HUSD\": 21805853.341969773,\n \"LINK\": 29781.519398084733,\n \"MDX\": 365317.5222089768,\n \"UNI\": 614606.6948123734,\n \"USDC\": 11086671.074609376,\n \"USDT\": 58530450.61588761,\n \"YFI\": 12421.247784036,\n \"binance-eth\": 112462.81245740927,\n },\n \"usdTvl\": 320255527.22683716,\n }\n ");
77
+ return [2 /*return*/];
78
+ case 2:
79
+ _b.apply(void 0, [_g.sent()]).toBeGreaterThan(1e5);
80
+ _c = expect;
81
+ return [4 /*yield*/, _1.default({
82
+ "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599": "200000000", // 2 WBTC
83
+ }, "now")];
84
+ case 3:
85
+ _c.apply(void 0, [_g.sent()]).toBeGreaterThan(1e3);
86
+ _d = expect;
87
+ return [4 /*yield*/, _1.default({
88
+ "pancakeswap-token": "1000.51", // 1000 CAKE
89
+ }, "now")];
90
+ case 4:
91
+ _d.apply(void 0, [_g.sent()]).toBeGreaterThan(1e3);
92
+ _e = expect;
93
+ return [4 /*yield*/, _1.default({
94
+ "bsc:0x0e09fabb73bd3ade0a17ecc321fd13a19e81ce82": "100000000000000000000",
95
+ }, "now")];
96
+ case 5:
97
+ _e.apply(void 0, [_g.sent()]).toBeGreaterThan(1e3);
98
+ _f = expect;
99
+ return [4 /*yield*/, _1.default({
100
+ "0x0000000000000000000000000000000000000000": "100000000000000000000", // 100 ETH
101
+ }, "now", false, knownPrices)];
102
+ case 6:
103
+ _f.apply(void 0, [_g.sent()]).toBeGreaterThan(1e3);
104
+ return [2 /*return*/];
105
+ }
106
+ });
107
+ }); });
@@ -1,9 +1,9 @@
1
- export interface TokenPrices {
2
- [token: string]: {
3
- usd: number;
4
- } | undefined;
5
- }
6
- export declare type GetCoingeckoLog = () => Promise<any>;
7
- export declare function makeCoingeckoCall(url: string, coingeckoMaxRetries: number, getCoingeckoLock: GetCoingeckoLog): Promise<any>;
8
- export declare function getTokenPrices(originalIds: string[], url: string, knownTokenPrices: TokenPrices, getCoingeckoLock: GetCoingeckoLog, coingeckoMaxRetries: number, prefix?: string): Promise<TokenPrices>;
9
- export declare function getHistoricalTokenPrices(ids: string[], url: string, timestamp: number, getCoingeckoLock: GetCoingeckoLog, coingeckoMaxRetries: number): Promise<TokenPrices>;
1
+ export interface TokenPrices {
2
+ [token: string]: {
3
+ usd: number;
4
+ } | undefined;
5
+ }
6
+ export declare type GetCoingeckoLog = () => Promise<any>;
7
+ export declare function makeCoingeckoCall(url: string, coingeckoMaxRetries: number, getCoingeckoLock: GetCoingeckoLog): Promise<any>;
8
+ export declare function getTokenPrices(originalIds: string[], url: string, knownTokenPrices: TokenPrices, getCoingeckoLock: GetCoingeckoLog, coingeckoMaxRetries: number, prefix?: string): Promise<TokenPrices>;
9
+ export declare function getHistoricalTokenPrices(ids: string[], url: string, timestamp: number, getCoingeckoLock: GetCoingeckoLog, coingeckoMaxRetries: number): Promise<TokenPrices>;
@@ -1,163 +1,163 @@
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
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- var __importDefault = (this && this.__importDefault) || function (mod) {
39
- return (mod && mod.__esModule) ? mod : { "default": mod };
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.getHistoricalTokenPrices = exports.getTokenPrices = exports.makeCoingeckoCall = void 0;
43
- var node_fetch_1 = __importDefault(require("node-fetch"));
44
- function fetchJson(url) {
45
- return node_fetch_1.default(url).then(function (res) { return res.json(); });
46
- }
47
- function makeCoingeckoCall(url, coingeckoMaxRetries, getCoingeckoLock) {
48
- return __awaiter(this, void 0, void 0, function () {
49
- var j, values, e_1;
50
- return __generator(this, function (_a) {
51
- switch (_a.label) {
52
- case 0:
53
- j = 0;
54
- _a.label = 1;
55
- case 1:
56
- if (!(j < coingeckoMaxRetries)) return [3 /*break*/, 7];
57
- _a.label = 2;
58
- case 2:
59
- _a.trys.push([2, 5, , 6]);
60
- return [4 /*yield*/, getCoingeckoLock()];
61
- case 3:
62
- _a.sent();
63
- return [4 /*yield*/, fetchJson(url)];
64
- case 4:
65
- values = _a.sent();
66
- return [2 /*return*/, values];
67
- case 5:
68
- e_1 = _a.sent();
69
- if (j >= coingeckoMaxRetries - 1) {
70
- throw e_1;
71
- }
72
- return [3 /*break*/, 6];
73
- case 6:
74
- j++;
75
- return [3 /*break*/, 1];
76
- case 7: return [2 /*return*/];
77
- }
78
- });
79
- });
80
- }
81
- exports.makeCoingeckoCall = makeCoingeckoCall;
82
- function getTokenPrices(originalIds, url, knownTokenPrices, getCoingeckoLock, coingeckoMaxRetries, prefix) {
83
- if (prefix === void 0) { prefix = ""; }
84
- return __awaiter(this, void 0, void 0, function () {
85
- var tokenPrices, newIds, i, knownPrice, i, tempTokenPrices;
86
- return __generator(this, function (_a) {
87
- switch (_a.label) {
88
- case 0:
89
- tokenPrices = {};
90
- newIds = originalIds.slice();
91
- for (i = 0; i < newIds.length; i++) {
92
- knownPrice = knownTokenPrices[prefix + newIds[i]];
93
- if (knownPrice !== undefined) {
94
- tokenPrices[newIds[i]] = knownPrice;
95
- newIds.splice(i, 1);
96
- i--;
97
- }
98
- }
99
- i = 0;
100
- _a.label = 1;
101
- case 1:
102
- if (!(i < newIds.length)) return [3 /*break*/, 4];
103
- return [4 /*yield*/, makeCoingeckoCall("https://api.coingecko.com/api/" + url + "=" + newIds
104
- .slice(i, i + 100)
105
- .join(",") + "&vs_currencies=usd", coingeckoMaxRetries, getCoingeckoLock)];
106
- case 2:
107
- tempTokenPrices = _a.sent();
108
- Object.assign(tokenPrices, tempTokenPrices);
109
- Object.entries(tempTokenPrices).forEach(function (tokenPrice) {
110
- knownTokenPrices[prefix + tokenPrice[0]] = tokenPrice[1];
111
- });
112
- _a.label = 3;
113
- case 3:
114
- i += 100;
115
- return [3 /*break*/, 1];
116
- case 4: return [2 /*return*/, tokenPrices];
117
- }
118
- });
119
- });
120
- }
121
- exports.getTokenPrices = getTokenPrices;
122
- var secondsPerHalfDay = Math.round((24 * 3600) / 2);
123
- function getHistoricalTokenPrices(ids, url, timestamp, getCoingeckoLock, coingeckoMaxRetries) {
124
- var _a;
125
- return __awaiter(this, void 0, void 0, function () {
126
- var tokenPrices, _i, ids_1, id, range, closest, _b, _c, price;
127
- return __generator(this, function (_d) {
128
- switch (_d.label) {
129
- case 0:
130
- tokenPrices = {};
131
- _i = 0, ids_1 = ids;
132
- _d.label = 1;
133
- case 1:
134
- if (!(_i < ids_1.length)) return [3 /*break*/, 4];
135
- id = ids_1[_i];
136
- return [4 /*yield*/, makeCoingeckoCall(url + "/" + id.toLowerCase() + "/market_chart/range?vs_currency=usd&from=" + (timestamp - secondsPerHalfDay) + "&to=" + (timestamp + secondsPerHalfDay), coingeckoMaxRetries, getCoingeckoLock)];
137
- case 2:
138
- range = _d.sent();
139
- if (range.error === undefined && ((_a = range.prices) === null || _a === void 0 ? void 0 : _a.length) > 0) {
140
- closest = range.prices[0];
141
- for (_b = 0, _c = range.prices; _b < _c.length; _b++) {
142
- price = _c[_b];
143
- if (Math.abs(price[0] - timestamp) < Math.abs(closest[0] - timestamp)) {
144
- closest = price;
145
- }
146
- }
147
- tokenPrices[id.toLowerCase()] = {
148
- usd: closest[1],
149
- };
150
- }
151
- else {
152
- tokenPrices[id.toLowerCase()] = undefined;
153
- }
154
- _d.label = 3;
155
- case 3:
156
- _i++;
157
- return [3 /*break*/, 1];
158
- case 4: return [2 /*return*/, tokenPrices];
159
- }
160
- });
161
- });
162
- }
163
- exports.getHistoricalTokenPrices = getHistoricalTokenPrices;
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
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.getHistoricalTokenPrices = exports.getTokenPrices = exports.makeCoingeckoCall = void 0;
43
+ var node_fetch_1 = __importDefault(require("node-fetch"));
44
+ function fetchJson(url) {
45
+ return node_fetch_1.default(url).then(function (res) { return res.json(); });
46
+ }
47
+ function makeCoingeckoCall(url, coingeckoMaxRetries, getCoingeckoLock) {
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var j, values, e_1;
50
+ return __generator(this, function (_a) {
51
+ switch (_a.label) {
52
+ case 0:
53
+ j = 0;
54
+ _a.label = 1;
55
+ case 1:
56
+ if (!(j < coingeckoMaxRetries)) return [3 /*break*/, 7];
57
+ _a.label = 2;
58
+ case 2:
59
+ _a.trys.push([2, 5, , 6]);
60
+ return [4 /*yield*/, getCoingeckoLock()];
61
+ case 3:
62
+ _a.sent();
63
+ return [4 /*yield*/, fetchJson(url)];
64
+ case 4:
65
+ values = _a.sent();
66
+ return [2 /*return*/, values];
67
+ case 5:
68
+ e_1 = _a.sent();
69
+ if (j >= coingeckoMaxRetries - 1) {
70
+ throw e_1;
71
+ }
72
+ return [3 /*break*/, 6];
73
+ case 6:
74
+ j++;
75
+ return [3 /*break*/, 1];
76
+ case 7: return [2 /*return*/];
77
+ }
78
+ });
79
+ });
80
+ }
81
+ exports.makeCoingeckoCall = makeCoingeckoCall;
82
+ function getTokenPrices(originalIds, url, knownTokenPrices, getCoingeckoLock, coingeckoMaxRetries, prefix) {
83
+ if (prefix === void 0) { prefix = ""; }
84
+ return __awaiter(this, void 0, void 0, function () {
85
+ var tokenPrices, newIds, i, knownPrice, i, tempTokenPrices;
86
+ return __generator(this, function (_a) {
87
+ switch (_a.label) {
88
+ case 0:
89
+ tokenPrices = {};
90
+ newIds = originalIds.slice();
91
+ for (i = 0; i < newIds.length; i++) {
92
+ knownPrice = knownTokenPrices[prefix + newIds[i]];
93
+ if (knownPrice !== undefined) {
94
+ tokenPrices[newIds[i]] = knownPrice;
95
+ newIds.splice(i, 1);
96
+ i--;
97
+ }
98
+ }
99
+ i = 0;
100
+ _a.label = 1;
101
+ case 1:
102
+ if (!(i < newIds.length)) return [3 /*break*/, 4];
103
+ return [4 /*yield*/, makeCoingeckoCall("https://api.coingecko.com/api/" + url + "=" + newIds
104
+ .slice(i, i + 100)
105
+ .join(",") + "&vs_currencies=usd", coingeckoMaxRetries, getCoingeckoLock)];
106
+ case 2:
107
+ tempTokenPrices = _a.sent();
108
+ Object.assign(tokenPrices, tempTokenPrices);
109
+ Object.entries(tempTokenPrices).forEach(function (tokenPrice) {
110
+ knownTokenPrices[prefix + tokenPrice[0]] = tokenPrice[1];
111
+ });
112
+ _a.label = 3;
113
+ case 3:
114
+ i += 100;
115
+ return [3 /*break*/, 1];
116
+ case 4: return [2 /*return*/, tokenPrices];
117
+ }
118
+ });
119
+ });
120
+ }
121
+ exports.getTokenPrices = getTokenPrices;
122
+ var secondsPerHalfDay = Math.round((24 * 3600) / 2);
123
+ function getHistoricalTokenPrices(ids, url, timestamp, getCoingeckoLock, coingeckoMaxRetries) {
124
+ var _a;
125
+ return __awaiter(this, void 0, void 0, function () {
126
+ var tokenPrices, _i, ids_1, id, range, closest, _b, _c, price;
127
+ return __generator(this, function (_d) {
128
+ switch (_d.label) {
129
+ case 0:
130
+ tokenPrices = {};
131
+ _i = 0, ids_1 = ids;
132
+ _d.label = 1;
133
+ case 1:
134
+ if (!(_i < ids_1.length)) return [3 /*break*/, 4];
135
+ id = ids_1[_i];
136
+ return [4 /*yield*/, makeCoingeckoCall(url + "/" + id.toLowerCase() + "/market_chart/range?vs_currency=usd&from=" + (timestamp - secondsPerHalfDay) + "&to=" + (timestamp + secondsPerHalfDay), coingeckoMaxRetries, getCoingeckoLock)];
137
+ case 2:
138
+ range = _d.sent();
139
+ if (range.error === undefined && ((_a = range.prices) === null || _a === void 0 ? void 0 : _a.length) > 0) {
140
+ closest = range.prices[0];
141
+ for (_b = 0, _c = range.prices; _b < _c.length; _b++) {
142
+ price = _c[_b];
143
+ if (Math.abs(price[0] - timestamp) < Math.abs(closest[0] - timestamp)) {
144
+ closest = price;
145
+ }
146
+ }
147
+ tokenPrices[id.toLowerCase()] = {
148
+ usd: closest[1],
149
+ };
150
+ }
151
+ else {
152
+ tokenPrices[id.toLowerCase()] = undefined;
153
+ }
154
+ _d.label = 3;
155
+ case 3:
156
+ _i++;
157
+ return [3 /*break*/, 1];
158
+ case 4: return [2 /*return*/, tokenPrices];
159
+ }
160
+ });
161
+ });
162
+ }
163
+ exports.getHistoricalTokenPrices = getHistoricalTokenPrices;
@@ -1,31 +1,31 @@
1
- import { Address } from "../types";
2
- import { Chain } from "../general";
3
- export declare function info(tokenAddress: Address, chain?: Chain): Promise<{
4
- output: {
5
- symbol: any;
6
- decimals: any;
7
- };
8
- }>;
9
- export declare function symbol(tokenAddress: Address, chain?: Chain): Promise<{
10
- output: any;
11
- }>;
12
- export declare function decimals(tokenAddress: Address, chain?: Chain): Promise<{
13
- output: any;
14
- }>;
15
- export declare function totalSupply(params: {
16
- target: Address;
17
- block?: number;
18
- decimals?: number;
19
- chain?: Chain;
20
- }): Promise<{
21
- output: string;
22
- }>;
23
- export declare function balanceOf(params: {
24
- target: Address;
25
- owner: Address;
26
- block?: number;
27
- decimals?: number;
28
- chain?: Chain;
29
- }): Promise<{
30
- output: string;
31
- }>;
1
+ import { Address } from "../types";
2
+ import { Chain } from "../general";
3
+ export declare function info(tokenAddress: Address, chain?: Chain): Promise<{
4
+ output: {
5
+ symbol: any;
6
+ decimals: any;
7
+ };
8
+ }>;
9
+ export declare function symbol(tokenAddress: Address, chain?: Chain): Promise<{
10
+ output: any;
11
+ }>;
12
+ export declare function decimals(tokenAddress: Address, chain?: Chain): Promise<{
13
+ output: any;
14
+ }>;
15
+ export declare function totalSupply(params: {
16
+ target: Address;
17
+ block?: number;
18
+ decimals?: number;
19
+ chain?: Chain;
20
+ }): Promise<{
21
+ output: string;
22
+ }>;
23
+ export declare function balanceOf(params: {
24
+ target: Address;
25
+ owner: Address;
26
+ block?: number;
27
+ decimals?: number;
28
+ chain?: Chain;
29
+ }): Promise<{
30
+ output: string;
31
+ }>;