Skip to content

Commit

Permalink
feat(bundler3)!: replace encoders
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Bundler encoding functions now take the chainId as the first argument.
This change is necessary to support the new bundler3 contract.
  • Loading branch information
Rubilmax committed Jan 27, 2025
1 parent 84132ba commit a39f381
Show file tree
Hide file tree
Showing 18 changed files with 1,736 additions and 763 deletions.
7 changes: 5 additions & 2 deletions packages/blue-sdk-ethers/src/fetch/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,14 @@ export async function fetchUser(
chainId ?? (await runner.provider.getNetwork()).chainId,
);

const { morpho, bundler } = getChainAddresses(chainId);
const {
morpho,
bundler3: { generalAdapter1 },
} = getChainAddresses(chainId);
const blue = MorphoBlue__factory.connect(morpho, runner);

const [isBundlerAuthorized, morphoNonce] = await Promise.all([
blue.isAuthorized(address, bundler, overrides),
blue.isAuthorized(address, generalAdapter1, overrides),
blue.nonce(address, overrides),
]);

Expand Down
17 changes: 11 additions & 6 deletions packages/blue-sdk-ethers/test/e2e/Holding.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ import { maxUint256 } from "viem";
import { Holding } from "../../src/augment/Holding";
import { permit2Abi } from "./abis";

const { morpho, bundler, permit2, wNative, wbC3M } =
addresses[ChainId.EthMainnet];
const {
morpho,
bundler3: { generalAdapter1 },
permit2,
wNative,
wbC3M,
} = addresses[ChainId.EthMainnet];

describe("augment/Holding", async () => {
test("should fetch user WETH data ", async ({ client, wallet }) => {
Expand Down Expand Up @@ -50,7 +55,7 @@ describe("augment/Holding", async () => {
});
await client.approve({
address: wNative,
args: [bundler, expectedData.erc20Allowances.bundler],
args: [generalAdapter1, expectedData.erc20Allowances.bundler],
});
await client.approve({
address: wNative,
Expand All @@ -73,7 +78,7 @@ describe("augment/Holding", async () => {
functionName: "approve",
args: [
wNative,
bundler,
generalAdapter1,
expectedData.permit2Allowances.bundler.amount,
Number(expectedData.permit2Allowances.bundler.expiration),
],
Expand Down Expand Up @@ -152,7 +157,7 @@ describe("augment/Holding", async () => {
});
await client.approve({
address: wbC3M,
args: [bundler, expectedData.erc20Allowances.bundler],
args: [generalAdapter1, expectedData.erc20Allowances.bundler],
});
await client.approve({
address: wbC3M,
Expand All @@ -175,7 +180,7 @@ describe("augment/Holding", async () => {
functionName: "approve",
args: [
wbC3M,
bundler,
generalAdapter1,
expectedData.permit2Allowances.bundler.amount,
Number(expectedData.permit2Allowances.bundler.expiration),
],
Expand Down
7 changes: 5 additions & 2 deletions packages/blue-sdk-ethers/test/e2e/User.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,18 @@ import { ChainId, addresses } from "@morpho-org/blue-sdk";
import { User } from "../../src/augment/User";
import { blueAbi } from "./abis";

const { morpho, bundler } = addresses[ChainId.EthMainnet];
const {
morpho,
bundler3: { generalAdapter1 },
} = addresses[ChainId.EthMainnet];

describe("augment/User", () => {
test("should fetch user data", async ({ client, wallet }) => {
await client.writeContract({
address: morpho,
abi: blueAbi,
functionName: "setAuthorization",
args: [bundler, true],
args: [generalAdapter1, true],
});

const expectedData = new User({
Expand Down
277 changes: 277 additions & 0 deletions packages/blue-sdk-viem/src/abis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7949,3 +7949,280 @@ export const erc5267Abi = [
type: "function",
},
] as const;

export const daiAbi = [
{
inputs: [{ internalType: "uint256", name: "chainId_", type: "uint256" }],
payable: false,
stateMutability: "nonpayable",
type: "constructor",
},
{
anonymous: false,
inputs: [
{ indexed: true, internalType: "address", name: "src", type: "address" },
{ indexed: true, internalType: "address", name: "guy", type: "address" },
{ indexed: false, internalType: "uint256", name: "wad", type: "uint256" },
],
name: "Approval",
type: "event",
},
{
anonymous: true,
inputs: [
{ indexed: true, internalType: "bytes4", name: "sig", type: "bytes4" },
{ indexed: true, internalType: "address", name: "usr", type: "address" },
{ indexed: true, internalType: "bytes32", name: "arg1", type: "bytes32" },
{ indexed: true, internalType: "bytes32", name: "arg2", type: "bytes32" },
{ indexed: false, internalType: "bytes", name: "data", type: "bytes" },
],
name: "LogNote",
type: "event",
},
{
anonymous: false,
inputs: [
{ indexed: true, internalType: "address", name: "src", type: "address" },
{ indexed: true, internalType: "address", name: "dst", type: "address" },
{ indexed: false, internalType: "uint256", name: "wad", type: "uint256" },
],
name: "Transfer",
type: "event",
},
{
constant: true,
inputs: [],
name: "DOMAIN_SEPARATOR",
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [],
name: "PERMIT_TYPEHASH",
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [
{ internalType: "address", name: "", type: "address" },
{ internalType: "address", name: "", type: "address" },
],
name: "allowance",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "address", name: "usr", type: "address" },
{ internalType: "uint256", name: "wad", type: "uint256" },
],
name: "approve",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [{ internalType: "address", name: "", type: "address" }],
name: "balanceOf",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "address", name: "usr", type: "address" },
{ internalType: "uint256", name: "wad", type: "uint256" },
],
name: "burn",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [],
name: "decimals",
outputs: [{ internalType: "uint8", name: "", type: "uint8" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [{ internalType: "address", name: "guy", type: "address" }],
name: "deny",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "address", name: "usr", type: "address" },
{ internalType: "uint256", name: "wad", type: "uint256" },
],
name: "mint",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "address", name: "src", type: "address" },
{ internalType: "address", name: "dst", type: "address" },
{ internalType: "uint256", name: "wad", type: "uint256" },
],
name: "move",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [],
name: "name",
outputs: [{ internalType: "string", name: "", type: "string" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [{ internalType: "address", name: "", type: "address" }],
name: "nonces",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "address", name: "holder", type: "address" },
{ internalType: "address", name: "spender", type: "address" },
{ internalType: "uint256", name: "nonce", type: "uint256" },
{ internalType: "uint256", name: "expiry", type: "uint256" },
{ internalType: "bool", name: "allowed", type: "bool" },
{ internalType: "uint8", name: "v", type: "uint8" },
{ internalType: "bytes32", name: "r", type: "bytes32" },
{ internalType: "bytes32", name: "s", type: "bytes32" },
],
name: "permit",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "address", name: "usr", type: "address" },
{ internalType: "uint256", name: "wad", type: "uint256" },
],
name: "pull",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "address", name: "usr", type: "address" },
{ internalType: "uint256", name: "wad", type: "uint256" },
],
name: "push",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: false,
inputs: [{ internalType: "address", name: "guy", type: "address" }],
name: "rely",
outputs: [],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [],
name: "symbol",
outputs: [{ internalType: "string", name: "", type: "string" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [],
name: "totalSupply",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "address", name: "dst", type: "address" },
{ internalType: "uint256", name: "wad", type: "uint256" },
],
name: "transfer",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: false,
inputs: [
{ internalType: "address", name: "src", type: "address" },
{ internalType: "address", name: "dst", type: "address" },
{ internalType: "uint256", name: "wad", type: "uint256" },
],
name: "transferFrom",
outputs: [{ internalType: "bool", name: "", type: "bool" }],
payable: false,
stateMutability: "nonpayable",
type: "function",
},
{
constant: true,
inputs: [],
name: "version",
outputs: [{ internalType: "string", name: "", type: "string" }],
payable: false,
stateMutability: "view",
type: "function",
},
{
constant: true,
inputs: [{ internalType: "address", name: "", type: "address" }],
name: "wards",
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
payable: false,
stateMutability: "view",
type: "function",
},
] as const;
8 changes: 6 additions & 2 deletions packages/blue-sdk-viem/src/fetch/Holding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ export async function fetchHolding(
});

if (deployless) {
const { morpho, permit2, bundler } = addresses[parameters.chainId];
const {
morpho,
permit2,
bundler3: { generalAdapter1 },
} = addresses[parameters.chainId];
try {
const {
balance,
Expand All @@ -79,7 +83,7 @@ export async function fetchHolding(
user,
morpho,
permit2,
bundler,
generalAdapter1,
permissionedBackedTokens[parameters.chainId].has(token),
permissionedWrapperTokens[parameters.chainId].has(token),
],
Expand Down
Loading

0 comments on commit a39f381

Please sign in to comment.