Skip to content

Commit

Permalink
Bugfix/throw error on divergence (#83)
Browse files Browse the repository at this point in the history
* throw an error if iterate rates does not converge

* update package version

* removing unary ++
  • Loading branch information
jeffywu authored May 18, 2022
1 parent 0ba1f9c commit 39f1dd1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <jeff@notional.finance>",
"homepage": "https://notional.finance",
Expand Down
3 changes: 3 additions & 0 deletions src/system/Market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 39f1dd1

Please sign in to comment.