From a3bfaa2b0817c3b9279770c0b1bc54ad220b5114 Mon Sep 17 00:00:00 2001 From: tim Date: Tue, 29 Oct 2024 21:08:56 -0400 Subject: [PATCH] arb1 redeploy --- src/charts/chart-misc.js | 6 ------ src/charts/shape.js | 31 ++++++++++++++++++++++++++++--- src/components/Withdraw.vue | 3 ++- src/misc.js | 13 ++++++++++++- src/orderbuild.js | 15 +-------------- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/src/charts/chart-misc.js b/src/charts/chart-misc.js index f8d30bd..53ebbc6 100644 --- a/src/charts/chart-misc.js +++ b/src/charts/chart-misc.js @@ -18,12 +18,6 @@ export function nearestOhlcStart(timestamp, periodSeconds=null) { return Math.round((timestamp-OHLC_START) / periodSeconds) * periodSeconds + OHLC_START } -export function pointsToTvOhlcStart(points, periodSeconds=null) { - return points === null ? null : points.map((p) => { - return {time: nearestOhlcStart(p.time, periodSeconds), price: p.price} - }) -} - export function dirtyPoints(pointsA, pointsB) { if (pointsA === undefined) return true diff --git a/src/charts/shape.js b/src/charts/shape.js index 1d9241b..6e2eb62 100644 --- a/src/charts/shape.js +++ b/src/charts/shape.js @@ -3,7 +3,9 @@ import {invokeCallback, mixin} from "@/common.js"; import {chart, createShape, deleteShapeId, dragging, draggingShapeIds, drawShape, widget} from "@/charts/chart.js"; import Color from "color"; -import {dirtyItems, dirtyPoints, pointsToTvOhlcStart} from "@/charts/chart-misc.js"; +import {dirtyItems, dirtyPoints, nearestOhlcStart, pointsToTvOhlcStart} from "@/charts/chart-misc.js"; +import {readonly} from "vue"; +import {computeInterceptSlope} from "@/misc.js"; // @@ -222,7 +224,7 @@ export class Shape { // createShape(this.type, this.points, {overrides:this.props}, new ShapeTVCallbacks(this)) options = mixin(options, this.drawingOverrides()) options['overrides'] = props - this.tvPoints = pointsToTvOhlcStart(points) + this.tvPoints = this.pointsToTvOhlcStart(points) this.tvCallbacks = new ShapeTVCallbacks(this); const id = createShape(this.type, this.tvPoints, options, this.tvCallbacks) // todo set id? @@ -267,7 +269,7 @@ export class Shape { if (this.id === null) this.create() else { - points = pointsToTvOhlcStart(points) + points = this.pointsToTvOhlcStart(points) if (dirtyPoints(this.tvPoints, points)) { /* setPoints(e) { @@ -298,6 +300,13 @@ export class Shape { } } + // diagonals need to override this to adjust their price as well. + pointsToTvOhlcStart(points, periodSeconds=null) { + return points === null ? null : points.map((p) => { + return {time: nearestOhlcStart(p.time, periodSeconds), price: p.price} + }) +} + onPoints(points) {} // the control points of an existing shape were changed setProps(props) { @@ -602,4 +611,20 @@ export class DLine extends Line { super.onProps(props); this.updateModel({extendLeft: props.extendLeft, extendRight: props.extendRight}) } + + + pointsToTvOhlcStart(points, periodSeconds = null) { + if (points === null) return null + const [v,w] = points + const [b,m] = computeInterceptSlope(v.time, v.price, w.time, w.price) + points.map((p) => { + let {time, price} = p + const aligned = nearestOhlcStart(time, periodSeconds); + if (time !== aligned) { + time = aligned + price = b + m * aligned + } + return {time, price} + }) + } } diff --git a/src/components/Withdraw.vue b/src/components/Withdraw.vue index f6ab55b..e3bbdfb 100644 --- a/src/components/Withdraw.vue +++ b/src/components/Withdraw.vue @@ -36,7 +36,8 @@ const props = defineProps(['modelValue', 'vault', 'token']) const emit = defineEmits(['update:modelValue']) const balance = computed(() => { console.log('balance', props.vault, props.token, s.vaultBalances) - return BigInt(s.vaultBalances[props.vault][props.token.address]) || 0n + const b = s.vaultBalances[props.vault][props.token.address]; + return b === undefined ? 0n : BigInt(b) }) const balanceFloat = computed(() => tokenFloat(props.token, balance.value)) const floatAmount = ref(0) diff --git a/src/misc.js b/src/misc.js index 363046b..7944f9d 100644 --- a/src/misc.js +++ b/src/misc.js @@ -1,4 +1,4 @@ -import {ethers, FixedNumber} from "ethers"; +import {FixedNumber} from "ethers"; import {usePrefStore, useStore} from "@/store/store.js"; import {token} from "@/blockchain/token.js"; import Color from "color"; @@ -242,3 +242,14 @@ export function interpolate(a, b, zeroToOne) { return a + d * zeroToOne } +export function computeInterceptSlope(time0, price0, time1, price1) { + if (!time0 || !price0 && price0 !== 0 || !time1 || !price1 && price1 !== 0) + throw Error(`invalid line points data ${time0} ${price0} ${time1} ${price1}`) + const t0 = time0 + const t1 = time1 + if (t0 === t1) + throw Error("line points' times must be different") + const slope = (price1 - price0) / (t1 - t0) + const intercept = price1 - slope * t1 + return [intercept, slope] +} \ No newline at end of file diff --git a/src/orderbuild.js b/src/orderbuild.js index a416f17..3406fe1 100644 --- a/src/orderbuild.js +++ b/src/orderbuild.js @@ -1,4 +1,4 @@ -import {timestamp, uuid} from "@/misc.js"; +import {computeInterceptSlope, 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"; @@ -112,19 +112,6 @@ export function applyLimitOld(tranche, price = null, isMinimum = null) { } -function computeInterceptSlope(time0, price0, time1, price1) { - if (!time0 || !price0 && price0 !== 0 || !time1 || !price1 && price1 !== 0) - throw Error(`invalid line points data ${time0} ${price0} ${time1} ${price1}`) - const t0 = time0 - const t1 = time1 - if (t0 === t1) - throw Error("line points' times must be different") - const slope = (price1 - price0) / (t1 - t0) - const intercept = price1 - slope * t1 - return [intercept, slope] -} - - export function linePointsValue(time0, price0, time1, price1, unixTime = null) { if (unixTime === null) unixTime = timestamp()