order amount bugfix

This commit is contained in:
Tim Olson
2023-11-27 18:35:40 -04:00
parent 1dff2da3fe
commit e25239d81f
4 changed files with 17 additions and 16 deletions

View File

@@ -2,8 +2,10 @@
<order title="Ladder" subtitle="Multiple price levels" :tranches="buildTranches" :valid="validOrder"> <order title="Ladder" subtitle="Multiple price levels" :tranches="buildTranches" :valid="validOrder">
<limit-price :required="true" label="start price" :show-price="false"/> <limit-price :required="true" label="start price" :show-price="false"/>
<limit-price store-var="limitPrice2" :required="true" label="end price"/> <limit-price store-var="limitPrice2" :required="true" label="end price"/>
<v-text-field label='Parts' type="number" step="1" aria-valuemin="0" min="1" variant="outlined" <v-text-field label="Tranches" type="number" variant="outlined" aria-valuemin="1" min="1" max="255"
v-model="num" /> v-model="os.tranches" :rules="[validateRequired,validateTranches]">
<template v-slot:append-inner>tranches</template>
</v-text-field>
<v-text-field label='Skew' type="number" step="10" aria-valuemin="0" min="-100" max="100" variant="outlined" <v-text-field label='Skew' type="number" step="10" aria-valuemin="0" min="-100" max="100" variant="outlined"
v-model="skew" clearable @click:clear="skew=0" suffix="%"/> v-model="skew" clearable @click:clear="skew=0" suffix="%"/>
<!-- todo deadline --> <!-- todo deadline -->
@@ -27,16 +29,16 @@ import {useOrderStore} from "@/store/store";
import LimitPrice from "@/components/LimitPrice.vue"; import LimitPrice from "@/components/LimitPrice.vue";
import Order from "@/components/Order.vue"; import Order from "@/components/Order.vue";
import {computed, ref} from "vue"; import {computed, ref} from "vue";
import {newTimeConstraint, TimeMode} from "@/blockchain/orderlib.js";
import {limitConstraint, maxFraction} from "@/orderbuild.js"; import {limitConstraint, maxFraction} from "@/orderbuild.js";
import {validateMax} from "@/validate.js"; import {validateRequired, validateTranches} from "@/validate.js";
const os = useOrderStore() const os = useOrderStore()
const num = ref(3)
const skew = ref(0) const skew = ref(0)
const rungs = computed(()=>{ const rungs = computed(()=>{
const n = num.value; if( !os.limitPrice || !os.limitPrice2 )
return []
const n = os.tranches;
const a = parseFloat(os.limitPrice); const a = parseFloat(os.limitPrice);
const b = parseFloat(os.limitPrice2); const b = parseFloat(os.limitPrice2);
if( n < 1 || !a || !b ) return [] if( n < 1 || !a || !b ) return []
@@ -52,7 +54,7 @@ const rungsFmt = computed(()=>{
return rungs.value.map((r)=>r.toPrecision(5)) // todo precisions return rungs.value.map((r)=>r.toPrecision(5)) // todo precisions
}) })
const fractions = computed(()=>{ const fractions = computed(()=>{
const n = num.value const n = os.tranches
const s = skew.value / 100 const s = skew.value / 100
const result = [] const result = []
if( s === 1 ) { if( s === 1 ) {
@@ -72,11 +74,11 @@ const fractions = computed(()=>{
} }
return result return result
}) })
const amounts = computed( ()=>fractions.value.map((f)=>f*os.amount) ) const amounts = computed( ()=>fractions.value.map((f)=>f*os.totalAmount) )
function buildTranches() { function buildTranches() {
const ts = [] const ts = []
const n = num.value const n = os.tranches
const mf = Number(maxFraction) const mf = Number(maxFraction)
for( let i=0; i<n; i++ ) { for( let i=0; i<n; i++ ) {
// todo optional deadline // todo optional deadline

View File

@@ -20,19 +20,16 @@
<script setup> <script setup>
import {useOrderStore, useStore} from "@/store/store"; import {useOrderStore, useStore} from "@/store/store";
import {computed, ref} from "vue";
import PhoneCard from "@/components/PhoneCard.vue"; import PhoneCard from "@/components/PhoneCard.vue";
import Amount from "@/components/Amount.vue" import Amount from "@/components/Amount.vue"
// noinspection ES6UnusedImports // noinspection ES6UnusedImports
import {routeInverted, SingletonCoroutine, vAutoSelect} from "@/misc.js"; import {routeInverted, SingletonCoroutine, vAutoSelect} from "@/misc.js";
import {newLimitConstraint, newOrder, newTimeConstraint, TimeMode} from "@/blockchain/orderlib.js"; import {newOrder} from "@/blockchain/orderlib.js";
import {FixedNumber} from "ethers"; import {FixedNumber} from "ethers";
import {pendOrder} from "@/blockchain/wallet.js"; import {pendOrder} from "@/blockchain/wallet.js";
import NeedsProvider from "@/components/NeedsProvider.vue"; import NeedsProvider from "@/components/NeedsProvider.vue";
import RoutePrice from "@/components/RoutePrice.vue";
import router from "@/router/index.js"; import router from "@/router/index.js";
import PairChoice from "@/components/PairChoice.vue"; import PairChoice from "@/components/PairChoice.vue";
import {isEmpty, validateAmount, validateRequired} from "@/validate.js";
const s = useStore() const s = useStore()
const os = useOrderStore() const os = useOrderStore()
@@ -44,7 +41,7 @@ function placeOrder() {
const tokenIn = os.buy ? tb.address : ta.address const tokenIn = os.buy ? tb.address : ta.address
const tokenOut = os.buy ? ta.address : tb.address const tokenOut = os.buy ? ta.address : tb.address
const route = os.route const route = os.route
const amt = FixedNumber.fromString(os.amount.toString(), {decimals: os.amountToken.decimals}).value const amt = FixedNumber.fromString(os.totalAmount.toString(), {decimals: os.amountToken.decimals}).value
const ts = props.tranches() const ts = props.tranches()
const order = newOrder(tokenIn, tokenOut, route.exchange, route.fee, amt, os.amountIsInput, ts) const order = newOrder(tokenIn, tokenOut, route.exchange, route.fee, amt, os.amountIsInput, ts)
pendOrder(order) pendOrder(order)

View File

@@ -1,6 +1,6 @@
import {routeInverted} from "@/misc.js"; import {routeInverted} from "@/misc.js";
import {newLimitConstraint, newTimeConstraint, TimeMode} from "@/blockchain/orderlib.js"; import {newLimitConstraint, newTimeConstraint, TimeMode} from "@/blockchain/orderlib.js";
import {useOrderStore, useStore} from "@/store/store.js"; import {useOrderStore} from "@/store/store.js";
export const maxFraction = 65535n // by contract definition of uint16 fraction export const maxFraction = 65535n // by contract definition of uint16 fraction

View File

@@ -150,6 +150,8 @@ export const useOrderStore = defineStore('order', ()=> {
const limitIsMinimum = computed(() => !(buy.value ^ inverted.value)) const limitIsMinimum = computed(() => !(buy.value ^ inverted.value))
const amountToken = computed(() => amountIsTokenA.value ? tokenA.value : tokenB.value) const amountToken = computed(() => amountIsTokenA.value ? tokenA.value : tokenB.value)
const amountIsInput = computed(() => amountIsTokenA.value !== buy.value) const amountIsInput = computed(() => amountIsTokenA.value !== buy.value)
const totalAmount = computed(()=> amountIsTotal.value ? amount.value : amount.value * tranches.value )
const trancheAmount = computed(()=> amountIsTotal.value ? amount.value / tranches.value : amount.value )
function setDefaultTokens(tokens) { function setDefaultTokens(tokens) {
if( tokens.length > 0 ) if( tokens.length > 0 )
@@ -161,6 +163,6 @@ export const useOrderStore = defineStore('order', ()=> {
return { return {
tokenA, tokenB, buy, inverted, amount, amountIsTokenA, amountIsTotal, limitPrice, limitPrice2, tranches, tokenA, tokenB, buy, inverted, amount, amountIsTokenA, amountIsTotal, limitPrice, limitPrice2, tranches,
interval, intervalIsTotal, timeUnitIndex, routes, routesPending, validOrder, route, base, quote, pairSymbol, interval, intervalIsTotal, timeUnitIndex, routes, routesPending, validOrder, route, base, quote, pairSymbol,
limitIsMinimum, amountToken, amountIsInput, setDefaultTokens, limitIsMinimum, amountToken, amountIsInput, setDefaultTokens, totalAmount, trancheAmount,
} }
}) })