diff --git a/docs/node/CATEGORIES/16-loan.md b/docs/node/CATEGORIES/16-loan.md index 6a460bf319..a52610426c 100644 --- a/docs/node/CATEGORIES/16-loan.md +++ b/docs/node/CATEGORIES/16-loan.md @@ -450,6 +450,12 @@ interface VaultLiquidationBatch { index: number collaterals: string[] loan: string + highestBid?: HighestBid +} + +interface HighestBid { + amount: string // amount@symbol + owner: string } ``` @@ -499,6 +505,12 @@ interface VaultLiquidationBatch { index: number collaterals: string[] loan: string + highestBid?: HighestBid +} + +interface HighestBid { + amount: string // amount@symbol + owner: string } interface ListVaultOptions { @@ -682,6 +694,12 @@ interface VaultLiquidationBatch { index: number collaterals: string[] loan: string + highestBid?: HighestBid +} + +interface HighestBid { + amount: string // amount@symbol + owner: string } ``` ## listAuctionHistory diff --git a/packages/jellyfish-api-core/__tests__/category/loan/getVault.test.ts b/packages/jellyfish-api-core/__tests__/category/loan/getVault.test.ts index c51322c317..5274cc4c3c 100644 --- a/packages/jellyfish-api-core/__tests__/category/loan/getVault.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/loan/getVault.test.ts @@ -185,10 +185,15 @@ describe('Loan getVault', () => { await testing.generate(12) // Wait for 12 blocks which are equivalent to 2 hours (1 block = 10 minutes) in order to liquidate the vault // get auction details - const auctionDetails: [] = await testing.container.call('listauctions') + await testing.rpc.account.sendTokensToAddress({}, { [collateralAddress]: ['40@TSLA'] }) + await testing.generate(1) + + const txid = await testing.container.call('placeauctionbid', [vaultId, 0, collateralAddress, '40@TSLA']) + expect(typeof txid).toStrictEqual('string') + expect(txid.length).toStrictEqual(64) + await testing.generate(1) const vaultDataAfterPriceHike = await testing.rpc.loan.getVault(vaultId) - console.log(vaultDataAfterPriceHike) expect(vaultDataAfterPriceHike).toStrictEqual({ vaultId: vaultId, loanSchemeId: 'default', // Get default loan scheme @@ -197,7 +202,28 @@ describe('Loan getVault', () => { liquidationHeight: 168, liquidationPenalty: 5, batchCount: 2, - batches: auctionDetails.filter((auction: { vaultId: string }) => auction.vaultId === vaultId).map((auction: { batches: [] }) => auction.batches)[0] + batches: [ + { + collaterals: [ + '6666.66660000@DFI', + '0.66666666@BTC' + ], + index: 0, + loan: '20.00004539@TSLA', + highestBid: { + amount: '40.00000000@TSLA', + owner: collateralAddress + } + }, + { + collaterals: [ + '3333.33340000@DFI', + '0.33333334@BTC' + ], + index: 1, + loan: '10.00002301@TSLA' + } + ] }) // set the price oracle back to original price diff --git a/packages/jellyfish-api-core/__tests__/category/loan/listAuctons.test.ts b/packages/jellyfish-api-core/__tests__/category/loan/listAuctons.test.ts index 428abc438b..413dae2a77 100644 --- a/packages/jellyfish-api-core/__tests__/category/loan/listAuctons.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/loan/listAuctons.test.ts @@ -8,12 +8,13 @@ describe('Loan listAuctions', () => { const testing = Testing.create(container) let vaultId1: string + let collateralAddress: string beforeAll(async () => { await testing.container.start() await testing.container.waitForWalletCoinbaseMaturity() - const collateralAddress = await testing.generateAddress() + collateralAddress = await testing.generateAddress() await testing.token.dfi({ address: collateralAddress, amount: 300000 @@ -142,7 +143,7 @@ describe('Loan listAuctions', () => { await testing.generate(1) // Vault 1 - vaultId1 = await testing.rpc.container.call('createvault', [await testing.generateAddress(), 'default']) + vaultId1 = await testing.rpc.container.call('createvault', [collateralAddress, 'default']) await testing.generate(1) await testing.container.call('deposittovault', [vaultId1, collateralAddress, '10000@DFI']) @@ -269,6 +270,14 @@ describe('Loan listAuctions', () => { const vault4 = await testing.rpc.loan.getVault(auction4.vaultId) expect(vault4.state).toStrictEqual('inLiquidation') } + + await testing.rpc.account.sendTokensToAddress({}, { [collateralAddress]: ['252@AAPL'] }) + await testing.generate(1) + + const txid = await testing.container.call('placeauctionbid', [vaultId1, 0, collateralAddress, '5252@AAPL']) + expect(typeof txid).toStrictEqual('string') + expect(txid.length).toStrictEqual(64) + await testing.generate(1) }) afterAll(async () => { @@ -295,7 +304,11 @@ describe('Loan listAuctions', () => { '0.33333333@BTC' ], index: 0, - loan: '5000.01992715@AAPL' + loan: '5000.01992715@AAPL', + highestBid: { + amount: '5252.00000000@AAPL', + owner: collateralAddress + } }, { collaterals: [ diff --git a/packages/jellyfish-api-core/__tests__/category/loan/listVaults.test.ts b/packages/jellyfish-api-core/__tests__/category/loan/listVaults.test.ts index 1e3808d266..28e3991edc 100644 --- a/packages/jellyfish-api-core/__tests__/category/loan/listVaults.test.ts +++ b/packages/jellyfish-api-core/__tests__/category/loan/listVaults.test.ts @@ -209,6 +209,12 @@ describe('Loan listVaults with options and pagination', () => { }) await testing.generate(1) + await testing.token.mint({ + symbol: 'AAPL', + amount: 10 + }) + await testing.generate(1) + await testing.rpc.loan.setLoanToken({ symbol: 'GOOGL', fixedIntervalPriceId: 'GOOGL/USD' @@ -253,6 +259,14 @@ describe('Loan listVaults with options and pagination', () => { prices: [{ tokenAmount: '1000@AAPL', currency: 'USD' }] }) await testing.generate(12) // Wait for 12 blocks which are equivalent to 2 hours (1 block = 10 minutes) in order to liquidate the vault + + await testing.rpc.account.sendTokensToAddress({}, { [collateralAddress]: ['40@AAPL'] }) + await testing.generate(1) + + const txid = await testing.container.call('placeauctionbid', [vaultId4, 0, collateralAddress, '40@AAPL']) + expect(typeof txid).toStrictEqual('string') + expect(txid.length).toStrictEqual(64) + await testing.generate(1) }) afterAll(async () => { @@ -304,7 +318,17 @@ describe('Loan listVaults with options and pagination', () => { liquidationHeight: expect.any(Number), liquidationPenalty: expect.any(Number), batchCount: expect.any(Number), - batches: expect.any(Array) + batches: [ + { + collaterals: expect.any(Array), + highestBid: { + amount: expect.any(String), + owner: expect.any(String) + }, + index: expect.any(Number), + loan: expect.any(String) + } + ] } ])) }) @@ -543,7 +567,7 @@ describe('Loan listVaults with options and pagination', () => { ts, { prices: [{ tokenAmount: '800@GOOGL', currency: 'USD' }] } ) - await testing.generate(12) + await testing.container.waitForActivePrice('GOOGL/USD', '800') const liqVaults = await testing.rpc.loan.listVaults({}, { state: VaultState.IN_LIQUIDATION }) expect(liqVaults.length).toBeGreaterThan(0) diff --git a/packages/jellyfish-api-core/src/category/loan.ts b/packages/jellyfish-api-core/src/category/loan.ts index 5e1998af54..aaa89703c1 100644 --- a/packages/jellyfish-api-core/src/category/loan.ts +++ b/packages/jellyfish-api-core/src/category/loan.ts @@ -644,6 +644,12 @@ export interface VaultLiquidationBatch { index: number collaterals: string[] loan: string + highestBid?: HighestBid +} + +export interface HighestBid { + amount: string // amount@symbol + owner: string } export interface ListAuctionHistoryPagination {