@raac/rpc 1.0.2-beta.3 → 1.0.2-beta.4
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/{RPCLibrary.ts → RPCLibrary.js} +7 -121
- package/assets/{getAsset.ts → getAsset.js} +6 -6
- package/assets/{getAssets.ts → getAssets.js} +2 -3
- package/assets/{getSupply.ts → getSupply.js} +5 -7
- package/configs/chains/index.js +13 -0
- package/configs/index.js +17 -0
- package/contracts/feeCollector/{claimRewardFromPool.ts → claimRewardFromPool.js} +4 -10
- package/contracts/{getContract.ts → getContract.js} +5 -6
- package/contracts/{getContractAddress.ts → getContractAddress.js} +4 -6
- package/contracts/housePrices/{getLatestPrice.ts → getLatestPrice.js} +6 -8
- package/contracts/housePrices/{setOracle.ts → setOracle.js} +6 -8
- package/contracts/indexToken/{getNextRandomNFT.ts → getNextRandomNFT.js} +5 -7
- package/contracts/indexToken/{redeemNFT.ts → redeemNFT.js} +5 -7
- package/contracts/zeno/{createAuction.ts → createAuction.js} +14 -16
- package/contracts/zeno/{createZeno.ts → createZeno.js} +8 -10
- package/contracts/zeno/{getAuctions.ts → getAuctions.js} +5 -7
- package/contracts/zeno/{getZenos.ts → getZenos.js} +5 -7
- package/methods/commons/{checkAllowance.ts → checkAllowance.js} +10 -12
- package/methods/commons/{estimateGasPrice.ts → estimateGasPrice.js} +5 -7
- package/minter/{get.ts → get.js} +6 -8
- package/minter/{getApy.ts → getApy.js} +5 -7
- package/minter/{tick.ts → tick.js} +5 -7
- package/nfts/{getAllTokens.ts → getAllTokens.js} +7 -9
- package/nfts/{getBaseUri.ts → getBaseUri.js} +5 -7
- package/nfts/{getHousePrice.ts → getHousePrice.js} +6 -8
- package/nfts/{getMintFeePercentage.ts → getMintFeePercentage.js} +4 -6
- package/nfts/{getMintPrice.ts → getMintPrice.js} +7 -9
- package/nfts/{getTokenURI.ts → getTokenURI.js} +7 -9
- package/nfts/{getTokensByOwner.ts → getTokensByOwner.js} +8 -10
- package/nfts/{getTotalPropertiesCount.ts → getTotalPropertiesCount.js} +5 -7
- package/nfts/{mint.ts → mint.js} +7 -9
- package/nfts/{setBaseUri.ts → setBaseUri.js} +4 -6
- package/nfts/{totalNFTSupply.ts → totalNFTSupply.js} +4 -6
- package/package.json +1 -1
- package/pools/lendingPool/{borrowFromLendingPool.ts → borrowFromLendingPool.js} +8 -10
- package/pools/lendingPool/{borrowFromLendingPoolWithInsurance.ts → borrowFromLendingPoolWithInsurance.js} +8 -10
- package/pools/lendingPool/{calculateInsuranceFee.ts → calculateInsuranceFee.js} +9 -11
- package/pools/lendingPool/{claimReward.ts → claimReward.js} +5 -7
- package/pools/lendingPool/{closeLiquidation.ts → closeLiquidation.js} +7 -9
- package/pools/lendingPool/{depositNFTToLendingPool.ts → depositNFTToLendingPool.js} +6 -8
- package/pools/lendingPool/{depositToLendingPool.ts → depositToLendingPool.js} +6 -8
- package/pools/lendingPool/{getAllUserData.ts → getAllUserData.js} +7 -14
- package/pools/lendingPool/{getEligibleUserDeposits.ts → getEligibleUserDeposits.js} +7 -9
- package/pools/lendingPool/{getHealthFactor.ts → getHealthFactor.js} +8 -10
- package/pools/lendingPool/{getHousePrice.ts → getHousePrice.js} +6 -8
- package/pools/lendingPool/{getLendingPoolInfo.ts → getLendingPoolInfo.js} +23 -31
- package/pools/lendingPool/{getLendingPoolTotalLiquidity.ts → getLendingPoolTotalLiquidity.js} +7 -10
- package/pools/lendingPool/{getPendingReward.ts → getPendingReward.js} +7 -9
- package/pools/lendingPool/{getPositionDebt.ts → getPositionDebt.js} +8 -10
- package/pools/lendingPool/{getPositionScaledDebt.ts → getPositionScaledDebt.js} +8 -10
- package/pools/lendingPool/{getPositionView.ts → getPositionView.js} +9 -11
- package/pools/lendingPool/{getPositionsScaledDebt.ts → getPositionsScaledDebt.js} +7 -9
- package/pools/lendingPool/{getRawUserDepositsInLendingPool.ts → getRawUserDepositsInLendingPool.js} +7 -9
- package/pools/lendingPool/{getUserCollateralValue.ts → getUserCollateralValue.js} +7 -9
- package/pools/lendingPool/{initializeLiquidation.ts → initializeLiquidation.js} +8 -10
- package/pools/lendingPool/{repayToLendingPool.ts → repayToLendingPool.js} +8 -10
- package/pools/lendingPool/{withdrawFromLendingPool.ts → withdrawFromLendingPool.js} +9 -10
- package/pools/lendingPool/{withdrawNFTFromLendingPool.ts → withdrawNFTFromLendingPool.js} +7 -9
- package/pools/stabilityPool/{calculateRAACRewards.ts → calculateRAACRewards.js} +6 -9
- package/pools/stabilityPool/configs/chains/index.js +17 -0
- package/pools/stabilityPool/configs/index.js +43 -0
- package/pools/stabilityPool/{depositNFTToStabilityPool.ts → depositNFTToStabilityPool.js} +6 -9
- package/pools/stabilityPool/{depositToStabilityPool.ts → depositToStabilityPool.js} +6 -8
- package/pools/stabilityPool/{getRawUserDepositsInStabilityPool.ts → getRawUserDepositsInStabilityPool.js} +7 -9
- package/pools/stabilityPool/{getStabilityPoolInfo.ts → getStabilityPoolInfo.js} +10 -12
- package/pools/stabilityPool/{getStabilityPoolTotalDeposits.ts → getStabilityPoolTotalDeposits.js} +6 -8
- package/pools/stabilityPool/methods/commons/estimateGasPrice.js +28 -0
- package/pools/stabilityPool/pools/stabilityPool/withdrawFromStabilityPool.js +34 -0
- package/pools/stabilityPool/utils/artifacts.js +74 -0
- package/pools/stabilityPool/utils/contracts.js +82 -0
- package/pools/stabilityPool/{withdrawFromStabilityPool.ts → withdrawFromStabilityPool.js} +6 -8
- package/ts-to-js.sh +42 -0
- package/utils/{artifacts.ts → artifacts.js} +1 -4
- package/utils/{contracts.ts → contracts.js} +16 -18
- package/wallet/assets/{approveAsset.ts → approveAsset.js} +7 -8
- package/wallet/assets/{burnAsset.ts → burnAsset.js} +7 -9
- package/wallet/assets/{getAllowance.ts → getAllowance.js} +9 -10
- package/wallet/assets/{getAsset.ts → getAsset.js} +6 -7
- package/wallet/assets/{getAssets.ts → getAssets.js} +5 -6
- package/wallet/assets/{getBalance.ts → getBalance.js} +8 -9
- package/wallet/assets/{mintAsset.ts → mintAsset.js} +8 -9
- package/wallet/assets/{transferAsset.ts → transferAsset.js} +10 -11
- package/configs/chains/index.ts +0 -17
- package/configs/index.ts +0 -51
- /package/configs/chains/{chain.d.ts → chain.d.js} +0 -0
- /package/configs/{createConfig.ts → createConfig.js} +0 -0
- /package/contracts/crvUSDToken/{getBalance.ts → getBalance.js} +0 -0
- /package/contracts/crvUSDToken/{getTotalSupply.ts → getTotalSupply.js} +0 -0
- /package/contracts/rcrvUSDToken/{getBalance.ts → getBalance.js} +0 -0
- /package/contracts/rcrvUSDToken/{getTotalSupply.ts → getTotalSupply.js} +0 -0
- /package/{custom-types.d.ts → custom-types.d.js} +0 -0
- /package/{index.ts → index.js} +0 -0
- /package/methods/{approveToken.ts → approveToken.js} +0 -0
- /package/methods/{getAssetBalance.ts → getAssetBalance.js} +0 -0
- /package/methods/{getAssetsBalance.ts → getAssetsBalance.js} +0 -0
- /package/pools/liquidityPool/{getLiquidityPoolInfo.ts → getLiquidityPoolInfo.js} +0 -0
- /package/scripts/{index.ts → index.js} +0 -0
- /package/tests/{test.ts → test.js} +0 -0
- /package/utils/{chain.ts → chain.js} +0 -0
- /package/utils/{config.ts → config.js} +0 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ABIS = exports.getABI = void 0;
|
|
7
|
+
const crvUSDToken_json_1 = __importDefault(require("../artifacts/mocks/core/tokens/crvUSDToken.sol/crvUSDToken.json")); // assert { type: "json" };
|
|
8
|
+
const veRAACToken_json_1 = __importDefault(require("../artifacts/core/tokens/veRAACToken.sol/veRAACToken.json")); // assert { type: "json" };
|
|
9
|
+
const RToken_json_1 = __importDefault(require("../artifacts/core/tokens/RToken.sol/RToken.json")); // assert { type: "json" };
|
|
10
|
+
const LendingPool_json_1 = __importDefault(require("../artifacts/core/pools/LendingPool/LendingPool.sol/LendingPool.json")); // assert { type: "json" };
|
|
11
|
+
const StabilityPool_json_1 = __importDefault(require("../artifacts/core/pools/StabilityPool/StabilityPool.sol/StabilityPool.json")); // assert { type: "json" };
|
|
12
|
+
// import LiquidityPoolArtifact from "../artifacts/LiquidityPool/LiquidityPool.sol/LiquidityPool.json"; // assert { type: "json" };
|
|
13
|
+
const RAACNFT_json_1 = __importDefault(require("../artifacts/core/tokens/RAACNFT.sol/RAACNFT.json")); // assert { type: "json" };
|
|
14
|
+
const DEToken_json_1 = __importDefault(require("../artifacts/core/tokens/DEToken.sol/DEToken.json")); // assert { type: "json" };
|
|
15
|
+
const RAACToken_json_1 = __importDefault(require("../artifacts/core/tokens/RAACToken.sol/RAACToken.json")); // assert { type: "json" };
|
|
16
|
+
const RAACMinter_json_1 = __importDefault(require("../artifacts/core/minters/RAACMinter/RAACMinter.sol/RAACMinter.json")); // assert { type: "json" };
|
|
17
|
+
const RAACHousePrices_json_1 = __importDefault(require("../artifacts/core/primitives/RAACHousePrices.sol/RAACHousePrices.json")); // assert { type: "json" };
|
|
18
|
+
const AuctionFactory_json_1 = __importDefault(require("../artifacts/zeno/AuctionFactory.sol/AuctionFactory.json")); // assert { type: "json" };
|
|
19
|
+
const Auction_json_1 = __importDefault(require("../artifacts/zeno/Auction.sol/Auction.json")); // assert { type: "json" };
|
|
20
|
+
const ZenoFactory_json_1 = __importDefault(require("../artifacts/zeno/ZenoFactory.sol/ZenoFactory.json")); // assert { type: "json" };
|
|
21
|
+
const Zeno_json_1 = __importDefault(require("../artifacts/zeno/Zeno.sol/Zeno.json")); // assert { type: "json" };
|
|
22
|
+
const FeeCollector_json_1 = __importDefault(require("../artifacts/core/collectors/FeeCollector.sol/FeeCollector.json")); // assert { type: "json" };
|
|
23
|
+
const IndexToken_json_1 = __importDefault(require("../artifacts/core/tokens/IndexToken.sol/IndexToken.json")); // assert { type: "json" };
|
|
24
|
+
const MockVRFCoordinatorV2_json_1 = __importDefault(require("../artifacts/mocks/core/oracles/MockVRFCoordinatorV2.sol/MockVRFCoordinatorV2.json")); // assert { type: "json" };
|
|
25
|
+
const BaseVRFv2Consumer_json_1 = __importDefault(require("../artifacts/core/oracles/BaseVRFv2Consumer.sol/BaseVRFv2Consumer.json")); // assert { type: "json" };
|
|
26
|
+
const CRVUSD_ABI = crvUSDToken_json_1.default.abi;
|
|
27
|
+
const RToken_json_2 = __importDefault(require("../artifacts/core/tokens/RToken.sol/RToken.json")); // assert { type: "json" }; // TODO: Isnt this same as rcrvusd?
|
|
28
|
+
const RTOKEN_ABI = RToken_json_2.default.abi;
|
|
29
|
+
const VERAAC_ABI = veRAACToken_json_1.default.abi;
|
|
30
|
+
const RCRVUSD_ABI = RToken_json_1.default.abi;
|
|
31
|
+
const DETOKEN_ABI = DEToken_json_1.default.abi;
|
|
32
|
+
const RAACLENDINGPOOL_ABI = LendingPool_json_1.default.abi;
|
|
33
|
+
const RAACSTABILITYPOOL_ABI = StabilityPool_json_1.default.abi;
|
|
34
|
+
// const LIQUIDITYPOOL_ABI = LiquidityPoolArtifact.abi;
|
|
35
|
+
const RAACMINTER_ABI = RAACMinter_json_1.default.abi;
|
|
36
|
+
const RAACNFT_ABI = RAACNFT_json_1.default.abi;
|
|
37
|
+
const RAACToken_ABI = RAACToken_json_1.default.abi;
|
|
38
|
+
const RAACHOUSEPRICES_ABI = RAACHousePrices_json_1.default.abi;
|
|
39
|
+
const FEECOLLECTOR_ABI = FeeCollector_json_1.default.abi;
|
|
40
|
+
const ABIS = {
|
|
41
|
+
// Tokens
|
|
42
|
+
crvusd: CRVUSD_ABI,
|
|
43
|
+
// RAAC
|
|
44
|
+
raacnft: RAACNFT_ABI,
|
|
45
|
+
raactoken: RAACToken_ABI,
|
|
46
|
+
veraac: VERAAC_ABI,
|
|
47
|
+
// Pools tokens
|
|
48
|
+
rcrvusd: RCRVUSD_ABI,
|
|
49
|
+
rtoken: RTOKEN_ABI,
|
|
50
|
+
detoken: DETOKEN_ABI,
|
|
51
|
+
// Pools
|
|
52
|
+
lendingpool: RAACLENDINGPOOL_ABI,
|
|
53
|
+
stabilitypool: RAACSTABILITYPOOL_ABI,
|
|
54
|
+
// liquiditypool: LIQUIDITYPOOL_ABI,
|
|
55
|
+
raacminter: RAACMINTER_ABI,
|
|
56
|
+
// contracts
|
|
57
|
+
// contracts#raacHousePrices
|
|
58
|
+
raachouseprices: RAACHOUSEPRICES_ABI,
|
|
59
|
+
feecollector: FEECOLLECTOR_ABI,
|
|
60
|
+
// contracts#auction
|
|
61
|
+
auction: Auction_json_1.default.abi,
|
|
62
|
+
auctionfactory: AuctionFactory_json_1.default.abi,
|
|
63
|
+
zeno: Zeno_json_1.default.abi,
|
|
64
|
+
zenofactory: ZenoFactory_json_1.default.abi,
|
|
65
|
+
indextoken: IndexToken_json_1.default.abi,
|
|
66
|
+
mockvrfcoordinator: MockVRFCoordinatorV2_json_1.default.abi,
|
|
67
|
+
vrfconsumer: BaseVRFv2Consumer_json_1.default.abi,
|
|
68
|
+
eth: [],
|
|
69
|
+
};
|
|
70
|
+
exports.ABIS = ABIS;
|
|
71
|
+
const getABI = (name) => {
|
|
72
|
+
return ABIS[name];
|
|
73
|
+
};
|
|
74
|
+
exports.getABI = getABI;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContractAddress = exports.getContract = exports.getConfig = exports.setOverrideConfig = exports.getConfigs = void 0;
|
|
4
|
+
const configs_1 = require("../configs");
|
|
5
|
+
const chains_1 = require("../configs/chains");
|
|
6
|
+
const artifacts_1 = require("./artifacts");
|
|
7
|
+
const ethers_1 = require("ethers");
|
|
8
|
+
let _config;
|
|
9
|
+
let _configs;
|
|
10
|
+
const getConfigs = () => {
|
|
11
|
+
if (!_configs) {
|
|
12
|
+
_configs = (0, configs_1.getChainsConfig)();
|
|
13
|
+
}
|
|
14
|
+
return _configs;
|
|
15
|
+
};
|
|
16
|
+
exports.getConfigs = getConfigs;
|
|
17
|
+
const setOverrideConfig = (chainId, newConfig) => {
|
|
18
|
+
if (!_configs) {
|
|
19
|
+
_configs = (0, exports.getConfigs)();
|
|
20
|
+
}
|
|
21
|
+
// FIXME: configs is not defined here.
|
|
22
|
+
if (!chains_1.configs[chainId]) {
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
chains_1.configs[chainId] = {};
|
|
25
|
+
}
|
|
26
|
+
chains_1.configs[chainId] = {
|
|
27
|
+
...chains_1.configs[chainId],
|
|
28
|
+
...newConfig,
|
|
29
|
+
contracts: {
|
|
30
|
+
...chains_1.configs[chainId].contracts,
|
|
31
|
+
...newConfig.contracts,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
exports.setOverrideConfig = setOverrideConfig;
|
|
36
|
+
const getConfig = (chainId) => {
|
|
37
|
+
const configs = (0, exports.getConfigs)();
|
|
38
|
+
if (!configs[chainId]) {
|
|
39
|
+
throw new Error(`Unsupported chain ID: ${chainId}. Has ${JSON.stringify(Object.keys(configs))}`);
|
|
40
|
+
}
|
|
41
|
+
return configs[chainId];
|
|
42
|
+
};
|
|
43
|
+
exports.getConfig = getConfig;
|
|
44
|
+
const getContract = (chainId, contractName, provider) => {
|
|
45
|
+
const normalizedContractName = contractName.toLowerCase();
|
|
46
|
+
const address = (0, exports.getContractAddress)(chainId, normalizedContractName);
|
|
47
|
+
const abi = (0, artifacts_1.getABI)(normalizedContractName);
|
|
48
|
+
return new ethers_1.ethers.Contract(address, abi, provider);
|
|
49
|
+
};
|
|
50
|
+
exports.getContract = getContract;
|
|
51
|
+
const getContractAddress = (chainId, contractName) => {
|
|
52
|
+
var _a;
|
|
53
|
+
const normalizedContractName = contractName.toLowerCase();
|
|
54
|
+
const config = (0, exports.getConfig)(chainId);
|
|
55
|
+
if (!config) {
|
|
56
|
+
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
57
|
+
}
|
|
58
|
+
const chainKeys = ["contracts", "assets", "pools", "nfts"];
|
|
59
|
+
const keys = Object.keys(config).filter((key) => chainKeys.includes(key));
|
|
60
|
+
let address = null;
|
|
61
|
+
for (const key of keys) {
|
|
62
|
+
if (config[key] && config[key][normalizedContractName]) {
|
|
63
|
+
address = (_a = config[key][normalizedContractName]) === null || _a === void 0 ? void 0 : _a.contract;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (!address) {
|
|
68
|
+
const hasIds = keys
|
|
69
|
+
.map((key) => `${key}: ${Object.keys(config[key]).join(", ")}`)
|
|
70
|
+
.join("\n");
|
|
71
|
+
throw new Error(`Contract ${normalizedContractName} not found for chain ID: ${chainId}.\nHas:\n${hasIds}`);
|
|
72
|
+
}
|
|
73
|
+
return address;
|
|
74
|
+
};
|
|
75
|
+
exports.getContractAddress = getContractAddress;
|
|
76
|
+
exports.default = {
|
|
77
|
+
getContract: exports.getContract,
|
|
78
|
+
getContractAddress: exports.getContractAddress,
|
|
79
|
+
setOverrideConfig: exports.setOverrideConfig,
|
|
80
|
+
getConfig: exports.getConfig,
|
|
81
|
+
getConfigs: exports.getConfigs,
|
|
82
|
+
};
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { ethers, Signer } from "ethers";
|
|
2
|
-
import
|
|
2
|
+
import getContractAddress from "../../contracts/getContractAddress";
|
|
3
3
|
import { getABI } from "../../utils/artifacts";
|
|
4
4
|
import estimateGasPrice from "../../methods/commons/estimateGasPrice";
|
|
5
|
-
import { ChainId } from "../../configs/chains/index";
|
|
6
|
-
import { StabilityPool } from "../../typechain-types";
|
|
7
5
|
|
|
8
6
|
async function withdrawFromStabilityPool(
|
|
9
|
-
chainId
|
|
10
|
-
amount
|
|
11
|
-
signer
|
|
7
|
+
chainId,
|
|
8
|
+
amount,
|
|
9
|
+
signer
|
|
12
10
|
) {
|
|
13
11
|
if (!signer) {
|
|
14
12
|
throw new Error("Wallet not connected");
|
|
@@ -21,7 +19,7 @@ async function withdrawFromStabilityPool(
|
|
|
21
19
|
stabilityPoolAddress,
|
|
22
20
|
abi,
|
|
23
21
|
signer
|
|
24
|
-
)
|
|
22
|
+
);
|
|
25
23
|
|
|
26
24
|
const amountInWei = ethers.parseEther(amount);
|
|
27
25
|
const { maxFeePerGas } = await estimateGasPrice(signer);
|
|
@@ -38,7 +36,7 @@ async function withdrawFromStabilityPool(
|
|
|
38
36
|
receipt?.hash
|
|
39
37
|
);
|
|
40
38
|
return receipt;
|
|
41
|
-
} catch (error
|
|
39
|
+
} catch (error) {
|
|
42
40
|
console.error(`Error withdrawing from Stability Pool:`, error);
|
|
43
41
|
throw new Error(`Withdrawal from Stability Pool failed: ${error.message}`);
|
|
44
42
|
}
|
package/ts-to-js.sh
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Script to find all TypeScript (.ts) files and transform them to JavaScript (.js)
|
|
4
|
+
# Author: RAAC
|
|
5
|
+
# Usage: ./ts-to-js.sh
|
|
6
|
+
|
|
7
|
+
# Set up error handling
|
|
8
|
+
set -e
|
|
9
|
+
|
|
10
|
+
echo "Starting TypeScript to JavaScript transformation..."
|
|
11
|
+
|
|
12
|
+
# Find all .ts files (excluding node_modules, dist, and typechain-types directories)
|
|
13
|
+
TS_FILES=$(find . -type f -name "*.ts" ! -path "*/node_modules/*" ! -path "*/dist/*" ! -path "*/typechain-types/*")
|
|
14
|
+
|
|
15
|
+
# Check if any TypeScript files were found
|
|
16
|
+
if [ -z "$TS_FILES" ]; then
|
|
17
|
+
echo "No TypeScript files found."
|
|
18
|
+
exit 0
|
|
19
|
+
fi
|
|
20
|
+
|
|
21
|
+
# Count the number of files to process
|
|
22
|
+
FILE_COUNT=$(echo "$TS_FILES" | wc -l)
|
|
23
|
+
echo "Found $FILE_COUNT TypeScript files to process."
|
|
24
|
+
|
|
25
|
+
# Process each TypeScript file
|
|
26
|
+
for TS_FILE in $TS_FILES; do
|
|
27
|
+
echo "Processing $TS_FILE..."
|
|
28
|
+
|
|
29
|
+
# Get the directory and filename without extension
|
|
30
|
+
DIR=$(dirname "$TS_FILE")
|
|
31
|
+
FILENAME=$(basename "$TS_FILE" .ts)
|
|
32
|
+
|
|
33
|
+
# Create the JavaScript file by copying and renaming
|
|
34
|
+
cp "$TS_FILE" "$DIR/$FILENAME.js"
|
|
35
|
+
|
|
36
|
+
# Remove the TypeScript file
|
|
37
|
+
rm "$TS_FILE"
|
|
38
|
+
|
|
39
|
+
echo "✓ Generated $DIR/$FILENAME.js"
|
|
40
|
+
done
|
|
41
|
+
|
|
42
|
+
echo "Transformation complete. $FILE_COUNT files processed."
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { getChainsConfig
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ethers, Provider } from "ethers";
|
|
1
|
+
import { getChainsConfig } from "../configs";
|
|
2
|
+
import { configs } from "../configs/chains";
|
|
3
|
+
import { getABI } from "./artifacts";
|
|
4
|
+
import { ethers } from "ethers";
|
|
6
5
|
|
|
7
6
|
let _config;
|
|
8
|
-
let _configs
|
|
7
|
+
let _configs = getChainsConfig();
|
|
9
8
|
|
|
10
9
|
export const getConfigs = () => {
|
|
11
10
|
if (!_configs) {
|
|
@@ -14,7 +13,7 @@ export const getConfigs = () => {
|
|
|
14
13
|
return _configs;
|
|
15
14
|
};
|
|
16
15
|
|
|
17
|
-
export const setOverrideConfig = (chainId
|
|
16
|
+
export const setOverrideConfig = (chainId, newConfig) => {
|
|
18
17
|
if (!_configs) {
|
|
19
18
|
_configs = getConfigs();
|
|
20
19
|
}
|
|
@@ -33,7 +32,7 @@ export const setOverrideConfig = (chainId: ChainId, newConfig: any) => {
|
|
|
33
32
|
};
|
|
34
33
|
};
|
|
35
34
|
|
|
36
|
-
export const getConfig = (chainId
|
|
35
|
+
export const getConfig = (chainId) => {
|
|
37
36
|
const configs = getConfigs();
|
|
38
37
|
if (!configs[chainId]) {
|
|
39
38
|
throw new Error(
|
|
@@ -46,31 +45,30 @@ export const getConfig = (chainId: ChainId) => {
|
|
|
46
45
|
};
|
|
47
46
|
|
|
48
47
|
export const getContract = (
|
|
49
|
-
chainId
|
|
50
|
-
contractName
|
|
51
|
-
provider
|
|
48
|
+
chainId,
|
|
49
|
+
contractName,
|
|
50
|
+
provider
|
|
52
51
|
) => {
|
|
53
|
-
const normalizedContractName =
|
|
54
|
-
contractName.toLowerCase() as keyof typeof ABIS;
|
|
52
|
+
const normalizedContractName = contractName.toLowerCase();
|
|
55
53
|
const address = getContractAddress(chainId, normalizedContractName);
|
|
56
54
|
const abi = getABI(normalizedContractName);
|
|
57
55
|
return new ethers.Contract(address, abi, provider);
|
|
58
56
|
};
|
|
59
57
|
|
|
60
|
-
export const getContractAddress = (chainId
|
|
58
|
+
export const getContractAddress = (chainId, contractName) => {
|
|
61
59
|
const normalizedContractName = contractName.toLowerCase();
|
|
62
60
|
const config = getConfig(chainId);
|
|
63
61
|
if (!config) {
|
|
64
62
|
throw new Error(`Unsupported chain ID: ${chainId}`);
|
|
65
63
|
}
|
|
66
|
-
const chainKeys = ["contracts", "assets", "pools", "nfts"]
|
|
67
|
-
const keys =
|
|
64
|
+
const chainKeys = ["contracts", "assets", "pools", "nfts"];
|
|
65
|
+
const keys = Object.keys(config).filter((key) =>
|
|
68
66
|
chainKeys.includes(key)
|
|
69
67
|
);
|
|
70
68
|
let address = null;
|
|
71
69
|
for (const key of keys) {
|
|
72
|
-
if (config[key] &&
|
|
73
|
-
address =
|
|
70
|
+
if (config[key] && config[key][normalizedContractName]) {
|
|
71
|
+
address = config[key][normalizedContractName]?.contract;
|
|
74
72
|
break;
|
|
75
73
|
}
|
|
76
74
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { ethers, Signer } from "ethers";
|
|
2
2
|
import { getContractAddress } from "../../utils/contracts";
|
|
3
|
-
import { ABIS,
|
|
3
|
+
import { ABIS, getABI } from "../../utils/artifacts";
|
|
4
4
|
import estimateGasPrice from "../../methods/commons/estimateGasPrice";
|
|
5
|
-
import { ChainId } from "../../configs/chains/index";
|
|
6
5
|
|
|
7
6
|
async function approveAsset(
|
|
8
|
-
chainId
|
|
9
|
-
assetId
|
|
10
|
-
spender
|
|
11
|
-
amount
|
|
12
|
-
signer
|
|
7
|
+
chainId,
|
|
8
|
+
assetId,
|
|
9
|
+
spender,
|
|
10
|
+
amount,
|
|
11
|
+
signer
|
|
13
12
|
) {
|
|
14
13
|
if (!signer) {
|
|
15
14
|
throw new Error("Wallet not connected");
|
|
@@ -36,7 +35,7 @@ async function approveAsset(
|
|
|
36
35
|
receipt.transactionHash
|
|
37
36
|
);
|
|
38
37
|
return receipt;
|
|
39
|
-
} catch (error
|
|
38
|
+
} catch (error) {
|
|
40
39
|
console.error(`Approval error for ${assetId}:`, error);
|
|
41
40
|
throw new Error(`Token approval failed for ${assetId}: ${error.message}`);
|
|
42
41
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { ethers, Signer } from "ethers";
|
|
2
2
|
import { getConfig } from "../../utils/contracts";
|
|
3
3
|
import estimateGasPrice from "../../methods/commons/estimateGasPrice";
|
|
4
|
-
import {
|
|
5
|
-
import { ChainId } from "../../configs/chains/index";
|
|
4
|
+
import { getABI } from "../../utils/artifacts";
|
|
6
5
|
|
|
7
6
|
async function burnAsset(
|
|
8
|
-
chainId
|
|
9
|
-
assetId
|
|
10
|
-
amount
|
|
11
|
-
signer
|
|
7
|
+
chainId,
|
|
8
|
+
assetId,
|
|
9
|
+
amount,
|
|
10
|
+
signer
|
|
12
11
|
) {
|
|
13
12
|
try {
|
|
14
13
|
if (!signer) {
|
|
@@ -17,8 +16,7 @@ async function burnAsset(
|
|
|
17
16
|
|
|
18
17
|
const { assets } = getConfig(chainId);
|
|
19
18
|
const asset = Object.values(assets).find(
|
|
20
|
-
|
|
21
|
-
(asset) => asset.id.toLowerCase() === (assetId as string).toLowerCase()
|
|
19
|
+
(asset) => asset.id.toLowerCase() === assetId.toLowerCase()
|
|
22
20
|
);
|
|
23
21
|
if (!asset) {
|
|
24
22
|
throw new Error(`Asset ${assetId} not found on chain ${chainId}`);
|
|
@@ -49,7 +47,7 @@ async function burnAsset(
|
|
|
49
47
|
receipt.transactionHash
|
|
50
48
|
);
|
|
51
49
|
return receipt;
|
|
52
|
-
} catch (error
|
|
50
|
+
} catch (error) {
|
|
53
51
|
console.error(`Error burning asset ${assetId}:`, error);
|
|
54
52
|
throw new Error(`Burning failed for ${assetId}: ${error.message}`);
|
|
55
53
|
}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import { ethers
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { ChainId } from "../../configs/chains/index";
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import getContractAddress from "../../contracts/getContractAddress";
|
|
3
|
+
import { getABI } from "../../utils/artifacts";
|
|
5
4
|
|
|
6
5
|
async function getAllowance(
|
|
7
|
-
chainId
|
|
8
|
-
assetId
|
|
9
|
-
owner
|
|
10
|
-
spender
|
|
11
|
-
provider
|
|
6
|
+
chainId,
|
|
7
|
+
assetId,
|
|
8
|
+
owner,
|
|
9
|
+
spender,
|
|
10
|
+
provider
|
|
12
11
|
) {
|
|
13
12
|
try {
|
|
14
13
|
if (assetId === "eth") {
|
|
@@ -27,7 +26,7 @@ async function getAllowance(
|
|
|
27
26
|
);
|
|
28
27
|
const allowance = await contract.allowance(owner, spender);
|
|
29
28
|
return ethers.formatEther(allowance);
|
|
30
|
-
} catch (error
|
|
29
|
+
} catch (error) {
|
|
31
30
|
console.error(`Error getting allowance for asset ${assetId}:`, error);
|
|
32
31
|
console.log({ assetId, owner, spender });
|
|
33
32
|
console.log(error);
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { Provider
|
|
2
|
-
import { AssetType } from "../../utils/artifacts";
|
|
1
|
+
import { Provider } from "ethers";
|
|
3
2
|
import { getConfig } from "../../utils/contracts";
|
|
4
3
|
import { ChainId } from "../../configs/chains/index";
|
|
5
4
|
|
|
6
5
|
async function getAsset(
|
|
7
|
-
chainId
|
|
8
|
-
assetId
|
|
9
|
-
address
|
|
10
|
-
provider
|
|
6
|
+
chainId,
|
|
7
|
+
assetId,
|
|
8
|
+
address,
|
|
9
|
+
provider
|
|
11
10
|
) {
|
|
12
11
|
const { assets } = getConfig(chainId);
|
|
13
12
|
// @ts-ignore
|
|
@@ -22,7 +21,7 @@ async function getAsset(
|
|
|
22
21
|
try {
|
|
23
22
|
const balance = await this.getBalance(chainId, assetId, owner, provider);
|
|
24
23
|
response.balance = parseFloat(balance).toString();
|
|
25
|
-
} catch (error
|
|
24
|
+
} catch (error) {
|
|
26
25
|
console.log(`Error getting balance: ${error}`);
|
|
27
26
|
}
|
|
28
27
|
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { Provider
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
2
|
import { getConfig } from "../../utils/contracts";
|
|
3
|
-
import { ChainId } from "../../configs/chains/index";
|
|
4
3
|
import RPCLibrary from "../../RPCLibrary";
|
|
5
4
|
|
|
6
5
|
async function getAssets(
|
|
7
|
-
chainId
|
|
8
|
-
address
|
|
9
|
-
provider
|
|
6
|
+
chainId,
|
|
7
|
+
address,
|
|
8
|
+
provider
|
|
10
9
|
) {
|
|
11
10
|
const { assets } = getConfig(chainId);
|
|
12
|
-
const responses
|
|
11
|
+
const responses = {};
|
|
13
12
|
|
|
14
13
|
const assetIds = Object.keys(assets);
|
|
15
14
|
const assetPromises = assetIds.map(async (assetId) => {
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { ethers
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import { ChainId } from "../../configs/chains/index";
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import getContractAddress from "../../contracts/getContractAddress";
|
|
3
|
+
import { getABI } from "../../utils/artifacts";
|
|
5
4
|
|
|
6
5
|
async function getBalance(
|
|
7
|
-
chainId
|
|
8
|
-
assetId
|
|
9
|
-
address
|
|
10
|
-
provider
|
|
6
|
+
chainId,
|
|
7
|
+
assetId,
|
|
8
|
+
address,
|
|
9
|
+
provider
|
|
11
10
|
) {
|
|
12
11
|
const BALANCE_OF_ABI = ["function balanceOf(address) view returns (uint256)"];
|
|
13
12
|
try {
|
|
@@ -25,7 +24,7 @@ async function getBalance(
|
|
|
25
24
|
const balance = await contract.balanceOf(address);
|
|
26
25
|
const parsedBalance = parseFloat(ethers.formatEther(balance));
|
|
27
26
|
return parsedBalance.toString();
|
|
28
|
-
} catch (error
|
|
27
|
+
} catch (error) {
|
|
29
28
|
console.error(`Error getting balance for asset ${assetId}:`, error);
|
|
30
29
|
return 0;
|
|
31
30
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { ethers, Signer } from "ethers";
|
|
2
2
|
import { getConfig } from "../../utils/contracts";
|
|
3
3
|
import estimateGasPrice from "../../methods/commons/estimateGasPrice";
|
|
4
|
-
import {
|
|
5
|
-
import { ChainId } from "../../configs/chains/index";
|
|
4
|
+
import { getABI } from "../../utils/artifacts";
|
|
6
5
|
|
|
7
6
|
async function mintAsset(
|
|
8
|
-
chainId
|
|
9
|
-
assetId
|
|
10
|
-
amount
|
|
11
|
-
address
|
|
12
|
-
signer
|
|
7
|
+
chainId,
|
|
8
|
+
assetId,
|
|
9
|
+
amount,
|
|
10
|
+
address,
|
|
11
|
+
signer
|
|
13
12
|
) {
|
|
14
13
|
try {
|
|
15
14
|
if (!signer) {
|
|
@@ -20,7 +19,7 @@ async function mintAsset(
|
|
|
20
19
|
console.log("assets", assets);
|
|
21
20
|
const asset = Object.values(assets).find(
|
|
22
21
|
// @ts-ignore
|
|
23
|
-
(asset) => asset.id.toLowerCase() ===
|
|
22
|
+
(asset) => asset.id.toLowerCase() === assetId.toLowerCase()
|
|
24
23
|
);
|
|
25
24
|
if (!asset) {
|
|
26
25
|
throw new Error(`Asset ${assetId} not found on chain ${chainId}`);
|
|
@@ -51,7 +50,7 @@ async function mintAsset(
|
|
|
51
50
|
const receipt = await tx.wait();
|
|
52
51
|
console.log(`Minted ${amount} ${assetId} successfully:`, receipt.hash);
|
|
53
52
|
return receipt;
|
|
54
|
-
} catch (error
|
|
53
|
+
} catch (error) {
|
|
55
54
|
console.error(`Error minting asset ${assetId}:`, error);
|
|
56
55
|
throw new Error(`Minting failed for ${assetId}: ${error.message}`);
|
|
57
56
|
}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { ethers, Signer } from "ethers";
|
|
2
2
|
import { getConfig } from "../../utils/contracts";
|
|
3
3
|
import estimateGasPrice from "../../methods/commons/estimateGasPrice";
|
|
4
|
-
import {
|
|
5
|
-
import { ChainId } from "../../configs/chains/index";
|
|
4
|
+
import { getABI } from "../../utils/artifacts";
|
|
6
5
|
|
|
7
6
|
async function transferAsset(
|
|
8
|
-
chainId
|
|
9
|
-
assetId
|
|
10
|
-
amount
|
|
11
|
-
fromAddress
|
|
12
|
-
toAddress
|
|
13
|
-
signer
|
|
7
|
+
chainId,
|
|
8
|
+
assetId,
|
|
9
|
+
amount,
|
|
10
|
+
fromAddress,
|
|
11
|
+
toAddress,
|
|
12
|
+
signer
|
|
14
13
|
) {
|
|
15
14
|
try {
|
|
16
15
|
if (!signer) {
|
|
@@ -20,7 +19,7 @@ async function transferAsset(
|
|
|
20
19
|
const { maxFeePerGas } = await estimateGasPrice(signer);
|
|
21
20
|
const amountToTransfer = ethers.parseEther(amount.toString());
|
|
22
21
|
|
|
23
|
-
if (
|
|
22
|
+
if (assetId.toLowerCase() === "eth") {
|
|
24
23
|
// Handle ETH transfer
|
|
25
24
|
const tx = await signer.sendTransaction({
|
|
26
25
|
to: toAddress,
|
|
@@ -41,7 +40,7 @@ async function transferAsset(
|
|
|
41
40
|
const { assets } = getConfig(chainId);
|
|
42
41
|
const asset = Object.values(assets).find(
|
|
43
42
|
// @ts-ignore
|
|
44
|
-
(asset) => asset.id.toLowerCase() ===
|
|
43
|
+
(asset) => asset.id.toLowerCase() === assetId.toLowerCase()
|
|
45
44
|
);
|
|
46
45
|
if (!asset) {
|
|
47
46
|
throw new Error(`Asset ${assetId} not found on chain ${chainId}`);
|
|
@@ -71,7 +70,7 @@ async function transferAsset(
|
|
|
71
70
|
);
|
|
72
71
|
return receipt;
|
|
73
72
|
}
|
|
74
|
-
} catch (error
|
|
73
|
+
} catch (error) {
|
|
75
74
|
console.error(`Error transferring asset ${assetId}:`, error);
|
|
76
75
|
throw new Error(`Transfer failed for ${assetId}: ${error.message}`);
|
|
77
76
|
}
|
package/configs/chains/index.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
import chain8453 from "./8453.json"; // assert { type: "json" };
|
|
3
|
-
import chain17000 from "./17000.json"; // assert { type: "json" };
|
|
4
|
-
import chain11155111 from "./11155111.json"; // assert { type: "json" };
|
|
5
|
-
import { Chain, Chain8453, Chain11155111 } from "./chain";
|
|
6
|
-
|
|
7
|
-
const chains = {
|
|
8
|
-
8453: chain8453 as Chain8453,
|
|
9
|
-
17000: chain17000 as Chain8453, // the interface is the same for all the chains, so taking this
|
|
10
|
-
11155111: chain11155111 as Chain11155111,
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export default chains;
|
|
14
|
-
export const configs = chains;
|
|
15
|
-
export type Configs = typeof chains;
|
|
16
|
-
export type ConfigKeys = keyof Configs;
|
|
17
|
-
export type ChainId = ConfigKeys | string | number;
|
package/configs/index.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
// let fs;
|
|
2
|
-
// let path;
|
|
3
|
-
// let fileURLToPath;
|
|
4
|
-
|
|
5
|
-
// if (typeof window === 'undefined') {
|
|
6
|
-
// // Server-side
|
|
7
|
-
// // fs = import('fs');
|
|
8
|
-
// path = import('path');
|
|
9
|
-
// fileURLToPath = import('url').fileURLToPath;
|
|
10
|
-
// }
|
|
11
|
-
|
|
12
|
-
import { Chain } from "./chains/chain";
|
|
13
|
-
import chains, { ChainId } from "./chains/index";
|
|
14
|
-
|
|
15
|
-
function getChainsConfig() {
|
|
16
|
-
// if (typeof window === 'undefined') {
|
|
17
|
-
// // Server-side logic
|
|
18
|
-
// const __filename = fileURLToPath(import.meta.url);
|
|
19
|
-
// const __dirname = path.dirname(__filename);
|
|
20
|
-
// const chainsDir = `${__dirname}/chains`;
|
|
21
|
-
// const chainsFiles = fs.readdirSync(chainsDir).filter(file => file.endsWith('.json'));
|
|
22
|
-
|
|
23
|
-
// const chains = {};
|
|
24
|
-
// for(const chainFileName of chainsFiles) {
|
|
25
|
-
// const chainId = chainFileName.split('.')[0];
|
|
26
|
-
// const chainConfig = fs.readFileSync(`${chainsDir}/${chainFileName}`, 'utf8');
|
|
27
|
-
// chains[chainId] = JSON.parse(chainConfig);
|
|
28
|
-
// }
|
|
29
|
-
// return chains;
|
|
30
|
-
// } else {
|
|
31
|
-
// const chainConfigs = {
|
|
32
|
-
// 8453: chain8453,
|
|
33
|
-
// };
|
|
34
|
-
// // Client-side logic via API ?
|
|
35
|
-
// return chainConfigs;
|
|
36
|
-
// }
|
|
37
|
-
|
|
38
|
-
return chains;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function setChainConfig(chainId: ChainId, config: any) {
|
|
42
|
-
chains[chainId] = config;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function getChainConfig(chainId: ChainId) {
|
|
46
|
-
const chains = getChainsConfig();
|
|
47
|
-
return chains[chainId];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export default { getChainsConfig, getChainConfig, setChainConfig };
|
|
51
|
-
export { getChainsConfig, getChainConfig, setChainConfig };
|