@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
- 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(`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
  }
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.1301",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",