# xWIN Finance Technical Docs

xWin Finance V2 is an enhanced version of the DEFI platform on the Binance Smart Chain and Ethereum network that uses advanced algorithms and optimization techniques to help you create and manage your portfolio based on your risk tolerance and investment goals. xWin Robo Advisor, a new feature in xWIN Finance V2, you can optimize your portfolio through different optimization approaches. You can have various native tokens such as BTC or ETH or integrate xWin strategies tokens into your portfolio.

But that's not all - xWin Finance V2 also offers the option to deploy your own private vaults, where your funds are secured in a smart contract and can only be accessed by you. And if you're feeling ambitious, you can even become a fund manager by opening your vault to the public, earning management and performance fees in the process.

* BNB Network - LIVE
* Polygon Network - LIVE
* Arbitrum Network - LIVE
* ETHEREUM Network - TO BE SUPPORTED in Q4 2024


# Smart Contract Overview

<figure><img src="https://466113786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTG45H8vI4SWqrd6h2tHn%2Fuploads%2F68oprvkYqjmGGDR4Ifug%2FSmart%20Contract.png?alt=media&amp;token=c43a7e3c-bb54-448d-b2ea-3b505b035e3b" alt=""><figcaption></figcaption></figure>

**xWin FundFactory:** The purpose of this smart contract is to deploy various funds that the user requests. This fund factory will keep track of all the funds as well as many of the administrative controls for the funds.&#x20;

**xWin Fund:** Each of these smart contracts can be a public or private fund for a user. The fund can allow users to invest in xWin strategies as well as individual tokens. It also allows the users to rebalance through the xWin Finance Website or through our SDK.&#x20;

**xWin Pricemaster:** Pricemaster is a helper smart contract that ensures the price of the tokens and strategies are correct. It does this by utilizing Chainlink Price Oracle to ensure that the price does not get arbitraged.&#x20;

**xWin Swap:** xWin Finance has its own swap engine that uses various DEFI swap protocols in order to get the best prices.&#x20;

**xWin Emit Event:** This contract is used to emit events that occur on all the other smart contracts. This makes it easier to track the events that occur in other smart contracts.&#x20;

**xWin Strategies:** xWin Finance offers strategies for investors to use that vary significantly in terms of functionality. However, all the strategies follow a similar pattern and fee structure.


# xWin Private Fund

<figure><img src="https://466113786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTG45H8vI4SWqrd6h2tHn%2Fuploads%2FPvGxbJL11YVBETFLPVKg%2FxWinPrivateFund.png?alt=media&amp;token=f0b265ce-059e-4494-8a81-5f8fce26e19a" alt=""><figcaption></figcaption></figure>

Users in xWin Finance who create a private vault can allocate tokens and strategies to their vault. There they have the ability to rebalance to whatever tokens and strategies supported by xWin Finance. This alleviates the users from having to go to swapping protocols and allows the users to invest into Hedgefund managed funds.


# Smart Contracts


# xWin Parent Contracts

<figure><img src="https://466113786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTG45H8vI4SWqrd6h2tHn%2Fuploads%2FOCxDlaC45E0f9i0VuGj0%2FxWin%20Parent%20Contracts.png?alt=media&amp;token=c352bb31-97ea-4e78-83f1-db3e367965a3" alt=""><figcaption></figcaption></figure>

A diagram of how xWin Strategy, Strategy With Fee, and Strategy Interactor contracts are used.&#x20;

The xWin Swap Contract includes both the xWin Swap V3 and xWin Swap V3 Pancake.&#x20;

The xWin Single Asset Contracts are all the strategies that use different protocols for staking.&#x20;


# xWin Strategy

### xWinStrategy

#### stablecoinUSDAddr

```solidity
address stablecoinUSDAddr
```

stablecoinUSDAddr is used for view functions with the 'inUSD' suffix.

#### baseToken

```solidity
address baseToken
```

baseToken for the fund/strategy, token for deposit, and token recieved on withdraw

#### emitEvent

```solidity
contract IxWinEmitEvent emitEvent
```

#### \_\_xWinStrategy\_init

```solidity
function __xWinStrategy_init(string name, string symbol, address _baseToken, address _USDTokenAddr) internal
```

#### \_Deposit

```solidity
event _Deposit(uint256 datetime, address contractaddress, uint256 rate, uint256 depositAmount, uint256 shares)
```

#### \_Withdraw

```solidity
event _Withdraw(uint256 datetime, address contractaddress, uint256 rate, uint256 avrCost, uint256 withdrawAmount, uint256 shares)
```

#### getVaultValues

```solidity
function getVaultValues() external view virtual returns (uint256)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### \_getVaultValues

```solidity
function _getVaultValues() internal view virtual returns (uint256)
```

#### getUnitPrice

```solidity
function getUnitPrice() external view virtual returns (uint256)
```

The unitprice of a share of this fund in baseToken

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view virtual returns (uint256)
```

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() external view virtual returns (uint256)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() external view virtual returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### deposit

```solidity
function deposit(uint256 amount) external virtual returns (uint256)
```

Deposits baseToken into the fund, and receives shares based on the fund's unitPrice

**Parameters**

| Name   | Type    | Description                    |
| ------ | ------- | ------------------------------ |
| amount | uint256 | Amount of baseToken to deposit |

**Return Values**

| Name | Type    | Description                                 |
| ---- | ------- | ------------------------------------------- |
| \[0] | uint256 | shares Amount of shares minted to depositor |

#### withdraw

```solidity
function withdraw(uint256 amount) external virtual returns (uint256)
```

Withdraws from the fund by burning shares, liquidating assets into baseToken and transfering to user

**Parameters**

| Name   | Type    | Description                  |
| ------ | ------- | ---------------------------- |
| amount | uint256 | Amount of shares to withdraw |

**Return Values**

| Name | Type    | Description                                          |
| ---- | ------- | ---------------------------------------------------- |
| \[0] | uint256 | amount Amount of baseTokens transferred to depositor |

#### deposit

```solidity
function deposit(uint256 amount, uint32 slippage) external virtual returns (uint256)
```

Deposits baseToken into the fund, and receives shares based on the fund's unitPrice

**Parameters**

| Name     | Type    | Description                                      |
| -------- | ------- | ------------------------------------------------ |
| amount   | uint256 | Amount of baseToken to deposit                   |
| slippage | uint32  | Slippage to use for any swaps during the process |

**Return Values**

| Name | Type    | Description                                 |
| ---- | ------- | ------------------------------------------- |
| \[0] | uint256 | shares Amount of shares minted to depositor |

#### withdraw

```solidity
function withdraw(uint256 amount, uint32 slippage) external virtual returns (uint256)
```

Withdraws from the fund by burning shares, liquidating assets into baseToken and transfering to user

**Parameters**

| Name     | Type    | Description                                      |
| -------- | ------- | ------------------------------------------------ |
| amount   | uint256 | Amount of shares to withdraw                     |
| slippage | uint32  | Slippage to use for any swaps during the process |

**Return Values**

| Name | Type    | Description                                          |
| ---- | ------- | ---------------------------------------------------- |
| \[0] | uint256 | amount Amount of baseTokens transferred to depositor |

#### setEmitEvent

```solidity
function setEmitEvent(address _addr) external
```

#### updateUSDAddr

```solidity
function updateUSDAddr(address _newUSDAddr) external
```

#### setPause

```solidity
function setPause() external
```

#### setUnPause

```solidity
function setUnPause() external
```


# xWin Strategy Interactor

### xWinStrategyInteractor

#### onlyAdmin

```solidity
modifier onlyAdmin()
```

#### StrategyData

```solidity
struct StrategyData {
  address baseToken;
  bool isActive;
}
```

#### admins

```solidity
mapping(address => bool) admins
```

#### xWinStrategies

```solidity
mapping(address => struct xWinStrategyInteractor.StrategyData) xWinStrategies
```

#### \_\_xWinStrategyInteractor\_init

```solidity
function __xWinStrategyInteractor_init() internal
```

#### setAdmin

```solidity
function setAdmin(address _wallet, bool _allow) external
```

#### isAdmin

```solidity
function isAdmin(address _wallet) public view returns (bool)
```

#### registerStrategyContract

```solidity
function registerStrategyContract(address _newStrat, address _baseToken) external
```

#### activateStrategy

```solidity
function activateStrategy(address _strat) public
```

#### deactivateStrategy

```solidity
function deactivateStrategy(address _strat) public
```

#### isxWinStrategy

```solidity
function isxWinStrategy(address _strat) public view returns (bool)
```

#### isActivexWinStrategy

```solidity
function isActivexWinStrategy(address _strat) public view returns (bool)
```

#### getStrategyBaseToken

```solidity
function getStrategyBaseToken(address _strat) public view returns (address)
```

#### depositToStrategy

```solidity
function depositToStrategy(uint256 _amount, address _strat) internal returns (uint256)
```

#### withdrawFromStrategy

```solidity
function withdrawFromStrategy(uint256 _amount, address _strat) internal returns (uint256)
```


# xWin Strategy With Fee

### xWinStrategyWithFee

#### waivedPerformanceFees

```solidity
mapping(address => bool) waivedPerformanceFees
```

Priviliged addresses with fees waived for this fund (e.g. manager/platform)

#### performanceFee

```solidity
uint256 performanceFee
```

performance fee in 4 decimals, e.g 100% = 10000

#### managerFee

```solidity
uint256 managerFee
```

manager fee in 4 decimals, e.g 100% = 10000

#### pendingMFee

```solidity
uint256 pendingMFee
```

Pending shares to award to manager

#### collectionPeriod

```solidity
uint256 collectionPeriod
```

Blocks between performance fee collection

#### collectionBlock

```solidity
uint256 collectionBlock
```

Next available collection block number

#### prevCollectionBlock

```solidity
uint256 prevCollectionBlock
```

Last performance fee collection block number

#### watermarkUnitprice

```solidity
uint256 watermarkUnitprice
```

High water mark for performance fee collection

#### strategyManager

```solidity
address strategyManager
```

Manager of this strategy

#### lastManagerFeeCollection

```solidity
uint256 lastManagerFeeCollection
```

Last management fee collection block number

#### blocksPerDay

```solidity
uint256 blocksPerDay
```

#### pendingNewPerformanceFee

```solidity
uint256 pendingNewPerformanceFee
```

New performance fee rate, which will be applied on next performance fee collection

#### lockingAddress

```solidity
address lockingAddress
```

Address of locked staking contract, for performance fee discounts

#### \_\_xWinStrategyWithFee\_init

```solidity
function __xWinStrategyWithFee_init(string _name, string _symbol, address _baseToken, address _USDTokenAddr, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) internal
```

#### updateLockedStakingAddress

```solidity
function updateLockedStakingAddress(address _lockedStaking) external
```

#### canCollectPerformanceFee

```solidity
function canCollectPerformanceFee() public view virtual returns (bool)
```

View function to check if performance fee can be collected

#### \_calcFundFee

```solidity
function _calcFundFee() internal virtual
```

Calculates management fee, updating pendingMFee

#### collectFundFee

```solidity
function collectFundFee() external virtual
```

Mints management fee shares to manager

#### collectPerformanceFee

```solidity
function collectPerformanceFee() external virtual
```

collects performance fee

#### performanceWithdraw

```solidity
function performanceWithdraw(uint256 _withdrawUnits, uint256 _amtOut) internal returns (uint256)
```

Function to handle performance fee on withdraw

**Parameters**

| Name            | Type    | Description                                           |
| --------------- | ------- | ----------------------------------------------------- |
| \_withdrawUnits | uint256 | Amount of shares being withdrawn                      |
| \_amtOut        | uint256 | Amount of tokens after swapping back to base currency |

**Return Values**

| Name | Type    | Description                                        |
| ---- | ------- | -------------------------------------------------- |
| \[0] | uint256 | amount Amount left after performance fee deduction |

#### \_getMintQty

```solidity
function _getMintQty(uint256 _depositAmt) internal view virtual returns (uint256 mintQty)
```

Calc qty to issue during deposit

#### \_getNewFundUnits

```solidity
function _getNewFundUnits(uint256 totalFundB4, uint256 totalValueAfter) internal view virtual returns (uint256)
```

#### setPerformanceFee

```solidity
function setPerformanceFee(uint256 _newPerformanceFee) external
```

#### setManagerFee

```solidity
function setManagerFee(uint256 _newManagerFee) external
```

#### setPerformanceCollectionPeriod

```solidity
function setPerformanceCollectionPeriod(uint256 _newPeriod) external
```

#### setBlockPerDay

```solidity
function setBlockPerDay(uint256 _newBlocksPerDay) external
```

#### getFundTotalSupply

```solidity
function getFundTotalSupply() public view virtual returns (uint256)
```

#### GetStrategyData

```solidity
function GetStrategyData() external view returns (address baseCcy, uint256 totalUnitB4, uint256 unitprice, uint256 fundvalue, uint256 unitpriceUSD, uint256 fundvalueUSD, string name, string symbol, uint256 managementFee, uint256 performFee, address mAddr, uint256 highWaterMarkPrice)
```

View function to get all the fund's main data and parameters

#### setManagerWallet

```solidity
function setManagerWallet(address _newManagerWallet) external
```

#### \_convertTo18

```solidity
function _convertTo18(uint256 value, address token) internal view returns (uint256)
```

#### \_convertFrom18

```solidity
function _convertFrom18(uint256 value, address token) internal view returns (uint256)
```

#### addWaiveFee

```solidity
function addWaiveFee(address _contract) external
```

#### removeWaiveFee

```solidity
function removeWaiveFee(address _contract) external
```

#### \_isContract

```solidity
function _isContract(address addr) internal view returns (bool)
```


# xWin FundFactory

### FundV2Initialize

#### initialize

```solidity
function initialize(string _name, string _symbol, address _USDAddr, address _manageraddr, address _managerRebaddr, address _platformWallet) external
```

### FundV2Factory

#### fundV2Array

```solidity
address[] fundV2Array
```

#### supportedBaseTokens

```solidity
mapping(address => bool) supportedBaseTokens
```

#### whitelisted

```solidity
mapping(address => bool) whitelisted
```

#### fundIDs

```solidity
mapping(address => uint256) fundIDs
```

#### xWinToken

```solidity
contract IERC20Upgradeable xWinToken
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### xEmitEvent

```solidity
contract IxWinEmitEvent xEmitEvent
```

#### beaconContract

```solidity
address beaconContract
```

#### autoLockAddr

```solidity
address autoLockAddr
```

#### xWinSwapAddr

```solidity
address xWinSwapAddr
```

#### xWinAdminWallet

```solidity
address xWinAdminWallet
```

#### DEFAULT\_BASETOKEN

```solidity
address DEFAULT_BASETOKEN
```

#### DEFAULT\_MANAGER

```solidity
address DEFAULT_MANAGER
```

#### DEFAULT\_PLATFORM

```solidity
address DEFAULT_PLATFORM
```

#### DEFAULT\_MANAGER\_FEE

```solidity
uint256 DEFAULT_MANAGER_FEE
```

#### DEFAULT\_PERFORMANCE\_FEE

```solidity
uint256 DEFAULT_PERFORMANCE_FEE
```

#### DEFAULT\_CREATION\_FEE

```solidity
uint256 DEFAULT_CREATION_FEE
```

#### DEFAULT\_PLATFORM\_FEE

```solidity
uint256 DEFAULT_PLATFORM_FEE
```

#### DEFAULT\_REBALANCE\_PERIOD

```solidity
uint256 DEFAULT_REBALANCE_PERIOD
```

#### DEFAULT\_BLOCKSPERDAY

```solidity
uint256 DEFAULT_BLOCKSPERDAY
```

#### DEFAULT\_SMALLRATIO

```solidity
uint256 DEFAULT_SMALLRATIO
```

#### BaseTokenUpdate

```solidity
event BaseTokenUpdate(address, bool)
```

#### Received

```solidity
event Received(address, uint256)
```

#### FundCreation

```solidity
event FundCreation(address rebalanceOwner, address newFund, uint256 fundId, string name, string symbol)
```

#### executors

```solidity
mapping(address => bool) executors
```

#### initialize

```solidity
function initialize(address _xWinAdminWallet, address _xWinSwapAddr, address _xWinPriceMaster, address _emitEventAddr, address _xWinLockStaking, address _xwinAddr, address _beaconAddress, address _baseToken, address _defaultManagerAddr, address _defaultPlatformAddr) public
```

#### createFundPrivate

```solidity
function createFundPrivate(string name, string symbol, address[] _toAddresses, uint256[] _targetWeight) external
```

Create a Fund

**Parameters**

| Name           | Type       | Description                                  |
| -------------- | ---------- | -------------------------------------------- |
| name           | string     | Name of new fund                             |
| symbol         | string     | Symbol of new fund                           |
| \_toAddresses  | address\[] | Array of initial target allocation addresses |
| \_targetWeight | uint256\[] | Array of inital target allocation weights    |

#### createFundPrivateWithBaseToken

```solidity
function createFundPrivateWithBaseToken(string name, string symbol, address _baseToken, address[] _toAddresses, uint256[] _targetWeight) external
```

Create a Fund, with specific base token

**Parameters**

| Name           | Type       | Description                                  |
| -------------- | ---------- | -------------------------------------------- |
| name           | string     | Name of new fund                             |
| symbol         | string     | Symbol of new fund                           |
| \_baseToken    | address    | base token for new fund                      |
| \_toAddresses  | address\[] | Array of initial target allocation addresses |
| \_targetWeight | uint256\[] | Array of inital target allocation weights    |

#### createFund

```solidity
function createFund(string name, string symbol, address _baseToken, address managerFeeAddr, address rebalanceAddr, address _USDAddr) external returns (uint256)
```

#### createProxy

```solidity
function createProxy(string name, string symbol, address _baseToken, address managerFeeAddr, address rebalanceAddr, address _USDAddr) internal returns (address)
```

#### initialiseFund

```solidity
function initialiseFund(uint256 fundId, uint256 _managerFee, uint256 _performanceFee, bool _openForPublic, uint256 _unitpriceMultiplier, address _platformAddr) external
```

#### \_initialiseFund

```solidity
function _initialiseFund(uint256 fundId, uint256 _managerFee, uint256 _performanceFee, bool _openForPublic, uint256 _unitpriceMultiplier, address _platformAddr) internal
```

#### massProcessPlatformFee

```solidity
function massProcessPlatformFee() external
```

#### processPlatformFee

```solidity
function processPlatformFee(address _fundAddr) external
```

#### processManagerFee

```solidity
function processManagerFee(address _fundAddr) external
```

#### massProcessManagerFee

```solidity
function massProcessManagerFee() external
```

#### setSwapAddr

```solidity
function setSwapAddr(address _xWinSwapAddr) external
```

#### addNewBaseToken

```solidity
function addNewBaseToken(address _newTokenAddr) external
```

#### removeBaseToken

```solidity
function removeBaseToken(address _tokenAddr) external
```

#### updatePriceMaster

```solidity
function updatePriceMaster(address _newPriceMaster) external
```

#### getLatestFundID

```solidity
function getLatestFundID() public view returns (uint256)
```

#### getFundfromIndex

```solidity
function getFundfromIndex(uint256 _index) public view returns (address)
```

#### setProperties

```solidity
function setProperties(address _baseToken, uint256 _defaultManagerFee, uint256 _defaultPerformFee, address _defaultManager, uint256 _defaultPlatFee, uint256 _defaultRebalancePeriod, uint256 _defaultBlockPerDays, uint256 _defaultSmallRatio, address _defaultPlatform) external
```

#### addWhiteList

```solidity
function addWhiteList(address _addr) external
```

#### removeWhiteList

```solidity
function removeWhiteList(address _addr) external
```

#### setPause

```solidity
function setPause(address _fundAddr, bool _pauseVal) external
```

#### MoveNonIndexNameToBase

```solidity
function MoveNonIndexNameToBase(address _fundAddr, address _tokenaddress, uint32 _slippage) external returns (uint256 balanceToken, uint256 swapOutput)
```

#### setOpenForPublic

```solidity
function setOpenForPublic(address _fundAddr, bool _allow) external
```

#### updateOtherProperties

```solidity
function updateOtherProperties(address _fundAddr, uint256 newCycle, uint256 _ratio, uint256 _UPMultiplier) external
```

#### updatePlatformProperty

```solidity
function updatePlatformProperty(address _fundAddr, address newPlatformWallet, uint256 newPlatformFee) external
```

#### setPerformanceFee

```solidity
function setPerformanceFee(address _fundAddr, uint256 newPerformFee) external
```

#### updateManagerProperty

```solidity
function updateManagerProperty(address _fundAddr, address newRebManager, address newManager, uint256 newFeebps) external
```

#### updateBlockPerday

```solidity
function updateBlockPerday(address _fundAddr, uint256 _blocksPerDay) external
```

#### updatexWinEngines

```solidity
function updatexWinEngines(address _fundAddr, address _xwinPricesMaster, address _xwinSwap) external
```

#### updateUSDAddr

```solidity
function updateUSDAddr(address _fundAddr, address _newUSDAddr) external
```

#### updateEmitEvent

```solidity
function updateEmitEvent(address _fundAddr) external
```

#### updateLockedStaking

```solidity
function updateLockedStaking(address _fundAddr) external
```

#### setWaivedPerformanceFee

```solidity
function setWaivedPerformanceFee(address _fundAddr, address _toWaive, bool _status) external
```

#### setAdminWallet

```solidity
function setAdminWallet(address _address) external
```

#### setEmitEvent

```solidity
function setEmitEvent(address _newEmitEvent) external
```

#### setAutoLock

```solidity
function setAutoLock(address _newAutoLock) external
```

#### setCreationFee

```solidity
function setCreationFee(uint256 _newCreationFee) external
```

#### isRegistered

```solidity
function isRegistered(address _fundAddress) internal view
```

#### countTotalFunds

```solidity
function countTotalFunds() external view returns (uint256 count)
```

#### countActiveFunds

```solidity
function countActiveFunds() external view returns (uint256 count)
```

#### countTVL

```solidity
function countTVL() external view returns (uint256 amount)
```

#### countFundNumberByAddress

```solidity
function countFundNumberByAddress(address _user) external view returns (uint256 count)
```

#### countTotalTVLByAddress

```solidity
function countTotalTVLByAddress(address _user) external view returns (uint256 amount)
```

Gets the total deposit value of the given address in all FundV2 contracts

**Parameters**

| Name   | Type    | Description     |
| ------ | ------- | --------------- |
| \_user | address | Wallet to query |

#### receive

```solidity
receive() external payable
```

#### setExecutor

```solidity
function setExecutor(address _address, bool _allow) external
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```


# xWin Fund

### FundV2

#### userAvgPrice

```solidity
struct userAvgPrice {
  uint256 shares;
  uint256 avgPrice;
}
```

#### validInvestors

```solidity
mapping(address => bool) validInvestors
```

Whitelisted addresses that can use the fund if openForPublic=false

#### performanceMap

```solidity
mapping(address => struct FundV2.userAvgPrice) performanceMap
```

User average price, and share amount for performace fee calculations

#### waivedPerformanceFees

```solidity
mapping(address => bool) waivedPerformanceFees
```

Priviliged addresses with fees waived for this fund (e.g. manager/platform)

#### TargetWeight

```solidity
mapping(address => uint256) TargetWeight
```

Stores the weight of the target asset

#### targetAddr

```solidity
address[] targetAddr
```

Array containing target asset addresses

#### priceMaster

```solidity
contract IxWinPriceMaster priceMaster
```

Address of price master

#### xWinSwap

```solidity
contract IxWinSwap xWinSwap
```

Address of swap engine

#### lockingAddress

```solidity
address lockingAddress
```

Address of locked staking contract, for performance fee discounts

#### managerAddr

```solidity
address managerAddr
```

Address of manager wallet to receive management fees

#### managerRebAddr

```solidity
address managerRebAddr
```

Address of manager account, which can execute manager only functions

#### platformWallet

```solidity
address platformWallet
```

Address of platform wallet to receive platform fees

#### lastFeeCollection

```solidity
uint256 lastFeeCollection
```

Last block where fees were collected

#### nextRebalance

```solidity
uint256 nextRebalance
```

Next available block

#### pendingMFee

```solidity
uint256 pendingMFee
```

Pending shares to award to manager

#### pendingPFee

```solidity
uint256 pendingPFee
```

Pending shares to award to platform

#### managerFee

```solidity
uint256 managerFee
```

manager fee in 4 decimals, e.g 100% = 10000

#### platformFee

```solidity
uint256 platformFee
```

platform fee in 4 decimals, e.g 100% = 10000

#### smallRatio

```solidity
uint256 smallRatio
```

#### performFee

```solidity
uint256 performFee
```

platform fee in 4 decimals, e.g 100% = 10000

#### UPMultiplier

```solidity
uint256 UPMultiplier
```

Unit price multiplier

#### openForPublic

```solidity
bool openForPublic
```

#### Received

```solidity
event Received(address, uint256)
```

#### ManagerFeeUpdate

```solidity
event ManagerFeeUpdate(uint256 fromFee, uint256 toFee, uint256 txnTime)
```

#### ManagerOwnerUpdate

```solidity
event ManagerOwnerUpdate(address fromAddress, address toAddress, uint256 txnTime)
```

#### initialize

```solidity
function initialize(string _name, string _symbol, address _baseToken, address _USDAddr, address _manageraddr, address _managerRebaddr, address _platformWallet, address _lockedStaking) external
```

#### init

```solidity
function init(uint256 _managerFee, uint256 _performFee, uint256 _platformFee, bool _openForPublic, uint256 _UPMultiplier, uint256 _rebalancePeriod, uint256 _blocksPerDay, uint256 _smallRatio) external
```

#### collectFundFee

```solidity
function collectFundFee() external
```

Mints management fee to manager wallet, sets pendingMFee to 0

#### collectPlatformFee

```solidity
function collectPlatformFee() external
```

Mints platform fee to platform wallet, sets pendingPFee to 0

#### \_calcFundFee

```solidity
function _calcFundFee() internal
```

Updates pending management/platform fee

#### createTargetNames

```solidity
function createTargetNames(address[] _toAddr, uint256[] _targets) public
```

Sets target token addresses and weights for the fund

#### Rebalance

```solidity
function Rebalance(address[] _toAddr, uint256[] _targets, uint32 _slippage) public
```

Performs rebalance with new weight and reset next rebalance period

#### Rebalance

```solidity
function Rebalance(address[] _toAddr, uint256[] _targets) external
```

#### deposit

```solidity
function deposit(uint256 amount, uint32 _slippage) public returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 amount) external returns (uint256)
```

Deposits baseToken into the fund, and receives shares based on the fund's unitPrice

**Parameters**

| Name   | Type    | Description                    |
| ------ | ------- | ------------------------------ |
| amount | uint256 | Amount of baseToken to deposit |

**Return Values**

| Name | Type    | Description                                 |
| ---- | ------- | ------------------------------------------- |
| \[0] | uint256 | shares Amount of shares minted to depositor |

#### \_deposit

```solidity
function _deposit(uint256 amount, uint32 _slippage) internal returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 amount, uint32 _slippage) public returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 amount) external returns (uint256)
```

Withdraws from the fund by burning shares, liquidating assets into baseToken and transfering to user

**Parameters**

| Name   | Type    | Description                  |
| ------ | ------- | ---------------------------- |
| amount | uint256 | Amount of shares to withdraw |

**Return Values**

| Name | Type    | Description                                          |
| ---- | ------- | ---------------------------------------------------- |
| \[0] | uint256 | amount Amount of baseTokens transferred to depositor |

#### \_withdraw

```solidity
function _withdraw(uint256 amount, uint32 _slippage) internal returns (uint256)
```

#### MoveNonIndexNameToBase

```solidity
function MoveNonIndexNameToBase(address _token, uint32 _slippage) external returns (uint256 balanceToken, uint256 swapOutput)
```

fund owner move any name back to baseToken

#### emergencyRedeem

```solidity
function emergencyRedeem(uint256 redeemUnit) external
```

get the proportional token without swapping it in emergency case

#### \_getTransferAmt

```solidity
function _getTransferAmt(address underying, uint256 redeemratio) internal view returns (struct xWinLib.transferData transData)
```

Calc return balance during redemption

#### \_getMintQty

```solidity
function _getMintQty(uint256 _unitPrice) internal view returns (uint256 mintQty)
```

Calc qty to issue during subscription

#### \_getActiveOverWeight

```solidity
function _getActiveOverWeight(address destAddr, uint256 totalvalue) internal view returns (uint256 destRebQty, uint256 destActiveWeight, bool overweight)
```

Calculates the weight difference between the current fund and target

**Parameters**

| Name       | Type    | Description      |
| ---------- | ------- | ---------------- |
| destAddr   | address | token address    |
| totalvalue | uint256 | fund vault value |

**Return Values**

| Name             | Type    | Description                                   |
| ---------------- | ------- | --------------------------------------------- |
| destRebQty       | uint256 | Amount of tokens to sell if overweight        |
| destActiveWeight | uint256 | amount of weight the token is off from target |
| overweight       | bool    | bool to indicate if token is overweight       |

#### \_rebalance

```solidity
function _rebalance(uint32 _slippage) internal
```

#### \_sellOverWeightNames

```solidity
function _sellOverWeightNames(uint32 _slippage) internal returns (struct xWinLib.UnderWeightData[] underwgts, uint256 totalunderwgt)
```

Sells overweight tokens

**Parameters**

| Name       | Type   | Description                 |
| ---------- | ------ | --------------------------- |
| \_slippage | uint32 | Slippage used for the swaps |

**Return Values**

| Name          | Type                              | Description                                        |
| ------------- | --------------------------------- | -------------------------------------------------- |
| underwgts     | struct xWinLib.UnderWeightData\[] | Returns remaining underweighted tokens, and amount |
| totalunderwgt | uint256                           | Total underweighted sum                            |

#### \_buyUnderWeightNames

```solidity
function _buyUnderWeightNames(struct xWinLib.UnderWeightData[] underweights, uint256 totalunderwgt, uint32 _slippage) internal
```

Buys Underweighted tokens

#### \_moveNonIndex

```solidity
function _moveNonIndex(address _token, uint32 _slippage) internal returns (uint256 balanceToken, uint256 swapOutput)
```

#### \_getDeleteNames

```solidity
function _getDeleteNames(address[] _toAddr) internal view returns (struct xWinLib.DeletedNames[] delNames)
```

#### \_convertTo18

```solidity
function _convertTo18(uint256 value, address token) internal view returns (uint256)
```

#### getEstimateShares

```solidity
function getEstimateShares(uint256 _amt) external view returns (uint256 mintQty)
```

Display estimate shares if deposit

#### getUnitPrice

```solidity
function getUnitPrice() external view returns (uint256)
```

The unitprice of a share of this fund in baseToken

#### \_getUnitPrice

```solidity
function _getUnitPrice(uint256 fundvalue) internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() external view returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### getLatestPrice

```solidity
function getLatestPrice(address _targetAdd) external view returns (uint256)
```

#### getVaultValues

```solidity
function getVaultValues() external view returns (uint256)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() external view returns (uint256)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### getTokenValues

```solidity
function getTokenValues(address tokenaddress) external view returns (uint256)
```

return token value in the vault in base currency

#### getFundTotalSupply

```solidity
function getFundTotalSupply() public view returns (uint256)
```

Actual total supply, taking into account for fees

#### \_getLatestPrice

```solidity
function _getLatestPrice(address _targetAdd) internal view returns (uint256)
```

#### \_getLatestPriceInUSD

```solidity
function _getLatestPriceInUSD(address _targetAdd) internal view returns (uint256)
```

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256)
```

#### \_getVaultValuesInUSD

```solidity
function _getVaultValuesInUSD() internal view returns (uint256)
```

#### \_getUP

```solidity
function _getUP() internal view returns (uint256)
```

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### \_getUPInUSD

```solidity
function _getUPInUSD() internal view returns (uint256)
```

#### \_getTokenValues

```solidity
function _getTokenValues(address token) internal view returns (uint256)
```

#### \_getTokenValuesInUSD

```solidity
function _getTokenValuesInUSD(address token) internal view returns (uint256)
```

#### getBalance

```solidity
function getBalance(address fromAdd) public view returns (uint256)
```

#### getTargetNamesAddress

```solidity
function getTargetNamesAddress() external view returns (address[] _targetNamesAddress)
```

#### getTargetWeightQty

```solidity
function getTargetWeightQty(address targetAdd, uint256 srcQty) internal view returns (uint256)
```

*return target amount based on weight of each token in the fund*

#### GetFundExtra

```solidity
function GetFundExtra() external view returns (uint256 managementFee, uint256 performanceFee, uint256 platFee, address mAddr, address mRebAddr, address pWallet)
```

Get All Extra the fund data needed for client

#### GetFundDataAll

```solidity
function GetFundDataAll() external view returns (contract IERC20Upgradeable baseCcy, address[] targetAddress, uint256 totalUnitB4, uint256 baseBalance, uint256 unitprice, uint256 fundvalue, uint256 unitpriceUSD, uint256 fundvalueUSD, string fundName, string symbolName)
```

Get All the fund data needed for client

#### setValidInvestor

```solidity
function setValidInvestor(address _wallet, bool _allow) external
```

#### setOpenForPublic

```solidity
function setOpenForPublic(bool _allow) external
```

#### updateOtherProperties

```solidity
function updateOtherProperties(uint256 newCycle, uint256 _ratio, uint256 _UPMultiplier) external
```

#### updateBlockPerday

```solidity
function updateBlockPerday(uint256 _blocksPerDay) external
```

*update average blocks per day value*

#### updatePlatformProperty

```solidity
function updatePlatformProperty(address _newAddr, uint256 _newFee) external
```

*update platform fee and wallet*

#### setPerformanceFee

```solidity
function setPerformanceFee(uint256 _performFee) external
```

#### updateManagerProperty

```solidity
function updateManagerProperty(address newRebManager, address newManager, uint256 newFeebps) external
```

*update manager fee and wallet*

#### updatexWinEngines

```solidity
function updatexWinEngines(address _priceMaster, address _xwinSwap) external
```

*update xwin master contract*

#### updateLockedStakingAddress

```solidity
function updateLockedStakingAddress(address _lockedStaking) external
```

#### setPerformDeposit

```solidity
function setPerformDeposit(uint256 mintShares, uint256 latestUP) internal
```

Handles performance fee logic, keeping record of deposits

**Parameters**

| Name       | Type    | Description        |
| ---------- | ------- | ------------------ |
| mintShares | uint256 | Shares minted      |
| latestUP   | uint256 | Unit price of fund |

#### setPerformWithdraw

```solidity
function setPerformWithdraw(uint256 swapOutput, uint256 _shares, address _investorAddress, address _managerAddress) internal returns (uint256)
```

Handles performance fee logic, calculating profit after swap

**Parameters**

| Name              | Type    | Description                        |
| ----------------- | ------- | ---------------------------------- |
| swapOutput        | uint256 | Amount of tokens received          |
| \_shares          | uint256 | Amount of shares burned            |
| \_investorAddress | address | User address that is withdrawing   |
| \_managerAddress  | address | Address to receive performance fee |

#### getUserAveragePrice

```solidity
function getUserAveragePrice(address _user) external view returns (uint256 shares, uint256 avgPrice)
```

Returns Users average price and shares

**Parameters**

| Name   | Type    | Description         |
| ------ | ------- | ------------------- |
| \_user | address | Address of the user |

**Return Values**

| Name     | Type    | Description                     |
| -------- | ------- | ------------------------------- |
| shares   | uint256 | Total shares minted by the user |
| avgPrice | uint256 | Average mint price              |

#### getDiscountedPerformFee

```solidity
function getDiscountedPerformFee(address _user) public view returns (uint256 newPerformanceFee)
```

Returns performance fee for user after applying discount

**Parameters**

| Name   | Type    | Description         |
| ------ | ------- | ------------------- |
| \_user | address | Address of the user |

#### addContractWaiveFee

```solidity
function addContractWaiveFee(address _contract) external
```

#### removeContractWaiveFee

```solidity
function removeContractWaiveFee(address _contract) external
```

#### receive

```solidity
receive() external payable
```

#### onlyRebManager

```solidity
modifier onlyRebManager()
```


# xWin Pricemaster

### xWinPriceMaster

#### SourceMap

```solidity
struct SourceMap {
  uint8 source;
  address chainLinkAddr;
}
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### stratInteractor

```solidity
contract IxWinStrategyInteractor stratInteractor
```

#### \_TWAPOracle

```solidity
address _TWAPOracle
```

#### chainLinkUSDpair

```solidity
mapping(address => address) chainLinkUSDpair
```

#### priceSourceMap

```solidity
mapping(address => mapping(address => struct xWinPriceMaster.SourceMap)) priceSourceMap
```

#### executors

```solidity
mapping(address => bool) executors
```

#### initialize

```solidity
function initialize(address _stratInteractor, address _twapAddress) external
```

#### getPrice

```solidity
function getPrice(address _from, address _to) public view returns (uint256 rate)
```

Get token price from xWinPriceMaster in the form of from/to, e.g ETH/USDC, BTC/ETH

**Parameters**

| Name   | Type    | Description        |
| ------ | ------- | ------------------ |
| \_from | address | from Token address |
| \_to   | address | to Token address   |

#### \_getTWAPPrice

```solidity
function _getTWAPPrice(address _from, address _to) internal view returns (uint256 amountOut)
```

#### \_getLPPrice

```solidity
function _getLPPrice(address _from, address _to) internal view returns (uint256 rate)
```

#### addPrice

```solidity
function addPrice(address _from, address _to, uint8 _source, address _chainLinkAddr) external
```

#### addChainlinkUSDPrice

```solidity
function addChainlinkUSDPrice(address _token, address _chainLinkAddr) external
```

#### setExecutor

```solidity
function setExecutor(address _address, bool _allow) external
```

#### setTWAPOracle

```solidity
function setTWAPOracle(address _address) external
```

#### updateStratInteractor

```solidity
function updateStratInteractor(address _stratInteractor) public
```

#### \_convertFrom18

```solidity
function _convertFrom18(uint256 value, address token) internal view returns (uint256)
```


# xWin Swap Contracts


# xWin Swap V3

### xWinSwapV3

#### SwapMethod

```solidity
enum SwapMethod {
  UNISWAPV2,
  UNISWAPV3,
  UNISWAPV3Multihop
}
```

#### SwapInfo

```solidity
struct SwapInfo {
  address router;
  address[] path;
  bytes multihopPath;
  uint24 slippage;
  uint24 poolFee;
  enum xWinSwapV3.SwapMethod swapMethod;
}
```

#### Received

```solidity
event Received(address, uint256)
```

#### receive

```solidity
receive() external payable
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### swapData

```solidity
mapping(address => mapping(address => struct xWinSwapV3.SwapInfo)) swapData
```

Mapping containing swapInfo, for swap pair fromToken, toToken

#### executors

```solidity
mapping(address => bool) executors
```

#### priceMaster

```solidity
contract IxWinPriceMaster priceMaster
```

#### initialize

```solidity
function initialize() external
```

#### swapTokenToToken

```solidity
function swapTokenToToken(uint256 _amount, address _fromToken, address _toToken) external returns (uint256)
```

Swap tokens using xWin Swap

**Parameters**

| Name        | Type    | Description              |
| ----------- | ------- | ------------------------ |
| \_amount    | uint256 | Amount of tokens to swap |
| \_fromToken | address | Token to swap            |
| \_toToken   | address | Token to receive         |

#### swapTokenToToken

```solidity
function swapTokenToToken(uint256 _amount, address _fromToken, address _toToken, uint32 _slippage) public returns (uint256)
```

Swap tokens using xWin Swap with slippage

**Parameters**

| Name        | Type    | Description              |
| ----------- | ------- | ------------------------ |
| \_amount    | uint256 | Amount of tokens to swap |
| \_fromToken | address | Token to swap            |
| \_toToken   | address | Token to receive         |
| \_slippage  | uint32  | Slippage for the swap    |

#### internalSwap

```solidity
function internalSwap(uint256 _amount, address _fromToken, address _toToken, address recipient, uint32 _slippage) internal returns (uint256)
```

Main logic for swapping tokens

#### \_swapV2

```solidity
function _swapV2(address _fromToken, uint256 amountIn, address[] path, address router, address destination, uint256 amountOutQuote) internal returns (uint256)
```

makes swaps using a uniswapV2 style router

#### \_swapV3

```solidity
function _swapV3(uint256 _amount, address _fromToken, address _toToken, address _recipient, address routerV3, uint256 amountOutQuote, uint24 poolFee) internal returns (uint256)
```

makes direct swap using a uniswapV3 style router

#### \_swapV3Multihop

```solidity
function _swapV3Multihop(uint256 _amount, address _fromToken, address _recipient, address routerV3, uint256 amountOutQuote, bytes multihopPath) internal returns (uint256)
```

makes a multihop swap using a uniswapV3 style router

#### getSwapData

```solidity
function getSwapData(address _fromtoken, address _totoken) external view returns (struct xWinSwapV3.SwapInfo _swapInfo)
```

View function to get swapInfo for a swap pair

**Parameters**

| Name        | Type    | Description      |
| ----------- | ------- | ---------------- |
| \_fromtoken | address | Token to swap    |
| \_totoken   | address | Token to receive |

**Return Values**

| Name       | Type                       | Description                |
| ---------- | -------------------------- | -------------------------- |
| \_swapInfo | struct xWinSwapV3.SwapInfo | SwapInfo for the swap pair |

#### addTokenPath

```solidity
function addTokenPath(address _fromtoken, address _totoken, address _router, address[] path, bytes _pathData, uint24 _slippage, uint24 _fee, enum xWinSwapV3.SwapMethod _swapMethod) external
```

#### \_xWinStratSwap

```solidity
function _xWinStratSwap(uint256 _amount, address _fromToken, address _toToken, uint32 _slippage) internal returns (bool, uint256)
```

This function handles xWinStrategy Token swaps

*check if input tokens are xWinStrategies, if yes handle the swap and return true else return false*

#### adminMoveToken

```solidity
function adminMoveToken(address _tokenAddress) public
```

#### setPriceMaster

```solidity
function setPriceMaster(address _newPriceMaster) external
```

#### setExecutor

```solidity
function setExecutor(address _address, bool _allow) external
```

#### depositToStrategy

```solidity
function depositToStrategy(uint256 _amount, address _strat, uint32 _slippage) internal returns (uint256)
```

#### withdrawFromStrategy

```solidity
function withdrawFromStrategy(uint256 _amount, address _strat, uint32 _slippage) internal returns (uint256)
```


# xWin Swap V3 Pancake

## xWinSwapV3Pancake

#### SwapMethod

```solidity
enum SwapMethod {
  UNISWAPV2,
  UNISWAPV3,
  UNISWAPV3Multihop
}
```

#### SwapInfo

```solidity
struct SwapInfo {
  address router;
  address[] path;
  bytes multihopPath;
  uint24 slippage;
  uint24 poolFee;
  enum xWinSwapV3Pancake.SwapMethod swapMethod;
}
```

#### Received

```solidity
event Received(address, uint256)
```

#### receive

```solidity
receive() external payable
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### swapData

```solidity
mapping(address => mapping(address => struct xWinSwapV3Pancake.SwapInfo)) swapData
```

Mapping containing swapInfo, for swap pair fromToken, toToken

#### executors

```solidity
mapping(address => bool) executors
```

#### priceMaster

```solidity
contract IxWinPriceMaster priceMaster
```

#### initialize

```solidity
function initialize() external
```

#### swapTokenToToken

```solidity
function swapTokenToToken(uint256 _amount, address _fromToken, address _toToken) external returns (uint256)
```

Swap tokens using xWin Swap with slippage

**Parameters**

| Name        | Type    | Description              |
| ----------- | ------- | ------------------------ |
| \_amount    | uint256 | Amount of tokens to swap |
| \_fromToken | address | Token to swap            |
| \_toToken   | address | Token to receive         |

#### swapTokenToToken

```solidity
function swapTokenToToken(uint256 _amount, address _fromToken, address _toToken, uint32 _slippage) public returns (uint256)
```

Swap tokens using xWin Swap with slippage

**Parameters**

| Name        | Type    | Description              |
| ----------- | ------- | ------------------------ |
| \_amount    | uint256 | Amount of tokens to swap |
| \_fromToken | address | Token to swap            |
| \_toToken   | address | Token to receive         |
| \_slippage  | uint32  | Slippage for the swap    |

#### internalSwap

```solidity
function internalSwap(uint256 _amount, address _fromToken, address _toToken, address recipient, uint32 _slippage) internal returns (uint256)
```

#### \_swapV2

```solidity
function _swapV2(address _fromToken, uint256 amountIn, address[] path, address router, address destination, uint256 amountOutQuote) internal returns (uint256)
```

#### \_swapV3

```solidity
function _swapV3(uint256 _amount, address _fromToken, address _toToken, address _recipient, address routerV3, uint256 amountOutQuote, uint24 poolFee) internal returns (uint256)
```

#### \_swapV3Multihop

```solidity
function _swapV3Multihop(uint256 _amount, address _fromToken, address _recipient, address routerV3, uint256 amountOutQuote, bytes multihopPath) internal returns (uint256)
```

#### getSwapData

```solidity
function getSwapData(address _fromtoken, address _totoken) external view returns (struct xWinSwapV3Pancake.SwapInfo _swapInfo)
```

View function to get swapInfo for a swap pair

**Parameters**

| Name        | Type    | Description      |
| ----------- | ------- | ---------------- |
| \_fromtoken | address | Token to swap    |
| \_totoken   | address | Token to receive |

**Return Values**

| Name       | Type                              | Description                |
| ---------- | --------------------------------- | -------------------------- |
| \_swapInfo | struct xWinSwapV3Pancake.SwapInfo | SwapInfo for the swap pair |

#### addTokenPath

```solidity
function addTokenPath(address _fromtoken, address _totoken, address _router, address[] path, bytes _pathData, uint24 _slippage, uint24 _fee, enum xWinSwapV3Pancake.SwapMethod _swapMethod) external
```

#### \_xWinStratSwap

```solidity
function _xWinStratSwap(uint256 _amount, address _fromToken, address _toToken, uint32 _slippage) internal returns (bool, uint256)
```

#### adminMoveToken

```solidity
function adminMoveToken(address _tokenAddress) public
```

#### setPriceMaster

```solidity
function setPriceMaster(address _newPriceMaster) external
```

#### setExecutor

```solidity
function setExecutor(address _address, bool _allow) external
```

#### depositToStrategy

```solidity
function depositToStrategy(uint256 _amount, address _strat, uint32 _slippage) internal returns (uint256)
```

#### withdrawFromStrategy

```solidity
function withdrawFromStrategy(uint256 _amount, address _strat, uint32 _slippage) internal returns (uint256)
```


# xWin Event Emit

### xWinEmitEvent

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### onlyAdmin

```solidity
modifier onlyAdmin()
```

#### executors

```solidity
mapping(address => bool) executors
```

#### admins

```solidity
mapping(address => bool) admins
```

#### FundActivity

```solidity
event FundActivity(string eventtype, address contractaddress, address useraddress, uint256 rate, uint256 outAmount, uint256 shares)
```

#### FeeCollected

```solidity
event FeeCollected(string eventtype, address contractaddress, uint256 fee)
```

#### FeeTransfered

```solidity
event FeeTransfered(address token, uint256 amount, address _managerWallet)
```

#### initialize

```solidity
function initialize() external
```

#### FeeEvent

```solidity
function FeeEvent(string _eventtype, address _contractaddress, uint256 _fee) external
```

#### FundEvent

```solidity
function FundEvent(string _type, address _contractaddress, address _useraddress, uint256 _rate, uint256 _amount, uint256 _shares) external
```

#### feeTransfered

```solidity
function feeTransfered(address _token, uint256 _amount, address _managerWallet) public
```

#### setExecutor

```solidity
function setExecutor(address _address, bool _allow) external
```

#### setAdmin

```solidity
function setAdmin(address _address, bool _allow) external
```


# xWin Strategies


# Portfolio Vaults

xWin Funds that are created by xWin FundFactory are set to open to the public. In BSC and ARB, the portfolio vaults are often index funds. The funds created by xWin FundFactory are default set to private but if a trader wants to open the fund to the public they can do so. When they do set the fund to the public, then the fund will be placed in the portfolio vault on the website.&#x20;

For Polygon and future chains, we will be moving away from the portfolio vault and moving towards using xWin Allocation as we find it more suitable with the fee structure.&#x20;


# xWin DCA Contracts


# xWin DCA-ARB

### xWinDCA

#### targetToken

```solidity
contract IERC20Upgradeable targetToken
```

#### \_baseTokenStaking

```solidity
contract IxWinSingleAssetInterface _baseTokenStaking
```

#### swapEngine

```solidity
contract IxWinSwap swapEngine
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### executors

```solidity
mapping(address => bool) executors
```

#### lastInvestedBlock

```solidity
uint256 lastInvestedBlock
```

#### maxPerSwap

```solidity
uint256 maxPerSwap
```

#### swapDuration

```solidity
uint256 swapDuration
```

#### reinvestDuration

```solidity
uint256 reinvestDuration
```

#### initialize

```solidity
function initialize(address _baseToken, contract IERC20Upgradeable _targetToken, address _swapEngine, address _priceMaster, address baseTokenStaking_, address _USDTokenAddr, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) external
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### deposit

```solidity
function deposit(uint256 _amount) external returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_deposit

```solidity
function _deposit(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### getAmountToSwap

```solidity
function getAmountToSwap() public view returns (uint256)
```

View function to get the amount of base tokens to swap into target token

#### canSystemDeposit

```solidity
function canSystemDeposit() public view returns (bool)
```

#### systemDeposit

```solidity
function systemDeposit() external returns (uint256)
```

Swaps from base token to target token

*Only possible when contract not paused.*

#### getStableCoinTotalBalance

```solidity
function getStableCoinTotalBalance() public view returns (uint256)
```

#### getVaultValues

```solidity
function getVaultValues() public view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256 vaultValue)
```

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() public view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### getStableValues

```solidity
function getStableValues() public view returns (uint256 vaultValue)
```

#### getTargetValues

```solidity
function getTargetValues() public view returns (uint256 vaultValue)
```

#### getBaseValues

```solidity
function getBaseValues() public view returns (uint256 vaultValue)
```

#### withdraw

```solidity
function withdraw(uint256 _shares) external returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _shares, uint32 _slippage) public returns (uint256)
```

#### \_withdraw

```solidity
function _withdraw(uint256 _shares, uint32 _slippage) internal returns (uint256)
```

#### emergencyUnWindPosition

```solidity
function emergencyUnWindPosition() external
```

#### updateProperties

```solidity
function updateProperties(uint256 _maxPerSwap, uint256 _swapDuration, uint256 _reinvestDuration) public
```

#### setExecutor

```solidity
function setExecutor(address _wallet, bool _allow) external
```

#### setSwapEngine

```solidity
function setSwapEngine(address _newSwapEngine) external
```

#### getUnitPrice

```solidity
function getUnitPrice() public view returns (uint256)
```

Calculates the price per share

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() public view returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### getNextInvestBlock

```solidity
function getNextInvestBlock() public view returns (uint256)
```


# xWin DCA

### xWinDCA

#### targetToken

```solidity
contract IERC20Upgradeable targetToken
```

#### \_baseTokenStaking

```solidity
contract IxWinSingleAssetInterface _baseTokenStaking
```

#### swapEngine

```solidity
contract IxWinSwap swapEngine
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### executors

```solidity
mapping(address => bool) executors
```

#### lastInvestedBlock

```solidity
uint256 lastInvestedBlock
```

#### maxPerSwap

```solidity
uint256 maxPerSwap
```

#### swapDuration

```solidity
uint256 swapDuration
```

#### reinvestDuration

```solidity
uint256 reinvestDuration
```

#### initialize

```solidity
function initialize(address _baseToken, contract IERC20Upgradeable _targetToken, address _swapEngine, address _priceMaster, address baseTokenStaking_, address _USDTokenAddr, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) external
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### deposit

```solidity
function deposit(uint256 _amount) external returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_deposit

```solidity
function _deposit(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### getAmountToSwap

```solidity
function getAmountToSwap() public view returns (uint256)
```

View function to get the amount of base tokens to swap into target token

#### canSystemDeposit

```solidity
function canSystemDeposit() public view returns (bool)
```

#### systemDeposit

```solidity
function systemDeposit() external returns (uint256)
```

Swaps from base token to target token

*Only possible when contract not paused.*

#### getStableCoinTotalBalance

```solidity
function getStableCoinTotalBalance() public view returns (uint256)
```

#### getVaultValues

```solidity
function getVaultValues() public view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256 vaultValue)
```

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() public view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### getStableValues

```solidity
function getStableValues() public view returns (uint256 vaultValue)
```

#### getTargetValues

```solidity
function getTargetValues() public view returns (uint256 vaultValue)
```

#### getBaseValues

```solidity
function getBaseValues() public view returns (uint256 vaultValue)
```

#### withdraw

```solidity
function withdraw(uint256 _shares) external returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _shares, uint32 _slippage) public returns (uint256)
```

#### \_withdraw

```solidity
function _withdraw(uint256 _shares, uint32 _slippage) internal returns (uint256)
```

#### emergencyUnWindPosition

```solidity
function emergencyUnWindPosition() external
```

#### updateProperties

```solidity
function updateProperties(uint256 _maxPerSwap, uint256 _swapDuration, uint256 _reinvestDuration) public
```

#### setExecutor

```solidity
function setExecutor(address _wallet, bool _allow) external
```

#### setSwapEngine

```solidity
function setSwapEngine(address _newSwapEngine) external
```

#### getUnitPrice

```solidity
function getUnitPrice() public view returns (uint256)
```

Calculates the price per share

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() public view returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### getNextInvestBlock

```solidity
function getNextInvestBlock() public view returns (uint256)
```


# xWin SCA

### xWinERC20Alpha

#### targetToken

```solidity
contract IERC20Upgradeable targetToken
```

#### \_baseTokenStaking

```solidity
contract IERC20Upgradeable _baseTokenStaking
```

#### swapEngine

```solidity
contract IxWinSwap swapEngine
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### executors

```solidity
mapping(address => bool) executors
```

#### lastInvestedBlock

```solidity
uint256 lastInvestedBlock
```

#### reinvestDuration

```solidity
uint256 reinvestDuration
```

#### totalDeposit

```solidity
uint256 totalDeposit
```

#### Pause

```solidity
event Pause()
```

#### Unpause

```solidity
event Unpause()
```

#### initialize

```solidity
function initialize(address _baseToken, address _USDTokenAddr, string _name, string _symbol, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) external
```

#### init

```solidity
function init(contract IERC20Upgradeable _targetToken, address _swapEngine, address baseTokenStaking_, address _xWinPriceMaster) external
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### deposit

```solidity
function deposit(uint256 _amount) external returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_deposit

```solidity
function _deposit(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### canSystemDeposit

```solidity
function canSystemDeposit() external view returns (bool)
```

#### \_calcMintQty

```solidity
function _calcMintQty(uint256 _unitPrice) internal view returns (uint256 mintQty)
```

#### systemDeposit

```solidity
function systemDeposit() external
```

Swaps interest received from baseTokenStaking into target token

*Only possible when contract not paused.*

#### getAmountToSwap

```solidity
function getAmountToSwap() public view returns (uint256)
```

#### getVaultValues

```solidity
function getVaultValues() public view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256 vaultValue)
```

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() public view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### \_getVaultValuesInUSD

```solidity
function _getVaultValuesInUSD() internal view returns (uint256 vaultValue)
```

#### getStableValues

```solidity
function getStableValues() external view returns (uint256 vaultValue)
```

#### getTargetValues

```solidity
function getTargetValues() external view returns (uint256 vaultValue)
```

#### getBaseValues

```solidity
function getBaseValues() external view returns (uint256 vaultValue)
```

#### withdraw

```solidity
function withdraw(uint256 _shares) external returns (uint256)
```

Withdraws from funds from the Cake Vault

**Parameters**

| Name     | Type    | Description |
| -------- | ------- | ----------- |
| \_shares | uint256 |             |

#### withdraw

```solidity
function withdraw(uint256 _shares, uint32 _slippage) public returns (uint256)
```

#### \_withdraw

```solidity
function _withdraw(uint256 _shares, uint32 _slippage) internal returns (uint256)
```

#### adminStakeStable

```solidity
function adminStakeStable() external
```

#### emergencyUnWindPosition

```solidity
function emergencyUnWindPosition() external
```

#### setPriceMaster

```solidity
function setPriceMaster(address _newPriceMaster) external
```

#### setProperties

```solidity
function setProperties(uint256 _reinvestDuration) external
```

#### setExecutor

```solidity
function setExecutor(address _wallet, bool _allow) external
```

#### setSwapEngine

```solidity
function setSwapEngine(address _newSwapEngine) external
```

#### getUnitPrice

```solidity
function getUnitPrice() public view returns (uint256)
```

Calculates the price per share

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() public view returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### getNextInvestBlock

```solidity
function getNextInvestBlock() external view returns (uint256)
```


# xWin BBMA (BSC)

### xWinBBMA

#### TradeQueue

```solidity
struct TradeQueue {
  bool nextTrade;
  uint256 nextTradeBlock;
  uint8 tradeType;
}
```

#### targetToken

```solidity
contract IERC20Upgradeable targetToken
```

#### swapEngine

```solidity
contract IxWinSwap swapEngine
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### executors

```solidity
mapping(address => bool) executors
```

#### tradeQueue

```solidity
struct xWinBBMA.TradeQueue tradeQueue
```

#### maxPerSwap

```solidity
uint256 maxPerSwap
```

#### tradeCycle

```solidity
uint256 tradeCycle
```

#### stopLossPrice

```solidity
uint256 stopLossPrice
```

#### takeProfitPrice

```solidity
uint256 takeProfitPrice
```

#### stopLossPerc

```solidity
uint256 stopLossPerc
```

#### takeProfitPerc

```solidity
uint256 takeProfitPerc
```

#### initialize

```solidity
function initialize(address _baseToken, contract IERC20Upgradeable _targetToken, address _swapEngine, address _USDTokenAddr, address _xWinPriceMaster, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) external
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### checkUpkeep

```solidity
function checkUpkeep(bytes) external view returns (bool upkeepNeeded, bytes performData)
```

#### performUpkeep

```solidity
function performUpkeep(bytes) external
```

#### updatexWinPriceMaster

```solidity
function updatexWinPriceMaster(address _xWinPriceMaster) external
```

*update xwin master contract*

#### deposit

```solidity
function deposit(uint256 _amount) external returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_deposit

```solidity
function _deposit(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### systemReTrade

```solidity
function systemReTrade() external
```

#### systemTrade

```solidity
function systemTrade(uint8 _tradeType) public
```

Triggered offchain when there is a signal buy or close-buy

#### \_systemTrade

```solidity
function _systemTrade(uint8 _tradeType) internal
```

#### \_setStopLossBuy

```solidity
function _setStopLossBuy(uint256 _rate) internal
```

#### \_setTakeProfitBuy

```solidity
function _setTakeProfitBuy(uint256 _rate) internal
```

#### getTriggerTakeProfit

```solidity
function getTriggerTakeProfit() public view returns (bool)
```

#### getTriggerStopLoss

```solidity
function getTriggerStopLoss() public view returns (bool)
```

#### getVaultValues

```solidity
function getVaultValues() public view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() public view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256 vaultValue)
```

#### \_getVaultValuesInUSD

```solidity
function _getVaultValuesInUSD() internal view returns (uint256 vaultValue)
```

#### getStableValues

```solidity
function getStableValues() public view returns (uint256 vaultValue)
```

#### getTargetValues

```solidity
function getTargetValues() public view returns (uint256 vaultValue)
```

#### withdraw

```solidity
function withdraw(uint256 _shares) external returns (uint256)
```

Withdraws from funds from the Cake Vault

**Parameters**

| Name     | Type    | Description |
| -------- | ------- | ----------- |
| \_shares | uint256 |             |

#### withdraw

```solidity
function withdraw(uint256 _shares, uint32 _slippage) public returns (uint256)
```

#### \_withdraw

```solidity
function _withdraw(uint256 _shares, uint32 _slippage) internal returns (uint256)
```

#### emergencyUnWindPosition

```solidity
function emergencyUnWindPosition() external
```

#### setProperties

```solidity
function setProperties(uint256 _stopLossPerc, uint256 _takeProfitPerc, uint256 _tradeCycle, uint256 _maxPerSwap) public
```

#### setExecutor

```solidity
function setExecutor(address _wallet, bool _allow) external
```

#### setSwapEngine

```solidity
function setSwapEngine(address _newSwapEngine) external
```

#### getUnitPrice

```solidity
function getUnitPrice() public view returns (uint256)
```

The unitprice of a share of this fund in baseToken

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() public view returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### isReTrade

```solidity
function isReTrade() public view returns (bool)
```


# xWin IRT (BSC)

### xWinIRT

#### TradeQueue

```solidity
struct TradeQueue {
  bool nextTrade;
  uint8 tradeType;
  bool ReadyToTrade;
  uint256 nextTradeBlock;
  uint256 AmountToBuy;
  uint256 AmountPerDay;
}
```

#### targetToken

```solidity
contract IERC20Upgradeable targetToken
```

#### swapEngine

```solidity
contract IxWinSwap swapEngine
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### stopLossPrice

```solidity
uint256 stopLossPrice
```

#### stopLossPerc

```solidity
uint256 stopLossPerc
```

#### executors

```solidity
mapping(address => bool) executors
```

#### tradeQueue

```solidity
struct xWinIRT.TradeQueue tradeQueue
```

#### maxPerSwap

```solidity
uint256 maxPerSwap
```

#### tradeCycle

```solidity
uint256 tradeCycle
```

#### initialize

```solidity
function initialize(address _baseToken, contract IERC20Upgradeable _targetToken, address _swapEngine, address _USDTokenAddr, address _xWinPriceMaster, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) external
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### updatexWinPriceMaster

```solidity
function updatexWinPriceMaster(address _xWinPriceMaster) external
```

*update xwin master contract*

#### checkUpkeep

```solidity
function checkUpkeep(bytes) external view returns (bool upkeepNeeded, bytes performData)
```

#### performUpkeep

```solidity
function performUpkeep(bytes) external
```

#### getTriggerStopLoss

```solidity
function getTriggerStopLoss() public view returns (bool)
```

#### \_setStopLossBuy

```solidity
function _setStopLossBuy(uint256 _rate) internal
```

#### deposit

```solidity
function deposit(uint256 _amount) external returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_deposit

```solidity
function _deposit(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### systemReTrade

```solidity
function systemReTrade() external
```

#### systemTrade

```solidity
function systemTrade(uint8 _tradeType) public
```

Triggered offchain when there is a signal buy or close-buy

#### \_systemTrade

```solidity
function _systemTrade(uint8 _tradeType) internal
```

#### getVaultValues

```solidity
function getVaultValues() public view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256 vaultValue)
```

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() public view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### getStableValues

```solidity
function getStableValues() public view returns (uint256 vaultValue)
```

#### getTargetValues

```solidity
function getTargetValues() public view returns (uint256 vaultValue)
```

#### withdraw

```solidity
function withdraw(uint256 _shares) external returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _shares, uint32 _slippage) public returns (uint256)
```

#### \_withdraw

```solidity
function _withdraw(uint256 _shares, uint32 _slippage) internal returns (uint256)
```

#### emergencyUnWindPosition

```solidity
function emergencyUnWindPosition() external
```

#### setProperties

```solidity
function setProperties(uint256 _tradeCycle, uint256 _maxPerSwap) public
```

#### setExecutor

```solidity
function setExecutor(address _wallet, bool _allow) external
```

#### setSwapEngine

```solidity
function setSwapEngine(address _newSwapEngine) external
```

#### setStopLossPerc

```solidity
function setStopLossPerc(uint256 _newStopLossPerc) external
```

#### getUnitPrice

```solidity
function getUnitPrice() public view returns (uint256)
```

Calculates the price per share

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() public view returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### GetAmountPerDay

```solidity
function GetAmountPerDay() external view returns (uint256)
```

#### GetAmountToBuy

```solidity
function GetAmountToBuy() external view returns (uint256)
```

#### BuyOrSell

```solidity
function BuyOrSell() public view returns (uint256)
```

#### ReadyToTrade

```solidity
function ReadyToTrade() public view returns (bool)
```

#### UserShares

```solidity
function UserShares() external view returns (uint256)
```

#### isReTrade

```solidity
function isReTrade() public view returns (bool)
```


# xWin Single Asset Contract


# xWin Single Asset

### xWinSingleAsset

#### swapEngine

```solidity
contract IxWinSwap swapEngine
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### \_OlaFinance

```solidity
contract OlaFinance _OlaFinance
```

#### \_rainMaker

```solidity
contract RainMakerForOlaLens _rainMaker
```

#### lendingRewardToken

```solidity
contract IERC20Upgradeable lendingRewardToken
```

#### smallRatio

```solidity
uint256 smallRatio
```

#### executors

```solidity
mapping(address => bool) executors
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### initialize

```solidity
function initialize(string name, string symbol, address _baseToken, address _USDTokenAddr, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) external
```

#### init

```solidity
function init(address _swapEngine, address _lendingRewardToken, address _xWinPriceMaster) external
```

#### updateProperties

```solidity
function updateProperties(address olaFinance_, address rainMaker_) external
```

#### getUserBalance

```solidity
function getUserBalance(address _user) public view returns (uint256)
```

#### getSupplyRatePerBlock

```solidity
function getSupplyRatePerBlock() public view returns (uint256)
```

#### getBorrowRatePerBlock

```solidity
function getBorrowRatePerBlock() public view returns (uint256)
```

#### getUnitPrice

```solidity
function getUnitPrice() public view returns (uint256)
```

The unitprice of a share of this fund in baseToken

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### \_getUnitPrice

```solidity
function _getUnitPrice(uint256 fundvalue) internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() public view returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### deposit

```solidity
function deposit(uint256 _amount) external returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_deposit

```solidity
function _deposit(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _amount) external returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_withdraw

```solidity
function _withdraw(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### getVaultValues

```solidity
function getVaultValues() external view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() external view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256)
```

#### \_getVaultValuesInUSD

```solidity
function _getVaultValuesInUSD() internal view returns (uint256)
```

#### canReclaimRainMaker

```solidity
function canReclaimRainMaker() public view returns (bool)
```

#### canSystemDeposit

```solidity
function canSystemDeposit() public view returns (bool)
```

#### systemDeposit

```solidity
function systemDeposit() external
```

#### emergencyUnWindPosition

```solidity
function emergencyUnWindPosition() external
```

#### reinvestClaimComp

```solidity
function reinvestClaimComp() public
```

#### getAccruedComp

```solidity
function getAccruedComp() public view returns (uint256)
```

#### getStrategyInfo

```solidity
function getStrategyInfo() external view returns (address targetaddress, address rewardaddress)
```

#### \_depositOla

```solidity
function _depositOla() internal
```

#### \_removeOla

```solidity
function _removeOla(uint256 _amount) internal
```

#### setExecutor

```solidity
function setExecutor(address _wallet, bool _allow) external
```

#### updateSmallRatio

```solidity
function updateSmallRatio(uint256 _ratio) external
```

*update small ratio*

#### setSwapEngine

```solidity
function setSwapEngine(address _newSwapEngine) external
```

#### setPriceMaster

```solidity
function setPriceMaster(address _newPriceMaster) external
```

#### setLendingRewardToken

```solidity
function setLendingRewardToken(address _newRewardToken) public
```

#### setRainMaker

```solidity
function setRainMaker(address rainMaker_) public
```


# xWin Single Asset Aave

### xWinSingleAssetAave

#### swapEngine

```solidity
contract IxWinSwap swapEngine
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### aavePool

```solidity
contract IPool aavePool
```

#### aavePoolDataProvider

```solidity
contract IPoolDataProvider aavePoolDataProvider
```

#### targetToken

```solidity
contract IERC20Upgradeable targetToken
```

#### smallRatio

```solidity
uint256 smallRatio
```

#### executors

```solidity
mapping(address => bool) executors
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### initialize

```solidity
function initialize(string name, string symbol, address _baseToken, address _swapEngine, address _xWinPriceMaster, address _USDTokenAddr, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) external
```

#### updateProperties

```solidity
function updateProperties(address _targetToken, address _pool, address _aavePoolDataProvider) external
```

#### getUserBalance

```solidity
function getUserBalance(address _user) public view returns (uint256)
```

#### getSupplyRate

```solidity
function getSupplyRate() public view returns (uint256)
```

#### getUnitPrice

```solidity
function getUnitPrice() public view returns (uint256)
```

The unitprice of a share of this fund in baseToken

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### \_getUnitPrice

```solidity
function _getUnitPrice(uint256 fundvalue) internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() public view returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### deposit

```solidity
function deposit(uint256 _amount) external returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_deposit

```solidity
function _deposit(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### \_getMintQty

```solidity
function _getMintQty(uint256 _unitPrice) internal view returns (uint256 mintQty)
```

#### withdraw

```solidity
function withdraw(uint256 _amount) external returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_withdraw

```solidity
function _withdraw(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### getVaultValues

```solidity
function getVaultValues() external view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() external view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256)
```

#### \_getVaultValuesInUSD

```solidity
function _getVaultValuesInUSD() internal view returns (uint256)
```

#### canSystemDeposit

```solidity
function canSystemDeposit() public view returns (bool)
```

#### systemDeposit

```solidity
function systemDeposit() external
```

#### emergencyUnWindPosition

```solidity
function emergencyUnWindPosition() external
```

#### \_depositAave

```solidity
function _depositAave() internal
```

#### \_removeAave

```solidity
function _removeAave(uint256 _amount) internal
```

#### setExecutor

```solidity
function setExecutor(address _wallet, bool _allow) external
```

#### updateSmallRatio

```solidity
function updateSmallRatio(uint256 _ratio) external
```

*update small ratio*

#### setSwapEngine

```solidity
function setSwapEngine(address _newSwapEngine) external
```

#### setPriceMaster

```solidity
function setPriceMaster(address _newPriceMaster) external
```


# xWin Single Asset Alpaca

### xWinSingleAssetAlpaca

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### \_Alpaca

```solidity
contract IAlpaca _Alpaca
```

#### smallRatio

```solidity
uint256 smallRatio
```

#### executors

```solidity
mapping(address => bool) executors
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### initialize

```solidity
function initialize(string name, string symbol, address _baseToken, address _xWinPriceMaster, address alpaca_, address _USDTokenAddr, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) external
```

#### getUserBalance

```solidity
function getUserBalance(address _user) public view returns (uint256)
```

#### getUnitPrice

```solidity
function getUnitPrice() public view returns (uint256)
```

The unitprice of a share of this fund in baseToken

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### \_getUnitPrice

```solidity
function _getUnitPrice(uint256 fundvalue) internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() public view returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### deposit

```solidity
function deposit(uint256 _amount) external returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_deposit

```solidity
function _deposit(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _amount) external returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_withdraw

```solidity
function _withdraw(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### getVaultValues

```solidity
function getVaultValues() external view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() external view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256)
```

#### \_getVaultValuesInUSD

```solidity
function _getVaultValuesInUSD() internal view returns (uint256)
```

#### canSystemDeposit

```solidity
function canSystemDeposit() public view returns (bool)
```

#### systemDeposit

```solidity
function systemDeposit() external
```

#### emergencyUnWindPosition

```solidity
function emergencyUnWindPosition() external
```

#### \_getAlpacaPrice

```solidity
function _getAlpacaPrice() internal view returns (uint256 price)
```

#### \_deposit

```solidity
function _deposit() internal
```

#### \_removeAlpaca

```solidity
function _removeAlpaca(uint256 _amount) internal
```

#### setExecutor

```solidity
function setExecutor(address _wallet, bool _allow) external
```

#### updateSmallRatio

```solidity
function updateSmallRatio(uint256 _ratio) external
```

*update small ratio*

#### setPriceMaster

```solidity
function setPriceMaster(address _newPriceMaster) external
```


# xWin Single Asset Ola

### xWinSingleAssetOla

#### swapEngine

```solidity
contract IxWinSwap swapEngine
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### \_OlaFinance

```solidity
contract OlaFinance _OlaFinance
```

#### \_rainMaker

```solidity
contract RainMakerForOlaLens _rainMaker
```

#### lendingRewardToken

```solidity
contract IERC20Upgradeable lendingRewardToken
```

#### smallRatio

```solidity
uint256 smallRatio
```

#### executors

```solidity
mapping(address => bool) executors
```

#### SwitchProtocol

```solidity
event SwitchProtocol(address fromProtocol, address toProtocol)
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### initialize

```solidity
function initialize(string name, string symbol, address _baseToken, address _USDTokenAddr, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) external
```

#### init

```solidity
function init(address _swapEngine, address _lendingRewardToken, address _xWinPriceMaster) external
```

#### updateProperties

```solidity
function updateProperties(address olaFinance_, address rainMaker_) external
```

#### getUserBalance

```solidity
function getUserBalance(address _user) public view returns (uint256)
```

#### getSupplyRatePerBlock

```solidity
function getSupplyRatePerBlock() public view returns (uint256)
```

#### getBorrowRatePerBlock

```solidity
function getBorrowRatePerBlock() public view returns (uint256)
```

#### getUnitPrice

```solidity
function getUnitPrice() public view returns (uint256)
```

The unitprice of a share of this fund in baseToken

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### \_getUnitPrice

```solidity
function _getUnitPrice(uint256 fundvalue) internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() public view returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### deposit

```solidity
function deposit(uint256 _amount) external returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_deposit

```solidity
function _deposit(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _amount) external returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_withdraw

```solidity
function _withdraw(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### getVaultValues

```solidity
function getVaultValues() external view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() external view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256)
```

#### \_getVaultValuesInUSD

```solidity
function _getVaultValuesInUSD() internal view returns (uint256)
```

#### canReclaimRainMaker

```solidity
function canReclaimRainMaker() public view returns (bool)
```

#### canSystemDeposit

```solidity
function canSystemDeposit() public view returns (bool)
```

#### systemDeposit

```solidity
function systemDeposit() external
```

#### emergencyUnWindPosition

```solidity
function emergencyUnWindPosition() external
```

#### reinvestClaimComp

```solidity
function reinvestClaimComp() public
```

#### getAccruedComp

```solidity
function getAccruedComp() public view returns (uint256)
```

#### getStrategyInfo

```solidity
function getStrategyInfo() external view returns (address targetaddress, address rewardaddress)
```

#### \_depositOla

```solidity
function _depositOla() internal
```

#### \_removeOla

```solidity
function _removeOla(uint256 _amount) internal
```

#### setExecutor

```solidity
function setExecutor(address _wallet, bool _allow) external
```

#### updateSmallRatio

```solidity
function updateSmallRatio(uint256 _ratio) external
```

*update small ratio*

#### setSwapEngine

```solidity
function setSwapEngine(address _newSwapEngine) external
```

#### setPriceMaster

```solidity
function setPriceMaster(address _newPriceMaster) external
```

#### setLendingRewardToken

```solidity
function setLendingRewardToken(address _newRewardToken) public
```

#### setRainMaker

```solidity
function setRainMaker(address rainMaker_) public
```


# xWin Single Asset Prime

### xWinSingleAssetWithPrime

#### swapEngine

```solidity
contract IxWinSwap swapEngine
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### \_OlaFinance

```solidity
contract OlaFinance _OlaFinance
```

#### \_rainMaker

```solidity
contract RainMakerForOlaLens _rainMaker
```

#### lendingRewardToken

```solidity
contract IERC20Upgradeable lendingRewardToken
```

#### smallRatio

```solidity
uint256 smallRatio
```

#### executors

```solidity
mapping(address => bool) executors
```

#### UserDataXVS

```solidity
struct UserDataXVS {
  uint256 shares;
}
```

#### userDataMapXVS

```solidity
mapping(address => struct xWinSingleAsset.UserDataXVS) userDataMapXVS
```

#### totalUserSharesXVS

```solidity
uint256 totalUserSharesXVS
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### initialize

```solidity
function initialize(string name, string symbol, address _baseToken, address _USDTokenAddr, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) external
```

#### init

```solidity
function init(address _swapEngine, address _lendingRewardToken, address _xWinPriceMaster) external
```

#### updateProperties

```solidity
function updateProperties(address olaFinance_, address rainMaker_) external
```

#### getUserBalance

```solidity
function getUserBalance(address _user) public view returns (uint256)
```

#### getSupplyRatePerBlock

```solidity
function getSupplyRatePerBlock() public view returns (uint256)
```

#### getBorrowRatePerBlock

```solidity
function getBorrowRatePerBlock() public view returns (uint256)
```

#### getUnitPrice

```solidity
function getUnitPrice() public view returns (uint256)
```

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### \_getUnitPrice

```solidity
function _getUnitPrice(uint256 fundvalue) internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() public view returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 _amount) external returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_deposit

```solidity
function _deposit(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _amount) external returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_withdraw

```solidity
function _withdraw(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### getVaultValues

```solidity
function getVaultValues() external view returns (uint256 vaultValue)
```

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() external view returns (uint256 vaultValue)
```

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256)
```

#### \_getVaultValuesInUSD

```solidity
function _getVaultValuesInUSD() internal view returns (uint256)
```

#### canReclaimRainMaker

```solidity
function canReclaimRainMaker() public view returns (bool)
```

#### canSystemDeposit

```solidity
function canSystemDeposit() public view returns (bool)
```

#### systemDeposit

```solidity
function systemDeposit() external
```

#### emergencyUnWindPosition

```solidity
function emergencyUnWindPosition() external
```

#### reinvestClaimComp

```solidity
function reinvestClaimComp() public
```

#### getAccruedComp

```solidity
function getAccruedComp() public view returns (uint256)
```

#### getStrategyInfo

```solidity
function getStrategyInfo() external view returns (address targetaddress, address rewardaddress)
```

#### \_depositOla

```solidity
function _depositOla() internal
```

#### \_removeOla

```solidity
function _removeOla(uint256 _amount) internal
```

#### setExecutor

```solidity
function setExecutor(address _wallet, bool _allow) external
```

#### updateSmallRatio

```solidity
function updateSmallRatio(uint256 _ratio) external
```

*update small ratio*

#### setSwapEngine

```solidity
function setSwapEngine(address _newSwapEngine) external
```

#### setPriceMaster

```solidity
function setPriceMaster(address _newPriceMaster) external
```

#### setLendingRewardToken

```solidity
function setLendingRewardToken(address _newRewardToken) public
```

#### setRainMaker

```solidity
function setRainMaker(address rainMaker_) public
```

#### depositXVS

```solidity
function depositXVS(uint256 _amount) public returns (uint256)
```

#### withdrawXVS

```solidity
function withdrawXVS(uint256 _shares) public returns (uint256)
```

#### claimRewardsXVS

```solidity
function claimRewardsXVS() public
```

#### claimPrimeToken

```solidity
function claimPrimeToken() public
```

#### getUnitPriceXVS

```solidity
function getUnitPriceXVS() public
```

#### getVaultValueXVS

```solidity
function getVaultValueXVS(uint256 _amount) public
```

#### \_getMintQtyXVS

```solidity
function _getMintQtyXVS(uint256 _amount) internal returns (uint256)
```


# xWin Allocation

### xWinAllocations

#### xWinSwap

```solidity
contract IxWinSwap xWinSwap
```

#### priceMaster

```solidity
contract IxWinPriceMaster priceMaster
```

#### executors

```solidity
mapping(address => bool) executors
```

#### TargetWeight

```solidity
mapping(address => uint256) TargetWeight
```

#### targetAddr

```solidity
address[] targetAddr
```

#### initialize

```solidity
function initialize(string _name, string _symbol, address _baseToken, address _swapEngine, address _USDTokenAddr, address _xWinPriceMaster, uint256 _managerFee, uint256 _performanceFee, uint256 _collectionPeriod, address _managerAddr) external
```

#### onlyExecutor

```solidity
modifier onlyExecutor()
```

#### updatexWinPriceMaster

```solidity
function updatexWinPriceMaster(address _xWinPriceMaster) external
```

*update xwin master contract*

#### \_deposit

```solidity
function _deposit(uint256 _amount, uint32 _slippage) internal returns (uint256)
```

#### deposit

```solidity
function deposit(uint256 amount) external returns (uint256)
```

Deposits baseToken into the fund, and receives shares based on the fund's unitPrice

**Parameters**

| Name   | Type    | Description                    |
| ------ | ------- | ------------------------------ |
| amount | uint256 | Amount of baseToken to deposit |

**Return Values**

| Name | Type    | Description                                 |
| ---- | ------- | ------------------------------------------- |
| \[0] | uint256 | shares Amount of shares minted to depositor |

#### deposit

```solidity
function deposit(uint256 _amount, uint32 _slippage) public returns (uint256)
```

#### \_calcMintQty

```solidity
function _calcMintQty(uint256 _unitPrice) internal view returns (uint256 mintQty)
```

#### \_withdraw

```solidity
function _withdraw(uint256 _shares, uint32 _slippage) internal returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _shares) external returns (uint256)
```

#### withdraw

```solidity
function withdraw(uint256 _shares, uint32 _slippage) public returns (uint256)
```

#### \_getLatestPrice

```solidity
function _getLatestPrice(address _targetAdd) internal view returns (uint256)
```

#### \_getLatestPriceInUSD

```solidity
function _getLatestPriceInUSD(address _targetAdd) internal view returns (uint256)
```

#### getLatestPrice

```solidity
function getLatestPrice(address _targetAdd) external view returns (uint256)
```

#### createTargetNames

```solidity
function createTargetNames(address[] _toAddr, uint256[] _targets) public
```

Sets target token addresses and weights for the fund

#### Rebalance

```solidity
function Rebalance(address[] _toAddr, uint256[] _targets, uint32 _slippage) public
```

Performs rebalance with new weight and reset next rebalance period

#### \_moveNonIndex

```solidity
function _moveNonIndex(address _token, uint32 _slippage) internal returns (uint256 balanceToken, uint256 swapOutput)
```

#### \_getDeleteNames

```solidity
function _getDeleteNames(address[] _toAddr) internal view returns (struct xWinLib.DeletedNames[] delNames)
```

#### Rebalance

```solidity
function Rebalance(address[] _toAddr, uint256[] _targets) external
```

Performs rebalance with new weight and reset next rebalance period

#### \_rebalance

```solidity
function _rebalance(uint32 _slippage) internal
```

#### \_sellOverWeightNames

```solidity
function _sellOverWeightNames(uint32 _slippage) internal returns (struct xWinLib.UnderWeightData[] underwgts, uint256 totalunderwgt)
```

#### \_buyUnderWeightNames

```solidity
function _buyUnderWeightNames(struct xWinLib.UnderWeightData[] underweights, uint256 totalunderwgt, uint32 _slippage) internal
```

#### \_getActiveOverWeight

```solidity
function _getActiveOverWeight(address destAddr, uint256 totalvalue) internal view returns (uint256 destRebQty, uint256 destActiveWeight, bool overweight)
```

#### getTokenValues

```solidity
function getTokenValues(address tokenaddress) external view returns (uint256)
```

#### \_getTokenValues

```solidity
function _getTokenValues(address token) internal view returns (uint256)
```

#### getBalance

```solidity
function getBalance(address fromAdd) public view returns (uint256)
```

#### \_getTransferAmt

```solidity
function _getTransferAmt(address underying, uint256 redeemratio) internal view returns (struct xWinLib.transferData transData)
```

#### setExecutor

```solidity
function setExecutor(address _wallet, bool _allow) external
```

#### getUnitPrice

```solidity
function getUnitPrice() public view returns (uint256)
```

The unitprice of a share of this fund in baseToken

#### \_getUnitPrice

```solidity
function _getUnitPrice() internal view returns (uint256)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() public view returns (uint256)
```

The unitprice of a share of this fund, in stablecoinUSDAddr

#### getVaultValues

```solidity
function getVaultValues() public view returns (uint256 vaultValue)
```

Gets the total value of the tokens within the fund, value shown in baseToken

#### \_getVaultValues

```solidity
function _getVaultValues() internal view returns (uint256 vaultValue)
```

#### getTargetWeightQty

```solidity
function getTargetWeightQty(address targetAdd, uint256 srcQty) internal view returns (uint256)
```

#### \_getTokenValuesInUSD

```solidity
function _getTokenValuesInUSD(address token) internal view returns (uint256)
```

#### getVaultValuesInUSD

```solidity
function getVaultValuesInUSD() external view returns (uint256)
```

Gets the total value of the tokens within the fund, value shown in stablecoinUSDAddr

#### \_getVaultValuesInUSD

```solidity
function _getVaultValuesInUSD() internal view returns (uint256)
```

#### getStableValues

```solidity
function getStableValues() public view returns (uint256 vaultValue)
```

#### getTargetNamesAddress

```solidity
function getTargetNamesAddress() external view returns (address[] _targetNamesAddress)
```


# Deployed Smart Contract


# BSC

### xWIN Smart Contracts

<table><thead><tr><th width="237">Name</th><th>Address</th></tr></thead><tbody><tr><td>xWIN Swap</td><td>0x9Ce3fCffaeB4B7Fbdf39E9313F845d977393D8d1</td></tr><tr><td>xWIN TWAP</td><td>0x7A8aa080EAdA0b670fb719D7E53f87898a1299Ac</td></tr><tr><td>xWIN PriceMaster</td><td>0xB1233713FeA0984fff84c7456d2cCed43e5e48E2</td></tr><tr><td>xWIN EventEmitter</td><td>0xc4c0171A31b6CEd6daA4342343425F2eeA703cc6</td></tr><tr><td>xWIN FundV2Factory</td><td>0x9ab3c504De0fDa0087D378123bDC318AADbC60a0</td></tr></tbody></table>

### xWIN Strategies Smart Contracts

<table><thead><tr><th width="158">Symbol</th><th width="252">Name</th><th>Address</th></tr></thead><tbody><tr><td>xSCA</td><td>(BTC) Stable USDT Alpha</td><td>0x0a652784DF3f8Abde85dAEeee77D1EA97f5c5B24</td></tr><tr><td>xDCA</td><td>(BTC) Dollar Cost Average</td><td>0x482ae949E4a70953fCa090717b68359b73b8602a</td></tr><tr><td>xWinBBMA</td><td>(BTC) Band Bollinger Moving Average</td><td>0x5EFaaBc34a3ba66f1fD02F056AC457AeBaF57D55</td></tr><tr><td>xWinIRT</td><td>(BTC) Interest Rate Indicator</td><td>0x5A8a66DF53DF88844c60829967b88d00eD208E08</td></tr><tr><td>xCAKE-V</td><td>CAKE Staking Venus</td><td>0x1d2430bBfe86432E36A7C7286E99f78546F23De9</td></tr><tr><td>xETH-V</td><td>ETH Staking Venus</td><td>0x0C34Aa4e36983aB6ec11bC557A3B8cF79A7a9Ae7</td></tr><tr><td>xUSDC-V</td><td>USDC Staking Venus</td><td>0xcBca44d60c5A2b3c56ACfB51aFC66Ea04b8a2742</td></tr><tr><td>xBUSD-V</td><td>BUSD Staking Venus</td><td>0xf4979C043df6f7d5dA929DeAB11b220A82886395</td></tr><tr><td>xBTC-V</td><td>BTC Staking Venus</td><td>0x7A0dEc70473602Cd0EF3Dc3d909b6Dc3FA42116C</td></tr><tr><td>xUSDT-V</td><td>USDT Staking Venus</td><td>0x8B7fcACB99124F009c8470FDa6f5fcF60277BDB2</td></tr><tr><td>xADA-V</td><td>ADA Staking Venus</td><td>0x605926F795FD9B4c3A8B1A2db33cBE01c66bA83f</td></tr><tr><td>xBTC-O</td><td>BTC Staking OlaFinance</td><td>0x69764856e82180150f5366be610E40c2f812d7D6</td></tr><tr><td>xUSDT-O</td><td>USDT Staking OlaFinance</td><td>0xCEbd365e4BFd8589Fd6BDe21898DB35a8095f956</td></tr></tbody></table>

### xWIN Public Allocation Vaults Smart Contracts

<table><thead><tr><th width="144">Symbol</th><th width="212">Name</th><th>Address</th></tr></thead><tbody><tr><td>fDEFI</td><td>xWIN DEFI Index</td><td>0x61d5722290F8755b2f31D260064658D6Ad837F37</td></tr><tr><td>fMIV</td><td>Major Index Vault</td><td>0x0A0817454710102F2bcB2215D616cBe3aFf495e5</td></tr><tr><td>fxDollar</td><td>Dollar Zanmai</td><td>0xFa4d4B4243dDA1F5f4d09269f61D57d02470635C</td></tr><tr><td>fBTCETH</td><td>BTC-ETH-50-50</td><td>0x284b4aDD0C9669f635EA64418C216821c45D0B48</td></tr><tr><td>fvUSDT</td><td>USDT Venus / Ola Staking</td><td>0xE949d266E8740470a15DFB1F40A795b5a2b63f02</td></tr><tr><td>fCombo</td><td>xWIN Combo</td><td>0x4d4F948C8E9Ec3d1cE1B80d598f57F8c75c64e4a</td></tr><tr><td>fTACombo</td><td>xWIN TA Combo</td><td>0xaaFF5eFe1376474a520FFe9129d8Aa8d7422AAbe</td></tr></tbody></table>


# Arbitrum

### xWIN Smart Contracts

<table><thead><tr><th width="237">Name</th><th>Address</th></tr></thead><tbody><tr><td>xWIN Swap</td><td>0x800B4980BCd3218761F43aC2098Fc82a9670406a</td></tr><tr><td>xWIN PriceMaster</td><td>0x8a3c24716447992C85a86231606759931f83c667</td></tr><tr><td>xWIN EventEmitter</td><td>0x87b34058a5D38Bf6Cabd0A1AC497183A1f7b8e5a</td></tr><tr><td>xWIN FundV2Factory</td><td>0x6cC1CaD8b330731e6FF469EaEBf19961ea1DFc03</td></tr></tbody></table>

### xWIN Strategies Smart Contracts

<table><thead><tr><th width="141">Symbol</th><th width="257">Name</th><th>Address</th></tr></thead><tbody><tr><td>xDCA.btc</td><td>(BTC) Dollar Cost Average</td><td>0x5834542ee7B6FE644Cd568E3ad48A5B0D58EC8ba</td></tr><tr><td>xSCA.btc</td><td>(BTC) Stable USDC Alpha</td><td>0xa3960cB557872D5F68ef06dc63a14b7E6b64d552</td></tr><tr><td>xDCA.gmx</td><td>(GMX) Dollar Cost Average</td><td>0x9cCD1D6c0992c57d064745B8261CC7d5FBad8c80</td></tr><tr><td>xSCA.gmx</td><td>(GMX) Stable Coin Alpha</td><td>0x4c4CBc2Aa5C477747B32530d2eDD83254f61fa71</td></tr><tr><td>xUSDT-A</td><td>USDT Staking</td><td>0x1602D4ecF7f2cA9F7159E27d6149c90F39B4d763</td></tr><tr><td>xUSDC-A</td><td>USDC.e AAVE</td><td>0x8a0Fa3B0010c76099E935E2C8909d5441390fF62</td></tr><tr><td>xDAI-A</td><td>DAI AAVE</td><td>0x093d0496303dE127806aeFd8050eBb3eA44125d5</td></tr><tr><td>xWBTC-A</td><td>WBTC AAVE</td><td>0x69fA363DBB41f64E491BB6f3DedEc8F6cC93b0F0</td></tr><tr><td>xLink-A</td><td>LINK AAVE</td><td>0xc41F7E081d99010Be7Ad4F085d6CF10C772f688E</td></tr><tr><td>xWETH-A</td><td>WETH AAVE</td><td>0x6ae47584953eE351Db0c089eCE8e69429dAeBDA6</td></tr></tbody></table>

### xWIN Public Allocation Vaults Smart Contracts

<table><thead><tr><th width="132">Symbol</th><th width="204">Name</th><th>Address</th></tr></thead><tbody><tr><td>fMIV.e</td><td>Arb Major Index</td><td>0x5b0D58149CbD7f041a8833f8EfE4b2DdADAc47D2</td></tr><tr><td>fEMG.e</td><td>Emerging Index</td><td>0xc9F5559fAf40c515932A2A18aE1d676af83A0221</td></tr><tr><td>fBTCETH.e</td><td>BTC-ETH-50-50</td><td>0x03d6Fe36281Cb82ddB52E7e5Aff190aBCC9A6988</td></tr><tr><td>fZanmai.e</td><td>Dollar Zanmai Staking</td><td>0xEd83FDfaae296674d13672a629A8740724eEeeD7</td></tr></tbody></table>


# Polygon

### xWIN Smart Contracts

<table><thead><tr><th width="237">Name</th><th>Address</th></tr></thead><tbody><tr><td>xWIN Swap</td><td>0x5493881D5FC68bE3519CB25F2a4717d192800707</td></tr><tr><td>xWIN PriceMaster</td><td>0x4259ED91681159E455629a35d81c0b0020e3FeeD</td></tr><tr><td>xWIN EventEmitter</td><td>0x3f2bef656821faC3a969D6a1f831E5F3ce25c062</td></tr><tr><td>xWIN FundV2Factory</td><td>0x9eBc52D849F961b43289d6da55663F3b9f628a68</td></tr></tbody></table>

### xWIN Strategies Smart Contracts

<table><thead><tr><th width="158">Symbol</th><th width="252">Name</th><th>Address</th></tr></thead><tbody><tr><td>xPIV</td><td>Polygon Major Index</td><td>0xC1c53b4A16b834599B1F6acfd869765B08d422ac</td></tr><tr><td>xBTCETH</td><td>BTC-ETH-50-50 Index</td><td>0x75DaB5000AF15e7a9dd9C2365Ae69e394c252A5a</td></tr><tr><td>xDollar</td><td>Dollar Zanmai Polygon</td><td>0xB4319e7dFBb84C8160846359EbA6d3b9b9440f69</td></tr><tr><td>xDCA</td><td>(BTC) Dollar Cost Average</td><td>0x99c04716ec9285d4057765022183E2e05D51a2C6</td></tr><tr><td>xDCA.matic</td><td>(MATIC) Dollar Cost Average</td><td>0x53b533C7Fa420E48C97Aa78ccADbde976AA86dA8</td></tr><tr><td>xSCA</td><td>(BTC) Stable Coin Alpha</td><td>0xb26698F9764833BE909D04Aed7Bb6832117288e3</td></tr><tr><td>xUSDC-A</td><td>USDC Staking AAVE</td><td>0x1DB49D9871a61101275EA72D9b9498948434AF2C</td></tr><tr><td>xUSDT-A</td><td>USDT Staking AAVE</td><td>0xC78d44eA63B0ABeAAE91FDED93a4b0B841509cd5</td></tr><tr><td>xDAI-A</td><td>DAI Staking AAVE</td><td>0xB9F7c086AbC55Bdc936C36EDB21c5B5eFB4b31f1</td></tr><tr><td>xBTC-A</td><td>BTC Staking AAVE</td><td>0x982407d122ae37E7a38f7CCE83595e74F7E85156</td></tr><tr><td>xETH-A</td><td>ETH-Staking AAVE</td><td>0x21a738Bd4058498b9245BF8FcC9f15fB46699526</td></tr><tr><td>xBAL-A</td><td>BAL Staking AAVE</td><td>0x98e487aC80d2a80e7c980D028F330F2cd4b5282A</td></tr></tbody></table>


# xWin Token Smart Contracts (BSC)


# xWin Token Smart Contracts

<figure><img src="https://466113786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTG45H8vI4SWqrd6h2tHn%2Fuploads%2FraBtSDDSGhgkEpjrnm06%2FxWin%20Token%20Smart%20Contract%20(2).png?alt=media&amp;token=560e46b2-3f09-4370-bb43-be1eb0639517" alt=""><figcaption></figcaption></figure>

xWin Token is a BEP-20 token that can be used staked into xWinMasterChef. Previously, the xWin Token was used to allow users to create private vaults through the fundFactory. However, that has now been removed and we are looking into the future utilization of xWin Tokens. The xWinMasterChef consists of many different LP pools that users can stake. Each LP pool has its own APY percentage that users can earn. These LP pools are created by xWin Finance as well as other providers like ApeSwap.


# Deployed Address

<table><thead><tr><th width="209">Name</th><th width="497">Address</th></tr></thead><tbody><tr><td>xWin Token</td><td>0xd88ca08d8eec1E9E09562213Ae83A7853ebB5d28</td></tr><tr><td>xWin Buddy Chef</td><td>0x4B87a60fC5a94e5ac886867977e29c9711C2E903</td></tr><tr><td>xWin Master Chef</td><td>0xD09774e3d5Dc02fa969896c53D3Cbb5bC8900A60</td></tr><tr><td>xWin Auto Locked Staking</td><td>0xa4AE0DCC89Af9855946C0b2ad4A10FF27125a9Fc</td></tr></tbody></table>


# xWin Defi (Helper)

### Context

#### constructor

```solidity
constructor() internal
```

#### \_msgSender

```solidity
function _msgSender() internal view returns (address payable)
```

#### \_msgData

```solidity
function _msgData() internal view returns (bytes)
```

### Ownable

\_Contract module which provides a basic access control mechanism, where there is an account (an owner) that can be granted exclusive access to specific functions.

By default, the owner account will be the one that deploys the contract. This can later be changed with {transferOwnership}.

This module is used through inheritance. It will make available the modifier `onlyOwner`, which can be applied to your functions to restrict their use to the owner.\_

#### OwnershipTransferred

```solidity
event OwnershipTransferred(address previousOwner, address newOwner)
```

#### constructor

```solidity
constructor() internal
```

*Initializes the contract setting the deployer as the initial owner.*

#### owner

```solidity
function owner() public view returns (address)
```

*Returns the address of the current owner.*

#### onlyOwner

```solidity
modifier onlyOwner()
```

*Throws if called by any account other than the owner.*

#### renounceOwnership

```solidity
function renounceOwnership() public
```

\_Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner.

NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.\_

#### transferOwnership

```solidity
function transferOwnership(address newOwner) public
```

*Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.*

#### \_transferOwnership

```solidity
function _transferOwnership(address newOwner) internal
```

*Transfers ownership of the contract to a new account (`newOwner`).*

### ReentrancyGuard

\_Contract module that helps prevent reentrant calls to a function.

Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier available, which can be applied to functions to make sure there are no nested (reentrant) calls to them.

Note that because there is a single `nonReentrant` guard, functions marked as `nonReentrant` may not call one another. This can be worked around by making those functions `private`, and then adding `external` `nonReentrant` entry points to them.

TIP: If you would like to learn more about reentrancy and alternative ways to protect against it, check out our blog post <https://blog.openzeppelin.com/reentrancy-after-istanbul/\\[Reentrancy> After Istanbul].\_

#### constructor

```solidity
constructor() internal
```

#### nonReentrant

```solidity
modifier nonReentrant()
```

*Prevents a contract from calling itself, directly or indirectly. Calling a `nonReentrant` function from another `nonReentrant` function is not supported. It is possible to prevent this from happening by making the `nonReentrant` function external, and make it call a `private` function that does the actual work.*

### SafeMath

\_Wrappers over Solidity's arithmetic operations with added overflow checks.

Arithmetic operations in Solidity wrap on overflow. This can easily result in bugs, because programmers usually assume that an overflow raises an error, which is the standard behavior in high level programming languages. `SafeMath` restores this intuition by reverting the transaction when an operation overflows.

Using this library instead of the unchecked operations eliminates an entire class of bugs, so it's recommended to use it always.\_

#### add

```solidity
function add(uint256 a, uint256 b) internal pure returns (uint256)
```

\_Returns the addition of two unsigned integers, reverting on overflow.

Counterpart to Solidity's `+` operator.

Requirements:

* Addition cannot overflow.\_

#### sub

```solidity
function sub(uint256 a, uint256 b) internal pure returns (uint256)
```

\_Returns the subtraction of two unsigned integers, reverting on overflow (when the result is negative).

Counterpart to Solidity's `-` operator.

Requirements:

* Subtraction cannot overflow.\_

#### sub

```solidity
function sub(uint256 a, uint256 b, string errorMessage) internal pure returns (uint256)
```

\_Returns the subtraction of two unsigned integers, reverting with custom message on overflow (when the result is negative).

Counterpart to Solidity's `-` operator.

Requirements:

* Subtraction cannot overflow.\_

#### mul

```solidity
function mul(uint256 a, uint256 b) internal pure returns (uint256)
```

\_Returns the multiplication of two unsigned integers, reverting on overflow.

Counterpart to Solidity's `*` operator.

Requirements:

* Multiplication cannot overflow.\_

#### div

```solidity
function div(uint256 a, uint256 b) internal pure returns (uint256)
```

\_Returns the integer division of two unsigned integers. Reverts on division by zero. The result is rounded towards zero.

Counterpart to Solidity's `/` operator. Note: this function uses a `revert` opcode (which leaves remaining gas untouched) while Solidity uses an invalid opcode to revert (consuming all remaining gas).

Requirements:

* The divisor cannot be zero.\_

#### div

```solidity
function div(uint256 a, uint256 b, string errorMessage) internal pure returns (uint256)
```

\_Returns the integer division of two unsigned integers. Reverts with custom message on division by zero. The result is rounded towards zero.

Counterpart to Solidity's `/` operator. Note: this function uses a `revert` opcode (which leaves remaining gas untouched) while Solidity uses an invalid opcode to revert (consuming all remaining gas).

Requirements:

* The divisor cannot be zero.\_

#### mod

```solidity
function mod(uint256 a, uint256 b) internal pure returns (uint256)
```

\_Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), Reverts when dividing by zero.

Counterpart to Solidity's `%` operator. This function uses a `revert` opcode (which leaves remaining gas untouched) while Solidity uses an invalid opcode to revert (consuming all remaining gas).

Requirements:

* The divisor cannot be zero.\_

#### mod

```solidity
function mod(uint256 a, uint256 b, string errorMessage) internal pure returns (uint256)
```

\_Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), Reverts with custom message when dividing by zero.

Counterpart to Solidity's `%` operator. This function uses a `revert` opcode (which leaves remaining gas untouched) while Solidity uses an invalid opcode to revert (consuming all remaining gas).

Requirements:

* The divisor cannot be zero.\_

#### min

```solidity
function min(uint256 x, uint256 y) internal pure returns (uint256 z)
```

#### sqrt

```solidity
function sqrt(uint256 y) internal pure returns (uint256 z)
```

### Address

*Collection of functions related to the address type*

#### isContract

```solidity
function isContract(address account) internal view returns (bool)
```

\_Returns true if `account` is a contract.

## \[IMPORTANT]

It is unsafe to assume that an address for which this function returns false is an externally-owned account (EOA) and not a contract.

Among others, `isContract` will return false for the following types of addresses:

* an externally-owned account
* a contract in construction
* an address where a contract will be created
* an address where a contract lived, but was destroyed ====\_

#### sendValue

```solidity
function sendValue(address payable recipient, uint256 amount) internal
```

\_Replacement for Solidity's `transfer`: sends `amount` wei to `recipient`, forwarding all available gas and reverting on errors.

<https://eips.ethereum.org/EIPS/eip-1884\\[EIP1884>] increases the gas cost of certain opcodes, possibly making contracts go over the 2300 gas limit imposed by `transfer`, making them unable to receive funds via `transfer`. {sendValue} removes this limitation.

<https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/\\[Learn> more].

IMPORTANT: because control is transferred to `recipient`, care must be taken to not create reentrancy vulnerabilities. Consider using {ReentrancyGuard} or the <https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern\\[checks-effects-interactions> pattern].\_

#### functionCall

```solidity
function functionCall(address target, bytes data) internal returns (bytes)
```

\_Performs a Solidity function call using a low level `call`. A plain`call` is an unsafe replacement for a function call: use this function instead.

If `target` reverts with a revert reason, it is bubbled up by this function (like regular Solidity function calls).

Returns the raw returned data. To convert to the expected return value, use <https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions\\[`abi.decode`>].

Requirements:

* `target` must be a contract.
* calling `target` with `data` must not revert.

*Available since v3.1.*\_

#### functionCall

```solidity
function functionCall(address target, bytes data, string errorMessage) internal returns (bytes)
```

\_Same as {xref-Address-functionCall-address-bytes-}\[`functionCall`], but with `errorMessage` as a fallback revert reason when `target` reverts.

*Available since v3.1.*\_

#### functionCallWithValue

```solidity
function functionCallWithValue(address target, bytes data, uint256 value) internal returns (bytes)
```

\_Same as {xref-Address-functionCall-address-bytes-}\[`functionCall`], but also transferring `value` wei to `target`.

Requirements:

* the calling contract must have an ETH balance of at least `value`.
* the called Solidity function must be `payable`.

*Available since v3.1.*\_

#### functionCallWithValue

```solidity
function functionCallWithValue(address target, bytes data, uint256 value, string errorMessage) internal returns (bytes)
```

\_Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}\[`functionCallWithValue`], but with `errorMessage` as a fallback revert reason when `target` reverts.

*Available since v3.1.*\_

### IBEP20

#### totalSupply

```solidity
function totalSupply() external view returns (uint256)
```

*Returns the amount of tokens in existence.*

#### decimals

```solidity
function decimals() external view returns (uint8)
```

*Returns the token decimals.*

#### symbol

```solidity
function symbol() external view returns (string)
```

*Returns the token symbol.*

#### name

```solidity
function name() external view returns (string)
```

*Returns the token name.*

#### getOwner

```solidity
function getOwner() external view returns (address)
```

*Returns the bep token owner.*

#### balanceOf

```solidity
function balanceOf(address account) external view returns (uint256)
```

*Returns the amount of tokens owned by `account`.*

#### transfer

```solidity
function transfer(address recipient, uint256 amount) external returns (bool)
```

\_Moves `amount` tokens from the caller's account to `recipient`.

Returns a boolean value indicating whether the operation succeeded.

Emits a {Transfer} event.\_

#### allowance

```solidity
function allowance(address _owner, address spender) external view returns (uint256)
```

\_Returns the remaining number of tokens that `spender` will be allowed to spend on behalf of `owner` through {transferFrom}. This is zero by default.

This value changes when {approve} or {transferFrom} are called.\_

#### approve

```solidity
function approve(address spender, uint256 amount) external returns (bool)
```

\_Sets `amount` as the allowance of `spender` over the caller's tokens.

Returns a boolean value indicating whether the operation succeeded.

IMPORTANT: Beware that changing an allowance with this method brings the risk that someone may use both the old and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: <https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729>

Emits an {Approval} event.\_

#### transferFrom

```solidity
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool)
```

\_Moves `amount` tokens from `sender` to `recipient` using the allowance mechanism. `amount` is then deducted from the caller's allowance.

Returns a boolean value indicating whether the operation succeeded.

Emits a {Transfer} event.\_

#### Transfer

```solidity
event Transfer(address from, address to, uint256 value)
```

\_Emitted when `value` tokens are moved from one account (`from`) to another (`to`).

Note that `value` may be zero.\_

#### Approval

```solidity
event Approval(address owner, address spender, uint256 value)
```

*Emitted when the allowance of a `spender` for an `owner` is set by a call to {approve}. `value` is the new allowance.*

### SafeBEP20

*Wrappers around BEP20 operations that throw on failure (when the token contract returns false). Tokens that return no value (and instead revert or throw on failure) are also supported, non-reverting calls are assumed to be successful. To use this library you can add a `using SafeBEP20 for IBEP20;` statement to your contract, which allows you to call the safe operations as `token.safeTransfer(...)`, etc.*

#### safeTransfer

```solidity
function safeTransfer(contract IBEP20 token, address to, uint256 value) internal
```

#### safeTransferFrom

```solidity
function safeTransferFrom(contract IBEP20 token, address from, address to, uint256 value) internal
```

#### safeApprove

```solidity
function safeApprove(contract IBEP20 token, address spender, uint256 value) internal
```

\_Deprecated. This function has issues similar to the ones found in {IBEP20-approve}, and its usage is discouraged.

Whenever possible, use {safeIncreaseAllowance} and {safeDecreaseAllowance} instead.\_

#### safeIncreaseAllowance

```solidity
function safeIncreaseAllowance(contract IBEP20 token, address spender, uint256 value) internal
```

#### safeDecreaseAllowance

```solidity
function safeDecreaseAllowance(contract IBEP20 token, address spender, uint256 value) internal
```

### xWinLib

#### PoolInfo

```solidity
struct PoolInfo {
  address lpToken;
  uint256 rewardperblock;
  uint256 multiplier;
}
```

#### UserInfo

```solidity
struct UserInfo {
  uint256 amount;
  uint256 blockstart;
}
```

#### TradeParams

```solidity
struct TradeParams {
  address xFundAddress;
  uint256 amount;
  uint256 priceImpactTolerance;
  uint256 deadline;
  bool returnInBase;
  address referral;
}
```

#### transferData

```solidity
struct transferData {
  address[] targetNamesAddress;
  uint256 totalTrfAmt;
  uint256 totalUnderlying;
  uint256 qtyToTrfAToken;
}
```

#### xWinReward

```solidity
struct xWinReward {
  uint256 blockstart;
  uint256 accBasetoken;
  uint256 accMinttoken;
  uint256 previousRealizedQty;
}
```

#### xWinReferral

```solidity
struct xWinReferral {
  address referral;
}
```

#### UnderWeightData

```solidity
struct UnderWeightData {
  uint256 activeWeight;
  uint256 fundWeight;
  bool overweight;
  address token;
}
```

#### DeletedNames

```solidity
struct DeletedNames {
  address token;
  uint256 targetWeight;
}
```

#### PancakePriceToken

```solidity
struct PancakePriceToken {
  string tokenname;
  address addressToken;
}
```

### TransferHelper

#### safeApprove

```solidity
function safeApprove(address token, address to, uint256 value) internal
```

#### safeTransfer

```solidity
function safeTransfer(address token, address to, uint256 value) internal
```

#### safeTransferFrom

```solidity
function safeTransferFrom(address token, address from, address to, uint256 value) internal
```

#### safeTransferBNB

```solidity
function safeTransferBNB(address to, uint256 value) internal
```

### xWinFund

#### getManagerFee

```solidity
function getManagerFee() external view returns (uint256)
```

#### getTargetWeight

```solidity
function getTargetWeight(address addr) external view returns (uint256)
```

#### getWhoIsManager

```solidity
function getWhoIsManager() external view returns (address mangerAddress)
```

#### getBalance

```solidity
function getBalance(address fromAdd) external view returns (uint256 balance)
```

#### getFundValues

```solidity
function getFundValues() external view returns (uint256)
```

#### getTargetWeightQty

```solidity
function getTargetWeightQty(address targetAdd, uint256 srcQty) external view returns (uint256)
```

#### updateManager

```solidity
function updateManager(address managerAdd) external payable
```

#### updateManagerFee

```solidity
function updateManagerFee(uint256 newFeebps) external payable
```

#### updateRebalancePeriod

```solidity
function updateRebalancePeriod(uint256 newCycle) external payable
```

#### updateProtocol

```solidity
function updateProtocol(address _newProtocol) external
```

#### Redeem

```solidity
function Redeem(struct xWinLib.TradeParams _tradeParams, address _investorAddress) external payable returns (uint256)
```

#### Rebalance

```solidity
function Rebalance(address[] _toAddresses, uint256[] _targetWeight, uint256 deadline, uint256 priceImpactTolerance) external payable returns (uint256 baseccyBal)
```

#### Subscribe

```solidity
function Subscribe(struct xWinLib.TradeParams _tradeParams, address _investorAddress) external payable returns (uint256)
```

#### MoveNonIndexNameToBase

```solidity
function MoveNonIndexNameToBase(address _tokenaddress, uint256 deadline, uint256 priceImpactTolerance) external returns (uint256 balanceToken, uint256 swapOutput)
```

#### CreateTargetNames

```solidity
function CreateTargetNames(address[] _toAddresses, uint256[] _targetWeight) external payable
```

#### emergencyRedeem

```solidity
function emergencyRedeem(uint256 redeemUnit, address _investorAddress) external payable
```

#### emergencyRemoveFromFarm

```solidity
function emergencyRemoveFromFarm() external
```

#### getUnitPrice

```solidity
function getUnitPrice() external view returns (uint256 unitprice)
```

#### getUnitPriceInUSD

```solidity
function getUnitPriceInUSD() external view returns (uint256 unitprice)
```

#### getTargetNamesAddress

```solidity
function getTargetNamesAddress() external view returns (address[] _targetNamesAddress)
```

### xWinStake

#### StakeReward

```solidity
function StakeReward(address payable _investorAddress, uint256 rewardQty, uint256 bnbQty, uint256 deadline) external payable
```

#### GetQuotes

```solidity
function GetQuotes(uint256 rewardQty, uint256 baseQty, address targetToken) external view returns (uint256 amountB, uint256 amountA, uint256 amountOut)
```

### xWinDefiProtocol

#### name

```solidity
string name
```

#### xWinToken

```solidity
address xWinToken
```

#### xwinBenefitPool

```solidity
address xwinBenefitPool
```

#### startblock

```solidity
uint256 startblock
```

#### emergencyOn

```solidity
bool emergencyOn
```

#### userInfo

```solidity
mapping(uint256 => mapping(address => struct xWinLib.UserInfo)) userInfo
```

#### isxwinFund

```solidity
mapping(address => bool) isxwinFund
```

#### poolInfo

```solidity
struct xWinLib.PoolInfo[] poolInfo
```

#### xWinRewards

```solidity
mapping(address => struct xWinLib.xWinReward) xWinRewards
```

#### xWinReferral

```solidity
mapping(address => struct xWinLib.xWinReferral) xWinReferral
```

#### rewardRemaining

```solidity
uint256 rewardRemaining
```

#### Received

```solidity
event Received(address, uint256)
```

#### \_MoveNonIndexNameToBaseEvent

```solidity
event _MoveNonIndexNameToBaseEvent(address from, address toFund, address tokenAddress, uint256 amount, uint256 swapOutput)
```

#### \_RebalanceAllInOne

```solidity
event _RebalanceAllInOne(address from, address toFund, uint256 baseBalance, uint256 txnTime)
```

#### \_Subscribe

```solidity
event _Subscribe(address from, address toFund, uint256 subsAmt, uint256 mintQty)
```

#### \_Redeem

```solidity
event _Redeem(address from, address toFund, uint256 redeemUnit, uint256 rewardQty, uint256 redeemratio)
```

#### \_CreateTarget

```solidity
event _CreateTarget(address from, address toFund, address[] newTargets, uint256[] newWeight, uint256 txnTime)
```

#### \_StakeMyReward

```solidity
event _StakeMyReward(address from, uint256 rewardQty)
```

#### \_WithdrawReward

```solidity
event _WithdrawReward(address from, uint256 rewardQty)
```

#### \_DepositFarm

```solidity
event _DepositFarm(address from, uint256 pid, uint256 amount)
```

#### \_WithdrawFarm

```solidity
event _WithdrawFarm(address from, uint256 pid, uint256 amount)
```

#### \_EmergencyRedeem

```solidity
event _EmergencyRedeem(address user, address fundaddress, uint256 amount)
```

#### onlyEmergency

```solidity
modifier onlyEmergency()
```

#### onlyNonEmergency

```solidity
modifier onlyNonEmergency()
```

#### constructor

```solidity
constructor(uint256 _platformFeeBps, address _platformWallet, address _xwinBenefitPool, address _stakeAddress, address _xWinToken) public
```

#### receive

```solidity
receive() external payable
```

#### addxwinFund

```solidity
function addxwinFund(address[] _fundaddress, bool[] _isxwinFund) public
```

#### poolLength

```solidity
function poolLength() external view returns (uint256)
```

#### add

```solidity
function add(address _lpToken, uint256 _rewardperblock, uint256 _multiplier) public
```

#### emergencyWithdraw

```solidity
function emergencyWithdraw(uint256 _pid) public
```

#### updateRewardPerBlock

```solidity
function updateRewardPerBlock(uint256 _rewardperblock) external
```

*reward per block by deployer*

#### updateEmergencyState

```solidity
function updateEmergencyState(bool _state) external
```

*turn on emerrgency state by deployer*

#### updateProtocol

```solidity
function updateProtocol(address _fundaddress, address _newProtocol) external
```

*update xwin defi protocol*

#### updateFarmPoolInfo

```solidity
function updateFarmPoolInfo(uint256 _pid, uint256 _rewardperblock, uint256 _multiplier) external
```

*create or update farm pool fee by deployer*

#### getAllPendingXwin

```solidity
function getAllPendingXwin(address _user) public view returns (uint256)
```

*View function to see all pending xWin token earn on frontend.*

#### pendingXwin

```solidity
function pendingXwin(uint256 _pid, address _user) public view returns (uint256)
```

*View function to see pending xWin on frontend.*

#### DepositFarm

```solidity
function DepositFarm(uint256 _pid, uint256 _amount) public
```

*Deposit LP tokens to xWin Protocol for xWin allocation.*

#### WithdrawFarm

```solidity
function WithdrawFarm(uint256 _pid, uint256 _amount) public
```

*Withdraw LP tokens from xWin Protocol.*

#### Subscribe

```solidity
function Subscribe(struct xWinLib.TradeParams _tradeParams) public payable
```

*perform subscription based on ratio setup and put into lending if available*

#### Redeem

```solidity
function Redeem(struct xWinLib.TradeParams _tradeParams) external payable
```

*perform redemption based on unit redeem*

#### emergencyRedeem

```solidity
function emergencyRedeem(uint256 _redeemAmount, address _fundaddress) external payable
```

*perform redemption based on unit redeem and give up all xwin rewards*

#### emergencyRemoveFromFarm

```solidity
function emergencyRemoveFromFarm(address _fundaddress) external payable
```

*manager perform remove from farm for emergency state*

#### MoveNonIndexNameToBase

```solidity
function MoveNonIndexNameToBase(address xFundAddress, address _tokenaddress, uint256 deadline, uint256 priceImpactTolerance) external payable
```

*perform MoveNonIndexNameTo BNB for non benchmark name*

#### CreateTarget

```solidity
function CreateTarget(address[] _toAddresses, uint256[] _targetWeight, address xFundAddress) external
```

*create target ratio by portfolio manager*

#### RebalanceAllInOne

```solidity
function RebalanceAllInOne(struct xWinLib.TradeParams _tradeParams, address[] _toAddresses, uint256[] _targetWeight) external payable
```

*perform update target, move non-bm to base and finally rebalance*

#### updatePlatformFee

```solidity
function updatePlatformFee(uint256 newPlatformFee) external
```

*update platform fee by deployer*

#### getPlatformFee

```solidity
function getPlatformFee() external view returns (uint256)
```

*get platform fee*

#### getPlatformAddress

```solidity
function getPlatformAddress() external view returns (address)
```

*get platform wallet address*

#### gexWinBenefitPool

```solidity
function gexWinBenefitPool() external view returns (address)
```

*get platform wallet address*

#### updateXwinBenefitPool

```solidity
function updateXwinBenefitPool(address _xwinBenefitPool) external
```

*update platform fee by deployer*

#### updateRewardRemaining

```solidity
function updateRewardRemaining(uint256 _newRemaining) external
```

*update rewardRemaining by deployer*

#### updateStakeProtocol

```solidity
function updateStakeProtocol(address newStakeProtocol) external
```

*update platform fee by deployer*

#### updateReferralRewardPerUnit

```solidity
function updateReferralRewardPerUnit(uint256 _referralperunit) external
```

*update referal fee by deployer*

#### updateManagerRewardPerUnit

```solidity
function updateManagerRewardPerUnit(uint256 _managerRewardperunit) external
```

*update manager reward by deployer*

#### \_multiplier

```solidity
function _multiplier(uint256 _blockstart) internal view returns (uint256)
```

#### GetEstimateReward

```solidity
function GetEstimateReward(address fromAddress) public view returns (uint256)
```

*get estimated reward of XWN token*

#### GetQuotes

```solidity
function GetQuotes(uint256 tokenBal, address targetToken) external view returns (uint256 amountB, uint256 amountA)
```

#### StakeMyReward

```solidity
function StakeMyReward(uint256 deadline) external payable
```

*User to claim the reward and stake them into DEX*

#### \_updateReferralReward

```solidity
function _updateReferralReward(struct xWinLib.TradeParams _tradeParams, address _managerAddress) internal
```

#### WithdrawReward

```solidity
function WithdrawReward() external payable
```

*withdraw reward of XWN token*

#### \_storeRewardQty

```solidity
function _storeRewardQty(address from, uint256 baseQty, uint256 mintQty) internal
```

#### \_updateRewardBal

```solidity
function _updateRewardBal(address from, uint256 redeemUnit) internal returns (uint256 rewardQty)
```

#### ProtocolTransfer

```solidity
function ProtocolTransfer(address _newProtocol, uint256 amount) public payable
```

*emergency trf XWN token to new protocol*

#### \_sendRewards

```solidity
function _sendRewards(address _to, uint256 amount) internal
```

#### \_resetRewards

```solidity
function _resetRewards(address _from) internal
```


# xWin Token

### SafeMath

#### add

```solidity
function add(uint256 a, uint256 b) internal pure returns (uint256)
```

\_Returns the addition of two unsigned integers, reverting on overflow.

Counterpart to Solidity's `+` operator.

Requirements:

* Addition cannot overflow.\_

#### sub

```solidity
function sub(uint256 a, uint256 b) internal pure returns (uint256)
```

\_Returns the subtraction of two unsigned integers, reverting on overflow (when the result is negative).

Counterpart to Solidity's `-` operator.

Requirements:

* Subtraction cannot overflow.\_

#### sub

```solidity
function sub(uint256 a, uint256 b, string errorMessage) internal pure returns (uint256)
```

\_Returns the subtraction of two unsigned integers, reverting with custom message on overflow (when the result is negative).

Counterpart to Solidity's `-` operator.

Requirements:

* Subtraction cannot overflow.\_

#### mul

```solidity
function mul(uint256 a, uint256 b) internal pure returns (uint256)
```

\_Returns the multiplication of two unsigned integers, reverting on overflow.

Counterpart to Solidity's `*` operator.

Requirements:

* Multiplication cannot overflow.\_

#### div

```solidity
function div(uint256 a, uint256 b) internal pure returns (uint256)
```

\_Returns the integer division of two unsigned integers. Reverts on division by zero. The result is rounded towards zero.

Counterpart to Solidity's `/` operator. Note: this function uses a `revert` opcode (which leaves remaining gas untouched) while Solidity uses an invalid opcode to revert (consuming all remaining gas).

Requirements:

* The divisor cannot be zero.\_

#### div

```solidity
function div(uint256 a, uint256 b, string errorMessage) internal pure returns (uint256)
```

\_Returns the integer division of two unsigned integers. Reverts with custom message on division by zero. The result is rounded towards zero.

Counterpart to Solidity's `/` operator. Note: this function uses a `revert` opcode (which leaves remaining gas untouched) while Solidity uses an invalid opcode to revert (consuming all remaining gas).

Requirements:

* The divisor cannot be zero.\_

#### mod

```solidity
function mod(uint256 a, uint256 b) internal pure returns (uint256)
```

\_Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), Reverts when dividing by zero.

Counterpart to Solidity's `%` operator. This function uses a `revert` opcode (which leaves remaining gas untouched) while Solidity uses an invalid opcode to revert (consuming all remaining gas).

Requirements:

* The divisor cannot be zero.\_

#### mod

```solidity
function mod(uint256 a, uint256 b, string errorMessage) internal pure returns (uint256)
```

\_Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), Reverts with custom message when dividing by zero.

Counterpart to Solidity's `%` operator. This function uses a `revert` opcode (which leaves remaining gas untouched) while Solidity uses an invalid opcode to revert (consuming all remaining gas).

Requirements:

* The divisor cannot be zero.\_

#### min

```solidity
function min(uint256 x, uint256 y) internal pure returns (uint256 z)
```

#### sqrt

```solidity
function sqrt(uint256 y) internal pure returns (uint256 z)
```

### Address

#### isContract

```solidity
function isContract(address account) internal view returns (bool)
```

\_Returns true if `account` is a contract.

## \[IMPORTANT]

It is unsafe to assume that an address for which this function returns false is an externally-owned account (EOA) and not a contract.

Among others, `isContract` will return false for the following types of addresses:

* an externally-owned account
* a contract in construction
* an address where a contract will be created
* an address where a contract lived, but was destroyed ====\_

#### sendValue

```solidity
function sendValue(address payable recipient, uint256 amount) internal
```

\_Replacement for Solidity's `transfer`: sends `amount` wei to `recipient`, forwarding all available gas and reverting on errors.

<https://eips.ethereum.org/EIPS/eip-1884\\[EIP1884>] increases the gas cost of certain opcodes, possibly making contracts go over the 2300 gas limit imposed by `transfer`, making them unable to receive funds via `transfer`. {sendValue} removes this limitation.

<https://diligence.consensys.net/posts/2019/09/stop-using-soliditys-transfer-now/\\[Learn> more].

IMPORTANT: because control is transferred to `recipient`, care must be taken to not create reentrancy vulnerabilities. Consider using {ReentrancyGuard} or the <https://solidity.readthedocs.io/en/v0.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern\\[checks-effects-interactions> pattern].\_

#### functionCall

```solidity
function functionCall(address target, bytes data) internal returns (bytes)
```

\_Performs a Solidity function call using a low level `call`. A plain`call` is an unsafe replacement for a function call: use this function instead.

If `target` reverts with a revert reason, it is bubbled up by this function (like regular Solidity function calls).

Returns the raw returned data. To convert to the expected return value, use <https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions\\[`abi.decode`>].

Requirements:

* `target` must be a contract.
* calling `target` with `data` must not revert.

*Available since v3.1.*\_

#### functionCall

```solidity
function functionCall(address target, bytes data, string errorMessage) internal returns (bytes)
```

\_Same as {xref-Address-functionCall-address-bytes-}\[`functionCall`], but with `errorMessage` as a fallback revert reason when `target` reverts.

*Available since v3.1.*\_

#### functionCallWithValue

```solidity
function functionCallWithValue(address target, bytes data, uint256 value) internal returns (bytes)
```

\_Same as {xref-Address-functionCall-address-bytes-}\[`functionCall`], but also transferring `value` wei to `target`.

Requirements:

* the calling contract must have an ETH balance of at least `value`.
* the called Solidity function must be `payable`.

*Available since v3.1.*\_

#### functionCallWithValue

```solidity
function functionCallWithValue(address target, bytes data, uint256 value, string errorMessage) internal returns (bytes)
```

\_Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}\[`functionCallWithValue`], but with `errorMessage` as a fallback revert reason when `target` reverts.

*Available since v3.1.*\_

### EnumerableSet

\_Library for managing <https://en.wikipedia.org/wiki/Set_(abstract\\_data\\_type)\\[sets>] of primitive types.

Sets have the following properties:

* Elements are added, removed, and checked for existence in constant time (O(1)).
* Elements are enumerated in O(n). No guarantees are made on the ordering.

```
contract Example {
    // Add the library methods
    using EnumerableSet for EnumerableSet.AddressSet;

    // Declare a set state variable
    EnumerableSet.AddressSet private mySet;
}
```

As of v3.0.0, only sets of type `address` (`AddressSet`) and `uint256` (`UintSet`) are supported.\_

#### Set

```solidity
struct Set {
  bytes32[] _values;
  mapping(bytes32 => uint256) _indexes;
}
```

#### AddressSet

```solidity
struct AddressSet {
  struct EnumerableSet.Set _inner;
}
```

#### add

```solidity
function add(struct EnumerableSet.AddressSet set, address value) internal returns (bool)
```

\_Add a value to a set. O(1).

Returns true if the value was added to the set, that is if it was not already present.\_

#### remove

```solidity
function remove(struct EnumerableSet.AddressSet set, address value) internal returns (bool)
```

\_Removes a value from a set. O(1).

Returns true if the value was removed from the set, that is if it was present.\_

#### contains

```solidity
function contains(struct EnumerableSet.AddressSet set, address value) internal view returns (bool)
```

*Returns true if the value is in the set. O(1).*

#### length

```solidity
function length(struct EnumerableSet.AddressSet set) internal view returns (uint256)
```

*Returns the number of values in the set. O(1).*

#### at

```solidity
function at(struct EnumerableSet.AddressSet set, uint256 index) internal view returns (address)
```

\_Returns the value stored at position `index` in the set. O(1).

Note that there are no guarantees on the ordering of values inside the array, and it may change when more values are added or removed.

Requirements:

* `index` must be strictly less than {length}.\_

#### UintSet

```solidity
struct UintSet {
  struct EnumerableSet.Set _inner;
}
```

#### add

```solidity
function add(struct EnumerableSet.UintSet set, uint256 value) internal returns (bool)
```

\_Add a value to a set. O(1).

Returns true if the value was added to the set, that is if it was not already present.\_

#### remove

```solidity
function remove(struct EnumerableSet.UintSet set, uint256 value) internal returns (bool)
```

\_Removes a value from a set. O(1).

Returns true if the value was removed from the set, that is if it was present.\_

#### contains

```solidity
function contains(struct EnumerableSet.UintSet set, uint256 value) internal view returns (bool)
```

*Returns true if the value is in the set. O(1).*

#### length

```solidity
function length(struct EnumerableSet.UintSet set) internal view returns (uint256)
```

*Returns the number of values on the set. O(1).*

#### at

```solidity
function at(struct EnumerableSet.UintSet set, uint256 index) internal view returns (uint256)
```

\_Returns the value stored at position `index` in the set. O(1).

Note that there are no guarantees on the ordering of values inside the array, and it may change when more values are added or removed.

Requirements:

* `index` must be strictly less than {length}.\_

### Context

#### constructor

```solidity
constructor() internal
```

#### \_msgSender

```solidity
function _msgSender() internal view returns (address payable)
```

#### \_msgData

```solidity
function _msgData() internal view returns (bytes)
```

### AccessControl

#### RoleData

```solidity
struct RoleData {
  struct EnumerableSet.AddressSet members;
  bytes32 adminRole;
}
```

#### DEFAULT\_ADMIN\_ROLE

```solidity
bytes32 DEFAULT_ADMIN_ROLE
```

#### RoleAdminChanged

```solidity
event RoleAdminChanged(bytes32 role, bytes32 previousAdminRole, bytes32 newAdminRole)
```

\_Emitted when `newAdminRole` is set as `role`'s admin role, replacing `previousAdminRole`

`DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite {RoleAdminChanged} not being emitted signaling this.

*Available since v3.1.*\_

#### RoleGranted

```solidity
event RoleGranted(bytes32 role, address account, address sender)
```

\_Emitted when `account` is granted `role`.

`sender` is the account that originated the contract call, an admin role bearer except when using {*setupRole}.*

#### RoleRevoked

```solidity
event RoleRevoked(bytes32 role, address account, address sender)
```

\_Emitted when `account` is revoked `role`.

`sender` is the account that originated the contract call:

* if using `revokeRole`, it is the admin role bearer
* if using `renounceRole`, it is the role bearer (i.e. `account`)\_

#### hasRole

```solidity
function hasRole(bytes32 role, address account) public view returns (bool)
```

*Returns `true` if `account` has been granted `role`.*

#### getRoleMemberCount

```solidity
function getRoleMemberCount(bytes32 role) public view returns (uint256)
```

*Returns the number of accounts that have `role`. Can be used together with {getRoleMember} to enumerate all bearers of a role.*

#### getRoleMember

```solidity
function getRoleMember(bytes32 role, uint256 index) public view returns (address)
```

\_Returns one of the accounts that have `role`. `index` must be a value between 0 and {getRoleMemberCount}, non-inclusive.

Role bearers are not sorted in any particular way, and their ordering may change at any point.

WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure you perform all queries on the same block. See the following <https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296\\[forum> post] for more information.\_

#### getRoleAdmin

```solidity
function getRoleAdmin(bytes32 role) public view returns (bytes32)
```

\_Returns the admin role that controls `role`. See {grantRole} and {revokeRole}.

To change a role's admin, use {*setRoleAdmin}.*

#### grantRole

```solidity
function grantRole(bytes32 role, address account) public virtual
```

\_Grants `role` to `account`.

If `account` had not been already granted `role`, emits a {RoleGranted} event.

Requirements:

* the caller must have `role`'s admin role.\_

#### revokeRole

```solidity
function revokeRole(bytes32 role, address account) public virtual
```

\_Revokes `role` from `account`.

If `account` had been granted `role`, emits a {RoleRevoked} event.

Requirements:

* the caller must have `role`'s admin role.\_

#### renounceRole

```solidity
function renounceRole(bytes32 role, address account) public virtual
```

\_Revokes `role` from the calling account.

Roles are often managed via {grantRole} and {revokeRole}: this function's purpose is to provide a mechanism for accounts to lose their privileges if they are compromised (such as when a trusted device is misplaced).

If the calling account had been granted `role`, emits a {RoleRevoked} event.

Requirements:

* the caller must be `account`.\_

#### \_setupRole

```solidity
function _setupRole(bytes32 role, address account) internal virtual
```

\_Grants `role` to `account`.

If `account` had not been already granted `role`, emits a {RoleGranted} event. Note that unlike {grantRole}, this function doesn't perform any checks on the calling account.

## \[WARNING]

This function should only be called from the constructor when setting up the initial roles for the system.

Using this function in any other way is effectively circumventing the admin system imposed by {AccessControl}. ====\_

#### \_setRoleAdmin

```solidity
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual
```

\_Sets `adminRole` as `role`'s admin role.

Emits a {RoleAdminChanged} event.\_

### AdminAccessRoles

#### MINT\_ROLE

```solidity
bytes32 MINT_ROLE
```

#### constructor

```solidity
constructor(address root) public
```

*Add `root` to the admin role as a member.*

#### onlyAdmin

```solidity
modifier onlyAdmin()
```

*Restricted to members of the admin role.*

#### onlyMintUser

```solidity
modifier onlyMintUser()
```

*Restricted to members of the user role.*

#### isAdmin

```solidity
function isAdmin(address account) public view virtual returns (bool)
```

*Return `true` if the account belongs to the admin role.*

#### isMintUser

```solidity
function isMintUser(address account) public view virtual returns (bool)
```

*Return `true` if the account belongs to the user role.*

#### addMintUser

```solidity
function addMintUser(address account) public virtual
```

*Add an account to the user role. Restricted to admins.*

#### addAdmin

```solidity
function addAdmin(address account) public virtual
```

*Add an account to the admin role. Restricted to admins.*

#### removeMintUser

```solidity
function removeMintUser(address account) public virtual
```

*Remove an account from the user role. Restricted to admins.*

#### renounceAdmin

```solidity
function renounceAdmin() public virtual
```

*Remove oneself from the admin role.*

### IBEP20

#### totalSupply

```solidity
function totalSupply() external view returns (uint256)
```

*Returns the amount of tokens in existence.*

#### decimals

```solidity
function decimals() external view returns (uint8)
```

*Returns the token decimals.*

#### symbol

```solidity
function symbol() external view returns (string)
```

*Returns the token symbol.*

#### name

```solidity
function name() external view returns (string)
```

*Returns the token name.*

#### getOwner

```solidity
function getOwner() external view returns (address)
```

*Returns the bep token owner.*

#### balanceOf

```solidity
function balanceOf(address account) external view returns (uint256)
```

*Returns the amount of tokens owned by `account`.*

#### transfer

```solidity
function transfer(address recipient, uint256 amount) external returns (bool)
```

\_Moves `amount` tokens from the caller's account to `recipient`.

Returns a boolean value indicating whether the operation succeeded.

Emits a {Transfer} event.\_

#### allowance

```solidity
function allowance(address _owner, address spender) external view returns (uint256)
```

\_Returns the remaining number of tokens that `spender` will be allowed to spend on behalf of `owner` through {transferFrom}. This is zero by default.

This value changes when {approve} or {transferFrom} are called.\_

#### approve

```solidity
function approve(address spender, uint256 amount) external returns (bool)
```

\_Sets `amount` as the allowance of `spender` over the caller's tokens.

Returns a boolean value indicating whether the operation succeeded.

IMPORTANT: Beware that changing an allowance with this method brings the risk that someone may use both the old and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards: <https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729>

Emits an {Approval} event.\_

#### transferFrom

```solidity
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool)
```

\_Moves `amount` tokens from `sender` to `recipient` using the allowance mechanism. `amount` is then deducted from the caller's allowance.

Returns a boolean value indicating whether the operation succeeded.

Emits a {Transfer} event.\_

#### Transfer

```solidity
event Transfer(address from, address to, uint256 value)
```

\_Emitted when `value` tokens are moved from one account (`from`) to another (`to`).

Note that `value` may be zero.\_

#### Approval

```solidity
event Approval(address owner, address spender, uint256 value)
```

*Emitted when the allowance of a `spender` for an `owner` is set by a call to {approve}. `value` is the new allowance.*

### Ownable

#### OwnershipTransferred

```solidity
event OwnershipTransferred(address previousOwner, address newOwner)
```

#### constructor

```solidity
constructor() internal
```

*Initializes the contract setting the deployer as the initial owner.*

#### owner

```solidity
function owner() public view returns (address)
```

*Returns the address of the current owner.*

#### onlyOwner

```solidity
modifier onlyOwner()
```

*Throws if called by any account other than the owner.*

#### renounceOwnership

```solidity
function renounceOwnership() public
```

\_Leaves the contract without owner. It will not be possible to call `onlyOwner` functions anymore. Can only be called by the current owner.

NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.\_

#### transferOwnership

```solidity
function transferOwnership(address newOwner) public
```

*Transfers ownership of the contract to a new account (`newOwner`). Can only be called by the current owner.*

#### \_transferOwnership

```solidity
function _transferOwnership(address newOwner) internal
```

*Transfers ownership of the contract to a new account (`newOwner`).*

### BEP20

#### constructor

```solidity
constructor(string name, string symbol) public
```

\_Sets the values for {name} and {symbol}, initializes {decimals} with a default value of 18.

To select a different value for {decimals}, use {\_setupDecimals}.

All three of these values are immutable: they can only be set once during construction.\_

#### getOwner

```solidity
function getOwner() external view returns (address)
```

*Returns the bep token owner.*

#### name

```solidity
function name() public view returns (string)
```

*Returns the token name.*

#### decimals

```solidity
function decimals() public view returns (uint8)
```

*Returns the token decimals.*

#### symbol

```solidity
function symbol() public view returns (string)
```

*Returns the token symbol.*

#### totalSupply

```solidity
function totalSupply() public view returns (uint256)
```

*See {BEP20-totalSupply}.*

#### balanceOf

```solidity
function balanceOf(address account) public view returns (uint256)
```

*See {BEP20-balanceOf}.*

#### transfer

```solidity
function transfer(address recipient, uint256 amount) public returns (bool)
```

\_See {BEP20-transfer}.

Requirements:

* `recipient` cannot be the zero address.
* the caller must have a balance of at least `amount`.\_

#### allowance

```solidity
function allowance(address owner, address spender) public view returns (uint256)
```

*See {BEP20-allowance}.*

#### approve

```solidity
function approve(address spender, uint256 amount) public returns (bool)
```

\_See {BEP20-approve}.

Requirements:

* `spender` cannot be the zero address.\_

#### transferFrom

```solidity
function transferFrom(address sender, address recipient, uint256 amount) public returns (bool)
```

\_See {BEP20-transferFrom}.

Emits an {Approval} event indicating the updated allowance. This is not required by the EIP. See the note at the beginning of {BEP20};

Requirements:

* `sender` and `recipient` cannot be the zero address.
* `sender` must have a balance of at least `amount`.
* the caller must have allowance for `sender`'s tokens of at least `amount`.\_

#### increaseAllowance

```solidity
function increaseAllowance(address spender, uint256 addedValue) public returns (bool)
```

\_Atomically increases the allowance granted to `spender` by the caller.

This is an alternative to {approve} that can be used as a mitigation for problems described in {BEP20-approve}.

Emits an {Approval} event indicating the updated allowance.

Requirements:

* `spender` cannot be the zero address.\_

#### decreaseAllowance

```solidity
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool)
```

\_Atomically decreases the allowance granted to `spender` by the caller.

This is an alternative to {approve} that can be used as a mitigation for problems described in {BEP20-approve}.

Emits an {Approval} event indicating the updated allowance.

Requirements:

* `spender` cannot be the zero address.
* `spender` must have allowance for the caller of at least `subtractedValue`.\_

#### \_transfer

```solidity
function _transfer(address sender, address recipient, uint256 amount) internal
```

\_Moves tokens `amount` from `sender` to `recipient`.

This is internal function is equivalent to {transfer}, and can be used to e.g. implement automatic token fees, slashing mechanisms, etc.

Emits a {Transfer} event.

Requirements:

* `sender` cannot be the zero address.
* `recipient` cannot be the zero address.
* `sender` must have a balance of at least `amount`.\_

#### \_mint

```solidity
function _mint(address account, uint256 amount) internal
```

\_Creates `amount` tokens and assigns them to `account`, increasing the total supply.

Emits a {Transfer} event with `from` set to the zero address.

Requirements

* `to` cannot be the zero address.\_

#### \_burn

```solidity
function _burn(address account, uint256 amount) internal
```

\_Destroys `amount` tokens from `account`, reducing the total supply.

Emits a {Transfer} event with `to` set to the zero address.

Requirements

* `account` cannot be the zero address.
* `account` must have at least `amount` tokens.\_

#### \_approve

```solidity
function _approve(address owner, address spender, uint256 amount) internal
```

\_Sets `amount` as the allowance of `spender` over the `owner`s tokens.

This is internal function is equivalent to `approve`, and can be used to e.g. set automatic allowances for certain subsystems, etc.

Emits an {Approval} event.

Requirements:

* `owner` cannot be the zero address.
* `spender` cannot be the zero address.\_

#### \_burnFrom

```solidity
function _burnFrom(address account, uint256 amount) internal
```

\_Destroys `amount` tokens from `account`.`amount` is then deducted from the caller's allowance.

See {\_burn} and {*approve}.*

#### \_beforeTokenTransfer

```solidity
function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual
```

\_Hook that is called before any transfer of tokens. This includes minting and burning.

Calling conditions:

* when `from` and `to` are both non-zero, `amount` of `from`'s tokens will be to transferred to `to`.
* when `from` is zero, `amount` tokens will be minted for `to`.
* when `to` is zero, `amount` of `from`'s tokens will be burned.
* `from` and `to` are never both zero.

To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks\[Using Hooks].\_

### XWINToken

#### constructor

```solidity
constructor(uint256 cap_) public
```

#### mint

```solidity
function mint(address _to, uint256 _amount) external
```

Creates `_amount` token to `_to`. Must only be called by the owner (admin).

#### isCapReach

```solidity
function isCapReach() external view returns (bool)
```

#### maxCap

```solidity
function maxCap() external view returns (uint256)
```

#### \_delegates

```solidity
mapping(address => address) _delegates
```

#### Checkpoint

```solidity
struct Checkpoint {
  uint32 fromBlock;
  uint256 votes;
}
```

#### checkpoints

```solidity
mapping(address => mapping(uint32 => struct XWINToken.Checkpoint)) checkpoints
```

A record of votes checkpoints for each account, by index

#### numCheckpoints

```solidity
mapping(address => uint32) numCheckpoints
```

The number of checkpoints for each account

#### DOMAIN\_TYPEHASH

```solidity
bytes32 DOMAIN_TYPEHASH
```

The EIP-712 typehash for the contract's domain

#### DELEGATION\_TYPEHASH

```solidity
bytes32 DELEGATION_TYPEHASH
```

The EIP-712 typehash for the delegation struct used by the contract

#### nonces

```solidity
mapping(address => uint256) nonces
```

A record of states for signing / validating signatures

#### DelegateChanged

```solidity
event DelegateChanged(address delegator, address fromDelegate, address toDelegate)
```

An event thats emitted when an account changes its delegate

#### DelegateVotesChanged

```solidity
event DelegateVotesChanged(address delegate, uint256 previousBalance, uint256 newBalance)
```

An event thats emitted when a delegate account's vote balance changes

#### delegates

```solidity
function delegates(address delegator) external view returns (address)
```

Delegate votes from `msg.sender` to `delegatee`

**Parameters**

| Name      | Type    | Description                      |
| --------- | ------- | -------------------------------- |
| delegator | address | The address to get delegatee for |

#### delegate

```solidity
function delegate(address delegatee) external
```

Delegate votes from `msg.sender` to `delegatee`

**Parameters**

| Name      | Type    | Description                      |
| --------- | ------- | -------------------------------- |
| delegatee | address | The address to delegate votes to |

#### delegateBySig

```solidity
function delegateBySig(address delegatee, uint256 nonce, uint256 expiry, uint8 v, bytes32 r, bytes32 s) external
```

Delegates votes from signatory to `delegatee`

**Parameters**

| Name      | Type    | Description                                        |
| --------- | ------- | -------------------------------------------------- |
| delegatee | address | The address to delegate votes to                   |
| nonce     | uint256 | The contract state required to match the signature |
| expiry    | uint256 | The time at which to expire the signature          |
| v         | uint8   | The recovery byte of the signature                 |
| r         | bytes32 | Half of the ECDSA signature pair                   |
| s         | bytes32 | Half of the ECDSA signature pair                   |

#### getCurrentVotes

```solidity
function getCurrentVotes(address account) external view returns (uint256)
```

Gets the current votes balance for `account`

**Parameters**

| Name    | Type    | Description                      |
| ------- | ------- | -------------------------------- |
| account | address | The address to get votes balance |

**Return Values**

| Name | Type    | Description                               |
| ---- | ------- | ----------------------------------------- |
| \[0] | uint256 | The number of current votes for `account` |

#### getPriorVotes

```solidity
function getPriorVotes(address account, uint256 blockNumber) external view returns (uint256)
```

Determine the prior number of votes for an account as of a block number

*Block number must be a finalized block or else this function will revert to prevent misinformation.*

**Parameters**

| Name        | Type    | Description                                 |
| ----------- | ------- | ------------------------------------------- |
| account     | address | The address of the account to check         |
| blockNumber | uint256 | The block number to get the vote balance at |

**Return Values**

| Name | Type    | Description                                               |
| ---- | ------- | --------------------------------------------------------- |
| \[0] | uint256 | The number of votes the account had as of the given block |

#### \_delegate

```solidity
function _delegate(address delegator, address delegatee) internal
```

#### \_moveDelegates

```solidity
function _moveDelegates(address srcRep, address dstRep, uint256 amount) internal
```

#### \_writeCheckpoint

```solidity
function _writeCheckpoint(address delegatee, uint32 nCheckpoints, uint256 oldVotes, uint256 newVotes) internal
```

#### safe32

```solidity
function safe32(uint256 n, string errorMessage) internal pure returns (uint32)
```

#### getChainId

```solidity
function getChainId() internal pure returns (uint256)
```


# xWin BuddyChef (Legacy)

### xWinBuddyChef

#### UserInfo

```solidity
struct UserInfo {
  uint256 amount;
  uint256 rewardDebt;
}
```

#### PoolInfo

```solidity
struct PoolInfo {
  contract IERC20Upgradeable lpToken;
  contract IERC20Upgradeable rewardToken;
  uint256 endPeriod;
  uint256 lastRewardBlock;
  uint256 accCakePerShare;
  uint256 tokenPerBlock;
  uint256 totalStaked;
  uint256 totalBuddyTokens;
}
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### usdtToken

```solidity
address usdtToken
```

#### devAddress

```solidity
address devAddress
```

#### poolInfo

```solidity
struct xWinBuddyChef.PoolInfo[] poolInfo
```

#### devFee

```solidity
uint256 devFee
```

#### startBlock

```solidity
uint256 startBlock
```

#### BONUS\_MULTIPLIER

```solidity
uint256 BONUS_MULTIPLIER
```

#### blocksPerDay

```solidity
uint256 blocksPerDay
```

#### userInfo

```solidity
mapping(uint256 => mapping(address => struct xWinBuddyChef.UserInfo)) userInfo
```

mapping of a nft token to its current properties

#### Deposit

```solidity
event Deposit(address user, uint256 pid, uint256 amount)
```

#### Withdraw

```solidity
event Withdraw(address user, uint256 pid, uint256 amount)
```

#### EmergencyWithdraw

```solidity
event EmergencyWithdraw(address user, uint256 pid, uint256 amount)
```

#### Received

```solidity
event Received(address, uint256)
```

#### initialize

```solidity
function initialize(address _devAddress, address _xWinPriceMaster, address _usdtToken, uint256 _blocksPerDay) public
```

#### poolLength

```solidity
function poolLength() external view returns (uint256)
```

#### stopPool

```solidity
function stopPool(uint256 _pid) public
```

#### updateDevAddress

```solidity
function updateDevAddress(address _devAdd) public
```

#### \_stopPool

```solidity
function _stopPool(uint256 _pid) internal
```

#### add

```solidity
function add(contract IERC20Upgradeable _lpToken, contract IERC20Upgradeable _rewardToken, uint256 _duration, uint256 _totalBuddyTokens) public
```

#### set

```solidity
function set(uint256 _pid, uint256 _newDuration, uint256 _totalBuddyTokens, uint256 _amountToAdd) public
```

#### pendingRewards

```solidity
function pendingRewards(uint256 _pid, address _user) public view returns (uint256)
```

#### getMultiplier

```solidity
function getMultiplier(uint256 _from, uint256 _to, uint256 _endBlock) public view returns (uint256)
```

#### massUpdatePools

```solidity
function massUpdatePools() public
```

#### updatePool

```solidity
function updatePool(uint256 _pid) public
```

#### harvestAll

```solidity
function harvestAll() public
```

#### deposit

```solidity
function deposit(uint256 _pid, uint256 _amount) public
```

#### \_deposit

```solidity
function _deposit(uint256 _pid, uint256 _amount) internal
```

#### withdraw

```solidity
function withdraw(uint256 _pid, uint256 _amount) public
```

#### safeTokenTransfer

```solidity
function safeTokenTransfer(contract IERC20Upgradeable rewardToken, address _to, uint256 _amount) internal
```

#### emergencyWithdraw

```solidity
function emergencyWithdraw(uint256 _pid) public
```

#### setPriceMaster

```solidity
function setPriceMaster(address _newPriceMaster) external
```

#### setUSDToken

```solidity
function setUSDToken(address _newUSDAddr) external
```

#### setDevFee

```solidity
function setDevFee(uint256 _newDevFee) external
```

#### setBonusMultiplier

```solidity
function setBonusMultiplier(uint256 _newMultiplier) external
```

#### setBlocksPerDay

```solidity
function setBlocksPerDay(uint256 _newBlocksPerDay) external
```


# xWin MasterChef

### xWinDefi

#### UserInfo

```solidity
struct UserInfo {
  uint256 amount;
  uint256 blockstart;
}
```

#### PoolInfo

```solidity
struct PoolInfo {
  address lpToken;
  uint256 rewardperblock;
  uint256 multiplier;
}
```

#### DepositFarm

```solidity
function DepositFarm(uint256 _pid, uint256 _amount) public
```

#### pendingXwin

```solidity
function pendingXwin(uint256 _pid, address _user) public view returns (uint256)
```

#### WithdrawFarm

```solidity
function WithdrawFarm(uint256 _pid, uint256 _amount) public
```

#### userInfo

```solidity
mapping(uint256 => mapping(address => struct xWinDefi.UserInfo)) userInfo
```

#### poolInfo

```solidity
struct xWinDefi.PoolInfo[] poolInfo
```

### xWinMasterChef

#### UserInfo

```solidity
struct UserInfo {
  uint256 amount;
  uint256 rewardDebt;
}
```

#### PoolInfo

```solidity
struct PoolInfo {
  contract IERC20Upgradeable lpToken;
  uint256 endPeriod;
  uint256 allocPoint;
  uint256 lastRewardBlock;
  uint256 accCakePerShare;
  uint256 totalDeposit;
}
```

#### xWinPriceMaster

```solidity
contract IxWinPriceMaster xWinPriceMaster
```

#### rewardsToken

```solidity
contract IERC20Upgradeable rewardsToken
```

#### usdtToken

```solidity
address usdtToken
```

#### burnAddress

```solidity
address burnAddress
```

#### \_xwinDefi

```solidity
contract xWinDefi _xwinDefi
```

#### poolInfo

```solidity
struct xWinMasterChef.PoolInfo[] poolInfo
```

#### burnFee

```solidity
uint256 burnFee
```

#### xwinPerBlock

```solidity
uint256 xwinPerBlock
```

#### totalAllocPoint

```solidity
uint256 totalAllocPoint
```

#### startBlock

```solidity
uint256 startBlock
```

#### BONUS\_MULTIPLIER

```solidity
uint256 BONUS_MULTIPLIER
```

#### xwinpid

```solidity
uint256 xwinpid
```

#### blocksPerDay

```solidity
uint256 blocksPerDay
```

#### userInfo

```solidity
mapping(uint256 => mapping(address => struct xWinMasterChef.UserInfo)) userInfo
```

mapping of a nft token to its current properties

#### Deposit

```solidity
event Deposit(address user, uint256 pid, uint256 amount)
```

#### Withdraw

```solidity
event Withdraw(address user, uint256 pid, uint256 amount)
```

#### EmergencyWithdraw

```solidity
event EmergencyWithdraw(address user, uint256 pid, uint256 amount)
```

#### Received

```solidity
event Received(address, uint256)
```

#### initialize

```solidity
function initialize(string name, string symbol, address _usdtToken, uint256 _blocksPerDay) external
```

#### farmTokenByAdmin

```solidity
function farmTokenByAdmin() external
```

#### unFarmTokenByAdmin

```solidity
function unFarmTokenByAdmin() external
```

#### updateProperties

```solidity
function updateProperties(contract IERC20Upgradeable _rewardsToken, uint256 _xwinpid, uint256 _xwinPerBlock) public
```

#### poolLength

```solidity
function poolLength() external view returns (uint256)
```

#### updateSmartContract

```solidity
function updateSmartContract(address _xwinDefiaddr, address _xWinPriceMaster) external
```

#### stopPool

```solidity
function stopPool(uint256 _pid) external
```

#### \_stopPool

```solidity
function _stopPool(uint256 _pid) internal
```

#### add

```solidity
function add(uint256 _allocPoint, contract IERC20Upgradeable _lpToken, uint256 _duration) external
```

#### set

```solidity
function set(uint256 _pid, uint256 _allocPoint, uint256 _newDuration) external
```

#### pendingRewards

```solidity
function pendingRewards(uint256 _pid, address _user) public view returns (uint256)
```

#### getMultiplier

```solidity
function getMultiplier(uint256 _from, uint256 _to) public view returns (uint256)
```

#### massUpdatePools

```solidity
function massUpdatePools() public
```

#### updatePool

```solidity
function updatePool(uint256 _pid) public
```

#### harvestAll

```solidity
function harvestAll() external
```

#### deposit

```solidity
function deposit(uint256 _pid, uint256 _amount) external returns (uint256)
```

#### \_deposit

```solidity
function _deposit(uint256 _pid, uint256 _amount) internal returns (uint256 rewardAmount)
```

#### withdraw

```solidity
function withdraw(uint256 _pid, uint256 _amount) external returns (uint256 rewardAmount)
```

#### safexWINTransfer

```solidity
function safexWINTransfer(address _to, uint256 _amount) internal returns (uint256)
```

#### harvest

```solidity
function harvest(uint256 _pid) external returns (uint256)
```

#### emergencyWithdraw

```solidity
function emergencyWithdraw(uint256 _pid) external
```

#### setBurnFee

```solidity
function setBurnFee(uint256 _burnFee) external
```

#### setBonusMultiplier

```solidity
function setBonusMultiplier(uint256 _bonusMultiplier) external
```

#### setBlockPerDay

```solidity
function setBlockPerDay(uint256 _blocksPerDay) external
```

#### setUSDToken

```solidity
function setUSDToken(address _newUSDToken) external
```

#### getAPR

```solidity
function getAPR(uint256 _pid) external view returns (uint256 apr)
```

Returns the APR for a given pool

#### getPoolUserRewardPerBlock

```solidity
function getPoolUserRewardPerBlock(uint256 _pid, address _user) external view returns (uint256)
```

View the reward per block for a given pool and user


# xWin Locked Stake

### xWinLockedStake

#### UserInfo

```solidity
struct UserInfo {
  uint256 shares;
  uint256 amount;
  uint256 lockedShares;
  uint256 rewardDebt;
  uint256 startTimestamp;
  uint256 endPeriodTimestamp;
  uint256 xWinFavor;
}
```

#### token

```solidity
contract IERC20Upgradeable token
```

#### masterChef

```solidity
contract xWinMasterChef masterChef
```

#### userInfo

```solidity
mapping(address => struct xWinLockedStake.UserInfo) userInfo
```

#### totalShares

```solidity
uint256 totalShares
```

#### lastHarvestedTime

```solidity
uint256 lastHarvestedTime
```

#### totalLockedShares

```solidity
uint256 totalLockedShares
```

#### accXWINperLockedShare

```solidity
uint256 accXWINperLockedShare
```

#### treasury

```solidity
address treasury
```

#### lockedRewardsVault

```solidity
uint256 lockedRewardsVault
```

#### performanceFee

```solidity
uint256 performanceFee
```

#### callFee

```solidity
uint256 callFee
```

#### blocksPerDay

```solidity
uint256 blocksPerDay
```

#### xwinpid

```solidity
uint256 xwinpid
```

#### lockpid

```solidity
uint256 lockpid
```

#### Deposit

```solidity
event Deposit(address sender, uint256 amount, uint256 shares)
```

#### Withdraw

```solidity
event Withdraw(address sender, uint256 amount, uint256 shares)
```

#### Harvest

```solidity
event Harvest(address sender, uint256 performanceFee, uint256 callFee)
```

#### initialize

```solidity
function initialize(contract IERC20Upgradeable _token, address _masterChef, address _treasury, uint256 _xwinpid, uint256 _lockpid) external
```

#### masterChefDeposit

```solidity
function masterChefDeposit() external
```

#### deposit

```solidity
function deposit(uint256 _amount, uint8 _duration) external
```

Deposit into locked staking farm If locked position already exists, this function acts to deposit more and extend locking period

**Parameters**

| Name       | Type    | Description                      |
| ---------- | ------- | -------------------------------- |
| \_amount   | uint256 | Amount of xWin Tokens to deposit |
| \_duration | uint8   | Duration to lock                 |

#### harvest

```solidity
function harvest() public
```

Re-invest rewards for compounding rewards

#### \_harvest

```solidity
function _harvest() internal
```

#### harvestLockBonus

```solidity
function harvestLockBonus() internal
```

Collect locking bonus

#### withdraw

```solidity
function withdraw() external
```

Withdraws everything from user

#### \_earn

```solidity
function _earn() internal
```

Reinvest reward tokens into MasterChef to compound staking rewards

#### setTreasury

```solidity
function setTreasury(address _treasury) external
```

Sets treasury address

*Only callable by the contract owner.*

#### setFees

```solidity
function setFees(uint256 _callFee, uint256 _performanceFee) external
```

Sets call fee and performance fee

*Only callable by the contract admin.*

#### setBlocksPerDay

```solidity
function setBlocksPerDay(uint256 _blocksPerDay) external
```

#### migrateMasterChef

```solidity
function migrateMasterChef(address _newMasterChef, uint256 _xwinpid, uint256 _lockpid) external
```

#### calculateHarvestCakeRewards

```solidity
function calculateHarvestCakeRewards() external view returns (uint256)
```

Calculates the expected harvest reward from third party

**Return Values**

| Name | Type    | Description                        |
| ---- | ------- | ---------------------------------- |
| \[0] | uint256 | Expected reward to collect in CAKE |

#### calculateTotalPendingCakeRewards

```solidity
function calculateTotalPendingCakeRewards() external view returns (uint256)
```

Calculates the total pending rewards that can be restaked

**Return Values**

| Name | Type    | Description                        |
| ---- | ------- | ---------------------------------- |
| \[0] | uint256 | Returns total pending cake rewards |

#### \_doWithdraw

```solidity
function _doWithdraw(struct xWinLockedStake.UserInfo user) internal returns (uint256)
```

withdraws the user's entire position from both lock bonus and staking

#### getPricePerFullShare

```solidity
function getPricePerFullShare() external view returns (uint256)
```

Calculates the price per share

#### available

```solidity
function available() public view returns (uint256)
```

Custom logic for how much the vault allows to be borrowed

*The contract puts all of the tokens except for lockedRewards to work.*

#### getFavor

```solidity
function getFavor(address _user) external view returns (uint256)
```

#### totalXWINBalance

```solidity
function totalXWINBalance() public view returns (uint256)
```

Calculates the total underlying tokens

*It includes tokens held by the contract and held in MasterChef*

#### shareMultiplier

```solidity
function shareMultiplier(uint256 amount, uint8 period) public pure returns (uint256)
```

#### getUserPosition

```solidity
function getUserPosition(address _user) public view returns (uint256 rewardAmount, uint256 xwinAmount)
```

Views a user's current position

**Parameters**

| Name   | Type    | Description     |
| ------ | ------- | --------------- |
| \_user | address | Address of user |

**Return Values**

| Name         | Type    | Description                           |
| ------------ | ------- | ------------------------------------- |
| rewardAmount | uint256 | xWin Token amount from locking reward |
| xwinAmount   | uint256 | xWin Tokens amount from staking       |

#### convertWeeksToTimestamp

```solidity
function convertWeeksToTimestamp(uint256 w) internal pure returns (uint256)
```

#### getUserCompoundAPYrate

```solidity
function getUserCompoundAPYrate(address _user) external view returns (uint256 estimatedDailyRate)
```

Returns user's daily reward rate

#### getUserLockingBonusAPR

```solidity
function getUserLockingBonusAPR(address _user) external view returns (uint256 apr)
```

Gets the user's rate from lock duration bonus

#### getEstimatedDepositAPY

```solidity
function getEstimatedDepositAPY(uint256 _amount, uint8 _duration) external view returns (uint256 estimatedDailyRate, uint256 estimatedBonusApr)
```

Given an amount and duration, return the user's rate and bonus rate

**Parameters**

| Name       | Type    | Description            |
| ---------- | ------- | ---------------------- |
| \_amount   | uint256 | Amount to be deposited |
| \_duration | uint8   | Duration to be locked  |


# Partner Vaults


# xWin Strategy Hedge Fund

<figure><img src="https://466113786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTG45H8vI4SWqrd6h2tHn%2Fuploads%2Flmwt7Fr1k4cl5hWUzlUt%2FxWin%20Strategy%20Active%20Traded%20(1).png?alt=media&amp;token=90246eb0-463d-4327-b170-b41347bcc484" alt=""><figcaption></figcaption></figure>

xWin Finance partners with professional traders to allow expert traders to trade on Defi without having to create smart contracts and extensive knowledge about programming. With our easy-to-use SDK, partners at xWin Finance can rebalance whenever they like. These strategies can then be deposited by investors.&#x20;


# xWin Split Fee Wallet

xWin Finance has a smart contract that we deploy for every strategy that is partnered with funds. This smart contract will collect the fees where the smart contract divides the fee between our partner and xWin.&#x20;

### xWinSplitFeeWallet

#### Manager

```solidity
struct Manager {
  address managerAddress;
  uint256[] ratio;
}
```

#### managers

```solidity
struct xWinSplitFeeWallet.Manager[] managers
```

#### tokens

```solidity
address[] tokens
```

#### emitEvent

```solidity
contract IxWinEmitEvent emitEvent
```

#### startBlock

```solidity
uint256 startBlock
```

#### period

```solidity
uint256 period
```

#### initialize

```solidity
function initialize(address _emitEvent, struct xWinSplitFeeWallet.Manager[] _managers) external
```

#### restateManagers

```solidity
function restateManagers(struct xWinSplitFeeWallet.Manager[] _managers) external
```

resets the manager information

**Parameters**

| Name       | Type                                 | Description                                |
| ---------- | ------------------------------------ | ------------------------------------------ |
| \_managers | struct xWinSplitFeeWallet.Manager\[] | Array of manager addresses and their ratio |

#### distributeFees

```solidity
function distributeFees() external returns (bool)
```

distributes the fees to all the managers

#### addToken

```solidity
function addToken(address _token) external
```

Adds a new token to be tracked by this contract

**Parameters**

| Name    | Type    | Description   |
| ------- | ------- | ------------- |
| \_token | address | token address |

#### removeToken

```solidity
function removeToken(uint256 index) external
```

#### updateEventEmitter

```solidity
function updateEventEmitter(address _newEmitEvent) external
```

#### updateStartBlock

```solidity
function updateStartBlock(uint256 _newStartBlock) external
```

#### setPeriod

```solidity
function setPeriod(uint256 _newPeriod) external
```

#### tokenLength

```solidity
function tokenLength() public view returns (uint256)
```

#### managersLength

```solidity
function managersLength() public view returns (uint256)
```

#### managerAll

```solidity
function managerAll() public view returns (struct xWinSplitFeeWallet.Manager[])
```

#### managerRatio

```solidity
function managerRatio(uint256 index) public view returns (struct xWinSplitFeeWallet.Manager)
```


# Listing of partner Strategy

<table><thead><tr><th width="208">Partner Name</th><th width="90">Name</th><th width="443">Contract Address</th></tr></thead><tbody><tr><td>Future Money</td><td>BCIF10</td><td>0x5C85E550BF88c5c38929dc2A0AfE7B975124c9f6</td></tr><tr><td>Moonbit</td><td>PAA</td><td>0x24CfBB02c24Eeb0Bef09031c737964832e6aE62a</td></tr><tr><td>Moonbit</td><td>VRS</td><td>0x60bAF23a9344Ca808f55C3b29783b14fB642f4F4</td></tr><tr><td><em>Okinawa FINTECH SCHOOL</em> </td><td>RQF</td><td>0xf3a8e2229642caded317265c1cf17a6a76771df8</td></tr></tbody></table>


# SDK

## <https://github.com/xwinfinance/xwin-finance-sdk>

## @xwin-finance/sdk

A SDK package that develop by xwin-finance team.

#### Installation

```
npm install @xwin-finance/sdk
```

### Example of Usage

#### for FundV2 deposit,

```
import { SmartContractSdk } from "@xwin-finance/sdk";

const deposit = async () => {
  const sdk = await SmartContractSdk.start({
    rpcUrl: '<selected-rpc-url>',
    privateKey: '<your-private-key>',
  });

  const outout = await sdk.FundV2().deposit({
    contractAddress: "0x358f8203f102edef499ac197d76f29f7c40c5714",
    amount: 1000,
    slippage: 1,
  });
}

deposit();
```

#### for FundV2 withdraw,

```
import { SmartContractSdk } from "@xwin-finance/sdk";

const withdraw = async () => {
  const sdk = await SmartContractSdk.start({
    rpcUrl: '<selected-rpc-url>',
    privateKey: '<your-private-key>',
  });

  const outout = await sdk.FundV2().withdraw({
    contractAddress: "0x358f8203f102edef499ac197d76f29f7c40c5714",
    amount: 1000,
    slippage: 1,
  });
}

withdraw();
```

#### for FundV2 rebalance,

```
import { SmartContractSdk } from "@xwin-finance/sdk";

const rebalance = async () => {
  const sdk = await SmartContractSdk.start({
    rpcUrl: '<selected-rpc-url>',
    privateKey: '<your-private-key>',
  });

  const outout = await sdk.FundV2().rebalance({
    contractAddress: "0x358f8203f102edef499ac197d76f29f7c40c5714",
    toAddress: ["0x358f8203f102edef499ac197d76f29f7c40ccas4"],
    targets: ["10"],
    slippage: 1,
  });
}

rebalance();
```

#### for FundV2 rebalance,

```
import { SmartContractSdk } from "@xwin-finance/sdk";

const getFundWeightsData = async () => {
  const sdk = await SmartContractSdk.start({
    rpcUrl: '<selected-rpc-url>',
    privateKey: '<your-private-key>',
  });

  const outout = await sdk.FundV2().getFundWeightsData("0x358f8203f102edef499ac197d76f29f7c40c5714");
}

getFundWeightsData();
```

### Docs

please refer to the docs for more references

* [types docs](https://download.xwin.finance/docs/@xwin-finance/sdk/latest/index.html)


# Smart Contract Audit

<https://skynet.certik.com/projects/xwinfinance>


