@morpho-org/bundler-sdk-viem 2.0.0-next.2 → 2.0.0-next.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024 Morpho Labs
3
+ Copyright (c) 2024 Morpho Association
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
1
1
  import { type Address, type Hex } from "viem";
2
- import type { Action, Authorization, MarketParams, Permit2PermitSingle, ReallocationWithdrawal } from "./types/index.js";
2
+ import type { Action, Authorization, InputMarketParams, Permit2PermitSingle, ReallocationWithdrawal } from "./types/index.js";
3
3
  export type BundlerCall = Hex;
4
4
  /**
5
5
  * Namespace to easily encode calls to the Bundler contract, using ethers.
@@ -117,7 +117,7 @@ export declare namespace BundlerAction {
117
117
  * @param onBehalf The address to supply on behalf of.
118
118
  * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupply` callback.
119
119
  */
120
- function morphoSupply(market: MarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, onBehalf: Address, callbackCalls: BundlerCall[]): BundlerCall;
120
+ function morphoSupply(market: InputMarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, onBehalf: Address, callbackCalls: BundlerCall[]): BundlerCall;
121
121
  /**
122
122
  * Encodes a call to the Bundler to supply collateral to a Morpho Blue market.
123
123
  * @param market The market params to supply to.
@@ -125,7 +125,7 @@ export declare namespace BundlerAction {
125
125
  * @param onBehalf The address to supply on behalf of.
126
126
  * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupplyCollateral` callback.
127
127
  */
128
- function morphoSupplyCollateral(market: MarketParams, assets: bigint, onBehalf: Address, callbackCalls: BundlerCall[]): BundlerCall;
128
+ function morphoSupplyCollateral(market: InputMarketParams, assets: bigint, onBehalf: Address, callbackCalls: BundlerCall[]): BundlerCall;
129
129
  /**
130
130
  * Encodes a call to the Bundler to borrow from a Morpho Blue market.
131
131
  * @param market The market params to borrow from.
@@ -134,7 +134,7 @@ export declare namespace BundlerAction {
134
134
  * @param slippageAmount The minimum (resp. maximum) amount of assets (resp. borrow shares) to borrow (resp. mint) (protects the sender from unexpected slippage).
135
135
  * @param receiver The address to send borrowed tokens to.
136
136
  */
137
- function morphoBorrow(market: MarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, receiver: Address): BundlerCall;
137
+ function morphoBorrow(market: InputMarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, receiver: Address): BundlerCall;
138
138
  /**
139
139
  * Encodes a call to the Bundler to repay to a Morpho Blue market.
140
140
  * @param market The market params to repay to.
@@ -144,7 +144,7 @@ export declare namespace BundlerAction {
144
144
  * @param onBehalf The address to repay on behalf of.
145
145
  * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupply` callback.
146
146
  */
147
- function morphoRepay(market: MarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, onBehalf: Address, callbackCalls: BundlerCall[]): BundlerCall;
147
+ function morphoRepay(market: InputMarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, onBehalf: Address, callbackCalls: BundlerCall[]): BundlerCall;
148
148
  /**
149
149
  * Encodes a call to the Bundler to withdraw from a Morpho Blue market.
150
150
  * @param market The market params to withdraw from.
@@ -153,14 +153,14 @@ export declare namespace BundlerAction {
153
153
  * @param slippageAmount The minimum (resp. maximum) amount of assets (resp. supply shares) to withdraw (resp. redeem) (protects the sender from unexpected slippage).
154
154
  * @param receiver The address to send withdrawn tokens to.
155
155
  */
156
- function morphoWithdraw(market: MarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, receiver: Address): BundlerCall;
156
+ function morphoWithdraw(market: InputMarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, receiver: Address): BundlerCall;
157
157
  /**
158
158
  * Encodes a call to the Bundler to withdraw collateral from a Morpho Blue market.
159
159
  * @param market The market params to withdraw from.
160
160
  * @param assets The amount of assets to withdraw.
161
161
  * @param receiver The address to send withdrawn tokens to.
162
162
  */
163
- function morphoWithdrawCollateral(market: MarketParams, assets: bigint, receiver: Address): BundlerCall;
163
+ function morphoWithdrawCollateral(market: InputMarketParams, assets: bigint, receiver: Address): BundlerCall;
164
164
  /**
165
165
  * Encodes a call to the Bundler to flash loan from Morpho Blue.
166
166
  * @param asset The address of the ERC20 token to flash loan.
@@ -176,7 +176,7 @@ export declare namespace BundlerAction {
176
176
  * @param withdrawals The array of withdrawals to perform, before supplying everything to the supply market.
177
177
  * @param supplyMarketParams The market params to reallocate to.
178
178
  */
179
- function metaMorphoReallocateTo(publicAllocator: Address, vault: Address, value: bigint, withdrawals: ReallocationWithdrawal[], supplyMarketParams: MarketParams): BundlerCall;
179
+ function metaMorphoReallocateTo(publicAllocator: Address, vault: Address, value: bigint, withdrawals: ReallocationWithdrawal[], supplyMarketParams: InputMarketParams): BundlerCall;
180
180
  /**
181
181
  * Encodes a call to the Bundler to claim rewards from the Universal Rewards Distributor.
182
182
  * @param distributor The address of the distributor to claim rewards from.
package/lib/actions.js CHANGED
@@ -425,17 +425,17 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
425
425
  }
426
426
  case "Blue_Supply": {
427
427
  const { id, assets = 0n, shares = 0n, onBehalf } = operation.args;
428
- const { config } = dataBefore.getMarket(id);
428
+ const { params } = dataBefore.getMarket(id);
429
429
  // Already takes slippage into account.
430
430
  const slippageAmount = shares === 0n
431
431
  ? dataAfter.getPosition(onBehalf, id).supplyShares -
432
432
  dataBefore.getPosition(onBehalf, id).supplyShares
433
- : dataAfter.getHolding(sender, config.loanToken).balance -
434
- dataBefore.getHolding(sender, config.loanToken).balance;
433
+ : dataAfter.getHolding(sender, params.loanToken).balance -
434
+ dataBefore.getHolding(sender, params.loanToken).balance;
435
435
  actions.push({
436
436
  type: "morphoSupply",
437
437
  args: [
438
- config,
438
+ params,
439
439
  assets,
440
440
  shares,
441
441
  slippageAmount,
@@ -447,47 +447,47 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
447
447
  }
448
448
  case "Blue_Withdraw": {
449
449
  const { id, assets = 0n, shares = 0n, onBehalf, receiver, } = operation.args;
450
- const { config } = dataBefore.getMarket(id);
450
+ const { params } = dataBefore.getMarket(id);
451
451
  // Already takes slippage into account.
452
452
  const slippageAmount = shares === 0n
453
453
  ? dataBefore.getPosition(onBehalf, id).supplyShares -
454
454
  dataAfter.getPosition(onBehalf, id).supplyShares
455
- : dataBefore.getHolding(sender, config.loanToken).balance -
456
- dataAfter.getHolding(sender, config.loanToken).balance;
455
+ : dataBefore.getHolding(sender, params.loanToken).balance -
456
+ dataAfter.getHolding(sender, params.loanToken).balance;
457
457
  actions.push({
458
458
  type: "morphoWithdraw",
459
- args: [config, assets, shares, slippageAmount, receiver],
459
+ args: [params, assets, shares, slippageAmount, receiver],
460
460
  });
461
461
  break;
462
462
  }
463
463
  case "Blue_Borrow": {
464
464
  const { id, assets = 0n, shares = 0n, onBehalf, receiver, } = operation.args;
465
- const { config } = dataBefore.getMarket(id);
465
+ const { params } = dataBefore.getMarket(id);
466
466
  // Already takes slippage into account.
467
467
  const slippageAmount = shares === 0n
468
468
  ? dataAfter.getPosition(onBehalf, id).borrowShares -
469
469
  dataBefore.getPosition(onBehalf, id).borrowShares
470
- : dataAfter.getHolding(sender, config.loanToken).balance -
471
- dataBefore.getHolding(sender, config.loanToken).balance;
470
+ : dataAfter.getHolding(sender, params.loanToken).balance -
471
+ dataBefore.getHolding(sender, params.loanToken).balance;
472
472
  actions.push({
473
473
  type: "morphoBorrow",
474
- args: [config, assets, shares, slippageAmount, receiver],
474
+ args: [params, assets, shares, slippageAmount, receiver],
475
475
  });
476
476
  break;
477
477
  }
478
478
  case "Blue_Repay": {
479
479
  const { id, assets = 0n, shares = 0n, onBehalf } = operation.args;
480
- const { config } = dataBefore.getMarket(id);
480
+ const { params } = dataBefore.getMarket(id);
481
481
  // Already takes slippage into account.
482
482
  const slippageAmount = shares === 0n
483
483
  ? dataBefore.getPosition(onBehalf, id).borrowShares -
484
484
  dataAfter.getPosition(onBehalf, id).borrowShares
485
- : dataBefore.getHolding(sender, config.loanToken).balance -
486
- dataAfter.getHolding(sender, config.loanToken).balance;
485
+ : dataBefore.getHolding(sender, params.loanToken).balance -
486
+ dataAfter.getHolding(sender, params.loanToken).balance;
487
487
  actions.push({
488
488
  type: "morphoRepay",
489
489
  args: [
490
- config,
490
+ params,
491
491
  assets,
492
492
  shares,
493
493
  slippageAmount,
@@ -499,26 +499,26 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
499
499
  }
500
500
  case "Blue_SupplyCollateral": {
501
501
  const { id, assets, onBehalf } = operation.args;
502
- const { config } = dataBefore.getMarket(id);
503
- if (convexWrapperTokens[chainId].has(config.collateralToken)) {
502
+ const { params } = dataBefore.getMarket(id);
503
+ if (convexWrapperTokens[chainId].has(params.collateralToken)) {
504
504
  actions.push({
505
505
  type: "erc20WrapperDepositFor",
506
- args: [config.collateralToken, assets],
506
+ args: [params.collateralToken, assets],
507
507
  });
508
508
  break;
509
509
  }
510
510
  actions.push({
511
511
  type: "morphoSupplyCollateral",
512
- args: [config, assets, onBehalf, callbackBundle?.actions ?? []],
512
+ args: [params, assets, onBehalf, callbackBundle?.actions ?? []],
513
513
  });
514
514
  break;
515
515
  }
516
516
  case "Blue_WithdrawCollateral": {
517
517
  const { id, assets, receiver } = operation.args;
518
- const { config } = dataBefore.getMarket(id);
518
+ const { params } = dataBefore.getMarket(id);
519
519
  actions.push({
520
520
  type: "morphoWithdrawCollateral",
521
- args: [config, assets, receiver],
521
+ args: [params, assets, receiver],
522
522
  });
523
523
  break;
524
524
  }
@@ -581,10 +581,10 @@ export const encodeOperation = (operation, dataBefore, supportsSignature = true,
581
581
  address,
582
582
  fee,
583
583
  withdrawals.map(({ id, assets }) => ({
584
- marketParams: dataBefore.getMarket(id).config,
584
+ marketParams: dataBefore.getMarket(id).params,
585
585
  amount: assets,
586
586
  })),
587
- dataBefore.getMarket(supplyMarketId).config,
587
+ dataBefore.getMarket(supplyMarketId).params,
588
588
  ],
589
589
  });
590
590
  break;
package/lib/operations.js CHANGED
@@ -195,7 +195,7 @@ export const populateSubBundle = (inputOperation, data, options = {}) => {
195
195
  const newTotalSupplyAssets = market.totalSupplyAssets - withdrawnAssets;
196
196
  const newTotalBorrowAssets = market.totalBorrowAssets + borrowedAssets;
197
197
  const reallocations = {};
198
- const supplyTargetUtilization = publicAllocatorOptions?.supplyTargetUtilization?.[market.config.id] ??
198
+ const supplyTargetUtilization = publicAllocatorOptions?.supplyTargetUtilization?.[market.params.id] ??
199
199
  DEFAULT_SUPPLY_TARGET_UTILIZATION;
200
200
  if (MarketUtils.getUtilization({
201
201
  totalSupplyAssets: newTotalSupplyAssets,
@@ -439,10 +439,10 @@ export const finalizeBundle = (operations, startData, receiver, unwrapTokens = n
439
439
  switch (operation.type) {
440
440
  case "Blue_Borrow":
441
441
  case "Blue_Withdraw":
442
- token = startData.getMarket(operation.args.id).config.loanToken;
442
+ token = startData.getMarket(operation.args.id).params.loanToken;
443
443
  break;
444
444
  case "Blue_WithdrawCollateral":
445
- token = startData.getMarket(operation.args.id).config.collateralToken;
445
+ token = startData.getMarket(operation.args.id).params.collateralToken;
446
446
  break;
447
447
  case "MetaMorpho_Withdraw":
448
448
  token = startData.getVault(operation.address).asset;
@@ -1,7 +1,7 @@
1
1
  import type { Account, Chain, Client, Hex, SendTransactionRequest, Transport } from "viem";
2
- import type { Address, MarketConfig } from "@morpho-org/blue-sdk";
2
+ import type { Address, MarketParams } from "@morpho-org/blue-sdk";
3
3
  import type { SimulationResult } from "@morpho-org/simulation-sdk";
4
- export type MarketParams = Pick<MarketConfig, "loanToken" | "collateralToken" | "oracle" | "irm" | "lltv">;
4
+ export type InputMarketParams = Pick<MarketParams, "loanToken" | "collateralToken" | "oracle" | "irm" | "lltv">;
5
5
  export interface Authorization {
6
6
  authorizer: Address;
7
7
  authorized: Address;
@@ -10,7 +10,7 @@ export interface Authorization {
10
10
  deadline: bigint;
11
11
  }
12
12
  export interface ReallocationWithdrawal {
13
- marketParams: MarketParams;
13
+ marketParams: InputMarketParams;
14
14
  amount: bigint;
15
15
  }
16
16
  export interface Permit2PermitSingleDetails {
@@ -88,7 +88,7 @@ export interface ActionArgs {
88
88
  skipRevert?: boolean
89
89
  ];
90
90
  morphoSupply: [
91
- market: MarketParams,
91
+ market: InputMarketParams,
92
92
  assets: bigint,
93
93
  shares: bigint,
94
94
  slippageAmount: bigint,
@@ -96,20 +96,20 @@ export interface ActionArgs {
96
96
  onMorphoSupply: Action[]
97
97
  ];
98
98
  morphoSupplyCollateral: [
99
- market: MarketParams,
99
+ market: InputMarketParams,
100
100
  assets: bigint,
101
101
  onBehalf: Address,
102
102
  onMorphoSupplyCollateral: Action[]
103
103
  ];
104
104
  morphoBorrow: [
105
- market: MarketParams,
105
+ market: InputMarketParams,
106
106
  assets: bigint,
107
107
  shares: bigint,
108
108
  slippageAmount: bigint,
109
109
  receiver: Address
110
110
  ];
111
111
  morphoRepay: [
112
- market: MarketParams,
112
+ market: InputMarketParams,
113
113
  assets: bigint,
114
114
  shares: bigint,
115
115
  slippageAmount: bigint,
@@ -117,14 +117,14 @@ export interface ActionArgs {
117
117
  onMorphoRepay: Action[]
118
118
  ];
119
119
  morphoWithdraw: [
120
- market: MarketParams,
120
+ market: InputMarketParams,
121
121
  assets: bigint,
122
122
  shares: bigint,
123
123
  slippageAmount: bigint,
124
124
  receiver: Address
125
125
  ];
126
126
  morphoWithdrawCollateral: [
127
- market: MarketParams,
127
+ market: InputMarketParams,
128
128
  assets: bigint,
129
129
  receiver: Address
130
130
  ];
@@ -133,7 +133,7 @@ export interface ActionArgs {
133
133
  vault: Address,
134
134
  value: bigint,
135
135
  withdrawals: ReallocationWithdrawal[],
136
- supplyMarket: MarketParams
136
+ supplyMarket: InputMarketParams
137
137
  ];
138
138
  urdClaim: [
139
139
  distributor: Address,
package/package.json CHANGED
@@ -1,7 +1,17 @@
1
1
  {
2
2
  "name": "@morpho-org/bundler-sdk-viem",
3
- "version": "2.0.0-next.2",
4
- "author": "Morpho Labs <contact@morpho.org>",
3
+ "description": "Viem-based extension of `@morpho-org/simulation-sdk` that exports utilities to transform simple interactions on Morpho (such as `Blue_Borrow`) and Morpho Vaults (such as `MetaMorpho_Deposit`) into the required bundles (with ERC20 approvals, transfers, etc) to submit to the bundler onchain.",
4
+ "version": "2.0.0-next.20",
5
+ "author": "Morpho Association <contact@morpho.org>",
6
+ "contributors": [
7
+ "Rubilmax <rmilon@gmail.com>"
8
+ ],
9
+ "repository": "github:morpho-org/sdks",
10
+ "homepage": "https://github.com/morpho-org/sdks",
11
+ "bugs": {
12
+ "url": "https://github.com/morpho-org/sdks/issues",
13
+ "email": "contact@morpho.org"
14
+ },
5
15
  "license": "MIT",
6
16
  "type": "module",
7
17
  "main": "lib/index.js",
@@ -10,59 +20,31 @@
10
20
  ],
11
21
  "peerDependencies": {
12
22
  "viem": "^2.0.0",
13
- "@morpho-org/blue-sdk-viem": "^1.12.4",
14
- "@morpho-org/morpho-ts": "^1.12.4",
15
- "@morpho-org/blue-sdk": "^1.12.4",
16
- "@morpho-org/simulation-sdk": "^1.12.4"
23
+ "@morpho-org/blue-sdk-viem": "^2.0.0-next.18",
24
+ "@morpho-org/blue-sdk": "^2.0.0-next.20",
25
+ "@morpho-org/morpho-ts": "^2.0.0-next.9",
26
+ "@morpho-org/simulation-sdk": "^2.0.0-next.15"
17
27
  },
18
28
  "devDependencies": {
19
29
  "@testing-library/dom": "^10.4.0",
20
- "@types/lodash": "^4.17.7",
21
- "@types/node": "^22.2.0",
30
+ "@types/lodash": "^4.17.12",
31
+ "@types/node": "^22.7.8",
22
32
  "lodash": "^4.17.21",
23
33
  "typescript": "^5.6.3",
24
- "viem": "^2.21.19",
34
+ "viem": "^2.21.36",
25
35
  "vitest": "^2.1.3",
26
- "@morpho-org/blue-sdk": "^1.12.4",
27
- "@morpho-org/blue-sdk-viem": "^1.12.4",
28
- "@morpho-org/morpho-test": "^1.12.4",
29
- "@morpho-org/morpho-ts": "^1.12.4",
30
- "@morpho-org/simulation-sdk": "^1.12.4",
31
- "@morpho-org/test-viem": "^1.12.4",
32
- "@morpho-org/test-wagmi": "^1.12.4",
33
- "@morpho-org/simulation-sdk-wagmi": "^1.12.4"
34
- },
35
- "release": {
36
- "branches": [
37
- "main",
38
- {
39
- "name": "next",
40
- "prerelease": true
41
- }
42
- ],
43
- "extends": "semantic-release-monorepo",
44
- "plugins": [
45
- "@semantic-release/commit-analyzer",
46
- "@semantic-release/release-notes-generator",
47
- [
48
- "@semantic-release/exec",
49
- {
50
- "prepareCmd": "pnpm version ${nextRelease.version} --no-git-tag-version",
51
- "publishCmd": "pnpm publish --access public --tag ${nextRelease.channel} --no-git-checks"
52
- }
53
- ],
54
- "@semantic-release/github"
55
- ]
36
+ "@morpho-org/blue-sdk": "^2.0.0-next.20",
37
+ "@morpho-org/morpho-test": "^2.0.0-next.11",
38
+ "@morpho-org/morpho-ts": "^2.0.0-next.9",
39
+ "@morpho-org/blue-sdk-viem": "^2.0.0-next.18",
40
+ "@morpho-org/simulation-sdk": "^2.0.0-next.15",
41
+ "@morpho-org/simulation-sdk-wagmi": "^2.0.0-next.18",
42
+ "@morpho-org/test": "^2.0.0-next.16",
43
+ "@morpho-org/test-wagmi": "^2.0.0-next.16"
56
44
  },
57
45
  "scripts": {
58
46
  "prepublish": "$npm_execpath build",
59
47
  "build": "tsc --build tsconfig.build.json"
60
48
  },
61
- "types": "lib/index.d.ts",
62
- "exports": {
63
- ".": {
64
- "types": "./lib/index.d.ts",
65
- "default": "./lib/index.js"
66
- }
67
- }
49
+ "types": "lib/index.d.ts"
68
50
  }