@riocrypto/common-server 1.0.1302 → 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) {
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.1303",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",