@defillama/sdk 2.3.21 → 2.3.25
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 +25 -25
- package/build/abi/index.js +166 -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 +50 -49
- package/build/computeTVL/index.js +371 -353
- 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 +88 -88
- 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/general.test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
package/build/general.test.js
CHANGED
|
@@ -1,73 +1,73 @@
|
|
|
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 index_1 = require("./eth/index");
|
|
40
|
-
jest.setTimeout(10000);
|
|
41
|
-
test("RPC nodes from multiple chains support archive queries", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
-
var _i, _a, chain, ethOwned, e_1;
|
|
43
|
-
return __generator(this, function (_b) {
|
|
44
|
-
switch (_b.label) {
|
|
45
|
-
case 0:
|
|
46
|
-
_i = 0, _a = ["ethereum", "fantom", "rsk", "avax"];
|
|
47
|
-
_b.label = 1;
|
|
48
|
-
case 1:
|
|
49
|
-
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
50
|
-
chain = _a[_i];
|
|
51
|
-
_b.label = 2;
|
|
52
|
-
case 2:
|
|
53
|
-
_b.trys.push([2, 4, , 5]);
|
|
54
|
-
return [4 /*yield*/, index_1.getBalance({
|
|
55
|
-
target: "0x0000000000000000000000000000000000000000",
|
|
56
|
-
block: 100,
|
|
57
|
-
chain: chain,
|
|
58
|
-
})];
|
|
59
|
-
case 3:
|
|
60
|
-
ethOwned = _b.sent();
|
|
61
|
-
expect(ethOwned.output).toBe("0");
|
|
62
|
-
return [3 /*break*/, 5];
|
|
63
|
-
case 4:
|
|
64
|
-
e_1 = _b.sent();
|
|
65
|
-
console.log("Error on chain " + chain);
|
|
66
|
-
throw e_1;
|
|
67
|
-
case 5:
|
|
68
|
-
_i++;
|
|
69
|
-
return [3 /*break*/, 1];
|
|
70
|
-
case 6: return [2 /*return*/];
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}); });
|
|
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 index_1 = require("./eth/index");
|
|
40
|
+
jest.setTimeout(10000);
|
|
41
|
+
test("RPC nodes from multiple chains support archive queries", function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
42
|
+
var _i, _a, chain, ethOwned, e_1;
|
|
43
|
+
return __generator(this, function (_b) {
|
|
44
|
+
switch (_b.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
_i = 0, _a = ["ethereum", "fantom", "rsk", "avax"];
|
|
47
|
+
_b.label = 1;
|
|
48
|
+
case 1:
|
|
49
|
+
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
50
|
+
chain = _a[_i];
|
|
51
|
+
_b.label = 2;
|
|
52
|
+
case 2:
|
|
53
|
+
_b.trys.push([2, 4, , 5]);
|
|
54
|
+
return [4 /*yield*/, index_1.getBalance({
|
|
55
|
+
target: "0x0000000000000000000000000000000000000000",
|
|
56
|
+
block: 100,
|
|
57
|
+
chain: chain,
|
|
58
|
+
})];
|
|
59
|
+
case 3:
|
|
60
|
+
ethOwned = _b.sent();
|
|
61
|
+
expect(ethOwned.output).toBe("0");
|
|
62
|
+
return [3 /*break*/, 5];
|
|
63
|
+
case 4:
|
|
64
|
+
e_1 = _b.sent();
|
|
65
|
+
console.log("Error on chain " + chain);
|
|
66
|
+
throw e_1;
|
|
67
|
+
case 5:
|
|
68
|
+
_i++;
|
|
69
|
+
return [3 /*break*/, 1];
|
|
70
|
+
case 6: return [2 /*return*/];
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}); });
|
package/build/generalUtil.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import computeTVL from "./computeTVL";
|
|
2
|
-
import type { Balances, StringNumber, Address } from "./types";
|
|
3
|
-
export declare function sumMultiBalanceOf(balances: Balances, results: {
|
|
4
|
-
ethCallCount?: number;
|
|
5
|
-
output: {
|
|
6
|
-
output: StringNumber;
|
|
7
|
-
success: boolean;
|
|
8
|
-
input: {
|
|
9
|
-
target: Address;
|
|
10
|
-
params: string[];
|
|
11
|
-
};
|
|
12
|
-
}[];
|
|
13
|
-
}, allCallsMustBeSuccessful?: boolean, transformAddress?: (addr: string) => string): void;
|
|
14
|
-
export declare function sumSingleBalance(balances: Balances, token: string, balance: string | number): void;
|
|
15
|
-
declare type ChainBlocks = {
|
|
16
|
-
[chain: string]: number;
|
|
17
|
-
};
|
|
18
|
-
export declare function sumChainTvls(chainTvls: Array<(timestamp: number, ethBlock: number, chainBlocks: ChainBlocks) => Promise<Balances>>): (timestamp: number, ethBlock: number, chainBlocks: ChainBlocks) => Promise<{}>;
|
|
19
|
-
export { computeTVL };
|
|
1
|
+
import computeTVL from "./computeTVL";
|
|
2
|
+
import type { Balances, StringNumber, Address } from "./types";
|
|
3
|
+
export declare function sumMultiBalanceOf(balances: Balances, results: {
|
|
4
|
+
ethCallCount?: number;
|
|
5
|
+
output: {
|
|
6
|
+
output: StringNumber;
|
|
7
|
+
success: boolean;
|
|
8
|
+
input: {
|
|
9
|
+
target: Address;
|
|
10
|
+
params: string[];
|
|
11
|
+
};
|
|
12
|
+
}[];
|
|
13
|
+
}, allCallsMustBeSuccessful?: boolean, transformAddress?: (addr: string) => string): void;
|
|
14
|
+
export declare function sumSingleBalance(balances: Balances, token: string, balance: string | number): void;
|
|
15
|
+
declare type ChainBlocks = {
|
|
16
|
+
[chain: string]: number;
|
|
17
|
+
};
|
|
18
|
+
export declare function sumChainTvls(chainTvls: Array<(timestamp: number, ethBlock: number, chainBlocks: ChainBlocks) => Promise<Balances>>): (timestamp: number, ethBlock: number, chainBlocks: ChainBlocks) => Promise<{}>;
|
|
19
|
+
export { computeTVL };
|
package/build/generalUtil.js
CHANGED
|
@@ -1,117 +1,117 @@
|
|
|
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.computeTVL = exports.sumChainTvls = exports.sumSingleBalance = exports.sumMultiBalanceOf = void 0;
|
|
43
|
-
var ethers_1 = require("ethers");
|
|
44
|
-
var computeTVL_1 = __importDefault(require("./computeTVL"));
|
|
45
|
-
exports.computeTVL = computeTVL_1.default;
|
|
46
|
-
// We ignore `sum` as it's never used (only in some SDK wrapper code)
|
|
47
|
-
function sumMultiBalanceOf(balances, results, allCallsMustBeSuccessful, transformAddress) {
|
|
48
|
-
if (allCallsMustBeSuccessful === void 0) { allCallsMustBeSuccessful = true; }
|
|
49
|
-
if (transformAddress === void 0) { transformAddress = function (addr) { return addr; }; }
|
|
50
|
-
results.output.map(function (result) {
|
|
51
|
-
var _a;
|
|
52
|
-
if (result.success) {
|
|
53
|
-
var address = transformAddress(result.input.target);
|
|
54
|
-
var balance = result.output;
|
|
55
|
-
if (ethers_1.BigNumber.from(balance).lte(0)) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
balances[address] = ethers_1.BigNumber.from((_a = balances[address]) !== null && _a !== void 0 ? _a : 0)
|
|
59
|
-
.add(balance)
|
|
60
|
-
.toString();
|
|
61
|
-
}
|
|
62
|
-
else if (allCallsMustBeSuccessful) {
|
|
63
|
-
console.error(result);
|
|
64
|
-
throw new Error("balanceOf multicall failed");
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
exports.sumMultiBalanceOf = sumMultiBalanceOf;
|
|
69
|
-
function sumSingleBalance(balances, token, balance) {
|
|
70
|
-
var _a, _b;
|
|
71
|
-
if (typeof balance === 'number') {
|
|
72
|
-
var prevBalance = (_a = balances[token]) !== null && _a !== void 0 ? _a : 0;
|
|
73
|
-
if (typeof prevBalance !== 'number') {
|
|
74
|
-
throw new Error("Trying to merge token balance and coingecko amount for " + token);
|
|
75
|
-
}
|
|
76
|
-
balances[token] = prevBalance + balance;
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
var prevBalance = ethers_1.BigNumber.from((_b = balances[token]) !== null && _b !== void 0 ? _b : "0");
|
|
80
|
-
balances[token] = prevBalance.add(ethers_1.BigNumber.from(balance)).toString();
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
exports.sumSingleBalance = sumSingleBalance;
|
|
84
|
-
function mergeBalances(balances, balancesToMerge) {
|
|
85
|
-
Object.entries(balancesToMerge).forEach(function (balance) {
|
|
86
|
-
sumSingleBalance(balances, balance[0], balance[1]);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
function sumChainTvls(chainTvls) {
|
|
90
|
-
var _this = this;
|
|
91
|
-
return function (timestamp, ethBlock, chainBlocks) { return __awaiter(_this, void 0, void 0, function () {
|
|
92
|
-
var balances;
|
|
93
|
-
var _this = this;
|
|
94
|
-
return __generator(this, function (_a) {
|
|
95
|
-
switch (_a.label) {
|
|
96
|
-
case 0:
|
|
97
|
-
balances = {};
|
|
98
|
-
return [4 /*yield*/, Promise.all(chainTvls.map(function (chainTvl) { return __awaiter(_this, void 0, void 0, function () {
|
|
99
|
-
var chainBalances;
|
|
100
|
-
return __generator(this, function (_a) {
|
|
101
|
-
switch (_a.label) {
|
|
102
|
-
case 0: return [4 /*yield*/, chainTvl(timestamp, ethBlock, chainBlocks)];
|
|
103
|
-
case 1:
|
|
104
|
-
chainBalances = _a.sent();
|
|
105
|
-
mergeBalances(balances, chainBalances);
|
|
106
|
-
return [2 /*return*/];
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}); }))];
|
|
110
|
-
case 1:
|
|
111
|
-
_a.sent();
|
|
112
|
-
return [2 /*return*/, balances];
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
}); };
|
|
116
|
-
}
|
|
117
|
-
exports.sumChainTvls = sumChainTvls;
|
|
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.computeTVL = exports.sumChainTvls = exports.sumSingleBalance = exports.sumMultiBalanceOf = void 0;
|
|
43
|
+
var ethers_1 = require("ethers");
|
|
44
|
+
var computeTVL_1 = __importDefault(require("./computeTVL"));
|
|
45
|
+
exports.computeTVL = computeTVL_1.default;
|
|
46
|
+
// We ignore `sum` as it's never used (only in some SDK wrapper code)
|
|
47
|
+
function sumMultiBalanceOf(balances, results, allCallsMustBeSuccessful, transformAddress) {
|
|
48
|
+
if (allCallsMustBeSuccessful === void 0) { allCallsMustBeSuccessful = true; }
|
|
49
|
+
if (transformAddress === void 0) { transformAddress = function (addr) { return addr; }; }
|
|
50
|
+
results.output.map(function (result) {
|
|
51
|
+
var _a;
|
|
52
|
+
if (result.success) {
|
|
53
|
+
var address = transformAddress(result.input.target);
|
|
54
|
+
var balance = result.output;
|
|
55
|
+
if (ethers_1.BigNumber.from(balance).lte(0)) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
balances[address] = ethers_1.BigNumber.from((_a = balances[address]) !== null && _a !== void 0 ? _a : 0)
|
|
59
|
+
.add(balance)
|
|
60
|
+
.toString();
|
|
61
|
+
}
|
|
62
|
+
else if (allCallsMustBeSuccessful) {
|
|
63
|
+
console.error(result);
|
|
64
|
+
throw new Error("balanceOf multicall failed");
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
exports.sumMultiBalanceOf = sumMultiBalanceOf;
|
|
69
|
+
function sumSingleBalance(balances, token, balance) {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
if (typeof balance === 'number') {
|
|
72
|
+
var prevBalance = (_a = balances[token]) !== null && _a !== void 0 ? _a : 0;
|
|
73
|
+
if (typeof prevBalance !== 'number') {
|
|
74
|
+
throw new Error("Trying to merge token balance and coingecko amount for " + token);
|
|
75
|
+
}
|
|
76
|
+
balances[token] = prevBalance + balance;
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
var prevBalance = ethers_1.BigNumber.from((_b = balances[token]) !== null && _b !== void 0 ? _b : "0");
|
|
80
|
+
balances[token] = prevBalance.add(ethers_1.BigNumber.from(balance)).toString();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.sumSingleBalance = sumSingleBalance;
|
|
84
|
+
function mergeBalances(balances, balancesToMerge) {
|
|
85
|
+
Object.entries(balancesToMerge).forEach(function (balance) {
|
|
86
|
+
sumSingleBalance(balances, balance[0], balance[1]);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
function sumChainTvls(chainTvls) {
|
|
90
|
+
var _this = this;
|
|
91
|
+
return function (timestamp, ethBlock, chainBlocks) { return __awaiter(_this, void 0, void 0, function () {
|
|
92
|
+
var balances;
|
|
93
|
+
var _this = this;
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
switch (_a.label) {
|
|
96
|
+
case 0:
|
|
97
|
+
balances = {};
|
|
98
|
+
return [4 /*yield*/, Promise.all(chainTvls.map(function (chainTvl) { return __awaiter(_this, void 0, void 0, function () {
|
|
99
|
+
var chainBalances;
|
|
100
|
+
return __generator(this, function (_a) {
|
|
101
|
+
switch (_a.label) {
|
|
102
|
+
case 0: return [4 /*yield*/, chainTvl(timestamp, ethBlock, chainBlocks)];
|
|
103
|
+
case 1:
|
|
104
|
+
chainBalances = _a.sent();
|
|
105
|
+
mergeBalances(balances, chainBalances);
|
|
106
|
+
return [2 /*return*/];
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}); }))];
|
|
110
|
+
case 1:
|
|
111
|
+
_a.sent();
|
|
112
|
+
return [2 /*return*/, balances];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}); };
|
|
116
|
+
}
|
|
117
|
+
exports.sumChainTvls = sumChainTvls;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -1,59 +1,59 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var generalUtil_1 = require("./generalUtil");
|
|
4
|
-
test("sumMultiBalanceOf", function () {
|
|
5
|
-
var balances = {
|
|
6
|
-
"0x0000000000000000000000000000000000000000": "1380309269697565432250",
|
|
7
|
-
};
|
|
8
|
-
generalUtil_1.sumMultiBalanceOf(balances, {
|
|
9
|
-
ethCallCount: 1,
|
|
10
|
-
output: [
|
|
11
|
-
{
|
|
12
|
-
input: {
|
|
13
|
-
target: "0x514910771af9ca656af840dff83e8264ecf986ca",
|
|
14
|
-
params: ["0xa04197e5f7971e7aef78cf5ad2bc65aac1a967aa"],
|
|
15
|
-
},
|
|
16
|
-
success: true,
|
|
17
|
-
output: "121787335350553116046",
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
input: {
|
|
21
|
-
target: "0xc00e94cb662c3520282e6f5717214004a7f26888",
|
|
22
|
-
params: ["0xfa203e643d1fddc5d8b91253ea23b3bd826cae9e"],
|
|
23
|
-
},
|
|
24
|
-
success: true,
|
|
25
|
-
output: "196377513373723266",
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
input: {
|
|
29
|
-
target: "0x80fb784b7ed66730e8b1dbd9820afd29931aab03",
|
|
30
|
-
params: ["0xd48c88a18bfa81486862c6d1d172a39f1365e8ac"],
|
|
31
|
-
},
|
|
32
|
-
success: true,
|
|
33
|
-
output: "240068223687113307904",
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
input: {
|
|
37
|
-
target: "0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f",
|
|
38
|
-
params: ["0x4cc89906db523af7c3bb240a959be21cb812b434"],
|
|
39
|
-
},
|
|
40
|
-
success: true,
|
|
41
|
-
output: "32125191633871661847",
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
});
|
|
45
|
-
expect(balances).toEqual({
|
|
46
|
-
"0x0000000000000000000000000000000000000000": "1380309269697565432250",
|
|
47
|
-
"0x514910771af9ca656af840dff83e8264ecf986ca": "121787335350553116046",
|
|
48
|
-
"0xc00e94cb662c3520282e6f5717214004a7f26888": "196377513373723266",
|
|
49
|
-
"0x80fb784b7ed66730e8b1dbd9820afd29931aab03": "240068223687113307904",
|
|
50
|
-
"0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f": "32125191633871661847",
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
test("sumSingleBalance", function () {
|
|
54
|
-
var balances = {};
|
|
55
|
-
generalUtil_1.sumSingleBalance(balances, "ethereum", "2");
|
|
56
|
-
expect(balances).toMatchInlineSnapshot("\n Object {\n \"ethereum\": \"2\",\n }\n ");
|
|
57
|
-
generalUtil_1.sumSingleBalance(balances, "ethereum", "5");
|
|
58
|
-
expect(balances).toMatchInlineSnapshot("\n Object {\n \"ethereum\": \"7\",\n }\n ");
|
|
59
|
-
});
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var generalUtil_1 = require("./generalUtil");
|
|
4
|
+
test("sumMultiBalanceOf", function () {
|
|
5
|
+
var balances = {
|
|
6
|
+
"0x0000000000000000000000000000000000000000": "1380309269697565432250",
|
|
7
|
+
};
|
|
8
|
+
generalUtil_1.sumMultiBalanceOf(balances, {
|
|
9
|
+
ethCallCount: 1,
|
|
10
|
+
output: [
|
|
11
|
+
{
|
|
12
|
+
input: {
|
|
13
|
+
target: "0x514910771af9ca656af840dff83e8264ecf986ca",
|
|
14
|
+
params: ["0xa04197e5f7971e7aef78cf5ad2bc65aac1a967aa"],
|
|
15
|
+
},
|
|
16
|
+
success: true,
|
|
17
|
+
output: "121787335350553116046",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
input: {
|
|
21
|
+
target: "0xc00e94cb662c3520282e6f5717214004a7f26888",
|
|
22
|
+
params: ["0xfa203e643d1fddc5d8b91253ea23b3bd826cae9e"],
|
|
23
|
+
},
|
|
24
|
+
success: true,
|
|
25
|
+
output: "196377513373723266",
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
input: {
|
|
29
|
+
target: "0x80fb784b7ed66730e8b1dbd9820afd29931aab03",
|
|
30
|
+
params: ["0xd48c88a18bfa81486862c6d1d172a39f1365e8ac"],
|
|
31
|
+
},
|
|
32
|
+
success: true,
|
|
33
|
+
output: "240068223687113307904",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
input: {
|
|
37
|
+
target: "0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f",
|
|
38
|
+
params: ["0x4cc89906db523af7c3bb240a959be21cb812b434"],
|
|
39
|
+
},
|
|
40
|
+
success: true,
|
|
41
|
+
output: "32125191633871661847",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
});
|
|
45
|
+
expect(balances).toEqual({
|
|
46
|
+
"0x0000000000000000000000000000000000000000": "1380309269697565432250",
|
|
47
|
+
"0x514910771af9ca656af840dff83e8264ecf986ca": "121787335350553116046",
|
|
48
|
+
"0xc00e94cb662c3520282e6f5717214004a7f26888": "196377513373723266",
|
|
49
|
+
"0x80fb784b7ed66730e8b1dbd9820afd29931aab03": "240068223687113307904",
|
|
50
|
+
"0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f": "32125191633871661847",
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
test("sumSingleBalance", function () {
|
|
54
|
+
var balances = {};
|
|
55
|
+
generalUtil_1.sumSingleBalance(balances, "ethereum", "2");
|
|
56
|
+
expect(balances).toMatchInlineSnapshot("\n Object {\n \"ethereum\": \"2\",\n }\n ");
|
|
57
|
+
generalUtil_1.sumSingleBalance(balances, "ethereum", "5");
|
|
58
|
+
expect(balances).toMatchInlineSnapshot("\n Object {\n \"ethereum\": \"7\",\n }\n ");
|
|
59
|
+
});
|
package/build/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * as util from "./generalUtil";
|
|
2
|
-
export * as api from "./api";
|
|
1
|
+
export * as util from "./generalUtil";
|
|
2
|
+
export * as api from "./api";
|
package/build/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.api = exports.util = void 0;
|
|
23
|
-
exports.util = __importStar(require("./generalUtil"));
|
|
24
|
-
exports.api = __importStar(require("./api"));
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.api = exports.util = void 0;
|
|
23
|
+
exports.util = __importStar(require("./generalUtil"));
|
|
24
|
+
exports.api = __importStar(require("./api"));
|