Mure: Smart Contract Suite

Welcome to Mure, a comprehensive suite of smart contracts designed for easy transactions regarding fundraising, distribution, and payments. Our project is built with security, efficiency, and scalability in mind, leveraging the robust capabilities of the Ethereum blockchain.

About

Mure aims to make safe, scalable and trustless transactions available for anyone, even if they don't have blockchain experience. Developed using Solidity, our contracts are meticulously designed to ensure secure, gas-efficient, and self-custodial management of funds and payments.

Powered by Foundry

Our development process is empowered by Foundry, a blazing-fast, portable, and modular toolkit for Ethereum application development. Foundry allows us to:

  • Test: Conduct comprehensive tests with flexibility and high performance.
  • Build: Compile Solidity code swiftly, ensuring rapid development cycles.
  • Deploy: Streamline smart contract deployment with precise control over network interactions.

Features

  • Fundraising: Collect funds from various sources and get automatic, on-chain bookkeeping for easy dispersement of on-chain assets.
  • Distribution: Distribute funds through airdrops or claims, leveraging the data stored from the deposits made by the customer.
  • Payments: Leverage the blockchain for the on-chain security and use it as a payments confirmation layer to hook into your off-chain store or service business.

API Documentation

Our APIs are used to interface with your smart contract and help with off-chain needs like KYC, AML, allowlisting, and so on.

For detailed information about our API documentation and how to interact with them, please refer to the API Documentation.

License

Mure is released under the BUSL-1.1. See the LICENSE file for more details.

Contact

For any inquiries or to discuss collaboration, please reach out to [email protected].

Contents

Chargeable

Git Source

Author: Mure

Interface for the fees related functionalities for ClaimPlugin

Functions

calculateFee

function calculateFee(address poolContract, string calldata poolName, address depositor)
    external
    view
    returns (uint256);

Claimable

Git Source

Inherits: IERC165

Author: Mure

Interface for claim functionality of pools with support for ERC-165 detection.

Functions

claim

function claim(ClaimRecord calldata claim) external returns (uint256 depositDelta, uint256 claimDelta);

deltas

function deltas(ClaimRecord calldata claimRecord)
    external
    pure
    returns (uint256 depositDelta, uint256 claimDelta, uint256 fee);

Events

Claim

event Claim(address indexed depositor, uint256 indexed amount);

Errors

BalanceMismatch

error BalanceMismatch(uint256 collectedFunds, uint256 reserves);

Structs

ClaimRecord

struct ClaimRecord {
    address claimCurrency;
    address depositor;
    uint256 share;
    uint256 supply;
    uint256 claimReserves;
    uint256 depositReserves;
    uint256 deposit;
    uint256 totalCollected;
    string poolName;
    address custodian;
    uint16 feePercentage;
}

Config

Git Source

Inherits: IERC165

Author: Mure

Interface for MureConfig core with support for ERC-165 detection.

Functions

getAppDelegate

Must not revert, should return address(0) incase delegate does not exist

function getAppDelegate(address poolApp) external returns (address);

setAppDelegate

function setAppDelegate(address poolApp, address delegate) external;

verifyMureSignature

function verifyMureSignature(bytes32 structHash, bytes memory signature) external;

toggleWhitelistedSigner

function toggleWhitelistedSigner(address mureSigner_) external;

getFeeContractAddress

function getFeeContractAddress() external view returns (address);

setMureFeeContract

function setMureFeeContract(address feeContractAddress) external;

getPoolFee

function getPoolFee(address poolApp, string calldata poolName, uint256 amount)
    external
    returns (uint256 feeAmount, address recipient);

PoolConfig

Git Source

struct PoolConfig {
    uint256 claimReserves;
    uint256 depositReserves;
    uint256 supply;
    uint16 plugins;
    uint16 feePercentage;
    address claimCurrency;
}

DelegateErrorReason

Git Source

enum DelegateErrorReason {
    TRANSFER_FAILURE,
    INVALID_PERCENTAGE,
    ALREADY_DEPOSITED_FUNDS
}

Delegatable

Git Source

Inherits: IERC165, PoolMetadata

Author: Mure

Interface for Delegate core with support for ERC-165 detection.

Functions

beforeDeposit

function beforeDeposit(string calldata poolName, uint256 amount, address depositor, bytes memory sig) external;

afterDeposit

function afterDeposit(string calldata poolName, uint256 amount, address depositor, bytes memory sig) external;

beforeRefund

function beforeRefund(string calldata poolName, address depositor) external;

afterRefund

function afterRefund(string calldata poolName, address depositor, uint256 amount) external;

withdrawPoolFunds

function withdrawPoolFunds(string calldata poolName) external;

depositPoolFunds

function depositPoolFunds(string calldata poolName, uint256 refundFunds, uint256 claimFunds) external;

deposit

function deposit(string calldata poolName, uint256 amount, bytes memory sig) external;

refund

function refund(string calldata poolName) external;

refund

function refund(string calldata poolName, address depositor, uint256 amount) external;

claim

function claim(string calldata poolName) external;

sendFunds

function sendFunds(address to, uint256 amount, address currency) external;

poolConfig

function poolConfig(string calldata poolName) external view returns (PoolConfig memory);

poolAddress

function poolAddress() external view returns (address);

deposited

function deposited(string calldata poolName, address depositor) external view returns (uint256);

getClaimCurrency

function getClaimCurrency(string calldata poolName) external view returns (address);

Events

PoolFundsDeposit

event PoolFundsDeposit(string poolName, uint256 indexed refundFunds, uint256 indexed claimFunds);

FundTransfer

event FundTransfer(address indexed to, uint256 indexed amount, address indexed currency);

ConfigUpdate

event ConfigUpdate(string poolName);

PoolContractUpdate

event PoolContractUpdate(address indexed poolContract);

Errors

PluginDisabled

error PluginDisabled(uint16 plugin);

PluginEnabled

error PluginEnabled(uint16 plugin);

InvalidAmount

error InvalidAmount();

DelegateError

error DelegateError(DelegateErrorReason reason);

DepositRecord

Git Source

Structure of a deposit

struct DepositRecord {
    uint112 amount;
    uint8 nonce;
}

Depositable

Git Source

Author: Mure

Interface for deposit functionality of pools.

Functions

deposit

function deposit(string calldata poolName, uint256 amount, bytes calldata sig) external;

deposit

function deposit(string calldata poolName, uint256 amount, bytes calldata data, bytes calldata sig) external;

deposited

function deposited(string calldata poolName, address depositor) external view returns (uint256);

Events

Deposit

event Deposit(string poolName, uint256 indexed amount, address indexed from, bytes data);

Distributable

Git Source

Functions

distribute

function distribute(DistributionRecord calldata distribution, bytes calldata signature) external;

distribute

function distribute(DistributionRecord calldata distribution, address to, bytes calldata signature) external;

moveDistribution

function moveDistribution(address source, string calldata poolName, address from, address to) external;

distribution

function distribution(address source, string calldata poolName, address depositor)
    external
    view
    returns (DistributionHistory memory);

nonce

function nonce(address depositor) external view returns (uint24);

Events

Move

event Move(address indexed source, address indexed from, address indexed to, string poolName);

Distribution

event Distribution(
    address indexed token,
    address indexed source,
    address indexed depositor,
    address repository,
    string poolName,
    uint256 amount
);

Errors

UnsupportedSource

error UnsupportedSource();

UnsupportedToken

error UnsupportedToken();

Undistributed

error Undistributed();

Structs

DistributionRecord

struct DistributionRecord {
    address token;
    address source;
    address repository;
    address depositor;
    string poolName;
    uint256 amount;
    uint256 deadline;
}

DistributionHistory

struct DistributionHistory {
    uint256 distributed;
}

IERC165

Git Source

Interface of the ERC165 standard, as defined in the https://eips.ethereum.org/EIPS/eip-165[EIP]. Implementers can declare support of contract interfaces, which can then be queried by others ({ERC165Checker}). For an implementation, see {ERC165}.

Functions

supportsInterface

Returns true if this contract implements the interface defined by interfaceId. See the corresponding https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] to learn more about how these ids are created. This function call must use less than 30 000 gas.

function supportsInterface(bytes4 interfaceId) external view returns (bool);

IERC721Metadata

Git Source

Functions

name

function name() external view returns (string memory);

symbol

function symbol() external view returns (string memory);

tokenURI

function tokenURI(uint256 tokenId) external view returns (string memory);

PoolFeeConfig

Git Source

Structure of a pool fee config

struct PoolFeeConfig {
    address feeRecipient;
    uint8 initialized;
    uint16 poolFeePercentage;
}

FeeConfig

Git Source

Inherits: IERC165

Author: Mure

Interface for fee configuration with support for ERC-165 detection.

Functions

getPoolFee

function getPoolFee(address poolApp, string calldata poolName, uint256 amount)
    external
    returns (uint256 feeAmount, address recipient);

setPoolFee

function setPoolFee(address poolApp, string calldata poolName, uint16 feePercentage, address feeRecipient) external;

poolFeePercentage

function poolFeePercentage(address poolApp, string calldata poolName) external view returns (uint16 feePercentage);

PoolApp

Git Source

Inherits: IERC165, Poolable, Depositable, Refundable, PoolMetadata

Author: Mure

Interface for MurePool core with support for ERC-165 detection.

Functions

withdrawPoolFunds

function withdrawPoolFunds(string calldata poolName) external;

depositFor

function depositFor(string calldata poolName, uint256 amount, address depositor, bytes memory sig) external;

refundTo

function refundTo(string calldata poolName, address depositor, uint256 amount) external;

nonce

function nonce(string calldata poolName, address depositor) external view returns (uint8);

updatePoolPaused

function updatePoolPaused(string calldata poolName, bool pause) external;

updatePoolRefundable

function updatePoolRefundable(string calldata poolName, bool refundable) external;

depositPoolFunds

function depositPoolFunds(string calldata poolName, address depositor, uint256 amount) external;

Structs

Transaction

struct Transaction {
    address depositor;
    uint112 amount;
    Operation operation;
}

Enums

Operation

enum Operation {
    Deposit,
    Withdrawal
}

PoolState

Git Source

Structure of a pool

struct PoolState {
    uint112 totalCollected;
    uint112 poolSize;
    uint16 flags;
    uint16 depositors;
    uint32 endTime;
    address currency;
    address custodian;
    address signer;
}

PoolMetadata

Git Source

Author: Mure

Interface for pool information like its state and existence

Functions

isPoolActive

function isPoolActive(string calldata poolName) external view returns (bool);

poolExists

function poolExists(string calldata pool) external view returns (bool);

poolState

function poolState(string calldata poolName) external view returns (PoolState memory);

withdrawableAmount

function withdrawableAmount(string calldata poolName) external view returns (uint112);

PoolParameters

Git Source

Structure of parameters of a pool

struct PoolParameters {
    uint112 poolSize;
    uint32 endTime;
    uint16 flags;
    address currency;
    address custodian;
    address signer;
}

PoolMetrics

Git Source

Structure for pool metrics. Could be updated in future

struct PoolMetrics {
    uint112 totalWithdrawn;
}

PoolParameter

Git Source

enum PoolParameter {
    POOL_SIZE,
    END_TIME,
    FLAGS,
    DEPOSITORS,
    CURRENCY,
    CUSTODIAN,
    SIGNER
}

PoolErrorReason

Git Source

enum PoolErrorReason {
    POOL_SIZE_TOO_SMALL,
    TRANSFER_FAILURE,
    ARITHMETIC_OUT_OF_BOUNDS,
    ALREADY_INVESTED_POOL,
    INVALID_POOL_TYPE,
    POOL_EMPTY
}

Poolable

Git Source

Author: Mure

Interface for pool administration functionality and pool errors.

Functions

createPool

function createPool(string calldata poolName, PoolParameters calldata params, bytes calldata sig) external;

updatePool

function updatePool(string calldata poolName, PoolParameters calldata params) external;

poolMetrics

function poolMetrics(string calldata poolName) external view returns (PoolMetrics memory);

Events

PoolCreation

event PoolCreation(string poolName);

PoolUpdate

event PoolUpdate(string poolName);

Withdrawal

event Withdrawal(string poolName, uint256 indexed amount, address indexed to, bytes data);

Errors

PoolClosed

error PoolClosed();

PoolOpen

error PoolOpen();

PoolError

error PoolError(PoolErrorReason reason);

IllegalPoolState

error IllegalPoolState(PoolParameter param);

IllegalPoolOperation

error IllegalPoolOperation(PoolErrorReason reason);

PoolInitialized

error PoolInitialized();

PoolFull

error PoolFull();

PoolPaused

error PoolPaused();

PoolNotEmpty

error PoolNotEmpty();

Refundable

Git Source

Author: Mure

Interface for refund fuctioanlity for pools with support for ERC-165 detection.

Functions

refund

function refund(string calldata poolName) external;

updatePoolRefundable

function updatePoolRefundable(string calldata poolName, bool refundable) external;

Events

Refund

event Refund(string poolName, uint256 indexed amount, address indexed depositor, bytes data);

Errors

DepositNotFound

error DepositNotFound();

Contents

MureErrors

Git Source

Author: Mure

Library with global errors for Mure

Errors

InvalidAddress

thrown when address is invalid, eg: zero address

error InvalidAddress(address addr);

SignatureExpired

thrown when a signature has expired before verification

error SignatureExpired();

Unauthorized

thrown when any restricted operation is performed by an unauthorized entity

error Unauthorized();

InvalidDelegate

thrown when address is not a valid delegate

error InvalidDelegate();

PoolNotFound

thrown when pool with given parameters is not found

error PoolNotFound();

InvalidFee

thrown when fee is invalid

error InvalidFee();

NoAdmin

thrown when no member has a DEFAULT_ADMIN_ROLE role

error NoAdmin();

Contents

MockERC20

Git Source

Inherits: ERC20

Functions

constructor

constructor(string memory name, string memory symbol) ERC20(name, symbol);

mint

function mint(address to, uint256 amount) public;

Contents

ClaimPlugin

Git Source

Inherits: UUPSUpgradeable, OwnableUpgradeable, ERC165Upgradeable, Claimable

Author: Mure Implements UUPSUpgradeable for upgradeability, OwnableUpgradeable for access control, ERC165Upgradeable for interface support, and Claimable interface for compatibility checks. Facilitates the calculation and execution of reward claims, allowing depositors to receive their entitled rewards along with their shares from the total collected pool funds.

Contract managing reward distribution to users of an application.

Functions

initialize

function initialize(address owner) external initializer;

claim

Sends reward funds from the delegate to depositor.

function claim(ClaimRecord calldata claimRecord) external returns (uint256 depositDelta, uint256 claimDelta);

Parameters

NameTypeDescription
claimRecordClaimRecordstruct containing all information needed to compute and execute a claimRecord. See Claimable.ClaimRecord for more information

deltas

Returns the refund amount, claim amount and fee.

function deltas(ClaimRecord calldata claimRecord)
    public
    pure
    returns (uint256 depositDelta, uint256 claimDelta, uint256 fee);

Parameters

NameTypeDescription
claimRecordClaimRecordstruct containing all information needed to compute and execute a claimRecord. See Claimable.ClaimRecord for more information

Returns

NameTypeDescription
depositDeltauint256amount from the original deposit to be refunded
claimDeltauint256amount from the claim reserves to be claimed
feeuint256fee to be charged from claimDelta

_calculateShare

Calculates the user share amount.

function _calculateShare(uint256 share, uint256 supply, uint256 reserve) private pure returns (uint256);

Parameters

NameTypeDescription
shareuint256share of the user
supplyuint256total supply
reserveuint256current reserve

calculateFee

Calculates the fee to be charged.

function calculateFee(uint256 amount, uint256 feePercentage) private pure returns (uint256);

Parameters

NameTypeDescription
amountuint256total amount
feePercentageuint256fee percentage in basis points

supportsInterface

See IERC165-supportsInterface.

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ERC165Upgradeable, IERC165)
    returns (bool);

_authorizeUpgrade

required by the OZ UUPS module

function _authorizeUpgrade(address) internal override onlyOwner;

Contents

Constants

Git Source

POOL_OPERATOR_ROLE

Role allows user to create and update pools along with pool administration

bytes32 constant POOL_OPERATOR_ROLE = keccak256("POOL_OPERATOR");

DEFAULT_ADMIN_ROLE

Default RBAC admin role

bytes32 constant DEFAULT_ADMIN_ROLE = 0x00;

Role

Git Source

Enum for pool member roles

enum Role {
    DEFAULT_ADMIN,
    POOL_OPERATOR
}

AppMember

Git Source

Struct for a pool member

struct AppMember {
    address member;
    Role role;
}

Constants

Git Source

APP_MEMBER_HASH

Struct hash for validating app deployments keccak256("AppMember(address member,uint8 role)")

bytes32 constant APP_MEMBER_HASH = 0xe3128a5e7b51cb6b5d75b976cb4b51c8420a8c2a5c60709fd3af893c19fc754a;

Delegate

Git Source

Inherits: ERC165Upgradeable, ReentrancyGuardUpgradeable, AccessControlUpgradeable, Delegatable

Author: Mure Implements AccessControlUpgradeable for access control, UUPSUpgradeable for efficient upgrades, ERC165Upgradeable for interface support, and Delegatable for plugin compatibility. Manages storage for delegated functions, including user share per pool, pool configurations, pool contract,and plugins. Also provides hooks for custom functionality in pool-related operations. Delegate handles the various plugins that might be required by a particular application, for example, for reward claims and for fees deduction. Each application can subscribe to one or more plugins which will then link to the delegate for that application and be available to use. NOTE: A single instance of a delegate shall be bound to a single instance of the pool contract.

Abstract contract governing delegated functionality for the applications in Mure protocol.

State Variables

DelegateStorageLocation

Struct hash for storage location keccak256(abi.encode(uint256(keccak256("mure.Delegate")) - 1)) & ~bytes32(uint256(0xff))

bytes32 internal constant DelegateStorageLocation = 0xc4200f32c1c30cddd40d021baa377d96970df44812e3c252691c8e5d8633a500;

CLAIM

Defines if the claim plugin is enabled

uint16 constant CLAIM = 0x01;

DELEGATE_OPERATOR_ROLE

Role allows user to create and update pools along with pool administration

bytes32 public constant DELEGATE_OPERATOR_ROLE = keccak256("DELEGATE_OPERATOR");

Functions

onlyPool

modifier onlyPool();

validPool

modifier validPool(string calldata poolName);

onlyPlugin

modifier onlyPlugin();

pluginEnabled

modifier pluginEnabled(string calldata poolName, uint16 plugin);

pluginDisabled

modifier pluginDisabled(string calldata poolName, uint16 plugin);

onlyCustodianOrOwner

modifier onlyCustodianOrOwner(string calldata poolName);

__Delegate_init

Initializes the contract setting owner, poolContract, and claimPlugin.

function __Delegate_init(address owner, address poolContract_, address claimPlugin_) internal onlyInitializing;

withdrawPoolFunds

Places a delegated call to withdraw pool funds.

pauses the pool and locks refunds

function withdrawPoolFunds(string calldata poolName) external onlyCustodianOrOwner(poolName);

Parameters

NameTypeDescription
poolNamestringname of the pool

depositPoolFunds

Deposits the withdrawn pool funds back. This operation assumes that the contract is an approved spender of the depositor.

Transfers the original collected funds back to the pool app. Additional funds stay on the delegate

Unpauses the pool and unlocks refunds

function depositPoolFunds(string calldata poolName, uint256 depositFunds, uint256 claimFunds)
    external
    onlyCustodianOrOwner(poolName)
    nonReentrant;

Parameters

NameTypeDescription
poolNamestringname of the pool
depositFundsuint256the amount to be deposited back to the pool
claimFundsuint256funds for claims

share

Returns the user depositor value.

function share(string calldata poolName, address depositor) external view returns (uint256);

Parameters

NameTypeDescription
poolNamestringname of the pool
depositoraddressaddress of the depositor

state

Returns the pool config state.

function state(string calldata poolName) external view returns (PoolConfig memory);

Parameters

NameTypeDescription
poolNamestringname of the pool

claim

Processes user claims.

function claim(string calldata poolName) external pluginEnabled(poolName, CLAIM) validPool(poolName);

Parameters

NameTypeDescription
poolNamestringname of the pool

activateClaimPlugin

Activates the claim plugin.

function activateClaimPlugin(string calldata poolName, address claimCurrency)
    external
    onlyRole(DELEGATE_OPERATOR_ROLE)
    validPool(poolName);

Parameters

NameTypeDescription
poolNamestringname of the pool to activate the plugin on
claimCurrencyaddress

deactivateClaimPlugin

Deactivates the claim plugin.

function deactivateClaimPlugin(string calldata poolName)
    external
    onlyRole(DELEGATE_OPERATOR_ROLE)
    validPool(poolName);

Parameters

NameTypeDescription
poolNamestringname of the pool to deactivate the plugin on

setPoolClaimCurrency

Sets the pool claim currency.

function setPoolClaimCurrency(string calldata poolName, address currency)
    external
    onlyRole(DELEGATE_OPERATOR_ROLE)
    validPool(poolName);

Parameters

NameTypeDescription
poolNamestringname of the pool
currencyaddressthe claim currency to be set

setPoolFeePercentage

Sets the pools fee percentage.

Can only be called if the fee plugin is enabled.

Fee percentage is in basis points (1 = 0.01%).

function setPoolFeePercentage(string calldata poolName, uint16 feePercentage)
    external
    onlyRole(DELEGATE_OPERATOR_ROLE)
    validPool(poolName);

Parameters

NameTypeDescription
poolNamestringname of the pool
feePercentageuint16the fee percentage to be set

setPoolContract

Sets the pool app address.

Set as address(0) to deprecate delegate.

function setPoolContract(address poolContract) external onlyRole(DELEGATE_OPERATOR_ROLE);

Parameters

NameTypeDescription
poolContractaddressaddress of the pool app

setClaimPlugin

Sets the claim plugin address.

function setClaimPlugin(address pluginAddress) external onlyRole(DELEGATE_OPERATOR_ROLE);

Parameters

NameTypeDescription
pluginAddressaddressaddress of the claim plugin

deposit

Places a delegated call to deposit on the pool app. This operation assumes that the pool app is an approved spender of the depositor.

function deposit(string calldata poolName, uint256 amount, bytes memory sig) external nonReentrant;

Parameters

NameTypeDescription
poolNamestringname of the pool
amountuint256the amount to deposit
sigbytesthe signatures generated for the user, including the amount.

refund

Places a delegated call for refund on the pool app.

function refund(string calldata poolName) external nonReentrant pluginDisabled(poolName, CLAIM);

Parameters

NameTypeDescription
poolNamestringname of the pool

refund

Places a delegated call for refund on the pool app.

function refund(string calldata poolName, address depositor, uint256 amount) external nonReentrant onlyPlugin;

Parameters

NameTypeDescription
poolNamestringname of the pool
depositoraddress
amountuint256amount to refund

sendFunds

Transfers funds to a specific address.

Can only be called by a verified plugin.

function sendFunds(address to, uint256 amount, address currency) external onlyPlugin nonReentrant;

Parameters

NameTypeDescription
toaddressaddress to be transferred to
amountuint256the amount to be transferred
currencyaddressthe currency to be transferred

previewClaim

Returns the refund amount, claim amount and fee.

function previewClaim(string calldata poolName, address depositor)
    external
    view
    returns (uint256 depositDelta, uint256 claimDelta, uint256 fee);

Parameters

NameTypeDescription
poolNamestringname of the pool
depositoraddressaddress of the depositor

Returns

NameTypeDescription
depositDeltauint256amount from the original deposit to be refunded
claimDeltauint256amount from the claim reserves to be claimed
feeuint256fee to be charged from claimDelta

beforeDeposit

Hook to be called by the pool app before a deposit.

function beforeDeposit(string calldata poolName, uint256 amount, address depositor, bytes memory sig)
    external
    virtual
    onlyPool;

Parameters

NameTypeDescription
poolNamestringname of the pool
amountuint256the amount to be deposited
depositoraddressaddress of the depositor
sigbytesthe signature used for deposit

afterDeposit

Hook to be called by the pool app after a deposit.

function afterDeposit(string calldata poolName, uint256 amount, address depositor, bytes memory sig)
    external
    virtual
    onlyPool;

Parameters

NameTypeDescription
poolNamestringname of the pool
amountuint256the amount to be deposited
depositoraddressaddress of the depositor
sigbytesthe signature used for deposit

beforeRefund

Hook to be called by the pool app before a refund.

function beforeRefund(string calldata poolName, address depositor) external virtual onlyPool;

Parameters

NameTypeDescription
poolNamestringname of the pool
depositoraddressaddress of the depositor

afterRefund

Hook to be called by the pool app after a refund.

function afterRefund(string calldata poolName, address depositor, uint256 amount) external virtual onlyPool;

Parameters

NameTypeDescription
poolNamestringname of the pool
depositoraddressaddress of the depositor
amountuint256refunded amount

withdrawCurrency

Withdraw any token from the contract. This should only be used in emergencies as this can withdraw capital from any pool, be it active or not. Always prefer using withdraw over this function, unless you need clean up the contract by, e.g., burning garbage tokens.

function withdrawCurrency(address receiver, address currency) external onlyRole(DELEGATE_OPERATOR_ROLE);

Parameters

NameTypeDescription
receiveraddressthe address to which the token will be transferred
currencyaddressthe address of the token contract

poolConfig

Retrieves the config of the specified pool.

function poolConfig(string calldata poolName) external view returns (PoolConfig memory);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to retrieve the config of

poolAddress

Retrieves the pool app address.

function poolAddress() external view returns (address);

claimPluginAddress

Retrieves the claim plugin address.

function claimPluginAddress() external view returns (address);

isPoolActive

Checks if the specified pool is active.

function isPoolActive(string calldata poolName) external view returns (bool);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to check if it is active

withdrawableAmount

Checks if the specified pool is active.

function withdrawableAmount(string calldata poolName) external view returns (uint112);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to check if it is active

poolState

Retrieves the state of the specified pool.

Requires the pool to exist.

function poolState(string calldata poolName) external view returns (PoolState memory);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to retrieve the state of

deposited

Retrieves the amount deposited by the specified depositor in the specified pool.

Requires the pool to exist.

function deposited(string calldata poolName, address depositor) external view returns (uint256);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to retrieve the deposit from
depositoraddressthe address of the depositor

poolExists

Checks if the specified pool exists.

function poolExists(string calldata poolName) external view returns (bool);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to check for existence

getClaimCurrency

Returns the address of the claim currency for a pool.

function getClaimCurrency(string calldata poolName) external view returns (address);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to check for claim currency

supportsInterface

See IERC165-supportsInterface.

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ERC165Upgradeable, IERC165, AccessControlUpgradeable)
    returns (bool);

_transferCurrency

Transfers currency between two addresses with a specified amount of a given currency.

function _transferCurrency(address from, address to, uint256 amount, address currency) internal;

Parameters

NameTypeDescription
fromaddressthe address from which the transfer is initiated
toaddressthe address to which the transfer is made
amountuint256the amount of the currency being transferred
currencyaddressthe address of the currency being transferred

_refund

function _refund(address poolContract, string calldata poolName, address depositor, uint256 amount) internal;

_addSupply

function _addSupply(string calldata poolName, address depositor, uint256 supply) internal;

_deductSupply

function _deductSupply(string calldata poolName, address depositor, uint256 supply) internal;

_claim

function _claim(string calldata poolName, uint256 totalCollected, address custodian, uint256 userDeposit) internal;

_pluginEnabled

Checks whether a specific plugin is enabled.

function _pluginEnabled(uint16 plugins, uint16 plugin) internal pure returns (bool);

Parameters

NameTypeDescription
pluginsuint16the set of plugins being checked
pluginuint16the plugin being checked for activation

_activatePlugin

Activates the specified plugin.

function _activatePlugin(uint16 plugins, uint16 plugin) internal pure returns (uint16);

Parameters

NameTypeDescription
pluginsuint16the set of plugins being modified
pluginuint16the plugin being activated

_deactivatePlugin

Deactivates the specified plugin.

function _deactivatePlugin(uint16 plugins, uint16 plugin) internal pure returns (uint16);

Parameters

NameTypeDescription
pluginsuint16the set of plugins being modified
pluginuint16the plugin being activated

_getStorage

Retrieves the storage for the Delegate contract.

function _getStorage() internal pure returns (DelegateStorage storage $);

_isPlugin

Checks if the provided address is a plugin.

function _isPlugin(address address_) internal view returns (bool);

Parameters

NameTypeDescription
address_addressthe address to check

Events

PluginActivated

event PluginActivated(string poolName, uint16 indexed plugin);

PluginDeactivated

event PluginDeactivated(string poolName, uint16 indexed plugin);

PluginUpdate

event PluginUpdate(address indexed pluginAddress, uint16 indexed plugin);

Structs

DelegateStorage

struct DelegateStorage {
    mapping(string => mapping(address => uint256)) shares;
    mapping(string => PoolConfig) poolConfigs;
    address poolContract;
    address claimPlugin;
}

MureConfig

Git Source

Inherits: EIP712Upgradeable, OwnableUpgradeable, UUPSUpgradeable, ERC165Upgradeable, Config

Author: Mure

Upgradeable configuration contract governing Mure protocol settings, signers, and app delegates. Implements Ownable for access control, UUPSUpgradeable for efficient upgrades, ERC165Upgradeable for interface support, and Config interface for compatibility checks. Manages whitelisted signers for secure operations, like verifying any EIP-712 signature used within the Mure protocol is signed by one of the whitelisted signers. Supports toggling the whitelisting of signers. Manages app delegates for flexible app functionality. Ensures that delegate contracts being set for an application conform to the Delegatable interface, maintaining consistency and compatibility.

State Variables

MureConfigStorageLocation

Struct hash for storage location keccak256(abi.encode(uint256(keccak256("mure.MureConfig")) - 1)) & ~bytes32(uint256(0xff))

bytes32 private constant MureConfigStorageLocation = 0x449166636934a062783bf0dfc33be04087c7302a55ece21ecb76ecfd3ffd2100;

Functions

initialize

function initialize(string calldata name, string calldata version, address owner) external initializer;

toggleWhitelistedSigner

Toggles the whitelisting of the specified address.

function toggleWhitelistedSigner(address mureSigner_) external onlyOwner;

Parameters

NameTypeDescription
mureSigner_addressThe address whose whitelisting is to be toggled.

setAppDelegate

Sets the app delegate.

Set to address(0) to disable delegate

function setAppDelegate(address app, address delegate) external onlyOwner;

Parameters

NameTypeDescription
appaddressaddress of the app
delegateaddressaddress of the delegate

setMureFeeContract

Sets the fee contract address.

function setMureFeeContract(address feeContractAddress) external onlyOwner;

Parameters

NameTypeDescription
feeContractAddressaddressaddress of the fee contract

getAppDelegate

Retrieves the app delegate.

function getAppDelegate(address app) external view returns (address);

Parameters

NameTypeDescription
appaddressaddress of the app

getFeeContractAddress

Retrieves the fee contract address.

function getFeeContractAddress() external view returns (address);

getPoolFee

function getPoolFee(address poolApp, string calldata poolName, uint256 amount) external returns (uint256, address);

verifyMureSignature

Validates if the provided signature has been created by one of the whitelisted signers.

function verifyMureSignature(bytes32 structHash, bytes memory signature) external view;

Parameters

NameTypeDescription
structHashbytes32The hashed message that was signed.
signaturebytesThe signature to be validated.

isWhitelistedSigner

Checks whether the specified address is whitelisted.

function isWhitelistedSigner(address address_) public view returns (bool);

Parameters

NameTypeDescription
address_addressThe address to check.

_getStorage

Retrieves the storage for the MureConfig contract.

function _getStorage() private pure returns (MureConfigStorage storage $);

_supportsDelegateInterface

Checks if delegate supports delegate interface.

function _supportsDelegateInterface(address delegate) private view returns (bool);

supportsInterface

See IERC165-supportsInterface.

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ERC165Upgradeable, IERC165)
    returns (bool);

_supportsFeeConfigInterface

Checks if fee config supports the fee config interface.

function _supportsFeeConfigInterface(address feeConfig) private view returns (bool);

_authorizeUpgrade

required by the OZ UUPS module

function _authorizeUpgrade(address) internal override onlyOwner;

Events

AppDelegated

event AppDelegated(address indexed app, address indexed delegate);

FeeContractSet

event FeeContractSet(address indexed mureFeeContract);

Structs

MureConfigStorage

struct MureConfigStorage {
    mapping(address => uint8) signers;
    mapping(address => address) delegate;
    address mureFeeContract;
}

MureDelegate

Git Source

Inherits: Delegate

Functions

initialize

function initialize(address owner, address poolContract_, address claimPlugin_) external initializer;

MureDistribution

Git Source

Inherits: EIP712Upgradeable, ERC165Upgradeable, AccessControlUpgradeable, ReentrancyGuardUpgradeable, UUPSUpgradeable, Distributable

Author: Mure

Distribution contract for distributing assets described by PoolMetadata contracts.

Recommended use is with a MurePool contract, where off-chain signatures are provided for permits and saving gas by depending on off-chain compute power for complex computations based on on-chain state.

State Variables

DISTRIBUTION_ADMIN_ROLE

Role allows user to create and update pools along with pool administration

bytes32 public constant DISTRIBUTION_ADMIN_ROLE = keccak256("DISTRIBUTION_ADMIN");

MureDistributionStorageLocation

Hash for storage location keccak256(abi.encode(uint256(keccak256("mure.MureDistribution")) - 1)) & ~bytes32(uint256(0xff))

bytes32 private constant MureDistributionStorageLocation =
    0xcb2c43c8a077042ee388281b9a5a398915ca6047194d75b071075a7b241a5800;

DISTRIBUTION_HASH

Struct hash for validating deposits keccak256("Distribution(address token,address source,string pool,address repository,address depositor,address claimer,uint256 amount,uint256 deadline,uint24 nonce)")

bytes32 private constant DISTRIBUTION_HASH = 0xc947aa90aaf074203df95a7de07adb71025f14e165fb180a3c83663110a02ce1;

Functions

distributable

modifier distributable(DistributionRecord calldata distribution);

validManager

modifier validManager(address source);

initialize

function initialize(string calldata name, string calldata version, address owner) external initializer;

supportsInterface

See IERC165-supportsInterface.

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ERC165Upgradeable, AccessControlUpgradeable)
    returns (bool);

distribute

function distribute(DistributionRecord calldata distribution, bytes calldata signature) external;

distribute

function distribute(DistributionRecord calldata distribution, address to, bytes calldata signature) external;

moveDistribution

Moves a distribution record from one depositor to another.

Only used for moving complete distributions in cases such as from being a compromised wallet.

function moveDistribution(address source, string calldata poolName, address from, address to)
    external
    validManager(source);

Parameters

NameTypeDescription
sourceaddressthe address to the application contract where the deposit information exists
poolNamestringthe name of the pool where the deposit was conducted
fromaddressthe address of the original depositor
toaddressthe address of the new depositor

distribution

Read distribution history of depositor in the designated source and poolName

function distribution(address source, string calldata poolName, address depositor)
    external
    view
    returns (DistributionHistory memory);

Parameters

NameTypeDescription
sourceaddressthe address of the pooling contract
poolNamestringthe name pf the pool
depositoraddressthe address of the depositor

nonce

Read nonce of depositor

function nonce(address depositor) external view returns (uint24);

Parameters

NameTypeDescription
depositoraddressthe address of the depositor

_distribute

Assumes that the token address is a valid ERC20 token as the standard doesn't depend on ERC165. Make sure that the token is valid to avoid reverts without error codes

function _distribute(DistributionRecord calldata distribution, address to, bytes calldata signature)
    internal
    distributable(distribution)
    nonReentrant;

_hashDistribution

Generates a struct hash for a distribution.

function _hashDistribution(DistributionRecord calldata distribution, address to) private view returns (bytes32);

Parameters

NameTypeDescription
distributionDistributionRecordthe distribution information
toaddress

_transferAssets

function _transferAssets(DistributionRecord calldata distribution, address to) internal;

_encodeDistributionKey

function _encodeDistributionKey(address source, string calldata poolName, address depositor)
    internal
    pure
    returns (bytes32);

_verifySignature

function _verifySignature(DistributionRecord calldata distribution, address signer, address to, bytes calldata sig)
    private
    view;

_getDistributionStorage

Retrieves the storage for the pool metrics.

function _getDistributionStorage() private pure returns (MureDistributionStorage storage $);

_authorizeUpgrade

function _authorizeUpgrade(address) internal override onlyRole(DISTRIBUTION_ADMIN_ROLE);

Structs

MureDistributionStorage

struct MureDistributionStorage {
    mapping(bytes32 => DistributionHistory) distributions;
    mapping(address => uint24) nonces;
}

MureFee

Git Source

Inherits: OwnableUpgradeable, UUPSUpgradeable, FeeConfig

Author: Mure

Manages pool specific fee configuration and calculations. If specific config is not set for a pool; default fee config is applied. Fee configuration is stored in a mapping against an encoded key.

Upgradeable configuration contract governing Mure protocol fee settings

Implements Ownable for access control, UUPSUpgradeable for efficient upgrades, ERC165Upgradeable for interface support, and FeeConfig interface for compatibility checks.

State Variables

MureFeeStorageLocation

Struct hash for storage location keccak256(abi.encode(uint256(keccak256("mure.MureFee")) - 1)) & ~bytes32(uint256(0xff))

bytes32 private constant MureFeeStorageLocation = 0x5ce6e1025f6bcb2fbc14816760e865aaac081dc4c60162a5e592c26e03f6f100;

Functions

initialize

function initialize(address defaultFeeRecipient_, uint16 defaultFeePercentage_, address owner) external initializer;

setPoolFee

Sets fee configurations for a particular pool.

Requires the pool to exist. Can only be called by the contract owner.

function setPoolFee(address poolApp, string calldata poolName, uint16 feePercentage, address feeRecipient)
    external
    onlyOwner;

Parameters

NameTypeDescription
poolAppaddressaddress of the pool app
poolNamestringthe name of the pool
feePercentageuint16fee percentage in basis points
feeRecipientaddressaddress of the fee recipient

setDefaultFeeConfig

Sets the default fee configuration.

Can only be called by the contract owner.

function setDefaultFeeConfig(uint16 defaultFeePercentage_, address defaultFeeRecipient_) external onlyOwner;

Parameters

NameTypeDescription
defaultFeePercentage_uint16default fee percentage in basis points
defaultFeeRecipient_addressdefault address of the fee recipient

getPoolFee

Calculates the fee to be charged on amount.

function getPoolFee(address poolApp, string calldata poolName, uint256 amount)
    external
    view
    returns (uint256, address);

Parameters

NameTypeDescription
poolAppaddressaddress of the pool app
poolNamestringthe name of the pool
amountuint256

Returns

NameTypeDescription
<none>uint256fee amount and recipient
<none>address

poolFeePercentage

Retrieves the pool fee percentage.

function poolFeePercentage(address poolApp, string calldata poolName) public view returns (uint16 feePercentage);

Parameters

NameTypeDescription
poolAppaddressaddress of the pool app
poolNamestringthe name of the pool

Returns

NameTypeDescription
feePercentageuint16configured fee percentage

encodeHash

Calculates the encoded hash for pool config.

function encodeHash(address poolApp, string calldata poolName) public pure returns (bytes32);

Parameters

NameTypeDescription
poolAppaddressaddress of the pool app
poolNamestringthe name of the pool

Returns

NameTypeDescription
<none>bytes32encoded hash

supportsInterface

See IERC165-supportsInterface.

function supportsInterface(bytes4 interfaceId) public view virtual returns (bool);

_calculateFee

Calculates the fee to be charged.

function _calculateFee(uint256 amount, uint256 feePercentage) private pure returns (uint256);

Parameters

NameTypeDescription
amountuint256total amount
feePercentageuint256fee percentage in basis points

_supportsPoolAppInterface

Checks if address supports the pool app interface.

function _supportsPoolAppInterface(address pool) private view returns (bool);

_getStorage

Retrieves the storage for the MureFee contract.

function _getStorage() private pure returns (MureFeeStorage storage $);

_authorizeUpgrade

required by the OZ UUPS module

function _authorizeUpgrade(address) internal override onlyOwner;

Events

FeeConfigSet

event FeeConfigSet(
    address indexed poolApp, string poolName, uint16 indexed feePercentage, address indexed feeRecipient
);

Structs

MureFeeStorage

struct MureFeeStorage {
    address defaultFeeRecipient;
    uint16 defaultFeePercentage;
    mapping(bytes32 => PoolFeeConfig) poolFee;
}

MurePool

Git Source

Inherits: EIP712Upgradeable, ReentrancyGuardUpgradeable, PausableUpgradeable, ERC165Upgradeable, AccessControlUpgradeable, PoolApp

Author: Mure

Facilitates secure and configurable pool management, supporting operations such as pool creation, deposits, withdrawals, and refunds.

Core implementation contract for pooled investments in the Mure protocol. Utilizes the beacon proxy pattern to deploy multiple proxies, each representing a distinct application within the protocol. The MureFactory contract handles these deployments. Implements the EIP-712 standard for signature validation, preventing unauthorized access. Relies on the MureConfig contract to verify EIP-712 signatures and manage the pool creation process. Interaction with the MureConfig contract allows dynamic configuration and signature validation. Security measures include the OpenZeppelin PausableUpgradeable pattern for emergency pausing, ReentrancyGuardUpgradeable to prevent reentrancy attacks, and role based access control through AccessControlUpgradeable. Flag-based functionality enables features like refundability, passthrough of funds, and more. Provides hooks for custom functionality in pool-related operations Depending on the kind of application, the MurePool proxy instance could be linked to a MureDelegate proxy instance for interacting with various plugins that the protocol provides.

State Variables

MurePoolStorageLocation

Hash for storage location keccak256(abi.encode(uint256(keccak256("mure.MurePool")) - 1)) & ~bytes32(uint256(0xff))

bytes32 private constant MurePoolStorageLocation = 0x79bd164051f83036bb52eee1d9b6be5ba887eaf3a9d8907adbaadfa56c970700;

PoolMetricsStorageLocation

Hash for storage location keccak256(abi.encode(uint256(keccak256("mure.PoolMetrics")) - 1)) & ~bytes32(uint256(0xff))

bytes32 private constant PoolMetricsStorageLocation = 0x1ca3e723ed845754b3d7cf12c13e1b284ab752e694e983a627f991c98b3a0700;

DEPOSIT_HASH

Struct hash for validating deposits keccak256("Deposit(uint256 amount,string pool,address depositor,uint8 nonce)")

bytes32 private constant DEPOSIT_HASH = 0xc5b44054231c7194afce4ed4062c5abd2c0cb26e0686f9ba69d2cfc04b490e33;

CREATE_POOL_HASH

Struct hash for validating pool creation keccak256("CreatePool(string pool,uint32 endTime,uint24 nonce)")

bytes32 private constant CREATE_POOL_HASH = 0x38c6f9238aff6821963f06d84f958ebb018ff9e4343c962882ef7b3308ff1b4d;

MURE_CONFIG

Address for the MureConfig contract

Update config address

address constant MURE_CONFIG = 0x2b727332eF478bAe460ecF0CAb7C1487a87D68B8;

INITIALIZED

Defines if the pool is initialized

uint16 constant INITIALIZED = 0x01;

PAUSED

Defines if the pool is paused from any interaction

uint16 constant PAUSED = 0x02;

PASSTHROUGH_FUNDS

PASSTHROUGH_FUNDS and REFUNDABLE cannot be set at the same time

Defines if deposits should pass straight to associtated raising wallet upon deposit

uint16 constant PASSTHROUGH_FUNDS = 0x04;

REFUNDABLE

PASSTHROUGH_FUNDS and REFUNDABLE cannot be set at the same time

Defines if the pool is open for claiming refunds

uint16 constant REFUNDABLE = 0x08;

TIERED

Defines if the pool is having tiers and gating

uint16 constant TIERED = 0x10;

CROSS_CHAIN

Defines if the pool is cross-chain enabled, pooling funds across different networks

uint16 constant CROSS_CHAIN = 0x20;

DELEGATED

Defines if the pool allows for use of delegated wallets for security

uint16 constant DELEGATED = 0x40;

Functions

poolValid

modifier poolValid(string calldata poolName);

poolActive

modifier poolActive(string calldata poolName);

poolNotPaused

modifier poolNotPaused(string calldata poolName);

valid

modifier valid(PoolParameters calldata params);

onlyDelegateOrOperator

modifier onlyDelegateOrOperator();

onlyDelegate

modifier onlyDelegate();

notDelegated

modifier notDelegated();

initialize

function initialize(string calldata name, string calldata version, AppMember[] calldata members) external initializer;

createPool

Creates a new pool with the specified parameters.

Requires the pool to not already exist. Can only be called by a pool operator.

function createPool(string calldata poolName, PoolParameters calldata params, bytes memory sig)
    external
    onlyRole(POOL_OPERATOR_ROLE)
    valid(params);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to create
paramsPoolParametersthe parameters for the new pool
sigbytesthe signature generated for pool creation for client

updatePool

Updates the specified pool with the provided parameters.

Requires the pool to exist. Can only be called by a pool operator.

Requires the updated pool size to be greater than or equal to the total amount collected.

function updatePool(string calldata poolName, PoolParameters calldata params)
    external
    onlyRole(POOL_OPERATOR_ROLE)
    valid(params)
    poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to update
paramsPoolParametersthe updated parameters for the pool

updatePoolSize

Updates the size of the specified pool.

Requires the pool to exist. Can only be called by a pool operator.

Requires the new pool size to be greater than or equal to the total amount collected.

function updatePoolSize(string calldata poolName, uint256 poolSize)
    external
    onlyRole(POOL_OPERATOR_ROLE)
    poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to update
poolSizeuint256the updated size of the pool

updatePoolEndTime

Updates the end time of the specified pool.

Requires the pool to exist. Can only be called by a pool operator.

function updatePoolEndTime(string calldata poolName, uint256 endTime)
    external
    onlyRole(POOL_OPERATOR_ROLE)
    poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to update
endTimeuint256the updated end time for the pool

updatePoolSigner

Updates the signer of the specified pool.

Requires the pool to exist. Can only be called by a pool operator.

function updatePoolSigner(string calldata poolName, address _signer)
    external
    onlyRole(POOL_OPERATOR_ROLE)
    poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to update
_signeraddressthe updated signer for the pool

updatePoolPaused

Pauses or unpauses the specified pool.

Requires the pool to exist. Can only be called by a pool operator or delegate.

function updatePoolPaused(string calldata poolName, bool pause) external onlyDelegateOrOperator poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to pause or unpause
pauseboola boolean representing whether to pause or unpause the pool

updatePoolRefundable

Updates whether the specified pool allows refunds or not.

Requires the pool to exist. Can only be called by a pool operator.

Requires that the pool does not have the PASSTHROUGH_FUNDS flag set if enabling refunds.

function updatePoolRefundable(string calldata poolName, bool refundable)
    external
    onlyDelegateOrOperator
    poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to update
refundableboola boolean representing whether refunds should be enabled or not

updatePoolPassthroughFunds

Updates whether the specified pool passes funds through to the custodian directly or not.

Requires the pool to exist. Can only be called by a pool operator.

Requires that the pool does not have the REFUNDABLE flag set if enabling passthrough funds.

function updatePoolPassthroughFunds(string calldata poolName, bool passthroughFunds)
    external
    onlyRole(POOL_OPERATOR_ROLE)
    poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to update
passthroughFundsboola boolean representing whether to enable passthrough funds or not

withdrawPoolFunds

Withdraws the total collected amount from the specified pool.

Requires the pool to exist. Can only be called by a pool operator or the delegate if it is set.

function withdrawPoolFunds(string calldata poolName) external onlyDelegateOrOperator poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to withdraw from

withdrawCurrency

Withdraw any token from the contract. This should only be used in emergencies as this can withdraw capital from any pool, be it active or not. Always prefer using withdrawPoolFunds over this function, unless you need clean up the contract by, e.g., burning garbage tokens.

function withdrawCurrency(address receiver, address currency) external onlyRole(DEFAULT_ADMIN_ROLE);

Parameters

NameTypeDescription
receiveraddressthe address to which the token will be transferred
currencyaddressthe address of the token contract

addDeposit

Adds a deposit of the specified amount to the pool for the designated depositor.

Requires the pool to exist. Can only be called by a pool operator.

function addDeposit(string calldata poolName, address depositor, uint256 amount)
    external
    onlyRole(POOL_OPERATOR_ROLE)
    poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to add the deposit to
depositoraddressthe address of the depositor
amountuint256the amount of the deposit

deductDeposit

Deducts the specified amount from the deposit of the designated depositor in the pool.

Requires the pool to exist. Can only be called by a pool operator.

function deductDeposit(string calldata poolName, address depositor, uint256 amount)
    external
    onlyRole(POOL_OPERATOR_ROLE)
    poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to deduct the deposit from
depositoraddressthe address of the depositor
amountuint256the amount to deduct

moveDeposit

Moves the specified amount from one depositor's deposit to another in the pool.

Requires the pool to exist. Can only be called by a pool operator.

function moveDeposit(string calldata poolName, address from, address to, uint256 amount)
    external
    onlyRole(POOL_OPERATOR_ROLE)
    poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to move the deposit in
fromaddressthe address of the depositor to deduct the deposit from
toaddressthe address of the depositor to add the deposit to
amountuint256the amount to move

batchDeposit

Adds or deducts balances on a per-depositor basis in batches.

Requires the pool to exist. Can only be called by the contract owner.

function batchDeposit(string calldata poolName, Transaction[] calldata transactions)
    external
    onlyRole(POOL_OPERATOR_ROLE)
    poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to move the deposit in
transactionsTransaction[]the set of Transactions to execute on the provided poolName

deposit

Deposits amount of the relevant currency for the pool poolName. This operation assumes that the contract is an approved spender of the depositor. This operation is disabled for delegated pools, use depositFor instead

function deposit(string calldata poolName, uint256 amount, bytes calldata sig) external notDelegated;

Parameters

NameTypeDescription
poolNamestringbytes32 representation of the pool name
amountuint256the amount the user want to invest. Need that for accounting
sigbytesthe signatures generated for the user, including the amount. and verifying the signature.

deposit

Deposits amount of the relevant currency for the pool poolName. This operation assumes that the contract is an approved spender of the depositor. This operation is disabled for delegated pools, use depositFor instead

function deposit(string calldata poolName, uint256 amount, bytes calldata data, bytes calldata sig)
    external
    notDelegated;

Parameters

NameTypeDescription
poolNamestringbytes32 representation of the pool name
amountuint256the amount the user want to invest. Need that for accounting
databytesadditional data as contextual data for off-chain validation
sigbytesthe signatures generated for the user, including the amount. and verifying the signature.

depositFor

Deposits amount of the relevant currency for the pool poolName. This operation assumes that the contract is an approved spender of the depositor.

function depositFor(string calldata poolName, uint256 amount, address depositor, bytes calldata sig)
    external
    onlyDelegate;

Parameters

NameTypeDescription
poolNamestringbytes32 representation of the pool name
amountuint256the amount the user want to invest. Need that for accounting
depositoraddressaddress of the depositor.
sigbytesthe signatures generated for the user, including the amount.

refund

Allows a user to refund their deposited amount from the specified pool. This operation is disabled for delegated pools, use refundTo instead.

Requires the pool to exist.

Requires the pool to be not paused and must have the REFUNDABLE flag set.

function refund(string calldata poolName) external notDelegated;

Parameters

NameTypeDescription
poolNamestringthe name of the pool from which to refund

refund

Allows a user to refund their deposited amount from the specified pool. This operation is disabled for delegated pools, use refundTo instead.

Requires the pool to exist.

Requires the pool to be not paused and must have the REFUNDABLE flag set.

function refund(string calldata poolName, bytes calldata data) external notDelegated;

Parameters

NameTypeDescription
poolNamestringthe name of the pool from which to refund
databytesadditional data as contextual data for off-chain validation

refundTo

Allows a refund of the deposited amount from the specified pool.

Requires the pool to exist.

Requires the pool to be not paused and must have the REFUNDABLE flag set.

function refundTo(string calldata poolName, address depositor, uint256 amount) external onlyDelegate;

Parameters

NameTypeDescription
poolNamestringthe name of the pool from which to refund
depositoraddressaddress of the depositor
amountuint256

depositPoolFunds

Deposits the withdrawn pool funds back. This operation assumes that the contract is an approved spender of the depositor.

Transfers the original collected funds back to the pool app

function depositPoolFunds(string calldata poolName, address depositor, uint256 amount) external onlyDelegate;

Parameters

NameTypeDescription
poolNamestringname of the pool
depositoraddressthe address of the depositor
amountuint256the amount to be deposited back to the pool

poolState

Retrieves the state of the specified pool.

Requires the pool to exist.

function poolState(string calldata poolName) external view poolValid(poolName) returns (PoolState memory);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to retrieve the state of

poolMetrics

Retrieves the metrics of the specified pool.

Requires the pool to exist.

function poolMetrics(string calldata poolName) external view poolValid(poolName) returns (PoolMetrics memory);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to retrieve the metrics of

deposited

Retrieves the amount deposited by the specified depositor in the specified pool.

Requires the pool to exist.

function deposited(string calldata poolName, address depositor) external view poolValid(poolName) returns (uint256);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to retrieve the deposit from
depositoraddressthe address of the depositor

nonce

Retrieves the nonce of the specified depositor in the specified pool.

Requires the pool to exist.

function nonce(string calldata poolName, address depositor) external view poolValid(poolName) returns (uint8);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to retrieve the nonce from
depositoraddressthe address of the depositor

nonce

Retrieves the nonce for create pool signature generation.

function nonce() external view returns (uint24);

poolExists

Checks if the specified pool exists.

function poolExists(string calldata pool) external view returns (bool);

Parameters

NameTypeDescription
poolstringthe name of the pool to check for existence

isPoolActive

Checks if the specified pool is active.

function isPoolActive(string calldata poolName) external view returns (bool);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to check if it is active

withdrawableAmount

Checks if the specified pool is active.

function withdrawableAmount(string calldata poolName) external view returns (uint112);

Parameters

NameTypeDescription
poolNamestringthe name of the pool to check if it is active

supportsInterface

See IERC165-supportsInterface.

function supportsInterface(bytes4 interfaceId)
    public
    view
    virtual
    override(ERC165Upgradeable, IERC165, AccessControlUpgradeable)
    returns (bool);

_grantRolesToMembers

Grants roles to the members based on their specified roles in the struct.

function _grantRolesToMembers(AppMember[] calldata members) private;

Parameters

NameTypeDescription
membersAppMember[]An array of AppMember structs containing the member's address and their role to be granted.

_deposit

Deposits amount of the relevant currency for the pool poolName. This operation assumes that the contract is an approved spender of the depositor.

function _deposit(string calldata poolName, uint256 amount, address depositor, bytes memory data, bytes calldata sig)
    private
    whenNotPaused
    nonReentrant
    poolValid(poolName)
    poolActive(poolName);

Parameters

NameTypeDescription
poolNamestringbytes32 representation of the pool name
amountuint256the amount the user want to invest. Need that for accounting
depositoraddressaddress of the depositor.
databytesadditional data as contextual data for off-chain validation
sigbytesthe signatures generated for the user, including the amount. and verifying the signature.

_refund

Allows a user to refund their deposited amount from the specified pool.

Requires the pool to exist.

Requires the pool to be not paused and must have the REFUNDABLE flag set.

function _refund(string calldata poolName, address depositor, uint256 amount, bytes memory data)
    private
    nonReentrant
    whenNotPaused
    poolNotPaused(poolName)
    poolValid(poolName);

Parameters

NameTypeDescription
poolNamestringthe name of the pool from which to refund
depositoraddressaddress of the depositor to refund from
amountuint256the amount to refund
databytesadditional data as contextual data for off-chain validation

_depositPoolFunds

Deposits the withdrawn pool funds back.

Transfers the original collected funds back to the pool app

function _depositPoolFunds(string calldata poolName, address depositor, uint256 amount) private nonReentrant;

Parameters

NameTypeDescription
poolNamestringname of the pool
depositoraddressthe address of the depositor
amountuint256the amount to be deposited back to the pool

_addDeposit

Adds deposit amount to designated poolName under depositor. As totalCollected is bound by poolSize, overflow is not possible unless poolSize is in a disallowed state to begin with.

function _addDeposit(string calldata poolName, address depositor, uint256 amount, bytes memory data) private;

_deductDeposit

Deducts deposit amount from designated poolName under depositor. As totalCollected is the cumulative sum of all depositors under poolName, underflow is not possible unless totalCollected is in a disallowed state to begin with.

function _deductDeposit(string calldata poolName, address depositor, uint256 amount, bytes memory data) private;

_deductFee

Determines and transfers the mure fee on deposits.

function _deductFee(string calldata poolName, address depositor, address currency, uint256 amount)
    private
    returns (uint256);

Parameters

NameTypeDescription
poolNamestringname of the pool
depositoraddressthe address of the depositor
currencyaddressthe address of the currency being transferred
amountuint256the amount of the currency being transferred

_transferUpdate

Updates the transfer between two addresses with a specified amount of a given currency.

function _transferUpdate(address from, address to, uint256 amount, address currency) private;

Parameters

NameTypeDescription
fromaddressthe address from which the transfer is initiated
toaddressthe address to which the transfer is made
amountuint256the amount of the currency being transferred
currencyaddressthe address of the currency being transferred

_poolExists

Checks whether a pool with the specified name exists.

function _poolExists(string calldata pool) private view returns (bool);

Parameters

NameTypeDescription
poolstringthe name of the pool being checked

_verifyParams

Verifies the validity of the specified pool parameters.

function _verifyParams(PoolParameters calldata config) private view;

Parameters

NameTypeDescription
configPoolParametersthe parameters of the pool being verified

_poolComplete

Checks whether the specified pool has been completed.

function _poolComplete(string calldata poolName) private view returns (bool);

Parameters

NameTypeDescription
poolNamestringthe name of the pool being checked

_hashDeposit

Generates a hashed representation of the specified amount and pool name, along with the sender's nonce.

function _hashDeposit(uint256 amount, string calldata poolName, address depositor) private view returns (bytes32);

Parameters

NameTypeDescription
amountuint256the amount of the deposit
poolNamestringthe name of the pool
depositoraddressaddress of the depositor

_hashCreatePool

Generates a struct hash of the specified pool name and end time, along with the nonce.

function _hashCreatePool(string calldata poolName, uint32 endTime) private view returns (bytes32);

Parameters

NameTypeDescription
poolNamestringthe name of the pool
endTimeuint32the endtime block timestamp for the pool

_verifyPoolSize

Verifies the validity of the pool size for an existing pool.

function _verifyPoolSize(uint112 totalCollected, uint112 newPoolSize) private pure;

Parameters

NameTypeDescription
totalCollecteduint112total collected amount for the pool being updated
newPoolSizeuint112new pool size for the pool being updated

_hasFlag

Checks whether a specific flag is activated within a set of flags.

function _hasFlag(uint16 flags, uint16 flag) private pure returns (bool);

Parameters

NameTypeDescription
flagsuint16the set of flags being checked
flaguint16the flag being checked for activation

_activateFlag

Activates the specified flag within a set of flags.

function _activateFlag(uint16 flags, uint16 flag) private pure returns (uint16);

Parameters

NameTypeDescription
flagsuint16the set of flags being modified
flaguint16the flag being activated

_deactivateFlag

Deactivates the specified flag within a set of flags.

function _deactivateFlag(uint16 flags, uint16 flag) private pure returns (uint16);

Parameters

NameTypeDescription
flagsuint16the set of flags being modified
flaguint16the flag being deactivated

_getDelegateAddress

Retrieves the delegate address from config.

function _getDelegateAddress() private returns (address delegate);

_beforeDeposit

Performs delegate operations before deposit operation.

function _beforeDeposit(
    address delegateAddress,
    string calldata poolName,
    uint256 amount,
    address depositor,
    bytes calldata sig
) private;

Parameters

NameTypeDescription
delegateAddressaddressaddress of the delegate contract
poolNamestringname of the pool
amountuint256deposit amount
depositoraddress
sigbytesdeposit signature

_afterDeposit

Performs delegate operations after deposit operation.

function _afterDeposit(
    address delegateAddress,
    string calldata poolName,
    uint256 amount,
    address depositor,
    bytes calldata sig
) private;

Parameters

NameTypeDescription
delegateAddressaddressaddress of the delegate contract
poolNamestringname of the pool
amountuint256deposit amount
depositoraddress
sigbytesdeposit signature

_beforeRefund

Performs delegate operations before refund operation.

function _beforeRefund(address delegateAddress, string calldata poolName, address depositor) private;

Parameters

NameTypeDescription
delegateAddressaddressaddress of the delegate contract
poolNamestringname of the pool
depositoraddressaddress of the depositor

_afterRefund

Performs delegate operations after refund operation.

function _afterRefund(address delegateAddress, string calldata poolName, address depositor, uint256 amount) private;

Parameters

NameTypeDescription
delegateAddressaddressaddress of the delegate contract
poolNamestringname of the pool
depositoraddressaddress of the depositor
amountuint256the refund amount

_getStorage

Retrieves the storage for the MurePool contract.

function _getStorage() private pure returns (MurePoolStorage storage $);

_getPoolMetricsStorage

Retrieves the storage for the pool metrics.

function _getPoolMetricsStorage() private pure returns (PoolMetricsStorage storage $);

_verifySignature

function _verifySignature(
    uint256 amount,
    string calldata poolName,
    address depositor,
    address signer,
    bytes calldata sig
) private view;

Structs

MurePoolStorage

struct MurePoolStorage {
    mapping(string => PoolState) pools;
    mapping(string => mapping(address => DepositRecord)) deposits;
    uint24 nonce;
}

PoolMetricsStorage

struct PoolMetricsStorage {
    mapping(string => PoolMetrics) poolMetrics;
}

MurePoolFactory

Git Source

Inherits: Ownable, EIP712

Author: Mure

Factory contract for deploying applications as instances of the BeaconProxy contract within the Mure protocol.

Facilitates the secure and efficient deployment of upgradeable app contracts using the beacon proxy pattern. Implements the EIP-712 standard for signature validation and Ownable for access control. The factory contract relies on the MureConfig contract to verify EIP-712 signatures and manage the deployment process. Signatures are added with an expiry to enhance the security of the deployment process by ensuring that the provided signature is only valid within a certain time frame.

State Variables

beaconAddress

address public beaconAddress;

config

MureConfig public config;

DEPLOY_APP_HASH

Struct hash for validating app deployments keccak256("Deployment(string appName,string version,AppMember[] appMembers,uint256 nonce,uint256 deadline,address caller,string data)AppMember(address member,uint8 role)")

bytes32 private constant DEPLOY_APP_HASH = 0xe78e92e91ab6665af572917421100be08c66583917c23ae7a02b72bed7edc218;

nonces

Nonce mapping for signatures to prevent replay

mapping(address => uint256) public nonces;

Functions

constructor

constructor(address beaconAddress_, address config_, string memory name_, string memory version_)
    Ownable(msg.sender)
    EIP712(name_, version_);

deployAppProxy

Deploys an instance of the beacon proxy.

Requires signature for authorization.

function deployAppProxy(
    string calldata appName,
    string calldata version,
    AppMember[] calldata appMembers,
    uint256 deadline,
    string calldata data,
    bytes calldata sig
) external returns (address proxy);

Parameters

NameTypeDescription
appNamestringname of the app contract instance
versionstringof the app contract instance
appMembersAppMember[]array of app members and their roles for the app contract instance
deadlineuint256expiration time of the signature
datastringdata to be emitted on creation
sigbytessignature generated for the user

setBeaconAddress

Sets the beacon address for future proxy creation.

Can only be called by the contract owner.

function setBeaconAddress(address beaconAddress_) external onlyOwner;

Parameters

NameTypeDescription
beaconAddress_addressnew beacon address to be set

_hash

Generates a hashed representation of the app name, version, members, deadline, along with the sender's nonce.

function _hash(
    string calldata appName,
    string calldata version,
    AppMember[] calldata appMembers,
    uint256 deadline,
    string calldata data
) private view returns (bytes32);

Parameters

NameTypeDescription
appNamestringname of the app contract
versionstringversion of the app contract
appMembersAppMember[]array of admin addresses and their corresponding roles for the app contract
deadlineuint256expiry of the signature
datastringdata to be emitted on creation

_hashAppMembers

Computes the keccak256 hash of an array of AppMember structs.

function _hashAppMembers(AppMember[] calldata appMembers) private pure returns (bytes32);

Parameters

NameTypeDescription
appMembersAppMember[]The array of AppMember structs to be hashed.

_extractAppRoles

Extracts and categorizes members into admins and operators based on their roles.

function _extractAppRoles(AppMember[] calldata appMembers) private pure returns (address[] memory, address[] memory);

Parameters

NameTypeDescription
appMembersAppMember[]An array of AppMember structs containing the member address and role.

_validateAdminRoleExists

Validates that there is at least one member with the DEFAULT_ADMIN role in the provided appMembers array.

function _validateAdminRoleExists(AppMember[] calldata appMembers) private pure returns (bool);

Parameters

NameTypeDescription
appMembersAppMember[]An array of AppMember structs containing the member address and role.

Events

Deployment

event Deployment(
    string indexed appName, address[] appAdmins, address[] appOperators, address indexed appAddress, string data
);

BeaconUpdate

event BeaconUpdate(address indexed beaconAddress);

TestUsdc

Git Source

Inherits: ERC20

Functions

constructor

constructor() ERC20("TestUsdc", "USDC");

mint

function mint(address account, uint256 amount) external;

burn

function burn(address account, uint256 amount) external;