@ember-finance/sdk 1.1.2 → 1.1.3
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.
|
@@ -112,6 +112,10 @@ export declare class EVMUserCalls extends EVMOnChainCalls {
|
|
|
112
112
|
* Gets the vault contract instance for read operations
|
|
113
113
|
*/
|
|
114
114
|
private getVaultContract;
|
|
115
|
+
/**
|
|
116
|
+
* Gets an ERC20 contract instance for read operations
|
|
117
|
+
*/
|
|
118
|
+
private getERC20Contract;
|
|
115
119
|
/**
|
|
116
120
|
* Get the user's total vault shares (share token balance)
|
|
117
121
|
* @param vaultAddress The address of the vault
|
|
@@ -119,4 +123,19 @@ export declare class EVMUserCalls extends EVMOnChainCalls {
|
|
|
119
123
|
* @returns The user's share balance as bigint
|
|
120
124
|
*/
|
|
121
125
|
getVaultShares(vaultAddress: string, account?: string): Promise<bigint>;
|
|
126
|
+
/**
|
|
127
|
+
* Get the user's balance of any ERC20 token
|
|
128
|
+
* @param tokenAddress The address of the ERC20 token contract
|
|
129
|
+
* @param account Optional account address (defaults to caller's wallet)
|
|
130
|
+
* @returns The user's token balance as bigint
|
|
131
|
+
*/
|
|
132
|
+
getTokenBalance(tokenAddress: string, account?: string): Promise<bigint>;
|
|
133
|
+
/**
|
|
134
|
+
* Get the allowance of an ERC20 token for a spender
|
|
135
|
+
* @param tokenAddress The address of the ERC20 token contract
|
|
136
|
+
* @param spender The address of the spender
|
|
137
|
+
* @param owner Optional owner address (defaults to caller's wallet)
|
|
138
|
+
* @returns The allowance as bigint
|
|
139
|
+
*/
|
|
140
|
+
getTokenAllowance(tokenAddress: string, spender: string, owner?: string): Promise<bigint>;
|
|
122
141
|
}
|
|
@@ -164,6 +164,22 @@ class EVMUserCalls extends onchain_calls_1.EVMOnChainCalls {
|
|
|
164
164
|
}
|
|
165
165
|
return new ethers_1.Contract(vaultAddress, EmberVault_json_1.default.abi, this.provider);
|
|
166
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Gets an ERC20 contract instance for read operations
|
|
169
|
+
*/
|
|
170
|
+
getERC20Contract(tokenAddress) {
|
|
171
|
+
if (!this.provider) {
|
|
172
|
+
throw new Error("Provider required for read operations");
|
|
173
|
+
}
|
|
174
|
+
const erc20Abi = [
|
|
175
|
+
"function balanceOf(address account) view returns (uint256)",
|
|
176
|
+
"function allowance(address owner, address spender) view returns (uint256)",
|
|
177
|
+
"function decimals() view returns (uint8)",
|
|
178
|
+
"function symbol() view returns (string)",
|
|
179
|
+
"function name() view returns (string)"
|
|
180
|
+
];
|
|
181
|
+
return new ethers_1.Contract(tokenAddress, erc20Abi, this.provider);
|
|
182
|
+
}
|
|
167
183
|
/**
|
|
168
184
|
* Get the user's total vault shares (share token balance)
|
|
169
185
|
* @param vaultAddress The address of the vault
|
|
@@ -175,5 +191,28 @@ class EVMUserCalls extends onchain_calls_1.EVMOnChainCalls {
|
|
|
175
191
|
const vault = this.getVaultContract(vaultAddress);
|
|
176
192
|
return vault.balanceOf(userAddress);
|
|
177
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Get the user's balance of any ERC20 token
|
|
196
|
+
* @param tokenAddress The address of the ERC20 token contract
|
|
197
|
+
* @param account Optional account address (defaults to caller's wallet)
|
|
198
|
+
* @returns The user's token balance as bigint
|
|
199
|
+
*/
|
|
200
|
+
async getTokenBalance(tokenAddress, account) {
|
|
201
|
+
const userAddress = account ?? (await this.getWalletAddress());
|
|
202
|
+
const token = this.getERC20Contract(tokenAddress);
|
|
203
|
+
return token.balanceOf(userAddress);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Get the allowance of an ERC20 token for a spender
|
|
207
|
+
* @param tokenAddress The address of the ERC20 token contract
|
|
208
|
+
* @param spender The address of the spender
|
|
209
|
+
* @param owner Optional owner address (defaults to caller's wallet)
|
|
210
|
+
* @returns The allowance as bigint
|
|
211
|
+
*/
|
|
212
|
+
async getTokenAllowance(tokenAddress, spender, owner) {
|
|
213
|
+
const ownerAddress = owner ?? (await this.getWalletAddress());
|
|
214
|
+
const token = this.getERC20Contract(tokenAddress);
|
|
215
|
+
return token.allowance(ownerAddress, spender);
|
|
216
|
+
}
|
|
178
217
|
}
|
|
179
218
|
exports.EVMUserCalls = EVMUserCalls;
|