Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

poolpair.listpoolpairs, poolpair.getpoolpair, poolpair.listpoolshares, poolpair.createpoolpair, poolpair.addpoolliquidity #121

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
452 changes: 452 additions & 0 deletions packages/jellyfish-api-core/__tests__/category/poolpair.test.ts

Large diffs are not rendered by default.

182 changes: 182 additions & 0 deletions packages/jellyfish-api-core/src/category/poolpair.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import BigNumber from 'bignumber.js'
import { ApiClient } from '..'

/**
* PoolPair related RPC calls for DeFiChain
*/
export class PoolPair {
private readonly client: ApiClient

constructor (client: ApiClient) {
this.client = client
}

/**
* Create a poolpair with given metadata
*
* @param {CreatePoolPairMetadata} metadata a data providing information for pool pair creation
* @param {string} metadata.tokenA uses to trade to obtain tokenB
* @param {string} metadata.tokenB
* @param {number} metadata.commission
* @param {boolean} metadata.status
* @param {string} metadata.ownerAddress
* @param {string} [metadata.customRewards]
* @param {string} [metadata.pairSymbol]
* @param {CreatePoolPairUTXO[]} utxos is an array of specific UTXOs to spend
* @param {string} utxos.txid
* @param {number} utxos.vout
* @return {Promise<string>}
*/
async createPoolPair (metadata: CreatePoolPairMetadata, utxos: CreatePoolPairUTXO[] = []): Promise<string> {
return await this.client.call('createpoolpair', [metadata, utxos], 'number')
}

/**
* Returns information about pools
*
* @param {PoolPairPagination} pagination
* @param {number} pagination.start default is 0
* @param {boolean} pagination.including_start default = true
* @param {number} pagination.limit to limit number of records
* @param {boolean} verbose default = true, otherwise only symbol, name, status, idTokena, idTokenB
* @return {Promise<PoolPairResult>}
*/
async listPoolPairs (
pagination: PoolPairPagination = {
start: 0,
including_start: true,
limit: 100
},
verbose = true
): Promise<PoolPairResult> {
return await this.client.call('listpoolpairs', [pagination, verbose], 'bignumber')
}

/**
* Returns information about pool
*
* @param {string} symbol token's symbol
* @param {boolean} verbose default = true, otherwise only symbol, name, status, idTokena, idTokenB
* @return {Promise<PoolPairResult>}
*/
async getPoolPair (symbol: string, verbose = true): Promise<PoolPairResult> {
return await this.client.call('getpoolpair', [symbol, verbose], 'bignumber')
}

/**
* Add pool liquidity transaction
*
* @param {AddPoolLiquiditySource} from pool liquidity sources
* @param {string | string[]} from[address] provides at least two types of token with format 'amoun@token'
* @param {string} shareAddress defi address for crediting tokens
* @param {AddPoolLiquidityOptions} [options]
* @param {AddPoolLiquidityUTXO[]} [options.utxos] utxos array of specific UTXOs to spend
* @param {string} [options.utxos.txid]
* @param {number} [options.utxos.vout]
* @return {Promise<string>}
*/
async addPoolLiquidity (from: AddPoolLiquiditySource, shareAddress: string, options: AddPoolLiquidityOptions = {}): Promise<string> {
const { utxos } = options
return await this.client.call('addpoolliquidity', [from, shareAddress, utxos], 'bignumber')
}

/**
* Returns information about pool shares
*
* @param {PoolPairPagination} pagination
* @param {number} pagination.start default is 0
* @param {boolean} pagination.including_start default = true
* @param {number} pagination.limit to limit number of records
* @param {boolean} verbose default = true, otherwise only poolID, owner and %
* @param {PoolShareOptions} [options]
* @param {boolean} [options.isMineOnly=true]
* @return {Promise<PoolShareResult>}
*/
async listPoolShares (
pagination: PoolPairPagination = {
start: 0,
including_start: true,
limit: 100
},
verbose = true,
options: PoolShareOptions = {}
): Promise<PoolShareResult> {
const { isMineOnly = true } = options
return await this.client.call('listpoolshares', [pagination, verbose, isMineOnly], 'bignumber')
}
}

export interface CreatePoolPairMetadata {
tokenA: string
tokenB: string
commission: number
status: boolean
ownerAddress: string
customRewards?: string
pairSymbol?: string
}

export interface CreatePoolPairUTXO {
txid: string
vout: number
}

export interface PoolPairResult {
[id: string]: PoolPairInfo
}

export interface PoolPairInfo {
symbol: string
name: string
status: string
idTokenA: string
idTokenB: string
reserveA: BigNumber
reserveB: BigNumber
commission: BigNumber
totalLiquidity: BigNumber
['reserveA/reserveB']: BigNumber | string
['reserveB/reserveA']: BigNumber | string
tradeEnabled: boolean
ownerAddress: string
blockCommissionA: BigNumber
blockCommissionB: BigNumber
rewardPct: BigNumber
customRewards: BigNumber
creationTx: string
creationHeight: BigNumber
}
export interface PoolShareResult {
[id: string]: PoolShareInfo
}

interface PoolShareInfo {
poolID: string
owner: string
['%']: BigNumber
amount: BigNumber
totalLiquidity: BigNumber
}

export interface PoolPairPagination {
start: number
including_start: boolean
limit: number
}

export interface AddPoolLiquiditySource {
[address: string]: string | string[]
}

export interface AddPoolLiquidityOptions {
utxos?: AddPoolLiquidityUTXO[]
}

export interface AddPoolLiquidityUTXO {
txid: string
vout: number
}

export interface PoolShareOptions {
isMineOnly?: boolean
}
12 changes: 6 additions & 6 deletions packages/jellyfish-api-core/src/category/rawtx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export class RawTx {
*
* @param {CreateRawTxIn[]} inputs array of inputs
* @param {CreateRawTxOut[]} outputs array with outputs
* @param {CreateRawTxOptions=} options
* @param {number=} options.locktime Non-0 value also locktime-activates inputs
* @param {boolean=} options.replaceable Marks this transaction as BIP125-replaceable
* @param {CreateRawTxOptions} [options]
* @param {number} [options.locktime] Non-0 value also locktime-activates inputs
* @param {boolean} [options.replaceable] Marks this transaction as BIP125-replaceable
* @return {Promise<string>} hex string of the transaction
*/
async createRawTransaction (
Expand All @@ -49,9 +49,9 @@ export class RawTx {
*
* @param {string} rawTx unsigned raw transaction
* @param {string[]} privKeys array of base58-encoded private keys for signing (WIF)
* @param {SignRawTxWithKeyOptions=} options
* @param {SigHashType=} options.sigHashType the signature hash type to use
* @param {SignRawTxWithKeyPrevTx[]=} options.prevTxs array of previous dependent transaction outputs
* @param {SignRawTxWithKeyOption} [options]
* @param {SigHashType} [options.sigHashType] the signature hash type to use
* @param {SignRawTxWithKeyPrevTx[]} [options.prevTxs] array of previous dependent transaction outputs
* @return {Promise<SignRawTxWithKeyResult>}
*/
async signRawTransactionWithKey (
Expand Down
14 changes: 7 additions & 7 deletions packages/jellyfish-api-core/src/category/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ export class Token {
* Updates a token with given metadata
*
* @param {string} token symbolKey, id ror creation tx
* @param {UpdateTokenMetadata=} metadata
* @param {string=} metadata.symbol
* @param {string=} metadata.name
* @param {boolean=} metadata.isDAT
* @param {boolean=} metadata.mintable
* @param {boolean=} metadata.tradeable
* @param {boolean=} metadata.finalize
* @param {UpdateTokenMetadata} [metadata]
* @param {string} [metadata.symbol]
* @param {string} [metadata.name]
* @param {boolean} [metadata.isDAT]
* @param {boolean} [metadata.mintable]
* @param {boolean} [metadata.tradeable]
* @param {boolean} [metadata.finalize]
* @return {Promise<string>}
*/
async updateToken (token: string, metadata?: UpdateTokenMetadata): Promise<string> {
Expand Down
42 changes: 21 additions & 21 deletions packages/jellyfish-api-core/src/category/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export class Wallet {
*
* @param {number} minimumConfirmation default = 1, to filter
* @param {number} maximumConfirmation default = 9999999, to filter
* @param {ListUnspentOptions=} options
* @param {string[]=} options.addresses to filter
* @param {boolean=} options.includeUnsafe default = true, include outputs that are not safe to spend
* @param {ListUnspentQueryOptions=} options.queryOptions
* @param {number=} options.queryOptions.minimumAmount default = 0, minimum value of each UTXO
* @param {number=} options.queryOptions.maximumAmount default is 'unlimited', maximum value of each UTXO
* @param {number=} options.queryOptions.maximumCount default is 'unlimited', maximum number of UTXOs
* @param {number=} options.queryOptions.minimumSumAmount default is 'unlimited', minimum sum valie of all UTXOs
* @param {string=} options.queryOptions.tokenId default is 'all', filter by token
* @param {ListUnspentOptions} [options]
* @param {string[]} [options.addresses] to filter
* @param {boolean} [options.includeUnsafe=true] default = true, include outputs that are not safe to spend
* @param {ListUnspentQueryOptions} [options.queryOptions]
* @param {number} [options.queryOptions.minimumAmount] default = 0, minimum value of each UTXO
* @param {number} [options.queryOptions.maximumAmount] default is 'unlimited', maximum value of each UTXO
* @param {number} [options.queryOptions.maximumCount] default is 'unlimited', maximum number of UTXOs
* @param {number} [options.queryOptions.minimumSumAmount] default is 'unlimited', minimum sum valie of all UTXOs
* @param {string} [options.queryOptions.tokenId] default is 'all', filter by token
* @return {Promise<UTXO[]>}
*/
async listUnspent (
Expand All @@ -86,10 +86,10 @@ export class Wallet {
*
* @param {string} walletName
* @param {boolean} disablePrivateKeys
* @param {CreateWalletOptions=} options
* @param {boolean=} options.blank
* @param {string=} options.passphrase
* @param {boolean=} options.avoidReuse
* @param {CreateWalletOptions} [options]
* @param {boolean} [options.blank]
* @param {string} [options.passphrase]
* @param {boolean} [options.avoidReuse]
* @return {Promise<CreateWalletResult>}
*/
async createWallet (
Expand Down Expand Up @@ -169,14 +169,14 @@ export class Wallet {
*
* @param {string} address
* @param {number} amount
* @param {SendToAddressOptions=} options
* @param {string=} options.comment
* @param {string=} options.commentTo
* @param {boolean=} options.subtractFeeFromAmount
* @param {boolean=} options.replaceable
* @param {number=} options.confTarget
* @param {Mode=} options.estimateMode
* @param {boolean=} options.avoidReuse
* @param {SendToAddressOptions} [options]
* @param {string} [options.comment]
* @param {string} [options.commentTo]
* @param {boolean} [options.subtractFeeFromAmount]
* @param {boolean} [options.replaceable]
* @param {number} [options.confTarget]
* @param {Mode} [options.estimateMode]
* @param {boolean} [options.avoidReuse]
* @return {Promise<string>}
*/
async sendToAddress (
Expand Down
3 changes: 3 additions & 0 deletions packages/jellyfish-api-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { Blockchain } from './category/blockchain'
import { Mining } from './category/mining'
import { RawTx } from './category/rawtx'
import { Wallet } from './category/wallet'
import { PoolPair } from './category/poolpair'
import { Token } from './category/token'

export * from '@defichain/jellyfish-json'
export * from './category/blockchain'
export * from './category/mining'
export * as rawtx from './category/rawtx'
export * from './category/wallet'
export * from './category/poolpair'
export * from './category/token'

/**
Expand All @@ -20,6 +22,7 @@ export abstract class ApiClient {
public readonly mining = new Mining(this)
public readonly rawtx = new RawTx(this)
public readonly wallet = new Wallet(this)
public readonly poolpair = new PoolPair(this)
public readonly token = new Token(this)

/**
Expand Down
Loading