MakinaXModule
Inherits: MakinaXContext, MakinaXGovernable, OracleRegistry, WeirollComponent, SwapComponent, BridgeComponent, ReentrancyGuard, IMakinaXModule
Constants
MAX_BPS
Full scale value in basis points
uint256 private constant MAX_BPS = 10_000;MAX_FEE_RATE
Full scale value for fee rates
uint256 private constant MAX_FEE_RATE = 1e18;Functions
constructor
constructor(address _registry, address _weirollVm) MakinaXContext(_registry) WeirollComponent(_weirollVm);Parameters
| Name | Type | Description |
|---|---|---|
| _registry | address | |
| _weirollVm | address |
initialize
Initializes the module with the given parameters.
function initialize(MakinaXModuleInitParams calldata params, MakinaXModuleServiceParams calldata serviceParams)
external
override
initializer;Parameters
| Name | Type | Description |
|---|---|---|
| params | MakinaXModuleInitParams | The strategy and risk initialization parameters. |
| serviceParams | MakinaXModuleServiceParams | The protocol-controlled service initialization parameters. |
receive
receive() external payable;setFeedRoute
Sets the price feed route for a given token.
Both feeds, if set, must be Chainlink-interface-compliant. The combination of feed1 and feed2 must be able to price the token in the reference currency. If feed2 is set to address(0), the token price in the reference currency is assumed to be returned by feed1.
function setFeedRoute(
address token,
address feed1,
uint256 stalenessThreshold1,
address feed2,
uint256 stalenessThreshold2
) external override nonReentrant onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| token | address | The address of the token for which the price feed route is set. |
| feed1 | address | The address of the first price feed. |
| stalenessThreshold1 | uint256 | The staleness threshold for the first price feed. |
| feed2 | address | The address of the second price feed. Can be set to address(0). |
| stalenessThreshold2 | uint256 | The staleness threshold for the second price feed. Ignored if feed2 is address(0). |
clearFeedRoute
Clears the price feed route for a given token.
Staleness thresholds for the route's feeds are preserved, as the feeds may be used by other routes.
function clearFeedRoute(address token) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| token | address | The address of the token for which the price feed route is cleared. |
setFeedStaleThreshold
Sets the price staleness threshold for a given feed.
function setFeedStaleThreshold(address feed, uint256 newThreshold) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| feed | address | The address of the price feed. |
| newThreshold | uint256 | The value of staleness threshold. |
accountForPosition
Prices a position.
function accountForPosition(IWeirollComponent.Instruction calldata instruction)
external
override
nonReentrant
whenOperational
onlyOperator
returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| instruction | IWeirollComponent.Instruction | The accounting instruction. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 | The new position value. |
accountForPositionBatch
Prices a batch of positions.
function accountForPositionBatch(IWeirollComponent.Instruction[] calldata instructions, uint256[] calldata)
external
override
nonReentrant
whenOperational
onlyOperator
returns (uint256[] memory);Parameters
| Name | Type | Description |
|---|---|---|
| instructions | IWeirollComponent.Instruction[] | The array of accounting instructions. |
| _ | uint256[] | Ignored parameter kept to preserve interface compatibility with Makina Core. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256[] | The new position values. |
managePosition
Manages a position's state through paired management and accounting instructions.
The WALLED mode matrix evaluates three factors to determine required validations:
-
Affected Tokens flow - Sign of the change in the Safe's aggregate value of
mgmtInstruction.affectedTokens -
Debt Position - Whether position represents protocol liability (true) vs asset (false)
-
Position Δ direction - Direction of position value change (increase/decrease/null)
┌──────────────────────┬───────────────┬──────────────────────┬───────────────────────────┐
│ Affected Tokens flow │ Debt Position │ Position Δ direction │ Action │
├──────────────────────┼───────────────┼──────────────────────┼───────────────────────────┤
│ Outflow │ No │ Decrease │ Revert: Invalid direction │
│ Outflow │ Yes │ Increase │ Revert: Invalid direction │
│ Outflow │ No │ Increase / Null │ Minimum Δ Check │
│ Outflow │ Yes │ Decrease / Null │ Minimum Δ Check │
│ Inflow / Null │ No │ Decrease │ Maximum Δ Check │
│ Inflow / Null │ Yes │ Increase │ Maximum Δ Check │
│ Inflow / Null │ No │ Increase / Null │ No check (favorable move) │
│ Inflow / Null │ Yes │ Decrease / Null │ No check (favorable move) │
└──────────────────────┴───────────────┴──────────────────────┴───────────────────────────┘
If acctInstruction is provided, it is executed before and after the management instruction to
compute the new position value and its signed delta.
In WALLED mode, acctInstruction must be provided and value preservation checks are applied using
a validation matrix to prevent economic inconsistencies between position changes and token flows.
function managePosition(
IWeirollComponent.Instruction calldata mgmtInstruction,
IWeirollComponent.Instruction calldata acctInstruction
) external override nonReentrant whenOperational onlyOperator returns (uint256, int256);Parameters
| Name | Type | Description |
|---|---|---|
| mgmtInstruction | IWeirollComponent.Instruction | The management instruction. |
| acctInstruction | IWeirollComponent.Instruction | The accounting instruction. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 | The new position value, or 0 if acctInstruction was not provided. |
| <none> | int256 | The signed position value delta, or 0 if acctInstruction was not provided. |
managePositionBatch
Manages a batch of positions.
Convenience function to manage multiple positions in a single transaction.
function managePositionBatch(
IWeirollComponent.Instruction[] calldata mgmtInstructions,
IWeirollComponent.Instruction[] calldata acctInstructions
) external override nonReentrant whenOperational onlyOperator returns (uint256[] memory, int256[] memory);Parameters
| Name | Type | Description |
|---|---|---|
| mgmtInstructions | IWeirollComponent.Instruction[] | The array of management instructions. |
| acctInstructions | IWeirollComponent.Instruction[] | The array of accounting instructions. |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256[] | The new position values. |
| <none> | int256[] | The changes in the position values. |
manageFlashLoan
Manages flash loan funds.
function manageFlashLoan(IWeirollComponent.Instruction calldata instruction, address token, uint256 amount)
external
override;Parameters
| Name | Type | Description |
|---|---|---|
| instruction | IWeirollComponent.Instruction | The flash loan management instruction. |
| token | address | The loan token. |
| amount | uint256 | The loan amount. |
harvest
Harvests one or multiple positions.
function harvest(IWeirollComponent.Instruction calldata instruction, ISwapComponent.SwapOrder[] calldata swapOrders)
external
override
nonReentrant
whenOperational
onlyOperator;Parameters
| Name | Type | Description |
|---|---|---|
| instruction | IWeirollComponent.Instruction | The harvest instruction. |
| swapOrders | ISwapComponent.SwapOrder[] | The array of swap orders to be executed after the harvest. |
setAllowedInstrRoot
Sets the root of the Merkle tree containing allowed instructions.
function setAllowedInstrRoot(bytes32 newAllowedInstrRoot) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| newAllowedInstrRoot | bytes32 | The new Merkle root. |
setAccountingCurrency
Sets the currency used to value positions.
function setAccountingCurrency(address newAccountingCurrency) external override nonReentrant onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| newAccountingCurrency | address | The new currency. |
setMaxPositionIncreaseLossBps
Sets the maximum allowed relative value loss for position increases while in WALLED mode.
function setMaxPositionIncreaseLossBps(uint256 newMaxPositionIncreaseLossBps) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| newMaxPositionIncreaseLossBps | uint256 | The new maximum value loss in basis points. |
setMaxPositionDecreaseLossBps
Sets the maximum allowed relative value loss for position decreases while in WALLED mode.
function setMaxPositionDecreaseLossBps(uint256 newMaxPositionDecreaseLossBps) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| newMaxPositionDecreaseLossBps | uint256 | The new maximum value loss in basis points. |
setInstrCooldownDuration
Sets the cooldown duration for instruction executions while in WALLED mode.
function setInstrCooldownDuration(uint256 newInstrCooldownDuration) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| newInstrCooldownDuration | uint256 | The new cooldown duration in seconds. |
swap
Swaps tokens on behalf of the Safe using a given swapper.
function swap(ISwapComponent.SwapOrder calldata order) external override nonReentrant whenOperational onlyOperator;Parameters
| Name | Type | Description |
|---|---|---|
| order | ISwapComponent.SwapOrder | The swap params. |
setMaxSwapLossBps
Sets the maximum allowed relative value loss for token swaps while in FENCED or WALLED mode.
function setMaxSwapLossBps(uint256 newMaxSwapLossBps) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| newMaxSwapLossBps | uint256 | The new maximum value loss in basis points. |
setSwapCooldownDuration
Sets the cooldown duration for token swaps while in FENCED or WALLED mode.
function setSwapCooldownDuration(uint256 newSwapCooldownDuration) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| newSwapCooldownDuration | uint256 | The new cooldown duration in seconds. |
setSwapFeeRate
Sets the swap fee rate.
function setSwapFeeRate(uint256 newSwapFeeRate) external override onlyProvider;Parameters
| Name | Type | Description |
|---|---|---|
| newSwapFeeRate | uint256 | The new swap fee rate, 1e18 = 100%. |
setSwapperTargets
Sets approval and execution targets for a given swapper ID.
function setSwapperTargets(uint16 swapperId, address approvalTarget, address executionTarget)
external
override
onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| swapperId | uint16 | The swapper ID. |
| approvalTarget | address | The approval target. |
| executionTarget | address | The execution target. |
sendOutBridgeTransfer
Executes an outgoing bridge transfer.
function sendOutBridgeTransfer(IBridgeComponent.BridgeOrder calldata order)
external
override
nonReentrant
whenOperational
onlyOperator;Parameters
| Name | Type | Description |
|---|---|---|
| order | IBridgeComponent.BridgeOrder | The bridge transfer params. |
setMaxBridgeLossBps
Sets the maximum allowed relative value loss for transfers via this bridge while in FENCED or WALLED mode.
function setMaxBridgeLossBps(uint16 bridgeId, uint256 newMaxBridgeLossBps) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| bridgeId | uint16 | The ID of the bridge. |
| newMaxBridgeLossBps | uint256 | The new maximum value loss in basis points. |
setBridgeCooldownDuration
Sets the cooldown duration for bridge transfers while in FENCED or WALLED mode.
function setBridgeCooldownDuration(uint256 newBridgeCooldownDuration) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| newBridgeCooldownDuration | uint256 | The new cooldown duration in seconds. |
addRecipient
Adds a whitelisted recipient for bridge transfer to a given foreign chain while in FENCED or WALLED mode.
function addRecipient(uint256 foreignChainId, address recipient) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| foreignChainId | uint256 | The foreign chain ID. |
| recipient | address | The address of the recipient. |
removeRecipient
Removes a whitelisted recipient for bridge transfer to a given foreign chain while in FENCED or WALLED mode.
function removeRecipient(uint256 foreignChainId, address recipient) external override onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| foreignChainId | uint256 | The foreign chain ID. |
| recipient | address | The address of the recipient. |
sweepERC20
Sweeps the entire balance of a given ERC20 token to the Safe.
function sweepERC20(address token) external nonReentrant onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| token | address | The address of the ERC20 token to sweep. |
sweepERC721
Sweeps a given ERC721 token to the Safe.
function sweepERC721(address token, uint256 tokenId) external nonReentrant onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| token | address | The address of the ERC721 collection to sweep from. |
| tokenId | uint256 | The id of the ERC721 token to sweep. |
sweepERC6909
Sweeps the entire balance of a given ERC6909 token of type id to the Safe.
function sweepERC6909(address token, uint256 id) external nonReentrant onlySafe;Parameters
| Name | Type | Description |
|---|---|---|
| token | address | The address of the ERC6909 token contract. |
| id | uint256 | The type of the ERC6909 token to sweep. |
sweepNative
Sweeps the entire native currency balance (e.g. ETH) to the Safe.
function sweepNative() external nonReentrant onlySafe;_swapForSafe
Internal logic to execute token swaps on behalf of the Safe using a given swapper.
function _swapForSafe(ISwapComponent.SwapOrder calldata order) internal;Parameters
| Name | Type | Description |
|---|---|---|
| order | ISwapComponent.SwapOrder |
_valueOf
Returns the value of baseTokenAmount of baseToken denominated in quoteToken, using the registered price route.
function _valueOf(address baseToken, address quoteToken, uint256 baseTokenAmount)
internal
view
override(WeirollComponent, SwapComponent)
returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| baseToken | address | |
| quoteToken | address | |
| baseTokenAmount | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |
_refundFlashLoan
Transfers amount of ERC20 token from the Safe to the flash loan module via a module call.
function _refundFlashLoan(address token, uint256 amount, address flashLoanModule) internal override;Parameters
| Name | Type | Description |
|---|---|---|
| token | address | |
| amount | uint256 | |
| flashLoanModule | address |
_pullERC20FromSafe
Transfers amount of ERC20 token from the Safe to the given recipient via a module call.
function _pullERC20FromSafe(address token, uint256 amount, address recipient) internal;Parameters
| Name | Type | Description |
|---|---|---|
| token | address | |
| amount | uint256 | |
| recipient | address |
_checkBps
Performs sanity check on a basis points value.
function _checkBps(uint256 bpsValue) internal pure;Parameters
| Name | Type | Description |
|---|---|---|
| bpsValue | uint256 |
_checkFeeRate
Performs sanity check on a fee rate.
function _checkFeeRate(uint256 rate) internal pure;Parameters
| Name | Type | Description |
|---|---|---|
| rate | uint256 |
_chargeSwapFee
Computes the fee for a given swap output, transfers it to the fee collector, and returns it.
function _chargeSwapFee(address tokenOut, uint256 amountOut) internal returns (uint256);Parameters
| Name | Type | Description |
|---|---|---|
| tokenOut | address | |
| amountOut | uint256 |
Returns
| Name | Type | Description |
|---|---|---|
| <none> | uint256 |