Skip to content

Solidity API

PaymentCommitment

Facilitates collateral-backed commitments between two parties (a committer and a committee) using tokenized assets.

Underpinned by ERC-1155, this contract supports deposits, withdrawals, and refutations during the payment lifecycle, with conditions to govern the commitment process.

referenceId

solidity
string referenceId

An arbitrary reference ID, set by the initiator for identifying the payment commitment.

committee

solidity
address committee

Participants The address of the committee receiving the committed value.

COMMITTER

solidity
address COMMITTER

The immutable address of the committer responsible for the payment.

The committer's address is set at contract deployment and cannot be changed afterwards. The committer's identity is fixed, it guarantees that the same committer is responsible for fulfilling the commitment, which is important for maintaining trust in the contract's execution and ensuring that no unauthorized parties can alter the committer after deployment.

CommitmentStatus

Enum representing the stages of a payment commitment.

This enum tracks the various stages that a payment commitment can go through, from its creation to the final discharge of the commitment.

solidity
enum CommitmentStatus {
  DRAFTING,
  INITIATED,
  ACCEPTED,
  CONTINGENT,
  EFFECTIVE,
  DISCHARGING,
  DISCHARGED
}

status

solidity
enum PaymentCommitment.CommitmentStatus status

The current status of the payment commitment.

DischargeStatus

Enum representing the discharge process's stages.

solidity
enum DischargeStatus {
  OPEN,
  DISCHARGE_INITIATED,
  DISCHARGE_REFUTED,
  DISCHARGED
}

dischargeStatus

solidity
enum PaymentCommitment.DischargeStatus dischargeStatus

The current discharge status of the payment commitment.

collateralToken

solidity
address collateralToken

Collateral asset details @notice The collateral token address (e.g. ERC-20 tokens) used in payment commitment.

collateralValue

solidity
uint256 collateralValue

The value of collateral used in the payment commitment.

commitmentDate

solidity
uint256 commitmentDate

Time tracking The timestamp (in seconds) when the commitment was made.

dueDate

solidity
uint256 dueDate

The timestamp (in seconds) when the settlement is due.

ConditionStatus

Conditions triggering actions Enum representing the various states of a condition.

solidity
enum ConditionStatus {
  NULL,
  UNFULFILLED,
  FULFILLMENT_INITIATED,
  FULFILLMENT_REFUTED,
  FULFILLED
}

ChangeTypes

Enum representing types of change requests that can be made to a commitment.

solidity
enum ChangeTypes {
  COLLATERAL_VALUE,
  DUE_DATE
}

ConditionActions

solidity
enum ConditionActions {
  NULL,
  DEPOSIT,
  ACCEPT,
  FULFILL_CONDITION,
  DISCHARGE
}

ConditionRequiredFields

solidity
enum ConditionRequiredFields {
  COMPLETE_COLLATERAL_DEPOSIT,
  TRADE_TOKEN_ADDRESS,
  TRADE_TOKEN_VALUE
}

ConditionFulfillmentActions

solidity
enum ConditionFulfillmentActions {
  SET_VALUE,
  DISCHARGE_USING_COLLATERAL,
  TRANSFER_DEPOSIT_AND_SET_VALUE
}

ConditionFulfillmentFields

solidity
enum ConditionFulfillmentFields {
  STATUS,
  DISCHARGE_STATUS,
  TRANSFER_FROM,
  TRANSFER_TO,
  TRANSFER_VALUE,
  TRANSFER_TOKEN_ID
}

Condition

Struct representing the details of a condition.

solidity
struct Condition {
  enum PaymentCommitment.ConditionActions action;
  struct PaymentCommitment.FieldRequirement[] requiredFields;
  address fulfiller;
  enum PaymentCommitment.ConditionStatus status;
  enum PaymentCommitment.ConditionFulfillmentActions fulfillmentAction;
  struct PaymentCommitment.FieldUpdate[] fulfillmentFields;
  uint256 fulfillmentRequestTimestamp;
}

FieldRequirement

solidity
struct FieldRequirement {
  enum PaymentCommitment.ConditionRequiredFields field;
  bytes value;
}

FieldUpdate

solidity
struct FieldUpdate {
  enum PaymentCommitment.ConditionFulfillmentFields field;
  bytes value;
}

conditions

solidity
mapping(uint256 => struct PaymentCommitment.Condition) conditions

conditionIds

solidity
uint256[] conditionIds

Array to store the condition IDs for iteration.

refutationWindow

solidity
uint256 refutationWindow

Defines the time window (in seconds) during which a counterparty can refute and prevent a fulfill or discharge action.

This value specifies the duration from each fulfillConditionInitiate or dischargeInitiate request within which refutations can be made to halt the corresponding action.

disputeResolver

solidity
address disputeResolver

The address of the account with authority to resolve refutations.

This account can override refutations if they are valid and prevent potential disputes from delaying actions.

dischargeAccounts

solidity
address[] dischargeAccounts

The list of accounts that will be drained for corressponding discharge value of discharge Token.

This is populated when initiating a discharge and is used when completing it.

dischargeValues

solidity
uint256[] dischargeValues

The list of discharge Token values that will be drained from corressponding discharge account .

This is populated when initiating a discharge and is used when completing it.

dischargeToken

solidity
address dischargeToken

The token to be drained from discharge accounts on discharge completion.

This is populated when initiating a discharge and is used when completing it.

PaymentCommitmentInvalidAddress

solidity
error PaymentCommitmentInvalidAddress(address receivedAddress)

Logs the address that was received, which is considered invalid.

Thrown when an invalid address is received.

PaymentCommitmentConditionAlreadyExists

solidity
error PaymentCommitmentConditionAlreadyExists(uint256 conditionId)

Logs the ID of the condition that is attempting to be re-created.

Thrown when a condition with the specified ID already exists.

PaymentCommitmentInvalidConditionStatus

solidity
error PaymentCommitmentInvalidConditionStatus(enum PaymentCommitment.ConditionStatus conditionStatus)

Logs the invalid condition status.

Thrown when the status of a condition is invalid.

PaymentCommitmentTransferFailed

solidity
error PaymentCommitmentTransferFailed(address token, address to, uint256 value)

Logs the token address, the recipient's address, and the value of the transfer.

Thrown when an ERC-20 token transfer fails.

PaymentCommitmentInvalidStatus

solidity
error PaymentCommitmentInvalidStatus(enum PaymentCommitment.CommitmentStatus status)

Logs the current commitment status that is considered invalid.

Thrown when the deposit state is invalid.

PaymentCommitmentUnauthorizedCaller

solidity
error PaymentCommitmentUnauthorizedCaller(address sender)

Logs the address of the unauthorized sender.

Thrown when an unauthorized caller attempts to interact with the contract.

PaymentCommitmentInvalidConditionId

solidity
error PaymentCommitmentInvalidConditionId(uint256 conditionId)

Logs the invalid condition ID that triggered the error.

Thrown when an invalid condition ID is provided.

PaymentCommitmentInvalidDischargeStatus

solidity
error PaymentCommitmentInvalidDischargeStatus(enum PaymentCommitment.DischargeStatus dischargeStatus)

Logs the discharge status that caused the error.

Thrown when the discharge status is invalid.

PaymentCommitmentUnauthorizedCollateralWithdrawal

solidity
error PaymentCommitmentUnauthorizedCollateralWithdrawal(uint256 dueDateTill, enum PaymentCommitment.CommitmentStatus status)

Logs the due date until withdrawal is allowed and the current commitment status.

Thrown when an unauthorized attempt is made to withdraw collateral.

PaymentCommitmentDueDateNotPassed

solidity
error PaymentCommitmentDueDateNotPassed(uint256 currentTime, uint256 dueDate)

Logs the current time and the due date to show the difference.

Thrown when an action is attempted before the due date has passed.

PaymentCommitmentActiveRefutationWindow

solidity
error PaymentCommitmentActiveRefutationWindow(uint256 currentTime, uint256 refutationWindowTill)

Logs the current time and the time until the refutation window is active.

Thrown when a refutation window is still active for a payment commitment.

PaymentCommitmentUnauthorizedResolver

solidity
error PaymentCommitmentUnauthorizedResolver(address sender, address disputeResolver)

Logs the sender's address and the address of the dispute resolver.

Thrown when an unauthorized resolver attempts to resolve a dispute.

PaymentCommitmentUnauthorizedCollateralTransfer

solidity
error PaymentCommitmentUnauthorizedCollateralTransfer()

Thrown when an unauthorized attempt is made to transfer collateral.

PaymentCommitmentInvalidValueChange

solidity
error PaymentCommitmentInvalidValueChange(uint256 current, uint256 newValue, uint256 lowerBound, uint256 upperBound)

Logs the current value, the new value, and the lower and upper bounds of the allowed range.

Thrown when a value change is outside the allowed range.

ERC1155MissingApprovalForAll

solidity
error ERC1155MissingApprovalForAll(address operator, address owner)

Logs the new status of the payment commitment.

Triggered when the status of a payment commitment is updated.

PaymentCommitmentInvalidData

solidity
error PaymentCommitmentInvalidData()

StatusUpdated

solidity
event StatusUpdated(enum PaymentCommitment.CommitmentStatus newStatus)

CollateralValueUpdated

solidity
event CollateralValueUpdated(uint256 oldValue, uint256 newValue)

Logs the old value and the new value of the collateral.

Triggered when the collateral value is updated.

DueDateUpdated

solidity
event DueDateUpdated(uint256 oldValue, uint256 newValue)

Logs the old due date and the new due date.

Triggered when the due date of a payment commitment is updated.

DischargeStatusUpdated

solidity
event DischargeStatusUpdated(enum PaymentCommitment.DischargeStatus newValue)

Logs the new status of the discharge.

Triggered when the discharge status is updated.

TokensWithdrawn

solidity
event TokensWithdrawn(address from, address token, uint256 value, address to)

Logs the sender's address, the token address, the amount withdrawn, and the recipient's address.

Triggered when tokens are withdrawn from the contract.

TokensDeposited

solidity
event TokensDeposited(address depositor, address token, uint256 value, uint256 tokenId)

Logs the depositor's address, the token address, the amount deposited, and the associated token ID.

Triggered when tokens are deposited into the contract.

DepositUnwrapped

solidity
event DepositUnwrapped(address sender, address from, address wrapperToken, address wrappedToken, uint256 value)

ConditionAdded

solidity
event ConditionAdded(uint256 conditionId, address fulfiller)

Logs the condition ID and address of the fulfiller.

Triggered when a condition is added to the contract.

ConditionFulfillmentInitiated

solidity
event ConditionFulfillmentInitiated(address fulfiller, uint256 conditionId)

Logs the address of the fulfiller and the ID of the condition being fulfilled.

Triggered when a condition fulfillment process is initiated.

ConditionFulfilled

solidity
event ConditionFulfilled(uint256 conditionId)

Logs the ID of the condition that was fulfilled.

Triggered when a condition is successfully fulfilled.

ConditionFulfillmentRefuted

solidity
event ConditionFulfillmentRefuted(address refuter, uint256 conditionId)

Logs the address of the refuter and the ID of the condition being refuted.

Triggered when a condition fulfillment is refuted (challenged or invalidated).

ConditionFulfillmentCancelled

solidity
event ConditionFulfillmentCancelled(address sender, uint256 conditionId)

Logs the address of the sender canceling the fulfillment and the ID of the condition.

Triggered when a condition fulfillment is cancelled.

DischargeRefuted

solidity
event DischargeRefuted(address refuter)

Logs the address of the refuter who initiated the refutation.

Triggered when a discharge request is refuted (challenged or invalidated).

DischargeCancelled

solidity
event DischargeCancelled()

This event does not log any specific data, but it indicates that a discharge process was stopped.

Triggered when a discharge process is cancelled.

DischargeInitiated

solidity
event DischargeInitiated()

This event indicates the start of the discharge process, but it does not log any specific data.

Triggered when a discharge process is initiated.

DischargeCompleted

solidity
event DischargeCompleted()

This event indicates that the discharge process has been finalized.

Triggered when a discharge process is successfully completed.

constructor

solidity
constructor(address _initialOwner, address _committer, string _erc1155Uri) public

Initializes the PaymentCommitment contract.

This constructor sets the initial owner, committer, and ERC1155 URI. The committer address is immutable and cannot be changed after deployment. It also sets the contract status to "DRAFTING" and discharge status to "OPEN".

Parameters

NameTypeDescription
_initialOwneraddressThe address that will be the owner of the contract.
_committeraddressThe address of the committer responsible for the payment.
_erc1155UristringThe URI that will be associated with the ERC1155 token. Error: - PaymentCommitmentInvalidAddress: Reverts if sender's address is invalid.

initiate

solidity
function initiate(string _referenceId, address _committee, address _collateralToken, uint256 _collateralValue, uint256 _commitmentDate, uint256 _dueDate, uint256 _refutationWindow, address _disputeResolver) external

Initiates the payment commitment with all necessary details.

This function sets up all the parameters required for the commitment and changes the contract's status to "INITIATED". The contract must be in the "DRAFTING" status to call this function. It validates the provided addresses and ensures they are non-zero. The trade token compatibility with ERC-20 standards is verified internally.

Parameters

NameTypeDescription
_referenceIdstringThe unique reference ID for this commitment.
_committeeaddressThe address of the committee that will receive the committed value.
_collateralTokenaddressThe address of the ERC-20 token used as collateral in the commitment.
_collateralValueuint256The value of tokens used as collateral committed for the trade.
_commitmentDateuint256The date when the commitment was made (in epoch seconds).
_dueDateuint256The due date for the commitment's settlement (in epoch seconds).
_refutationWindowuint256The time window in seconds during which the counterparty can refute the commitment's fulfillment.
_disputeResolveraddressThe address with the authority to resolve any refutations or disputes. Error: - PaymentCommitmentInvalidStatus: Reverts if the contract is not in the "DRAFTING" status. - PaymentCommitmentInvalidAddress: Reverts if any of the provided addresses are invalid (zero address). Emits: - StatusUpdated: Emitted when the commitment status is updated to "INITIATED".

addCondition

solidity
function addCondition(uint256 _conditionId, enum PaymentCommitment.ConditionActions _triggeringAction, enum PaymentCommitment.ConditionRequiredFields[] _requiredFields, bytes[] _requiredValues, address _fulfiller, enum PaymentCommitment.ConditionFulfillmentActions _fulfillmentAction, enum PaymentCommitment.ConditionFulfillmentFields[] _fulfillmentFields, bytes[] _fulfillmentValues) external

Adds a new condition to the payment commitment.

This function allows the owner to add a condition to the commitment. It ensures the contract is in the "INITIATED" status and checks that the condition does not already exist. Once validated, the condition is added with the given fulfiller address and its status is set to "UNFULFILLED". The condition status is set to "UNFULFILLED", and the fulfiller is assigned to the condition. The condition ID is then added to the list of conditions for future reference. Error PaymentCommitmentInvalidStatus If the contract is not in the "INITIATED" status. Error PaymentCommitmentConditionAlreadyExists If the condition ID already exists.

Parameters

NameTypeDescription
_conditionIduint256The unique ID of the condition being added.
_triggeringActionenum PaymentCommitment.ConditionActionsThe enum equivalent of action that triggers a condition's verification and fulfillment.
_requiredFieldsenum PaymentCommitment.ConditionRequiredFields[]The array of field enums that are required to fulfill the condition.
_requiredValuesbytes[]The array of byte encoded field values indexed corresponding to the fields above.
_fulfilleraddressThe address of account expected to fulfill this condition.
_fulfillmentActionenum PaymentCommitment.ConditionFulfillmentActionsThe action to be performed on condition fulfillment.
_fulfillmentFieldsenum PaymentCommitment.ConditionFulfillmentFields[]The fields to be updated on fulfilment of the condition.
_fulfillmentValuesbytes[]The byte encoded field values indexed corresponding to the fields above.

getConditionCount

solidity
function getConditionCount() public view returns (uint256)

Returns the total number of conditions in the payment commitment.

This function retrieves the current number of conditions that have been added to the contract. It simply returns the length of the conditionIds array, which holds all the condition IDs.

Return Values

NameTypeDescription
[0]uint256The total number of conditions stored in the contract.

getAllConditionIds

solidity
function getAllConditionIds() public view returns (uint256[])

Retrieves all the condition IDs stored in the contract.

This function returns an array of all the condition IDs that have been added to the contract. It can be useful for tracking all the conditions associated with the payment commitment.

Return Values

NameTypeDescription
[0]uint256[]An array of condition IDs.

accept

solidity
function accept() external

Accepts the payment commitment by the committee.

_This function allows the committee to accept the commitment. It checks if the caller is the committee and if the contract is in the "INITIATED" status. If these conditions are met, the status is updated to "ACCEPTED".

Error:

  • PaymentCommitmentUnauthorizedCaller: Reverts if the caller is not the committee.
  • PaymentCommitmentInvalidStatus: Reverts if the contract is not in the "INITIATED" status.

Emits:

  • StatusUpdated: Emitted when the commitment status is updated to "ACCEPTED"._

deposit

solidity
function deposit(address _token, uint256 _value, address _to) external

Allows depositing ERC-20 tokens into the contract.

Mints ERC-1155 tokens equivalent to the deposited ERC-20 tokens and moves the status to contingent/effective when complete collateral value has been deposited.

Parameters

NameTypeDescription
_tokenaddressThe address of the ERC-20 token to deposit.
_valueuint256The amount of the token to deposit. Error: - PaymentCommitmentInvalidStatus: Reverts if the commitment status is before EFFECTIVE - PaymentCommitmentTransferFailed: Reverts if the ERC-20 token transfer fails. Emits: - TokensDeposited: Emitted when tokens are deposited into the contract. - StatusUpdated: Emitted when the commitment status is updated to "EFFECTIVE" or "CONTINGENT".
_toaddress

unwrapDeposit

solidity
function unwrapDeposit(address _from, address _wrapperTokenAddress, address _wrappedTokenAddress, uint256 _value, bytes _signature) external

_verifyCondition

solidity
function _verifyCondition(uint256 _conditionId, address _token, uint256 _value) internal view returns (bool _conditionMet)

Internal function to fulfill a condition.

Parameters

NameTypeDescription
_conditionIduint256The ID of the condition to fulfill.
_tokenaddressThe address of the deposited token.
_valueuint256The amount of the deposited token.

fulfillCondition

solidity
function fulfillCondition(uint256 conditionId) external

_fulfillCondition

solidity
function _fulfillCondition(uint256 _conditionId) internal

requestChange

solidity
function requestChange(enum PaymentCommitment.ChangeTypes _changeType, bytes newValue) external

Updates the trade token value for the payment commitment.

Handles the ChangeTypes.COLLATERAL_VALUE type, allowing the collateral value to be updated. The function ensures that the change is within a valid range (±5% of the current collateral value). If the new value is outside the allowed range, the function reverts with an error.

Parameters

NameTypeDescription
_changeTypeenum PaymentCommitment.ChangeTypesThe type of change request being processed.
newValuebytesThe new value encoded as bytes. Error: - PaymentCommitmentUnauthorizedCaller: Reverts if caller is not the committee. - PaymentCommitmentInvalidStatus: Reverts if the commitment status is not "ACCEPTED". - PaymentCommitmentInvalidValueChange: Reverts if the new value is outside the allowed range. Emits : - CollateralValueUpdated: Emitted when the collateral value is successfully updated. - DueDateUpdated: Emitted when the due date value is successfully updated.

initiateConditionFulfillment

solidity
function initiateConditionFulfillment(uint256 _conditionId) external

Initiates the fulfillment process for a specific condition within the payment commitment.

The function verifies the contract status, condition existence, and caller's authority before initiating fulfillment. Updates the condition's status to FULFILLMENT_INITIATED and records the timestamp of the request.

Parameters

NameTypeDescription
_conditionIduint256The unique identifier of the condition to be fulfilled. Error: - PaymentCommitmentInvalidStatus: Reverts if the contract is not in the CONTINGENT status. - PaymentCommitmentInvalidConditionId: Reverts if the specified condition does not exist or is invalid. - PaymentCommitmentUnauthorizedCaller: Reverts if the caller is not authorized to fulfill the condition. Emits: - ConditionFulfillmentInitiated: Emitted when the fulfillment process is successfully initiated for a condition.

completeConditionFulfillment

solidity
function completeConditionFulfillment(uint256 _conditionId) external

Completes the fulfillment of a specified condition within the payment commitment.

_This function allows:

  • The fulfiller to complete the fulfillment after the refutation window has elapsed, provided no refutations are present.
  • The disputeResolver to complete the fulfillment despite the refutation state.
  • Conditions pre-verified by the disputeResolver to be directly marked as fulfilled without a refutation process. Once all conditions are fulfilled, the status of the commitment changes to EFFECTIVE, and collateral is transferred to the committee._

Parameters

NameTypeDescription
_conditionIduint256The unique identifier of the condition to be completed. Error: - PaymentCommitmentInvalidConditionId: Reverts if the condition is not in a valid state for completion. - PaymentCommitmentActiveRefutationWindow: Reverts if the refutation window for the condition has not yet expired. - PaymentCommitmentUnauthorizedCaller: Reverts if the caller is neither the fulfiller nor the disputeResolver. Emits: - ConditionFulfilled: Emitted when a condition is successfully marked as fulfilled. - StatusUpdated: Emitted when the contract's status transitions to EFFECTIVE.

refuteConditionFulfillment

solidity
function refuteConditionFulfillment(uint256 _conditionId) external

Refutes the fulfillment of a specified condition within the payment commitment.

This function allows the committee or COMMITTER to refute a condition's fulfillment during its fulfillment process. The condition must be in the FULFILLMENT_INITIATED state to be refuted. Once refuted, the condition's status changes to FULFILLMENT_REFUTED, halting the fulfillment process.

Parameters

NameTypeDescription
_conditionIduint256The unique identifier of the condition to be refuted. Error: - PaymentCommitmentUnauthorizedCaller: Reverts if the caller is neither the committee nor the COMMITTER. - PaymentCommitmentInvalidConditionStatus: Reverts if the condition is not in the FULFILLMENT_INITIATED state. Emits: - ConditionFulfillmentRefuted: Emitted when a condition's fulfillment is successfully refuted.

cancelConditionFulfillment

solidity
function cancelConditionFulfillment(uint256 _conditionId) external

Cancels the fulfillment process of a specified condition in the payment commitment.

This function allows the registered disputeResolver or the condition's fulfiller to cancel an ongoing condition fulfillment. It resets the condition's status to UNFULFILLED and clears its fulfillment request timestamp.

Parameters

NameTypeDescription
_conditionIduint256The unique identifier of the condition to be canceled. Error: - PaymentCommitmentUnauthorizedResolver: Reverts if the caller is neither the disputeResolver nor the condition's fulfiller. Emits: - ConditionFulfillmentCancelled: Emitted when a condition's fulfillment is successfully canceled.

initiateDischarge

solidity
function initiateDischarge(address[] accounts, uint256[] values, address token) external

Initiates the discharge process for the payment commitment.

_This function can only be called by the COMMITTER and updates the contract's status to DISCHARGING. It also records the timestamp when the discharge process begins.

Error:

  • PaymentCommitmentUnauthorizedCaller: Reverts if the caller is not the COMMITTER.

Emits:

  • DischargeInitiated: Emitted when the discharge process is initiated by the committer.
  • StatusUpdated: Emitted when the contract status transitions to DISCHARGING._

completeDischarge

solidity
function completeDischarge() external

Completes the discharge process after the refutation window has passed or as approved by the dispute resolver.

_Finalizes the discharge process and transfers collateral back to the committer. Ensures that only the COMMITTER or disputeResolver can execute this, based on discharge state.

Error:

  • PaymentCommitmentActiveRefutationWindow: Reverts if the refutation window is still active.
  • PaymentCommitmentInvalidDischargeStatus: Reverts if the discharge status is invalid for the caller.
  • PaymentCommitmentUnauthorizedCaller: Reverts if the caller is neither the COMMITTER nor the disputeResolver.

Emits

  • DischargeCompleted: Emitted when the discharge process is successfully completed.
  • StatusUpdated: Emitted when the commitment status transitions to DISCHARGED._

refuteDischarge

solidity
function refuteDischarge() external

Refutes the initiated discharge process within the active refutation window.

_Allows collateral holders to refute the discharge by checking their balance of collateral tokens.

Error:

  • PaymentCommitmentUnauthorizedCaller: Reverts if the caller holds no collateral tokens.
  • PaymentCommitmentActiveRefutationWindow: Reverts if the refutation window has expired.

Emits:

  • DischargeRefuted: Emitted when the discharge is successfully refuted by a collateral holder._

cancelDischarge

solidity
function cancelDischarge() external

Cancels the discharge process if it has been refuted.

_This function is restricted to the disputeResolver and resets the discharge status.

Error:

  • PaymentCommitmentUnauthorizedCaller: Reverts if the caller is not the disputeResolver.
  • PaymentCommitmentInvalidDischargeStatus: Reverts if the discharge status is not DISCHARGE_REFUTED.

Emits:

  • DischargeCancelled: Emitted when the discharge process is successfully cancelled.
  • StatusUpdated: Emitted when the commitment status transitions back to EFFECTIVE._

withdraw

solidity
function withdraw(address _token, uint256 _value, address _to) external

Withdraws ERC-20 tokens from the contract that correspond to the caller's ERC-1155 token balance.

The caller must hold equivalent ERC-1155 tokens in the contract to withdraw ERC-20 tokens. For the collateralToken token, the withdrawal is only allowed after the due date or when the commitment status is DISCHARGED. If the caller's balance becomes zero after the withdrawal, they are removed from the collateral owners' list.

Parameters

NameTypeDescription
_tokenaddressThe address of the ERC-20 token to withdraw.
_valueuint256The amount of ERC-20 tokens to withdraw.
_toaddressThe address to which the ERC-20 tokens will be credited. Error: - PaymentCommitmentUnauthorizedCollateralWithdrawal: Reverts if the caller attempts to withdraw collateral tokens before the due date or if the commitment status is not DISCHARGED. - PaymentCommitmentTransferFailed: Reverts if the ERC-20 token transfer fails. Emits: - TokensWithdrawn: Emitted when a withdrawal is successfully executed.

safeTransferFrom

solidity
function safeTransferFrom(address from, address to, uint256 id, uint256 value, bytes data) public

Safely transfers ERC-1155 tokens from one address to another with custom restrictions for collateral tokens.

This override of the safeTransferFrom function ensures that collateral tokens are only transferred under specific contract conditions (e.g., when the status is effective and not during the discharging process). It also manages the addition and removal of collateral owners based on the transfer of collateral tokens. If the sender or recipient does not have approval, the transfer will be reverted.

Parameters

NameTypeDescription
fromaddressThe address from which to transfer the token.
toaddressThe address to which the token will be transferred.
iduint256The ID of the token to transfer.
valueuint256The amount of tokens to transfer.
databytesAdditional data passed with the transfer (unused in this implementation). Error - PaymentCommitmentUnauthorizedCollateralTransfer: Reverts if the transfer of collateral tokens is unauthorized based on the contract's status. - ERC1155MissingApprovalForAll: Reverts if a failure with the operator’s approval.

safeBatchTransferFrom

solidity
function safeBatchTransferFrom(address from, address to, uint256[] ids, uint256[] values, bytes data) public

Safely transfers a batch of ERC-1155 tokens with custom collateral restrictions.

Ensures that collateral tokens can only be transferred when the contract is in the effective state. If the collateral token is being transferred, it checks for the contract status and updates the collateral ownership accordingly.

Parameters

NameTypeDescription
fromaddressThe address to transfer tokens from.
toaddressThe address to transfer tokens to.
idsuint256[]An array of token IDs.
valuesuint256[]An array of token values to transfer.
databytesAdditional data with the transfer. Error - PaymentCommitmentUnauthorizedCollateralTransfer: Reverts if the transfer of collateral tokens is unauthorized based on contract status. - ERC1155MissingApprovalForAll: Reverts if the sender does not have approval for all transfers from the from address.

_isCompatibleERC20

solidity
function _isCompatibleERC20(address token) internal returns (bool, string)

Checks if the specified address is a valid ERC20 token by verifying the presence of essential ERC20 functions: allowance, transfer, and transferFrom.

Verifies if the given address is a valid ERC20 token by checking the presence of the transfer, transferFrom, and allowance functions using staticcall.

Parameters

NameTypeDescription
tokenaddressThe token address to verify.

Return Values

NameTypeDescription
[0]bool_isCompatibleERC20 True if the address is a valid ERC20 token (with the required functions).
[1]string

_deleteCondition

solidity
function _deleteCondition(uint256 _conditionId) internal

This function deletes the specified condition and removes it from the conditionIds array.

Deletes a condition from the state by its conditionId.

Parameters

NameTypeDescription
_conditionIduint256The ID of the condition to be deleted. It ensures the array is properly shifted after the condition is deleted to maintain correct indexing.

_isDischargeAccount

solidity
function _isDischargeAccount(address _account) internal view returns (bool)

This function iterates through the dischargeAccounts array to verify if the address exists.

Checks if the specified address is a discharge account.

Parameters

NameTypeDescription
_accountaddressThe address to check for ownership.

Return Values

NameTypeDescription
[0]boolbool Returns true if the address is a collateral owner, false otherwise.