@waiaas/actions 2.8.0-rc.1 → 2.8.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 +17 -5
- package/dist/index.d.ts +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/aave-v3/aave-contracts.d.ts +90 -0
- package/dist/providers/aave-v3/aave-contracts.d.ts.map +1 -0
- package/dist/providers/aave-v3/aave-contracts.js +148 -0
- package/dist/providers/aave-v3/aave-contracts.js.map +1 -0
- package/dist/providers/aave-v3/aave-rpc.d.ts +102 -0
- package/dist/providers/aave-v3/aave-rpc.d.ts.map +1 -0
- package/dist/providers/aave-v3/aave-rpc.js +134 -0
- package/dist/providers/aave-v3/aave-rpc.js.map +1 -0
- package/dist/providers/aave-v3/config.d.ts +20 -0
- package/dist/providers/aave-v3/config.d.ts.map +1 -0
- package/dist/providers/aave-v3/config.js +77 -0
- package/dist/providers/aave-v3/config.js.map +1 -0
- package/dist/providers/aave-v3/index.d.ts +25 -0
- package/dist/providers/aave-v3/index.d.ts.map +1 -0
- package/dist/providers/aave-v3/index.js +352 -0
- package/dist/providers/aave-v3/index.js.map +1 -0
- package/dist/providers/aave-v3/schemas.d.ts +73 -0
- package/dist/providers/aave-v3/schemas.d.ts.map +1 -0
- package/dist/providers/aave-v3/schemas.js +53 -0
- package/dist/providers/aave-v3/schemas.js.map +1 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -120,14 +120,25 @@ npx @waiaas/skills add all
|
|
|
120
120
|
|
|
121
121
|
This adds `.skill.md` instruction files to your project. Include them in your agent's context and it learns the WAIaaS API automatically. Available skills: `setup`, `quickstart`, `wallet`, `transactions`, `policies`, `admin`, `actions`, `x402`.
|
|
122
122
|
|
|
123
|
-
### Agent Self-Setup
|
|
123
|
+
### Agent Self-Setup (Auto-Provision)
|
|
124
124
|
|
|
125
|
-
AI agents can set up WAIaaS
|
|
125
|
+
AI agents can set up WAIaaS fully autonomously with no human interaction:
|
|
126
126
|
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
```bash
|
|
128
|
+
npm install -g @waiaas/cli
|
|
129
|
+
waiaas init --auto-provision # Generates random master password → recovery.key
|
|
130
|
+
waiaas start # No password prompt
|
|
131
|
+
waiaas quickset # Creates wallets + sessions automatically
|
|
132
|
+
waiaas set-master # (Later) Harden password, then delete recovery.key
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The `--auto-provision` flag generates a cryptographically random master password and saves it to `~/.waiaas/recovery.key`. All subsequent CLI commands read it automatically. See the [Agent Self-Setup Guide](docs/guides/agent-self-setup.md) for the complete flow.
|
|
129
136
|
|
|
130
|
-
|
|
137
|
+
For manual setup with human-guided password entry, install skills and follow `waiaas-setup/SKILL.md`:
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
npx @waiaas/skills add all
|
|
141
|
+
```
|
|
131
142
|
|
|
132
143
|
## Alternative: Docker
|
|
133
144
|
|
|
@@ -203,6 +214,7 @@ Enabled by default (`admin_ui = true` in config.toml).
|
|
|
203
214
|
| [Security Model](docs/security-model.md) | Authentication, policy engine, Kill Switch, AutoStop |
|
|
204
215
|
| [Deployment Guide](docs/deployment.md) | Docker, npm, configuration reference |
|
|
205
216
|
| [API Reference](docs/api-reference.md) | REST API endpoints and authentication |
|
|
217
|
+
| [Agent Self-Setup Guide](docs/guides/agent-self-setup.md) | Fully autonomous setup with auto-provision |
|
|
206
218
|
| [Agent Skills Integration](docs/guides/agent-skills-integration.md) | Universal guide for 27+ AI agent platforms |
|
|
207
219
|
| [Claude Code Integration](docs/guides/claude-code-integration.md) | Skill files + MCP server setup for Claude Code |
|
|
208
220
|
| [OpenClaw Integration](docs/guides/openclaw-integration.md) | Quick setup for OpenClaw bot |
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* and individual provider classes for direct usage.
|
|
6
6
|
*/
|
|
7
7
|
import type { IActionProvider } from '@waiaas/core';
|
|
8
|
+
import type { IRpcCaller } from './providers/aave-v3/aave-rpc.js';
|
|
8
9
|
export { JupiterSwapActionProvider } from './providers/jupiter-swap/index.js';
|
|
9
10
|
export { JUPITER_PROGRAM_ID, JUPITER_SWAP_DEFAULTS } from './providers/jupiter-swap/config.js';
|
|
10
11
|
export type { JupiterSwapConfig } from './providers/jupiter-swap/config.js';
|
|
@@ -24,6 +25,11 @@ export { JitoStakingActionProvider } from './providers/jito-staking/index.js';
|
|
|
24
25
|
export { JITO_STAKING_DEFAULTS, JITO_MAINNET_ADDRESSES, getJitoAddresses } from './providers/jito-staking/config.js';
|
|
25
26
|
export type { JitoStakingConfig } from './providers/jito-staking/config.js';
|
|
26
27
|
export { JitoEpochTracker } from './providers/jito-staking/epoch-tracker.js';
|
|
28
|
+
export { AaveV3LendingProvider } from './providers/aave-v3/index.js';
|
|
29
|
+
export { AAVE_V3_DEFAULTS, AAVE_V3_ADDRESSES, getAaveAddresses, AAVE_CHAIN_ID_MAP } from './providers/aave-v3/config.js';
|
|
30
|
+
export type { AaveV3Config, AaveChainAddresses } from './providers/aave-v3/config.js';
|
|
31
|
+
export type { IRpcCaller, UserAccountData, ReserveData } from './providers/aave-v3/aave-rpc.js';
|
|
32
|
+
export { decodeGetUserAccountData, decodeGetReserveData, simulateHealthFactor, rayToApy, hfToNumber, LIQUIDATION_THRESHOLD_HF, WARNING_THRESHOLD_HF } from './providers/aave-v3/aave-rpc.js';
|
|
27
33
|
export { ActionApiClient } from './common/action-api-client.js';
|
|
28
34
|
export { asBps, asPct, clampSlippageBps, bpsToPct, pctToBps } from './common/slippage.js';
|
|
29
35
|
export type { SlippageBps, SlippagePct } from './common/slippage.js';
|
|
@@ -42,7 +48,9 @@ interface ProviderRegistry {
|
|
|
42
48
|
* Reads provider config from SettingsReader (DB > config.toml > default fallback chain).
|
|
43
49
|
* Each provider is registered when its `actions.{name}_enabled` setting is 'true'.
|
|
44
50
|
*/
|
|
45
|
-
export declare function registerBuiltInProviders(registry: ProviderRegistry, settingsReader: SettingsReader
|
|
51
|
+
export declare function registerBuiltInProviders(registry: ProviderRegistry, settingsReader: SettingsReader, options?: {
|
|
52
|
+
rpcCaller?: IRpcCaller;
|
|
53
|
+
}): {
|
|
46
54
|
loaded: string[];
|
|
47
55
|
skipped: string[];
|
|
48
56
|
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,eAAe,EAAe,MAAM,cAAc,CAAC;AAWjE,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAC/F,YAAY,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AAE5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,YAAY,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC;AAC5I,YAAY,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAC;AAEzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC3F,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAEzG,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,o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AAC1C,YAAY,EACV,mBAAmB,EACnB,mBAAmB,EACnB,YAAY,GACb,MAAM,kCAAkC,CAAC;AAM1C,+EAA+E;AAC/E,MAAM,WAAW,cAAc;IAC7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B;AAED,UAAU,gBAAgB;IACxB,QAAQ,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI,CAAC;CAC3C;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,gBAAgB,EAC1B,cAAc,EAAE,cAAc,EAC9B,OAAO,CAAC,EAAE;IAAE,SAAS,CAAC,EAAE,UAAU,CAAA;CAAE,GACnC;IAAE,MAAM,EAAE,MAAM,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CA8HzC"}
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,8 @@ import { LidoStakingActionProvider } from './providers/lido-staking/index.js';
|
|
|
6
6
|
import { getLidoAddresses } from './providers/lido-staking/config.js';
|
|
7
7
|
import { JitoStakingActionProvider } from './providers/jito-staking/index.js';
|
|
8
8
|
import { getJitoAddresses } from './providers/jito-staking/config.js';
|
|
9
|
+
import { AaveV3LendingProvider } from './providers/aave-v3/index.js';
|
|
10
|
+
import {} from './providers/aave-v3/config.js';
|
|
9
11
|
// Re-export provider classes
|
|
10
12
|
export { JupiterSwapActionProvider } from './providers/jupiter-swap/index.js';
|
|
11
13
|
export { JUPITER_PROGRAM_ID, JUPITER_SWAP_DEFAULTS } from './providers/jupiter-swap/config.js';
|
|
@@ -21,6 +23,9 @@ export { LidoWithdrawalTracker } from './providers/lido-staking/withdrawal-track
|
|
|
21
23
|
export { JitoStakingActionProvider } from './providers/jito-staking/index.js';
|
|
22
24
|
export { JITO_STAKING_DEFAULTS, JITO_MAINNET_ADDRESSES, getJitoAddresses } from './providers/jito-staking/config.js';
|
|
23
25
|
export { JitoEpochTracker } from './providers/jito-staking/epoch-tracker.js';
|
|
26
|
+
export { AaveV3LendingProvider } from './providers/aave-v3/index.js';
|
|
27
|
+
export { AAVE_V3_DEFAULTS, AAVE_V3_ADDRESSES, getAaveAddresses, AAVE_CHAIN_ID_MAP } from './providers/aave-v3/config.js';
|
|
28
|
+
export { decodeGetUserAccountData, decodeGetReserveData, simulateHealthFactor, rayToApy, hfToNumber, LIQUIDATION_THRESHOLD_HF, WARNING_THRESHOLD_HF } from './providers/aave-v3/aave-rpc.js';
|
|
24
29
|
// Re-export common utilities
|
|
25
30
|
export { ActionApiClient } from './common/action-api-client.js';
|
|
26
31
|
export { asBps, asPct, clampSlippageBps, bpsToPct, pctToBps } from './common/slippage.js';
|
|
@@ -32,7 +37,7 @@ export { BRIDGE_STATUS_VALUES, BridgeStatusEnum, } from './common/async-status-t
|
|
|
32
37
|
* Reads provider config from SettingsReader (DB > config.toml > default fallback chain).
|
|
33
38
|
* Each provider is registered when its `actions.{name}_enabled` setting is 'true'.
|
|
34
39
|
*/
|
|
35
|
-
export function registerBuiltInProviders(registry, settingsReader) {
|
|
40
|
+
export function registerBuiltInProviders(registry, settingsReader, options) {
|
|
36
41
|
const loaded = [];
|
|
37
42
|
const skipped = [];
|
|
38
43
|
const providers = [
|
|
@@ -119,6 +124,14 @@ export function registerBuiltInProviders(registry, settingsReader) {
|
|
|
119
124
|
return new JitoStakingActionProvider(config);
|
|
120
125
|
},
|
|
121
126
|
},
|
|
127
|
+
{
|
|
128
|
+
key: 'aave_v3',
|
|
129
|
+
enabledKey: 'actions.aave_v3_enabled',
|
|
130
|
+
factory: () => {
|
|
131
|
+
const config = { enabled: true };
|
|
132
|
+
return new AaveV3LendingProvider(config, options?.rpcCaller);
|
|
133
|
+
},
|
|
134
|
+
},
|
|
122
135
|
];
|
|
123
136
|
for (const { key, enabledKey, factory } of providers) {
|
|
124
137
|
if (settingsReader.get(enabledKey) === 'true') {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRo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AE,CAAC;QACrD,IAAI,cAAc,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,MAAM,EAAE,CAAC;YAC9C,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,OAAO,EAAE,CAAC;gBAC3B,IAAI,QAAQ,EAAE,CAAC;oBACb,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;oBAC5B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC;qBAAM,CAAC;oBACN,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACpB,CAAC;YACH,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,CAAC,IAAI,CAAC,sBAAsB,GAAG,wBAAwB,EAAE,GAAG,CAAC,CAAC;gBACrE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aave V3 manual hex ABI encoding helpers.
|
|
3
|
+
*
|
|
4
|
+
* Manual ABI encoding (no viem dependency) for:
|
|
5
|
+
* - Pool.supply(address,uint256,address,uint16)
|
|
6
|
+
* - Pool.borrow(address,uint256,uint256,uint16,address)
|
|
7
|
+
* - Pool.repay(address,uint256,uint256,address)
|
|
8
|
+
* - Pool.withdraw(address,uint256,address)
|
|
9
|
+
* - ERC-20 approve(address,uint256)
|
|
10
|
+
* - Pool.getUserAccountData(address) [read]
|
|
11
|
+
* - PoolDataProvider.getReserveData(address) [read]
|
|
12
|
+
*
|
|
13
|
+
* Function selectors are hardcoded hex constants derived from keccak256 of function signatures.
|
|
14
|
+
* Follows the Lido pattern (lido-contract.ts).
|
|
15
|
+
*/
|
|
16
|
+
export declare const AAVE_SELECTORS: {
|
|
17
|
+
readonly supply: "0x617ba037";
|
|
18
|
+
readonly borrow: "0xa415bcad";
|
|
19
|
+
readonly repay: "0x573ade81";
|
|
20
|
+
readonly withdraw: "0x69328dec";
|
|
21
|
+
readonly getUserAccountData: "0xbf92857c";
|
|
22
|
+
readonly getReserveData: "0x35ea6a75";
|
|
23
|
+
readonly approve: "0x095ea7b3";
|
|
24
|
+
};
|
|
25
|
+
export declare const MAX_UINT256: bigint;
|
|
26
|
+
/**
|
|
27
|
+
* Encode Aave V3 Pool.supply() calldata.
|
|
28
|
+
*
|
|
29
|
+
* @param asset - ERC-20 token address to supply
|
|
30
|
+
* @param amount - Amount in token's smallest unit (wei for 18-decimal tokens)
|
|
31
|
+
* @param onBehalfOf - Address to credit the aToken to
|
|
32
|
+
* @param referralCode - Referral code (defaults to 0)
|
|
33
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
34
|
+
*/
|
|
35
|
+
export declare function encodeSupplyCalldata(asset: string, amount: bigint, onBehalfOf: string, referralCode?: number): string;
|
|
36
|
+
/**
|
|
37
|
+
* Encode Aave V3 Pool.borrow() calldata.
|
|
38
|
+
*
|
|
39
|
+
* Parameter order matches IPool.sol: (asset, amount, interestRateMode, referralCode, onBehalfOf).
|
|
40
|
+
*
|
|
41
|
+
* @param asset - ERC-20 token address to borrow
|
|
42
|
+
* @param amount - Amount to borrow in token's smallest unit
|
|
43
|
+
* @param onBehalfOf - Address that will receive the borrowed tokens and incur the debt
|
|
44
|
+
* @param interestRateMode - 2 = variable (stable is deprecated)
|
|
45
|
+
* @param referralCode - Referral code (defaults to 0)
|
|
46
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
47
|
+
*/
|
|
48
|
+
export declare function encodeBorrowCalldata(asset: string, amount: bigint, onBehalfOf: string, interestRateMode?: bigint, referralCode?: number): string;
|
|
49
|
+
/**
|
|
50
|
+
* Encode Aave V3 Pool.repay() calldata.
|
|
51
|
+
*
|
|
52
|
+
* @param asset - ERC-20 token address to repay
|
|
53
|
+
* @param amount - Amount to repay (use MAX_UINT256 for full repay)
|
|
54
|
+
* @param onBehalfOf - Address whose debt will be repaid
|
|
55
|
+
* @param interestRateMode - 2 = variable
|
|
56
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
57
|
+
*/
|
|
58
|
+
export declare function encodeRepayCalldata(asset: string, amount: bigint, onBehalfOf: string, interestRateMode?: bigint): string;
|
|
59
|
+
/**
|
|
60
|
+
* Encode Aave V3 Pool.withdraw() calldata.
|
|
61
|
+
*
|
|
62
|
+
* @param asset - ERC-20 token address to withdraw
|
|
63
|
+
* @param amount - Amount to withdraw (use MAX_UINT256 for full withdrawal)
|
|
64
|
+
* @param to - Address to receive the withdrawn tokens
|
|
65
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
66
|
+
*/
|
|
67
|
+
export declare function encodeWithdrawCalldata(asset: string, amount: bigint, to: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Encode ERC-20 approve(address spender, uint256 amount) calldata.
|
|
70
|
+
*
|
|
71
|
+
* @param spender - Spender address to approve
|
|
72
|
+
* @param amount - Amount to approve in token's smallest unit
|
|
73
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
74
|
+
*/
|
|
75
|
+
export declare function encodeApproveCalldata(spender: string, amount: bigint): string;
|
|
76
|
+
/**
|
|
77
|
+
* Encode Pool.getUserAccountData(address) calldata.
|
|
78
|
+
*
|
|
79
|
+
* @param user - User address to query
|
|
80
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
81
|
+
*/
|
|
82
|
+
export declare function encodeGetUserAccountDataCalldata(user: string): string;
|
|
83
|
+
/**
|
|
84
|
+
* Encode PoolDataProvider.getReserveData(address) calldata.
|
|
85
|
+
*
|
|
86
|
+
* @param asset - Asset address to query
|
|
87
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
88
|
+
*/
|
|
89
|
+
export declare function encodeGetReserveDataCalldata(asset: string): string;
|
|
90
|
+
//# sourceMappingURL=aave-contracts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aave-contracts.d.ts","sourceRoot":"","sources":["../../../src/providers/aave-v3/aave-contracts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAuBH,eAAO,MAAM,cAAc;;;;;;;;CAWjB,CAAC;AAMX,eAAO,MAAM,WAAW,QAAoB,CAAC;AAM7C;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,YAAY,GAAE,MAAU,GACvB,MAAM,CAER;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,gBAAgB,GAAE,MAAW,EAC7B,YAAY,GAAE,MAAU,GACvB,MAAM,CAER;AAMD;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,gBAAgB,GAAE,MAAW,GAC5B,MAAM,CAER;AAMD;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,GACT,MAAM,CAER;AAMD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE7E;AAMD;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAErE;AAMD;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAElE"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aave V3 manual hex ABI encoding helpers.
|
|
3
|
+
*
|
|
4
|
+
* Manual ABI encoding (no viem dependency) for:
|
|
5
|
+
* - Pool.supply(address,uint256,address,uint16)
|
|
6
|
+
* - Pool.borrow(address,uint256,uint256,uint16,address)
|
|
7
|
+
* - Pool.repay(address,uint256,uint256,address)
|
|
8
|
+
* - Pool.withdraw(address,uint256,address)
|
|
9
|
+
* - ERC-20 approve(address,uint256)
|
|
10
|
+
* - Pool.getUserAccountData(address) [read]
|
|
11
|
+
* - PoolDataProvider.getReserveData(address) [read]
|
|
12
|
+
*
|
|
13
|
+
* Function selectors are hardcoded hex constants derived from keccak256 of function signatures.
|
|
14
|
+
* Follows the Lido pattern (lido-contract.ts).
|
|
15
|
+
*/
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Utility: pad a hex value to 32 bytes (64 hex chars)
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
function padHex(value, length = 64) {
|
|
20
|
+
return value.padStart(length, '0');
|
|
21
|
+
}
|
|
22
|
+
function addressToHex(address) {
|
|
23
|
+
return padHex(address.slice(2).toLowerCase());
|
|
24
|
+
}
|
|
25
|
+
function uint256ToHex(value) {
|
|
26
|
+
if (value < 0n)
|
|
27
|
+
throw new Error('uint256 cannot be negative');
|
|
28
|
+
return padHex(value.toString(16));
|
|
29
|
+
}
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
// Function selectors (verified via keccak256)
|
|
32
|
+
// ---------------------------------------------------------------------------
|
|
33
|
+
export const AAVE_SELECTORS = {
|
|
34
|
+
// Pool write functions
|
|
35
|
+
supply: '0x617ba037', // supply(address,uint256,address,uint16)
|
|
36
|
+
borrow: '0xa415bcad', // borrow(address,uint256,uint256,uint16,address)
|
|
37
|
+
repay: '0x573ade81', // repay(address,uint256,uint256,address)
|
|
38
|
+
withdraw: '0x69328dec', // withdraw(address,uint256,address)
|
|
39
|
+
// Pool read functions
|
|
40
|
+
getUserAccountData: '0xbf92857c', // getUserAccountData(address)
|
|
41
|
+
getReserveData: '0x35ea6a75', // getReserveData(address)
|
|
42
|
+
// ERC-20
|
|
43
|
+
approve: '0x095ea7b3', // approve(address,uint256)
|
|
44
|
+
};
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// MAX_UINT256 sentinel (for full repay/withdraw)
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
export const MAX_UINT256 = (1n << 256n) - 1n;
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// supply(address asset, uint256 amount, address onBehalfOf, uint16 referralCode)
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
/**
|
|
53
|
+
* Encode Aave V3 Pool.supply() calldata.
|
|
54
|
+
*
|
|
55
|
+
* @param asset - ERC-20 token address to supply
|
|
56
|
+
* @param amount - Amount in token's smallest unit (wei for 18-decimal tokens)
|
|
57
|
+
* @param onBehalfOf - Address to credit the aToken to
|
|
58
|
+
* @param referralCode - Referral code (defaults to 0)
|
|
59
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
60
|
+
*/
|
|
61
|
+
export function encodeSupplyCalldata(asset, amount, onBehalfOf, referralCode = 0) {
|
|
62
|
+
return `${AAVE_SELECTORS.supply}${addressToHex(asset)}${uint256ToHex(amount)}${addressToHex(onBehalfOf)}${uint256ToHex(BigInt(referralCode))}`;
|
|
63
|
+
}
|
|
64
|
+
// ---------------------------------------------------------------------------
|
|
65
|
+
// borrow(address asset, uint256 amount, uint256 interestRateMode, uint16 referralCode, address onBehalfOf)
|
|
66
|
+
// ---------------------------------------------------------------------------
|
|
67
|
+
/**
|
|
68
|
+
* Encode Aave V3 Pool.borrow() calldata.
|
|
69
|
+
*
|
|
70
|
+
* Parameter order matches IPool.sol: (asset, amount, interestRateMode, referralCode, onBehalfOf).
|
|
71
|
+
*
|
|
72
|
+
* @param asset - ERC-20 token address to borrow
|
|
73
|
+
* @param amount - Amount to borrow in token's smallest unit
|
|
74
|
+
* @param onBehalfOf - Address that will receive the borrowed tokens and incur the debt
|
|
75
|
+
* @param interestRateMode - 2 = variable (stable is deprecated)
|
|
76
|
+
* @param referralCode - Referral code (defaults to 0)
|
|
77
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
78
|
+
*/
|
|
79
|
+
export function encodeBorrowCalldata(asset, amount, onBehalfOf, interestRateMode = 2n, referralCode = 0) {
|
|
80
|
+
return `${AAVE_SELECTORS.borrow}${addressToHex(asset)}${uint256ToHex(amount)}${uint256ToHex(interestRateMode)}${uint256ToHex(BigInt(referralCode))}${addressToHex(onBehalfOf)}`;
|
|
81
|
+
}
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// repay(address asset, uint256 amount, uint256 interestRateMode, address onBehalfOf)
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
/**
|
|
86
|
+
* Encode Aave V3 Pool.repay() calldata.
|
|
87
|
+
*
|
|
88
|
+
* @param asset - ERC-20 token address to repay
|
|
89
|
+
* @param amount - Amount to repay (use MAX_UINT256 for full repay)
|
|
90
|
+
* @param onBehalfOf - Address whose debt will be repaid
|
|
91
|
+
* @param interestRateMode - 2 = variable
|
|
92
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
93
|
+
*/
|
|
94
|
+
export function encodeRepayCalldata(asset, amount, onBehalfOf, interestRateMode = 2n) {
|
|
95
|
+
return `${AAVE_SELECTORS.repay}${addressToHex(asset)}${uint256ToHex(amount)}${uint256ToHex(interestRateMode)}${addressToHex(onBehalfOf)}`;
|
|
96
|
+
}
|
|
97
|
+
// ---------------------------------------------------------------------------
|
|
98
|
+
// withdraw(address asset, uint256 amount, address to)
|
|
99
|
+
// ---------------------------------------------------------------------------
|
|
100
|
+
/**
|
|
101
|
+
* Encode Aave V3 Pool.withdraw() calldata.
|
|
102
|
+
*
|
|
103
|
+
* @param asset - ERC-20 token address to withdraw
|
|
104
|
+
* @param amount - Amount to withdraw (use MAX_UINT256 for full withdrawal)
|
|
105
|
+
* @param to - Address to receive the withdrawn tokens
|
|
106
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
107
|
+
*/
|
|
108
|
+
export function encodeWithdrawCalldata(asset, amount, to) {
|
|
109
|
+
return `${AAVE_SELECTORS.withdraw}${addressToHex(asset)}${uint256ToHex(amount)}${addressToHex(to)}`;
|
|
110
|
+
}
|
|
111
|
+
// ---------------------------------------------------------------------------
|
|
112
|
+
// approve(address spender, uint256 amount) -- ERC-20
|
|
113
|
+
// ---------------------------------------------------------------------------
|
|
114
|
+
/**
|
|
115
|
+
* Encode ERC-20 approve(address spender, uint256 amount) calldata.
|
|
116
|
+
*
|
|
117
|
+
* @param spender - Spender address to approve
|
|
118
|
+
* @param amount - Amount to approve in token's smallest unit
|
|
119
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
120
|
+
*/
|
|
121
|
+
export function encodeApproveCalldata(spender, amount) {
|
|
122
|
+
return `${AAVE_SELECTORS.approve}${addressToHex(spender)}${uint256ToHex(amount)}`;
|
|
123
|
+
}
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// getUserAccountData(address user) -- read
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
/**
|
|
128
|
+
* Encode Pool.getUserAccountData(address) calldata.
|
|
129
|
+
*
|
|
130
|
+
* @param user - User address to query
|
|
131
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
132
|
+
*/
|
|
133
|
+
export function encodeGetUserAccountDataCalldata(user) {
|
|
134
|
+
return `${AAVE_SELECTORS.getUserAccountData}${addressToHex(user)}`;
|
|
135
|
+
}
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
// getReserveData(address asset) -- read
|
|
138
|
+
// ---------------------------------------------------------------------------
|
|
139
|
+
/**
|
|
140
|
+
* Encode PoolDataProvider.getReserveData(address) calldata.
|
|
141
|
+
*
|
|
142
|
+
* @param asset - Asset address to query
|
|
143
|
+
* @returns ABI-encoded calldata with 0x prefix
|
|
144
|
+
*/
|
|
145
|
+
export function encodeGetReserveDataCalldata(asset) {
|
|
146
|
+
return `${AAVE_SELECTORS.getReserveData}${addressToHex(asset)}`;
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=aave-contracts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aave-contracts.js","sourceRoot":"","sources":["../../../src/providers/aave-v3/aave-contracts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,8EAA8E;AAC9E,sDAAsD;AACtD,8EAA8E;AAE9E,SAAS,MAAM,CAAC,KAAa,EAAE,SAAiB,EAAE;IAChD,OAAO,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AACrC,CAAC;AAED,SAAS,YAAY,CAAC,OAAe;IACnC,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,KAAK,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,4BAA4B,CAAC,CAAC;IAC9D,OAAO,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC;AACpC,CAAC;AAED,8EAA8E;AAC9E,8CAA8C;AAC9C,8EAA8E;AAE9E,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,uBAAuB;IACvB,MAAM,EAAE,YAAY,EAAc,yCAAyC;IAC3E,MAAM,EAAE,YAAY,EAAc,iDAAiD;IACnF,KAAK,EAAE,YAAY,EAAe,yCAAyC;IAC3E,QAAQ,EAAE,YAAY,EAAY,oCAAoC;IACtE,sBAAsB;IACtB,kBAAkB,EAAE,YAAY,EAAE,8BAA8B;IAChE,cAAc,EAAE,YAAY,EAAM,0BAA0B;IAC5D,SAAS;IACT,OAAO,EAAE,YAAY,EAAa,2BAA2B;CACrD,CAAC;AAEX,8EAA8E;AAC9E,iDAAiD;AACjD,8EAA8E;AAE9E,MAAM,CA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AAsB,CACpC,KAAa,EACb,MAAc,EACd,EAAU;IAEV,OAAO,GAAG,cAAc,CAAC,QAAQ,GAAG,YAAY,CAAC,KAAK,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC,EAAE,CAAC,EAAE,CAAC;AACtG,CAAC;AAED,8EAA8E;AAC9E,qDAAqD;AACrD,8EAA8E;AAE9E;;;;;;GAMG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAe,EAAE,MAAc;IACnE,OAAO,GAAG,cAAc,CAAC,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,GAAG,YAAY,CAAC,MAAM,CAAC,EAAE,CAAC;AACpF,CAAC;AAED,8EAA8E;AAC9E,2CAA2C;AAC3C,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAAC,IAAY;IAC3D,OAAO,GAAG,cAAc,CAAC,kBAAkB,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;AACrE,CAAC;AAED,8EAA8E;AAC9E,wCAAwC;AACxC,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAAC,KAAa;IACxD,OAAO,GAAG,cAAc,CAAC,cAAc,GAAG,YAAY,CAAC,KAAK,CAAC,EAAE,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lightweight RPC caller interface for read-only eth_call operations.
|
|
3
|
+
* Implementations wrap viem PublicClient or mock in tests.
|
|
4
|
+
*/
|
|
5
|
+
export interface IRpcCaller {
|
|
6
|
+
call(params: {
|
|
7
|
+
to: string;
|
|
8
|
+
data: string;
|
|
9
|
+
chainId?: number;
|
|
10
|
+
}): Promise<string>;
|
|
11
|
+
}
|
|
12
|
+
export interface UserAccountData {
|
|
13
|
+
/** Total collateral in base currency (8 decimals, USD). */
|
|
14
|
+
totalCollateralBase: bigint;
|
|
15
|
+
/** Total debt in base currency (8 decimals, USD). */
|
|
16
|
+
totalDebtBase: bigint;
|
|
17
|
+
/** Available borrows in base currency (8 decimals, USD). */
|
|
18
|
+
availableBorrowsBase: bigint;
|
|
19
|
+
/** Current liquidation threshold in basis points (e.g., 8250 = 82.5%). */
|
|
20
|
+
currentLiquidationThreshold: bigint;
|
|
21
|
+
/** Loan-to-value ratio in basis points (e.g., 8000 = 80%). */
|
|
22
|
+
ltv: bigint;
|
|
23
|
+
/** Health factor with 18 decimal precision (1e18 = HF 1.0). */
|
|
24
|
+
healthFactor: bigint;
|
|
25
|
+
}
|
|
26
|
+
export interface ReserveData {
|
|
27
|
+
/** Current supply rate in ray units (1e27). */
|
|
28
|
+
liquidityRate: bigint;
|
|
29
|
+
/** Current variable borrow rate in ray units (1e27). */
|
|
30
|
+
variableBorrowRate: bigint;
|
|
31
|
+
/** Liquidity index in ray units. */
|
|
32
|
+
liquidityIndex: bigint;
|
|
33
|
+
/** Variable borrow index in ray units. */
|
|
34
|
+
variableBorrowIndex: bigint;
|
|
35
|
+
}
|
|
36
|
+
/** Health factor at liquidation threshold (1.0 in 18 decimals). */
|
|
37
|
+
export declare const LIQUIDATION_THRESHOLD_HF = 1000000000000000000n;
|
|
38
|
+
/** Health factor warning threshold (1.2 in 18 decimals). */
|
|
39
|
+
export declare const WARNING_THRESHOLD_HF = 1200000000000000000n;
|
|
40
|
+
/**
|
|
41
|
+
* Decode Pool.getUserAccountData() response.
|
|
42
|
+
*
|
|
43
|
+
* Returns 6 uint256 values:
|
|
44
|
+
* [0] totalCollateralBase (8 decimals, base currency = USD)
|
|
45
|
+
* [1] totalDebtBase (8 decimals)
|
|
46
|
+
* [2] availableBorrowsBase (8 decimals)
|
|
47
|
+
* [3] currentLiquidationThreshold (basis points)
|
|
48
|
+
* [4] ltv (basis points)
|
|
49
|
+
* [5] healthFactor (18 decimals)
|
|
50
|
+
*
|
|
51
|
+
* @param hexResponse - Raw hex response from eth_call (with or without 0x prefix)
|
|
52
|
+
* @throws Error if hex string is too short
|
|
53
|
+
*/
|
|
54
|
+
export declare function decodeGetUserAccountData(hexResponse: string): UserAccountData;
|
|
55
|
+
/**
|
|
56
|
+
* Decode PoolDataProvider.getReserveData() response (simplified).
|
|
57
|
+
*
|
|
58
|
+
* Extracts only the fields needed for APY calculation:
|
|
59
|
+
* - [1] liquidityIndex (index 1 = chars 64..128)
|
|
60
|
+
* - [2] variableBorrowIndex (index 2 = chars 128..192)
|
|
61
|
+
* - [3] currentLiquidityRate (index 3 = chars 192..256)
|
|
62
|
+
* - [4] currentVariableBorrowRate (index 4 = chars 256..320)
|
|
63
|
+
*
|
|
64
|
+
* @param hexResponse - Raw hex response from eth_call (with or without 0x prefix)
|
|
65
|
+
* @throws Error if hex string is too short
|
|
66
|
+
*/
|
|
67
|
+
export declare function decodeGetReserveData(hexResponse: string): ReserveData;
|
|
68
|
+
/**
|
|
69
|
+
* Convert Aave V3 ray-unit rate to decimal APY.
|
|
70
|
+
*
|
|
71
|
+
* Linear approximation: rate / 1e27 (good enough for display at typical DeFi rates).
|
|
72
|
+
* Returns as decimal (e.g., 0.035 for 3.5% APY).
|
|
73
|
+
*
|
|
74
|
+
* @param rayRate - Rate in ray units (1e27)
|
|
75
|
+
*/
|
|
76
|
+
export declare function rayToApy(rayRate: bigint): number;
|
|
77
|
+
/**
|
|
78
|
+
* Simulate health factor after a borrow or withdraw action.
|
|
79
|
+
*
|
|
80
|
+
* Uses bigint-only arithmetic for precision (Research Flag C2).
|
|
81
|
+
* Returns MAX_UINT256 when newTotalDebt is 0 (no debt = infinite HF).
|
|
82
|
+
*
|
|
83
|
+
* @param currentData - Current position data from getUserAccountData
|
|
84
|
+
* @param action - 'borrow' or 'withdraw'
|
|
85
|
+
* @param amountBase - Amount in base currency (8 decimals, USD)
|
|
86
|
+
* @returns Simulated health factor as 18-decimal bigint
|
|
87
|
+
*/
|
|
88
|
+
export declare function simulateHealthFactor(currentData: {
|
|
89
|
+
totalCollateralBase: bigint;
|
|
90
|
+
totalDebtBase: bigint;
|
|
91
|
+
currentLiquidationThreshold: bigint;
|
|
92
|
+
}, action: 'borrow' | 'withdraw', amountBase: bigint): bigint;
|
|
93
|
+
/**
|
|
94
|
+
* Convert 18-decimal bigint health factor to a display number.
|
|
95
|
+
*
|
|
96
|
+
* This is ONLY for API display responses, NOT for threshold comparisons.
|
|
97
|
+
* Use bigint comparisons (e.g., hf >= LIQUIDATION_THRESHOLD_HF) for safety checks.
|
|
98
|
+
*
|
|
99
|
+
* @param hf - Health factor as 18-decimal bigint
|
|
100
|
+
*/
|
|
101
|
+
export declare function hfToNumber(hf: bigint): number;
|
|
102
|
+
//# sourceMappingURL=aave-rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aave-rpc.d.ts","sourceRoot":"","sources":["../../../src/providers/aave-v3/aave-rpc.ts"],"names":[],"mappings":"AAeA;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CAC/E;AAMD,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,mBAAmB,EAAE,MAAM,CAAC;IAC5B,qDAAqD;IACrD,aAAa,EAAE,MAAM,CAAC;IACtB,4DAA4D;IAC5D,oBAAoB,EAAE,MAAM,CAAC;IAC7B,0EAA0E;IAC1E,2BAA2B,EAAE,MAAM,CAAC;IACpC,8DAA8D;IAC9D,GAAG,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,YAAY,EAAE,MAAM,CAAC;CACtB;AAMD,MAAM,WAAW,WAAW;IAC1B,+CAA+C;IAC/C,aAAa,EAAE,MAAM,CAAC;IACtB,wDAAwD;IACxD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,oCAAoC;IACpC,cAAc,EAAE,MAAM,CAAC;IACvB,0CAA0C;IAC1C,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAMD,mEAAmE;AACnE,eAAO,MAAM,wBAAwB,uBAA6B,CAAC;AAEnE,4DAA4D;AAC5D,eAAO,MAAM,oBAAoB,uBAA6B,CAAC;AAM/D;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,eAAe,CAiB7E;AAMD;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,WAAW,CAerE;AAMD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEhD;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE;IACX,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,2BAA2B,EAAE,MAAM,CAAC;CACrC,EACD,MAAM,EAAE,QAAQ,GAAG,UAAU,EAC7B,UAAU,EAAE,MAAM,GACjB,MAAM,CAmBR;AAMD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE7C"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aave V3 RPC response decoders, health factor simulation, and APY conversion.
|
|
3
|
+
*
|
|
4
|
+
* Pure functions operating on hex strings and bigints -- no actual RPC calls here.
|
|
5
|
+
* The IRpcCaller interface is the injection point for real RPC or mock in tests.
|
|
6
|
+
*
|
|
7
|
+
* IMPORTANT: All health factor threshold comparisons use bigint arithmetic.
|
|
8
|
+
* Never convert to Number for safety-critical HF checks (Research Flag C2).
|
|
9
|
+
*/
|
|
10
|
+
import { MAX_UINT256 } from './aave-contracts.js';
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
// Health factor threshold constants (18-decimal bigints)
|
|
13
|
+
// ---------------------------------------------------------------------------
|
|
14
|
+
/** Health factor at liquidation threshold (1.0 in 18 decimals). */
|
|
15
|
+
export const LIQUIDATION_THRESHOLD_HF = 1000000000000000000n;
|
|
16
|
+
/** Health factor warning threshold (1.2 in 18 decimals). */
|
|
17
|
+
export const WARNING_THRESHOLD_HF = 1200000000000000000n;
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
// decodeGetUserAccountData -- parse 6 x uint256 from hex response
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
/**
|
|
22
|
+
* Decode Pool.getUserAccountData() response.
|
|
23
|
+
*
|
|
24
|
+
* Returns 6 uint256 values:
|
|
25
|
+
* [0] totalCollateralBase (8 decimals, base currency = USD)
|
|
26
|
+
* [1] totalDebtBase (8 decimals)
|
|
27
|
+
* [2] availableBorrowsBase (8 decimals)
|
|
28
|
+
* [3] currentLiquidationThreshold (basis points)
|
|
29
|
+
* [4] ltv (basis points)
|
|
30
|
+
* [5] healthFactor (18 decimals)
|
|
31
|
+
*
|
|
32
|
+
* @param hexResponse - Raw hex response from eth_call (with or without 0x prefix)
|
|
33
|
+
* @throws Error if hex string is too short
|
|
34
|
+
*/
|
|
35
|
+
export function decodeGetUserAccountData(hexResponse) {
|
|
36
|
+
const data = hexResponse.startsWith('0x') ? hexResponse.slice(2) : hexResponse;
|
|
37
|
+
if (data.length < 384) {
|
|
38
|
+
throw new Error(`Invalid getUserAccountData response: expected at least 384 hex chars (6 x 32 bytes), got ${data.length}`);
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
totalCollateralBase: BigInt('0x' + data.slice(0, 64)),
|
|
42
|
+
totalDebtBase: BigInt('0x' + data.slice(64, 128)),
|
|
43
|
+
availableBorrowsBase: BigInt('0x' + data.slice(128, 192)),
|
|
44
|
+
currentLiquidationThreshold: BigInt('0x' + data.slice(192, 256)),
|
|
45
|
+
ltv: BigInt('0x' + data.slice(256, 320)),
|
|
46
|
+
healthFactor: BigInt('0x' + data.slice(320, 384)),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
// decodeGetReserveData -- extract rate fields from hex response
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
/**
|
|
53
|
+
* Decode PoolDataProvider.getReserveData() response (simplified).
|
|
54
|
+
*
|
|
55
|
+
* Extracts only the fields needed for APY calculation:
|
|
56
|
+
* - [1] liquidityIndex (index 1 = chars 64..128)
|
|
57
|
+
* - [2] variableBorrowIndex (index 2 = chars 128..192)
|
|
58
|
+
* - [3] currentLiquidityRate (index 3 = chars 192..256)
|
|
59
|
+
* - [4] currentVariableBorrowRate (index 4 = chars 256..320)
|
|
60
|
+
*
|
|
61
|
+
* @param hexResponse - Raw hex response from eth_call (with or without 0x prefix)
|
|
62
|
+
* @throws Error if hex string is too short
|
|
63
|
+
*/
|
|
64
|
+
export function decodeGetReserveData(hexResponse) {
|
|
65
|
+
const data = hexResponse.startsWith('0x') ? hexResponse.slice(2) : hexResponse;
|
|
66
|
+
if (data.length < 320) {
|
|
67
|
+
throw new Error(`Invalid getReserveData response: expected at least 320 hex chars (5 x 32 bytes), got ${data.length}`);
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
liquidityIndex: BigInt('0x' + data.slice(64, 128)),
|
|
71
|
+
variableBorrowIndex: BigInt('0x' + data.slice(128, 192)),
|
|
72
|
+
liquidityRate: BigInt('0x' + data.slice(192, 256)),
|
|
73
|
+
variableBorrowRate: BigInt('0x' + data.slice(256, 320)),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
// rayToApy -- convert ray (1e27) rate to decimal APY
|
|
78
|
+
// ---------------------------------------------------------------------------
|
|
79
|
+
/**
|
|
80
|
+
* Convert Aave V3 ray-unit rate to decimal APY.
|
|
81
|
+
*
|
|
82
|
+
* Linear approximation: rate / 1e27 (good enough for display at typical DeFi rates).
|
|
83
|
+
* Returns as decimal (e.g., 0.035 for 3.5% APY).
|
|
84
|
+
*
|
|
85
|
+
* @param rayRate - Rate in ray units (1e27)
|
|
86
|
+
*/
|
|
87
|
+
export function rayToApy(rayRate) {
|
|
88
|
+
return Number(rayRate) / 1e27;
|
|
89
|
+
}
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// simulateHealthFactor -- pre-action HF estimation
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
/**
|
|
94
|
+
* Simulate health factor after a borrow or withdraw action.
|
|
95
|
+
*
|
|
96
|
+
* Uses bigint-only arithmetic for precision (Research Flag C2).
|
|
97
|
+
* Returns MAX_UINT256 when newTotalDebt is 0 (no debt = infinite HF).
|
|
98
|
+
*
|
|
99
|
+
* @param currentData - Current position data from getUserAccountData
|
|
100
|
+
* @param action - 'borrow' or 'withdraw'
|
|
101
|
+
* @param amountBase - Amount in base currency (8 decimals, USD)
|
|
102
|
+
* @returns Simulated health factor as 18-decimal bigint
|
|
103
|
+
*/
|
|
104
|
+
export function simulateHealthFactor(currentData, action, amountBase) {
|
|
105
|
+
let collateral = currentData.totalCollateralBase;
|
|
106
|
+
let newTotalDebt = currentData.totalDebtBase;
|
|
107
|
+
if (action === 'borrow') {
|
|
108
|
+
newTotalDebt = currentData.totalDebtBase + amountBase;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
// withdraw reduces collateral
|
|
112
|
+
collateral = currentData.totalCollateralBase - amountBase;
|
|
113
|
+
}
|
|
114
|
+
const collateralThresholdAdjusted = (collateral * currentData.currentLiquidationThreshold) / 10000n;
|
|
115
|
+
if (newTotalDebt === 0n) {
|
|
116
|
+
return MAX_UINT256;
|
|
117
|
+
}
|
|
118
|
+
return (collateralThresholdAdjusted * 10n ** 18n) / newTotalDebt;
|
|
119
|
+
}
|
|
120
|
+
// ---------------------------------------------------------------------------
|
|
121
|
+
// hfToNumber -- convert 18-decimal bigint HF to display number
|
|
122
|
+
// ---------------------------------------------------------------------------
|
|
123
|
+
/**
|
|
124
|
+
* Convert 18-decimal bigint health factor to a display number.
|
|
125
|
+
*
|
|
126
|
+
* This is ONLY for API display responses, NOT for threshold comparisons.
|
|
127
|
+
* Use bigint comparisons (e.g., hf >= LIQUIDATION_THRESHOLD_HF) for safety checks.
|
|
128
|
+
*
|
|
129
|
+
* @param hf - Health factor as 18-decimal bigint
|
|
130
|
+
*/
|
|
131
|
+
export function hfToNumber(hf) {
|
|
132
|
+
return Number(hf) / 1e18;
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=aave-rpc.js.map
|