mirror of
https://github.com/Instadapp/dsa-connectors-2.0.git
synced 2024-07-29 21:57:39 +00:00
feat: update
This commit is contained in:
parent
19dd322655
commit
3981750ec9
|
|
@ -15,7 +15,7 @@ contract Events {
|
||||||
Id indexed id,
|
Id indexed id,
|
||||||
uint256 assets,
|
uint256 assets,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
address onBehalf,
|
address indexed onBehalf,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
@ -30,7 +30,7 @@ contract Events {
|
||||||
event LogSupplyCollateralOnBehalf(
|
event LogSupplyCollateralOnBehalf(
|
||||||
Id indexed id,
|
Id indexed id,
|
||||||
uint256 assets,
|
uint256 assets,
|
||||||
address onBehalf,
|
address indexed onBehalf,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
@ -47,8 +47,8 @@ contract Events {
|
||||||
Id indexed id,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
address onBehalf,
|
address indexed onBehalf,
|
||||||
address receiver,
|
address indexed receiver,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
@ -65,7 +65,7 @@ contract Events {
|
||||||
Id indexed id,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
address onBehalf,
|
address indexed onBehalf,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
@ -80,8 +80,8 @@ contract Events {
|
||||||
event LogWithdrawCollateralOnBehalf(
|
event LogWithdrawCollateralOnBehalf(
|
||||||
Id indexed id,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
address onBehalf,
|
address indexed onBehalf,
|
||||||
address receiver,
|
address indexed receiver,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
@ -98,7 +98,7 @@ contract Events {
|
||||||
Id indexed id,
|
Id indexed id,
|
||||||
uint256 amounts,
|
uint256 amounts,
|
||||||
uint256 shares,
|
uint256 shares,
|
||||||
address onBehalf,
|
address indexed onBehalf,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,14 @@ import "../../common/stores.sol";
|
||||||
import "../../common/basic.sol";
|
import "../../common/basic.sol";
|
||||||
import "../../common/interfaces.sol";
|
import "../../common/interfaces.sol";
|
||||||
import {MorphoBalancesLib} from "./libraries/periphery/MorphoBalancesLib.sol";
|
import {MorphoBalancesLib} from "./libraries/periphery/MorphoBalancesLib.sol";
|
||||||
|
import {MorphoLib} from "./libraries/periphery/MorphoLib.sol";
|
||||||
import {UtilsLib} from "./libraries/UtilsLib.sol";
|
import {UtilsLib} from "./libraries/UtilsLib.sol";
|
||||||
import {MarketParamsLib} from "./libraries/MarketParamsLib.sol";
|
import {MarketParamsLib} from "./libraries/MarketParamsLib.sol";
|
||||||
import {SharesMathLib} from "./libraries/SharesMathLib.sol";
|
import {SharesMathLib} from "./libraries/SharesMathLib.sol";
|
||||||
|
|
||||||
abstract contract Helpers is Stores, Basic {
|
abstract contract Helpers is Stores, Basic {
|
||||||
using MorphoBalancesLib for IMorpho;
|
using MorphoBalancesLib for IMorpho;
|
||||||
|
using MorphoLib for IMorpho;
|
||||||
using MarketParamsLib for MarketParams;
|
using MarketParamsLib for MarketParams;
|
||||||
using UtilsLib for uint256;
|
using UtilsLib for uint256;
|
||||||
using SharesMathLib for uint256;
|
using SharesMathLib for uint256;
|
||||||
|
|
@ -82,7 +84,7 @@ abstract contract Helpers is Stores, Basic {
|
||||||
|
|
||||||
// Perform eth to weth conversion if necessary
|
// Perform eth to weth conversion if necessary
|
||||||
convertEthToWeth(
|
convertEthToWeth(
|
||||||
true,
|
_isEth,
|
||||||
_isModeCollateral
|
_isModeCollateral
|
||||||
? TokenInterface(_marketParams.collateralToken)
|
? TokenInterface(_marketParams.collateralToken)
|
||||||
: TokenInterface(_marketParams.loanToken),
|
: TokenInterface(_marketParams.loanToken),
|
||||||
|
|
@ -147,7 +149,7 @@ abstract contract Helpers is Stores, Basic {
|
||||||
|
|
||||||
// Perform ETH to WETH conversion if necessary
|
// Perform ETH to WETH conversion if necessary
|
||||||
convertEthToWeth(
|
convertEthToWeth(
|
||||||
true,
|
_isEth,
|
||||||
TokenInterface(_marketParams.loanToken),
|
TokenInterface(_marketParams.loanToken),
|
||||||
_assets
|
_assets
|
||||||
);
|
);
|
||||||
|
|
@ -161,9 +163,7 @@ abstract contract Helpers is Stores, Basic {
|
||||||
MarketParams memory _marketParams,
|
MarketParams memory _marketParams,
|
||||||
address _onBehalf
|
address _onBehalf
|
||||||
) internal view returns (uint256 _assets) {
|
) internal view returns (uint256 _assets) {
|
||||||
uint256 _borrowedShareAmt = MORPHO_BLUE
|
uint256 _borrowedShareAmt = MORPHO_BLUE.borrowShares(_id, _onBehalf);
|
||||||
.position(_id, _onBehalf)
|
|
||||||
.borrowShares;
|
|
||||||
|
|
||||||
(, , uint256 totalBorrowAssets, uint256 totalBorrowShares) = MORPHO_BLUE
|
(, , uint256 totalBorrowAssets, uint256 totalBorrowShares) = MORPHO_BLUE
|
||||||
.expectedMarketBalances(_marketParams);
|
.expectedMarketBalances(_marketParams);
|
||||||
|
|
|
||||||
|
|
@ -1,150 +0,0 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
pragma solidity ^0.8.0;
|
|
||||||
|
|
||||||
import {Id, MarketParams} from "../interfaces/IMorpho.sol";
|
|
||||||
|
|
||||||
/// @title EventsLib
|
|
||||||
/// @author Morpho Labs
|
|
||||||
/// @custom:contact security@morpho.org
|
|
||||||
/// @notice Library exposing events.
|
|
||||||
library EventsLib {
|
|
||||||
/// @notice Emitted when setting a new owner.
|
|
||||||
/// @param newOwner The new owner of the contract.
|
|
||||||
event SetOwner(address indexed newOwner);
|
|
||||||
|
|
||||||
/// @notice Emitted when setting a new fee.
|
|
||||||
/// @param id The market id.
|
|
||||||
/// @param newFee The new fee.
|
|
||||||
event SetFee(Id indexed id, uint256 newFee);
|
|
||||||
|
|
||||||
/// @notice Emitted when setting a new fee recipient.
|
|
||||||
/// @param newFeeRecipient The new fee recipient.
|
|
||||||
event SetFeeRecipient(address indexed newFeeRecipient);
|
|
||||||
|
|
||||||
/// @notice Emitted when enabling an IRM.
|
|
||||||
/// @param irm The IRM that was enabled.
|
|
||||||
event EnableIrm(address indexed irm);
|
|
||||||
|
|
||||||
/// @notice Emitted when enabling an LLTV.
|
|
||||||
/// @param lltv The LLTV that was enabled.
|
|
||||||
event EnableLltv(uint256 lltv);
|
|
||||||
|
|
||||||
/// @notice Emitted when creating a market.
|
|
||||||
/// @param id The market id.
|
|
||||||
/// @param marketParams The market that was created.
|
|
||||||
event CreateMarket(Id indexed id, MarketParams marketParams);
|
|
||||||
|
|
||||||
/// @notice Emitted on supply of assets.
|
|
||||||
/// @dev Warning: `feeRecipient` receives some shares during interest accrual without any supply event emitted.
|
|
||||||
/// @param id The market id.
|
|
||||||
/// @param caller The caller.
|
|
||||||
/// @param onBehalf The owner of the modified position.
|
|
||||||
/// @param assets The amount of assets supplied.
|
|
||||||
/// @param shares The amount of shares minted.
|
|
||||||
event Supply(Id indexed id, address indexed caller, address indexed onBehalf, uint256 assets, uint256 shares);
|
|
||||||
|
|
||||||
/// @notice Emitted on withdrawal of assets.
|
|
||||||
/// @param id The market id.
|
|
||||||
/// @param caller The caller.
|
|
||||||
/// @param onBehalf The owner of the modified position.
|
|
||||||
/// @param receiver The address that received the withdrawn assets.
|
|
||||||
/// @param assets The amount of assets withdrawn.
|
|
||||||
/// @param shares The amount of shares burned.
|
|
||||||
event Withdraw(
|
|
||||||
Id indexed id,
|
|
||||||
address caller,
|
|
||||||
address indexed onBehalf,
|
|
||||||
address indexed receiver,
|
|
||||||
uint256 assets,
|
|
||||||
uint256 shares
|
|
||||||
);
|
|
||||||
|
|
||||||
/// @notice Emitted on borrow of assets.
|
|
||||||
/// @param id The market id.
|
|
||||||
/// @param caller The caller.
|
|
||||||
/// @param onBehalf The owner of the modified position.
|
|
||||||
/// @param receiver The address that received the borrowed assets.
|
|
||||||
/// @param assets The amount of assets borrowed.
|
|
||||||
/// @param shares The amount of shares minted.
|
|
||||||
event Borrow(
|
|
||||||
Id indexed id,
|
|
||||||
address caller,
|
|
||||||
address indexed onBehalf,
|
|
||||||
address indexed receiver,
|
|
||||||
uint256 assets,
|
|
||||||
uint256 shares
|
|
||||||
);
|
|
||||||
|
|
||||||
/// @notice Emitted on repayment of assets.
|
|
||||||
/// @param id The market id.
|
|
||||||
/// @param caller The caller.
|
|
||||||
/// @param onBehalf The owner of the modified position.
|
|
||||||
/// @param assets The amount of assets repaid. May be 1 over the corresponding market's `totalBorrowAssets`.
|
|
||||||
/// @param shares The amount of shares burned.
|
|
||||||
event Repay(Id indexed id, address indexed caller, address indexed onBehalf, uint256 assets, uint256 shares);
|
|
||||||
|
|
||||||
/// @notice Emitted on supply of collateral.
|
|
||||||
/// @param id The market id.
|
|
||||||
/// @param caller The caller.
|
|
||||||
/// @param onBehalf The owner of the modified position.
|
|
||||||
/// @param assets The amount of collateral supplied.
|
|
||||||
event SupplyCollateral(Id indexed id, address indexed caller, address indexed onBehalf, uint256 assets);
|
|
||||||
|
|
||||||
/// @notice Emitted on withdrawal of collateral.
|
|
||||||
/// @param id The market id.
|
|
||||||
/// @param caller The caller.
|
|
||||||
/// @param onBehalf The owner of the modified position.
|
|
||||||
/// @param receiver The address that received the withdrawn collateral.
|
|
||||||
/// @param assets The amount of collateral withdrawn.
|
|
||||||
event WithdrawCollateral(
|
|
||||||
Id indexed id, address caller, address indexed onBehalf, address indexed receiver, uint256 assets
|
|
||||||
);
|
|
||||||
|
|
||||||
/// @notice Emitted on liquidation of a position.
|
|
||||||
/// @param id The market id.
|
|
||||||
/// @param caller The caller.
|
|
||||||
/// @param borrower The borrower of the position.
|
|
||||||
/// @param repaidAssets The amount of assets repaid. May be 1 over the corresponding market's `totalBorrowAssets`.
|
|
||||||
/// @param repaidShares The amount of shares burned.
|
|
||||||
/// @param seizedAssets The amount of collateral seized.
|
|
||||||
/// @param badDebtAssets The amount of assets of bad debt realized.
|
|
||||||
/// @param badDebtShares The amount of borrow shares of bad debt realized.
|
|
||||||
event Liquidate(
|
|
||||||
Id indexed id,
|
|
||||||
address indexed caller,
|
|
||||||
address indexed borrower,
|
|
||||||
uint256 repaidAssets,
|
|
||||||
uint256 repaidShares,
|
|
||||||
uint256 seizedAssets,
|
|
||||||
uint256 badDebtAssets,
|
|
||||||
uint256 badDebtShares
|
|
||||||
);
|
|
||||||
|
|
||||||
/// @notice Emitted on flash loan.
|
|
||||||
/// @param caller The caller.
|
|
||||||
/// @param token The token that was flash loaned.
|
|
||||||
/// @param assets The amount that was flash loaned.
|
|
||||||
event FlashLoan(address indexed caller, address indexed token, uint256 assets);
|
|
||||||
|
|
||||||
/// @notice Emitted when setting an authorization.
|
|
||||||
/// @param caller The caller.
|
|
||||||
/// @param authorizer The authorizer address.
|
|
||||||
/// @param authorized The authorized address.
|
|
||||||
/// @param newIsAuthorized The new authorization status.
|
|
||||||
event SetAuthorization(
|
|
||||||
address indexed caller, address indexed authorizer, address indexed authorized, bool newIsAuthorized
|
|
||||||
);
|
|
||||||
|
|
||||||
/// @notice Emitted when setting an authorization with a signature.
|
|
||||||
/// @param caller The caller.
|
|
||||||
/// @param authorizer The authorizer address.
|
|
||||||
/// @param usedNonce The nonce that was used.
|
|
||||||
event IncrementNonce(address indexed caller, address indexed authorizer, uint256 usedNonce);
|
|
||||||
|
|
||||||
/// @notice Emitted when accruing interest.
|
|
||||||
/// @param id The market id.
|
|
||||||
/// @param prevBorrowRate The previous borrow rate.
|
|
||||||
/// @param interest The amount of interest accrued.
|
|
||||||
/// @param feeShares The amount of shares minted as fee.
|
|
||||||
event AccrueInterest(Id indexed id, uint256 prevBorrowRate, uint256 interest, uint256 feeShares);
|
|
||||||
}
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
||||||
pragma solidity ^0.8.0;
|
|
||||||
|
|
||||||
import {IERC20} from "../interfaces/IERC20.sol";
|
|
||||||
|
|
||||||
import {ErrorsLib} from "../libraries/ErrorsLib.sol";
|
|
||||||
|
|
||||||
interface IERC20Internal {
|
|
||||||
function transfer(address to, uint256 value) external returns (bool);
|
|
||||||
function transferFrom(address from, address to, uint256 value) external returns (bool);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// @title SafeTransferLib
|
|
||||||
/// @author Morpho Labs
|
|
||||||
/// @custom:contact security@morpho.org
|
|
||||||
/// @notice Library to manage transfers of tokens, even if calls to the transfer or transferFrom functions are not
|
|
||||||
/// returning a boolean.
|
|
||||||
library SafeTransferLib {
|
|
||||||
function safeTransfer(IERC20 token, address to, uint256 value) internal {
|
|
||||||
require(address(token).code.length > 0, ErrorsLib.NO_CODE);
|
|
||||||
|
|
||||||
(bool success, bytes memory returndata) =
|
|
||||||
address(token).call(abi.encodeCall(IERC20Internal.transfer, (to, value)));
|
|
||||||
require(success, ErrorsLib.TRANSFER_REVERTED);
|
|
||||||
require(returndata.length == 0 || abi.decode(returndata, (bool)), ErrorsLib.TRANSFER_RETURNED_FALSE);
|
|
||||||
}
|
|
||||||
|
|
||||||
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
|
|
||||||
require(address(token).code.length > 0, ErrorsLib.NO_CODE);
|
|
||||||
|
|
||||||
(bool success, bytes memory returndata) =
|
|
||||||
address(token).call(abi.encodeCall(IERC20Internal.transferFrom, (from, to, value)));
|
|
||||||
require(success, ErrorsLib.TRANSFER_FROM_REVERTED);
|
|
||||||
require(returndata.length == 0 || abi.decode(returndata, (bool)), ErrorsLib.TRANSFER_FROM_RETURNED_FALSE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,3 +1,8 @@
|
||||||
|
// import "@nomiclabs/hardhat-waffle";
|
||||||
|
// import "@nomiclabs/hardhat-ethers";
|
||||||
|
// import "@nomiclabs/hardhat-etherscan";
|
||||||
|
import "@nomicfoundation/hardhat-toolbox";
|
||||||
|
|
||||||
import "@typechain/hardhat";
|
import "@typechain/hardhat";
|
||||||
import { resolve } from "path";
|
import { resolve } from "path";
|
||||||
import { config as dotenvConfig } from "dotenv";
|
import { config as dotenvConfig } from "dotenv";
|
||||||
|
|
@ -65,7 +70,7 @@ const config: any = {
|
||||||
solidity: {
|
solidity: {
|
||||||
compilers: [
|
compilers: [
|
||||||
{
|
{
|
||||||
version: "0.8.22",
|
version: "0.8.2",
|
||||||
settings: {
|
settings: {
|
||||||
optimizer: {
|
optimizer: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
|
|
||||||
8454
package-lock.json
generated
8454
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
|
@ -8,12 +8,13 @@
|
||||||
"typechain": "^8.3.2"
|
"typechain": "^8.3.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
|
||||||
|
"@nomiclabs/hardhat-web3": "^2.0.0",
|
||||||
"@openzeppelin/contracts": "^4.9.5",
|
"@openzeppelin/contracts": "^4.9.5",
|
||||||
"@typechain/ethers-v5": "^10.2.1",
|
|
||||||
"@typechain/hardhat": "^6.1.6",
|
|
||||||
"bignumber.js": "^4.0.4",
|
|
||||||
"dotenv": "^16.3.1",
|
"dotenv": "^16.3.1",
|
||||||
"ts-node": "^10.9.2",
|
"ts-node": "^10.9.2",
|
||||||
"web3": "^4.3.0"
|
"web3": "^1.10.3",
|
||||||
|
"ethers": "^5.4.7",
|
||||||
|
"@nomiclabs/hardhat-ethers": "^2.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user