DCABuilder slippage parameter fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import {uint32max, uint64max} from "@/misc.js";
|
import {uint32max, uint64max} from "@/misc.js";
|
||||||
import {encodeIEE754} from "@/common.js";
|
import {encodeIEE754} from "@/common.js";
|
||||||
|
import {DEFAULT_SLIPPAGE} from "@/orderbuild.js";
|
||||||
|
|
||||||
export const MAX_FRACTION = 65535;
|
export const MAX_FRACTION = 65535;
|
||||||
export const NO_CONDITIONAL_ORDER = uint64max;
|
export const NO_CONDITIONAL_ORDER = uint64max;
|
||||||
@@ -86,6 +87,10 @@ export function newTranche({
|
|||||||
if( marketOrder ) {
|
if( marketOrder ) {
|
||||||
if (minIntercept !== 0 || minSlope !== 0 || maxIntercept !== 0 || maxSlope !== 0)
|
if (minIntercept !== 0 || minSlope !== 0 || maxIntercept !== 0 || maxSlope !== 0)
|
||||||
console.warn('Ignoring line information in a market order')
|
console.warn('Ignoring line information in a market order')
|
||||||
|
if (slippage === 0) {
|
||||||
|
console.warn(`setting market order slippage to ${DEFAULT_SLIPPAGE}`)
|
||||||
|
slippage = DEFAULT_SLIPPAGE
|
||||||
|
}
|
||||||
minIntercept = encodeIEE754(slippage) // this is the slippage field for market orders
|
minIntercept = encodeIEE754(slippage) // this is the slippage field for market orders
|
||||||
minSlope = 0
|
minSlope = 0
|
||||||
maxIntercept = 0
|
maxIntercept = 0
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import {nav, uuid} from "@/misc.js";
|
import {nav, sleep, uuid} from "@/misc.js";
|
||||||
import {vaultContract} from "@/blockchain/contract.js";
|
import {vaultContract} from "@/blockchain/contract.js";
|
||||||
import {ensureVault, provider, switchChain, useWalletStore} from "@/blockchain/wallet.js";
|
import {ensureVault, provider, switchChain, useWalletStore} from "@/blockchain/wallet.js";
|
||||||
import {toRaw} from "vue";
|
import {toRaw} from "vue";
|
||||||
@@ -128,9 +128,15 @@ export class Transaction {
|
|||||||
this.failed('vault contract was null while sending order transaction')
|
this.failed('vault contract was null while sending order transaction')
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
const tx = toRaw(await this.createTx(contract))
|
const tx = toRaw(await this.createTx(contract))
|
||||||
this.signed(tx)
|
this.signed(tx)
|
||||||
console.log(`sent transaction`, tx)
|
console.log(`sent transaction`, tx)
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
this.failed(e)
|
||||||
|
return null
|
||||||
|
}
|
||||||
tx.wait().then(this.mined.bind(this)).catch(this.failed.bind(this))
|
tx.wait().then(this.mined.bind(this)).catch(this.failed.bind(this))
|
||||||
return this.tx
|
return this.tx
|
||||||
}
|
}
|
||||||
@@ -159,7 +165,20 @@ export class PlaceOrderTransaction extends Transaction {
|
|||||||
|
|
||||||
|
|
||||||
async createTx(vaultContract) {
|
async createTx(vaultContract) {
|
||||||
this.fee = await placementFee(this.vault, this.order)
|
const tries = 3;
|
||||||
|
let i;
|
||||||
|
for (i=0; i<tries; i++ ) {
|
||||||
|
try {
|
||||||
|
this.fee = await placementFee(vaultContract, this.order)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
console.warn('failed to get placement fee', e)
|
||||||
|
await sleep(1000)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i===tries)
|
||||||
|
throw Error('failed to get placement fee')
|
||||||
console.log('placing order', this.id, this.fee, this.order)
|
console.log('placing order', this.id, this.fee, this.order)
|
||||||
return await vaultContract.placeDexorder(this.order, {value: this.fee.reduce((a, b) => a + b)})
|
return await vaultContract.placeDexorder(this.order, {value: this.fee.reduce((a, b) => a + b)})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,8 +75,11 @@ function changeAccounts(chainId, accounts) {
|
|||||||
console.log('account logged in', addr)
|
console.log('account logged in', addr)
|
||||||
store.account = addr
|
store.account = addr
|
||||||
store.vaults = []
|
store.vaults = []
|
||||||
|
// one of these two methods will call flushTransactions()
|
||||||
|
if (useWalletStore().transaction!==null)
|
||||||
|
ensureVault()
|
||||||
|
else
|
||||||
discoverVaults(addr)
|
discoverVaults(addr)
|
||||||
flushTransactions()
|
|
||||||
socket.emit('address', chainId, addr)
|
socket.emit('address', chainId, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,6 +218,7 @@ async function _discoverVaults(owner) {
|
|||||||
return // do not change what was already found todo is this correct?
|
return // do not change what was already found todo is this correct?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log('new account === owner?', s.account, owner)
|
||||||
if( s.account === owner ) { // double-check the account since it could have changed during our await
|
if( s.account === owner ) { // double-check the account since it could have changed during our await
|
||||||
s.vaults = result
|
s.vaults = result
|
||||||
s.vaultVersions = versions
|
s.vaultVersions = versions
|
||||||
@@ -291,6 +295,7 @@ export async function cancelAll(vault) {
|
|||||||
|
|
||||||
export function flushOrders(chainId, owner, num, vault) {
|
export function flushOrders(chainId, owner, num, vault) {
|
||||||
const ws = useWalletStore();
|
const ws = useWalletStore();
|
||||||
|
console.log('flushOrders', ws.transaction)
|
||||||
if (ws.transaction!==null && ws.transaction.state < TransactionState.Proposed)
|
if (ws.transaction!==null && ws.transaction.state < TransactionState.Proposed)
|
||||||
ws.transaction.propose(owner, vault)
|
ws.transaction.propose(owner, vault)
|
||||||
let needsFlush = false
|
let needsFlush = false
|
||||||
@@ -376,6 +381,22 @@ export function flushTransactions() {
|
|||||||
|
|
||||||
async function asyncFlushTransactions() {
|
async function asyncFlushTransactions() {
|
||||||
const s = useStore()
|
const s = useStore()
|
||||||
|
const ws = useWalletStore()
|
||||||
|
console.log('flushTransactions', ws.transaction, s.vault)
|
||||||
|
if (ws.transaction !== null) {
|
||||||
|
if (s.vault === null) {
|
||||||
|
await ensureVault()
|
||||||
|
if (s.vault === null) {
|
||||||
|
console.error('vault could not be created')
|
||||||
|
const tx = ws.transaction
|
||||||
|
if (tx) {
|
||||||
|
tx.state = TransactionState.Error
|
||||||
|
ws.transaction = null
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if( provider === null ) {
|
if( provider === null ) {
|
||||||
console.log('warning: asyncFlushOrders() cancelled due to null provider')
|
console.log('warning: asyncFlushOrders() cancelled due to null provider')
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -102,7 +102,8 @@ function buildTranches() {
|
|||||||
const endTime = Math.ceil(props.builder.endTime + 10*props.builder.tranches)
|
const endTime = Math.ceil(props.builder.endTime + 10*props.builder.tranches)
|
||||||
const startTime = Math.floor(props.builder.startTime);
|
const startTime = Math.floor(props.builder.startTime);
|
||||||
const tranches = [newTranche({marketOrder:true,
|
const tranches = [newTranche({marketOrder:true,
|
||||||
startTime, endTime, rateLimitFraction: rate, rateLimitPeriod: Math.floor(interval)})]
|
startTime, endTime, rateLimitFraction: rate, rateLimitPeriod: Math.floor(interval),
|
||||||
|
slippage: props.builder.slippage})]
|
||||||
return {tranches, warnings}
|
return {tranches, warnings}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,11 @@ export async function getFeeSchedule(vaultAddr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function placementFee(vaultAddr, order, window = 300) {
|
export async function placementFee(vaultContractOrAddr, 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.
|
||||||
// If the fees sent are too much, the vault will refund the sender.
|
// If the fees sent are too much, the vault will refund the sender.
|
||||||
const vault = await vaultContract(vaultAddr, provider)
|
console.log('placementFee', vaultContractOrAddr, order)
|
||||||
|
const vault = typeof vaultContractOrAddr === 'string' ? await vaultContract(vaultContractOrAddr, provider) : vaultContractOrAddr
|
||||||
const feeManager = await getFeeManagerContract(vault);
|
const feeManager = await getFeeManagerContract(vault);
|
||||||
const [sched, changeTimestamp] = await Promise.all([feeManager.fees(), feeManager.proposedFeeActivationTime()])
|
const [sched, changeTimestamp] = await Promise.all([feeManager.fees(), feeManager.proposedFeeActivationTime()])
|
||||||
console.log('sched', order, sched)
|
console.log('sched', order, sched)
|
||||||
|
|||||||
@@ -4,7 +4,8 @@
|
|||||||
<v-dialog v-model="showTransactionDialog" max-width="300">
|
<v-dialog v-model="showTransactionDialog" max-width="300">
|
||||||
<v-card :title="title">
|
<v-card :title="title">
|
||||||
<v-card-text v-if="description!==null">{{description}}</v-card-text>
|
<v-card-text v-if="description!==null">{{description}}</v-card-text>
|
||||||
<v-card-text>Confirm this {{noun}} in your wallet.</v-card-text>
|
<v-card-text v-if="s.vault">Confirm this {{noun}} in your wallet.</v-card-text>
|
||||||
|
<v-card-text v-if="!s.vault">Creating your trading vault smart contract. Please wait a few seconds...</v-card-text>
|
||||||
</v-card>
|
</v-card>
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
</v-app>
|
</v-app>
|
||||||
|
|||||||
Reference in New Issue
Block a user