diff --git a/src/blockchain/orderlib.js b/src/blockchain/orderlib.js index 6bd3589..62785d5 100644 --- a/src/blockchain/orderlib.js +++ b/src/blockchain/orderlib.js @@ -15,6 +15,7 @@ export const DISTANT_FUTURE = uint32max // uint256 minFillAmount; // if a tranche has less than this amount available to fill, it is considered completed // bool amountIsInput; // bool outputDirectlyToOwner; +// bool inverted; // uint64 conditionalOrder; // use NO_CONDITIONAL_ORDER for no chaining. conditionalOrder index must be < than this order's index for safety (written first) and conditionalOrder state must be Template // Tranche[] tranches; // } @@ -22,7 +23,7 @@ export const DISTANT_FUTURE = uint32max // Exchange exchange; // uint24 fee; // } -export function newOrder(tokenIn, tokenOut, exchange, fee, amount, amountIsInput, tranches, +export function newOrder(tokenIn, tokenOut, exchange, fee, amount, amountIsInput, inverted, tranches, minFillAmount=null, outputDirectlyToOwner = false, conditionalOrder = NO_CONDITIONAL_ORDER) { amountIsInput = !!amountIsInput // force convert to bool outputDirectlyToOwner = !!outputDirectlyToOwner // force convert to bool @@ -34,7 +35,7 @@ export function newOrder(tokenIn, tokenOut, exchange, fee, amount, amountIsInput return { tokenIn, tokenOut, route:{exchange, fee}, amount, minFillAmount, amountIsInput, - outputDirectlyToOwner, conditionalOrder, tranches + outputDirectlyToOwner, inverted, conditionalOrder, tranches } } @@ -186,6 +187,7 @@ export function parseOrder(order) { minFillAmount, amountIsInput, outputDirectlyToOwner, + inverted, conditionalOrder, tranches, ] = order @@ -194,7 +196,7 @@ export function parseOrder(order) { minFillAmount = BigInt(minFillAmount) tranches = tranches.map(parseTranche) return { - tokenIn, tokenOut, route, amount, minFillAmount, amountIsInput, outputDirectlyToOwner, conditionalOrder, tranches + tokenIn, tokenOut, route, amount, minFillAmount, amountIsInput, outputDirectlyToOwner, inverted, conditionalOrder, tranches } } diff --git a/src/blockchain/wallet.js b/src/blockchain/wallet.js index 1c361db..091f4d8 100644 --- a/src/blockchain/wallet.js +++ b/src/blockchain/wallet.js @@ -265,7 +265,8 @@ export const PendingOrderState = { Sent: -102, // tx is awaiting blockchain mining } -const placementFeeSelector = 'placementFee((address,address,(uint8,uint24),uint256,uint256,bool,bool,uint64,(uint16,bool,bool,bool,bool,bool,bool,bool,bool,uint16,uint24,uint32,uint32,(uint32,uint32),(uint32,uint32))[]),(uint8,uint8,uint8,uint8,uint8))' +// single order placement selector +const placementFeeSelector = 'placementFee((address,address,(uint8,uint24),uint256,uint256,bool,bool,bool,uint64,(uint16,bool,bool,bool,bool,bool,bool,bool,bool,uint16,uint24,uint32,uint32,(uint32,uint32),(uint32,uint32))[]),(uint8,uint8,uint8,uint8,uint8))' export async function placementFee(vault, order, window=300) { // If the fees are about to change within `window` seconds of now, we send the higher native amount of the two fees. diff --git a/src/charts/datafeed.js b/src/charts/datafeed.js index fb982e5..b83bf5f 100644 --- a/src/charts/datafeed.js +++ b/src/charts/datafeed.js @@ -86,7 +86,11 @@ const feeGroups = {} // keyed by ticker without the final fee field. values are // symbol is keyed by the `ticker` which is defined as 'chain_id|pool_addr' for absolute uniqueness. export function tickerForOrder(chainId, order) { - return tickerKey(chainId, order.route.exchange, order.tokenIn, order.tokenOut, order.route.fee, true) + let [base, quote] = [order.tokenIn, order.tokenOut] + const inv = base > quote + if (inv !== order.inverted) + [base, quote] = [quote, base] + return tickerKey(chainId, order.route.exchange, base, quote, order.route.fee, false) } export function tickerKey(chainId, exchange, tokenAddrA, tokenAddrB, fee, chooseInversion=false ) { diff --git a/src/charts/ordershapes.js b/src/charts/ordershapes.js index 4689d12..fdebd54 100644 --- a/src/charts/ordershapes.js +++ b/src/charts/ordershapes.js @@ -2,6 +2,7 @@ import {DISTANT_FUTURE, DISTANT_PAST} from "@/blockchain/orderlib.js"; import {allocationText, DLine, HLine} from "@/charts/shape.js"; import {createShape, deleteShapeId} from "@/charts/chart.js"; import {timestamp} from "@/misc.js"; +import {useChartOrderStore} from "@/orderbuild.js"; export class OrderShapes { constructor(symbol, orderStatus) { @@ -30,6 +31,11 @@ export class OrderShapes { class TrancheShapes { constructor(symbol, orderStatus, trancheIndex) { + // todo validate base/quote + if (symbol.inverted !== orderStatus.order.inverted) { + console.log('OrderShapes.createLine(): symbol has wrong inverson for this order') + return + } this.symbol = symbol this.status = orderStatus this.trancheIndex = trancheIndex @@ -68,18 +74,18 @@ class TrancheShapes { * 10 ** -(amountIsBase ? this.symbol.base.d : this.symbol.quote.d) const weight = Number(filledAmount) / Number(this.status.order.amount) const amountSymbol = amountIsBase ? this.symbol.base.s : this.symbol.quote.s - // console.log('fillpoint', buy, filledAmount, this.status.order, this.symbol) + console.log('fillpoint', buy, filledAmount, this.status.order, this.symbol) const time = f.time const out = Number(f.filledOut) / (1-this.status.order.route.fee/1000000) let price = out / Number(f.filledIn) if (buy) price = 1/price price *= scale - // console.log('price', price) + console.log('price', price) const channel = buy?'low':'high'; const text = (buy ? 'Buy ' : 'Sell ') + allocationText(weight, amount, amountSymbol, '\n') const s = createShape(buy?'arrow_up':'arrow_down', {time, price}, {channel,text,lock:true}) - // console.log('created fill shape at', time, price) + console.log('created fill shape at', time, price) this.fills.push(s) } @@ -89,21 +95,18 @@ class TrancheShapes { const symbol = this.symbol const scale = 10**symbol.decimals; const buy = status.order.tokenIn === this.symbol.quote.a - const inverted = buy amount = Number(amount) * 10 ** -(buy ? this.symbol.base.d : this.symbol.quote.d) const amountSymbol = buy ? this.symbol.base.s : this.symbol.quote.s const color = buy ? 'green' : 'red' if (intercept !== 0 || slope !== 0) { - // console.log('tranche line', intercept, slope) + console.log('tranche line', intercept, slope) // line active if (slope === 0) { let price = intercept - if (inverted) - price = 1/price price *= scale // horizontal line - // console.log('hline', price, inverted) + console.log('hline', price) const model = {price, color, maxAllocation: status.order.amount, amount, amountSymbol}; const s = new HLine(model, null, null, null, true) this.shapes.push(s) @@ -111,16 +114,12 @@ class TrancheShapes { // diagonal line let startTime = t.startTime if (startTime === DISTANT_PAST) - startTime = 1231006505 // use Bitcoin genesis as the drawing point's start time. unnecessary. + startTime = timestamp() - useChartOrderStore().intervalSecs * 20 // 20 bars ago let endTime = t.endTime if (endTime === DISTANT_FUTURE) endTime = timestamp() // use "now" as the drawing point's time let startPrice = (intercept + slope * startTime); let endPrice = (intercept + slope * endTime); - if (inverted) { - startPrice = 1/startPrice - endPrice = 1/endPrice - } startPrice *= scale endPrice *= scale console.log('dline', startTime, endTime, DISTANT_FUTURE, startPrice, endPrice) diff --git a/src/components/Faucet.vue b/src/components/Faucet.vue index a5451e8..cbc2909 100644 --- a/src/components/Faucet.vue +++ b/src/components/Faucet.vue @@ -68,7 +68,7 @@ const FAUCET_CONFIG = { USXD: 0, WETH: 0, ARB: 0, - USDC: 10000, + USDC: 1000000, } function gib() { diff --git a/src/components/LinePrice.vue b/src/components/LinePrice.vue index 7d78b37..82731f5 100644 --- a/src/components/LinePrice.vue +++ b/src/components/LinePrice.vue @@ -20,14 +20,14 @@ const s = useStore() const price = computed(()=>{ if (props.m === 0) return props.b === 0 ? null : props.b - console.log('raw line price', props.b + props.m * s.clock) + // console.log('raw line price', props.b + props.m * s.clock) return props.b + props.m * s.clock }) const description = computed(()=>{ if( props.m !== 0 ) return 'diagonal' - return props.isMin ? 'limit' : 'dont-chase' + return props.isBreakout ? 'breakout' : 'limit' }) diff --git a/src/components/Order.vue b/src/components/Order.vue index 8ac7654..209096c 100644 --- a/src/components/Order.vue +++ b/src/components/Order.vue @@ -46,7 +46,7 @@ function placeOrder() { const amt = FixedNumber.fromString(os.totalAmount.toString(), {decimals: os.amountToken.decimals}).value const ts = props.tranches() console.log('new order', symbol) - const order = newOrder(tokenIn, tokenOut, symbol.e, symbol.fee, amt, os.amountIsInput, ts) // todo: minAmount, outputToOwner, conditionalOrder + const order = newOrder(tokenIn, tokenOut, symbol.e, symbol.fee, amt, os.amountIsInput, symbol.inverted, ts) // todo: minAmount, outputToOwner, conditionalOrder pendOrder(order) } diff --git a/src/components/Status.vue b/src/components/Status.vue index ca8b5b1..8b29e9e 100644 --- a/src/components/Status.vue +++ b/src/components/Status.vue @@ -95,12 +95,12 @@