ladder orders!

This commit is contained in:
Tim Olson
2023-11-27 17:00:54 -04:00
parent d2db5dc4f7
commit 1dff2da3fe
8 changed files with 145 additions and 25 deletions

View File

@@ -2,16 +2,23 @@ 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
export const maxFraction = 65535n // by contract definition of uint16 fraction
export function limitConstraint(price=null) {
const os = useOrderStore()
if( price === null ) {
price = os.limitPrice
if (!price)
return null
}
const route = os.route
const inverted = routeInverted(route)
const isAbove = s.limitIsMinimum ^ inverted
const isAbove = os.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
const decimals = 10 ** (os.tokenA.decimals - os.tokenB.decimals)
const limit = inverted ? decimals / price : price / decimals
return newLimitConstraint(isAbove, isRatio, limit)
}
@@ -32,9 +39,8 @@ export function timesliceTranches() {
} 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
const ceil = maxFraction % BigInt(n) ? 1n : 0n
const amtPerTranche = maxFraction / 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)))