Skip to content

Commit 1bb6cfd

Browse files
committed
feat: collateral price methods
Added isCollateralPriceUpdated and refreshCollateralPrice methods
1 parent 8d617c5 commit 1bb6cfd

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/services/LoanRequest.ts

+18
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ export default class LoanRequest extends BaseService implements LoanAPIInstance
7070
})
7171
}
7272

73+
public async isCollateralPriceUpdated(loanAddress: string): Promise<boolean> {
74+
return await this.apiRequest(
75+
`/request/iscollateralpriceupdated/${loanAddress}`,
76+
'getting isCollateralPriceUpdated',
77+
loanAddress
78+
)
79+
}
80+
81+
public async refreshCollateralPrice(loanAddress: string, walletAddress: string): Promise<Transaction> {
82+
return await this.apiRequest(
83+
'/request/refreshcollateralprice',
84+
'refreshCollateralPrice transaction',
85+
loanAddress,
86+
'post',
87+
{ loanAddress, caller: walletAddress }
88+
)
89+
}
90+
7391
public async getLoanData(loanAddress: string): Promise<LoanRequestModel> {
7492
BaseService.checkAddressChecksum(loanAddress)
7593

src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ export interface LoanAPIInstance {
4545
fund(loanAddress: string, lenderAddress: string, amount: number): Promise<Transaction>
4646
payback(loanAddress: string, borrowerAddress: string): Promise<Transaction>
4747
getMaxLoanAmountFromCollateral(collateralAmount: number, collateralType: string, moe: string): Promise<number>
48+
isCollateralPriceUpdated(loanAddress: string): Promise<boolean>
49+
refreshCollateralPrice(loanAddress: string, walletAddress: string): Promise<Transaction>
4850
getLoanData(loanAddress: string): Promise<LoanRequestModel>
4951
getAllAddresses(): Promise<string[]>
5052
getLoansByBorrower(borrowerAddress: string): Promise<string[]>

test/LoanRequest.test.ts

+14-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('LoanRequest test', () => {
1919
expect(data).toBeTruthy()
2020
})
2121

22-
it('Should load requests metadata from api', async () => {
22+
it('Should load requests getMaxLoanAmountFromCollateral from api', async () => {
2323
const data = await request.getMaxLoanAmountFromCollateral(2312, 'LEND', 'ETH')
2424
expect(data).toBeTruthy()
2525
})
@@ -29,6 +29,19 @@ describe('LoanRequest test', () => {
2929
expect(data).toBeTruthy()
3030
})
3131

32+
it('Should check isCollateralPriceUpdated via api', async () => {
33+
const data = await request.isCollateralPriceUpdated('0x71f4CF5Cfb74a9D3c9060aC4c25070F989cFC39C')
34+
expect(data).toBeTruthy()
35+
})
36+
37+
it('Should get refreshCollateralPrice transaction via api', async () => {
38+
const data = await request.refreshCollateralPrice(
39+
'0x71f4CF5Cfb74a9D3c9060aC4c25070F989cFC39C',
40+
'0x4206925f7652a5af8a0F48aB714ABbd1EF27D916'
41+
)
42+
expect(data).toBeTruthy()
43+
})
44+
3245
it('Should get all loans by borrower data from api', async () => {
3346
const data = await request.getLoansByBorrower('0x4206925f7652a5af8a0F48aB714ABbd1EF27D916')
3447
expect(data).toBeTruthy()

0 commit comments

Comments
 (0)