@@ -203,22 +203,57 @@ export async function reticketPointBetweenWallets({
203203
204204 progress(TRANSACTION_PROGRESS.TRANSFERRING);
205205
206− await sendAndAwaitAllSerial(
206+ const receipts = await sendAndAwaitAllSerial(
207207 web3,
208208 txPairs.map(p => p.signed),
209209 usedTank
210210 );
211211
212+ const realCost = gasPriceWeiBN.mul(
213+ receipts.reduce((sum, receipt) => {
214+ return sum.add(toBN(receipt.gasUsed));
215+ }, toBN(0))
216+ );
217+
212218 //
213219 // move leftover eth
214220 //
215221
216222 progress(TRANSACTION_PROGRESS.CLEANING);
217223
218− // if non-trivial eth left in invite wallet, transfer to new ownership
219224 let balance = toBN(await web3.eth.getBalance(fromWallet.address));
220225 const gasLimit = GAS_LIMITS.SEND_ETH;
221226 const sendEthCost = gasPriceWeiBN.mul(toBN(gasLimit));
227+
228+ // if we have funds left over from what the gas tank gave us, send those back
229+ if (usedTank && realCost.add(sendEthCost).lt(totalCost)) {
230+ try {
231+ const remainder = totalCost.sub(realCost).sub(sendEthCost);
232+ console.log('returning to gas tank', remainder.toString());
233+ const txn = { to: tank.TANK_ADDRESS, value: remainder };
234+ const stx = await signTransaction({
235+ wallet: fromWallet,
236+ walletType: fromWalletType,
237+ walletHdPath: fromWalletHdPath,
238+ txn,
239+ chainId,
240+ networkType,
241+ gasPrice: gasPriceGwei,
242+ gasLimit,
243+ nonce: inviteNonce,
244+ });
245+ sendSignedTransaction(web3, stx);
246+
247+ // only update these after the above succeeded
248+ inviteNonce++;
249+ balance = balance.sub(remainder).sub(sendEthCost);
250+ } catch (err) {
251+ console.log('error returning gas, safely ignored:');
252+ console.log(err);
253+ }
254+ }
255+
256+ // if non-trivial eth left in invite wallet, transfer to new ownership
222257 if (transferEth && balance.gt(sendEthCost)) {
223258 try {
224259 const value = balance.sub(sendEthCost);