diff --git a/layer/data/spot.ts b/layer/data/spot.ts new file mode 100644 index 00000000..e42ecffe --- /dev/null +++ b/layer/data/spot.ts @@ -0,0 +1,72 @@ +export const spotMarketIdMap: Record = + { + '0xd0ba680312852ffb0709446fff518e6c4d798fb70cfd2699aba3717a2517cfd5': { + // APP/INJ + slug: 'app-usdt', + ticker: 'APP/USDT' + }, + '0x959c9401a557ac090fff3ec11db5a1a9832e51a97a41b722d2496bb3cb0b2f72': { + // ANDR/INJ + slug: 'andr-usdt', + ticker: 'ANDR/USDT' + }, + '0xa6ec1de114a5ffa85b6b235144383ce51028a1c0c2dee7db5ff8bf14d5ca0d49': { + slug: 'pythlegacy-usdt', + ticker: 'PYTHlegacy/USDT' + } + } + +export const spotDenomMap: Record = { + 'factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1tjcf9497fwmrnk22jfu5hsdq82qshga54ajvzy': + ({ slug, ticker }: { slug: string; ticker: string }) => ({ + slug: slug.replace('pyth', 'pythlegacy'), + ticker: ticker.replace('PYTH', 'PYTHlegacy') + }), + peggy0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48: ({ + slug, + ticker + }: { + slug: string + ticker: string + }) => ({ + slug: slug.replace('usdc', 'usdclegacy'), + ticker: ticker.replace('USDC', 'USDClegacy') + }), + 'factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1q6zlut7gtkzknkk773jecujwsdkgq882akqksk': + ({ slug, ticker }: { slug: string; ticker: string }) => ({ + slug: slug.replace('usdc', 'usdcet'), + ticker: ticker.replace('USDC', 'USDCet') + }), + 'ibc/2CBC2EA121AE42563B08028466F37B600F2D7D4282342DE938283CC3FB2BC00E': ({ + slug, + ticker + }: { + slug: string + ticker: string + }) => ({ + slug: slug.replace('usdcnb', 'usdc'), + ticker: ticker.replace('USDCnb', 'USDC') + }), + 'factory/inj1alwxgkns9x7d2sprymwwfvzl5t7teetym02lrj/NONJA': ({ + slug, + ticker + }: { + slug: string + ticker: string + }) => ({ + slug: slug.replace('nonja', 'nonjaunverified'), + ticker: ticker.replace('NONJA', 'NONJAunverified') + }), + 'factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1sthrn5ep8ls5vzz8f9gp89khhmedahhdkqa8z3': + ({ ticker }: { ticker: string }) => ({ + ticker: ticker.replace('SOL', 'SOLlegacy') + }), + 'factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1d5vz0uzwlpfvgwrwulxg6syy82axa58y4fuszd': + ({ ticker }: { ticker: string }) => ({ + ticker: ticker.replace('ARB', 'ARBlegacy') + }), + 'factory/inj14ejqjyq8um4p3xfqj74yld5waqljf88f9eneuk/inj1dxv423h8ygzgxmxnvrf33ws3k94aedfdevxd8h': + ({ ticker }: { ticker: string }) => ({ + ticker: ticker.replace('WMATIC', 'WMATIClegacy') + }) +} diff --git a/layer/package.json b/layer/package.json index 39633641..573f3373 100644 --- a/layer/package.json +++ b/layer/package.json @@ -13,9 +13,9 @@ "@injectivelabs/networks": "1.14.11-beta.4", "@injectivelabs/ts-types": "1.14.11-beta.1", "@injectivelabs/sdk-ts": "1.14.11-beta.34", - "@injectivelabs/sdk-ui-ts": "1.14.11-beta.46", + "@injectivelabs/sdk-ui-ts": "1.14.11-beta.47", "@injectivelabs/token-metadata": "1.14.11-beta.26", - "@injectivelabs/wallet-ts": "1.14.11-beta.42", + "@injectivelabs/wallet-ts": "1.14.11-beta.43", "@vueuse/integrations": "^10.7.1", "floating-vue": "2.0.0-beta.24", "vue-gtag": "^2.0.1", diff --git a/layer/utils/formatter.ts b/layer/utils/formatter.ts index 64d0ede2..d25b0399 100644 --- a/layer/utils/formatter.ts +++ b/layer/utils/formatter.ts @@ -15,32 +15,6 @@ export const sharedToBalanceInWei = ({ return new BigNumberInBase(10).pow(decimalPlaces).times(value) } -export const sharedConvertTimestampToMilliseconds = ( - timestamp: number | string -): number => { - const timestampInBigNumber = new BigNumberInBase(timestamp) - - if (timestamp.toString().length > 13) { - const formatNumberBy = new BigNumberInBase(10).pow( - timestamp.toString().length - 13 - ) - - const formattedValue = timestampInBigNumber - .dividedBy(formatNumberBy) - .toFixed(0, BigNumber.ROUND_HALF_UP) - - return new BigNumberInBase(formattedValue).toNumber() - } - - if (timestamp.toString().length < 13) { - const trailingZeros = 13 - timestamp.toString().length - - return timestampInBigNumber.times(10 ** trailingZeros).toNumber() - } - - return timestampInBigNumber.toNumber() -} - export const sharedToBalanceInTokenInBase = ({ value, decimalPlaces = 18 @@ -116,3 +90,65 @@ export const sharedFormatSecondsToDisplay = ({ return output } + +export const sharedConvertTimestampToMilliseconds = ( + timestamp: number | string +): number => { + const timestampInBigNumber = new BigNumberInBase(timestamp) + + if (timestamp.toString().length > 13) { + const formatNumberBy = new BigNumberInBase(10).pow( + timestamp.toString().length - 13 + ) + + const formattedValue = timestampInBigNumber + .dividedBy(formatNumberBy) + .toFixed(0, BigNumber.ROUND_HALF_UP) + + return new BigNumberInBase(formattedValue).toNumber() + } + + if (timestamp.toString().length < 13) { + const trailingZeros = 13 - timestamp.toString().length + + return timestampInBigNumber.times(10 ** trailingZeros).toNumber() + } + + return timestampInBigNumber.toNumber() +} + +export const sharedGetExactDecimalsFromNumber = ( + number: number | string +): number => { + if (!number.toString().includes('.')) { + return 0 + } + + if (Number(number) % 1 === 0) { + return 0 + } + + const [, decimals] = number.toString().split('.') + + if (!decimals) { + return 0 + } + + return decimals.length +} + +export const sharedGetTensMultiplier = (number: number | string): number => { + const numberToBn = new BigNumber(number) + + if (numberToBn.eq(1)) { + return 0 + } + + if (numberToBn.lt(1)) { + return -1 * sharedGetExactDecimalsFromNumber(numberToBn.toFixed()) + } + + const [, zerosInTheNumber] = numberToBn.toFixed().split('1') + + return zerosInTheNumber.length +} diff --git a/layer/utils/market.ts b/layer/utils/market.ts new file mode 100644 index 00000000..1b56c546 --- /dev/null +++ b/layer/utils/market.ts @@ -0,0 +1,29 @@ +import { spotMarketIdMap, spotDenomMap } from '@/data/spot' + +export const sharedSpotGetSlugAndTicket = ({ + marketId, + slug, + ticker, + baseDenom, + quoteDenom +}: { + marketId: string + slug: string + ticker: string + baseDenom: string + quoteDenom: string +}): { slug: string; ticker: string } => { + if (spotMarketIdMap[marketId]) { + return spotMarketIdMap[marketId] + } + + if (spotDenomMap[baseDenom]) { + return spotDenomMap[baseDenom]({ slug, ticker }) + } + + if (spotDenomMap[quoteDenom]) { + return spotDenomMap[quoteDenom]({ slug, ticker }) + } + + return { slug, ticker } +} diff --git a/layer/yarn.lock b/layer/yarn.lock index 560fb4fe..88b1d70e 100644 --- a/layer/yarn.lock +++ b/layer/yarn.lock @@ -1648,10 +1648,10 @@ shx "^0.3.2" snakecase-keys "^5.4.1" -"@injectivelabs/sdk-ui-ts@1.14.11-beta.46": - version "1.14.11-beta.46" - resolved "https://registry.npmjs.org/@injectivelabs/sdk-ui-ts/-/sdk-ui-ts-1.14.11-beta.46.tgz#fc074c304036468b2193abc23ef2f3cc34a57022" - integrity sha512-COM8Aff1cerM41JVDHnTkCKojQHVc749qa09sakFTAorKZRzF+mSyyYurf9fHuPtO9PQ0KxDd1qxwpTiP08XkQ== +"@injectivelabs/sdk-ui-ts@1.14.11-beta.47": + version "1.14.11-beta.47" + resolved "https://registry.yarnpkg.com/@injectivelabs/sdk-ui-ts/-/sdk-ui-ts-1.14.11-beta.47.tgz#26cda020261cf0cfa7706a175c866ac6e0e8b273" + integrity sha512-IVGX+yonL4UdtGgiK9DC4eBpblR5XKuWA9qN4IKwAFOyNc5aag1cypCEXD82DjEkRkxJ+IoZ/QagI8dM11u3uQ== dependencies: "@injectivelabs/contracts" "^1.14.11-beta.4" "@injectivelabs/exceptions" "^1.14.11-beta.3" @@ -1728,10 +1728,10 @@ snakecase-keys "^5.1.2" store2 "^2.12.0" -"@injectivelabs/wallet-ts@1.14.11-beta.42": - version "1.14.11-beta.42" - resolved "https://registry.npmjs.org/@injectivelabs/wallet-ts/-/wallet-ts-1.14.11-beta.42.tgz#d5f58cfa6884524062c56fa4c91b9c99c006753a" - integrity sha512-Ccq65Bc+CoWMStsrbd8dghFr82bvM3yAF2B5QwElQ6Nj6SFFvYCt5hhhpsjC+W8MGiqyNp3/AzS9G51NfU0rwA== +"@injectivelabs/wallet-ts@1.14.11-beta.43": + version "1.14.11-beta.43" + resolved "https://registry.yarnpkg.com/@injectivelabs/wallet-ts/-/wallet-ts-1.14.11-beta.43.tgz#9ae49178b831eadd6392fac287b04a4e1716a645" + integrity sha512-vJfJMBJtUlE8tXi+YFc4fBabFeknBLfzvJV2CPdVKYS+/Ky9sPWJBPgi1RbiwXVQoEsoQ2aPkCGiB4LsZJ3aGw== dependencies: "@cosmjs/launchpad" "0.27.1" "@cosmjs/proto-signing" "0.32.2"