-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Nimbora SDK documentation and assets
- Loading branch information
ioanSL
committed
Feb 14, 2024
1 parent
d04058e
commit d45931c
Showing
7 changed files
with
175 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"label": "Guides", | ||
"position": 2, | ||
"collapsed": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
id: background | ||
title: Background | ||
sidebar_position: 2 | ||
--- | ||
|
||
# Background | ||
|
||
For those new to Nimbora, reviewing some key web3 developer concepts, the format of our examples, and SDK ideas can be beneficial before starting the integration. | ||
|
||
## Providers | ||
|
||
Interacting with the blockchain typically involves utilizing a provider and local representations of smart contracts along with their ABIs. | ||
|
||
In our examples, we use the [starknet.js](https://www.starknetjs.com/docs/guides/intro/) library to accomplish this. Initializing a provider requires a data source. We present two options in our examples: | ||
|
||
- JSON RPC URL: Services like [Infura](https://www.infura.io) or [Alchemy](https://www.starknetjs.com/docs/guides/intro/) offer JSON RPC URLs for various chains and testnets, which you can use if you're directly interacting with the Ethereum mainnet or a local fork. In our examples, we primarily use the Ethereum mainnet. | ||
|
||
## SDK Structures and Concepts | ||
|
||
Understanding the design decisions and their necessities can be beneficial when working with the SDK. Here are a few key concepts. | ||
|
||
### ABI | ||
|
||
Each smart contract offers an Application Binary Interface (ABI), enabling other users to interact with it. ABIs, defined on the blockchain, must be accurately supplied to our Javascript functionalities. Various SDKs provide the necessary ABIs, which are imported when required. In some instances, an ABI may be directly defined as needed. | ||
|
||
### Currency | ||
|
||
Currently, the Starknet network uses the ERC20 version of Ethereum (ETH) for transaction fees. ERC20 is a standard used for smart contracts on the Ethereum blockchain for implementing tokens. However, Starknet plans to transition to using its own native token, STRK, for transaction costs in the future. This shift will occur to further establish Starknet's ecosystem and potentially bring about new dynamics and utilities within the network. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
--- | ||
id: deposit | ||
title: Depositing into strategy | ||
sidebar_position: 3 | ||
--- | ||
|
||
Depositing tokens into the Layer 2 Token Manager contract is achieved by calling the `deposit` function. This function is capable of executing a `multi-call` under certain conditions. | ||
|
||
A `multi-call` is a type of transaction that allows you to perform multiple actions within a single transaction. In this context, it is executed if the current allowance, or the amount of tokens that the Token Manager contract is authorized to withdraw from the user's account, is insufficient to cover the deposit. | ||
|
||
When the `deposit` function is called, if the amount of tokens the user wants to deposit exceeds the current allowance, the function will first call the `approve` function to increase the allowance to cover the deposit amount, and then call the `transfer` function to transfer the tokens. | ||
|
||
This sequence of actions is packaged into a single transaction, hence the term `multi-call`. | ||
|
||
```typescript | ||
... | ||
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 | ||
} | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
id: token_manager | ||
title: Using the Token Manager | ||
sidebar_position: 2 | ||
--- | ||
|
||
|
||
# Token Manager | ||
|
||
The Token Manager is a core component in the system that allows users to interact with the Strategy. This interaction may include actions such as sending, receiving, or managing tokens. Setting it up involves several steps. | ||
|
||
First, necessary packages and modules such as TokenManager and RpcProvider are imported. | ||
|
||
The tokenManagerAddress is then defined, followed by the initialization of the provider using the RpcProvider. The user's account details, including the accountAddress and accountPrivateKey, are then set. | ||
|
||
Finally, a new instance of TokenManager is created, using the previously defined tokenManagerAddress, provider, and account. This instance can then be used to interact with the Strategy. | ||
|
||
For this guide, the following packages are used: | ||
|
||
- [nimbora-token-manager](https://www.npmjs.com/package/nimbora-token-manager) | ||
- [starknet.js](https://www.npmjs.com/package/starknet) | ||
|
||
|
||
```typescript | ||
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); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--- | ||
id: withdraw | ||
title: Withdrawing from strategy | ||
sidebar_position: 4 | ||
--- | ||
|
||
A withdrawal involves transferring assets from the Layer 2 Token Manager contract on the StarkNet network to the Ethereum mainnet. This is a two-step operation. | ||
|
||
First, you call the `requestWithdrawal` function, specifying the number of shares to be converted back into Ethereum tokens. These shares reflect the balance in the Token Manager contract. | ||
|
||
After the withdrawal request is processed and finalized on the StarkNet network, you can claim the withdrawal by calling the `claimWithdrawal` function which moves the tokens back to your Ethereum account. | ||
|
||
### Request Withdrawal | ||
|
||
To make a withdrawal request from the token manager, users need to invoke the `requestWithdrawal` function. This function requires the user to specify the amount of shares they wish to exchange for the underlying tokens. | ||
|
||
The `requestWithdrawal` function is part of the Token Manager's smart contract, which manages the transfer of tokens between the layer 2 StarkNet network and the Ethereum mainnet. The shares represent a user's balance in the Token Manager contract. | ||
|
||
When a user calls the `requestWithdrawal` function, they are effectively initiating a process to convert their shares back into the equivalent amount of tokens on the Ethereum mainnet. | ||
|
||
This process is crucial for users who want to move their assets out of the StarkNet network and back to the Ethereum mainnet. | ||
|
||
```typescript | ||
... | ||
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 | ||
|
||
Claiming a withdrawal from a token manager involves several steps. Initially, the user has to call the `claimWithdrawal` function, which facilitates the entire process. | ||
|
||
This function helps in retrieving the tokens that have been previously requested for withdrawal from the Layer 2 Token Manager contract back to the Ethereum mainnet. It's important to note that this can only be done once the withdrawal request has been processed and finalized on the StarkNet network. | ||
|
||
The `claimWithdrawal` function requires the ID of the withdrawal request as a parameter, which is generated when the `requestWithdrawal` function is called. | ||
|
||
After the `claimWithdrawal` function has been successfully executed, the tokens are transferred back to the user's Ethereum account. | ||
|
||
It's a crucial step for users who wish to transfer their assets from the StarkNet network back to the Ethereum mainnet. | ||
|
||
```typescript | ||
... | ||
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 | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.