diff --git a/.changeset/perfect-kangaroos-hunt.md b/.changeset/perfect-kangaroos-hunt.md new file mode 100644 index 0000000..fdb1455 --- /dev/null +++ b/.changeset/perfect-kangaroos-hunt.md @@ -0,0 +1,5 @@ +--- +"@shadeprotocol/shadejs": patch +--- + +handle null stableswap price ratio diff --git a/docs/queries/swap.md b/docs/queries/swap.md index 8d3a524..830e6c0 100644 --- a/docs/queries/swap.md +++ b/docs/queries/swap.md @@ -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, diff --git a/src/contracts/services/swap.ts b/src/contracts/services/swap.ts index 2d26319..c3a62e1 100644 --- a/src/contracts/services/swap.ts +++ b/src/contracts/services/swap.ts @@ -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, diff --git a/src/lib/swap/router.ts b/src/lib/swap/router.ts index 15de5fb..c0d8f90 100644 --- a/src/lib/swap/router.ts +++ b/src/lib/swap/router.ts @@ -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 = { diff --git a/src/types/contracts/swap/model.ts b/src/types/contracts/swap/model.ts index a2b2015..ba38651 100644 --- a/src/types/contracts/swap/model.ts +++ b/src/types/contracts/swap/model.ts @@ -60,7 +60,7 @@ type StableTokenData = { } type StableParams = { - priceRatio: string, + priceRatio: string | null, alpha: string, gamma1: string, gamma2: string,