Skip to content

Commit

Permalink
Pool maintanence (#663)
Browse files Browse the repository at this point in the history
* Consistent naming of functions and events with LPs
Reorg interface functions and events based on their action

* Move LP transfer logic from Pool to external library

* Improve LPs events, introduce Increase/Decrease LPs and include owner address

* Fix events comment

* Update function comments to reflect new events naming
  • Loading branch information
grandizzy authored Mar 7, 2023
1 parent c43b3a4 commit 99a5f6a
Show file tree
Hide file tree
Showing 8 changed files with 537 additions and 386 deletions.
2 changes: 1 addition & 1 deletion src/PositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ contract PositionManager is ERC721, PermitERC721, IPositionManager, Multicall, R
address owner = ownerOf(params_.tokenId);

// approve owner to take over the LPs ownership (required for transferLPs pool call)
pool.increaseLPAllowance(owner, params_.indexes, lpAmounts);
pool.increaseLPsAllowance(owner, params_.indexes, lpAmounts);
// update pool lps accounting and transfer ownership of lps from PositionManager contract
pool.transferLPs(address(this), owner, params_.indexes);

Expand Down
222 changes: 84 additions & 138 deletions src/base/Pool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -164,128 +164,6 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
_transferQuoteTokenFrom(msg.sender, quoteTokenAmountToAdd_);
}

/// @inheritdoc IPoolLenderActions
function decreaseLPAllowance(
address spender_,
uint256[] calldata indexes_,
uint256[] calldata amounts_
) external override nonReentrant {
mapping(uint256 => uint256) storage allowances = _lpAllowances[msg.sender][spender_];

uint256 indexesLength = indexes_.length;
uint256 index;

for (uint256 i = 0; i < indexesLength; ) {
index = indexes_[i];

allowances[index] -= amounts_[i];

unchecked { ++i; }
}

emit SetLpAllowance(
spender_,
indexes_,
amounts_
);
}

/// @inheritdoc IPoolLenderActions
function increaseLPAllowance(
address spender_,
uint256[] calldata indexes_,
uint256[] calldata amounts_
) external override nonReentrant {
mapping(uint256 => uint256) storage allowances = _lpAllowances[msg.sender][spender_];

uint256 indexesLength = indexes_.length;
uint256 index;

for (uint256 i = 0; i < indexesLength; ) {
index = indexes_[i];

allowances[index] += amounts_[i];

unchecked { ++i; }
}

emit SetLpAllowance(
spender_,
indexes_,
amounts_
);
}

/// @inheritdoc IPoolLenderActions
function revokeLPAllowance(
address spender_,
uint256[] calldata indexes_
) external override nonReentrant {
mapping(uint256 => uint256) storage allowances = _lpAllowances[msg.sender][spender_];

uint256 indexesLength = indexes_.length;
uint256 index;

for (uint256 i = 0; i < indexesLength; ) {
index = indexes_[i];

allowances[index] = 0;

unchecked { ++i; }
}

emit RevokeLpAllowance(
spender_,
indexes_
);
}

/**
* @inheritdoc IPoolLenderActions
* @dev write state:
* - approvedTransferors mapping
*/
function approveLpTransferors(
address[] calldata transferors_
) external override {
mapping(address => bool) storage allowances = approvedTransferors[msg.sender];

uint256 transferorsLength = transferors_.length;
for (uint256 i = 0; i < transferorsLength; ) {
allowances[transferors_[i]] = true;

unchecked { ++i; }
}

emit ApproveLpTransferors(
msg.sender,
transferors_
);
}

/**
* @inheritdoc IPoolLenderActions
* @dev write state:
* - approvedTransferors mapping
*/
function revokeLpTransferors(
address[] calldata transferors_
) external override {
mapping(address => bool) storage allowances = approvedTransferors[msg.sender];

uint256 transferorsLength = transferors_.length;
for (uint256 i = 0; i < transferorsLength; ) {
delete allowances[transferors_[i]];

unchecked { ++i; }
}

emit RevokeLpTransferors(
msg.sender,
transferors_
);
}

/// @inheritdoc IPoolLenderActions
function moveQuoteToken(
uint256 maxAmountToMove_,
Expand Down Expand Up @@ -354,22 +232,6 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
_transferQuoteToken(msg.sender, removedAmount_);
}

/// @inheritdoc IPoolLenderActions
function transferLPs(
address owner_,
address newOwner_,
uint256[] calldata indexes_
) external override nonReentrant {
LenderActions.transferLPs(
buckets,
_lpAllowances,
approvedTransferors,
owner_,
newOwner_,
indexes_
);
}

/// @inheritdoc IPoolLenderActions
function updateInterest() external override nonReentrant {
PoolState memory poolState = _accruePoolInterest();
Expand Down Expand Up @@ -565,6 +427,90 @@ abstract contract Pool is Clone, ReentrancyGuard, Multicall, IPool {
_transferQuoteToken(msg.sender, amount_);
}

/******************************/
/*** Transfer LPs Functions ***/
/******************************/

/// @inheritdoc IPoolLenderActions
function increaseLPsAllowance(
address spender_,
uint256[] calldata indexes_,
uint256[] calldata amounts_
) external override nonReentrant {
LenderActions.increaseLPsAllowance(
_lpAllowances[msg.sender][spender_],
spender_,
indexes_,
amounts_
);
}

/// @inheritdoc IPoolLenderActions
function decreaseLPsAllowance(
address spender_,
uint256[] calldata indexes_,
uint256[] calldata amounts_
) external override nonReentrant {
LenderActions.decreaseLPsAllowance(
_lpAllowances[msg.sender][spender_],
spender_,
indexes_,
amounts_
);
}

/// @inheritdoc IPoolLenderActions
function revokeLPsAllowance(
address spender_,
uint256[] calldata indexes_
) external override nonReentrant {
LenderActions.revokeLPsAllowance(
_lpAllowances[msg.sender][spender_],
spender_,
indexes_
);
}

/// @inheritdoc IPoolLenderActions
function approveLPsTransferors(
address[] calldata transferors_
) external override {
LenderActions.approveLPsTransferors(
approvedTransferors[msg.sender],
transferors_
);
}

/**
* @inheritdoc IPoolLenderActions
* @dev write state:
* - approvedTransferors mapping
*/
function revokeLPsTransferors(
address[] calldata transferors_
) external override {
LenderActions.revokeLPsTransferors(
approvedTransferors[msg.sender],
transferors_
);
}

/// @inheritdoc IPoolLenderActions
function transferLPs(
address owner_,
address newOwner_,
uint256[] calldata indexes_
) external override nonReentrant {
LenderActions.transferLPs(
buckets,
_lpAllowances,
approvedTransferors,
owner_,
newOwner_,
indexes_
);
}

/*****************************/
/*** Pool Helper Functions ***/
/*****************************/
Expand Down
Loading

0 comments on commit 99a5f6a

Please sign in to comment.