order placement doesnt crash
This commit is contained in:
@@ -53,6 +53,6 @@ export const vaultAbi = [
|
||||
'function withdrawTo(address payable,uint256) public',
|
||||
'function withdraw(address,uint256) public',
|
||||
'function withdrawTo(address,address,uint256) public',
|
||||
'function placeOrder((address,address,(uint8,uint24),uint256,bool,bool,uint64,(uint64,(uint8,bytes)[])[])) public',
|
||||
'function placeOrders((address,address,(uint8,uint24),uint256,bool,bool,uint64,(uint64,(uint8,bytes)[])[])[],uint8) 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,(uint16,(uint8,bytes)[])[])[],uint8) public',
|
||||
]
|
||||
|
||||
@@ -29,12 +29,12 @@ export function newOrder(tokenIn, tokenOut, exchange, fee, amount, amountIsInput
|
||||
}
|
||||
|
||||
// struct Tranche {
|
||||
// uint64 fraction; // 18-decimal fraction of the order amount which is available to this tranche. must be <= 1
|
||||
// uint64 fraction;
|
||||
// Constraint[] constraints;
|
||||
// }
|
||||
export function newTranche(amountRatio, constraints) {
|
||||
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
|
||||
]
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ export let provider = null
|
||||
|
||||
export function onChainChanged(chainId) {
|
||||
chainId = Number(chainId)
|
||||
// console.log('chain changed', chainId)
|
||||
console.log('chain changed', chainId)
|
||||
const store = useStore()
|
||||
if( chainId !== store.chainId ) {
|
||||
store.chainId = chainId
|
||||
@@ -29,8 +29,8 @@ function onAccountsChanged(accounts) {
|
||||
else if (accounts[0] !== store.account) {
|
||||
store.account = accounts[0].address
|
||||
flushOrders()
|
||||
socket.emit('address', store.chainId, accounts[0].address)
|
||||
}
|
||||
socket.emit('address', store.chainId, accounts[0].address)
|
||||
}
|
||||
|
||||
export async function watchWallet() {
|
||||
@@ -79,7 +79,7 @@ export async function connectWallet() {
|
||||
|
||||
|
||||
export async function pendOrder(order) {
|
||||
console.log('order', order)
|
||||
console.log('order', JSON.stringify(order))
|
||||
const s = useStore()
|
||||
s.pendingOrders.push(order)
|
||||
const signer = await connectWallet()
|
||||
@@ -98,18 +98,40 @@ export function flushOrders() {
|
||||
export async function asyncFlushOrders() {
|
||||
const s = useStore()
|
||||
const orders = s.pendingOrders
|
||||
if(!orders.length || !s.account)
|
||||
if (!orders.length)
|
||||
return
|
||||
const contract = await vaultContract(0, await provider.getSigner())
|
||||
if( !contract )
|
||||
let signer
|
||||
try {
|
||||
signer = await provider.getSigner();
|
||||
} catch (e) {
|
||||
console.log('signer denied')
|
||||
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)
|
||||
proms.push(contract.placeOrder(order))
|
||||
s.pendingOrders = []
|
||||
const txs = await Promise.all(proms)
|
||||
for( const tx of txs )
|
||||
doPlaceOrder(s, contract, order)
|
||||
}
|
||||
|
||||
function doPlaceOrder(s, contract, order) {
|
||||
contract.placeOrder(order).then((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)=>{
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
<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"/>
|
||||
<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>
|
||||
|
||||
<script setup>
|
||||
import {useStore} from "@/store/store";
|
||||
import {connectWallet} from "@/blockchain/wallet.js";
|
||||
|
||||
const s = useStore()
|
||||
|
||||
async function connect() {
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
@@ -159,7 +159,7 @@ async function findRoute() {
|
||||
}
|
||||
catch (e) {
|
||||
routes.value = []
|
||||
// console.log('routes exception', e)
|
||||
console.log('routes exception', e)
|
||||
return
|
||||
}
|
||||
// todo expose all available pools
|
||||
@@ -178,6 +178,7 @@ async function findRoute() {
|
||||
}
|
||||
}
|
||||
routes.value = [result]
|
||||
console.log('found route', result)
|
||||
}
|
||||
|
||||
const routeFinder = new SingletonCoroutine(findRoute,10)
|
||||
@@ -245,7 +246,7 @@ async function placeOrder() {
|
||||
const route = routes.value[0];
|
||||
const amountToken = amountIsTokenA ? ta : tb
|
||||
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
|
||||
const n = tranches.value // num tranches
|
||||
|
||||
@@ -16,6 +16,8 @@ import '@/styles/style.scss'
|
||||
import {watchWallet} from "@/blockchain/wallet.js";
|
||||
import "./socket.js"
|
||||
|
||||
BigInt.prototype.toJSON = function() { return this.toString() }
|
||||
|
||||
const app = createApp(App)
|
||||
registerPlugins(app)
|
||||
|
||||
|
||||
@@ -30,6 +30,9 @@ export const useStore = defineStore('app', {
|
||||
helper: (s)=>!s.chain?null:s.chain.helper,
|
||||
},
|
||||
actions: {
|
||||
removePendingOrder(order) {
|
||||
this.pendingOrders = this.pendingOrders.filter((v) => v !== order)
|
||||
},
|
||||
error(title, text, closeable=true) {
|
||||
this.errors.push({title, text, closeable})
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user