# Nimbora - SDK

### About us

Nimbora is a platform that offers you the opportunity to interact with your favorite Layer 1 (L1) protocols at a fraction of the cost of Layer 2 (L2) solutions.

You can learn more about Nimbora by follow us on [Medium](https://medium.com/@Nimbora), [Twitter](https://twitter.com/nimbora_io), or join our [Telegram group](https://t.me/+606MBKpVsdthYTU0).

### About the SDK

This SDK helps you integrate with Nimbora YieldDex.

## Contents:

-   [Token Manager](#token-manager)

## Token Manager

## Installation

```bash
$ npm install nimbora-token-manager
$ yarn add nimbora-token-manager
```

## All methods

### Setup a Token Manager

```ts
import { TokenManager } from 'nimbora-token-manager';
import { RpcProvider } from 'starknet';

const tokenManagerAddress: string = '';
const provider = new RpcProvider({ nodeUrl: 'https://starknet-goerli.g.alchemy.com/v2/XXX' });

const accountAddress = process.env.ACCOUNT_ADDRESS;
const accountPrivateKey = process.env.ACCOUNT_PRIVATE_KEY;
const account = new Account(provider, accountAddress, accountPrivateKey);

const tokenManager = new TokenManager(tokenManagerAddress, provider, account);
```

### Deposit

Deposit tokens into the Layer 2 Token Manager contract by calling `deposit` function. This function can execute a `multi-call` if the allowance to the token manager is insufficient [allowance + deposit].

```ts
...
try {
    const { shares, hash } = await tokenManager.deposit({
        amount: "100",
        receiver: account.address, // The shares receiver account address.
        referral: account.address, // The referral account address.
        onTxStageChange: txStageChangeCallback, // Optional callback for getting information about transaction stage
    })
} catch (e) {
    // Handle Errors
}
```

### Request Withdrawal

A withdrawal request from a token manager can be made by invoking the requestWithdrawal function, specifying the amount of shares the user wishes to exchange for underlying tokens.

```ts
...
try {
    const { id, hash } = await tokenManager.requestWithdrawal({
        shares: "100", // Total shares to exchange for the underlying token.
        onTxStageChange: txStageChangeCallback, // Optional callback for getting information about transaction stage.
    })
} catch (e) {
    // Handle Errors
}
```

### Claim Withdrawal

Claim a withdrawal from a token manager can be done by calling the `claimWithdrawal`.

```ts
...
try {
    const hash = await tokenManager.claimWithdrawal({
        claimWithdrawal: "1", // The request withdrawal id.
        onTxStageChange: txStageChangeCallback, // Optional callback for getting information about transaction stage.
    })
} catch (e) {
    // Handle Errors
}
```

### performanceFees

Returns the protocol performance fee

```ts
...
try {
    const fee = await tokenManager.performanceFees()
} catch (e) {
    // Handle Errors
}
```

### depositLimitLow

Returns the minimum amount allowed to deposit into the token manager

```ts
...
try {
    const amount = await tokenManager.depositLimitLow()
} catch (e) {
    // Handle Errors
}
```

### depositLimitHigh

Returns the maximum amount allowed to deposit into the token manager

```ts
...
try {
    const amount = await tokenManager.depositLimitHigh()
} catch (e) {
    // Handle Errors
}
```

### withdrawalLimitLow

Returns the minimum amount allowed to withdraw from the token manager

```ts
...
try {
    const amount = await tokenManager.withdrawalLimitLow()
} catch (e) {
    // Handle Errors
}
```

### withdrawalLimitHigh

Returns the maximum amount allowed to withdraw from the token manager

```ts
...
try {
    const amount = await tokenManager.withdrawalLimitHigh()
} catch (e) {
    // Handle Errors
}
```

### withdrawalEpochDelay

Returns the epoch delay before the request withdrawal is processed by the pooling manager

```ts
...
try {
    const epoch = await tokenManager.withdrawalEpochDelay()
} catch (e) {
    // Handle Errors
}
```

### epoch

Returns the current epoch

```ts
...
try {
    const epoch = await tokenManager.epoch()
} catch (e) {
    // Handle Errors
}
```

### lastProcessedEpoch

Returns the epoch reported and where withdrawals were processed

```ts
...
try {
    const epoch = await tokenManager.lastProcessedEpoch()
} catch (e) {
    // Handle Errors
}
```

### l1NetAssetValue

Returns the L1 net asset value

```ts
...
try {
    const nav = await tokenManager.l1NetAssetValue()
} catch (e) {
    // Handle Errors
}
```

### totalAssets

This returns the Total Value Locked (TVL) in the underlying token. It includes the buffered tokens on both L1, L2, as well as the tokens in transit (currently bridged).

```ts
...
try {
    const tvl = await tokenManager.totalAssets()
} catch (e) {
    // Handle Errors
}
```

### withdrawalExchangeRate

The exchange rate to convert the shares<>underlying tokens per epoch.

```ts
...
try {
    const epoch = 1
    const rate = await tokenManager.withdrawalExchangeRate(epoch)
} catch (e) {
    // Handle Errors
}
```

### listUserRequestWithdrawal

List all the users request withdrawal

```ts
...
try {
    const address = account.address // user address
    const withdrawals = await tokenManager.listUserRequestWithdrawal(address)
} catch (e) {
    // Handle Errors
}
```

### lastUserRequestWithdrawal

Return the last request withdrawal made by the user.

```ts
...
try {
    const address = account.address // user address
    const withdrawal = await tokenManager.lastUserRequestWithdrawal(address)
} catch (e) {
    // Handle Errors
}
```

### shareToUnderlying

Convert the shares to underlying token

```ts
...
try {
    const shares = "100" // amount in shares
    const underlyingAmount = await tokenManager.shareToUnderlying(shares)
} catch (e) {
    // Handle Errors
}
```

### UnderlyingToShare

Convert the underlying to shares token.

```ts
...
try {
    const underlyingAmount = "100" // amount in shares
    const shares = await tokenManager.UnderlyingToShare(underlyingAmount)
} catch (e) {
    // Handle Errors
}
```

### underlying

Returns the underlying contract

```ts
...
try {
    const underlingContract = await tokenManager.underlying()
    const balance = await underlingContract.call('balance_of', [account.address])
} catch (e) {
    // Handle Errors
}
```

### token

Returns the token share contract

```ts
...
try {
    const tokenContract = await tokenManager.token()
    const balance = await tokenContract.call('balance_of', [account.address])
} catch (e) {
    // Handle Errors
}
```

## Learn more

-   [Nimbora]()
-   [Github](https://github.com/0xSpaceShard/nimbora-sdk)
-   [Docs](https://docs.nimbora.io/)
