nimbora-token-manager-simple
v0.0.9
Published
Nimbora Yield dex token manager sdk
Downloads
36
Maintainers
Readme
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, Twitter, or join our Telegram group.
About the SDK
This SDK helps you integrate with Nimbora YieldDex.
Contents:
Token Manager
Installation
$ npm install nimbora-token-manager
$ yarn add nimbora-token-manager
All methods
Setup a Token Manager
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].
...
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.
...
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
.
...
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
...
try {
const fee = await tokenManager.performanceFees()
} catch (e) {
// Handle Errors
}
depositLimitLow
Returns the minimum amount allowed to deposit into the token manager
...
try {
const amount = await tokenManager.depositLimitLow()
} catch (e) {
// Handle Errors
}
depositLimitHigh
Returns the maximum amount allowed to deposit into the token manager
...
try {
const amount = await tokenManager.depositLimitHigh()
} catch (e) {
// Handle Errors
}
withdrawalLimitLow
Returns the minimum amount allowed to withdraw from the token manager
...
try {
const amount = await tokenManager.withdrawalLimitLow()
} catch (e) {
// Handle Errors
}
withdrawalLimitHigh
Returns the maximum amount allowed to withdraw from the token manager
...
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
...
try {
const epoch = await tokenManager.withdrawalEpochDelay()
} catch (e) {
// Handle Errors
}
epoch
Returns the current epoch
...
try {
const epoch = await tokenManager.epoch()
} catch (e) {
// Handle Errors
}
lastProcessedEpoch
Returns the epoch reported and where withdrawals were processed
...
try {
const epoch = await tokenManager.lastProcessedEpoch()
} catch (e) {
// Handle Errors
}
l1NetAssetValue
Returns the L1 net asset value
...
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).
...
try {
const tvl = await tokenManager.totalAssets()
} catch (e) {
// Handle Errors
}
withdrawalExchangeRate
The exchange rate to convert the shares<>underlying tokens per epoch.
...
try {
const epoch = 1
const rate = await tokenManager.withdrawalExchangeRate(epoch)
} catch (e) {
// Handle Errors
}
listUserRequestWithdrawal
List all the users request withdrawal
...
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.
...
try {
const address = account.address // user address
const withdrawal = await tokenManager.lastUserRequestWithdrawal(address)
} catch (e) {
// Handle Errors
}
shareToUnderlying
Convert the shares to underlying token
...
try {
const shares = "100" // amount in shares
const underlyingAmount = await tokenManager.shareToUnderlying(shares)
} catch (e) {
// Handle Errors
}
UnderlyingToShare
Convert the underlying to shares token.
...
try {
const underlyingAmount = "100" // amount in shares
const shares = await tokenManager.UnderlyingToShare(underlyingAmount)
} catch (e) {
// Handle Errors
}
underlying
Returns the underlying contract
...
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
...
try {
const tokenContract = await tokenManager.token()
const balance = await tokenContract.call('balance_of', [account.address])
} catch (e) {
// Handle Errors
}