Fire insurance example components

This directory contains the set of contracts required for the fire insurance. The fire insurance example is a minimal fully permissioned set of example components that can be used to run a (very simple) fire insurance.

The product is built without a distribution and oracle component.

Contracts

FirePool

import "@etherisc/gif-next/contracts/examples/fire/FirePool.sol";
Functions
  • [constructor(registry, fireProductNftId, componentName, authorization)]

  • [_intialize(registry, fireProductNftId, componentName, poolInfo, authorization, initialOwner)]

  • [createBundle(fee, initialAmount, lifetime)]

  • [approveTokenHandler(token, amount)]

  • [setLocked(locked)]

  • [setWallet(newWallet)]

BasicPool
  • [_initializeBasicPool(registry, productNftId, name, poolInfo, authorization, initialOwner)]

  • [stake(bundleNftId, amount)]

  • [unstake(bundleNftId, amount)]

  • [extend(bundleNftId, lifetimeExtension)]

  • [setBundleLocked(bundleNftId, locked)]

  • [closeBundle(bundleNftId)]

  • [setBundleFee(bundleNftId, fee)]

  • [withdrawBundleFees(bundleNftId, amount)]

  • [setMaxBalanceAmount(maxBalanceAmount)]

  • [setFees(poolFee, stakingFee, performanceFee)]

Pool
  • [getContractLocation(name)]

  • [verifyApplication(applicationNftId, bundleNftId, collateralizationAmount)]

  • [processConfirmedClaim(policyNftId, claimId, amount)]

  • [applicationMatchesBundle(applicationNftId, applicationData, bundleNftId, bundleFilter, collateralizationAmount)]

  • [getInitialPoolInfo()]

  • [__Pool_init(registry, productNftId, name, poolInfo, authorization, initialOwner)]

  • [_setPoolFees(poolFee, stakingFee, performanceFee)]

  • [_setMaxBalanceAmount(maxBalanceAmount)]

  • [_fundPoolWallet(amount)]

  • [_defundPoolWallet(amount)]

  • [_createBundle(bundleOwner, fee, lifetime, filter)]

  • [_setBundleFee(bundleNftId, fee)]

  • [_stake(bundleNftId, amount)]

  • [_unstake(bundleNftId, amount)]

  • [_extend(bundleNftId, lifetimeExtension)]

  • [_setBundleLocked(bundleNftId, locked)]

  • [_closeBundle(bundleNftId)]

  • [_withdrawBundleFees(bundleNftId, amount)]

  • [_processFundedClaim(policyNftId, claimId, availableAmount)]

InstanceLinkedComponent
  • [getInstance()]

  • [getAuthorization()]

  • [withdrawFees(amount)]

  • [_sendRequest(oracleNftId, requestData, expiryAt, callbackMethod)]

  • [_cancelRequest(requestId)]

  • [_resendRequest(requestId)]

  • [__InstanceLinkedComponent_init(registry, parentNftId, name, componentType, authorization, isInterceptor, initialOwner)]

  • [_checkAndGetInstanceNftId(registryAddress, parentNftId, componentType)]

  • [_checkAndGetRegistry(registryAddress, objectNftId, requiredType)]

  • [_setWallet(newWallet)]

  • [_getComponentInfo()]

  • [_getInstanceReader()]

  • [_withdrawFees(amount)]

Component
  • [__Component_init(authority, registry, parentNftId, name, componentType, isInterceptor, initialOwner, registryData)]

  • [nftTransferFrom(from, to, tokenId, operator)]

  • [getWallet()]

  • [getTokenHandler()]

  • [getToken()]

  • [getName()]

  • [getVersion()]

  • [getComponentInfo()]

  • [getInitialComponentInfo()]

  • [isNftInterceptor()]

  • [isRegistered()]

  • [_approveTokenHandler(token, amount)]

  • [_nftTransferFrom(from, to, tokenId, operator)]

  • [_setLocked(locked)]

  • [_getServiceAddress(domain)]

Registerable
  • [__Registerable_init(authority, registry, parentNftId, objectType, isInterceptor, initialOwner, data)]

  • [isActive()]

  • [getRelease()]

  • [getInitialInfo()]

NftOwnable
  • [_checkNftType(nftId, expectedObjectType)]

  • [__NftOwnable_init(registry, initialOwner)]

  • [linkToRegisteredNftId()]

  • [getNftId()]

  • [getOwner()]

  • [_linkToNftOwnable(nftOwnableAddress)]

RegistryLinked
  • [__RegistryLinked_init(registry)]

  • [getRegistry()]

InitializableERC165
  • [__ERC165_init()]

  • [_initializeERC165()]

  • [_registerInterface(interfaceId)]

  • [_registerInterfaceNotInitializing(interfaceId)]

  • [supportsInterface(interfaceId)]

AccessManagedUpgradeable
  • [__AccessManaged_init(initialAuthority)]

  • [__AccessManaged_init_unchained(initialAuthority)]

  • [authority()]

  • [setAuthority(newAuthority)]

  • [isConsumingScheduledOp()]

  • [_setAuthority(newAuthority)]

  • [_checkCanCall(caller, data)]

ContextUpgradeable
  • [__Context_init()]

  • [__Context_init_unchained()]

  • [_msgSender()]

  • [_msgData()]

  • [_contextSuffixLength()]

Initializable
  • [_checkInitializing()]

  • [_disableInitializers()]

  • [_getInitializedVersion()]

  • [_isInitializing()]

Events
IPoolComponent
  • [LogPoolVerifiedByPool(pool, applicationNftId, collateralizationAmount)]

IComponent
  • [LogComponentWalletAddressChanged(oldWallet, newWallet)]

  • [LogComponentWalletTokensTransferred(from, to, amount)]

  • [LogComponentTokenHandlerApproved(tokenHandler, token, limit, isMaxAmount)]

INftOwnable
  • [LogNftOwnableNftLinkedToAddress(nftId, owner)]

IAccessManaged
  • [AuthorityUpdated(authority)]

Initializable
  • [Initialized(version)]

constructor(address registry, NftId fireProductNftId, string componentName, contract IAuthorization authorization) public

_intialize(address registry, NftId fireProductNftId, string componentName, struct IComponents.PoolInfo poolInfo, contract IAuthorization authorization, address initialOwner) internal

createBundle(struct Fee fee, Amount initialAmount, Seconds lifetime) → NftId bundleNftId, Amount netStakedAmount external

approveTokenHandler(contract IERC20Metadata token, Amount amount) external

setLocked(bool locked) external

setWallet(address newWallet) external

FirePoolAuthorization

import "@etherisc/gif-next/contracts/examples/fire/FirePoolAuthorization.sol";
Functions
  • [constructor(poolName)]

  • [_setupTargetAuthorizations()]

BasicPoolAuthorization
  • [_setupServiceTargets()]

  • [_setupTokenHandlerAuthorizations()]

Authorization
  • [getTokenHandlerName()]

  • [getTokenHandlerTarget()]

  • [getTarget(targetName)]

  • [getTargets()]

  • [targetExists(target)]

  • [_setupTargets()]

  • [_setupRoles()]

  • [_addCustomRole(roleId, adminRoleId, maxMemberCount, name)]

  • [_addGifTarget(contractName)]

  • [_addInstanceTarget(contractName)]

  • [_addTarget(name)]

  • [_toTargetRoleId(targetDomain)]

  • [_toTargetRoleName(targetName)]

ServiceAuthorization
  • [getDomain()]

  • [getRelease()]

  • [getCommitHash()]

  • [getMainTargetName()]

  • [getMainTarget()]

  • [getServiceDomains()]

  • [getServiceDomain(idx)]

  • [getServiceTarget(serviceDomain)]

  • [getServiceRole(serviceDomain)]

  • [getServiceAddress(serviceDomain)]

  • [getTargetRole(target)]

  • [roleExists(roleId)]

  • [getRoles()]

  • [getRoleInfo(roleId)]

  • [getRoleName(roleId)]

  • [getAuthorizedRoles(target)]

  • [getAuthorizedFunctions(target, roleId)]

  • [_setupDomains()]

  • [_setupDomainAuthorizations()]

  • [_authorizeServiceDomain(serviceDomain, serviceAddress)]

  • [_addTargetWithRole(targetName, roleId, roleName)]

  • [_addRole(roleId, info)]

  • [_authorizeForService(serviceDomain, authorizedDomain)]

  • [_authorizeForTarget(target, authorizedRoleId)]

  • [_authorize(functions, selector, name)]

InitializableERC165
  • [__ERC165_init()]

  • [_initializeERC165()]

  • [_registerInterface(interfaceId)]

  • [_registerInterfaceNotInitializing(interfaceId)]

  • [supportsInterface(interfaceId)]

Initializable
  • [_checkInitializing()]

  • [_disableInitializers()]

  • [_getInitializedVersion()]

  • [_isInitializing()]

Events
Initializable
  • [Initialized(version)]

constructor(string poolName) public

_setupTargetAuthorizations() internal

Sets up the relevant target authorizations for the component. Overwrite this function for use case specific authorizations.

FireProduct

import "@etherisc/gif-next/contracts/examples/fire/FireProduct.sol";

This is the product component for the fire insurance example. It show how to insure a house for a given suminsured in a city. The risk is based on the city. If a fire is reported in the city, the policy holder is able to submit a claim and get a payout.

Functions
  • [constructor(registry, instanceNftid, componentName, authorization)]

  • [_initialize(registry, instanceNftId, componentName, authorization, initialOwner)]

  • [cities()]

  • [city(idx)]

  • [riskId(cityName)]

  • [pauseCity(cityName)]

  • [unpauseCity(cityName)]

  • [calculatePremium(cityName, sumInsured, lifetime, bundleNftId)]

  • [calculateNetPremium(sumInsured, , lifetime, )]

  • [createApplication(cityName, sumInsured, lifetime, bundleNftId)]

  • [initializeCity(cityName)]

  • [createPolicy(policyNftId, activateAt)]

  • [decline(policyNftId)]

  • [expire(policyNftId, expireAt)]

  • [close(policyNftId)]

  • [reportFire(fireId, cityName, damageLevel, reportedAt)]

  • [fire(fireId)]

  • [submitClaim(policyNftId, fireId)]

  • [_checkClaimConditions(policyNftId, policyInfo, fireId)]

  • [_getClaimAmount(policyNftId, sumInsured, damageLevel)]

  • [_damageLevelToPayoutPercentage(damageLevel)]

  • [approveTokenHandler(token, amount)]

  • [setLocked(locked)]

  • [setWallet(newWallet)]

BasicProduct
  • [setFees(productFee, processingFee)]

  • [_initializeBasicProduct(registry, instanceNftId, name, productInfo, feeInfo, authorization, initialOwner)]

Product
  • [registerComponent(component)]

  • [processFundedClaim(policyNftId, claimId, availableAmount)]

  • [calculatePremium(sumInsuredAmount, riskId, lifetime, applicationData, bundleNftId, referralId)]

  • [getInitialProductInfo()]

  • [getInitialFeeInfo()]

  • [__Product_init(registry, instanceNftId, name, productInfo, feeInfo, authorization, initialOwner)]

  • [_setFees(productFee, processingFee)]

  • [_createRisk(id, data)]

  • [_updateRisk(id, data)]

  • [_setRiskLocked(id, locked)]

  • [_closeRisk(id)]

  • [_createApplication(applicationOwner, riskId, sumInsuredAmount, premiumAmount, lifetime, bundleNftId, referralId, applicationData)]

  • [_revoke(applicationNftId)]

  • [_createPolicy(applicationNftId, activateAt, maxPremiumAmount)]

  • [_decline(policyNftId)]

  • [_expire(policyNftId, expireAt)]

  • [_adjustActivation(policyNftId, activateAt)]

  • [_collectPremium(policyNftId, activateAt)]

  • [_activate(policyNftId, activateAt)]

  • [_close(policyNftId)]

  • [_submitClaim(policyNftId, claimAmount, claimData)]

  • [_revokeClaim(policyNftId, claimId)]

  • [_confirmClaim(policyNftId, claimId, confirmedAmount, data)]

  • [_declineClaim(policyNftId, claimId, data)]

  • [_cancelConfirmedClaim(policyNftId, claimId)]

  • [_createPayout(policyNftId, claimId, amount, data)]

  • [_createPayoutForBeneficiary(policyNftId, claimId, amount, beneficiary, data)]

  • [_processPayout(policyNftId, payoutId)]

  • [_cancelPayout(policyNftId, payoutId)]

  • [_getProductStorage()]

InstanceLinkedComponent
  • [getInstance()]

  • [getAuthorization()]

  • [withdrawFees(amount)]

  • [_sendRequest(oracleNftId, requestData, expiryAt, callbackMethod)]

  • [_cancelRequest(requestId)]

  • [_resendRequest(requestId)]

  • [__InstanceLinkedComponent_init(registry, parentNftId, name, componentType, authorization, isInterceptor, initialOwner)]

  • [_checkAndGetInstanceNftId(registryAddress, parentNftId, componentType)]

  • [_checkAndGetRegistry(registryAddress, objectNftId, requiredType)]

  • [_setWallet(newWallet)]

  • [_getComponentInfo()]

  • [_getInstanceReader()]

  • [_withdrawFees(amount)]

Component
  • [__Component_init(authority, registry, parentNftId, name, componentType, isInterceptor, initialOwner, registryData)]

  • [nftTransferFrom(from, to, tokenId, operator)]

  • [getWallet()]

  • [getTokenHandler()]

  • [getToken()]

  • [getName()]

  • [getVersion()]

  • [getComponentInfo()]

  • [getInitialComponentInfo()]

  • [isNftInterceptor()]

  • [isRegistered()]

  • [_approveTokenHandler(token, amount)]

  • [_nftTransferFrom(from, to, tokenId, operator)]

  • [_setLocked(locked)]

  • [_getServiceAddress(domain)]

Registerable
  • [__Registerable_init(authority, registry, parentNftId, objectType, isInterceptor, initialOwner, data)]

  • [isActive()]

  • [getRelease()]

  • [getInitialInfo()]

NftOwnable
  • [_checkNftType(nftId, expectedObjectType)]

  • [__NftOwnable_init(registry, initialOwner)]

  • [linkToRegisteredNftId()]

  • [getNftId()]

  • [getOwner()]

  • [_linkToNftOwnable(nftOwnableAddress)]

RegistryLinked
  • [__RegistryLinked_init(registry)]

  • [getRegistry()]

InitializableERC165
  • [__ERC165_init()]

  • [_initializeERC165()]

  • [_registerInterface(interfaceId)]

  • [_registerInterfaceNotInitializing(interfaceId)]

  • [supportsInterface(interfaceId)]

AccessManagedUpgradeable
  • [__AccessManaged_init(initialAuthority)]

  • [__AccessManaged_init_unchained(initialAuthority)]

  • [authority()]

  • [setAuthority(newAuthority)]

  • [isConsumingScheduledOp()]

  • [_setAuthority(newAuthority)]

  • [_checkCanCall(caller, data)]

ContextUpgradeable
  • [__Context_init()]

  • [__Context_init_unchained()]

  • [_msgSender()]

  • [_msgData()]

  • [_contextSuffixLength()]

Initializable
  • [_checkInitializing()]

  • [_disableInitializers()]

  • [_getInitializedVersion()]

  • [_isInitializing()]

Events
IComponent
  • [LogComponentWalletAddressChanged(oldWallet, newWallet)]

  • [LogComponentWalletTokensTransferred(from, to, amount)]

  • [LogComponentTokenHandlerApproved(tokenHandler, token, limit, isMaxAmount)]

INftOwnable
  • [LogNftOwnableNftLinkedToAddress(nftId, owner)]

IAccessManaged
  • [AuthorityUpdated(authority)]

Initializable
  • [Initialized(version)]

constructor(address registry, NftId instanceNftid, string componentName, contract IAuthorization authorization) public

_initialize(address registry, NftId instanceNftId, string componentName, contract IAuthorization authorization, address initialOwner) internal

cities() → uint256 public

city(uint256 idx) → string public

riskId(string cityName) → RiskId public

pauseCity(string cityName) public

unpauseCity(string cityName) public

calculatePremium(string cityName, Amount sumInsured, Seconds lifetime, NftId bundleNftId) → Amount premiumAmount public

calculateNetPremium(Amount sumInsured, RiskId, Seconds lifetime, bytes) → Amount netPremiumAmount external

createApplication(string cityName, Amount sumInsured, Seconds lifetime, NftId bundleNftId) → NftId policyNftId public

initializeCity(string cityName) → RiskId risk public

createPolicy(NftId policyNftId, Timestamp activateAt) public

Calling this method will lock the sum insured amount in the pool and activate the policy at the given time. It will also collect the tokens payment for the premium. An approval with the correct amount towards the TokenHandler of the product is therefor required.

decline(NftId policyNftId) public

Decline the policy application

expire(NftId policyNftId, Timestamp expireAt) → Timestamp public

close(NftId policyNftId) public

reportFire(uint256 fireId, string cityName, DamageLevel damageLevel, Timestamp reportedAt) public

fire(uint256 fireId) → struct FireProduct.Fire public

submitClaim(NftId policyNftId, uint256 fireId) → ClaimId claimId, PayoutId payoutId public

_checkClaimConditions(NftId policyNftId, struct IPolicy.PolicyInfo policyInfo, uint256 fireId) internal

_getClaimAmount(NftId policyNftId, Amount sumInsured, DamageLevel damageLevel) → Amount internal

_damageLevelToPayoutPercentage(DamageLevel damageLevel) → UFixed internal

approveTokenHandler(contract IERC20Metadata token, Amount amount) external

setLocked(bool locked) external

setWallet(address newWallet) external

FireProductAuthorization

import "@etherisc/gif-next/contracts/examples/fire/FireProductAuthorization.sol";
Functions
  • [constructor(poolName)]

  • [_setupTargetAuthorizations()]

BasicProductAuthorization
  • [_setupServiceTargets()]

  • [_setupTokenHandlerAuthorizations()]

Authorization
  • [getTokenHandlerName()]

  • [getTokenHandlerTarget()]

  • [getTarget(targetName)]

  • [getTargets()]

  • [targetExists(target)]

  • [_setupTargets()]

  • [_setupRoles()]

  • [_addCustomRole(roleId, adminRoleId, maxMemberCount, name)]

  • [_addGifTarget(contractName)]

  • [_addInstanceTarget(contractName)]

  • [_addTarget(name)]

  • [_toTargetRoleId(targetDomain)]

  • [_toTargetRoleName(targetName)]

ServiceAuthorization
  • [getDomain()]

  • [getRelease()]

  • [getCommitHash()]

  • [getMainTargetName()]

  • [getMainTarget()]

  • [getServiceDomains()]

  • [getServiceDomain(idx)]

  • [getServiceTarget(serviceDomain)]

  • [getServiceRole(serviceDomain)]

  • [getServiceAddress(serviceDomain)]

  • [getTargetRole(target)]

  • [roleExists(roleId)]

  • [getRoles()]

  • [getRoleInfo(roleId)]

  • [getRoleName(roleId)]

  • [getAuthorizedRoles(target)]

  • [getAuthorizedFunctions(target, roleId)]

  • [_setupDomains()]

  • [_setupDomainAuthorizations()]

  • [_authorizeServiceDomain(serviceDomain, serviceAddress)]

  • [_addTargetWithRole(targetName, roleId, roleName)]

  • [_addRole(roleId, info)]

  • [_authorizeForService(serviceDomain, authorizedDomain)]

  • [_authorizeForTarget(target, authorizedRoleId)]

  • [_authorize(functions, selector, name)]

InitializableERC165
  • [__ERC165_init()]

  • [_initializeERC165()]

  • [_registerInterface(interfaceId)]

  • [_registerInterfaceNotInitializing(interfaceId)]

  • [supportsInterface(interfaceId)]

Initializable
  • [_checkInitializing()]

  • [_disableInitializers()]

  • [_getInitializedVersion()]

  • [_isInitializing()]

Events
Initializable
  • [Initialized(version)]

constructor(string poolName) public

_setupTargetAuthorizations() internal

Sets up the relevant target authorizations for the component. Overwrite this function for use case specific authorizations.

FireUSD

import "@etherisc/gif-next/contracts/examples/fire/FireUSD.sol";

FireUSD is a stablecoin with 6 decimals and an initial supply of 1 Billion tokens.

Functions
  • [constructor()]

  • [decimals()]

ERC20
  • [name()]

  • [symbol()]

  • [totalSupply()]

  • [balanceOf(account)]

  • [transfer(to, value)]

  • [allowance(owner, spender)]

  • [approve(spender, value)]

  • [transferFrom(from, to, value)]

  • [_transfer(from, to, value)]

  • [_update(from, to, value)]

  • [_mint(account, value)]

  • [_burn(account, value)]

  • [_approve(owner, spender, value)]

  • [_approve(owner, spender, value, emitEvent)]

  • [_spendAllowance(owner, spender, value)]

Events
IERC20
  • [Transfer(from, to, value)]

  • [Approval(owner, spender, value)]

constructor() public

decimals() → uint8 public

Returns the number of decimals used to get its user representation. For example, if decimals equals 2, a balance of 505 tokens should be displayed to a user as 5.05 (505 / 10 ** 2).

Tokens usually opt for a value of 18, imitating the relationship between Ether and Wei. This is the default value returned by this function, unless it’s overridden.

This information is only used for display purposes: it in no way affects any of the arithmetic of the contract, including {IERC20-balanceOf} and {IERC20-transfer}.