Modules
This document is better viewed at https://docs.etherisc.com/contracts/api/modules |
Contracts
AccessController
import "@etherisc/gif-contracts/contracts/modules/AccessController.sol";
The provided smart contract is called "AccessController" and is written in Solidity. It implements the "IAccess" interface and inherits from the "CoreController" contract and the "AccessControlEnumerable" contract. The contract provides functionalities for access control and role management.
Roles:
The contract defines three role identifiers as bytes32 constants: 1. PRODUCT_OWNER_ROLE: Represents the role of a product owner. 2. ORACLE_PROVIDER_ROLE: Represents the role of an oracle provider. 3. RISKPOOL_KEEPER_ROLE: Represents the role of a risk pool keeper.
State Variables:
-
validRole
: A mapping that stores the validity of each role. It maps a role identifier (bytes32) to a boolean value indicating whether the role is valid. -
_defaultAdminSet
: A boolean flag indicating whether the default admin role has been set.
Modifiers:
-
onlyInstanceOperator
: A modifier that restricts access to functions to only instance operators.
Overall, the contract provides a flexible access control mechanism by defining roles and
allowing the assignment, revocation, and validation of roles by instance operators.
It also sets a default admin role and manages the validity of roles through the validRole
mapping.
_afterInitialize()
internal
This function is called after contract initialization and adds the product owner, oracle provider, and riskpool keeper roles.
setDefaultAdminRole(address defaultAdmin)
external
Sets the default admin role for the Access Control List (ACL).
revokeRole(bytes32 role, address principal)
public
Revokes the specified role from the specified principal.
renounceRole(bytes32 role, address principal)
public
Removes the specified principal
from the role
in the access control list (ACL) of the contract.
hasRole(bytes32 role, address principal) → bool
public
Checks if a given principal has a specific role.
getOracleProviderRole() → bytes32
public
Returns the bytes32 identifier of the Oracle Provider role.
getRiskpoolKeeperRole() → bytes32
public
Returns the bytes32 value of the RISKPOOL_KEEPER_ROLE.
The "AccessController" smart contract is a Solidity implementation that provides access control and role management functionalities. It inherits from other contracts and implements the "IAccess" interface. It defines three role identifiers: PRODUCT_OWNER_ROLE, ORACLE_PROVIDER_ROLE, and RISKPOOL_KEEPER_ROLE. The contract has state variables to store role validity and a flag to indicate if the default admin role is set. It includes functions to grant, revoke, and renounce roles, as well as add and invalidate roles. t also has functions to check role membership and retrieve role identifiers. The contract ensures that only instance operators can access certain functions. Overall, it offers a flexible access control mechanism for managing roles and permissions.
BundleController
import "@etherisc/gif-contracts/contracts/modules/BundleController.sol";
The smart contract is used to manage bundles, which are collections of policies.
-
The contract imports other Solidity contracts such as
PolicyController.sol
,CoreController.sol
, andBundleToken.sol
. -
The contract implements the
IBundle
interface and extends theCoreController
contract. -
It defines several mappings to store information about bundles, active policies, locked capital per policy, and the number of unburt bundles for each risk pool.
-
There is a private variable
_bundleCount
to keep track of the number of bundles created. -
The contract includes modifiers to restrict access to certain functions, such as
onlyRiskpoolService
andonlyFundableBundle
.
The contract includes various modifiers and event emitters to enforce access control and emit relevant events.
Overall, the BundleController
contract provides functionality to manage bundles and their associated policies, including creating, funding, locking, unlocking, closing, burning, collateralizing, and releasing policies within a bundle.
-
LogBundleCreated(bundleId, riskpoolId, owner, state, amount)
-
LogBundleCapitalProvided(bundleId, sender, amount, capacity)
-
LogBundleCapitalWithdrawn(bundleId, recipient, amount, capacity)
-
LogBundlePolicyCollateralized(bundleId, processId, amount, capacity)
-
LogBundlePolicyReleased(bundleId, processId, amount, capacity)
create(address owner_, uint256 riskpoolId_, bytes filter_, uint256 amount_) → uint256 bundleId
external
Creates a new bundle and mints a corresponding NFT token. Only callable by the RiskpoolService contract.
defund(uint256 bundleId, uint256 amount)
external
Allows the Riskpool service to withdraw amount
from the bundleId
Bundle.
collateralizePolicy(uint256 bundleId, bytes32 processId, uint256 amount)
external
Collateralizes a policy by locking a specific amount of capital in the corresponding bundle.
processPremium(uint256 bundleId, bytes32 processId, uint256 amount)
external
Process the premium payment for a given bundle and update its balance.
processPayout(uint256 bundleId, bytes32 processId, uint256 amount)
external
Processes a payout for a policy from a bundle.
releasePolicy(uint256 bundleId, bytes32 processId) → uint256 remainingCollateralAmount
external
Release a policy and update the bundle capital.
getOwner(uint256 bundleId) → address
public
Returns the address of the owner of the token associated with the given bundle ID.
getState(uint256 bundleId) → enum IBundle.BundleState
public
Returns the state of the bundle with the given ID.
getTotalValueLocked(uint256 bundleId) → uint256
public
Returns the total value locked in a particular bundle.
getBundle(uint256 bundleId) → struct IBundle.Bundle
public
Returns the bundle with the specified bundle ID.
unburntBundles(uint256 riskpoolId) → uint256
external
Returns the number of unburnt bundles for a given riskpool ID.
_getPoolController() → contract PoolController _poolController
internal
Returns the pool controller contract instance.
_changeState(uint256 bundleId, enum IBundle.BundleState newState)
internal
Changes the state of a bundle.
_setState(uint256 bundleId, enum IBundle.BundleState newState)
internal
Sets the state and updated timestamp of a given bundle.
_checkStateTransition(enum IBundle.BundleState oldState, enum IBundle.BundleState newState)
internal
Checks if a state transition is valid.
The "BundleController" smart contract is designed to manage bundles, which are collections of policies. It imports other Solidity contracts, implements the "IBundle" interface, and extends the "CoreController" contract. The contract includes mappings to store information about bundles, active policies, locked capital, and unburt bundles. It has functions to create bundles, fund and defund them, lock and unlock assets, close and burn bundles, and collateralize and release policies. The contract includes modifiers and event emitters for access control and important events. Overall, it provides comprehensive functionality for managing bundles and their associated policies.
ComponentController
import "@etherisc/gif-contracts/contracts/modules/ComponentController.sol";
The smart contract provides functionality to manage and control components in a system. The contract defines several mappings and sets to store information about components, such as their addresses, IDs, states, and types. It also includes modifiers to restrict access to certain functions based on the caller’s role.
The contract also includes various modifiers (onlyComponentOwnerService
and onlyInstanceOperatorService
) to ensure that only authorized callers can access certain functions.
The contract imports several Solidity files from external dependencies and uses the EnumerableSet
library from the OpenZeppelin library for set operations.
_persistComponent(contract IComponent component) → uint256 id
internal
Persists a new component into the system.
decline(uint256 id)
external
Changes the state of a component with the given ID to "Declined" and emits a LogComponentDeclined event. Calls the declineCallback function of the component with the given ID.
resume(uint256 id)
external
Resumes a component by changing its state to Active and emitting an event. It also calls the resumeCallback() function of the component to inform it about the resuming.
archiveFromComponentOwner(uint256 id)
external
Archives a component with the given ID, changing its state to "Archived" and emitting a LogComponentArchived event. Also calls the archiveCallback function of the component with the given ID, informing it about the archiving.
getComponent(uint256 id) → contract IComponent component
public
Returns the component with the given ID.
getComponentId(address componentAddress) → uint256 id
public
Returns the ID of a registered component given its address.
getComponentType(uint256 id) → enum IComponent.ComponentType componentType
public
Returns the component type of a given component ID.
getComponentState(uint256 id) → enum IComponent.ComponentState componentState
public
Returns the state of the component with the given ID.
getRiskpoolId(uint256 idx) → uint256 riskpoolId
public
Returns the riskpool ID at the specified index.
getProductId(uint256 idx) → uint256 productId
public
Returns the product ID at the given index in the _products set.
getRequiredRole(enum IComponent.ComponentType componentType) → bytes32
external
Returns the required role for a given component type.
components() → uint256 count
public
Returns the number of components currently stored in the contract.
getPolicyFlow(uint256 productId) → address _policyFlow
public
Returns the address of the policy flow for a given product ID.
_changeState(uint256 componentId, enum IComponent.ComponentState newState)
internal
Changes the state of a component.
_checkStateTransition(enum IComponent.ComponentState oldState, enum IComponent.ComponentState newState)
internal
Checks if the state transition is valid. Throws an error if the newState is the same as the oldState. Throws an error if the transition from Created state is not to Proposed state. Throws an error if the transition from Proposed state is not to Active or Declined state. Throws an error if the transition from Declined state is attempted. Throws an error if the transition from Active state is not to Paused or Suspended state. Throws an error if the transition from Paused state is not to Active or Archived state. Throws an error if the transition from Suspended state is not to Active or Archived state. Throws an error if the initial state is not handled.
The "Component Controller" smart contract provides functionality to manage and control components within a system. It includes mappings and sets to store information about components, such as addresses, IDs, states, and types. The contract allows component owners to propose new components, and the contract owner can approve, decline, suspend, resume, pause, unpause, or archive components. Functions are available to retrieve component information, such as ID, type, state, and required role. The contract includes modifiers to restrict access to authorized callers, and it utilizes external dependencies and libraries for set operations. Overall, the contract enables efficient management and control of components in a system.
LicenseController
import "@etherisc/gif-contracts/contracts/modules/LicenseController.sol";
The smart contract serves as a controller contract for managing licenses related to products in an insurance ecosystem.
The contract implements the ILicense
interface and extends the CoreController
contract.
The contract imports two other contracts: ComponentController.sol
and CoreController.sol
, which are expected to be located in specific file paths.
It also imports several interfaces from the "etherisc/gif-interface" library, including IComponent.sol
, IProduct.sol
, and ILicense.sol
.
The contract includes a private variable _component
of type ComponentController
, which is used to interact with the ComponentController
contract.
Overall, the LicenseController
contract serves as a controller for managing licenses and provides functions to check the authorization status and activity of products within an insurance ecosystem.
_afterInitialize()
internal
This function is called after the contract is initialized and sets the _component
variable to the address of the ComponentController
contract.
getAuthorizationStatus(address productAddress) → uint256 productId, bool isAuthorized, address policyFlow
public
Returns the authorization status of a given product address.
_getProduct(uint256 id) → contract IProduct product
internal
Returns the product associated with the given ID.
The "LicenseController" smart contract serves as a controller for managing licenses in an insurance ecosystem. It implements the ILicense interface and extends the CoreController contract. The contract interacts with the ComponentController contract to retrieve information about products and their authorization status. Functions are available to check the authorization status of a product, validate if a product is active, and retrieve product information. The contract plays a crucial role in managing licenses within the insurance ecosystem.
PolicyController
import "@etherisc/gif-contracts/contracts/modules/PolicyController.sol";
The smart contract implements functions for policy operations, including creation, update, cancellation, and retrieval.
It also provides functions for claim creation, confirmation, decline, closure, and payout creation.
Additionally, it includes functions to process payouts, retrieve metadata and application information, and get the number of claims and payouts associated with a policy.
The contract inherits from the IPolicy
interface and the CoreController
contract.
State Variables:
-
metadata
: A mapping that stores metadata associated with policy flows. -
applications
: A mapping that stores insurance applications associated with policy flows. -
policies
: A mapping that stores policies associated with policy flows. -
claims
: A nested mapping that stores claims associated with policies. -
payouts
: A nested mapping that stores payouts associated with policies. -
payoutCount
: A mapping that stores the count of payouts for each policy flow. -
_assigendProcessIds
: A counter variable for assigning unique process IDs. -
_component
: A reference to theComponentController
contract.
Overall, these functions provide functionality for creating, managing, and processing claims and payouts within the insurance policy contract.
-
LogApplicationCreated(processId, premiumAmount, sumInsuredAmount)
-
LogApplicationSumInsuredAdjusted(processId, sumInsuredAmountOld, sumInsuredAmount)
-
LogApplicationPremiumAdjusted(processId, premiumAmountOld, premiumAmount)
-
LogPolicyPremiumAdjusted(processId, premiumExpectedAmountOld, premiumExpectedAmount)
_afterInitialize()
internal
Internal function that sets the _component variable to the address of the ComponentController contract.
createPolicyFlow(address owner, uint256 productId, bytes data) → bytes32 processId
external
Creates a new policy flow for a given owner and product.
createApplication(bytes32 processId, uint256 premiumAmount, uint256 sumInsuredAmount, bytes data)
external
Creates a new insurance application for a given process ID.
underwriteApplication(bytes32 processId)
external
Changes the state of an application to underwritten.
adjustPremiumSumInsured(bytes32 processId, uint256 expectedPremiumAmount, uint256 sumInsuredAmount)
external
This function adjusts the premium and sum insured amount of an insurance policy application.
createClaim(bytes32 processId, uint256 claimAmount, bytes data) → uint256 claimId
external
Creates a new claim for a given policy.
confirmClaim(bytes32 processId, uint256 claimId, uint256 confirmedAmount)
external
Confirms a claim for a policy, updating the claim state to Confirmed and setting the confirmed amount.
declineClaim(bytes32 processId, uint256 claimId)
external
This function allows the Policy contract to decline a claim.
createPayout(bytes32 processId, uint256 claimId, uint256 payoutAmount, bytes data) → uint256 payoutId
external
Creates a new payout for a confirmed claim in a policy.
processPayout(bytes32 processId, uint256 payoutId)
external
Processes a payout for a policy and claim.
getMetadata(bytes32 processId) → struct IPolicy.Metadata _metadata
public
Returns the metadata for the given process ID.
getApplication(bytes32 processId) → struct IPolicy.Application application
public
Returns the application associated with the provided process ID.
getNumberOfClaims(bytes32 processId) → uint256 numberOfClaims
external
Returns the number of claims associated with a given process ID.
getNumberOfPayouts(bytes32 processId) → uint256 numberOfPayouts
external
Returns the number of payouts for a given process ID.
getPolicy(bytes32 processId) → struct IPolicy.Policy policy
public
Returns the policy associated with the given process ID.
getClaim(bytes32 processId, uint256 claimId) → struct IPolicy.Claim claim
public
Returns the claim with the given ID for the specified process.
getPayout(bytes32 processId, uint256 payoutId) → struct IPolicy.Payout payout
public
Retrieves a specific payout from a process.
processIds() → uint256
external
Returns the number of process IDs that have been assigned.
The "PolicyController" smart contract implements functions for policy operations, such as creation, update, cancellation, and retrieval. It also handles claim creation, confirmation, decline, closure, and payout creation. The contract includes mappings to store policies, claims, payouts, and metadata associated with policy flows. It inherits from the IPolicy interface and the CoreController contract. The functions validate inputs, update states, and emit events to manage the lifecycle of policies, claims, and payouts. The contract provides comprehensive functionality for managing insurance policies and associated operations.
PoolController
import "@etherisc/gif-contracts/contracts/modules/PoolController.sol";
The smart contract manages riskpools, their registration, funding, defunding, collateralization, and other related operations.
-
The contract implements the IPool interface and extends the CoreController contract.
-
It imports other contracts such as ComponentController, PolicyController, BundleController, and CoreController.
-
It uses the EnumerableSet library from OpenZeppelin for managing sets of bundle IDs.
-
The contract defines constants for full collateralization level, collateralization level cap, and default maximum number of active bundles.
-
It maintains mappings to store riskpool information, riskpool IDs for products, maximum number of active bundles for riskpools, and active bundle IDs for riskpools.
-
The contract has a private array to store riskpool IDs.
-
It has references to other contracts: ComponentController, PolicyController, and BundleController.
-
The contract defines modifiers for access control to specific functions.
Overall, the PoolController contract provides functionality to manage riskpools, register riskpools, collateralize policies, process premium payments, process payouts, and release collaterals. It acts as an intermediary between the PolicyController, ComponentController, and BundleController contracts to coordinate these operations.
-
LogRiskpoolRegistered(riskpoolId, wallet, erc20Token, collateralizationLevel, sumOfSumInsuredCap)
-
LogRiskpoolRequiredCollateral(processId, sumInsured, collateral)
-
LogRiskpoolCollateralizationFailed(riskpoolId, processId, amount)
-
LogRiskpoolCollateralizationSucceeded(riskpoolId, processId, amount)
-
LogRiskpoolCollateralReleased(riskpoolId, processId, amount)
_afterInitialize()
internal
This function is called after the contract is initialized and sets the addresses of the ComponentController, PolicyController, and BundleController contracts.
registerRiskpool(uint256 riskpoolId, address wallet, address erc20Token, uint256 collateralizationLevel, uint256 sumOfSumInsuredCap)
external
Registers a new riskpool with the given parameters.
setRiskpoolForProduct(uint256 productId, uint256 riskpoolId)
external
Sets the riskpool ID for a given product ID.
defund(uint256 riskpoolId, uint256 amount)
external
Allows the Riskpool service to defund the specified Riskpool by the given amount.
underwrite(bytes32 processId) → bool success
external
Underwrites a policy application by calculating the required collateral amount and asking the responsible riskpool to secure the application.
calculateCollateral(uint256 riskpoolId, uint256 sumInsuredAmount) → uint256 collateralAmount
public
Calculates the required collateral amount for a given riskpool and sum insured amount.
processPremium(bytes32 processId, uint256 amount)
external
Processes the premium payment for a policy.
processPayout(bytes32 processId, uint256 amount)
external
Process a payout for a policy flow in the Pool.
setMaximumNumberOfActiveBundles(uint256 riskpoolId, uint256 maxNumberOfActiveBundles)
external
Sets the maximum number of active bundles for a given riskpool ID.
getMaximumNumberOfActiveBundles(uint256 riskpoolId) → uint256 maximumNumberOfActiveBundles
public
Returns the maximum number of active bundles for a given riskpool ID.
getRiskpool(uint256 riskpoolId) → struct IPool.Pool riskPool
public
Returns the risk pool data for a given risk pool ID.
getRiskPoolForProduct(uint256 productId) → uint256 riskpoolId
external
Returns the risk pool ID associated with the given product ID.
activeBundles(uint256 riskpoolId) → uint256 numberOfActiveBundles
external
Returns the number of active bundles for a given risk pool ID.
getActiveBundleId(uint256 riskpoolId, uint256 bundleIdx) → uint256 bundleId
external
Returns the active bundle ID at the specified index for the given risk pool ID.
addBundleIdToActiveSet(uint256 riskpoolId, uint256 bundleId)
external
Adds a bundle ID to the active set for a specific riskpool ID.
removeBundleIdFromActiveSet(uint256 riskpoolId, uint256 bundleId)
external
Removes a bundle ID from the active set for a given risk pool ID.
getFullCollateralizationLevel() → uint256
external
Returns the full collateralization level of the contract.
_getRiskpoolComponent(struct IPolicy.Metadata metadata) → contract IRiskpool riskpool
internal
Returns the Riskpool contract instance associated with the given policy metadata.
_getRiskpoolForId(uint256 riskpoolId) → contract IRiskpool riskpool
internal
Returns the Riskpool contract instance for a given riskpoolId.
The "PoolController" smart contract manages riskpools and their operations, including registration, funding, defunding, collateralization, and more. It interacts with other contracts such as ComponentController, PolicyController, and BundleController. The contract maintains mappings to store riskpool information and handles functions for funding, defunding, underwriting, calculating collateral, processing premiums and payouts, and releasing collateral. It ensures access control through modifiers and emits events to track the success or failure of operations. The PoolController contract acts as a central component for coordinating riskpool-related operations within the ecosystem.
QueryModule
import "@etherisc/gif-contracts/contracts/modules/QueryModule.sol";
The smart contract implements the "IQuery" interface and extends the "CoreController" contract. The contract imports several external contracts from the "etherisc/gif-interface" repository, including "IComponent.sol", "IOracle.sol", "IQuery.sol", and "IInstanceService.sol". It also imports two local contracts, "ComponentController.sol" and "CoreController.sol".
The contract defines a private variable _component
of type "ComponentController" and an array _oracleRequests
of type "OracleRequest[]".
The contract includes two modifiers:
-
onlyOracleService
: It requires that the caller must be the contract with the address specified by the "OracleService" contract address stored in the CoreController. -
onlyResponsibleOracle
: It checks if the oracle specified by theresponder
address is responsible for the givenrequestId
.
The contract emits the following events:
-
LogOracleRequested
: Indicates the creation of a new oracle request and includes the process ID, request ID, and responsible oracle ID. -
LogOracleResponded
: Indicates the response to an oracle request and includes the process ID, request ID, responder address, and success status. -
LogOracleCanceled
: Indicates the cancellation of an oracle request and includes the request ID.
_afterInitialize()
internal
Internal function that sets the _component
variable to the ComponentController
contract address.
request(bytes32 processId, bytes input, string callbackMethodName, address callbackContractAddress, uint256 responsibleOracleId) → uint256 requestId
external
Creates a new oracle request for a given process with the specified input data and callback information.
respond(uint256 requestId, address responder, bytes data)
external
Responds to an oracle request with the given requestId, responder address, and data.
getProcessId(uint256 requestId) → bytes32 processId
external
Returns the process ID associated with a given request ID.
_getOracle(uint256 id) → contract IOracle oracle
internal
Returns the Oracle component with the specified ID.
The "QueryModule" smart contract implements the IQuery interface and extends the CoreController contract. It interacts with external contracts such as IComponent.sol, IOracle.sol, IQuery.sol, and IInstanceService.sol. The contract allows the creation of oracle requests, enables oracles to respond to requests, cancels requests, and provides functions to retrieve information about requests and oracles. It ensures access control through modifiers and emits events to track the creation, response, and cancellation of oracle requests. The QueryModule contract acts as a module for managing oracle queries within the ecosystem.
RegistryController
import "@etherisc/gif-contracts/contracts/modules/RegistryController.sol";
The smart contract implements the IRegistry
interface and inherits from the CoreController
contract.
The contract provides functionality for registering, deregistering, and accessing contracts within different releases. It maintains mappings and sets to store contract names and addresses in different releases.
-
MAX_CONTRACTS
: A constant variable set to 100, representing the maximum number of contracts allowed in a release. -
release
: A bytes32 variable representing the current release identifier. -
startBlock
: An unsigned integer storing the block number at which the contract was deployed. -
_contracts
: A nested mapping that stores contract addresses based on the release and contract name. -
_contractsInRelease
: A mapping that keeps track of the number of contracts in each release. -
_contractNames
: A private EnumerableSet that stores the names of contracts in a specific release.
The contract emits various events such as LogContractRegistered
and LogContractDeregistered
to notify when contracts are registered or deregistered.
Overall, the RegistryController
contract provides a mechanism to manage and track contracts within different releases, allowing for controlled registration and deregistration of contracts.
initializeRegistry(bytes32 _initialRelease)
public
Initializes the GIF registry with an initial release and sets the deployment block for reading logs.
ensureSender(address sender, bytes32 _contractName) → bool _senderMatches
external
Verifies if the provided 'sender' address matches the address of the contract with the given '_contractName' in the current release.
getContract(bytes32 _contractName) → address _addr
public
Returns the address of a contract by its name.
register(bytes32 _contractName, address _contractAddress)
external
Registers a contract with a given name and address.
getContractInRelease(bytes32 _release, bytes32 _contractName) → address _addr
external
Returns the address of a specific contract within a given release.
registerInRelease(bytes32 _release, bytes32 _contractName, address _contractAddress)
external
Registers a contract in a specific release.
deregisterInRelease(bytes32 _release, bytes32 _contractName)
external
Deregisters a contract name from a specific release.
prepareRelease(bytes32 _newRelease)
external
Prepares a new release by copying all contracts from the current release to the new one.
contracts() → uint256 _numberOfContracts
external
Returns the number of contracts in the current release.
contractName(uint256 idx) → bytes32 _contractName
external
Returns the name of the contract at the specified index in the contractNames set.
_getContractInRelease(bytes32 _release, bytes32 _contractName) → address _addr
internal
Returns the address of a contract in a specific release.
_registerInRelease(bytes32 _release, bool isNewRelease, bytes32 _contractName, address _contractAddress)
internal
Registers a contract in a release.
_deregisterInRelease(bytes32 _release, bytes32 _contractName)
internal
Internal function to deregister a contract in a specific release.
The "RegistryController" smart contract implements the IRegistry interface and inherits from the CoreController contract. It facilitates the registration, deregistration, and access of contracts within different releases. The contract maintains mappings and sets to store contract names and addresses in various releases. It provides functions to register and deregister contracts, retrieve contract addresses, and manage releases. The contract ensures sender verification and emits events to track contract registration and deregistration. The RegistryController contract serves as a centralized registry for managing contracts in different releases within the ecosystem.
TreasuryModule
import "@etherisc/gif-contracts/contracts/modules/TreasuryModule.sol";
The smart contract implements the ITreasury interface and inherits from the CoreController and Pausable contracts. The contract imports several other contracts and interfaces, including ComponentController.sol, PolicyController.sol, BundleController.sol, PoolController.sol, CoreController.sol, TransferHelper.sol, and various interfaces from the "etherisc/gif-interface" and "openzeppelin/contracts" libraries.
The contract defines several state variables, including:
-
FRACTION_FULL_UNIT: a constant representing the full unit value (10^18).
-
FRACTIONAL_FEE_MAX: a constant representing the maximum fractional fee value (25%).
-
event LogTransferHelperInputValidation1Failed: an event that logs a failed input validation.
-
event LogTransferHelperInputValidation2Failed: an event that logs a failed input validation.
-
event LogTransferHelperCallFailed: an event that logs a failed external call.
-
_instanceWalletAddress: a private variable representing the address of the instance wallet.
-
_riskpoolWallet: a mapping of riskpool IDs to wallet addresses.
-
_fees: a mapping of component IDs to FeeSpecification structs.
-
_componentToken: a mapping of product IDs/riskpool IDs to ERC20 token addresses.
-
_bundle: an instance of the BundleController contract.
-
_component: an instance of the ComponentController contract.
-
_policy: an instance of the PolicyController contract.
-
_pool: an instance of the PoolController contract.
The contract includes several modifiers that enforce certain conditions on function execution, such as the instanceWalletDefined modifier, which requires the instance wallet address to be defined; the riskpoolWalletDefinedForProcess modifier, which requires the riskpool wallet address to be defined for a given process ID; the riskpoolWalletDefinedForBundle modifier, which requires the riskpool wallet address to be defined for a given bundle ID; the whenNotSuspended modifier, which requires the contract to not be paused; and the onlyRiskpoolService modifier, which restricts access to the RiskpoolService contract.
The contract contains various functions for managing the treasury, such as setting the product token address, setting the instance wallet address, setting the riskpool wallet address, creating fee specifications, and setting premium and capital fees for components. There are also functions for suspending and resuming the treasury contract.
The contract includes a function to calculate the fee amount and net amount for a given component ID and amount. It also includes functions to process premium payments for policies, either for the remaining premium amount or for a specific amount.
Overall, the TreasuryModule contract provides functionality for managing fees, processing premium payments, and interacting with other controllers and contracts in the system.
-
LogTreasuryProductTokenSet(productId, riskpoolId, erc20Address)
-
LogTreasuryPremiumFeesSet(productId, fixedFee, fractionalFee)
-
LogTreasuryCapitalFeesSet(riskpoolId, fixedFee, fractionalFee)
-
LogTreasuryPremiumTransferred(from, riskpoolWalletAddress, amount)
-
LogTreasuryPayoutTransferred(riskpoolWalletAddress, to, amount)
-
LogTreasuryCapitalTransferred(from, riskpoolWalletAddress, amount)
-
LogTreasuryFeesTransferred(from, instanceWalletAddress, amount)
-
LogTreasuryWithdrawalTransferred(riskpoolWalletAddress, to, amount)
-
LogTreasuryWithdrawalProcessed(riskpoolId, bundleId, amount)
_afterInitialize()
internal
Sets the addresses of the BundleController, ComponentController, PolicyController, and PoolController contracts.
suspend()
external
Suspends the treasury contract, preventing any further transfers or withdrawals. Can only be called by the instance operator.
setProductToken(uint256 productId, address erc20Address)
external
Sets the ERC20 token address for a given product ID and its associated risk pool.
setRiskpoolWallet(uint256 riskpoolId, address riskpoolWalletAddress)
external
Sets the wallet address for a specific riskpool.
createFeeSpecification(uint256 componentId, uint256 fixedFee, uint256 fractionalFee, bytes feeCalculationData) → struct ITreasury.FeeSpecification
external
Creates a fee specification for a given component.
setPremiumFees(struct ITreasury.FeeSpecification feeSpec)
external
Sets the premium fees for a specific component.
setCapitalFees(struct ITreasury.FeeSpecification feeSpec)
external
Sets the fee specification for a given component, which includes the fixed and fractional fees.
calculateFee(uint256 componentId, uint256 amount) → uint256 feeAmount, uint256 netAmount
public
Calculates the fee amount and net amount for a given component ID and amount.
processPremium(bytes32 processId) → bool success, uint256 feeAmount, uint256 netPremiumAmount
external
Processes the premium for a given policy process ID.
processPremium(bytes32 processId, uint256 amount) → bool success, uint256 feeAmount, uint256 netAmount
public
Processes a premium payment for a policy.
processPayout(bytes32 processId, uint256 payoutId) → uint256 feeAmount, uint256 netPayoutAmount
external
Processes a payout for a specific process and payout ID.
processCapital(uint256 bundleId, uint256 capitalAmount) → uint256 feeAmount, uint256 netCapitalAmount
external
Processes capital for a given bundle ID and calculates fees. Transfers fees to the instance wallet and net capital to the riskpool wallet.
processWithdrawal(uint256 bundleId, uint256 amount) → uint256 feeAmount, uint256 netAmount
external
Processes a withdrawal of a specified amount from a bundle, transferring the funds to the bundle owner’s wallet.
getComponentToken(uint256 componentId) → contract IERC20 token
public
Returns the ERC20 token address associated with the given component ID.
getFeeSpecification(uint256 componentId) → struct ITreasury.FeeSpecification
public
Returns the fee specification of a given component.
getRiskpoolWallet(uint256 riskpoolId) → address
public
Returns the wallet address of the specified risk pool.
_calculatePremiumFee(struct ITreasury.FeeSpecification feeSpec, bytes32 processId) → struct IPolicy.Application application, uint256 feeAmount
internal
Calculates the premium fee for a given fee specification and process ID.
_calculateFee(struct ITreasury.FeeSpecification feeSpec, uint256 amount) → uint256 feeAmount
internal
Calculates the fee amount based on the given fee specification and the transaction amount.
_getRiskpoolWallet(bytes32 processId) → uint256 riskpoolId, address riskpoolWalletAddress
internal
Returns the riskpool ID and wallet address for a given process ID.
LogTransferHelperCallFailed(bool callSuccess, uint256 returnDataLength, bytes returnData)
event
The "TreasuryModule" smart contract implements the ITreasury interface and inherits from the CoreController and Pausable contracts. It imports various contracts and interfaces to handle treasury operations. The contract defines state variables, including constants, wallet addresses, fee specifications, and instances of other contracts. It includes modifiers to enforce conditions for function execution. The contract provides functions to set token and wallet addresses, create fee specifications, process premium payments, and manage suspension/resumption. It also calculates fee amounts and net amounts. The TreasuryModule contract serves as a central component for managing fees and treasury operations, interacting with other controllers and contracts within the system.