xWin Defi (Helper)

Context

constructor

constructor() internal

_msgSender

function _msgSender() internal view returns (address payable)

_msgData

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

event OwnershipTransferred(address previousOwner, address newOwner)

constructor

constructor() internal

Initializes the contract setting the deployer as the initial owner.

owner

function owner() public view returns (address)

Returns the address of the current owner.

onlyOwner

modifier onlyOwner()

Throws if called by any account other than the owner.

renounceOwnership

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

function transferOwnership(address newOwner) public

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

_transferOwnership

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

constructor() internal

nonReentrant

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

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

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

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

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

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

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

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

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

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

sqrt

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

Address

Collection of functions related to the address type

isContract

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

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

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

_Performs a Solidity function call using a low level call. A plaincall 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

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

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

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

function totalSupply() external view returns (uint256)

Returns the amount of tokens in existence.

decimals

function decimals() external view returns (uint8)

Returns the token decimals.

symbol

function symbol() external view returns (string)

Returns the token symbol.

name

function name() external view returns (string)

Returns the token name.

getOwner

function getOwner() external view returns (address)

Returns the bep token owner.

balanceOf

function balanceOf(address account) external view returns (uint256)

Returns the amount of tokens owned by account.

transfer

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

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

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

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

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

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

function safeTransfer(contract IBEP20 token, address to, uint256 value) internal

safeTransferFrom

function safeTransferFrom(contract IBEP20 token, address from, address to, uint256 value) internal

safeApprove

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

function safeIncreaseAllowance(contract IBEP20 token, address spender, uint256 value) internal

safeDecreaseAllowance

function safeDecreaseAllowance(contract IBEP20 token, address spender, uint256 value) internal

xWinLib

PoolInfo

struct PoolInfo {
  address lpToken;
  uint256 rewardperblock;
  uint256 multiplier;
}

UserInfo

struct UserInfo {
  uint256 amount;
  uint256 blockstart;
}

TradeParams

struct TradeParams {
  address xFundAddress;
  uint256 amount;
  uint256 priceImpactTolerance;
  uint256 deadline;
  bool returnInBase;
  address referral;
}

transferData

struct transferData {
  address[] targetNamesAddress;
  uint256 totalTrfAmt;
  uint256 totalUnderlying;
  uint256 qtyToTrfAToken;
}

xWinReward

struct xWinReward {
  uint256 blockstart;
  uint256 accBasetoken;
  uint256 accMinttoken;
  uint256 previousRealizedQty;
}

xWinReferral

struct xWinReferral {
  address referral;
}

UnderWeightData

struct UnderWeightData {
  uint256 activeWeight;
  uint256 fundWeight;
  bool overweight;
  address token;
}

DeletedNames

struct DeletedNames {
  address token;
  uint256 targetWeight;
}

PancakePriceToken

struct PancakePriceToken {
  string tokenname;
  address addressToken;
}

TransferHelper

safeApprove

function safeApprove(address token, address to, uint256 value) internal

safeTransfer

function safeTransfer(address token, address to, uint256 value) internal

safeTransferFrom

function safeTransferFrom(address token, address from, address to, uint256 value) internal

safeTransferBNB

function safeTransferBNB(address to, uint256 value) internal

xWinFund

getManagerFee

function getManagerFee() external view returns (uint256)

getTargetWeight

function getTargetWeight(address addr) external view returns (uint256)

getWhoIsManager

function getWhoIsManager() external view returns (address mangerAddress)

getBalance

function getBalance(address fromAdd) external view returns (uint256 balance)

getFundValues

function getFundValues() external view returns (uint256)

getTargetWeightQty

function getTargetWeightQty(address targetAdd, uint256 srcQty) external view returns (uint256)

updateManager

function updateManager(address managerAdd) external payable

updateManagerFee

function updateManagerFee(uint256 newFeebps) external payable

updateRebalancePeriod

function updateRebalancePeriod(uint256 newCycle) external payable

updateProtocol

function updateProtocol(address _newProtocol) external

Redeem

function Redeem(struct xWinLib.TradeParams _tradeParams, address _investorAddress) external payable returns (uint256)

Rebalance

function Rebalance(address[] _toAddresses, uint256[] _targetWeight, uint256 deadline, uint256 priceImpactTolerance) external payable returns (uint256 baseccyBal)

Subscribe

function Subscribe(struct xWinLib.TradeParams _tradeParams, address _investorAddress) external payable returns (uint256)

MoveNonIndexNameToBase

function MoveNonIndexNameToBase(address _tokenaddress, uint256 deadline, uint256 priceImpactTolerance) external returns (uint256 balanceToken, uint256 swapOutput)

CreateTargetNames

function CreateTargetNames(address[] _toAddresses, uint256[] _targetWeight) external payable

emergencyRedeem

function emergencyRedeem(uint256 redeemUnit, address _investorAddress) external payable

emergencyRemoveFromFarm

function emergencyRemoveFromFarm() external

getUnitPrice

function getUnitPrice() external view returns (uint256 unitprice)

getUnitPriceInUSD

function getUnitPriceInUSD() external view returns (uint256 unitprice)

getTargetNamesAddress

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

xWinStake

StakeReward

function StakeReward(address payable _investorAddress, uint256 rewardQty, uint256 bnbQty, uint256 deadline) external payable

GetQuotes

function GetQuotes(uint256 rewardQty, uint256 baseQty, address targetToken) external view returns (uint256 amountB, uint256 amountA, uint256 amountOut)

xWinDefiProtocol

name

string name

xWinToken

address xWinToken

xwinBenefitPool

address xwinBenefitPool

startblock

uint256 startblock

emergencyOn

bool emergencyOn

userInfo

mapping(uint256 => mapping(address => struct xWinLib.UserInfo)) userInfo

isxwinFund

mapping(address => bool) isxwinFund

poolInfo

struct xWinLib.PoolInfo[] poolInfo

xWinRewards

mapping(address => struct xWinLib.xWinReward) xWinRewards

xWinReferral

mapping(address => struct xWinLib.xWinReferral) xWinReferral

rewardRemaining

uint256 rewardRemaining

Received

event Received(address, uint256)

_MoveNonIndexNameToBaseEvent

event _MoveNonIndexNameToBaseEvent(address from, address toFund, address tokenAddress, uint256 amount, uint256 swapOutput)

_RebalanceAllInOne

event _RebalanceAllInOne(address from, address toFund, uint256 baseBalance, uint256 txnTime)

_Subscribe

event _Subscribe(address from, address toFund, uint256 subsAmt, uint256 mintQty)

_Redeem

event _Redeem(address from, address toFund, uint256 redeemUnit, uint256 rewardQty, uint256 redeemratio)

_CreateTarget

event _CreateTarget(address from, address toFund, address[] newTargets, uint256[] newWeight, uint256 txnTime)

_StakeMyReward

event _StakeMyReward(address from, uint256 rewardQty)

_WithdrawReward

event _WithdrawReward(address from, uint256 rewardQty)

_DepositFarm

event _DepositFarm(address from, uint256 pid, uint256 amount)

_WithdrawFarm

event _WithdrawFarm(address from, uint256 pid, uint256 amount)

_EmergencyRedeem

event _EmergencyRedeem(address user, address fundaddress, uint256 amount)

onlyEmergency

modifier onlyEmergency()

onlyNonEmergency

modifier onlyNonEmergency()

constructor

constructor(uint256 _platformFeeBps, address _platformWallet, address _xwinBenefitPool, address _stakeAddress, address _xWinToken) public

receive

receive() external payable

addxwinFund

function addxwinFund(address[] _fundaddress, bool[] _isxwinFund) public

poolLength

function poolLength() external view returns (uint256)

add

function add(address _lpToken, uint256 _rewardperblock, uint256 _multiplier) public

emergencyWithdraw

function emergencyWithdraw(uint256 _pid) public

updateRewardPerBlock

function updateRewardPerBlock(uint256 _rewardperblock) external

reward per block by deployer

updateEmergencyState

function updateEmergencyState(bool _state) external

turn on emerrgency state by deployer

updateProtocol

function updateProtocol(address _fundaddress, address _newProtocol) external

update xwin defi protocol

updateFarmPoolInfo

function updateFarmPoolInfo(uint256 _pid, uint256 _rewardperblock, uint256 _multiplier) external

create or update farm pool fee by deployer

getAllPendingXwin

function getAllPendingXwin(address _user) public view returns (uint256)

View function to see all pending xWin token earn on frontend.

pendingXwin

function pendingXwin(uint256 _pid, address _user) public view returns (uint256)

View function to see pending xWin on frontend.

DepositFarm

function DepositFarm(uint256 _pid, uint256 _amount) public

Deposit LP tokens to xWin Protocol for xWin allocation.

WithdrawFarm

function WithdrawFarm(uint256 _pid, uint256 _amount) public

Withdraw LP tokens from xWin Protocol.

Subscribe

function Subscribe(struct xWinLib.TradeParams _tradeParams) public payable

perform subscription based on ratio setup and put into lending if available

Redeem

function Redeem(struct xWinLib.TradeParams _tradeParams) external payable

perform redemption based on unit redeem

emergencyRedeem

function emergencyRedeem(uint256 _redeemAmount, address _fundaddress) external payable

perform redemption based on unit redeem and give up all xwin rewards

emergencyRemoveFromFarm

function emergencyRemoveFromFarm(address _fundaddress) external payable

manager perform remove from farm for emergency state

MoveNonIndexNameToBase

function MoveNonIndexNameToBase(address xFundAddress, address _tokenaddress, uint256 deadline, uint256 priceImpactTolerance) external payable

perform MoveNonIndexNameTo BNB for non benchmark name

CreateTarget

function CreateTarget(address[] _toAddresses, uint256[] _targetWeight, address xFundAddress) external

create target ratio by portfolio manager

RebalanceAllInOne

function RebalanceAllInOne(struct xWinLib.TradeParams _tradeParams, address[] _toAddresses, uint256[] _targetWeight) external payable

perform update target, move non-bm to base and finally rebalance

updatePlatformFee

function updatePlatformFee(uint256 newPlatformFee) external

update platform fee by deployer

getPlatformFee

function getPlatformFee() external view returns (uint256)

get platform fee

getPlatformAddress

function getPlatformAddress() external view returns (address)

get platform wallet address

gexWinBenefitPool

function gexWinBenefitPool() external view returns (address)

get platform wallet address

updateXwinBenefitPool

function updateXwinBenefitPool(address _xwinBenefitPool) external

update platform fee by deployer

updateRewardRemaining

function updateRewardRemaining(uint256 _newRemaining) external

update rewardRemaining by deployer

updateStakeProtocol

function updateStakeProtocol(address newStakeProtocol) external

update platform fee by deployer

updateReferralRewardPerUnit

function updateReferralRewardPerUnit(uint256 _referralperunit) external

update referal fee by deployer

updateManagerRewardPerUnit

function updateManagerRewardPerUnit(uint256 _managerRewardperunit) external

update manager reward by deployer

_multiplier

function _multiplier(uint256 _blockstart) internal view returns (uint256)

GetEstimateReward

function GetEstimateReward(address fromAddress) public view returns (uint256)

get estimated reward of XWN token

GetQuotes

function GetQuotes(uint256 tokenBal, address targetToken) external view returns (uint256 amountB, uint256 amountA)

StakeMyReward

function StakeMyReward(uint256 deadline) external payable

User to claim the reward and stake them into DEX

_updateReferralReward

function _updateReferralReward(struct xWinLib.TradeParams _tradeParams, address _managerAddress) internal

WithdrawReward

function WithdrawReward() external payable

withdraw reward of XWN token

_storeRewardQty

function _storeRewardQty(address from, uint256 baseQty, uint256 mintQty) internal

_updateRewardBal

function _updateRewardBal(address from, uint256 redeemUnit) internal returns (uint256 rewardQty)

ProtocolTransfer

function ProtocolTransfer(address _newProtocol, uint256 amount) public payable

emergency trf XWN token to new protocol

_sendRewards

function _sendRewards(address _to, uint256 amount) internal

_resetRewards

function _resetRewards(address _from) internal

Last updated