@riocrypto/common-server 1.0.998 → 1.0.1003

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.
@@ -1,26 +1,7 @@
1
- import { CCXTLiquidityProvider, Fiat, Side, Crypto } from "@riocrypto/common";
1
+ import { Fiat, Side, Crypto } from "@riocrypto/common";
2
2
  declare class CCXTClient {
3
3
  private env;
4
4
  constructor(env: "production" | "development");
5
- createBuyOrder(amount: number, crypto: Crypto, fiat: Fiat, ccxtLiquidityProvider: CCXTLiquidityProvider): Promise<{
6
- ccxtId: any;
7
- price: any;
8
- amountCrypto: any;
9
- amountFiat: number;
10
- crypto: Crypto;
11
- fiat: Fiat;
12
- side: Side;
13
- }>;
14
- createSellOrder(amount: number, crypto: Crypto, fiat: Fiat, ccxtLiquidityProvider: CCXTLiquidityProvider): Promise<{
15
- ccxtId: any;
16
- price: any;
17
- amountCrypto: number;
18
- amountFiat: number;
19
- crypto: Crypto;
20
- fiat: Fiat;
21
- side: Side;
22
- }>;
23
- transfer(side: Side, amount: number, crypto: Crypto, cryptoAddress: string, ccxtLiquidityProvider: CCXTLiquidityProvider): Promise<void>;
24
5
  getBuyQuote(crypto: Crypto, fiat: Fiat, amountFiat?: number, amountCrypto?: number): Promise<{
25
6
  price: number;
26
7
  amountCrypto: number | undefined;
@@ -31,7 +12,6 @@ declare class CCXTClient {
31
12
  }>;
32
13
  private getOptimalExchange;
33
14
  private round;
34
- private getExchange;
35
15
  getSellQuote(crypto: Crypto, fiat: Fiat, amountFiat?: number, amountCrypto?: number): Promise<{
36
16
  price: number;
37
17
  amountCrypto: number;
@@ -20,75 +20,6 @@ class CCXTClient {
20
20
  constructor(env) {
21
21
  this.env = env;
22
22
  }
23
- createBuyOrder(amount, crypto, fiat, ccxtLiquidityProvider) {
24
- return __awaiter(this, void 0, void 0, function* () {
25
- if (this.env === "production") {
26
- const exchange = yield this.getExchange(ccxtLiquidityProvider);
27
- const order = yield exchange.createOrder(`${crypto}/${fiat}`, "market", "buy", amount);
28
- return {
29
- ccxtId: order.id,
30
- price: order.price,
31
- amountCrypto: order.amount,
32
- amountFiat: amount,
33
- crypto,
34
- fiat,
35
- side: common_1.Side.Buy,
36
- };
37
- }
38
- else {
39
- return {
40
- ccxtId: "1",
41
- price: 1,
42
- amountCrypto: amount,
43
- amountFiat: amount,
44
- crypto,
45
- fiat,
46
- side: common_1.Side.Buy,
47
- };
48
- }
49
- });
50
- }
51
- createSellOrder(amount, crypto, fiat, ccxtLiquidityProvider) {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- if (this.env === "production") {
54
- const exchange = yield this.getExchange(ccxtLiquidityProvider);
55
- const order = yield exchange.createOrder(`${crypto}/${fiat}`, "market", "sell", amount);
56
- return {
57
- ccxtId: order.id,
58
- price: order.price,
59
- amountCrypto: amount,
60
- amountFiat: order.amount * order.price,
61
- crypto,
62
- fiat,
63
- side: common_1.Side.Sell,
64
- };
65
- }
66
- else {
67
- return {
68
- ccxtId: "1",
69
- price: 1,
70
- amountCrypto: amount,
71
- amountFiat: amount,
72
- crypto,
73
- fiat,
74
- side: common_1.Side.Sell,
75
- };
76
- }
77
- });
78
- }
79
- transfer(side, amount, crypto, cryptoAddress, ccxtLiquidityProvider) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- if (this.env === "production") {
82
- const exchange = yield this.getExchange(ccxtLiquidityProvider);
83
- const params = ccxtLiquidityProvider === common_1.CCXTLiquidityProvider.Kraken
84
- ? {
85
- key: "Metamask",
86
- }
87
- : undefined;
88
- yield exchange.withdraw(crypto, this.round(amount, 8), cryptoAddress, undefined, params);
89
- }
90
- });
91
- }
92
23
  getBuyQuote(crypto, fiat, amountFiat, amountCrypto) {
93
24
  return __awaiter(this, void 0, void 0, function* () {
94
25
  if (this.env === "production") {
@@ -171,24 +102,6 @@ class CCXTClient {
171
102
  return Math.round(value);
172
103
  }
173
104
  }
174
- getExchange(ccxtLiquidityProvider) {
175
- return __awaiter(this, void 0, void 0, function* () {
176
- const SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue(`${ccxtLiquidityProvider.toLocaleUpperCase()}_SECRET`);
177
- if (!SECRET) {
178
- throw new Error("Unable to get SECRET");
179
- }
180
- const API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue(`${ccxtLiquidityProvider.toLocaleUpperCase()}_API_KEY`);
181
- if (!API_KEY) {
182
- throw new Error("Unable to get API_KEY");
183
- }
184
- // @ts-ignore
185
- const exchangeClass = ccxt_1.default[ccxtLiquidityProvider], exchange = new exchangeClass({
186
- apiKey: API_KEY,
187
- secret: SECRET,
188
- });
189
- return exchange;
190
- });
191
- }
192
105
  getSellQuote(crypto, fiat, amountFiat, amountCrypto) {
193
106
  return __awaiter(this, void 0, void 0, function* () {
194
107
  if (amountFiat && amountCrypto) {
@@ -0,0 +1,9 @@
1
+ import { RioEnv } from "@riocrypto/common";
2
+ declare class GoogleSheetsAPIClient {
3
+ private env;
4
+ googleAuth: any;
5
+ constructor(env: RioEnv);
6
+ getSheetValues(sheetId: string, range: string): Promise<any[][] | null | undefined>;
7
+ }
8
+ export declare const googleSheetsAPIClient: GoogleSheetsAPIClient;
9
+ export {};
@@ -0,0 +1,34 @@
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.googleSheetsAPIClient = void 0;
13
+ const googleapis_1 = require("googleapis");
14
+ class GoogleSheetsAPIClient {
15
+ constructor(env) {
16
+ this.env = env;
17
+ this.googleAuth = new googleapis_1.google.auth.GoogleAuth({
18
+ keyFile: "/etc/secrets/google-sheets/google-sheets-service-account-key.json",
19
+ scopes: ["https://www.googleapis.com/auth/spreadsheets"],
20
+ });
21
+ }
22
+ getSheetValues(sheetId, range) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const authClientObject = yield this.googleAuth.getClient();
25
+ const sheets = googleapis_1.google.sheets({ version: "v4", auth: authClientObject });
26
+ const response = yield sheets.spreadsheets.values.get({
27
+ spreadsheetId: sheetId,
28
+ range,
29
+ });
30
+ return response.data.values;
31
+ });
32
+ }
33
+ }
34
+ exports.googleSheetsAPIClient = new GoogleSheetsAPIClient(process.env.RIO_ENV || process.env.NEXT_PUBLIC_RIO_ENV);
package/build/index.d.ts CHANGED
@@ -52,6 +52,7 @@ export * from "./clients/gcloud-storage-client";
52
52
  export * from "./clients/currency-api-client";
53
53
  export * from "./clients/aiprise-client";
54
54
  export * from "./clients/bridge-client";
55
+ export * from "./clients/google-sheets-api-client";
55
56
  export * from "./helpers/get-user-helper";
56
57
  export * from "./helpers/get-platform-and-partner-fees";
57
58
  export * from "./helpers/get-processor-fees";
package/build/index.js CHANGED
@@ -68,6 +68,7 @@ __exportStar(require("./clients/gcloud-storage-client"), exports);
68
68
  __exportStar(require("./clients/currency-api-client"), exports);
69
69
  __exportStar(require("./clients/aiprise-client"), exports);
70
70
  __exportStar(require("./clients/bridge-client"), exports);
71
+ __exportStar(require("./clients/google-sheets-api-client"), exports);
71
72
  __exportStar(require("./helpers/get-user-helper"), exports);
72
73
  __exportStar(require("./helpers/get-platform-and-partner-fees"), exports);
73
74
  __exportStar(require("./helpers/get-processor-fees"), exports);
@@ -9,7 +9,6 @@ const buildOrder = (mongoose) => {
9
9
  const orderSchema = new mongoose.Schema({
10
10
  quoteId: {
11
11
  type: String,
12
- required: true,
13
12
  },
14
13
  userId: {
15
14
  type: String,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riocrypto/common-server",
3
- "version": "1.0.998",
3
+ "version": "1.0.1003",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -24,13 +24,15 @@
24
24
  "@aws-sdk/client-s3": "^3.297.0",
25
25
  "@everapi/currencyapi-js": "^1.0.6",
26
26
  "@google-cloud/storage": "^6.9.5",
27
- "@riocrypto/common": "^1.0.860",
27
+ "@riocrypto/common": "^1.0.866",
28
28
  "@types/express": "^4.17.13",
29
29
  "axios": "^0.27.2",
30
30
  "ccxt": "^3.0.30",
31
31
  "express": "^4.18.1",
32
32
  "express-validator": "^6.14.2",
33
33
  "fireblocks-sdk": "^4.0.0",
34
+ "google-auth-library": "^9.0.0",
35
+ "googleapis": "^123.0.0",
34
36
  "jsonwebtoken": "^8.5.1",
35
37
  "mongoose": "^7.0.2",
36
38
  "node-cache": "^5.1.2",