Skip to content

Commit 648a76f

Browse files
OlenaDolinchukg1nt0kicursoragent
authored
Update Stobox adapter to arbitrum with dynamic token list (#11326)
* add Stobox adapter * code refactor * refactor: update Stobox adapter to arbitrum with dynamic token list * add JSDoc comments --------- Co-authored-by: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 1af7a2e commit 648a76f

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed
Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,57 @@
1-
2-
31
import { Write } from "../../utils/dbInterfaces";
42
import getWrites from "../../utils/getWrites";
53
import { getApi } from "../../utils/sdk";
64

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',
259
},
26-
}
10+
};
2711

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+
*/
2819
async function getTokenPrices(chain: string, timestamp: number) {
2920
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+
3233
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)',
3435
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+
3739
const pricesObject: any = {};
3840
const writes: Write[] = [];
39-
tokens.forEach((contract: any, idx: number) => {
41+
tokens.forEach((contract: string, idx: number) => {
4042
pricesObject[contract] = { price: tokenInfo[idx][1] / 1e18 };
4143
});
4244

43-
await getWrites({ chain, timestamp, writes, pricesObject, projectName: "stobox", })
45+
await getWrites({ chain, timestamp, writes, pricesObject, projectName: "stobox" });
4446
return writes;
4547
}
4648

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+
*/
4755
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)));
4957
}

0 commit comments

Comments
 (0)