From 85ce625f8330a9386262d457a3d47b60912452f5 Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Thu, 12 Dec 2024 14:44:42 -0500 Subject: [PATCH] chore: only use try/catch when commit phase is not atomic - see https://github.com/Agoric/agoric-sdk/pull/10659/commits/e33f9e8d3c66fab4ca8a70816f21d1f79deb3044#r1878631017 - note: try/catch/finally remains for `borrow()` and `deposit()` so we can exit seats --- packages/fast-usdc/src/exos/liquidity-pool.js | 54 +++++++------------ 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/packages/fast-usdc/src/exos/liquidity-pool.js b/packages/fast-usdc/src/exos/liquidity-pool.js index 21a7f612dfd..6c5b64fe02b 100644 --- a/packages/fast-usdc/src/exos/liquidity-pool.js +++ b/packages/fast-usdc/src/exos/liquidity-pool.js @@ -171,13 +171,7 @@ export const prepareLiquidityPoolKit = (zone, zcf, USDC, tools) => { ); // COMMIT POINT - try { - zcf.atomicRearrange(harden([[poolSeat, toSeat, amountKWR]])); - } catch (cause) { - const reason = Error('🚨 cannot commit borrow', { cause }); - console.error(reason.message, cause); - zcf.shutdownWithFailure(reason); - } + zcf.atomicRearrange(harden([[poolSeat, toSeat, amountKWR]])); Object.assign(this.state, post); this.facets.external.publishPoolMetrics(); @@ -233,23 +227,17 @@ export const prepareLiquidityPoolKit = (zone, zcf, USDC, tools) => { const { ContractFee, ...rest } = amounts; // COMMIT POINT - try { - zcf.atomicRearrange( - harden([ - [ - fromSeat, - poolSeat, - rest, - { USDC: add(amounts.PoolFee, amounts.Principal) }, - ], - [fromSeat, feeSeat, { ContractFee }, { USDC: ContractFee }], - ]), - ); - } catch (cause) { - const reason = Error('🚨 cannot commit repay', { cause }); - console.error(reason.message, cause); - zcf.shutdownWithFailure(reason); - } + zcf.atomicRearrange( + harden([ + [ + fromSeat, + poolSeat, + rest, + { USDC: add(amounts.PoolFee, amounts.Principal) }, + ], + [fromSeat, feeSeat, { ContractFee }, { USDC: ContractFee }], + ]), + ); Object.assign(this.state, post); this.facets.external.publishPoolMetrics(); @@ -284,9 +272,8 @@ export const prepareLiquidityPoolKit = (zone, zcf, USDC, tools) => { const post = depositCalc(shareWorth, proposal); // COMMIT POINT - + const mint = shareMint.mintGains(post.payouts); try { - const mint = shareMint.mintGains(post.payouts); this.state.shareWorth = post.shareWorth; zcf.atomicRearrange( harden([ @@ -296,12 +283,11 @@ export const prepareLiquidityPoolKit = (zone, zcf, USDC, tools) => { [mint, lp, post.payouts], ]), ); + } catch (cause) { + throw new Error('🚨 cannot commit deposit', { cause }); + } finally { lp.exit(); mint.exit(); - } catch (cause) { - const reason = Error('🚨 cannot commit deposit', { cause }); - console.error(reason.message, cause); - zcf.shutdownWithFailure(reason); } external.publishPoolMetrics(); }, @@ -321,7 +307,6 @@ export const prepareLiquidityPoolKit = (zone, zcf, USDC, tools) => { const post = withdrawCalc(shareWorth, proposal); // COMMIT POINT - try { this.state.shareWorth = post.shareWorth; zcf.atomicRearrange( @@ -333,12 +318,11 @@ export const prepareLiquidityPoolKit = (zone, zcf, USDC, tools) => { ]), ); shareMint.burnLosses(proposal.give, burn); + } catch (cause) { + throw new Error('🚨 cannot commit withdraw', { cause }); + } finally { lp.exit(); burn.exit(); - } catch (cause) { - const reason = Error('🚨 cannot commit withdraw', { cause }); - console.error(reason.message, cause); - zcf.shutdownWithFailure(reason); } external.publishPoolMetrics(); },