@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
- if (vaultAccount.assets) {
96
- for (const asset of vaultAccount.assets) {
97
- if ([
98
- common_1.Crypto.USDC,
99
- common_1.Crypto.USDCPolygon,
100
- common_1.Crypto.USDCPolygonBridged,
101
- common_1.Crypto.USDCSolana,
102
- common_1.Crypto.USDTEthereum,
103
- common_1.Crypto.USDTPolygon,
104
- common_1.Crypto.USDTTron,
105
- ].includes(asset.id)) {
106
- balance += Number(asset.available || 0);
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
- exchanges.forEach((exchange) => {
118
- exchange.assets.forEach((asset) => {
119
- if ([
120
- common_1.Crypto.USDC,
121
- common_1.Crypto.USDCPolygon,
122
- common_1.Crypto.USDCPolygonBridged,
123
- common_1.Crypto.USDCSolana,
124
- common_1.Crypto.USDTEthereum,
125
- "USDT",
126
- "USD",
127
- common_1.Crypto.USDTPolygon,
128
- common_1.Crypto.USDTTron,
129
- ].includes(asset.id)) {
130
- balance += Number(asset.available);
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1299",
3
+ "version": "1.0.1302",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",