@galacticcouncil/sdk-next 1.0.0-beta.0 → 1.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 +131 -78
- package/build/aave/AaveClient.d.ts +77 -0
- package/build/aave/AaveUtils.d.ts +78 -0
- package/build/aave/abi/AavePool.d.ts +208 -0
- package/build/aave/abi/AavePoolDataProvider.d.ts +384 -0
- package/build/aave/abi/index.d.ts +2 -0
- package/build/aave/const.d.ts +6 -0
- package/build/aave/index.cjs +1 -0
- package/build/aave/index.d.ts +4 -0
- package/build/aave/index.mjs +1 -0
- package/build/aave/types.d.ts +17 -0
- package/build/api/Papi.d.ts +10 -0
- package/build/api/Watcher.d.ts +11 -0
- package/build/api/index.d.ts +3 -0
- package/build/api/probe.d.ts +26 -0
- package/build/api/provider/index.d.ts +2 -0
- package/build/api/provider/smoldot.d.ts +1 -0
- package/build/api/provider/websocket.d.ts +4 -0
- package/build/{types/client → client}/AssetClient.d.ts +1 -1
- package/build/client/BalanceClient.d.ts +20 -0
- package/build/client/ChainParams.d.ts +9 -0
- package/build/client/index.cjs +1 -0
- package/build/{types/client → client}/index.d.ts +1 -0
- package/build/client/index.mjs +1 -0
- package/build/{types/consts.d.ts → consts.d.ts} +2 -2
- package/build/evm/adapter.d.ts +11 -0
- package/build/evm/chain.d.ts +2 -0
- package/build/evm/client.d.ts +15 -0
- package/build/evm/index.cjs +1 -0
- package/build/evm/index.d.ts +4 -0
- package/build/evm/index.mjs +1 -0
- package/build/evm/types.d.ts +7 -0
- package/build/factory.d.ts +29 -0
- package/build/farm/LiquidityMiningApi.d.ts +29 -0
- package/build/farm/LiquidityMiningClient.d.ts +146 -0
- package/build/farm/MultiCurrencyContainer.d.ts +8 -0
- package/build/farm/RewardClaimSimulator.d.ts +16 -0
- package/build/farm/const.d.ts +4 -0
- package/build/farm/index.cjs +1 -0
- package/build/farm/index.d.ts +3 -0
- package/build/farm/index.mjs +1 -0
- package/build/farm/types.d.ts +46 -0
- package/build/gho/GhoTokenClient.d.ts +6 -0
- package/build/gho/abi.d.ts +124 -0
- package/build/gho/index.d.ts +2 -0
- package/build/index.cjs +1 -1
- package/build/{types/index.d.ts → index.d.ts} +6 -0
- package/build/index.mjs +1 -1
- package/build/oracle/MmOracleClient.d.ts +7 -0
- package/build/oracle/abi.d.ts +196 -0
- package/build/oracle/index.d.ts +3 -0
- package/build/oracle/types.d.ts +5 -0
- package/build/pool/PoolClient.d.ts +75 -0
- package/build/pool/PoolContextProvider.d.ts +41 -0
- package/build/pool/PoolLog.d.ts +11 -0
- package/build/pool/PoolStore.d.ts +20 -0
- package/build/pool/aave/AaveAbi.d.ts +126 -0
- package/build/pool/aave/AavePool.d.ts +24 -0
- package/build/pool/aave/AavePoolClient.d.ts +19 -0
- package/build/pool/aave/index.d.ts +2 -0
- package/build/pool/aave/types.d.ts +13 -0
- package/build/pool/hsm/HsmMath.d.ts +21 -0
- package/build/pool/hsm/HsmPool.d.ts +63 -0
- package/build/pool/hsm/HsmPoolClient.d.ts +26 -0
- package/build/pool/hsm/index.d.ts +3 -0
- package/build/pool/hsm/types.d.ts +7 -0
- package/build/pool/index.cjs +1 -0
- package/build/{types/pool → pool}/index.d.ts +4 -2
- package/build/pool/index.mjs +1 -0
- package/build/{types/pool → pool}/lbp/LbpPool.d.ts +1 -1
- package/build/{types/pool → pool}/lbp/LbpPoolClient.d.ts +9 -7
- package/build/{types/pool → pool}/omni/OmniMath.d.ts +7 -6
- package/build/{types/pool → pool}/omni/OmniPool.d.ts +14 -1
- package/build/pool/omni/OmniPoolClient.d.ts +29 -0
- package/build/pool/omni/types.d.ts +11 -0
- package/build/{types/pool → pool}/stable/StableMath.d.ts +1 -2
- package/build/{types/pool → pool}/stable/StableSwap.d.ts +21 -4
- package/build/pool/stable/StableSwapClient.d.ts +23 -0
- package/build/pool/stable/types.d.ts +15 -0
- package/build/{types/pool → pool}/types.d.ts +14 -3
- package/build/{types/pool → pool}/xyk/XykPool.d.ts +13 -1
- package/build/pool/xyk/XykPoolClient.d.ts +14 -0
- package/build/{types/sor → sor}/Router.d.ts +26 -8
- package/build/sor/TradeRouteBuilder.d.ts +4 -0
- package/build/sor/TradeRouter.d.ts +207 -0
- package/build/sor/TradeScheduler.d.ts +111 -0
- package/build/sor/const.d.ts +8 -0
- package/build/sor/index.cjs +1 -0
- package/build/sor/index.d.ts +6 -0
- package/build/sor/index.mjs +1 -0
- package/build/{types/sor → sor}/route/bfs.d.ts +11 -2
- package/build/{types/sor → sor}/route/index.d.ts +1 -1
- package/build/sor/route/suggester.d.ts +33 -0
- package/build/sor/types.d.ts +68 -0
- package/build/staking/StakingApi.d.ts +66 -0
- package/build/staking/StakingClient.d.ts +132 -0
- package/build/staking/index.cjs +1 -0
- package/build/staking/index.d.ts +2 -0
- package/build/staking/index.mjs +1 -0
- package/build/staking/types.d.ts +16 -0
- package/build/staking/utils.d.ts +1 -0
- package/build/tx/OrderTxBuilder.d.ts +21 -0
- package/build/tx/TradeTxBuilder.d.ts +18 -0
- package/build/tx/TxBuilder.d.ts +19 -0
- package/build/tx/TxBuilderFactory.d.ts +12 -0
- package/build/tx/index.cjs +1 -0
- package/build/tx/index.d.ts +2 -0
- package/build/tx/index.mjs +1 -0
- package/build/tx/types.d.ts +10 -0
- package/build/tx/utils.d.ts +5 -0
- package/build/{types/types.d.ts → types.d.ts} +9 -2
- package/build/utils/QueryBus.d.ts +10 -0
- package/build/utils/async.d.ts +1 -0
- package/build/utils/calc.d.ts +52 -0
- package/build/utils/format.d.ts +11 -0
- package/build/utils/index.cjs +1 -0
- package/build/{types/utils → utils}/index.d.ts +3 -3
- package/build/utils/index.mjs +1 -0
- package/build/{types/utils → utils}/math.d.ts +0 -9
- package/package.json +70 -15
- package/build/types/api/Papi.d.ts +0 -375
- package/build/types/api/client.d.ts +0 -2
- package/build/types/api/index.d.ts +0 -2
- package/build/types/client/BalanceClient.d.ts +0 -17
- package/build/types/pool/PoolClient.d.ts +0 -25
- package/build/types/pool/PoolContextProvider.d.ts +0 -26
- package/build/types/pool/omni/OmniPoolClient.d.ts +0 -13
- package/build/types/pool/stable/StableSwapClient.d.ts +0 -16
- package/build/types/pool/xyk/XykPoolClient.d.ts +0 -12
- package/build/types/sor/TradeRouter.d.ts +0 -155
- package/build/types/sor/TradeUtils.d.ts +0 -12
- package/build/types/sor/index.d.ts +0 -4
- package/build/types/sor/route/suggester.d.ts +0 -24
- package/build/types/sor/types.d.ts +0 -31
- package/build/types/utils/big.d.ts +0 -3
- package/build/types/utils/evm.d.ts +0 -3
- package/build/types/utils/format.d.ts +0 -4
- package/build/types/utils/xc.d.ts +0 -1
- /package/build/{types/errors.d.ts → errors.d.ts} +0 -0
- /package/build/{types/pool → pool}/PoolFactory.d.ts +0 -0
- /package/build/{types/pool → pool}/lbp/LbpMath.d.ts +0 -0
- /package/build/{types/pool → pool}/lbp/index.d.ts +0 -0
- /package/build/{types/pool → pool}/omni/index.d.ts +0 -0
- /package/build/{types/pool → pool}/stable/index.d.ts +0 -0
- /package/build/{types/pool → pool}/xyk/XykMath.d.ts +0 -0
- /package/build/{types/pool → pool}/xyk/index.d.ts +0 -0
- /package/build/{types/sor → sor}/route/graph.d.ts +0 -0
- /package/build/{types/utils → utils}/Queue.d.ts +0 -0
- /package/build/{types/utils → utils}/Stack.d.ts +0 -0
- /package/build/{types/utils → utils}/json.d.ts +0 -0
- /package/build/{types/utils → utils}/traversal/bfs.d.ts +0 -0
package/README.md
CHANGED
|
@@ -2,15 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@galacticcouncil/sdk-next)
|
|
4
4
|
|
|
5
|
-
Next gen
|
|
5
|
+
Next gen Hydration SDK built on top of [Polkadot API (Papi)](https://papi.how/).
|
|
6
6
|
|
|
7
|
-
Table of
|
|
7
|
+
Table of contents:
|
|
8
8
|
|
|
9
9
|
- [Installation](#installation)
|
|
10
|
+
- [Usage](#usage)
|
|
10
11
|
- [Components](#components)
|
|
11
|
-
- [
|
|
12
|
-
- [
|
|
12
|
+
- [api](#api)
|
|
13
|
+
- [client](#client)
|
|
14
|
+
- [ctx](#ctx)
|
|
15
|
+
- [tx](#tx)
|
|
16
|
+
- [API Reference](#api-reference)
|
|
17
|
+
- [AaveUtils](#aaveutils)
|
|
13
18
|
- [TradeRouter](#traderouter)
|
|
19
|
+
- [TradeScheduler](#tradescheduler)
|
|
20
|
+
- [BalanceClient](#balanceclient)
|
|
21
|
+
- [AssetClient](#assetclient)
|
|
22
|
+
- [Examples](#examples)
|
|
14
23
|
|
|
15
24
|
## Installation
|
|
16
25
|
|
|
@@ -18,124 +27,168 @@ Install with [npm](https://www.npmjs.com/):
|
|
|
18
27
|
|
|
19
28
|
`npm install @galacticcouncil/sdk-next`
|
|
20
29
|
|
|
21
|
-
##
|
|
30
|
+
## Usage
|
|
22
31
|
|
|
23
|
-
|
|
32
|
+
Use `createSdkContext` to quickly set up all components of the SDK — pool context, trading logic, client access, and transaction building — in a single call.
|
|
24
33
|
|
|
25
|
-
|
|
34
|
+
```ts
|
|
35
|
+
import { api, createSdkContext } from '@galacticcouncil/sdk-next';
|
|
36
|
+
import { createClient } from 'polkadot-api';
|
|
26
37
|
|
|
27
|
-
|
|
38
|
+
const provider = api.getWs('wss://hydradx-rpc.dwellir.com');
|
|
39
|
+
const client = createClient(provider);
|
|
40
|
+
const sdk = await createSdkContext(client);
|
|
28
41
|
|
|
29
|
-
|
|
42
|
+
// Don't forget to cleanup resources when DONE
|
|
43
|
+
sdk.destroy();
|
|
44
|
+
```
|
|
30
45
|
|
|
31
|
-
|
|
46
|
+
It handles all necessary setup under the hood. Just plug in your PolkadotClient, and you're ready to interact with registry, accounts, pools, router, and more.
|
|
32
47
|
|
|
33
|
-
|
|
34
|
-
import { api, pool } from '@galacticcouncil/sdk-next';
|
|
48
|
+
⚠️ **Note:** Make sure to keep only single instance of context per session.
|
|
35
49
|
|
|
36
|
-
|
|
37
|
-
const ctx = new pool.PoolContextProvider(client)
|
|
38
|
-
.withOmnipool()
|
|
39
|
-
.withStableswap()
|
|
40
|
-
.withXyk();
|
|
50
|
+
## Components
|
|
41
51
|
|
|
42
|
-
|
|
43
|
-
console.log(pools);
|
|
52
|
+
### `api`
|
|
44
53
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
```
|
|
54
|
+
- `aave: AaveUtils` — Aave-related utilities.
|
|
55
|
+
- `router: TradeRouter` — Off-chain optimization of trades across pools for best price execution.
|
|
56
|
+
- `scheduler: TradeScheduler` — Trade orders scheduling.
|
|
49
57
|
|
|
50
|
-
|
|
58
|
+
### `client`
|
|
51
59
|
|
|
52
|
-
|
|
60
|
+
- `asset: AssetClient` — Registry metadata and lookup.
|
|
61
|
+
- `balance: BalanceClient` — Account balance tracking.
|
|
62
|
+
- `evm: EvmClient` — Interacts with EVM.
|
|
53
63
|
|
|
54
|
-
|
|
64
|
+
### `ctx`
|
|
55
65
|
|
|
56
|
-
|
|
66
|
+
- `pool: PoolContextProvider` — Internal stateful pool context. Initialized with support for:
|
|
67
|
+
- Aave
|
|
68
|
+
- Omnipool
|
|
69
|
+
- Stableswap
|
|
70
|
+
- XYK pools
|
|
71
|
+
- LBP pools
|
|
57
72
|
|
|
58
|
-
|
|
73
|
+
### `tx`
|
|
59
74
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
| `getRoutes(assetIn: number, assetOut: number): Hop[][]` | Computes possible routes between two assets. |
|
|
64
|
-
| `getTradeableAssets(): number[]` | Lists all assets that are tradeable through the router. |
|
|
75
|
+
- `TxBuilderFactory` — Factory for generating submittable transaction using fluent APIs.
|
|
76
|
+
|
|
77
|
+
### `destroy()`
|
|
65
78
|
|
|
66
|
-
|
|
79
|
+
Gracefully cleans up SDK resources. Always call before exiting to avoid memory leaks or stale subscriptions.
|
|
67
80
|
|
|
68
|
-
|
|
81
|
+
## API Reference
|
|
69
82
|
|
|
70
|
-
|
|
83
|
+
### AaveUtils
|
|
71
84
|
|
|
72
|
-
| Method | Description
|
|
85
|
+
| Method | Description |
|
|
73
86
|
| :----- | :----------- |
|
|
87
|
+
| `getSummary(user: string): AaveSummary` | Returns market summary. |
|
|
88
|
+
| `getHealthFactor(user: string): number` | Calculate HF. |
|
|
89
|
+
| `getHealthFactorAfterWithdraw(user: string, reserve:number, withdrawAmount: string): number` | Calculate HF after withdraw. |
|
|
90
|
+
| `getHealthFactorAfterSupply(user: string, reserve:number, supplyAmount: string): number` | Calculate HF after supply. |
|
|
91
|
+
| `getMaxWithdraw(user: string, reserve:number): Amount` | Get max possible safe withdraw. |
|
|
92
|
+
|
|
93
|
+
➡️ For type definitions visit [types.ts](src/aave/types.ts)<br />
|
|
94
|
+
|
|
95
|
+
### TradeRouter
|
|
96
|
+
|
|
97
|
+
| Method | Description |
|
|
98
|
+
| :----- | :----------- |
|
|
99
|
+
| `getPools(): PoolBase[]` | Returns the current list of available pools. |
|
|
100
|
+
| `getRoutes(assetIn: number, assetOut: number): Hop[][]` | Computes possible routes between two assets. |
|
|
101
|
+
| `getTradeableAssets(): number[]` | Lists all assets that are tradeable through the router. |
|
|
74
102
|
| `getBestSell(tokenIn: number, tokenOut: number, amountIn: bigint \| string): Trade` | Find the best sell trade for given input amount. |
|
|
75
103
|
| `getBestBuy(tokenIn: number, tokenOut: number, amountOut: bigint \| string): Trade` | Find the best buy trade for given output amount. |
|
|
76
|
-
| `getBuy(tokenIn: number, tokenOut: number, amountOut: bigint \| string, route?: Hop[]): Trade` |
|
|
77
|
-
| `getSell(tokenIn: number, tokenOut: number, amountIn: bigint \| string, route?: Hop[]): Trade` |
|
|
104
|
+
| `getBuy(tokenIn: number, tokenOut: number, amountOut: bigint \| string, route?: Hop[]): Trade` | Calculate a buy using a specific route (optional). |
|
|
105
|
+
| `getSell(tokenIn: number, tokenOut: number, amountIn: bigint \| string, route?: Hop[]): Trade` | Calculate a sell using a specific route (optional). |
|
|
78
106
|
| `getSpotPrice(tokenIn: number, tokenOut: number): Amount` | Get the current spot price between two tokens. |
|
|
79
107
|
| `getMostLiquidRoute(tokenIn: number, tokenOut: number): Hop[]` | Find the route with the highest liquidity between two tokens. |
|
|
80
108
|
|
|
81
|
-
|
|
109
|
+
➡️ For type definitions visit [types.ts](src/sor/types.ts)<br />
|
|
82
110
|
|
|
83
|
-
|
|
111
|
+
### TradeScheduler
|
|
84
112
|
|
|
85
|
-
|
|
113
|
+
| Method | Description |
|
|
114
|
+
| :----- | :----------- |
|
|
115
|
+
| `getDcaOrder(assetIn: number, assetOut: number, amountInTotal: string, duration: number): TradeDcaOrder` | Calculate DCA order. |
|
|
116
|
+
| `getTwapBuyOrder(assetIn: number, assetOut: number, amountInTotal: string): TradeOrder` | Calculate TWAP buy order. |
|
|
117
|
+
| `getTwapSellOrder(assetIn: number, assetOut: number, amountInTotal: string): TradeOrder` | Calculate TWAP sell order. |
|
|
86
118
|
|
|
87
|
-
|
|
88
|
-
import { api, pool, sor } from '@galacticcouncil/sdk-next';
|
|
119
|
+
➡️ For type definitions visit [types.ts](src/sor/types.ts)<br />
|
|
89
120
|
|
|
90
|
-
|
|
91
|
-
const ctx = new pool.PoolContextProvider(client)
|
|
92
|
-
.withOmnipool()
|
|
93
|
-
.withStableswap()
|
|
94
|
-
.withXyk();
|
|
121
|
+
### BalanceClient
|
|
95
122
|
|
|
96
|
-
|
|
97
|
-
|
|
123
|
+
| Method | Description |
|
|
124
|
+
| :----- | :----------- |
|
|
125
|
+
| `watchBalance(address: string): Observable<AssetAmount>` | Subscribe account balance. |
|
|
126
|
+
| `watchSystemBalance(address: string): Observable<AssetAmount>` | Subscribe native account balance. |
|
|
127
|
+
| `watchTokenBalance(address: string, assetId: number): Observable<AssetAmount>` | Subscribe token account balance. |
|
|
128
|
+
| `watchTokensBalance(address: string): Observable<AssetAmount[]>` | Subscribe tokens account balances. |
|
|
129
|
+
| `watchErc20Balance(address: string, includeOnly?: number[]): Observable<AssetAmount[]>` | Subscribe erc20 assets balances |
|
|
98
130
|
|
|
99
|
-
|
|
100
|
-
const tx = await utils.buildSellTx(sell);
|
|
101
|
-
console.log(sell.toHuman());
|
|
102
|
-
console.log('Transaction hash: ' + tx.asHex());
|
|
131
|
+
➡️ For type definitions visit [types.ts](src/types.ts)<br />
|
|
103
132
|
|
|
104
|
-
|
|
105
|
-
ctx.destroy();
|
|
106
|
-
client.destroy();
|
|
107
|
-
```
|
|
133
|
+
### AssetClient
|
|
108
134
|
|
|
109
|
-
|
|
135
|
+
| Method | Description |
|
|
136
|
+
| :----- | :----------- |
|
|
137
|
+
| `getSupported(includeInvalid?: boolean, external?: ExternalAsset[]): Promise<Asset[]>` | Returns assets with metadata from registry. |
|
|
138
|
+
|
|
139
|
+
➡️ For type definitions visit [types.ts](src/types.ts)<br />
|
|
140
|
+
|
|
141
|
+
## Examples
|
|
110
142
|
|
|
111
|
-
|
|
143
|
+
All examples assume SDK has been initialized, [see](#usage)
|
|
112
144
|
|
|
113
|
-
|
|
145
|
+
### TradeRouter
|
|
114
146
|
|
|
115
|
-
|
|
147
|
+
Calculate sell of 1 DOT for HDX & build tx with 5% slippage (default to 1% if not specified)
|
|
116
148
|
|
|
117
149
|
```typescript
|
|
118
|
-
|
|
150
|
+
const { api, tx } = sdk;
|
|
151
|
+
|
|
152
|
+
const trade = await api.router.getBestSell(5, 10, 10_000_000_000n);
|
|
153
|
+
const tradeTx = await tx.trade(trade)
|
|
154
|
+
.withBeneficiary(BENEFICIARY)
|
|
155
|
+
.withSlippage(5)
|
|
156
|
+
.build();
|
|
157
|
+
const tradeCall = await tradeTx.get().getEncodedData();
|
|
158
|
+
console.log(trade.toHuman());
|
|
159
|
+
console.log('Transaction hash:', Binary.toHex(tradeCall));
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Note:** For convenience, the router amount can be specified either as a native bigint or as a human-readable string.
|
|
119
163
|
|
|
120
|
-
|
|
164
|
+
For example, `"1"` DOT (string) is equivalent to `10_000_000_000n` (bigint), as DOT has 10 decimals.
|
|
121
165
|
|
|
122
|
-
|
|
123
|
-
const balanceClient = new c.BalanceClient(client);
|
|
124
|
-
const observable = balanceClient.subscribeBalance(omnipoolAddress);
|
|
125
|
-
const balances = firstValueFrom(observable);
|
|
126
|
-
console.log(balances);
|
|
166
|
+
### BalanceClient
|
|
127
167
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
168
|
+
Subscribe hydration treasury account.
|
|
169
|
+
|
|
170
|
+
```typescript
|
|
171
|
+
const { client } = sdk;
|
|
172
|
+
|
|
173
|
+
const account = "7L53bUTBbfuj14UpdCNPwmgzzHSsrsTWBHX5pys32mVWM3C1"
|
|
174
|
+
const subscription = client.balance
|
|
175
|
+
.watch(account)
|
|
176
|
+
.subscribe((balances) => {
|
|
177
|
+
console.log(balances);
|
|
178
|
+
});
|
|
131
179
|
```
|
|
132
180
|
|
|
133
|
-
|
|
181
|
+
### AssetClient
|
|
182
|
+
|
|
183
|
+
Get default on-chain data.
|
|
134
184
|
|
|
135
|
-
|
|
185
|
+
```typescript
|
|
186
|
+
const { client } = sdk;
|
|
136
187
|
|
|
137
|
-
|
|
188
|
+
const assets = await client.asset.getSupported();
|
|
189
|
+
console.log(assets);
|
|
190
|
+
```
|
|
138
191
|
|
|
139
|
-
|
|
192
|
+
To demonstrate more full working examples on real chain see [script](test/script/examples) section.
|
|
140
193
|
|
|
141
|
-
|
|
194
|
+
Run: `$ npx tsx ./test/script/examples/<examplePackage>/<exampleName>.ts` with valid example package & name.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { EvmClient } from '../evm';
|
|
2
|
+
export declare class AaveClient {
|
|
3
|
+
private client;
|
|
4
|
+
constructor(evm: EvmClient);
|
|
5
|
+
getBlockTimestamp(): Promise<number>;
|
|
6
|
+
getReservesData(): Promise<readonly [readonly {
|
|
7
|
+
underlyingAsset: `0x${string}`;
|
|
8
|
+
name: string;
|
|
9
|
+
symbol: string;
|
|
10
|
+
decimals: bigint;
|
|
11
|
+
baseLTVasCollateral: bigint;
|
|
12
|
+
reserveLiquidationThreshold: bigint;
|
|
13
|
+
reserveLiquidationBonus: bigint;
|
|
14
|
+
reserveFactor: bigint;
|
|
15
|
+
usageAsCollateralEnabled: boolean;
|
|
16
|
+
borrowingEnabled: boolean;
|
|
17
|
+
stableBorrowRateEnabled: boolean;
|
|
18
|
+
isActive: boolean;
|
|
19
|
+
isFrozen: boolean;
|
|
20
|
+
liquidityIndex: bigint;
|
|
21
|
+
variableBorrowIndex: bigint;
|
|
22
|
+
liquidityRate: bigint;
|
|
23
|
+
variableBorrowRate: bigint;
|
|
24
|
+
stableBorrowRate: bigint;
|
|
25
|
+
lastUpdateTimestamp: number;
|
|
26
|
+
aTokenAddress: `0x${string}`;
|
|
27
|
+
stableDebtTokenAddress: `0x${string}`;
|
|
28
|
+
variableDebtTokenAddress: `0x${string}`;
|
|
29
|
+
interestRateStrategyAddress: `0x${string}`;
|
|
30
|
+
availableLiquidity: bigint;
|
|
31
|
+
totalPrincipalStableDebt: bigint;
|
|
32
|
+
averageStableRate: bigint;
|
|
33
|
+
stableDebtLastUpdateTimestamp: bigint;
|
|
34
|
+
totalScaledVariableDebt: bigint;
|
|
35
|
+
priceInMarketReferenceCurrency: bigint;
|
|
36
|
+
priceOracle: `0x${string}`;
|
|
37
|
+
variableRateSlope1: bigint;
|
|
38
|
+
variableRateSlope2: bigint;
|
|
39
|
+
stableRateSlope1: bigint;
|
|
40
|
+
stableRateSlope2: bigint;
|
|
41
|
+
baseStableBorrowRate: bigint;
|
|
42
|
+
baseVariableBorrowRate: bigint;
|
|
43
|
+
optimalUsageRatio: bigint;
|
|
44
|
+
isPaused: boolean;
|
|
45
|
+
isSiloedBorrowing: boolean;
|
|
46
|
+
accruedToTreasury: bigint;
|
|
47
|
+
unbacked: bigint;
|
|
48
|
+
isolationModeTotalDebt: bigint;
|
|
49
|
+
flashLoanEnabled: boolean;
|
|
50
|
+
debtCeiling: bigint;
|
|
51
|
+
debtCeilingDecimals: bigint;
|
|
52
|
+
eModeCategoryId: number;
|
|
53
|
+
borrowCap: bigint;
|
|
54
|
+
supplyCap: bigint;
|
|
55
|
+
eModeLtv: number;
|
|
56
|
+
eModeLiquidationThreshold: number;
|
|
57
|
+
eModeLiquidationBonus: number;
|
|
58
|
+
eModePriceSource: `0x${string}`;
|
|
59
|
+
eModeLabel: string;
|
|
60
|
+
borrowableInIsolation: boolean;
|
|
61
|
+
}[], {
|
|
62
|
+
marketReferenceCurrencyUnit: bigint;
|
|
63
|
+
marketReferenceCurrencyPriceInUsd: bigint;
|
|
64
|
+
networkBaseTokenPriceInUsd: bigint;
|
|
65
|
+
networkBaseTokenPriceDecimals: number;
|
|
66
|
+
}]>;
|
|
67
|
+
getUserReservesData(user: string): Promise<readonly [readonly {
|
|
68
|
+
underlyingAsset: `0x${string}`;
|
|
69
|
+
scaledATokenBalance: bigint;
|
|
70
|
+
usageAsCollateralEnabledOnUser: boolean;
|
|
71
|
+
stableBorrowRate: bigint;
|
|
72
|
+
scaledVariableDebt: bigint;
|
|
73
|
+
principalStableDebt: bigint;
|
|
74
|
+
stableBorrowLastUpdateTimestamp: bigint;
|
|
75
|
+
}[], number]>;
|
|
76
|
+
getUserAccountData(user: string): Promise<readonly [bigint, bigint, bigint, bigint, bigint, bigint]>;
|
|
77
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { AaveSummary } from './types';
|
|
2
|
+
import { EvmClient } from '../evm';
|
|
3
|
+
import { Amount } from '../types';
|
|
4
|
+
export declare class AaveUtils {
|
|
5
|
+
private client;
|
|
6
|
+
constructor(evm: EvmClient);
|
|
7
|
+
getSummary(user: string): Promise<AaveSummary>;
|
|
8
|
+
/**
|
|
9
|
+
* Check if user has active borrow positions
|
|
10
|
+
*
|
|
11
|
+
* @param user - user address
|
|
12
|
+
* @returns true if user has debt, otherwise false
|
|
13
|
+
*/
|
|
14
|
+
hasBorrowPositions(user: string): Promise<boolean>;
|
|
15
|
+
/**
|
|
16
|
+
* Get current user health factor
|
|
17
|
+
*
|
|
18
|
+
* @param user - user address
|
|
19
|
+
* @returns health factor decimal value
|
|
20
|
+
*/
|
|
21
|
+
getHealthFactor(user: string): Promise<number>;
|
|
22
|
+
/**
|
|
23
|
+
* Estimate health factor after aToken withdraw
|
|
24
|
+
*
|
|
25
|
+
* @param user - user address
|
|
26
|
+
* @param reserve - reserve on-chain id (registry)
|
|
27
|
+
* @param withdrawAmount - aToken withdrawAmount amount (decimal)
|
|
28
|
+
* @returns health factor decimal value
|
|
29
|
+
*/
|
|
30
|
+
getHealthFactorAfterWithdraw(user: string, reserve: number, withdrawAmount: string): Promise<number>;
|
|
31
|
+
/**
|
|
32
|
+
* Estimate health factor after reserve supply
|
|
33
|
+
*
|
|
34
|
+
* @param user - user address
|
|
35
|
+
* @param reserve - reserve on-chain id (registry)
|
|
36
|
+
* @param supplyAmount - reserve supply amount (decimal)
|
|
37
|
+
* @returns health factor decimal value
|
|
38
|
+
*/
|
|
39
|
+
getHealthFactorAfterSupply(user: string, reserve: number, supplyAmount: string): Promise<number>;
|
|
40
|
+
/**
|
|
41
|
+
* Estimate health factor after swapping between reserves
|
|
42
|
+
*
|
|
43
|
+
* @param user - user address
|
|
44
|
+
* @param fromAmount - amount to withdraw (decimal)
|
|
45
|
+
* @param fromReserve - reserve on-chain id (registry) to withdraw from
|
|
46
|
+
* @param toAmount - amount to supply (decimal)
|
|
47
|
+
* @param toReserve - reserve on-chain id (registry) to supply to
|
|
48
|
+
* @returns health factor decimal value after swap
|
|
49
|
+
*/
|
|
50
|
+
getHealthFactorAfterSwap(user: string, fromAmount: string, fromReserve: number, toAmount: string, toReserve: number): Promise<number>;
|
|
51
|
+
/**
|
|
52
|
+
* Get MAX withdraw balance for given user reserve
|
|
53
|
+
*
|
|
54
|
+
* @param user - user address
|
|
55
|
+
* @param reserve - reserve on-chain id (registry)
|
|
56
|
+
* @returns aToken max withdrawable balance
|
|
57
|
+
*/
|
|
58
|
+
getMaxWithdraw(user: string, reserve: number): Promise<Amount>;
|
|
59
|
+
/**
|
|
60
|
+
* Get MAX withdraw balances for all user reserves
|
|
61
|
+
*
|
|
62
|
+
* @param user - user address
|
|
63
|
+
* @returns aTokens max withdrawable balances
|
|
64
|
+
*/
|
|
65
|
+
getMaxWithdrawAll(user: string): Promise<Record<number, Amount>>;
|
|
66
|
+
/**
|
|
67
|
+
* Calculate maxWithdraw using following formula:
|
|
68
|
+
*
|
|
69
|
+
* maxWithdraw = (HF - 1.01 x totalDebt) / reserveLT
|
|
70
|
+
*/
|
|
71
|
+
private calculateWithdrawMax;
|
|
72
|
+
private calculateLinearInterest;
|
|
73
|
+
/**
|
|
74
|
+
* Original AAVE health factor calculation formula:
|
|
75
|
+
* @see https://github.com/aave/aave-utilities/blob/432e283b2e76d9793b20d37bd4cb94aca97ed20e/packages/math-utils/src/pool-math.ts#L139
|
|
76
|
+
*/
|
|
77
|
+
private calculateHealthFactorFromBalances;
|
|
78
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
export declare const AAVE_POOL_ABI: readonly [{
|
|
2
|
+
readonly anonymous: false;
|
|
3
|
+
readonly inputs: readonly [{
|
|
4
|
+
readonly indexed: true;
|
|
5
|
+
readonly internalType: "address";
|
|
6
|
+
readonly name: "reserve";
|
|
7
|
+
readonly type: "address";
|
|
8
|
+
}, {
|
|
9
|
+
readonly indexed: false;
|
|
10
|
+
readonly internalType: "address";
|
|
11
|
+
readonly name: "user";
|
|
12
|
+
readonly type: "address";
|
|
13
|
+
}, {
|
|
14
|
+
readonly indexed: true;
|
|
15
|
+
readonly internalType: "address";
|
|
16
|
+
readonly name: "onBehalfOf";
|
|
17
|
+
readonly type: "address";
|
|
18
|
+
}, {
|
|
19
|
+
readonly indexed: false;
|
|
20
|
+
readonly internalType: "uint256";
|
|
21
|
+
readonly name: "amount";
|
|
22
|
+
readonly type: "uint256";
|
|
23
|
+
}, {
|
|
24
|
+
readonly indexed: true;
|
|
25
|
+
readonly internalType: "uint16";
|
|
26
|
+
readonly name: "referralCode";
|
|
27
|
+
readonly type: "uint16";
|
|
28
|
+
}];
|
|
29
|
+
readonly name: "Supply";
|
|
30
|
+
readonly type: "event";
|
|
31
|
+
}, {
|
|
32
|
+
readonly anonymous: false;
|
|
33
|
+
readonly inputs: readonly [{
|
|
34
|
+
readonly indexed: true;
|
|
35
|
+
readonly internalType: "address";
|
|
36
|
+
readonly name: "reserve";
|
|
37
|
+
readonly type: "address";
|
|
38
|
+
}, {
|
|
39
|
+
readonly indexed: true;
|
|
40
|
+
readonly internalType: "address";
|
|
41
|
+
readonly name: "user";
|
|
42
|
+
readonly type: "address";
|
|
43
|
+
}, {
|
|
44
|
+
readonly indexed: true;
|
|
45
|
+
readonly internalType: "address";
|
|
46
|
+
readonly name: "to";
|
|
47
|
+
readonly type: "address";
|
|
48
|
+
}, {
|
|
49
|
+
readonly indexed: false;
|
|
50
|
+
readonly internalType: "uint256";
|
|
51
|
+
readonly name: "amount";
|
|
52
|
+
readonly type: "uint256";
|
|
53
|
+
}];
|
|
54
|
+
readonly name: "Withdraw";
|
|
55
|
+
readonly type: "event";
|
|
56
|
+
}, {
|
|
57
|
+
readonly inputs: readonly [{
|
|
58
|
+
readonly internalType: "address";
|
|
59
|
+
readonly name: "asset";
|
|
60
|
+
readonly type: "address";
|
|
61
|
+
}, {
|
|
62
|
+
readonly internalType: "uint256";
|
|
63
|
+
readonly name: "amount";
|
|
64
|
+
readonly type: "uint256";
|
|
65
|
+
}, {
|
|
66
|
+
readonly internalType: "address";
|
|
67
|
+
readonly name: "to";
|
|
68
|
+
readonly type: "address";
|
|
69
|
+
}];
|
|
70
|
+
readonly name: "withdraw";
|
|
71
|
+
readonly outputs: readonly [{
|
|
72
|
+
readonly internalType: "uint256";
|
|
73
|
+
readonly name: "";
|
|
74
|
+
readonly type: "uint256";
|
|
75
|
+
}];
|
|
76
|
+
readonly stateMutability: "nonpayable";
|
|
77
|
+
readonly type: "function";
|
|
78
|
+
}, {
|
|
79
|
+
readonly anonymous: false;
|
|
80
|
+
readonly inputs: readonly [{
|
|
81
|
+
readonly indexed: true;
|
|
82
|
+
readonly internalType: "address";
|
|
83
|
+
readonly name: "reserve";
|
|
84
|
+
readonly type: "address";
|
|
85
|
+
}, {
|
|
86
|
+
readonly indexed: false;
|
|
87
|
+
readonly internalType: "address";
|
|
88
|
+
readonly name: "user";
|
|
89
|
+
readonly type: "address";
|
|
90
|
+
}, {
|
|
91
|
+
readonly indexed: true;
|
|
92
|
+
readonly internalType: "address";
|
|
93
|
+
readonly name: "onBehalfOf";
|
|
94
|
+
readonly type: "address";
|
|
95
|
+
}, {
|
|
96
|
+
readonly indexed: false;
|
|
97
|
+
readonly internalType: "uint256";
|
|
98
|
+
readonly name: "amount";
|
|
99
|
+
readonly type: "uint256";
|
|
100
|
+
}, {
|
|
101
|
+
readonly indexed: false;
|
|
102
|
+
readonly internalType: "enum DataTypes.InterestRateMode";
|
|
103
|
+
readonly name: "interestRateMode";
|
|
104
|
+
readonly type: "uint8";
|
|
105
|
+
}, {
|
|
106
|
+
readonly indexed: false;
|
|
107
|
+
readonly internalType: "uint256";
|
|
108
|
+
readonly name: "borrowRate";
|
|
109
|
+
readonly type: "uint256";
|
|
110
|
+
}, {
|
|
111
|
+
readonly indexed: true;
|
|
112
|
+
readonly internalType: "uint16";
|
|
113
|
+
readonly name: "referralCode";
|
|
114
|
+
readonly type: "uint16";
|
|
115
|
+
}];
|
|
116
|
+
readonly name: "Borrow";
|
|
117
|
+
readonly type: "event";
|
|
118
|
+
}, {
|
|
119
|
+
readonly inputs: readonly [{
|
|
120
|
+
readonly internalType: "address";
|
|
121
|
+
readonly name: "asset";
|
|
122
|
+
readonly type: "address";
|
|
123
|
+
}, {
|
|
124
|
+
readonly internalType: "uint256";
|
|
125
|
+
readonly name: "amount";
|
|
126
|
+
readonly type: "uint256";
|
|
127
|
+
}, {
|
|
128
|
+
readonly internalType: "uint256";
|
|
129
|
+
readonly name: "interestRateMode";
|
|
130
|
+
readonly type: "uint256";
|
|
131
|
+
}, {
|
|
132
|
+
readonly internalType: "uint16";
|
|
133
|
+
readonly name: "referralCode";
|
|
134
|
+
readonly type: "uint16";
|
|
135
|
+
}, {
|
|
136
|
+
readonly internalType: "address";
|
|
137
|
+
readonly name: "onBehalfOf";
|
|
138
|
+
readonly type: "address";
|
|
139
|
+
}];
|
|
140
|
+
readonly name: "borrow";
|
|
141
|
+
readonly outputs: readonly [];
|
|
142
|
+
readonly stateMutability: "nonpayable";
|
|
143
|
+
readonly type: "function";
|
|
144
|
+
}, {
|
|
145
|
+
readonly anonymous: false;
|
|
146
|
+
readonly inputs: readonly [{
|
|
147
|
+
readonly indexed: true;
|
|
148
|
+
readonly internalType: "address";
|
|
149
|
+
readonly name: "reserve";
|
|
150
|
+
readonly type: "address";
|
|
151
|
+
}, {
|
|
152
|
+
readonly indexed: true;
|
|
153
|
+
readonly internalType: "address";
|
|
154
|
+
readonly name: "user";
|
|
155
|
+
readonly type: "address";
|
|
156
|
+
}, {
|
|
157
|
+
readonly indexed: true;
|
|
158
|
+
readonly internalType: "address";
|
|
159
|
+
readonly name: "repayer";
|
|
160
|
+
readonly type: "address";
|
|
161
|
+
}, {
|
|
162
|
+
readonly indexed: false;
|
|
163
|
+
readonly internalType: "uint256";
|
|
164
|
+
readonly name: "amount";
|
|
165
|
+
readonly type: "uint256";
|
|
166
|
+
}, {
|
|
167
|
+
readonly indexed: false;
|
|
168
|
+
readonly internalType: "bool";
|
|
169
|
+
readonly name: "useATokens";
|
|
170
|
+
readonly type: "bool";
|
|
171
|
+
}];
|
|
172
|
+
readonly name: "Repay";
|
|
173
|
+
readonly type: "event";
|
|
174
|
+
}, {
|
|
175
|
+
readonly inputs: readonly [{
|
|
176
|
+
readonly internalType: "address";
|
|
177
|
+
readonly name: "user";
|
|
178
|
+
readonly type: "address";
|
|
179
|
+
}];
|
|
180
|
+
readonly name: "getUserAccountData";
|
|
181
|
+
readonly outputs: readonly [{
|
|
182
|
+
readonly internalType: "uint256";
|
|
183
|
+
readonly name: "totalCollateralBase";
|
|
184
|
+
readonly type: "uint256";
|
|
185
|
+
}, {
|
|
186
|
+
readonly internalType: "uint256";
|
|
187
|
+
readonly name: "totalDebtBase";
|
|
188
|
+
readonly type: "uint256";
|
|
189
|
+
}, {
|
|
190
|
+
readonly internalType: "uint256";
|
|
191
|
+
readonly name: "availableBorrowsBase";
|
|
192
|
+
readonly type: "uint256";
|
|
193
|
+
}, {
|
|
194
|
+
readonly internalType: "uint256";
|
|
195
|
+
readonly name: "currentLiquidationThreshold";
|
|
196
|
+
readonly type: "uint256";
|
|
197
|
+
}, {
|
|
198
|
+
readonly internalType: "uint256";
|
|
199
|
+
readonly name: "ltv";
|
|
200
|
+
readonly type: "uint256";
|
|
201
|
+
}, {
|
|
202
|
+
readonly internalType: "uint256";
|
|
203
|
+
readonly name: "healthFactor";
|
|
204
|
+
readonly type: "uint256";
|
|
205
|
+
}];
|
|
206
|
+
readonly stateMutability: "view";
|
|
207
|
+
readonly type: "function";
|
|
208
|
+
}];
|