Skip to content

Commit

Permalink
CU-86a6j59wv - BSLib - MoralisEDSEthereum - Remove the getWrappedNati…
Browse files Browse the repository at this point in the history
…veToken request and just query it locally
  • Loading branch information
raulduartep committed Feb 4, 2025
1 parent 71e44c2 commit 833174a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-ethereum",
"comment": "Remove the getWrappedNativeToken request and just query it locally",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-ethereum"
}
10 changes: 10 additions & 0 deletions packages/bs-ethereum/src/constants/BSEthereumConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ export class BSEthereumConstants {

static NATIVE_WRAPPED_HASH_BY_NETWORK_ID: Partial<Record<BSEthereumNetworkId, string>> = {
'1': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
'10': '0x4200000000000000000000000000000000000006',
'25': '0x5c7f8a570d578ed84e63fdfa7b1ee72deae1ae23',
'56': '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c',
'137': '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
'250': '0x21be370d5312f44cb42ce377bc9b8a0cef1a4c83',
'8453': '0x4200000000000000000000000000000000000006',
'42161': '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
'42220': '0x471EcE3750Da237f93B8E339c536989b8978a438',
'43114': '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7',
'59144': '0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f',
}

static RPC_LIST_BY_NETWORK_ID: Record<BSEthereumNetworkId, string[]> = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ import { BSEthereumConstants, BSEthereumNetworkId } from '../../constants/BSEthe
import { BSEthereumHelper } from '../../helpers/BSEthereumHelper'
import { MoralisBDSEthereum } from '../blockchain-data/MoralisBDSEthereum'

type MoralisERC20MetadataResponse = {
address: string
name: string
symbol: string
decimals: string
possible_spam: boolean
verified_contract: boolean
}

type MoralisERC20PriceResponse = {
tokenName: string
tokenSymbol: string
Expand Down Expand Up @@ -49,29 +40,12 @@ export class MoralisEDSEthereum extends CryptoCompareEDS implements ExchangeData
const nativeToken = BSEthereumHelper.getNativeAsset(this.#network)
const wrappedSymbol = `W${nativeToken.symbol}`
const localWrappedHash = BSEthereumConstants.NATIVE_WRAPPED_HASH_BY_NETWORK_ID[this.#network.id]
if (localWrappedHash) {
return {
...nativeToken,
symbol: wrappedSymbol,
hash: localWrappedHash,
}
}

const client = MoralisBDSEthereum.getClient(this.#network)
const { data } = await client.get<MoralisERC20MetadataResponse[]>('/erc20/metadata/symbols', {
params: {
symbols: [wrappedSymbol],
},
})

const wrapperToken = data.find(token => token.verified_contract && !token.possible_spam)
if (!wrapperToken) throw new Error('Wrapper token not found')
if (!localWrappedHash) throw new Error('Wrapper token not found')

return {
decimals: Number(wrapperToken.decimals),
hash: wrapperToken.address,
name: wrapperToken.name,
symbol: wrapperToken.symbol,
...nativeToken,
symbol: wrappedSymbol,
hash: localWrappedHash,
}
}

Expand Down Expand Up @@ -107,6 +81,8 @@ export class MoralisEDSEthereum extends CryptoCompareEDS implements ExchangeData
}
})

if (tokensBody.length === 0) return []

const splitTokensBody = []
for (let i = 0; i < tokensBody.length; i += this.#maxTokenPricesPerCall) {
splitTokensBody.push(tokensBody.slice(i, i + this.#maxTokenPricesPerCall))
Expand Down

0 comments on commit 833174a

Please sign in to comment.