@reyaxyz/common 0.235.0 → 0.236.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
|
|
|
@@ -7,11 +7,12 @@ exports.calculateMaxPriceLimit = exports.calculatePriceLimitForTrade = void 0;
|
|
|
7
7
|
var bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
8
8
|
var ethers_1 = require("ethers");
|
|
9
9
|
// todo: need the ability to supply custom slippage or use a more conservative default for the slippage tolerance
|
|
10
|
-
function calculatePriceLimitForTrade(orderPrice, amount) {
|
|
10
|
+
function calculatePriceLimitForTrade(orderPrice, amount, factor) {
|
|
11
|
+
if (factor === void 0) { factor = 100; }
|
|
11
12
|
// Ensure orderPrice is BigInt
|
|
12
13
|
var orderPriceBigInt = (0, bignumber_js_1.default)(orderPrice);
|
|
13
|
-
// Calculate 1% of the order price
|
|
14
|
-
var offset = orderPriceBigInt.div(
|
|
14
|
+
// Calculate 1% (or provided factor) of the order price
|
|
15
|
+
var offset = orderPriceBigInt.div(factor);
|
|
15
16
|
// Determine if the amount is positive or negative and adjust the price accordingly
|
|
16
17
|
if (amount > 0) {
|
|
17
18
|
// Trade is long, so add
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trade.js","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AACrC,iCAAoC;AAEpC,iHAAiH;AACjH,SAAgB,2BAA2B,CACzC,UAAkB,EAClB,MAAc;
|
|
1
|
+
{"version":3,"file":"trade.js","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAqC;AACrC,iCAAoC;AAEpC,iHAAiH;AACjH,SAAgB,2BAA2B,CACzC,UAAkB,EAClB,MAAc,EACd,MAAY;IAAZ,uBAAA,EAAA,YAAY;IAEZ,8BAA8B;IAC9B,IAAM,gBAAgB,GAAG,IAAA,sBAAS,EAAC,UAAU,CAAC,CAAC;IAE/C,uDAAuD;IACvD,IAAM,MAAM,GAAG,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAE5C,mFAAmF;IACnF,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC;QACf,wBAAwB;QACxB,OAAO,MAAM,CACX,IAAA,sBAAS,EAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAChE,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,OAAO,MAAM,CACX,IAAA,sBAAS,EAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CACjE,CAAC;IACJ,CAAC;AACH,CAAC;AAtBD,kEAsBC;AAED,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 BigNumber from 'bignumber.js';\nimport { MaxUint256 } from 'ethers';\n\n// todo: need the ability to supply custom slippage or use a more conservative default for the slippage tolerance\nexport function calculatePriceLimitForTrade(\n orderPrice: number,\n amount: number,\n factor = 100,\n): bigint {\n // Ensure orderPrice is BigInt\n const orderPriceBigInt = BigNumber(orderPrice);\n\n // Calculate 1% (or provided factor) of the order price\n const offset = orderPriceBigInt.div(factor);\n\n // Determine if the amount is positive or negative and adjust the price accordingly\n if (amount > 0) {\n // Trade is long, so add\n return BigInt(\n BigNumber(orderPriceBigInt).plus(offset).times(1e18).toFixed(0),\n );\n } else {\n return BigInt(\n BigNumber(orderPriceBigInt).minus(offset).times(1e18).toFixed(0),\n );\n }\n}\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,3 +1,3 @@
|
|
|
1
|
-
export declare function calculatePriceLimitForTrade(orderPrice: number, amount: number): bigint;
|
|
1
|
+
export declare function calculatePriceLimitForTrade(orderPrice: number, amount: number, factor?: number): bigint;
|
|
2
2
|
export declare function calculateMaxPriceLimit(isLong: boolean): bigint;
|
|
3
3
|
//# sourceMappingURL=trade.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trade.d.ts","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":"AAIA,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"trade.d.ts","sourceRoot":"/","sources":["transactions/trade.ts"],"names":[],"mappings":"AAIA,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,SAAM,GACX,MAAM,CAkBR;AAED,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.236.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public",
|
|
6
6
|
"registry": "https://registry.npmjs.org"
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"generate:coverage-badges": "npx istanbul-badges-readme --silent"
|
|
44
44
|
},
|
|
45
45
|
"packageManager": "pnpm@8.3.1",
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "30ff194ee60462f8a0fbfaaf98a5378ecd3e7554"
|
|
47
47
|
}
|
|
@@ -5,12 +5,13 @@ import { MaxUint256 } from 'ethers';
|
|
|
5
5
|
export function calculatePriceLimitForTrade(
|
|
6
6
|
orderPrice: number,
|
|
7
7
|
amount: number,
|
|
8
|
+
factor = 100,
|
|
8
9
|
): bigint {
|
|
9
10
|
// Ensure orderPrice is BigInt
|
|
10
11
|
const orderPriceBigInt = BigNumber(orderPrice);
|
|
11
12
|
|
|
12
|
-
// Calculate 1% of the order price
|
|
13
|
-
const offset = orderPriceBigInt.div(
|
|
13
|
+
// Calculate 1% (or provided factor) of the order price
|
|
14
|
+
const offset = orderPriceBigInt.div(factor);
|
|
14
15
|
|
|
15
16
|
// Determine if the amount is positive or negative and adjust the price accordingly
|
|
16
17
|
if (amount > 0) {
|