price constraints working
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import {uint32max, uint64max} from "@/misc.js";
|
||||
import {ethers} from "ethers";
|
||||
|
||||
@@ -49,18 +48,14 @@ export const Exchange = {
|
||||
}
|
||||
|
||||
// enum ConstraintMode {
|
||||
// Time, // 0
|
||||
// Limit, // 1
|
||||
// Trailing, // 2
|
||||
// Barrier, // 3
|
||||
// Line // 4
|
||||
// Time, // 0
|
||||
// Line, // 1
|
||||
// Barrier // 2
|
||||
// }
|
||||
export const ConstraintMode = {
|
||||
Time: 0,
|
||||
Limit: 1,
|
||||
Trailing: 2,
|
||||
Barrier: 3,
|
||||
Line: 4,
|
||||
Line: 1,
|
||||
Barrier: 2,
|
||||
}
|
||||
|
||||
// struct Constraint {
|
||||
@@ -98,12 +93,6 @@ export function newTimeConstraint(startMode, start, endMode, end) {
|
||||
)
|
||||
}
|
||||
|
||||
// struct PriceConstraint {
|
||||
// bool isAbove;
|
||||
// bool isRatio;
|
||||
// uint160 valueSqrtX96;
|
||||
// }
|
||||
|
||||
// struct LineConstraint {
|
||||
// bool isAbove;
|
||||
// bool isRatio;
|
||||
@@ -112,3 +101,19 @@ export function newTimeConstraint(startMode, start, endMode, end) {
|
||||
// int160 slopeSqrtX96; // price change per second
|
||||
// }
|
||||
|
||||
export function newLimitConstraint( isAbove, isRatio, price ) {
|
||||
return newLineConstraint(isAbove, isRatio, 0, price, 0)
|
||||
}
|
||||
|
||||
export function newLineConstraint( isAbove, isRatio, time, price, slope ) {
|
||||
return encodeConstraint(
|
||||
ConstraintMode.Line,
|
||||
['bool', 'bool', 'uint32', 'uint160', 'int160'],
|
||||
[isAbove, isRatio, time, sqrtX96(price), sqrtX96(slope)]
|
||||
)
|
||||
}
|
||||
|
||||
export function sqrtX96(value) {
|
||||
return BigInt(Math.round(Math.sqrt(value * 2 ** (96*2))))
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user