Custom Transactions

Custom Transactions are special transactions to interact with dApps on DeFiChain, such as Vaults and the DeX.

Custom transaction can be identified by the first vout of a transaction

  • begin with a OP_RETURN
  • followed by a DfTx marker (serialized in UTF as 44665478)
  • followed by one character marker denoting the type of transaction (serialized in UTF), conversion table here
  • followed by custom transaction data, if required

For example, in the following custom transaction

"vout": [
{
    "value": 0.00000000,
    "n": 0,
    "scriptPubKey": {
    "asm": "OP_RETURN 446654784301d823ad3976574a50001f4ca5a5326a1c1232a0a70000",
    "hex": "6a054466547841",
    "type": "nulldata"
    },
    "tokenId": 0
},
...
]

The custom transaction can be broken down to

asmMeaning
44665478DfTx marker
43C in UTF, corresponds to CreateMasternode message (CCreateMasterNodeMessage)
01operatorType variable
d823ad3976574a50001f4ca5a5326a1c1232a0a7operatorAuthAddress variable
0000timelock variable

Transaction Types

Masternodes

CreateMasterNode

Creates a new masternode in the network

Marker: C

Message Format
VariableData TypeDescription
operatorTypechar1 for P2PKH, 4 for P2WPKH
operatorAuthAddressCKeyIDDeFiChain address of masternode operator
timelockuint16_tminimum time that masternode must be active, either 0, 5 or 10 years

ResignMasternode

Removes enabled or pre-enabled masternode from network.

Marker: R

Message Format
VariableData TypeDescription
nodeIDuint256ID of masternode to resign

SetForcedRewardAddress

Sets reward address for masternode.

Marker: F

VariableData TypeDescription
nodeIDuint256masternode ID
rewardAddressTypechar1 for P2PKH, 4 for P2WPKH
rewardAddressCKeyIDnew DeFiChain address for rewards

RemForcedRewardAddress

Removes reward address for masternode if any.

Marker: f

VariableData TypeDescription
nodeIDuint256masternode ID

UpdateMasternode

Updates masternode metadata.

Marker: m

Message Format
VariableData TypeDescription
operatorTypechar1 for P2PKH, 4 for P2WPKH
operatorAuthAddressCKeyIDDeFiChain address of masternode operator
timelockuint16_tminimum time that masternode must be active, either 0, 5 or 10 years

Custom Tokens

CreateToken

Creates new custom token.

Marker: T

Message Format
VariableData TypeDescription
tokenCTokentoken definition

Class CToken has the following structure

VariableData TypeDescription
symbolstringtoken ticker
namestringname of token
decimaluint8_thow divisible a token can be, fixed to 8
limitCAmountdeprecated
flagsuint8_tsets options for token

The following flags are available for a token:

Bit indexFlag
0None
1Mintable
2Tradeable
3DeFi Asset Token (tokens backed by collateral, e.g. dBTC)
4Liquidity Pool Share
5Finalized
6Loan Token
7Unused

Tokens are mintable and tradeable by default.

MintToken

Mints new custom tokens.

Marker: M

Message Format
VariableData TypeDescription
balancesCBalancesamount and type of token to mint

UpdateToken

Set DAT flag for a token to true or false. Deprecated.

Marker: N

VariableData TypeDescription
tokenTxuint256CreateToken transaction for a custom token
isDATboolis token a DAT

UpdateTokenAny

Update a token, supports all fields in CToken.

Marker: n

VariableData TypeDescription
balancesCBalancesamount and type of token to mint

DeX

CreatePoolPair

Create new liquidity pool.

Marker: p

Message Format
VariableData TypeDescription
poolPairCPoolPairMessagemetadata for liquidity pool
pairSymbolstringname of liquidity pool
rewardsCBalancespercentage of coinbase liquidity rewards allocated to pool

CPoolPairMessage has the following message structure:

VariableData TypeDescription
idTokenADCT_IDtoken ID for first token in LP
idTokenBstringtoken ID for second token in LP
commissionCAmountdefine fees for swap
ownerAddressCScriptowner of DeX pool
statusboolpool status (active/inactive)

UpdatePoolPair

Update a liquidity pool.

Marker: u

Message Format
VariableData TypeDescription
poolIdDCT_IDpool ID
statusboolset pool status (active/inactive)
commissionCAmountdefine fees for swap
ownerAddressCScriptowner of DeX pool
rewardsCBalancespercentage of coinbase liquidity rewards allocated to pool P2WPKH

PoolSwap

Swap tokens using a liqidity pool. Deprecated.

Marker: s

Message Format
VariableData TypeDescription
fromCScripttransaction input
toCScripttransaction output
idTokenFromDCT_IDinput token ID
idTokenToDCT_IDoutput token ID
amountFromCAmountamount of tokens to swap
maxPricePoolPricemaximum possible price

PoolSwapV2

Swap tokens using a liqidity pool. Has 16 digits precision instead of 8 in V1.

Marker: i

Message Format
VariableData TypeDescription
swapInfoCPoolSwapMessageswap metadata (contents of V1 message)
poolIDsvector<DCT_ID>IDs of pools to swap with

AddPoolLiquidity

Mint LP tokens and add liquidity to a liquidity pool.

Marker: l

Message Format
VariableData TypeDescription
fromCAccountsdToken input
shareAddressCScriptaddress for LP rewards

RemovePoolLiquidity

Redeem LP tokens and withdraw liquidity from a liquidity pool.

Marker: r

Message Format
VariableData TypeDescription
fromCAccountsLP token input
amountCTokenAmountwithdrawal amount

Accounts

UtxosToAccount

Spend UTXOs from a wallet and transfer tokens to to any DeFiChain address.

Marker: U

Message Format
VariableData TypeDescription
toCAccountsaccount and amount of tokens to send

AccountToUtxos

Creates UTXO from a wallet account.

Marker: b

Message Format
VariableData TypeDescription
fromCScriptUTXOs to spend
balancesCBalancesamount of DFI to send
mintingOutputsStartuint32_tnumber of transaction outputs

AccountToAccount

Transfer tokens between a wallet and any DeFiChain address.

Marker: B

Message Format
VariableData TypeDescription
fromCScriptUTXOs to spend
toCBalancesaccount to send tokens to

AnyAccountsToAccounts

Transfer tokens from any DeFiChain address to any DeFiChain address.

Marker: a

Message Format
VariableData TypeDescription
fromCScriptUTXOs to spend
toCBalancesaccount to send tokens to

SmartContract

Interact with DFIP2201 contract.

Marker: K

Message Format
VariableData TypeDescription
namestringname of the smart contract
accountsCAccountsaccount and amount of tokens to send

DFIP2203

Interact with DFIP2203 (Futures) contract.

Marker: Q

Message Format
VariableData TypeDescription
ownerCScriptaddress to fund contract and recieve token
sourceCTokenAmountamount of tokens to fund future contract
destinationuint32_tset underlying asset (if source id DUSD)
withdrawboolwithdraw asset to owner address

Governance

SetGovVariable

Update governance variables.

Marker: G

Message Format
VariableData TypeDescription
govsmap<shared_ptr>list of variables and values to update

SetGovVariableHeight

Set one governance variable at a particular block height.

Marker: j

Message Format
VariableData TypeDescription
govsshared_ptrvariable name and value to update
startHeightuint32_theight at which change is in effect

Authorisation

AutoAuthPrep

This is an empty custom transaction.

Marker: A

Oracles

AppointOracle

Create new oracle at an address.

Marker: o

Message Format

VariableData TypeDescription
oracleAddressCScriptaddress of new oracle
weightageuint8_toracle weightage
availablePairssetset of token prices available

RemoveOracleAppoint

Remove existing oracle.

Marker: h

Message Format

VariableData TypeDescription
oracleIdCOracleIdoracle ID

UpdateOracleAppoint

Update existing oracle.

Marker: t

Message Format

VariableData TypeDescription
oracleIdCOracleIdoracle ID
newOracleAppointCAppointOracleMessagenew oracle metadata (contents of AppointOracle message)

SetOracleData

Update oracle prices.

Marker: y

Message Format

VariableData TypeDescription
oracleIdCOracleIdoracle ID
timestampint64_ttimestamp of oracle data
pricesCTokenPricesarray of price and token strings

Interchain Exchange (ICX)

ICX is currently disabled on the mainnet.

ICXCreateOrder

Create ICX order.

Marker: 1

Message Format

VariableData TypeDescription
orderTypeuint8_tis maker buying or selling DFI
idTokenDCT_IDtoken ID on DeFiChain
ownerAddressCScriptaddress for funding DeFiChain transaction fees
receivePubkeyCPubKeypublic key which can claim external HTLC
amountFromCAmountamount of asset to be sold
amountToFillCAmountamount of tokens in order available to fill
orderPriceCAmountquoted price of asset
expiryuint32_tblock height for order expiry

ICXMakeOffer

Make an offer for an ICX order.

Marker: 2

Message Format

VariableData TypeDescription
orderTxuint256transaction ID of order
amountCAmountamount of asset to swap
ownerAddressCScriptaddress for funding DeFiChain transaction fees
receivePubkeyCPubKeypublic key which can claim external HTLC
expiryuint32_tblock height for order expiry
takerFeeCAmounttaker fee

ICXSubmitDFCHTLC

Submit a DFI hash time lock contract (HTLC) for offer.

Marker: 3

Message Format

VariableData TypeDescription
offerTxuint256transaction ID of offer
amountCAmountamount to put in HTLC
hashuint256hash of seed used for the hash lock
timeoutuint32_ttimeout for expiration of HTLC in DeFiChain blocks

ICXSubmitEXTHTLC

Submit a BTC hash time lock contract (HTLC) for offer.

Marker: 4

Message Format

VariableData TypeDescription
offerTxuint256transaction ID of offer
amountCAmountamount to put in HTLC
hashuint256hash of seed used for the hash lock
htlcscriptAddressstringscript address of external htlc
ownerPubkeyCPubKeyrefund address in case of HTLC timeout
timeoutuint32_ttimeout for expiration of HTLC in DeFiChain blocks

ICXClaimDFCHTLC

Claim a DFI HTLC.

Marker: 5

Message Format

VariableData TypeDescription
dfchtlcTxuint256transaction ID of DeFiChain HTLC
seedvectorsecret seed for claiming HTLC

ICXCloseOrder

Close an ICX order.

Marker: 6

Message Format

VariableData TypeDescription
orderTxuint256transaction ID of ICX order

ICXCloseOffer

Close an ICX offer.

Marker: 7

Message Format

VariableData TypeDescription
offerTxuint256transaction ID of ICX offer

Loans

SetLoanCollateralToken

Sets what tokens are allowed as collateral.

Marker: c

Message Format
VariableData TypeDescription
idTokenDCT_IDtoken ID
factorCAmountminimum collateralization ratio
fixedIntervalPriceIdCTokenCurrencyPairoracle price for current loan period
activateAfterBlockuint32_tblock number at which change will be activated

SetLoanToken

Sets loan token.

Marker: g

Message Format
VariableData TypeDescription
symbolstringticker for loan token
namestringname of loan token
fixedIntervalPriceIdCTokenCurrencyPairoracle price for current loan period
mintablebooltoken's mintable property, defaults to true
interestCAmountinterest rate for the token

UpdateLoanToken

Update loan token.

Marker: x

Message Format
VariableData TypeDescription
tokenTxuint256token creation tx
symbolstringticker for loan token
namestringname of loan token
fixedIntervalPriceIdCTokenCurrencyPairoracle price for current loan period
mintablebooltoken's mintable property, defaults to true
interestCAmountinterest rate for the token

LoanScheme

Create a loan scheme.

Marker: L

Message Format
VariableData TypeDescription
identifierstringloan scheme identifier
updateHeightuint64_tblock height to create scheme at
ratiouint32_tminimum collateralization ratio
rateCAmountinterest rate

DefaultLoanScheme

Set default loan scheme.

Marker: d

Message Format
VariableData TypeDescription
identifierstringloan scheme identifier

DestroyLoanScheme

Delete existing loan scheme.

Marker: D

Message Format
VariableData TypeDescription
identifierstringloan scheme identifier
destroyHeightuint64_tblock height to destroy scheme at

Vault

Create new vault.

Marker: V

Message Format
VariableData TypeDescription
ownerAddressCScriptowner of vault
schemeIdstringloan scheme to use

CloseVault

Close existing vault.

Marker: e

Message Format
VariableData TypeDescription
vaultIdCVaultIdID of vault
toCScriptaddress to send collateral to

UpdateVault

Update existing open vault.

Marker: v

Message Format
VariableData TypeDescription
vaultIdCVaultIdID of vault
ownerAddressCScriptowner of vault
schemeIdstringloan scheme to use

DepositToVault

Deposit collateral in a vault.

Marker: S

Message Format
VariableData TypeDescription
vaultIdCVaultIdID of vault
fromCScriptaddress funding the vault
amountCTokenAmountamount of tokens to deposit

WithdrawFromVault

Withdraw collateral in a vault.

Marker: J

Message Format
VariableData TypeDescription
vaultIdCVaultIdID of vault
toCScriptaddress to send collateral to
amountCTokenAmountamount of tokens to deposit

TakeLoan

Mint loan token against a loan vault.

Marker: X

Message Format
VariableData TypeDescription
vaultIdCVaultIdID of vault
toCScriptaddress to send loan tokens to
amountCBalancesamount of loan token to mint

PaybackLoan

Repay an existing loan. Deprecated.

Marker: H

Message Format
VariableData TypeDescription
vaultIdCVaultIdID of vault
fromCScriptaddress repaying the loan
amountCBalancesamount of loan token to repay

PaybackLoanV2

Repay an existing loan.

Marker: k

Message Format
VariableData TypeDescription
vaultIdCVaultIdID of vault
fromCScriptaddress repaying the loan
loansmap<DCT_ID, CBalances>amount of loan token to repay

AuctionBid

Bid for an auction on a vault.

Marker: I

Message Format
VariableData TypeDescription
vaultIdCVaultIdID of vault
indexuint32_tauction index
fromCScriptaddress to recieve vault collateral
amountCTokenAmountbid amount

FutureSwapExecution

Unimplemented

Marker: q

FutureSwapRefund

Unimplemented

Marker: w