AssetHolder.sol

View Source: contracts/AssetHolder.sol

โ†— Extends: IAssetHolder โ†˜ Derived Contracts: ERC20AssetHolder, ETHAssetHolder, TESTAssetHolder

An implementation of the IAssetHolder 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 channel and/or external destinations, as well as for guarantees to be claimed. Note there is no deposit function and the _transferAsset function is unimplemented; inheriting contracts should implement these functions in a manner appropriate to the asset type (e.g. ETH or ERC20 tokens).


Contract Members

Constants & Variables

address public AdjudicatorAddress;
mapping(bytes32 => uint256) public holdings;
mapping(bytes32 => bytes32) public assetOutcomeHashes;

Modifiers

AdjudicatorOnly

modifier AdjudicatorOnly() internal

Arguments

NameTypeDescription

Functions


transfer

Transfers as many funds escrowed against channelId as can be afforded for a specific destination. Assumes no repeated entries.

function transfer(bytes32 fromChannelId, bytes allocationBytes, uint256[] indices) external nonpayable

Arguments

NameTypeDescription
fromChannelIdbytes32Unique identifier for state channel to transfer funds from.
allocationBytesbytesThe abi.encode of AssetOutcome.Allocation
indicesuint256[]Array with each entry denoting the index of a destination to transfer funds to. An empty array indicates "all".

claim

Transfers as many funds escrowed against guarantorChannelId as can be afforded for a specific destination in the beneficiaries of the target of that channel. Checks against the storage in this contract.

function claim(bytes32 guarantorChannelId, bytes guaranteeBytes, bytes allocationBytes, uint256[] indices) external nonpayable

Arguments

NameTypeDescription
guarantorChannelIdbytes32Unique identifier for a guarantor state channel.
guaranteeBytesbytesThe abi.encode of Outcome.Guarantee
allocationBytesbytesThe abi.encode of AssetOutcome.Allocation for the target
indicesuint256[]Array with each entry denoting the index of a destination (in the target channel) to transfer funds to. Should be in increasing order. An empty array indicates "all".

transferAllAdjudicatorOnly

Transfers the funds escrowed against channelId to the beneficiaries of that channel. No checks performed against storage in this contract. Permissioned.

function transferAllAdjudicatorOnly(bytes32 channelId, bytes allocationBytes) external nonpayable AdjudicatorOnly

Arguments

NameTypeDescription
channelIdbytes32Unique identifier for a state channel.
allocationBytesbytesThe abi.encode of AssetOutcome.Allocation

setAssetOutcomeHash

Sets the given assetOutcomeHash for the given channelId in the assetOutcomeHashes storage mapping.

function setAssetOutcomeHash(bytes32 channelId, bytes32 assetOutcomeHash) external nonpayable AdjudicatorOnly

Arguments

NameTypeDescription
channelIdbytes32Unique identifier for a state channel.
assetOutcomeHashbytes32The keccak256 of the abi.encode of the Outcome.

_computeNewAllocationWithGuarantee

function _computeNewAllocationWithGuarantee(uint256 initialHoldings, struct Outcome.AllocationItem[] allocation, uint256[] indices, struct Outcome.Guarantee guarantee) public pure
returns(newAllocation struct Outcome.AllocationItem[], safeToDelete bool, payouts uint256[], totalPayouts uint256)

Arguments

NameTypeDescription
initialHoldingsuint256
allocationstruct Outcome.AllocationItem[]
indicesuint256[]
guaranteestruct Outcome.Guarantee

_computeNewAllocation

function _computeNewAllocation(uint256 initialHoldings, struct Outcome.AllocationItem[] allocation, uint256[] indices) public pure
returns(newAllocation struct Outcome.AllocationItem[], safeToDelete bool, payouts uint256[], totalPayouts uint256)

Arguments

NameTypeDescription
initialHoldingsuint256
allocationstruct Outcome.AllocationItem[]
indicesuint256[]

_transfer

Transfers as many funds escrowed against channelId as can be afforded for a specific destination. Assumes no repeated entries. Does not check allocationBytes against on chain storage.

function _transfer(bytes32 fromChannelId, bytes allocationBytes, uint256[] indices) internal nonpayable

Arguments

NameTypeDescription
fromChannelIdbytes32Unique identifier for state channel to transfer funds from.
allocationBytesbytesThe abi.encode of AssetOutcome.Allocation
indicesuint256[]Array with each entry denoting the index of a destination to transfer funds to. Should be in increasing order. An empty array indicates "all".

_claim

Transfers as many funds escrowed against guarantorChannelId as can be afforded for a specific destination in the beneficiaries of the target of that channel. Does not check allocationBytes or guarantee against on chain storage.

function _claim(bytes32 guarantorChannelId, struct Outcome.Guarantee guarantee, bytes allocationBytes, uint256[] indices) internal nonpayable

Arguments

NameTypeDescription
guarantorChannelIdbytes32Unique identifier for a guarantor state channel.
guaranteestruct Outcome.GuaranteeThe guarantee
allocationBytesbytesThe abi.encode of AssetOutcome.Allocation for the target
indicesuint256[]Array with each entry denoting the index of a destination (in the target channel) to transfer funds to. An empty array indicates "all".

_setAssetOutcomeHash

Sets the given assetOutcomeHash for the given channelId in the assetOutcomeHashes storage mapping

function _setAssetOutcomeHash(bytes32 channelId, bytes32 assetOutcomeHash) internal nonpayable

Arguments

NameTypeDescription
channelIdbytes32Unique identifier for a state channel.
assetOutcomeHashbytes32The keccak256 of the abi.encode of the Outcome.

_transferAsset

Transfers the given amount of this AssetHolders's asset type to a supplied ethereum address.

function _transferAsset(address payable destination, uint256 amount) internal nonpayable

Arguments

NameTypeDescription
destinationaddress payableethereum address to be credited.
amountuint256Quantity of assets to be transferred.

_isExternalDestination

Checks if a given destination is external (and can therefore have assets transferred to it) or not.

function _isExternalDestination(bytes32 destination) internal pure
returns(bool)

Returns

True if the destination is external, false otherwise.

Arguments

NameTypeDescription
destinationbytes32Destination to be checked.

_addressToBytes32

Converts an ethereum address to a nitro external destination.

function _addressToBytes32(address participant) internal pure
returns(bytes32)

Returns

The input address left-padded with zeros.

Arguments

NameTypeDescription
participantaddressThe address to be converted.

_bytes32ToAddress

Converts a nitro destination to an ethereum address.

function _bytes32ToAddress(bytes32 destination) internal pure
returns(address payable)

Returns

The rightmost 160 bits of the input string.

Arguments

NameTypeDescription
destinationbytes32The destination to be converted.

_requireCorrectAllocationHash

function _requireCorrectAllocationHash(bytes32 channelId, bytes allocationBytes) internal view

Arguments

NameTypeDescription
channelIdbytes32
allocationBytesbytes

_requireCorrectGuaranteeHash

function _requireCorrectGuaranteeHash(bytes32 guarantorChannelId, bytes guaranteeBytes) internal view

Arguments

NameTypeDescription
guarantorChannelIdbytes32
guaranteeBytesbytes

_requireIncreasingIndices

function _requireIncreasingIndices(uint256[] indices) internal pure

Arguments

NameTypeDescription
indicesuint256[]

min

function min(uint256 a, uint256 b) internal pure
returns(uint256)

Arguments

NameTypeDescription
auint256
buint256
Last updated on by geoknee