@reyaxyz/common 0.310.3 → 0.311.0
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/README.md
CHANGED
|
@@ -6,5 +6,5 @@
|
|
|
6
6
|
|
|
7
7
|
| Statements | Branches | Functions | Lines |
|
|
8
8
|
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
|
|
9
|
-
|  |  |  |  |
|
|
10
10
|
|
|
@@ -1,28 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.calculateMaxPriceLimit =
|
|
7
|
-
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
3
|
+
exports.calculateMaxPriceLimit = void 0;
|
|
8
4
|
var ethers_1 = require("ethers");
|
|
9
|
-
// todo: need the ability to supply custom slippage or use a more conservative default for the slippage tolerance
|
|
10
|
-
function calculatePriceLimitForTrade(orderPrice, amount, factor) {
|
|
11
|
-
if (factor === void 0) { factor = 100; }
|
|
12
|
-
// Ensure orderPrice is BigInt
|
|
13
|
-
var orderPriceBigInt = (0, bignumber_js_1.default)(orderPrice);
|
|
14
|
-
// Calculate 1% (or provided factor) of the order price
|
|
15
|
-
var offset = orderPriceBigInt.div(factor);
|
|
16
|
-
// Determine if the amount is positive or negative and adjust the price accordingly
|
|
17
|
-
if (amount > 0) {
|
|
18
|
-
// Trade is long, so add
|
|
19
|
-
return BigInt((0, bignumber_js_1.default)(orderPriceBigInt).plus(offset).times(1e18).toFixed(0));
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return BigInt((0, bignumber_js_1.default)(orderPriceBigInt).minus(offset).times(1e18).toFixed(0));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
exports.calculatePriceLimitForTrade = calculatePriceLimitForTrade;
|
|
26
5
|
function calculateMaxPriceLimit(isLong) {
|
|
27
6
|
// Determine if the amount is positive or negative and adjust the price accordingly
|
|
28
7
|
if (isLong) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trade.js","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trade.js","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":";;;AAAA,iCAAoC;AAEpC,SAAgB,sBAAsB,CAAC,MAAe;IACpD,mFAAmF;IACnF,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,mBAAU,CAAC;IACpB,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;IACnB,CAAC;AACH,CAAC;AAPD,wDAOC","sourcesContent":["import { MaxUint256 } from 'ethers';\n\nexport function calculateMaxPriceLimit(isLong: boolean): bigint {\n // Determine if the amount is positive or negative and adjust the price accordingly\n if (isLong) {\n return MaxUint256;\n } else {\n return BigInt(0);\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trade.d.ts","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trade.d.ts","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":"AAEA,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAO9D"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reyaxyz/common",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.311.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -44,5 +44,5 @@
|
|
|
44
44
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
45
45
|
},
|
|
46
46
|
"packageManager": "pnpm@8.3.1",
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "820bf1d931672522440894ba3b13568bc7ea753e"
|
|
48
48
|
}
|
|
@@ -1,31 +1,5 @@
|
|
|
1
|
-
import BigNumber from 'bignumber.js';
|
|
2
1
|
import { MaxUint256 } from 'ethers';
|
|
3
2
|
|
|
4
|
-
// todo: need the ability to supply custom slippage or use a more conservative default for the slippage tolerance
|
|
5
|
-
export function calculatePriceLimitForTrade(
|
|
6
|
-
orderPrice: number,
|
|
7
|
-
amount: number,
|
|
8
|
-
factor = 100,
|
|
9
|
-
): bigint {
|
|
10
|
-
// Ensure orderPrice is BigInt
|
|
11
|
-
const orderPriceBigInt = BigNumber(orderPrice);
|
|
12
|
-
|
|
13
|
-
// Calculate 1% (or provided factor) of the order price
|
|
14
|
-
const offset = orderPriceBigInt.div(factor);
|
|
15
|
-
|
|
16
|
-
// Determine if the amount is positive or negative and adjust the price accordingly
|
|
17
|
-
if (amount > 0) {
|
|
18
|
-
// Trade is long, so add
|
|
19
|
-
return BigInt(
|
|
20
|
-
BigNumber(orderPriceBigInt).plus(offset).times(1e18).toFixed(0),
|
|
21
|
-
);
|
|
22
|
-
} else {
|
|
23
|
-
return BigInt(
|
|
24
|
-
BigNumber(orderPriceBigInt).minus(offset).times(1e18).toFixed(0),
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
3
|
export function calculateMaxPriceLimit(isLong: boolean): bigint {
|
|
30
4
|
// Determine if the amount is positive or negative and adjust the price accordingly
|
|
31
5
|
if (isLong) {
|