line inversion fixes

This commit is contained in:
Tim
2024-05-08 15:14:40 -04:00
parent a68c4a4b05
commit 35eb18618d
6 changed files with 65 additions and 27 deletions

View File

@@ -1,4 +1,4 @@
import {timestamp, uuid} from "@/misc.js";
import {routeInverted, timestamp, uuid} from "@/misc.js";
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
import {useOrderStore, useStore} from "@/store/store.js";
import {encodeIEE754} from "@/common.js";
@@ -10,8 +10,6 @@ import Color from "color";
export const MIN_EXECUTION_TIME = 60 // give at least one full minute for each tranche to trigger
function unimplemented() { throw Error('Unimplemented') }
// Builders are data objects which store a configuration state
// the component name must match a corresponding Vue component in the BuilderFactory.vue component, which is responsible
// for instantiating the UI component for a given builder dictionary, based on its builder.component field.
@@ -101,7 +99,8 @@ export const useChartOrderStore = defineStore('chart_orders', () => {
})
export function applyLimit(tranche, price = null, isMinimum = null) {
export function applyLimitOld(tranche, price = null, isMinimum = null) {
// todo deprecate. used by old forms-based components.
if (price === null) {
const os = useOrderStore()
price = os.limitPrice
@@ -109,7 +108,7 @@ export function applyLimit(tranche, price = null, isMinimum = null) {
return
}
applyLine(tranche, price, 0, isMinimum)
applyLineOld(tranche, price, 0, isMinimum)
}
@@ -139,23 +138,45 @@ export function linePointsValue(time0, price0, time1, price1, unixTime = null) {
}
export function applyLinePoints(tranche, buy, time0, price0, time1, price1, poolDecimals, inverted) {
export function applyLinePoints(tranche, isMinimum, time0, price0, time1, price1) {
const [intercept, slope] = computeInterceptSlope(time0, price0, time1, price1);
applyLine(tranche, buy, intercept, slope, poolDecimals, inverted)
applyLine(tranche, isMinimum, intercept, slope)
}
export function applyLine(tranche, buy, intercept, slope, poolDecimals, inverted) {
export function applyLineOld(tranche, intercept, slope, isMinimum = null) {
console.log('intercept, slope', intercept, slope)
// intercept and slope are still in "human" units of decimal-adjusted prices
const scale = 10 ** -poolDecimals
let m = slope === 0 ? 0 : inverted ? -scale / slope : scale * slope
let b = inverted ? scale / intercept : scale * intercept
// const cur = b + timestamp() * m
// console.log('inverted b, m, cur', inverted, b, m, cur)
const os = useOrderStore()
const route = os.route
const inverted = routeInverted(route)
const scale = 10 ** (os.tokenA.d - os.tokenB.d)
let m = inverted ? -scale / slope : slope / scale
let b = inverted ? scale / intercept : intercept / scale
const cur = b + timestamp() * m
console.log('inverted b, m, cur', inverted, b, m, cur)
m = encodeIEE754(m)
b = encodeIEE754(b)
if (isMinimum === null)
isMinimum = os.limitIsMinimum
console.log('limit is minimum', isMinimum)
if (isMinimum) {
tranche.minIntercept = b;
tranche.minSlope = m;
} else {
tranche.maxIntercept = b;
tranche.maxSlope = m;
}
tranche.marketOrder = false;
}
export function applyLine(tranche, isMinimum, intercept, slope) {
// intercept and slope must be already adjusted to be in correct pool units
let m = slope
let b = intercept
m = encodeIEE754(m)
b = encodeIEE754(b)
const isMinimum = !(buy ^ inverted)
console.log('applyLine', buy, intercept, slope, poolDecimals, inverted, isMinimum)
if (isMinimum) {
tranche.minIntercept = b;
tranche.minSlope = m;