Strategy
Interface: IStrategy.sol​

Functions

The following functions can be called by any user or public roles.

Sweep

Public: Anyone can call this function.
This function converts any token sent to the strategy into the reserve asset and sends it to the garden.
1
function sweep(address _token, uint256 _newSlippage) external;
Copied!
The strategy must be inactive
Parameter
Description
address _token
Address of the token to sweep
uint256 _newSlippage
Overrides slippage setting

UpdateParams

Only the Strategist can call this function
This function updates specific strategy parameters.
1
function updateParams(uint256[5] calldata _params) external;
Copied!
Parameter
Description
1
uint256[5] calldata _params
Copied!
Array of 5 parameters. See below.
Definition of strategy parameters:
1
* _params[0] duration Strategy duration in seconds
2
* _params[1] maxGasFeePercentage Max gas fee % capped to 10e16
3
* _params[2] maxTradeSlippagePercentage Max trading slippage % capped to 20e16
4
* _params[3] maxAllocationPercentage Max garden capital allocation % (<= 1e18)
5
* _params[4] maxCapitalRequested Max capital requested in reserveAsset
Copied!
New duration value must be equal or less than the original duration.

DeleteCandidateStrategy

Only the Strategist can call this function
This function deletes a candidate strategy.
1
function deleteCandidateStrategy() external;
Copied!

Privileged Functions

The following functions can only be executed by protocol privileged roles.

ResolveVoting

Only the protocol Keeper can call this function
This function adds off-chain gas-less voting results on-chain.
1
function resolveVoting(
2
address[] calldata _voters,
3
int256[] calldata _votes,
4
uint256 _fee
5
) external;
Copied!
Parameters
Description
address[] calldata _voters
An array of garden member who voted on strategy
int256[] calldata _votes
An array of votes by on strategy by garden members
uint256 _fee
The fee paid to keeper to compensate the gas cost

ExecuteStrategy

Only the protocol Keeper can call this function
This function executes a strategy that has been activated and gone through the cooldown period.
1
function executeStrategy(uint256 _capital, uint256 _fee) external;
Copied!
Parameter
Description
uint256 _capital
The capital to allocate to this strategy
uint256 _fee
The fee paid to keeper to compensate the gas cost

FinalizeStrategy

Only the protocol Keeper can call this function
This function exits from an executed strategy. Returns balance back to the garden and sets the capital aside for withdrawals in ETH. Pays the keeper and updates the reserve asset position accordingly.
1
function finalizeStrategy(
2
uint256 _fee,
3
string memory _tokenURI,
4
uint256 _minReserveOut
5
) external;
Copied!
Parameter
Description
uint256 _fee
The fee paid to keeper to compensate the gas cost
string memory _tokenURI
URL with the JSON for the strategy to grant NFT to the strategist
uint256 _minReserveOut
Minimum reserve asset to get during strategy finalization

UnwindStrategy

Only the protocol Keeper can call this function
This function partially unwinds a strategy. Triggered from a penalty withdrawal in the Garden.
1
function unwindStrategy(uint256 _amountToUnwind, uint256 _strategyNAV) external;
Copied!
Parameter
Description
uint256 _amountToUnwind
The amount of capital to unwind
uint256 _strategyNAV
NAV of the strategy to unwind

ExpireStrategy

Only the protocol Keeper can call this function
This function expires a candidate that has spent more than CANDIDATE_PERIOD seconds without reaching quorum.
1
function expireStrategy(uint256 _fee) external;
Copied!
Parameter
Description
uint256 _fee
The keeper fee

SetData

Only the garden can call this function
Sets the data for the operations of this strategy.
1
function setData(
2
uint8[] calldata _opTypes,
3
address[] calldata _opIntegrations,
4
bytes memory _opEncodedData
5
) external;
Copied!
Parameter
Description
uint8[] calldata _opTypes
An array with the op types
address[] calldata _opIntegrations
Addresses with the integration for each op
bytes memory _opEncodedData
64 bytes of operations metadata per operation (size of 64 * numOps)
Definition of types of operations:
1
// 0 = BuyOperation
2
// 1 = LiquidityOperation
3
// 2 = VaultOperation
4
// 3 = LendOperation
5
// 4 = BorrowOperation
Copied!

Trade

Only a valid operation can call this function
Function that calculates the price using the oracle and executes a trade. Must call the exchange to get the price and pass minReceiveQuantity accordingly.
1
function trade(
2
address _sendToken,
3
uint256 _sendQuantity,
4
address _receiveToken
5
) external returns (uint256);
6
​
7
function trade(
8
address _sendToken,
9
uint256 _sendQuantity,
10
address _receiveToken,
11
uint256 _overrideSlippage
12
) external returns (uint256);
Copied!
Parameter
Description
address _sendToken
Token to exchange
uint256 _sendQuantity
Amount of tokens to send
address _receiveToken
Token to receive
uint256 _overrideSlippage
Slippage to override (if any)

HandleWeth

Only a valid operation can call this function
Function that deposits or withdraws WETH from an operation in this context.
1
function handleWeth(bool _isDeposit, uint256 _wethAmount) external;
Copied!
Parameter
Description
bool _isDeposit
Whether is a deposit or withdraw
uint256 _wethAmount
Amount to deposit or withdraw

InvokeFromIntegration

Only a valid integration can call this function
Helper to invoke a call to an external contract from integrations in the strategy context.
1
function invokeFromIntegration(
2
address _target,
3
uint256 _value,
4
bytes calldata _data
5
) external returns (bytes memory);
Copied!
Parameter
Description
address _target
Address of the smart contract to call
uint256 _value
Quantity of Ether to provide the call (typically 0)
bytes calldata _data
Encoded function selector and arguments
return value
Bytes encoded return value

InvokeApprove

Only a valid integration can call this function
Helper to invoke Approve on ERC20 from integrations in the strategy context.
1
function invokeApprove(
2
address _spender,
3
address _asset,
4
uint256 _quantity
5
) external;
Copied!
Parameter
Description
address _spender
Spender address to be allowed
address _asset
Asset address
uint256 _quantity
Amount to approve

View functions

The following functions can be called by anyone without a transaction to retrieve information from the strategy.

GetNAV

Function to get the strategy Net Asset Value (NAV) in reserveAsset.
1
function getNAV() external view returns (uint256);
Copied!

OpEncodedData

Function to get encoded operation data (in bytes) where each consecutive 64 bytes are reserved for each operation metadata. Metadata is usually including operation addresses and values needed for those operations.
1
function opEncodedData() external view returns (bytes memory);
Copied!

GetOperationsCount

Function to get the number of operations used by the strategy.
1
function getOperationsCount() external view returns (uint256);
Copied!

GetOperationByIndex

Function to get the operation data by index.
1
function getOperationByIndex(uint8 _index)
2
external
3
view
4
returns (
5
uint8,
6
address,
7
bytes memory
8
);
Copied!

GetStrategyDetails

Function to get the details of the strategy.
1
function getStrategyDetails()
2
external
3
view
4
returns (
5
address garden,
6
address strategist,
7
uint256 opIntLength,
8
uint256 stake,
9
uint256 totalPositiveVotes,
10
uint256 totalNegativeVotes,
11
uint256 capitalAllocated,
12
uint256 capitalReturned,
13
uint256 duration,
14
uint256 expectedReturn,
15
uint256 maxCapitalRequested,
16
address strategyNFT,
17
uint256 enteredAt,
18
uint256 nav
19
);
Copied!
Parameter
Description
address garden
Garden address
address strategist
Strategist address
uint256 opIntLength
Length of the array of addresses with the integration for each op
uint256 stake
Stake of the strategist in this strategy
uint256 totalPositiveVotes
Total positive votes for the strategy
uint256 totalNegativeVotes
Total negative votes for the strategy
uint256 capitalAllocated
Capital allocated for the strategy in reserveAsset
uint256 capitalReturned
Capital returned by the strategy after finalization in reserveAsset
uint256 duration
Duration of the strategy (in seconds)
uint256 expectedReturn
Expected positive % profit (i.e. 5%) in 18 decimals precision.
uint256 maxCapitalRequested
Amount of max capital to allocate to the strategy
address strategyNFT
Address of the strategyNFT
uint256 enteredAt
Timestamp when the strategy was created
uint256 nav
Net Asset Value of the strategy in reserveAsset

GetStrategyState

Function to get the state of the strategy.
1
function getStrategyState()
2
external
3
view
4
returns (
5
address strategy,
6
bool active,
7
bool dataSet,
8
bool finalized,
9
uint256 executedAt,
10
uint256 exitedAt,
11
uint256 updatedAt
12
);
Copied!
Parameter
Description
address strategy
Address of the strategy
bool active
Whether or not the strategy is active
bool dataSet
Whether or not the strategy data is set
bool finalized
Whether or not the strategy has finalized
uint256 executedAt
Timestamp of initial execution (0 if still not executed)
uint256 exitedAt
Timestamp of strategy finalization (0 if still not finalized)
uint256 updatedAt
Timestamp of last strategy update

GetStrategyRewardsContext

Function to get all relevant context strategy data required for BABL mining program calculations.
1
function getStrategyRewardsContext()
2
external
3
view
4
returns (
5
address strategist,
6
uint256[] memory data,
7
bool[] memory boolData
8
);
Copied!
Parameter
Description
address strategist
Address of the strategist
uin256[] memory data
Context data. See below.
bool[] memory boolData
Boolean context data. See below.
Definition of strategy context data:
1
data[0] Timestamp of when the strategy was executed (executedAt)
2
data[1] Timestamp of when the strategy was finalized (exitedAt)
3
data[2] Timestamp of when the strategy was updated (updatedAt)
4
data[3] Timestamp of when the strategy was created (enteredAt)
5
data[4] Amount of total positive votes for the strategy
6
data[5] Amount of total positive votes against the strategy
7
data[6] Capital allocated to the strategy
8
data[7] Capital returned by the strategy
9
data[8] Expected capital returned (considers expected return)
10
data[9] Strategy Rewards
11
data[10] Profit amount (if any)
12
data[11] Amount difference between real return and expected capital returned
13
data[12] Garden token supply when the strategy was created
14
data[13] Garden token supply when the strategy was finalized
15
data[14] Proportional slippage factor vs. total duration
16
boolData[0] Profits (true) losses (false)
17
boolData[1] If profits where above expectations (true) or below (false)
Copied!

IsStrategyActive

Function to check whether or not the strategy is active.
1
function isStrategyActive() external view returns (bool);
Copied!

GetUserVotes

Function to get specific user votes for a user.
1
function getUserVotes(address _address) external view returns (int256);
Copied!

Strategist

Function to get the strategist address.
1
function strategist() external view returns (address);
Copied!

EnteredAt

Function to get the timestamp when the strategy was created.
1
function enteredAt() external view returns (uint256);
Copied!

EnteredCooldownAt

Function to get the timestamp when the strategy reached quorum.
Other view functions are the following:

Stake

Function to get the stake of the strategist in the strategy.
1
function stake() external view returns (uint256);
Copied!

StrategyRewards

Function to get the assigned strategyRewards from BABL Mining program for the strategy.
1
function strategyRewards() external view returns (uint256);
Copied!

MaxCapitalRequested

Function to get the max capital requested for the strategy in reserveAsset.
1
function maxCapitalRequested() external view returns (uint256);
Copied!

MaxAllocationPercentage

Function to get the maximum capital allocation percentage (%).
1
function maxAllocationPercentage() external view returns (uint256);
Copied!

MaxTradeSlippagePercentage

Function to get the maximum trading slippage in % with 18 decimals precision.
1
function maxTradeSlippagePercentage() external view returns (uint256);
Copied!

MaxGasFeePercentage

Function to get the maximum gas fee percentage to limit the execution cost for the strategy-keeper.
1
function maxGasFeePercentage() external view returns (uint256);
Copied!

ExpectedReturn

Function to get the expected return or expected profits in % with 18 decimals precision (i.e. 5% 5e16)
1
function expectedReturn() external view returns (uint256);
Copied!

Duration

Function to get the duration of the strategy (in seconds).
1
function duration() external view returns (uint256);
Copied!

TotalPositiveVotes

Function to get the total positive votes of the strategy.
1
function totalPositiveVotes() external view returns (uint256);
Copied!

TotalNegativeVotes

Function to get the total negative votes of the strategy.
1
function totalNegativeVotes() external view returns (uint256);
Copied!

CapitalReturned

Function to get the capital returned in reserveAsset.
1
function capitalReturned() external view returns (uint256);
Copied!

CapitalAllocated

Function to get the capital allocated in reserveAsset.
1
function capitalAllocated() external view returns (uint256);
Copied!

Garden

Function to get the garden address the strategy belongs to.
1
function garden() external view returns (IGarden);
Copied!
​