@riocrypto/common 1.0.474 → 1.0.478
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.
- package/build/clients/ccxt-client.d.ts +7 -0
- package/build/clients/ccxt-client.js +29 -0
- package/build/clients/fireblocks-client.d.ts +10 -0
- package/build/clients/fireblocks-client.js +59 -0
- package/build/clients/kapstar-client.d.ts +6 -0
- package/build/clients/kapstar-client.js +26 -0
- package/build/index.d.ts +2 -0
- package/build/index.js +2 -0
- package/build/middlewares/authorize.js +0 -4
- package/package.json +2 -1
|
@@ -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,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();
|
package/build/index.d.ts
CHANGED
|
@@ -169,4 +169,6 @@ export * from "./clients/fixer-client";
|
|
|
169
169
|
export * from "./clients/kushki-client";
|
|
170
170
|
export * from "./clients/slack-client";
|
|
171
171
|
export * from "./clients/gueno-client";
|
|
172
|
+
export * from "./clients/fireblocks-client";
|
|
173
|
+
export * from "./clients/kapstar-client";
|
|
172
174
|
export * from "./helpers/get-user-helper";
|
package/build/index.js
CHANGED
|
@@ -185,4 +185,6 @@ __exportStar(require("./clients/fixer-client"), exports);
|
|
|
185
185
|
__exportStar(require("./clients/kushki-client"), exports);
|
|
186
186
|
__exportStar(require("./clients/slack-client"), exports);
|
|
187
187
|
__exportStar(require("./clients/gueno-client"), exports);
|
|
188
|
+
__exportStar(require("./clients/fireblocks-client"), exports);
|
|
189
|
+
__exportStar(require("./clients/kapstar-client"), exports);
|
|
188
190
|
__exportStar(require("./helpers/get-user-helper"), exports);
|
|
@@ -161,10 +161,6 @@ const authorize = (req, res, next, mongoose, authorizationTypes) => __awaiter(vo
|
|
|
161
161
|
req.user = user;
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
console.log("req.currentAuth", req.currentAuth);
|
|
165
|
-
console.log("req.currentAdminAuth", req.currentAdminAuth);
|
|
166
|
-
console.log("req.user", req.user);
|
|
167
|
-
console.log("req.partner", req.partner);
|
|
168
164
|
if (
|
|
169
165
|
// if no auth
|
|
170
166
|
(!req.currentAdminAuth && !req.currentAuth && !req.user && !req.partner) ||
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.478",
|
|
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"
|