@ichidao/ichi-vaults-sdk 0.1.42 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +61 -208
- package/dist/abis/types/AlgebraIntegralPool.d.ts +702 -793
- package/dist/abis/types/AlgebraPool.d.ts +693 -730
- package/dist/abis/types/ClPool.d.ts +789 -871
- package/dist/abis/types/DepositGuard.d.ts +193 -178
- package/dist/abis/types/DepositGuardWithHtsWrapping.d.ts +300 -297
- package/dist/abis/types/ERC20.d.ts +120 -147
- package/dist/abis/types/ERC20Wrapper.d.ts +147 -155
- package/dist/abis/types/IchiVault.d.ts +598 -728
- package/dist/abis/types/MultiFeeDistributer.d.ts +314 -423
- package/dist/abis/types/Multicall.d.ts +58 -73
- package/dist/abis/types/UniswapV3Pool.d.ts +654 -693
- package/dist/abis/types/common.d.ts +40 -12
- package/dist/abis/types/factories/AlgebraIntegralPool__factory.d.ts +2 -3
- package/dist/abis/types/factories/AlgebraIntegralPool__factory.js +10 -13
- package/dist/abis/types/factories/AlgebraIntegralPool__factory.js.map +1 -1
- package/dist/abis/types/factories/AlgebraPool__factory.d.ts +2 -3
- package/dist/abis/types/factories/AlgebraPool__factory.js +10 -13
- package/dist/abis/types/factories/AlgebraPool__factory.js.map +1 -1
- package/dist/abis/types/factories/ClPool__factory.d.ts +2 -3
- package/dist/abis/types/factories/ClPool__factory.js +10 -13
- package/dist/abis/types/factories/ClPool__factory.js.map +1 -1
- package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.d.ts +2 -3
- package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.js +10 -13
- package/dist/abis/types/factories/DepositGuardWithHtsWrapping__factory.js.map +1 -1
- package/dist/abis/types/factories/DepositGuard__factory.d.ts +2 -3
- package/dist/abis/types/factories/DepositGuard__factory.js +10 -13
- package/dist/abis/types/factories/DepositGuard__factory.js.map +1 -1
- package/dist/abis/types/factories/ERC20Wrapper__factory.d.ts +2 -3
- package/dist/abis/types/factories/ERC20Wrapper__factory.js +10 -13
- package/dist/abis/types/factories/ERC20Wrapper__factory.js.map +1 -1
- package/dist/abis/types/factories/ERC20__factory.d.ts +2 -3
- package/dist/abis/types/factories/ERC20__factory.js +10 -13
- package/dist/abis/types/factories/ERC20__factory.js.map +1 -1
- package/dist/abis/types/factories/IchiVault__factory.d.ts +2 -3
- package/dist/abis/types/factories/IchiVault__factory.js +10 -13
- package/dist/abis/types/factories/IchiVault__factory.js.map +1 -1
- package/dist/abis/types/factories/MultiFeeDistributer__factory.d.ts +2 -3
- package/dist/abis/types/factories/MultiFeeDistributer__factory.js +10 -13
- package/dist/abis/types/factories/MultiFeeDistributer__factory.js.map +1 -1
- package/dist/abis/types/factories/Multicall__factory.d.ts +2 -3
- package/dist/abis/types/factories/Multicall__factory.js +10 -13
- package/dist/abis/types/factories/Multicall__factory.js.map +1 -1
- package/dist/abis/types/factories/UniswapV3Pool__factory.d.ts +2 -3
- package/dist/abis/types/factories/UniswapV3Pool__factory.js +10 -13
- package/dist/abis/types/factories/UniswapV3Pool__factory.js.map +1 -1
- package/dist/src/__tests__/index.test.js +376 -700
- package/dist/src/__tests__/index.test.js.map +1 -1
- package/dist/src/abis/types/AlgebraIntegralPool.d.ts +702 -793
- package/dist/src/abis/types/AlgebraPool.d.ts +693 -730
- package/dist/src/abis/types/ClPool.d.ts +789 -871
- package/dist/src/abis/types/DepositGuard.d.ts +193 -178
- package/dist/src/abis/types/DepositGuardWithHtsWrapping.d.ts +300 -297
- package/dist/src/abis/types/ERC20.d.ts +120 -147
- package/dist/src/abis/types/ERC20Wrapper.d.ts +147 -155
- package/dist/src/abis/types/IchiVault.d.ts +598 -728
- package/dist/src/abis/types/MultiFeeDistributer.d.ts +314 -423
- package/dist/src/abis/types/Multicall.d.ts +58 -73
- package/dist/src/abis/types/UniswapV3Pool.d.ts +654 -693
- package/dist/src/abis/types/common.d.ts +40 -12
- package/dist/src/abis/types/factories/AlgebraIntegralPool__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/AlgebraPool__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/ClPool__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/DepositGuardWithHtsWrapping__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/DepositGuard__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/ERC20Wrapper__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/ERC20__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/IchiVault__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/MultiFeeDistributer__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/Multicall__factory.d.ts +2 -3
- package/dist/src/abis/types/factories/UniswapV3Pool__factory.d.ts +2 -3
- package/dist/src/contracts/index.d.ts +1 -1
- package/dist/src/contracts/index.js +12 -12
- package/dist/src/contracts/index.js.map +1 -1
- package/dist/src/functions/_totalBalances.d.ts +2 -3
- package/dist/src/functions/_totalBalances.js +46 -117
- package/dist/src/functions/_totalBalances.js.map +1 -1
- package/dist/src/functions/_vaultEvents.js +347 -488
- package/dist/src/functions/_vaultEvents.js.map +1 -1
- package/dist/src/functions/_withdrawHelpers.d.ts +2 -3
- package/dist/src/functions/_withdrawHelpers.js +13 -62
- package/dist/src/functions/_withdrawHelpers.js.map +1 -1
- package/dist/src/functions/calculateApr.d.ts +1 -1
- package/dist/src/functions/calculateApr.js +77 -150
- package/dist/src/functions/calculateApr.js.map +1 -1
- package/dist/src/functions/calculateDtr.d.ts +1 -1
- package/dist/src/functions/calculateDtr.js +84 -169
- package/dist/src/functions/calculateDtr.js.map +1 -1
- package/dist/src/functions/calculateFees.d.ts +1 -1
- package/dist/src/functions/calculateFees.js +97 -172
- package/dist/src/functions/calculateFees.js.map +1 -1
- package/dist/src/functions/chains.js +6 -6
- package/dist/src/functions/chains.js.map +1 -1
- package/dist/src/functions/claimRewards.d.ts +3 -4
- package/dist/src/functions/claimRewards.js +29 -92
- package/dist/src/functions/claimRewards.js.map +1 -1
- package/dist/src/functions/deposit.d.ts +7 -9
- package/dist/src/functions/deposit.js +199 -364
- package/dist/src/functions/deposit.js.map +1 -1
- package/dist/src/functions/depositWithHtsWrapping.d.ts +4 -6
- package/dist/src/functions/depositWithHtsWrapping.js +109 -226
- package/dist/src/functions/depositWithHtsWrapping.js.map +1 -1
- package/dist/src/functions/getFeeAprs.d.ts +1 -1
- package/dist/src/functions/getFeeAprs.js +55 -111
- package/dist/src/functions/getFeeAprs.js.map +1 -1
- package/dist/src/functions/priceFromPool.d.ts +3 -4
- package/dist/src/functions/priceFromPool.js +99 -208
- package/dist/src/functions/priceFromPool.js.map +1 -1
- package/dist/src/functions/rewardInfo.js +79 -159
- package/dist/src/functions/rewardInfo.js.map +1 -1
- package/dist/src/functions/totalBalances.d.ts +2 -3
- package/dist/src/functions/totalBalances.js +14 -67
- package/dist/src/functions/totalBalances.js.map +1 -1
- package/dist/src/functions/userBalances.d.ts +2 -3
- package/dist/src/functions/userBalances.js +244 -368
- package/dist/src/functions/userBalances.js.map +1 -1
- package/dist/src/functions/userRewards.d.ts +1 -1
- package/dist/src/functions/userRewards.js +87 -145
- package/dist/src/functions/userRewards.js.map +1 -1
- package/dist/src/functions/vault.d.ts +1 -1
- package/dist/src/functions/vault.js +203 -383
- package/dist/src/functions/vault.js.map +1 -1
- package/dist/src/functions/vaultBasics.js +6 -7
- package/dist/src/functions/vaultBasics.js.map +1 -1
- package/dist/src/functions/vaultMetrics.d.ts +1 -1
- package/dist/src/functions/vaultMetrics.js +111 -189
- package/dist/src/functions/vaultMetrics.js.map +1 -1
- package/dist/src/functions/vaultPositions.d.ts +1 -1
- package/dist/src/functions/vaultPositions.js +69 -134
- package/dist/src/functions/vaultPositions.js.map +1 -1
- package/dist/src/functions/vaultTvl.d.ts +1 -1
- package/dist/src/functions/vaultTvl.js +80 -165
- package/dist/src/functions/vaultTvl.js.map +1 -1
- package/dist/src/functions/withdraw.d.ts +6 -8
- package/dist/src/functions/withdraw.js +165 -295
- package/dist/src/functions/withdraw.js.map +1 -1
- package/dist/src/functions/withdrawWithErc20Wrapping.d.ts +2 -4
- package/dist/src/functions/withdrawWithErc20Wrapping.js +59 -126
- package/dist/src/functions/withdrawWithErc20Wrapping.js.map +1 -1
- package/dist/src/graphql/constants.js +211 -212
- package/dist/src/graphql/constants.js.map +1 -1
- package/dist/src/graphql/functions.js +30 -102
- package/dist/src/graphql/functions.js.map +1 -1
- package/dist/src/graphql/queries.js +407 -42
- package/dist/src/graphql/queries.js.map +1 -1
- package/dist/src/index.cjs.js +3 -2
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.esm.js +3 -2
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/src/contracts/index.d.ts +1 -1
- package/dist/src/src/functions/_totalBalances.d.ts +2 -3
- package/dist/src/src/functions/_withdrawHelpers.d.ts +2 -3
- package/dist/src/src/functions/calculateApr.d.ts +1 -1
- package/dist/src/src/functions/calculateDtr.d.ts +1 -1
- package/dist/src/src/functions/calculateFees.d.ts +1 -1
- package/dist/src/src/functions/claimRewards.d.ts +3 -4
- package/dist/src/src/functions/deposit.d.ts +7 -9
- package/dist/src/src/functions/depositWithHtsWrapping.d.ts +4 -6
- package/dist/src/src/functions/getFeeAprs.d.ts +1 -1
- package/dist/src/src/functions/priceFromPool.d.ts +3 -4
- package/dist/src/src/functions/totalBalances.d.ts +2 -3
- package/dist/src/src/functions/userBalances.d.ts +2 -3
- package/dist/src/src/functions/userRewards.d.ts +1 -1
- package/dist/src/src/functions/vault.d.ts +1 -1
- package/dist/src/src/functions/vaultMetrics.d.ts +1 -1
- package/dist/src/src/functions/vaultPositions.d.ts +1 -1
- package/dist/src/src/functions/vaultTvl.d.ts +1 -1
- package/dist/src/src/functions/withdraw.d.ts +6 -8
- package/dist/src/src/functions/withdrawWithErc20Wrapping.d.ts +2 -4
- package/dist/src/src/index.d.ts +1 -0
- package/dist/src/src/types/calculateGasMargin.d.ts +1 -2
- package/dist/src/src/types/index.d.ts +11 -13
- package/dist/src/src/utils/amountWithSlippage.d.ts +1 -2
- package/dist/src/src/utils/config/addresses.d.ts +1 -1
- package/dist/src/src/utils/formatBigInt.d.ts +1 -2
- package/dist/src/src/utils/getConfigByFactory.d.ts +33 -0
- package/dist/src/src/utils/getPrice.d.ts +1 -2
- package/dist/src/src/utils/multicallUtils.d.ts +9 -10
- package/dist/src/src/utils/parseBigInt.d.ts +1 -2
- package/dist/src/types/calculateGasMargin.d.ts +1 -2
- package/dist/src/types/calculateGasMargin.js +4 -5
- package/dist/src/types/calculateGasMargin.js.map +1 -1
- package/dist/src/types/index.d.ts +11 -13
- package/dist/src/types/index.js.map +1 -1
- package/dist/src/utils/amountWithSlippage.d.ts +1 -2
- package/dist/src/utils/amountWithSlippage.js +1 -1
- package/dist/src/utils/amountWithSlippage.js.map +1 -1
- package/dist/src/utils/cache.js +2 -2
- package/dist/src/utils/cache.js.map +1 -1
- package/dist/src/utils/config/addresses.d.ts +1 -1
- package/dist/src/utils/config/addresses.js +267 -268
- package/dist/src/utils/config/addresses.js.map +1 -1
- package/dist/src/utils/formatBigInt.d.ts +1 -2
- package/dist/src/utils/formatBigInt.js +4 -5
- package/dist/src/utils/formatBigInt.js.map +1 -1
- package/dist/src/utils/getConfigByFactory.d.ts +33 -0
- package/dist/src/utils/getConfigByFactory.js +79 -0
- package/dist/src/utils/getConfigByFactory.js.map +1 -0
- package/dist/src/utils/getGraphUrls.js +8 -12
- package/dist/src/utils/getGraphUrls.js.map +1 -1
- package/dist/src/utils/getPrice.d.ts +1 -2
- package/dist/src/utils/getPrice.js +5 -6
- package/dist/src/utils/getPrice.js.map +1 -1
- package/dist/src/utils/isVelodrome.js +2 -3
- package/dist/src/utils/isVelodrome.js.map +1 -1
- package/dist/src/utils/multicallUtils.d.ts +9 -10
- package/dist/src/utils/multicallUtils.js +38 -93
- package/dist/src/utils/multicallUtils.js.map +1 -1
- package/dist/src/utils/parseBigInt.d.ts +1 -2
- package/dist/src/utils/parseBigInt.js +5 -7
- package/dist/src/utils/parseBigInt.js.map +1 -1
- package/dist/src/utils/positionKey.js +2 -4
- package/dist/src/utils/positionKey.js.map +1 -1
- package/package.json +5 -17
package/README.md
CHANGED
|
@@ -7,6 +7,8 @@ This sdk contains collection of functions to interact with IchiVault's smart con
|
|
|
7
7
|
## Table of Contents
|
|
8
8
|
|
|
9
9
|
* [__Installation__](#Installation)
|
|
10
|
+
* [Version Compatibility](#version-compatibility)
|
|
11
|
+
* [Migration from v1 to v2](#migration-from-v1-to-v2)
|
|
10
12
|
* [__Subgraphs__](#Subgraphs)
|
|
11
13
|
* [__Usage__](#Usage)
|
|
12
14
|
* [__Vault Functions__](#Vault)
|
|
@@ -18,11 +20,6 @@ This sdk contains collection of functions to interact with IchiVault's smart con
|
|
|
18
20
|
* [`withdraw()`](#6-withdraw)
|
|
19
21
|
* [`withdrawWithSlippage()`](#7-withdraw)
|
|
20
22
|
* [`withdrawNativeToken()`](#8-withdraw)
|
|
21
|
-
* [`approveToken()`](#8a-approveToken)
|
|
22
|
-
* [`isTokenApproved()`](#8b-isTokenApproved)
|
|
23
|
-
* [`getActualDepositToken()`](#8c-getActualDepositToken)
|
|
24
|
-
* [`depositWithHtsWrapping()`](#8d-depositWithHtsWrapping)
|
|
25
|
-
* [`withdrawWithErc20Wrapping()`](#8e-withdrawWithErc20Wrapping)
|
|
26
23
|
* [`isDepositTokenApproved()`](#9-isDepositTokenApproved)
|
|
27
24
|
* [`isTokenAllowed()`](#10-isTokenAllowed)
|
|
28
25
|
* [`getMaxDepositAmount()`](#11-getMaxDepositAmount)
|
|
@@ -59,12 +56,69 @@ or
|
|
|
59
56
|
npm install @ichidao/ichi-vaults-sdk
|
|
60
57
|
```
|
|
61
58
|
|
|
59
|
+
### Version Compatibility
|
|
60
|
+
|
|
61
|
+
| SDK Version | Ethers.js Version | Status |
|
|
62
|
+
|-------------|-------------------|--------|
|
|
63
|
+
| 2.x.x | v6 | Active |
|
|
64
|
+
| 0.1.x | v5 | Maintenance |
|
|
65
|
+
|
|
66
|
+
**Version 2.x (ethers v6)** - Current default version. If you're using ethers v6 in your project, install the latest version:
|
|
67
|
+
```bash
|
|
68
|
+
yarn add @ichidao/ichi-vaults-sdk
|
|
69
|
+
# or
|
|
70
|
+
npm install @ichidao/ichi-vaults-sdk
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
**Version 0.1.x (ethers v5)** - For projects still using ethers v5, install the legacy version:
|
|
74
|
+
```bash
|
|
75
|
+
yarn add @ichidao/ichi-vaults-sdk@ethers5
|
|
76
|
+
# or
|
|
77
|
+
npm install @ichidao/ichi-vaults-sdk@ethers5
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
To install a specific version:
|
|
81
|
+
```bash
|
|
82
|
+
yarn add @ichidao/ichi-vaults-sdk@0.1.x
|
|
83
|
+
# or
|
|
84
|
+
npm install @ichidao/ichi-vaults-sdk@0.1.x
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Migration from v0.1 to v2
|
|
88
|
+
|
|
89
|
+
The main breaking change in v2 is that functions requiring transaction signing now accept a `Signer` instead of `JsonRpcProvider`. This aligns with ethers v6's architecture where signers are explicitly passed rather than obtained from providers.
|
|
90
|
+
|
|
91
|
+
**Before (v0.1 with ethers v5):**
|
|
92
|
+
```typescript
|
|
93
|
+
import { JsonRpcProvider } from '@ethersproject/providers';
|
|
94
|
+
const provider = new JsonRpcProvider(rpcUrl);
|
|
95
|
+
await deposit(account, amount0, amount1, vaultAddress, provider, dex);
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**After (v2 with ethers v6):**
|
|
99
|
+
```typescript
|
|
100
|
+
import { JsonRpcProvider, Wallet } from 'ethers';
|
|
101
|
+
const provider = new JsonRpcProvider(rpcUrl);
|
|
102
|
+
const signer = new Wallet(privateKey, provider);
|
|
103
|
+
await deposit(account, amount0, amount1, vaultAddress, signer, dex);
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
Functions affected by this change:
|
|
107
|
+
- `approveDepositToken()`
|
|
108
|
+
- `deposit()`
|
|
109
|
+
- `depositNativeToken()`
|
|
110
|
+
- `approveVaultToken()`
|
|
111
|
+
- `withdraw()`
|
|
112
|
+
- `withdrawWithSlippage()`
|
|
113
|
+
- `withdrawNativeToken()`
|
|
114
|
+
- `claimRewards()`
|
|
115
|
+
|
|
116
|
+
Read-only functions continue to accept `JsonRpcProvider`.
|
|
117
|
+
|
|
62
118
|
## Usage
|
|
63
119
|
### Subgraphs
|
|
64
120
|
This SDK uses subgraphs to obtain information about ICHI vaults. The subgraphs are deployed in the Subgraph Studio and published on Arbitrum One. If you prefer to use published subgraphs, you need to add your [subgraph API key](https://thegraph.com/studio/apikeys/) to the SUBGRAPH_API_KEY environment variable. Otherwise, the SDK will use the subgraph's Studio endpoint.
|
|
65
121
|
|
|
66
|
-
**Note for Flow users:** The Flow blockchain uses Alchemy subgraph instead of Subgraph Studio. If you're using this SDK on Flow, you need to provide your own Alchemy subgraph API key by adding it to the ALCHEMY_SUBGRAPH_API_KEY environment variable.
|
|
67
|
-
|
|
68
122
|
### Vault
|
|
69
123
|
|
|
70
124
|
#### 1. `approveDepositToken()`
|
|
@@ -387,206 +441,6 @@ const txnDetails = await withdraw(
|
|
|
387
441
|
)
|
|
388
442
|
```
|
|
389
443
|
|
|
390
|
-
#### 8a. `approveToken()`
|
|
391
|
-
|
|
392
|
-
| param | type | default | required
|
|
393
|
-
| -------- | -------- | -------- | --------
|
|
394
|
-
| accountAddress | string | - | true
|
|
395
|
-
| tokenAddress | string | - | true
|
|
396
|
-
| vaultAddress | string | - | true |
|
|
397
|
-
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
|
398
|
-
| dex | SupportedDex | - | true |
|
|
399
|
-
| amount | string \| number \| BigNumber | undefined | false |
|
|
400
|
-
| overrides | [Overrides](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/contracts/lib/index.d.ts#L7) | undefined | false
|
|
401
|
-
|
|
402
|
-
<br/>
|
|
403
|
-
|
|
404
|
-
This function approves a specific token for deposit into the vault by token address. Unlike `approveDepositToken()` which uses a token index (0 or 1), this function accepts the actual token address. This is particularly useful when working with HTS wrapped tokens where the actual deposit token may differ from the vault's token. Use `getActualDepositToken()` to determine the correct token address to approve.
|
|
405
|
-
|
|
406
|
-
```typescript
|
|
407
|
-
import { Web3Provider } from '@ethersproject/providers';
|
|
408
|
-
import { approveToken, getActualDepositToken, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
|
409
|
-
|
|
410
|
-
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
|
411
|
-
const vaultAddress = "0x3ac9...a5f132"
|
|
412
|
-
const accountAddress = "0xaaaa...aaaaaa"
|
|
413
|
-
const depositToken = "0xbbbb...bbbbbb" // original deposit token from vault
|
|
414
|
-
const dex = SupportedDex.Bonzo
|
|
415
|
-
|
|
416
|
-
// Get the actual token to approve (may be ERC20 counterpart of HTS token)
|
|
417
|
-
const actualToken = await getActualDepositToken(depositToken, web3Provider);
|
|
418
|
-
|
|
419
|
-
const txnDetails = await approveToken(
|
|
420
|
-
accountAddress,
|
|
421
|
-
actualToken,
|
|
422
|
-
vaultAddress,
|
|
423
|
-
web3Provider,
|
|
424
|
-
dex,
|
|
425
|
-
100 // amount (optional)
|
|
426
|
-
);
|
|
427
|
-
|
|
428
|
-
await txnDetails.wait();
|
|
429
|
-
```
|
|
430
|
-
|
|
431
|
-
#### 8b. `isTokenApproved()`
|
|
432
|
-
|
|
433
|
-
| param | type | default | required
|
|
434
|
-
| -------- | -------- | -------- | --------
|
|
435
|
-
| accountAddress | string | - | true
|
|
436
|
-
| tokenAddress | string | - | true
|
|
437
|
-
| amount | string \| number \| BigNumber | - | true |
|
|
438
|
-
| vaultAddress | string | - | true |
|
|
439
|
-
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
|
440
|
-
| dex | SupportedDex | - | true |
|
|
441
|
-
|
|
442
|
-
<br/>
|
|
443
|
-
|
|
444
|
-
This function returns true if the specified token's allowance is non-zero and greater than or equal to the specified amount. Use this to check approval status for the actual deposit token (which may be the ERC20 counterpart of an HTS token for vaults on Hedera).
|
|
445
|
-
|
|
446
|
-
```typescript
|
|
447
|
-
import { Web3Provider } from '@ethersproject/providers';
|
|
448
|
-
import { isTokenApproved, getActualDepositToken, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
|
449
|
-
|
|
450
|
-
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
|
451
|
-
const vaultAddress = "0x3ac9...a5f132"
|
|
452
|
-
const accountAddress = "0xaaaa...aaaaaa"
|
|
453
|
-
const depositToken = "0xbbbb...bbbbbb"
|
|
454
|
-
const amount = 100
|
|
455
|
-
const dex = SupportedDex.Bonzo
|
|
456
|
-
|
|
457
|
-
// Get the actual token to check (may be ERC20 counterpart of HTS token)
|
|
458
|
-
const actualToken = await getActualDepositToken(depositToken, web3Provider);
|
|
459
|
-
|
|
460
|
-
const isApproved: boolean = await isTokenApproved(
|
|
461
|
-
accountAddress,
|
|
462
|
-
actualToken,
|
|
463
|
-
amount,
|
|
464
|
-
vaultAddress,
|
|
465
|
-
web3Provider,
|
|
466
|
-
dex
|
|
467
|
-
)
|
|
468
|
-
```
|
|
469
|
-
|
|
470
|
-
#### 8c. `getActualDepositToken()` - Bonzo on Hedera Only
|
|
471
|
-
|
|
472
|
-
| param | type | default | required
|
|
473
|
-
| -------- | -------- | -------- | --------
|
|
474
|
-
| depositToken | string | - | true
|
|
475
|
-
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
|
476
|
-
|
|
477
|
-
<br/>
|
|
478
|
-
|
|
479
|
-
> **Note:** This function is only available for Bonzo vaults on the Hedera chain.
|
|
480
|
-
|
|
481
|
-
This helper function checks if the deposit token is an HTS wrapped token and returns its ERC20 counterpart if one exists. If no ERC20 counterpart exists, it returns the original token address. Use this function to determine the correct token address for approval and deposit operations.
|
|
482
|
-
|
|
483
|
-
```typescript
|
|
484
|
-
import { Web3Provider } from '@ethersproject/providers';
|
|
485
|
-
import { getActualDepositToken } from '@ichidao/ichi-vaults-sdk';
|
|
486
|
-
|
|
487
|
-
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
|
488
|
-
const depositToken = "0xbbbb...bbbbbb" // HTS wrapped token
|
|
489
|
-
|
|
490
|
-
const actualToken = await getActualDepositToken(depositToken, web3Provider);
|
|
491
|
-
// actualToken will be the ERC20 counterpart if one exists, otherwise the original token
|
|
492
|
-
```
|
|
493
|
-
|
|
494
|
-
#### 8d. `depositWithHtsWrapping()` - Bonzo on Hedera Only
|
|
495
|
-
|
|
496
|
-
| param | type | default | required
|
|
497
|
-
| -------- | -------- | -------- | --------
|
|
498
|
-
| accountAddress | string | - | true
|
|
499
|
-
| amount0 | string \| number \| BigNumber | - | true
|
|
500
|
-
| amount1 | string \| number \| BigNumber | - | true
|
|
501
|
-
| vaultAddress | string | - | true
|
|
502
|
-
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
|
503
|
-
| dex | SupportedDex | - | true
|
|
504
|
-
| percentSlippage | number | 1 | false
|
|
505
|
-
| overrides | [Overrides](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/contracts/lib/index.d.ts#L7) | undefined | false
|
|
506
|
-
|
|
507
|
-
<br/>
|
|
508
|
-
|
|
509
|
-
> **Note:** This function is only available for Bonzo vaults on the Hedera chain. Using it with other vaults or chains will throw an error.
|
|
510
|
-
|
|
511
|
-
This function facilitates deposits into Bonzo vaults on Hedera with automatic HTS token wrapping. If the deposit token is an HTS wrapped token, the function automatically finds and uses its ERC20 counterpart for the deposit. The vault tokens received will be wrapped to HTS format. Use `approveToken()` with `getActualDepositToken()` to approve the correct token before calling this function.
|
|
512
|
-
|
|
513
|
-
```typescript
|
|
514
|
-
import { Web3Provider } from '@ethersproject/providers';
|
|
515
|
-
import { depositWithHtsWrapping, approveToken, getActualDepositToken, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
|
516
|
-
|
|
517
|
-
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
|
518
|
-
const vaultAddress = "0x3ac9...a5f132"
|
|
519
|
-
const dex = SupportedDex.Bonzo
|
|
520
|
-
const accountAddress = "0xaaaa...aaaaaa"
|
|
521
|
-
const depositToken = "0xbbbb...bbbbbb" // token from vault
|
|
522
|
-
|
|
523
|
-
// First, get the actual token and approve it
|
|
524
|
-
const actualToken = await getActualDepositToken(depositToken, web3Provider);
|
|
525
|
-
await approveToken(accountAddress, actualToken, vaultAddress, web3Provider, dex);
|
|
526
|
-
|
|
527
|
-
const amount0 = 100
|
|
528
|
-
const amount1 = 0
|
|
529
|
-
|
|
530
|
-
const txnDetails = await depositWithHtsWrapping(
|
|
531
|
-
accountAddress,
|
|
532
|
-
amount0,
|
|
533
|
-
amount1,
|
|
534
|
-
vaultAddress,
|
|
535
|
-
web3Provider,
|
|
536
|
-
dex,
|
|
537
|
-
1 // acceptable slippage (percent)
|
|
538
|
-
)
|
|
539
|
-
```
|
|
540
|
-
|
|
541
|
-
#### 8e. `withdrawWithErc20Wrapping()` - Bonzo on Hedera Only
|
|
542
|
-
|
|
543
|
-
| param | type | default | required
|
|
544
|
-
| -------- | -------- | -------- | --------
|
|
545
|
-
| accountAddress | string | - | true
|
|
546
|
-
| shares | string \| number \| BigNumber | - | true
|
|
547
|
-
| vaultAddress | string | - | true
|
|
548
|
-
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
|
549
|
-
| dex | SupportedDex | - | true
|
|
550
|
-
| percentSlippage | number | 1 | false
|
|
551
|
-
| overrides | [Overrides](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/contracts/lib/index.d.ts#L7) | undefined | false
|
|
552
|
-
|
|
553
|
-
<br/>
|
|
554
|
-
|
|
555
|
-
> **Note:** This function is only available for Bonzo vaults on the Hedera chain. Using it with other vaults or chains will throw an error.
|
|
556
|
-
|
|
557
|
-
This function facilitates withdrawals from Bonzo vaults on Hedera with automatic unwrapping of HTS tokens to their ERC20 counterparts. If the vault tokens are HTS wrapped, they will be automatically converted to ERC20 tokens during withdrawal. Ensure to use the `approveVaultToken()` function before invoking this function.
|
|
558
|
-
|
|
559
|
-
```typescript
|
|
560
|
-
import { Web3Provider } from '@ethersproject/providers';
|
|
561
|
-
import { getUserBalance, withdrawWithErc20Wrapping, approveVaultToken, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
|
562
|
-
|
|
563
|
-
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
|
564
|
-
const vaultAddress = "0x3ac9...a5f132"
|
|
565
|
-
const dex = SupportedDex.Bonzo
|
|
566
|
-
const accountAddress = "0xaaaa...aaaaaa"
|
|
567
|
-
|
|
568
|
-
const totalUserShares: string = await getUserBalance(
|
|
569
|
-
accountAddress,
|
|
570
|
-
vaultAddress,
|
|
571
|
-
web3Provider,
|
|
572
|
-
dex
|
|
573
|
-
)
|
|
574
|
-
|
|
575
|
-
let shares = Number(totalUserShares) * 0.5 // 50% of user share balance
|
|
576
|
-
|
|
577
|
-
// Approve vault tokens first
|
|
578
|
-
await approveVaultToken(accountAddress, vaultAddress, web3Provider, dex, shares);
|
|
579
|
-
|
|
580
|
-
const txnDetails = await withdrawWithErc20Wrapping(
|
|
581
|
-
accountAddress,
|
|
582
|
-
shares,
|
|
583
|
-
vaultAddress,
|
|
584
|
-
web3Provider,
|
|
585
|
-
dex,
|
|
586
|
-
1 // acceptable slippage (percent)
|
|
587
|
-
)
|
|
588
|
-
```
|
|
589
|
-
|
|
590
444
|
#### 9. `isDepositTokenApproved()`
|
|
591
445
|
|
|
592
446
|
| param | type | default | required
|
|
@@ -1446,7 +1300,6 @@ enum SupportedDex {
|
|
|
1446
1300
|
Linehub = 'Linehub',
|
|
1447
1301
|
Lynex = 'Lynex',
|
|
1448
1302
|
Metavault = 'Metavault',
|
|
1449
|
-
Nest = 'Nest',
|
|
1450
1303
|
Nile = 'Nile',
|
|
1451
1304
|
Ocelex = 'Ocelex',
|
|
1452
1305
|
Pancakeswap = 'PancakeSwap',
|