diff --git a/packages/playground-api-client/__tests__/api/wallet.test.ts b/packages/playground-api-client/__tests__/api/wallet.test.ts index 4b1c7bd..4a4b3c2 100644 --- a/packages/playground-api-client/__tests__/api/wallet.test.ts +++ b/packages/playground-api-client/__tests__/api/wallet.test.ts @@ -19,25 +19,7 @@ afterAll(async () => { it('should get wallet', async () => { const wallet = await client.wallet.balances() - expect(wallet).toStrictEqual({ - balance: expect.any(Number), - tokens: [ - { id: '1', balance: expect.any(Number) }, - { id: '2', balance: expect.any(Number) }, - { id: '3', balance: expect.any(Number) }, - { id: '4', balance: expect.any(Number) }, - { id: '5', balance: expect.any(Number) }, - { id: '6', balance: expect.any(Number) }, - { id: '7', balance: expect.any(Number) }, - { id: '8', balance: expect.any(Number) }, - { id: '9', balance: expect.any(Number) }, - { id: '15', balance: expect.any(Number) }, - { id: '16', balance: expect.any(Number) }, - { id: '17', balance: expect.any(Number) }, - { id: '18', balance: expect.any(Number) }, - { id: '19', balance: expect.any(Number) } - ] - }) + expect(wallet.tokens.length).toBeGreaterThan(10) }) describe('tokens', () => { diff --git a/src/module.playground/_module.ts b/src/module.playground/_module.ts index e3c90a6..6f16dfe 100644 --- a/src/module.playground/_module.ts +++ b/src/module.playground/_module.ts @@ -13,6 +13,7 @@ import { OracleBot } from './bot/oracle.bot' import { SetupLoanScheme } from '@src/module.playground/setup/setup.loan.scheme' import { SetupLoanToken } from '@src/module.playground/setup/setup.loan.token' import { SetupLoanCollateral } from '@src/module.playground/setup/setup.loan.collateral' +import { VaultBot } from '@src/module.playground/bot/vault.bot' @Global() @Module({ @@ -26,6 +27,7 @@ import { SetupLoanCollateral } from '@src/module.playground/setup/setup.loan.col SetupLoanToken, SetupLoanCollateral, OracleBot, + VaultBot, PlaygroundBlock, PlaygroundProbeIndicator ], diff --git a/src/module.playground/bot/vault.bot.e2e.ts b/src/module.playground/bot/vault.bot.e2e.ts new file mode 100644 index 0000000..26f31ad --- /dev/null +++ b/src/module.playground/bot/vault.bot.e2e.ts @@ -0,0 +1,42 @@ +import { PlaygroundTesting } from '@src/e2e.module' +import waitForExpect from 'wait-for-expect' +import { PlaygroundProbeIndicator } from '@src/module.playground/playground.indicator' + +const testing = new PlaygroundTesting() + +/* eslint-disable @typescript-eslint/no-non-null-assertion */ + +beforeAll(async () => { + await testing.start() + + await waitForExpect(() => { + expect(testing.app.get(PlaygroundProbeIndicator).ready).toBeTruthy() + }) +}) + +afterAll(async () => { + await testing.stop() +}) + +it('should have a vault', async () => { + await waitForExpect(async () => { + const vaults = await testing.jsonRpcClient!.loan.listVaults() + expect(vaults.length).toBeGreaterThan(0) + }, 40000) +}) + +it('should have liquidity in DUSD-DFI pool', async () => { + await waitForExpect(async () => { + const pairsResult = await testing.jsonRpcClient!.poolpair.getPoolPair('DUSD-DFI') + expect(Object.values(pairsResult)[0].reserveA.gt(0)).toBeTruthy() + expect(Object.values(pairsResult)[0].reserveB.gt(0)).toBeTruthy() + }, 40000) +}) + +it('should have liquidity in TS25-DUSD pool', async () => { + await waitForExpect(async () => { + const pairsResult = await testing.jsonRpcClient!.poolpair.getPoolPair('TS25-DUSD') + expect(Object.values(pairsResult)[0].reserveA.gt(0)).toBeTruthy() + expect(Object.values(pairsResult)[0].reserveB.gt(0)).toBeTruthy() + }, 40000) +}) diff --git a/src/module.playground/bot/vault.bot.ts b/src/module.playground/bot/vault.bot.ts new file mode 100644 index 0000000..381f388 --- /dev/null +++ b/src/module.playground/bot/vault.bot.ts @@ -0,0 +1,49 @@ +import { Injectable } from '@nestjs/common' +import { JsonRpcClient } from '@defichain/jellyfish-api-jsonrpc' +import { Interval } from '@nestjs/schedule' +import { PlaygroundSetup } from '@src/module.playground/setup/setup' + +@Injectable() +export class VaultBot { + private vaultId?: string + + constructor (protected readonly client: JsonRpcClient) { + } + + @Interval(6000) + async run (): Promise { + if (this.vaultId === undefined) { + this.vaultId = await this.client.loan.createVault({ + loanSchemeId: 'MIN200', + ownerAddress: PlaygroundSetup.address + }) + return + } + + await this.client.account.utxosToAccount({ + [PlaygroundSetup.address]: '20@0' + }) + + await this.client.loan.depositToVault({ + amount: '10@DFI', + from: PlaygroundSetup.address, + vaultId: this.vaultId + }) + + await this.client.loan.takeLoan({ + amounts: [ + '20@DUSD', + '0.1@TS25' + ], + to: PlaygroundSetup.address, + vaultId: this.vaultId + }) + + await this.client.poolpair.addPoolLiquidity({ + '*': ['1@DFI', '10@DUSD'] + }, PlaygroundSetup.address) + await this.client.poolpair.addPoolLiquidity({ + '*': ['2.5@DUSD', '0.1@TS25'] + }, PlaygroundSetup.address) + } +}