@galacticcouncil/sdk-next 1.0.0-pr159-5456ce2 → 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 +101 -130
- 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/{types/pool → pool}/aave/AavePool.d.ts +3 -3
- package/build/{types/pool → pool}/aave/AavePoolClient.d.ts +12 -7
- 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 +3 -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/utils/index.d.ts +6 -0
- package/build/utils/index.mjs +1 -0
- package/build/{types/utils → utils}/math.d.ts +0 -9
- package/package.json +67 -12
- package/build/types/api/Papi.d.ts +0 -384
- 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 -30
- 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/erc20.d.ts +0 -5
- package/build/types/utils/evm.d.ts +0 -3
- package/build/types/utils/format.d.ts +0 -4
- package/build/types/utils/index.d.ts +0 -7
- 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}/aave/AaveAbi.d.ts +0 -0
- /package/build/{types/pool → pool}/aave/index.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,17 +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
10
|
- [Usage](#usage)
|
|
11
|
-
|
|
12
|
-
- [
|
|
11
|
+
- [Components](#components)
|
|
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)
|
|
14
20
|
- [BalanceClient](#balanceclient)
|
|
15
21
|
- [AssetClient](#assetclient)
|
|
22
|
+
- [Examples](#examples)
|
|
16
23
|
|
|
17
24
|
## Installation
|
|
18
25
|
|
|
@@ -22,87 +29,76 @@ Install with [npm](https://www.npmjs.com/):
|
|
|
22
29
|
|
|
23
30
|
## Usage
|
|
24
31
|
|
|
25
|
-
|
|
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.
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
```ts
|
|
35
|
+
import { api, createSdkContext } from '@galacticcouncil/sdk-next';
|
|
36
|
+
import { createClient } from 'polkadot-api';
|
|
28
37
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
| Method | Description |
|
|
34
|
-
| :----- | :----------- |
|
|
35
|
-
| `getPools(): Promise<PoolBase[]>` | Returns list of available pools. |
|
|
36
|
-
| `getPoolFees(pool: PoolBase, feeAsset: number): Promise<PoolFees>` | Returns current pool fees |
|
|
38
|
+
const provider = api.getWs('wss://hydradx-rpc.dwellir.com');
|
|
39
|
+
const client = createClient(provider);
|
|
40
|
+
const sdk = await createSdkContext(client);
|
|
37
41
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
Initialize pool context supporting Omnipool, Stableswap & XYK pools.
|
|
42
|
+
// Don't forget to cleanup resources when DONE
|
|
43
|
+
sdk.destroy();
|
|
44
|
+
```
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
import { api, pool, sor } from '@galacticcouncil/sdk-next';
|
|
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.
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
⚠️ **Note:** Make sure to keep only single instance of context per session.
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
.withOmnipool()
|
|
51
|
-
.withStableswap()
|
|
52
|
-
.withXyk();
|
|
50
|
+
## Components
|
|
53
51
|
|
|
54
|
-
|
|
55
|
-
ctx.destroy();
|
|
56
|
-
client.destroy();
|
|
57
|
-
```
|
|
52
|
+
### `api`
|
|
58
53
|
|
|
59
|
-
|
|
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.
|
|
60
57
|
|
|
61
|
-
|
|
58
|
+
### `client`
|
|
62
59
|
|
|
63
|
-
|
|
60
|
+
- `asset: AssetClient` — Registry metadata and lookup.
|
|
61
|
+
- `balance: BalanceClient` — Account balance tracking.
|
|
62
|
+
- `evm: EvmClient` — Interacts with EVM.
|
|
64
63
|
|
|
65
|
-
|
|
66
|
-
| :----- | :----------- |
|
|
67
|
-
| `getPools(): PoolBase[]` | Returns the current list of available pools. |
|
|
68
|
-
| `getRoutes(assetIn: number, assetOut: number): Hop[][]` | Computes possible routes between two assets. |
|
|
69
|
-
| `getTradeableAssets(): number[]` | Lists all assets that are tradeable through the router. |
|
|
64
|
+
### `ctx`
|
|
70
65
|
|
|
71
|
-
|
|
66
|
+
- `pool: PoolContextProvider` — Internal stateful pool context. Initialized with support for:
|
|
67
|
+
- Aave
|
|
68
|
+
- Omnipool
|
|
69
|
+
- Stableswap
|
|
70
|
+
- XYK pools
|
|
71
|
+
- LBP pools
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
### `tx`
|
|
74
74
|
|
|
75
|
-
|
|
75
|
+
- `TxBuilderFactory` — Factory for generating submittable transaction using fluent APIs.
|
|
76
76
|
|
|
77
|
-
|
|
78
|
-
import { api, pool, sor } from '@galacticcouncil/sdk-next';
|
|
77
|
+
### `destroy()`
|
|
79
78
|
|
|
80
|
-
|
|
79
|
+
Gracefully cleans up SDK resources. Always call before exiting to avoid memory leaks or stale subscriptions.
|
|
81
80
|
|
|
82
|
-
|
|
83
|
-
const ctx = new pool.PoolContextProvider(client)
|
|
84
|
-
.withOmnipool()
|
|
85
|
-
.withStableswap()
|
|
86
|
-
.withXyk();
|
|
81
|
+
## API Reference
|
|
87
82
|
|
|
88
|
-
|
|
83
|
+
### AaveUtils
|
|
89
84
|
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
| Method | Description |
|
|
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
92
|
|
|
93
|
-
|
|
94
|
-
ctx.destroy();
|
|
95
|
-
client.destroy();
|
|
96
|
-
```
|
|
93
|
+
➡️ For type definitions visit [types.ts](src/aave/types.ts)<br />
|
|
97
94
|
|
|
98
95
|
### TradeRouter
|
|
99
96
|
|
|
100
|
-
Off-chain optimization of orders across pools for best price execution. TradeRouter does not perform any on-chain transations.
|
|
101
|
-
|
|
102
|
-
#### Api Reference
|
|
103
|
-
|
|
104
97
|
| Method | Description |
|
|
105
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. |
|
|
106
102
|
| `getBestSell(tokenIn: number, tokenOut: number, amountIn: bigint \| string): Trade` | Find the best sell trade for given input amount. |
|
|
107
103
|
| `getBestBuy(tokenIn: number, tokenOut: number, amountOut: bigint \| string): Trade` | Find the best buy trade for given output amount. |
|
|
108
104
|
| `getBuy(tokenIn: number, tokenOut: number, amountOut: bigint \| string, route?: Hop[]): Trade` | Calculate a buy using a specific route (optional). |
|
|
@@ -112,112 +108,87 @@ Off-chain optimization of orders across pools for best price execution. TradeRou
|
|
|
112
108
|
|
|
113
109
|
➡️ For type definitions visit [types.ts](src/sor/types.ts)<br />
|
|
114
110
|
|
|
115
|
-
|
|
111
|
+
### TradeScheduler
|
|
116
112
|
|
|
117
|
-
|
|
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. |
|
|
118
118
|
|
|
119
|
-
|
|
120
|
-
import { api, pool, sor } from '@galacticcouncil/sdk-next';
|
|
119
|
+
➡️ For type definitions visit [types.ts](src/sor/types.ts)<br />
|
|
121
120
|
|
|
122
|
-
|
|
121
|
+
### BalanceClient
|
|
123
122
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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 |
|
|
128
130
|
|
|
129
|
-
|
|
130
|
-
const utils = new sor.TradeUtils(client);
|
|
131
|
+
➡️ For type definitions visit [types.ts](src/types.ts)<br />
|
|
131
132
|
|
|
132
|
-
|
|
133
|
-
const tx = await utils.buildSellTx(sell, 5);
|
|
134
|
-
console.log(sell.toHuman());
|
|
135
|
-
console.log('Transaction hash:', tx.asHex());
|
|
133
|
+
### AssetClient
|
|
136
134
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
```
|
|
135
|
+
| Method | Description |
|
|
136
|
+
| :----- | :----------- |
|
|
137
|
+
| `getSupported(includeInvalid?: boolean, external?: ExternalAsset[]): Promise<Asset[]>` | Returns assets with metadata from registry. |
|
|
141
138
|
|
|
142
|
-
|
|
139
|
+
➡️ For type definitions visit [types.ts](src/types.ts)<br />
|
|
143
140
|
|
|
144
|
-
|
|
141
|
+
## Examples
|
|
145
142
|
|
|
146
|
-
|
|
143
|
+
All examples assume SDK has been initialized, [see](#usage)
|
|
147
144
|
|
|
148
|
-
|
|
145
|
+
### TradeRouter
|
|
149
146
|
|
|
150
|
-
|
|
151
|
-
- "Token assets"
|
|
152
|
-
- "ERC-20 tokens"
|
|
147
|
+
Calculate sell of 1 DOT for HDX & build tx with 5% slippage (default to 1% if not specified)
|
|
153
148
|
|
|
154
|
-
|
|
149
|
+
```typescript
|
|
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
|
+
```
|
|
155
161
|
|
|
156
|
-
|
|
157
|
-
| :----- | :----------- |
|
|
158
|
-
| `subscribeSystemBalance(address: string): Observable<AssetAmount>` | Subscribe native account balance. |
|
|
159
|
-
| `subscribeTokenBalance(address: string, assetId: number): Observable<AssetAmount>` | Subscribe token account balance. |
|
|
160
|
-
| `subscribeTokensBalance(address: string): Observable<AssetAmount[]>` | Subscribe tokens account balances. |
|
|
161
|
-
| `subscribeErc20Balance(address: string, includeOnly?: number[]): Observable<AssetAmount[]>` | Subscribe erc20 assets balances |
|
|
162
|
+
**Note:** For convenience, the router amount can be specified either as a native bigint or as a human-readable string.
|
|
162
163
|
|
|
163
|
-
|
|
164
|
+
For example, `"1"` DOT (string) is equivalent to `10_000_000_000n` (bigint), as DOT has 10 decimals.
|
|
164
165
|
|
|
165
|
-
|
|
166
|
+
### BalanceClient
|
|
166
167
|
|
|
167
168
|
Subscribe hydration treasury account.
|
|
168
169
|
|
|
169
170
|
```typescript
|
|
170
|
-
|
|
171
|
+
const { client } = sdk;
|
|
171
172
|
|
|
172
173
|
const account = "7L53bUTBbfuj14UpdCNPwmgzzHSsrsTWBHX5pys32mVWM3C1"
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
const balanceClient = new c.BalanceClient(client);
|
|
176
|
-
|
|
177
|
-
const subscription = balanceClient
|
|
178
|
-
.subscribeBalance(account)
|
|
174
|
+
const subscription = client.balance
|
|
175
|
+
.watch(account)
|
|
179
176
|
.subscribe((balances) => {
|
|
180
177
|
console.log(balances);
|
|
181
178
|
});
|
|
182
|
-
|
|
183
|
-
// Don't forget to cleanup the resources
|
|
184
|
-
subscription.unsubscribe();
|
|
185
|
-
client.destroy();
|
|
186
179
|
```
|
|
187
180
|
|
|
188
181
|
### AssetClient
|
|
189
182
|
|
|
190
|
-
Helper class to fetch registry metadata.
|
|
191
|
-
|
|
192
|
-
#### API Reference
|
|
193
|
-
|
|
194
|
-
| Method | Description |
|
|
195
|
-
| :----- | :----------- |
|
|
196
|
-
| `getOnChainAssets(includeInvalid?: boolean, external?: ExternalAsset[]): Promise<Asset[]>` | Returns assets with metadata from registry. |
|
|
197
|
-
|
|
198
|
-
➡️ For type definitions visit [types.ts](src/types.ts)<br />
|
|
199
|
-
|
|
200
|
-
#### Example
|
|
201
|
-
|
|
202
183
|
Get default on-chain data.
|
|
203
184
|
|
|
204
185
|
```typescript
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
const client = await api.getWs('wss://hydradx-rpc.dwellir.com');
|
|
208
|
-
const assetClient = new c.AssetClient(client);
|
|
186
|
+
const { client } = sdk;
|
|
209
187
|
|
|
210
|
-
const assets = await
|
|
188
|
+
const assets = await client.asset.getSupported();
|
|
211
189
|
console.log(assets);
|
|
212
|
-
|
|
213
|
-
// Don't forget to cleanup the resources
|
|
214
|
-
client.destroy();
|
|
215
190
|
```
|
|
216
191
|
|
|
217
|
-
## Examples
|
|
218
|
-
|
|
219
192
|
To demonstrate more full working examples on real chain see [script](test/script/examples) section.
|
|
220
193
|
|
|
221
|
-
### Execution
|
|
222
|
-
|
|
223
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
|
+
}];
|