From e0f42f80e76bca67be1c289301d472d253ea02a2 Mon Sep 17 00:00:00 2001 From: tim Date: Sun, 25 Aug 2024 21:02:29 -0400 Subject: [PATCH] updated SwapOrderStatus with Andrew's changes --- src/blockchain/orderlib.js | 20 ++++++++++-------- src/blockchain/wallet.js | 2 +- src/common.js | 1 + src/components/Status.vue | 28 +++++++++++++++----------- src/components/chart/MarketBuilder.vue | 8 +++++--- 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/blockchain/orderlib.js b/src/blockchain/orderlib.js index f1966e9..3126467 100644 --- a/src/blockchain/orderlib.js +++ b/src/blockchain/orderlib.js @@ -90,10 +90,12 @@ export function newTranche({ maxIntercept = encodeIEE754(maxIntercept) maxSlope = encodeIEE754(maxSlope) } + const minLine = {intercept: minIntercept, slope: minSlope} + const maxLine = {intercept: maxIntercept, slope: maxSlope} return { fraction: Math.min(MAX_FRACTION, Math.round(fraction)), marketOrder, startTimeIsRelative, startTime, endTimeIsRelative, endTime, - minIsBarrier, minIntercept, minSlope, maxIsBarrier, maxIntercept, maxSlope, + minIsBarrier, minLine, maxIsBarrier, maxLine, minIsRatio, maxIsRatio, _reserved7: false, rateLimitFraction, rateLimitPeriod, } } @@ -137,22 +139,24 @@ export function parseOrderStatus(chainId, status) { ocoGroup, filledIn, filledOut, - trancheFilledIn, - trancheFilledOut, - trancheActivationTime, + trancheStatus, ] = status order = parseOrder(order) filledIn = BigInt(filledIn) filledOut = BigInt(filledOut) - trancheFilledIn = trancheFilledIn.map((f)=>BigInt(f)) - trancheFilledOut = trancheFilledOut.map((f)=>BigInt(f)) - trancheActivationTime = trancheActivationTime.map((v)=>Number(v)) + trancheStatus = trancheStatus.map((obj)=>parseTrancheStatus(obj)) return { 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) { let [ diff --git a/src/blockchain/wallet.js b/src/blockchain/wallet.js index 6fca4fd..d367b4c 100644 --- a/src/blockchain/wallet.js +++ b/src/blockchain/wallet.js @@ -276,7 +276,7 @@ export const PendingOrderState = { 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) { // If the fees are about to change within `window` seconds of now, we send the higher native amount of the two fees. diff --git a/src/common.js b/src/common.js index c47f5d5..7ecf8fd 100644 --- a/src/common.js +++ b/src/common.js @@ -124,6 +124,7 @@ export class AbiURLCache extends AsyncURLCache { const files = { // If a contract is in a file different than its name, put the exception here // 'IVaultLogic' : 'IVault', // for example + 'IVaultLogic' : 'IVault', // for example } export function abiPath(name) { diff --git a/src/components/Status.vue b/src/components/Status.vue index eafbd33..0ea5d44 100644 --- a/src/components/Status.vue +++ b/src/components/Status.vue @@ -102,8 +102,8 @@ - - + + / @@ -198,10 +198,8 @@ const orders = computed(()=>{ // 0, rateLimitPeriod // 0, start time // 20, end time - // 730643660, min intercept - // 0, min slope - // 0, max intercept - // 0 max slope + // [730643660, 0], [min intercept, slope] + // [0, 0], [max intercept, slope] // ], // [...], // [...], @@ -258,9 +256,8 @@ const orders = computed(()=>{ st.avg = null else { 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.input = 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.token0 = o.tokenIn < o.tokenOut ? o.tokenIn : o.tokenOut 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) @@ -279,14 +281,16 @@ function describeTrancheTime(st, isStart, t) { let result = '' if( t.minIsBarrier || t.maxIsBarrier ) return 'barrier' + const now = Math.round(Date.now()/1000) if( isStart && t.startTime > 0 ) { - const started = t.startTimeIsRelative ? st.startTime + t.startTime : t.startTime - result += started*1000 < Date.now() ? 'Activated ' : 'Activates ' - result += timestampString(started) + ' ' + const start = t.startTimeIsRelative ? st.startTime + t.startTime : t.startTime + result += now < start ? 'Activates ' : + st.trancheStatus.activationTime < now ? 'Rate Limited ' : 'Activated ' + result += timestampString(st.trancheStatus.activationTime) + ' ' } if( !isStart && t.endTime < 4294967295 ) { 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) } return result diff --git a/src/components/chart/MarketBuilder.vue b/src/components/chart/MarketBuilder.vue index 601e1b7..357dd64 100644 --- a/src/components/chart/MarketBuilder.vue +++ b/src/components/chart/MarketBuilder.vue @@ -27,11 +27,13 @@ const props = defineProps(['order', 'builder']) const emit = defineEmits(['update:builder']) // 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({ - get() {console.log('slip',props.builder,props.builder.slippage); return props.builder.slippage}, - set(v) {props.builder.slippage=v; emit('update:builder', props.builder)} + get() {console.log('slip',props.builder,props.builder.slippage); return props.builder.slippage*100}, + set(v) {props.builder.slippage=v/100; emit('update:builder', props.builder)} }) function buildTranches() {