Delegate
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
Name | Type | Description |
---|---|---|
poolName | string | name 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
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
depositFunds | uint256 | the amount to be deposited back to the pool |
claimFunds | uint256 | funds for claims |
share
Returns the user depositor value.
function share(string calldata poolName, address depositor) external view returns (uint256);
Parameters
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
depositor | address | address of the depositor |
state
Returns the pool config state.
function state(string calldata poolName) external view returns (PoolConfig memory);
Parameters
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
claim
Processes user claims.
function claim(string calldata poolName) external pluginEnabled(poolName, CLAIM) validPool(poolName);
Parameters
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
activateClaimPlugin
Activates the claim plugin.
function activateClaimPlugin(string calldata poolName, address claimCurrency)
external
onlyRole(DELEGATE_OPERATOR_ROLE)
validPool(poolName);
Parameters
Name | Type | Description |
---|---|---|
poolName | string | name of the pool to activate the plugin on |
claimCurrency | address |
deactivateClaimPlugin
Deactivates the claim plugin.
function deactivateClaimPlugin(string calldata poolName)
external
onlyRole(DELEGATE_OPERATOR_ROLE)
validPool(poolName);
Parameters
Name | Type | Description |
---|---|---|
poolName | string | name 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
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
currency | address | the 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
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
feePercentage | uint16 | the 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
Name | Type | Description |
---|---|---|
poolContract | address | address of the pool app |
setClaimPlugin
Sets the claim plugin address.
function setClaimPlugin(address pluginAddress) external onlyRole(DELEGATE_OPERATOR_ROLE);
Parameters
Name | Type | Description |
---|---|---|
pluginAddress | address | address 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
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
amount | uint256 | the amount to deposit |
sig | bytes | the 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
Name | Type | Description |
---|---|---|
poolName | string | name 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
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
depositor | address | |
amount | uint256 | amount 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
Name | Type | Description |
---|---|---|
to | address | address to be transferred to |
amount | uint256 | the amount to be transferred |
currency | address | the 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
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
depositor | address | address of the depositor |
Returns
Name | Type | Description |
---|---|---|
depositDelta | uint256 | amount from the original deposit to be refunded |
claimDelta | uint256 | amount from the claim reserves to be claimed |
fee | uint256 | fee 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
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
amount | uint256 | the amount to be deposited |
depositor | address | address of the depositor |
sig | bytes | the 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
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
amount | uint256 | the amount to be deposited |
depositor | address | address of the depositor |
sig | bytes | the 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
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
depositor | address | address 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
Name | Type | Description |
---|---|---|
poolName | string | name of the pool |
depositor | address | address of the depositor |
amount | uint256 | refunded 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
Name | Type | Description |
---|---|---|
receiver | address | the address to which the token will be transferred |
currency | address | the address of the token contract |
poolConfig
Retrieves the config of the specified pool.
function poolConfig(string calldata poolName) external view returns (PoolConfig memory);
Parameters
Name | Type | Description |
---|---|---|
poolName | string | the 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
Name | Type | Description |
---|---|---|
poolName | string | the 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
Name | Type | Description |
---|---|---|
poolName | string | the 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
Name | Type | Description |
---|---|---|
poolName | string | the 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
Name | Type | Description |
---|---|---|
poolName | string | the name of the pool to retrieve the deposit from |
depositor | address | the address of the depositor |
poolExists
Checks if the specified pool exists.
function poolExists(string calldata poolName) external view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
poolName | string | the 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
Name | Type | Description |
---|---|---|
poolName | string | the 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
Name | Type | Description |
---|---|---|
from | address | the address from which the transfer is initiated |
to | address | the address to which the transfer is made |
amount | uint256 | the amount of the currency being transferred |
currency | address | the 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
Name | Type | Description |
---|---|---|
plugins | uint16 | the set of plugins being checked |
plugin | uint16 | the plugin being checked for activation |
_activatePlugin
Activates the specified plugin.
function _activatePlugin(uint16 plugins, uint16 plugin) internal pure returns (uint16);
Parameters
Name | Type | Description |
---|---|---|
plugins | uint16 | the set of plugins being modified |
plugin | uint16 | the plugin being activated |
_deactivatePlugin
Deactivates the specified plugin.
function _deactivatePlugin(uint16 plugins, uint16 plugin) internal pure returns (uint16);
Parameters
Name | Type | Description |
---|---|---|
plugins | uint16 | the set of plugins being modified |
plugin | uint16 | the 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
Name | Type | Description |
---|---|---|
address_ | address | the 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
Note: storage-location: erc7201:mure.Delegate
struct DelegateStorage {
mapping(string => mapping(address => uint256)) shares;
mapping(string => PoolConfig) poolConfigs;
address poolContract;
address claimPlugin;
}