Skip to content

Commit

Permalink
[docs] add converters
Browse files Browse the repository at this point in the history
  • Loading branch information
Cast0001 committed Oct 6, 2023
1 parent 8944d88 commit b8d8e01
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 3 deletions.
54 changes: 51 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const sdk = new StakeWiseSDK({ network: Network.Mainnet })
| network | `Network` | **Require** | Chain id |
| provider | `any` | **Optional** | You can provide your implementation of the provender for ethers |
| endpoints.subgraph | `string` | **Optional** | stakewise sbugraph url |
| endpoints.web3 | `number` | **Require** | Your url for connect to blockchian |
| endpoints.web3 | `number` | **Optional** | Your url for connect to blockchian |
| endpoints.api | `string` | **Optional** | stakewise backend url |

## Quick Links
Expand All @@ -71,8 +71,8 @@ const sdk = new StakeWiseSDK({ network: Network.Mainnet })
| [sdk.vault.getAllocatorActions](#sdkvaultgetallocatoractions) | [sdk.osToken.getBurnAmount](#sdkostokengetburnamount) | [sdk.utils.getRewardsPerYear](#sdkutilsgetrewardsperyear) |
| [sdk.vault.getDaySnapshots](#sdkvaultgetdaysnapshots) | [sdk.osToken.getHealthFactor](#sdkostokengethealthfactor) | [sdk.utils.getSwiseUsdPrice](#sdkutilsgetswiseusdprice) |
| [sdk.vault.getExitQueue](#sdkvaultgetexitqueue) | [sdk.osToken.getAPY](#sdkostokengetapy) | [sdk.utils.getTransactions](#sdkutilsgettransactions) |
| [sdk.vault.getValidators](#sdkvaultgetvalidators) | [sdk.osToken.getPosition](#sdkostokengetposition) |
| [sdk.vault.getVault](#sdkvaultgetvault) | [sdk.osToken.getMaxMint](#sdkostokengetmaxmint) |
| [sdk.vault.getValidators](#sdkvaultgetvalidators) | [sdk.osToken.getPosition](#sdkostokengetposition) | [sdk.utils.getAssetsFromShares](#sdkutilsgetassetsfromshares) |
| [sdk.vault.getVault](#sdkvaultgetvault) | [sdk.osToken.getMaxMint](#sdkostokengetmaxmint) | [sdk.utils.getSharesFromAssets](#sdkutilsgetsharesfromassets) |
| [sdk.vault.getWithdrawData](#sdkvaultgetwithdrawdata) | [sdk.osToken.getBaseData](#sdkostokengetbasedata) |
| [sdk.vault.getHarvestParams](#sdkvaultgetharvestparams) |
| [sdk.vault.getStakeBalance](#sdkvaultgetstakebalance) |
Expand Down Expand Up @@ -708,6 +708,54 @@ type Output = Array<{
await sdk.utils.getTransactions({ hash: '0x...' })
```
---
### `sdk.utils.getAssetsFromShares`
#### Description:
Convert osToken to ETH
#### Arguments:
| Name | Type | Type |
|------|------|-------------|
| amount | `bigint` | **Require** |
#### Returns:
```ts
type Output = bigint
```
#### Example:
```ts
await sdk.utils.getAssetsFromShares({ amount: 0n })
```
---
### `sdk.utils.getSharesFromAssets`
#### Description:
Convert ETH to osToken
#### Arguments:
| Name | Type | Type |
|------|------|-------------|
| amount | `bigint` | **Require** |
#### Returns:
```ts
type Output = bigint
```
#### Example:
```ts
await sdk.utils.getSharesFromAssets({ amount: 0n })
```
---
## Description of other parts of the api
To retrieve the storage data, you just need the method above. Other parts of the api are needed for specific tasks.
Expand Down
15 changes: 15 additions & 0 deletions src/methods/utils/getAssetsFromShares.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type GetAssetsFromSharesInput = {
contracts: StakeWise.Contracts
amount: bigint
}

const getAssetsFromShares = async (values: GetAssetsFromSharesInput) => {
const { contracts, amount } = values

const result = await contracts.tokens.mintToken.convertToAssets(amount)

return result || 0n
}


export default getAssetsFromShares
15 changes: 15 additions & 0 deletions src/methods/utils/getSharesFromAssets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type GetSharesFromAssetsInput = {
contracts: StakeWise.Contracts
amount: bigint
}

const getSharesFromAssets = async (values: GetSharesFromAssetsInput) => {
const { contracts, amount } = values

const result = await contracts.tokens.mintToken.convertToShares(amount)

return result || 0n
}


export default getSharesFromAssets
2 changes: 2 additions & 0 deletions src/methods/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export { default as getSharesFromAssets } from './getSharesFromAssets'
export { default as getAssetsFromShares } from './getAssetsFromShares'
export { default as getRewardsPerYear } from './getRewardsPerYear'
export { default as getSwiseUsdPrice } from './getSwiseUsdPrice'
export { default as getTransactions } from './getTransactions'

0 comments on commit b8d8e01

Please sign in to comment.