Verified contractPartialUNLICENSED
OrbitProvider
Address0xdc9b4f1bd77efe78b985d4dcfb8b30f5674bffde
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.35
- Same code
Only this contract
Details
- Compiler
- solc 0.8.35+commit.47b9dedd
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- prague
- License
- UNLICENSED
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,441,982
- Creation transaction
- 0x92213dc1a4…b68d0b0bb2
15 files
- src/OrbitProvider.solmain5.19 KB
- lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/proxy/Clones.sol14.52 KB
- lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Create2.sol4.37 KB
- lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Errors.sol896 B
- lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/LowLevelCall.sol5.55 KB
- lib/makina-x/src/interfaces/IBridgeComponent.sol3.26 KB
- lib/makina-x/src/interfaces/IMakinaXContext.sol186 B
- lib/makina-x/src/interfaces/IMakinaXGovernable.sol2.99 KB
- lib/makina-x/src/interfaces/IMakinaXModule.sol3.51 KB
- lib/makina-x/src/interfaces/IMakinaXRegistry.sol2.39 KB
- lib/makina-x/src/interfaces/IModuleFactory.sol3.21 KB
- lib/makina-x/src/interfaces/IOracleRegistry.sol4.19 KB
- lib/makina-x/src/interfaces/ISwapComponent.sol3.28 KB
- lib/makina-x/src/interfaces/IWeirollComponent.sol9.25 KB
- src/interfaces/IOrbitProvider.sol4.73 KB
src/OrbitProvider.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.35;
import {Clones} from "@openzeppelin/contracts/proxy/Clones.sol";
import {IMakinaXContext} from "@makina-x/interfaces/IMakinaXContext.sol";
import {IMakinaXModule} from "@makina-x/interfaces/IMakinaXModule.sol";
import {IMakinaXRegistry} from "@makina-x/interfaces/IMakinaXRegistry.sol";
import {IModuleFactory} from "@makina-x/interfaces/IModuleFactory.sol";
import {IOrbitProvider} from "./interfaces/IOrbitProvider.sol";
/// @title OrbitProvider
/// @notice Deploys Orbit users' MakinaX modules through the official factory with itself as provider, and sets one of
/// three fixed swap fees on them. No upgradeability, no receive/fallback, no stored funds.
contract OrbitProvider is IOrbitProvider {
/// @inheritdoc IOrbitProvider
uint256 public constant FEE_FREE = 2e15;
/// @inheritdoc IOrbitProvider
uint256 public constant FEE_BASIC = 5e14;
/// @inheritdoc IOrbitProvider
uint256 public constant FEE_PRO = 0;
/// @inheritdoc IOrbitProvider
bytes32 public constant ORBIT_REFERRAL_KEY = "dialectic-orbit";
/// @inheritdoc IOrbitProvider
address public immutable ADMIN;
/// @inheritdoc IOrbitProvider
address public immutable FACTORY;
constructor(address admin, address factory) {
ADMIN = admin;
FACTORY = factory;
}
modifier onlyAdmin() {
if (msg.sender != ADMIN) revert NotAdmin();
_;
}
// ------------------------------------------------------------------ createModuleFree
/// @inheritdoc IOrbitProvider
function createModuleFree(IMakinaXModule.MakinaXModuleInitParams calldata params, bytes32 salt)
external
returns (address module)
{
if (params.safe != msg.sender) revert NotSafe();
module = IModuleFactory(FACTORY)
.createModule(
params,
IMakinaXModule.MakinaXModuleServiceParams({
initialProvider: address(this), initialSwapFeeRate: FEE_FREE
}),
_deploySalt(msg.sender, salt),
ORBIT_REFERRAL_KEY
);
emit ModuleDeployed(msg.sender, module, salt);
}
/// @inheritdoc IOrbitProvider
function predict(address safe, bytes32 salt) external view returns (address) {
address implementation = IMakinaXRegistry(IMakinaXContext(FACTORY).registry()).moduleImplementation();
return Clones.predictDeterministicAddress(implementation, _deploySalt(safe, salt), FACTORY);
}
// ------------------------------------------------------------------ fees
/// @inheritdoc IOrbitProvider
function setFeeFree(address module) external onlyAdmin {
_setFee(module, FEE_FREE);
}
/// @inheritdoc IOrbitProvider
function setFeeBasic(address module) external onlyAdmin {
_setFee(module, FEE_BASIC);
}
/// @inheritdoc IOrbitProvider
function setFeePro(address module) external onlyAdmin {
_setFee(module, FEE_PRO);
}
// ------------------------------------------------------------------ admin pass-throughs
/// @inheritdoc IOrbitProvider
function suspend(address module) external onlyAdmin {
_requireOrbitModule(module);
IMakinaXModule(module).suspend();
emit ModuleSuspended(module, true);
}
/// @inheritdoc IOrbitProvider
function unsuspend(address module) external onlyAdmin {
_requireOrbitModule(module);
IMakinaXModule(module).unsuspend();
emit ModuleSuspended(module, false);
}
/// @inheritdoc IOrbitProvider
function setProvider(address module, address newProvider) external onlyAdmin {
if (newProvider == address(0)) revert ZeroProvider();
if (newProvider == address(this)) revert SameProvider();
_requireOrbitModule(module);
IMakinaXModule(module).setProvider(newProvider);
emit ProviderHandedOver(module, newProvider);
}
// ------------------------------------------------------------------ views
/// @inheritdoc IOrbitProvider
function isOrbitModule(address module) public view returns (bool) {
// Registry lookup first: no call reaches `module` unless the factory registered it.
return IModuleFactory(FACTORY).isMakinaXModule(module) && IMakinaXModule(module).provider() == address(this);
}
// ------------------------------------------------------------------ internal
/// @dev `keccak256(abi.encode(safe, salt))`, identical to makina-x `ModuleFactory.createModuleFree`'s namespaced
/// salt, so `predict` equals Orbit's existing free-path predictor.
function _deploySalt(address safe, bytes32 salt) private pure returns (bytes32) {
return keccak256(abi.encode(safe, salt));
}
function _setFee(address module, uint256 fee) private {
_requireOrbitModule(module);
IMakinaXModule(module).setSwapFeeRate(fee);
emit FeeSet(module, IMakinaXModule(module).safe(), fee);
}
function _requireOrbitModule(address module) private view {
if (!isOrbitModule(module)) revert NotOrbitModule(module);
}
}
lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/proxy/Clones.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (proxy/Clones.sol)
pragma solidity ^0.8.20;
import {Create2} from "../utils/Create2.sol";
import {Errors} from "../utils/Errors.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-1167[ERC-1167] is a standard for
* deploying minimal proxy contracts, also known as "clones".
*
* > To simply and cheaply clone contract functionality in an immutable way, this standard specifies
* > a minimal bytecode implementation that delegates all calls to a known, fixed address.
*
* The library includes functions to deploy a proxy using either `create` (traditional deployment) or `create2`
* (salted deterministic deployment). It also includes functions to predict the addresses of clones deployed using the
* deterministic method.
*/
library Clones {
error CloneArgumentsTooLong();
/**
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation`.
*
* This function uses the create opcode, which should never revert.
*
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
*/
function clone(address implementation) internal returns (address instance) {
return clone(implementation, 0);
}
/**
* @dev Same as {xref-Clones-clone-address-}[clone], but with a `value` parameter to send native currency
* to the new contract.
*
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function clone(address implementation, uint256 value) internal returns (address instance) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
assembly ("memory-safe") {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(232, shl(96, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(120, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create(value, 0x09, 0x37)
}
if (instance == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation`.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy
* the clone. Using the same `implementation` and `salt` multiple times will revert, since
* the clones cannot be deployed twice at the same address.
*
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
*/
function cloneDeterministic(address implementation, bytes32 salt) internal returns (address instance) {
return cloneDeterministic(implementation, salt, 0);
}
/**
* @dev Same as {xref-Clones-cloneDeterministic-address-bytes32-}[cloneDeterministic], but with
* a `value` parameter to send native currency to the new contract.
*
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function cloneDeterministic(
address implementation,
bytes32 salt,
uint256 value
) internal returns (address instance) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
assembly ("memory-safe") {
// Cleans the upper 96 bits of the `implementation` word, then packs the first 3 bytes
// of the `implementation` address with the bytecode before the address.
mstore(0x00, or(shr(232, shl(96, implementation)), 0x3d602d80600a3d3981f3363d3d373d3d3d363d73000000))
// Packs the remaining 17 bytes of `implementation` with the bytecode after the address.
mstore(0x20, or(shl(120, implementation), 0x5af43d82803e903d91602b57fd5bf3))
instance := create2(value, 0x09, 0x37, salt)
}
if (instance == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
assembly ("memory-safe") {
let ptr := mload(0x40)
mstore(add(ptr, 0x38), deployer)
mstore(add(ptr, 0x24), 0x5af43d82803e903d91602b57fd5bf3ff)
mstore(add(ptr, 0x14), implementation)
mstore(ptr, 0x3d602d80600a3d3981f3363d3d373d3d3d363d73)
mstore(add(ptr, 0x58), salt)
mstore(add(ptr, 0x78), keccak256(add(ptr, 0x0c), 0x37))
predicted := and(keccak256(add(ptr, 0x43), 0x55), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministic}.
*/
function predictDeterministicAddress(
address implementation,
bytes32 salt
) internal view returns (address predicted) {
return predictDeterministicAddress(implementation, salt, address(this));
}
/**
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation` with custom
* immutable arguments. These are provided through `args` and cannot be changed after deployment. To
* access the arguments within the implementation, use {fetchCloneArgs}.
*
* This function uses the create opcode, which should never revert.
*
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
*/
function cloneWithImmutableArgs(address implementation, bytes memory args) internal returns (address instance) {
return cloneWithImmutableArgs(implementation, args, 0);
}
/**
* @dev Same as {xref-Clones-cloneWithImmutableArgs-address-bytes-}[cloneWithImmutableArgs], but with a `value`
* parameter to send native currency to the new contract.
*
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function cloneWithImmutableArgs(
address implementation,
bytes memory args,
uint256 value
) internal returns (address instance) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
assembly ("memory-safe") {
instance := create(value, add(bytecode, 0x20), mload(bytecode))
}
if (instance == address(0)) {
revert Errors.FailedDeployment();
}
}
/**
* @dev Deploys and returns the address of a clone that mimics the behavior of `implementation` with custom
* immutable arguments. These are provided through `args` and cannot be changed after deployment. To
* access the arguments within the implementation, use {fetchCloneArgs}.
*
* This function uses the create2 opcode and a `salt` to deterministically deploy the clone. Using the same
* `implementation`, `args` and `salt` multiple times will revert, since the clones cannot be deployed twice
* at the same address.
*
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
*/
function cloneDeterministicWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt
) internal returns (address instance) {
return cloneDeterministicWithImmutableArgs(implementation, args, salt, 0);
}
/**
* @dev Same as {xref-Clones-cloneDeterministicWithImmutableArgs-address-bytes-bytes32-}[cloneDeterministicWithImmutableArgs],
* but with a `value` parameter to send native currency to the new contract.
*
* WARNING: This function does not check if `implementation` has code. A clone that points to an address
* without code cannot be initialized. Initialization calls may appear to be successful when, in reality, they
* have no effect and leave the clone uninitialized, allowing a third party to initialize it later.
*
* NOTE: Using a non-zero value at creation will require the contract using this function (e.g. a factory)
* to always have enough balance for new deployments. Consider exposing this function under a payable method.
*/
function cloneDeterministicWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt,
uint256 value
) internal returns (address instance) {
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
return Create2.deploy(value, salt, bytecode);
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministicWithImmutableArgs}.
*/
function predictDeterministicAddressWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt,
address deployer
) internal pure returns (address predicted) {
bytes memory bytecode = _cloneCodeWithImmutableArgs(implementation, args);
return Create2.computeAddress(salt, keccak256(bytecode), deployer);
}
/**
* @dev Computes the address of a clone deployed using {Clones-cloneDeterministicWithImmutableArgs}.
*/
function predictDeterministicAddressWithImmutableArgs(
address implementation,
bytes memory args,
bytes32 salt
) internal view returns (address predicted) {
return predictDeterministicAddressWithImmutableArgs(implementation, args, salt, address(this));
}
/**
* @dev Get the immutable args attached to a clone.
*
* - If `instance` is a clone that was deployed using `clone` or `cloneDeterministic`, this
* function will return an empty array.
* - If `instance` is a clone that was deployed using `cloneWithImmutableArgs` or
* `cloneDeterministicWithImmutableArgs`, this function will return the args array used at
* creation.
* - If `instance` is NOT a clone deployed using this library, the behavior is undefined. This
* function should only be used to check addresses that are known to be clones.
*/
function fetchCloneArgs(address instance) internal view returns (bytes memory) {
bytes memory result = new bytes(instance.code.length - 0x2d); // revert if length is too short
assembly ("memory-safe") {
extcodecopy(instance, add(result, 0x20), 0x2d, mload(result))
}
return result;
}
/**
* @dev Helper that prepares the initcode of the proxy with immutable args.
*
* An assembly variant of this function requires copying the `args` array, which can be efficiently done using
* `mcopy`. Unfortunately, that opcode is not available before cancun. A pure solidity implementation using
* abi.encodePacked is more expensive but also more portable and easier to review.
*
* NOTE: https://eips.ethereum.org/EIPS/eip-170[EIP-170] limits the length of the contract code to 24576 bytes.
* With the proxy code taking 45 bytes, that limits the length of the immutable args to 24531 bytes.
*/
function _cloneCodeWithImmutableArgs(
address implementation,
bytes memory args
) private pure returns (bytes memory) {
if (args.length > 0x5fd3) revert CloneArgumentsTooLong();
return
abi.encodePacked(
hex"61",
uint16(args.length + 0x2d),
hex"3d81600a3d39f3363d3d373d3d3d363d73",
implementation,
hex"5af43d82803e903d91602b57fd5bf3",
args
);
}
}
lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Create2.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.5.0) (utils/Create2.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
import {LowLevelCall} from "./LowLevelCall.sol";
/**
* @dev Helper to make usage of the `CREATE2` EVM opcode easier and safer.
* `CREATE2` can be used to compute in advance the address where a smart
* contract will be deployed, which allows for interesting new mechanisms known
* as 'counterfactual interactions'.
*
* See the https://eips.ethereum.org/EIPS/eip-1014#motivation[EIP] for more
* information.
*/
library Create2 {
/**
* @dev There's no code to deploy.
*/
error Create2EmptyBytecode();
/**
* @dev Deploys a contract using `CREATE2`. The address where the contract
* will be deployed can be known in advance via {computeAddress}.
*
* The bytecode for a contract can be obtained from Solidity with
* `type(contractName).creationCode`.
*
* Requirements:
*
* - `bytecode` must not be empty.
* - `salt` must have not been used for `bytecode` already.
* - the factory must have a balance of at least `amount`.
* - if `amount` is non-zero, `bytecode` must have a `payable` constructor.
*/
function deploy(uint256 amount, bytes32 salt, bytes memory bytecode) internal returns (address addr) {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
if (bytecode.length == 0) {
revert Create2EmptyBytecode();
}
assembly ("memory-safe") {
addr := create2(amount, add(bytecode, 0x20), mload(bytecode), salt)
}
if (addr == address(0)) {
if (LowLevelCall.returnDataSize() == 0) {
revert Errors.FailedDeployment();
} else {
LowLevelCall.bubbleRevert();
}
}
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy}. Any change in the
* `bytecodeHash` or `salt` will result in a new destination address.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash) internal view returns (address) {
return computeAddress(salt, bytecodeHash, address(this));
}
/**
* @dev Returns the address where a contract will be stored if deployed via {deploy} from a contract located at
* `deployer`. If `deployer` is this contract's address, returns the same value as {computeAddress}.
*/
function computeAddress(bytes32 salt, bytes32 bytecodeHash, address deployer) internal pure returns (address addr) {
assembly ("memory-safe") {
let ptr := mload(0x40) // Get free memory pointer
// | | ↓ ptr ... ↓ ptr + 0x0B (start) ... ↓ ptr + 0x20 ... ↓ ptr + 0x40 ... |
// |---------------------|---------------------------------------------------------------------------|
// | bytecodeHash | CCCCCCCCCCCCC...CC |
// | salt | BBBBBBBBBBBBB...BB |
// | deployer | 000000...0000AAAAAAAAAAAAAAAAAAA...AA |
// | 0xFF | FF |
// |---------------------|---------------------------------------------------------------------------|
// | memory | 000000...00FFAAAAAAAAAAAAAAAAAAA...AABBBBBBBBBBBBB...BBCCCCCCCCCCCCC...CC |
// | keccak(start, 0x55) | ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ |
mstore(add(ptr, 0x40), bytecodeHash)
mstore(add(ptr, 0x20), salt)
mstore(ptr, deployer) // Right-aligned with 12 preceding garbage bytes
let start := add(ptr, 0x0b) // The hashed data starts at the final garbage byte which we will set to 0xff
mstore8(start, 0xff)
addr := and(keccak256(start, 0x55), 0xffffffffffffffffffffffffffffffffffffffff)
}
}
}
lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/Errors.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}
lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/utils/LowLevelCall.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.6.0) (utils/LowLevelCall.sol)
pragma solidity ^0.8.20;
/**
* @dev Library of low level call functions that implement different calling strategies to deal with the return data.
*
* WARNING: Using this library requires an advanced understanding of Solidity and how the EVM works. It is recommended
* to use the {Address} library instead.
*/
library LowLevelCall {
/// @dev Performs a Solidity function call using a low level `call` and ignoring the return data.
function callNoReturn(address target, bytes memory data) internal returns (bool success) {
return callNoReturn(target, 0, data);
}
/// @dev Same as {callNoReturn-address-bytes}, but allows specifying the value to be sent in the call.
function callNoReturn(address target, uint256 value, bytes memory data) internal returns (bool success) {
assembly ("memory-safe") {
success := call(gas(), target, value, add(data, 0x20), mload(data), 0x00, 0x00)
}
}
/// @dev Performs a Solidity function call using a low level `call` and returns the first 64 bytes of the result
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
///
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
/// and this function doesn't zero it out.
function callReturn64Bytes(
address target,
bytes memory data
) internal returns (bool success, bytes32 result1, bytes32 result2) {
return callReturn64Bytes(target, 0, data);
}
/// @dev Same as {callReturn64Bytes-address-bytes}, but allows specifying the value to be sent in the call.
function callReturn64Bytes(
address target,
uint256 value,
bytes memory data
) internal returns (bool success, bytes32 result1, bytes32 result2) {
assembly ("memory-safe") {
success := call(gas(), target, value, add(data, 0x20), mload(data), 0x00, 0x40)
result1 := mload(0x00)
result2 := mload(0x20)
}
}
/// @dev Performs a Solidity function call using a low level `staticcall` and ignoring the return data.
function staticcallNoReturn(address target, bytes memory data) internal view returns (bool success) {
assembly ("memory-safe") {
success := staticcall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x00)
}
}
/// @dev Performs a Solidity function call using a low level `staticcall` and returns the first 64 bytes of the result
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
///
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
/// and this function doesn't zero it out.
function staticcallReturn64Bytes(
address target,
bytes memory data
) internal view returns (bool success, bytes32 result1, bytes32 result2) {
assembly ("memory-safe") {
success := staticcall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x40)
result1 := mload(0x00)
result2 := mload(0x20)
}
}
/// @dev Performs a Solidity function call using a low level `delegatecall` and ignoring the return data.
function delegatecallNoReturn(address target, bytes memory data) internal returns (bool success) {
assembly ("memory-safe") {
success := delegatecall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x00)
}
}
/// @dev Performs a Solidity function call using a low level `delegatecall` and returns the first 64 bytes of the result
/// in the scratch space of memory. Useful for functions that return a tuple with two single-word values.
///
/// WARNING: Do not assume that the results are zero if `success` is false. Memory can be already allocated
/// and this function doesn't zero it out.
function delegatecallReturn64Bytes(
address target,
bytes memory data
) internal returns (bool success, bytes32 result1, bytes32 result2) {
assembly ("memory-safe") {
success := delegatecall(gas(), target, add(data, 0x20), mload(data), 0x00, 0x40)
result1 := mload(0x00)
result2 := mload(0x20)
}
}
/// @dev Returns the size of the return data buffer.
function returnDataSize() internal pure returns (uint256 size) {
assembly ("memory-safe") {
size := returndatasize()
}
}
/// @dev Returns a buffer containing the return data from the last call.
function returnData() internal pure returns (bytes memory result) {
assembly ("memory-safe") {
result := mload(0x40)
mstore(result, returndatasize())
returndatacopy(add(result, 0x20), 0x00, returndatasize())
mstore(0x40, add(result, add(0x20, returndatasize())))
}
}
/// @dev Revert with the return data from the last call.
function bubbleRevert() internal pure {
assembly ("memory-safe") {
let fmp := mload(0x40)
returndatacopy(fmp, 0x00, returndatasize())
revert(fmp, returndatasize())
}
}
function bubbleRevert(bytes memory returndata) internal pure {
assembly ("memory-safe") {
revert(add(returndata, 0x20), mload(returndata))
}
}
}
lib/makina-x/src/interfaces/IBridgeComponent.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IBridgeComponent {
event BridgeTransferRecipientAdded(uint256 indexed foreignChainId, address indexed recipient);
event BridgeTransferRecipientRemoved(uint256 indexed foreignChainId, address indexed recipient);
event BridgeCooldownDurationChanged(uint256 oldBridgeCooldownDuration, uint256 newBridgeCooldownDuration);
event MaxBridgeLossBpsChanged(
uint16 indexed bridgeId, uint256 indexed oldMaxBridgeLossBps, uint256 indexed newMaxBridgeLossBps
);
/// @notice Generic bridge transfer params.
/// @param bridgeId The ID of the bridge.
/// @param destinationChainId The destination EVM chain ID.
/// @param recipient The address of the recipient.
/// @param inputToken The address of the input token.
/// @param inputAmount The amount of input token to bridge.
/// @param minOutputAmount The minimum amount of output token expected.
/// @param extraData Extra data specific to each bridge integration.
struct BridgeOrder {
uint16 bridgeId;
uint256 destinationChainId;
address recipient;
address inputToken;
uint256 inputAmount;
uint256 minOutputAmount;
bytes extraData;
}
/// @notice Bridge ID => Max allowed value loss in basis points for transfers via this bridge while in FENCED or WALLED mode.
function getMaxBridgeLossBps(uint16 bridgeId) external view returns (uint256);
/// @notice Foreign Chain ID => Recipient => Whitelisting status while in FENCED or WALLED mode.
function isWhitelistedRecipient(uint256 foreignChainId, address recipient) external view returns (bool);
/// @notice Cooldown duration (in seconds) for bridge transfers while in FENCED or WALLED mode.
function bridgeCooldownDuration() external view returns (uint256);
/// @notice Executes an outgoing bridge transfer.
/// @param order The bridge transfer params.
function sendOutBridgeTransfer(BridgeOrder calldata order) external;
/// @notice Sets the maximum allowed relative value loss for transfers via this bridge while in FENCED or WALLED mode.
/// @param bridgeId The ID of the bridge.
/// @param newMaxBridgeLossBps The new maximum value loss in basis points.
function setMaxBridgeLossBps(uint16 bridgeId, uint256 newMaxBridgeLossBps) external;
/// @notice Sets the cooldown duration for bridge transfers while in FENCED or WALLED mode.
/// @param newBridgeCooldownDuration The new cooldown duration in seconds.
function setBridgeCooldownDuration(uint256 newBridgeCooldownDuration) external;
/// @notice Adds a whitelisted recipient for bridge transfer to a given foreign chain while in FENCED or WALLED mode.
/// @param foreignChainId The foreign chain ID.
/// @param recipient The address of the recipient.
function addRecipient(uint256 foreignChainId, address recipient) external;
/// @notice Removes a whitelisted recipient for bridge transfer to a given foreign chain while in FENCED or WALLED mode.
/// @param foreignChainId The foreign chain ID.
/// @param recipient The address of the recipient.
function removeRecipient(uint256 foreignChainId, address recipient) external;
}
lib/makina-x/src/interfaces/IMakinaXContext.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IMakinaXContext {
/// @notice Address of the registry.
function registry() external view returns (address);
}
lib/makina-x/src/interfaces/IMakinaXGovernable.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IMakinaXGovernable {
/// @notice Operating modes of a module, ordered by increasing restriction.
enum OperatingMode {
OPEN,
FENCED,
WALLED
}
event GuardianAdded(address indexed newGuardian);
event GuardianRemoved(address indexed guardian);
event OperatingModeChanged(OperatingMode indexed mode);
event OperatorAdded(address indexed newOperator);
event OperatorRemoved(address indexed operator);
event Paused(address indexed guardian);
event Unpaused(address indexed guardian);
event ProviderChanged(address indexed oldProvider, address indexed newProvider);
event Suspended();
event Unsuspended();
/// @notice Address of the Safe.
function safe() external view returns (address);
/// @notice Address of the MakinaX service account.
function provider() external view returns (address);
/// @notice Account => Whether the account is an operator.
function isOperator(address account) external view returns (bool);
/// @notice Account => Whether the account is a guardian.
function isGuardian(address account) external view returns (bool);
/// @notice Current operating mode of the contract.
function operatingMode() external view returns (OperatingMode);
/// @notice True if the contract is suspended by the provider, false otherwise.
function suspendedByProvider() external view returns (bool);
/// @notice True if the contract is paused by a guardian, false otherwise.
function paused() external view returns (bool);
/// @notice Sets the provider address.
/// @param newProvider The address of the new provider.
function setProvider(address newProvider) external;
/// @notice Adds a new operator.
/// @param newOperator The address of the new operator.
function addOperator(address newOperator) external;
/// @notice Removes an operator.
/// @param operator The address of the operator to remove.
function removeOperator(address operator) external;
/// @notice Adds a new guardian.
/// @param newGuardian The address of the new guardian.
function addGuardian(address newGuardian) external;
/// @notice Removes a guardian.
/// @param guardian The address of the guardian to remove.
function removeGuardian(address guardian) external;
/// @notice Sets the operating mode.
/// @param newMode The operating mode to set.
function setOperatingMode(OperatingMode newMode) external;
/// @notice Suspends operations. Used by the provider to enforce service restrictions.
function suspend() external;
/// @notice Restores operations after a provider suspension.
function unsuspend() external;
/// @notice Pauses operations. Used by a guardian in case of emergency.
function pause() external;
/// @notice Unpauses operations after an emergency pause.
function unpause() external;
}
lib/makina-x/src/interfaces/IMakinaXModule.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {IBridgeComponent} from "./IBridgeComponent.sol";
import {IMakinaXContext} from "./IMakinaXContext.sol";
import {IMakinaXGovernable} from "./IMakinaXGovernable.sol";
import {IOracleRegistry} from "./IOracleRegistry.sol";
import {ISwapComponent} from "./ISwapComponent.sol";
import {IWeirollComponent} from "./IWeirollComponent.sol";
interface IMakinaXModule is
IMakinaXContext,
IMakinaXGovernable,
IOracleRegistry,
IWeirollComponent,
ISwapComponent,
IBridgeComponent
{
/// @notice Strategy and risk initialization parameters.
/// @param safe The address of the Safe that the module will be connected to.
/// @param initialOperatingMode The initial operating mode of the module.
/// @param initialAllowedInstrRoot The root of the Merkle tree containing the allowed instructions for the module.
/// @param initialMaxPositionIncreaseLossBps The max allowed value loss (in basis points) for position increases while in WALLED mode.
/// @param initialMaxPositionDecreaseLossBps The max allowed value loss (in basis points) for position decreases while in WALLED mode.
/// @param initialInstrCooldownDuration The cooldown duration (in seconds) for position management while in WALLED mode.
/// @param initialMaxSwapLossBps The maximum allowed loss in basis points for swap operations while in FENCED or WALLED mode.
/// @param initialSwapCooldownDuration The cooldown duration (in seconds) for swap operations while in FENCED or WALLED mode.
struct MakinaXModuleInitParams {
address safe;
IMakinaXGovernable.OperatingMode initialOperatingMode;
bytes32 initialAllowedInstrRoot;
uint256 initialMaxPositionIncreaseLossBps;
uint256 initialMaxPositionDecreaseLossBps;
uint256 initialInstrCooldownDuration;
uint256 initialMaxSwapLossBps;
uint256 initialSwapCooldownDuration;
}
/// @notice Protocol-controlled service initialization parameters.
/// @param initialProvider The address of the MakinaX service account.
/// @param initialSwapFeeRate The fee rate for swap operations, 1e18 = 100%.
struct MakinaXModuleServiceParams {
address initialProvider;
uint256 initialSwapFeeRate;
}
/// @notice Initializes the module with the given parameters.
/// @param params The strategy and risk initialization parameters.
/// @param serviceParams The protocol-controlled service initialization parameters.
function initialize(MakinaXModuleInitParams calldata params, MakinaXModuleServiceParams calldata serviceParams)
external;
/// @notice Sweeps the entire balance of a given ERC20 token to the Safe.
/// @param token The address of the ERC20 token to sweep.
function sweepERC20(address token) external;
/// @notice Sweeps a given ERC721 token to the Safe.
/// @param token The address of the ERC721 collection to sweep from.
/// @param tokenId The id of the ERC721 token to sweep.
function sweepERC721(address token, uint256 tokenId) external;
/// @notice Sweeps the entire balance of a given ERC6909 token of type id to the Safe.
/// @param token The address of the ERC6909 token contract.
/// @param id The type of the ERC6909 token to sweep.
function sweepERC6909(address token, uint256 id) external;
/// @notice Sweeps the entire native currency balance (e.g. ETH) to the Safe.
function sweepNative() external;
}
lib/makina-x/src/interfaces/IMakinaXRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface IMakinaXRegistry {
event BridgeEncoderChanged(
uint16 indexed bridgeId, address indexed oldBridgeEncoder, address indexed newBridgeEncoder
);
event FeeCollectorChanged(address indexed oldFeeCollector, address indexed newFeeCollector);
event FlashLoanModuleChanged(address indexed oldFlashLoanModule, address indexed newFlashLoanModule);
event ModuleFactoryChanged(address indexed oldModuleFactory, address indexed newModuleFactory);
event ModuleImplementationChanged(address indexed oldModuleImplementation, address indexed newModuleImplementation);
/// @notice Address of the MakinaXModule factory.
function moduleFactory() external view returns (address);
/// @notice Address of the MakinaXModule implementation.
function moduleImplementation() external view returns (address);
/// @notice Address of the fee collector.
function feeCollector() external view returns (address);
/// @notice Address of the flash loan module.
function flashLoanModule() external view returns (address);
/// @notice Bridge ID => Address of the corresponding bridge encoder.
function getBridgeEncoder(uint16 bridgeId) external view returns (address);
/// @notice Sets the address of the MakinaXModule factory.
/// @param newModuleFactory The address of the new MakinaXModule factory.
function setModuleFactory(address newModuleFactory) external;
/// @notice Sets the MakinaXModule implementation for future deployments.
/// @param newImplementation The address of the new implementation contract.
function setModuleImplementation(address newImplementation) external;
/// @notice Sets the address of the fee collector.
/// @param newFeeCollector The address of the new fee collector.
function setFeeCollector(address newFeeCollector) external;
/// @notice Sets the address of the flash loan module.
/// @param newFlashLoanModule The address of the new flash loan module.
function setFlashLoanModule(address newFlashLoanModule) external;
/// @notice Sets a bridge encoder instance for a given bridge ID.
/// @param bridgeId The ID of the bridge.
/// @param bridgeEncoder The address of the new bridge encoder instance.
function setBridgeEncoder(uint16 bridgeId, address bridgeEncoder) external;
}
lib/makina-x/src/interfaces/IModuleFactory.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {IMakinaXModule} from "./IMakinaXModule.sol";
interface IModuleFactory {
event MakinaXModuleCreated(address indexed module, address indexed implementation, bytes32 indexed referralKey);
event DefaultProviderChanged(address indexed oldDefaultProvider, address indexed newDefaultProvider);
event DefaultSwapFeeRateChanged(uint256 oldDefaultSwapFeeRate, uint256 newDefaultSwapFeeRate);
event FreeDeploymentChanged(bool enabled);
/// @notice Module => Whether the module was deployed by this factory.
function isMakinaXModule(address module) external view returns (bool);
/// @notice Provider enforced by default on modules deployed through the free path.
function defaultProvider() external view returns (address);
/// @notice Swap fee rate enforced by default on modules deployed through the free path, 1e18 = 100%.
function defaultSwapFeeRate() external view returns (uint256);
/// @notice Whether free module deployment is currently enabled.
function freeDeployment() external view returns (bool);
/// @notice Deploys a new MakinaXModule clone with caller-provided service parameters.
/// @dev Restricted to authorized deployers.
/// @param params The strategy and risk initialization parameters for the MakinaXModule.
/// @param serviceParams The protocol-controlled service initialization parameters.
/// @param salt The salt used for deterministic deployment of the module clone.
/// @param referralKey The referral key associated with the module creation.
/// @return The address of the newly deployed MakinaXModule.
function createModule(
IMakinaXModule.MakinaXModuleInitParams calldata params,
IMakinaXModule.MakinaXModuleServiceParams calldata serviceParams,
bytes32 salt,
bytes32 referralKey
) external returns (address);
/// @notice Deploys a new MakinaXModule clone, with service parameters enforced by the factory.
/// @dev Callable by anyone while free deployment is enabled.
/// @param params The strategy and risk initialization parameters for the MakinaXModule.
/// @param salt The caller-scoped salt used for deterministic deployment of the module clone.
/// @param referralKey The referral key associated with the module creation.
/// @return The address of the newly deployed MakinaXModule.
function createModuleFree(IMakinaXModule.MakinaXModuleInitParams calldata params, bytes32 salt, bytes32 referralKey)
external
returns (address);
/// @notice Sets the provider enforced on free deployment.
/// @param newDefaultProvider The new default provider address.
function setDefaultProvider(address newDefaultProvider) external;
/// @notice Sets the swap fee rate enforced on free deployment.
/// @param newDefaultSwapFeeRate The new default swap fee rate, 1e18 = 100%.
function setDefaultSwapFeeRate(uint256 newDefaultSwapFeeRate) external;
/// @notice Enables or disables free module deployment.
/// @param enabled True to enable free deployment, false to disable it.
function setFreeDeployment(bool enabled) external;
}
lib/makina-x/src/interfaces/IOracleRegistry.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
/// @notice An aggregator of Chainlink price feeds that prices tokens in a reference currency (e.g., USD) using up to two feeds.
/// If a direct feed between a base token and the reference currency does not exist, it combines two feeds to compute the price.
///
/// Example:
/// To price Token A in Token B:
/// - If a feed for Token A -> Reference Currency exists, the registry uses that feed.
/// - If Token B lacks a direct feed to the Reference Currency, but feeds for Token B -> Intermediate Token and
/// Intermediate Token -> Reference Currency exist, the registry combines these feeds to derive the price.
/// - Finally, the price Token A -> Token B is calculated using both tokens' individual prices in the reference currency.
///
interface IOracleRegistry {
event FeedRouteCleared(address indexed token);
event FeedRouteRegistered(address indexed token, address indexed feed1, address indexed feed2);
event FeedStaleThresholdChanged(address indexed feed, uint256 oldThreshold, uint256 newThreshold);
struct FeedRoute {
address feed1;
address feed2;
}
/// @notice Feed => Staleness threshold in seconds
function getFeedStaleThreshold(address feed) external view returns (uint256);
/// @notice Token => Is feed route registered for the token
function isFeedRouteRegistered(address token) external view returns (bool);
/// @notice Gets the price feed route for a given token.
/// @param token The address of the token for which the price feed route is requested.
/// @return feed1 The address of the first price feed.
/// @return feed2 The address of the optional second price feed.
function getFeedRoute(address token) external view returns (address, address);
/// @notice Returns the price of one unit of the given token in terms of the reference currency.
/// @param baseToken The address of the token for which the price is requested.
/// @return price The price of baseToken denominated in the reference currency (expressed in 18 decimals).
function getReferencePrice(address baseToken) external view returns (uint256);
/// @notice Returns the price of one unit of baseToken in terms of quoteToken.
/// @param baseToken The address of the token for which the price is requested.
/// @param quoteToken The address of the token in which the price is quoted.
/// @return price The price of baseToken denominated in quoteToken (expressed in quoteToken decimals).
function getPrice(address baseToken, address quoteToken) external view returns (uint256);
/// @notice Sets the price feed route for a given token.
/// @dev 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.
/// @param token The address of the token for which the price feed route is set.
/// @param feed1 The address of the first price feed.
/// @param stalenessThreshold1 The staleness threshold for the first price feed.
/// @param feed2 The address of the second price feed. Can be set to address(0).
/// @param stalenessThreshold2 The staleness threshold for the second price feed. Ignored if feed2 is address(0).
function setFeedRoute(
address token,
address feed1,
uint256 stalenessThreshold1,
address feed2,
uint256 stalenessThreshold2
) external;
/// @notice Clears the price feed route for a given token.
/// @dev Staleness thresholds for the route's feeds are preserved, as the feeds may be used by other routes.
/// @param token The address of the token for which the price feed route is cleared.
function clearFeedRoute(address token) external;
/// @notice Sets the price staleness threshold for a given feed.
/// @param feed The address of the price feed.
/// @param newThreshold The value of staleness threshold.
function setFeedStaleThreshold(address feed, uint256 newThreshold) external;
}
lib/makina-x/src/interfaces/ISwapComponent.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
interface ISwapComponent {
event MaxSwapLossBpsChanged(uint256 oldMaxSwapLossBps, uint256 newMaxSwapLossBps);
event Swap(
uint16 indexed swapperId,
address indexed inputToken,
address indexed outputToken,
uint256 inputAmount,
uint256 outputAmount
);
event SwapCooldownDurationChanged(uint256 oldSwapCooldownDuration, uint256 newSwapCooldownDuration);
event SwapFeeRateChanged(uint256 oldSwapFeeRate, uint256 newSwapFeeRate);
event SwapperTargetsSet(uint16 indexed swapperId, address approvalTarget, address executionTarget);
struct SwapperTargets {
address approvalTarget;
address executionTarget;
}
/// @notice Generic swap params.
/// @param swapperId The ID of the external swap protocol.
/// @param data The swap calldata to pass to the swapper's execution target.
/// @param inputToken The input token.
/// @param outputToken The output token.
/// @param inputAmount The input amount.
/// @param minOutputAmount The minimum expected output amount.
struct SwapOrder {
uint16 swapperId;
bytes data;
address inputToken;
address outputToken;
uint256 inputAmount;
uint256 minOutputAmount;
}
/// @notice Max allowed value loss (in basis points) for token swaps while in FENCED or WALLED mode.
function maxSwapLossBps() external view returns (uint256);
/// @notice Cooldown duration (in seconds) for token swaps while in FENCED or WALLED mode.
function swapCooldownDuration() external view returns (uint256);
/// @notice Swap fee rate, 1e18 = 100%.
function swapFeeRate() external view returns (uint256);
/// @notice Returns approval and execution targets for a given swapper ID.
/// @param swapperId The swapper ID.
/// @return approvalTarget The approval target.
/// @return executionTarget The execution target.
function getSwapperTargets(uint16 swapperId) external view returns (address approvalTarget, address executionTarget);
/// @notice Swaps tokens on behalf of the Safe using a given swapper.
/// @param order The swap params.
function swap(SwapOrder calldata order) external;
/// @notice Sets the maximum allowed relative value loss for token swaps while in FENCED or WALLED mode.
/// @param newMaxSwapLossBps The new maximum value loss in basis points.
function setMaxSwapLossBps(uint256 newMaxSwapLossBps) external;
/// @notice Sets the cooldown duration for token swaps while in FENCED or WALLED mode.
/// @param newSwapCooldownDuration The new cooldown duration in seconds.
function setSwapCooldownDuration(uint256 newSwapCooldownDuration) external;
/// @notice Sets the swap fee rate.
/// @param newSwapFeeRate The new swap fee rate, 1e18 = 100%.
function setSwapFeeRate(uint256 newSwapFeeRate) external;
/// @notice Sets approval and execution targets for a given swapper ID.
/// @param swapperId The swapper ID.
/// @param approvalTarget The approval target.
/// @param executionTarget The execution target.
function setSwapperTargets(uint16 swapperId, address approvalTarget, address executionTarget) external;
}
lib/makina-x/src/interfaces/IWeirollComponent.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.28;
import {ISwapComponent} from "./ISwapComponent.sol";
interface IWeirollComponent {
event AllowedInstrRootChanged(bytes32 indexed oldRoot, bytes32 indexed newRoot);
event AccountingCurrencyChanged(address indexed oldAccountingCurrency, address indexed newAccountingCurrency);
event InstrCooldownDurationChanged(uint256 oldInstrCooldownDuration, uint256 newInstrCooldownDuration);
event MaxPositionIncreaseLossBpsChanged(
uint256 oldMaxPositionIncreaseLossBps, uint256 newMaxPositionIncreaseLossBps
);
event MaxPositionDecreaseLossBpsChanged(
uint256 oldMaxPositionDecreaseLossBps, uint256 newMaxPositionDecreaseLossBps
);
event PositionManaged(bool indexed withValuation, bool indexed guarded, uint256 indexed positionId, uint256 value);
enum InstructionType {
MANAGEMENT,
ACCOUNTING,
HARVEST,
FLASHLOAN_MANAGEMENT
}
/// @notice Instruction parameters.
/// @param positionId The ID of the involved position.
/// @param isDebt Whether the position is a debt.
/// @param groupId The ID of the position accounting group.
/// Set to 0 if the instruction is not of type ACCOUNTING, or if the involved position is ungrouped.
/// @param instructionType The type of the instruction.
/// @param affectedTokens The array of affected tokens.
/// @param positionTokens The array of position tokens.
/// @param commands The array of commands.
/// @param state The array of state.
/// @param stateBitmap The state bitmap.
/// @param merkleProof The array of Merkle proof elements.
struct Instruction {
uint256 positionId;
bool isDebt;
uint256 groupId;
InstructionType instructionType;
address[] affectedTokens;
address[] positionTokens;
bytes32[] commands;
bytes[] state;
uint128 stateBitmap;
bytes32[] merkleProof;
}
/// @notice Address of the Weiroll VM.
function weirollVm() external view returns (address);
/// @notice Root of the Merkle tree containing allowed instructions.
function allowedInstrRoot() external view returns (bytes32);
/// @notice Currency used to value positions.
/// @dev If set to address(0), the reference currency of the OracleRegistry is used.
function accountingCurrency() external view returns (address);
/// @notice Max allowed value loss (in basis points) when increasing a position while in WALLED mode.
function maxPositionIncreaseLossBps() external view returns (uint256);
/// @notice Max allowed value loss (in basis points) when decreasing a position while in WALLED mode.
function maxPositionDecreaseLossBps() external view returns (uint256);
/// @notice Cooldown duration for instruction executions in seconds.
function instrCooldownDuration() external view returns (uint256);
/// @notice Prices a position.
/// @param instruction The accounting instruction.
/// @return value The new position value.
function accountForPosition(Instruction calldata instruction) external returns (uint256 value);
/// @notice Prices a batch of positions.
/// @param instructions The array of accounting instructions.
/// @param groupIds Ignored parameter kept to preserve interface compatibility with Makina Core.
/// @return values The new position values.
function accountForPositionBatch(Instruction[] calldata instructions, uint256[] calldata groupIds)
external
returns (uint256[] memory values);
/// @notice Manages a position's state through paired management and accounting instructions.
/// @dev If `acctInstruction` is provided, it is executed before and after the management instruction to
/// compute the new position value and its signed delta.
/// @dev 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.
///
/// 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) │
/// └──────────────────────┴───────────────┴──────────────────────┴───────────────────────────┘
///
/// @param mgmtInstruction The management instruction.
/// @param acctInstruction The accounting instruction.
/// @return value The new position value, or 0 if `acctInstruction` was not provided.
/// @return change The signed position value delta, or 0 if `acctInstruction` was not provided.
function managePosition(Instruction calldata mgmtInstruction, Instruction calldata acctInstruction)
external
returns (uint256 value, int256 change);
/// @notice Manages a batch of positions.
/// @dev Convenience function to manage multiple positions in a single transaction.
/// @param mgmtInstructions The array of management instructions.
/// @param acctInstructions The array of accounting instructions.
/// @return values The new position values.
/// @return changes The changes in the position values.
function managePositionBatch(Instruction[] calldata mgmtInstructions, Instruction[] calldata acctInstructions)
external
returns (uint256[] memory values, int256[] memory changes);
/// @notice Manages flash loan funds.
/// @param instruction The flash loan management instruction.
/// @param token The loan token.
/// @param amount The loan amount.
function manageFlashLoan(Instruction calldata instruction, address token, uint256 amount) external;
/// @notice Harvests one or multiple positions.
/// @param instruction The harvest instruction.
/// @param swapOrders The array of swap orders to be executed after the harvest.
function harvest(Instruction calldata instruction, ISwapComponent.SwapOrder[] calldata swapOrders) external;
/// @notice Sets the root of the Merkle tree containing allowed instructions.
/// @param newAllowedInstrRoot The new Merkle root.
function setAllowedInstrRoot(bytes32 newAllowedInstrRoot) external;
/// @notice Sets the currency used to value positions.
/// @param newAccountingCurrency The new currency.
function setAccountingCurrency(address newAccountingCurrency) external;
/// @notice Sets the maximum allowed relative value loss for position increases while in WALLED mode.
/// @param newMaxPositionIncreaseLossBps The new maximum value loss in basis points.
function setMaxPositionIncreaseLossBps(uint256 newMaxPositionIncreaseLossBps) external;
/// @notice Sets the maximum allowed relative value loss for position decreases while in WALLED mode.
/// @param newMaxPositionDecreaseLossBps The new maximum value loss in basis points.
function setMaxPositionDecreaseLossBps(uint256 newMaxPositionDecreaseLossBps) external;
/// @notice Sets the cooldown duration for instruction executions while in WALLED mode.
/// @param newInstrCooldownDuration The new cooldown duration in seconds.
function setInstrCooldownDuration(uint256 newInstrCooldownDuration) external;
}
src/interfaces/IOrbitProvider.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.35;
import {IMakinaXModule} from "@makina-x/interfaces/IMakinaXModule.sol";
/// @title IOrbitProvider
/// @notice Deployer and MakinaX provider of Orbit users' modules. Sets one of three fixed swap fees per module and
/// passes provider-only admin calls through. Holds no funds and has no owner beyond its immutables.
interface IOrbitProvider {
/// @notice `createModuleFree` was called by an address other than `params.safe`.
error NotSafe();
/// @notice Fee setter or admin pass-through called by an address other than `ADMIN`.
error NotAdmin();
/// @notice `module` is not registered by `FACTORY`, or its provider is not this contract.
error NotOrbitModule(address module);
/// @notice `setProvider` was given the zero address.
error ZeroProvider();
/// @notice `setProvider` was given this contract, which would be a silent no-op on the module.
error SameProvider();
/// @notice A module was deployed for `safe` with the caller-supplied raw `salt`.
event ModuleDeployed(address indexed safe, address indexed module, bytes32 salt);
/// @notice The swap fee of `module` (owned by `safe`) is now `fee` (1e18 = 100%). The complete fee record.
event FeeSet(address indexed module, address indexed safe, uint256 fee);
/// @notice `module` was suspended (`true`) or unsuspended (`false`) by this provider.
event ModuleSuspended(address indexed module, bool suspended);
/// @notice This contract handed the provider role of `module` to `newProvider`.
event ProviderHandedOver(address indexed module, address indexed newProvider);
/// @notice Pro receiver Safe: the only caller of the fee setters and admin pass-throughs.
function ADMIN() external view returns (address);
/// @notice Official MakinaX module factory: the only factory this contract deploys through and recognises.
function FACTORY() external view returns (address);
/// @notice Free tier swap fee, 2e15 (20 bps). Also the reset value.
function FEE_FREE() external view returns (uint256);
/// @notice Basic tier swap fee, 5e14 (5 bps).
function FEE_BASIC() external view returns (uint256);
/// @notice Pro tier swap fee, 0.
function FEE_PRO() external view returns (uint256);
/// @notice Referral key passed to the factory for every module: ASCII "dialectic-orbit", right-padded. Referrals
/// are tracked off-chain with access codes, not per module.
function ORBIT_REFERRAL_KEY() external view returns (bytes32);
/// @notice Deploys a module for `params.safe` (must be the caller) with this contract as provider and `FEE_FREE`.
/// @dev Deploys through `FACTORY.createModule` (role 2) with `ORBIT_REFERRAL_KEY`. Same parameters as makina-x
/// `IModuleFactory.createModuleFree` minus the referral key.
/// @param params Strategy and risk initialization parameters; `params.safe` must equal `msg.sender`.
/// @param salt Raw caller salt; the factory receives `keccak256(abi.encode(msg.sender, salt))`, the same
/// namespaced salt the factory's own free path uses. A Safe that already used `FACTORY.createModuleFree`
/// with this salt occupies the address and this call reverts; only that Safe can cause it.
/// @return module The new module address.
function createModuleFree(IMakinaXModule.MakinaXModuleInitParams calldata params, bytes32 salt)
external
returns (address module);
/// @notice Address `createModuleFree` would return for `safe` and `salt`, using the registry's current module
/// implementation. Equals the factory free path's own prediction for the same Safe and salt.
function predict(address safe, bytes32 salt) external view returns (address);
/// @notice Sets `module`'s swap fee to `FEE_FREE`. `ADMIN` only.
function setFeeFree(address module) external;
/// @notice Sets `module`'s swap fee to `FEE_BASIC`. `ADMIN` only.
function setFeeBasic(address module) external;
/// @notice Sets `module`'s swap fee to `FEE_PRO`. `ADMIN` only.
function setFeePro(address module) external;
/// @notice Suspends `module`. `ADMIN` only.
function suspend(address module) external;
/// @notice Unsuspends `module`. `ADMIN` only.
function unsuspend(address module) external;
/// @notice Hands `module`'s provider role to `newProvider` (non-zero, not this contract). `ADMIN` only.
function setProvider(address module, address newProvider) external;
/// @notice Whether `module` is registered by `FACTORY` and its provider is this contract.
function isOrbitModule(address module) external view returns (bool);
}
Compiler settingsShow
{
"viaIR": false,
"metadata": {
"appendCBOR": false,
"bytecodeHash": "none",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"viaSSACFG": false,
"evmVersion": "prague",
"remappings": [
"forge-std/=lib/forge-std/src/",
"@makina-x/=lib/makina-x/src/",
"@openzeppelin/contracts/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/",
"@openzeppelin/contracts-upgradeable/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/contracts/",
"@enso-weiroll/=lib/makina-x/lib/enso-weiroll/contracts/",
"lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:erc4626-tests/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:erc4626-tests/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"lib/makina-x/lib/openzeppelin-contracts-upgradeable/:erc4626-tests/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"lib/makina-x/lib/openzeppelin-contracts-upgradeable/:erc4626-tests/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"lib/makina-x/lib/openzeppelin-contracts-upgradeable/:halmos-cheatcodes/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"lib/makina-x/lib/openzeppelin-contracts-upgradeable/:halmos-cheatcodes/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"enso-weiroll/=lib/makina-x/lib/enso-weiroll/contracts/",
"erc4626-tests/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"makina-x/=lib/makina-x/",
"openzeppelin-contracts-upgradeable/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/makina-x/lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/"
],
"experimental": false
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.