From 63df17ccabbc934bcfe15fb960e69cf20cbe7e2f Mon Sep 17 00:00:00 2001 From: Rikkard29 Date: Sun, 19 Nov 2023 11:38:55 +0100 Subject: [PATCH] =?UTF-8?q?Change=20type=20of=20amount=20parameter=20?= =?UTF-8?q?=F0=9F=96=8C=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/nodes/ParachainNode.ts | 2 +- src/pallets/builder/builders/Builder.ts | 4 +-- .../builder/builders/ParaToParaBuilder.ts | 4 +-- .../builder/builders/ParaToRelayBuilder.ts | 6 ++--- src/pallets/xcmPallet/transfer.ts | 27 ++++++++++++------- src/types.ts | 2 +- src/utils.ts | 2 +- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/nodes/ParachainNode.ts b/src/nodes/ParachainNode.ts index 68021de2..b7bb2c28 100644 --- a/src/nodes/ParachainNode.ts +++ b/src/nodes/ParachainNode.ts @@ -68,7 +68,7 @@ abstract class ParachainNode { api: ApiPromise, currencySymbol: string | undefined, currencyId: string | undefined, - amount: any, + amount: string, to: string, destination?: TNode, serializedApiCallEnabled = false diff --git a/src/pallets/builder/builders/Builder.ts b/src/pallets/builder/builders/Builder.ts index a0e77e9b..eb6c21d3 100644 --- a/src/pallets/builder/builders/Builder.ts +++ b/src/pallets/builder/builders/Builder.ts @@ -46,7 +46,7 @@ class FromGeneralBuilder { return new ToGeneralBuilder(this.api, this.from, node) } - amount(amount: any) { + amount(amount: string | number | bigint) { return ParaToRelayBuilder.create(this.api, this.from, amount) } @@ -105,5 +105,5 @@ export interface AddressBuilder { } export interface AmountBuilder { - amount(amount: any): AddressBuilder + amount(amount: string | number | bigint): AddressBuilder } diff --git a/src/pallets/builder/builders/ParaToParaBuilder.ts b/src/pallets/builder/builders/ParaToParaBuilder.ts index ef26340a..9f13e901 100644 --- a/src/pallets/builder/builders/ParaToParaBuilder.ts +++ b/src/pallets/builder/builders/ParaToParaBuilder.ts @@ -11,7 +11,7 @@ class ParaToParaBuilder implements AmountBuilder, AddressBuilder, FinalBuilder { private to: TNode private currency: string | number | bigint - private _amount: any + private _amount: string | number | bigint private _address: string private constructor(api: ApiPromise, from: TNode, to: TNode, currency: string | number | bigint) { @@ -30,7 +30,7 @@ class ParaToParaBuilder implements AmountBuilder, AddressBuilder, FinalBuilder { return new ParaToParaBuilder(api, from, to, currency) } - amount(amount: any) { + amount(amount: string | number | bigint) { this._amount = amount return this } diff --git a/src/pallets/builder/builders/ParaToRelayBuilder.ts b/src/pallets/builder/builders/ParaToRelayBuilder.ts index 68b71619..8eb30ce8 100644 --- a/src/pallets/builder/builders/ParaToRelayBuilder.ts +++ b/src/pallets/builder/builders/ParaToRelayBuilder.ts @@ -9,17 +9,17 @@ import { AddressBuilder, FinalBuilder } from './Builder' class ParaToRelayBuilder implements AddressBuilder, FinalBuilder { private api: ApiPromise private from: TNode - private amount: any + private amount: string | number | bigint private _address: string - private constructor(api: ApiPromise, from: TNode, amount: any) { + private constructor(api: ApiPromise, from: TNode, amount: string | number | bigint) { this.api = api this.from = from this.amount = amount } - static create(api: ApiPromise, from: TNode, amount: any): AddressBuilder { + static create(api: ApiPromise, from: TNode, amount: string | number | bigint): AddressBuilder { return new ParaToRelayBuilder(api, from, amount) } diff --git a/src/pallets/xcmPallet/transfer.ts b/src/pallets/xcmPallet/transfer.ts index 571a8a09..a6cdb777 100644 --- a/src/pallets/xcmPallet/transfer.ts +++ b/src/pallets/xcmPallet/transfer.ts @@ -19,7 +19,7 @@ const sendCommon = ( api: ApiPromise, origin: TNode, currencySymbolOrId: string | number | bigint, - amount: any, + amount: string, to: string, destination?: TNode, serializedApiCallEnabled = false @@ -68,7 +68,7 @@ export const sendSerializedApiCall = ( api: ApiPromise, origin: TNode, currencySymbolOrId: string | number | bigint, - amount: any, + amount: string | number | bigint, to: string, destination?: TNode ): TSerializedApiCall => { @@ -76,7 +76,7 @@ export const sendSerializedApiCall = ( api, origin, currencySymbolOrId, - amount, + amount.toString(), to, destination, true @@ -87,18 +87,25 @@ export function send( api: ApiPromise, origin: TNode, currencySymbolOrId: string | number | bigint, - amount: any, + amount: string | number | bigint, to: string, destination?: TNode ): Extrinsic { - return sendCommon(api, origin, currencySymbolOrId, amount, to, destination) as Extrinsic + return sendCommon( + api, + origin, + currencySymbolOrId, + amount.toString(), + to, + destination + ) as Extrinsic } // TODO: Refactor this function export const transferRelayToParaCommon = ( api: ApiPromise, destination: TNode, - amount: any, + amount: string, to: string, serializedApiCallEnabled = false ): Extrinsic | TSerializedApiCall | never => { @@ -177,16 +184,16 @@ export const transferRelayToParaCommon = ( export function transferRelayToPara( api: ApiPromise, destination: TNode, - amount: any, + amount: string | number | bigint, to: string ): Extrinsic | never { - return transferRelayToParaCommon(api, destination, amount, to) as Extrinsic | never + return transferRelayToParaCommon(api, destination, amount.toString(), to) as Extrinsic | never } export const transferRelayToParaSerializedApiCall = ( api: ApiPromise, destination: TNode, - amount: any, + amount: string | number | bigint, to: string ): TSerializedApiCall => - transferRelayToParaCommon(api, destination, amount, to, true) as TSerializedApiCall + transferRelayToParaCommon(api, destination, amount.toString(), to, true) as TSerializedApiCall diff --git a/src/types.ts b/src/types.ts index 1606bf06..9bbdb5e2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -45,7 +45,7 @@ export type XTokensTransferInput = { api: ApiPromise currency: string | undefined currencyID: string | undefined - amount: any + amount: string addressSelection: any fees: number scenario: TScenario diff --git a/src/utils.ts b/src/utils.ts index 3c3fd077..563bb30c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -107,7 +107,7 @@ export const generateAddressPayload = ( } export const createCurrencySpecification = ( - amount: any, + amount: string, scenario: TScenario, version: Version, node?: TNode,