order building fixes

This commit is contained in:
Tim
2024-03-27 16:11:12 -04:00
parent fb82f23d88
commit 204c63f1b9
3 changed files with 10 additions and 20 deletions

View File

@@ -6,21 +6,9 @@ import {metadata, metadataMap} from "@/version.js";
// synchronous version may return null but will trigger a lookup
export function token(addr) {
// todo deprecated. use metadataMap[chainId][addr]
console.warn('token() is deprecated')
console.log('token', addr)
if( !addr ) {
// console.log('ignoring call to token', addr)
return null
}
const s = useStore()
if( !(addr in s.tokens) ) {
// noinspection JSIgnoredPromiseFromCall
getToken(addr)
return null
}
return s.tokens[addr]
export function token(chainId, addr) {
const found = metadataMap[chainId][addr]
return found ? found : null
}

View File

@@ -80,8 +80,8 @@ function buildOrder() {
// }
const symbol = co.selectedSymbol
const fee = co.selectedPool[1]
const tokenIn = order.buy ^ symbol.inverted ? symbol.quote : symbol.base
const tokenOut = order.buy ^ symbol.inverted ? symbol.base : symbol.quote
const tokenIn = order.buy ? symbol.quote : symbol.base
const tokenOut = order.buy ? symbol.base : symbol.quote
const amountDec = order.amountIsTokenA ? symbol.base.d : symbol.quote.d
const amount = BigInt(Math.trunc(order.amount * 10 ** amountDec))
const amountIsInput = !!(order.amountIsTokenA ^ order.buy)

View File

@@ -139,15 +139,17 @@ export function applyLine(tranche, intercept, slope, isMinimum = null) {
export function applyLine2(tranche, isMinimum, intercept, slope, poolDecimals, inverted) {
// console.log('intercept, slope', intercept, slope)
console.log('intercept, slope', intercept, slope)
// intercept and slope are still in "human" units of decimal-adjusted prices
const scale = 10 ** -poolDecimals
let m = inverted ? -scale / slope : slope / scale
let b = inverted ? scale / intercept : intercept / scale
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)
m = encodeIEE754(m)
b = encodeIEE754(b)
if (inverted)
isMinimum = !isMinimum
if (isMinimum) {
tranche.minIntercept = b;
tranche.minSlope = m;