Skip to content

Commit

Permalink
Merge branch 'main' of github.com:morpho-org/sdks into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Jan 14, 2025
2 parents 93f51c8 + 3be1464 commit a83e59d
Show file tree
Hide file tree
Showing 20 changed files with 522 additions and 222 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"conventional-changelog-conventionalcommits": "^8.0.0",
"conventional-changelog-writer": "^8.0.0",
"conventional-recommended-bump": "^10.0.0",
"dotenv-cli": "^7.4.4",
"dotenv-cli": "^8.0.0",
"happy-dom": "^16.5.3",
"husky": "^9.1.7",
"lint-staged": "^15.2.11",
Expand Down
4 changes: 2 additions & 2 deletions packages/blue-sdk-ethers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"ethers": "^6.0.0",
"ethers-types": "^3.17.0"
"ethers-types": "^3.18.1"
},
"devDependencies": {
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/morpho-test": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"@morpho-org/test": "workspace:^",
"ethers": "^6.13.5",
"ethers-types": "^3.17.3",
"ethers-types": "^3.18.1",
"typescript": "^5.7.2",
"viem": "^2.22.2",
"vitest": "^2.1.8"
Expand Down
11 changes: 10 additions & 1 deletion packages/blue-sdk-ethers/src/fetch/Vault.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { type Provider, resolveProperties } from "ethers";
import { MetaMorpho__factory, PublicAllocator__factory } from "ethers-types";
import {
MetaMorphoV1_1__factory,
MetaMorpho__factory,
PublicAllocator__factory,
} from "ethers-types";

import {
AccrualVault,
Expand Down Expand Up @@ -43,6 +47,7 @@ export async function fetchVault(
totalSupply,
totalAssets,
lastTotalAssets,
lostAssets,
supplyQueueSize,
withdrawQueueSize,
hasPublicAllocator,
Expand All @@ -65,6 +70,9 @@ export async function fetchVault(
mm.totalSupply(overrides),
mm.totalAssets(overrides),
mm.lastTotalAssets(overrides),
MetaMorphoV1_1__factory.connect(address, runner)
.lostAssets(overrides)
.catch(() => undefined),
mm.supplyQueueLength(overrides).then((r) => Number(r)),
mm.withdrawQueueLength(overrides).then((r) => Number(r)),
chainAddresses.publicAllocator &&
Expand Down Expand Up @@ -122,6 +130,7 @@ export async function fetchVault(
totalSupply,
totalAssets,
lastTotalAssets,
lostAssets,
});
}

Expand Down
54 changes: 52 additions & 2 deletions packages/blue-sdk-ethers/test/e2e/Vault.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect } from "vitest";
import { test } from "./setup";
import { test, test2 } from "./setup";

import {
ChainId,
Expand All @@ -13,7 +13,7 @@ import { zeroAddress, zeroHash } from "viem";
import { Vault } from "../../src/augment/Vault";
import { metaMorphoAbi, publicAllocatorAbi } from "./abis";

const { steakUsdc } = vaults[ChainId.EthMainnet];
const { steakUsdc, steakPaxg } = vaults[ChainId.EthMainnet];

describe("augment/Vault", () => {
test("should fetch vault data", async ({ client, wallet }) => {
Expand Down Expand Up @@ -91,4 +91,54 @@ describe("augment/Vault", () => {

expect(value).toEqual(expectedData);
});

test2("should fetch vault v1.1 data", async ({ wallet }) => {
const expectedData = new Vault({
...steakPaxg,
curator: zeroAddress,
fee: 50000000000000000n,
feeRecipient: "0x255c7705e8BB334DfCae438197f7C4297988085a",
guardian: "0x5148Db8942C69A431167C1B7FA7590c15DF934f1",
owner: "0x0A0e559bc3b0950a7e448F0d4894db195b9cf8DD",
pendingGuardian: {
validAt: 0n,
value: zeroAddress,
},
pendingOwner: zeroAddress,
pendingTimelock: {
validAt: 0n,
value: 0n,
},
skimRecipient: zeroAddress,
publicAllocatorConfig: {
admin: "0xfeed46c11F57B7126a773EeC6ae9cA7aE1C03C9a",
fee: 0n,
accruedFee: 0n,
},
supplyQueue: [
"0xb1963517b52c4315a4ed5f6811aee279ab7adc90d9dfbd8f187e05f2758f4d1a" as MarketId,
],
timelock: 604800n,
withdrawQueue: [
"0xb1963517b52c4315a4ed5f6811aee279ab7adc90d9dfbd8f187e05f2758f4d1a" as MarketId,
],
lastTotalAssets: 206000400000000000000n,
lostAssets: 0n,
totalAssets: 206000400000000000000n,
totalSupply: 206000400000000000000n,
eip5267Domain: new Eip5267Domain({
fields: "0x0f",
name: "",
version: "1",
chainId: 1n,
verifyingContract: steakPaxg.address,
salt: zeroHash,
extensions: [],
}),
});

const value = await Vault.fetch(steakPaxg.address, wallet);

expect(value).toEqual(expectedData);
});
});
11 changes: 11 additions & 0 deletions packages/blue-sdk-ethers/test/e2e/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { createEthersTest } from "@morpho-org/test/vitest/ethers";
import { mainnet } from "viem/chains";

/**
* This test will run on `mainnet` forked at block `19,530,000`.
*/
export const test = createEthersTest(mainnet, {
forkUrl: process.env.MAINNET_RPC_URL,
forkBlockNumber: 19_530_000,
});

/**
* This test will run on `mainnet` forked at block `21,595,000`.
*/
export const test2 = createEthersTest(mainnet, {
forkUrl: process.env.MAINNET_RPC_URL,
forkBlockNumber: 21_595_000,
});
2 changes: 1 addition & 1 deletion packages/blue-sdk-viem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@morpho-org/morpho-test": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"@morpho-org/test": "workspace:^",
"hardhat": "^2.22.17",
"hardhat": "^2.22.18",
"typescript": "^5.7.2",
"viem": "^2.22.2",
"vitest": "^2.1.8"
Expand Down
13 changes: 13 additions & 0 deletions packages/blue-sdk-viem/src/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3684,6 +3684,19 @@ export const metaMorphoAbi = [
],
stateMutability: "view",
},
{
type: "function",
name: "lostAssets", // Only defined for MetaMorpho V1.1 vaults.
inputs: [],
outputs: [
{
name: "",
type: "uint256",
internalType: "uint256",
},
],
stateMutability: "view",
},
{
type: "function",
name: "maxDeposit",
Expand Down
8 changes: 8 additions & 0 deletions packages/blue-sdk-viem/src/fetch/Vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export async function fetchVault(
totalSupply,
totalAssets,
lastTotalAssets,
lostAssets,
supplyQueueSize,
withdrawQueueSize,
hasPublicAllocator,
Expand Down Expand Up @@ -187,6 +188,12 @@ export async function fetchVault(
abi: metaMorphoAbi,
functionName: "lastTotalAssets",
}),
readContract(client, {
...parameters,
address,
abi: metaMorphoAbi,
functionName: "lostAssets",
}).catch(() => undefined),
readContract(client, {
...parameters,
address,
Expand Down Expand Up @@ -285,6 +292,7 @@ export async function fetchVault(
totalSupply,
totalAssets,
lastTotalAssets,
lostAssets,
});
}
export async function fetchAccrualVault(
Expand Down
54 changes: 52 additions & 2 deletions packages/blue-sdk-viem/test/Vault.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect } from "vitest";
import { test } from "./setup";
import { test, test2 } from "./setup";

import {
ChainId,
Expand All @@ -13,7 +13,7 @@ import { zeroAddress, zeroHash } from "viem";
import { metaMorphoAbi, publicAllocatorAbi } from "../src";
import { Vault } from "../src/augment/Vault";

const { steakUsdc } = vaults[ChainId.EthMainnet];
const { steakUsdc, steakPaxg } = vaults[ChainId.EthMainnet];

describe("augment/Vault", () => {
test("should fetch vault data", async ({ client }) => {
Expand Down Expand Up @@ -91,4 +91,54 @@ describe("augment/Vault", () => {

expect(value).toStrictEqual(expectedData);
});

test2("should fetch vault v1.1 data", async ({ client }) => {
const expectedData = new Vault({
...steakPaxg,
curator: zeroAddress,
fee: 50000000000000000n,
feeRecipient: "0x255c7705e8BB334DfCae438197f7C4297988085a",
guardian: "0x5148Db8942C69A431167C1B7FA7590c15DF934f1",
owner: "0x0A0e559bc3b0950a7e448F0d4894db195b9cf8DD",
pendingGuardian: {
validAt: 0n,
value: zeroAddress,
},
pendingOwner: zeroAddress,
pendingTimelock: {
validAt: 0n,
value: 0n,
},
skimRecipient: zeroAddress,
publicAllocatorConfig: {
admin: "0xfeed46c11F57B7126a773EeC6ae9cA7aE1C03C9a",
fee: 0n,
accruedFee: 0n,
},
supplyQueue: [
"0xb1963517b52c4315a4ed5f6811aee279ab7adc90d9dfbd8f187e05f2758f4d1a" as MarketId,
],
timelock: 604800n,
withdrawQueue: [
"0xb1963517b52c4315a4ed5f6811aee279ab7adc90d9dfbd8f187e05f2758f4d1a" as MarketId,
],
lastTotalAssets: 206000400000000000000n,
lostAssets: 0n,
totalAssets: 206000400000000000000n,
totalSupply: 206000400000000000000n,
eip5267Domain: new Eip5267Domain({
fields: "0x0f",
name: "",
version: "1",
chainId: 1n,
verifyingContract: steakPaxg.address,
salt: zeroHash,
extensions: [],
}),
});

const value = await Vault.fetch(steakPaxg.address, client);

expect(value).toEqual(expectedData);
});
});
11 changes: 11 additions & 0 deletions packages/blue-sdk-viem/test/setup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { createViemTest } from "@morpho-org/test/vitest";
import { mainnet } from "viem/chains";

/**
* This test will run on `mainnet` forked at block `19,530,000`.
*/
export const test = createViemTest(mainnet, {
forkUrl: process.env.MAINNET_RPC_URL,
forkBlockNumber: 19_530_000,
});

/**
* This test will run on `mainnet` forked at block `21,595,000`.
*/
export const test2 = createViemTest(mainnet, {
forkUrl: process.env.MAINNET_RPC_URL,
forkBlockNumber: 21_595_000,
});
2 changes: 1 addition & 1 deletion packages/blue-sdk-wagmi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"@tanstack/react-query": "^5.62.11",
"@testing-library/dom": "^10.4.0",
"@testing-library/react": "^16.1.0",
"@types/react": "^19.0.4",
"@types/react": "^19.0.7",
"@types/react-dom": "^19.0.2",
"react": "^19.0.0",
"react-dom": "^19.0.0",
Expand Down
Loading

0 comments on commit a83e59d

Please sign in to comment.