From 3c21d34aeafeee144c9a6fe5fb78dccd485ffac8 Mon Sep 17 00:00:00 2001 From: peroxy Date: Mon, 20 Nov 2023 11:19:21 +0100 Subject: [PATCH] Add validation for twaps --- packages/kamino-sdk/src/Kamino.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/kamino-sdk/src/Kamino.ts b/packages/kamino-sdk/src/Kamino.ts index 7f6776ac..b667b903 100644 --- a/packages/kamino-sdk/src/Kamino.ts +++ b/packages/kamino-sdk/src/Kamino.ts @@ -1810,19 +1810,23 @@ export class Kamino { const bPrice = await this._scope.getPriceFromChain(tokenB.scopePriceChain, prices); const tokenATwap = stripTwapZeros(tokenA.scopeTwapPriceChain); const tokenBTwap = stripTwapZeros(tokenB.scopeTwapPriceChain); - const aTwapPrice = tokenATwap.length > 0 ? await this._scope.getPriceFromChain(tokenATwap, prices) : null; - const bTwapPrice = tokenBTwap.length > 0 ? await this._scope.getPriceFromChain(tokenBTwap, prices) : null; + const aTwapPrice = Scope.isScopeChainValid(tokenATwap) + ? await this._scope.getPriceFromChain(tokenATwap, prices) + : null; + const bTwapPrice = Scope.isScopeChainValid(tokenBTwap) + ? await this._scope.getPriceFromChain(tokenBTwap, prices) + : null; const reward0Price = - strategy.reward0Decimals.toNumber() !== 0 + strategy.reward0Decimals.toNumber() !== 0 && Scope.isScopeChainValid(rewardToken0.scopePriceChain) ? await this._scope.getPriceFromChain(rewardToken0.scopePriceChain, prices) : null; const reward1Price = - strategy.reward1Decimals.toNumber() !== 0 + strategy.reward1Decimals.toNumber() !== 0 && Scope.isScopeChainValid(rewardToken1.scopePriceChain) ? await this._scope.getPriceFromChain(rewardToken1.scopePriceChain, prices) : null; const reward2Price = - strategy.reward2Decimals.toNumber() !== 0 + strategy.reward2Decimals.toNumber() !== 0 && Scope.isScopeChainValid(rewardToken2.scopePriceChain) ? await this._scope.getPriceFromChain(rewardToken2.scopePriceChain, prices) : null;