major refactor of web store into vue setup style declaration; reactivity debugging; order view has known refresh issues
This commit is contained in:
46
src/orderbuild.js
Normal file
46
src/orderbuild.js
Normal file
@@ -0,0 +1,46 @@
|
||||
import {routeInverted} from "@/misc.js";
|
||||
import {newLimitConstraint, newTimeConstraint, TimeMode} from "@/blockchain/orderlib.js";
|
||||
import {useOrderStore, useStore} from "@/store/store.js";
|
||||
|
||||
export function limitConstraint() {
|
||||
const s = useStore()
|
||||
if (!s.limitPrice)
|
||||
return null
|
||||
const route = s.route
|
||||
const inverted = routeInverted(route)
|
||||
const isAbove = s.limitIsMinimum ^ inverted
|
||||
const isRatio = false // todo ratios
|
||||
const decimals = 10 ** (s.tokenA.decimals - s.tokenB.decimals)
|
||||
const limit = inverted ? decimals / s.limitPrice : s.limitPrice / decimals
|
||||
return newLimitConstraint(isAbove, isRatio, limit)
|
||||
}
|
||||
|
||||
export function timesliceTranches() {
|
||||
const ts = []
|
||||
const os = useOrderStore()
|
||||
const n = os.tranches // num tranches
|
||||
const interval = os.interval;
|
||||
const timeUnitIndex = os.timeUnitIndex;
|
||||
let duration =
|
||||
timeUnitIndex === 0 ? interval * 60 : // minutes
|
||||
timeUnitIndex === 1 ? interval * 60 * 60 : // hours
|
||||
interval * 24 * 60 * 60; // days
|
||||
let window
|
||||
if (!os.intervalIsTotal) {
|
||||
window = duration
|
||||
duration *= n // duration is the total time for all tranches
|
||||
} else {
|
||||
window = Math.round(duration / n)
|
||||
}
|
||||
const oneHundredPercent = 65535n // by contract definition of uint16 fraction
|
||||
const ceil = oneHundredPercent % BigInt(n) ? 1n : 0n
|
||||
const amtPerTranche = oneHundredPercent / BigInt(n) + ceil
|
||||
duration -= 15 // subtract 15 seconds so the last tranche completes before the deadline
|
||||
for (let i = 0; i < n; i++) {
|
||||
const start = Math.floor(i * (duration / Math.max((n - 1), 1)))
|
||||
const end = start + window
|
||||
const cs = [newTimeConstraint(TimeMode.SinceOrderStart, start, TimeMode.SinceOrderStart, end)]
|
||||
ts.push([amtPerTranche, cs])
|
||||
}
|
||||
return ts
|
||||
}
|
||||
Reference in New Issue
Block a user