@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
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# rpc
|
package/RPCLibrary.ts
ADDED
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AddressLike,
|
|
3
|
+
Eip1193Provider,
|
|
4
|
+
ethers,
|
|
5
|
+
JsonRpcSigner,
|
|
6
|
+
Provider,
|
|
7
|
+
Signer,
|
|
8
|
+
Wallet,
|
|
9
|
+
} from "ethers";
|
|
10
|
+
// import { getContractAddress,getConfig } from './utils/contracts.js';
|
|
11
|
+
// Commons
|
|
12
|
+
import checkAllowance from "./methods/commons/checkAllowance";
|
|
13
|
+
import estimateGasPrice from "./methods/commons/estimateGasPrice";
|
|
14
|
+
|
|
15
|
+
import {
|
|
16
|
+
getChainsConfig,
|
|
17
|
+
getChainConfig,
|
|
18
|
+
setChainConfig,
|
|
19
|
+
} from "./configs/index";
|
|
20
|
+
|
|
21
|
+
// Assets
|
|
22
|
+
import getAsset from "./assets/getAsset";
|
|
23
|
+
import getSupply from "./assets/getSupply";
|
|
24
|
+
import getAssets from "./assets/getAssets";
|
|
25
|
+
// Pools
|
|
26
|
+
// Pools#StabilityPool
|
|
27
|
+
import getStabilityPoolInfo from "./pools/stabilityPool/getStabilityPoolInfo";
|
|
28
|
+
import depositToStabilityPool from "./pools/stabilityPool/depositToStabilityPool";
|
|
29
|
+
import withdrawFromStabilityPool from "./pools/stabilityPool/withdrawFromStabilityPool";
|
|
30
|
+
import calculateRAACRewards from "./pools/stabilityPool/calculateRAACRewards";
|
|
31
|
+
import getStabilityPoolTotalDeposits from "./pools/stabilityPool/getStabilityPoolTotalDeposits";
|
|
32
|
+
|
|
33
|
+
// Pools#LendingPool
|
|
34
|
+
import getLendingPoolInfo from "./pools/lendingPool/getLendingPoolInfo";
|
|
35
|
+
import depositToLendingPool from "./pools/lendingPool/depositToLendingPool";
|
|
36
|
+
import withdrawFromLendingPool from "./pools/lendingPool/withdrawFromLendingPool";
|
|
37
|
+
import getLendingPoolTotalLiquidity from "./pools/lendingPool/getLendingPoolTotalLiquidity";
|
|
38
|
+
import borrowFromLendingPool from "./pools/lendingPool/borrowFromLendingPool";
|
|
39
|
+
import repayToLendingPool from "./pools/lendingPool/repayToLendingPool";
|
|
40
|
+
|
|
41
|
+
// Pools#LiquidityPool
|
|
42
|
+
// import getLiquidityPoolInfo from "./pools/liquidityPool/getLiquidityPoolInfo";
|
|
43
|
+
|
|
44
|
+
import depositNFTToLendingPool from "./pools/lendingPool/depositNFTToLendingPool";
|
|
45
|
+
import withdrawNFTFromLendingPool from "./pools/lendingPool/withdrawNFTFromLendingPool";
|
|
46
|
+
|
|
47
|
+
import getHousePrice from "./pools/lendingPool/getHousePrice";
|
|
48
|
+
|
|
49
|
+
// NFTs
|
|
50
|
+
import mintNFT from "./nfts/mint";
|
|
51
|
+
import getNFTHousePrice from "./nfts/getHousePrice";
|
|
52
|
+
import addNewNFTBatch from "./nfts/addNewBatch";
|
|
53
|
+
import setNFTBaseUri from "./nfts/setBaseUri";
|
|
54
|
+
import getNFTCurrentBatchSize from "./nfts/getCurrentBatchSize";
|
|
55
|
+
import getOwnedNFTs from "./nfts/getOwnedNFTs";
|
|
56
|
+
// Contracts
|
|
57
|
+
import getContractAddress from "./contracts/getContractAddress";
|
|
58
|
+
import getContract from "./contracts/getContract";
|
|
59
|
+
// House Prices
|
|
60
|
+
import getLatestPrice from "./contracts/housePrices/getLatestPrice";
|
|
61
|
+
import setOracle from "./contracts/housePrices/setOracle";
|
|
62
|
+
|
|
63
|
+
// Minter
|
|
64
|
+
import tick from "./minter/tick";
|
|
65
|
+
import get from "./minter/get";
|
|
66
|
+
import getApy from "./minter/getApy";
|
|
67
|
+
|
|
68
|
+
// Wallet
|
|
69
|
+
// Wallet#Assets
|
|
70
|
+
import mintAsset from "./wallet/assets/mintAsset";
|
|
71
|
+
import burnAsset from "./wallet/assets/burnAsset";
|
|
72
|
+
import approveAsset from "./wallet/assets/approveAsset";
|
|
73
|
+
import getWalletAssets from "./wallet/assets/getAssets";
|
|
74
|
+
import getWalletAsset from "./wallet/assets/getAsset";
|
|
75
|
+
import getWalletAllowance from "./wallet/assets/getAllowance";
|
|
76
|
+
import getWalletBalance from "./wallet/assets/getBalance";
|
|
77
|
+
import transferAsset from "./wallet/assets/transferAsset";
|
|
78
|
+
|
|
79
|
+
// Zeno auctions
|
|
80
|
+
import getAuctions from "./contracts/zeno/getAuctions";
|
|
81
|
+
import createAuction from "./contracts/zeno/createAuction";
|
|
82
|
+
import createZeno from "./contracts/zeno/createZeno";
|
|
83
|
+
import getZenos from "./contracts/zeno/getZenos";
|
|
84
|
+
import { ChainId } from "./configs/chains";
|
|
85
|
+
import getDepositedNFTs from "./nfts/getDepositedNFTs";
|
|
86
|
+
|
|
87
|
+
class RPCLibrary {
|
|
88
|
+
signer: Signer | null;
|
|
89
|
+
isConnected: boolean;
|
|
90
|
+
address: JsonRpcSigner | string;
|
|
91
|
+
chainId: ChainId | bigint | null;
|
|
92
|
+
privateKey: any;
|
|
93
|
+
|
|
94
|
+
// valid
|
|
95
|
+
assets: {
|
|
96
|
+
getAsset: typeof getAsset;
|
|
97
|
+
getAssets: typeof getAssets;
|
|
98
|
+
getSupply: typeof getSupply;
|
|
99
|
+
};
|
|
100
|
+
// valid
|
|
101
|
+
wallet: {
|
|
102
|
+
assets: {
|
|
103
|
+
getBalance: typeof getWalletBalance;
|
|
104
|
+
getAllowance: typeof getWalletAllowance;
|
|
105
|
+
getAsset: typeof getWalletAsset;
|
|
106
|
+
getAssets: typeof getWalletAssets;
|
|
107
|
+
transferAsset: typeof transferAsset;
|
|
108
|
+
approveAsset: typeof approveAsset;
|
|
109
|
+
mintAsset: typeof mintAsset;
|
|
110
|
+
burnAsset: typeof burnAsset;
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
nfts: {
|
|
114
|
+
mint: typeof mintNFT;
|
|
115
|
+
getHousePrice: typeof getNFTHousePrice;
|
|
116
|
+
getOwnedNFTs: typeof getOwnedNFTs;
|
|
117
|
+
getDepositedNFTs: typeof getDepositedNFTs;
|
|
118
|
+
addNewBatch: typeof addNewNFTBatch;
|
|
119
|
+
setBaseUri: typeof setNFTBaseUri;
|
|
120
|
+
getCurrentBatchSize: typeof getNFTCurrentBatchSize;
|
|
121
|
+
};
|
|
122
|
+
contracts: {
|
|
123
|
+
housePrices: {
|
|
124
|
+
getLatestPrice: typeof getLatestPrice;
|
|
125
|
+
setOracle: typeof setOracle;
|
|
126
|
+
};
|
|
127
|
+
minter: { tick: typeof tick; get: typeof get; getApy: typeof getApy };
|
|
128
|
+
getContractAddress: typeof getContractAddress;
|
|
129
|
+
getContract: typeof getContract;
|
|
130
|
+
};
|
|
131
|
+
pools: {
|
|
132
|
+
stabilityPool: {
|
|
133
|
+
getStabilityPoolInfo: typeof getStabilityPoolInfo;
|
|
134
|
+
depositToStabilityPool: typeof depositToStabilityPool;
|
|
135
|
+
withdrawFromStabilityPool: typeof withdrawFromStabilityPool;
|
|
136
|
+
calculateRAACRewards: typeof calculateRAACRewards;
|
|
137
|
+
};
|
|
138
|
+
// LendingPool
|
|
139
|
+
lendingPool: {
|
|
140
|
+
repayToLendingPool: typeof repayToLendingPool;
|
|
141
|
+
borrowFromLendingPool: typeof borrowFromLendingPool;
|
|
142
|
+
getHousePrice: typeof getHousePrice;
|
|
143
|
+
depositNFTToLendingPool: typeof depositNFTToLendingPool;
|
|
144
|
+
withdrawNFTFromLendingPool: typeof withdrawNFTFromLendingPool;
|
|
145
|
+
getLendingPoolInfo: typeof getLendingPoolInfo;
|
|
146
|
+
};
|
|
147
|
+
depositToLendingPool: typeof depositToLendingPool;
|
|
148
|
+
withdrawFromLendingPool: typeof withdrawFromLendingPool;
|
|
149
|
+
getLendingPoolTotalLiquidity: typeof getLendingPoolTotalLiquidity;
|
|
150
|
+
calculateRAACRewards: typeof calculateRAACRewards;
|
|
151
|
+
repayToLendingPool: typeof repayToLendingPool;
|
|
152
|
+
borrowFromLendingPool: typeof borrowFromLendingPool;
|
|
153
|
+
getHousePrice: typeof getHousePrice;
|
|
154
|
+
// StabilityPool
|
|
155
|
+
getStabilityPoolTotalDeposits: typeof getStabilityPoolTotalDeposits;
|
|
156
|
+
getStabilityPoolInfo: typeof getStabilityPoolInfo;
|
|
157
|
+
depositToStabilityPool: typeof depositToStabilityPool;
|
|
158
|
+
withdrawFromStabilityPool: typeof withdrawFromStabilityPool;
|
|
159
|
+
};
|
|
160
|
+
zeno: {
|
|
161
|
+
createAuction: typeof createAuction;
|
|
162
|
+
getAuctions: typeof getAuctions;
|
|
163
|
+
createZeno: typeof createZeno;
|
|
164
|
+
getZenos: typeof getZenos;
|
|
165
|
+
};
|
|
166
|
+
provider: any;
|
|
167
|
+
|
|
168
|
+
estimateGasPrice: any;
|
|
169
|
+
checkAllowance!: typeof checkAllowance;
|
|
170
|
+
getChainsConfig!: typeof getChainsConfig;
|
|
171
|
+
setChainsConfig!: typeof setChainConfig;
|
|
172
|
+
|
|
173
|
+
constructor(privateKey?: string) {
|
|
174
|
+
this.signer = null;
|
|
175
|
+
this.isConnected = false;
|
|
176
|
+
this.address = "";
|
|
177
|
+
this.chainId = null;
|
|
178
|
+
|
|
179
|
+
this.privateKey = privateKey;
|
|
180
|
+
|
|
181
|
+
this.assets = {
|
|
182
|
+
getAsset,
|
|
183
|
+
getAssets,
|
|
184
|
+
getSupply,
|
|
185
|
+
};
|
|
186
|
+
this.wallet = {
|
|
187
|
+
assets: {
|
|
188
|
+
getBalance: getWalletBalance,
|
|
189
|
+
getAllowance: getWalletAllowance,
|
|
190
|
+
getAsset: getWalletAsset,
|
|
191
|
+
getAssets: getWalletAssets,
|
|
192
|
+
transferAsset,
|
|
193
|
+
approveAsset,
|
|
194
|
+
mintAsset,
|
|
195
|
+
burnAsset,
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
this.nfts = {
|
|
200
|
+
mint: mintNFT,
|
|
201
|
+
getHousePrice: getNFTHousePrice,
|
|
202
|
+
getOwnedNFTs,
|
|
203
|
+
getDepositedNFTs,
|
|
204
|
+
addNewBatch: addNewNFTBatch,
|
|
205
|
+
setBaseUri: setNFTBaseUri,
|
|
206
|
+
getCurrentBatchSize: getNFTCurrentBatchSize,
|
|
207
|
+
};
|
|
208
|
+
this.contracts = {
|
|
209
|
+
housePrices: {
|
|
210
|
+
getLatestPrice,
|
|
211
|
+
setOracle,
|
|
212
|
+
},
|
|
213
|
+
minter: {
|
|
214
|
+
tick,
|
|
215
|
+
get,
|
|
216
|
+
getApy,
|
|
217
|
+
},
|
|
218
|
+
getContractAddress,
|
|
219
|
+
getContract,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
this.pools = {
|
|
223
|
+
stabilityPool: {
|
|
224
|
+
getStabilityPoolInfo,
|
|
225
|
+
depositToStabilityPool,
|
|
226
|
+
withdrawFromStabilityPool,
|
|
227
|
+
calculateRAACRewards,
|
|
228
|
+
},
|
|
229
|
+
// LendingPool
|
|
230
|
+
lendingPool: {
|
|
231
|
+
repayToLendingPool,
|
|
232
|
+
borrowFromLendingPool,
|
|
233
|
+
getHousePrice,
|
|
234
|
+
depositNFTToLendingPool,
|
|
235
|
+
withdrawNFTFromLendingPool,
|
|
236
|
+
getLendingPoolInfo,
|
|
237
|
+
},
|
|
238
|
+
depositToLendingPool,
|
|
239
|
+
withdrawFromLendingPool,
|
|
240
|
+
getLendingPoolTotalLiquidity,
|
|
241
|
+
calculateRAACRewards,
|
|
242
|
+
repayToLendingPool,
|
|
243
|
+
borrowFromLendingPool,
|
|
244
|
+
getHousePrice,
|
|
245
|
+
// StabilityPool
|
|
246
|
+
getStabilityPoolTotalDeposits,
|
|
247
|
+
getStabilityPoolInfo,
|
|
248
|
+
depositToStabilityPool,
|
|
249
|
+
withdrawFromStabilityPool,
|
|
250
|
+
};
|
|
251
|
+
this.zeno = {
|
|
252
|
+
createAuction,
|
|
253
|
+
getAuctions,
|
|
254
|
+
createZeno,
|
|
255
|
+
getZenos,
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
async getWallet(privateKey: string, provider: Provider) {
|
|
260
|
+
if (typeof window !== "undefined" && window.ethereum) {
|
|
261
|
+
// Browser environment with MetaMask
|
|
262
|
+
await window.ethereum.request({ method: "eth_requestAccounts" });
|
|
263
|
+
const browserProvider = new ethers.BrowserProvider(window.ethereum);
|
|
264
|
+
const signer = await browserProvider.getSigner();
|
|
265
|
+
return signer;
|
|
266
|
+
} else {
|
|
267
|
+
const wallet = new ethers.Wallet(privateKey, provider);
|
|
268
|
+
return wallet;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
async getProvider(chainId: ChainId) {
|
|
273
|
+
if (
|
|
274
|
+
typeof globalThis !== "undefined" &&
|
|
275
|
+
globalThis.window &&
|
|
276
|
+
typeof globalThis.window.ethereum !== "undefined"
|
|
277
|
+
) {
|
|
278
|
+
const provider = new ethers.BrowserProvider(globalThis.window.ethereum);
|
|
279
|
+
return provider;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
const config = getChainConfig(chainId);
|
|
283
|
+
const rpcs = config.rpcs;
|
|
284
|
+
const provider = new ethers.JsonRpcProvider(rpcs[0]);
|
|
285
|
+
return provider;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
async getSigner(chainId: ChainId, address: string) {
|
|
289
|
+
const provider = await this.getProvider(chainId);
|
|
290
|
+
const signer = await provider.getSigner(address);
|
|
291
|
+
return signer;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async connectWallet() {
|
|
295
|
+
if (
|
|
296
|
+
typeof globalThis !== "undefined" &&
|
|
297
|
+
globalThis.window &&
|
|
298
|
+
typeof globalThis.window.ethereum !== "undefined"
|
|
299
|
+
) {
|
|
300
|
+
try {
|
|
301
|
+
await globalThis.window.ethereum.request({
|
|
302
|
+
method: "eth_requestAccounts",
|
|
303
|
+
});
|
|
304
|
+
const provider = new ethers.BrowserProvider(globalThis.window.ethereum);
|
|
305
|
+
const network = await provider.getNetwork();
|
|
306
|
+
this.chainId = network.chainId;
|
|
307
|
+
this.signer = await provider.getSigner();
|
|
308
|
+
this.address = await this.signer.getAddress();
|
|
309
|
+
this.isConnected = true;
|
|
310
|
+
} catch (error: any) {
|
|
311
|
+
console.error("Failed to connect wallet:", error);
|
|
312
|
+
throw new Error(`Failed to connect wallet: ${error.message}`);
|
|
313
|
+
}
|
|
314
|
+
} else if (this.provider) {
|
|
315
|
+
// For non-browser environments, use the provider passed to the constructor
|
|
316
|
+
try {
|
|
317
|
+
const network = await this.provider.getNetwork();
|
|
318
|
+
this.chainId = network.chainId;
|
|
319
|
+
this.signer = new ethers.Wallet(this.privateKey, this.provider);
|
|
320
|
+
this.address = await this.signer.getAddress();
|
|
321
|
+
this.isConnected = true;
|
|
322
|
+
} catch (error: any) {
|
|
323
|
+
console.error("Failed to connect wallet:", error);
|
|
324
|
+
throw new Error(`Failed to connect wallet: ${error.message}`);
|
|
325
|
+
}
|
|
326
|
+
} else {
|
|
327
|
+
throw new Error("No provider available");
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
async checkConnection() {
|
|
332
|
+
if (typeof window.ethereum !== "undefined") {
|
|
333
|
+
const provider = new ethers.BrowserProvider(window.ethereum);
|
|
334
|
+
const network = await provider.getNetwork();
|
|
335
|
+
this.chainId = network.chainId;
|
|
336
|
+
const accounts = await provider.listAccounts();
|
|
337
|
+
if (accounts.length > 0) {
|
|
338
|
+
this.signer = await provider.getSigner();
|
|
339
|
+
this.isConnected = true;
|
|
340
|
+
this.address = accounts[0];
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Mine a block
|
|
346
|
+
async mineBlock(wallet: Eip1193Provider) {
|
|
347
|
+
const provider = new ethers.BrowserProvider(wallet);
|
|
348
|
+
await provider.send("evm_mine", []);
|
|
349
|
+
// await provider.send('evm_mine', []);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
RPCLibrary.prototype.checkAllowance = checkAllowance;
|
|
354
|
+
RPCLibrary.prototype.estimateGasPrice = estimateGasPrice;
|
|
355
|
+
RPCLibrary.prototype.getChainsConfig = getChainsConfig;
|
|
356
|
+
RPCLibrary.prototype.setChainsConfig = setChainConfig;
|
|
357
|
+
|
|
358
|
+
export default RPCLibrary;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import getSupply from "./getSupply";
|
|
2
|
+
import { getConfig } from "../utils/contracts";
|
|
3
|
+
import { ChainId } from "../configs/chains";
|
|
4
|
+
import { AssetType } from "../utils/artifacts";
|
|
5
|
+
import { Provider } from "ethers";
|
|
6
|
+
|
|
7
|
+
async function getAsset(
|
|
8
|
+
chainId: ChainId,
|
|
9
|
+
assetId: AssetType,
|
|
10
|
+
provider: Provider
|
|
11
|
+
) {
|
|
12
|
+
try {
|
|
13
|
+
const { assets } = getConfig(chainId);
|
|
14
|
+
const asset = Object.values(assets).find((asset) => asset.id === assetId);
|
|
15
|
+
if (!asset) {
|
|
16
|
+
throw new Error(`Asset ${assetId} not found on chain ${chainId}`);
|
|
17
|
+
}
|
|
18
|
+
asset.supply = await getSupply(chainId, assetId, provider);
|
|
19
|
+
return asset;
|
|
20
|
+
} catch (error: any) {
|
|
21
|
+
console.error(`Error getting asset ${assetId}:`, error);
|
|
22
|
+
return 0;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export default getAsset;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Provider } from "ethers";
|
|
2
|
+
import { ChainId } from "../configs/chains";
|
|
3
|
+
import { getConfig } from "../utils/contracts";
|
|
4
|
+
|
|
5
|
+
async function getAssets(chainId: ChainId, provider: Provider) {
|
|
6
|
+
const { assets } = getConfig(chainId);
|
|
7
|
+
const responses: any = {};
|
|
8
|
+
|
|
9
|
+
const assetIds = Object.keys(assets);
|
|
10
|
+
const assetPromises = assetIds.map(async (assetId) => {
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
const asset = await this.getAsset(chainId, assetId, provider);
|
|
13
|
+
responses[assetId] = {
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
...assets[assetId],
|
|
16
|
+
...asset,
|
|
17
|
+
};
|
|
18
|
+
return responses[assetId];
|
|
19
|
+
});
|
|
20
|
+
const assetsPromise = await Promise.all(assetPromises);
|
|
21
|
+
|
|
22
|
+
const response = {};
|
|
23
|
+
for (const asset of assetsPromise) {
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
response[asset.id] = asset;
|
|
26
|
+
}
|
|
27
|
+
return response;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export default getAssets;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ethers, Provider } from "ethers";
|
|
2
|
+
import { getContractAddress } from "../utils/contracts";
|
|
3
|
+
import { ChainId } from "../configs/chains";
|
|
4
|
+
import { AssetType } from "../utils/artifacts";
|
|
5
|
+
|
|
6
|
+
async function getSupply(
|
|
7
|
+
chainId: ChainId,
|
|
8
|
+
assetId: AssetType,
|
|
9
|
+
provider: Provider
|
|
10
|
+
) {
|
|
11
|
+
try {
|
|
12
|
+
const SUPPLY_ABI = ["function totalSupply() view returns (uint256)"];
|
|
13
|
+
const contractAddress = getContractAddress(chainId, assetId);
|
|
14
|
+
const contract = new ethers.Contract(contractAddress, SUPPLY_ABI, provider);
|
|
15
|
+
const supply = await contract.totalSupply();
|
|
16
|
+
return ethers.formatEther(supply);
|
|
17
|
+
} catch (error: any) {
|
|
18
|
+
console.error(`Error getting supply for asset ${assetId}:`, error);
|
|
19
|
+
return 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default getSupply;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
{
|
|
2
|
+
"chainId": 8453,
|
|
3
|
+
"name": "localhost",
|
|
4
|
+
"rpcs": ["http://127.0.0.1:8545"],
|
|
5
|
+
"nativeCurrency": {
|
|
6
|
+
"name": "ETH",
|
|
7
|
+
"symbol": "ETH",
|
|
8
|
+
"decimals": 18
|
|
9
|
+
},
|
|
10
|
+
"blockExplorer": [
|
|
11
|
+
{
|
|
12
|
+
"name": "Etherscan",
|
|
13
|
+
"url": "https://etherscan.io"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"contracts": {
|
|
17
|
+
"raachouseprices": {
|
|
18
|
+
"id": "raachouseprices",
|
|
19
|
+
"name": "RAAC House Prices",
|
|
20
|
+
"contract": "0x1B0a4142A467852271efC5DA8B6128D9f7e811dC"
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
"auctionfactory": {
|
|
24
|
+
"id": "auctionfactory",
|
|
25
|
+
"name": "Auction Factory",
|
|
26
|
+
"contract": "0xC644A84734A7329eE46d3B6704746179d272f990"
|
|
27
|
+
},
|
|
28
|
+
"zenofactory": {
|
|
29
|
+
"id": "zenofactory",
|
|
30
|
+
"name": "Zeno Factory",
|
|
31
|
+
"contract": "0xa9eE59A113bCB4B2CC10f802D1efF0Bae1Ab91D2"
|
|
32
|
+
},
|
|
33
|
+
"raacminter": {
|
|
34
|
+
"id": "raacminter",
|
|
35
|
+
"name": "RAAC Minter",
|
|
36
|
+
"contract": "0xa04684348f68cd82A028F51D643c60CA40b5dDa3"
|
|
37
|
+
},
|
|
38
|
+
"feecollector": {
|
|
39
|
+
"id": "feecollector",
|
|
40
|
+
"name": "Fee Collector",
|
|
41
|
+
"contract": "0x2AefD948d5F971F58B129b32B4AFf43fd3288D4b"
|
|
42
|
+
},
|
|
43
|
+
"treasury": {
|
|
44
|
+
"id": "treasury",
|
|
45
|
+
"name": "Treasury",
|
|
46
|
+
"contract": "0xF6B8c7b1F3886655A7F224F7b1F5EC5F7F5C0D1f"
|
|
47
|
+
},
|
|
48
|
+
"repairfund": {
|
|
49
|
+
"id": "repairfund",
|
|
50
|
+
"name": "Repair Fund",
|
|
51
|
+
"contract": "0x8d231e53b16005960f5227Cc245279d523188dBE"
|
|
52
|
+
},
|
|
53
|
+
"releaseorchestrator": {
|
|
54
|
+
"id": "releaseorchestrator",
|
|
55
|
+
"name": "Release Orchestrator",
|
|
56
|
+
"contract": "0xc9B0b1D3508Edb263699aEDf7100a266bE973Ff9"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
"pools": {
|
|
60
|
+
"stabilitypool": {
|
|
61
|
+
"id": "stabilitypool",
|
|
62
|
+
"name": "Stability Pool",
|
|
63
|
+
"contract": "0x009a664dDE58c58F8d3006e23115106b7e5F144F"
|
|
64
|
+
},
|
|
65
|
+
"lendingpool": {
|
|
66
|
+
"id": "lendingpool",
|
|
67
|
+
"name": "Lending Pool",
|
|
68
|
+
"contract": "0x2e0c587b6D3723874b0B0cc994d42969455e14fc"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"nfts": {
|
|
72
|
+
"raacnft": {
|
|
73
|
+
"id": "raacnft",
|
|
74
|
+
"name": "RAAC NFT",
|
|
75
|
+
"contract": "0xF31622C2c5464605154c43b9e62dBa3e9De76C72"
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
"assets": {
|
|
79
|
+
"eth": {
|
|
80
|
+
"id": "eth",
|
|
81
|
+
"name": "ETH",
|
|
82
|
+
"decimals": 18,
|
|
83
|
+
"contract": "0x0000000000000000000000000000000000000000"
|
|
84
|
+
},
|
|
85
|
+
"crvusd": {
|
|
86
|
+
"id": "crvusd",
|
|
87
|
+
"name": "CRVUSD",
|
|
88
|
+
"decimals": 18,
|
|
89
|
+
"contract": "0x5130220647908B7d9d8cC8c05Ac5683a799A4471"
|
|
90
|
+
},
|
|
91
|
+
"rtoken": {
|
|
92
|
+
"id": "rtoken",
|
|
93
|
+
"name": "RToken",
|
|
94
|
+
"decimals": 18,
|
|
95
|
+
"contract": "0xB59dFCD4968540C9FE7D67Bb5C86AfD8f26A0Ab0"
|
|
96
|
+
},
|
|
97
|
+
"detoken": {
|
|
98
|
+
"id": "detoken",
|
|
99
|
+
"name": "DEToken",
|
|
100
|
+
"decimals": 18,
|
|
101
|
+
"contract": "0x848a59daCE7e021e18aB0f5cb03B7C4Fd9A79244"
|
|
102
|
+
},
|
|
103
|
+
"raactoken": {
|
|
104
|
+
"id": "raactoken",
|
|
105
|
+
"name": "RAAC",
|
|
106
|
+
"decimals": 18,
|
|
107
|
+
"contract": "0x97c72eEB8640Ce4646743dD07548B1Df85Be33F9"
|
|
108
|
+
},
|
|
109
|
+
"veraac": {
|
|
110
|
+
"id": "veraac",
|
|
111
|
+
"name": "VERAAC",
|
|
112
|
+
"decimals": 18,
|
|
113
|
+
"contract": "0x81bf888E0BD2B4184189FC165CE97531e3EC2F11"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export interface Chain {
|
|
2
|
+
chainId: number;
|
|
3
|
+
name: string;
|
|
4
|
+
rpcs: string[];
|
|
5
|
+
contracts: Contracts;
|
|
6
|
+
pools: Pools;
|
|
7
|
+
nfts: Nfts;
|
|
8
|
+
assets: Assets;
|
|
9
|
+
nativeCurrency: NativeCurrency;
|
|
10
|
+
blockExplorer: BlockExplorer[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface BlockExplorer {
|
|
14
|
+
name: string;
|
|
15
|
+
url: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Chain8453 extends Chain {
|
|
19
|
+
contracts: Contracts8453;
|
|
20
|
+
pools: Pools8453;
|
|
21
|
+
nfts: Nfts8453;
|
|
22
|
+
assets: Assets8453;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface NativeCurrency {
|
|
26
|
+
name: string;
|
|
27
|
+
symbol: string;
|
|
28
|
+
decimals: number;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Contracts {
|
|
32
|
+
[contract: string]: DeployedContract;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface Contracts8453 {
|
|
36
|
+
raachouseprices: DeployedContract;
|
|
37
|
+
raacminter: DeployedContract;
|
|
38
|
+
auctionfactory: DeployedContract;
|
|
39
|
+
zenofactory: DeployedContract;
|
|
40
|
+
feecollector: DeployedContract;
|
|
41
|
+
treasury: DeployedContract;
|
|
42
|
+
repairfund: DeployedContract;
|
|
43
|
+
releaseorchestrator: DeployedContract;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface Pools {
|
|
47
|
+
[pool: string]: DeployedContract;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface Pools8453 {
|
|
51
|
+
stabilitypool: DeployedContract;
|
|
52
|
+
lendingpool: DeployedContract;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface Nfts {
|
|
56
|
+
[nft: string]: DeployedContract;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface Nfts8453 {
|
|
60
|
+
raacnft: DeployedContract;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface Assets {
|
|
64
|
+
[asset: string]: Asset;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export interface Assets8453 {
|
|
68
|
+
eth: Asset;
|
|
69
|
+
crvusd: Asset;
|
|
70
|
+
rtoken: Asset;
|
|
71
|
+
detoken: Asset;
|
|
72
|
+
raactoken: Asset;
|
|
73
|
+
veraac: Asset;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface DeployedContract {
|
|
77
|
+
id: string;
|
|
78
|
+
name: string;
|
|
79
|
+
contract: string;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export interface Asset {
|
|
83
|
+
id: string;
|
|
84
|
+
name: string;
|
|
85
|
+
decimals: number;
|
|
86
|
+
contract: string;
|
|
87
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import chain8453 from "./8453.json"; // assert { type: "json" };
|
|
3
|
+
import { Chain, Chain8453 } from "./chain";
|
|
4
|
+
|
|
5
|
+
const chains = {
|
|
6
|
+
8453: chain8453 as Chain8453,
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export default chains;
|
|
10
|
+
export const configs = chains;
|
|
11
|
+
export type Configs = typeof chains;
|
|
12
|
+
export type ConfigKeys = keyof Configs;
|
|
13
|
+
export type ChainId = ConfigKeys | string | number;
|