@ichidao/ichi-vaults-sdk 0.0.1
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 +420 -0
- package/dist/abis/types/DepositGuard.d.ts +114 -0
- package/dist/abis/types/DepositGuard.js +3 -0
- package/dist/abis/types/DepositGuard.js.map +1 -0
- package/dist/abis/types/ERC20.d.ts +168 -0
- package/dist/abis/types/ERC20.js +3 -0
- package/dist/abis/types/ERC20.js.map +1 -0
- package/dist/abis/types/IchiVault.d.ts +828 -0
- package/dist/abis/types/IchiVault.js +3 -0
- package/dist/abis/types/IchiVault.js.map +1 -0
- package/dist/abis/types/common.d.ts +22 -0
- package/dist/abis/types/common.js +3 -0
- package/dist/abis/types/common.js.map +1 -0
- package/dist/abis/types/factories/DepositGuard__factory.d.ts +139 -0
- package/dist/abis/types/factories/DepositGuard__factory.js +191 -0
- package/dist/abis/types/factories/DepositGuard__factory.js.map +1 -0
- package/dist/abis/types/factories/ERC20__factory.d.ts +175 -0
- package/dist/abis/types/factories/ERC20__factory.js +243 -0
- package/dist/abis/types/factories/ERC20__factory.js.map +1 -0
- package/dist/abis/types/factories/IchiVault__factory.d.ts +899 -0
- package/dist/abis/types/factories/IchiVault__factory.js +1168 -0
- package/dist/abis/types/factories/IchiVault__factory.js.map +1 -0
- package/dist/abis/types/factories/index.d.ts +3 -0
- package/dist/abis/types/factories/index.js +13 -0
- package/dist/abis/types/factories/index.js.map +1 -0
- package/dist/abis/types/index.d.ts +7 -0
- package/dist/abis/types/index.js +34 -0
- package/dist/abis/types/index.js.map +1 -0
- package/dist/src/__tests__/index.test.d.ts +1 -0
- package/dist/src/__tests__/index.test.js +238 -0
- package/dist/src/__tests__/index.test.js.map +1 -0
- package/dist/src/abis/IchiVault.json +1147 -0
- package/dist/src/abis/types/DepositGuard.d.ts +114 -0
- package/dist/src/abis/types/ERC20.d.ts +168 -0
- package/dist/src/abis/types/IchiVault.d.ts +828 -0
- package/dist/src/abis/types/common.d.ts +22 -0
- package/dist/src/abis/types/factories/DepositGuard__factory.d.ts +139 -0
- package/dist/src/abis/types/factories/ERC20__factory.d.ts +175 -0
- package/dist/src/abis/types/factories/IchiVault__factory.d.ts +899 -0
- package/dist/src/abis/types/factories/index.d.ts +3 -0
- package/dist/src/abis/types/index.d.ts +7 -0
- package/dist/src/contracts/index.d.ts +6 -0
- package/dist/src/contracts/index.js +22 -0
- package/dist/src/contracts/index.js.map +1 -0
- package/dist/src/functions/balances.d.ts +12 -0
- package/dist/src/functions/balances.js +227 -0
- package/dist/src/functions/balances.js.map +1 -0
- package/dist/src/functions/deposit.d.ts +9 -0
- package/dist/src/functions/deposit.js +260 -0
- package/dist/src/functions/deposit.js.map +1 -0
- package/dist/src/functions/vault.d.ts +3 -0
- package/dist/src/functions/vault.js +96 -0
- package/dist/src/functions/vault.js.map +1 -0
- package/dist/src/functions/withdraw.d.ts +5 -0
- package/dist/src/functions/withdraw.js +102 -0
- package/dist/src/functions/withdraw.js.map +1 -0
- package/dist/src/index.cjs.js +18 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.esm.js +16 -0
- package/dist/src/index.js +23 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/src/__tests__/index.test.d.ts +1 -0
- package/dist/src/src/contracts/index.d.ts +6 -0
- package/dist/src/src/functions/balances.d.ts +12 -0
- package/dist/src/src/functions/deposit.d.ts +9 -0
- package/dist/src/src/functions/vault.d.ts +3 -0
- package/dist/src/src/functions/withdraw.d.ts +5 -0
- package/dist/src/src/index.d.ts +5 -0
- package/dist/src/src/types/calculateGasMargin.d.ts +2 -0
- package/dist/src/src/types/index.d.ts +32 -0
- package/dist/src/src/types/vaultQueryData.d.ts +10 -0
- package/dist/src/src/utils/config/addresses.d.ts +14 -0
- package/dist/src/src/utils/formatBigInt.d.ts +2 -0
- package/dist/src/src/utils/parseBigInt.d.ts +2 -0
- package/dist/src/src/utils/positionKey.d.ts +2 -0
- package/dist/src/types/calculateGasMargin.d.ts +2 -0
- package/dist/src/types/calculateGasMargin.js +8 -0
- package/dist/src/types/calculateGasMargin.js.map +1 -0
- package/dist/src/types/index.d.ts +32 -0
- package/dist/src/types/index.js +18 -0
- package/dist/src/types/index.js.map +1 -0
- package/dist/src/types/vaultQueryData.d.ts +10 -0
- package/dist/src/types/vaultQueryData.js +3 -0
- package/dist/src/types/vaultQueryData.js.map +1 -0
- package/dist/src/utils/config/addresses.d.ts +14 -0
- package/dist/src/utils/config/addresses.js +41 -0
- package/dist/src/utils/config/addresses.js.map +1 -0
- package/dist/src/utils/formatBigInt.d.ts +2 -0
- package/dist/src/utils/formatBigInt.js +12 -0
- package/dist/src/utils/formatBigInt.js.map +1 -0
- package/dist/src/utils/parseBigInt.d.ts +2 -0
- package/dist/src/utils/parseBigInt.js +12 -0
- package/dist/src/utils/parseBigInt.js.map +1 -0
- package/dist/src/utils/positionKey.d.ts +2 -0
- package/dist/src/utils/positionKey.js +8 -0
- package/dist/src/utils/positionKey.js.map +1 -0
- package/package.json +98 -0
package/README.md
ADDED
@@ -0,0 +1,420 @@
|
|
1
|
+

|
2
|
+
# @ichidao/ichi-vaults-sdk
|
3
|
+

|
4
|
+
|
5
|
+
This sdk contains collection of functions to interact with IchiVault's smart contract.
|
6
|
+
|
7
|
+
## Table of Contents
|
8
|
+
|
9
|
+
* [__Installation__](#Installation)
|
10
|
+
* [__Usage__](#Usage)
|
11
|
+
* [__Vault Functions__](#Vault)
|
12
|
+
* [`isDepositTokenApproved()`](#1-isDepositTokenApproved)
|
13
|
+
* [`approveDepositToken()`](#2-approveDepositToken)
|
14
|
+
* [`isTokenAllowed()`](#3-isTokenAllowed)
|
15
|
+
* [`getMaxDepositAmount()`](#4-getMaxDepositAmount)
|
16
|
+
* [`deposit()`](#5-depositLP)
|
17
|
+
* [`getUserBalance()`](#6-getUserBalance)
|
18
|
+
* [`getUserAmounts()`](#7-getUserAmounts)
|
19
|
+
* [`getTotalSupply()`](#8-getTotalSupply)
|
20
|
+
* [`getTotalAmounts()`](#9-getTotalAmounts)
|
21
|
+
* [`withdraw()`](#10-withdraw)
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
## Installation
|
26
|
+
Install with
|
27
|
+
```bash
|
28
|
+
yarn add @ichidao/ichi-vaults-sdk
|
29
|
+
```
|
30
|
+
or
|
31
|
+
```bash
|
32
|
+
npm install @ichidao/ichi-vaults-sdk
|
33
|
+
```
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
### Vault
|
37
|
+
|
38
|
+
#### 1. `isDepositTokenApproved()`
|
39
|
+
|
40
|
+
| param | type | default | required
|
41
|
+
| -------- | -------- | -------- | --------
|
42
|
+
| accountAddress | string | - | true
|
43
|
+
| tokenIdx | 0 \| 1 | - | true
|
44
|
+
| amount | string \| number, | - | true |
|
45
|
+
| vaultAddress | string | - | true |
|
46
|
+
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
47
|
+
| dex | SupportedDex | - | true |
|
48
|
+
|
49
|
+
<br/>
|
50
|
+
|
51
|
+
```typescript
|
52
|
+
import { Web3Provider } from '@ethersproject/providers';
|
53
|
+
import { isDepositTokenApproved, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
54
|
+
|
55
|
+
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
56
|
+
const vaultAddress = "0x3ac9...a5f132"
|
57
|
+
const accountAddress = "0xaaaa...aaaaaa"
|
58
|
+
const amount = 100
|
59
|
+
const dex = SupportedDex.UniswapV3
|
60
|
+
|
61
|
+
const isToken0Approved: boolean = await isDepositTokenApproved(
|
62
|
+
accountAddress,
|
63
|
+
0, // token idx can be 0 or 1
|
64
|
+
amount,
|
65
|
+
vaultAddress,
|
66
|
+
web3Provider,
|
67
|
+
dex
|
68
|
+
)
|
69
|
+
```
|
70
|
+
|
71
|
+
#### 2. `approveDepositToken()`
|
72
|
+
|
73
|
+
| param | type | default | required
|
74
|
+
| -------- | -------- | -------- | --------
|
75
|
+
| accountAddress | string | - | true
|
76
|
+
| tokenIdx | 0 \| 1 | - | true
|
77
|
+
| vaultAddress | string | - | true |
|
78
|
+
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
79
|
+
| dex | SupportedDex | - | true |
|
80
|
+
| amount | string \| number | undefined | false |
|
81
|
+
| overrides | [Overrides](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/contracts/lib/index.d.ts#L7) | undefined | false
|
82
|
+
|
83
|
+
<br/>
|
84
|
+
|
85
|
+
```typescript
|
86
|
+
import { Web3Provider } from '@ethersproject/providers';
|
87
|
+
import { approveDepositToken, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
88
|
+
|
89
|
+
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
90
|
+
const vaultAddress = "0x3ac9...a5f132"
|
91
|
+
const accountAddress = "0xaaaa...aaaaaa"
|
92
|
+
const amount = 100
|
93
|
+
const dex = SupportedDex.UniswapV3
|
94
|
+
|
95
|
+
const txnDetails = await approveDepositToken(
|
96
|
+
accountAddress,
|
97
|
+
0, // token idx can be 0 or 1
|
98
|
+
vaultAddress,
|
99
|
+
web3Provider,
|
100
|
+
dex,
|
101
|
+
amount // (optional)
|
102
|
+
);
|
103
|
+
|
104
|
+
await txnDetails.wait();
|
105
|
+
|
106
|
+
// can now deposit token0
|
107
|
+
// ...
|
108
|
+
```
|
109
|
+
|
110
|
+
#### 3. `isTokenAllowed()`
|
111
|
+
|
112
|
+
| param | type | default | required
|
113
|
+
| -------- | -------- | -------- | --------
|
114
|
+
| tokenIdx | 0 \| 1 | - | true
|
115
|
+
| vaultAddress | string | - | true |
|
116
|
+
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
117
|
+
| dex | SupportedDex | - | true |
|
118
|
+
|
119
|
+
<br/>
|
120
|
+
|
121
|
+
```typescript
|
122
|
+
import { Web3Provider } from '@ethersproject/providers';
|
123
|
+
import { isTokenAllowed, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
124
|
+
|
125
|
+
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
126
|
+
const vaultAddress = "0x3ac9...a5f132"
|
127
|
+
const dex = SupportedDex.UniswapV3
|
128
|
+
|
129
|
+
const isAllowed = await isTokenAllowed(
|
130
|
+
0, // token idx can be 0 or 1
|
131
|
+
vaultAddress,
|
132
|
+
web3Provider,
|
133
|
+
dex
|
134
|
+
)
|
135
|
+
|
136
|
+
```
|
137
|
+
|
138
|
+
#### 4. `getMaxDepositAmount()`
|
139
|
+
|
140
|
+
| param | type | default | required
|
141
|
+
| -------- | -------- | -------- | --------
|
142
|
+
| tokenIdx | 0 \| 1 | - | true
|
143
|
+
| vaultAddress | string | - | true |
|
144
|
+
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
145
|
+
| dex | SupportedDex | - | true |
|
146
|
+
|
147
|
+
<br/>
|
148
|
+
|
149
|
+
```typescript
|
150
|
+
import { Web3Provider } from '@ethersproject/providers';
|
151
|
+
import { getMaxDepositAmount, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
152
|
+
|
153
|
+
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
154
|
+
const vaultAddress = "0x3ac9...a5f132"
|
155
|
+
const dex = SupportedDex.UniswapV3
|
156
|
+
|
157
|
+
const maxAmount = await getMaxDepositAmount(
|
158
|
+
0, // token idx can be 0 or 1
|
159
|
+
vaultAddress,
|
160
|
+
web3Provider,
|
161
|
+
dex
|
162
|
+
)
|
163
|
+
|
164
|
+
```
|
165
|
+
|
166
|
+
#### 5. `deposit()`
|
167
|
+
|
168
|
+
| param | type | default | required
|
169
|
+
| -------- | -------- | -------- | --------
|
170
|
+
| accountAddress | string | - | true
|
171
|
+
| amount0 | string \| number | - | true
|
172
|
+
| amount1 | string \| number | - | true
|
173
|
+
| vaultAddress | string | - | true
|
174
|
+
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
175
|
+
| dex | SupportedDex | - | true
|
176
|
+
| percentSlippage | number | 1 | false
|
177
|
+
| overrides | [Overrides](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/contracts/lib/index.d.ts#L7) | undefined | false
|
178
|
+
|
179
|
+
<br/>
|
180
|
+
|
181
|
+
```typescript
|
182
|
+
import { Web3Provider } from '@ethersproject/providers';
|
183
|
+
import { deposit, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
184
|
+
|
185
|
+
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
186
|
+
const vaultAddress = "0x3ac9...a5f132"
|
187
|
+
const dex = SupportedDex.UniswapV3
|
188
|
+
const accountAddress = "0xaaaa...aaaaaa"
|
189
|
+
|
190
|
+
const amount0 = 100
|
191
|
+
const amount1 = 0
|
192
|
+
|
193
|
+
const txnDetails = await deposit(
|
194
|
+
accountAddress,
|
195
|
+
amount0, // can be 0 when only depositing amount1
|
196
|
+
amount1, // can be 0 when only depositing amount0
|
197
|
+
vaultAddress,
|
198
|
+
web3Provider,
|
199
|
+
dex,
|
200
|
+
1 // acceptable slippage (percents)
|
201
|
+
)
|
202
|
+
```
|
203
|
+
|
204
|
+
#### 6. `getUserBalance()`
|
205
|
+
|
206
|
+
| param | type | default | required
|
207
|
+
| -------- | -------- | -------- | --------
|
208
|
+
| accountAddress | string | - | true |
|
209
|
+
| vaultAddress | string | - | true |
|
210
|
+
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
211
|
+
| dex | SupportedDex | - | true
|
212
|
+
| raw | true | undefined | false |
|
213
|
+
|
214
|
+
<br/>
|
215
|
+
|
216
|
+
```typescript
|
217
|
+
import { Web3Provider } from '@ethersproject/providers';
|
218
|
+
import { getUserBalance, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
219
|
+
|
220
|
+
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
221
|
+
const vaultAddress = "0x3ac9...a5f132"
|
222
|
+
const dex = SupportedDex.UniswapV3
|
223
|
+
const accountAddress = "0xaaaa...aaaaaa"
|
224
|
+
|
225
|
+
const shares: string = await getUserBalance(
|
226
|
+
accountAddress,
|
227
|
+
vaultAddress,
|
228
|
+
web3Provider
|
229
|
+
dex
|
230
|
+
)
|
231
|
+
|
232
|
+
// - or -
|
233
|
+
|
234
|
+
const sharesBN: BigNumber = await getUserBalance(
|
235
|
+
accountAddress,
|
236
|
+
vaultAddress,
|
237
|
+
web3Provider
|
238
|
+
dex,
|
239
|
+
true
|
240
|
+
)
|
241
|
+
```
|
242
|
+
|
243
|
+
#### 7. `getUserAmounts()`
|
244
|
+
|
245
|
+
| param | type | default | required
|
246
|
+
| -------- | -------- | -------- | --------
|
247
|
+
| accountAddress | string | - | true |
|
248
|
+
| vaultAddress | string | - | true |
|
249
|
+
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
250
|
+
| dex | SupportedDex | - | true
|
251
|
+
| raw | true | undefined | false |
|
252
|
+
|
253
|
+
<br/>
|
254
|
+
|
255
|
+
```typescript
|
256
|
+
import { Web3Provider } from '@ethersproject/providers';
|
257
|
+
import { getUserAmounts, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
258
|
+
|
259
|
+
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
260
|
+
const vaultAddress = "0x3ac9...a5f132"
|
261
|
+
const dex = SupportedDex.UniswapV3
|
262
|
+
const accountAddress = "0xaaaa...aaaaaa"
|
263
|
+
|
264
|
+
const amounts: [string, string] & {amount0: string, amount1: string} = await getUserAmounts(
|
265
|
+
accountAddress,
|
266
|
+
vaultAddress,
|
267
|
+
web3Provider
|
268
|
+
dex,
|
269
|
+
)
|
270
|
+
|
271
|
+
// - or -
|
272
|
+
|
273
|
+
const amountsBN: [BigNumber, BigNumber] & {amount0: BigNumber, amount1: BigNumber} = await getUserAmounts(
|
274
|
+
accountAddress,
|
275
|
+
vaultAddress,
|
276
|
+
web3Provider
|
277
|
+
dex,
|
278
|
+
true
|
279
|
+
)
|
280
|
+
```
|
281
|
+
|
282
|
+
#### 8. `getTotalSupply()`
|
283
|
+
|
284
|
+
| param | type | default | required
|
285
|
+
| -------- | -------- | -------- | --------
|
286
|
+
| vaultAddress | string | - | true |
|
287
|
+
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
288
|
+
| dex | SupportedDex | - | true
|
289
|
+
| raw | true | undefined | false |
|
290
|
+
|
291
|
+
<br/>
|
292
|
+
|
293
|
+
```typescript
|
294
|
+
import { Web3Provider } from '@ethersproject/providers';
|
295
|
+
import { getTotalSupply, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
296
|
+
|
297
|
+
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
298
|
+
const vaultAddress = "0x3ac9...a5f132"
|
299
|
+
const dex = SupportedDex.UniswapV3
|
300
|
+
|
301
|
+
const shares: string = await getTotalSupply(
|
302
|
+
accountAddress,
|
303
|
+
vaultAddress,
|
304
|
+
web3Provider
|
305
|
+
dex,
|
306
|
+
)
|
307
|
+
|
308
|
+
// - or -
|
309
|
+
|
310
|
+
const sharesBN: BigNumber = await getTotalSupply(
|
311
|
+
accountAddress,
|
312
|
+
vaultAddress,
|
313
|
+
web3Provider
|
314
|
+
dex,
|
315
|
+
true
|
316
|
+
)
|
317
|
+
```
|
318
|
+
|
319
|
+
#### 9. `getTotalAmounts()`
|
320
|
+
|
321
|
+
| param | type | default | required
|
322
|
+
| -------- | -------- | -------- | --------
|
323
|
+
| vaultAddress | string | - | true |
|
324
|
+
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
325
|
+
| dex | SupportedDex | - | true
|
326
|
+
| raw | true | undefined | false |
|
327
|
+
|
328
|
+
<br/>
|
329
|
+
|
330
|
+
```typescript
|
331
|
+
import { Web3Provider } from '@ethersproject/providers';
|
332
|
+
import { getTotalAmounts, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
333
|
+
|
334
|
+
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
335
|
+
const vaultAddress = "0x3ac9...a5f132"
|
336
|
+
const dex = SupportedDex.UniswapV3
|
337
|
+
const accountAddress = "0xaaaa...aaaaaa"
|
338
|
+
|
339
|
+
const amounts: [string, string] & {total0: string, total1: string} = await getTotalAmounts(
|
340
|
+
accountAddress,
|
341
|
+
vaultAddress,
|
342
|
+
web3Provider
|
343
|
+
dex,
|
344
|
+
)
|
345
|
+
|
346
|
+
// - or -
|
347
|
+
|
348
|
+
const amountsBN: [BigNumber, BigNumber] & {total0: BigNumber, total1: BigNumber} = await getTotalAmounts(
|
349
|
+
accountAddress,
|
350
|
+
vaultAddress,
|
351
|
+
web3Provider
|
352
|
+
dex,
|
353
|
+
true
|
354
|
+
)
|
355
|
+
```
|
356
|
+
|
357
|
+
#### 10. `withdraw()`
|
358
|
+
|
359
|
+
| param | type | default | required
|
360
|
+
| -------- | -------- | -------- | --------
|
361
|
+
| accountAddress | string | - | true
|
362
|
+
| shares | string \| number | - | true
|
363
|
+
| vaultAddress | string | - | true
|
364
|
+
| jsonProvider | [JsonRpcProvider](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/providers/src.ts/json-rpc-provider.ts#L393) | - | true
|
365
|
+
| dex | SupportedDex | - | true
|
366
|
+
| overrides | [Overrides](https://github.com/ethers-io/ethers.js/blob/f97b92bbb1bde22fcc44100af78d7f31602863ab/packages/contracts/lib/index.d.ts#L7) | undefined | false
|
367
|
+
|
368
|
+
<br/>
|
369
|
+
|
370
|
+
```typescript
|
371
|
+
import { Web3Provider } from '@ethersproject/providers';
|
372
|
+
import { getUserBalance, withdraw, SupportedDex } from '@ichidao/ichi-vaults-sdk';
|
373
|
+
|
374
|
+
const web3Provider = new Web3Provider(YOUR_WEB3_PROVIDER);
|
375
|
+
const vaultAddress = "0x3ac9...a5f132"
|
376
|
+
const dex = SupportedDex.UniswapV3
|
377
|
+
const accountAddress = "0xaaaa...aaaaaa"
|
378
|
+
|
379
|
+
const totalUserShares: string = await getUserBalance(
|
380
|
+
accountAddress,
|
381
|
+
vaultAddress,
|
382
|
+
web3Provider
|
383
|
+
dex,
|
384
|
+
)
|
385
|
+
|
386
|
+
let shares = Number(totalUserShare) * 0.5 // 50% of user deshare balance
|
387
|
+
|
388
|
+
const txnDetails = await withdraw(
|
389
|
+
accountAddress,
|
390
|
+
shares,
|
391
|
+
vaultAddress,
|
392
|
+
web3Provider,
|
393
|
+
dex
|
394
|
+
)
|
395
|
+
```
|
396
|
+
|
397
|
+
|
398
|
+
|
399
|
+
## Types
|
400
|
+
|
401
|
+
### SupportedChainId
|
402
|
+
|
403
|
+
```typescript
|
404
|
+
enum SupportedChainId {
|
405
|
+
arbitrum = 42161,
|
406
|
+
mainnet = 1,
|
407
|
+
polygon = 137,
|
408
|
+
bsc = 56,
|
409
|
+
}
|
410
|
+
```
|
411
|
+
|
412
|
+
### SupportedDex
|
413
|
+
|
414
|
+
```typescript
|
415
|
+
enum SupportedDex {
|
416
|
+
UniswapV3,
|
417
|
+
Retro,
|
418
|
+
Pancakeswap,
|
419
|
+
}
|
420
|
+
```
|
@@ -0,0 +1,114 @@
|
|
1
|
+
import type { BaseContract, BigNumber, BigNumberish, BytesLike, CallOverrides, ContractTransaction, Overrides, PopulatedTransaction, Signer, utils } from "ethers";
|
2
|
+
import type { FunctionFragment, Result, EventFragment } from "@ethersproject/abi";
|
3
|
+
import type { Listener, Provider } from "@ethersproject/providers";
|
4
|
+
import type { TypedEventFilter, TypedEvent, TypedListener, OnEvent, PromiseOrValue } from "./common";
|
5
|
+
export interface DepositGuardInterface extends utils.Interface {
|
6
|
+
functions: {
|
7
|
+
"ICHIVaultFactory()": FunctionFragment;
|
8
|
+
"forwardDepositToICHIVault(address,address,address,uint256,uint256,address)": FunctionFragment;
|
9
|
+
"vaultKey(address,address,address,uint24,bool,bool)": FunctionFragment;
|
10
|
+
};
|
11
|
+
getFunction(nameOrSignatureOrTopic: "ICHIVaultFactory" | "forwardDepositToICHIVault" | "vaultKey"): FunctionFragment;
|
12
|
+
encodeFunctionData(functionFragment: "ICHIVaultFactory", values?: undefined): string;
|
13
|
+
encodeFunctionData(functionFragment: "forwardDepositToICHIVault", values: [
|
14
|
+
PromiseOrValue<string>,
|
15
|
+
PromiseOrValue<string>,
|
16
|
+
PromiseOrValue<string>,
|
17
|
+
PromiseOrValue<BigNumberish>,
|
18
|
+
PromiseOrValue<BigNumberish>,
|
19
|
+
PromiseOrValue<string>
|
20
|
+
]): string;
|
21
|
+
encodeFunctionData(functionFragment: "vaultKey", values: [
|
22
|
+
PromiseOrValue<string>,
|
23
|
+
PromiseOrValue<string>,
|
24
|
+
PromiseOrValue<string>,
|
25
|
+
PromiseOrValue<BigNumberish>,
|
26
|
+
PromiseOrValue<boolean>,
|
27
|
+
PromiseOrValue<boolean>
|
28
|
+
]): string;
|
29
|
+
decodeFunctionResult(functionFragment: "ICHIVaultFactory", data: BytesLike): Result;
|
30
|
+
decodeFunctionResult(functionFragment: "forwardDepositToICHIVault", data: BytesLike): Result;
|
31
|
+
decodeFunctionResult(functionFragment: "vaultKey", data: BytesLike): Result;
|
32
|
+
events: {
|
33
|
+
"Deployed(address)": EventFragment;
|
34
|
+
"DepositForwarded(address,address,address,uint256,uint256,address)": EventFragment;
|
35
|
+
};
|
36
|
+
getEvent(nameOrSignatureOrTopic: "Deployed"): EventFragment;
|
37
|
+
getEvent(nameOrSignatureOrTopic: "DepositForwarded"): EventFragment;
|
38
|
+
}
|
39
|
+
export interface DeployedEventObject {
|
40
|
+
_ICHIVaultFactory: string;
|
41
|
+
}
|
42
|
+
export type DeployedEvent = TypedEvent<[string], DeployedEventObject>;
|
43
|
+
export type DeployedEventFilter = TypedEventFilter<DeployedEvent>;
|
44
|
+
export interface DepositForwardedEventObject {
|
45
|
+
sender: string;
|
46
|
+
vault: string;
|
47
|
+
token: string;
|
48
|
+
amount: BigNumber;
|
49
|
+
shares: BigNumber;
|
50
|
+
to: string;
|
51
|
+
}
|
52
|
+
export type DepositForwardedEvent = TypedEvent<[
|
53
|
+
string,
|
54
|
+
string,
|
55
|
+
string,
|
56
|
+
BigNumber,
|
57
|
+
BigNumber,
|
58
|
+
string
|
59
|
+
], DepositForwardedEventObject>;
|
60
|
+
export type DepositForwardedEventFilter = TypedEventFilter<DepositForwardedEvent>;
|
61
|
+
export interface DepositGuard extends BaseContract {
|
62
|
+
connect(signerOrProvider: Signer | Provider | string): this;
|
63
|
+
attach(addressOrName: string): this;
|
64
|
+
deployed(): Promise<this>;
|
65
|
+
interface: DepositGuardInterface;
|
66
|
+
queryFilter<TEvent extends TypedEvent>(event: TypedEventFilter<TEvent>, fromBlockOrBlockhash?: string | number | undefined, toBlock?: string | number | undefined): Promise<Array<TEvent>>;
|
67
|
+
listeners<TEvent extends TypedEvent>(eventFilter?: TypedEventFilter<TEvent>): Array<TypedListener<TEvent>>;
|
68
|
+
listeners(eventName?: string): Array<Listener>;
|
69
|
+
removeAllListeners<TEvent extends TypedEvent>(eventFilter: TypedEventFilter<TEvent>): this;
|
70
|
+
removeAllListeners(eventName?: string): this;
|
71
|
+
off: OnEvent<this>;
|
72
|
+
on: OnEvent<this>;
|
73
|
+
once: OnEvent<this>;
|
74
|
+
removeListener: OnEvent<this>;
|
75
|
+
functions: {
|
76
|
+
ICHIVaultFactory(overrides?: CallOverrides): Promise<[string]>;
|
77
|
+
forwardDepositToICHIVault(vault: PromiseOrValue<string>, vaultDeployer: PromiseOrValue<string>, token: PromiseOrValue<string>, amount: PromiseOrValue<BigNumberish>, minimumProceeds: PromiseOrValue<BigNumberish>, to: PromiseOrValue<string>, overrides?: Overrides & {
|
78
|
+
from?: PromiseOrValue<string>;
|
79
|
+
}): Promise<ContractTransaction>;
|
80
|
+
vaultKey(vaultDeployer: PromiseOrValue<string>, token0: PromiseOrValue<string>, token1: PromiseOrValue<string>, fee: PromiseOrValue<BigNumberish>, allowToken0: PromiseOrValue<boolean>, allowToken1: PromiseOrValue<boolean>, overrides?: CallOverrides): Promise<[string] & {
|
81
|
+
key: string;
|
82
|
+
}>;
|
83
|
+
};
|
84
|
+
ICHIVaultFactory(overrides?: CallOverrides): Promise<string>;
|
85
|
+
forwardDepositToICHIVault(vault: PromiseOrValue<string>, vaultDeployer: PromiseOrValue<string>, token: PromiseOrValue<string>, amount: PromiseOrValue<BigNumberish>, minimumProceeds: PromiseOrValue<BigNumberish>, to: PromiseOrValue<string>, overrides?: Overrides & {
|
86
|
+
from?: PromiseOrValue<string>;
|
87
|
+
}): Promise<ContractTransaction>;
|
88
|
+
vaultKey(vaultDeployer: PromiseOrValue<string>, token0: PromiseOrValue<string>, token1: PromiseOrValue<string>, fee: PromiseOrValue<BigNumberish>, allowToken0: PromiseOrValue<boolean>, allowToken1: PromiseOrValue<boolean>, overrides?: CallOverrides): Promise<string>;
|
89
|
+
callStatic: {
|
90
|
+
ICHIVaultFactory(overrides?: CallOverrides): Promise<string>;
|
91
|
+
forwardDepositToICHIVault(vault: PromiseOrValue<string>, vaultDeployer: PromiseOrValue<string>, token: PromiseOrValue<string>, amount: PromiseOrValue<BigNumberish>, minimumProceeds: PromiseOrValue<BigNumberish>, to: PromiseOrValue<string>, overrides?: CallOverrides): Promise<BigNumber>;
|
92
|
+
vaultKey(vaultDeployer: PromiseOrValue<string>, token0: PromiseOrValue<string>, token1: PromiseOrValue<string>, fee: PromiseOrValue<BigNumberish>, allowToken0: PromiseOrValue<boolean>, allowToken1: PromiseOrValue<boolean>, overrides?: CallOverrides): Promise<string>;
|
93
|
+
};
|
94
|
+
filters: {
|
95
|
+
"Deployed(address)"(_ICHIVaultFactory?: null): DeployedEventFilter;
|
96
|
+
Deployed(_ICHIVaultFactory?: null): DeployedEventFilter;
|
97
|
+
"DepositForwarded(address,address,address,uint256,uint256,address)"(sender?: PromiseOrValue<string> | null, vault?: PromiseOrValue<string> | null, token?: PromiseOrValue<string> | null, amount?: null, shares?: null, to?: null): DepositForwardedEventFilter;
|
98
|
+
DepositForwarded(sender?: PromiseOrValue<string> | null, vault?: PromiseOrValue<string> | null, token?: PromiseOrValue<string> | null, amount?: null, shares?: null, to?: null): DepositForwardedEventFilter;
|
99
|
+
};
|
100
|
+
estimateGas: {
|
101
|
+
ICHIVaultFactory(overrides?: CallOverrides): Promise<BigNumber>;
|
102
|
+
forwardDepositToICHIVault(vault: PromiseOrValue<string>, vaultDeployer: PromiseOrValue<string>, token: PromiseOrValue<string>, amount: PromiseOrValue<BigNumberish>, minimumProceeds: PromiseOrValue<BigNumberish>, to: PromiseOrValue<string>, overrides?: Overrides & {
|
103
|
+
from?: PromiseOrValue<string>;
|
104
|
+
}): Promise<BigNumber>;
|
105
|
+
vaultKey(vaultDeployer: PromiseOrValue<string>, token0: PromiseOrValue<string>, token1: PromiseOrValue<string>, fee: PromiseOrValue<BigNumberish>, allowToken0: PromiseOrValue<boolean>, allowToken1: PromiseOrValue<boolean>, overrides?: CallOverrides): Promise<BigNumber>;
|
106
|
+
};
|
107
|
+
populateTransaction: {
|
108
|
+
ICHIVaultFactory(overrides?: CallOverrides): Promise<PopulatedTransaction>;
|
109
|
+
forwardDepositToICHIVault(vault: PromiseOrValue<string>, vaultDeployer: PromiseOrValue<string>, token: PromiseOrValue<string>, amount: PromiseOrValue<BigNumberish>, minimumProceeds: PromiseOrValue<BigNumberish>, to: PromiseOrValue<string>, overrides?: Overrides & {
|
110
|
+
from?: PromiseOrValue<string>;
|
111
|
+
}): Promise<PopulatedTransaction>;
|
112
|
+
vaultKey(vaultDeployer: PromiseOrValue<string>, token0: PromiseOrValue<string>, token1: PromiseOrValue<string>, fee: PromiseOrValue<BigNumberish>, allowToken0: PromiseOrValue<boolean>, allowToken1: PromiseOrValue<boolean>, overrides?: CallOverrides): Promise<PopulatedTransaction>;
|
113
|
+
};
|
114
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"DepositGuard.js","sourceRoot":"","sources":["../../../abis/types/DepositGuard.ts"],"names":[],"mappings":""}
|