@riocrypto/common 1.0.475 → 1.0.479

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.
@@ -34,4 +34,11 @@ export declare class CCXTClient {
34
34
  private getOptimalExchange;
35
35
  private round;
36
36
  private getExchange;
37
+ getSellQuote(amount: number, crypto: Crypto, fiat: Fiat): Promise<{
38
+ price: number;
39
+ amountCrypto: number;
40
+ amountFiat: number;
41
+ crypto: Crypto;
42
+ fiat: Fiat;
43
+ }>;
37
44
  }
@@ -154,5 +154,34 @@ class CCXTClient {
154
154
  return exchange;
155
155
  });
156
156
  }
157
+ getSellQuote(amount, crypto, fiat) {
158
+ return __awaiter(this, void 0, void 0, function* () {
159
+ if (this.env === "production") {
160
+ const exchange = yield this.getOptimalExchange(crypto);
161
+ if (!exchange)
162
+ throw new Error("Unable to get optimal exchange");
163
+ exchange.options["fetchMarketsMethod"] = "fetch_markets_from_api";
164
+ let ticker = yield exchange.fetchTicker(`${crypto}/${fiat}`);
165
+ if (!ticker.vwap)
166
+ throw new Error("Unable to get ticker vwap");
167
+ return {
168
+ price: ticker.vwap,
169
+ amountCrypto: amount,
170
+ amountFiat: amount * ticker.vwap,
171
+ crypto,
172
+ fiat,
173
+ };
174
+ }
175
+ else {
176
+ return {
177
+ price: 1,
178
+ amountCrypto: 100,
179
+ amountFiat: 100,
180
+ crypto,
181
+ fiat,
182
+ };
183
+ }
184
+ });
185
+ }
157
186
  }
158
187
  exports.CCXTClient = CCXTClient;
@@ -0,0 +1,10 @@
1
+ import { Crypto } from "../types/crypto";
2
+ import { FireblocksSDK } from "fireblocks-sdk";
3
+ declare class FireblocksClient {
4
+ fireblocks: FireblocksSDK;
5
+ constructor(privateKey: string, apiKey: string);
6
+ estimateWithdrawFromExchangeFee(crypto: Crypto, address: string, amountCrypto: number): Promise<string | undefined>;
7
+ estimateWithdrawFromVaultFee(crypto: Crypto, address: string, amountCrypto: number): Promise<string | undefined>;
8
+ }
9
+ export declare const fireblocksClient: FireblocksClient;
10
+ export {};
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.fireblocksClient = void 0;
13
+ const fireblocks_sdk_1 = require("fireblocks-sdk");
14
+ class FireblocksClient {
15
+ constructor(privateKey, apiKey) {
16
+ this.fireblocks = new fireblocks_sdk_1.FireblocksSDK(privateKey, apiKey, "https://api.fireblocks.io");
17
+ }
18
+ estimateWithdrawFromExchangeFee(crypto, address, amountCrypto) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ let estimate = yield this.fireblocks.estimateFeeForTransaction({
21
+ assetId: crypto,
22
+ source: {
23
+ type: fireblocks_sdk_1.PeerType.VAULT_ACCOUNT,
24
+ id: "0",
25
+ },
26
+ destination: {
27
+ type: fireblocks_sdk_1.PeerType.ONE_TIME_ADDRESS,
28
+ oneTimeAddress: {
29
+ address,
30
+ },
31
+ },
32
+ amount: amountCrypto,
33
+ operation: fireblocks_sdk_1.TransactionOperation.TRANSFER,
34
+ });
35
+ return estimate.medium.networkFee;
36
+ });
37
+ }
38
+ estimateWithdrawFromVaultFee(crypto, address, amountCrypto) {
39
+ return __awaiter(this, void 0, void 0, function* () {
40
+ let estimate = yield this.fireblocks.estimateFeeForTransaction({
41
+ assetId: crypto,
42
+ source: {
43
+ type: fireblocks_sdk_1.PeerType.VAULT_ACCOUNT,
44
+ id: "0",
45
+ },
46
+ destination: {
47
+ type: fireblocks_sdk_1.PeerType.ONE_TIME_ADDRESS,
48
+ oneTimeAddress: {
49
+ address,
50
+ },
51
+ },
52
+ amount: amountCrypto,
53
+ operation: fireblocks_sdk_1.TransactionOperation.TRANSFER,
54
+ });
55
+ return estimate.medium.networkFee;
56
+ });
57
+ }
58
+ }
59
+ exports.fireblocksClient = new FireblocksClient(process.env.FIREBLOCKS_PRIVATE_KEY, process.env.FIREBLOCKS_API_KEY);
@@ -0,0 +1,6 @@
1
+ declare class KapstarClient {
2
+ constructor();
3
+ getBRLExchangeRateUSD(): Promise<number>;
4
+ }
5
+ export declare const kapstarClient: KapstarClient;
6
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.kapstarClient = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ class KapstarClient {
18
+ constructor() { }
19
+ getBRLExchangeRateUSD() {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ const kapstarResponse = yield axios_1.default.get(`https://api.ecsa.finance/quotation-service/v1/quotation/last`);
22
+ return 1 / kapstarResponse.data;
23
+ });
24
+ }
25
+ }
26
+ exports.kapstarClient = new KapstarClient();
@@ -0,0 +1,8 @@
1
+ import { CustomError } from "./custom-error";
2
+ export declare class InvalidOrderSizeError extends CustomError {
3
+ statusCode: number;
4
+ constructor();
5
+ serializeErrors(): {
6
+ message: string;
7
+ }[];
8
+ }
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InvalidOrderSizeError = void 0;
4
+ const custom_error_1 = require("./custom-error");
5
+ class InvalidOrderSizeError extends custom_error_1.CustomError {
6
+ constructor() {
7
+ super("Invalid order size");
8
+ this.statusCode = 400;
9
+ Object.setPrototypeOf(this, InvalidOrderSizeError.prototype);
10
+ }
11
+ serializeErrors() {
12
+ return [{ message: "Invalid order size" }];
13
+ }
14
+ }
15
+ exports.InvalidOrderSizeError = InvalidOrderSizeError;
package/build/index.d.ts CHANGED
@@ -25,6 +25,7 @@ export * from "./errors/not-broker-error";
25
25
  export * from "./errors/rio-settings-not-found-error";
26
26
  export * from "./errors/address-check-failed-error";
27
27
  export * from "./errors/partner-already-exists-error";
28
+ export * from "./errors/invalid-order-size-error";
28
29
  export * from "./middlewares/error-handler";
29
30
  export * from "./middlewares/validate-request";
30
31
  export * from "./middlewares/current-auth";
@@ -169,4 +170,6 @@ export * from "./clients/fixer-client";
169
170
  export * from "./clients/kushki-client";
170
171
  export * from "./clients/slack-client";
171
172
  export * from "./clients/gueno-client";
173
+ export * from "./clients/fireblocks-client";
174
+ export * from "./clients/kapstar-client";
172
175
  export * from "./helpers/get-user-helper";
package/build/index.js CHANGED
@@ -41,6 +41,7 @@ __exportStar(require("./errors/not-broker-error"), exports);
41
41
  __exportStar(require("./errors/rio-settings-not-found-error"), exports);
42
42
  __exportStar(require("./errors/address-check-failed-error"), exports);
43
43
  __exportStar(require("./errors/partner-already-exists-error"), exports);
44
+ __exportStar(require("./errors/invalid-order-size-error"), exports);
44
45
  __exportStar(require("./middlewares/error-handler"), exports);
45
46
  __exportStar(require("./middlewares/validate-request"), exports);
46
47
  __exportStar(require("./middlewares/current-auth"), exports);
@@ -185,4 +186,6 @@ __exportStar(require("./clients/fixer-client"), exports);
185
186
  __exportStar(require("./clients/kushki-client"), exports);
186
187
  __exportStar(require("./clients/slack-client"), exports);
187
188
  __exportStar(require("./clients/gueno-client"), exports);
189
+ __exportStar(require("./clients/fireblocks-client"), exports);
190
+ __exportStar(require("./clients/kapstar-client"), exports);
188
191
  __exportStar(require("./helpers/get-user-helper"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common",
3
- "version": "1.0.475",
3
+ "version": "1.0.479",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -26,6 +26,7 @@
26
26
  "ccxt": "^3.0.30",
27
27
  "express": "^4.18.1",
28
28
  "express-validator": "^6.14.2",
29
+ "fireblocks-sdk": "^4.0.0",
29
30
  "jsonwebtoken": "^8.5.1",
30
31
  "mongoose": "^7.0.2",
31
32
  "node-nats-streaming": "^0.3.2"