diff --git a/package.json b/package.json index 73a7d1528..f27870454 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,8 @@ "e2e": "lerna run e2e", "lint": "lerna run lint", "updateDeps": " ts-node scripts/updateDeps.ts", - "updatePackages": "python3 scripts/updatePackageVersion.py ./packages" + "updatePackages": "python3 scripts/updatePackageVersion.py ./packages", + "checkVersion": "ts-node scripts/checkVersionPublished.ts ./packages" }, "husky": { "hooks": { diff --git a/packages/xchain-thorchain-amm/package.json b/packages/xchain-thorchain-amm/package.json index 7050fb289..225128217 100644 --- a/packages/xchain-thorchain-amm/package.json +++ b/packages/xchain-thorchain-amm/package.json @@ -55,7 +55,7 @@ "@xchainjs/xchain-midgard": "^0.5.2", "@xchainjs/xchain-thorchain": "^0.28.8", "@xchainjs/xchain-thornode": "^0.3.8", - "@xchainjs/xchain-thorchain-query": "^0.6.4", + "@xchainjs/xchain-thorchain-query": "^0.6.5", "@xchainjs/xchain-util": "^0.13.1", "@xchainjs/xchain-utxo-providers": "^0.2.5", "axios": "^1.3.6", @@ -91,7 +91,7 @@ "@xchainjs/xchain-midgard": "^0.5.2", "@xchainjs/xchain-thornode": "^0.3.8", "@xchainjs/xchain-thorchain": "^0.28.8", - "@xchainjs/xchain-thorchain-query": "^0.6.4", + "@xchainjs/xchain-thorchain-query": "^0.6.5", "@xchainjs/xchain-util": "^0.13.1", "@xchainjs/xchain-utxo-providers": "^0.2.5", "axios": "^1.3.6", diff --git a/packages/xchain-thorchain-query/CHANGELOG.md b/packages/xchain-thorchain-query/CHANGELOG.md index b575a0032..5789a7292 100644 --- a/packages/xchain-thorchain-query/CHANGELOG.md +++ b/packages/xchain-thorchain-query/CHANGELOG.md @@ -1,3 +1,9 @@ +# v0.6.5 (2023-10-22) + +## Update + +- address comparion fix, previously failing case matching + # v0.6.4 (2023-10-19) ## Update diff --git a/packages/xchain-thorchain-query/__e2e__/thorchain-thorname.e2e.ts b/packages/xchain-thorchain-query/__e2e__/thorchain-thorname.e2e.ts index 38f6a987e..ad3b38d9e 100644 --- a/packages/xchain-thorchain-query/__e2e__/thorchain-thorname.e2e.ts +++ b/packages/xchain-thorchain-query/__e2e__/thorchain-thorname.e2e.ts @@ -41,7 +41,7 @@ describe('Thorchain-query thorname Integration Tests', () => { }) it('Estimate not registered thorname without expirity', async () => { const thorname = await thorchainQuery.estimateThorname({ - thorname: 'hippo-2', + thorname: 'asgardex', chain: BTCChain, chainAddress: btcAddress, owner: owner, diff --git a/packages/xchain-thorchain-query/package.json b/packages/xchain-thorchain-query/package.json index a433c1d35..97239d9d6 100644 --- a/packages/xchain-thorchain-query/package.json +++ b/packages/xchain-thorchain-query/package.json @@ -1,6 +1,6 @@ { "name": "@xchainjs/xchain-thorchain-query", - "version": "0.6.4", + "version": "0.6.5", "license": "MIT", "description": "Thorchain query module that is resposible for estimating swap calculations and add/remove liquidity for thorchain ", "keywords": [ @@ -53,4 +53,4 @@ "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/packages/xchain-thorchain-query/src/thorchain-query.ts b/packages/xchain-thorchain-query/src/thorchain-query.ts index 8a3284983..63be0956e 100644 --- a/packages/xchain-thorchain-query/src/thorchain-query.ts +++ b/packages/xchain-thorchain-query/src/thorchain-query.ts @@ -1,4 +1,4 @@ -import { LastBlock, Thorname } from '@xchainjs/xchain-thornode' +import { LastBlock } from '@xchainjs/xchain-thornode' import { Address, Asset, @@ -770,8 +770,9 @@ export class ThorchainQuery { const blockData = (await this.thorchainCache.thornode.getLastBlock()).find( (item: LastBlock) => item.chain === params.asset.chain, ) + // address comparison is done after conversion to lower case const savers = (await this.thorchainCache.thornode.getSavers(`${params.asset.chain}.${params.asset.symbol}`)).find( - (item) => item.asset_address === params.address, + (item) => item.asset_address.toLowerCase() === params.address.toLowerCase(), ) const pool = (await this.thorchainCache.getPoolForAsset(params.asset)).thornodeDetails @@ -1004,10 +1005,38 @@ export class ThorchainQuery { public async getThornameDetails(thorname: string, height?: number): Promise { const errors: string[] = [] - const thornameResp = await this.thorchainCache.thornode.getThornameDetails(thorname, height) - const response: { error?: string } = JSON.parse(JSON.stringify(thornameResp)) - if (response.error) errors.push(`Thornode request quote failed: ${response.error}`) - if (errors.length > 0) { + try { + const thornameResp = await this.thorchainCache.thornode.getThornameDetails(thorname, height) + const response: { error?: string } = JSON.parse(JSON.stringify(thornameResp)) + if (response.error) errors.push(`Thornode request quote failed: ${response.error}`) + if (errors.length > 0) { + const errorResp: ThornameDetails = { + name: '', + expireBlockHeight: 0, + owner: '', + preferredAsset: '', + affiliateCollectorRune: '', + aliases: [], + error: errors, + } + return errorResp + } + + const thornameAliases: ThornameAlias[] = thornameResp.aliases.map((alias) => ({ + chain: alias.chain as Chain, + address: alias.address as Address, + })) + + const thornameDetails: ThornameDetails = { + name: thornameResp.name || '', + expireBlockHeight: thornameResp.expire_block_height || 0, + owner: thornameResp.owner || '', + preferredAsset: thornameResp.preferred_asset || '', + affiliateCollectorRune: thornameResp.affiliate_collector_rune || '', + aliases: thornameAliases || [], + } + return thornameDetails + } catch (e) { const errorResp: ThornameDetails = { name: '', expireBlockHeight: 0, @@ -1019,22 +1048,6 @@ export class ThorchainQuery { } return errorResp } - - const thornameAliases: ThornameAlias[] = thornameResp.aliases.map((alias) => ({ - chain: alias.chain as Chain, - address: alias.address as Address, - })) - - const thornameDetails: ThornameDetails = { - name: thornameResp.name || '', - expireBlockHeight: thornameResp.expire_block_height || 0, - owner: thornameResp.owner || '', - preferredAsset: thornameResp.preferred_asset || '', - affiliateCollectorRune: thornameResp.affiliate_collector_rune || '', - aliases: thornameAliases || [], - } - - return thornameDetails } /** @@ -1050,18 +1063,16 @@ export class ThorchainQuery { */ public async estimateThorname(params: QuoteThornameParams) { // CHECK IF ALREADY EXISTS - const thornameDetails = (await this.thorchainCache.thornode.getThornameDetails( - params.thorname, - )) as unknown as Thorname // TODO: Until integrate THORNode PR + const thornameDetails = await this.getThornameDetails(params.thorname) - if (thornameDetails && !params.isUpdate) { + if (thornameDetails.owner !== '' && !params.isUpdate) { throw Error('Thorname already registered') } const blockData = await this.thorchainCache.thornode.getLastBlock() const currentThorchainHeight = blockData[0].thorchain const currentHeightForExpirity = params.isUpdate - ? (thornameDetails?.expire_block_height as number) + ? (thornameDetails?.expireBlockHeight as number) : currentThorchainHeight // DEFAULT EXPIRITY @@ -1074,8 +1085,8 @@ export class ThorchainQuery { const numberOfSecondsToExpire = expirityTimestamp - currentTimestamp const numberOfBlocks = Math.round(numberOfSecondsToExpire / 6) const newHeightExpirity = currentThorchainHeight + numberOfBlocks - numberOfBlocksToAddToExpirity = thornameDetails?.expire_block_height - ? newHeightExpirity - thornameDetails?.expire_block_height + numberOfBlocksToAddToExpirity = thornameDetails?.expireBlockHeight + ? newHeightExpirity - thornameDetails?.expireBlockHeight : numberOfBlocks } // COMPUTE VALUE diff --git a/packages/xchain-thorchain-query/src/utils/thornode.ts b/packages/xchain-thorchain-query/src/utils/thornode.ts index ab62b0c15..3cfad66b7 100644 --- a/packages/xchain-thorchain-query/src/utils/thornode.ts +++ b/packages/xchain-thorchain-query/src/utils/thornode.ts @@ -505,11 +505,7 @@ export class Thornode { try { const resp = (await api.thorname(thorname, height)).data return resp - // eslint-disable-next-line @typescript-eslint/no-explicit-any - } catch (e: any) { - if (e.response.status == 404) { - } - } + } catch (e) {} } throw new Error(`THORNode is not responding`) } diff --git a/scripts/README.md b/scripts/README.md index ee7a9e8fc..51ad97ec8 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -7,10 +7,9 @@ ### Examples - ### Using python scripting update package version Minor or Patch -It will only bump version number by 1. i.e for patch > 0.1.1 -> 0.1.2 for Minor > 0.1.1 -> 0.2.0 +It will only bump version number by 1. i.e for patch > 0.1.1 -> 0.1.2 for Minor > 0.1.1 -> 0.2.0 For the whole library. @@ -26,8 +25,7 @@ For just one package. yarn updatePackages minor Update "update rollup config and axios to the latest" avax ``` - -## Using Typescript to update package dependencies in other library packages. +## Using Typescript to update package dependencies in other library packages. // For xchainjs packages, will search the library for matching args and update yarn updateDeps @@ -38,7 +36,7 @@ yarn updateDeps client 0.13.7 ### For other packages -For all other package deps flag last arg for script to search for non xchainjs packages +For all other package deps flag last arg for script to search for non xchainjs packages yarn updateDeps @@ -46,4 +44,8 @@ yarn updateDeps yarn updateDeps @psf/bitcoincashjs-lib 4.0.3 true ``` +### For version comparison between published version & current xchainjs Master version +``` +yarn checkVersion +``` diff --git a/scripts/checkVersionPublished.ts b/scripts/checkVersionPublished.ts new file mode 100644 index 000000000..19f6b9ac6 --- /dev/null +++ b/scripts/checkVersionPublished.ts @@ -0,0 +1,75 @@ +const { execSync } = require('child_process') +const fs = require('fs') +const path = require('path') + +interface SimplePackageJson { + name: string + version: string +} + +function getLatestVersion(packageName: string): string { + try { + return execSync(`npm show ${packageName} version`, { encoding: 'utf-8' }).trim() + } catch (e) { + return 'unavailable' + } +} + +const publishCommands: string[] = [] + +function compareVersions(packagePath: string, packageName: string, currentVersion: string): void { + const latestVersion = getLatestVersion(packageName) + if (latestVersion === 'unavailable') { + console.log(`Unable to fetch latest version for ${packageName}.`) + return + } + + if (currentVersion !== latestVersion) { + const relativePath = path.relative(process.cwd(), packagePath) + const publishCommand = `(cd ${relativePath} && npm publish)` + + console.log( + `Publish new version for ${packageName} in ${packagePath} from npm version ${latestVersion} to ${currentVersion}`, + ) + publishCommands.push(publishCommand) + } +} +function checkPackageJson(packagePath: string): void { + const packageJsonPath = path.join(packagePath, 'package.json') + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')) as SimplePackageJson + + const { name, version } = packageJson + compareVersions(packagePath, name, version) +} + +function getPackagePaths(directoryPath: string): string[] { + const files = fs.readdirSync(directoryPath) + const packagePaths: string[] = [] + + for (const file of files) { + const filePath = path.join(directoryPath, file) + const fileStat = fs.statSync(filePath) + if (fileStat.isDirectory() && fs.existsSync(path.join(filePath, 'package.json'))) { + packagePaths.push(filePath) + } else if (fileStat.isDirectory()) { + packagePaths.push(...getPackagePaths(filePath)) + } + } + + return packagePaths +} + +function main(): void { + const packagesPath = path.join(__dirname, '..', 'packages') + const packagePaths = getPackagePaths(packagesPath) + + for (const packagePath of packagePaths) { + checkPackageJson(packagePath) + } + if (publishCommands.length > 0) { + console.log('\nPublish Commands:') + console.log(publishCommands.join('\n')) + } +} + +main()