Skip to content

Commit 9ae8aa4

Browse files
authored
poolpair.listpoolpairs, poolpair.getpoolpair, poolpair.listpoolshares, poolpair.createpoolpair, poolpair.addpoolliquidity (#121)
1 parent 554b629 commit 9ae8aa4

File tree

8 files changed

+834
-34
lines changed

8 files changed

+834
-34
lines changed

packages/jellyfish-api-core/__tests__/category/poolpair.test.ts

Lines changed: 452 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
import BigNumber from 'bignumber.js'
2+
import { ApiClient } from '..'
3+
4+
/**
5+
* PoolPair related RPC calls for DeFiChain
6+
*/
7+
export class PoolPair {
8+
private readonly client: ApiClient
9+
10+
constructor (client: ApiClient) {
11+
this.client = client
12+
}
13+
14+
/**
15+
* Create a poolpair with given metadata
16+
*
17+
* @param {CreatePoolPairMetadata} metadata a data providing information for pool pair creation
18+
* @param {string} metadata.tokenA uses to trade to obtain tokenB
19+
* @param {string} metadata.tokenB
20+
* @param {number} metadata.commission
21+
* @param {boolean} metadata.status
22+
* @param {string} metadata.ownerAddress
23+
* @param {string} [metadata.customRewards]
24+
* @param {string} [metadata.pairSymbol]
25+
* @param {CreatePoolPairUTXO[]} utxos is an array of specific UTXOs to spend
26+
* @param {string} utxos.txid
27+
* @param {number} utxos.vout
28+
* @return {Promise<string>}
29+
*/
30+
async createPoolPair (metadata: CreatePoolPairMetadata, utxos: CreatePoolPairUTXO[] = []): Promise<string> {
31+
return await this.client.call('createpoolpair', [metadata, utxos], 'number')
32+
}
33+
34+
/**
35+
* Returns information about pools
36+
*
37+
* @param {PoolPairPagination} pagination
38+
* @param {number} pagination.start default is 0
39+
* @param {boolean} pagination.including_start default = true
40+
* @param {number} pagination.limit to limit number of records
41+
* @param {boolean} verbose default = true, otherwise only symbol, name, status, idTokena, idTokenB
42+
* @return {Promise<PoolPairResult>}
43+
*/
44+
async listPoolPairs (
45+
pagination: PoolPairPagination = {
46+
start: 0,
47+
including_start: true,
48+
limit: 100
49+
},
50+
verbose = true
51+
): Promise<PoolPairResult> {
52+
return await this.client.call('listpoolpairs', [pagination, verbose], 'bignumber')
53+
}
54+
55+
/**
56+
* Returns information about pool
57+
*
58+
* @param {string} symbol token's symbol
59+
* @param {boolean} verbose default = true, otherwise only symbol, name, status, idTokena, idTokenB
60+
* @return {Promise<PoolPairResult>}
61+
*/
62+
async getPoolPair (symbol: string, verbose = true): Promise<PoolPairResult> {
63+
return await this.client.call('getpoolpair', [symbol, verbose], 'bignumber')
64+
}
65+
66+
/**
67+
* Add pool liquidity transaction
68+
*
69+
* @param {AddPoolLiquiditySource} from pool liquidity sources
70+
* @param {string | string[]} from[address] provides at least two types of token with format 'amoun@token'
71+
* @param {string} shareAddress defi address for crediting tokens
72+
* @param {AddPoolLiquidityOptions} [options]
73+
* @param {AddPoolLiquidityUTXO[]} [options.utxos] utxos array of specific UTXOs to spend
74+
* @param {string} [options.utxos.txid]
75+
* @param {number} [options.utxos.vout]
76+
* @return {Promise<string>}
77+
*/
78+
async addPoolLiquidity (from: AddPoolLiquiditySource, shareAddress: string, options: AddPoolLiquidityOptions = {}): Promise<string> {
79+
const { utxos } = options
80+
return await this.client.call('addpoolliquidity', [from, shareAddress, utxos], 'bignumber')
81+
}
82+
83+
/**
84+
* Returns information about pool shares
85+
*
86+
* @param {PoolPairPagination} pagination
87+
* @param {number} pagination.start default is 0
88+
* @param {boolean} pagination.including_start default = true
89+
* @param {number} pagination.limit to limit number of records
90+
* @param {boolean} verbose default = true, otherwise only poolID, owner and %
91+
* @param {PoolShareOptions} [options]
92+
* @param {boolean} [options.isMineOnly=true]
93+
* @return {Promise<PoolShareResult>}
94+
*/
95+
async listPoolShares (
96+
pagination: PoolPairPagination = {
97+
start: 0,
98+
including_start: true,
99+
limit: 100
100+
},
101+
verbose = true,
102+
options: PoolShareOptions = {}
103+
): Promise<PoolShareResult> {
104+
const { isMineOnly = true } = options
105+
return await this.client.call('listpoolshares', [pagination, verbose, isMineOnly], 'bignumber')
106+
}
107+
}
108+
109+
export interface CreatePoolPairMetadata {
110+
tokenA: string
111+
tokenB: string
112+
commission: number
113+
status: boolean
114+
ownerAddress: string
115+
customRewards?: string
116+
pairSymbol?: string
117+
}
118+
119+
export interface CreatePoolPairUTXO {
120+
txid: string
121+
vout: number
122+
}
123+
124+
export interface PoolPairResult {
125+
[id: string]: PoolPairInfo
126+
}
127+
128+
export interface PoolPairInfo {
129+
symbol: string
130+
name: string
131+
status: string
132+
idTokenA: string
133+
idTokenB: string
134+
reserveA: BigNumber
135+
reserveB: BigNumber
136+
commission: BigNumber
137+
totalLiquidity: BigNumber
138+
['reserveA/reserveB']: BigNumber | string
139+
['reserveB/reserveA']: BigNumber | string
140+
tradeEnabled: boolean
141+
ownerAddress: string
142+
blockCommissionA: BigNumber
143+
blockCommissionB: BigNumber
144+
rewardPct: BigNumber
145+
customRewards: BigNumber
146+
creationTx: string
147+
creationHeight: BigNumber
148+
}
149+
export interface PoolShareResult {
150+
[id: string]: PoolShareInfo
151+
}
152+
153+
interface PoolShareInfo {
154+
poolID: string
155+
owner: string
156+
['%']: BigNumber
157+
amount: BigNumber
158+
totalLiquidity: BigNumber
159+
}
160+
161+
export interface PoolPairPagination {
162+
start: number
163+
including_start: boolean
164+
limit: number
165+
}
166+
167+
export interface AddPoolLiquiditySource {
168+
[address: string]: string | string[]
169+
}
170+
171+
export interface AddPoolLiquidityOptions {
172+
utxos?: AddPoolLiquidityUTXO[]
173+
}
174+
175+
export interface AddPoolLiquidityUTXO {
176+
txid: string
177+
vout: number
178+
}
179+
180+
export interface PoolShareOptions {
181+
isMineOnly?: boolean
182+
}

packages/jellyfish-api-core/src/category/rawtx.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export class RawTx {
2525
*
2626
* @param {CreateRawTxIn[]} inputs array of inputs
2727
* @param {CreateRawTxOut[]} outputs array with outputs
28-
* @param {CreateRawTxOptions=} options
29-
* @param {number=} options.locktime Non-0 value also locktime-activates inputs
30-
* @param {boolean=} options.replaceable Marks this transaction as BIP125-replaceable
28+
* @param {CreateRawTxOptions} [options]
29+
* @param {number} [options.locktime] Non-0 value also locktime-activates inputs
30+
* @param {boolean} [options.replaceable] Marks this transaction as BIP125-replaceable
3131
* @return {Promise<string>} hex string of the transaction
3232
*/
3333
async createRawTransaction (
@@ -49,9 +49,9 @@ export class RawTx {
4949
*
5050
* @param {string} rawTx unsigned raw transaction
5151
* @param {string[]} privKeys array of base58-encoded private keys for signing (WIF)
52-
* @param {SignRawTxWithKeyOptions=} options
53-
* @param {SigHashType=} options.sigHashType the signature hash type to use
54-
* @param {SignRawTxWithKeyPrevTx[]=} options.prevTxs array of previous dependent transaction outputs
52+
* @param {SignRawTxWithKeyOption} [options]
53+
* @param {SigHashType} [options.sigHashType] the signature hash type to use
54+
* @param {SignRawTxWithKeyPrevTx[]} [options.prevTxs] array of previous dependent transaction outputs
5555
* @return {Promise<SignRawTxWithKeyResult>}
5656
*/
5757
async signRawTransactionWithKey (

packages/jellyfish-api-core/src/category/token.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ export class Token {
3838
* Updates a token with given metadata
3939
*
4040
* @param {string} token symbolKey, id ror creation tx
41-
* @param {UpdateTokenMetadata=} metadata
42-
* @param {string=} metadata.symbol
43-
* @param {string=} metadata.name
44-
* @param {boolean=} metadata.isDAT
45-
* @param {boolean=} metadata.mintable
46-
* @param {boolean=} metadata.tradeable
47-
* @param {boolean=} metadata.finalize
41+
* @param {UpdateTokenMetadata} [metadata]
42+
* @param {string} [metadata.symbol]
43+
* @param {string} [metadata.name]
44+
* @param {boolean} [metadata.isDAT]
45+
* @param {boolean} [metadata.mintable]
46+
* @param {boolean} [metadata.tradeable]
47+
* @param {boolean} [metadata.finalize]
4848
* @return {Promise<string>}
4949
*/
5050
async updateToken (token: string, metadata?: UpdateTokenMetadata): Promise<string> {

packages/jellyfish-api-core/src/category/wallet.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ export class Wallet {
5353
*
5454
* @param {number} minimumConfirmation default = 1, to filter
5555
* @param {number} maximumConfirmation default = 9999999, to filter
56-
* @param {ListUnspentOptions=} options
57-
* @param {string[]=} options.addresses to filter
58-
* @param {boolean=} options.includeUnsafe default = true, include outputs that are not safe to spend
59-
* @param {ListUnspentQueryOptions=} options.queryOptions
60-
* @param {number=} options.queryOptions.minimumAmount default = 0, minimum value of each UTXO
61-
* @param {number=} options.queryOptions.maximumAmount default is 'unlimited', maximum value of each UTXO
62-
* @param {number=} options.queryOptions.maximumCount default is 'unlimited', maximum number of UTXOs
63-
* @param {number=} options.queryOptions.minimumSumAmount default is 'unlimited', minimum sum valie of all UTXOs
64-
* @param {string=} options.queryOptions.tokenId default is 'all', filter by token
56+
* @param {ListUnspentOptions} [options]
57+
* @param {string[]} [options.addresses] to filter
58+
* @param {boolean} [options.includeUnsafe=true] default = true, include outputs that are not safe to spend
59+
* @param {ListUnspentQueryOptions} [options.queryOptions]
60+
* @param {number} [options.queryOptions.minimumAmount] default = 0, minimum value of each UTXO
61+
* @param {number} [options.queryOptions.maximumAmount] default is 'unlimited', maximum value of each UTXO
62+
* @param {number} [options.queryOptions.maximumCount] default is 'unlimited', maximum number of UTXOs
63+
* @param {number} [options.queryOptions.minimumSumAmount] default is 'unlimited', minimum sum valie of all UTXOs
64+
* @param {string} [options.queryOptions.tokenId] default is 'all', filter by token
6565
* @return {Promise<UTXO[]>}
6666
*/
6767
async listUnspent (
@@ -86,10 +86,10 @@ export class Wallet {
8686
*
8787
* @param {string} walletName
8888
* @param {boolean} disablePrivateKeys
89-
* @param {CreateWalletOptions=} options
90-
* @param {boolean=} options.blank
91-
* @param {string=} options.passphrase
92-
* @param {boolean=} options.avoidReuse
89+
* @param {CreateWalletOptions} [options]
90+
* @param {boolean} [options.blank]
91+
* @param {string} [options.passphrase]
92+
* @param {boolean} [options.avoidReuse]
9393
* @return {Promise<CreateWalletResult>}
9494
*/
9595
async createWallet (
@@ -169,14 +169,14 @@ export class Wallet {
169169
*
170170
* @param {string} address
171171
* @param {number} amount
172-
* @param {SendToAddressOptions=} options
173-
* @param {string=} options.comment
174-
* @param {string=} options.commentTo
175-
* @param {boolean=} options.subtractFeeFromAmount
176-
* @param {boolean=} options.replaceable
177-
* @param {number=} options.confTarget
178-
* @param {Mode=} options.estimateMode
179-
* @param {boolean=} options.avoidReuse
172+
* @param {SendToAddressOptions} [options]
173+
* @param {string} [options.comment]
174+
* @param {string} [options.commentTo]
175+
* @param {boolean} [options.subtractFeeFromAmount]
176+
* @param {boolean} [options.replaceable]
177+
* @param {number} [options.confTarget]
178+
* @param {Mode} [options.estimateMode]
179+
* @param {boolean} [options.avoidReuse]
180180
* @return {Promise<string>}
181181
*/
182182
async sendToAddress (

packages/jellyfish-api-core/src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { Blockchain } from './category/blockchain'
33
import { Mining } from './category/mining'
44
import { RawTx } from './category/rawtx'
55
import { Wallet } from './category/wallet'
6+
import { PoolPair } from './category/poolpair'
67
import { Token } from './category/token'
78

89
export * from '@defichain/jellyfish-json'
910
export * from './category/blockchain'
1011
export * from './category/mining'
1112
export * as rawtx from './category/rawtx'
1213
export * from './category/wallet'
14+
export * from './category/poolpair'
1315
export * from './category/token'
1416

1517
/**
@@ -20,6 +22,7 @@ export abstract class ApiClient {
2022
public readonly mining = new Mining(this)
2123
public readonly rawtx = new RawTx(this)
2224
public readonly wallet = new Wallet(this)
25+
public readonly poolpair = new PoolPair(this)
2326
public readonly token = new Token(this)
2427

2528
/**

0 commit comments

Comments
 (0)