@defillama/sdk 5.0.10 → 5.0.12
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/build/Balances.d.ts +10 -0
- package/build/Balances.js +51 -107
- package/build/ChainApi.d.ts +1 -0
- package/build/ChainApi.js +152 -253
- package/build/abi/abi2.js +47 -144
- package/build/abi/convertResults.js +9 -29
- package/build/abi/index.js +220 -326
- package/build/abi/multicall.js +115 -217
- package/build/abi/multicall3.js +59 -123
- package/build/abi/rpcCall.js +43 -106
- package/build/abi/tron.js +153 -283
- package/build/api.js +3 -4
- package/build/computeTVL/blocks.d.ts +1 -1
- package/build/computeTVL/blocks.js +2 -1
- package/build/computeTVL/humanizeNumber.js +6 -7
- package/build/computeTVL/prices.js +55 -145
- package/build/erc20/index.js +34 -122
- package/build/eth/index.js +37 -107
- package/build/general.js +22 -23
- package/build/generalUtil.js +68 -127
- package/build/index.js +2 -2
- package/build/providers.json +1 -1
- package/build/util/blocks.d.ts +5 -2
- package/build/util/blocks.js +234 -373
- package/build/util/blockscout.js +13 -58
- package/build/util/cache.js +112 -274
- package/build/util/computeTVL.js +72 -150
- package/build/util/cosmos.js +21 -75
- package/build/util/debugLog.js +5 -13
- package/build/util/env.d.ts +3 -2
- package/build/util/env.js +30 -35
- package/build/util/index.d.ts +5 -3
- package/build/util/index.js +105 -134
- package/build/util/internal-cache.js +7 -8
- package/build/util/logs.d.ts +1 -2
- package/build/util/logs.js +148 -236
- package/build/util/promisePool.js +11 -62
- package/build/util/r2.js +36 -95
- package/build/util/updateProviderList.js +23 -83
- package/package.json +2 -3
package/build/Balances.d.ts
CHANGED
|
@@ -30,5 +30,15 @@ export declare class Balances {
|
|
|
30
30
|
usdTokenBalances: BalancesV1;
|
|
31
31
|
rawTokenBalances: BalancesV1;
|
|
32
32
|
}>;
|
|
33
|
+
static getUSDValue(balances: BalancesV1, timestamp?: number): Promise<number>;
|
|
34
|
+
static getBalanceObjects(balances: BalancesV1, timestamp?: number): Promise<{
|
|
35
|
+
usdTvl: number;
|
|
36
|
+
usdTokenBalances: BalancesV1;
|
|
37
|
+
}>;
|
|
38
|
+
static getUSDJSONs(balances: BalancesV1, timestamp?: number): Promise<{
|
|
39
|
+
usdTvl: number;
|
|
40
|
+
usdTokenBalances: BalancesV1;
|
|
41
|
+
rawTokenBalances: BalancesV1;
|
|
42
|
+
}>;
|
|
33
43
|
}
|
|
34
44
|
export default Balances;
|
package/build/Balances.js
CHANGED
|
@@ -1,60 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
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 (g && (g = 0, op[0] && (_ = 0)), _) 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
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
40
4
|
};
|
|
41
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
6
|
exports.Balances = void 0;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
7
|
+
const generalUtil_1 = require("./generalUtil");
|
|
8
|
+
const computeTVL_1 = __importDefault(require("./util/computeTVL"));
|
|
9
|
+
const nullAddress = '0x0000000000000000000000000000000000000000';
|
|
10
|
+
class Balances {
|
|
11
|
+
constructor(params) {
|
|
48
12
|
var _a;
|
|
49
13
|
this.chain = (_a = params.chain) !== null && _a !== void 0 ? _a : 'ethereum';
|
|
50
14
|
this.timestamp = params.timestamp;
|
|
51
15
|
this._balances = {};
|
|
52
16
|
}
|
|
53
|
-
|
|
54
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.skipChain, skipChain = _c === void 0 ? false : _c;
|
|
17
|
+
_add(token, balance, { skipChain = false } = {}) {
|
|
55
18
|
token = token.replace(/\//g, ':');
|
|
56
|
-
|
|
57
|
-
|
|
19
|
+
const isIBCToken = token.startsWith('ibc:');
|
|
20
|
+
let chain = this.chain;
|
|
58
21
|
if (skipChain || isIBCToken) {
|
|
59
22
|
chain = undefined;
|
|
60
23
|
}
|
|
@@ -63,48 +26,42 @@ var Balances = /** @class */ (function () {
|
|
|
63
26
|
token = token.replace('peggy', '');
|
|
64
27
|
}
|
|
65
28
|
(0, generalUtil_1.sumSingleBalance)(this._balances, token, balance, chain);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
var _this = this;
|
|
69
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.skipChain, skipChain = _c === void 0 ? false : _c;
|
|
29
|
+
}
|
|
30
|
+
add(token, balance, { skipChain = false } = {}) {
|
|
70
31
|
if (!token)
|
|
71
32
|
throw new Error('token is required');
|
|
72
33
|
if (!balance)
|
|
73
34
|
return;
|
|
74
35
|
if (Array.isArray(balance)) {
|
|
75
36
|
if (Array.isArray(token)) {
|
|
76
|
-
this.addTokens(token, balance, { skipChain
|
|
37
|
+
this.addTokens(token, balance, { skipChain });
|
|
77
38
|
return;
|
|
78
39
|
}
|
|
79
40
|
else if (typeof token === 'string') {
|
|
80
|
-
balance.forEach(
|
|
41
|
+
balance.forEach((v) => this._add(token, v, { skipChain }));
|
|
81
42
|
return;
|
|
82
43
|
}
|
|
83
44
|
}
|
|
84
45
|
if (typeof token !== 'string')
|
|
85
46
|
throw new Error('token must be a string');
|
|
86
|
-
this._add(token, balance, { skipChain
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
Balances.prototype.addGasToken = function (balance) {
|
|
47
|
+
this._add(token, balance, { skipChain });
|
|
48
|
+
}
|
|
49
|
+
addToken(token, balance, { skipChain = false } = {}) {
|
|
50
|
+
this._add(token, balance, { skipChain });
|
|
51
|
+
}
|
|
52
|
+
addGasToken(balance) {
|
|
93
53
|
this._add(nullAddress, balance);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
var _this = this;
|
|
97
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.skipChain, skipChain = _c === void 0 ? false : _c;
|
|
54
|
+
}
|
|
55
|
+
addTokens(tokens, balances, { skipChain = false } = {}) {
|
|
98
56
|
if (!Array.isArray(tokens))
|
|
99
57
|
throw new Error('tokens must be an array');
|
|
100
58
|
if (!Array.isArray(balances))
|
|
101
59
|
throw new Error('balances must be an array');
|
|
102
60
|
if (tokens.length !== balances.length)
|
|
103
61
|
throw new Error('token and balance must have the same length');
|
|
104
|
-
tokens.forEach(
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
var _this = this;
|
|
62
|
+
tokens.forEach((v, i) => this._add(v, balances[i], { skipChain }));
|
|
63
|
+
}
|
|
64
|
+
addBalances(balances) {
|
|
108
65
|
if (balances instanceof Balances) {
|
|
109
66
|
if (balances === this)
|
|
110
67
|
return;
|
|
@@ -112,49 +69,36 @@ var Balances = /** @class */ (function () {
|
|
|
112
69
|
}
|
|
113
70
|
if (balances === this._balances)
|
|
114
71
|
return;
|
|
115
|
-
Object.entries(balances).forEach(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
Balances.prototype.getBalances = function () {
|
|
72
|
+
Object.entries(balances).forEach(([token, balance]) => this._add(token, balance, { skipChain: true }));
|
|
73
|
+
}
|
|
74
|
+
getBalances() {
|
|
121
75
|
return this._balances;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
Object.keys(this._balances).forEach(function (i) {
|
|
76
|
+
}
|
|
77
|
+
removeTokenBalance(token) {
|
|
78
|
+
const regex = new RegExp(token, 'i');
|
|
79
|
+
Object.keys(this._balances).forEach((i) => {
|
|
127
80
|
if (regex.test(i))
|
|
128
|
-
delete
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
Balances.prototype.getUSDValue = function () {
|
|
132
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
-
var usdTvl;
|
|
134
|
-
return __generator(this, function (_a) {
|
|
135
|
-
switch (_a.label) {
|
|
136
|
-
case 0: return [4 /*yield*/, (0, computeTVL_1.default)(this.getBalances(), this.timestamp)];
|
|
137
|
-
case 1:
|
|
138
|
-
usdTvl = (_a.sent()).usdTvl;
|
|
139
|
-
return [2 /*return*/, usdTvl];
|
|
140
|
-
}
|
|
141
|
-
});
|
|
81
|
+
delete this._balances[i];
|
|
142
82
|
});
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
83
|
+
}
|
|
84
|
+
async getUSDValue() {
|
|
85
|
+
const { usdTvl } = await (0, computeTVL_1.default)(this.getBalances(), this.timestamp);
|
|
86
|
+
return usdTvl;
|
|
87
|
+
}
|
|
88
|
+
async getUSDJSONs() {
|
|
89
|
+
const { usdTvl, usdTokenBalances } = await (0, computeTVL_1.default)(this.getBalances(), this.timestamp);
|
|
90
|
+
return { usdTvl, usdTokenBalances, rawTokenBalances: this.getBalances() };
|
|
91
|
+
}
|
|
92
|
+
static async getUSDValue(balances, timestamp) {
|
|
93
|
+
return (await (0, computeTVL_1.default)(balances, timestamp)).usdTvl;
|
|
94
|
+
}
|
|
95
|
+
static async getBalanceObjects(balances, timestamp) {
|
|
96
|
+
return (0, computeTVL_1.default)(balances, timestamp);
|
|
97
|
+
}
|
|
98
|
+
static async getUSDJSONs(balances, timestamp) {
|
|
99
|
+
const { usdTvl, usdTokenBalances } = await (0, computeTVL_1.default)(balances, timestamp);
|
|
100
|
+
return { usdTvl, usdTokenBalances, rawTokenBalances: balances };
|
|
101
|
+
}
|
|
102
|
+
}
|
|
159
103
|
exports.Balances = Balances;
|
|
160
104
|
exports.default = Balances;
|
package/build/ChainApi.d.ts
CHANGED