Skip to main content

BaseCreatorStrategy

Git Source

Inherits: IStrategy, Ownable, ReentrancyGuard

Title: BaseCreatorStrategy

Author: 0xakita.eth (CreatorVault)

Base strategy contract for CreatorOVault yield strategies

SINGLE-TOKEN PATTERN:

  • Each strategy manages one token (the Creator Coin)
  • Compatible with the IStrategy interface
  • Inherit this contract and implement _deployFunds() and _freeFunds()

ARCHITECTURE: CreatorOVault → BaseCreatorStrategy → [CharmStrategy, AaveStrategy, etc.] └──> External yield protocols

REQUIRED OVERRIDES:

  • _deployFunds(amount) - Deploy funds to yield source
  • _freeFunds(amount) - Withdraw from yield source
  • _totalDeployed() - Get total value in yield source
  • _harvest() - Collect yields

State Variables

ASSET

The underlying token this strategy manages

IERC20 public immutable ASSET

vault

The vault this strategy serves

address public vault

strategyName

Strategy metadata

string public strategyName

isActive_

Strategy state

bool public isActive_

isEmergencyMode

bool public isEmergencyMode

totalDeposited

Accounting

uint256 public totalDeposited

totalWithdrawn

uint256 public totalWithdrawn

totalHarvested

uint256 public totalHarvested

lastHarvest

Performance

uint256 public lastHarvest

lastDeposit

uint256 public lastDeposit

Functions

onlyVault

modifier onlyVault() ;

whenActive

modifier whenActive() ;

whenNotEmergency

modifier whenNotEmergency() ;

constructor

Initialize the strategy

constructor(address _asset, address _vault, string memory _name, address _owner) Ownable(_owner);

Parameters

NameTypeDescription
_assetaddressThe token this strategy manages (Creator Coin)
_vaultaddressThe CreatorOVault address
_namestringStrategy name for identification
_owneraddressOwner address

isActive

Check if strategy is active

function isActive() external view override returns (bool);

asset

Get the underlying asset

function asset() external view override returns (address);

getTotalAssets

Get total assets managed by this strategy

function getTotalAssets() external view override returns (uint256);

deposit

Deposit tokens into the strategy

function deposit(uint256 amount)
external
override
nonReentrant
onlyVault
whenActive
whenNotEmergency
returns (uint256 deposited);

Parameters

NameTypeDescription
amountuint256Amount to deposit

Returns

NameTypeDescription
depositeduint256Actual amount deposited

withdraw

Withdraw tokens from the strategy

function withdraw(uint256 amount) external override nonReentrant onlyVault returns (uint256 withdrawn);

Parameters

NameTypeDescription
amountuint256Amount to withdraw

Returns

NameTypeDescription
withdrawnuint256Actual amount withdrawn

emergencyWithdraw

Emergency withdraw all funds

function emergencyWithdraw() external override nonReentrant onlyVault returns (uint256 withdrawn);

Returns

NameTypeDescription
withdrawnuint256Total amount withdrawn

harvest

Harvest yields from the strategy

function harvest() external override nonReentrant onlyVault whenActive whenNotEmergency returns (uint256 profit);

Returns

NameTypeDescription
profituint256Amount harvested

rebalance

Rebalance strategy position

function rebalance() external override nonReentrant onlyVault whenActive whenNotEmergency;

_deployFunds

Deploy funds to yield source

Override in child contract

function _deployFunds(uint256 amount) internal virtual returns (uint256 deployed);

Parameters

NameTypeDescription
amountuint256Amount to deploy

Returns

NameTypeDescription
deployeduint256Actual amount deployed

_freeFunds

Free funds from yield source

Override in child contract

function _freeFunds(uint256 amount) internal virtual returns (uint256 freed);

Parameters

NameTypeDescription
amountuint256Amount to free

Returns

NameTypeDescription
freeduint256Actual amount freed

_totalDeployed

Get total value deployed to yield source

Override in child contract

function _totalDeployed() internal view virtual returns (uint256);

_harvest

Harvest yields

Override in child contract

function _harvest() internal virtual returns (uint256 profit);

Returns

NameTypeDescription
profituint256Amount of profit harvested

_rebalance

Rebalance position (optional)

Override if needed, default does nothing

function _rebalance() internal virtual;

setVault

Set new vault address

function setVault(address _vault) external onlyOwner;

activate

Activate strategy

function activate() external onlyOwner;

deactivate

Deactivate strategy

function deactivate() external onlyOwner;

enableEmergencyMode

Enable emergency mode

function enableEmergencyMode() external onlyOwner;

disableEmergencyMode

Disable emergency mode

function disableEmergencyMode() external onlyOwner;

rescueToken

Rescue stuck tokens (not the main asset)

function rescueToken(address token, uint256 amount, address to) external onlyOwner;

getStats

Get strategy statistics

function getStats()
external
view
returns (
uint256 _totalDeposited,
uint256 _totalWithdrawn,
uint256 _totalHarvested,
uint256 _lastHarvest,
uint256 _lastDeposit,
uint256 _currentBalance,
uint256 _deployedBalance
);

localBalance

Get local token balance

function localBalance() external view returns (uint256);

deployedBalance

Get deployed balance

function deployedBalance() external view returns (uint256);

Events

VaultSet

event VaultSet(address indexed vault);

StrategyActivated

event StrategyActivated();

StrategyDeactivated

event StrategyDeactivated();

EmergencyModeEnabled

event EmergencyModeEnabled();

EmergencyModeDisabled

event EmergencyModeDisabled();

Errors

NotVault

error NotVault();

NotActive

error NotActive();

EmergencyMode

error EmergencyMode();

ZeroAmount

error ZeroAmount();

ZeroAddress

error ZeroAddress();