@raac/rpc 1.0.0
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/README.md +1 -0
- package/RPCLibrary.ts +358 -0
- package/assets/getAsset.ts +26 -0
- package/assets/getAssets.ts +30 -0
- package/assets/getSupply.ts +23 -0
- package/configs/chains/8453.json +116 -0
- package/configs/chains/chain.d.ts +87 -0
- package/configs/chains/index.ts +13 -0
- package/configs/chains/list.json +3 -0
- package/configs/createConfig.ts +91 -0
- package/configs/index.ts +51 -0
- package/contracts/crvUSDToken/getBalance.ts +23 -0
- package/contracts/crvUSDToken/getTotalSupply.ts +36 -0
- package/contracts/getContract.ts +21 -0
- package/contracts/getContractAddress.ts +61 -0
- package/contracts/housePrices/getLatestPrice.ts +38 -0
- package/contracts/housePrices/setOracle.ts +40 -0
- package/contracts/rcrvUSDToken/getBalance.ts +23 -0
- package/contracts/rcrvUSDToken/getTotalSupply.ts +39 -0
- package/contracts/zeno/createAuction.ts +57 -0
- package/contracts/zeno/createZeno.ts +45 -0
- package/contracts/zeno/getAuctions.ts +38 -0
- package/contracts/zeno/getZenos.ts +38 -0
- package/custom-types.d.ts +20 -0
- package/index.ts +3 -0
- package/methods/approveToken.ts +47 -0
- package/methods/commons/checkAllowance.ts +36 -0
- package/methods/commons/estimateGasPrice.ts +21 -0
- package/methods/debug/mintToken.js +83 -0
- package/methods/getAssetBalance.ts +47 -0
- package/methods/getAssetsBalance.ts +9 -0
- package/minter/get.ts +150 -0
- package/minter/getApy.ts +37 -0
- package/minter/tick.ts +40 -0
- package/nfts/addNewBatch.ts +37 -0
- package/nfts/getCurrentBatchSize.ts +26 -0
- package/nfts/getDepositedNFTs.ts +31 -0
- package/nfts/getHousePrice.ts +30 -0
- package/nfts/getOwnedNFTs.ts +46 -0
- package/nfts/mint.ts +43 -0
- package/nfts/setBaseUri.ts +33 -0
- package/package.json +27 -0
- package/pools/lendingPool/borrowFromLendingPool.ts +39 -0
- package/pools/lendingPool/depositNFTToLendingPool.ts +70 -0
- package/pools/lendingPool/depositToLendingPool.ts +52 -0
- package/pools/lendingPool/getHousePrice.ts +46 -0
- package/pools/lendingPool/getLendingPoolInfo.ts +153 -0
- package/pools/lendingPool/getLendingPoolTotalLiquidity.ts +32 -0
- package/pools/lendingPool/repayToLendingPool.ts +52 -0
- package/pools/lendingPool/withdrawFromLendingPool.ts +68 -0
- package/pools/lendingPool/withdrawNFTFromLendingPool.ts +39 -0
- package/pools/liquidityPool/getLiquidityPoolInfo.ts +90 -0
- package/pools/stabilityPool/calculateRAACRewards.ts +37 -0
- package/pools/stabilityPool/depositToStabilityPool.ts +47 -0
- package/pools/stabilityPool/getStabilityPoolInfo.ts +121 -0
- package/pools/stabilityPool/getStabilityPoolTotalDeposits.ts +27 -0
- package/pools/stabilityPool/withdrawFromStabilityPool.ts +47 -0
- package/sync-contracts.sh +63 -0
- package/tests/test.ts +40 -0
- package/tsconfig.json +113 -0
- package/utils/artifacts.ts +66 -0
- package/utils/chain.ts +94 -0
- package/utils/config.ts +49 -0
- package/utils/contracts.ts +94 -0
- package/wallet/assets/approveAsset.ts +44 -0
- package/wallet/assets/burnAsset.ts +55 -0
- package/wallet/assets/getAllowance.ts +38 -0
- package/wallet/assets/getAsset.ts +33 -0
- package/wallet/assets/getAssets.ts +35 -0
- package/wallet/assets/getBalance.ts +34 -0
- package/wallet/assets/mintAsset.ts +57 -0
- package/wallet/assets/transferAsset.ts +78 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { getContract, getContractAddress } from "../../utils/contracts";
|
|
3
|
+
import { ContractType } from "../../utils/artifacts";
|
|
4
|
+
import { ChainId } from "../../configs/chains/index";
|
|
5
|
+
import { ERC20 } from "../../typechain-types";
|
|
6
|
+
|
|
7
|
+
const checkAllowance = async (
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
tokenId: ContractType,
|
|
10
|
+
address: string,
|
|
11
|
+
spenderAddress: string,
|
|
12
|
+
provider: Provider
|
|
13
|
+
) => {
|
|
14
|
+
let tokenAddress = getContractAddress(chainId, tokenId as string);
|
|
15
|
+
console.log(
|
|
16
|
+
`[commons/checkAllowance] Checking allowance for ${address} to ${spenderAddress} on ${chainId} ${tokenId}:${tokenAddress}`
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
const tokenContract = getContract(
|
|
21
|
+
chainId,
|
|
22
|
+
tokenId,
|
|
23
|
+
provider
|
|
24
|
+
) as any as ERC20;
|
|
25
|
+
const allowance = await tokenContract.allowance(address, spenderAddress);
|
|
26
|
+
return allowance;
|
|
27
|
+
} catch (error: any) {
|
|
28
|
+
console.error(`Error calling allowance: ${error}`);
|
|
29
|
+
throw new Error(
|
|
30
|
+
`[commons/checkAllowance] ${chainId} ${tokenId}:${tokenAddress} ${address} ${spenderAddress} ${error}`
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export default checkAllowance;
|
|
36
|
+
export { checkAllowance };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Provider, Signer } from "ethers";
|
|
2
|
+
|
|
3
|
+
export const estimateGasPrice = async (signer: Signer) => {
|
|
4
|
+
const provider = signer.provider as Provider;
|
|
5
|
+
try {
|
|
6
|
+
const feeData = await provider.getFeeData();
|
|
7
|
+
return {
|
|
8
|
+
maxFeePerGas: feeData.maxFeePerGas,
|
|
9
|
+
maxPriorityFeePerGas: feeData.maxPriorityFeePerGas,
|
|
10
|
+
};
|
|
11
|
+
} catch (error: any) {
|
|
12
|
+
console.log("Error getting gas price", error);
|
|
13
|
+
if ((provider as any)?.getGasPrice) {
|
|
14
|
+
const gasPrice = await (provider as any).getGasPrice();
|
|
15
|
+
return { gasPrice };
|
|
16
|
+
}
|
|
17
|
+
return { gasPrice: 0 };
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export default estimateGasPrice;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
|
|
3
|
+
import { getContractAddress } from "../../contracts/getContractAddress";
|
|
4
|
+
import estimateGasPrice from "../commons/estimateGasPrice";
|
|
5
|
+
|
|
6
|
+
import crvUSDTokenArtifact from "../../artifacts/Tokens/crvUSDToken.sol/crvUSDToken.json"; // assert { type: "json" };
|
|
7
|
+
import spcrvUSDTokenArtifact from "../../artifacts/Tokens/spcrvUSDToken.sol/spcrvUSDToken.json"; // assert { type: "json" };
|
|
8
|
+
import RAACTokenArtifact from "../../artifacts/Tokens/RAACToken.sol/RAACToken.json"; // assert { type: "json" };
|
|
9
|
+
import veRAACTokenArtifact from "../../artifacts/Tokens/veRAACToken.sol/veRAACToken.json"; // assert { type: "json" };
|
|
10
|
+
import rcrvUSDTokenArtifact from "../../artifacts/Tokens/rCRVUSDToken.sol/rCRVUSDToken.json"; // assert { type: "json" };
|
|
11
|
+
import RAACLendingPoolArtifact from "../../artifacts/LendingPool/RAACLendingPool.sol/RAACLendingPool.json"; // assert { type: "json" };
|
|
12
|
+
import RAACStabilityPoolArtifact from "../../artifacts/StabilityPool/StabilityPool.sol/StabilityPool.json"; // assert { type: "json" };
|
|
13
|
+
import LiquidityPoolArtifact from "../../artifacts/LiquidityPool/LiquidityPool.sol/LiquidityPool.json"; // assert { type: "json" };
|
|
14
|
+
import RTokenArtifact from "../../artifacts/Tokens/RToken.sol/RToken.json"; // assert { type: "json" };
|
|
15
|
+
import RAACNFTArtifact from "../../artifacts/Tokens/RAACNFT.sol/RAACNFT.json"; // assert { type: "json" };
|
|
16
|
+
|
|
17
|
+
const CRVUSD_ABI = crvUSDTokenArtifact.abi;
|
|
18
|
+
const SPCRVUSD_ABI = spcrvUSDTokenArtifact.abi;
|
|
19
|
+
const VERAAC_ABI = veRAACTokenArtifact.abi;
|
|
20
|
+
const RCRVUSD_ABI = rcrvUSDTokenArtifact.abi;
|
|
21
|
+
const RAACLENDINGPOOL_ABI = RAACLendingPoolArtifact.abi;
|
|
22
|
+
const RAACSTABILITYPOOL_ABI = RAACStabilityPoolArtifact.abi;
|
|
23
|
+
const LIQUIDITYPOOL_ABI = LiquidityPoolArtifact.abi;
|
|
24
|
+
const RAAC_ABI = RAACNFTArtifact.abi;
|
|
25
|
+
const RTOKEN_ABI = RTokenArtifact.abi;
|
|
26
|
+
|
|
27
|
+
const mintToken = async (chainId, assetId, amount, signer) => {
|
|
28
|
+
if (!signer) {
|
|
29
|
+
throw new Error("Wallet not connected");
|
|
30
|
+
}
|
|
31
|
+
const normalizedAssetId = assetId.toLowerCase();
|
|
32
|
+
const contractAddress = getContractAddress(chainId, normalizedAssetId);
|
|
33
|
+
let contract;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
switch (normalizedAssetId) {
|
|
37
|
+
case "crvusd":
|
|
38
|
+
contract = new ethers.Contract(contractAddress, CRVUSD_ABI, signer);
|
|
39
|
+
break;
|
|
40
|
+
case "spcrvusd":
|
|
41
|
+
contract = new ethers.Contract(contractAddress, SPCRVUSD_ABI, signer);
|
|
42
|
+
break;
|
|
43
|
+
case "rcrvusd":
|
|
44
|
+
contract = new ethers.Contract(contractAddress, RCRVUSD_ABI, signer);
|
|
45
|
+
break;
|
|
46
|
+
case "rtoken":
|
|
47
|
+
contract = new ethers.Contract(contractAddress, RTOKEN_ABI, signer);
|
|
48
|
+
break;
|
|
49
|
+
case "raacnft":
|
|
50
|
+
contract = new ethers.Contract(contractAddress, RAACNFT_ABI, signer);
|
|
51
|
+
break;
|
|
52
|
+
case "veraac":
|
|
53
|
+
contract = new ethers.Contract(contractAddress, VERAAC_ABI, signer);
|
|
54
|
+
break;
|
|
55
|
+
default:
|
|
56
|
+
throw new Error(`Unsupported asset: ${normalizedAssetId}`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { maxFeePerGas } = await estimateGasPrice(signer);
|
|
60
|
+
const tx = await contract.mint(
|
|
61
|
+
await signer.getAddress(),
|
|
62
|
+
ethers.parseEther(amount),
|
|
63
|
+
{
|
|
64
|
+
maxFeePerGas,
|
|
65
|
+
// maxPriorityFeePerGas
|
|
66
|
+
}
|
|
67
|
+
);
|
|
68
|
+
console.log(`Minting transaction sent for ${normalizedAssetId}:`, tx.hash);
|
|
69
|
+
const receipt = await tx.wait();
|
|
70
|
+
console.log(
|
|
71
|
+
`Minted ${amount} ${normalizedAssetId} successfully:`,
|
|
72
|
+
receipt.transactionHash
|
|
73
|
+
);
|
|
74
|
+
return receipt;
|
|
75
|
+
} catch (error: any){
|
|
76
|
+
console.error(`Minting error for ${normalizedAssetId}:`, error);
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Minting failed for ${normalizedAssetId}: ${error.message}`
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default mintToken;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ethers, Provider, Signer } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../contracts/getContractAddress";
|
|
3
|
+
import { ChainId } from "../configs/chains/index";
|
|
4
|
+
import { AssetType, ContractType } from "../utils/artifacts";
|
|
5
|
+
import { ERC20 } from "../typechain-types";
|
|
6
|
+
|
|
7
|
+
const getAssetBalance = async (
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
address: string,
|
|
10
|
+
assetId: AssetType,
|
|
11
|
+
signer: Signer
|
|
12
|
+
) => {
|
|
13
|
+
if (!signer) {
|
|
14
|
+
throw new Error("Wallet not connected");
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
if (assetId === "eth") {
|
|
18
|
+
const provider = signer.provider as Provider;
|
|
19
|
+
// handle getBalance do not exist in ethers.js, check if not under the other method TODO FIXME
|
|
20
|
+
const balance = (await provider.getBalance(address)).toString();
|
|
21
|
+
return balance;
|
|
22
|
+
}
|
|
23
|
+
const tokenAddress = getContractAddress(chainId, assetId);
|
|
24
|
+
const abi = ["function balanceOf(address) view returns (uint256)"];
|
|
25
|
+
const contract = new ethers.Contract(
|
|
26
|
+
tokenAddress,
|
|
27
|
+
abi,
|
|
28
|
+
signer
|
|
29
|
+
) as any as ERC20;
|
|
30
|
+
|
|
31
|
+
const balance = await contract.balanceOf(address);
|
|
32
|
+
|
|
33
|
+
return ethers.formatEther(balance);
|
|
34
|
+
} catch (error: any) {
|
|
35
|
+
console.error(`Error in getAssetBalance for ${assetId}:`, error);
|
|
36
|
+
if (error.code === "BAD_DATA") {
|
|
37
|
+
console.error(
|
|
38
|
+
"Contract might not have balanceOf function. Check the contract address and ABI."
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
throw new Error(`Failed to fetch balance for ${assetId}: ${error.message}`);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default getAssetBalance;
|
|
46
|
+
|
|
47
|
+
export { getAssetBalance };
|
package/minter/get.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { ethers, Signer } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../utils/contracts";
|
|
3
|
+
import { getABI } from "../utils/artifacts";
|
|
4
|
+
import estimateGasPrice from "../methods/commons/estimateGasPrice";
|
|
5
|
+
import { ChainId } from "../configs/chains/index";
|
|
6
|
+
import { RAACMinter } from "../typechain-types";
|
|
7
|
+
|
|
8
|
+
async function get(chainId: ChainId, signer: Signer) {
|
|
9
|
+
if (!signer) {
|
|
10
|
+
throw new Error("Wallet not connected");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const raacMinterAddress = getContractAddress(chainId, "raacminter");
|
|
15
|
+
const raacMinterABI = getABI("raacminter");
|
|
16
|
+
// console.log(raacMinterAddress);
|
|
17
|
+
// console.log(raacMinterABI);
|
|
18
|
+
|
|
19
|
+
const raacMinterContract = new ethers.Contract(
|
|
20
|
+
raacMinterAddress,
|
|
21
|
+
raacMinterABI,
|
|
22
|
+
signer
|
|
23
|
+
) as any as RAACMinter;
|
|
24
|
+
|
|
25
|
+
const handleError = (operation: string) => (error: any) => {
|
|
26
|
+
if (error.code === "BAD_DATA") {
|
|
27
|
+
console.log(`BAD_DATA from getMinter - ${operation}:`, error.message);
|
|
28
|
+
return 0n;
|
|
29
|
+
}
|
|
30
|
+
throw error;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const { maxFeePerGas } = await estimateGasPrice(signer);
|
|
34
|
+
|
|
35
|
+
const [
|
|
36
|
+
emissionRate,
|
|
37
|
+
benchmarkRate,
|
|
38
|
+
minEmissionRate,
|
|
39
|
+
maxEmissionRate,
|
|
40
|
+
utilizationTarget,
|
|
41
|
+
excessTokens,
|
|
42
|
+
lastUpdateBlock,
|
|
43
|
+
raacToken,
|
|
44
|
+
stabilityPool,
|
|
45
|
+
lendingPool,
|
|
46
|
+
owner,
|
|
47
|
+
BLOCKS_PER_DAY,
|
|
48
|
+
] = await Promise.all([
|
|
49
|
+
raacMinterContract.emissionRate().catch(handleError("emissionRate")),
|
|
50
|
+
raacMinterContract.benchmarkRate().catch(handleError("benchmarkRate")),
|
|
51
|
+
raacMinterContract
|
|
52
|
+
.minEmissionRate()
|
|
53
|
+
.catch(handleError("minEmissionRate")),
|
|
54
|
+
raacMinterContract
|
|
55
|
+
.maxEmissionRate()
|
|
56
|
+
.catch(handleError("maxEmissionRate")),
|
|
57
|
+
raacMinterContract
|
|
58
|
+
.utilizationTarget()
|
|
59
|
+
.catch(handleError("utilizationTarget")),
|
|
60
|
+
raacMinterContract.excessTokens().catch(handleError("excessTokens")),
|
|
61
|
+
raacMinterContract
|
|
62
|
+
.lastUpdateBlock()
|
|
63
|
+
.catch(handleError("lastUpdateBlock")),
|
|
64
|
+
raacMinterContract.raacToken().catch(handleError("raacToken")),
|
|
65
|
+
raacMinterContract.stabilityPool().catch(handleError("stabilityPool")),
|
|
66
|
+
raacMinterContract.lendingPool().catch(handleError("lendingPool")),
|
|
67
|
+
raacMinterContract.owner().catch(handleError("owner")),
|
|
68
|
+
raacMinterContract.BLOCKS_PER_DAY().catch(handleError("BLOCKS_PER_DAY")),
|
|
69
|
+
]);
|
|
70
|
+
|
|
71
|
+
const result = {
|
|
72
|
+
emissionRate,
|
|
73
|
+
benchmarkRate,
|
|
74
|
+
minEmissionRate,
|
|
75
|
+
maxEmissionRate,
|
|
76
|
+
utilizationTarget,
|
|
77
|
+
excessTokens,
|
|
78
|
+
lastUpdateBlock,
|
|
79
|
+
raacToken,
|
|
80
|
+
stabilityPool,
|
|
81
|
+
lendingPool,
|
|
82
|
+
owner,
|
|
83
|
+
BLOCKS_PER_DAY,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Call all readable values from the RAACMinter contract
|
|
87
|
+
// result.emissionRate = await raacMinterContract.emissionRate();
|
|
88
|
+
// result.benchmarkRate = await raacMinterContract.benchmarkRate();
|
|
89
|
+
// result.minEmissionRate = await raacMinterContract.minEmissionRate();
|
|
90
|
+
// result.maxEmissionRate = await raacMinterContract.maxEmissionRate();
|
|
91
|
+
// result.utilizationTarget = await raacMinterContract.utilizationTarget();
|
|
92
|
+
// result.excessTokens = await raacMinterContract.excessTokens();
|
|
93
|
+
// result.lastUpdateBlock = await raacMinterContract.lastUpdateBlock();
|
|
94
|
+
// result.raacToken = await raacMinterContract.raacToken();
|
|
95
|
+
// result.stabilityPool = await raacMinterContract.stabilityPool();
|
|
96
|
+
// result.lendingPool = await raacMinterContract.lendingPool();
|
|
97
|
+
// result.owner = await raacMinterContract.owner();
|
|
98
|
+
// result.BLOCKS_PER_DAY = await raacMinterContract.BLOCKS_PER_DAY();
|
|
99
|
+
|
|
100
|
+
// APY:
|
|
101
|
+
const blocksPerYear = result.BLOCKS_PER_DAY * 365n;
|
|
102
|
+
const emissionRatePerYear = result.emissionRate * blocksPerYear;
|
|
103
|
+
console.log("emissionRatePerYear", emissionRatePerYear);
|
|
104
|
+
const totalSupply = await raacMinterContract.getTotalSupply();
|
|
105
|
+
console.log("totalSupply", totalSupply);
|
|
106
|
+
|
|
107
|
+
const apy = (emissionRatePerYear * 10000n) / totalSupply;
|
|
108
|
+
console.log("apy", apy);
|
|
109
|
+
|
|
110
|
+
// const BLOCKS_PER_YEAR = 2628000; // Assuming 6500 blocks per day * 365 days
|
|
111
|
+
// const emissionRatePerYear = result.emissionRate * BLOCKS_PER_YEAR;
|
|
112
|
+
// console.log("emissionRatePerYear", emissionRatePerYear);
|
|
113
|
+
// const totalSupply = await raacMinterContract.raacToken().totalSupply();
|
|
114
|
+
|
|
115
|
+
// if (totalSupply.gt(0)) {
|
|
116
|
+
// const apy = emissionRatePerYear * 10000 / totalSupply;
|
|
117
|
+
// result.apy = apy / 100; // Convert to percentage
|
|
118
|
+
// } else {
|
|
119
|
+
// result.apy = 0;
|
|
120
|
+
// }
|
|
121
|
+
// Constants
|
|
122
|
+
// result.PRECISION = await raacMinterContract.PRECISION();
|
|
123
|
+
// result.BLOCKS_PER_YEAR = await raacMinterContract.BLOCKS_PER_YEAR();
|
|
124
|
+
// result.INITIAL_EMISSION_RATE = await raacMinterContract.INITIAL_EMISSION_RATE();
|
|
125
|
+
|
|
126
|
+
// const params = await raacMinterContract.getParameters();
|
|
127
|
+
// result.parameters = {
|
|
128
|
+
// minEmissionRate: params[0],
|
|
129
|
+
// maxEmissionRate: params[1],
|
|
130
|
+
// utilizationTarget: params[2],
|
|
131
|
+
// adjustmentSpeed: params[3],
|
|
132
|
+
// benchmarkRate: params[4],
|
|
133
|
+
// emissionRate: params[5],
|
|
134
|
+
// excessTokens: params[6]
|
|
135
|
+
// };
|
|
136
|
+
|
|
137
|
+
// const tick = await raacMinterContract.tick();
|
|
138
|
+
// address, {
|
|
139
|
+
// maxFeePerGas,
|
|
140
|
+
// nonce: await signer.getNonce()
|
|
141
|
+
// });
|
|
142
|
+
|
|
143
|
+
// console.log(tick);
|
|
144
|
+
return result;
|
|
145
|
+
} catch (error: any) {
|
|
146
|
+
throw new Error(`Error calculating RAAC rewards: ${error.message}`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export default get;
|
package/minter/getApy.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ethers, Provider, Signer } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../utils/contracts";
|
|
3
|
+
import { getABI } from "../utils/artifacts";
|
|
4
|
+
import { ChainId } from "../configs/chains/index";
|
|
5
|
+
import { RAACMinter } from "../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function getApy(chainId: ChainId, provider: Provider) {
|
|
8
|
+
if (!provider) {
|
|
9
|
+
throw new Error("Wallet not connected");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const raacMinterAddress = getContractAddress(chainId, "raacminter");
|
|
14
|
+
const raacMinterABI = getABI("raacminter");
|
|
15
|
+
const raacMinterContract = new ethers.Contract(
|
|
16
|
+
raacMinterAddress,
|
|
17
|
+
raacMinterABI,
|
|
18
|
+
provider
|
|
19
|
+
) as any as RAACMinter;
|
|
20
|
+
|
|
21
|
+
const result = { emissionRate: 0n, BLOCKS_PER_DAY: 0n };
|
|
22
|
+
result.emissionRate = await raacMinterContract.emissionRate();
|
|
23
|
+
result.BLOCKS_PER_DAY = await raacMinterContract.BLOCKS_PER_DAY();
|
|
24
|
+
|
|
25
|
+
// APY:
|
|
26
|
+
const blocksPerYear = result.BLOCKS_PER_DAY * 365n;
|
|
27
|
+
const emissionRatePerYear = result.emissionRate * blocksPerYear;
|
|
28
|
+
const totalSupply = await raacMinterContract.getTotalSupply();
|
|
29
|
+
|
|
30
|
+
const apy = (emissionRatePerYear * 10000n) / totalSupply;
|
|
31
|
+
return apy;
|
|
32
|
+
} catch (error: any) {
|
|
33
|
+
throw new Error(`Error calculating RAAC rewards: ${error.message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default getApy;
|
package/minter/tick.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ethers, Signer } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../utils/contracts";
|
|
3
|
+
import { getABI } from "../utils/artifacts";
|
|
4
|
+
import estimateGasPrice from "../methods/commons/estimateGasPrice";
|
|
5
|
+
import { ChainId } from "../configs/chains/index";
|
|
6
|
+
import { RAACMinter } from "../typechain-types";
|
|
7
|
+
|
|
8
|
+
async function tick(chainId: ChainId, signer: Signer) {
|
|
9
|
+
if (!signer) {
|
|
10
|
+
throw new Error("Wallet not connected");
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
const raacMinterAddress = getContractAddress(chainId, "raacminter");
|
|
15
|
+
const raacMinterABI = getABI("raacminter");
|
|
16
|
+
|
|
17
|
+
const raacMinterContract = new ethers.Contract(
|
|
18
|
+
raacMinterAddress,
|
|
19
|
+
raacMinterABI,
|
|
20
|
+
signer
|
|
21
|
+
) as any as RAACMinter;
|
|
22
|
+
|
|
23
|
+
const { maxFeePerGas } = await estimateGasPrice(signer);
|
|
24
|
+
|
|
25
|
+
console.log({ maxFeePerGas });
|
|
26
|
+
const tick = await raacMinterContract.tick({
|
|
27
|
+
maxFeePerGas,
|
|
28
|
+
nonce: await signer.getNonce(),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
if (tick.wait) {
|
|
32
|
+
await tick.wait();
|
|
33
|
+
}
|
|
34
|
+
return tick;
|
|
35
|
+
} catch (error: any) {
|
|
36
|
+
throw new Error(`Error calculating RAAC rewards: ${error.message}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default tick;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { ethers, Signer } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../utils/contracts";
|
|
3
|
+
import { getABI } from "../utils/artifacts";
|
|
4
|
+
import { ChainId } from "../configs/chains/index";
|
|
5
|
+
import { RAACNFT } from "../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function addNewBatch(
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
batchSize: number,
|
|
10
|
+
signer: Signer
|
|
11
|
+
) {
|
|
12
|
+
if (!signer) {
|
|
13
|
+
throw new Error("Wallet not connected");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const raacNFTAddress = getContractAddress(chainId, "raacnft");
|
|
18
|
+
const raacNFTABI = getABI("raacnft");
|
|
19
|
+
|
|
20
|
+
const raacNFTContract = new ethers.Contract(
|
|
21
|
+
raacNFTAddress,
|
|
22
|
+
raacNFTABI,
|
|
23
|
+
signer
|
|
24
|
+
) as any as RAACNFT;
|
|
25
|
+
|
|
26
|
+
const tx = await raacNFTContract.addNewBatch(batchSize);
|
|
27
|
+
await tx.wait();
|
|
28
|
+
|
|
29
|
+
console.log(`Added new batch of size ${batchSize}`);
|
|
30
|
+
return tx;
|
|
31
|
+
} catch (error: any) {
|
|
32
|
+
console.error("Error adding new batch:", error);
|
|
33
|
+
throw new Error(`Failed to add new batch: ${error.message}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default addNewBatch;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ethers, Provider } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../utils/contracts";
|
|
3
|
+
import { getABI } from "../utils/artifacts";
|
|
4
|
+
import { ChainId } from "../configs/chains/index";
|
|
5
|
+
import { RAACNFT } from "../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function getCurrentBatchSize(chainId: ChainId, provider: Provider) {
|
|
8
|
+
try {
|
|
9
|
+
const raacNFTAddress = getContractAddress(chainId, "raacnft");
|
|
10
|
+
const raacNFTABI = getABI("raacnft");
|
|
11
|
+
|
|
12
|
+
const raacNFTContract = new ethers.Contract(
|
|
13
|
+
raacNFTAddress,
|
|
14
|
+
raacNFTABI,
|
|
15
|
+
provider
|
|
16
|
+
) as any as RAACNFT;
|
|
17
|
+
|
|
18
|
+
const batchSize = await raacNFTContract.currentBatchSize();
|
|
19
|
+
return batchSize.toString();
|
|
20
|
+
} catch (error: any) {
|
|
21
|
+
console.error("Error getting current batch size:", error);
|
|
22
|
+
throw new Error(`Failed to get current batch size: ${error.message}`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default getCurrentBatchSize;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ethers, Provider } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../utils/contracts";
|
|
3
|
+
import { getABI } from "../utils/artifacts";
|
|
4
|
+
import { ChainId } from "../configs/chains/index";
|
|
5
|
+
import { LendingPool } from "../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function getDepositedNFTs(
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
address: string,
|
|
10
|
+
provider: Provider
|
|
11
|
+
) {
|
|
12
|
+
try {
|
|
13
|
+
const lendingPoolAddress = getContractAddress(chainId, "lendingpool");
|
|
14
|
+
const lendingPoolABI = getABI("lendingpool");
|
|
15
|
+
|
|
16
|
+
const lendingPoolContract = new ethers.Contract(
|
|
17
|
+
lendingPoolAddress,
|
|
18
|
+
lendingPoolABI,
|
|
19
|
+
provider
|
|
20
|
+
) as any as LendingPool;
|
|
21
|
+
|
|
22
|
+
const nftTokenIds = await lendingPoolContract.getUserDepositedNFTs(address);
|
|
23
|
+
|
|
24
|
+
return { address, nftTokenIds };
|
|
25
|
+
} catch (error: any) {
|
|
26
|
+
console.error("Error getting deposited NFTs:", error);
|
|
27
|
+
throw new Error(`Failed to get deposited NFTs: ${error.message}`);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default getDepositedNFTs;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { ethers, Provider } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../utils/contracts";
|
|
3
|
+
import { getABI } from "../utils/artifacts";
|
|
4
|
+
import { ChainId } from "../configs/chains/index";
|
|
5
|
+
import { RAACNFT } from "../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function getHousePrice(
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
tokenId: number,
|
|
10
|
+
provider: Provider
|
|
11
|
+
) {
|
|
12
|
+
try {
|
|
13
|
+
const raacNFTAddress = getContractAddress(chainId, "raacnft");
|
|
14
|
+
const raacNFTABI = getABI("raacnft");
|
|
15
|
+
|
|
16
|
+
const raacNFTContract = new ethers.Contract(
|
|
17
|
+
raacNFTAddress,
|
|
18
|
+
raacNFTABI,
|
|
19
|
+
provider
|
|
20
|
+
) as any as RAACNFT;
|
|
21
|
+
|
|
22
|
+
const price = await raacNFTContract.getHousePrice(tokenId);
|
|
23
|
+
return ethers.formatEther(price);
|
|
24
|
+
} catch (error: any) {
|
|
25
|
+
console.error("Error getting house price:", error);
|
|
26
|
+
throw new Error(`Failed to get house price: ${error.message}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default getHousePrice;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ethers, Provider } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../utils/contracts";
|
|
3
|
+
import { getABI } from "../utils/artifacts";
|
|
4
|
+
import { ChainId } from "../configs/chains/index";
|
|
5
|
+
import { RAACNFT } from "../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function getOwnedNFTs(
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
address: string,
|
|
10
|
+
provider: Provider
|
|
11
|
+
) {
|
|
12
|
+
try {
|
|
13
|
+
const raacNFTAddress = getContractAddress(chainId, "raacnft");
|
|
14
|
+
const raacNFTABI = getABI("raacnft");
|
|
15
|
+
|
|
16
|
+
const raacNFTContract = new ethers.Contract(
|
|
17
|
+
raacNFTAddress,
|
|
18
|
+
raacNFTABI,
|
|
19
|
+
provider
|
|
20
|
+
) as any as RAACNFT;
|
|
21
|
+
|
|
22
|
+
const ownedTokens = [];
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const balance = await raacNFTContract.balanceOf(address);
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < balance; i++) {
|
|
28
|
+
try {
|
|
29
|
+
const tokenId = await raacNFTContract.tokenOfOwnerByIndex(address, i);
|
|
30
|
+
ownedTokens.push(tokenId.toString());
|
|
31
|
+
} catch (error: any) {
|
|
32
|
+
console.error("Error getting owned NFTs:", error);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
} catch (error: any) {
|
|
36
|
+
console.error("Error getting owned NFTs:", error);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return { address, ownedTokens };
|
|
40
|
+
} catch (error: any) {
|
|
41
|
+
console.error("Error getting owned NFTs:", error);
|
|
42
|
+
throw new Error(`Failed to get owned NFTs: ${error.message}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default getOwnedNFTs;
|
package/nfts/mint.ts
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ethers, Signer } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../utils/contracts";
|
|
3
|
+
import { getABI } from "../utils/artifacts";
|
|
4
|
+
import { ChainId } from "../configs/chains/index";
|
|
5
|
+
import { RAACNFT } from "../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function mint(
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
tokenId: string,
|
|
10
|
+
amount: bigint,
|
|
11
|
+
signer: Signer
|
|
12
|
+
) {
|
|
13
|
+
if (!signer) {
|
|
14
|
+
throw new Error("Wallet not connected");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const raacNFTAddress = getContractAddress(chainId, "raacnft");
|
|
19
|
+
const raacNFTABI = getABI("raacnft");
|
|
20
|
+
|
|
21
|
+
const raacNFTContract = new ethers.Contract(
|
|
22
|
+
raacNFTAddress,
|
|
23
|
+
raacNFTABI,
|
|
24
|
+
signer
|
|
25
|
+
) as any as RAACNFT;
|
|
26
|
+
|
|
27
|
+
const tx = await raacNFTContract.mint(
|
|
28
|
+
tokenId,
|
|
29
|
+
ethers.parseEther(amount.toString())
|
|
30
|
+
);
|
|
31
|
+
await tx.wait();
|
|
32
|
+
|
|
33
|
+
console.log(
|
|
34
|
+
`Minted RAAC NFT with token ID ${tokenId} for ${amount} tokens`
|
|
35
|
+
);
|
|
36
|
+
return tx;
|
|
37
|
+
} catch (error: any) {
|
|
38
|
+
console.error("Error minting RAAC NFT:", error);
|
|
39
|
+
throw new Error(`Failed to mint RAAC NFT: ${error.message}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export default mint;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ethers, Signer } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../utils/contracts";
|
|
3
|
+
import { getABI } from "../utils/artifacts";
|
|
4
|
+
import { ChainId } from "../configs/chains/index";
|
|
5
|
+
import { RAACNFT } from "../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function setBaseUri(chainId: ChainId, newUri: string, signer: Signer) {
|
|
8
|
+
if (!signer) {
|
|
9
|
+
throw new Error("Wallet not connected");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const raacNFTAddress = getContractAddress(chainId, "raacnft");
|
|
14
|
+
const raacNFTABI = getABI("raacnft");
|
|
15
|
+
|
|
16
|
+
const raacNFTContract = new ethers.Contract(
|
|
17
|
+
raacNFTAddress,
|
|
18
|
+
raacNFTABI,
|
|
19
|
+
signer
|
|
20
|
+
) as any as RAACNFT;
|
|
21
|
+
|
|
22
|
+
const tx = await raacNFTContract.setBaseUri(newUri);
|
|
23
|
+
await tx.wait();
|
|
24
|
+
|
|
25
|
+
console.log(`Set new base URI: ${newUri}`);
|
|
26
|
+
return tx;
|
|
27
|
+
} catch (error: any) {
|
|
28
|
+
console.error("Error setting base URI:", error);
|
|
29
|
+
throw new Error(`Failed to set base URI: ${error.message}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default setBaseUri;
|