order placement doesnt crash
This commit is contained in:
@@ -53,6 +53,6 @@ export const vaultAbi = [
|
|||||||
'function withdrawTo(address payable,uint256) public',
|
'function withdrawTo(address payable,uint256) public',
|
||||||
'function withdraw(address,uint256) public',
|
'function withdraw(address,uint256) public',
|
||||||
'function withdrawTo(address,address,uint256) public',
|
'function withdrawTo(address,address,uint256) public',
|
||||||
'function placeOrder((address,address,(uint8,uint24),uint256,bool,bool,uint64,(uint64,(uint8,bytes)[])[])) public',
|
'function placeOrder((address,address,(uint8,uint24),uint256,bool,bool,uint64,(uint16,(uint8,bytes)[])[])) public',
|
||||||
'function placeOrders((address,address,(uint8,uint24),uint256,bool,bool,uint64,(uint64,(uint8,bytes)[])[])[],uint8) public',
|
'function placeOrders((address,address,(uint8,uint24),uint256,bool,bool,uint64,(uint16,(uint8,bytes)[])[])[],uint8) public',
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -29,12 +29,12 @@ export function newOrder(tokenIn, tokenOut, exchange, fee, amount, amountIsInput
|
|||||||
}
|
}
|
||||||
|
|
||||||
// struct Tranche {
|
// struct Tranche {
|
||||||
// uint64 fraction; // 18-decimal fraction of the order amount which is available to this tranche. must be <= 1
|
// uint64 fraction;
|
||||||
// Constraint[] constraints;
|
// Constraint[] constraints;
|
||||||
// }
|
// }
|
||||||
export function newTranche(amountRatio, constraints) {
|
export function newTranche(amountRatio, constraints) {
|
||||||
return [
|
return [
|
||||||
BigInt(Math.ceil(amountRatio * 10**18)), // we use ceil to make sure the sum of tranche fractions doesn't round below 1
|
BigInt(Math.min(65535, Math.ceil(amountRatio * 65535))), // we use ceil to make sure the sum of tranche fractions doesn't round below 1
|
||||||
constraints
|
constraints
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export let provider = null
|
|||||||
|
|
||||||
export function onChainChanged(chainId) {
|
export function onChainChanged(chainId) {
|
||||||
chainId = Number(chainId)
|
chainId = Number(chainId)
|
||||||
// console.log('chain changed', chainId)
|
console.log('chain changed', chainId)
|
||||||
const store = useStore()
|
const store = useStore()
|
||||||
if( chainId !== store.chainId ) {
|
if( chainId !== store.chainId ) {
|
||||||
store.chainId = chainId
|
store.chainId = chainId
|
||||||
@@ -29,8 +29,8 @@ function onAccountsChanged(accounts) {
|
|||||||
else if (accounts[0] !== store.account) {
|
else if (accounts[0] !== store.account) {
|
||||||
store.account = accounts[0].address
|
store.account = accounts[0].address
|
||||||
flushOrders()
|
flushOrders()
|
||||||
|
socket.emit('address', store.chainId, accounts[0].address)
|
||||||
}
|
}
|
||||||
socket.emit('address', store.chainId, accounts[0].address)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function watchWallet() {
|
export async function watchWallet() {
|
||||||
@@ -79,7 +79,7 @@ export async function connectWallet() {
|
|||||||
|
|
||||||
|
|
||||||
export async function pendOrder(order) {
|
export async function pendOrder(order) {
|
||||||
console.log('order', order)
|
console.log('order', JSON.stringify(order))
|
||||||
const s = useStore()
|
const s = useStore()
|
||||||
s.pendingOrders.push(order)
|
s.pendingOrders.push(order)
|
||||||
const signer = await connectWallet()
|
const signer = await connectWallet()
|
||||||
@@ -98,18 +98,40 @@ export function flushOrders() {
|
|||||||
export async function asyncFlushOrders() {
|
export async function asyncFlushOrders() {
|
||||||
const s = useStore()
|
const s = useStore()
|
||||||
const orders = s.pendingOrders
|
const orders = s.pendingOrders
|
||||||
if(!orders.length || !s.account)
|
if (!orders.length)
|
||||||
return
|
return
|
||||||
const contract = await vaultContract(0, await provider.getSigner())
|
let signer
|
||||||
if( !contract )
|
try {
|
||||||
|
signer = await provider.getSigner();
|
||||||
|
} catch (e) {
|
||||||
|
console.log('signer denied')
|
||||||
return
|
return
|
||||||
const proms = []
|
}
|
||||||
|
const contract = await vaultContract(0, signer)
|
||||||
|
if (!contract) {
|
||||||
|
console.error(`no contract for vault 0 of ${signer.address}`)
|
||||||
|
return
|
||||||
|
}
|
||||||
for (const order of orders)
|
for (const order of orders)
|
||||||
proms.push(contract.placeOrder(order))
|
doPlaceOrder(s, contract, order)
|
||||||
s.pendingOrders = []
|
}
|
||||||
const txs = await Promise.all(proms)
|
|
||||||
for( const tx of txs )
|
function doPlaceOrder(s, contract, order) {
|
||||||
|
contract.placeOrder(order).then((tx)=>{
|
||||||
console.log('placed order', tx)
|
console.log('placed order', tx)
|
||||||
|
s.removePendingOrder(order)
|
||||||
|
tx.wait().then((tr)=>console.log('tx receipt',tr))
|
||||||
|
}).catch((e)=>{
|
||||||
|
if( e.info.error.code === 4001 ) {
|
||||||
|
console.log(`user rejected order`, order)
|
||||||
|
s.removePendingOrder(order)
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
console.error('error placing order', order, e.reason, e.info)
|
||||||
|
s.removePendingOrder(order)
|
||||||
|
// todo retry?
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
socket.on('vaults', (vaults)=>{
|
socket.on('vaults', (vaults)=>{
|
||||||
|
|||||||
@@ -1,15 +1,19 @@
|
|||||||
<template>
|
<template>
|
||||||
|
<!-- <v-card v-if="!s.account" prepend-icon="mdi-connection" title="Connect Wallet"-->
|
||||||
|
<!-- text="Please connect your wallet to an Arbitrum account.">-->
|
||||||
|
<!-- <v-card-actions><v-btn text="Connect Wallet" color="green" variant="elevated" @click="connectWallet" prepend-icon="mdi-power"/></v-card-actions>-->
|
||||||
|
<!-- </v-card>-->
|
||||||
<slot v-if="s.helper"/>
|
<slot v-if="s.helper"/>
|
||||||
<v-card v-if="!s.helper" prepend-icon='mdi-reload-alert' title="Change Blockchain" text="Dexorder works only with Arbitrum. Please choose the Arbitrum blockchain in your wallet."/>
|
<v-card v-if="!s.helper" prepend-icon='mdi-reload-alert' title="Change Blockchain"
|
||||||
|
text="Dexorder works only with Arbitrum. Please choose the Arbitrum blockchain in your wallet."/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {useStore} from "@/store/store";
|
import {useStore} from "@/store/store";
|
||||||
|
import {connectWallet} from "@/blockchain/wallet.js";
|
||||||
|
|
||||||
const s = useStore()
|
const s = useStore()
|
||||||
|
|
||||||
async function connect() {
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ async function findRoute() {
|
|||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
routes.value = []
|
routes.value = []
|
||||||
// console.log('routes exception', e)
|
console.log('routes exception', e)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// todo expose all available pools
|
// todo expose all available pools
|
||||||
@@ -178,6 +178,7 @@ async function findRoute() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
routes.value = [result]
|
routes.value = [result]
|
||||||
|
console.log('found route', result)
|
||||||
}
|
}
|
||||||
|
|
||||||
const routeFinder = new SingletonCoroutine(findRoute,10)
|
const routeFinder = new SingletonCoroutine(findRoute,10)
|
||||||
@@ -245,7 +246,7 @@ async function placeOrder() {
|
|||||||
const route = routes.value[0];
|
const route = routes.value[0];
|
||||||
const amountToken = amountIsTokenA ? ta : tb
|
const amountToken = amountIsTokenA ? ta : tb
|
||||||
const amt = FixedNumber.fromString(amount.value.toString(), {decimals: amountToken.decimals}).value
|
const amt = FixedNumber.fromString(amount.value.toString(), {decimals: amountToken.decimals}).value
|
||||||
const amountIsInput = !buy.value ^ amountIsTokenA.value
|
const amountIsInput = amountIsTokenA.value === buy.value
|
||||||
|
|
||||||
// build tranches
|
// build tranches
|
||||||
const n = tranches.value // num tranches
|
const n = tranches.value // num tranches
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ import '@/styles/style.scss'
|
|||||||
import {watchWallet} from "@/blockchain/wallet.js";
|
import {watchWallet} from "@/blockchain/wallet.js";
|
||||||
import "./socket.js"
|
import "./socket.js"
|
||||||
|
|
||||||
|
BigInt.prototype.toJSON = function() { return this.toString() }
|
||||||
|
|
||||||
const app = createApp(App)
|
const app = createApp(App)
|
||||||
registerPlugins(app)
|
registerPlugins(app)
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,9 @@ export const useStore = defineStore('app', {
|
|||||||
helper: (s)=>!s.chain?null:s.chain.helper,
|
helper: (s)=>!s.chain?null:s.chain.helper,
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
|
removePendingOrder(order) {
|
||||||
|
this.pendingOrders = this.pendingOrders.filter((v) => v !== order)
|
||||||
|
},
|
||||||
error(title, text, closeable=true) {
|
error(title, text, closeable=true) {
|
||||||
this.errors.push({title, text, closeable})
|
this.errors.push({title, text, closeable})
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user