diff --git a/src/AssetTransferApi.spec.ts b/src/AssetTransferApi.spec.ts index 03e544dc..9d89498d 100644 --- a/src/AssetTransferApi.spec.ts +++ b/src/AssetTransferApi.spec.ts @@ -423,7 +423,7 @@ describe('AssetTransferAPI', () => { injectedRegistry, }); - expect(mockSystemAssetsApi._opts.injectedRegistry).toStrictEqual(injectedRegistry); + expect(mockSystemAssetsApi.opts.injectedRegistry).toStrictEqual(injectedRegistry); }); }); diff --git a/src/AssetTransferApi.ts b/src/AssetTransferApi.ts index 22bbd141..8a12a135 100644 --- a/src/AssetTransferApi.ts +++ b/src/AssetTransferApi.ts @@ -88,12 +88,12 @@ import { validateNumber } from './validate'; * @constructor opts AssetTransferApiOpts */ export class AssetTransferApi { - readonly _api: ApiPromise; - readonly _opts: AssetTransferApiOpts; - readonly _specName: string; - readonly _safeXcmVersion: number; - readonly _nativeRelayChainAsset: string; - readonly _originChainId: string; + readonly api: ApiPromise; + readonly opts: AssetTransferApiOpts; + readonly specName: string; + readonly safeXcmVersion: number; + readonly nativeRelayChainAsset: string; + readonly originChainId: string; private registryConfig: { registryInitialized: boolean; registryType: RegistryTypes; @@ -101,17 +101,17 @@ export class AssetTransferApi { public registry: Registry; constructor(api: ApiPromise, specName: string, safeXcmVersion: number, opts: AssetTransferApiOpts = {}) { - this._api = api; - this._opts = opts; - this._specName = specName; - this._safeXcmVersion = safeXcmVersion; + this.api = api; + this.opts = opts; + this.specName = specName; + this.safeXcmVersion = safeXcmVersion; this.registry = new Registry(specName, opts); this.registryConfig = { registryInitialized: false, registryType: opts.registryType ? opts.registryType : 'CDN', }; - this._nativeRelayChainAsset = this.registry.currentRelayRegistry[RELAY_CHAIN_IDS[0]].tokens[0]; - this._originChainId = this.registry.lookupChainIdBySpecName(this._specName); + this.nativeRelayChainAsset = this.registry.currentRelayRegistry[RELAY_CHAIN_IDS[0]].tokens[0]; + this.originChainId = this.registry.lookupChainIdBySpecName(this.specName); } /** @@ -172,18 +172,18 @@ export class AssetTransferApi { * Ensure that the options passed in are compatible with eachother. * It will throw an error if any are incorrect. */ - checkBaseInputOptions(opts, this._specName); + checkBaseInputOptions(opts, this.specName); /** * Ensure all the inputs are the corrects primitive and or object types. * It will throw an error if any are incorrect. */ checkBaseInputTypes(destChainId, destAddr, assetIds, amounts); - const { _api, _specName, _safeXcmVersion, _originChainId, registry } = this; + const { api, specName, safeXcmVersion, originChainId, registry } = this; const isLiquidTokenTransfer = transferLiquidToken === true; const chainOriginDestInfo = { - isOriginSystemParachain: SYSTEM_PARACHAINS_NAMES.includes(_specName.toLowerCase()), - isOriginParachain: isParachain(_originChainId), + isOriginSystemParachain: SYSTEM_PARACHAINS_NAMES.includes(specName.toLowerCase()), + isOriginParachain: isParachain(originChainId), isDestRelayChain: destChainId === RELAY_CHAIN_IDS[0], isDestSystemParachain: isSystemChain(destChainId), isDestParachain: isParachain(destChainId), @@ -195,13 +195,13 @@ export class AssetTransferApi { */ const addr = sanitizeAddress(destAddr); - const localTxChainType = this.establishLocalTxChainType(_originChainId, destChainId, chainOriginDestInfo); + const localTxChainType = this.establishLocalTxChainType(originChainId, destChainId, chainOriginDestInfo); const isLocalTx = localTxChainType !== LocalTxChainType.None; const xcmDirection = this.establishDirection(isLocalTx, chainOriginDestInfo); const isForeignAssetsTransfer: boolean = this.checkIsForeignAssetTransfer(assetIds); - const isPrimaryParachainNativeAsset = isParachainPrimaryNativeAsset(registry, _specName, xcmDirection, assetIds[0]); - const xcmPallet = establishXcmPallet(_api, xcmDirection, isForeignAssetsTransfer, isPrimaryParachainNativeAsset); - const declaredXcmVersion = xcmVersion === undefined ? _safeXcmVersion : xcmVersion; + const isPrimaryParachainNativeAsset = isParachainPrimaryNativeAsset(registry, specName, xcmDirection, assetIds[0]); + const xcmPallet = establishXcmPallet(api, xcmDirection, isForeignAssetsTransfer, isPrimaryParachainNativeAsset); + const declaredXcmVersion = xcmVersion === undefined ? safeXcmVersion : xcmVersion; checkXcmVersion(declaredXcmVersion); // Throws an error when the xcmVersion is not supported. /** @@ -226,14 +226,14 @@ export class AssetTransferApi { } const baseArgs = { - api: _api, + api: api, direction: xcmDirection as XcmDirection, destAddr: addr, assetIds, amounts, destChainId, xcmVersion: declaredXcmVersion, - specName: _specName, + specName: specName, registry: this.registry, }; @@ -255,7 +255,7 @@ export class AssetTransferApi { const assetType = this.fetchAssetType(xcmDirection, isForeignAssetsTransfer); const assetCallType = this.fetchCallType( - _originChainId, + originChainId, destChainId, assetIds, xcmDirection, @@ -308,7 +308,7 @@ export class AssetTransferApi { } } - return this.constructFormat(transaction, xcmDirection, declaredXcmVersion, txMethod, destChainId, _specName, { + return this.constructFormat(transaction, xcmDirection, declaredXcmVersion, txMethod, destChainId, specName, { format, paysWithFeeOrigin, sendersAddr, @@ -357,33 +357,33 @@ export class AssetTransferApi { tx: ConstructedFormat, format: T, ): Promise { - const { _api } = this; + const { api } = this; if (format === 'payload') { - const extrinsicPayload = _api.registry.createType('ExtrinsicPayload', tx, { + const extrinsicPayload = api.registry.createType('ExtrinsicPayload', tx, { version: EXTRINSIC_VERSION, }); - const ext = _api.registry.createType( + const ext = api.registry.createType( 'Extrinsic', { method: extrinsicPayload.method }, { version: EXTRINSIC_VERSION }, ); const u8a = ext.toU8a(); - return await _api.call.transactionPaymentApi.queryInfo(ext, u8a.length); + return await api.call.transactionPaymentApi.queryInfo(ext, u8a.length); } else if (format === 'call') { - const ext = _api.registry.createType('Extrinsic', { method: tx }, { version: EXTRINSIC_VERSION }); + const ext = api.registry.createType('Extrinsic', { method: tx }, { version: EXTRINSIC_VERSION }); const u8a = ext.toU8a(); - return await _api.call.transactionPaymentApi.queryInfo(ext, u8a.length); + return await api.call.transactionPaymentApi.queryInfo(ext, u8a.length); } else if (format === 'submittable') { - const ext = _api.registry.createType('Extrinsic', tx, { + const ext = api.registry.createType('Extrinsic', tx, { version: EXTRINSIC_VERSION, }); const u8a = ext.toU8a(); - return await _api.call.transactionPaymentApi.queryInfo(ext, u8a.length); + return await api.call.transactionPaymentApi.queryInfo(ext, u8a.length); } return null; @@ -400,26 +400,26 @@ export class AssetTransferApi { * @param format The format the tx is in */ public decodeExtrinsic(encodedTransaction: string, format: T): string { - const { _api } = this; + const { api } = this; const fmt = format ? format : 'payload'; if (fmt === 'payload') { - const extrinsicPayload = _api.registry.createType('ExtrinsicPayload', encodedTransaction, { + const extrinsicPayload = api.registry.createType('ExtrinsicPayload', encodedTransaction, { version: EXTRINSIC_VERSION, }); - const call = _api.registry.createType('Call', extrinsicPayload.method); + const call = api.registry.createType('Call', extrinsicPayload.method); const decodedMethodInfo = JSON.stringify(call.toHuman()); return decodedMethodInfo; } else if (fmt === 'call') { - const call = _api.registry.createType('Call', encodedTransaction); + const call = api.registry.createType('Call', encodedTransaction); const decodedMethodInfo = JSON.stringify(call.toHuman()); return decodedMethodInfo; } else if (fmt === 'submittable') { - const extrinsic = _api.registry.createType('Extrinsic', encodedTransaction); + const extrinsic = api.registry.createType('Extrinsic', encodedTransaction); const decodedMethodInfo = JSON.stringify(extrinsic.method.toHuman()); @@ -437,7 +437,7 @@ export class AssetTransferApi { private establishDirection(isLocal: boolean, chainOriginDestInfo: ChainOriginDestInfo): Direction { if (isLocal) return Direction.Local; - const { _api } = this; + const { api } = this; const { isDestParachain, isDestRelayChain, isDestSystemParachain, isOriginParachain, isOriginSystemParachain } = chainOriginDestInfo; @@ -459,11 +459,11 @@ export class AssetTransferApi { /** * Check if the origin is a Relay Chain */ - if (_api.query.paras && isDestSystemParachain) { + if (api.query.paras && isDestSystemParachain) { return Direction.RelayToSystem; } - if (_api.query.paras && isDestParachain) { + if (api.query.paras && isDestParachain) { return Direction.RelayToPara; } @@ -679,7 +679,7 @@ export class AssetTransferApi { // if a paysWithFeeOrigin is provided and the chain is of system origin // we assign the assetId to the value of paysWithFeeOrigin - const isOriginSystemParachain = SYSTEM_PARACHAINS_NAMES.includes(this._specName.toLowerCase()); + const isOriginSystemParachain = SYSTEM_PARACHAINS_NAMES.includes(this.specName.toLowerCase()); if (paysWithFeeOrigin && isOriginSystemParachain) { const isValidInt = validateNumber(paysWithFeeOrigin); @@ -699,7 +699,7 @@ export class AssetTransferApi { if (!isValidLpToken) { throw new BaseError( - `assetId ${JSON.stringify(feeAsset)} is not a valid liquidity pool token for ${this._specName}`, + `assetId ${JSON.stringify(feeAsset)} is not a valid liquidity pool token for ${this.specName}`, BaseErrorsEnum.NoFeeAssetLpFound, ); } @@ -708,24 +708,24 @@ export class AssetTransferApi { } } - const lastHeader = await this._api.rpc.chain.getHeader(); - const blockNumber = this._api.registry.createType('BlockNumber', lastHeader.number.toNumber()); + const lastHeader = await this.api.rpc.chain.getHeader(); + const blockNumber = this.api.registry.createType('BlockNumber', lastHeader.number.toNumber()); const method = tx.method; - const era = this._api.registry.createType('ExtrinsicEra', { + const era = this.api.registry.createType('ExtrinsicEra', { current: lastHeader.number.toNumber(), period: 64, }); - const nonce = await this._api.rpc.system.accountNextIndex(sendersAddr); + const nonce = await this.api.rpc.system.accountNextIndex(sendersAddr); const unsignedPayload: UnsignedTransaction = { - specVersion: this._api.runtimeVersion.specVersion.toHex(), - transactionVersion: this._api.runtimeVersion.transactionVersion.toHex(), + specVersion: this.api.runtimeVersion.specVersion.toHex(), + transactionVersion: this.api.runtimeVersion.transactionVersion.toHex(), assetId, address: sendersAddr, blockHash: lastHeader.hash.toHex(), blockNumber: blockNumber.toHex(), era: era.toHex(), - genesisHash: this._api.genesisHash.toHex(), + genesisHash: this.api.genesisHash.toHex(), method: method.toHex(), nonce: nonce.toHex(), signedExtensions: [ @@ -738,11 +738,11 @@ export class AssetTransferApi { 'CheckWeight', 'ChargeTransactionPayment', ], - tip: this._api.registry.createType('Compact', 0).toHex(), + tip: this.api.registry.createType('Compact', 0).toHex(), version: tx.version, }; - const extrinsicPayload = this._api.registry.createType('ExtrinsicPayload', unsignedPayload, { + const extrinsicPayload = this.api.registry.createType('ExtrinsicPayload', unsignedPayload, { version: unsignedPayload.version, }); @@ -758,7 +758,7 @@ export class AssetTransferApi { */ private checkAssetIsSufficient = async (assetId: BN): Promise => { try { - const asset = (await this._api.query.assets.asset(assetId)).unwrap(); + const asset = (await this.api.query.assets.asset(assetId)).unwrap(); if (asset.isSufficient.toString().toLowerCase() === 'true') { return true; @@ -832,9 +832,9 @@ export class AssetTransferApi { ); } - if (this._api.query.assetConversion !== undefined) { + if (this.api.query.assetConversion !== undefined) { try { - for (const poolPairsData of await this._api.query.assetConversion.pools.entries()) { + for (const poolPairsData of await this.api.query.assetConversion.pools.entries()) { const poolStorageKeyData = poolPairsData[0]; // remove any commas from multilocation key values e.g. Parachain: 2,125 -> Parachain: 2125 @@ -855,7 +855,7 @@ export class AssetTransferApi { } } catch (e) { throw new BaseError( - `error querying ${this._specName} liquidity token pool assets: ${e as string}`, + `error querying ${this.specName} liquidity token pool assets: ${e as string}`, BaseErrorsEnum.InternalError, ); } @@ -873,7 +873,7 @@ export class AssetTransferApi { if (isOriginSystemParachain && isDestSystemParachain && originChainId === destChainId) { return LocalTxChainType.System; - } else if (destChainId === '0' && RELAY_CHAIN_NAMES.includes(this._specName.toLowerCase())) { + } else if (destChainId === '0' && RELAY_CHAIN_NAMES.includes(this.specName.toLowerCase())) { return LocalTxChainType.Relay; } else if (isOriginParachain && isDestParachain && originChainId === destChainId) { return LocalTxChainType.Parachain; @@ -892,12 +892,12 @@ export class AssetTransferApi { localTxChainType: LocalTxChainType, opts: LocalTxOpts, ) { - const { _api, _specName } = this; + const { api, specName } = this; let assetId = assetIds[0]; const amount = amounts[0]; const isValidNumber = validateNumber(assetId); let isNativeRelayChainAsset = false; - if (assetIds.length === 0 || this._nativeRelayChainAsset.toLowerCase() === assetId.toLowerCase()) { + if (assetIds.length === 0 || this.nativeRelayChainAsset.toLowerCase() === assetId.toLowerCase()) { isNativeRelayChainAsset = true; } @@ -906,10 +906,10 @@ export class AssetTransferApi { // check for the general index of the assetId and assign the correct value for the local tx // throws an error if the general index is not found assetId = await getAssetId( - this._api, + this.api, this.registry, assetId, - this._specName, + this.specName, declaredXcmVersion, opts.isForeignAssetsTransfer, ); @@ -918,10 +918,10 @@ export class AssetTransferApi { if (localTxChainType === LocalTxChainType.System) { const localAssetType = await checkLocalSystemParachainInput( - this._api, + this.api, assetIds, amounts, - this._specName, + this.specName, this.registry, declaredXcmVersion, opts.isForeignAssetsTransfer, @@ -933,35 +933,35 @@ export class AssetTransferApi { if (localAssetType === LocalTxType.Balances) { tx = method === 'transferKeepAlive' - ? balances.transferKeepAlive(_api, addr, amount) - : balances.transfer(_api, addr, amount); + ? balances.transferKeepAlive(api, addr, amount) + : balances.transfer(api, addr, amount); palletMethod = `balances::${method}`; } else if (localAssetType === LocalTxType.Assets) { tx = method === 'transferKeepAlive' - ? assets.transferKeepAlive(_api, addr, assetId, amount) - : assets.transfer(_api, addr, assetId, amount); + ? assets.transferKeepAlive(api, addr, assetId, amount) + : assets.transfer(api, addr, assetId, amount); palletMethod = `assets::${method}`; } else if (localAssetType === LocalTxType.PoolAssets) { tx = method === 'transferKeepAlive' - ? poolAssets.transferKeepAlive(_api, addr, assetId, amount) - : poolAssets.transfer(_api, addr, assetId, amount); + ? poolAssets.transferKeepAlive(api, addr, assetId, amount) + : poolAssets.transfer(api, addr, assetId, amount); palletMethod = `poolAssets::${method}`; } else { const multiLocation = resolveMultiLocation(assetId, declaredXcmVersion); tx = method === 'transferKeepAlive' - ? foreignAssets.transferKeepAlive(_api, addr, multiLocation, amount) - : foreignAssets.transfer(_api, addr, multiLocation, amount); + ? foreignAssets.transferKeepAlive(api, addr, multiLocation, amount) + : foreignAssets.transfer(api, addr, multiLocation, amount); palletMethod = `foreignAssets::${method}`; } - return await this.constructFormat(tx, 'local', null, palletMethod, destChainId, this._specName, { + return await this.constructFormat(tx, 'local', null, palletMethod, destChainId, this.specName, { ...opts, }); } else if (localTxChainType === LocalTxChainType.Parachain) { - const localAssetType = checkLocalParachainInput(_api, assetIds, amounts); + const localAssetType = checkLocalParachainInput(api, assetIds, amounts); /** * If no asset is passed in then it's assumed that its a balance transfer. * If an asset is passed in then it's a token transfer. @@ -970,18 +970,18 @@ export class AssetTransferApi { const palletMethod: LocalTransferTypes = `balances::${method}`; const tx = method === 'transferKeepAlive' - ? balances.transferKeepAlive(_api, addr, amount) - : balances.transfer(_api, addr, amount); - return this.constructFormat(tx, 'local', null, palletMethod, destChainId, _specName, { + ? balances.transferKeepAlive(api, addr, amount) + : balances.transfer(api, addr, amount); + return this.constructFormat(tx, 'local', null, palletMethod, destChainId, specName, { ...opts, }); } else if (localAssetType === LocalTxType.Tokens) { const palletMethod: LocalTransferTypes = `tokens::${method}`; const tx = method === 'transferKeepAlive' - ? tokens.transferKeepAlive(_api, addr, assetIds[0], amount) - : tokens.transfer(_api, addr, assetIds[0], amount); - return this.constructFormat(tx, 'local', null, palletMethod, destChainId, _specName, { + ? tokens.transferKeepAlive(api, addr, assetIds[0], amount) + : tokens.transfer(api, addr, assetIds[0], amount); + return this.constructFormat(tx, 'local', null, palletMethod, destChainId, specName, { ...opts, }); } else { @@ -998,9 +998,9 @@ export class AssetTransferApi { const palletMethod: LocalTransferTypes = `balances::${method}`; const tx = method === 'transferKeepAlive' - ? balances.transferKeepAlive(_api, addr, amount) - : balances.transfer(_api, addr, amount); - return this.constructFormat(tx, 'local', null, palletMethod, destChainId, _specName, { + ? balances.transferKeepAlive(api, addr, amount) + : balances.transfer(api, addr, amount); + return this.constructFormat(tx, 'local', null, palletMethod, destChainId, specName, { ...opts, }); } diff --git a/src/createXcmTypes/util/getAssetId.spec.ts b/src/createXcmTypes/util/getAssetId.spec.ts index 7d870c8b..8d55bd69 100644 --- a/src/createXcmTypes/util/getAssetId.spec.ts +++ b/src/createXcmTypes/util/getAssetId.spec.ts @@ -14,7 +14,7 @@ describe('getAssetId', () => { it('Should correctly return the integer assetId when given a valid native system chain token symbol', async () => { const expected = '10'; - const result = await getAssetId(systemAssetsApi._api, registry, 'USDC', 'statemine', 2, false); + const result = await getAssetId(systemAssetsApi.api, registry, 'USDC', 'statemine', 2, false); expect(result).toEqual(expected); }); @@ -22,22 +22,22 @@ describe('getAssetId', () => { it('Should correctly return the integer assetId when given a valid native system chain token assetId', async () => { const expected = '8'; - const result = await getAssetId(systemAssetsApi._api, registry, 'RMRK', 'statemine', 2, false); + const result = await getAssetId(systemAssetsApi.api, registry, 'RMRK', 'statemine', 2, false); expect(result).toEqual(expected); }); it('Should error when an asset id symbol is given that is not present in the registry or chain state', async () => { await expect(async () => { - await getAssetId(systemAssetsApi._api, registry, 'hello', 'statemine', 2, false); - }).rejects.toThrowError('assetId hello is not a valid symbol or integer asset id'); + await getAssetId(systemAssetsApi.api, registry, 'hello', 'statemine', 2, false); + }).rejects.toThrow('assetId hello is not a valid symbol or integer asset id'); }); it('Should correctly return the foreign asset multilocation when given a valid foreign asset multilocation', async () => { const multiLocation = '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; const expected = '{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'; - const result = await getAssetId(systemAssetsApi._api, registry, multiLocation, 'statemine', 2, true); + const result = await getAssetId(systemAssetsApi.api, registry, multiLocation, 'statemine', 2, true); expect(result).toEqual(expected); }); @@ -46,8 +46,8 @@ describe('getAssetId', () => { const multiLocation = '{"parents":"1","interior":{"X1":{"Parachain":"212500000"}}}'; await expect(async () => { - await getAssetId(systemAssetsApi._api, registry, multiLocation, 'statemine', 2, true); - }).rejects.toThrowError(`MultiLocation ${multiLocation} not found`); + await getAssetId(systemAssetsApi.api, registry, multiLocation, 'statemine', 2, true); + }).rejects.toThrow(`MultiLocation ${multiLocation} not found`); }); }); @@ -58,15 +58,15 @@ describe('getAssetId', () => { it('Should correctly return the xcAsset multilocation when given a valid asset symbol', async () => { const expected = '{"v1":{"parents":1,"interior":{"x2":[{"parachain":2023},{"palletInstance":10}]}}}'; - const result = await getAssetId(bifrostAssetsApi._api, registry, 'movr', 'bifrost', 2, false); + const result = await getAssetId(bifrostAssetsApi.api, registry, 'movr', 'bifrost', 2, false); expect(result).toEqual(expected); }); it('Should correctly error when given an invalid xcAsset symbol', async () => { await expect(async () => { - await getAssetId(bifrostAssetsApi._api, registry, 'TEST', 'bifrost', 2, true); - }).rejects.toThrowError(`parachain assetId TEST is not a valid symbol assetId in bifrost`); + await getAssetId(bifrostAssetsApi.api, registry, 'TEST', 'bifrost', 2, true); + }).rejects.toThrow(`parachain assetId TEST is not a valid symbol assetId in bifrost`); }); }); @@ -77,7 +77,7 @@ describe('getAssetId', () => { it('Should correctly return the xcAsset integer assetId when given a valid xcAsset symbol', async () => { const expected = '42259045809535163221576417993425387648'; - const result = await getAssetId(moonriverAssetsApi._api, registry, 'xcKSM', 'bifrost', 2, false); + const result = await getAssetId(moonriverAssetsApi.api, registry, 'xcKSM', 'bifrost', 2, false); expect(result).toEqual(expected); }); @@ -86,7 +86,7 @@ describe('getAssetId', () => { const expected = '42259045809535163221576417993425387648'; const result = await getAssetId( - moonriverAssetsApi._api, + moonriverAssetsApi.api, registry, '42259045809535163221576417993425387648', 'moonriver', @@ -99,13 +99,13 @@ describe('getAssetId', () => { it('Should correctly error when given an invalid xcAsset symbol', async () => { await expect(async () => { - await getAssetId(moonriverAssetsApi._api, registry, 'TEST', 'moonriver', 2, true); + await getAssetId(moonriverAssetsApi.api, registry, 'TEST', 'moonriver', 2, true); }).rejects.toThrowError(`parachain assetId TEST is not a valid symbol assetIid in moonriver`); }); it('Should correctly error when given an invalid integer xcAssetId', async () => { await expect(async () => { - await getAssetId(moonriverAssetsApi._api, registry, '25830838603860', 'moonriver', 2, true); + await getAssetId(moonriverAssetsApi.api, registry, '25830838603860', 'moonriver', 2, true); }).rejects.toThrowError(`parachain assetId 25830838603860 is not a valid integer assetIid in moonriver`); }); }); diff --git a/src/createXcmTypes/util/getAssetId.ts b/src/createXcmTypes/util/getAssetId.ts index 4432e5a1..aa1ed55d 100644 --- a/src/createXcmTypes/util/getAssetId.ts +++ b/src/createXcmTypes/util/getAssetId.ts @@ -23,7 +23,7 @@ import { foreignAssetsMultiLocationExists } from './foreignAssetsMultiLocationEx * @param isForeignAssetsTransfer boolean */ export const getAssetId = async ( - _api: ApiPromise, + api: ApiPromise, registry: Registry, asset: string, specName: string, @@ -81,7 +81,7 @@ export const getAssetId = async ( if (multiLocationIsInRegistry) { assetId = asset; } else { - const isValidForeignAsset = await foreignAssetsMultiLocationExists(_api, registry, asset, xcmVersion); + const isValidForeignAsset = await foreignAssetsMultiLocationExists(api, registry, asset, xcmVersion); if (!isValidForeignAsset) { throw new BaseError(`MultiLocation ${asset} not found`, BaseErrorsEnum.AssetNotFound); @@ -96,11 +96,11 @@ export const getAssetId = async ( assetId = tokens[0]; } else if (assetIsValidInt) { - const maybeAsset = await _api.query.assets.asset(asset); + const maybeAsset = await api.query.assets.asset(asset); if (maybeAsset.isSome) { assetId = asset; - const assetMetadata = await _api.query.assets.metadata(asset); + const assetMetadata = await api.query.assets.metadata(asset); const assetSymbol = assetMetadata.symbol.toHuman()?.toString(); if (assetSymbol) { @@ -129,16 +129,16 @@ export const getAssetId = async ( ); } - if (_api.query.assets) { + if (api.query.assets) { if (!assetIsValidInt) { // if not assetHub and assetId isnt a number, query the parachain for the asset symbol - const parachainAssets = await _api.query.assets.asset.entries(); + const parachainAssets = await api.query.assets.asset.entries(); for (let i = 0; i < parachainAssets.length; i++) { const parachainAsset = parachainAssets[i]; const id = parachainAsset[0].args[0]; - const metadata = await _api.query.assets.metadata(id); + const metadata = await api.query.assets.metadata(id); if (metadata.symbol.toHuman()?.toString().toLowerCase() === asset.toLowerCase()) { assetId = id.toString(); // add queried asset to registry @@ -170,7 +170,7 @@ export const getAssetId = async ( } } else { // if not assetHub and assetId is a number, query the parachain for the asset - const parachainAsset = await _api.query.assets.asset(asset); + const parachainAsset = await api.query.assets.asset(asset); if (parachainAsset.isSome) { assetId = asset; // add queried asset to registry diff --git a/src/createXcmTypes/util/getXcAssetMultiLocationByAssetId.spec.ts b/src/createXcmTypes/util/getXcAssetMultiLocationByAssetId.spec.ts index 2ca4790a..e7a40296 100644 --- a/src/createXcmTypes/util/getXcAssetMultiLocationByAssetId.spec.ts +++ b/src/createXcmTypes/util/getXcAssetMultiLocationByAssetId.spec.ts @@ -45,7 +45,7 @@ describe('getXcAssetMultiLocationByAssetId', () => { const expected = '{"v1":{"parents":1,"interior":{"x3":[{"parachain":1000},{"palletInstance":50},{"generalIndex":1984}]}}}'; const result = await getXcAssetMultiLocationByAssetId( - bifrostApi._api, + bifrostApi.api, assetId, specName, xcmVersion, @@ -61,7 +61,7 @@ describe('getXcAssetMultiLocationByAssetId', () => { const specName = 'bifrost'; await expect(async () => { - await getXcAssetMultiLocationByAssetId(bifrostApi._api, assetId, specName, xcmVersion, bifrostRegistry); + await getXcAssetMultiLocationByAssetId(bifrostApi.api, assetId, specName, xcmVersion, bifrostRegistry); }).rejects.toThrowError(`parachain assetId vmover is not a valid symbol assetId in bifrost`); }); }); @@ -90,7 +90,7 @@ describe('getXcAssetMultiLocationByAssetId', () => { const expected = '{"v1":{"parents":1,"interior":{"x2":[{"parachain":2001},{"generalKey":"0x010a"}]}}}'; const result = await getXcAssetMultiLocationByAssetId( - moonriverApi._api, + moonriverApi.api, assetId, specName, xcmVersion, @@ -107,7 +107,7 @@ describe('getXcAssetMultiLocationByAssetId', () => { const expected = '{"v1":{"parents":1,"interior":{"x2":[{"parachain":2001},{"generalKey":"0x0101"}]}}}'; const result = await getXcAssetMultiLocationByAssetId( - moonriverApi._api, + moonriverApi.api, assetId, specName, xcmVersion, @@ -123,7 +123,7 @@ describe('getXcAssetMultiLocationByAssetId', () => { const specName = 'moonriver'; await expect(async () => { - await getXcAssetMultiLocationByAssetId(moonriverApi._api, assetId, specName, xcmVersion, moonriverRegistry); + await getXcAssetMultiLocationByAssetId(moonriverApi.api, assetId, specName, xcmVersion, moonriverRegistry); }).rejects.toThrowError(`parachain assetId mover is not a valid symbol assetIid in moonriver`); }); @@ -133,7 +133,7 @@ describe('getXcAssetMultiLocationByAssetId', () => { const specName = 'moonriver'; await expect(async () => { - await getXcAssetMultiLocationByAssetId(moonriverApi._api, assetId, specName, xcmVersion, moonriverRegistry); + await getXcAssetMultiLocationByAssetId(moonriverApi.api, assetId, specName, xcmVersion, moonriverRegistry); }).rejects.toThrowError(`assetId 242424332422323423424 is not a valid symbol or integer asset id for moonriver`); }); }); diff --git a/src/errors/checkLocalTxInput/checkLocalTxInput.spec.ts b/src/errors/checkLocalTxInput/checkLocalTxInput.spec.ts index b9e002ce..44c57c93 100644 --- a/src/errors/checkLocalTxInput/checkLocalTxInput.spec.ts +++ b/src/errors/checkLocalTxInput/checkLocalTxInput.spec.ts @@ -12,49 +12,49 @@ describe('checkLocalTxInput', () => { const systemAssetsApi = new AssetTransferApi(adjustedMockSystemApi, 'statemine', 2); it('Should correctly return Balances with an empty assetIds', async () => { - const res = await checkLocalTxInput(systemAssetsApi._api, [], ['10000'], specName, registry, 2, false, false); + const res = await checkLocalTxInput(systemAssetsApi.api, [], ['10000'], specName, registry, 2, false, false); expect(res).toEqual('Balances'); }); it('Should correctly return Balances with a native token', async () => { - const res = await checkLocalTxInput(systemAssetsApi._api, ['KSM'], ['10000'], specName, registry, 2, false, false); + const res = await checkLocalTxInput(systemAssetsApi.api, ['KSM'], ['10000'], specName, registry, 2, false, false); expect(res).toEqual('Balances'); }); it('Should correctly return Balances with an empty string assetId', async () => { - const res = await checkLocalTxInput(systemAssetsApi._api, [''], ['10000'], specName, registry, 2, false, false); + const res = await checkLocalTxInput(systemAssetsApi.api, [''], ['10000'], specName, registry, 2, false, false); expect(res).toEqual('Balances'); }); it('Should correctly return Assets with a valid assetId', async () => { - const res = await checkLocalTxInput(systemAssetsApi._api, ['1984'], ['10000'], specName, registry, 2, false, false); + const res = await checkLocalTxInput(systemAssetsApi.api, ['1984'], ['10000'], specName, registry, 2, false, false); expect(res).toEqual('Assets'); }); it('Should correctly throw an error for incorrect length on `assetIds`', async () => { await expect(async () => { - await checkLocalTxInput(systemAssetsApi._api, ['1', '2'], ['10000'], specName, registry, 2, false, false); + await checkLocalTxInput(systemAssetsApi.api, ['1', '2'], ['10000'], specName, registry, 2, false, false); }).rejects.toThrowError( 'Local transactions must have the `assetIds` input be a length of 1 or 0, and the `amounts` input be a length of 1', ); }); it('Should correctly throw an error for incorrect length on `amounts`', async () => { await expect(async () => { - await checkLocalTxInput(systemAssetsApi._api, ['1'], ['10000', '20000'], specName, registry, 2, false, false); + await checkLocalTxInput(systemAssetsApi.api, ['1'], ['10000', '20000'], specName, registry, 2, false, false); }).rejects.toThrowError( 'Local transactions must have the `assetIds` input be a length of 1 or 0, and the `amounts` input be a length of 1', ); }); it('Should correctly throw an error with an incorrect assetId', async () => { await expect(async () => { - await checkLocalTxInput(systemAssetsApi._api, ['TST'], ['10000'], specName, registry, 2, false, false); + await checkLocalTxInput(systemAssetsApi.api, ['TST'], ['10000'], specName, registry, 2, false, false); }).rejects.toThrowError('assetId TST is not a valid symbol or integer asset id for statemine'); }); it("Should correctly throw an error when the integer assetId doesn't exist", async () => { await expect(async () => { - await checkLocalTxInput(systemAssetsApi._api, ['9876111'], ['10000'], specName, registry, 2, false, false); + await checkLocalTxInput(systemAssetsApi.api, ['9876111'], ['10000'], specName, registry, 2, false, false); }).rejects.toThrowError('general index for assetId 9876111 was not found'); }); it('Should correctly return ForeignAssets when given a valid multilocation', async () => { const res = await checkLocalTxInput( - systemAssetsApi._api, + systemAssetsApi.api, ['{"parents":"1","interior":{"X2": [{"Parachain":"2125"}, {"GeneralIndex": "0"}]}}'], ['10000'], specName, @@ -72,7 +72,7 @@ describe('checkLocalTxInput', () => { await expect(async () => { await checkLocalTxInput( - systemAssetsApi._api, + systemAssetsApi.api, [incorrectMultiLocationStr], ['10000'], specName, @@ -90,7 +90,7 @@ describe('checkLocalTxInput', () => { await expect(async () => { await checkLocalTxInput( - systemAssetsApi._api, + systemAssetsApi.api, [nonExistentMultiLocationStr], ['10000'], specName, @@ -106,7 +106,7 @@ describe('checkLocalTxInput', () => { const expectedError = 'Local foreignAsset transactions must have the `assetIds` input be a length of 1'; await expect(async () => { - await checkLocalTxInput(systemAssetsApi._api, [], ['10000'], specName, registry, 2, true, false); + await checkLocalTxInput(systemAssetsApi.api, [], ['10000'], specName, registry, 2, true, false); }).rejects.toThrowError(expectedError); }); }); diff --git a/src/errors/checkXcmTxInputs.spec.ts b/src/errors/checkXcmTxInputs.spec.ts index a3c312b4..5a3fe188 100644 --- a/src/errors/checkXcmTxInputs.spec.ts +++ b/src/errors/checkXcmTxInputs.spec.ts @@ -34,7 +34,7 @@ const runTests = async (tests: Test[]) => { await expect(async () => { await checkAssetIdInput( - parachainAssetsApi._api, + parachainAssetsApi.api, testInputs, currentRegistry, specName, @@ -236,7 +236,7 @@ describe('checkAssetIds', () => { await expect(async () => { await checkAssetIdInput( - parachainAssetsApi._api, + parachainAssetsApi.api, testInputs, currentRegistry, specName, @@ -338,7 +338,7 @@ describe('checkAssetIds', () => { const currentRegistry = registry.currentRelayRegistry; await expect(async () => { await checkAssetIdInput( - parachainAssetsApi._api, + parachainAssetsApi.api, testInputs, currentRegistry, specName, @@ -374,7 +374,7 @@ describe('checkAssetIds', () => { await expect(async () => { await checkAssetIdInput( - parachainAssetsApi._api, + parachainAssetsApi.api, testInputs, currentRegistry, specName, @@ -393,7 +393,7 @@ describe('checkAssetIds', () => { await expect(async () => { await checkAssetIdInput( - parachainAssetsApi._api, + parachainAssetsApi.api, ['0x1234'], currentRegistry, 'moonriver', diff --git a/src/util/getFeeAssetItemIndex.spec.ts b/src/util/getFeeAssetItemIndex.spec.ts index 832a7397..ffdaf6b1 100644 --- a/src/util/getFeeAssetItemIndex.spec.ts +++ b/src/util/getFeeAssetItemIndex.spec.ts @@ -53,7 +53,7 @@ describe('getFeeAssetItemIndex', () => { }, }, ], - systemAssetsApi._api, + systemAssetsApi.api, 1, ], [ @@ -98,7 +98,7 @@ describe('getFeeAssetItemIndex', () => { }, }, ], - systemAssetsApi._api, + systemAssetsApi.api, 2, ], ]; @@ -156,7 +156,7 @@ describe('getFeeAssetItemIndex', () => { }, }, ], - relayAssetsApi._api, + relayAssetsApi.api, 1, ], [ @@ -201,7 +201,7 @@ describe('getFeeAssetItemIndex', () => { }, }, ], - relayAssetsApi._api, + relayAssetsApi.api, 1, ], ]; @@ -235,7 +235,7 @@ describe('getFeeAssetItemIndex', () => { }, }, ], - systemAssetsApi._api, + systemAssetsApi.api, 0, ], ]; @@ -281,7 +281,7 @@ describe('getFeeAssetItemIndex', () => { ]; await expect(async () => { - await getFeeAssetItemIndex(systemAssetsApi._api, registry, paysWithFeeDest, multiAssets, specName, 2, false); + await getFeeAssetItemIndex(systemAssetsApi.api, registry, paysWithFeeDest, multiAssets, specName, 2, false); }).rejects.toThrowError( 'Invalid paysWithFeeDest value. 1984 did not match any asset in assets: {"X2":[{"PalletInstance":"50"},{"GeneralIndex":"1337"}]},{"Here":""}', );