@@ -15,7 +15,7 @@ function detectCrossChainToken(tokenId) {
1515 if ( tokenId . includes ( 'v2_1.omni.hot.tg:1100_' ) ) {
1616 const stellarMappings = {
1717 '111bzQBB5v7AhLyPMDwS8uJgQV24KaAPXtwyVWu2KXbbfQU6NXRCz' : 'coingecko:stellar' ,
18- '111bzQBB65GxAPAVoxqmMcgYo5oS3txhqs1Uh1cgahKQUeTUq1TJu' : 'stellar:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN ' ,
18+ '111bzQBB65GxAPAVoxqmMcgYo5oS3txhqs1Uh1cgahKQUeTUq1TJu' : 'coingecko:usd-coin ' ,
1919 }
2020 const match = tokenId . match ( / 1 1 0 0 _ ( [ a - z A - Z 0 - 9 ] + ) $ / )
2121 if ( match && stellarMappings [ match [ 1 ] ] ) {
@@ -103,13 +103,11 @@ function validateConfiguration(configuration) {
103103 if ( ! configuration . collateral_asset ) throw new Error ( 'Missing collateral_asset in configuration' )
104104}
105105
106- function scaleTokenAmount ( amount , tokenAddress ) {
107- if ( tokenAddress === 'coingecko:bitcoin' ) {
108- return amount . div ( 1e8 ) . toFixed ( )
109- }
110- if ( tokenAddress === 'coingecko:stellar' ) {
111- return amount . div ( 1e7 ) . toFixed ( )
106+ function scaleTokenAmount ( amount , tokenAddress , decimals ) {
107+ if ( tokenAddress . startsWith ( 'coingecko' ) ) {
108+ return amount . div ( Math . pow ( 10 , decimals ) ) . toFixed ( ) ;
112109 }
110+
113111 return amount . toFixed ( )
114112}
115113
@@ -224,6 +222,9 @@ async function processMarket(marketContract) {
224222 const borrowAssetToken = extractTokenAddress ( configuration . borrow_asset , 'borrow' )
225223 const collateralAssetToken = extractTokenAddress ( configuration . collateral_asset , 'collateral' )
226224
225+ const borrowDecimals = configuration . price_oracle_configuration . borrow_asset_decimals
226+ const collateralDecimals = configuration . price_oracle_configuration . collateral_asset_decimals
227+
227228 const borrow_asset_deposited_active = BigNumber ( snapshot . borrow_asset_deposited_active )
228229 const borrow_asset_deposited_incoming = BigNumber ( snapshot . borrow_asset_deposited_incoming )
229230 const collateral_asset_deposited = BigNumber ( snapshot . collateral_asset_deposited )
@@ -239,6 +240,8 @@ async function processMarket(marketContract) {
239240 availableLiquidity,
240241 totalBorrowed : borrow_asset_borrowed ,
241242 totalCollateral : collateral_asset_deposited ,
243+ borrowDecimals,
244+ collateralDecimals,
242245 }
243246}
244247
@@ -255,9 +258,9 @@ async function tvl() {
255258
256259 results . forEach ( ( result , index ) => {
257260 if ( result . status === 'fulfilled' ) {
258- const { borrowAssetToken, collateralAssetToken, availableLiquidity, totalCollateral } = result . value
259- sumSingleBalance ( balances , borrowAssetToken , scaleTokenAmount ( availableLiquidity , borrowAssetToken ) )
260- sumSingleBalance ( balances , collateralAssetToken , scaleTokenAmount ( totalCollateral , collateralAssetToken ) )
261+ const { borrowAssetToken, collateralAssetToken, availableLiquidity, totalCollateral, borrowDecimals , collateralDecimals } = result . value
262+ sumSingleBalance ( balances , borrowAssetToken , scaleTokenAmount ( availableLiquidity , borrowAssetToken , borrowDecimals ) )
263+ sumSingleBalance ( balances , collateralAssetToken , scaleTokenAmount ( totalCollateral , collateralAssetToken , collateralDecimals ) )
261264 } else {
262265 throw new Error ( `Market ${ deployments [ index ] } failed: ${ result . reason ?. message || result . reason } ` )
263266 }
@@ -279,8 +282,8 @@ async function borrowed() {
279282
280283 results . forEach ( ( result , index ) => {
281284 if ( result . status === 'fulfilled' ) {
282- const { borrowAssetToken, totalBorrowed } = result . value
283- sumSingleBalance ( balances , borrowAssetToken , scaleTokenAmount ( totalBorrowed , borrowAssetToken ) )
285+ const { borrowAssetToken, totalBorrowed, borrowDecimals } = result . value
286+ sumSingleBalance ( balances , borrowAssetToken , scaleTokenAmount ( totalBorrowed , borrowAssetToken , borrowDecimals ) )
284287 } else {
285288 throw new Error ( `Market ${ deployments [ index ] } failed: ${ result . reason ?. message || result . reason } ` )
286289 }
0 commit comments