Skip to content

Commit

Permalink
Merge pull request #445 from morpho-org/docs/pkg
Browse files Browse the repository at this point in the history
docs(pkg): add jsdoc
  • Loading branch information
MerlinEgalite authored Jul 15, 2024
2 parents 3ea283f + ea49b4b commit 765fdf5
Show file tree
Hide file tree
Showing 3 changed files with 526 additions and 167 deletions.
122 changes: 121 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Each Bundler is a domain-specific abstract layer of contract that implements som

Some chain-specific domains are also scoped to the chain-specific folder, because they are not expected to be used on any other chain (e.g. DAI and its specific `permit` function is only available on Ethereum - see [`EthereumPermitBundler`](./src/ethereum/EthereumPermitBundler.sol)).

User-end bundlers are provided in each chain-specific folder, instanciating all the intermediary domain-specific bundlers and associated parameters (such as chain-specific protocol addresses, e.g. [`EthereumBundlerV2`](./src/ethereum/EthereumBundlerV2.sol)).
User-end bundlers are provided in each chain-specific folder, instantiating all the intermediary domain-specific bundlers and associated parameters (such as chain-specific protocol addresses, e.g. [`EthereumBundlerV2`](./src/ethereum/EthereumBundlerV2.sol)).

## Deployments

Expand All @@ -20,6 +20,126 @@ User-end bundlers are provided in each chain-specific folder, instanciating all

## Getting Started

### Package installation

```bash
npm install @morpho-org/morpho-blue-bundlers
```

```bash
yarn add @morpho-org/morpho-blue-bundlers
```

### Usage

Bundle a collateral supply and a borrow:

```typescript
import { BundlerAction } from "@morpho-org/morpho-blue-bundlers";

const collateral = 1_000000000000000000n;
const borrowedAssets = 1000_000000n;

const borrower = "0x...";
const marketParams = {
collateralToken: "0x...",
loanToken: "0x...",
irm: "0x...",
oracle: "0x...",
lltv: 86_0000000000000000n,
};

await bundler
.connect(supplier)
.multicall([
BundlerAction.transferFrom(marketParams.collateralToken, collateral),
BundlerAction.morphoSupplyCollateral(marketParams, collateral, borrower, "0x"),
BundlerAction.morphoBorrow(marketParams, borrowedAssets, 0n, borrower, borrower),
]);
```

Bundle a permit2 signature approval and a ERC-4626 deposit:

```typescript
import { Signature } from "ethers";

import { BundlerAction } from "@morpho-org/morpho-blue-bundlers";

const permit2Address = "0x000000000022D473030F116dDEE9F6B43aC78BA3";

const permit2Config = {
domain: {
name: "Permit2",
chainId: "0x1",
verifyingContract: permit2Address,
},
types: {
PermitSingle: [
{
name: "details",
type: "PermitDetails",
},
{
name: "spender",
type: "address",
},
{
name: "sigDeadline",
type: "uint256",
},
],
PermitDetails: [
{
name: "token",
type: "address",
},
{
name: "amount",
type: "uint160",
},
{
name: "expiration",
type: "uint48",
},
{
name: "nonce",
type: "uint48",
},
],
},
};

const assetAddress = "0x...";
const assets = 1000_000000n;

const supplier = "0x...";
const bundlerAddress = "0x...";
const permitSingle = {
details: {
token: assetAddress,
amount: assets,
nonce: 0n,
expiration: 2n ** 48n - 1,
},
spender: bundlerAddress,
sigDeadline: 2n ** 48n - 1,
};

await bundler
.connect(supplier)
.multicall([
BundlerAction.approve2(
permitSingle,
Signature.from(await supplier.signTypedData(permit2Config.domain, permit2Config.types, permitSingle)),
false,
),
BundlerAction.transferFrom2(assetAddress, assets),
BundlerAction.erc4626Deposit(erc4626Address, assets, 0, supplier),
]);
```

## Development

Install dependencies with `yarn`.

Run tests with `yarn test:forge --chain <chainid>` (chainid can be 1 or 8453).
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@morpho-org/morpho-blue-bundlers",
"description": "Morpho Blue Bundlers",
"license": "GPL-2.0-or-later",
"version": "1.1.2",
"version": "1.2.0",
"repository": {
"type": "git",
"url": "git+https://github.com/morpho-labs/morpho-blue-bundlers.git"
Expand Down
Loading

0 comments on commit 765fdf5

Please sign in to comment.