Asset

Git Source

Inherits: IAsset

Author: CapSign Inc.

A base contract for representing tokens of an asset with physical (raw) balances only. It does not handle any ratio-based adjustments like splits or dividends.

State Variables

name

string public name;

prefix

string public prefix;

totalSupply

uint256 public totalSupply;

lots

mapping(bytes32 => Lot) public lots;

balances

mapping(address => uint256) public balances;

operatorApprovals

mapping(address => mapping(address => bool)) private operatorApprovals;

allowances

mapping(bytes32 => mapping(address => mapping(address => uint96))) public allowances;

Functions

setName

Sets the name of the token.

function setName(string memory _name) public;

Parameters

Name
Type
Description

_name

string

The name of the token.

setPrefix

Sets the prefix of the token.

function setPrefix(string memory _prefix) public;

Parameters

Name
Type
Description

_prefix

string

The prefix of the token.

createLot

Creates a brand-new lot (e.g., an initial issuance) for a user.

function createLot(
    address to,
    uint96 quantity,
    address paymentCurrency,
    uint96 costBasis,
    uint64 acquisitionDate,
    string memory uri,
    bytes memory data
) public virtual returns (bytes32 lotId);

Parameters

Name
Type
Description

to

address

The owner of the lot.

quantity

uint96

The total raw quantity for this lot.

paymentCurrency

address

The payment currency for this lot.

costBasis

uint96

Raw cost basis per unit.

acquisitionDate

uint64

The original acquisition date.

uri

string

The URI of the lot.

data

bytes

Additional data associated with the lot.

Returns

Name
Type
Description

lotId

bytes32

The unique ID of the new lot.

transfer

*Transfers a lot or partial lot from 'from' to 'to', physically/fully (raw).

  • If the entire lot is transferred, the old lot is invalidated.

  • If partial, a new lot is created for the remainder.*

function transfer(bytes32 lotId, address to, uint96 quantity, string memory uri, bytes memory data) public virtual;

Parameters

Name
Type
Description

lotId

bytes32

The ID of the lot to transfer from.

to

address

The new owner.

quantity

uint96

The raw quantity to transfer.

uri

string

The URI of the lot.

data

bytes

Additional data associated with the transfer.

transferFrom

*Transfers a lot or partial lot from 'from' to 'to', physically/fully (raw).

  • If the entire lot is transferred, the old lot is invalidated.

  • If partial, a new lot is created for the remainder.*

function transferFrom(bytes32 lotId, address from, address to, uint96 quantity, string memory uri, bytes memory data)
    public
    virtual;

Parameters

Name
Type
Description

lotId

bytes32

The ID of the lot to transfer from.

from

address

The current owner of the lot.

to

address

The new owner.

quantity

uint96

The raw quantity to transfer.

uri

string

data

bytes

Additional data associated with the transfer.

adjustLot

Creates a new lot as a child of an old lot, typically used for spin-offs, cost basis corrections, partial reclassifications, etc.

function adjustLot(
    bytes32 oldLotId,
    uint96 newQuantity,
    uint96 newCostBasis,
    string memory newUri,
    bytes memory newData,
    string calldata reason
) public virtual returns (bytes32 newLotId);

Parameters

Name
Type
Description

oldLotId

bytes32

The old lot to be adjusted.

newQuantity

uint96

The raw quantity for the new lot.

newCostBasis

uint96

The raw cost basis for the new lot.

newUri

string

newData

bytes

reason

string

A short string explaining the adjustment type, e.g. "SpinOff", "ManualCorrection".

Returns

Name
Type
Description

newLotId

bytes32

The ID of the newly created lot.

getLot

Returns the stored data.

function getLot(bytes32 lotId)
    external
    view
    virtual
    returns (
        bytes32 parentLotId,
        bool isValid,
        uint96 quantity,
        address paymentCurrency,
        uint96 costBasis,
        uint64 acquisitionDate,
        uint64 lastUpdate,
        string memory uri,
        bytes memory data
    );

Parameters

Name
Type
Description

lotId

bytes32

The lot ID to query.

Returns

Name
Type
Description

parentLotId

bytes32

Hash of the parent lot, or 0x0 if none.

isValid

bool

Whether the lot is active.

quantity

uint96

The raw quantity.

paymentCurrency

address

The payment currency for this lot.

costBasis

uint96

The raw cost basis.

acquisitionDate

uint64

The original acquisition timestamp (unmodified).

lastUpdate

uint64

The last time this lot was updated.

uri

string

The URI of the lot.

data

bytes

Additional data associated with the lot.

balanceOf

Returns the balance of an owner.

function balanceOf(address owner) public view returns (uint256);

Parameters

Name
Type
Description

owner

address

The owner of the balance.

Returns

Name
Type
Description

<none>

uint256

The balance of the owner.

_transfer

*Internal function to transfer a lot or partial lot from 'from' to 'to', physically/fully (raw).

  • If the entire lot is transferred, the old lot is invalidated.

  • If partial, a new lot is created for the remainder.*

function _transfer(bytes32 lotId, address from, address to, uint96 quantity, string memory uri, bytes memory data)
    internal;

Parameters

Name
Type
Description

lotId

bytes32

The ID of the lot to transfer from.

from

address

The current owner of the lot.

to

address

The new owner.

quantity

uint96

The raw quantity to transfer.

uri

string

data

bytes

Additional data associated with the transfer.

setApprovalForAll

Approve or revoke permission for an operator to manage all of the caller's tokens.

function setApprovalForAll(address operator, bool approved) public;

Parameters

Name
Type
Description

operator

address

The address to grant or revoke approval.

approved

bool

True to grant approval, false to revoke.

isApprovedForAll

Returns true if operator is approved to manage all of owner's tokens.

function isApprovedForAll(address owner, address operator) public view returns (bool approved);

Parameters

Name
Type
Description

owner

address

The owner of the tokens.

operator

address

The operator address.

Returns

Name
Type
Description

approved

bool

True if approved, false otherwise.

approveLot

Approves spender to manage amount of a specific lot.

function approveLot(bytes32 lotId, address spender, uint96 amount) public;

Parameters

Name
Type
Description

lotId

bytes32

The ID of the lot.

spender

address

The address to approve.

amount

uint96

The amount of the lot they can manage.

Last updated

Was this helpful?