Skip to content

Liquidity Pool API Document

U-Zyn Chua edited this page Dec 1, 2020 · 4 revisions

Liquidity Pool API Documentation

listpoolpairs

( {"start":n,"including_start":bool,"limit":n} verbose )

Returns information about pools.

Arguments:
1. pagination                      (json object)
     {
       "start": n,                 (numeric) Optional first key to iterate from, in lexicographical order.Typically it's set to last ID from previous request.
       "including_start": bool,    (boolean) If true, then iterate including starting position. False by default
       "limit": n,                 (numeric) Maximum number of pools to return, 100 by default
     }
2. verbose                         (boolean) Flag for verbose list (default = true), otherwise only ids, symbols and names are listed

Result:
{id:{...},...}     (array) Json object with pools information

Examples:
> defi-cli listpoolpairs {"start":128} False
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listpoolpairs", "params": [{"start":128} False] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

getpoolpair

"key" ( verbose )

Returns information about pool.

Arguments:
1. key        (string, required) One of the keys may be specified (id/symbol/creationTx)
2. verbose    (boolean) Flag for verbose list (default = true), otherwise limited objects are listed

Result:
{id:{...}}     (array) Json object with pool information

Examples:
> defi-cli getpoolpair GOLD
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "getpoolpair", "params": [GOLD] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

addpoolliquidity

{"address":"str"} "shareAddress" ( [{"txid":"hex","vout":n},...] )

Creates (and submits to local node and network) a add pool liquidity transaction. The last optional argument (may be empty array) is an array of specific UTXOs to spend.

Arguments:
1. from                     (json object, required)
     {
       "address": "str",    (string, required) The defi address(es) is the key(s), the value(s) is amount in amount@token format. You should provide exectly two types of tokens for pool's 'token A' and 'token B' in any combinations.If multiple tokens from one address are to be transferred, specify an array ["amount1@t1", "amount2@t2"]
     }
2. shareAddress             (string, required) The defi address for crediting tokens.
3. inputs                   (json array, optional) A json array of json objects
     [
       {                    (json object)
         "txid": "hex",     (string, required) The transaction id
         "vout": n,         (numeric, required) The output number
       },
       ...
     ]

Result:
"hash"                  (string) The hex-encoded hash of broadcasted transaction

Examples:
> defi-cli addpoolliquidity '{"address1":"1.0@DFI","address2":"1.0@DFI"}' share_address []
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "addpoolliquidity", "params": ['{"address1":"1.0@DFI","address2":"1.0@DFI"}' share_address []] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

removepoolliquidity

"from" "amount" ( [{"txid":"hex","vout":n},...] )

Creates (and submits to local node and network) a remove pool liquidity transaction. The last optional argument (may be empty array) is an array of specific UTXOs to spend.

Arguments:
1. from                    (string, required) The defi address which has tokens
2. amount                  (string, required) Liquidity amount@Liquidity pool symbol
3. inputs                  (json array, optional) A json array of json objects
     [
       {                   (json object)
         "txid": "hex",    (string, required) The transaction id
         "vout": n,        (numeric, required) The output number
       },
       ...
     ]

Result:
"hash"                  (string) The hex-encoded hash of broadcasted transaction

Examples:
> defi-cli removepoolliquidity from_address amount [] > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "removepoolliquidity", "params": [from_address amount []] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

poolswap

( {"from":"str","tokenFrom":"str","amountFrom":n,"to":"str","tokenTo":"str","maxPrice":n} [{"txid":"hex","vout":n},...] )

Creates (and submits to local node and network) a poolswap transaction with given metadata. The second optional argument (may be empty array) is an array of specific UTXOs to spend.

Arguments:
1. metadata                   (json object)
     {
       "from": "str",         (string, required) Address of the owner of tokenA.
       "tokenFrom": "str",    (string, required) One of the keys may be specified (id/symbol)
       "amountFrom": n,       (numeric, required) tokenFrom coins amount
       "to": "str",           (string, required) Address of the owner of tokenB.
       "tokenTo": "str",      (string, required) One of the keys may be specified (id/symbol)
       "maxPrice": n,         (numeric) Maximum acceptable price
     }
2. inputs                     (json array, optional) A json array of json objects
     [
       {                      (json object)
         "txid": "hex",       (string, required) The transaction id
         "vout": n,           (numeric, required) The output number
       },
       ...
     ]

Result:
"hash"                  (string) The hex-encoded hash of broadcasted transaction

Examples:
> defi-cli poolswap "{\"from\":\"MyAddress\",\"tokenFrom\":\"MyToken1\",\"amountFrom\":\"0.001\",\"to\":\"Address\",\"tokenTo\":\"Token2\",\"maxPrice\":\"0.01\"}" "[{\"txid\":\"id\",\"vout\":0}]"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "poolswap", "params": ["{\"from\":\"MyAddress\",\"tokenFrom\":\"MyToken1\",\"amountFrom\":\"0.001\",\"to\":\"Address\",\"tokenTo\":\"Token2\",\"maxPrice\":\"0.01\"}" "[{\"txid\":\"id\",\"vout\":0}]" ] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

testpoolswap

( {"from":"str","tokenFrom":"str","amountFrom":n,"to":"str","tokenTo":"str","maxPrice":n} [{"txid":"hex","vout":n},...] )

Tests a poolswap transaction with given metadata and returns poolswap result.

Arguments:
1. metadata                   (json object)
     {
       "from": "str",         (string, required) Address of the owner of tokenA.
       "tokenFrom": "str",    (string, required) One of the keys may be specified (id/symbol)
       "amountFrom": n,       (numeric, required) tokenFrom coins amount
       "to": "str",           (string, required) Address of the owner of tokenB.
       "tokenTo": "str",      (string, required) One of the keys may be specified (id/symbol)
       "maxPrice": n,         (numeric) Maximum acceptable price
     }

Result:
"amount@tokenId"    (string) The string with amount result of poolswap in format AMOUNT@TOKENID.

Examples:
> defi-cli testpoolswap "{\"from\":\"MyAddress\",\"tokenFrom\":\"MyToken1\",\"amountFrom\":\"0.001\",\"to\":\"Address\",\"tokenTo\":\"Token2\",\"maxPrice\":\"0.01\"}"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "testpoolswap", "params": ["{\"from\":\"MyAddress\",\"tokenFrom\":\"MyToken1\",\"amountFrom\":\"0.001\",\"to\":\"Address\",\"tokenTo\":\"Token2\",\"maxPrice\":\"0.01\"}"] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

listpoolshares

( {"start":n,"including_start":bool,"limit":n} verbose )

Returns information about pool shares.

Arguments:
1. pagination                      (json object)
     {
       "start": n,                 (numeric) Optional first key to iterate from, in lexicographical order.
       "including_start": bool,    (boolean) If true, then iterate including starting position. False by default
       "limit": n,                 (numeric) Maximum number of pools to return, 100 by default
     }
2. verbose                         (boolean) Flag for verbose list (default = true), otherwise only % are shown.

Result:
{id:{...},...}     (array) Json object with pools information

Examples:
> defi-cli listpoolshares {"start":128} False
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "listpoolshares", "params": [{"start":128} False] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

createpoolpair

( {"tokenA":"str","tokenB":"str","commission":n,"status":bool,"ownerAddress":"str","pairSymbol":"str"} [{"txid":"hex","vout":n},...] )

Creates (and submits to local node and network) a poolpair transaction with given metadata. The second optional argument (may be empty array) is an array of specific UTXOs to spend.

Arguments:
1. metadata                      (json object)
     {
       "tokenA": "str",          (string, required) One of the keys may be specified (id/symbol)
       "tokenB": "str",          (string, required) One of the keys may be specified (id/symbol)
       "commission": n,          (numeric, required) Pool commission, up to 10^-8
       "status": bool,           (boolean, required) Pool Status: True is Active, False is Restricted
       "ownerAddress": "str",    (string, required) Address of the pool owner.
       "pairSymbol": "str",      (string) Pair symbol (unique), no longer than 8
     }
2. inputs                        (json array, optional) A json array of json objects
     [
       {                         (json object)
         "txid": "hex",          (string, required) The transaction id
         "vout": n,              (numeric, required) The output number
       },
       ...
     ]

Result:
"hash"                  (string) The hex-encoded hash of broadcasted transaction

Examples:
> defi-cli createpoolpair "{\"tokenA\":\"MyToken1\",\"tokenB\":\"MyToken2\",\"commission\":\"0.001\",\"status\":\"True\",\"ownerAddress\":\"Address\"}" "[{\"txid\":\"id\",\"vout\":0}]"
> curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "createpoolpair", "params": ["{\"tokenA\":\"MyToken1\",\"tokenB\":\"MyToken2\",\"commission\":\"0.001\",\"status\":\"True\",\"ownerAddress\":\"Address\"}" "[{\"txid\":\"id\",\"vout\":0}]" ] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/

updatepoolpair

( {"pool":"str","status":bool,"commission":n,"ownerAddress":"str"} [{"txid":"hex","vout":n},...] )

Creates (and submits to local node and network) a pool status update transaction. The second optional argument (may be empty array) is an array of specific UTXOs to spend. One of UTXO's must belong to the pool's owner (collateral) address

Arguments:
1. metadata                      (json object)
     {
       "pool": "str",            (string, required) The pool's symbol, id or creation tx
       "status": bool,           (boolean) Pool Status new property (bool)
       "commission": n,          (numeric) Pool commission, up to 10^-8
       "ownerAddress": "str",    (string) Address of the pool owner.
     }
2. inputs                        (json array, optional) A json array of json objects
     [
       {                         (json object)
         "txid": "hex",          (string, required) The transaction id
         "vout": n,              (numeric, required) The output number
       },
       ...
     ]

Result:
"hash"                  (string) The hex-encoded hash of broadcasted transaction

Examples:
> defi-cli updatepoolpair "{"pool":"POOL","status":true,"commission":0.01,"ownerAddress":"Address"}" "[{"txid":"id","vout":0}]" > curl --user myusername --data-binary '{"jsonrpc": "1.0", "id":"curltest", "method": "updatepoolpair", "params": ["{"pool":"POOL","status":true,"commission":0.01,"ownerAddress":"Address"}" "[{"txid":"id","vout":0}]"] }' -H 'content-type: text/plain;' http://127.0.0.1:8554/