@riocrypto/common-server 1.0.1301 → 1.0.1303

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.
@@ -3,7 +3,7 @@ import { Crypto } from "@riocrypto/common";
3
3
  declare class FireblocksClient {
4
4
  fireblocks: FireblocksSDK;
5
5
  constructor(privateKey: string, apiKey: string);
6
- estimateWithdrawFee(crypto: Crypto, address: string, amountCrypto: number): Promise<string | undefined>;
6
+ estimateWithdrawFee(crypto: Crypto, address: string, amountCrypto: number): Promise<number | undefined>;
7
7
  withdrawFromExchange(crypto: Crypto, address: string, amountCrypto: number): Promise<void>;
8
8
  withdrawFromVault(crypto: Crypto, address: string, amountCrypto: number): Promise<string>;
9
9
  getVaultCryptoBalance(vaultId: string, crypto: Crypto): Promise<number>;
@@ -18,28 +18,38 @@ const common_1 = require("@riocrypto/common");
18
18
  const secret_manager_client_1 = require("./secret-manager-client");
19
19
  const node_cache_1 = __importDefault(require("node-cache"));
20
20
  const cache = new node_cache_1.default({ stdTTL: 60 });
21
+ const cache2 = new node_cache_1.default({ stdTTL: 10000 });
21
22
  class FireblocksClient {
22
23
  constructor(privateKey, apiKey) {
23
24
  this.fireblocks = new fireblocks_sdk_1.FireblocksSDK(privateKey, apiKey, "https://api.fireblocks.io");
24
25
  }
25
26
  estimateWithdrawFee(crypto, address, amountCrypto) {
26
27
  return __awaiter(this, void 0, void 0, function* () {
27
- let estimate = yield this.fireblocks.estimateFeeForTransaction({
28
- assetId: crypto,
29
- source: {
30
- type: fireblocks_sdk_1.PeerType.VAULT_ACCOUNT,
31
- id: "2",
32
- },
33
- destination: {
34
- type: fireblocks_sdk_1.PeerType.ONE_TIME_ADDRESS,
35
- oneTimeAddress: {
36
- address,
28
+ let fee;
29
+ const cachedResponse = cache.get(`estimateWithdrawFee(${crypto}, ${address}, ${amountCrypto})`);
30
+ if (cachedResponse) {
31
+ fee = cachedResponse;
32
+ }
33
+ else {
34
+ let estimate = yield this.fireblocks.estimateFeeForTransaction({
35
+ assetId: crypto,
36
+ source: {
37
+ type: fireblocks_sdk_1.PeerType.VAULT_ACCOUNT,
38
+ id: "2",
37
39
  },
38
- },
39
- amount: amountCrypto,
40
- operation: fireblocks_sdk_1.TransactionOperation.TRANSFER,
41
- });
42
- return estimate.medium.networkFee;
40
+ destination: {
41
+ type: fireblocks_sdk_1.PeerType.ONE_TIME_ADDRESS,
42
+ oneTimeAddress: {
43
+ address,
44
+ },
45
+ },
46
+ amount: amountCrypto,
47
+ operation: fireblocks_sdk_1.TransactionOperation.TRANSFER,
48
+ });
49
+ let fee = estimate.medium.networkFee;
50
+ cache.set(`estimateWithdrawFee(${crypto}, ${address}, ${amountCrypto})`, fee);
51
+ }
52
+ return fee;
43
53
  });
44
54
  }
45
55
  withdrawFromExchange(crypto, address, amountCrypto) {
@@ -96,7 +106,7 @@ class FireblocksClient {
96
106
  getTotalVaultUSDBalance(vaultId) {
97
107
  return __awaiter(this, void 0, void 0, function* () {
98
108
  let balance = 0;
99
- const cachedResponse = cache.get(`this.fireblocks.getVaultAccountById(${vaultId})`);
109
+ const cachedResponse = cache.get(`getTotalVaultUSDBalance(${vaultId})`);
100
110
  if (cachedResponse) {
101
111
  balance = cachedResponse;
102
112
  }
@@ -117,33 +127,39 @@ class FireblocksClient {
117
127
  }
118
128
  }
119
129
  }
120
- cache.set(`this.fireblocks.getVaultAccountById(${vaultId})`, balance);
130
+ cache.set(`getTotalVaultUSDBalance(${vaultId})`, balance);
121
131
  }
122
- console.log("Balance is ", balance);
123
132
  return balance;
124
133
  });
125
134
  }
126
135
  getTotalExchangesUSDBalance() {
127
136
  return __awaiter(this, void 0, void 0, function* () {
128
- let exchanges = yield this.fireblocks.getExchangeAccounts();
129
137
  let balance = 0;
130
- exchanges.forEach((exchange) => {
131
- exchange.assets.forEach((asset) => {
132
- if ([
133
- common_1.Crypto.USDC,
134
- common_1.Crypto.USDCPolygon,
135
- common_1.Crypto.USDCPolygonBridged,
136
- common_1.Crypto.USDCSolana,
137
- common_1.Crypto.USDTEthereum,
138
- "USDT",
139
- "USD",
140
- common_1.Crypto.USDTPolygon,
141
- common_1.Crypto.USDTTron,
142
- ].includes(asset.id)) {
143
- balance += Number(asset.available);
144
- }
138
+ const cachedResponse = cache.get(`getTotalExchangesUSDBalance()`);
139
+ if (cachedResponse) {
140
+ balance = cachedResponse;
141
+ }
142
+ else {
143
+ let exchanges = yield this.fireblocks.getExchangeAccounts();
144
+ exchanges.forEach((exchange) => {
145
+ exchange.assets.forEach((asset) => {
146
+ if ([
147
+ common_1.Crypto.USDC,
148
+ common_1.Crypto.USDCPolygon,
149
+ common_1.Crypto.USDCPolygonBridged,
150
+ common_1.Crypto.USDCSolana,
151
+ common_1.Crypto.USDTEthereum,
152
+ "USDT",
153
+ "USD",
154
+ common_1.Crypto.USDTPolygon,
155
+ common_1.Crypto.USDTTron,
156
+ ].includes(asset.id)) {
157
+ balance += Number(asset.available);
158
+ }
159
+ });
145
160
  });
146
- });
161
+ cache.set(`getTotalExchangesUSDBalance()`, balance);
162
+ }
147
163
  return balance;
148
164
  });
149
165
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1301",
3
+ "version": "1.0.1303",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",