Skip to content

Commit

Permalink
Merge pull request #230 from terra-money/feat/osmosis-gas-prices
Browse files Browse the repository at this point in the history
  • Loading branch information
alecande11 authored Nov 29, 2023
2 parents cd6371c + 691eba4 commit 8197813
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 32 deletions.
10 changes: 9 additions & 1 deletion chains/mainnet/osmosis.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ module.exports = {
chainID: 'osmosis-1',
lcd: 'https://osmosis-1.terra.dev',
gasAdjustment: 2.2,
gasPrices: { uosmo: 0.025 },
gasPrices: {
uosmo: {
type: 'OSMOSIS',
url: '/osmosis/txfees/v1beta1/cur_eip_base_fee',
adjustment: 5,
// value to be used if the request to the LCD fails
defaultValue: 0.0025 * 5,
},
},
prefix: 'osmo',
coinType: '118',
baseAsset: 'uosmo',
Expand Down
82 changes: 56 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const glob = require('glob-promise')
const path = require('path')
const axios = require('axios')
const { Buffer } = require('buffer')
const { Hash } = require('@keplr-wallet/crypto')
const { AccAddress } = require('@terra-money/feather.js')
Expand All @@ -16,32 +17,59 @@ const fs = require('fs').promises
const chainFiles = await glob('./chains/*/*.js')
const tokens = []

chainFiles.forEach((file) => {
const [_, folder, network, fileName] = file.split('/')

if (typeof chains[network] === 'undefined') {
chains[network] = {}
}

const fullPath = `./${file}`
const chainData = require(fullPath)

if (network !== 'localterra' && !isValidUrl(chainData.lcd)) {
console.log(`${chainData.chainID}: Invalid LCD URL: ${chainData.lcd}`)
return
}
tokens.push(
...(chainData.tokens ?? []).map((t) => ({
...t,
chainID: chainData.chainID,
network,
}))
)
await Promise.all(
chainFiles.map(async (file) => {
const [_, folder, network, fileName] = file.split('/')

if (typeof chains[network] === 'undefined') {
chains[network] = {}
}

const fullPath = `./${file}`
const chainData = require(fullPath)

if (network !== 'localterra' && !isValidUrl(chainData.lcd)) {
console.log(`${chainData.chainID}: Invalid LCD URL: ${chainData.lcd}`)
return
}
tokens.push(
...(chainData.tokens ?? []).map((t) => ({
...t,
chainID: chainData.chainID,
network,
}))
)

delete chainData['tokens']
delete chainData['tokens']

const gasPrices = Object.fromEntries(
await Promise.all(
Object.entries(chainData.gasPrices).map(async ([key, value]) => {
if (typeof value === 'number') {
return [key, value]
} else {
if (value.type === 'OSMOSIS') {
try {
const { data } = await axios.get(value.url, {
baseURL: chainData.lcd,
})
return [key, Number(data.base_fee) * value.adjustment]
} catch (e) {
console.error(e)
console.error(
`Failed to get the gas price from ${value.url} on ${chainData.lcd}`
)
return [key, value.defaultValue]
}
}
}
})
)
)

chains[network][chainData.chainID] = chainData
})
chains[network][chainData.chainID] = { ...chainData, gasPrices }
})
)

// convert coins to json
const coinsOutPath = './build/denoms.json'
Expand All @@ -64,7 +92,6 @@ const fs = require('fs').promises

coinsOut[network][tokenId] = { ...coinData, chainID, chains: [chainID] }


// chain is disabled
if (!chains[network][chainID]) {
console.log(`${chainID} used by ${coinData.token} is disabled.`)
Expand All @@ -84,7 +111,10 @@ const fs = require('fs').promises
return
}

const denom = chains[network][chainID].prefix === "kujira" ? coinData.token?.replaceAll("/", ":") : coinData.token
const denom =
chains[network][chainID].prefix === 'kujira'
? coinData.token?.replaceAll('/', ':')
: coinData.token
const ibcDenom = calculateIBCDenom(channel, denom)
ibcDenomMapOut[network][`${otherChainID}:${ibcDenom}`] = {
token: tokenId,
Expand Down
26 changes: 21 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"dependencies": {
"@keplr-wallet/crypto": "^0.11.32",
"@terra-money/feather.js": "^1.0.0-beta.8",
"axios": "^1.6.2",
"buffer": "^6.0.3",
"glob": "^8.0.3",
"glob-promise": "^6.0.1",
Expand Down

0 comments on commit 8197813

Please sign in to comment.