# @zebec-protocol/plutus-sdk

> SDK for interacting with zebec bnb contracts

Latest version **1.0.2** (published 2023-08-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install @zebec-protocol/plutus-sdk
pnpm add @zebec-protocol/plutus-sdk
yarn add @zebec-protocol/plutus-sdk
bun add @zebec-protocol/plutus-sdk
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-08-14 |
| First published | 2023-06-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 1.4 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Zebec \| Roshan Shrestha \| Ashish Sapkota |
| Maintainers | aacs.spkt, shraddhabhuju, zebec-mahesh, zebec-protocol-labs |

## Links

- npm: https://www.npmjs.com/package/@zebec-protocol/plutus-sdk
- Repository: https://github.com/Zebec-protocol/plutus-sdk
- Homepage: https://github.com/Zebec-protocol/plutus-sdk#readme
- Issues: https://github.com/Zebec-protocol/plutus-sdk/issues
- npm.io page: https://npm.io/package/@zebec-protocol/plutus-sdk

## Dependencies (1)

- [ethers](https://npm.io/package/ethers.md) 5.7.2

## Recent versions

- 1.0.2 (latest) — 2023-08-14
- 1.0.1 — 2023-08-09
- 1.0.0-dev.22 — 2023-08-08
- 1.0.0-dev.21 — 2023-08-04
- 1.0.0-dev.20 — 2023-08-02
- 1.0.0-dev.19 — 2023-08-02
- 1.0.0-dev.18 — 2023-08-01
- 1.0.0-dev.17 — 2023-07-31
- 1.0.0-dev.16 — 2023-07-28
- 1.0.0-dev.15 — 2023-07-27
- 1.0.0-dev.14 — 2023-07-27
- 1.0.0-dev.13 — 2023-07-26
- 1.0.0-dev.12 — 2023-07-18
- 1.0.0-dev.11 — 2023-07-18
- 1.0.0-dev.10 — 2023-07-18
- … 9 more at https://npm.io/package/@zebec-protocol/plutus-sdk/versions

## README

# Zebec Plutus Contract SDK

SDK for interacting with zebec bnb contracts

## Installation

```bash
yarn add @zebec-protocol/plutus-sdk

// or

npm install @zebec-protocol/plutus-sdk
```

## Files and Folders

| Files and folders | Descriptions                                                      |
| ----------------- | ----------------------------------------------------------------- |
| Borrower          | Contains Borrower client and definitions                          |
| CreditDesk        | Contains CreditDesk client and definitions                        |
| PlutusConfig      | Contains PlutusConfig client and definitions                      |
| Pool              | Contains Pool client and definitions                              |
| Contracts         | Contains typechain generated files and are used to create clients |
| ZebecConsensus    | Contains ZebecConsensus Client and definitions                    |
| Utils             | Contains utility functions for logging, approving tokens, etc     |
| Contansts         | Contains constants such as contract address                       |

## Development

To run the project

```bash
yarn start
```

To build the project

```bash
yarn build
```

To remove dist folder

```bash
yarn clean
```

To run test scripts:

```bash
yarn test:single <path to test script>

# example for windows: yarn test:single tests\pool.spec.ts
# example for linux: yarn test:single tests/pool.spec.ts
```

To compile generate typechain files from abis

```bash
yarn build:typechain
```

## Usage

### Create Pool Client

Pool client can be created in following way.

```ts
const lender = <signer>;
const client = new PoolClient(lender);
```

### Deposit usdc to pool

To deposit usdc in pool, do as given below.

```ts
const depositReceipt = await client.deposit(amount);
```

After depositing usdc corresponding amount of PLP token is received by lender. You can see your PLP balance.

```ts
const owner = <signer>;
const plpToken = Token__factory.connect(PLP_ADDRESS, owner);
const lenderPlp = await plpToken.balanceOf(lender.address);
```

### Withdraw USDC from pool

Withdraw USDC from pool burns the PLP tokens that the lender have.

```ts
const amount = "100";
const withdrawTxn = await client.withdraw(amount, USDC_ADDRESS);
```

### Create CreditDesk Client

```ts
const signer = <signer>;
const creditDeskClient = new CreditDeskClient(signer);
```

### Create zebec consensus client

```ts
const admin = <signer>;
const zebecConsensusClient = new ZebecConsesusClient(admin, ZEBEC_CONSENSUS_ADDRESS)
```

### Tokenize assets

After tokenization, certain amount of asset token is minted to borrower as specified in loan limit.

```ts
const name = "Test Token";
const symbol = "TKN";
const borrower = "<address>";
const loanLimit = BigInt("10000");
const interestApr = 15; // percent
const paymentPeriodInDays = "30";
const termInDays = "90";
const lateFeeApr = "10"; // percent

const receipt = zebecConsensusClient.tokenization(
	name,
	symbol,
	borrower,
	loanLimit,
	interestApr,
	paymentPeriodInDays,
	termInDays,
	lateFeeApr,
);
```

### Detokenize assets

```ts
const assetTokenAddress = "<address>";
const creditLineAddress = "<address>";
const receipt = zebecConsensusClient.deTokenization(assetTokenAddress, creditLineAddress);
```

### Get creditline of underwriter

Here the underwriter is ZebecConsensus Contract.

```ts
const creditLines = creditDeskClient.getUnderwriterCreditLines(ZEBEC_CONSENSUS_ADDRESS);
```

### Get creditline of borrower

```ts
const borrowerAddress = "<address>";
const creditline = creditDeskClient.getBorrowerCreditLines(borrowerAddress);
```

### Get overall APR

```ts
const apr = creditDeskClient.getOverallApr(ZEBEC_CONSENSUS_ADDRESS);
```

### Get supply balance and interest

```ts
const lenderAddress = "<address>";
const { supplyAmountLended, claimableInterest } =
	creditDeskClient.getSupplyBalanceAndInterest(lenderAddress);
```

### Get pool usage

```ts
const usage = creditDeskClient.getPoolUsage(ZEBEC_CONSENSUS_ADDRESS);
```

### Create Borrower Client

```ts
const owner = <signer>;
const borrowerClient = new BorrowerClient(owner, BORROWER_ADDRESS, CREDIT_DESK_ADDRESS);
```

### Get loan

For getting loan, creditline must be approved and created by admin.

```ts
const creditLineAddress = "<address>";
const assetTokenAddress = "<address>";
const amount = "10000";
const receipt = borrowerClient.getLoan(creditLineAddress, amount, assetTokenAddress);
```

### Get next payment amount

```ts
const creditLineAddress = "<address>";
const paymentAmount = borrowerClient.getNextPaymentAmount(creditLineAddress);
```

### Repay loan

```ts
const amount = "100";
const creditLineAddress = "<address>";
const receipt = borrowerClient.repayLoan(creditLineAddress, amount);
```

### Repay loan in full

```ts
const creditLineAddress = "<address>";
const receipt = borrowerClient.repayLoanInFull(creditLineAddress);
```

---
_Source: https://npm.io/package/@zebec-protocol/plutus-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
