updated SwapOrderStatus with Andrew's changes

This commit is contained in:
tim
2024-08-25 21:02:29 -04:00
parent 2cf5f14b0d
commit e0f42f80e7
5 changed files with 35 additions and 24 deletions

View File

@@ -90,10 +90,12 @@ export function newTranche({
maxIntercept = encodeIEE754(maxIntercept) maxIntercept = encodeIEE754(maxIntercept)
maxSlope = encodeIEE754(maxSlope) maxSlope = encodeIEE754(maxSlope)
} }
const minLine = {intercept: minIntercept, slope: minSlope}
const maxLine = {intercept: maxIntercept, slope: maxSlope}
return { return {
fraction: Math.min(MAX_FRACTION, Math.round(fraction)), marketOrder, fraction: Math.min(MAX_FRACTION, Math.round(fraction)), marketOrder,
startTimeIsRelative, startTime, endTimeIsRelative, endTime, startTimeIsRelative, startTime, endTimeIsRelative, endTime,
minIsBarrier, minIntercept, minSlope, maxIsBarrier, maxIntercept, maxSlope, minIsBarrier, minLine, maxIsBarrier, maxLine,
minIsRatio, maxIsRatio, _reserved7: false, rateLimitFraction, rateLimitPeriod, minIsRatio, maxIsRatio, _reserved7: false, rateLimitFraction, rateLimitPeriod,
} }
} }
@@ -137,22 +139,24 @@ export function parseOrderStatus(chainId, status) {
ocoGroup, ocoGroup,
filledIn, filledIn,
filledOut, filledOut,
trancheFilledIn, trancheStatus,
trancheFilledOut,
trancheActivationTime,
] = status ] = status
order = parseOrder(order) order = parseOrder(order)
filledIn = BigInt(filledIn) filledIn = BigInt(filledIn)
filledOut = BigInt(filledOut) filledOut = BigInt(filledOut)
trancheFilledIn = trancheFilledIn.map((f)=>BigInt(f)) trancheStatus = trancheStatus.map((obj)=>parseTrancheStatus(obj))
trancheFilledOut = trancheFilledOut.map((f)=>BigInt(f))
trancheActivationTime = trancheActivationTime.map((v)=>Number(v))
return { return {
chainId, order, fillFeeHalfBps, state, startTime, startPrice, ocoGroup, chainId, order, fillFeeHalfBps, state, startTime, startPrice, ocoGroup,
filledIn, filledOut, trancheFilledIn, trancheFilledOut, trancheActivationTime filledIn, filledOut, trancheStatus,
} }
} }
function parseTrancheStatus(obj) {
let [filledIn, filledOut, activationTime, startTime, endTime,] = obj
filledIn = BigInt(filledIn)
filledOut = BigInt(filledOut)
return {filledIn, filledOut, activationTime, startTime, endTime}
}
export function parseOrder(order) { export function parseOrder(order) {
let [ let [

View File

@@ -276,7 +276,7 @@ export const PendingOrderState = {
Sent: -102, // tx is awaiting blockchain mining Sent: -102, // tx is awaiting blockchain mining
} }
const placementFeeSelector = 'placementFee((address,address,(uint8,uint24),uint256,uint256,bool,bool,uint64,(uint16,bool,bool,bool,bool,bool,bool,bool,bool,uint16,uint24,uint32,uint32,uint32,uint32,uint32,uint32)[]),(uint8,uint8,uint8,uint8,uint8))' const placementFeeSelector = 'placementFee((address,address,(uint8,uint24),uint256,uint256,bool,bool,uint64,(uint16,bool,bool,bool,bool,bool,bool,bool,bool,uint16,uint24,uint32,uint32,(uint32,uint32),(uint32,uint32))[]),(uint8,uint8,uint8,uint8,uint8))'
export async function placementFee(vault, order, window=300) { export async function placementFee(vault, order, window=300) {
// If the fees are about to change within `window` seconds of now, we send the higher native amount of the two fees. // If the fees are about to change within `window` seconds of now, we send the higher native amount of the two fees.

View File

@@ -124,6 +124,7 @@ export class AbiURLCache extends AsyncURLCache {
const files = { const files = {
// If a contract is in a file different than its name, put the exception here // If a contract is in a file different than its name, put the exception here
// 'IVaultLogic' : 'IVault', // for example // 'IVaultLogic' : 'IVault', // for example
'IVaultLogic' : 'IVault', // for example
} }
export function abiPath(name) { export function abiPath(name) {

View File

@@ -102,8 +102,8 @@
<td class="text-center w-33"> <td class="text-center w-33">
<suspense> <suspense>
<span v-if="item.state > OrderState.Signing"> <span v-if="item.state > OrderState.Signing">
<pulse :touch="item.trancheFilled[i]"> <pulse :touch="item.trancheStatus[i].filled">
<token-amount :chain-id="item.chainId" :addr="item.amountToken" :amount="item.trancheFilled[i]" :raw="true"/> <token-amount :chain-id="item.chainId" :addr="item.amountToken" :amount="item.trancheStatus[i].filled" :raw="true"/>
</pulse> </pulse>
/ /
</span> </span>
@@ -198,10 +198,8 @@ const orders = computed(()=>{
// 0, rateLimitPeriod // 0, rateLimitPeriod
// 0, start time // 0, start time
// 20, end time // 20, end time
// 730643660, min intercept // [730643660, 0], [min intercept, slope]
// 0, min slope // [0, 0], [max intercept, slope]
// 0, max intercept
// 0 max slope
// ], // ],
// [...], // [...],
// [...], // [...],
@@ -258,9 +256,8 @@ const orders = computed(()=>{
st.avg = null st.avg = null
else { else {
st.avg = FixedNumber.fromValue(status.filledOut, 0, fmtX18) st.avg = FixedNumber.fromValue(status.filledOut, 0, fmtX18)
.div(FixedNumber.fromValue(status.filledIn, 0, fmtX18)).toUnsafeFloat(); .div(FixedNumber.fromValue(status.filledIn, 0, fmtX18)).toUnsafeFloat() * (1+st.order.route.fee/1_000_000);
} }
st.trancheFilled = o.amountIsInput ? st.trancheFilledIn : st.trancheFilledOut
st.amountToken = o.amountIsInput ? o.tokenIn : o.tokenOut st.amountToken = o.amountIsInput ? o.tokenIn : o.tokenOut
st.input = o.amountIsInput ? o.amount : 0 st.input = o.amountIsInput ? o.amount : 0
st.output = !o.amountIsInput ? o.amount : 0 st.output = !o.amountIsInput ? o.amount : 0
@@ -268,6 +265,11 @@ const orders = computed(()=>{
st.selectable = st.state===OrderState.Open st.selectable = st.state===OrderState.Open
st.token0 = o.tokenIn < o.tokenOut ? o.tokenIn : o.tokenOut st.token0 = o.tokenIn < o.tokenOut ? o.tokenIn : o.tokenOut
st.token1 = o.tokenIn < o.tokenOut ? o.tokenOut : o.tokenIn st.token1 = o.tokenIn < o.tokenOut ? o.tokenOut : o.tokenIn
for( const ts of st.trancheStatus ) {
ts.filledIn = BigInt(ts.filledIn)
ts.filledOut = BigInt(ts.filledOut)
ts.filled = o.amountIsInput ? ts.filledIn : ts.filledOut
}
} }
} }
result.sort((a,b)=>b.startTime-a.startTime) result.sort((a,b)=>b.startTime-a.startTime)
@@ -279,14 +281,16 @@ function describeTrancheTime(st, isStart, t) {
let result = '' let result = ''
if( t.minIsBarrier || t.maxIsBarrier ) if( t.minIsBarrier || t.maxIsBarrier )
return 'barrier' return 'barrier'
const now = Math.round(Date.now()/1000)
if( isStart && t.startTime > 0 ) { if( isStart && t.startTime > 0 ) {
const started = t.startTimeIsRelative ? st.startTime + t.startTime : t.startTime const start = t.startTimeIsRelative ? st.startTime + t.startTime : t.startTime
result += started*1000 < Date.now() ? 'Activated ' : 'Activates ' result += now < start ? 'Activates ' :
result += timestampString(started) + ' ' st.trancheStatus.activationTime < now ? 'Rate Limited ' : 'Activated '
result += timestampString(st.trancheStatus.activationTime) + ' '
} }
if( !isStart && t.endTime < 4294967295 ) { if( !isStart && t.endTime < 4294967295 ) {
const ended = t.endTimeIsRelative ? st.startTime + t.endTime : t.endTime const ended = t.endTimeIsRelative ? st.startTime + t.endTime : t.endTime
result += ended*1000 < Date.now() ? 'Ended ' : 'Ending ' result += ended < now ? 'Ended ' : 'Ending '
result += timestampString(ended) result += timestampString(ended)
} }
return result return result

View File

@@ -27,11 +27,13 @@ const props = defineProps(['order', 'builder'])
const emit = defineEmits(['update:builder']) const emit = defineEmits(['update:builder'])
// Fields must be defined in order to be reactive // Fields must be defined in order to be reactive
builderDefaults(props.builder, {valid: true, slippage: 0.10,}) builderDefaults(props.builder, {valid: true, slippage: 0.0010,})
// slippage is expressed in % but the underlying builder value is an unadjusted ratio, so we convert by a factor of
// 100 in and out
const slippage = computed({ const slippage = computed({
get() {console.log('slip',props.builder,props.builder.slippage); return props.builder.slippage}, get() {console.log('slip',props.builder,props.builder.slippage); return props.builder.slippage*100},
set(v) {props.builder.slippage=v; emit('update:builder', props.builder)} set(v) {props.builder.slippage=v/100; emit('update:builder', props.builder)}
}) })
function buildTranches() { function buildTranches() {