Skip to content

Commit

Permalink
Add highestBid object to listVaults, getVault and listAuctions RPCs (#…
Browse files Browse the repository at this point in the history
…850)

* Add highestBid object to listVaults, getVault and listAuctions RPC

* Fix failed test
  • Loading branch information
jingyi2811 authored Nov 24, 2021
1 parent eb75d3a commit 2ba2c7f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 8 deletions.
18 changes: 18 additions & 0 deletions docs/node/CATEGORIES/16-loan.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ interface VaultLiquidationBatch {
index: number
collaterals: string[]
loan: string
highestBid?: HighestBid
}

interface HighestBid {
amount: string // amount@symbol
owner: string
}
```

Expand Down Expand Up @@ -499,6 +505,12 @@ interface VaultLiquidationBatch {
index: number
collaterals: string[]
loan: string
highestBid?: HighestBid
}

interface HighestBid {
amount: string // amount@symbol
owner: string
}

interface ListVaultOptions {
Expand Down Expand Up @@ -682,6 +694,12 @@ interface VaultLiquidationBatch {
index: number
collaterals: string[]
loan: string
highestBid?: HighestBid
}

interface HighestBid {
amount: string // amount@symbol
owner: string
}
```
## listAuctionHistory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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)
}
]
}
]))
})
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions packages/jellyfish-api-core/src/category/loan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2ba2c7f

Please sign in to comment.