orderbuilding fixes for new line price semantics

This commit is contained in:
tim
2024-09-04 02:47:39 -04:00
parent 5afdc83957
commit 93dfb8bdcd
6 changed files with 29 additions and 43 deletions

View File

@@ -151,10 +151,12 @@ export function parseOrderStatus(chainId, status) {
filledIn = BigInt(filledIn) filledIn = BigInt(filledIn)
filledOut = BigInt(filledOut) filledOut = BigInt(filledOut)
trancheStatus = trancheStatus.map((obj)=>parseTrancheStatus(obj)) trancheStatus = trancheStatus.map((obj)=>parseTrancheStatus(obj))
return { const result = {
chainId, order, fillFeeHalfBps, state, startTime, startPrice, ocoGroup, chainId, order, fillFeeHalfBps, state, startTime, startPrice, ocoGroup,
filledIn, filledOut, trancheStatus, filledIn, filledOut, trancheStatus,
} };
console.log('SwapOrderStatus', result)
return result
} }
function parseTrancheStatus(obj) { function parseTrancheStatus(obj) {
@@ -205,20 +207,18 @@ export function parseTranche(tranche) {
rateLimitPeriod, rateLimitPeriod,
startTime, startTime,
endTime, endTime,
minIntercept, minLine,
minSlope, maxLine,
maxIntercept,
maxSlope,
] = tranche ] = tranche
minIntercept = decodeIEE754(minIntercept) minLine = {intercept: minLine.intercept, slope: minLine.slope }
minSlope = decodeIEE754(minSlope) maxLine = {intercept: maxLine.intercept, slope: maxLine.slope }
maxIntercept = decodeIEE754(maxIntercept) const result = {
maxSlope = decodeIEE754(maxSlope)
return {
fraction, startTimeIsRelative, endTimeIsRelative, minIsBarrier, maxIsBarrier, marketOrder, fraction, startTimeIsRelative, endTimeIsRelative, minIsBarrier, maxIsBarrier, marketOrder,
minIsRatio, maxIsRatio, rateLimitFraction, rateLimitPeriod, minIsRatio, maxIsRatio, rateLimitFraction, rateLimitPeriod,
startTime, endTime, minIntercept, minSlope, maxIntercept, maxSlope, startTime, endTime, minLine, maxLine,
} }
console.log('parseTranche', tranche, result)
return result
} }

View File

@@ -28,7 +28,7 @@ import {useOrderStore, useStore} from "@/store/store";
import LimitPrice from "@/components/LimitPrice.vue"; import LimitPrice from "@/components/LimitPrice.vue";
import Order from "@/components/Order.vue"; import Order from "@/components/Order.vue";
import {computed, ref} from "vue"; import {computed, ref} from "vue";
import {applyLinePoints, linePointsValue} from "@/orderbuild.js"; import {applyLinePoints, linePointsValue, useChartOrderStore} from "@/orderbuild.js";
import {newTranche} from "@/blockchain/orderlib.js"; import {newTranche} from "@/blockchain/orderlib.js";
import TimeEntry from "@/components/TimeEntry.vue"; import TimeEntry from "@/components/TimeEntry.vue";
import RoutePrice from "@/components/RoutePrice.vue"; import RoutePrice from "@/components/RoutePrice.vue";
@@ -47,7 +47,8 @@ const curLimit = computed(()=>linePointsValue(time1.value, price1.value, time2.v
function buildTranches() { function buildTranches() {
const t = newTranche(); const t = newTranche();
applyLinePoints(t, time1.value, price1.value, time2.value, price2.value) const co = useChartOrderStore();
applyLinePoints(t, co.selectedSymbol, os.buy, time1.value, price1.value, time2.value, price2.value)
return [t] return [t]
} }

View File

@@ -124,11 +124,11 @@
<div class="mx-3" v-if="t.marketOrder">market order</div> <div class="mx-3" v-if="t.marketOrder">market order</div>
<line-price class="mx-3" v-if="!t.marketOrder" <line-price class="mx-3" v-if="!t.marketOrder"
:base="item.token0" :quote="item.token1" :base="item.token0" :quote="item.token1"
:b="t.minIntercept" :m="t.minSlope" :is-min="true" :b="t.minLine.intercept" :m="t.minLine.slope" :is-min="true"
:buy="item.order.tokenIn===item.token1" :show-btn="true"/> :buy="item.order.tokenIn===item.token1" :show-btn="true"/>
<line-price class="mx-3" v-if="!t.marketOrder" <line-price class="mx-3" v-if="!t.marketOrder"
:base="item.token0" :quote="item.token1" :base="item.token0" :quote="item.token1"
:b="t.maxIntercept" :m="t.maxSlope" :is-min="false" :b="t.maxLine.intercept" :m="t.maxLine.slope" :is-min="false"
:buy="item.order.tokenIn===item.token1" :show-btn="true"/> :buy="item.order.tokenIn===item.token1" :show-btn="true"/>
</div> </div>
</td> </td>

View File

@@ -136,9 +136,6 @@ function buildTranches() {
const lb = _endpoints.value[1] const lb = _endpoints.value[1]
const ws = weights.value const ws = weights.value
const symbol = co.selectedSymbol const symbol = co.selectedSymbol
const inverted = symbol.inverted
const scale = 10 ** -symbol.decimals
const isMinimum = inverted === order.buy
for (let i = 0; i < ws.length; i++) { for (let i = 0; i < ws.length; i++) {
const w = ws[i] const w = ws[i]
const t = newTranche({fraction: w * MAX_FRACTION}) const t = newTranche({fraction: w * MAX_FRACTION})
@@ -153,15 +150,7 @@ function buildTranches() {
// console.log('tranche start/end', // console.log('tranche start/end',
// t.startTime === DISTANT_PAST ? 'PAST' : t.startTime, // t.startTime === DISTANT_PAST ? 'PAST' : t.startTime,
// t.endTime === DISTANT_FUTURE ? 'FUTURE' : t.endTime) // t.endTime === DISTANT_FUTURE ? 'FUTURE' : t.endTime)
if (inverted) { applyLinePoints(t, symbol, order.buy, ...line)
// invert prices
line[1] = 1/line[1]
line[3] = 1/line[3]
}
// scale to pool decimals
line[1] *= scale
line[3] *= scale
applyLinePoints(t, isMinimum, ...line)
tranches.push(t) tranches.push(t)
} }
return tranches return tranches

View File

@@ -81,23 +81,16 @@ function buildTranches() {
console.log('buildTranches', builder, order, tranches) console.log('buildTranches', builder, order, tranches)
const ps = prices.value const ps = prices.value
const ws = weights.value const ws = weights.value
const symbol = co.selectedSymbol
const scale = 10 ** -symbol.decimals
const inverted = symbol.inverted
const isMinimum = inverted === order.buy
for(let i=0; i<ps.length; i++) { for(let i=0; i<ps.length; i++) {
let p = ps[i] let p = ps[i]
if (inverted)
p = 1/p
p *= scale
const w = ws[i] const w = ws[i]
const t = newTranche({ const t = newTranche({
// todo start/end // todo start/end
fraction: w * MAX_FRACTION, fraction: w * MAX_FRACTION,
}) })
const symbol = co.selectedSymbol const symbol = co.selectedSymbol
console.log('symbol', symbol, isMinimum, p) console.log('symbol', symbol, p)
applyLine(t, isMinimum, p, 0) applyLine(t, symbol, order.buy, p, 0)
tranches.push(t) tranches.push(t)
} }
return tranches return tranches

View File

@@ -138,9 +138,9 @@ export function linePointsValue(time0, price0, time1, price1, unixTime = null) {
} }
export function applyLinePoints(tranche, isMinimum, time0, price0, time1, price1) { export function applyLinePoints(tranche, symbol, buy, time0, price0, time1, price1) {
const [intercept, slope] = computeInterceptSlope(time0, price0, time1, price1); const [intercept, slope] = computeInterceptSlope(time0, price0, time1, price1);
applyLine(tranche, isMinimum, intercept, slope) applyLine(tranche, symbol, buy, intercept, slope)
} }
@@ -171,12 +171,15 @@ export function applyLineOld(tranche, intercept, slope, isMinimum = null) {
} }
export function applyLine(tranche, isMinimum, intercept, slope) { export function applyLine(tranche, symbol, buy, intercept, slope) {
// intercept and slope must be already adjusted to be in correct pool units console.log('applyLine', tranche, symbol, buy, intercept, slope)
let m = slope const scale = 10 ** symbol.decimals
let b = intercept const inverted = symbol.inverted
let m = inverted ? -scale / slope : slope / scale
let b = inverted ? scale / intercept : intercept / scale
m = encodeIEE754(m) m = encodeIEE754(m)
b = encodeIEE754(b) b = encodeIEE754(b)
const isMinimum = symbol.inverted===buy;
if (isMinimum) { if (isMinimum) {
tranche.minLine.intercept = b; tranche.minLine.intercept = b;
tranche.minLine.slope = m; tranche.minLine.slope = m;