order building fixes
This commit is contained in:
@@ -6,21 +6,9 @@ import {metadata, metadataMap} from "@/version.js";
|
|||||||
|
|
||||||
|
|
||||||
// synchronous version may return null but will trigger a lookup
|
// synchronous version may return null but will trigger a lookup
|
||||||
export function token(addr) {
|
export function token(chainId, addr) {
|
||||||
// todo deprecated. use metadataMap[chainId][addr]
|
const found = metadataMap[chainId][addr]
|
||||||
console.warn('token() is deprecated')
|
return found ? found : null
|
||||||
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]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ function buildOrder() {
|
|||||||
// }
|
// }
|
||||||
const symbol = co.selectedSymbol
|
const symbol = co.selectedSymbol
|
||||||
const fee = co.selectedPool[1]
|
const fee = co.selectedPool[1]
|
||||||
const tokenIn = order.buy ^ symbol.inverted ? symbol.quote : symbol.base
|
const tokenIn = order.buy ? symbol.quote : symbol.base
|
||||||
const tokenOut = order.buy ^ symbol.inverted ? symbol.base : symbol.quote
|
const tokenOut = order.buy ? symbol.base : symbol.quote
|
||||||
const amountDec = order.amountIsTokenA ? symbol.base.d : symbol.quote.d
|
const amountDec = order.amountIsTokenA ? symbol.base.d : symbol.quote.d
|
||||||
const amount = BigInt(Math.trunc(order.amount * 10 ** amountDec))
|
const amount = BigInt(Math.trunc(order.amount * 10 ** amountDec))
|
||||||
const amountIsInput = !!(order.amountIsTokenA ^ order.buy)
|
const amountIsInput = !!(order.amountIsTokenA ^ order.buy)
|
||||||
|
|||||||
@@ -139,15 +139,17 @@ export function applyLine(tranche, intercept, slope, isMinimum = null) {
|
|||||||
|
|
||||||
|
|
||||||
export function applyLine2(tranche, isMinimum, intercept, slope, poolDecimals, inverted) {
|
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
|
// intercept and slope are still in "human" units of decimal-adjusted prices
|
||||||
const scale = 10 ** -poolDecimals
|
const scale = 10 ** -poolDecimals
|
||||||
let m = inverted ? -scale / slope : slope / scale
|
let m = slope === 0 ? 0 : inverted ? -scale / slope : scale * slope
|
||||||
let b = inverted ? scale / intercept : intercept / scale
|
let b = inverted ? scale / intercept : scale * intercept
|
||||||
const cur = b + timestamp() * m
|
const cur = b + timestamp() * m
|
||||||
console.log('inverted b, m, cur', inverted, b, m, cur)
|
console.log('inverted b, m, cur', inverted, b, m, cur)
|
||||||
m = encodeIEE754(m)
|
m = encodeIEE754(m)
|
||||||
b = encodeIEE754(b)
|
b = encodeIEE754(b)
|
||||||
|
if (inverted)
|
||||||
|
isMinimum = !isMinimum
|
||||||
if (isMinimum) {
|
if (isMinimum) {
|
||||||
tranche.minIntercept = b;
|
tranche.minIntercept = b;
|
||||||
tranche.minSlope = m;
|
tranche.minSlope = m;
|
||||||
|
|||||||
Reference in New Issue
Block a user