@riocrypto/common-server 1.0.1316 → 1.0.1318
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/cosigner-client.d.ts +1 -1
- package/build/clients/cosigner-client.js +3 -3
- package/build/clients/polygon-client.d.ts +8 -0
- package/build/clients/polygon-client.js +38 -0
- package/build/helpers/get-exchange-rates.js +3 -3
- package/build/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/package.json +2 -2
|
@@ -5,5 +5,5 @@ declare class CosignerClient {
|
|
|
5
5
|
sendRequest(title: string, description: string, minApprovers: number, notificationUrl: string, approverGroupId: string, metadata?: Object): Promise<void>;
|
|
6
6
|
decryptNotification(encryptedData: string, iv: string): Promise<string>;
|
|
7
7
|
}
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const buildCosignerClient: () => Promise<CosignerClient>;
|
|
9
9
|
export {};
|
|
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.buildCosignerClient = void 0;
|
|
16
16
|
const secret_manager_client_1 = require("./secret-manager-client");
|
|
17
17
|
const axios_1 = __importDefault(require("axios"));
|
|
18
18
|
const crypto_1 = __importDefault(require("crypto"));
|
|
@@ -47,7 +47,7 @@ class CosignerClient {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
const
|
|
50
|
+
const buildCosignerClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
51
51
|
const COSIGNER_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("COSIGNER_API_KEY");
|
|
52
52
|
if (!COSIGNER_API_KEY) {
|
|
53
53
|
throw new Error("Unable to get COSIGNER_API_KEY");
|
|
@@ -59,4 +59,4 @@ const builCosignerClient = () => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
59
59
|
// Create GuenoClient instance and return
|
|
60
60
|
return new CosignerClient(COSIGNER_API_KEY, COSIGNER_WEBHOOK_SECRET);
|
|
61
61
|
});
|
|
62
|
-
exports.
|
|
62
|
+
exports.buildCosignerClient = buildCosignerClient;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Fiat } from "@riocrypto/common";
|
|
2
|
+
declare class PolygonClient {
|
|
3
|
+
private apiKey;
|
|
4
|
+
constructor(apiKey: string);
|
|
5
|
+
getExchangeRate(from: Fiat, to: Fiat): Promise<number>;
|
|
6
|
+
}
|
|
7
|
+
export declare const buildPolygonClient: () => Promise<PolygonClient>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,38 @@
|
|
|
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.buildPolygonClient = void 0;
|
|
16
|
+
const common_1 = require("@riocrypto/common");
|
|
17
|
+
const axios_1 = __importDefault(require("axios"));
|
|
18
|
+
const secret_manager_client_1 = require("./secret-manager-client");
|
|
19
|
+
class PolygonClient {
|
|
20
|
+
constructor(apiKey) {
|
|
21
|
+
this.apiKey = apiKey;
|
|
22
|
+
}
|
|
23
|
+
getExchangeRate(from, to) {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const { data } = yield axios_1.default.get(`https://api.polygon.io/v1/last_quote/currencies/${from}/${to}?apiKey=${this.apiKey}`);
|
|
26
|
+
return data.last.bid;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const buildPolygonClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
const POLYGON_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("POLYGON_API_KEY");
|
|
32
|
+
if (!POLYGON_API_KEY) {
|
|
33
|
+
throw new common_1.SecretManagerError();
|
|
34
|
+
}
|
|
35
|
+
// Create FixerClient instance and return
|
|
36
|
+
return new PolygonClient(POLYGON_API_KEY);
|
|
37
|
+
});
|
|
38
|
+
exports.buildPolygonClient = buildPolygonClient;
|
|
@@ -11,14 +11,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getExchangeRates = void 0;
|
|
13
13
|
const common_1 = require("@riocrypto/common");
|
|
14
|
-
const currency_api_client_1 = require("../clients/currency-api-client");
|
|
15
14
|
const kapstar_client_1 = require("../clients/kapstar-client");
|
|
15
|
+
const polygon_client_1 = require("../clients/polygon-client");
|
|
16
16
|
const getExchangeRates = (fiat) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const
|
|
17
|
+
const polygonClient = yield (0, polygon_client_1.buildPolygonClient)();
|
|
18
18
|
const kapstarClient = yield (0, kapstar_client_1.buildKapstarClient)();
|
|
19
19
|
const conversionRateToUSD = fiat === common_1.Fiat.BRL
|
|
20
20
|
? yield kapstarClient.getBRLExchangeRateUSD()
|
|
21
|
-
: yield
|
|
21
|
+
: (yield polygonClient.getExchangeRate(fiat, common_1.Fiat.USD)) * (1 + 2 / 10000);
|
|
22
22
|
let conversionRateFromUSD = 1 / conversionRateToUSD;
|
|
23
23
|
let conversionRateToUSDWithMarkups = conversionRateToUSD;
|
|
24
24
|
let conversionRateFromUSDWithMarkups = conversionRateFromUSD;
|
package/build/index.d.ts
CHANGED
|
@@ -60,6 +60,7 @@ export * from "./clients/cluster-client";
|
|
|
60
60
|
export * from "./clients/cosigner-client";
|
|
61
61
|
export * from "./clients/bitso-client";
|
|
62
62
|
export * from "./clients/circle-client";
|
|
63
|
+
export * from "./clients/polygon-client";
|
|
63
64
|
export * from "./helpers/get-user-helper";
|
|
64
65
|
export * from "./helpers/get-processor-fees";
|
|
65
66
|
export * from "./helpers/get-network-fees";
|
package/build/index.js
CHANGED
|
@@ -76,6 +76,7 @@ __exportStar(require("./clients/cluster-client"), exports);
|
|
|
76
76
|
__exportStar(require("./clients/cosigner-client"), exports);
|
|
77
77
|
__exportStar(require("./clients/bitso-client"), exports);
|
|
78
78
|
__exportStar(require("./clients/circle-client"), exports);
|
|
79
|
+
__exportStar(require("./clients/polygon-client"), exports);
|
|
79
80
|
__exportStar(require("./helpers/get-user-helper"), exports);
|
|
80
81
|
__exportStar(require("./helpers/get-processor-fees"), exports);
|
|
81
82
|
__exportStar(require("./helpers/get-network-fees"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riocrypto/common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1318",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@everapi/currencyapi-js": "^1.0.6",
|
|
28
28
|
"@google-cloud/storage": "^6.9.5",
|
|
29
29
|
"@google-cloud/vision": "^4.0.2",
|
|
30
|
-
"@riocrypto/common": "^1.0.
|
|
30
|
+
"@riocrypto/common": "^1.0.1182",
|
|
31
31
|
"@types/express": "^4.17.13",
|
|
32
32
|
"axios": "^0.27.2",
|
|
33
33
|
"ccxt": "^3.0.30",
|