PancakeswapV2RestrictedStrategyAddBaseTokenOnly 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 open a position supplying a base token, together with this strategy address from Alpaca interface, this contract will convert virtually half of the base token to farm token and provide liquidity to the DEX. Eventually will transfer the LP 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
- Called from worker
function Params
Name | Type | Description |
---|---|---|
_ | address | User address (Not used in this implementation) |
_ | uint256 | Debt amount (Not used in this implementation) |
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
- Compute the optimal amount of base token to be converted to farming token
- Fancy math occurred here.
- Swap the base token to farming token at PancakeSwap
- Provide liquidity for base token - farming token pair at PancakeSwap
- Transfer the LP token back to the caller / worker for further processing
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