@lit-protocol/vincent-ability-aave 1.0.2-mma → 1.0.3-mma
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/dist/lib/helpers/aave.d.ts +85 -0
- package/dist/lib/helpers/aave.d.ts.map +1 -0
- package/dist/lib/helpers/aave.js +310 -0
- package/dist/lib/helpers/aave.js.map +1 -0
- package/dist/lib/helpers/transactionKind.d.ts +6 -0
- package/dist/lib/helpers/transactionKind.d.ts.map +1 -0
- package/dist/lib/helpers/transactionKind.js +10 -0
- package/dist/lib/helpers/transactionKind.js.map +1 -0
- package/dist/lib/validateSimulation.d.ts +3 -0
- package/dist/lib/validateSimulation.d.ts.map +1 -0
- package/dist/lib/validateSimulation.js +56 -0
- package/dist/lib/validateSimulation.js.map +1 -0
- package/dist/lib/validateTransaction.d.ts +3 -0
- package/dist/lib/validateTransaction.d.ts.map +1 -0
- package/dist/lib/validateTransaction.js +75 -0
- package/dist/lib/validateTransaction.js.map +1 -0
- package/dist/package.json +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { Abi, Address, Hex } from 'viem';
|
|
2
|
+
/**
|
|
3
|
+
* Fee Contract ABI for Aave operations
|
|
4
|
+
* These functions route through the fee contract instead of directly to Aave
|
|
5
|
+
*/
|
|
6
|
+
export declare const FEE_CONTRACT_ABI: Abi;
|
|
7
|
+
export interface Transaction {
|
|
8
|
+
data: Hex;
|
|
9
|
+
from: Address;
|
|
10
|
+
to: Address;
|
|
11
|
+
value: Hex;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get fee contract address for a specific chain
|
|
15
|
+
* @param chainId The chain ID
|
|
16
|
+
* @returns The fee contract address, or null if not available for this chain
|
|
17
|
+
*/
|
|
18
|
+
export declare function getFeeContractAddress(chainId: number): Address | null;
|
|
19
|
+
/**
|
|
20
|
+
* AAVE v3 Pool Contract ABI
|
|
21
|
+
*/
|
|
22
|
+
export declare const AAVE_POOL_ABI: Abi;
|
|
23
|
+
/**
|
|
24
|
+
* Chain id to Aave Address Book mapping
|
|
25
|
+
*/
|
|
26
|
+
export declare const CHAIN_TO_AAVE_ADDRESS_BOOK: Record<number, any>;
|
|
27
|
+
/**
|
|
28
|
+
* Get AAVE addresses for a specific chain using the Aave Address Book
|
|
29
|
+
*/
|
|
30
|
+
export declare function getAaveAddresses(chainId: number): {
|
|
31
|
+
POOL: any;
|
|
32
|
+
POOL_ADDRESSES_PROVIDER: any;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Get ATokens (aave deposit representation tokens) for a specific chain using the Aave Address Book
|
|
36
|
+
*/
|
|
37
|
+
export declare function getATokens(chainId: number): Record<string, Address>;
|
|
38
|
+
/**
|
|
39
|
+
* Get available markets (asset addresses) for a specific chain using the Aave Address Book
|
|
40
|
+
*/
|
|
41
|
+
export declare function getAvailableMarkets(chainId: number): Record<string, Address>;
|
|
42
|
+
export interface AaveApprovalTxParams {
|
|
43
|
+
accountAddress: Address;
|
|
44
|
+
amount?: string;
|
|
45
|
+
assetAddress: Address;
|
|
46
|
+
chainId: number;
|
|
47
|
+
}
|
|
48
|
+
export declare function getAaveApprovalTx({ accountAddress, assetAddress, chainId, amount, }: AaveApprovalTxParams): Transaction;
|
|
49
|
+
export interface AaveSupplyTxParams {
|
|
50
|
+
appId: number;
|
|
51
|
+
accountAddress: Address;
|
|
52
|
+
amount: string;
|
|
53
|
+
assetAddress: Address;
|
|
54
|
+
chainId: number;
|
|
55
|
+
}
|
|
56
|
+
export declare function getAaveSupplyTx({ appId, accountAddress, amount, assetAddress, chainId, }: AaveSupplyTxParams): Transaction;
|
|
57
|
+
export interface AaveWithdrawTxParams {
|
|
58
|
+
appId: number;
|
|
59
|
+
accountAddress: Address;
|
|
60
|
+
amount: string;
|
|
61
|
+
assetAddress: Address;
|
|
62
|
+
chainId: number;
|
|
63
|
+
to?: Address;
|
|
64
|
+
}
|
|
65
|
+
export declare function getAaveWithdrawTx({ appId, accountAddress, amount, assetAddress, chainId, }: AaveWithdrawTxParams): Transaction;
|
|
66
|
+
export interface AaveBorrowTxParams {
|
|
67
|
+
accountAddress: Address;
|
|
68
|
+
amount: string;
|
|
69
|
+
assetAddress: Address;
|
|
70
|
+
chainId: number;
|
|
71
|
+
interestRateMode: number;
|
|
72
|
+
onBehalfOf?: Address;
|
|
73
|
+
referralCode?: number;
|
|
74
|
+
}
|
|
75
|
+
export declare function getAaveBorrowTx({ accountAddress, amount, assetAddress, chainId, interestRateMode, onBehalfOf, referralCode, }: AaveBorrowTxParams): Transaction;
|
|
76
|
+
export interface AaveRepayTxParams {
|
|
77
|
+
accountAddress: Address;
|
|
78
|
+
amount: string;
|
|
79
|
+
assetAddress: Address;
|
|
80
|
+
chainId: number;
|
|
81
|
+
interestRateMode: number;
|
|
82
|
+
onBehalfOf?: Address;
|
|
83
|
+
}
|
|
84
|
+
export declare function getAaveRepayTx({ accountAddress, amount, assetAddress, chainId, interestRateMode, onBehalfOf, }: AaveRepayTxParams): Transaction;
|
|
85
|
+
//# sourceMappingURL=aave.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aave.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/aave.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AA+B9C;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,GAA4B,CAAC;AAE5D,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,EAAE,GAAG,CAAC;CACZ;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,CAQrE;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,GAwF3B,CAAC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oBAAoB,eAmBtB;AAED,MAAM,WAAW,kBAAkB;IACjC,cAAc,EAAE,OAAO,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,eAAe,CAAC,EAC9B,cAAc,EACd,MAAM,EACN,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,UAA2B,EAC3B,YAAgB,GACjB,EAAE,kBAAkB,eAgBpB;AAED,MAAM,WAAW,iBAAiB;IAChC,cAAc,EAAE,OAAO,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,gBAAgB,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,cAAc,CAAC,EAC7B,cAAc,EACd,MAAM,EACN,YAAY,EACZ,OAAO,EACP,gBAAgB,EAChB,UAA2B,GAC5B,EAAE,iBAAiB,eAgBnB"}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CHAIN_TO_AAVE_ADDRESS_BOOK = exports.AAVE_POOL_ABI = exports.FEE_CONTRACT_ABI = void 0;
|
|
4
|
+
exports.getFeeContractAddress = getFeeContractAddress;
|
|
5
|
+
exports.getAaveAddresses = getAaveAddresses;
|
|
6
|
+
exports.getATokens = getATokens;
|
|
7
|
+
exports.getAvailableMarkets = getAvailableMarkets;
|
|
8
|
+
exports.getAaveApprovalTx = getAaveApprovalTx;
|
|
9
|
+
exports.getAaveSupplyTx = getAaveSupplyTx;
|
|
10
|
+
exports.getAaveWithdrawTx = getAaveWithdrawTx;
|
|
11
|
+
exports.getAaveBorrowTx = getAaveBorrowTx;
|
|
12
|
+
exports.getAaveRepayTx = getAaveRepayTx;
|
|
13
|
+
const aave_address_book_1 = require("@bgd-labs/aave-address-book");
|
|
14
|
+
const vincent_contracts_sdk_1 = require("@lit-protocol/vincent-contracts-sdk");
|
|
15
|
+
const viem_1 = require("viem");
|
|
16
|
+
const erc20_1 = require("./erc20");
|
|
17
|
+
const ZERO_VALUE = '0x0';
|
|
18
|
+
/**
|
|
19
|
+
* Fee Contract ABI for Aave operations
|
|
20
|
+
* These functions route through the fee contract instead of directly to Aave
|
|
21
|
+
*/
|
|
22
|
+
exports.FEE_CONTRACT_ABI = vincent_contracts_sdk_1.FEE_DIAMOND_ABI;
|
|
23
|
+
/**
|
|
24
|
+
* Get fee contract address for a specific chain
|
|
25
|
+
* @param chainId The chain ID
|
|
26
|
+
* @returns The fee contract address, or null if not available for this chain
|
|
27
|
+
*/
|
|
28
|
+
function getFeeContractAddress(chainId) {
|
|
29
|
+
const feeConfig = vincent_contracts_sdk_1.VINCENT_CONTRACT_ADDRESS_BOOK.fee[chainId];
|
|
30
|
+
if (!feeConfig) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return (0, viem_1.getAddress)(feeConfig.address);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* AAVE v3 Pool Contract ABI
|
|
37
|
+
*/
|
|
38
|
+
exports.AAVE_POOL_ABI = [
|
|
39
|
+
// Supply
|
|
40
|
+
{
|
|
41
|
+
inputs: [
|
|
42
|
+
{ internalType: 'address', name: 'asset', type: 'address' },
|
|
43
|
+
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
|
|
44
|
+
{ internalType: 'address', name: 'onBehalfOf', type: 'address' },
|
|
45
|
+
{ internalType: 'uint16', name: 'referralCode', type: 'uint16' },
|
|
46
|
+
],
|
|
47
|
+
name: 'supply',
|
|
48
|
+
outputs: [],
|
|
49
|
+
stateMutability: 'nonpayable',
|
|
50
|
+
type: 'function',
|
|
51
|
+
},
|
|
52
|
+
// Withdraw
|
|
53
|
+
{
|
|
54
|
+
inputs: [
|
|
55
|
+
{ internalType: 'address', name: 'asset', type: 'address' },
|
|
56
|
+
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
|
|
57
|
+
{ internalType: 'address', name: 'to', type: 'address' },
|
|
58
|
+
],
|
|
59
|
+
name: 'withdraw',
|
|
60
|
+
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
61
|
+
stateMutability: 'nonpayable',
|
|
62
|
+
type: 'function',
|
|
63
|
+
},
|
|
64
|
+
// Borrow
|
|
65
|
+
{
|
|
66
|
+
inputs: [
|
|
67
|
+
{ internalType: 'address', name: 'asset', type: 'address' },
|
|
68
|
+
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
|
|
69
|
+
{ internalType: 'uint256', name: 'interestRateMode', type: 'uint256' },
|
|
70
|
+
{ internalType: 'uint16', name: 'referralCode', type: 'uint16' },
|
|
71
|
+
{ internalType: 'address', name: 'onBehalfOf', type: 'address' },
|
|
72
|
+
],
|
|
73
|
+
name: 'borrow',
|
|
74
|
+
outputs: [],
|
|
75
|
+
stateMutability: 'nonpayable',
|
|
76
|
+
type: 'function',
|
|
77
|
+
},
|
|
78
|
+
// Repay
|
|
79
|
+
{
|
|
80
|
+
inputs: [
|
|
81
|
+
{ internalType: 'address', name: 'asset', type: 'address' },
|
|
82
|
+
{ internalType: 'uint256', name: 'amount', type: 'uint256' },
|
|
83
|
+
{ internalType: 'uint256', name: 'interestRateMode', type: 'uint256' },
|
|
84
|
+
{ internalType: 'address', name: 'onBehalfOf', type: 'address' },
|
|
85
|
+
],
|
|
86
|
+
name: 'repay',
|
|
87
|
+
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
|
|
88
|
+
stateMutability: 'nonpayable',
|
|
89
|
+
type: 'function',
|
|
90
|
+
},
|
|
91
|
+
// getUserAccountData
|
|
92
|
+
{
|
|
93
|
+
inputs: [{ internalType: 'address', name: 'user', type: 'address' }],
|
|
94
|
+
name: 'getUserAccountData',
|
|
95
|
+
outputs: [
|
|
96
|
+
{ internalType: 'uint256', name: 'totalCollateralBase', type: 'uint256' },
|
|
97
|
+
{ internalType: 'uint256', name: 'totalDebtBase', type: 'uint256' },
|
|
98
|
+
{
|
|
99
|
+
internalType: 'uint256',
|
|
100
|
+
name: 'availableBorrowsBase',
|
|
101
|
+
type: 'uint256',
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
internalType: 'uint256',
|
|
105
|
+
name: 'currentLiquidationThreshold',
|
|
106
|
+
type: 'uint256',
|
|
107
|
+
},
|
|
108
|
+
{ internalType: 'uint256', name: 'ltv', type: 'uint256' },
|
|
109
|
+
{ internalType: 'uint256', name: 'healthFactor', type: 'uint256' },
|
|
110
|
+
],
|
|
111
|
+
stateMutability: 'view',
|
|
112
|
+
type: 'function',
|
|
113
|
+
},
|
|
114
|
+
// setUserUseReserveAsCollateral
|
|
115
|
+
{
|
|
116
|
+
inputs: [
|
|
117
|
+
{ internalType: 'address', name: 'asset', type: 'address' },
|
|
118
|
+
{ internalType: 'bool', name: 'useAsCollateral', type: 'bool' },
|
|
119
|
+
],
|
|
120
|
+
name: 'setUserUseReserveAsCollateral',
|
|
121
|
+
outputs: [],
|
|
122
|
+
stateMutability: 'nonpayable',
|
|
123
|
+
type: 'function',
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
/**
|
|
127
|
+
* Chain id to Aave Address Book mapping
|
|
128
|
+
*/
|
|
129
|
+
exports.CHAIN_TO_AAVE_ADDRESS_BOOK = {
|
|
130
|
+
// Mainnets
|
|
131
|
+
1: aave_address_book_1.AaveV3Ethereum,
|
|
132
|
+
137: aave_address_book_1.AaveV3Polygon,
|
|
133
|
+
43114: aave_address_book_1.AaveV3Avalanche,
|
|
134
|
+
42161: aave_address_book_1.AaveV3Arbitrum,
|
|
135
|
+
10: aave_address_book_1.AaveV3Optimism,
|
|
136
|
+
8453: aave_address_book_1.AaveV3Base,
|
|
137
|
+
56: aave_address_book_1.AaveV3BNB,
|
|
138
|
+
100: aave_address_book_1.AaveV3Gnosis,
|
|
139
|
+
534352: aave_address_book_1.AaveV3Scroll,
|
|
140
|
+
1088: aave_address_book_1.AaveV3Metis,
|
|
141
|
+
59144: aave_address_book_1.AaveV3Linea,
|
|
142
|
+
324: aave_address_book_1.AaveV3ZkSync,
|
|
143
|
+
// Testnets
|
|
144
|
+
11155111: aave_address_book_1.AaveV3Sepolia,
|
|
145
|
+
84532: aave_address_book_1.AaveV3BaseSepolia,
|
|
146
|
+
421614: aave_address_book_1.AaveV3ArbitrumSepolia,
|
|
147
|
+
11155420: aave_address_book_1.AaveV3OptimismSepolia,
|
|
148
|
+
534351: aave_address_book_1.AaveV3ScrollSepolia,
|
|
149
|
+
};
|
|
150
|
+
/**
|
|
151
|
+
* Get AAVE addresses for a specific chain using the Aave Address Book
|
|
152
|
+
*/
|
|
153
|
+
function getAaveAddresses(chainId) {
|
|
154
|
+
// First try to get from the official Address Book
|
|
155
|
+
if (chainId in exports.CHAIN_TO_AAVE_ADDRESS_BOOK) {
|
|
156
|
+
try {
|
|
157
|
+
const addressBook = exports.CHAIN_TO_AAVE_ADDRESS_BOOK[chainId];
|
|
158
|
+
return {
|
|
159
|
+
POOL: addressBook.POOL,
|
|
160
|
+
POOL_ADDRESSES_PROVIDER: addressBook.POOL_ADDRESSES_PROVIDER,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.warn(`Failed to load from Address Book for chain ${chainId}:`, error);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
throw new Error(`Unsupported chain: ${chainId}. Supported chains: ${[
|
|
168
|
+
...Object.keys(exports.CHAIN_TO_AAVE_ADDRESS_BOOK),
|
|
169
|
+
].join(', ')}`);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Get ATokens (aave deposit representation tokens) for a specific chain using the Aave Address Book
|
|
173
|
+
*/
|
|
174
|
+
function getATokens(chainId) {
|
|
175
|
+
// First try to get from the official Address Book
|
|
176
|
+
if (chainId in exports.CHAIN_TO_AAVE_ADDRESS_BOOK) {
|
|
177
|
+
try {
|
|
178
|
+
const addressBook = exports.CHAIN_TO_AAVE_ADDRESS_BOOK[chainId];
|
|
179
|
+
const aTokens = {};
|
|
180
|
+
// Extract asset addresses from the address book
|
|
181
|
+
// The address book contains ASSETS object with token addresses
|
|
182
|
+
if (addressBook.ASSETS) {
|
|
183
|
+
Object.keys(addressBook.ASSETS).forEach((assetKey) => {
|
|
184
|
+
const asset = addressBook.ASSETS[assetKey];
|
|
185
|
+
if (asset.UNDERLYING) {
|
|
186
|
+
aTokens[assetKey] = asset.A_TOKEN;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return aTokens;
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
console.warn(`Failed to load ATokens from Address Book for ${chainId}:`, error);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
throw new Error(`No ATokens available for chain: ${chainId}. Supported chains: ${[
|
|
197
|
+
...Object.keys(exports.CHAIN_TO_AAVE_ADDRESS_BOOK),
|
|
198
|
+
].join(', ')}`);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Get available markets (asset addresses) for a specific chain using the Aave Address Book
|
|
202
|
+
*/
|
|
203
|
+
function getAvailableMarkets(chainId) {
|
|
204
|
+
// First try to get from the official Address Book
|
|
205
|
+
if (chainId in exports.CHAIN_TO_AAVE_ADDRESS_BOOK) {
|
|
206
|
+
try {
|
|
207
|
+
const addressBook = exports.CHAIN_TO_AAVE_ADDRESS_BOOK[chainId];
|
|
208
|
+
const markets = {};
|
|
209
|
+
// Extract asset addresses from the address book
|
|
210
|
+
// The address book contains ASSETS object with token addresses
|
|
211
|
+
if (addressBook.ASSETS) {
|
|
212
|
+
Object.keys(addressBook.ASSETS).forEach((assetKey) => {
|
|
213
|
+
const asset = addressBook.ASSETS[assetKey];
|
|
214
|
+
if (asset.UNDERLYING) {
|
|
215
|
+
markets[assetKey] = asset.UNDERLYING;
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
return markets;
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
console.warn(`Failed to load markets from Address Book for ${chainId}:`, error);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
throw new Error(`No markets available for chain: ${chainId}. Supported chains: ${[
|
|
226
|
+
...Object.keys(exports.CHAIN_TO_AAVE_ADDRESS_BOOK),
|
|
227
|
+
].join(', ')}`);
|
|
228
|
+
}
|
|
229
|
+
function getAaveApprovalTx({ accountAddress, assetAddress, chainId, amount, }) {
|
|
230
|
+
const feeContractAddress = getFeeContractAddress(chainId);
|
|
231
|
+
const approveData = (0, viem_1.encodeFunctionData)({
|
|
232
|
+
abi: erc20_1.ERC20_ABI,
|
|
233
|
+
functionName: 'approve',
|
|
234
|
+
args: [feeContractAddress, amount],
|
|
235
|
+
});
|
|
236
|
+
const approveTx = {
|
|
237
|
+
data: approveData,
|
|
238
|
+
from: accountAddress,
|
|
239
|
+
to: assetAddress,
|
|
240
|
+
value: ZERO_VALUE,
|
|
241
|
+
};
|
|
242
|
+
return approveTx;
|
|
243
|
+
}
|
|
244
|
+
function getAaveSupplyTx({ appId, accountAddress, amount, assetAddress, chainId, }) {
|
|
245
|
+
const feeContractAddress = getFeeContractAddress(chainId);
|
|
246
|
+
if (!feeContractAddress) {
|
|
247
|
+
throw new Error(`No fee contract address available for chain ${chainId}`);
|
|
248
|
+
}
|
|
249
|
+
const supplyData = (0, viem_1.encodeFunctionData)({
|
|
250
|
+
abi: vincent_contracts_sdk_1.FEE_DIAMOND_ABI,
|
|
251
|
+
functionName: 'depositToAave',
|
|
252
|
+
args: [appId, assetAddress, amount],
|
|
253
|
+
});
|
|
254
|
+
const supplyTx = {
|
|
255
|
+
data: supplyData,
|
|
256
|
+
from: accountAddress,
|
|
257
|
+
to: feeContractAddress,
|
|
258
|
+
value: ZERO_VALUE,
|
|
259
|
+
};
|
|
260
|
+
return supplyTx;
|
|
261
|
+
}
|
|
262
|
+
function getAaveWithdrawTx({ appId, accountAddress, amount, assetAddress, chainId, }) {
|
|
263
|
+
const feeContractAddress = getFeeContractAddress(chainId);
|
|
264
|
+
if (!feeContractAddress) {
|
|
265
|
+
throw new Error(`No fee contract address available for chain ${chainId}`);
|
|
266
|
+
}
|
|
267
|
+
const withdrawData = (0, viem_1.encodeFunctionData)({
|
|
268
|
+
abi: vincent_contracts_sdk_1.FEE_DIAMOND_ABI,
|
|
269
|
+
functionName: 'withdrawFromAave',
|
|
270
|
+
args: [appId, assetAddress, amount],
|
|
271
|
+
});
|
|
272
|
+
const withdrawTx = {
|
|
273
|
+
data: withdrawData,
|
|
274
|
+
from: accountAddress,
|
|
275
|
+
to: feeContractAddress,
|
|
276
|
+
value: ZERO_VALUE,
|
|
277
|
+
};
|
|
278
|
+
return withdrawTx;
|
|
279
|
+
}
|
|
280
|
+
function getAaveBorrowTx({ accountAddress, amount, assetAddress, chainId, interestRateMode, onBehalfOf = accountAddress, referralCode = 0, }) {
|
|
281
|
+
const { POOL } = getAaveAddresses(chainId);
|
|
282
|
+
const borrowData = (0, viem_1.encodeFunctionData)({
|
|
283
|
+
abi: exports.AAVE_POOL_ABI,
|
|
284
|
+
functionName: 'borrow',
|
|
285
|
+
args: [assetAddress, amount, interestRateMode, referralCode, onBehalfOf],
|
|
286
|
+
});
|
|
287
|
+
const borrowTx = {
|
|
288
|
+
data: borrowData,
|
|
289
|
+
from: accountAddress,
|
|
290
|
+
to: POOL,
|
|
291
|
+
value: ZERO_VALUE,
|
|
292
|
+
};
|
|
293
|
+
return borrowTx;
|
|
294
|
+
}
|
|
295
|
+
function getAaveRepayTx({ accountAddress, amount, assetAddress, chainId, interestRateMode, onBehalfOf = accountAddress, }) {
|
|
296
|
+
const { POOL } = getAaveAddresses(chainId);
|
|
297
|
+
const repayData = (0, viem_1.encodeFunctionData)({
|
|
298
|
+
abi: exports.AAVE_POOL_ABI,
|
|
299
|
+
functionName: 'repay',
|
|
300
|
+
args: [assetAddress, amount, interestRateMode, onBehalfOf],
|
|
301
|
+
});
|
|
302
|
+
const repayTx = {
|
|
303
|
+
data: repayData,
|
|
304
|
+
from: accountAddress,
|
|
305
|
+
to: POOL,
|
|
306
|
+
value: ZERO_VALUE,
|
|
307
|
+
};
|
|
308
|
+
return repayTx;
|
|
309
|
+
}
|
|
310
|
+
//# sourceMappingURL=aave.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aave.js","sourceRoot":"","sources":["../../../src/lib/helpers/aave.ts"],"names":[],"mappings":";;;AAiDA,sDAQC;AA2HD,4CAmBC;AAKD,gCA6BC;AAKD,kDA6BC;AASD,8CAqBC;AAUD,0CAyBC;AAWD,8CAyBC;AAYD,0CAwBC;AAWD,wCAuBC;AApbD,mEAkBqC;AACrC,+EAG6C;AAC7C,+BAAsD;AAEtD,mCAAoC;AAEpC,MAAM,UAAU,GAAQ,KAAK,CAAC;AAE9B;;;GAGG;AACU,QAAA,gBAAgB,GAAQ,uCAAsB,CAAC;AAS5D;;;;GAIG;AACH,SAAgB,qBAAqB,CAAC,OAAe;IACnD,MAAM,SAAS,GACb,qDAA6B,CAAC,GAAG,CAAC,OAAyD,CAAC,CAAC;IAC/F,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,IAAA,iBAAU,EAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AACvC,CAAC;AAED;;GAEG;AACU,QAAA,aAAa,GAAQ;IAChC,SAAS;IACT;QACE,MAAM,EAAE;YACN,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE;YAC3D,EAAE,YAAY,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EA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I,EAAE,SAAS;QACf,IAAI,EAAE,cAAc;QACpB,EAAE,EAAE,IAAI;QACR,KAAK,EAAE,UAAU;KAClB,CAAC;IAEF,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactionKind.d.ts","sourceRoot":"","sources":["../../../src/lib/helpers/transactionKind.ts"],"names":[],"mappings":"AAAA,oBAAY,eAAe;IACzB,IAAI,SAAS;IACb,KAAK,UAAU;IACf,GAAG,QAAQ;CACZ"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionKind = void 0;
|
|
4
|
+
var TransactionKind;
|
|
5
|
+
(function (TransactionKind) {
|
|
6
|
+
TransactionKind["AAVE"] = "aave";
|
|
7
|
+
TransactionKind["ERC20"] = "erc20";
|
|
8
|
+
TransactionKind["FEE"] = "fee";
|
|
9
|
+
})(TransactionKind || (exports.TransactionKind = TransactionKind = {}));
|
|
10
|
+
//# sourceMappingURL=transactionKind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transactionKind.js","sourceRoot":"","sources":["../../../src/lib/helpers/transactionKind.ts"],"names":[],"mappings":";;;AAAA,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,gCAAa,CAAA;IACb,kCAAe,CAAA;IACf,8BAAW,CAAA;AACb,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateSimulation.d.ts","sourceRoot":"","sources":["../../src/lib/validateSimulation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AAM9F,eAAO,MAAM,kBAAkB,GAAI,QAAQ,wBAAwB,SA6DlE,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateSimulation = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const aave_1 = require("./helpers/aave");
|
|
6
|
+
const validateSimulation = (params) => {
|
|
7
|
+
const { chainId, sender: _sender, simulation } = params;
|
|
8
|
+
if (simulation.error) {
|
|
9
|
+
const { message, revertReason } = simulation.error;
|
|
10
|
+
throw new Error(`Simulation failed - Reason: ${revertReason} - Message: ${message}`);
|
|
11
|
+
}
|
|
12
|
+
const _feeContract = (0, aave_1.getFeeContractAddress)(chainId) || viem_1.zeroAddress; // Default to zeroAddress for code simplicity
|
|
13
|
+
const feeContract = (0, viem_1.getAddress)(_feeContract, chainId);
|
|
14
|
+
const { POOL: aavePoolAddress } = (0, aave_1.getAaveAddresses)(chainId);
|
|
15
|
+
const aaveATokens = (0, aave_1.getATokens)(chainId);
|
|
16
|
+
const sender = (0, viem_1.getAddress)(_sender, chainId);
|
|
17
|
+
const pool = (0, viem_1.getAddress)(aavePoolAddress, chainId);
|
|
18
|
+
const aTokens = Object.values(aaveATokens).map((a) => (0, viem_1.getAddress)(a, chainId));
|
|
19
|
+
const allowed = new Set([viem_1.zeroAddress, sender, pool, feeContract, ...aTokens]);
|
|
20
|
+
simulation.changes.forEach((c, idx) => {
|
|
21
|
+
const assetType = c.assetType;
|
|
22
|
+
const changeType = c.changeType;
|
|
23
|
+
const from = (0, viem_1.getAddress)(c.from, chainId);
|
|
24
|
+
const to = (0, viem_1.getAddress)(c.to, chainId);
|
|
25
|
+
// Helper for throwing with context
|
|
26
|
+
const fail = (reason) => {
|
|
27
|
+
throw new Error(`Invalid simulation change at index ${idx}: ${reason} [assetType=${assetType}, changeType=${changeType}, from=${from}, to=${to}]`);
|
|
28
|
+
};
|
|
29
|
+
if (assetType === 'NATIVE') {
|
|
30
|
+
if (changeType !== 'TRANSFER') {
|
|
31
|
+
fail('Only TRANSFER is allowed for NATIVE');
|
|
32
|
+
}
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (assetType === 'ERC20') {
|
|
36
|
+
if (changeType === 'APPROVE') {
|
|
37
|
+
if (![sender, feeContract].includes(from) || ![pool, feeContract].includes(to)) {
|
|
38
|
+
fail('ERC20 APPROVE must be from userOp.sender to aave pool or fee contract');
|
|
39
|
+
}
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
if (changeType === 'TRANSFER') {
|
|
43
|
+
if (!allowed.has(from) || !allowed.has(to)) {
|
|
44
|
+
fail('ERC20 TRANSFER endpoints must be within {zero address, sender, fee contract or Aave addresses}');
|
|
45
|
+
}
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// Unknown change type for ERC20
|
|
49
|
+
fail('Unsupported ERC20 change type');
|
|
50
|
+
}
|
|
51
|
+
// Any other asset types are not permitted
|
|
52
|
+
fail('Unsupported asset type');
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.validateSimulation = validateSimulation;
|
|
56
|
+
//# sourceMappingURL=validateSimulation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateSimulation.js","sourceRoot":"","sources":["../../src/lib/validateSimulation.ts"],"names":[],"mappings":";;;AAEA,+BAA+C;AAE/C,yCAAqF;AAE9E,MAAM,kBAAkB,GAAG,CAAC,MAAgC,EAAE,EAAE;IACrE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAExD,IAAI,UAAU,CAAC,KAAK,EAAE,CAAC;QACrB,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,+BAA+B,YAAY,eAAe,OAAO,EAAE,CAAC,CAAC;IACvF,CAAC;IAED,MAAM,YAAY,GAAG,IAAA,4BAAqB,EAAC,OAAO,CAAC,IAAI,kBAAW,CAAC,CAAC,6CAA6C;IACjH,MAAM,WA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,EAAE,CAAC;YAC3B,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;gBAC9B,IAAI,CAAC,qCAAqC,CAAC,CAAC;YAC9C,CAAC;YACD,OAAO;QACT,CAAC;QAED,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;YAC1B,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;gBAC7B,IAAI,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,EAAE,CAAC;oBAC/E,IAAI,CAAC,uEAAuE,CAAC,CAAC;gBAChF,CAAC;gBACD,OAAO;YACT,CAAC;YACD,IAAI,UAAU,KAAK,UAAU,EAAE,CAAC;gBAC9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;oBAC3C,IAAI,CACF,gGAAgG,CACjG,CAAC;gBACJ,CAAC;gBACD,OAAO;YACT,CAAC;YAED,gCAAgC;YAChC,IAAI,CAAC,+BAA+B,CAAC,CAAC;QACxC,CAAC;QAED,0CAA0C;QAC1C,IAAI,CAAC,wBAAwB,CAAC,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA7DW,QAAA,kBAAkB,sBA6D7B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateTransaction.d.ts","sourceRoot":"","sources":["../../src/lib/validateTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,yBAAyB,EAC1B,MAAM,+CAA+C,CAAC;AAQvD,eAAO,MAAM,mBAAmB,GAAI,QAAQ,yBAAyB,SAkEpE,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateTransaction = void 0;
|
|
4
|
+
const viem_1 = require("viem");
|
|
5
|
+
const aave_1 = require("./helpers/aave");
|
|
6
|
+
const transactionKind_1 = require("./helpers/transactionKind");
|
|
7
|
+
const validateTransaction = (params) => {
|
|
8
|
+
const { chainId, decodedTransaction, sender } = params;
|
|
9
|
+
if (decodedTransaction.kind === 'error') {
|
|
10
|
+
const decodedTransactionError = decodedTransaction;
|
|
11
|
+
throw new Error(`Transaction failed to decode: ${decodedTransactionError.message}`);
|
|
12
|
+
}
|
|
13
|
+
const decodedTransactionSuccess = decodedTransaction;
|
|
14
|
+
const feeContractAddress = (0, aave_1.getFeeContractAddress)(chainId);
|
|
15
|
+
if (!feeContractAddress) {
|
|
16
|
+
throw new Error(`Fee contract address not found for chainId ${chainId}`);
|
|
17
|
+
}
|
|
18
|
+
if (decodedTransaction.kind === transactionKind_1.TransactionKind.ERC20) {
|
|
19
|
+
if (['approve', 'increaseAllowance'].includes(decodedTransactionSuccess.fn)) {
|
|
20
|
+
const [spender, amount] = decodedTransactionSuccess.args;
|
|
21
|
+
if (!(0, viem_1.isAddressEqual)(spender, feeContractAddress)) {
|
|
22
|
+
throw new Error(`ERC20 approval to forbidden spender ${spender}`);
|
|
23
|
+
}
|
|
24
|
+
if (amount === 2n ** 256n - 1n)
|
|
25
|
+
throw new Error('Infinite approval not allowed');
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
throw new Error('ERC20 function not allowed');
|
|
29
|
+
}
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (decodedTransaction.kind === transactionKind_1.TransactionKind.FEE) {
|
|
33
|
+
if (['depositToAave', 'withdrawFromAave'].includes(decodedTransactionSuccess.fn)) {
|
|
34
|
+
// const [appId, assetAddress, amount] =
|
|
35
|
+
// decodedTransactionSuccess.args as [number, Address, bigint];
|
|
36
|
+
// There is nothing to block here
|
|
37
|
+
// A wrong appId and the delegatee will produce an invalid signature
|
|
38
|
+
// A wrong assetAddress or amount and the deposit/withdrawal will fail
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
throw new Error('Fee function not allowed');
|
|
42
|
+
}
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (decodedTransaction.kind === transactionKind_1.TransactionKind.AAVE) {
|
|
46
|
+
const fn = decodedTransactionSuccess.fn;
|
|
47
|
+
const args = decodedTransactionSuccess.args; // Args depend on the function being called
|
|
48
|
+
if (fn === 'supply') {
|
|
49
|
+
if (!(0, viem_1.isAddressEqual)(args[2], sender))
|
|
50
|
+
throw new Error('supply.onBehalfOf != sender');
|
|
51
|
+
}
|
|
52
|
+
else if (fn === 'withdraw') {
|
|
53
|
+
if (!(0, viem_1.isAddressEqual)(args[2], sender))
|
|
54
|
+
throw new Error('withdraw.to != sender');
|
|
55
|
+
}
|
|
56
|
+
else if (fn === 'borrow') {
|
|
57
|
+
if (!(0, viem_1.isAddressEqual)(args[4], sender))
|
|
58
|
+
throw new Error('borrow.onBehalfOf != sender');
|
|
59
|
+
}
|
|
60
|
+
else if (fn === 'repay') {
|
|
61
|
+
if (!(0, viem_1.isAddressEqual)(args[3], sender))
|
|
62
|
+
throw new Error('repay.onBehalfOf != sender');
|
|
63
|
+
}
|
|
64
|
+
else if (fn === 'setUserUseReserveAsCollateral') {
|
|
65
|
+
// ok; self-scoped setting
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new Error(`Aave Pool function not allowed: ${fn}`);
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
throw new Error('Unknown decoded transaction kind. Could not validate transaction.');
|
|
73
|
+
};
|
|
74
|
+
exports.validateTransaction = validateTransaction;
|
|
75
|
+
//# sourceMappingURL=validateTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateTransaction.js","sourceRoot":"","sources":["../../src/lib/validateTransaction.ts"],"names":[],"mappings":";;;AAOA,+BAAsC;AAEtC,yCAAuD;AACvD,+DAA4D;AAErD,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CAAC;YAClD,0BAA0B;QAC5B,CAAC;aAAM,CAAC;YACN,MAAM,IAAI,KAAK,CAAC,mCAAmC,EAAE,EAAE,CAAC,CAAC;QAC3D,CAAC;QAED,OAAO;IACT,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;AACvF,CAAC,CAAC;AAlEW,QAAA,mBAAmB,uBAkE9B"}
|
package/dist/package.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lit-protocol/vincent-ability-aave",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3-mma",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
"@bgd-labs/aave-address-book": "^4.19.3",
|
|
9
9
|
"tslib": "2.8.1",
|
|
10
10
|
"viem": "^2.38.3",
|
|
11
|
-
"@lit-protocol/vincent-ability-sdk": "2.
|
|
12
|
-
"@lit-protocol/vincent-contracts-sdk": "5.
|
|
11
|
+
"@lit-protocol/vincent-ability-sdk": "2.4.1-mma",
|
|
12
|
+
"@lit-protocol/vincent-contracts-sdk": "5.1.1-mma"
|
|
13
13
|
},
|
|
14
14
|
"peerDependencies": {
|
|
15
15
|
"@lit-protocol/vincent-app-sdk": "^2.5.0"
|