@raac/rpc 1.1.0-beta.10 → 1.1.0-beta.12
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/scripts/index.js
CHANGED
|
@@ -50,6 +50,7 @@ async function setup() {
|
|
|
50
50
|
// signer
|
|
51
51
|
// );
|
|
52
52
|
console.log(await rpc.pools.lendingPool.getLendingPoolInfo(chainId, signer.address, provider));
|
|
53
|
+
console.log(await rpc.wallet.assets.getBalance(chainId, "rtoken", signer.address, provider));
|
|
53
54
|
// // // // set the oracle address of the RAACHousePrice. TEmporarily simulating that I AM THE ORACLE
|
|
54
55
|
// await rpc.contracts.housePrices.setOracle(chainId, signer.address, signer);
|
|
55
56
|
// // // // // set price for 3 houses
|
|
@@ -2,12 +2,8 @@ import { Provider } from "ethers";
|
|
|
2
2
|
import { AssetType } from "../../utils/artifacts";
|
|
3
3
|
import { ChainId } from "../../configs/chains/index";
|
|
4
4
|
declare function getBalance(chainId: ChainId, assetId: AssetType, address: string, provider: Provider): Promise<{
|
|
5
|
-
balance:
|
|
5
|
+
balance: string;
|
|
6
6
|
symbol: string;
|
|
7
7
|
decimals: number;
|
|
8
|
-
} | {
|
|
9
|
-
balance: string;
|
|
10
|
-
symbol: any;
|
|
11
|
-
decimals: any;
|
|
12
8
|
}>;
|
|
13
9
|
export default getBalance;
|
|
@@ -3,11 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const ethers_1 = require("ethers");
|
|
4
4
|
const contracts_1 = require("../../utils/contracts");
|
|
5
5
|
async function getBalance(chainId, assetId, address, provider) {
|
|
6
|
+
console.log(assetId);
|
|
7
|
+
console.log(address);
|
|
8
|
+
console.log(provider);
|
|
9
|
+
console.log(chainId);
|
|
6
10
|
const BALANCE_OF_ABI = ["function balanceOf(address) view returns (uint256)", "function symbol() view returns (string)", "function decimals() view returns (uint8)"];
|
|
7
11
|
try {
|
|
8
12
|
if (assetId === "eth") {
|
|
9
13
|
const balance = await provider.getBalance(address);
|
|
10
|
-
const parsedBalance =
|
|
14
|
+
const parsedBalance = (ethers_1.ethers.formatEther(balance));
|
|
11
15
|
return {
|
|
12
16
|
balance: parsedBalance,
|
|
13
17
|
symbol: "ETH",
|
|
@@ -15,21 +19,24 @@ async function getBalance(chainId, assetId, address, provider) {
|
|
|
15
19
|
};
|
|
16
20
|
}
|
|
17
21
|
const contractAddress = (0, contracts_1.getContractAddress)(chainId, assetId);
|
|
22
|
+
console.log(contractAddress);
|
|
18
23
|
const contract = new ethers_1.ethers.Contract(contractAddress, BALANCE_OF_ABI, provider);
|
|
24
|
+
console.log(contract);
|
|
19
25
|
const balance = await contract.balanceOf(address);
|
|
20
|
-
|
|
21
|
-
const
|
|
26
|
+
console.log(balance);
|
|
27
|
+
const symbol = (await contract.symbol())?.toString() || "";
|
|
28
|
+
const decimals = parseInt(await contract.decimals()) || 0;
|
|
22
29
|
const parsedBalance = ethers_1.ethers.formatUnits(balance, decimals);
|
|
23
30
|
return {
|
|
24
31
|
balance: parsedBalance,
|
|
25
|
-
symbol,
|
|
32
|
+
symbol: symbol,
|
|
26
33
|
decimals,
|
|
27
34
|
};
|
|
28
35
|
}
|
|
29
36
|
catch (error) {
|
|
30
37
|
console.error(`Error getting balance for asset ${assetId}:`, error);
|
|
31
38
|
return {
|
|
32
|
-
balance: 0,
|
|
39
|
+
balance: "0",
|
|
33
40
|
symbol: "",
|
|
34
41
|
decimals: 0,
|
|
35
42
|
};
|