orders submitting but breaking due to fee send

This commit is contained in:
Tim
2024-03-23 19:17:26 -04:00
parent 68a820a9f6
commit 0d0200009e
7 changed files with 208 additions and 70 deletions

View File

@@ -22,13 +22,17 @@ export const DISTANT_FUTURE = uint32max
// Exchange exchange;
// uint24 fee;
// }
export function newOrder(tokenIn, tokenOut, exchange, fee, amount, amountIsInput, tranches, minAmount=null,
outputToOwner = false, chainOrder = NO_CHAIN) {
export function newOrder(tokenIn, tokenOut, exchange, fee, amount, amountIsInput, tranches,
minFillAmount=null, outputDirectlyToOwner = false, chainOrder = NO_CHAIN) {
if (!tranches)
tranches = [newTranche({marketOrder: true})] // todo this is just a swap: issue warning?
if( minAmount === null )
minAmount = BigInt(amount) / 100n // default to min trade size of 1%
return [tokenIn, tokenOut, [exchange, fee], amount, minAmount, amountIsInput, outputToOwner, chainOrder, tranches]
if( minFillAmount === null )
minFillAmount = BigInt(amount) / 100n // default to min trade size of 1%
return {
tokenIn, tokenOut, route:{exchange, fee},
amount, minFillAmount, amountIsInput,
outputDirectlyToOwner, chainOrder, tranches
}
}
// struct Tranche {
@@ -55,23 +59,24 @@ export function newOrder(tokenIn, tokenOut, exchange, fee, amount, amountIsInput
// float maxSlope;
// }
export function newTranche({
fraction = MAX_FRACTION,
marketOrder = false,
startTimeIsRelative = false,
startTime = DISTANT_PAST,
endTimeIsRelative = false,
endTime = DISTANT_FUTURE,
minIsBarrier = false,
minIntercept = 0,
minSlope = 0,
maxIsBarrier = false,
maxIntercept = 0,
maxSlope = 0,
fraction = MAX_FRACTION,
marketOrder = false,
startTimeIsRelative = false,
startTime = DISTANT_PAST,
endTimeIsRelative = false,
endTime = DISTANT_FUTURE,
minIsBarrier = false,
minIntercept = 0,
slippage = 0, // may also set minIntercept instead
minSlope = 0,
maxIsBarrier = false,
maxIntercept = 0,
maxSlope = 0,
} = {}) {
if( minIntercept === 0 && minSlope === 0 && maxIntercept === 0 && maxSlope === 0 )
marketOrder = true
if( marketOrder )
minIntercept = encodeIEE754(minIntercept) // this is the slippage field for market orders
minIntercept = encodeIEE754(slippage) // this is the slippage field for market orders
else {
minIntercept = encodeIEE754(minIntercept)
minSlope = encodeIEE754(minSlope)