Skip to content

Commit

Permalink
TAKE_PAIR (#254)
Browse files Browse the repository at this point in the history
* TAKE_PAIR

* getfullcredit

* take pair recipient

* add recipient test
  • Loading branch information
dianakocsis authored Aug 3, 2024
1 parent eee5a0e commit 6fe5428
Show file tree
Hide file tree
Showing 19 changed files with 411 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
122739
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
129817
1 change: 1 addition & 0 deletions .forge-snapshots/PositionManager_collect_withTakePair.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
149846
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
115389
Original file line number Diff line number Diff line change
@@ -1 +1 @@
345325
345348
Original file line number Diff line number Diff line change
@@ -1 +1 @@
344866
344889
Original file line number Diff line number Diff line change
@@ -1 +1 @@
371125
371171
9 changes: 9 additions & 0 deletions src/PositionManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ contract PositionManager is
} else if (action == Actions.SETTLE_PAIR) {
(Currency currency0, Currency currency1) = params.decodeCurrencyPair();
_settlePair(currency0, currency1);
} else if (action == Actions.TAKE_PAIR) {
(Currency currency0, Currency currency1, address to) = params.decodeCurrencyPairAndAddress();
_takePair(currency0, currency1, to);
} else if (action == Actions.SWEEP) {
(Currency currency, address to) = params.decodeCurrencyAndAddress();
_sweep(currency, _mapRecipient(to));
Expand Down Expand Up @@ -271,6 +274,12 @@ contract PositionManager is
_settle(currency1, caller, _getFullDebt(currency1));
}

function _takePair(Currency currency0, Currency currency1, address to) internal {
address recipient = _mapRecipient(to);
_take(currency0, recipient, _getFullCredit(currency0));
_take(currency1, recipient, _getFullCredit(currency1));
}

/// @dev this is overloaded with ERC721Permit._burn
function _burn(
uint256 tokenId,
Expand Down
11 changes: 6 additions & 5 deletions src/libraries/Actions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ library Actions {
uint256 constant TAKE = 0x12;
uint256 constant TAKE_ALL = 0x13;
uint256 constant TAKE_PORTION = 0x14;
uint256 constant TAKE_PAIR = 0x15;

uint256 constant CLOSE_CURRENCY = 0x15;
uint256 constant CLEAR_OR_TAKE = 0x16;
uint256 constant SWEEP = 0x17;
uint256 constant CLOSE_CURRENCY = 0x16;
uint256 constant CLEAR_OR_TAKE = 0x17;
uint256 constant SWEEP = 0x18;

// minting/burning 6909s to close deltas
uint256 constant MINT_6909 = 0x18;
uint256 constant BURN_6909 = 0x19;
uint256 constant MINT_6909 = 0x19;
uint256 constant BURN_6909 = 0x20;
}
13 changes: 13 additions & 0 deletions src/libraries/CalldataDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ library CalldataDecoder {
}
}

/// @dev equivalent to: abi.decode(params, (Currency, Currency, address)) in calldata
function decodeCurrencyPairAndAddress(bytes calldata params)
internal
pure
returns (Currency currency0, Currency currency1, address _address)
{
assembly ("memory-safe") {
currency0 := calldataload(params.offset)
currency1 := calldataload(add(params.offset, 0x20))
_address := calldataload(add(params.offset, 0x40))
}
}

/// @dev equivalent to: abi.decode(params, (Currency, address)) in calldata
function decodeCurrencyAndAddress(bytes calldata params)
internal
Expand Down
12 changes: 12 additions & 0 deletions test/libraries/CalldataDecoder.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ contract CalldataDecoderTest is Test {
assertEq(Currency.unwrap(currency1), Currency.unwrap(_currency1));
}

function test_fuzz_decodeCurrencyPairAndAddress(Currency _currency0, Currency _currency1, address __address)
public
view
{
bytes memory params = abi.encode(_currency0, _currency1, __address);
(Currency currency0, Currency currency1, address _address) = decoder.decodeCurrencyPairAndAddress(params);

assertEq(Currency.unwrap(currency0), Currency.unwrap(_currency0));
assertEq(Currency.unwrap(currency1), Currency.unwrap(_currency1));
assertEq(_address, __address);
}

function test_fuzz_decodeCurrencyAndUint256(Currency _currency, uint256 _amount) public view {
bytes memory params = abi.encode(_currency, _amount);
(Currency currency, uint256 amount) = decoder.decodeCurrencyAndUint256(params);
Expand Down
8 changes: 8 additions & 0 deletions test/mocks/MockCalldataDecoder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ contract MockCalldataDecoder {
return params.decodeCurrencyPair();
}

function decodeCurrencyPairAndAddress(bytes calldata params)
external
pure
returns (Currency currency0, Currency currency1, address _address)
{
return params.decodeCurrencyPairAndAddress();
}

function decodeCurrencyAndUint256(bytes calldata params) external pure returns (Currency currency, uint256 _uint) {
return params.decodeCurrencyAndUint256();
}
Expand Down
Loading

0 comments on commit 6fe5428

Please sign in to comment.