@defillama/sdk 2.3.33 → 2.3.34
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/LICENSE +661 -661
- package/README.md +16 -16
- package/build/abi/cachedABIs.d.ts +4 -4
- package/build/abi/cachedABIs.js +70 -70
- package/build/abi/convertResults.d.ts +2 -2
- package/build/abi/convertResults.js +56 -56
- package/build/abi/index.d.ts +26 -25
- package/build/abi/index.js +185 -166
- package/build/abi/index.test.d.ts +1 -1
- package/build/abi/index.test.js +651 -651
- package/build/abi/multicall.d.ts +13 -13
- package/build/abi/multicall.js +210 -210
- package/build/api.d.ts +10 -10
- package/build/api.js +32 -32
- package/build/cdp/compoundTokens.d.ts +68 -68
- package/build/cdp/compoundTokens.js +69 -69
- package/build/cdp/index.d.ts +29 -29
- package/build/cdp/index.js +124 -124
- package/build/cdp/index.test.d.ts +1 -1
- package/build/cdp/index.test.js +82 -82
- package/build/cdp/makerTokens.d.ts +10 -10
- package/build/cdp/makerTokens.js +244 -244
- package/build/cli.d.ts +2 -2
- package/build/cli.js +95 -95
- package/build/computeTVL/blocks.d.ts +15 -15
- package/build/computeTVL/blocks.js +136 -136
- package/build/computeTVL/blocks.test.d.ts +1 -1
- package/build/computeTVL/blocks.test.js +56 -56
- package/build/computeTVL/humanizeNumber.d.ts +1 -1
- package/build/computeTVL/humanizeNumber.js +18 -18
- package/build/computeTVL/index.d.ts +52 -52
- package/build/computeTVL/index.js +373 -373
- package/build/computeTVL/index.test.d.ts +1 -1
- package/build/computeTVL/index.test.js +107 -107
- package/build/computeTVL/prices.d.ts +9 -9
- package/build/computeTVL/prices.js +163 -163
- package/build/erc20/index.d.ts +31 -31
- package/build/erc20/index.js +144 -144
- package/build/erc20/index.test.d.ts +1 -1
- package/build/erc20/index.test.js +124 -124
- package/build/eth/index.d.ts +21 -21
- package/build/eth/index.js +90 -90
- package/build/eth/index.test.d.ts +1 -1
- package/build/eth/index.test.js +122 -122
- package/build/general.d.ts +7 -7
- package/build/general.js +94 -94
- package/build/general.test.d.ts +1 -1
- package/build/general.test.js +73 -73
- package/build/generalUtil.d.ts +19 -19
- package/build/generalUtil.js +117 -117
- package/build/generalUtil.test.d.ts +1 -1
- package/build/generalUtil.test.js +59 -59
- package/build/index.d.ts +2 -2
- package/build/index.js +24 -24
- package/build/index.test.js +69 -69
- package/build/types.d.ts +5 -5
- package/build/types.js +2 -2
- package/build/util/index.d.ts +57 -57
- package/build/util/index.js +351 -351
- package/build/util/index.test.d.ts +1 -1
- package/build/util/index.test.js +314 -314
- package/build/util/tokenList.d.ts +14 -14
- package/build/util/tokenList.js +3631 -3631
- package/package.json +41 -41
package/build/cli.js
CHANGED
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
6
|
-
}) : (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
o[k2] = m[k];
|
|
9
|
-
}));
|
|
10
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
11
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12
|
-
}) : function(o, v) {
|
|
13
|
-
o["default"] = v;
|
|
14
|
-
});
|
|
15
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
16
|
-
if (mod && mod.__esModule) return mod;
|
|
17
|
-
var result = {};
|
|
18
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
19
|
-
__setModuleDefault(result, mod);
|
|
20
|
-
return result;
|
|
21
|
-
};
|
|
22
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
23
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
24
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
26
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
27
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
28
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
32
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
33
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
34
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
35
|
-
function step(op) {
|
|
36
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
37
|
-
while (_) try {
|
|
38
|
-
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;
|
|
39
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
40
|
-
switch (op[0]) {
|
|
41
|
-
case 0: case 1: t = op; break;
|
|
42
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
43
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
44
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
45
|
-
default:
|
|
46
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
47
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
48
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
49
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
50
|
-
if (t[2]) _.ops.pop();
|
|
51
|
-
_.trys.pop(); continue;
|
|
52
|
-
}
|
|
53
|
-
op = body.call(thisArg, _);
|
|
54
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
55
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
59
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
|
-
};
|
|
61
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
-
var path_1 = __importDefault(require("path"));
|
|
63
|
-
var computeTVL_1 = __importDefault(require("./computeTVL"));
|
|
64
|
-
var blocks_1 = require("./computeTVL/blocks");
|
|
65
|
-
var humanizeNumber_1 = require("./computeTVL/humanizeNumber");
|
|
66
|
-
if (process.argv.length < 3) {
|
|
67
|
-
console.error("Missing argument, you need to provide the filename of the adapter to test.\n Eg: npx @defillama/sdk projects/myadapter.js");
|
|
68
|
-
process.exit(1);
|
|
69
|
-
}
|
|
70
|
-
var passedFile = path_1.default.resolve(process.cwd(), process.argv[2]);
|
|
71
|
-
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
72
|
-
var moduleToTest, _a, timestamp, ethereumBlock, chainBlocks, tvl, usdTvl;
|
|
73
|
-
return __generator(this, function (_b) {
|
|
74
|
-
switch (_b.label) {
|
|
75
|
-
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require(passedFile)); })];
|
|
76
|
-
case 1:
|
|
77
|
-
moduleToTest = _b.sent();
|
|
78
|
-
return [4 /*yield*/, blocks_1.getCurrentBlocks()];
|
|
79
|
-
case 2:
|
|
80
|
-
_a = _b.sent(), timestamp = _a.timestamp, ethereumBlock = _a.ethereumBlock, chainBlocks = _a.chainBlocks;
|
|
81
|
-
return [4 /*yield*/, moduleToTest.tvl(timestamp, ethereumBlock, chainBlocks)];
|
|
82
|
-
case 3:
|
|
83
|
-
tvl = _b.sent();
|
|
84
|
-
if (typeof tvl !== "object") {
|
|
85
|
-
throw new Error("TVL returned is not a balances object");
|
|
86
|
-
}
|
|
87
|
-
return [4 /*yield*/, computeTVL_1.default(tvl, "now", true)];
|
|
88
|
-
case 4:
|
|
89
|
-
usdTvl = (_b.sent()).usdTvl;
|
|
90
|
-
console.log("Total:", humanizeNumber_1.humanizeNumber(usdTvl));
|
|
91
|
-
process.exit(0);
|
|
92
|
-
return [2 /*return*/];
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}); })();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
6
|
+
}) : (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
o[k2] = m[k];
|
|
9
|
+
}));
|
|
10
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
11
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12
|
+
}) : function(o, v) {
|
|
13
|
+
o["default"] = v;
|
|
14
|
+
});
|
|
15
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
16
|
+
if (mod && mod.__esModule) return mod;
|
|
17
|
+
var result = {};
|
|
18
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
19
|
+
__setModuleDefault(result, mod);
|
|
20
|
+
return result;
|
|
21
|
+
};
|
|
22
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
23
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
24
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
25
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
26
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
27
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
28
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
32
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
33
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
34
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
35
|
+
function step(op) {
|
|
36
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
37
|
+
while (_) try {
|
|
38
|
+
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;
|
|
39
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
40
|
+
switch (op[0]) {
|
|
41
|
+
case 0: case 1: t = op; break;
|
|
42
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
43
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
44
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
45
|
+
default:
|
|
46
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
47
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
48
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
49
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
50
|
+
if (t[2]) _.ops.pop();
|
|
51
|
+
_.trys.pop(); continue;
|
|
52
|
+
}
|
|
53
|
+
op = body.call(thisArg, _);
|
|
54
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
55
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
59
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
60
|
+
};
|
|
61
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
62
|
+
var path_1 = __importDefault(require("path"));
|
|
63
|
+
var computeTVL_1 = __importDefault(require("./computeTVL"));
|
|
64
|
+
var blocks_1 = require("./computeTVL/blocks");
|
|
65
|
+
var humanizeNumber_1 = require("./computeTVL/humanizeNumber");
|
|
66
|
+
if (process.argv.length < 3) {
|
|
67
|
+
console.error("Missing argument, you need to provide the filename of the adapter to test.\n Eg: npx @defillama/sdk projects/myadapter.js");
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
var passedFile = path_1.default.resolve(process.cwd(), process.argv[2]);
|
|
71
|
+
(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
72
|
+
var moduleToTest, _a, timestamp, ethereumBlock, chainBlocks, tvl, usdTvl;
|
|
73
|
+
return __generator(this, function (_b) {
|
|
74
|
+
switch (_b.label) {
|
|
75
|
+
case 0: return [4 /*yield*/, Promise.resolve().then(function () { return __importStar(require(passedFile)); })];
|
|
76
|
+
case 1:
|
|
77
|
+
moduleToTest = _b.sent();
|
|
78
|
+
return [4 /*yield*/, blocks_1.getCurrentBlocks()];
|
|
79
|
+
case 2:
|
|
80
|
+
_a = _b.sent(), timestamp = _a.timestamp, ethereumBlock = _a.ethereumBlock, chainBlocks = _a.chainBlocks;
|
|
81
|
+
return [4 /*yield*/, moduleToTest.tvl(timestamp, ethereumBlock, chainBlocks)];
|
|
82
|
+
case 3:
|
|
83
|
+
tvl = _b.sent();
|
|
84
|
+
if (typeof tvl !== "object") {
|
|
85
|
+
throw new Error("TVL returned is not a balances object");
|
|
86
|
+
}
|
|
87
|
+
return [4 /*yield*/, computeTVL_1.default(tvl, "now", true)];
|
|
88
|
+
case 4:
|
|
89
|
+
usdTvl = (_b.sent()).usdTvl;
|
|
90
|
+
console.log("Total:", humanizeNumber_1.humanizeNumber(usdTvl));
|
|
91
|
+
process.exit(0);
|
|
92
|
+
return [2 /*return*/];
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}); })();
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { Chain } from "../general";
|
|
2
|
-
export declare const chainsForBlocks: Chain[];
|
|
3
|
-
export declare function getBlocks(timestamp: number): Promise<{
|
|
4
|
-
ethereumBlock: number;
|
|
5
|
-
chainBlocks: {
|
|
6
|
-
[chain: string]: number;
|
|
7
|
-
};
|
|
8
|
-
}>;
|
|
9
|
-
export declare function getCurrentBlocks(): Promise<{
|
|
10
|
-
timestamp: number;
|
|
11
|
-
ethereumBlock: number;
|
|
12
|
-
chainBlocks: {
|
|
13
|
-
[chain: string]: number;
|
|
14
|
-
};
|
|
15
|
-
}>;
|
|
1
|
+
import type { Chain } from "../general";
|
|
2
|
+
export declare const chainsForBlocks: Chain[];
|
|
3
|
+
export declare function getBlocks(timestamp: number): Promise<{
|
|
4
|
+
ethereumBlock: number;
|
|
5
|
+
chainBlocks: {
|
|
6
|
+
[chain: string]: number;
|
|
7
|
+
};
|
|
8
|
+
}>;
|
|
9
|
+
export declare function getCurrentBlocks(): Promise<{
|
|
10
|
+
timestamp: number;
|
|
11
|
+
ethereumBlock: number;
|
|
12
|
+
chainBlocks: {
|
|
13
|
+
[chain: string]: number;
|
|
14
|
+
};
|
|
15
|
+
}>;
|
|
@@ -1,136 +1,136 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.getCurrentBlocks = exports.getBlocks = exports.chainsForBlocks = void 0;
|
|
40
|
-
var general_1 = require("../general");
|
|
41
|
-
var index_1 = require("../util/index");
|
|
42
|
-
exports.chainsForBlocks = ["avax", "bsc", "polygon", "xdai", "fantom", "arbitrum"];
|
|
43
|
-
var blockRetries = 5;
|
|
44
|
-
function getChainBlocks(timestamp) {
|
|
45
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
-
var chainBlocks;
|
|
47
|
-
var _this = this;
|
|
48
|
-
return __generator(this, function (_a) {
|
|
49
|
-
switch (_a.label) {
|
|
50
|
-
case 0:
|
|
51
|
-
chainBlocks = {};
|
|
52
|
-
return [4 /*yield*/, Promise.all(exports.chainsForBlocks.map(function (chain) { return __awaiter(_this, void 0, void 0, function () {
|
|
53
|
-
var i, _a, _b, e_1;
|
|
54
|
-
return __generator(this, function (_c) {
|
|
55
|
-
switch (_c.label) {
|
|
56
|
-
case 0:
|
|
57
|
-
i = 0;
|
|
58
|
-
_c.label = 1;
|
|
59
|
-
case 1:
|
|
60
|
-
if (!(i < blockRetries)) return [3 /*break*/, 6];
|
|
61
|
-
_c.label = 2;
|
|
62
|
-
case 2:
|
|
63
|
-
_c.trys.push([2, 4, , 5]);
|
|
64
|
-
_a = chainBlocks;
|
|
65
|
-
_b = chain;
|
|
66
|
-
return [4 /*yield*/, index_1.lookupBlock(timestamp, {
|
|
67
|
-
chain: chain,
|
|
68
|
-
}).then(function (block) { return block.block; })];
|
|
69
|
-
case 3:
|
|
70
|
-
_a[_b] = _c.sent();
|
|
71
|
-
return [3 /*break*/, 6];
|
|
72
|
-
case 4:
|
|
73
|
-
e_1 = _c.sent();
|
|
74
|
-
if (i === blockRetries - 1) {
|
|
75
|
-
throw e_1;
|
|
76
|
-
}
|
|
77
|
-
return [3 /*break*/, 5];
|
|
78
|
-
case 5:
|
|
79
|
-
i++;
|
|
80
|
-
return [3 /*break*/, 1];
|
|
81
|
-
case 6: return [2 /*return*/];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
}); }))];
|
|
85
|
-
case 1:
|
|
86
|
-
_a.sent();
|
|
87
|
-
return [2 /*return*/, chainBlocks];
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
function getBlocks(timestamp) {
|
|
93
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
-
var _a, ethBlock, chainBlocks;
|
|
95
|
-
return __generator(this, function (_b) {
|
|
96
|
-
switch (_b.label) {
|
|
97
|
-
case 0: return [4 /*yield*/, Promise.all([index_1.lookupBlock(timestamp), getChainBlocks(timestamp)])];
|
|
98
|
-
case 1:
|
|
99
|
-
_a = _b.sent(), ethBlock = _a[0], chainBlocks = _a[1];
|
|
100
|
-
chainBlocks['ethereum'] = ethBlock.block;
|
|
101
|
-
return [2 /*return*/, {
|
|
102
|
-
ethereumBlock: ethBlock.block,
|
|
103
|
-
chainBlocks: chainBlocks,
|
|
104
|
-
}];
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
exports.getBlocks = getBlocks;
|
|
110
|
-
function getCurrentBlocks() {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
-
var provider, lastBlockNumber, block, chainBlocks;
|
|
113
|
-
return __generator(this, function (_a) {
|
|
114
|
-
switch (_a.label) {
|
|
115
|
-
case 0:
|
|
116
|
-
provider = general_1.getProvider("ethereum");
|
|
117
|
-
return [4 /*yield*/, provider.getBlockNumber()];
|
|
118
|
-
case 1:
|
|
119
|
-
lastBlockNumber = _a.sent();
|
|
120
|
-
return [4 /*yield*/, provider.getBlock(lastBlockNumber - 5)];
|
|
121
|
-
case 2:
|
|
122
|
-
block = _a.sent();
|
|
123
|
-
return [4 /*yield*/, getChainBlocks(block.timestamp)];
|
|
124
|
-
case 3:
|
|
125
|
-
chainBlocks = _a.sent();
|
|
126
|
-
chainBlocks['ethereum'] = block.number;
|
|
127
|
-
return [2 /*return*/, {
|
|
128
|
-
timestamp: block.timestamp,
|
|
129
|
-
ethereumBlock: block.number,
|
|
130
|
-
chainBlocks: chainBlocks,
|
|
131
|
-
}];
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
exports.getCurrentBlocks = getCurrentBlocks;
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.getCurrentBlocks = exports.getBlocks = exports.chainsForBlocks = void 0;
|
|
40
|
+
var general_1 = require("../general");
|
|
41
|
+
var index_1 = require("../util/index");
|
|
42
|
+
exports.chainsForBlocks = ["avax", "bsc", "polygon", "xdai", "fantom", "arbitrum"];
|
|
43
|
+
var blockRetries = 5;
|
|
44
|
+
function getChainBlocks(timestamp) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
46
|
+
var chainBlocks;
|
|
47
|
+
var _this = this;
|
|
48
|
+
return __generator(this, function (_a) {
|
|
49
|
+
switch (_a.label) {
|
|
50
|
+
case 0:
|
|
51
|
+
chainBlocks = {};
|
|
52
|
+
return [4 /*yield*/, Promise.all(exports.chainsForBlocks.map(function (chain) { return __awaiter(_this, void 0, void 0, function () {
|
|
53
|
+
var i, _a, _b, e_1;
|
|
54
|
+
return __generator(this, function (_c) {
|
|
55
|
+
switch (_c.label) {
|
|
56
|
+
case 0:
|
|
57
|
+
i = 0;
|
|
58
|
+
_c.label = 1;
|
|
59
|
+
case 1:
|
|
60
|
+
if (!(i < blockRetries)) return [3 /*break*/, 6];
|
|
61
|
+
_c.label = 2;
|
|
62
|
+
case 2:
|
|
63
|
+
_c.trys.push([2, 4, , 5]);
|
|
64
|
+
_a = chainBlocks;
|
|
65
|
+
_b = chain;
|
|
66
|
+
return [4 /*yield*/, index_1.lookupBlock(timestamp, {
|
|
67
|
+
chain: chain,
|
|
68
|
+
}).then(function (block) { return block.block; })];
|
|
69
|
+
case 3:
|
|
70
|
+
_a[_b] = _c.sent();
|
|
71
|
+
return [3 /*break*/, 6];
|
|
72
|
+
case 4:
|
|
73
|
+
e_1 = _c.sent();
|
|
74
|
+
if (i === blockRetries - 1) {
|
|
75
|
+
throw e_1;
|
|
76
|
+
}
|
|
77
|
+
return [3 /*break*/, 5];
|
|
78
|
+
case 5:
|
|
79
|
+
i++;
|
|
80
|
+
return [3 /*break*/, 1];
|
|
81
|
+
case 6: return [2 /*return*/];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}); }))];
|
|
85
|
+
case 1:
|
|
86
|
+
_a.sent();
|
|
87
|
+
return [2 /*return*/, chainBlocks];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
function getBlocks(timestamp) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
+
var _a, ethBlock, chainBlocks;
|
|
95
|
+
return __generator(this, function (_b) {
|
|
96
|
+
switch (_b.label) {
|
|
97
|
+
case 0: return [4 /*yield*/, Promise.all([index_1.lookupBlock(timestamp), getChainBlocks(timestamp)])];
|
|
98
|
+
case 1:
|
|
99
|
+
_a = _b.sent(), ethBlock = _a[0], chainBlocks = _a[1];
|
|
100
|
+
chainBlocks['ethereum'] = ethBlock.block;
|
|
101
|
+
return [2 /*return*/, {
|
|
102
|
+
ethereumBlock: ethBlock.block,
|
|
103
|
+
chainBlocks: chainBlocks,
|
|
104
|
+
}];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
exports.getBlocks = getBlocks;
|
|
110
|
+
function getCurrentBlocks() {
|
|
111
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
+
var provider, lastBlockNumber, block, chainBlocks;
|
|
113
|
+
return __generator(this, function (_a) {
|
|
114
|
+
switch (_a.label) {
|
|
115
|
+
case 0:
|
|
116
|
+
provider = general_1.getProvider("ethereum");
|
|
117
|
+
return [4 /*yield*/, provider.getBlockNumber()];
|
|
118
|
+
case 1:
|
|
119
|
+
lastBlockNumber = _a.sent();
|
|
120
|
+
return [4 /*yield*/, provider.getBlock(lastBlockNumber - 5)];
|
|
121
|
+
case 2:
|
|
122
|
+
block = _a.sent();
|
|
123
|
+
return [4 /*yield*/, getChainBlocks(block.timestamp)];
|
|
124
|
+
case 3:
|
|
125
|
+
chainBlocks = _a.sent();
|
|
126
|
+
chainBlocks['ethereum'] = block.number;
|
|
127
|
+
return [2 /*return*/, {
|
|
128
|
+
timestamp: block.timestamp,
|
|
129
|
+
ethereumBlock: block.number,
|
|
130
|
+
chainBlocks: chainBlocks,
|
|
131
|
+
}];
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
exports.getCurrentBlocks = getCurrentBlocks;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,56 +1,56 @@
|
|
|
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
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
var blocks_1 = require("./blocks");
|
|
40
|
-
jest.setTimeout(30000);
|
|
41
|
-
test("multiple runs of getCurrentBlocks are fine", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
-
var calls, i;
|
|
43
|
-
return __generator(this, function (_a) {
|
|
44
|
-
switch (_a.label) {
|
|
45
|
-
case 0:
|
|
46
|
-
calls = [];
|
|
47
|
-
for (i = 0; i < 3; i++) {
|
|
48
|
-
calls.push(blocks_1.getCurrentBlocks());
|
|
49
|
-
}
|
|
50
|
-
return [4 /*yield*/, Promise.all(calls)];
|
|
51
|
-
case 1:
|
|
52
|
-
_a.sent();
|
|
53
|
-
return [2 /*return*/];
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
}); });
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
var blocks_1 = require("./blocks");
|
|
40
|
+
jest.setTimeout(30000);
|
|
41
|
+
test("multiple runs of getCurrentBlocks are fine", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
+
var calls, i;
|
|
43
|
+
return __generator(this, function (_a) {
|
|
44
|
+
switch (_a.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
calls = [];
|
|
47
|
+
for (i = 0; i < 3; i++) {
|
|
48
|
+
calls.push(blocks_1.getCurrentBlocks());
|
|
49
|
+
}
|
|
50
|
+
return [4 /*yield*/, Promise.all(calls)];
|
|
51
|
+
case 1:
|
|
52
|
+
_a.sent();
|
|
53
|
+
return [2 /*return*/];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}); });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function humanizeNumber(amount: number): string;
|
|
1
|
+
export declare function humanizeNumber(amount: number): string;
|