Skip to content

Commit

Permalink
Add Pool.getPoolBalance method
Browse files Browse the repository at this point in the history
  • Loading branch information
rigwild committed Aug 6, 2024
1 parent 033154e commit 1843bd3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ const nemeosPoolClient = nemeosSdk.getNemeosPoolClient({
})
```

#### Get Pool Balance

Retrieve the current balance of the pool smart contract in native token in wei (if balance is 1 ETH, will return `1000000000000000000`).

```ts
const poolBalance = await nemeosPoolClient.getPoolBalance()
console.log('Pool Balance:', poolBalance)
```

### Preview a loan

```ts
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nemeos-sdk",
"version": "0.1.6",
"version": "0.1.7",
"type": "module",
"description": "Nemeos SDK to facilitate integration with the Nemeos platform",
"license": "MIT",
Expand Down
5 changes: 5 additions & 0 deletions src/Pool/NemeosPoolClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export abstract class NemeosPoolClient {
this.poolContract = new ethers.Contract(nemeosPoolAddress, nemeosPoolInterface, signer)
}

public async getPoolBalance(): Promise<string> {
const balance = await this.signer.provider!.getBalance(this.nemeosPoolAddress)
return balance.toString()
}

public async retrieveLoan(nftId: string): Promise<Loan> {
const borrowerAddress = await this.signer.getAddress()

Expand Down
9 changes: 9 additions & 0 deletions tests/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,28 @@ async function main() {
nemeosPoolMode: NemeosSDK.NemeosPoolMode.BuyOpenSea,
})

const poolBalance = await nemeosPoolBuyOpenSeaClient.getPoolBalance()
console.log('Pool balance:', poolBalance)
console.log('Calling previewLoan...')
const loan1 = await nemeosPoolBuyOpenSeaClient.previewLoan(nftId1, loanDurationDays1)
console.dir(loan1, { depth: null })
console.log('Calling startLoan...')
await nemeosPoolBuyOpenSeaClient.startLoan(nftId1, loanDurationDays1)
await new Promise(res => setTimeout(res, 10_000))

console.log('Calling retrieveLoan 1...')
await nemeosPoolBuyOpenSeaClient.retrieveLoan(nftId1)
console.log('Calling payNextLoanStep 1...')
await nemeosPoolBuyOpenSeaClient.payNextLoanStep(nftId1)
await new Promise(res => setTimeout(res, 3_000))

console.log('Calling retrieveLoan 2...')
await nemeosPoolBuyOpenSeaClient.retrieveLoan(nftId1)
console.log('Calling payNextLoanStep 2...')
await nemeosPoolBuyOpenSeaClient.payNextLoanStep(nftId1)
await new Promise(res => setTimeout(res, 3_000))

console.log('Calling retrieveLoan 3...')
await nemeosPoolBuyOpenSeaClient.retrieveLoan(nftId1)

//
Expand Down

0 comments on commit 1843bd3

Please sign in to comment.