Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eth instant withdraw #347

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3955800
chore: add ETH instant withdraw implementation
zhoujia6139 Mar 10, 2023
d9b8166
chore: use ERC1155 for collateral NFT
zhoujia6139 Mar 10, 2023
3b1aee5
Merge branch 'main' into eth_instant_withdraw
zhoujia6139 Mar 10, 2023
da4867d
chore: add utilization check
zhoujia6139 Mar 11, 2023
0ca4da7
chore: fix some issue and add more test case
zhoujia6139 Mar 13, 2023
c251722
chore: fix typo
zhoujia6139 Mar 13, 2023
122bbba
chore: merge Oracle interface and withdraw NFT interface
zhoujia6139 Mar 13, 2023
3bb1016
chore: deployment script(wETH, awETH, stETH, wstETH)
zhoujia6139 Mar 15, 2023
aab411f
chore: add multicall to support complex operation
zhoujia6139 Mar 15, 2023
83ba1ae
chore: fix deploy
zhoujia6139 Mar 15, 2023
ecfdee6
chore: deploy stable debt token address for all asset
zhoujia6139 Mar 16, 2023
8bf3282
chore: protect goerli paraproxyinterfaces
GopherJ Mar 21, 2023
3cf9d61
chore: support mnemonic in anvil fork
GopherJ Mar 21, 2023
cc06130
fix: warning
GopherJ Mar 21, 2023
15722c3
chore: bump hardhat
GopherJ Mar 21, 2023
d90d8ea
chore: bump version
GopherJ Mar 21, 2023
af0e157
Merge remote-tracking branch 'origin/main' into eth_instant_withdraw
GopherJ Mar 21, 2023
8f033e7
fix: add missing stableBorrowing flag
GopherJ Mar 21, 2023
f9c90cf
Merge branch 'main' into eth_instant_withdraw
zhoujia6139 Mar 27, 2023
47d85f4
chore: fix lint
zhoujia6139 Mar 27, 2023
11526ee
chore: fix and extract total debt calculation logic
zhoujia6139 Mar 28, 2023
393306a
chore: add event
zhoujia6139 Mar 28, 2023
847be59
feat: initiate eth withdrawal (#339)
GopherJ Mar 28, 2023
fd70146
fix: build
GopherJ Mar 28, 2023
1062dfa
fix: size
GopherJ Mar 28, 2023
c409605
chore: remove unused exitEpoch,withdrawableEpoch
GopherJ Mar 28, 2023
cbf1703
chore: rename
GopherJ Mar 28, 2023
896d988
chore: use dynamic uri
GopherJ Mar 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions contracts/dependencies/openzeppelin/contracts/Counters.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)

pragma solidity ^0.8.0;

/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}

function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}

function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}

function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}

function reset(Counter storage counter) internal {
counter._value = 0;
}
}
167 changes: 102 additions & 65 deletions contracts/dependencies/openzeppelin/contracts/EnumerableSet.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.

pragma solidity 0.8.10;
pragma solidity ^0.8.0;

/**
* @dev Library for managing
Expand All @@ -25,6 +27,16 @@ pragma solidity 0.8.10;
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
Expand Down Expand Up @@ -82,12 +94,12 @@ library EnumerableSet {
uint256 lastIndex = set._values.length - 1;

if (lastIndex != toDeleteIndex) {
bytes32 lastvalue = set._values[lastIndex];
bytes32 lastValue = set._values[lastIndex];

// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastvalue;
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastvalue] = valueIndex; // Replace lastvalue's index to valueIndex
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}

// Delete the slot where the moved value was stored
Expand All @@ -105,11 +117,7 @@ library EnumerableSet {
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value)
private
view
returns (bool)
{
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}

Expand All @@ -130,14 +138,22 @@ library EnumerableSet {
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index)
private
view
returns (bytes32)
{
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}

/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}

// Bytes32Set

struct Bytes32Set {
Expand All @@ -150,10 +166,7 @@ library EnumerableSet {
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value)
internal
returns (bool)
{
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}

Expand All @@ -163,21 +176,14 @@ library EnumerableSet {
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value)
internal
returns (bool)
{
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}

/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value)
internal
view
returns (bool)
{
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}

Expand All @@ -198,14 +204,30 @@ library EnumerableSet {
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index)
internal
view
returns (bytes32)
{
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}

/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;

/// @solidity memory-safe-assembly
assembly {
result := store
}

return result;
}

// AddressSet

struct AddressSet {
Expand All @@ -218,10 +240,7 @@ library EnumerableSet {
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value)
internal
returns (bool)
{
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}

Expand All @@ -231,21 +250,14 @@ library EnumerableSet {
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value)
internal
returns (bool)
{
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}

/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value)
internal
view
returns (bool)
{
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}

Expand All @@ -266,14 +278,30 @@ library EnumerableSet {
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index)
internal
view
returns (address)
{
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}

/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;

/// @solidity memory-safe-assembly
assembly {
result := store
}

return result;
}

// UintSet

struct UintSet {
Expand All @@ -296,26 +324,19 @@ library EnumerableSet {
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value)
internal
returns (bool)
{
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}

/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value)
internal
view
returns (bool)
{
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}

/**
* @dev Returns the number of values on the set. O(1).
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
Expand All @@ -331,11 +352,27 @@ library EnumerableSet {
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index)
internal
view
returns (uint256)
{
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}

/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;

/// @solidity memory-safe-assembly
assembly {
result := store
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ contract Conduit is ConduitInterface, TokenTransferrer {
}

if (_protocolDataProvider != address(0)) {
(address xTokenAddress, ) = IProtocolDataProvider(
(address xTokenAddress, , ) = IProtocolDataProvider(
_protocolDataProvider
).getReserveTokensAddresses(item.token);
if (xTokenAddress != address(0)) {
Expand Down
6 changes: 6 additions & 0 deletions contracts/deployments/ReservesSetupHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ contract ReservesSetupHelper is Ownable {
uint256 reserveFactor;
uint256 borrowCap;
uint256 supplyCap;
bool stableBorrowingEnabled;
bool borrowingEnabled;
}

Expand Down Expand Up @@ -52,6 +53,11 @@ inputParams[i].asset,
inputParams[i].asset,
inputParams[i].borrowCap
);

configurator.setReserveStableRateBorrowing(
inputParams[i].asset,
inputParams[i].stableBorrowingEnabled
);
}
configurator.setSupplyCap(
inputParams[i].asset,
Expand Down
11 changes: 11 additions & 0 deletions contracts/interfaces/IBendPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.10;

interface IBendPool {
function deposit(
address asset,
uint256 amount,
address onBehalfOf,
uint16 referralCode
) external;
}
6 changes: 6 additions & 0 deletions contracts/interfaces/ICEther.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.10;

interface ICEther {
function mint() external payable;
}
Loading