Skip to content

Commit

Permalink
Sending tokens to the user
Browse files Browse the repository at this point in the history
  • Loading branch information
mehranhydary committed Sep 16, 2024
1 parent 37ce19b commit af8a2a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion contracts/src/MiladyPoolOrderManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ contract MiladyPoolOrderManager is

function afterInitialize(
address,
PoolKey calldata key,
PoolKey calldata,
uint160,
int24 tick,
bytes calldata
Expand Down
21 changes: 11 additions & 10 deletions contracts/src/base/Hook.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,21 @@ abstract contract Hook is BaseHook, WyvernInspired {
permit2Signature
);

_settle(
params.zeroForOne // Gets the token that is swapped in
? Currency(key.currency0)
: Currency(key.currency1),
uint128(amountIn)
);

// Can skip the entire amount to swap here if we just do the swap here
// At this point the first token is already in the pool so we need to call _take
_take(
params.zeroForOne // Gets the token that is swapped out
? Currency(key.currency1)
: Currency(key.currency0),
uint128(amountOut)
);

_settle(
params.zeroForOne // Gets the token that is swapped in
? Currency(key.currency0)
: Currency(key.currency1),
uint128(amountIn)
uint128(amountOut),
walletAddress
);

// Return the appropriate values
Expand Down Expand Up @@ -230,9 +231,9 @@ abstract contract Hook is BaseHook, WyvernInspired {
poolManager.settle();
}

function _take(Currency currency, uint128 amount) internal {
function _take(Currency currency, uint128 amount, address trader) internal {
// Should be used to move the tokens received via permit2 to the pool manager
poolManager.sync(currency);
currency.transfer(address(this), amount);
currency.transfer(trader, amount);
}
}

0 comments on commit af8a2a6

Please sign in to comment.