Skip to content

Commit

Permalink
feat(apps/playground): add new poolpair for BTC-USDT (#1345)
Browse files Browse the repository at this point in the history
* feat(apps/playground): add new poolpair for BTC-USDT

* update numbers

* update tests

* fix failing tests

* update tests
  • Loading branch information
thedoublejay authored Apr 13, 2022
1 parent b8e0de9 commit 868b4b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ afterAll(async () => {

it('should have pool pairs setup', async () => {
const pairs = await testing.container.call('listpoolpairs')
expect(Object.values(pairs).length).toBe(14)
expect(Object.values(pairs).length).toBe(15)
})

it('should have tokens setup', async () => {
const tokens = await testing.container.call('listtokens')
expect(Object.values(tokens).length).toBe(31)
expect(Object.values(tokens).length).toBe(32)
})

it('should have oracles setup', async () => {
Expand Down
21 changes: 17 additions & 4 deletions apps/playground-api/src/setups/setup.dex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ export class SetupDex extends PlaygroundSetup<PoolPairSetup> {
add: {
'*': ['100000@CU10', '1000@DUSD']
}
},
{
symbol: 'BTC-USDT',
create: {
tokenA: 'BTC',
tokenB: 'USDT',
commission: 0.01,
status: true,
ownerAddress: PlaygroundSetup.address
},
add: {
'*': ['1000@BTC', '10000000@USDT']
}
}
]
}
Expand Down Expand Up @@ -240,18 +253,18 @@ export class SetupDex extends PlaygroundSetup<PoolPairSetup> {
const poolPairs = await this.client.poolpair.listPoolPairs()
const poolPairIds = Object.keys(poolPairs)

// apply `toFixed(8)` due to 1 / 14 = 0.07142857 which is invalid amount on setgov
// apply `toFixed(8)` due to 1 / 15 = 0.06666667 which is invalid amount on setgov
const splits = Number(new BigNumber(1 / poolPairIds.length).toFixed(8))

const lpSplits: any = {}
for (const k in poolPairs) {
lpSplits[parseInt(k)] = splits
}

// to fix: LP_SPLITS: total = 99999998 vs expected 100000000', code: -32600, method: setgov
// 0.07142857 * 14 !== 100000000
// to fix: LP_SPLITS: total = 100000005 vs expected 100000000', code: -32600, method: setgov
// 0.066666667 * 15 !== 100000000
const lstKey = Object.keys(lpSplits)[0]
lpSplits[lstKey] = Number(new BigNumber(lpSplits[lstKey]).plus(0.00000002).toFixed(8))
lpSplits[lstKey] = Number(new BigNumber(lpSplits[lstKey]).minus(0.00000005).toFixed(8))

await this.client.masternode.setGov({ LP_SPLITS: lpSplits })
await this.generate(1)
Expand Down

0 comments on commit 868b4b0

Please sign in to comment.