@riocrypto/common-server 1.0.1299 → 1.0.1302
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.
|
@@ -8,11 +8,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.buildFireblocksClient = void 0;
|
|
13
16
|
const fireblocks_sdk_1 = require("fireblocks-sdk");
|
|
14
17
|
const common_1 = require("@riocrypto/common");
|
|
15
18
|
const secret_manager_client_1 = require("./secret-manager-client");
|
|
19
|
+
const node_cache_1 = __importDefault(require("node-cache"));
|
|
20
|
+
const cache = new node_cache_1.default({ stdTTL: 60 });
|
|
16
21
|
class FireblocksClient {
|
|
17
22
|
constructor(privateKey, apiKey) {
|
|
18
23
|
this.fireblocks = new fireblocks_sdk_1.FireblocksSDK(privateKey, apiKey, "https://api.fireblocks.io");
|
|
@@ -90,47 +95,61 @@ class FireblocksClient {
|
|
|
90
95
|
}
|
|
91
96
|
getTotalVaultUSDBalance(vaultId) {
|
|
92
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const vaultAccount = yield this.fireblocks.getVaultAccountById(vaultId);
|
|
94
98
|
let balance = 0;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
99
|
+
const cachedResponse = cache.get(`getTotalVaultUSDBalance(${vaultId})`);
|
|
100
|
+
if (cachedResponse) {
|
|
101
|
+
balance = cachedResponse;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
const vaultAccount = yield this.fireblocks.getVaultAccountById(vaultId);
|
|
105
|
+
if (vaultAccount.assets) {
|
|
106
|
+
for (const asset of vaultAccount.assets) {
|
|
107
|
+
if ([
|
|
108
|
+
common_1.Crypto.USDC,
|
|
109
|
+
common_1.Crypto.USDCPolygon,
|
|
110
|
+
common_1.Crypto.USDCPolygonBridged,
|
|
111
|
+
common_1.Crypto.USDCSolana,
|
|
112
|
+
common_1.Crypto.USDTEthereum,
|
|
113
|
+
common_1.Crypto.USDTPolygon,
|
|
114
|
+
common_1.Crypto.USDTTron,
|
|
115
|
+
].includes(asset.id)) {
|
|
116
|
+
balance += Number(asset.available || 0);
|
|
117
|
+
}
|
|
107
118
|
}
|
|
108
119
|
}
|
|
120
|
+
cache.set(`getTotalVaultUSDBalance(${vaultId})`, balance);
|
|
109
121
|
}
|
|
110
122
|
return balance;
|
|
111
123
|
});
|
|
112
124
|
}
|
|
113
125
|
getTotalExchangesUSDBalance() {
|
|
114
126
|
return __awaiter(this, void 0, void 0, function* () {
|
|
115
|
-
let exchanges = yield this.fireblocks.getExchangeAccounts();
|
|
116
127
|
let balance = 0;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
const cachedResponse = cache.get(`getTotalExchangesUSDBalance()`);
|
|
129
|
+
if (cachedResponse) {
|
|
130
|
+
balance = cachedResponse;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
let exchanges = yield this.fireblocks.getExchangeAccounts();
|
|
134
|
+
exchanges.forEach((exchange) => {
|
|
135
|
+
exchange.assets.forEach((asset) => {
|
|
136
|
+
if ([
|
|
137
|
+
common_1.Crypto.USDC,
|
|
138
|
+
common_1.Crypto.USDCPolygon,
|
|
139
|
+
common_1.Crypto.USDCPolygonBridged,
|
|
140
|
+
common_1.Crypto.USDCSolana,
|
|
141
|
+
common_1.Crypto.USDTEthereum,
|
|
142
|
+
"USDT",
|
|
143
|
+
"USD",
|
|
144
|
+
common_1.Crypto.USDTPolygon,
|
|
145
|
+
common_1.Crypto.USDTTron,
|
|
146
|
+
].includes(asset.id)) {
|
|
147
|
+
balance += Number(asset.available);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
132
150
|
});
|
|
133
|
-
|
|
151
|
+
cache.set(`getTotalExchangesUSDBalance()`, balance);
|
|
152
|
+
}
|
|
134
153
|
return balance;
|
|
135
154
|
});
|
|
136
155
|
}
|