@morpho-org/bundler-sdk-viem 1.12.4

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Morpho Association
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,34 @@
1
+ # @morpho-org/bundler-sdk-viem
2
+
3
+ <a href="https://www.npmjs.com/package/@morpho-org/bundler-sdk-viem">
4
+ <picture>
5
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/@morpho-org/bundler-sdk-viem?colorA=21262d&colorB=21262d&style=flat">
6
+ <img src="https://img.shields.io/npm/v/@morpho-org/bundler-sdk-viem?colorA=f6f8fa&colorB=f6f8fa&style=flat" alt="Version">
7
+ </picture>
8
+ </a>
9
+ <a href="https://github.com/morpho-org/bundler-sdk-viem/blob/main/LICENSE">
10
+ <picture>
11
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/l/@morpho-org/bundler-sdk-viem?colorA=21262d&colorB=21262d&style=flat">
12
+ <img src="https://img.shields.io/npm/l/@morpho-org/bundler-sdk-viem?colorA=f6f8fa&colorB=f6f8fa&style=flat" alt="MIT License">
13
+ </picture>
14
+ </a>
15
+ <a href="https://www.npmjs.com/package/@morpho-org/bundler-sdk-viem">
16
+ <picture>
17
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/dm/@morpho-org/bundler-sdk-viem?colorA=21262d&colorB=21262d&style=flat">
18
+ <img src="https://img.shields.io/npm/dm/@morpho-org/bundler-sdk-viem?colorA=f6f8fa&colorB=f6f8fa&style=flat" alt="Downloads per month">
19
+ </picture>
20
+ </a>
21
+ <br />
22
+ <br />
23
+
24
+ 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.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ npm install @morpho-org/bundler-sdk-viem
30
+ ```
31
+
32
+ ```bash
33
+ yarn add @morpho-org/bundler-sdk-viem
34
+ ```
@@ -0,0 +1,320 @@
1
+ import { type Address, type Hex } from "viem";
2
+ import type { Action, Authorization, MarketParams, Permit2PermitSingle, ReallocationWithdrawal } from "./types/index.js";
3
+ export type BundlerCall = Hex;
4
+ /**
5
+ * Namespace to easily encode calls to the Bundler contract, using ethers.
6
+ */
7
+ export declare namespace BundlerAction {
8
+ function encode({ type, args }: Action): BundlerCall;
9
+ /**
10
+ * Encodes a call to the Bundler to transfer native tokens (ETH on ethereum, MATIC on polygon, etc).
11
+ * @param recipient The address to send native tokens to.
12
+ * @param amount The amount of native tokens to send (in wei).
13
+ */
14
+ function nativeTransfer(recipient: Address, amount: bigint): BundlerCall;
15
+ /**
16
+ * Encodes a call to the Bundler to transfer ERC20 tokens.
17
+ * @param asset The address of the ERC20 token to transfer.
18
+ * @param recipient The address to send tokens to.
19
+ * @param amount The amount of tokens to send.
20
+ */
21
+ function erc20Transfer(asset: Address, recipient: Address, amount: bigint): BundlerCall;
22
+ /**
23
+ * Encodes a call to the Bundler to transfer ERC20 tokens from the sender to the Bundler.
24
+ * @param asset The address of the ERC20 token to transfer.
25
+ * @param amount The amount of tokens to send.
26
+ */
27
+ function erc20TransferFrom(asset: Address, amount: bigint): BundlerCall;
28
+ /**
29
+ * Encodes a call to the Bundler to permit an ERC20 token.
30
+ * @param asset The address of the ERC20 token to permit.
31
+ * @param amount The amount of tokens to permit.
32
+ * @param deadline The timestamp until which the signature is valid.
33
+ * @param signature The Ethers signature to permit the tokens.
34
+ * @param skipRevert Whether to allow the permit to revert without making the whole multicall revert.
35
+ */
36
+ function permit(asset: Address, amount: bigint, deadline: bigint, signature: Hex, skipRevert: boolean): BundlerCall;
37
+ /**
38
+ * Encodes a call to the Bundler to permit DAI.
39
+ * @param nonce The permit nonce used.
40
+ * @param expiry The timestamp until which the signature is valid.
41
+ * @param allowed The amount of DAI to permit.
42
+ * @param signature The Ethers signature to permit the tokens.
43
+ * @param skipRevert Whether to allow the permit to revert without making the whole multicall revert.
44
+ */
45
+ function permitDai(nonce: bigint, expiry: bigint, allowed: boolean, signature: Hex, skipRevert: boolean): BundlerCall;
46
+ /**
47
+ * Encodes a call to the Bundler to permit ERC20 tokens via Permit2.
48
+ * @param permitSingle The permit details to submit to Permit2.
49
+ * @param signature The Ethers signature to permit the tokens.
50
+ * @param skipRevert Whether to allow the permit to revert without making the whole multicall revert.
51
+ */
52
+ function approve2(permitSingle: Permit2PermitSingle, signature: Hex, skipRevert: boolean): BundlerCall;
53
+ /**
54
+ * Encodes a call to the Bundler to transfer ERC20 tokens via Permit2 from the sender to the Bundler.
55
+ * @param asset The address of the ERC20 token to transfer.
56
+ * @param amount The amount of tokens to send.
57
+ */
58
+ function transferFrom2(asset: Address, amount: bigint): BundlerCall;
59
+ /**
60
+ * Encodes a call to the Bundler to wrap ERC20 tokens via the provided ERC20Wrapper.
61
+ * @param wrapper The address of the ERC20 wrapper token.
62
+ * @param amount The amount of tokens to send.
63
+ */
64
+ function erc20WrapperDepositFor(wrapper: Address, amount: bigint): BundlerCall;
65
+ /**
66
+ * Encodes a call to the Bundler to unwrap ERC20 tokens from the provided ERC20Wrapper.
67
+ * @param wrapper The address of the ERC20 wrapper token.
68
+ * @param account The address to send the underlying ERC20 tokens.
69
+ * @param amount The amount of tokens to send.
70
+ */
71
+ function erc20WrapperWithdrawTo(wrapper: Address, account: Address, amount: bigint): BundlerCall;
72
+ /**
73
+ * Encodes a call to the Bundler to mint shares of the provided ERC4626 vault.
74
+ * @param erc4626 The address of the ERC4626 vault.
75
+ * @param shares The amount of shares to mint.
76
+ * @param maxAssets The maximum amount of assets to deposit (protects the sender from unexpected slippage).
77
+ * @param receiver The address to send the shares to.
78
+ */
79
+ function erc4626Mint(erc4626: Address, shares: bigint, maxAssets: bigint, receiver: Address): BundlerCall;
80
+ /**
81
+ * Encodes a call to the Bundler to deposit assets into the provided ERC4626 vault.
82
+ * @param erc4626 The address of the ERC4626 vault.
83
+ * @param assets The amount of assets to deposit.
84
+ * @param minShares The minimum amount of shares to mint (protects the sender from unexpected slippage).
85
+ * @param receiver The address to send the shares to.
86
+ */
87
+ function erc4626Deposit(erc4626: Address, assets: bigint, minShares: bigint, receiver: Address): BundlerCall;
88
+ /**
89
+ * Encodes a call to the Bundler to withdraw assets from the provided ERC4626 vault.
90
+ * @param erc4626 The address of the ERC4626 vault.
91
+ * @param assets The amount of assets to withdraw.
92
+ * @param maxShares The maximum amount of shares to redeem (protects the sender from unexpected slippage).
93
+ * @param receiver The address to send the assets to.
94
+ */
95
+ function erc4626Withdraw(erc4626: Address, assets: bigint, maxShares: bigint, receiver: Address, owner: Address): BundlerCall;
96
+ /**
97
+ * Encodes a call to the Bundler to redeem shares from the provided ERC4626 vault.
98
+ * @param erc4626 The address of the ERC4626 vault.
99
+ * @param shares The amount of shares to redeem.
100
+ * @param minAssets The minimum amount of assets to withdraw (protects the sender from unexpected slippage).
101
+ * @param receiver The address to send the assets to.
102
+ */
103
+ function erc4626Redeem(erc4626: Address, shares: bigint, minAssets: bigint, receiver: Address, owner: Address): BundlerCall;
104
+ /**
105
+ * Encodes a call to the Bundler to authorize an account on Morpho Blue.
106
+ * @param authorization The authorization details to submit to Morpho Blue.
107
+ * @param signature The Ethers signature to authorize the account.
108
+ * @param skipRevert Whether to allow the authorization call to revert without making the whole multicall revert.
109
+ */
110
+ function morphoSetAuthorizationWithSig(authorization: Authorization, signature: Hex, skipRevert: boolean): BundlerCall;
111
+ /**
112
+ * Encodes a call to the Bundler to supply to a Morpho Blue market.
113
+ * @param market The market params to supply to.
114
+ * @param assets The amount of assets to supply.
115
+ * @param shares The amount of supply shares to mint.
116
+ * @param slippageAmount The maximum (resp. minimum) amount of assets (resp. supply shares) to supply (resp. mint) (protects the sender from unexpected slippage).
117
+ * @param onBehalf The address to supply on behalf of.
118
+ * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupply` callback.
119
+ */
120
+ function morphoSupply(market: MarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, onBehalf: Address, callbackCalls: BundlerCall[]): BundlerCall;
121
+ /**
122
+ * Encodes a call to the Bundler to supply collateral to a Morpho Blue market.
123
+ * @param market The market params to supply to.
124
+ * @param assets The amount of assets to supply.
125
+ * @param onBehalf The address to supply on behalf of.
126
+ * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupplyCollateral` callback.
127
+ */
128
+ function morphoSupplyCollateral(market: MarketParams, assets: bigint, onBehalf: Address, callbackCalls: BundlerCall[]): BundlerCall;
129
+ /**
130
+ * Encodes a call to the Bundler to borrow from a Morpho Blue market.
131
+ * @param market The market params to borrow from.
132
+ * @param assets The amount of assets to borrow.
133
+ * @param shares The amount of borrow shares to mint.
134
+ * @param slippageAmount The minimum (resp. maximum) amount of assets (resp. borrow shares) to borrow (resp. mint) (protects the sender from unexpected slippage).
135
+ * @param receiver The address to send borrowed tokens to.
136
+ */
137
+ function morphoBorrow(market: MarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, receiver: Address): BundlerCall;
138
+ /**
139
+ * Encodes a call to the Bundler to repay to a Morpho Blue market.
140
+ * @param market The market params to repay to.
141
+ * @param assets The amount of assets to repay.
142
+ * @param shares The amount of borrow shares to redeem.
143
+ * @param slippageAmount The maximum (resp. minimum) amount of assets (resp. borrow shares) to repay (resp. redeem) (protects the sender from unexpected slippage).
144
+ * @param onBehalf The address to repay on behalf of.
145
+ * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoSupply` callback.
146
+ */
147
+ function morphoRepay(market: MarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, onBehalf: Address, callbackCalls: BundlerCall[]): BundlerCall;
148
+ /**
149
+ * Encodes a call to the Bundler to withdraw from a Morpho Blue market.
150
+ * @param market The market params to withdraw from.
151
+ * @param assets The amount of assets to withdraw.
152
+ * @param shares The amount of supply shares to redeem.
153
+ * @param slippageAmount The minimum (resp. maximum) amount of assets (resp. supply shares) to withdraw (resp. redeem) (protects the sender from unexpected slippage).
154
+ * @param receiver The address to send withdrawn tokens to.
155
+ */
156
+ function morphoWithdraw(market: MarketParams, assets: bigint, shares: bigint, slippageAmount: bigint, receiver: Address): BundlerCall;
157
+ /**
158
+ * Encodes a call to the Bundler to withdraw collateral from a Morpho Blue market.
159
+ * @param market The market params to withdraw from.
160
+ * @param assets The amount of assets to withdraw.
161
+ * @param receiver The address to send withdrawn tokens to.
162
+ */
163
+ function morphoWithdrawCollateral(market: MarketParams, assets: bigint, receiver: Address): BundlerCall;
164
+ /**
165
+ * Encodes a call to the Bundler to flash loan from Morpho Blue.
166
+ * @param asset The address of the ERC20 token to flash loan.
167
+ * @param amount The amount of tokens to flash loan.
168
+ * @param callbackCalls The array of calls to execute inside Morpho Blue's `onMorphoFlashLoan` callback.
169
+ */
170
+ function morphoFlashLoan(asset: Address, amount: bigint, callbackCalls: BundlerCall[]): BundlerCall;
171
+ /**
172
+ * Encodes a call to the Bundler to trigger a public reallocation on the PublicAllocator.
173
+ * @param publicAllocator The address of the PublicAllocator to use.
174
+ * @param vault The vault to reallocate.
175
+ * @param value The value of the call. Can be used to pay the vault reallocation fees.
176
+ * @param withdrawals The array of withdrawals to perform, before supplying everything to the supply market.
177
+ * @param supplyMarketParams The market params to reallocate to.
178
+ */
179
+ function metaMorphoReallocateTo(publicAllocator: Address, vault: Address, value: bigint, withdrawals: ReallocationWithdrawal[], supplyMarketParams: MarketParams): BundlerCall;
180
+ /**
181
+ * Encodes a call to the Bundler to claim rewards from the Universal Rewards Distributor.
182
+ * @param distributor The address of the distributor to claim rewards from.
183
+ * @param account The address to claim rewards for.
184
+ * @param reward The address of the reward token to claim.
185
+ * @param amount The amount of rewards to claim.
186
+ * @param proof The Merkle proof to claim the rewards.
187
+ * @param skipRevert Whether to allow the claim to revert without making the whole multicall revert.
188
+ */
189
+ function urdClaim(distributor: Address, account: Address, reward: Address, amount: bigint, proof: Hex[], skipRevert: boolean): BundlerCall;
190
+ /**
191
+ * Encodes a call to the Bundler to wrap native tokens (ETH to WETH on ethereum, MATIC to WMATIC on polygon, etc).
192
+ * @param amount The amount of native tokens to wrap (in wei).
193
+ */
194
+ function wrapNative(amount: bigint): BundlerCall;
195
+ /**
196
+ * Encodes a call to the Bundler to unwrap native tokens (WETH to ETH on ethereum, WMATIC to MATIC on polygon, etc).
197
+ * @param amount The amount of native tokens to unwrap (in wei).
198
+ */
199
+ function unwrapNative(amount: bigint): BundlerCall;
200
+ /**
201
+ * Encodes a call to the Bundler to stake native tokens using Lido (ETH to stETH on ethereum).
202
+ * @param amount The amount of native tokens to stake (in wei).
203
+ * @param minShares The minimum amount of shares to mint (protects the sender from unexpected slippage).
204
+ * @param referral The referral address to use.
205
+ */
206
+ function stakeEth(amount: bigint, minShares: bigint, referral: Address): BundlerCall;
207
+ /**
208
+ * Encodes a call to the Bundler to wrap stETH (stETH to wstETH on ethereum).
209
+ * @param amount The amount of stETH to wrap (in wei).
210
+ */
211
+ function wrapStEth(amount: bigint): BundlerCall;
212
+ /**
213
+ * Encodes a call to the Bundler to unwrap wstETH (wstETH to stETH on ethereum).
214
+ * @param amount The amount of wstETH to unwrap (in wei).
215
+ */
216
+ function unwrapStEth(amount: bigint): BundlerCall;
217
+ /**
218
+ * ! Only available on AaveV2MigrationBundler instances (not the main Bundler contract!).
219
+ * Encodes a call to the Bundler to repay a debt on AaveV2.
220
+ * @param asset The debt asset to repay.
221
+ * @param amount The amount of debt to repay.
222
+ * @param rateMode The interest rate mode used by the debt to repay.
223
+ */
224
+ function aaveV2Repay(asset: Address, amount: bigint, rateMode: bigint): BundlerCall;
225
+ /**
226
+ * ! Only available on AaveV2MigrationBundler instances (not the main Bundler contract!).
227
+ * Encodes a call to the Bundler to withdrawn from AaveV2.
228
+ * @param asset The asset to withdraw.
229
+ * @param amount The amount of asset to withdraw.
230
+ */
231
+ function aaveV2Withdraw(asset: Address, amount: bigint): BundlerCall;
232
+ /**
233
+ * ! Only available on AaveV3MigrationBundler instances (not the main Bundler contract!).
234
+ * Encodes a call to the Bundler to repay a debt on AaveV3.
235
+ * @param asset The debt asset to repay.
236
+ * @param amount The amount of debt to repay.
237
+ * @param rateMode The interest rate mode used by the debt to repay.
238
+ */
239
+ function aaveV3Repay(asset: Address, amount: bigint, rateMode: bigint): BundlerCall;
240
+ /**
241
+ * ! Only available on AaveV3MigrationBundler instances (not the main Bundler contract!).
242
+ * Encodes a call to the Bundler to withdrawn from AaveV3.
243
+ * @param asset The asset to withdraw.
244
+ * @param amount The amount of asset to withdraw.
245
+ */
246
+ function aaveV3Withdraw(asset: Address, amount: bigint): BundlerCall;
247
+ /**
248
+ * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!).
249
+ * Encodes a call to the Bundler to repay a debt on Morpho's AaveV3Optimizer.
250
+ * @param underlying The underlying debt asset to repay.
251
+ * @param amount The amount of debt to repay.
252
+ * @param maxIterations The maximum amount of iterations to use for the repayment.
253
+ */
254
+ function aaveV3OptimizerRepay(underlying: Address, amount: bigint): BundlerCall;
255
+ /**
256
+ * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!).
257
+ * Encodes a call to the Bundler to withdraw from Morpho's AaveV3Optimizer.
258
+ * @param underlying The underlying asset to withdraw.
259
+ * @param amount The amount to withdraw.
260
+ * @param maxIterations The maximum amount of iterations to use for the withdrawal.
261
+ */
262
+ function aaveV3OptimizerWithdraw(underlying: Address, amount: bigint, maxIterations: bigint): BundlerCall;
263
+ /**
264
+ * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!).
265
+ * Encodes a call to the Bundler to withdraw collateral from Morpho's AaveV3Optimizer.
266
+ * @param underlying The underlying asset to withdraw.
267
+ * @param amount The amount to withdraw.
268
+ */
269
+ function aaveV3OptimizerWithdrawCollateral(underlying: Address, amount: bigint): BundlerCall;
270
+ /**
271
+ * ! Only available on AaveV3OptimizerMigrationBundler instances (not the main Bundler contract!).
272
+ * Encodes a call to the Bundler to approve the Bundler as the sender's manager on Morpho's AaveV3Optimizer.
273
+ * @param isApproved Whether the manager is approved.
274
+ * @param nonce The nonce used to sign.
275
+ * @param deadline The timestamp until which the signature is valid.
276
+ * @param signature The Ethers signature to submit.
277
+ * @param skipRevert Whether to allow the signature to revert without making the whole multicall revert.
278
+ */
279
+ function aaveV3OptimizerApproveManagerWithSig(isApproved: boolean, nonce: bigint, deadline: bigint, signature: Hex, skipRevert: boolean): BundlerCall;
280
+ /**
281
+ * ! Only available on CompoundV2MigrationBundler instances (not the main Bundler contract!).
282
+ * Encodes a call to the Bundler to repay a debt on CompoundV2.
283
+ * @param cToken The cToken on which to repay the debt.
284
+ * @param amount The amount of debt to repay.
285
+ */
286
+ function compoundV2Repay(cToken: Address, amount: bigint): BundlerCall;
287
+ /**
288
+ * ! Only available on CompoundV2MigrationBundler instances (not the main Bundler contract!).
289
+ * Encodes a call to the Bundler to withdraw collateral from CompoundV2.
290
+ * @param cToken The cToken on which to withdraw.
291
+ * @param amount The amount to withdraw.
292
+ */
293
+ function compoundV2Redeem(cToken: Address, amount: bigint): BundlerCall;
294
+ /**
295
+ * ! Only available on CompoundV3MigrationBundler instances (not the main Bundler contract!).
296
+ * Encodes a call to the Bundler to repay a debt on CompoundV3.
297
+ * @param instance The CompoundV3 instance on which to repay the debt.
298
+ * @param amount The amount of debt to repay.
299
+ */
300
+ function compoundV3Repay(instance: Address, amount: bigint): BundlerCall;
301
+ /**
302
+ * ! Only available on CompoundV3MigrationBundler instances (not the main Bundler contract!).
303
+ * Encodes a call to the Bundler to withdraw collateral from CompoundV3.
304
+ * @param instance The CompoundV3 instance on which to withdraw.
305
+ * @param amount The amount to withdraw.
306
+ */
307
+ function compoundV3WithdrawFrom(instance: Address, asset: Address, amount: bigint): BundlerCall;
308
+ /**
309
+ * ! Only available on CompoundV3MigrationBundler instances (not the main Bundler contract!).
310
+ * Encodes a call to the Bundler to allow the Bundler to act on the sender's position on CompoundV3.
311
+ * @param instance The CompoundV3 instance on which to submit the signature.
312
+ * @param isAllowed Whether the manager is allowed.
313
+ * @param nonce The nonce used to sign.
314
+ * @param expiry The timestamp until which the signature is valid.
315
+ * @param signature The Ethers signature to submit.
316
+ * @param skipRevert Whether to allow the signature to revert without making the whole multicall revert.
317
+ */
318
+ function compoundV3AllowBySig(instance: Address, isAllowed: boolean, nonce: bigint, expiry: bigint, signature: Hex, skipRevert: boolean): BundlerCall;
319
+ }
320
+ export default BundlerAction;