@riocrypto/common-server 1.0.1299 → 1.0.1301
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,23 +95,31 @@ 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(`this.fireblocks.getVaultAccountById(${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(`this.fireblocks.getVaultAccountById(${vaultId})`, balance);
|
|
109
121
|
}
|
|
122
|
+
console.log("Balance is ", balance);
|
|
110
123
|
return balance;
|
|
111
124
|
});
|
|
112
125
|
}
|