Skip to content

Commit f80c5df

Browse files
authored
Fixed Morpho reward resolver (#1788)
* Add non ideal state * Fix morpho rewards resolver
1 parent 8580d03 commit f80c5df

File tree

2 files changed

+23
-4
lines changed
  • apps/hyperdrive-trading/src/ui/markets/PoolsList
  • packages/hyperdrive-appconfig/src/rewards/resolvers

2 files changed

+23
-4
lines changed

apps/hyperdrive-trading/src/ui/markets/PoolsList/PoolsList.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,12 @@ export function PoolsList(): ReactElement {
225225
</Fade>
226226
)}
227227
</>
228-
) : null}
228+
) : (
229+
<NonIdealState
230+
heading="Error loading pools"
231+
text="Please try again"
232+
/>
233+
)}
229234
</div>
230235
</>
231236
);

packages/hyperdrive-appconfig/src/rewards/resolvers/morpho.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,11 +324,17 @@ function parseAllocationRewards({
324324
// Calculate "Reward rates" (like APR) for tokens that have monetary
325325
// value, based on the vault's allocated assets.
326326
if (reward.supplyApr) {
327+
const vaultAdjustedRewardRate = percentOfVaultAllocatedToMarket.mul(
328+
// The supplyAPR is provided as a javascript number from the
329+
// Morpho endpoint, which could end up having more than 18 numbers
330+
// after the decimal point. Since fixed=-point-wasm doesn't like
331+
// that, we must make sure to truncate the supplyApr before using
332+
// it.
333+
parseFixed(truncateTo18Decimals(reward.supplyApr)),
334+
);
327335
return {
328336
reward,
329-
vaultAdjustedRewardRate: percentOfVaultAllocatedToMarket.mul(
330-
parseFixed(reward.supplyApr),
331-
),
337+
vaultAdjustedRewardRate,
332338
};
333339
}
334340

@@ -429,3 +435,11 @@ function parseAllocationRewards({
429435

430436
return [...transferableTokenRewards, ...nonTransferableTokenRewards];
431437
}
438+
439+
/**
440+
* Truncates a number to no more than 18 decimal places after the decimal point.
441+
* This prevents fixed point wasm errors, "Exponent 18 is too small for I256"
442+
*/
443+
function truncateTo18Decimals(num: number) {
444+
return Math.floor(num * 1e18) / 1e18;
445+
}

0 commit comments

Comments
 (0)