@riocrypto/common-server 1.0.1305 → 1.0.1307
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.
|
@@ -52,32 +52,15 @@ const getExchangeRates = (from, to, noMarkups) => __awaiter(void 0, void 0, void
|
|
|
52
52
|
conversionRateWithMarkups = conversionRate * 0.996;
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
|
-
console.log("conversion rate with markups", conversionRateWithMarkups);
|
|
56
|
-
let safestPrice = conversionRateWithMarkups;
|
|
57
|
-
// Volatility based markups
|
|
58
|
-
const { startDate, endDate } = getDateRange();
|
|
59
|
-
const data = yield currencyAPIClient.getHistoricalExchangeRates(from, to, startDate.toISOString(), endDate.toISOString());
|
|
60
|
-
const values = data.map((point) => point.currencies[to].value);
|
|
61
|
-
const average = values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
62
|
-
const squaredDeviations = values.map((value) => (value - average) ** 2);
|
|
63
|
-
const variance = squaredDeviations.reduce((sum, deviation) => sum + deviation, 0) /
|
|
64
|
-
values.length;
|
|
65
|
-
const volatility = Math.sqrt(variance);
|
|
66
|
-
const maximumPriceChange = volatility * (QUOTE_DURATION_MINUTES / 2);
|
|
67
|
-
safestPrice = safestPrice - maximumPriceChange;
|
|
68
|
-
// Bank based markups
|
|
69
|
-
let exchangeRateMultiplier = from === common_1.Fiat.PEN ? 0.9987 : 0.9997;
|
|
70
|
-
safestPrice = safestPrice * exchangeRateMultiplier;
|
|
71
55
|
return {
|
|
72
56
|
conversionRate,
|
|
73
57
|
conversionRateWithMarkups,
|
|
74
|
-
safestPrice,
|
|
75
58
|
};
|
|
76
59
|
});
|
|
77
60
|
exports.getExchangeRates = getExchangeRates;
|
|
78
|
-
function getDateRange() {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
61
|
+
// function getDateRange(): { startDate: Date; endDate: Date } {
|
|
62
|
+
// const endDate = new Date(); // Current time
|
|
63
|
+
// // Subtract 10 minutes from the end_date
|
|
64
|
+
// const startDate = new Date(endDate.getTime() - 10 * 60 * 1000);
|
|
65
|
+
// return { startDate, endDate };
|
|
66
|
+
// }
|
|
@@ -11,27 +11,56 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.getNetworkFees = void 0;
|
|
13
13
|
const common_1 = require("@riocrypto/common");
|
|
14
|
-
const ccxt_client_1 = require("../clients/ccxt-client");
|
|
15
|
-
const fireblocks_client_1 = require("../clients/fireblocks-client");
|
|
16
14
|
const getNetworkFees = (crypto, conversionRateToUSD) => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
-
const address =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
//
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
// const address =
|
|
16
|
+
// crypto === Crypto.USDCSolana
|
|
17
|
+
// ? "HN7cABqLq46Es1jh92dQQisAq662SmxELLLsHHe4YWrH"
|
|
18
|
+
// : "0x66ECBd38905CC32249ddd6f4f0B4A3DdDDCbd608";
|
|
19
|
+
// const fireblocksClient = await buildFireblocksClient();
|
|
20
|
+
// // Hacky way bc ccxt doesn't support TRON, so quote in MATIC
|
|
21
|
+
// const cryptoToWithdraw =
|
|
22
|
+
// crypto === Crypto.USDTTron ? Crypto.USDCPolygon : crypto;
|
|
23
|
+
// const withdrawFee = await fireblocksClient.estimateWithdrawFee(
|
|
24
|
+
// cryptoToWithdraw,
|
|
25
|
+
// address,
|
|
26
|
+
// 100
|
|
27
|
+
// );
|
|
28
|
+
// if (!withdrawFee) {
|
|
29
|
+
// console.log("No withdraw fee");
|
|
30
|
+
// throw new GenericInternalError();
|
|
31
|
+
// }
|
|
32
|
+
// // Hacky way bc ccxt doesn't support TRON, so quote in MATIC
|
|
33
|
+
// const gasSymbol =
|
|
34
|
+
// crypto === Crypto.USDTTron
|
|
35
|
+
// ? "MATIC"
|
|
36
|
+
// : new CryptoAsset(crypto).getGasSymbol();
|
|
37
|
+
// const withdrawFeeUSDResponse = await ccxtWrapper.getSellQuote(
|
|
38
|
+
// gasSymbol as Crypto,
|
|
39
|
+
// Fiat.USD,
|
|
40
|
+
// undefined,
|
|
41
|
+
// Number(withdrawFee)
|
|
42
|
+
// );
|
|
43
|
+
// const withdrawFeeInBaseCrypto = withdrawFeeUSDResponse.amountFiat;
|
|
44
|
+
// const withdrawFeeInBaseFiat =
|
|
45
|
+
// Number(withdrawFeeUSDResponse.amountFiat) * (1 / conversionRateToUSD);
|
|
46
|
+
let withdrawFeeInUSD = 0;
|
|
47
|
+
if (crypto === common_1.Crypto.USDTTron) {
|
|
48
|
+
withdrawFeeInUSD = 3;
|
|
27
49
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
50
|
+
else if (crypto === common_1.Crypto.USDCSolana) {
|
|
51
|
+
withdrawFeeInUSD = 0.01;
|
|
52
|
+
}
|
|
53
|
+
else if (crypto === common_1.Crypto.USDCPolygon) {
|
|
54
|
+
withdrawFeeInUSD = 0.01;
|
|
55
|
+
}
|
|
56
|
+
else if (crypto === common_1.Crypto.USDC || crypto === common_1.Crypto.USDTEthereum) {
|
|
57
|
+
withdrawFeeInUSD = 20;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
withdrawFeeInUSD = 0.01;
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
withdrawFeeInBaseFiat: withdrawFeeInUSD * (1 / conversionRateToUSD),
|
|
64
|
+
};
|
|
36
65
|
});
|
|
37
66
|
exports.getNetworkFees = getNetworkFees;
|