otomato-sdk 2.0.8 → 2.0.10
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/src/constants/version.js +1 -1
- package/dist/src/index.js +1 -0
- package/dist/src/services/ApiService.js +2 -2
- package/dist/src/utils/balances/addressBalance.js +177 -0
- package/dist/src/utils/balances/getBalanceInUnderlying.js +95 -0
- package/dist/src/utils/typeValidator.js +1 -1
- package/dist/types/examples/everyhour-ifusdc-ionic.d.ts +1 -0
- package/dist/types/examples/lending-aggregator.d.ts +1 -0
- package/dist/types/src/constants/version.d.ts +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/services/ApiService.d.ts +1 -1
- package/dist/types/src/utils/balances/addressBalance.d.ts +20 -0
- package/dist/types/src/utils/balances/getBalanceInUnderlying.d.ts +44 -0
- package/dist/types/test/addressBalance.spec.d.ts +1 -0
- package/package.json +1 -1
package/dist/src/index.js
CHANGED
|
@@ -53,10 +53,10 @@ class ApiServices {
|
|
|
53
53
|
return yield axiosInstance.delete(url, { headers });
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
-
generateLoginPayload(address, chainId,
|
|
56
|
+
generateLoginPayload(address, chainId, referralCode) {
|
|
57
57
|
return __awaiter(this, void 0, void 0, function* () {
|
|
58
58
|
const headers = { 'Content-Type': 'application/json' };
|
|
59
|
-
const response = yield axiosInstance.post('/auth/generate-payload', { address, chainId,
|
|
59
|
+
const response = yield axiosInstance.post('/auth/generate-payload', { address, chainId, referralCode }, { headers });
|
|
60
60
|
return response.data;
|
|
61
61
|
});
|
|
62
62
|
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
// getUserProtocolBalances.ts
|
|
11
|
+
import { ethers } from 'ethers';
|
|
12
|
+
import { rpcServices } from '../../services/RpcServices';
|
|
13
|
+
// -------------- PROTOCOLS ENUM --------------
|
|
14
|
+
export const PROTOCOLS = {
|
|
15
|
+
AAVE: 'AAVE',
|
|
16
|
+
COMPOUND: 'COMPOUND',
|
|
17
|
+
IONIC: 'IONIC',
|
|
18
|
+
MOONWELL: 'MOONWELL',
|
|
19
|
+
WALLET: 'WALLET',
|
|
20
|
+
};
|
|
21
|
+
// Minimal ABIs
|
|
22
|
+
const ERC20_ABI = [
|
|
23
|
+
'function balanceOf(address) view returns (uint256)',
|
|
24
|
+
'function decimals() view returns (uint8)',
|
|
25
|
+
'function symbol() view returns (string)',
|
|
26
|
+
];
|
|
27
|
+
const COMPOUNDV2_EXCHANGERATE_ABI = [
|
|
28
|
+
'function exchangeRateCurrent() view returns (uint)',
|
|
29
|
+
];
|
|
30
|
+
// -------------- ACTUAL MAP --------------
|
|
31
|
+
const chainTokenProtocolMap = {
|
|
32
|
+
8453: {
|
|
33
|
+
// USDC on Base
|
|
34
|
+
'0x833589fcd6edb6e08f4c7c32d4f71b54bda02913': [
|
|
35
|
+
{ protocol: PROTOCOLS.AAVE, token: '0x4e65fE4DbA92790696d040ac24Aa414708F5c0AB' },
|
|
36
|
+
{ protocol: PROTOCOLS.COMPOUND, token: '0xb125E6687d4313864e53df431d5425969c15Eb2F' },
|
|
37
|
+
{ protocol: PROTOCOLS.IONIC, token: '0xa900A17a49Bc4D442bA7F72c39FA2108865671f0' },
|
|
38
|
+
{ protocol: PROTOCOLS.MOONWELL, token: '0xEdc817A28E8B93B03976FBd4a3dDBc9f7D176c22' },
|
|
39
|
+
{ protocol: PROTOCOLS.WALLET, token: '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913' },
|
|
40
|
+
],
|
|
41
|
+
// WETH on Base
|
|
42
|
+
'0x4200000000000000000000000000000000000006': [
|
|
43
|
+
{ protocol: PROTOCOLS.AAVE, token: '0xd4a0e0b9149BCee3C920d2E00b5dE09138fd8bb7' },
|
|
44
|
+
{ protocol: PROTOCOLS.COMPOUND, token: '0x46e6b214b524310239732D51387075E0e70970bf' },
|
|
45
|
+
{ protocol: PROTOCOLS.IONIC, token: '0x49420311B518f3d0c94e897592014de53831cfA3' },
|
|
46
|
+
{ protocol: PROTOCOLS.MOONWELL, token: '0x628ff693426583D9a7FB391E54366292F509D457' },
|
|
47
|
+
{ protocol: PROTOCOLS.WALLET, token: '0x4200000000000000000000000000000000000006' },
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
34443: {
|
|
51
|
+
// USDC on Mode
|
|
52
|
+
'0xd988097fb8612cc24eeC14542bC03424c656005f': [
|
|
53
|
+
{ protocol: PROTOCOLS.IONIC, token: '0x2BE717340023C9e14C1Bb12cb3ecBcfd3c3fB038' },
|
|
54
|
+
{ protocol: PROTOCOLS.WALLET, token: '0xd988097fb8612cc24eeC14542bC03424c656005f' },
|
|
55
|
+
],
|
|
56
|
+
// WETH on Mode
|
|
57
|
+
'0x4200000000000000000000000000000000000006': [
|
|
58
|
+
{ protocol: PROTOCOLS.IONIC, token: '0x71ef7EDa2Be775E5A7aa8afD02C45F059833e9d2' },
|
|
59
|
+
{ protocol: PROTOCOLS.WALLET, token: '0x4200000000000000000000000000000000000006' },
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
// -------------- EXACT getBalanceInUnderlying LOGIC --------------
|
|
64
|
+
function executeReadContract(address, abi, method, params, provider) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
const contract = new ethers.Contract(address, abi, provider);
|
|
67
|
+
return contract[method](...params);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The function that does your protocol-specific "wrapper => underlying" logic
|
|
72
|
+
* using BigInt(10) instead of 10n for older TS targets.
|
|
73
|
+
*/
|
|
74
|
+
function getBalanceInUnderlying(protocol, chainId, smartAccountAddress, contractAddress, balanceObj, decimals, provider) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
switch (protocol) {
|
|
77
|
+
case PROTOCOLS.WALLET:
|
|
78
|
+
return balanceObj.displayValue;
|
|
79
|
+
case PROTOCOLS.AAVE:
|
|
80
|
+
return balanceObj.displayValue;
|
|
81
|
+
case PROTOCOLS.COMPOUND: {
|
|
82
|
+
return balanceObj.displayValue;
|
|
83
|
+
}
|
|
84
|
+
case PROTOCOLS.IONIC:
|
|
85
|
+
case PROTOCOLS.MOONWELL: {
|
|
86
|
+
// read exchangeRateCurrent
|
|
87
|
+
const rawExRate = yield executeReadContract(contractAddress, COMPOUNDV2_EXCHANGERATE_ABI, 'exchangeRateCurrent', [], provider);
|
|
88
|
+
const exRateBN = BigInt(rawExRate.toString());
|
|
89
|
+
// For IONIC => scale = 18 - decimals + 6
|
|
90
|
+
// For MOONWELL => you used scale=18. Let's handle them with logic or keep it simple
|
|
91
|
+
let scale = 18 - decimals + 6;
|
|
92
|
+
// If MOONWELL, you said "scale=18" in your snippet
|
|
93
|
+
if (protocol === PROTOCOLS.MOONWELL) {
|
|
94
|
+
scale = 18;
|
|
95
|
+
}
|
|
96
|
+
// Fix: BigInt(10) instead of 10n
|
|
97
|
+
const TEN = BigInt(10);
|
|
98
|
+
const divisor = TEN ** BigInt(scale);
|
|
99
|
+
const rawBalanceInAssetBN = (balanceObj.value * exRateBN) / divisor;
|
|
100
|
+
const balanceInAssetString = ethers.formatUnits(rawBalanceInAssetBN, decimals);
|
|
101
|
+
return balanceInAssetString;
|
|
102
|
+
}
|
|
103
|
+
default:
|
|
104
|
+
return balanceObj.displayValue;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
// -------------- MAIN FUNCTION --------------
|
|
109
|
+
export function getUserProtocolBalances(params) {
|
|
110
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
111
|
+
const { chainId, address, contractAddress } = params;
|
|
112
|
+
const chainMap = chainTokenProtocolMap[chainId];
|
|
113
|
+
if (!chainMap || chainId === undefined) {
|
|
114
|
+
throw new Error(`No token map for chainId=${chainId}`);
|
|
115
|
+
}
|
|
116
|
+
// If recognized => read all wrappers
|
|
117
|
+
const protocolWrappers = chainMap[contractAddress.toLowerCase()];
|
|
118
|
+
let addressesToCheck;
|
|
119
|
+
if (protocolWrappers) {
|
|
120
|
+
addressesToCheck = protocolWrappers;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// fallback => just WALLET
|
|
124
|
+
addressesToCheck = [
|
|
125
|
+
{
|
|
126
|
+
protocol: PROTOCOLS.WALLET,
|
|
127
|
+
token: contractAddress,
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
}
|
|
131
|
+
// Setup provider from rpcServices
|
|
132
|
+
const rpcUrl = rpcServices.getRPC(chainId);
|
|
133
|
+
const provider = new ethers.JsonRpcProvider(rpcUrl);
|
|
134
|
+
// Minimal read ABI
|
|
135
|
+
const readABI = [
|
|
136
|
+
'function balanceOf(address) view returns (uint256)',
|
|
137
|
+
'function decimals() view returns (uint8)',
|
|
138
|
+
'function symbol() view returns (string)',
|
|
139
|
+
];
|
|
140
|
+
const results = [];
|
|
141
|
+
for (const { protocol, token } of addressesToCheck) {
|
|
142
|
+
const contract = new ethers.Contract(token, readABI, provider);
|
|
143
|
+
const [rawBalanceBN, decimals, symbol] = yield Promise.all([
|
|
144
|
+
contract.balanceOf(address),
|
|
145
|
+
contract.decimals(),
|
|
146
|
+
contract.symbol(),
|
|
147
|
+
]);
|
|
148
|
+
const rawBalance = BigInt(rawBalanceBN.toString());
|
|
149
|
+
const displayValue = ethers.formatUnits(rawBalance, decimals);
|
|
150
|
+
// We'll guess the underlying decimals from the symbol or fallback
|
|
151
|
+
// In your snippet, you explicitly used the WALLET decimals for USDC => 6
|
|
152
|
+
let underlyingDecimals = decimals;
|
|
153
|
+
if (symbol.toLowerCase().includes('usdc')) {
|
|
154
|
+
underlyingDecimals = 6;
|
|
155
|
+
}
|
|
156
|
+
else if (symbol.toLowerCase().includes('weth') || symbol.toLowerCase().includes('eth')) {
|
|
157
|
+
underlyingDecimals = 18;
|
|
158
|
+
}
|
|
159
|
+
// Build the "balanceObj"
|
|
160
|
+
const balanceObj = {
|
|
161
|
+
value: rawBalance,
|
|
162
|
+
decimals,
|
|
163
|
+
symbol,
|
|
164
|
+
displayValue,
|
|
165
|
+
};
|
|
166
|
+
// Now do your conversion
|
|
167
|
+
const underlyingBalance = yield getBalanceInUnderlying(protocol, chainId, address, token, balanceObj, underlyingDecimals, provider);
|
|
168
|
+
results.push({
|
|
169
|
+
protocol,
|
|
170
|
+
wrapperTokenAddress: token,
|
|
171
|
+
wrapperBalance: displayValue, // raw wrapper token balance
|
|
172
|
+
underlyingBalance, // computed by getBalanceInUnderlying
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return results;
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// getBalanceInUnderlying.ts
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
import { ethers } from 'ethers';
|
|
12
|
+
// The protocol enumeration you already use
|
|
13
|
+
export const PROTOCOLS = {
|
|
14
|
+
AAVE: 'AAVE',
|
|
15
|
+
COMPOUND: 'COMPOUND',
|
|
16
|
+
IONIC: 'IONIC',
|
|
17
|
+
MOONWELL: 'MOONWELL',
|
|
18
|
+
WALLET: 'WALLET',
|
|
19
|
+
};
|
|
20
|
+
// Reuse your COMPOUNDV2_EXCHANGERATE_ABI if needed
|
|
21
|
+
// (exchangeRateCurrent is read-only in your snippet)
|
|
22
|
+
export const COMPOUNDV2_EXCHANGERATE_ABI = [
|
|
23
|
+
'function exchangeRateCurrent() view returns (uint)',
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* A minimal "executeReadContract" helper, exactly like in your code snippet.
|
|
27
|
+
* You can import this from wherever you defined it.
|
|
28
|
+
*/
|
|
29
|
+
export function executeReadContract(address_1, abi_1, method_1) {
|
|
30
|
+
return __awaiter(this, arguments, void 0, function* (address, abi, method, params = [], provider) {
|
|
31
|
+
const contract = new ethers.Contract(address, abi, provider);
|
|
32
|
+
return contract[method](...params);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* getBalanceInUnderlying:
|
|
37
|
+
* Keeps the exact logic you provided for each protocol.
|
|
38
|
+
*
|
|
39
|
+
* @param protocol - which protocol (WALLET, AAVE, COMPOUND, IONIC, MOONWELL)
|
|
40
|
+
* @param chainId - the chain you’re on (not actively used in this snippet, but kept for consistency)
|
|
41
|
+
* @param smartAccountAddress - the user’s address (passed, but your snippet only uses it for logs or COMPOUND custom calls if you expand logic)
|
|
42
|
+
* @param contractAddress - the “wrapper token” contract to read from
|
|
43
|
+
* @param balanceObj - the result from getBalanceObject (raw BigInt, decimals, displayValue, etc.)
|
|
44
|
+
* @param decimals - typically the “underlying decimals” you want to interpret. (In your code, you used the WALLET entry’s decimals for USDC.)
|
|
45
|
+
* @param provider - a JsonRpcProvider for read calls (required if you do exchangeRateCurrent).
|
|
46
|
+
*
|
|
47
|
+
* @returns a string representing the final “underlying” balance
|
|
48
|
+
*/
|
|
49
|
+
export function getBalanceInUnderlying(protocol, chainId, smartAccountAddress, contractAddress, balanceObj, decimals, provider) {
|
|
50
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
+
switch (protocol) {
|
|
52
|
+
// WALLET => actual USDC, 1:1 => if rawBalance = 1, then underlying = 1
|
|
53
|
+
case PROTOCOLS.WALLET: {
|
|
54
|
+
return balanceObj.displayValue;
|
|
55
|
+
}
|
|
56
|
+
// AAVE => often pegged 1:1 for typical aTokens => 1 => 1
|
|
57
|
+
case PROTOCOLS.AAVE: {
|
|
58
|
+
return balanceObj.displayValue;
|
|
59
|
+
}
|
|
60
|
+
// COMPOUND => your snippet simply logs the balanceObj and returns displayValue
|
|
61
|
+
// (If you wanted a real conversion, you could do “collateralBalanceOf” logic here)
|
|
62
|
+
case PROTOCOLS.COMPOUND: {
|
|
63
|
+
return balanceObj.displayValue;
|
|
64
|
+
}
|
|
65
|
+
// IONIC => calls “exchangeRateCurrent”, then does BigInt math
|
|
66
|
+
case PROTOCOLS.IONIC: {
|
|
67
|
+
const rawExRate = yield executeReadContract(contractAddress, COMPOUNDV2_EXCHANGERATE_ABI, 'exchangeRateCurrent', [], provider);
|
|
68
|
+
const exRateBN = BigInt(rawExRate.toString());
|
|
69
|
+
// “Suppose we do scale = 18 - decimals + 6 (typical for cTokens w/ USDC underlying).”
|
|
70
|
+
// In your snippet, “decimals” is from the WALLET token (if that’s USDC => 6).
|
|
71
|
+
const scale = 18 - decimals + 6;
|
|
72
|
+
const divisor = BigInt(10) ** BigInt(scale);
|
|
73
|
+
// cTokenBalance * exchangeRate / divisor => underlying
|
|
74
|
+
const rawBalanceInAssetBN = (balanceObj.value * exRateBN) / divisor;
|
|
75
|
+
const balanceInAssetString = ethers.formatUnits(rawBalanceInAssetBN, decimals);
|
|
76
|
+
return balanceInAssetString;
|
|
77
|
+
}
|
|
78
|
+
// MOONWELL => same logic, but you used a fixed scale=18
|
|
79
|
+
case PROTOCOLS.MOONWELL: {
|
|
80
|
+
const rawExRate = yield executeReadContract(contractAddress, COMPOUNDV2_EXCHANGERATE_ABI, 'exchangeRateCurrent', [], provider);
|
|
81
|
+
const exRateBN = BigInt(rawExRate.toString());
|
|
82
|
+
// “ALL the moonwell tokens have 8 decimals,” so you did scale=18
|
|
83
|
+
const scale = 18;
|
|
84
|
+
const divisor = BigInt(10) ** BigInt(scale);
|
|
85
|
+
const rawBalanceInAssetBN = (balanceObj.value * exRateBN) / divisor;
|
|
86
|
+
const balanceInAssetString = ethers.formatUnits(rawBalanceInAssetBN, decimals);
|
|
87
|
+
return balanceInAssetString;
|
|
88
|
+
}
|
|
89
|
+
default: {
|
|
90
|
+
// If not recognized, just return the wrapper’s displayValue
|
|
91
|
+
return balanceObj.displayValue;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
@@ -108,7 +108,7 @@ function isValidValue(value) {
|
|
|
108
108
|
return false;
|
|
109
109
|
}
|
|
110
110
|
function isVariable(value) {
|
|
111
|
-
return /\{\{nodeMap\.[^.}]+\.(?:output|parameters(?:\.abi\.parameters)?)\.[
|
|
111
|
+
return /\{\{(?:nodeMap\.[^.}]+\.(?:output|parameters(?:\.abi\.parameters)?)|external\.functions\.[^(}]+)\([^)]*\)\}\}/.test(value);
|
|
112
112
|
}
|
|
113
113
|
export function typeIsNumber(type) {
|
|
114
114
|
switch (type) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.10";
|
|
2
2
|
export declare function compareVersions(v1: string, v2: string): number;
|
|
@@ -6,7 +6,7 @@ declare class ApiServices {
|
|
|
6
6
|
patch(url: string, data: any): Promise<import("axios").AxiosResponse<any, any>>;
|
|
7
7
|
get(url: string): Promise<any>;
|
|
8
8
|
delete(url: string): Promise<import("axios").AxiosResponse<any, any>>;
|
|
9
|
-
generateLoginPayload(address: string, chainId: number,
|
|
9
|
+
generateLoginPayload(address: string, chainId: number, referralCode: string): Promise<any>;
|
|
10
10
|
getToken(loginPayload: any, signature: string): Promise<{
|
|
11
11
|
token: any;
|
|
12
12
|
}>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const PROTOCOLS: {
|
|
2
|
+
readonly AAVE: "AAVE";
|
|
3
|
+
readonly COMPOUND: "COMPOUND";
|
|
4
|
+
readonly IONIC: "IONIC";
|
|
5
|
+
readonly MOONWELL: "MOONWELL";
|
|
6
|
+
readonly WALLET: "WALLET";
|
|
7
|
+
};
|
|
8
|
+
export type Protocol = typeof PROTOCOLS[keyof typeof PROTOCOLS];
|
|
9
|
+
export interface GetUserProtocolBalancesParams {
|
|
10
|
+
chainId: number;
|
|
11
|
+
address: string;
|
|
12
|
+
contractAddress: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ProtocolBalanceResult {
|
|
15
|
+
protocol: Protocol;
|
|
16
|
+
wrapperTokenAddress: string;
|
|
17
|
+
wrapperBalance: string;
|
|
18
|
+
underlyingBalance: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function getUserProtocolBalances(params: GetUserProtocolBalancesParams): Promise<ProtocolBalanceResult[]>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { ethers } from 'ethers';
|
|
2
|
+
export declare const PROTOCOLS: {
|
|
3
|
+
readonly AAVE: "AAVE";
|
|
4
|
+
readonly COMPOUND: "COMPOUND";
|
|
5
|
+
readonly IONIC: "IONIC";
|
|
6
|
+
readonly MOONWELL: "MOONWELL";
|
|
7
|
+
readonly WALLET: "WALLET";
|
|
8
|
+
};
|
|
9
|
+
export declare const COMPOUNDV2_EXCHANGERATE_ABI: string[];
|
|
10
|
+
/**
|
|
11
|
+
* A minimal "executeReadContract" helper, exactly like in your code snippet.
|
|
12
|
+
* You can import this from wherever you defined it.
|
|
13
|
+
*/
|
|
14
|
+
export declare function executeReadContract(address: string, abi: string[], method: string, params: any[] | undefined, provider: ethers.JsonRpcProvider): Promise<any>;
|
|
15
|
+
/**
|
|
16
|
+
* The shape of the "balanceObj" from your code:
|
|
17
|
+
* {
|
|
18
|
+
* value: bigint,
|
|
19
|
+
* decimals: number,
|
|
20
|
+
* symbol: string,
|
|
21
|
+
* displayValue: string,
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
export interface BalanceObject {
|
|
25
|
+
value: bigint;
|
|
26
|
+
decimals: number;
|
|
27
|
+
symbol: string;
|
|
28
|
+
displayValue: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* getBalanceInUnderlying:
|
|
32
|
+
* Keeps the exact logic you provided for each protocol.
|
|
33
|
+
*
|
|
34
|
+
* @param protocol - which protocol (WALLET, AAVE, COMPOUND, IONIC, MOONWELL)
|
|
35
|
+
* @param chainId - the chain you’re on (not actively used in this snippet, but kept for consistency)
|
|
36
|
+
* @param smartAccountAddress - the user’s address (passed, but your snippet only uses it for logs or COMPOUND custom calls if you expand logic)
|
|
37
|
+
* @param contractAddress - the “wrapper token” contract to read from
|
|
38
|
+
* @param balanceObj - the result from getBalanceObject (raw BigInt, decimals, displayValue, etc.)
|
|
39
|
+
* @param decimals - typically the “underlying decimals” you want to interpret. (In your code, you used the WALLET entry’s decimals for USDC.)
|
|
40
|
+
* @param provider - a JsonRpcProvider for read calls (required if you do exchangeRateCurrent).
|
|
41
|
+
*
|
|
42
|
+
* @returns a string representing the final “underlying” balance
|
|
43
|
+
*/
|
|
44
|
+
export declare function getBalanceInUnderlying(protocol: string, chainId: number, smartAccountAddress: string, contractAddress: string, balanceObj: BalanceObject, decimals: number, provider: ethers.JsonRpcProvider): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|