PancakeswapV2RestrictedStrategyPartialCloseLiquidate Strategy

https://github.com/alpaca-finance/bsc-alpaca-contract/blob/main/contracts/6/protocol/strategies/pancakeswapV2-restricted/PancakeswapV2RestrictedStrategyPartialCloseLiquidate.sol

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

Attributes

AddBaseTokenOnly Attribute

NameTypePublicDescription
factoryIPancakeFactory
PancakeSwap Factory address
routerIPancakeRouter02
PancakeSwap Router address
okWorkersaddressboolmapping
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

Functions

Functions

NameTypeDescriptionDocumented
initializeExternalConstructor
executeExternalPerform operations on DEX
setWorkersOkExternalOwnerSet whitelist of workers that can call this contract

initialize

Use case

function Params

NameTypeDescription
_routerPancakeSwapRouterAddress of PancakeSwap router which will be used

Logic

  1. Assign state variable

Execute

Use case

function Params

NameTypeDescription
_addressUser address (Not used in this implementation)
debtuint256Debt amount
databytescalldataDynamic variable

Logic

  1. Check if the caller is in the whitelist (Modifier)
  1. Retrieve the farming token the contract will operate on with and min additional LP tokens if provided
  1. Remove some of LP out of the PancakeSwap pool with respect to amount that want to get back
  1. Swap the farming token back to base token
  1. Transfer the base token back to the caller / worker for further processing
  1. Transfer remaining LP back to worker to deposit back to the PancakeSwap Masterchef contract

setWorkersOk

Use case

function Params

NameTypeDescription
workersaddressarrayArray of worker addreses
isOkboolTrue if whitelist, false if to blacklist

Logic

  1. Loop through all address
  1. Set the flag to whitelist/blacklist according to isOk flag