@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,91 @@
|
|
|
1
|
+
import { ChainId } from "./chains";
|
|
2
|
+
|
|
3
|
+
function createConfig(chainId: ChainId) {
|
|
4
|
+
return {
|
|
5
|
+
chainId: chainId,
|
|
6
|
+
name: "Local",
|
|
7
|
+
rpcs: ["http://54.159.212.213:8545"],
|
|
8
|
+
contracts: {
|
|
9
|
+
raachouseprices: {
|
|
10
|
+
id: "raachouseprices",
|
|
11
|
+
name: "RAAC House Prices",
|
|
12
|
+
contract: "",
|
|
13
|
+
},
|
|
14
|
+
raacminter: {
|
|
15
|
+
id: "raacminter",
|
|
16
|
+
name: "RAAC Minter",
|
|
17
|
+
contract: "",
|
|
18
|
+
},
|
|
19
|
+
|
|
20
|
+
auctionfactory: {
|
|
21
|
+
id: "auctionfactory",
|
|
22
|
+
name: "Auction Factory",
|
|
23
|
+
contract: "",
|
|
24
|
+
},
|
|
25
|
+
zenofactory: {
|
|
26
|
+
id: "zenofactory",
|
|
27
|
+
name: "Zeno Factory",
|
|
28
|
+
contract: "",
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
pools: {
|
|
32
|
+
stabilitypool: {
|
|
33
|
+
id: "stabilitypool",
|
|
34
|
+
name: "Stability Pool",
|
|
35
|
+
contract: "",
|
|
36
|
+
},
|
|
37
|
+
lendingpool: {
|
|
38
|
+
id: "lendingpool",
|
|
39
|
+
name: "Lending Pool",
|
|
40
|
+
contract: "",
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
nfts: {
|
|
44
|
+
raacnft: {
|
|
45
|
+
id: "raacnft",
|
|
46
|
+
name: "RAAC NFT",
|
|
47
|
+
contract: "",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
assets: {
|
|
51
|
+
eth: {
|
|
52
|
+
id: "eth",
|
|
53
|
+
name: "ETH",
|
|
54
|
+
decimals: 18,
|
|
55
|
+
contract: "0x0000000000000000000000000000000000000000",
|
|
56
|
+
},
|
|
57
|
+
crvusd: {
|
|
58
|
+
id: "crvusd",
|
|
59
|
+
name: "CRVUSD",
|
|
60
|
+
decimals: 18,
|
|
61
|
+
contract: "",
|
|
62
|
+
},
|
|
63
|
+
rtoken: {
|
|
64
|
+
id: "rtoken",
|
|
65
|
+
name: "RToken",
|
|
66
|
+
decimals: 18,
|
|
67
|
+
contract: "",
|
|
68
|
+
},
|
|
69
|
+
detoken: {
|
|
70
|
+
id: "detoken",
|
|
71
|
+
name: "DEtoken",
|
|
72
|
+
decimals: 18,
|
|
73
|
+
contract: "",
|
|
74
|
+
},
|
|
75
|
+
raactoken: {
|
|
76
|
+
id: "raactoken",
|
|
77
|
+
name: "RAAC",
|
|
78
|
+
decimals: 18,
|
|
79
|
+
contract: "",
|
|
80
|
+
},
|
|
81
|
+
veraac: {
|
|
82
|
+
id: "veraac",
|
|
83
|
+
name: "VERAAC",
|
|
84
|
+
decimals: 18,
|
|
85
|
+
contract: "",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default createConfig;
|
package/configs/index.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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 };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import configs from "../../configs/chains";
|
|
3
|
+
import { ERC20 } from "../../typechain-types";
|
|
4
|
+
|
|
5
|
+
const BALANCE_OF_ABI =
|
|
6
|
+
"function balanceOf(address account) view returns (uint256)";
|
|
7
|
+
|
|
8
|
+
export const getBalance = async (
|
|
9
|
+
chainId: keyof typeof configs,
|
|
10
|
+
contractAddress: string,
|
|
11
|
+
address: string
|
|
12
|
+
) => {
|
|
13
|
+
const rpc = configs[chainId].rpcs[0] as string;
|
|
14
|
+
const provider = new ethers.JsonRpcProvider(rpc);
|
|
15
|
+
|
|
16
|
+
const contract = new ethers.Contract(
|
|
17
|
+
contractAddress,
|
|
18
|
+
[BALANCE_OF_ABI],
|
|
19
|
+
provider
|
|
20
|
+
) as any as ERC20;
|
|
21
|
+
const balance = await contract.balanceOf(address);
|
|
22
|
+
return ethers.formatEther(balance);
|
|
23
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ethers, Provider } from "ethers";
|
|
2
|
+
import configs, { ConfigKeys } from "../../configs/chains";
|
|
3
|
+
import { ERC20 } from "../../typechain-types";
|
|
4
|
+
|
|
5
|
+
const TOTAL_SUPPLY_ABI = "function totalSupply() view returns (uint256)";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {string} contractAddress
|
|
10
|
+
* @param {number} chainId
|
|
11
|
+
* @param {ethers.JsonRpcProvider} [provider]
|
|
12
|
+
* @returns {Promise<string>}
|
|
13
|
+
*/
|
|
14
|
+
export const getTotalSupply = async (
|
|
15
|
+
chainId: ConfigKeys,
|
|
16
|
+
contractAddress: string,
|
|
17
|
+
provider: Provider
|
|
18
|
+
) => {
|
|
19
|
+
console.log("Getting total supply for", contractAddress, "on chain", chainId);
|
|
20
|
+
if (!provider) {
|
|
21
|
+
console.log("Chain ID", chainId);
|
|
22
|
+
if (!chainId) {
|
|
23
|
+
throw new Error("Contract address not found in any chain configuration");
|
|
24
|
+
}
|
|
25
|
+
const rpc = configs[chainId].rpcs[0];
|
|
26
|
+
provider = new ethers.JsonRpcProvider(rpc);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const contract = new ethers.Contract(
|
|
30
|
+
contractAddress,
|
|
31
|
+
[TOTAL_SUPPLY_ABI],
|
|
32
|
+
provider
|
|
33
|
+
) as any as ERC20;
|
|
34
|
+
const totalSupply = await contract.totalSupply();
|
|
35
|
+
return ethers.formatEther(totalSupply);
|
|
36
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ethers, Signer } from "ethers";
|
|
2
|
+
import getContractAddress from "./getContractAddress";
|
|
3
|
+
import { ChainId } from "../configs/chains/index";
|
|
4
|
+
import { ContractType } from "../utils/artifacts";
|
|
5
|
+
|
|
6
|
+
export default async function getContract(
|
|
7
|
+
chainId: ChainId,
|
|
8
|
+
contractName: ContractType,
|
|
9
|
+
signer: Signer
|
|
10
|
+
) {
|
|
11
|
+
if (!signer) {
|
|
12
|
+
throw new Error("Signer is required");
|
|
13
|
+
}
|
|
14
|
+
const contractAddress = getContractAddress(chainId, contractName);
|
|
15
|
+
|
|
16
|
+
// You'll need to import the ABI for the contract. This is just a placeholder.
|
|
17
|
+
const abi: any[] = []; // Replace with actual ABI
|
|
18
|
+
|
|
19
|
+
const contract = new ethers.Contract(contractAddress, abi, signer);
|
|
20
|
+
return contract;
|
|
21
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Chain } from "../configs/chains/chain";
|
|
2
|
+
import configs, { ChainId } from "../configs/chains";
|
|
3
|
+
import { ContractType } from "../utils/artifacts";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Get the contract address for a given asset on a specific chain
|
|
7
|
+
* @param {number} chainId
|
|
8
|
+
* @param {string} contractName
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export const getContractAddress = (
|
|
12
|
+
chainId: ChainId,
|
|
13
|
+
contractName: ContractType
|
|
14
|
+
) => {
|
|
15
|
+
const normalizedContractName = contractName.toLowerCase();
|
|
16
|
+
|
|
17
|
+
if (!chainId) {
|
|
18
|
+
throw new Error("Chain ID is required");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const config = configs[chainId];
|
|
22
|
+
|
|
23
|
+
if (!config) {
|
|
24
|
+
throw new Error(`Chain configuration not found for chainId: ${chainId}`);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const lookupKeys = [
|
|
28
|
+
"contracts",
|
|
29
|
+
"assets",
|
|
30
|
+
"pools",
|
|
31
|
+
"nfts",
|
|
32
|
+
] as (keyof Chain)[];
|
|
33
|
+
|
|
34
|
+
let address = null;
|
|
35
|
+
for (const key of lookupKeys) {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
if (config[key] && config[key][normalizedContractName]) {
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
address =
|
|
40
|
+
// @ts-ignore
|
|
41
|
+
config[key][normalizedContractName].contract ||
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
config[key][normalizedContractName];
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!address) {
|
|
49
|
+
console.error(
|
|
50
|
+
`Contract address not found for ${normalizedContractName} on chain ${chainId}`
|
|
51
|
+
);
|
|
52
|
+
console.error("Available contracts:", Object.keys(config.contracts));
|
|
53
|
+
throw new Error(
|
|
54
|
+
`Contract ${normalizedContractName} not found for chain ID: ${chainId}`
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return address;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export default getContractAddress;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { RAACHousePrices } from "../../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function getLatestPrice(
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
tokenId: string,
|
|
10
|
+
provider: Provider
|
|
11
|
+
) {
|
|
12
|
+
try {
|
|
13
|
+
const raacHousePricesAddress = getContractAddress(
|
|
14
|
+
chainId,
|
|
15
|
+
"raachouseprices"
|
|
16
|
+
);
|
|
17
|
+
const raacHousePricesABI = getABI("raachouseprices");
|
|
18
|
+
|
|
19
|
+
const raacHousePricesContract = new ethers.Contract(
|
|
20
|
+
raacHousePricesAddress,
|
|
21
|
+
raacHousePricesABI,
|
|
22
|
+
provider
|
|
23
|
+
) as any as RAACHousePrices;
|
|
24
|
+
|
|
25
|
+
const [price, timestamp] = await raacHousePricesContract.getLatestPrice(
|
|
26
|
+
tokenId
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return { price, timestamp };
|
|
30
|
+
} catch (error: any) {
|
|
31
|
+
console.error("Error getting latest price:", error);
|
|
32
|
+
return { price: -1, timestamp: -1 };
|
|
33
|
+
// console.error('Error getting latest price:', error);
|
|
34
|
+
// throw new Error(`Failed to get latest price: ${error.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default getLatestPrice;
|
|
@@ -0,0 +1,40 @@
|
|
|
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 { RAACHousePrices } from "../../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function setOracle(
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
newOracleAddress: string,
|
|
10
|
+
signer: Signer
|
|
11
|
+
) {
|
|
12
|
+
if (!signer) {
|
|
13
|
+
throw new Error("Wallet not connected");
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
try {
|
|
17
|
+
const raacHousePricesAddress = getContractAddress(
|
|
18
|
+
chainId,
|
|
19
|
+
"raachouseprices"
|
|
20
|
+
);
|
|
21
|
+
const raacHousePricesABI = getABI("raachouseprices");
|
|
22
|
+
|
|
23
|
+
const raacHousePricesContract = new ethers.Contract(
|
|
24
|
+
raacHousePricesAddress,
|
|
25
|
+
raacHousePricesABI,
|
|
26
|
+
signer
|
|
27
|
+
) as any as RAACHousePrices;
|
|
28
|
+
|
|
29
|
+
const tx = await raacHousePricesContract.setOracle(newOracleAddress);
|
|
30
|
+
await tx.wait();
|
|
31
|
+
|
|
32
|
+
console.log(`Oracle address updated to: ${newOracleAddress}`);
|
|
33
|
+
return tx;
|
|
34
|
+
} catch (error: any) {
|
|
35
|
+
console.error("Error setting oracle:", error);
|
|
36
|
+
throw new Error(`Failed to set oracle: ${error.message}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default setOracle;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { ChainId, configs } from "../../configs/chains";
|
|
3
|
+
import { ERC20 } from "../../typechain-types";
|
|
4
|
+
|
|
5
|
+
const BALANCE_OF_ABI =
|
|
6
|
+
"function balanceOf(address account) view returns (uint256)";
|
|
7
|
+
|
|
8
|
+
export const getBalance = async (
|
|
9
|
+
chainId: ChainId,
|
|
10
|
+
contractAddress: string,
|
|
11
|
+
address: string
|
|
12
|
+
) => {
|
|
13
|
+
const rpc = configs[chainId].rpcs[0];
|
|
14
|
+
const provider = new ethers.JsonRpcProvider(rpc);
|
|
15
|
+
|
|
16
|
+
const contract = new ethers.Contract(
|
|
17
|
+
contractAddress,
|
|
18
|
+
[BALANCE_OF_ABI],
|
|
19
|
+
provider
|
|
20
|
+
) as any as ERC20;
|
|
21
|
+
const balance = await contract.balanceOf(address);
|
|
22
|
+
return ethers.formatEther(balance);
|
|
23
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ethers, Provider } from "ethers";
|
|
2
|
+
import configs, { ChainId } from "../../configs/chains";
|
|
3
|
+
import { ERC20 } from "../../typechain-types";
|
|
4
|
+
|
|
5
|
+
const TOTAL_SUPPLY_ABI = "function totalSupply() view returns (uint256)";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {string} contractAddress
|
|
10
|
+
* @param {number} chainId
|
|
11
|
+
* @param {ethers.JsonRpcProvider} [provider]
|
|
12
|
+
* @returns {Promise<string>}
|
|
13
|
+
*/
|
|
14
|
+
export const getTotalSupply = async (
|
|
15
|
+
chainId: ChainId,
|
|
16
|
+
contractAddress: string,
|
|
17
|
+
provider: Provider
|
|
18
|
+
) => {
|
|
19
|
+
if (!provider) {
|
|
20
|
+
if (!chainId) {
|
|
21
|
+
throw new Error("Contract address not found in any chain configuration");
|
|
22
|
+
}
|
|
23
|
+
const rpc = configs[chainId].rpcs[0];
|
|
24
|
+
provider = new ethers.JsonRpcProvider(rpc);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log(
|
|
28
|
+
`Getting total supply for ${contractAddress} on ${
|
|
29
|
+
(await provider.getNetwork()).chainId
|
|
30
|
+
} using provider ${provider}`
|
|
31
|
+
);
|
|
32
|
+
const contract = new ethers.Contract(
|
|
33
|
+
contractAddress,
|
|
34
|
+
[TOTAL_SUPPLY_ABI],
|
|
35
|
+
provider
|
|
36
|
+
) as any as ERC20;
|
|
37
|
+
const totalSupply = await contract.totalSupply();
|
|
38
|
+
return ethers.formatEther(totalSupply);
|
|
39
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
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 { AuctionFactory } from "../../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function createAuction(
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
zenoAddress: string,
|
|
10
|
+
usdcAddress: string,
|
|
11
|
+
businessAddress: string,
|
|
12
|
+
auctionStartTime: bigint,
|
|
13
|
+
auctionEndTime: bigint,
|
|
14
|
+
startingPrice: bigint,
|
|
15
|
+
reservePrice: bigint,
|
|
16
|
+
totalZenoAllocated: bigint,
|
|
17
|
+
signer: Signer
|
|
18
|
+
) {
|
|
19
|
+
if (!signer) {
|
|
20
|
+
throw new Error("Wallet not connected");
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const auctionFactoryAddress = getContractAddress(chainId, "auctionfactory");
|
|
25
|
+
const auctionFactoryABI = getABI("auctionfactory");
|
|
26
|
+
|
|
27
|
+
const auctionFactoryContract = new ethers.Contract(
|
|
28
|
+
auctionFactoryAddress,
|
|
29
|
+
auctionFactoryABI,
|
|
30
|
+
signer
|
|
31
|
+
) as any as AuctionFactory;
|
|
32
|
+
|
|
33
|
+
const tx = await auctionFactoryContract.createAuction(
|
|
34
|
+
zenoAddress,
|
|
35
|
+
usdcAddress,
|
|
36
|
+
businessAddress,
|
|
37
|
+
auctionStartTime,
|
|
38
|
+
auctionEndTime,
|
|
39
|
+
startingPrice,
|
|
40
|
+
reservePrice,
|
|
41
|
+
totalZenoAllocated
|
|
42
|
+
);
|
|
43
|
+
await tx.wait();
|
|
44
|
+
|
|
45
|
+
const auctionsCount = await auctionFactoryContract.getAuctionCount();
|
|
46
|
+
const auctionAddress = await auctionFactoryContract.getAuction(
|
|
47
|
+
auctionsCount - 1n
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
console.log(`Zeno auction created at address: ${auctionAddress}`);
|
|
51
|
+
} catch (error: any) {
|
|
52
|
+
console.error("Error creating zeno auction:", error);
|
|
53
|
+
throw new Error(`Failed to create zeno auction: ${error.message}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export default createAuction;
|
|
@@ -0,0 +1,45 @@
|
|
|
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 { ZENOFactory } from "../../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function createZeno(
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
usdcAddress: string,
|
|
10
|
+
maturityDate: string,
|
|
11
|
+
signer: Signer
|
|
12
|
+
) {
|
|
13
|
+
if (!signer) {
|
|
14
|
+
throw new Error("Wallet not connected");
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const zenoFactoryAddress = getContractAddress(chainId, "zenofactory");
|
|
19
|
+
const zenoFactoryABI = getABI("zenofactory");
|
|
20
|
+
|
|
21
|
+
const zenoFactoryContract = new ethers.Contract(
|
|
22
|
+
zenoFactoryAddress,
|
|
23
|
+
zenoFactoryABI,
|
|
24
|
+
signer
|
|
25
|
+
) as any as ZENOFactory;
|
|
26
|
+
|
|
27
|
+
const tx = await zenoFactoryContract.createZENOContract(
|
|
28
|
+
usdcAddress,
|
|
29
|
+
maturityDate
|
|
30
|
+
);
|
|
31
|
+
await tx.wait();
|
|
32
|
+
|
|
33
|
+
const zenosCount = await zenoFactoryContract.getZENOCount();
|
|
34
|
+
const zenoAddress = await zenoFactoryContract.getZENO(zenosCount - 1n);
|
|
35
|
+
|
|
36
|
+
console.log(`Zeno created at address: ${zenoAddress}`);
|
|
37
|
+
|
|
38
|
+
return zenoAddress;
|
|
39
|
+
} catch (error: any) {
|
|
40
|
+
console.error("Error creating zeno:", error);
|
|
41
|
+
throw new Error(`Failed to create zeno: ${error.message}`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export default createZeno;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { AuctionFactory } from "../../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function getAuctions(chainId: ChainId, signer: Signer) {
|
|
8
|
+
if (!signer) {
|
|
9
|
+
throw new Error("Wallet not connected");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const auctionFactoryAddress = getContractAddress(chainId, "auctionfactory");
|
|
14
|
+
const auctionFactoryABI = getABI("auctionfactory");
|
|
15
|
+
|
|
16
|
+
const auctionFactoryContract = new ethers.Contract(
|
|
17
|
+
auctionFactoryAddress,
|
|
18
|
+
auctionFactoryABI,
|
|
19
|
+
signer
|
|
20
|
+
) as any as AuctionFactory;
|
|
21
|
+
|
|
22
|
+
const auctionsCount = await auctionFactoryContract.getAuctionCount();
|
|
23
|
+
const auctions = [];
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < auctionsCount; i++) {
|
|
26
|
+
const auction = await auctionFactoryContract.getAuctionDetails(i);
|
|
27
|
+
auctions.push(auction);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log(`Auctions: ${auctions}`);
|
|
31
|
+
return auctions;
|
|
32
|
+
} catch (error: any) {
|
|
33
|
+
console.error("Error getting auctions:", error);
|
|
34
|
+
throw new Error(`Failed to get auctions: ${error.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default getAuctions;
|
|
@@ -0,0 +1,38 @@
|
|
|
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 { ZENO, ZENOFactory } from "../../typechain-types";
|
|
6
|
+
|
|
7
|
+
async function getZenos(chainId: ChainId, signer: Signer) {
|
|
8
|
+
if (!signer) {
|
|
9
|
+
throw new Error("Wallet not connected");
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
const zenoFactoryAddress = getContractAddress(chainId, "zenofactory");
|
|
14
|
+
const zenoFactoryABI = getABI("zenofactory");
|
|
15
|
+
|
|
16
|
+
const zenoFactoryContract = new ethers.Contract(
|
|
17
|
+
zenoFactoryAddress,
|
|
18
|
+
zenoFactoryABI,
|
|
19
|
+
signer
|
|
20
|
+
) as any as ZENOFactory;
|
|
21
|
+
|
|
22
|
+
const zenosCount = await zenoFactoryContract.getZENOCount();
|
|
23
|
+
const zenos = [];
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < zenosCount; i++) {
|
|
26
|
+
const zeno = await zenoFactoryContract.getZENODetails(i);
|
|
27
|
+
zenos.push(zeno);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
console.log(`Zenos: ${zenos}`);
|
|
31
|
+
return zenos;
|
|
32
|
+
} catch (error: any) {
|
|
33
|
+
console.error("Error getting zenos:", error);
|
|
34
|
+
throw new Error(`Failed to get zenos: ${error.message}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default getZenos;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type Reserve = {
|
|
2
|
+
reserveRTokenAddress: string;
|
|
3
|
+
reserveAssetAddress: string;
|
|
4
|
+
reserveDebtTokenAddress: string;
|
|
5
|
+
totalLiquidity: bigint;
|
|
6
|
+
totalUsage: bigint;
|
|
7
|
+
liquidityIndex: bigint;
|
|
8
|
+
usageIndex: bigint;
|
|
9
|
+
lastUpdateTimestamp: bigint;
|
|
10
|
+
};
|
|
11
|
+
export type RawData = {
|
|
12
|
+
currentLiquidityRate: bigint;
|
|
13
|
+
currentUsageRate: bigint;
|
|
14
|
+
primeRate: bigint;
|
|
15
|
+
baseRate: bigint;
|
|
16
|
+
optimalRate: bigint;
|
|
17
|
+
maxRate: bigint;
|
|
18
|
+
optimalUtilizationRate: bigint;
|
|
19
|
+
protocolFeeRate: bigint;
|
|
20
|
+
};
|
package/index.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ethers, Signer } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../contracts/getContractAddress";
|
|
3
|
+
import estimateGasPrice from "./commons/estimateGasPrice";
|
|
4
|
+
import { ChainId } from "../configs/chains/index";
|
|
5
|
+
import { ContractType } from "../utils/artifacts";
|
|
6
|
+
import { ERC20 } from "../typechain-types";
|
|
7
|
+
|
|
8
|
+
const approveToken = async (
|
|
9
|
+
chainId: ChainId,
|
|
10
|
+
tokenSymbol: ContractType,
|
|
11
|
+
spender: string,
|
|
12
|
+
amount: string,
|
|
13
|
+
signer: Signer
|
|
14
|
+
) => {
|
|
15
|
+
if (!signer) {
|
|
16
|
+
throw new Error("Wallet not connected");
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const tokenAddress = getContractAddress(chainId, tokenSymbol) as any as ERC20;
|
|
20
|
+
const tokenABI = [
|
|
21
|
+
"function approve(address spender, uint256 amount) public returns (bool)",
|
|
22
|
+
];
|
|
23
|
+
const tokenContract = new ethers.Contract(tokenAddress, tokenABI, signer);
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
const amountInWei = ethers.parseEther(amount);
|
|
27
|
+
const { maxFeePerGas } = await estimateGasPrice(signer);
|
|
28
|
+
|
|
29
|
+
const tx = await tokenContract.approve(spender, amountInWei, {
|
|
30
|
+
maxFeePerGas,
|
|
31
|
+
// maxPriorityFeePerGas
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log(`Approval transaction sent:`, tx.hash);
|
|
35
|
+
const receipt = await tx.wait();
|
|
36
|
+
console.log(
|
|
37
|
+
`Approved ${amount} ${tokenSymbol} for ${spender} successfully:`,
|
|
38
|
+
receipt.transactionHash
|
|
39
|
+
);
|
|
40
|
+
return receipt;
|
|
41
|
+
} catch (error: any) {
|
|
42
|
+
console.error(`Approval error:`, error);
|
|
43
|
+
throw new Error(`Token approval failed: ${error.message}`);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export default approveToken;
|