Skip to content

Commit

Permalink
Merge pull request #30 from morpho-org/feat/add-migration-addresses
Browse files Browse the repository at this point in the history
[1.5.6] Feat/add migration addresses
  • Loading branch information
Rubilmax authored Aug 7, 2024
2 parents 81bdd19 + 71c9dc4 commit 3037ecd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 14 deletions.
3 changes: 3 additions & 0 deletions packages/blue-sdk/src/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const addresses = {
aaveV2Bundler: "0xb3dCc75DB379925edFd3007511A8CE0cB4aa8e76" as const,
aaveV3Bundler: "0x98ccB155E86bb478d514a827d16f58c6912f9BDC" as const,
compoundV3Bundler: "0x3a0e2E9FB9c95fBc843daF166276C90B6C479558" as const,
compoundV2Bundler: "0x26bf52a84360ad3d01d7cdc28fc2ddc04d8c8647" as const,
adaptiveCurveIrm: "0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC" as const,
publicAllocator: "0xfd32fA2ca22c76dD6E550706Ad913FC6CE91c75D" as const,

Expand Down Expand Up @@ -76,6 +77,7 @@ export const addresses = {
morpho: "0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb" as const,
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3" as const,
bundler: "0x23055618898e202386e6c13955a58D3C68200BFB" as const,
compoundV2Bundler: "0x123f3167a416cA19365dE03a65e0AF3532af7223" as const,
aaveV3Bundler: "0xcAe2929baBc60Be34818EaA5F40bF69265677108" as const,
compoundV3Bundler: "0x1f8076e2EB6f10b12e6886f30D4909A91969F7dA" as const,
adaptiveCurveIrm: "0x46415998764C29aB2a25CbeA6254146D50D22687" as const,
Expand All @@ -96,6 +98,7 @@ export interface ChainAddresses {
aaveV2Bundler?: Address;
aaveV3Bundler?: Address;
compoundV3Bundler?: Address;
compoundV2Bundler?: Address;
adaptiveCurveIrm?: Address;
publicAllocator?: Address;

Expand Down
24 changes: 11 additions & 13 deletions packages/blue-sdk/src/maths/MathLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,29 +185,27 @@ export class MathLib {
}

/**
* Converts an apr to compounded apy
* Converts an rate to compounded apy
*
* @param apr The rate to convert (in WAD)
* @param compounding The compounding basis
* @param rate The rate to convert (in WAD)
* @param period The compounding basis
*/
static rateToApy(rate: BigIntish, unit: Time.Unit) {
const factor = Time[unit].from.y(1n);
static rateToApy(rate: BigIntish, period: Time.PeriodLike) {
const { unit, duration } = Time.toPeriod(period);
const factor = Time[unit].from.y(1) / duration;

return (
(1 + Number(format.number.of(BigInt(rate), 18))) ** Number(factor) - 1
);
return (1 + Number(format.number.of(BigInt(rate), 18))) ** factor - 1;
}

/**
* Converts an apr to compounded apy
*
* @param apr The yearly apr to convert (in WAD)
* @param apr The apr to convert (in WAD)
* @param compounding The compounding basis
*/
static aprToApy(apr: BigIntish, compounding: Time.Unit) {
const factor = Time[compounding].from.y(1n);

const rate = BigInt(apr) / factor;
static aprToApy(apr: BigIntish, compounding: Time.PeriodLike) {
const { unit, duration } = Time.toPeriod(compounding);
const rate = (BigInt(apr) * BigInt(duration)) / Time[unit].from.y(1n);

return this.rateToApy(rate, compounding);
}
Expand Down
16 changes: 15 additions & 1 deletion packages/morpho-ts/src/time/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ const toNumberish = (returnValue: bigint, initialValue: bigint | number) => {
};

const UNITS = ["ms", "s", "min", "h", "d", "w", "mo", "y"] as const;
export type TUnit = (typeof UNITS)[number];
type TUnit = (typeof UNITS)[number];
type TPeriod = {
unit: TUnit;
duration: number;
};

type P = {
[U in TUnit]: <T extends number | bigint>(
Expand Down Expand Up @@ -99,6 +103,16 @@ Object.defineProperties(

export namespace Time {
export type Unit = TUnit;
export type Period = TPeriod;
export type PeriodLike = TPeriod | TUnit;

export function toPeriod(periodLike: PeriodLike): Period {
if (typeof periodLike === "object") return periodLike;
return {
unit: periodLike,
duration: 1,
};
}

export async function wait<T>(ms: number, value?: T) {
return new Promise((resolve) => setTimeout(() => resolve(value), ms));
Expand Down

0 comments on commit 3037ecd

Please sign in to comment.