@riocrypto/common-server 1.0.1302 → 1.0.1304

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,40 @@ 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 = cache2.get(`estimateWithdrawFee(${crypto}, ${address}, ${amountCrypto})`);
30
+ console.log(`estimateWithdrawFee(${crypto}, ${address}, ${amountCrypto})`, cachedResponse);
31
+ if (cachedResponse) {
32
+ fee = cachedResponse;
33
+ }
34
+ else {
35
+ let estimate = yield this.fireblocks.estimateFeeForTransaction({
36
+ assetId: crypto,
37
+ source: {
38
+ type: fireblocks_sdk_1.PeerType.VAULT_ACCOUNT,
39
+ id: "2",
37
40
  },
38
- },
39
- amount: amountCrypto,
40
- operation: fireblocks_sdk_1.TransactionOperation.TRANSFER,
41
- });
42
- return estimate.medium.networkFee;
41
+ destination: {
42
+ type: fireblocks_sdk_1.PeerType.ONE_TIME_ADDRESS,
43
+ oneTimeAddress: {
44
+ address,
45
+ },
46
+ },
47
+ amount: amountCrypto,
48
+ operation: fireblocks_sdk_1.TransactionOperation.TRANSFER,
49
+ });
50
+ let fee = estimate.medium.networkFee;
51
+ console.log("fee", fee);
52
+ cache.set(`estimateWithdrawFee(${crypto}, ${address}, ${amountCrypto})`, fee);
53
+ }
54
+ return fee;
43
55
  });
44
56
  }
45
57
  withdrawFromExchange(crypto, address, amountCrypto) {
@@ -97,6 +109,7 @@ class FireblocksClient {
97
109
  return __awaiter(this, void 0, void 0, function* () {
98
110
  let balance = 0;
99
111
  const cachedResponse = cache.get(`getTotalVaultUSDBalance(${vaultId})`);
112
+ console.log(`getTotalVaultUSDBalance(${vaultId})`, cachedResponse);
100
113
  if (cachedResponse) {
101
114
  balance = cachedResponse;
102
115
  }
@@ -117,6 +130,7 @@ class FireblocksClient {
117
130
  }
118
131
  }
119
132
  }
133
+ console.log("balance", balance);
120
134
  cache.set(`getTotalVaultUSDBalance(${vaultId})`, balance);
121
135
  }
122
136
  return balance;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.1302",
3
+ "version": "1.0.1304",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",