Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.5.6] Feat/add migration addresses #30

Merged
merged 5 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 7 additions & 7 deletions packages/blue-sdk/src/maths/MathLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,11 @@ export class MathLib {
* @param apr The rate to convert (in WAD)
* @param compounding 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;
}

/**
Expand All @@ -204,8 +203,9 @@ export class MathLib {
* @param apr The yearly apr to convert (in WAD)
* @param compounding The compounding basis
*/
static aprToApy(apr: BigIntish, compounding: Time.Unit) {
const factor = Time[compounding].from.y(1n);
static aprToApy(apr: BigIntish, compounding: Time.PeriodLike) {
const { unit, duration } = Time.toPeriod(compounding);
const factor = Time[unit].from.y(1n) / BigInt(duration);

const rate = BigInt(apr) / factor;

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