diff --git a/package.json b/package.json index fe6807b..531bf94 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@notional-finance/sdk-v2", - "version": "0.5.0-beta.32", + "version": "0.5.1", "description": "Notional Finance SDK V2", "author": "Jeff Wu ", "homepage": "https://notional.finance", diff --git a/src/system/Market.ts b/src/system/Market.ts index 4a0a8ab..490e2c3 100644 --- a/src/system/Market.ts +++ b/src/system/Market.ts @@ -519,10 +519,13 @@ export default class Market { // Calculate derivative let delta = BigNumber.from(0); + let numLoops = 0; do { const exchangeRate = this.getExchangeRate(totalCashUnderlying, rateScalar, rateAnchor, fCashGuess); delta = this.calculateDelta(cashAmount, rateScalar, fCashGuess, totalCashUnderlying, exchangeRate, feeRate); fCashGuess = TypedBigNumber.from(fCashGuess.n.sub(delta), fCashGuess.type, fCashGuess.symbol); + if (numLoops > 200) throw Error('Rate calculation did not converge'); + numLoops += 1; } while (delta.abs().gt(0)); return fCashGuess;