@riocrypto/common-server 1.0.1671 → 1.0.1676
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/bridge-client.js +0 -1
- package/build/clients/circle-client.js +0 -1
- package/build/clients/cloud-vision-api-client.d.ts +0 -9
- package/build/clients/cloud-vision-api-client.js +54 -58
- package/build/clients/cluster-client.js +2 -2
- package/build/clients/coincover-client.js +0 -1
- package/build/clients/cosigner-client.js +0 -1
- package/build/index.d.ts +0 -17
- package/build/index.js +0 -17
- package/package.json +3 -9
- package/build/clients/aiprise-client.d.ts +0 -13
- package/build/clients/aiprise-client.js +0 -109
- package/build/clients/bitstamp-client.d.ts +0 -16
- package/build/clients/bitstamp-client.js +0 -97
- package/build/clients/brex-client.d.ts +0 -17
- package/build/clients/brex-client.js +0 -92
- package/build/clients/ccxt-client.d.ts +0 -25
- package/build/clients/ccxt-client.js +0 -164
- package/build/clients/coinbase-client.d.ts +0 -13
- package/build/clients/coinbase-client.js +0 -119
- package/build/clients/etherscan-client.d.ts +0 -7
- package/build/clients/etherscan-client.js +0 -40
- package/build/clients/fogbender-client.d.ts +0 -7
- package/build/clients/fogbender-client.js +0 -47
- package/build/clients/google-sheets-api-client.d.ts +0 -10
- package/build/clients/google-sheets-api-client.js +0 -75
- package/build/clients/gueno-client.d.ts +0 -11
- package/build/clients/gueno-client.js +0 -58
- package/build/clients/invopop-client.d.ts +0 -17
- package/build/clients/invopop-client.js +0 -225
- package/build/clients/kapstar-client.d.ts +0 -13
- package/build/clients/kapstar-client.js +0 -71
- package/build/clients/killb-client.d.ts +0 -13
- package/build/clients/killb-client.js +0 -76
- package/build/clients/polygon-client.d.ts +0 -11
- package/build/clients/polygon-client.js +0 -38
- package/build/helpers/get-polygon-exchange-rates.d.ts +0 -8
- package/build/helpers/get-polygon-exchange-rates.js +0 -34
- package/build/helpers/sanitize-chained-order-doc.d.ts +0 -27
- package/build/helpers/sanitize-chained-order-doc.js +0 -10
- package/build/helpers/sanitize-order-doc.d.ts +0 -27
- package/build/helpers/sanitize-order-doc.js +0 -20
- package/build/helpers/sanitize-quote-doc.d.ts +0 -27
- package/build/helpers/sanitize-quote-doc.js +0 -17
|
@@ -1,92 +0,0 @@
|
|
|
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.buildBrexClient = void 0;
|
|
16
|
-
const secret_manager_client_1 = require("./secret-manager-client");
|
|
17
|
-
const axios_1 = __importDefault(require("axios"));
|
|
18
|
-
const common_1 = require("@riocrypto/common");
|
|
19
|
-
class BrexClient {
|
|
20
|
-
constructor(apiKey) {
|
|
21
|
-
this.apiKey = apiKey;
|
|
22
|
-
if ([common_1.RioEnv.Development, common_1.RioEnv.Production, common_1.RioEnv.Staging].includes(process.env.RIO_ENV)) {
|
|
23
|
-
this.baseUrl = "https://platform.brexapis.com";
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
throw new common_1.GenericInputError("Brex client cannot be initialized in this environment");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
getTransfer(brexTransferId) {
|
|
30
|
-
var _a;
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const { data } = yield axios_1.default.get(`${this.baseUrl}/v1/transfers/${brexTransferId}`, {
|
|
33
|
-
headers: {
|
|
34
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
return {
|
|
38
|
-
processDate: new Date(data.process_date),
|
|
39
|
-
status: data.status,
|
|
40
|
-
amount: Math.abs(data.amount.amount),
|
|
41
|
-
paymentType: data.payment_type,
|
|
42
|
-
accountNumber: (_a = data.counterparty) === null || _a === void 0 ? void 0 : _a.account_number,
|
|
43
|
-
};
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
createTransferToCoinbase(amount, idempotencyKey) {
|
|
47
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
-
const COINBASE_PAYMENT_INSTRUMENT_ID_FOR_BREX = yield secret_manager_client_1.secretManagerClient.getSecretValue("COINBASE_PAYMENT_INSTRUMENT_ID_FOR_BREX");
|
|
49
|
-
if (!COINBASE_PAYMENT_INSTRUMENT_ID_FOR_BREX) {
|
|
50
|
-
throw new common_1.SecretManagerError();
|
|
51
|
-
}
|
|
52
|
-
const BREX_CASH_ACCOUNT_ID = yield secret_manager_client_1.secretManagerClient.getSecretValue("BREX_CASH_ACCOUNT_ID");
|
|
53
|
-
if (!BREX_CASH_ACCOUNT_ID) {
|
|
54
|
-
throw new common_1.SecretManagerError();
|
|
55
|
-
}
|
|
56
|
-
const { data } = yield axios_1.default.post(`${this.baseUrl}/v1/transfers`, {
|
|
57
|
-
counterparty: {
|
|
58
|
-
type: "VENDOR",
|
|
59
|
-
payment_instrument_id: COINBASE_PAYMENT_INSTRUMENT_ID_FOR_BREX,
|
|
60
|
-
},
|
|
61
|
-
amount: {
|
|
62
|
-
amount: amount * 100,
|
|
63
|
-
currency: "USD",
|
|
64
|
-
},
|
|
65
|
-
description: "Transfer to Coinbase for liquidity order with ID: " + idempotencyKey,
|
|
66
|
-
external_memo: "Rampa Labs Incorporated",
|
|
67
|
-
originating_account: {
|
|
68
|
-
type: "BREX_CASH",
|
|
69
|
-
id: BREX_CASH_ACCOUNT_ID,
|
|
70
|
-
},
|
|
71
|
-
}, {
|
|
72
|
-
headers: {
|
|
73
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
74
|
-
"Idempotency-Key": idempotencyKey,
|
|
75
|
-
},
|
|
76
|
-
});
|
|
77
|
-
return {
|
|
78
|
-
id: data.id,
|
|
79
|
-
};
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const buildBrexClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
-
// Retrieve secrets asynchronously
|
|
85
|
-
const BREX_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("BREX_API_KEY");
|
|
86
|
-
if (!BREX_API_KEY) {
|
|
87
|
-
throw new common_1.SecretManagerError();
|
|
88
|
-
}
|
|
89
|
-
// Create GuenoClient instance and return
|
|
90
|
-
return new BrexClient(BREX_API_KEY);
|
|
91
|
-
});
|
|
92
|
-
exports.buildBrexClient = buildBrexClient;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { Fiat, Side, Crypto } from "@riocrypto/common";
|
|
2
|
-
declare class CCXTClient {
|
|
3
|
-
private env;
|
|
4
|
-
constructor(env: "production" | "development");
|
|
5
|
-
getBuyQuote(crypto: Crypto, fiat: Fiat, amountFiat?: number, amountCrypto?: number): Promise<{
|
|
6
|
-
price: number;
|
|
7
|
-
amountCrypto: number | undefined;
|
|
8
|
-
amountFiat: number | undefined;
|
|
9
|
-
crypto: Crypto;
|
|
10
|
-
fiat: Fiat;
|
|
11
|
-
side: Side;
|
|
12
|
-
}>;
|
|
13
|
-
private getOptimalExchange;
|
|
14
|
-
private round;
|
|
15
|
-
getSellQuote(crypto: Crypto, fiat: Fiat, amountFiat?: number, amountCrypto?: number): Promise<{
|
|
16
|
-
price: number;
|
|
17
|
-
amountCrypto: number;
|
|
18
|
-
amountFiat: number | undefined;
|
|
19
|
-
crypto: Crypto;
|
|
20
|
-
fiat: Fiat;
|
|
21
|
-
}>;
|
|
22
|
-
getDepositAddress(crypto: Crypto): Promise<string>;
|
|
23
|
-
}
|
|
24
|
-
export declare const ccxtWrapper: CCXTClient;
|
|
25
|
-
export {};
|
|
@@ -1,164 +0,0 @@
|
|
|
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.ccxtWrapper = void 0;
|
|
16
|
-
const common_1 = require("@riocrypto/common");
|
|
17
|
-
const ccxt_1 = __importDefault(require("ccxt"));
|
|
18
|
-
const secret_manager_client_1 = require("./secret-manager-client");
|
|
19
|
-
class CCXTClient {
|
|
20
|
-
constructor(env) {
|
|
21
|
-
this.env = env;
|
|
22
|
-
}
|
|
23
|
-
getBuyQuote(crypto, fiat, amountFiat, amountCrypto) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
if (this.env === "production") {
|
|
26
|
-
const exchange = yield this.getOptimalExchange(crypto);
|
|
27
|
-
if (!exchange)
|
|
28
|
-
throw new Error("Unable to get optimal exchange");
|
|
29
|
-
let ticker = yield exchange.fetchTicker(`${crypto}/${fiat}`);
|
|
30
|
-
if (!ticker.vwap)
|
|
31
|
-
throw new Error("Unable to get ticker vwap");
|
|
32
|
-
const exchangeFee = exchange.id === "bitstamp" ? 0.002 : 0.002;
|
|
33
|
-
if (amountFiat && amountCrypto) {
|
|
34
|
-
throw new Error("Can only specify either amountFiat or amountCrypto");
|
|
35
|
-
}
|
|
36
|
-
if (!amountCrypto && !amountFiat) {
|
|
37
|
-
throw new Error("Must specify either amountFiat or amountCrypto");
|
|
38
|
-
}
|
|
39
|
-
if (amountFiat) {
|
|
40
|
-
return {
|
|
41
|
-
price: ticker.vwap * (1 + exchangeFee),
|
|
42
|
-
amountCrypto: amountFiat / (ticker.vwap * (1 + exchangeFee)),
|
|
43
|
-
amountFiat: amountFiat,
|
|
44
|
-
crypto,
|
|
45
|
-
fiat,
|
|
46
|
-
side: common_1.Side.Buy,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
return {
|
|
51
|
-
price: ticker.vwap * (1 + exchangeFee),
|
|
52
|
-
amountCrypto: amountCrypto,
|
|
53
|
-
amountFiat: amountCrypto * ticker.vwap * (1 + exchangeFee),
|
|
54
|
-
crypto,
|
|
55
|
-
fiat,
|
|
56
|
-
side: common_1.Side.Buy,
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
return {
|
|
62
|
-
price: 0.5,
|
|
63
|
-
amountCrypto: amountFiat,
|
|
64
|
-
amountFiat: amountFiat,
|
|
65
|
-
crypto,
|
|
66
|
-
fiat,
|
|
67
|
-
side: common_1.Side.Buy,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
getOptimalExchange(crypto) {
|
|
73
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
for (let exchangeId of ccxt_1.default.exchanges) {
|
|
75
|
-
if (exchangeId === "bitstamp") {
|
|
76
|
-
const SECRET = yield secret_manager_client_1.secretManagerClient.getSecretValue(`${exchangeId.toLocaleUpperCase()}_SECRET`);
|
|
77
|
-
if (!SECRET) {
|
|
78
|
-
throw new Error("Unable to get SECRET");
|
|
79
|
-
}
|
|
80
|
-
const API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue(`${exchangeId.toLocaleUpperCase()}_API_KEY`);
|
|
81
|
-
if (!API_KEY) {
|
|
82
|
-
throw new Error("Unable to get API_KEY");
|
|
83
|
-
}
|
|
84
|
-
//@ts-ignore
|
|
85
|
-
const exchangeClass = ccxt_1.default[exchangeId], exchange = new exchangeClass({
|
|
86
|
-
apiKey: API_KEY,
|
|
87
|
-
secret: SECRET,
|
|
88
|
-
});
|
|
89
|
-
return exchange;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return null;
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
round(value, precision) {
|
|
96
|
-
if (Number.isInteger(precision)) {
|
|
97
|
-
var shift = Math.pow(10, precision);
|
|
98
|
-
// Limited preventing decimal issue
|
|
99
|
-
return Math.round(value * shift + 0.00000000000001) / shift;
|
|
100
|
-
}
|
|
101
|
-
else {
|
|
102
|
-
return Math.round(value);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
getSellQuote(crypto, fiat, amountFiat, amountCrypto) {
|
|
106
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
107
|
-
if (amountFiat && amountCrypto) {
|
|
108
|
-
throw new Error("Can only specify either amountFiat or amountCrypto");
|
|
109
|
-
}
|
|
110
|
-
if (!amountCrypto && !amountFiat) {
|
|
111
|
-
throw new Error("Must specify either amountFiat or amountCrypto");
|
|
112
|
-
}
|
|
113
|
-
if (this.env === "production") {
|
|
114
|
-
const exchange = yield this.getOptimalExchange(crypto);
|
|
115
|
-
if (!exchange)
|
|
116
|
-
throw new Error("Unable to get optimal exchange");
|
|
117
|
-
exchange.options["fetchMarketsMethod"] = "fetch_markets_from_api";
|
|
118
|
-
let ticker = yield exchange.fetchTicker(`${crypto}/${fiat}`);
|
|
119
|
-
if (!ticker.vwap)
|
|
120
|
-
throw new Error("Unable to get ticker vwap");
|
|
121
|
-
const exchangeFee = exchange.id === "bitstamp" ? 0.002 : 0.002;
|
|
122
|
-
if (amountCrypto) {
|
|
123
|
-
return {
|
|
124
|
-
price: ticker.vwap * (1 - exchangeFee),
|
|
125
|
-
amountCrypto: amountCrypto,
|
|
126
|
-
amountFiat: amountCrypto * (ticker.vwap * (1 - exchangeFee)),
|
|
127
|
-
crypto,
|
|
128
|
-
fiat,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
return {
|
|
133
|
-
price: ticker.vwap * (1 - exchangeFee),
|
|
134
|
-
amountCrypto: amountFiat / (ticker.vwap * (1 - exchangeFee)),
|
|
135
|
-
amountFiat,
|
|
136
|
-
crypto,
|
|
137
|
-
fiat,
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
142
|
-
return {
|
|
143
|
-
price: 1,
|
|
144
|
-
amountCrypto: 100,
|
|
145
|
-
amountFiat: 100,
|
|
146
|
-
crypto,
|
|
147
|
-
fiat,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
getDepositAddress(crypto) {
|
|
153
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
const exchange = yield this.getOptimalExchange(crypto);
|
|
155
|
-
if (!exchange)
|
|
156
|
-
throw new Error("Unable to get optimal exchange");
|
|
157
|
-
let depositAddress = yield exchange.fetchDepositAddress(crypto);
|
|
158
|
-
if (!depositAddress)
|
|
159
|
-
throw new Error("Unable to get deposit address");
|
|
160
|
-
return depositAddress.address;
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
exports.ccxtWrapper = new CCXTClient(process.env.TEST_ENV === "true" ? "development" : "production");
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { Crypto } from "@riocrypto/common";
|
|
2
|
-
declare class CoinbaseClient {
|
|
3
|
-
private apiKey;
|
|
4
|
-
private baseUrl;
|
|
5
|
-
private productIdMappings;
|
|
6
|
-
constructor(apiKey: string, env?: "sandbox" | "production");
|
|
7
|
-
private getRequestHeaders;
|
|
8
|
-
createMarketOrder(crypto: Crypto, amount: number): Promise<any>;
|
|
9
|
-
getDeposits(after: Date): Promise<any>;
|
|
10
|
-
getOrder(coinbaseOrderId: string): Promise<any>;
|
|
11
|
-
}
|
|
12
|
-
export declare const buildCoinbaseClient: (env?: "sandbox" | "production") => Promise<CoinbaseClient>;
|
|
13
|
-
export {};
|
|
@@ -1,119 +0,0 @@
|
|
|
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.buildCoinbaseClient = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const common_1 = require("@riocrypto/common");
|
|
18
|
-
const crypto_1 = require("crypto");
|
|
19
|
-
const secret_manager_client_1 = require("./secret-manager-client");
|
|
20
|
-
class CoinbaseClient {
|
|
21
|
-
constructor(apiKey, env) {
|
|
22
|
-
this.apiKey = apiKey;
|
|
23
|
-
if (env) {
|
|
24
|
-
this.baseUrl =
|
|
25
|
-
env === "sandbox"
|
|
26
|
-
? "https://api-public.sandbox.exchange.coinbase.com"
|
|
27
|
-
: "https://api.exchange.coinbase.com";
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
if ([common_1.RioEnv.Development, common_1.RioEnv.Production, common_1.RioEnv.Staging].includes(process.env.RIO_ENV)) {
|
|
31
|
-
this.baseUrl = "https://api.exchange.coinbase.com";
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
this.baseUrl = "https://api-public.sandbox.exchange.coinbase.com";
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
this.productIdMappings = {
|
|
38
|
-
[common_1.Crypto.USDTEthereum]: "USDT-USD",
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
getRequestHeaders(requestPath, body, method) {
|
|
42
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
// create the json request object
|
|
44
|
-
const cb_access_timestamp = Date.now() / 1000;
|
|
45
|
-
const cb_access_passphrase = yield secret_manager_client_1.secretManagerClient.getSecretValue("COINBASE_API_PASSPHRASE");
|
|
46
|
-
if (!cb_access_passphrase) {
|
|
47
|
-
throw new common_1.SecretManagerError();
|
|
48
|
-
}
|
|
49
|
-
const secret = yield secret_manager_client_1.secretManagerClient.getSecretValue("COINBASE_API_SECRET");
|
|
50
|
-
if (!secret) {
|
|
51
|
-
throw new common_1.SecretManagerError();
|
|
52
|
-
}
|
|
53
|
-
// create the prehash string by concatenating required parts
|
|
54
|
-
const message = cb_access_timestamp + method + requestPath + body;
|
|
55
|
-
// decode the base64 secret
|
|
56
|
-
const key = Buffer.from(secret, "base64");
|
|
57
|
-
// create a sha256 hmac with the secret
|
|
58
|
-
const hmac = (0, crypto_1.createHmac)("sha256", key);
|
|
59
|
-
// sign the require message with the hmac and base64 encode the result
|
|
60
|
-
const cb_access_sign = hmac.update(message).digest("base64");
|
|
61
|
-
return {
|
|
62
|
-
"CB-ACCESS-KEY": this.apiKey,
|
|
63
|
-
"CB-ACCESS-SIGN": cb_access_sign,
|
|
64
|
-
"CB-ACCESS-TIMESTAMP": cb_access_timestamp,
|
|
65
|
-
"CB-ACCESS-PASSPHRASE": cb_access_passphrase,
|
|
66
|
-
"content-type": "application/json; charset=UTF-8",
|
|
67
|
-
"User-Agent": "request",
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
createMarketOrder(crypto, amount) {
|
|
72
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
-
const requestPath = "/orders";
|
|
74
|
-
const body = JSON.stringify({
|
|
75
|
-
type: "market",
|
|
76
|
-
funds: amount,
|
|
77
|
-
side: "buy",
|
|
78
|
-
product_id: this.productIdMappings[crypto],
|
|
79
|
-
});
|
|
80
|
-
const headers = yield this.getRequestHeaders(requestPath, body, "POST");
|
|
81
|
-
const { data } = yield axios_1.default.post(`${this.baseUrl}${requestPath}`, body, {
|
|
82
|
-
headers,
|
|
83
|
-
});
|
|
84
|
-
return data;
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
getDeposits(after) {
|
|
88
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
89
|
-
const requestPath = "/transfers?type=deposit&before=" + after.toISOString();
|
|
90
|
-
const body = "";
|
|
91
|
-
const headers = yield this.getRequestHeaders(requestPath, body, "GET");
|
|
92
|
-
const { data } = yield axios_1.default.get(`${this.baseUrl}${requestPath}`, {
|
|
93
|
-
headers,
|
|
94
|
-
});
|
|
95
|
-
return data;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
getOrder(coinbaseOrderId) {
|
|
99
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
100
|
-
const requestPath = `/orders/${coinbaseOrderId}`;
|
|
101
|
-
const body = "";
|
|
102
|
-
const headers = yield this.getRequestHeaders(requestPath, body, "GET");
|
|
103
|
-
const { data } = yield axios_1.default.get(`${this.baseUrl}${requestPath}`, {
|
|
104
|
-
headers,
|
|
105
|
-
});
|
|
106
|
-
return data;
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
const buildCoinbaseClient = (env) => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
-
// Retrieve secrets asynchronously
|
|
112
|
-
const COINBASE_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("COINBASE_API_KEY");
|
|
113
|
-
if (!COINBASE_API_KEY) {
|
|
114
|
-
throw new common_1.SecretManagerError();
|
|
115
|
-
}
|
|
116
|
-
// Create GuenoClient instance and return
|
|
117
|
-
return new CoinbaseClient(COINBASE_API_KEY, env);
|
|
118
|
-
});
|
|
119
|
-
exports.buildCoinbaseClient = buildCoinbaseClient;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance, AxiosStatic } from "axios";
|
|
2
|
-
export declare class EtherscanClient {
|
|
3
|
-
private axios;
|
|
4
|
-
constructor(axios: AxiosStatic | AxiosInstance);
|
|
5
|
-
getTransactions(address: string, page: string, offset: string): Promise<any[]>;
|
|
6
|
-
getTokenTransactions(contractAddress: string, address: string, page: string, offset: string): Promise<any[]>;
|
|
7
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
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.EtherscanClient = void 0;
|
|
13
|
-
const common_1 = require("@riocrypto/common");
|
|
14
|
-
const secret_manager_client_1 = require("./secret-manager-client");
|
|
15
|
-
class EtherscanClient {
|
|
16
|
-
constructor(axios) {
|
|
17
|
-
this.axios = axios;
|
|
18
|
-
}
|
|
19
|
-
getTransactions(address, page, offset) {
|
|
20
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
const ETHERSCAN_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("ETHERSCAN_API_KEY");
|
|
22
|
-
if (!ETHERSCAN_API_KEY) {
|
|
23
|
-
throw new common_1.SecretManagerError();
|
|
24
|
-
}
|
|
25
|
-
const { data } = yield this.axios.get(`https://api.etherscan.io/api?module=account&action=txlist&address=${address}&startblock=0&endblock=99999999&page=${page}&offset=${offset}&sort=asc&apikey=${ETHERSCAN_API_KEY}`);
|
|
26
|
-
return data.result;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
getTokenTransactions(contractAddress, address, page, offset) {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
const ETHERSCAN_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("ETHERSCAN_API_KEY");
|
|
32
|
-
if (!ETHERSCAN_API_KEY) {
|
|
33
|
-
throw new Error("Unable to get ETHERSCAN_API_KEY");
|
|
34
|
-
}
|
|
35
|
-
const { data } = yield this.axios.get(`https://api.etherscan.io/api?module=account&action=tokentx&contractaddress=${contractAddress}&address=${address}&startblock=0&endblock=99999999&page=${page}&offset=${offset}&sort=asc&apikey=${ETHERSCAN_API_KEY}`);
|
|
36
|
-
return data.result;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.EtherscanClient = EtherscanClient;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
declare class FogbenderClient {
|
|
2
|
-
private secret;
|
|
3
|
-
constructor(secret: string);
|
|
4
|
-
createToken(customerId: string, userId: string, userEmail: string, userName: string, customerName: string): Promise<string>;
|
|
5
|
-
}
|
|
6
|
-
export declare const buildFogbenderClient: () => Promise<FogbenderClient>;
|
|
7
|
-
export {};
|
|
@@ -1,47 +0,0 @@
|
|
|
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.buildFogbenderClient = void 0;
|
|
16
|
-
const axios_1 = __importDefault(require("axios"));
|
|
17
|
-
const secret_manager_client_1 = require("./secret-manager-client");
|
|
18
|
-
const common_1 = require("@riocrypto/common");
|
|
19
|
-
class FogbenderClient {
|
|
20
|
-
constructor(secret) {
|
|
21
|
-
this.secret = secret;
|
|
22
|
-
}
|
|
23
|
-
createToken(customerId, userId, userEmail, userName, customerName) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
const response = yield axios_1.default.post(`https://api.fogbender.com/tokens`, JSON.stringify({
|
|
26
|
-
customerId,
|
|
27
|
-
userId,
|
|
28
|
-
userEmail,
|
|
29
|
-
userName,
|
|
30
|
-
customerName,
|
|
31
|
-
}), {
|
|
32
|
-
headers: {
|
|
33
|
-
Authorization: `Bearer ${this.secret}`,
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
return response.data.token;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
const buildFogbenderClient = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
-
const FOGBENDER_API_KEY = yield secret_manager_client_1.secretManagerClient.getSecretValue("FOGBENDER_API_KEY");
|
|
42
|
-
if (!FOGBENDER_API_KEY) {
|
|
43
|
-
throw new common_1.SecretManagerError();
|
|
44
|
-
}
|
|
45
|
-
return new FogbenderClient(FOGBENDER_API_KEY);
|
|
46
|
-
});
|
|
47
|
-
exports.buildFogbenderClient = buildFogbenderClient;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { RioEnv } from "@riocrypto/common";
|
|
2
|
-
declare class GoogleSheetsAPIClient {
|
|
3
|
-
private env;
|
|
4
|
-
googleAuth: any;
|
|
5
|
-
constructor(env: RioEnv);
|
|
6
|
-
getNextAvailableRow(sheetId: string): Promise<number>;
|
|
7
|
-
appendRowToNextAvailableRow(sheetId: string, rowData: any[]): Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
export declare const googleSheetsAPIClient: GoogleSheetsAPIClient;
|
|
10
|
-
export {};
|
|
@@ -1,75 +0,0 @@
|
|
|
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
|
-
getNextAvailableRow(sheetId) {
|
|
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: "A:Z", // Adjust the range based on the columns you want to check (e.g., A:Z for columns A to Z)
|
|
29
|
-
});
|
|
30
|
-
const data = response.data.values;
|
|
31
|
-
if (!data || data.length === 0) {
|
|
32
|
-
// If the sheet is completely empty, return the first row (1)
|
|
33
|
-
return 1;
|
|
34
|
-
}
|
|
35
|
-
// Find the first row with empty cells after column A
|
|
36
|
-
for (let i = 0; i < data.length; i++) {
|
|
37
|
-
const row = data[i];
|
|
38
|
-
if (row.length > 1) {
|
|
39
|
-
// If any cell after column A has a value, move to the next row
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
// If all cells after column A are empty, return the row number
|
|
44
|
-
return i + 1;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
// If no empty row found, return the next row after the last row
|
|
48
|
-
return data.length;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
appendRowToNextAvailableRow(sheetId, rowData) {
|
|
52
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
53
|
-
const authClientObject = yield this.googleAuth.getClient();
|
|
54
|
-
const sheets = googleapis_1.google.sheets({ version: "v4", auth: authClientObject });
|
|
55
|
-
const nextAvailableRow = yield this.getNextAvailableRow(sheetId);
|
|
56
|
-
if (nextAvailableRow === -1) {
|
|
57
|
-
throw new Error("Failed to find the next available row.");
|
|
58
|
-
}
|
|
59
|
-
const startColumnIndex = 1; // Column B (index 1)
|
|
60
|
-
const range = `${String.fromCharCode(65 + startColumnIndex)}${nextAvailableRow}`;
|
|
61
|
-
// Append empty cells for column A (if needed) and the actual data for other columns
|
|
62
|
-
const valuesToAppend = Array(startColumnIndex).fill("");
|
|
63
|
-
valuesToAppend.push(...rowData);
|
|
64
|
-
yield sheets.spreadsheets.values.append({
|
|
65
|
-
spreadsheetId: sheetId,
|
|
66
|
-
range,
|
|
67
|
-
valueInputOption: "RAW",
|
|
68
|
-
requestBody: {
|
|
69
|
-
values: [rowData],
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
exports.googleSheetsAPIClient = new GoogleSheetsAPIClient(process.env.RIO_ENV || process.env.NEXT_PUBLIC_RIO_ENV);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Crypto } from "@riocrypto/common";
|
|
2
|
-
declare class GuenoClient {
|
|
3
|
-
private email;
|
|
4
|
-
private password;
|
|
5
|
-
private env;
|
|
6
|
-
constructor(email: string, password: string, env: "sandbox" | "production");
|
|
7
|
-
getAddressRiskScore(address: string, protocol: Crypto): Promise<any>;
|
|
8
|
-
getAccessToken(): Promise<any>;
|
|
9
|
-
}
|
|
10
|
-
export declare const buildGuenoClient: () => Promise<GuenoClient>;
|
|
11
|
-
export {};
|