diff --git a/src/blockchain/abi.js b/src/blockchain/abi.js index f8de743..8bfd844 100644 --- a/src/blockchain/abi.js +++ b/src/blockchain/abi.js @@ -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', ] diff --git a/src/blockchain/orderlib.js b/src/blockchain/orderlib.js index 2ce976e..85b4207 100644 --- a/src/blockchain/orderlib.js +++ b/src/blockchain/orderlib.js @@ -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 ] } diff --git a/src/blockchain/wallet.js b/src/blockchain/wallet.js index 7c7de7b..89a845c 100644 --- a/src/blockchain/wallet.js +++ b/src/blockchain/wallet.js @@ -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)=>{ diff --git a/src/components/NeedsQueryHelper.vue b/src/components/NeedsQueryHelper.vue index 0668896..a692ddd 100644 --- a/src/components/NeedsQueryHelper.vue +++ b/src/components/NeedsQueryHelper.vue @@ -1,15 +1,19 @@