Skip to content

Commit

Permalink
fix: handle null price ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
AustinWoetzel committed Jan 24, 2024
1 parent 61cda23 commit 066773d
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 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
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/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 066773d

Please sign in to comment.