Skip to main content

Token Converter Contract

Using this contract can build a connection between the base token and other tokens created on the chain. After building the connection, users can trade tokens with the Bancor model. You can find detailed information about Bancor in the AElf Economic System White Paper. Implement aelf Standards ACS1.

Contract Methods

Method NameRequest TypeResponse TypeDescription
InitializeTokenConverter.InitializeInputgoogle.protobuf.EmptyInitialize TokenConvert contract.
SetConnectorTokenConverter.Connectorgoogle.protobuf.Empty
BuyTokenConverter.BuyInputgoogle.protobuf.EmptyAfter establishing Bancor model of token and base token, you can buy token through this method.
SellTokenConverter.SellInputgoogle.protobuf.EmptyAfter establishing Bancor model of token and base token, you can sell token through this method.
SetFeeRategoogle.protobuf.StringValuegoogle.protobuf.EmptySet the fee rate for buy/sell (fee amount = cost * feeRate).
UpdateConnectorTokenConverter.Connectorgoogle.protobuf.EmptyBefore calling the EnableConnector, the connector controller can update the pair connector through this method.
AddPairConnectorTokenConverter.PairConnectorParamgoogle.protobuf.EmptyAdd a pair connector for new token and the base token.
EnableConnectorTokenConverter.ToBeConnectedTokenInfogoogle.protobuf.EmptyAfter adding a pair, you need to call this method to enable it before buying and selling tokens.
ChangeConnectorControllerAuthorityInfogoogle.protobuf.EmptySet the governance authority information for TokenConvert contract.
GetPairConnectorTokenConverter.TokenSymbolTokenConverter.PairConnectorQuery the pair connector according to token symbol.
GetFeeRategoogle.protobuf.Emptygoogle.protobuf.StringValueQuery the fee rate for buy/sell.
GetBaseTokenSymbolgoogle.protobuf.EmptyTokenConverter.TokenSymbolQuery the symbol of base token.
GetNeededDepositTokenConverter.ToBeConnectedTokenInfoTokenConverter.DepositInfoQuery how much the base token needs to be deposited before enabling the connector.
GetDepositConnectorBalancegoogle.protobuf.StringValuegoogle.protobuf.Int64ValueQuery how much the base token has been deposited.
GetControllerForManageConnectorgoogle.protobuf.EmptyAuthorityInfoQuery the governance authority information for TokenConvert contract.
IsSymbolAbleToSellgoogle.protobuf.StringValuegoogle.protobuf.BoolValueQuery whether the token can be sold.

AElf.Standards.ACS1

Method NameRequest TypeResponse TypeDescription
SetMethodFeeacs1.MethodFeesgoogle.protobuf.EmptySet the method fees for the specified method. Note that this will override all fees of the method.
ChangeMethodFeeControllerAuthorityInfogoogle.protobuf.EmptyChange the method fee controller, the default is parliament and default organization.
GetMethodFeegoogle.protobuf.StringValueacs1.MethodFeesQuery method fee information by method name.
GetMethodFeeControllergoogle.protobuf.EmptyAuthorityInfoQuery the method fee controller.

Contract Types

AElf.Contracts.TokenConverter

TokenConverter.BuyInput

FieldTypeDescriptionLabel
symbolstringThe token symbol you want to buy.
amountint64The amount you want to buy.
pay_limitint64Limit of cost. If the token required for buy exceeds this value, the buy will be abandoned. And 0 is no limit.

TokenConverter.Connector

FieldTypeDescriptionLabel
symbolstringThe token symbol.
virtual_balanceint64The virtual balance for base token.
weightstringThe calculated weight value for this Connector.
is_virtual_balance_enabledboolWhether to use Virtual Balance.
is_purchase_enabledboolWhether the connector is enabled.
related_symbolstringIndicates its related connector, the pair connector includes a new created token connector and the base token connector.
is_deposit_accountboolIndicates if the connector is base token connector.

TokenConverter.DepositInfo

FieldTypeDescriptionLabel
need_amountint64How much more base Token is needed as the deposit.
amount_out_of_token_convertint64How many tokens are not on the TokenConvert address.

TokenConverter.InitializeInput

FieldTypeDescriptionLabel
base_token_symbolstringBase token symbol, default is the native token symbol.
fee_ratestringThe fee rate for buy/sell.
connectorsConnectorThe default added connectors.repeated

TokenConverter.PairConnector

FieldTypeDescriptionLabel
resource_connectorConnectorThe connector of the specified token.
deposit_connectorConnectorThe related connector.

TokenConverter.PairConnectorParam

FieldTypeDescriptionLabel
resource_connector_symbolstringThe token symbol.
resource_weightstringThe weight value of this token in the Bancor model.
native_virtual_balanceint64This token corresponds to the value of base token.
native_weightstringThe weight value of base token in Bancor model.

TokenConverter.SellInput

FieldTypeDescriptionLabel
symbolstringThe token symbol you want to sell.
amountint64The amount you want to sell.
receive_limitint64Limits on tokens obtained by selling. If the token obtained is less than this value, the sale will be abandoned. And 0 is no limit.

TokenConverter.ToBeConnectedTokenInfo

FieldTypeDescriptionLabel
token_symbolstringThe token symbol.
amount_to_token_convertint64Specifies the number of tokens to convert to the TokenConvert contract.

TokenConverter.TokenBought

FieldTypeDescriptionLabel
symbolstringThe token symbol bought.
bought_amountint64The amount bought.
base_amountint64The total cost of the base token.
fee_amountint64The fee amount.

TokenConverter.TokenSold

FieldTypeDescriptionLabel
symbolstringThe token symbol sold.
sold_amountint64The amount sold.
base_amountint64The total received of the base token.
fee_amountint64The fee amount.

TokenConverter.TokenSymbol

FieldTypeDescriptionLabel
symbolstring The token symbol.

AElf.Standards.ACS1

acs1.MethodFee

FieldTypeDescriptionLabel
symbolstring The token symbol of the method fee.
basic_feeint64 The amount of fees to be charged.

acs1.MethodFees

FieldTypeDescriptionLabel
method_namestring The name of the method to be charged.
feesMethodFee List of fees to be charged.repeated
is_size_fee_freeboolOptional based on the implementation of SetMethodFee method.

AElf.Types

aelf.Address

FieldTypeDescriptionLabel
valuebytes

aelf.BinaryMerkleTree

FieldTypeDescriptionLabel
nodesHash The leaf nodes.repeated
rootHash The root node hash.
leaf_countint32 The count of leaf node.

aelf.Hash

FieldTypeDescriptionLabel
valuebytes

aelf.LogEvent

FieldTypeDescriptionLabel
addressAddress The contract address.
namestring The name of the log event.
indexedbytes The indexed data, used to calculate bloom.repeated
non_indexedbytes The non indexed data.

aelf.MerklePath

FieldTypeDescriptionLabel
merkle_path_nodesMerklePathNode The merkle path nodes.repeated

aelf.MerklePathNode

FieldTypeDescriptionLabel
hashHash The node hash.
is_left_child_nodeboolWhether it is a left child node.

aelf.SInt32Value

FieldTypeDescriptionLabel
valuesint32

aelf.SInt64Value

FieldTypeDescriptionLabel
valuesint64

aelf.ScopedStatePath

FieldTypeDescriptionLabel
addressAddressThe scope address, which will be the contract address.
pathStatePathThe path of contract state.

aelf.SmartContractRegistration

FieldTypeDescriptionLabel
categorysint32The category of contract code (0: C#).
codebytesThe byte array of the contract code.
code_hashHashThe hash of the contract code.
is_system_contractboolWhether it is a system contract.
versionint32The version of the current contract.

aelf.StatePath

FieldTypeDescriptionLabel
partsstringThe partial path of the state path.repeated

aelf.Transaction

FieldTypeDescriptionLabel
fromAddressThe address of the sender of the transaction.
toAddressThe address of the contract when calling a contract.
ref_block_numberint64The height of the referenced block hash.
ref_block_prefixbytesThe first four bytes of the referenced block hash.
method_namestringThe name of a method in the smart contract at the To address.
paramsbytesThe parameters to pass to the smart contract method.
signaturebytesWhen signing a transaction it’s actually a subset of the fields: from/to and the target method as well as the parameter that were given. It also contains the reference block number and prefix.

aelf.TransactionExecutingStateSet

FieldTypeDescriptionLabel
writesTransactionExecutingStateSet.WritesEntryThe changed states.repeated
readsTransactionExecutingStateSet.ReadsEntryThe read states.repeated
deletesTransactionExecutingStateSet.DeletesEntryThe deleted states.repeated

aelf.TransactionExecutingStateSet.DeletesEntry

FieldTypeDescriptionLabel
keystring
valuebool

aelf.TransactionExecutingStateSet.ReadsEntry

FieldTypeDescriptionLabel
keystring
valuebool

aelf.TransactionExecutingStateSet.WritesEntry

FieldTypeDescriptionLabel
keystring
valuebytes

aelf.TransactionResult

FieldTypeDescriptionLabel
transaction_idHashThe transaction id.
statusTransactionResultStatusThe transaction result status.
logsLogEventThe log events.repeated
bloombytesBloom filter for transaction logs. A transaction log event can be defined in the contract and stored in the bloom filter after the transaction is executed. Through this filter, we can quickly search for and determine whether a log exists in the transaction result.
return_valuebytesThe return value of the transaction execution.
block_numberint64The height of the block hat packages the transaction.
block_hashHashThe hash of the block hat packages the transaction.
errorstringFailed execution error message.

aelf.TransactionResultStatus

NameNumberDescription
NOT_EXISTED0The execution result of the transaction does not exist.
PENDING1The transaction is in the transaction pool waiting to be packaged.
FAILED2Transaction execution failed.
MINED3The transaction was successfully executed and successfully packaged into a block.
CONFLICT4When executed in parallel, there are conflicts with other transactions.
PENDING_VALIDATION5The transaction is waiting for validation.
NODE_VALIDATION_FAILED6Transaction validation failed.

AuthorityInfo

FieldTypeDescriptionLabel
contract_addressaelf.AddressThe contract address of the controller.
owner_addressaelf.AddressThe address of the owner of the contract.