Skip to content

Commit

Permalink
feat(blue-sdk-viem): add bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
Rubilmax committed Sep 27, 2024
1 parent e4034ac commit 0e5dbaf
Show file tree
Hide file tree
Showing 70 changed files with 9,164 additions and 329 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ jobs:
- name: blue-sdk-viem
jest: false
hardhat: true
- name: blue-sdk-viem-bundler
jest: false
hardhat: true
- name: blue-sdk-ethers-liquidation
jest: false
hardhat: true
Expand Down
13 changes: 13 additions & 0 deletions packages/blue-sdk-ethers/src/errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Address } from "@morpho-org/blue-sdk";

export class InvalidSignatureError extends Error {
constructor(
public readonly hash: string,
public readonly signer: Address,
public readonly recovered: Address,
) {
super(
`invalid signature for hash ${hash}: expected ${signer}, recovered ${recovered}`,
);
}
}
3 changes: 2 additions & 1 deletion packages/blue-sdk-ethers/src/signatures/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import {
recoverAddress,
} from "ethers";

import { Address, InvalidSignatureError } from "@morpho-org/blue-sdk";
import { Address } from "@morpho-org/blue-sdk";

import { InvalidSignatureError } from "../errors";
import { SignatureMessage } from "./types";

export async function safeSignTypedData(
Expand Down
2 changes: 2 additions & 0 deletions packages/blue-sdk-viem-bundler/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MAINNET_RPC_URL=
BASE_RPC_URL=
69 changes: 69 additions & 0 deletions packages/blue-sdk-viem-bundler/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import "dotenv/config";
import "hardhat-deal";
import { HardhatUserConfig } from "hardhat/config";
import { HardhatNetworkUserConfig } from "hardhat/types";

import "@nomicfoundation/hardhat-chai-matchers";
import "@nomicfoundation/hardhat-ethers";
import "@nomicfoundation/hardhat-network-helpers";

import { ChainId, addresses } from "@morpho-org/blue-sdk";

const hardhatNetworkConfigs: Record<string, HardhatNetworkUserConfig> = {
ethereum: {
chainId: 1,
forking: {
url: process.env.MAINNET_RPC_URL!,
blockNumber: 19_750_000,
},
},
base: {
chainId: 8453,
forking: {
url: process.env.BASE_RPC_URL!,
blockNumber: 16_260_000,
},
},
};

const network = process.env.NETWORK || "ethereum";
const hardhatNetworkConfig = hardhatNetworkConfigs[network];
if (!hardhatNetworkConfig) throw Error(`invalid network: ${network}`);
if (!hardhatNetworkConfig.forking?.url)
throw Error(`no RPC url provided for network: ${network}`);

const config: HardhatUserConfig = {
networks: {
hardhat: {
gasPrice: 0,
initialBaseFeePerGas: 0,
allowUnlimitedContractSize: true,
allowBlocksWithSameTimestamp: true,
mining: {
mempool: {
order: "fifo",
},
},
...hardhatNetworkConfig,
},
},
paths: {
tests: "./tests/e2e/",
cache: "./cache",
},
mocha: {
timeout: 300000,
reporterOptions: {
maxDiffSize: 2 ** 16,
},
fgrep: network,
},
tracer: {
nameTags: {
[addresses[ChainId.EthMainnet].bundler]: "EthereumBundler",
[addresses[ChainId.BaseMainnet].bundler]: "BaseBundler",
},
},
};

export default config;
82 changes: 82 additions & 0 deletions packages/blue-sdk-viem-bundler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"name": "@morpho-org/blue-sdk-viem-bundler",
"version": "1.0.0",
"author": "Morpho Association <contact@morpho.org>",
"license": "MIT",
"type": "module",
"main": "src/index.ts",
"files": [
"lib"
],
"scripts": {
"prepublish": "yarn build",
"build": "tsc --build tsconfig.build.json",
"test": "hardhat test",
"test-ethereum": "NETWORK=ethereum yarn test",
"test-base": "NETWORK=base yarn test"
},
"peerDependencies": {
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/blue-sdk-viem": "workspace:^",
"@morpho-org/blue-sdk-viem-simulation": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"mutative": "^1.0.8",
"viem": "^2.0.0"
},
"devDependencies": {
"@morpho-org/blue-sdk": "workspace:^",
"@morpho-org/blue-sdk-viem": "workspace:^",
"@morpho-org/blue-sdk-viem-simulation": "workspace:^",
"@morpho-org/morpho-test": "workspace:^",
"@morpho-org/morpho-ts": "workspace:^",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.2",
"@nomicfoundation/hardhat-ethers": "^3.0.6",
"@nomicfoundation/hardhat-network-helpers": "^1.0.9",
"@types/chai": "^4.3.17",
"@types/jest": "^29.5.12",
"@types/lodash": "^4.17.7",
"@types/mocha": "^10.0.6",
"@types/node": "^22.2.0",
"@types/sinon": "^17.0.3",
"@types/sinon-chai": "^3.2.12",
"chai": "^4.5.0",
"dotenv": "^16.3.1",
"ethers": "^6.12.1",
"ethers-types": "^3.17.1",
"hardhat": "^2.22.10",
"hardhat-deal": "^3.1.0",
"jest": "^29.6.2",
"lodash": "^4.17.21",
"mocha": "^10.4.0",
"sinon": "^19.0.2",
"sinon-chai": "^3.7.0",
"ts-jest": "^29.2.4",
"ts-node": "^10.9.2",
"typescript": "^5.6.2",
"viem": "^2.21.15"
},
"publishConfig": {
"access": "public",
"main": "lib/index.js"
},
"jest": {
"verbose": true,
"testTimeout": 15000,
"maxWorkers": 1,
"transform": {
"^.+\\.tsx?$": [
"ts-jest",
{
"tsconfig": "tsconfig.json"
}
]
},
"testMatch": [
"**/*.test.ts"
],
"testPathIgnorePatterns": [
"node_modules/",
"tests/e2e/"
]
}
}
Loading

0 comments on commit 0e5dbaf

Please sign in to comment.