API reference

Function

Function

constructor

constructor(swapTokenAddress, name, symbol)

Initialize AMP, initialize the default partition, and register the contract implementation in the global ERC1820Registry.

Parameter Name

Status

Type

Description

swapTokenAddress

Required

address

The address of the ERC-20 token that is set to be swappable for AMP

name

Required

string

Name of the token to be initialized

symbol

Required

string

Symbol of the token to be initialized

totalSupply

totalSupply()

Retrieves the total number of minted tokens.

Returns

Amp.totalSupply returns a uint256 containing the total number of minted tokens.

balanceOf

balanceOf(tokenHolder)

Retrieves the balance of the account with address tokenHolder across all partitions.

Note that this figure should not be used as the arbiter of the amount a token holder will successfully be able to send via the ERC-20 compatible Amp.transfer method. In order to get that figure, use Amp.balanceOfByPartition to get the balance of the default partition.

Method parameters

Parameter Name

Status

Type

Description

tokenHolder

Required

address

Address for which the balance is returned.

Returns

Amp.balanceOf returns a uint256 containing the amount of tokens held by tokenHolder across all partitions.

transfer

transfer(to, value)

Transfers an amount of tokens to the specified address.

Note that this only transfers from the msg.sender address's default partition. To transfer from other partitions, use function Amp.transferByPartition.

Method parameters

Parameter Name

Status

Type

Description

to

Required

address

The address to which the tokens should be transferred.

value

Required

uint256

The amount of tokens to be transferred.

Returns

Amp.transfer returns a bool indicating whether the operation was successful.

transferFrom

transferFrom(from, to, value)

Transfers an amount of tokens between two accounts.

Note that this only transfers from the from address's default partition. To transfer from other partitions, use function Amp.transferByPartition.

Method parameters

Parameter Name

Status

Type

Description

from

Required

address

The address from which the tokens are to be transferred.

to

Required

address

The address to which the tokens should be transferred.

value

Required

uint256

The amount of tokens to be transferred.

Returns

Amp.transferFrom returns a bool indicating whether the operation was successful.

allowance

allowance(owner, spender)

Retrieves the allowance of tokens that has been granted by owner to spender for the default partition.

Note that this only returns the allowance of the owner address's default partition. To retrieve the allowance for a different partition, use function Amp.allowanceByParititon.

Method parameters

Parameter Name

Status

Type

Description

owner

Required

address

The address holding the authorized tokens.

spender

Required

address

The address authorized to transfer the tokens from owner.

Returns

Amp.allowance returns a uint256 specifying the amount of tokens available for the spender to transfer from the owner's default partition.

approve

approve(spender, value)

Sets an allowance for an address to transfer an amount of tokens on behalf of the caller.

Note that this only affects the msg.sender address's default partition. To approve transfers from other partitions, use function Amp.approveByPartition.

This method is required for ERC-20 compatibility, but is subject to the race condition described in https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729.

Functions Amp.increaseAllowance and Amp.decreaseAllowance should be used instead.

Method parameters

Parameter Name

Status

Type

Description

value

Required

uint256

The amount of tokens to be authorized.

spender

Required

address

The address which is authorized to transfer tokens from default partition of msg.sender.

Returns

Amp.approve returns a bool indicating if the operation was successful.

increaseAllowance

increaseAllowance(spender, addedValue)

Increases the allowance granted to spender by the caller.

This is an alternative to Amp.approve that can be used as a mitigation for the race condition described in https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729.

Note that this only affects the msg.sender address's default partition. To increase the allowance for other partitions, use function Amp.increaseAllowanceByPartition.

Requirements:

  • spender cannot be the zero address.

Method parameters

Parameter Name

Status

Type

Description

spender

Required

address

The account authorized to transfer the tokens.

addedValue

Required

uint256

Additional amount of the msg.sender's tokens spender is allowed to transfer.

Returns

Amp.increaseAllowance returns a bool indicating if the operation was successful.

decreaseAllowance

decreaseAllowance(spender, substractedValue)

Decreases the allowance granted to spender by the caller.

This is an alternative to Amp.approve that can be used as a mitigation for the race condition described in https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729.

Note that this only affects the msg.sender address's default partition. To decrease the allowance for other partitions, use function decreaseAllowanceByPartition.

Requirements:

  • spender cannot be the zero address.

  • spender must have an allowance for the caller of at least subtractedValue.

Method parameters

Parameter Name

Status

Type

Description

spender

Required

address

Account whose authorization to transfer tokens is to be decreased.

substractedValue

Required

uint256

Amount by which the authorization for spender to transfer tokens held by msg.sender's account is to be decreased.

Returns

Amp.decreaseAllowance returns a bool indicating if the operation was successful.

swap

swap(from)

Exchanges an amount of source swap tokens from the contract defined at deployment for the equivalent amount of Amp tokens.

Requires the from account to have granted the Amp contract an allowance of swap tokens no greater than their balance.

Method parameters

Parameter Name

Status

Type

Description

from

Required

address

Token holder whose swap tokens will be exchanged for AMP tokens.

balanceOfByPartition

balanceOfByPartition(partition, tokenHolder)

Retrieves the balance of a token holder for a specific partition.

Method parameters

Parameter Name

Status

Type

Description

partition

Required

bytes32

The partition for which the balance is returned.

tokenHolder

Required

address

Address for which the balance is returned.

Returns

Amp.balanceOfByPartition returns a uint256 containing the amount of tokens held by tokenHolder in partition.

partitionsOf

partitionsOf(tokenHolder)

Retrieves the set of partitions for a particular token holder.

Method parameters

Parameter Name

Status

Type

Description

tokenHolder

Required

address

Address for which the partitions are returned.

Returns

Amp.partitionsOf returns a bytes32[] containing the partitions of tokenHolder.

transferByPartition

transferByPartition(partition, from, to, value, data, operatorData)

Transfers tokens from a specific partition on behalf of a token holder, optionally changing the partition and including arbitrary data used by the partition strategies and collateral managers to authorize the transfer.

This can be used to transfer an address's own tokens, or transfer a different address's tokens by specifying the from param. If attempting to transfer from a different address than msg.sender, the msg.sender will need to be an operator or have enough allowance for the partition of the from address.

Method parameters

Parameter Name

Status

Type

Description

partition

Required

bytes32

The partition from which the tokens are to be transferred.

from

Required

address

Address from which the tokens are to be transferred.

to

Required

address

Address to which the tokens are to be transferred.

value

Required

uint256

Amount of tokens to be transferred.

data

Required

bytes

Information attached to the transfer. Will contain the destination partition if changing partitions.

operatorData

Required

bytes

Additional data attached to the transfer. Used by partition strategies and collateral managers to authorize the transfer.

Returns

Amp.transferByPartition returns a bytes32 containing the destination partition.

authorizeOperator

authorizeOperator(operator)

Authorizes an address as an operator of msg.sender to transfer tokens on its behalf.

Note that this applies to all partitions.

msg.sender is always an operator for itself, and does not need to be explicitly added.

Method parameters

Parameter Name

Status

Type

Description

operator

Required

address

Address to set as an operator for msg.sender.

revokeOperator

revokeOperator(operator)

Remove the right of the operator address to be an operator for msg.sender and to transfer tokens on its behalf.

Note that this affects the account-wide authorization granted via function Amp.authorizeOperator, and does not affect authorizations granted via function Amp.authorizeOperatorByPartition.

msg.sender is always an operator for itself, and cannot be removed.

Method parameters

Parameter Name

Status

Type

Description

operator

Required

address

Address to be deauthorized an operator for msg.sender.

authorizeOperatorByPartition

authorizeOperatorByPartition(partition, operator)

Authorizes an account as an operator of a particular partition.

The msg.sender is always an operator for itself, and does not need to be explicitly added to a partition.

Method parameters

Parameter Name

Status

Type

Description

partition

Required

bytes32

The partition for which the operator is to be authorized.

operator

Required

address

Address to be authorized as an operator for msg.sender.

revokeOperatorByPartition

revokeOperatorByPartition(partition, operator)

Deauthorizes an address as an operator for a particular partition.

Note that this does not override an account-wide authorization granted via function Amp.authorizeOperator.

msg.sender is always an operator for itself, and cannot be removed from a partition.

Method parameters

Parameter Name

Status

Type

Description

partition

Required

bytes32

The partition for which the operator is deauthorized.

operator

Required

address

Address to deauthorize as an operator for msg.sender.

isOperator

isOperator(operator, tokenHolder)

Indicates whether the operator address is an operator of the tokenHolder address.

Note that this applies to all of the partitions of the msg.sender address.

Method parameters

Parameter Name

Status

Type

Description

operator

Required

address

Address which may be an operator of tokenHolder.

tokenHolder

Required

address

Address of a token holder which may have the operator address as an operator.

Returns

Amp.isOperator returns a bool indicating whether operator is an operator of tokenHolder.

isOperatorForPartition

isOperatorForPartition(partition, operator, tokenHolder)

Indicate whether the operator address is an operator of the tokenHolder address for the partition

Method parameters

Parameter Name

Status

Type

Description

partition

Required

bytes32

Partition for which operator may be authorized.

operator

Required

address

Address which may be an operator of tokenHolder for the partition.

tokenHolder

Required

address

Address of a token holder which may have the operator address as an operator for the partition.

Returns

Amp.isOperatorForPartition returns a bool indicating whether operator is an operator of tokenHolder for the partition.

isOperatorForCollateralManager

isOperatorForCollateralManager(partition, operator, collateralManager)

Indicates whether the operator address is an operator of the collateralManager address for the partition.

This method is functionally identical to Amp.isOperatorForPartition, except that it also requires the address that operator is being checked for must be a registered collateral manager.

Method parameters

Parameter Name

Status

Type

Description

partition

Required

bytes32

Partition for which operator may be authorized.

operator

Required

address

Address which may be an operator of collateralManager for the partition

collateralManager

Required

address

Address of a collateral manager which may have the operator address as an operator for the partition.

Returns

Amp.isOperatorForCollateralManager returns a bool indicating whether the operator address is an operator of the collateralManager address for the partition.

name

name()

Retrieves the name of the token.

Returns

Amp.name returns a string containing the name of the token. Always "Amp".

symbol

symbol()

Retrieves the symbol of the token.

Returns

Amp.symbol returns a string containing the symbol of the token. Always "AMP".

decimals

decimals()

Retrieves the number of decimals of the token.

Returns

Amp.decimals returns a uint8 containing the number of decimals of the token. Always 18.

granularity

granularity()

Retrieves the smallest part of the token that is not divisible.

Returns

Amp.granularity returns a uint256 containing the smallest non-divisible part of the token. Always 1.

totalPartitions

totalPartitions()

Retrieves the set of existing partitions.

Returns

Amp.totalPartitions returns a bytes32[] containing all partitions.

allowanceByPartition

allowanceByPartition(partition, owner, spender)

Retrieves the allowance of tokens that has been granted by a token holder to another account.

Method parameters

Parameter Name

Status

Type

Description

partition

Required

bytes32

Partition for which the spender may be authorized.

owner

Required

address

The address which owns the tokens.

spender

Required

address

The address which is authorized transfer tokens on behalf of the token holder.

Returns

Amp.allowanceByPartition returns a uint256 containing the amount of tokens available for spender to transfer.

approveByPartition

approveByPartition(partition, spender, value)

Approves the spender address to transfer the specified amount of tokens in partition on behalf of msg.sender.

Note that this method is subject to the race condition described in https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729. Functions Amp.increaseAllowanceByPartition and Amp.decreaseAllowanceByPartition should be used instead.

Method parameters

Parameter Name

Status

Type

Description

partition

Required

bytes32

Partition for which the spender is to be authorized to transfer tokens.

spender

Required

address

The address of the account to be authorized to transfer tokens.

value

Required

uint256

The amount of tokens to be authorized.

Returns

Amp.approveByPartition returns a bool indicating if the operation was successful.

increaseAllowanceByPartition

increaseAllowanceByPartition(partition, spender, addedValue)

Increases the allowance granted to an account by the caller for a partition.

This is an alternative to function Amp.approveByPartition that can be used as a mitigation for the race condition described in https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729

Requirements:

  • spender cannot be the zero address.

Method parameters

Parameter Name

Status

Type

Description

partition

Required

bytes32

Partition for which the spender is to be authorized to transfer tokens.

spender

Required

address

The address of the account to be authorized to transfer tokens.

addedValue

Required

uint256

Additional amount of the msg.sender's tokens spender is allowed to transfer.

Returns

Amp.increaseAllowanceByPartition returns a bool indicating if the operation was successful.

decreaseAllowanceByPartition

decreaseAllowanceByPartition(partition, spender, subtractedValue)

Decreases the allowance granted to spender by the caller.

This is an alternative to function Amp.approveByPartition that can be used as a mitigation for the race condition described in https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729

Requirements:

  • spender cannot be the zero address.

  • spender must have an allowance for the caller of at least subtractedValue.

Method parameters

Parameter Name

Status

Type

Description

partition

Required

bytes32

Partition for which spender's allowance is to be decreased.

spender

Required

address

Amount by which the authorization for spender to transfer tokens held by msg.sender's account is to be decreased.

subtractedValue

Required

uint256

Amount of the msg.sender's tokens spender is no longer allowed to transfer.

Returns

Amp.decreaseAllowanceByPartition returns a bool indicating if the operation was successful.

registerCollateralManager

registerCollateralManager(collateralManager)

Registers msg.sender as a collateral manager.

isCollateralManager

isCollateralManager(collateralManager)

Retrieves whether the supplied address is a collateral manager.

Method parameters

Parameter Name

Status

Type

Description

collateralManager

Required

address

The address of the collateral manager.

Returns

Amp.isCollateralManager returns a bool indicating whether collateralManager is registered as a collateral manager.

setPartitionStrategy

setPartitionStrategy(prefix, implementation)

Sets an implementation for a partition strategy identified by prefix.

Note: this function can only be called by the contract owner.

Method parameters

Parameter Name

Status

Type

Description

prefix

Required

bytes4

The 4 byte partition prefix the strategy applies to.

implementation

Required

address

The address of the implementation of the strategy hooks.

isPartitionStrategy

isPartitionStrategy(prefix)

Return whether the prefix has had a partition strategy registered.

Method parameters

Parameter Name

Status

Type

Description

prefix

Required

bytes4

The partition strategy identifier.

Returns

Amp.isPartitionStrategy returns a bool indicating if the strategy has been registered.

owner

owner()

Retrieves the owner of the contract

Returns

Amp.owner returns an address containing the contract owner.

authorizedNewOwner

authorizedNewOwner()

Retrieves the authorized new owner of the contract

Returns

Amp.authorizedNewOwner returns an address containing the authorized new contract owner.

authorizeOwnershipTransfer

authorizeOwnershipTransfer(authorizedAddress)

Authorizes the transfer of ownership from owner to the provided address.

Note that the transfer will not occur until authorizedAddress calls function Amp.assumeOwnership.

This authorization may be removed by another call to this function authorizing the zero address.

Method parameters

Parameter Name

Status

Type

Description

authorizedAddress

Required

address

The address authorized to become the new owner

assumeOwnership

assumeOwnership()

Transfers ownership of this contract to the authorized new owner.

canImplementInterfaceForAddress

canImplementInterfaceForAddress(interfaceHash,undefined)

Indicates whether the contract implements the interface interfaceHash.

Method parameters

Parameter Name

Status

Type

Description

interfaceHash

Required

bytes32

keccak256 hash of the name of the interface.

undefined

Required

address

Returns

Amp.canImplementInterfaceForAddress returns a bytes32 containing the ERC-1820 "accept magic" string if the contract implements ìnterfaceHash.

Last updated