MultiAssetHolder.sol
View Source: contracts/MultiAssetHolder.sol
โ Extends: IMultiAssetHolder, StatusManager โ Derived Contracts: NitroAdjudicator
An implementation of the IMultiAssetHolder interface. The AssetHolder contract escrows ETH or tokens against state channels. It allows assets to be internally accounted for, and ultimately prepared for transfer from one channel to other channels and/or external destinations, as well as for guarantees to be claimed.
Contract Members
Constants & Variables
Functions
- deposit
- transfer
- _apply_transfer_checks
- compute_transfer_effects_and_interactions
- _apply_transfer_effects
- _apply_transfer_interactions
- claim
- _apply_claim_checks
- compute_claim_effects_and_interactions
- _apply_claim_effects
- _apply_claim_interactions
- _executeSingleAssetExit
- _transferAsset
- _isExternalDestination
- _addressToBytes32
- _bytes32ToAddress
- _requireMatchingFingerprint
- _requireChannelFinalized
- _updateFingerprint
- _requireIncreasingIndices
- min
- decodeGuaranteeData
deposit
Deposit ETH or erc20 tokens against a given channelId.
Arguments
Name | Type | Description |
---|---|---|
asset | address | erc20 token address, or zero address to indicate ETH |
channelId | bytes32 | ChannelId to be credited. |
expectedHeld | uint256 | The number of wei/tokens the depositor believes are already escrowed against the channelId. |
amount | uint256 | The intended number of wei/tokens to be deposited. |
transfer
Transfers as many funds escrowed against channelId
as can be afforded for a specific destination. Assumes no repeated entries.
Arguments
Name | Type | Description |
---|---|---|
assetIndex | uint256 | Will be used to slice the outcome into a single asset outcome. |
fromChannelId | bytes32 | Unique identifier for state channel to transfer funds from. |
outcomeBytes | bytes | The encoded Outcome of this state channel |
stateHash | bytes32 | The hash of the state stored when the channel finalized. |
indices | uint256[] | Array with each entry denoting the index of a destination to transfer funds to. An empty array indicates "all". |
_apply_transfer_checks
Arguments
Name | Type | Description |
---|---|---|
assetIndex | uint256 | |
indices | uint256[] | |
channelId | bytes32 | |
stateHash | bytes32 | |
outcomeBytes | bytes |
compute_transfer_effects_and_interactions
Arguments
Name | Type | Description |
---|---|---|
initialHoldings | uint256 | |
allocations | struct ExitFormat.Allocation[] | |
indices | uint256[] |
_apply_transfer_effects
Arguments
Name | Type | Description |
---|---|---|
assetIndex | uint256 | |
asset | address | |
channelId | bytes32 | |
stateHash | bytes32 | |
outcome | struct ExitFormat.SingleAssetExit[] | |
newAllocations | struct ExitFormat.Allocation[] | |
initialHoldings | uint256 | |
totalPayouts | uint256 |
_apply_transfer_interactions
Arguments
Name | Type | Description |
---|---|---|
singleAssetExit | struct ExitFormat.SingleAssetExit | |
exitAllocations | struct ExitFormat.Allocation[] |
claim
Transfers as many funds escrowed against sourceChannelId
as can be afforded for the destinations specified by targetAllocationIndicesToPayout in the beneficiaries of the target of the channel at indexOfTargetInSource.
Arguments
Name | Type | Description |
---|---|---|
claimArgs | struct IMultiAssetHolder.ClaimArgs | arguments used in the claim function. Used to avoid stack too deep error. |
_apply_claim_checks
Checks that targetAllocationIndicesToPayout are increasing; that the source and target channels are finalized; that the supplied outcomes match the stored fingerprints; that the asset is identical in source and target. Computes and returns: the decoded outcomes, the asset being targetted; the number of assets held against the guarantor.
Arguments
Name | Type | Description |
---|---|---|
claimArgs | struct IMultiAssetHolder.ClaimArgs |
compute_claim_effects_and_interactions
Computes side effects for the claim function. First, computes the amount the source channel can afford for the target. Then, computes and returns updated allocations for the source and for the target, as well as exit allocations (to be paid out). It does this by walking the target allocations, testing against the guarantee in the source, and conditionally siphoning money out. See the Nitro paper.
Arguments
Name | Type | Description |
---|---|---|
initialHoldings | uint256 | |
sourceAllocations | struct ExitFormat.Allocation[] | |
targetAllocations | struct ExitFormat.Allocation[] | |
indexOfTargetInSource | uint256 | |
targetAllocationIndicesToPayout | uint256[] |
_apply_claim_effects
Applies precomputed side effects for claim. Updates the holdings of the source channel. Updates the fingerprint of the outcome for the source and the target channel. Emits an event for each channel.
Arguments
Name | Type | Description |
---|---|---|
claimArgs | struct IMultiAssetHolder.ClaimArgs | |
asset | address | |
sourceOutcome | struct ExitFormat.SingleAssetExit[] | |
newSourceAllocations | struct ExitFormat.Allocation[] | |
targetChannelId | bytes32 | |
targetOutcome | struct ExitFormat.SingleAssetExit[] | |
newTargetAllocations | struct ExitFormat.Allocation[] | |
initialHoldings | uint256 | |
totalPayouts | uint256 |
_apply_claim_interactions
Applies precomputed side effects for claim that interact with external contracts. "Executes" the supplied exit (pays out the money).
Arguments
Name | Type | Description |
---|---|---|
singleAssetExit | struct ExitFormat.SingleAssetExit | |
exitAllocations | struct ExitFormat.Allocation[] |
_executeSingleAssetExit
Executes a single asset exit by paying out the asset and calling external contracts, as well as updating the holdings stored in this contract.
Arguments
Name | Type | Description |
---|---|---|
singleAssetExit | struct ExitFormat.SingleAssetExit | The single asset exit to be paid out. |
_transferAsset
Transfers the given amount of this AssetHolders's asset type to a supplied ethereum address.
Arguments
Name | Type | Description |
---|---|---|
asset | address | |
destination | address | ethereum address to be credited. |
amount | uint256 | Quantity of assets to be transferred. |
_isExternalDestination
Checks if a given destination is external (and can therefore have assets transferred to it) or not.
Returns
True if the destination is external, false otherwise.
Arguments
Name | Type | Description |
---|---|---|
destination | bytes32 | Destination to be checked. |
_addressToBytes32
Converts an ethereum address to a nitro external destination.
Returns
The input address left-padded with zeros.
Arguments
Name | Type | Description |
---|---|---|
participant | address | The address to be converted. |
_bytes32ToAddress
Converts a nitro destination to an ethereum address.
Returns
The rightmost 160 bits of the input string.
Arguments
Name | Type | Description |
---|---|---|
destination | bytes32 | The destination to be converted. |
_requireMatchingFingerprint
Checks that a given variables hash to the data stored on chain.
Arguments
Name | Type | Description |
---|---|---|
stateHash | bytes32 | |
outcomeHash | bytes32 | |
channelId | bytes32 |
_requireChannelFinalized
Checks that a given channel is in the Finalized mode.
Arguments
Name | Type | Description |
---|---|---|
channelId | bytes32 | Unique identifier for a channel. |
_updateFingerprint
Arguments
Name | Type | Description |
---|---|---|
channelId | bytes32 | |
stateHash | bytes32 | |
outcomeHash | bytes32 |
_requireIncreasingIndices
Checks that the supplied indices are strictly increasing.
Arguments
Name | Type | Description |
---|---|---|
indices | uint256[] |
min
Arguments
Name | Type | Description |
---|---|---|
a | uint256 | |
b | uint256 |
decodeGuaranteeData
Arguments
Name | Type | Description |
---|---|---|
data | bytes |