@pbgtoken/rwa-contract 1.1.5 → 1.1.6
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.
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
import { PricesProvider } from "./PricesProvider";
|
|
2
2
|
import { TokenizedAccountProvider } from "./TokenizedAccountProvider";
|
|
3
|
+
export interface EthereumERC20AccountProvider extends TokenizedAccountProvider {
|
|
4
|
+
getInternalBalance(): Promise<bigint>;
|
|
5
|
+
}
|
|
3
6
|
export declare function makeEthereumERC20AccountProvider(walletAddress: string, priceProvider: PricesProvider, alchemyApiKey: string, tokenContractAddress?: `0x${string}` | null, rpcUrl?: string): TokenizedAccountProvider;
|
package/dist/index.js
CHANGED
|
@@ -875,7 +875,7 @@ function makeBitcoinWalletProvider(walletAddress, priceProvider) {
|
|
|
875
875
|
|
|
876
876
|
// src/EthereumERC20AccountProvider.ts
|
|
877
877
|
import { ethers } from "ethers";
|
|
878
|
-
var
|
|
878
|
+
var EthereumERC20AccountProviderImpl = class {
|
|
879
879
|
/**
|
|
880
880
|
* @param walletAddress The Ethereum wallet address to query.
|
|
881
881
|
* @param priceProvider CoinGecko Price Provider
|
|
@@ -992,6 +992,20 @@ var EthereumERC20AccountProvider = class {
|
|
|
992
992
|
const decimals = await contract.decimals();
|
|
993
993
|
return Number(ethers.formatUnits(balance, decimals));
|
|
994
994
|
}
|
|
995
|
+
async getInternalBalance() {
|
|
996
|
+
const provider = new ethers.JsonRpcProvider(this.rpcUrl);
|
|
997
|
+
if (!this.tokenContractAddress) {
|
|
998
|
+
const balance2 = await provider.getBalance(this.walletAddress);
|
|
999
|
+
return ethers.toBigInt(balance2);
|
|
1000
|
+
}
|
|
1001
|
+
const erc20Abi = [
|
|
1002
|
+
"function balanceOf(address) view returns (uint256)",
|
|
1003
|
+
"function decimals() view returns (uint8)"
|
|
1004
|
+
];
|
|
1005
|
+
const contract = new ethers.Contract(this.tokenContractAddress, erc20Abi, provider);
|
|
1006
|
+
const balance = await contract.balanceOf(this.walletAddress);
|
|
1007
|
+
return ethers.toBigInt(balance);
|
|
1008
|
+
}
|
|
995
1009
|
/**
|
|
996
1010
|
* Fetches the USD value of the wallet's balance using CoinGecko.
|
|
997
1011
|
* Uses the contract address for ERC-20 tokens, or native ETH if contract address is null.
|
|
@@ -1038,7 +1052,7 @@ var EthereumERC20AccountProvider = class {
|
|
|
1038
1052
|
}
|
|
1039
1053
|
};
|
|
1040
1054
|
function makeEthereumERC20AccountProvider(walletAddress, priceProvider, alchemyApiKey, tokenContractAddress = null, rpcUrl = "https://eth.rpc.blxrbdn.com") {
|
|
1041
|
-
return new
|
|
1055
|
+
return new EthereumERC20AccountProviderImpl(walletAddress, priceProvider, alchemyApiKey, tokenContractAddress, rpcUrl);
|
|
1042
1056
|
}
|
|
1043
1057
|
|
|
1044
1058
|
// src/BinanceAccountProvider.ts
|