Skip to content

Commit

Permalink
Merge pull request #81 from securesecrets/develop
Browse files Browse the repository at this point in the history
null pair info and unbound function on stableswap math
  • Loading branch information
AustinWoetzel authored Jan 24, 2024
2 parents 730b920 + 21669fc commit 94f9736
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/perfect-kangaroos-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shadeprotocol/shadejs": patch
---

handle null stableswap price ratio
5 changes: 5 additions & 0 deletions .changeset/short-worms-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shadeprotocol/shadejs": patch
---

fix unbound function in stableswap math
4 changes: 3 additions & 1 deletion docs/queries/swap.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,9 @@ type PairInfo = {
}
type StableParams = {
priceRatio: string,
priceRatio: string | null, // Null priceRatio caused by
// oracle issues, typically stale oracle data. Swaps are not possible
// while priceRatio is null
alpha: string,
gamma1: string,
gamma2: string,
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/services/swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ function parsePairInfo(
daoFee: pairInfo.pair[2] ? fees.stable_shade_dao_fee.nom / fees.stable_shade_dao_fee.denom
: fees.shade_dao_fee.nom / fees.shade_dao_fee.denom,
stableParams: stableInfo ? {
priceRatio: stableInfo.p!, // if stable params exist, we know price ratio will be available
priceRatio: stableInfo.p,
alpha: stableInfo.stable_params.a,
gamma1: stableInfo.stable_params.gamma1,
gamma2: stableInfo.stable_params.gamma2,
Expand Down
4 changes: 4 additions & 0 deletions src/lib/swap/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ function calculateRoute({
if (isStable && stableParams) {
poolMultiplier = GasMultiplier.STABLE;

if (!stableParams.priceRatio) {
throw new Error('PriceRatio not available: Oracle Error');
}

// token0 as the input
if (currentTokenContractAddress === token0Contract.address) {
const swapParams = {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/swap/stableswapCurve/stable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ export class StableConfig {
initialGuessNewton: tvl,
upperBoundBisect: tvl,
ignoreNegativeResult: true,
lazyLowerBoundBisect: this.geometricMeanDoubled,
lazyLowerBoundBisect: this.geometricMeanDoubled.bind(this),
lowerBoundBisect: undefined,
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/contracts/swap/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type StableTokenData = {
}

type StableParams = {
priceRatio: string,
priceRatio: string | null,
alpha: string,
gamma1: string,
gamma2: string,
Expand Down

0 comments on commit 94f9736

Please sign in to comment.