|
1 | | - |
2 | | - |
3 | 1 | import { Write } from "../../utils/dbInterfaces"; |
4 | 2 | import getWrites from "../../utils/getWrites"; |
5 | 3 | import { getApi } from "../../utils/sdk"; |
6 | 4 |
|
7 | | -const config: any = { |
8 | | - bsc: { |
9 | | - oracle: '0x4e9651AD369d8F986935852C945338F76b5fb360', |
10 | | - tokens: { |
11 | | - GFST: '0xbA2e788D83eA786d11ED87353763616157A35082', |
12 | | - STBX: '0x65DaD60a28626309F7504d853AFF0099FeD1aAaF', |
13 | | - SLX: '0x2C4A911B16435f96e6bD18E4d720a32480554a22', |
14 | | - LSRWA: '0x475eD67Bfc62B41c048b81310337c1D75D45aADd', |
15 | | - } |
16 | | - }, |
17 | | - polygon: { |
18 | | - oracle: '0x4e9651AD369d8F986935852C945338F76b5fb360', |
19 | | - tokens: { |
20 | | - CSB23: '0x76381bFCCB35736a854675570c07a73508622AFd', |
21 | | - MFRET: '0xAa6d73C22A953a6A83B9963052bA73f0C53FC764', |
22 | | - MRDTS: '0xF71272DBC0Da11aDd09cd44A0b7F7D384C0D5Fe1', |
23 | | - CTREAL: '0x06c3aa74645f424d24f6C835e8D606D35225Ab96', |
24 | | - } |
| 5 | +const config = { |
| 6 | + arbitrum: { |
| 7 | + oracle: '0x7C48bb52E63fe34C78F0D14Ee6E59BDe95D93645', |
| 8 | + factory: '0x096D75d0501c3B1479FFe15569192CeC998223b4', |
25 | 9 | }, |
26 | | -} |
| 10 | +}; |
27 | 11 |
|
| 12 | +/** |
| 13 | + * Fetches token prices from Stobox oracle for a specific chain. |
| 14 | + * Token list is retrieved dynamically from StoboxRWAVaultFactory contract. |
| 15 | + * @param chain - The blockchain network name |
| 16 | + * @param timestamp - Unix timestamp for price query (0 for current) |
| 17 | + * @returns Array of Write objects containing token prices |
| 18 | + */ |
28 | 19 | async function getTokenPrices(chain: string, timestamp: number) { |
29 | 20 | const api = await getApi(chain, timestamp); |
30 | | - let { oracle, tokens } = config[chain] |
31 | | - tokens = Object.values(tokens) |
| 21 | + const { oracle, factory } = config[chain as keyof typeof config]; |
| 22 | + |
| 23 | + // Fetch token list from factory contract |
| 24 | + const tokens: string[] = await api.call({ |
| 25 | + abi: 'function generalTokenList() external view returns (address[] memory)', |
| 26 | + target: factory, |
| 27 | + }); |
| 28 | + |
| 29 | + if (!tokens || tokens.length === 0) { |
| 30 | + return []; |
| 31 | + } |
| 32 | + |
32 | 33 | const tokenInfo = await api.multiCall({ |
33 | | - abi: 'function getCoinPrice(uint256, address, address)external view returns (bool, uint256)', |
| 34 | + abi: 'function getCoinPrice(uint256, address, address) external view returns (bool, uint256)', |
34 | 35 | target: oracle, |
35 | | - calls: tokens.map((token: string) => ({ params: [840, token, '0x0000000000000000000000000000000000000000',] })), |
36 | | - }) |
| 36 | + calls: tokens.map((token: string) => ({ params: [840, token, '0x0000000000000000000000000000000000000000'] })), |
| 37 | + }); |
| 38 | + |
37 | 39 | const pricesObject: any = {}; |
38 | 40 | const writes: Write[] = []; |
39 | | - tokens.forEach((contract: any, idx: number) => { |
| 41 | + tokens.forEach((contract: string, idx: number) => { |
40 | 42 | pricesObject[contract] = { price: tokenInfo[idx][1] / 1e18 }; |
41 | 43 | }); |
42 | 44 |
|
43 | | - await getWrites({ chain, timestamp, writes, pricesObject, projectName: "stobox", }) |
| 45 | + await getWrites({ chain, timestamp, writes, pricesObject, projectName: "stobox" }); |
44 | 46 | return writes; |
45 | 47 | } |
46 | 48 |
|
| 49 | +/** |
| 50 | + * Main adapter function for Stobox RWA tokens. |
| 51 | + * Fetches prices for all configured chains (Arbitrum). |
| 52 | + * @param timestamp - Unix timestamp for price query (0 for current) |
| 53 | + * @returns Promise resolving to array of Write objects for all chains |
| 54 | + */ |
47 | 55 | export function stobox(timestamp: number = 0) { |
48 | | - return Promise.all(Object.keys(config).map(i => getTokenPrices(i, timestamp))) |
| 56 | + return Promise.all(Object.keys(config).map((chain) => getTokenPrices(chain, timestamp))); |
49 | 57 | } |
0 commit comments