TimedOrder submission works
This commit is contained in:
@@ -1,17 +1,14 @@
|
||||
import {routeInverted} from "@/misc.js";
|
||||
import {newLimitConstraint, newTimeConstraint, TimeMode} from "@/blockchain/orderlib.js";
|
||||
import {MAX_FRACTION, newTranche} from "@/blockchain/orderlib.js";
|
||||
import {useOrderStore} from "@/store/store.js";
|
||||
|
||||
|
||||
export const maxFraction = 65535n // by contract definition of uint16 fraction
|
||||
|
||||
|
||||
export function limitConstraint(price=null) {
|
||||
export function applyLimit(tranche, price=null) {
|
||||
const os = useOrderStore()
|
||||
if( price === null ) {
|
||||
price = os.limitPrice
|
||||
if (!price)
|
||||
return null
|
||||
return
|
||||
}
|
||||
const route = os.route
|
||||
const inverted = routeInverted(route)
|
||||
@@ -19,7 +16,15 @@ export function limitConstraint(price=null) {
|
||||
const isRatio = false // todo ratios
|
||||
const decimals = 10 ** (os.tokenA.decimals - os.tokenB.decimals)
|
||||
const limit = inverted ? decimals / price : price / decimals
|
||||
return newLimitConstraint(isAbove, isRatio, limit)
|
||||
tranche.marketOrder = false;
|
||||
if( isAbove ) {
|
||||
tranche.minIntercept = limit;
|
||||
tranche.minSlope = 0;
|
||||
}
|
||||
else {
|
||||
tranche.maxIntercept = limit;
|
||||
tranche.maxSlope = 0;
|
||||
}
|
||||
}
|
||||
|
||||
export function timesliceTranches() {
|
||||
@@ -39,14 +44,18 @@ export function timesliceTranches() {
|
||||
} else {
|
||||
window = Math.round(duration / n)
|
||||
}
|
||||
const ceil = maxFraction % BigInt(n) ? 1n : 0n
|
||||
const amtPerTranche = maxFraction / BigInt(n) + ceil
|
||||
const amtPerTranche = Math.ceil(MAX_FRACTION / n)
|
||||
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])
|
||||
ts.push(newTranche({
|
||||
fraction: amtPerTranche,
|
||||
startTimeIsRelative: true,
|
||||
startTime: start,
|
||||
endTimeIsRelative: true,
|
||||
endTime: end,
|
||||
}))
|
||||
}
|
||||
return ts
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user