PancakeswapV2RestrictedStrategyPartialCloseLiquidate Strategy
Table of content
Background
This contract is where the action with PancakeSwap happened. The nature of this contract is used when users want to partially close the position and get the base token back, LP token and amount of base token that wanted back together with this strategy address from Alpaca interface, this contract will remove liquidity from the DEX and convert everything back to base token. Eventually will transfer the base token back to the caller (worker).
Abstract
- Implement IStrategy Interface
- Does not hold any token except during being called
- Token agonistic, it will retrieve the token addresses from it's caller / worker
- DEX specific. This contract can only perform functionality at PancakeSwap
Attributes
AddBaseTokenOnly Attribute
Name | Type | Public | Description |
---|---|---|---|
factory | IPancakeFactory | PancakeSwap Factory address | |
router | IPancakeRouter02 | PancakeSwap Router address | |
okWorkers | addressboolmapping | List of worker that is allowed to call this strategy |
Modifier
onlyWhitelistedWorkers
/// @notice require that only allowed workers are able to do the rest of the method call
modifier onlyWhitelistedWorkers() {
require(
okWorkers[msg.sender],
"PancakeswapV2RestrictedStrategyAddBaseTokenOnly::onlyWhitelistedWorkers:: bad worker"
);
_;
}
Logic
- Revert transaction if the caller is not in the whitelist
Functions
Functions
Name | Type | Description | Documented |
---|---|---|---|
initialize | External | Constructor | |
execute | External | Perform operations on DEX | |
setWorkersOk | ExternalOwner | Set whitelist of workers that can call this contract |
initialize
Use case
- Initialize contract
function Params
Name | Type | Description |
---|---|---|
_router | PancakeSwapRouter | Address of PancakeSwap router which will be used |
Logic
- Assign state variable
Execute
Use case
- Call from worker
function Params
Name | Type | Description |
---|---|---|
_ | address | User address (Not used in this implementation) |
debt | uint256 | Debt amount |
data | bytescalldata | Dynamic variable |
Logic
- Check if the caller is in the whitelist (Modifier)
- Retrieve the farming token the contract will operate on with and min additional LP tokens if provided
- Remove some of LP out of the PancakeSwap pool with respect to amount that want to get back
- Swap the farming token back to base token
- Transfer the base token back to the caller / worker for further processing
- Transfer remaining LP back to worker to deposit back to the PancakeSwap Masterchef contract
setWorkersOk
Use case
- Whitelist the contract list of worker that can call this contract
function Params
Name | Type | Description |
---|---|---|
workers | addressarray | Array of worker addreses |
isOk | bool | True if whitelist, false if to blacklist |
Logic
- Loop through all address
- Set the flag to whitelist/blacklist according to isOk flag