Skip to content

Commit

Permalink
fix(converter): use rateAtTarget when parsing market
Browse files Browse the repository at this point in the history
  • Loading branch information
oumar-fall committed Dec 3, 2024
1 parent a1d7b59 commit 49c19d0
Show file tree
Hide file tree
Showing 2 changed files with 377 additions and 26 deletions.
15 changes: 3 additions & 12 deletions packages/blue-api-sdk/src/converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
VaultMarketPublicAllocatorConfig,
VaultUtils,
} from "@morpho-org/blue-sdk";
import { Time, isDefined } from "@morpho-org/morpho-ts";
import { isDefined } from "@morpho-org/morpho-ts";

import {
Chain as BlueApiChain,
Expand Down Expand Up @@ -59,7 +59,7 @@ export interface PartialBlueApiMarket
| "supplyShares"
| "timestamp"
| "fee"
| "rateAtUTarget"
| "rateAtTarget"
>
>;
}
Expand Down Expand Up @@ -193,15 +193,6 @@ export class BlueSdkConverter {
const fee = this.options.parseNumber(dto.state.fee, 18);
const price = dto.collateralPrice ?? 1n;

const rateAtTarget =
// rateAtUTarget is not typed nullable, but it will be as soon as a non-compatible IRM is enabled.
dto.state.rateAtUTarget != null
? // API rate at target is compounded over the year, while the Market rateAtTarget is per second.
//TODO use rateAtTarget directly per second
this.options.parseNumber(Math.log1p(dto.state.rateAtUTarget), 18) /
Time.s.from.y(1n)
: undefined;

return new Market({
config,
totalSupplyAssets: dto.state.supplyAssets,
Expand All @@ -211,7 +202,7 @@ export class BlueSdkConverter {
lastUpdate: dto.state.timestamp,
fee,
price,
rateAtTarget,
rateAtTarget: dto.state.rateAtTarget ?? undefined,
});
}

Expand Down
Loading

0 comments on commit 49c19d0

Please sign in to comment.