diff --git a/docs/index.md b/docs/index.md index 462318f..84cd253 100644 --- a/docs/index.md +++ b/docs/index.md @@ -705,18 +705,10 @@ struct ChequeManagerStorage { } ``` -### ChequeVerified - -```solidity -event ChequeVerified(address fromCMAccount, address toCMAccount, address fromBot, address toBot, uint256 counter, uint256 amount, uint256 payment) -``` - -Cheque verified event. Emitted when a cheque is verified. - ### ChequeCashedIn ```solidity -event ChequeCashedIn(address fromBot, address toBot, uint256 counter, uint256 paid, uint256 developerFee) +event ChequeCashedIn(address fromCMAccount, address toCMAccount, address fromBot, address toBot, uint256 counter, uint256 amount, uint256 paidChequeAmount, uint256 paidDeveloperFee) ``` Cash-in event. Emitted when a cheque is cashed in. @@ -823,7 +815,7 @@ recover the signer. ### verifyCheque ```solidity -function verifyCheque(address fromCMAccount, address toCMAccount, address toBot, uint256 counter, uint256 amount, uint256 createdAt, uint256 expiresAt, bytes signature) public returns (address signer, uint256 paymentAmount) +function verifyCheque(address fromCMAccount, address toCMAccount, address toBot, uint256 counter, uint256 amount, uint256 createdAt, uint256 expiresAt, bytes signature) public view returns (address signer, uint256 paymentAmount) ``` Returns signer and payment amount if the signature is valid for the @@ -1061,14 +1053,6 @@ Returns the gas money withdrawal details for an account. | periodStart | uint256 | timestamp of the withdrawal period start | | withdrawnAmount | uint256 | amount withdrawn within the period | -## ICMAccount - -### initialize - -```solidity -function initialize(address manager, address bookingToken, uint256 prefundAmount, address owner, address upgrader) external -``` - ## BookingTokenOperator Booking token operator contract is used by the {CMAccount} contract to mint @@ -1148,1629 +1132,1629 @@ function buyReservedToken(uint256 tokenId) external payable function getReservationPrice(uint256 tokenId) external view returns (uint256 price, contract IERC20 paymentToken) ``` -## CMAccountManager +## ICMAccountManager -This contract manages the creation of the Camino Messenger accounts by -deploying {ERC1967Proxy} proxies that point to the{CMAccount} implementation -address. +### getAccountImplementation -Create CM Account: Users who want to create an account should call -`createCMAccount(address admin, address upgrader)` function with addresses of -the accounts admin and upgrader roles and also send the pre fund amount, -which is currently set as 100 CAMs. When the manager contract is paused, -account creation is stopped. +```solidity +function getAccountImplementation() external view returns (address) +``` -Developer Fee: This contracts also keeps the info about the developer wallet -and fee basis points. Which are used during the cheque cash in to pay for the -developer fee. +### getDeveloperFeeBp -Service Registry: {CMAccountManager} also acts as a registry for the services -that {CMAccount} contracts add as a supported or wanted service. Registry -works by hashing (keccak256) the service name (string) and creating a mapping -as keccak256(serviceName) => serviceName. And provides functions that -{CMAccount} function uses to register services. The {CMAccount} only keeps -the hashes (byte32) of the registered services. +```solidity +function getDeveloperFeeBp() external view returns (uint256) +``` -### PAUSER_ROLE +### getDeveloperWallet ```solidity -bytes32 PAUSER_ROLE +function getDeveloperWallet() external view returns (address) ``` -Pauser role can pause the contract. Currently this only affects the -creation of CM Accounts. When paused, account creation is stopped. - -### UPGRADER_ROLE +### isCMAccount ```solidity -bytes32 UPGRADER_ROLE +function isCMAccount(address account) external view returns (bool) ``` -Upgrader role can upgrade the contract to a new implementation. +### getRegisteredServiceHashByName -### VERSIONER_ROLE +```solidity +function getRegisteredServiceHashByName(string serviceName) external view returns (bytes32 serviceHash) +``` + +### getRegisteredServiceNameByHash ```solidity -bytes32 VERSIONER_ROLE +function getRegisteredServiceNameByHash(bytes32 serviceHash) external view returns (string serviceName) ``` -Versioner role can set new {CMAccount} implementation address. When a -new implementation address is set, it is used for the new {CMAccount} -creations. +## PartnerConfiguration -The old {CMAccount} contracts are not affected by this. Owners of those -should do the upgrade manually by calling the `upgradeToAndCall(address)` -function on the account. +Partner Configuration is used by the {CMAccount} contract to register +supported and wanted services by the partner. -### FEE_ADMIN_ROLE +### Service + +Struct for storing supported service details for suppliers ```solidity -bytes32 FEE_ADMIN_ROLE +struct Service { + uint256 _fee; + bool _restrictedRate; + string[] _capabilities; +} ``` -Fee admin role can set the developer fee basis points which used for -calculating the developer fee that is cut from the cheque payments. - -### DEVELOPER_WALLET_ADMIN_ROLE +### PaymentInfo ```solidity -bytes32 DEVELOPER_WALLET_ADMIN_ROLE +struct PaymentInfo { + bool _supportsOffChainPayment; + struct EnumerableSet.AddressSet _supportedTokens; +} ``` -Developer wallet admin role can set the developer wallet address -which is used to receive the developer fee. - -### PREFUND_ADMIN_ROLE +### PartnerConfigurationStorage ```solidity -bytes32 PREFUND_ADMIN_ROLE +struct PartnerConfigurationStorage { + struct EnumerableSet.Bytes32Set _servicesHashSet; + mapping(bytes32 => struct PartnerConfiguration.Service) _supportedServices; + struct PartnerConfiguration.PaymentInfo _paymentInfo; + struct EnumerableSet.AddressSet _publicKeyAddressesSet; + mapping(address => bytes) _publicKeys; + struct EnumerableSet.Bytes32Set _wantedServicesHashSet; +} ``` -Prefund admin role can set the mandatory prefund amount for {CMAccount} -contracts. - -### SERVICE_REGISTRY_ADMIN_ROLE +### ServiceAlreadyExists ```solidity -bytes32 SERVICE_REGISTRY_ADMIN_ROLE +error ServiceAlreadyExists(bytes32 serviceHash) ``` -Service registry admin role can add and remove services to the service -registry mapping. Implemented by {ServiceRegistry} contract. - -### CMACCOUNT_ROLE +### ServiceDoesNotExist ```solidity -bytes32 CMACCOUNT_ROLE +error ServiceDoesNotExist(bytes32 serviceHash) ``` -This role is granted to the created CM Accounts. It is used to keep -an enumerable list of CM Accounts. +### WantedServiceAlreadyExists -### CMAccountInfo +```solidity +error WantedServiceAlreadyExists(bytes32 serviceHash) +``` -CMAccount info struct, to keep track of created CM Accounts and their -creators. +### WantedServiceDoesNotExist ```solidity -struct CMAccountInfo { - bool isCMAccount; - address creator; -} +error WantedServiceDoesNotExist(bytes32 serviceHash) ``` -### CMAccountManagerStorage +### PaymentTokenAlreadyExists ```solidity -struct CMAccountManagerStorage { - address _latestAccountImplementation; - uint256 _prefundAmount; - address _developerWallet; - uint256 _developerFeeBp; - address _bookingToken; - mapping(address => struct CMAccountManager.CMAccountInfo) _cmAccountInfo; -} +error PaymentTokenAlreadyExists(address token) ``` -### CMAccountCreated +### PaymentTokenDoesNotExist ```solidity -event CMAccountCreated(address account) +error PaymentTokenDoesNotExist(address token) ``` -CM Account created event. - -#### Parameters +### PublicKeyAlreadyExists -| Name | Type | Description | -| ------- | ------- | -------------------------------- | -| account | address | The address of the new CMAccount | +```solidity +error PublicKeyAlreadyExists(address pubKeyAddress) +``` -### CMAccountImplementationUpdated +### PublicKeyDoesNotExist ```solidity -event CMAccountImplementationUpdated(address oldImplementation, address newImplementation) +error PublicKeyDoesNotExist(address pubKeyAddress) ``` -CM Account implementation address updated event. - -#### Parameters +### InvalidPublicKeyUseType -| Name | Type | Description | -| ----------------- | ------- | ------------------------------ | -| oldImplementation | address | The old implementation address | -| newImplementation | address | The new implementation address | +```solidity +error InvalidPublicKeyUseType(uint8 use) +``` -### DeveloperWalletUpdated +### ServiceAdded ```solidity -event DeveloperWalletUpdated(address oldDeveloperWallet, address newDeveloperWallet) +event ServiceAdded(bytes32 serviceHash) ``` -Developer wallet address updated event. - -#### Parameters +### ServiceRemoved -| Name | Type | Description | -| ------------------ | ------- | -------------------------------- | -| oldDeveloperWallet | address | The old developer wallet address | -| newDeveloperWallet | address | The new developer wallet address | +```solidity +event ServiceRemoved(bytes32 serviceHash) +``` -### DeveloperFeeBpUpdated +### WantedServiceAdded ```solidity -event DeveloperFeeBpUpdated(uint256 oldDeveloperFeeBp, uint256 newDeveloperFeeBp) +event WantedServiceAdded(bytes32 serviceHash) ``` -Developer fee basis points updated event. - -#### Parameters +### WantedServiceRemoved -| Name | Type | Description | -| ----------------- | ------- | ---------------------------------- | -| oldDeveloperFeeBp | uint256 | The old developer fee basis points | -| newDeveloperFeeBp | uint256 | The new developer fee basis points | +```solidity +event WantedServiceRemoved(bytes32 serviceHash) +``` -### BookingTokenAddressUpdated +### ServiceFeeUpdated ```solidity -event BookingTokenAddressUpdated(address oldBookingToken, address newBookingToken) +event ServiceFeeUpdated(bytes32 serviceHash, uint256 fee) ``` -Booking token address updated event. - -#### Parameters +### ServiceRestrictedRateUpdated -| Name | Type | Description | -| --------------- | ------- | ----------------------------- | -| oldBookingToken | address | The old booking token address | -| newBookingToken | address | The new booking token address | +```solidity +event ServiceRestrictedRateUpdated(bytes32 serviceHash, bool restrictedRate) +``` -### CMAccountInvalidImplementation +### ServiceCapabilitiesUpdated ```solidity -error CMAccountInvalidImplementation(address implementation) +event ServiceCapabilitiesUpdated(bytes32 serviceHash) ``` -The implementation of the CMAccount is invalid. - -#### Parameters +### ServiceCapabilityAdded -| Name | Type | Description | -| -------------- | ------- | ------------------------------------------- | -| implementation | address | The implementation address of the CMAccount | +```solidity +event ServiceCapabilityAdded(bytes32 serviceHash, string capability) +``` -### CMAccountInvalidAdmin +### ServiceCapabilityRemoved ```solidity -error CMAccountInvalidAdmin(address admin) +event ServiceCapabilityRemoved(bytes32 serviceHash, string capability) ``` -The admin address is invalid. - -#### Parameters +### PaymentTokenAdded -| Name | Type | Description | -| ----- | ------- | ----------------- | -| admin | address | The admin address | +```solidity +event PaymentTokenAdded(address token) +``` -### InvalidDeveloperWallet +### PaymentTokenRemoved ```solidity -error InvalidDeveloperWallet(address developerWallet) +event PaymentTokenRemoved(address token) ``` -Invalid developer address. +### OffChainPaymentSupportUpdated -#### Parameters +```solidity +event OffChainPaymentSupportUpdated(bool supportsOffChainPayment) +``` -| Name | Type | Description | -| --------------- | ------- | ---------------------------- | -| developerWallet | address | The developer wallet address | - -### InvalidBookingTokenAddress +### PublicKeyAdded ```solidity -error InvalidBookingTokenAddress(address bookingToken) +event PublicKeyAdded(address pubKeyAddress) ``` -Invalid booking token address. - -#### Parameters - -| Name | Type | Description | -| ------------ | ------- | ------------------------- | -| bookingToken | address | The booking token address | - -### IncorrectPrefundAmount +### PublicKeyRemoved ```solidity -error IncorrectPrefundAmount(uint256 expected, uint256 sended) +event PublicKeyRemoved(address pubKeyAddress) ``` -Incorrect pre fund amount. - -#### Parameters - -| Name | Type | Description | -| -------- | ------- | ---------------------------- | -| expected | uint256 | The expected pre fund amount | -| sended | uint256 | | - -### constructor +### \_\_PartnerConfiguration_init ```solidity -constructor() public +function __PartnerConfiguration_init() internal ``` -### initialize +### \_\_PartnerConfiguration_init_unchained ```solidity -function initialize(address defaultAdmin, address pauser, address upgrader, address versioner, address developerWallet, uint256 developerFeeBp) public +function __PartnerConfiguration_init_unchained() internal ``` -### pause +### \_addService ```solidity -function pause() public +function _addService(bytes32 serviceHash, uint256 fee, string[] capabilities, bool restrictedRate) internal virtual ``` -Pauses the CMAccountManager contract. Currently this only affects the -creation of CMAccount. When paused, account creation is stopped. - -### unpause +Adds a supported Service object for a given hash. -```solidity -function unpause() public -``` +#### Parameters -Unpauses the CMAccountManager contract. +| Name | Type | Description | +| -------------- | -------- | --------------------------------------------- | +| serviceHash | bytes32 | Hash of the service | +| fee | uint256 | Fee for the service | +| capabilities | string[] | Capabilities for the service | +| restrictedRate | bool | If the service is restricted to pre-agreement | -### \_authorizeUpgrade +### \_removeService ```solidity -function _authorizeUpgrade(address newImplementation) internal +function _removeService(bytes32 serviceHash) internal virtual ``` -Authorization for the CMAccountManager contract upgrade. - -### createCMAccount +Removes a supported Service object for a given hash. -```solidity -function createCMAccount(address admin, address upgrader) external payable returns (address) -``` +#### Parameters -Creates CMAccount by deploying a ERC1967Proxy with the CMAccount -implementation from the manager. +| Name | Type | Description | +| ----------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | -Because this function is deploying a contract, it reverts if the caller is -not KYC or KYB verified. (For EOAs only) +### \_setServiceFee -Caller must send the pre-fund amount with the transaction. +```solidity +function _setServiceFee(bytes32 serviceHash, uint256 fee) internal virtual +``` -_Emits a {CMAccountCreated} event._ +Sets the Service fee for a given hash. -### \_setCMAccountInfo +#### Parameters -```solidity -function _setCMAccountInfo(address account, struct CMAccountManager.CMAccountInfo info) internal -``` +| Name | Type | Description | +| ----------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | +| fee | uint256 | Fee | -### getCMAccountCreator +### \_setServiceRestrictedRate ```solidity -function getCMAccountCreator(address account) public view returns (address) +function _setServiceRestrictedRate(bytes32 serviceHash, bool restrictedRate) internal virtual ``` -Returns the given account's creator. +Sets the Service restricted rate for a given hash. #### Parameters -| Name | Type | Description | -| ------- | ------- | ------------------- | -| account | address | The account address | +| Name | Type | Description | +| -------------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | +| restrictedRate | bool | Restricted rate | -### isCMAccount +### \_setServiceCapabilities ```solidity -function isCMAccount(address account) public view returns (bool) +function _setServiceCapabilities(bytes32 serviceHash, string[] capabilities) internal virtual ``` -Check if an address is CMAccount created by the manager. +Sets the Service capabilities for a given hash. #### Parameters -| Name | Type | Description | -| ------- | ------- | ---------------------------- | -| account | address | The account address to check | +| Name | Type | Description | +| ------------ | -------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | +| capabilities | string[] | Capabilities | -### getAccountImplementation +### \_addServiceCapability ```solidity -function getAccountImplementation() public view returns (address) +function _addServiceCapability(bytes32 serviceHash, string capability) internal virtual ``` -Returns the CMAccount implementation address. +Adds a capability to the service. -### setAccountImplementation +#### Parameters + +| Name | Type | Description | +| ----------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | +| capability | string | Capability | + +### \_removeServiceCapability ```solidity -function setAccountImplementation(address newImplementation) public +function _removeServiceCapability(bytes32 serviceHash, string capability) internal virtual ``` -Set a new CMAccount implementation address. +Removes a capability from the service. #### Parameters -| Name | Type | Description | -| ----------------- | ------- | ------------------------------ | -| newImplementation | address | The new implementation address | +| Name | Type | Description | +| ----------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | +| capability | string | Capability | -### \_setAccountImplementation +### getAllServiceHashes ```solidity -function _setAccountImplementation(address newImplementation) internal +function getAllServiceHashes() public view returns (bytes32[] serviceHashes) ``` -### getPrefundAmount +Returns all supported service hashes. + +### getService ```solidity -function getPrefundAmount() public view returns (uint256) +function getService(bytes32 serviceHash) public view virtual returns (struct PartnerConfiguration.Service service) ``` -Returns the prefund amount. +Returns the Service object for a given hash. Service object contains fee and capabilities. -### setPrefundAmount +`serviceHash` is keccak256 hash of the pkg + service name as: -```solidity -function setPrefundAmount(uint256 newPrefundAmount) public +```text + ┌────────────── pkg ─────────────┐ ┌───── service name ─────┐ +keccak256("cmp.services.accommodation.v1alpha.AccommodationSearchService") ``` -Sets the prefund amount. - -### getBookingTokenAddress +_These services are coming from the Camino Messenger Protocol's protobuf +definitions._ -```solidity -function getBookingTokenAddress() public view returns (address) -``` +#### Parameters -Returns the booking token address. +| Name | Type | Description | +| ----------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | -### setBookingTokenAddress +### getServiceFee ```solidity -function setBookingTokenAddress(address token) public +function getServiceFee(bytes32 serviceHash) public view virtual returns (uint256 fee) ``` -Sets booking token address. +Returns the fee for a given service hash. -### \_setBookingTokenAddress +#### Parameters -```solidity -function _setBookingTokenAddress(address token) internal -``` +| Name | Type | Description | +| ----------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | -### getDeveloperWallet +### getServiceRestrictedRate ```solidity -function getDeveloperWallet() public view returns (address developerWallet) +function getServiceRestrictedRate(bytes32 serviceHash) public view virtual returns (bool restrictedRate) ``` -Returns developer wallet address. - -### setDeveloperWallet +Returns the restricted rate for a given service hash. -```solidity -function setDeveloperWallet(address developerWallet) public -``` +#### Parameters -Sets developer wallet address. +| Name | Type | Description | +| ----------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | -### getDeveloperFeeBp +### getServiceCapabilities ```solidity -function getDeveloperFeeBp() public view returns (uint256 developerFeeBp) +function getServiceCapabilities(bytes32 serviceHash) public view virtual returns (string[] capabilities) ``` -Returns developer fee in basis points. +Returns the capabilities for a given service hash. -### setDeveloperFeeBp +#### Parameters + +| Name | Type | Description | +| ----------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | + +### \_addWantedService ```solidity -function setDeveloperFeeBp(uint256 bp) public +function _addWantedService(bytes32 serviceHash) internal virtual ``` -Sets developer fee in basis points. +Adds a wanted service hash to the wanted services set. -A basis point (bp) is one hundredth of 1 percentage point. +Reverts if the service already exists. -1 bp = 0.01%, 1/10,000⁠, or 0.0001. -10 bp = 0.1%, 1/1,000⁠, or 0.001. -100 bp = 1%, ⁠1/100⁠, or 0.01. +#### Parameters -### registerService +| Name | Type | Description | +| ----------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | + +### \_removeWantedService ```solidity -function registerService(string serviceName) public +function _removeWantedService(bytes32 serviceHash) internal virtual ``` -Registers a given service name. CM Accounts can only register services -if they are also registered in the service registry on the manager contract. +Removes a wanted service hash from the wanted services set. + +Reverts if the service does not exist. #### Parameters -| Name | Type | Description | -| ----------- | ------ | ------------------- | -| serviceName | string | Name of the service | +| Name | Type | Description | +| ----------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | -### unregisterService +### getWantedServiceHashes ```solidity -function unregisterService(string serviceName) public +function getWantedServiceHashes() public view virtual returns (bytes32[] serviceHashes) ``` -Unregisters a given service name. CM Accounts will not be able to register -the service anymore. +Returns all wanted service hashes. -#### Parameters - -| Name | Type | Description | -| ----------- | ------ | ------------------- | -| serviceName | string | Name of the service | - -## ICMAccountManager - -### getAccountImplementation +#### Return Values -```solidity -function getAccountImplementation() external view returns (address) -``` +| Name | Type | Description | +| ------------- | --------- | --------------------- | +| serviceHashes | bytes32[] | Wanted service hashes | -### getDeveloperFeeBp +### \_addSupportedToken ```solidity -function getDeveloperFeeBp() external view returns (uint256) +function _addSupportedToken(address _token) internal virtual ``` -### getDeveloperWallet - -```solidity -function getDeveloperWallet() external view returns (address) -``` +Adds a supported payment token. -### isCMAccount +#### Parameters -```solidity -function isCMAccount(address account) external view returns (bool) -``` +| Name | Type | Description | +| ------- | ------- | --------------------------------- | +| \_token | address | Payment token address to be added | -### getRegisteredServiceHashByName +### \_removeSupportedToken ```solidity -function getRegisteredServiceHashByName(string serviceName) external view returns (bytes32 serviceHash) +function _removeSupportedToken(address _token) internal virtual ``` -### getRegisteredServiceNameByHash +Removes a supported payment token. -```solidity -function getRegisteredServiceNameByHash(bytes32 serviceHash) external view returns (string serviceName) -``` +#### Parameters -## CMAccountManagerV2 +| Name | Type | Description | +| ------- | ------- | ----------------------------------- | +| \_token | address | Payment token address to be removed | -### getVersion +### getSupportedTokens ```solidity -function getVersion() public pure returns (string) +function getSupportedTokens() public view virtual returns (address[] tokens) ``` -## PartnerConfiguration +Returns supported token addresses. -Partner Configuration is used by the {CMAccount} contract to register -supported and wanted services by the partner. +#### Return Values -### Service +| Name | Type | Description | +| ------ | --------- | ------------------------- | +| tokens | address[] | Supported token addresses | -Struct for storing supported service details for suppliers +### \_setOffChainPaymentSupported ```solidity -struct Service { - uint256 _fee; - bool _restrictedRate; - string[] _capabilities; -} +function _setOffChainPaymentSupported(bool _supportsOffChainPayment) internal virtual ``` -### PaymentInfo +Sets the off-chain payment support is supported. + +### offChainPaymentSupported ```solidity -struct PaymentInfo { - bool _supportsOffChainPayment; - struct EnumerableSet.AddressSet _supportedTokens; -} +function offChainPaymentSupported() public view virtual returns (bool) ``` -### PartnerConfigurationStorage +Returns true if off-chain payment is supported for the given service. + +### \_addPublicKey ```solidity -struct PartnerConfigurationStorage { - struct EnumerableSet.Bytes32Set _servicesHashSet; - mapping(bytes32 => struct PartnerConfiguration.Service) _supportedServices; - struct PartnerConfiguration.PaymentInfo _paymentInfo; - struct EnumerableSet.AddressSet _publicKeyAddressesSet; - mapping(address => bytes) _publicKeys; - struct EnumerableSet.Bytes32Set _wantedServicesHashSet; -} +function _addPublicKey(address pubKeyAddress, bytes publicKeyData) internal virtual ``` -### ServiceAlreadyExists +Adds public key with an address. Reverts if the public key already +exists. -```solidity -error ServiceAlreadyExists(bytes32 serviceHash) -``` +Beware: This functions does not check if the public key is actually for the +given address. -### ServiceDoesNotExist +### \_removePublicKey ```solidity -error ServiceDoesNotExist(bytes32 serviceHash) +function _removePublicKey(address pubKeyAddress) internal virtual ``` -### WantedServiceAlreadyExists +Removes the public key for a given address -```solidity -error WantedServiceAlreadyExists(bytes32 serviceHash) -``` +Reverts if the public key does not exist -### WantedServiceDoesNotExist +### getPublicKeysAddresses ```solidity -error WantedServiceDoesNotExist(bytes32 serviceHash) +function getPublicKeysAddresses() public view virtual returns (address[] pubKeyAddresses) ``` -### PaymentTokenAlreadyExists +Returns the addresses of all public keys. These can then be used to +retrieve the public keys the `getPublicKey(address)` function. + +### getPublicKey ```solidity -error PaymentTokenAlreadyExists(address token) +function getPublicKey(address pubKeyAddress) public view virtual returns (bytes data) ``` -### PaymentTokenDoesNotExist +Returns the public key for a given address. -```solidity -error PaymentTokenDoesNotExist(address token) -``` +Reverts if the public key does not exist -### PublicKeyAlreadyExists +#### Parameters -```solidity -error PublicKeyAlreadyExists(address pubKeyAddress) -``` +| Name | Type | Description | +| ------------- | ------- | ------------------------- | +| pubKeyAddress | address | Address of the public key | -### PublicKeyDoesNotExist +## ICMAccount + +### initialize ```solidity -error PublicKeyDoesNotExist(address pubKeyAddress) +function initialize(address manager, address bookingToken, uint256 prefundAmount, address owner, address upgrader) external ``` -### InvalidPublicKeyUseType +## BookingToken -```solidity -error InvalidPublicKeyUseType(uint8 use) -``` +Booking Token contract represents a booking done on the Camino Messenger. -### ServiceAdded +Suppliers can mint Booking Tokens and reserve them for a distributor address to +buy. -```solidity -event ServiceAdded(bytes32 serviceHash) -``` +Booking Tokens can have zero price, meaning that the payment will be done +off-chain. -### ServiceRemoved +When a token is minted with a reservation, it can not transferred until the +expiration timestamp is reached or the token is bought. + +### UPGRADER_ROLE ```solidity -event ServiceRemoved(bytes32 serviceHash) +bytes32 UPGRADER_ROLE ``` -### WantedServiceAdded +Upgrader role can upgrade the contract to a new implementation. + +### MIN_EXPIRATION_ADMIN_ROLE ```solidity -event WantedServiceAdded(bytes32 serviceHash) +bytes32 MIN_EXPIRATION_ADMIN_ROLE ``` -### WantedServiceRemoved +This role can set the mininum allowed expiration timestamp difference. + +### TokenReservation ```solidity -event WantedServiceRemoved(bytes32 serviceHash) +struct TokenReservation { + address reservedFor; + address supplier; + uint256 expirationTimestamp; + uint256 price; + contract IERC20 paymentToken; +} ``` -### ServiceFeeUpdated +### BookingTokenStorage ```solidity -event ServiceFeeUpdated(bytes32 serviceHash, uint256 fee) +struct BookingTokenStorage { + address _manager; + uint256 _nextTokenId; + uint256 _minExpirationTimestampDiff; + mapping(uint256 => struct BookingToken.TokenReservation) _reservations; +} ``` -### ServiceRestrictedRateUpdated +### TokenReserved ```solidity -event ServiceRestrictedRateUpdated(bytes32 serviceHash, bool restrictedRate) +event TokenReserved(uint256 tokenId, address reservedFor, address supplier, uint256 expirationTimestamp, uint256 price, contract IERC20 paymentToken) ``` -### ServiceCapabilitiesUpdated +Event emitted when a token is reserved. -```solidity -event ServiceCapabilitiesUpdated(bytes32 serviceHash) -``` +#### Parameters -### ServiceCapabilityAdded +| Name | Type | Description | +| ------------------- | --------------- | --------------------- | +| tokenId | uint256 | token id | +| reservedFor | address | reserved for address | +| supplier | address | supplier address | +| expirationTimestamp | uint256 | expiration timestamp | +| price | uint256 | price of the token | +| paymentToken | contract IERC20 | payment token address | + +### TokenBought ```solidity -event ServiceCapabilityAdded(bytes32 serviceHash, string capability) +event TokenBought(uint256 tokenId, address buyer) ``` -### ServiceCapabilityRemoved +Event emitted when a token is bought. -```solidity -event ServiceCapabilityRemoved(bytes32 serviceHash, string capability) -``` +#### Parameters -### PaymentTokenAdded +| Name | Type | Description | +| ------- | ------- | ------------- | +| tokenId | uint256 | token id | +| buyer | address | buyer address | + +### ExpirationTimestampTooSoon ```solidity -event PaymentTokenAdded(address token) +error ExpirationTimestampTooSoon(uint256 expirationTimestamp, uint256 minExpirationTimestampDiff) ``` -### PaymentTokenRemoved +Error for expiration timestamp too soon. It must be at least +`_minExpirationTimestampDiff` seconds in the future. + +### NotCMAccount ```solidity -event PaymentTokenRemoved(address token) +error NotCMAccount(address account) ``` -### OffChainPaymentSupportUpdated +Address is not a CM Account. -```solidity -event OffChainPaymentSupportUpdated(bool supportsOffChainPayment) -``` +#### Parameters -### PublicKeyAdded +| Name | Type | Description | +| ------- | ------- | --------------- | +| account | address | account address | + +### ReservationMismatch ```solidity -event PublicKeyAdded(address pubKeyAddress) +error ReservationMismatch(address reservedFor, address buyer) ``` -### PublicKeyRemoved +ReservedFor and buyer mismatch. -```solidity -event PublicKeyRemoved(address pubKeyAddress) -``` +#### Parameters -### \_\_PartnerConfiguration_init +| Name | Type | Description | +| ----------- | ------- | -------------------- | +| reservedFor | address | reserved for address | +| buyer | address | buyer address | + +### ReservationExpired ```solidity -function __PartnerConfiguration_init() internal +error ReservationExpired(uint256 tokenId, uint256 expirationTimestamp) ``` -### \_\_PartnerConfiguration_init_unchained +Reservation expired. -```solidity -function __PartnerConfiguration_init_unchained() internal -``` +#### Parameters -### \_addService +| Name | Type | Description | +| ------------------- | ------- | -------------------- | +| tokenId | uint256 | token id | +| expirationTimestamp | uint256 | expiration timestamp | + +### IncorrectPrice ```solidity -function _addService(bytes32 serviceHash, uint256 fee, string[] capabilities, bool restrictedRate) internal virtual +error IncorrectPrice(uint256 price, uint256 reservationPrice) ``` -Adds a supported Service object for a given hash. +Incorrect price. #### Parameters -| Name | Type | Description | -| -------------- | -------- | --------------------------------------------- | -| serviceHash | bytes32 | Hash of the service | -| fee | uint256 | Fee for the service | -| capabilities | string[] | Capabilities for the service | -| restrictedRate | bool | If the service is restricted to pre-agreement | +| Name | Type | Description | +| ---------------- | ------- | ------------------ | +| price | uint256 | price of the token | +| reservationPrice | uint256 | reservation price | -### \_removeService +### SupplierIsNotOwner ```solidity -function _removeService(bytes32 serviceHash) internal virtual +error SupplierIsNotOwner(uint256 tokenId, address supplier) ``` -Removes a supported Service object for a given hash. +Supplier is not the owner. #### Parameters -| Name | Type | Description | -| ----------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | +| Name | Type | Description | +| -------- | ------- | ---------------- | +| tokenId | uint256 | token id | +| supplier | address | supplier address | -### \_setServiceFee +### TokenIsReserved ```solidity -function _setServiceFee(bytes32 serviceHash, uint256 fee) internal virtual +error TokenIsReserved(uint256 tokenId, address reservedFor) ``` -Sets the Service fee for a given hash. +Token is reserved and can not be transferred. #### Parameters -| Name | Type | Description | -| ----------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | -| fee | uint256 | Fee | +| Name | Type | Description | +| ----------- | ------- | -------------------- | +| tokenId | uint256 | token id | +| reservedFor | address | reserved for address | -### \_setServiceRestrictedRate +### InsufficientAllowance ```solidity -function _setServiceRestrictedRate(bytes32 serviceHash, bool restrictedRate) internal virtual +error InsufficientAllowance(address sender, contract IERC20 paymentToken, uint256 price, uint256 allowance) ``` -Sets the Service restricted rate for a given hash. +Insufficient allowance to transfer the ERC20 token to the supplier. #### Parameters -| Name | Type | Description | -| -------------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | -| restrictedRate | bool | Restricted rate | +| Name | Type | Description | +| ------------ | --------------- | --------------------- | +| sender | address | msg.sender | +| paymentToken | contract IERC20 | payment token address | +| price | uint256 | price of the token | +| allowance | uint256 | allowance amount | -### \_setServiceCapabilities +### onlyCMAccount ```solidity -function _setServiceCapabilities(bytes32 serviceHash, string[] capabilities) internal virtual +modifier onlyCMAccount(address account) ``` -Sets the Service capabilities for a given hash. +Only CMAccount modifier. -#### Parameters +### initialize -| Name | Type | Description | -| ------------ | -------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | -| capabilities | string[] | Capabilities | +```solidity +function initialize(address manager, address defaultAdmin, address upgrader) public +``` -### \_addServiceCapability +### \_authorizeUpgrade ```solidity -function _addServiceCapability(bytes32 serviceHash, string capability) internal virtual +function _authorizeUpgrade(address newImplementation) internal ``` -Adds a capability to the service. +Function to authorize an upgrade for UUPS proxy. + +### safeMintWithReservation + +```solidity +function safeMintWithReservation(address reservedFor, string uri, uint256 expirationTimestamp, uint256 price, contract IERC20 paymentToken) public +``` + +Mints a new token with a reservation for a specific address. #### Parameters -| Name | Type | Description | -| ----------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | -| capability | string | Capability | +| Name | Type | Description | +| ------------------- | --------------- | --------------------------------------------------------------------- | +| reservedFor | address | The CM Account address that can buy the token | +| uri | string | The URI of the token | +| expirationTimestamp | uint256 | The expiration timestamp | +| price | uint256 | The price of the token | +| paymentToken | contract IERC20 | The token used to pay for the reservation. If address(0) then native. | -### \_removeServiceCapability +### buyReservedToken ```solidity -function _removeServiceCapability(bytes32 serviceHash, string capability) internal virtual +function buyReservedToken(uint256 tokenId) external payable ``` -Removes a capability from the service. +Buys a reserved token. The reservation must be for the message sender. + +Also the message sender should set allowance for the payment token to this +contract to at least the reservation price. (only for ERC20 tokens) + +For native coin, the message sender should send the exact amount. + +Only CM Accounts can call this function #### Parameters -| Name | Type | Description | -| ----------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | -| capability | string | Capability | +| Name | Type | Description | +| ------- | ------- | ------------ | +| tokenId | uint256 | The token id | -### getAllServiceHashes +### \_reserve ```solidity -function getAllServiceHashes() public view returns (bytes32[] serviceHashes) +function _reserve(uint256 tokenId, address reservedFor, address supplier, uint256 expirationTimestamp, uint256 price, contract IERC20 paymentToken) internal ``` -Returns all supported service hashes. +Reserve a token for a specific address with an expiration timestamp -### getService +### checkTransferable ```solidity -function getService(bytes32 serviceHash) public view virtual returns (struct PartnerConfiguration.Service service) +function checkTransferable(uint256 tokenId) internal ``` -Returns the Service object for a given hash. Service object contains fee and capabilities. +Check if the token is transferable -`serviceHash` is keccak256 hash of the pkg + service name as: +### isCMAccount -```text - ┌────────────── pkg ─────────────┐ ┌───── service name ─────┐ -keccak256("cmp.services.accommodation.v1alpha.AccommodationSearchService") +```solidity +function isCMAccount(address account) public view returns (bool) ``` -_These services are coming from the Camino Messenger Protocol's protobuf -definitions._ +Checks if an address is a CM Account. #### Parameters -| Name | Type | Description | -| ----------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | +| Name | Type | Description | +| ------- | ------- | -------------------- | +| account | address | The address to check | -### getServiceFee +#### Return Values + +| Name | Type | Description | +| ---- | ---- | ----------------------------------- | +| [0] | bool | true if the address is a CM Account | + +### requireCMAccount ```solidity -function getServiceFee(bytes32 serviceHash) public view virtual returns (uint256 fee) +function requireCMAccount(address account) internal view ``` -Returns the fee for a given service hash. +Checks if the address is a CM Account and reverts if not. #### Parameters -| Name | Type | Description | -| ----------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | +| Name | Type | Description | +| ------- | ------- | -------------------- | +| account | address | The address to check | -### getServiceRestrictedRate +### setManagerAddress ```solidity -function getServiceRestrictedRate(bytes32 serviceHash) public view virtual returns (bool restrictedRate) +function setManagerAddress(address manager) public ``` -Returns the restricted rate for a given service hash. +Sets for the manager address. #### Parameters -| Name | Type | Description | -| ----------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | +| Name | Type | Description | +| ------- | ------- | -------------------------- | +| manager | address | The address of the manager | -### getServiceCapabilities +### getManagerAddress ```solidity -function getServiceCapabilities(bytes32 serviceHash) public view virtual returns (string[] capabilities) +function getManagerAddress() public view returns (address) +``` + +Returns for the manager address. + +### setMinExpirationTimestampDiff + +```solidity +function setMinExpirationTimestampDiff(uint256 minExpirationTimestampDiff) public ``` -Returns the capabilities for a given service hash. +Sets minimum expiration timestamp difference in seconds. #### Parameters -| Name | Type | Description | -| ----------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | +| Name | Type | Description | +| -------------------------- | ------- | -------------------------------------------------- | +| minExpirationTimestampDiff | uint256 | Minimum expiration timestamp difference in seconds | -### \_addWantedService +### getMinExpirationTimestampDiff ```solidity -function _addWantedService(bytes32 serviceHash) internal virtual +function getMinExpirationTimestampDiff() public view returns (uint256) ``` -Adds a wanted service hash to the wanted services set. - -Reverts if the service already exists. - -#### Parameters - -| Name | Type | Description | -| ----------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | +Returns minimum expiration timestamp difference in seconds. -### \_removeWantedService +### getReservationPrice ```solidity -function _removeWantedService(bytes32 serviceHash) internal virtual +function getReservationPrice(uint256 tokenId) public view returns (uint256 price, contract IERC20 paymentToken) ``` -Removes a wanted service hash from the wanted services set. - -Reverts if the service does not exist. +Returns the token reservation price for a specific token. #### Parameters -| Name | Type | Description | -| ----------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | +| Name | Type | Description | +| ------- | ------- | ------------ | +| tokenId | uint256 | The token id | -### getWantedServiceHashes +### transferFrom ```solidity -function getWantedServiceHashes() public view virtual returns (bytes32[] serviceHashes) +function transferFrom(address from, address to, uint256 tokenId) public ``` -Returns all wanted service hashes. - -#### Return Values - -| Name | Type | Description | -| ------------- | --------- | --------------------- | -| serviceHashes | bytes32[] | Wanted service hashes | +Override transferFrom to check if token is reserved. It reverts if +the token is reserved. -### \_addSupportedToken +### safeTransferFrom ```solidity -function _addSupportedToken(address _token) internal virtual +function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) public ``` -Adds a supported payment token. +Override safeTransferFrom to check if token is reserved. It reverts if +the token is reserved. -#### Parameters +### \_update -| Name | Type | Description | -| ------- | ------- | --------------------------------- | -| \_token | address | Payment token address to be added | +```solidity +function _update(address to, uint256 tokenId, address auth) internal returns (address) +``` -### \_removeSupportedToken +### \_increaseBalance ```solidity -function _removeSupportedToken(address _token) internal virtual +function _increaseBalance(address account, uint128 value) internal ``` -Removes a supported payment token. - -#### Parameters +### tokenURI -| Name | Type | Description | -| ------- | ------- | ----------------------------------- | -| \_token | address | Payment token address to be removed | +```solidity +function tokenURI(uint256 tokenId) public view returns (string) +``` -### getSupportedTokens +### supportsInterface ```solidity -function getSupportedTokens() public view virtual returns (address[] tokens) +function supportsInterface(bytes4 interfaceId) public view returns (bool) ``` -Returns supported token addresses. +## CMAccountManager -#### Return Values +This contract manages the creation of the Camino Messenger accounts by +deploying {ERC1967Proxy} proxies that point to the{CMAccount} implementation +address. -| Name | Type | Description | -| ------ | --------- | ------------------------- | -| tokens | address[] | Supported token addresses | +Create CM Account: Users who want to create an account should call +`createCMAccount(address admin, address upgrader)` function with addresses of +the accounts admin and upgrader roles and also send the pre fund amount, +which is currently set as 100 CAMs. When the manager contract is paused, +account creation is stopped. -### \_setOffChainPaymentSupported +Developer Fee: This contracts also keeps the info about the developer wallet +and fee basis points. Which are used during the cheque cash in to pay for the +developer fee. + +Service Registry: {CMAccountManager} also acts as a registry for the services +that {CMAccount} contracts add as a supported or wanted service. Registry +works by hashing (keccak256) the service name (string) and creating a mapping +as keccak256(serviceName) => serviceName. And provides functions that +{CMAccount} function uses to register services. The {CMAccount} only keeps +the hashes (byte32) of the registered services. + +### PAUSER_ROLE ```solidity -function _setOffChainPaymentSupported(bool _supportsOffChainPayment) internal virtual +bytes32 PAUSER_ROLE ``` -Sets the off-chain payment support is supported. +Pauser role can pause the contract. Currently this only affects the +creation of CM Accounts. When paused, account creation is stopped. -### offChainPaymentSupported +### UPGRADER_ROLE ```solidity -function offChainPaymentSupported() public view virtual returns (bool) +bytes32 UPGRADER_ROLE ``` -Returns true if off-chain payment is supported for the given service. +Upgrader role can upgrade the contract to a new implementation. -### \_addPublicKey +### VERSIONER_ROLE ```solidity -function _addPublicKey(address pubKeyAddress, bytes publicKeyData) internal virtual +bytes32 VERSIONER_ROLE ``` -Adds public key with an address. Reverts if the public key already -exists. +Versioner role can set new {CMAccount} implementation address. When a +new implementation address is set, it is used for the new {CMAccount} +creations. -Beware: This functions does not check if the public key is actually for the -given address. +The old {CMAccount} contracts are not affected by this. Owners of those +should do the upgrade manually by calling the `upgradeToAndCall(address)` +function on the account. -### \_removePublicKey +### FEE_ADMIN_ROLE ```solidity -function _removePublicKey(address pubKeyAddress) internal virtual +bytes32 FEE_ADMIN_ROLE ``` -Removes the public key for a given address - -Reverts if the public key does not exist +Fee admin role can set the developer fee basis points which used for +calculating the developer fee that is cut from the cheque payments. -### getPublicKeysAddresses +### DEVELOPER_WALLET_ADMIN_ROLE ```solidity -function getPublicKeysAddresses() public view virtual returns (address[] pubKeyAddresses) +bytes32 DEVELOPER_WALLET_ADMIN_ROLE ``` -Returns the addresses of all public keys. These can then be used to -retrieve the public keys the `getPublicKey(address)` function. +Developer wallet admin role can set the developer wallet address +which is used to receive the developer fee. -### getPublicKey +### PREFUND_ADMIN_ROLE ```solidity -function getPublicKey(address pubKeyAddress) public view virtual returns (bytes data) +bytes32 PREFUND_ADMIN_ROLE ``` -Returns the public key for a given address. +Prefund admin role can set the mandatory prefund amount for {CMAccount} +contracts. -Reverts if the public key does not exist +### SERVICE_REGISTRY_ADMIN_ROLE -#### Parameters +```solidity +bytes32 SERVICE_REGISTRY_ADMIN_ROLE +``` -| Name | Type | Description | -| ------------- | ------- | ------------------------- | -| pubKeyAddress | address | Address of the public key | +Service registry admin role can add and remove services to the service +registry mapping. Implemented by {ServiceRegistry} contract. -## ServiceRegistry +### CMACCOUNT_ROLE -Service registry is used by the {CMAccountManager} contract to register -services by hashing (keccak256) the service name (string) and creating a mapping -as keccak256(serviceName) => serviceName. +```solidity +bytes32 CMACCOUNT_ROLE +``` -### ServiceRegistryStorage +This role is granted to the created CM Accounts. It is used to keep +an enumerable list of CM Accounts. + +### CMAccountInfo + +CMAccount info struct, to keep track of created CM Accounts and their +creators. ```solidity -struct ServiceRegistryStorage { - struct EnumerableSet.Bytes32Set _servicesHashSet; - mapping(bytes32 => string) _serviceNameByHash; - mapping(string => bytes32) _hashByServiceName; +struct CMAccountInfo { + bool isCMAccount; + address creator; } ``` -### ServiceRegistered +### CMAccountManagerStorage ```solidity -event ServiceRegistered(string serviceName, bytes32 serviceHash) +struct CMAccountManagerStorage { + address _latestAccountImplementation; + uint256 _prefundAmount; + address _developerWallet; + uint256 _developerFeeBp; + address _bookingToken; + mapping(address => struct CMAccountManager.CMAccountInfo) _cmAccountInfo; +} ``` -### ServiceUnregistered +### CMAccountCreated ```solidity -event ServiceUnregistered(string serviceName, bytes32 serviceHash) +event CMAccountCreated(address account) ``` -### ServiceAlreadyRegistered +CM Account created event. -```solidity -error ServiceAlreadyRegistered(string serviceName) -``` +#### Parameters -### ServiceNotRegistered +| Name | Type | Description | +| ------- | ------- | -------------------------------- | +| account | address | The address of the new CMAccount | + +### CMAccountImplementationUpdated ```solidity -error ServiceNotRegistered() +event CMAccountImplementationUpdated(address oldImplementation, address newImplementation) ``` -### \_\_ServiceRegistry_init +CM Account implementation address updated event. -```solidity -function __ServiceRegistry_init() internal -``` +#### Parameters -### \_\_ServiceRegistry_init_unchained +| Name | Type | Description | +| ----------------- | ------- | ------------------------------ | +| oldImplementation | address | The old implementation address | +| newImplementation | address | The new implementation address | + +### DeveloperWalletUpdated ```solidity -function __ServiceRegistry_init_unchained() internal +event DeveloperWalletUpdated(address oldDeveloperWallet, address newDeveloperWallet) ``` -### \_registerServiceName +Developer wallet address updated event. -```solidity -function _registerServiceName(string serviceName) internal virtual -``` +#### Parameters -Adds a new service by its name. This function calculates the hash of the -service name and adds it to the registry +| Name | Type | Description | +| ------------------ | ------- | -------------------------------- | +| oldDeveloperWallet | address | The old developer wallet address | +| newDeveloperWallet | address | The new developer wallet address | -{serviceName} is the pkg + service name as: +### DeveloperFeeBpUpdated -```text - ┌────────────── pkg ─────────────┐ ┌───── service name ─────┐ -"cmp.services.accommodation.v1alpha.AccommodationSearchService" +```solidity +event DeveloperFeeBpUpdated(uint256 oldDeveloperFeeBp, uint256 newDeveloperFeeBp) ``` -_These services are coming from the Camino Messenger Protocol's protobuf -definitions._ +Developer fee basis points updated event. #### Parameters -| Name | Type | Description | -| ----------- | ------ | ------------------- | -| serviceName | string | Name of the service | +| Name | Type | Description | +| ----------------- | ------- | ---------------------------------- | +| oldDeveloperFeeBp | uint256 | The old developer fee basis points | +| newDeveloperFeeBp | uint256 | The new developer fee basis points | -### \_unregisterServiceName +### BookingTokenAddressUpdated ```solidity -function _unregisterServiceName(string serviceName) internal virtual +event BookingTokenAddressUpdated(address oldBookingToken, address newBookingToken) ``` -Removes a service by its name. This function calculates the hash of the -service name and removes it from the registry. +Booking token address updated event. #### Parameters -| Name | Type | Description | -| ----------- | ------ | ------------------- | -| serviceName | string | Name of the service | +| Name | Type | Description | +| --------------- | ------- | ----------------------------- | +| oldBookingToken | address | The old booking token address | +| newBookingToken | address | The new booking token address | -### getRegisteredServiceNameByHash +### CMAccountInvalidImplementation ```solidity -function getRegisteredServiceNameByHash(bytes32 serviceHash) public view returns (string serviceName) +error CMAccountInvalidImplementation(address implementation) ``` -Returns the name of a service by its hash. +The implementation of the CMAccount is invalid. #### Parameters -| Name | Type | Description | -| ----------- | ------- | ------------------- | -| serviceHash | bytes32 | Hash of the service | +| Name | Type | Description | +| -------------- | ------- | ------------------------------------------- | +| implementation | address | The implementation address of the CMAccount | -### getRegisteredServiceHashByName +### CMAccountInvalidAdmin ```solidity -function getRegisteredServiceHashByName(string serviceName) public view returns (bytes32 serviceHash) +error CMAccountInvalidAdmin(address admin) ``` -Returns the hash of a service by its name. +The admin address is invalid. #### Parameters -| Name | Type | Description | -| ----------- | ------ | ------------------- | -| serviceName | string | Name of the service | +| Name | Type | Description | +| ----- | ------- | ----------------- | +| admin | address | The admin address | -### getAllRegisteredServiceHashes +### InvalidDeveloperWallet ```solidity -function getAllRegisteredServiceHashes() public view returns (bytes32[] services) +error InvalidDeveloperWallet(address developerWallet) ``` -Returns all registered service **hashes**. +Invalid developer address. -#### Return Values +#### Parameters -| Name | Type | Description | -| -------- | --------- | ----------------------------- | -| services | bytes32[] | All registered service hashes | +| Name | Type | Description | +| --------------- | ------- | ---------------------------- | +| developerWallet | address | The developer wallet address | -### getAllRegisteredServiceNames +### InvalidBookingTokenAddress ```solidity -function getAllRegisteredServiceNames() public view returns (string[] services) +error InvalidBookingTokenAddress(address bookingToken) ``` -Returns all registered service **names**. - -#### Return Values +Invalid booking token address. -| Name | Type | Description | -| -------- | -------- | ---------------------------- | -| services | string[] | All registered service names | +#### Parameters -## NullUSD +| Name | Type | Description | +| ------------ | ------- | ------------------------- | +| bookingToken | address | The booking token address | -### constructor +### IncorrectPrefundAmount ```solidity -constructor() public +error IncorrectPrefundAmount(uint256 expected, uint256 sended) ``` -## BookingToken - -Booking Token contract represents a booking done on the Camino Messenger. - -Suppliers can mint Booking Tokens and reserve them for a distributor address to -buy. +Incorrect pre fund amount. -Booking Tokens can have zero price, meaning that the payment will be done -off-chain. +#### Parameters -When a token is minted with a reservation, it can not transferred until the -expiration timestamp is reached or the token is bought. +| Name | Type | Description | +| -------- | ------- | ---------------------------- | +| expected | uint256 | The expected pre fund amount | +| sended | uint256 | | -### UPGRADER_ROLE +### constructor ```solidity -bytes32 UPGRADER_ROLE +constructor() public ``` -Upgrader role can upgrade the contract to a new implementation. - -### MIN_EXPIRATION_ADMIN_ROLE +### initialize ```solidity -bytes32 MIN_EXPIRATION_ADMIN_ROLE +function initialize(address defaultAdmin, address pauser, address upgrader, address versioner, address developerWallet, uint256 developerFeeBp) public ``` -This role can set the mininum allowed expiration timestamp difference. - -### TokenReservation +### pause ```solidity -struct TokenReservation { - address reservedFor; - address supplier; - uint256 expirationTimestamp; - uint256 price; - contract IERC20 paymentToken; -} +function pause() public ``` -### BookingTokenStorage +Pauses the CMAccountManager contract. Currently this only affects the +creation of CMAccount. When paused, account creation is stopped. + +### unpause ```solidity -struct BookingTokenStorage { - address _manager; - uint256 _nextTokenId; - uint256 _minExpirationTimestampDiff; - mapping(uint256 => struct BookingToken.TokenReservation) _reservations; -} +function unpause() public ``` -### TokenReserved +Unpauses the CMAccountManager contract. + +### \_authorizeUpgrade ```solidity -event TokenReserved(uint256 tokenId, address reservedFor, address supplier, uint256 expirationTimestamp, uint256 price, contract IERC20 paymentToken) +function _authorizeUpgrade(address newImplementation) internal ``` -Event emitted when a token is reserved. - -#### Parameters - -| Name | Type | Description | -| ------------------- | --------------- | --------------------- | -| tokenId | uint256 | token id | -| reservedFor | address | reserved for address | -| supplier | address | supplier address | -| expirationTimestamp | uint256 | expiration timestamp | -| price | uint256 | price of the token | -| paymentToken | contract IERC20 | payment token address | +Authorization for the CMAccountManager contract upgrade. -### TokenBought +### createCMAccount ```solidity -event TokenBought(uint256 tokenId, address buyer) +function createCMAccount(address admin, address upgrader) external payable returns (address) ``` -Event emitted when a token is bought. +Creates CMAccount by deploying a ERC1967Proxy with the CMAccount +implementation from the manager. -#### Parameters +Because this function is deploying a contract, it reverts if the caller is +not KYC or KYB verified. (For EOAs only) -| Name | Type | Description | -| ------- | ------- | ------------- | -| tokenId | uint256 | token id | -| buyer | address | buyer address | +Caller must send the pre-fund amount with the transaction. -### ExpirationTimestampTooSoon +_Emits a {CMAccountCreated} event._ + +### \_setCMAccountInfo ```solidity -error ExpirationTimestampTooSoon(uint256 expirationTimestamp, uint256 minExpirationTimestampDiff) +function _setCMAccountInfo(address account, struct CMAccountManager.CMAccountInfo info) internal ``` -Error for expiration timestamp too soon. It must be at least -`_minExpirationTimestampDiff` seconds in the future. - -### NotCMAccount +### getCMAccountCreator ```solidity -error NotCMAccount(address account) +function getCMAccountCreator(address account) public view returns (address) ``` -Address is not a CM Account. +Returns the given account's creator. #### Parameters -| Name | Type | Description | -| ------- | ------- | --------------- | -| account | address | account address | +| Name | Type | Description | +| ------- | ------- | ------------------- | +| account | address | The account address | -### ReservationMismatch +### isCMAccount ```solidity -error ReservationMismatch(address reservedFor, address buyer) +function isCMAccount(address account) public view returns (bool) ``` -ReservedFor and buyer mismatch. +Check if an address is CMAccount created by the manager. #### Parameters -| Name | Type | Description | -| ----------- | ------- | -------------------- | -| reservedFor | address | reserved for address | -| buyer | address | buyer address | +| Name | Type | Description | +| ------- | ------- | ---------------------------- | +| account | address | The account address to check | -### ReservationExpired +### getAccountImplementation ```solidity -error ReservationExpired(uint256 tokenId, uint256 expirationTimestamp) +function getAccountImplementation() public view returns (address) ``` -Reservation expired. - -#### Parameters - -| Name | Type | Description | -| ------------------- | ------- | -------------------- | -| tokenId | uint256 | token id | -| expirationTimestamp | uint256 | expiration timestamp | +Returns the CMAccount implementation address. -### IncorrectPrice +### setAccountImplementation ```solidity -error IncorrectPrice(uint256 price, uint256 reservationPrice) +function setAccountImplementation(address newImplementation) public ``` -Incorrect price. +Set a new CMAccount implementation address. #### Parameters -| Name | Type | Description | -| ---------------- | ------- | ------------------ | -| price | uint256 | price of the token | -| reservationPrice | uint256 | reservation price | +| Name | Type | Description | +| ----------------- | ------- | ------------------------------ | +| newImplementation | address | The new implementation address | -### SupplierIsNotOwner +### \_setAccountImplementation ```solidity -error SupplierIsNotOwner(uint256 tokenId, address supplier) +function _setAccountImplementation(address newImplementation) internal ``` -Supplier is not the owner. +### getPrefundAmount -#### Parameters +```solidity +function getPrefundAmount() public view returns (uint256) +``` -| Name | Type | Description | -| -------- | ------- | ---------------- | -| tokenId | uint256 | token id | -| supplier | address | supplier address | +Returns the prefund amount. -### TokenIsReserved +### setPrefundAmount ```solidity -error TokenIsReserved(uint256 tokenId, address reservedFor) +function setPrefundAmount(uint256 newPrefundAmount) public ``` -Token is reserved and can not be transferred. +Sets the prefund amount. -#### Parameters +### getBookingTokenAddress -| Name | Type | Description | -| ----------- | ------- | -------------------- | -| tokenId | uint256 | token id | -| reservedFor | address | reserved for address | +```solidity +function getBookingTokenAddress() public view returns (address) +``` -### InsufficientAllowance +Returns the booking token address. + +### setBookingTokenAddress ```solidity -error InsufficientAllowance(address sender, contract IERC20 paymentToken, uint256 price, uint256 allowance) +function setBookingTokenAddress(address token) public ``` -Insufficient allowance to transfer the ERC20 token to the supplier. +Sets booking token address. -#### Parameters +### \_setBookingTokenAddress -| Name | Type | Description | -| ------------ | --------------- | --------------------- | -| sender | address | msg.sender | -| paymentToken | contract IERC20 | payment token address | -| price | uint256 | price of the token | -| allowance | uint256 | allowance amount | +```solidity +function _setBookingTokenAddress(address token) internal +``` -### onlyCMAccount +### getDeveloperWallet ```solidity -modifier onlyCMAccount(address account) +function getDeveloperWallet() public view returns (address developerWallet) ``` -Only CMAccount modifier. +Returns developer wallet address. -### initialize +### setDeveloperWallet ```solidity -function initialize(address manager, address defaultAdmin, address upgrader) public +function setDeveloperWallet(address developerWallet) public ``` -### \_authorizeUpgrade +Sets developer wallet address. + +### getDeveloperFeeBp ```solidity -function _authorizeUpgrade(address newImplementation) internal +function getDeveloperFeeBp() public view returns (uint256 developerFeeBp) ``` -Function to authorize an upgrade for UUPS proxy. +Returns developer fee in basis points. -### safeMintWithReservation +### setDeveloperFeeBp ```solidity -function safeMintWithReservation(address reservedFor, string uri, uint256 expirationTimestamp, uint256 price, contract IERC20 paymentToken) public +function setDeveloperFeeBp(uint256 bp) public ``` -Mints a new token with a reservation for a specific address. +Sets developer fee in basis points. -#### Parameters +A basis point (bp) is one hundredth of 1 percentage point. -| Name | Type | Description | -| ------------------- | --------------- | --------------------------------------------------------------------- | -| reservedFor | address | The CM Account address that can buy the token | -| uri | string | The URI of the token | -| expirationTimestamp | uint256 | The expiration timestamp | -| price | uint256 | The price of the token | -| paymentToken | contract IERC20 | The token used to pay for the reservation. If address(0) then native. | +1 bp = 0.01%, 1/10,000⁠, or 0.0001. +10 bp = 0.1%, 1/1,000⁠, or 0.001. +100 bp = 1%, ⁠1/100⁠, or 0.01. -### buyReservedToken +### registerService ```solidity -function buyReservedToken(uint256 tokenId) external payable +function registerService(string serviceName) public ``` -Buys a reserved token. The reservation must be for the message sender. - -Also the message sender should set allowance for the payment token to this -contract to at least the reservation price. (only for ERC20 tokens) - -For native coin, the message sender should send the exact amount. - -Only CM Accounts can call this function +Registers a given service name. CM Accounts can only register services +if they are also registered in the service registry on the manager contract. #### Parameters -| Name | Type | Description | -| ------- | ------- | ------------ | -| tokenId | uint256 | The token id | +| Name | Type | Description | +| ----------- | ------ | ------------------- | +| serviceName | string | Name of the service | -### \_reserve +### unregisterService ```solidity -function _reserve(uint256 tokenId, address reservedFor, address supplier, uint256 expirationTimestamp, uint256 price, contract IERC20 paymentToken) internal +function unregisterService(string serviceName) public ``` -Reserve a token for a specific address with an expiration timestamp +Unregisters a given service name. CM Accounts will not be able to register +the service anymore. -### checkTransferable +#### Parameters -```solidity -function checkTransferable(uint256 tokenId) internal -``` +| Name | Type | Description | +| ----------- | ------ | ------------------- | +| serviceName | string | Name of the service | -Check if the token is transferable +## CMAccountManagerV2 -### isCMAccount +### getVersion ```solidity -function isCMAccount(address account) public view returns (bool) +function getVersion() public pure returns (string) ``` -Checks if an address is a CM Account. - -#### Parameters +## ServiceRegistry -| Name | Type | Description | -| ------- | ------- | -------------------- | -| account | address | The address to check | +Service registry is used by the {CMAccountManager} contract to register +services by hashing (keccak256) the service name (string) and creating a mapping +as keccak256(serviceName) => serviceName. -#### Return Values +### ServiceRegistryStorage -| Name | Type | Description | -| ---- | ---- | ----------------------------------- | -| [0] | bool | true if the address is a CM Account | +```solidity +struct ServiceRegistryStorage { + struct EnumerableSet.Bytes32Set _servicesHashSet; + mapping(bytes32 => string) _serviceNameByHash; + mapping(string => bytes32) _hashByServiceName; +} +``` -### requireCMAccount +### ServiceRegistered ```solidity -function requireCMAccount(address account) internal view +event ServiceRegistered(string serviceName, bytes32 serviceHash) ``` -Checks if the address is a CM Account and reverts if not. +### ServiceUnregistered -#### Parameters +```solidity +event ServiceUnregistered(string serviceName, bytes32 serviceHash) +``` -| Name | Type | Description | -| ------- | ------- | -------------------- | -| account | address | The address to check | +### ServiceAlreadyRegistered -### setManagerAddress +```solidity +error ServiceAlreadyRegistered(string serviceName) +``` + +### ServiceNotRegistered ```solidity -function setManagerAddress(address manager) public +error ServiceNotRegistered() ``` -Sets for the manager address. +### \_\_ServiceRegistry_init -#### Parameters +```solidity +function __ServiceRegistry_init() internal +``` -| Name | Type | Description | -| ------- | ------- | -------------------------- | -| manager | address | The address of the manager | +### \_\_ServiceRegistry_init_unchained -### getManagerAddress +```solidity +function __ServiceRegistry_init_unchained() internal +``` + +### \_registerServiceName ```solidity -function getManagerAddress() public view returns (address) +function _registerServiceName(string serviceName) internal virtual ``` -Returns for the manager address. +Adds a new service by its name. This function calculates the hash of the +service name and adds it to the registry -### setMinExpirationTimestampDiff +{serviceName} is the pkg + service name as: -```solidity -function setMinExpirationTimestampDiff(uint256 minExpirationTimestampDiff) public +```text + ┌────────────── pkg ─────────────┐ ┌───── service name ─────┐ +"cmp.services.accommodation.v1alpha.AccommodationSearchService" ``` -Sets minimum expiration timestamp difference in seconds. +_These services are coming from the Camino Messenger Protocol's protobuf +definitions._ #### Parameters -| Name | Type | Description | -| -------------------------- | ------- | -------------------------------------------------- | -| minExpirationTimestampDiff | uint256 | Minimum expiration timestamp difference in seconds | +| Name | Type | Description | +| ----------- | ------ | ------------------- | +| serviceName | string | Name of the service | -### getMinExpirationTimestampDiff +### \_unregisterServiceName ```solidity -function getMinExpirationTimestampDiff() public view returns (uint256) +function _unregisterServiceName(string serviceName) internal virtual ``` -Returns minimum expiration timestamp difference in seconds. +Removes a service by its name. This function calculates the hash of the +service name and removes it from the registry. -### getReservationPrice +#### Parameters + +| Name | Type | Description | +| ----------- | ------ | ------------------- | +| serviceName | string | Name of the service | + +### getRegisteredServiceNameByHash ```solidity -function getReservationPrice(uint256 tokenId) public view returns (uint256 price, contract IERC20 paymentToken) +function getRegisteredServiceNameByHash(bytes32 serviceHash) public view returns (string serviceName) ``` -Returns the token reservation price for a specific token. +Returns the name of a service by its hash. #### Parameters -| Name | Type | Description | -| ------- | ------- | ------------ | -| tokenId | uint256 | The token id | +| Name | Type | Description | +| ----------- | ------- | ------------------- | +| serviceHash | bytes32 | Hash of the service | -### transferFrom +### getRegisteredServiceHashByName ```solidity -function transferFrom(address from, address to, uint256 tokenId) public +function getRegisteredServiceHashByName(string serviceName) public view returns (bytes32 serviceHash) ``` -Override transferFrom to check if token is reserved. It reverts if -the token is reserved. - -### safeTransferFrom +Returns the hash of a service by its name. -```solidity -function safeTransferFrom(address from, address to, uint256 tokenId, bytes data) public -``` +#### Parameters -Override safeTransferFrom to check if token is reserved. It reverts if -the token is reserved. +| Name | Type | Description | +| ----------- | ------ | ------------------- | +| serviceName | string | Name of the service | -### \_update +### getAllRegisteredServiceHashes ```solidity -function _update(address to, uint256 tokenId, address auth) internal returns (address) +function getAllRegisteredServiceHashes() public view returns (bytes32[] services) ``` -### \_increaseBalance +Returns all registered service **hashes**. -```solidity -function _increaseBalance(address account, uint128 value) internal -``` +#### Return Values -### tokenURI +| Name | Type | Description | +| -------- | --------- | ----------------------------- | +| services | bytes32[] | All registered service hashes | + +### getAllRegisteredServiceNames ```solidity -function tokenURI(uint256 tokenId) public view returns (string) +function getAllRegisteredServiceNames() public view returns (string[] services) ``` -### supportsInterface +Returns all registered service **names**. -```solidity -function supportsInterface(bytes4 interfaceId) public view returns (bool) -``` +#### Return Values + +| Name | Type | Description | +| -------- | -------- | ---------------------------- | +| services | string[] | All registered service names | ## Dummy @@ -2780,6 +2764,14 @@ function supportsInterface(bytes4 interfaceId) public view returns (bool) function getVersion() public pure returns (string) ``` +## NullUSD + +### constructor + +```solidity +constructor() public +``` + ## ICaminoAdmin ### getKycState