diff --git a/src/index.ts b/src/index.ts index 7ec8165..ed177cc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -119,9 +119,7 @@ export class Squid extends TokensChains { return { ...data, requestId, integratorId }; } - async getRoute( - params: RouteRequest - ): Promise { + async getRoute(params: RouteRequest): Promise { this.validateInit(); const { data, headers, status } = await this.httpInstance.post( @@ -218,7 +216,6 @@ export class Squid extends TokensChains { } } - // TODO: IS THIS METHOD GONNA BE EVM ONLY ? public getRawTxHex( data: Omit & { nonce: number } ): string { @@ -228,58 +225,6 @@ export class Squid extends TokensChains { return this.handlers.evm.getRawTxHex({ ...data }); } - // INTERNAL PRIVATES METHODS - - private validateInit() { - if (!this.initialized) { - throw new Error( - "SquidSdk must be initialized! Please call the SquidSdk.init method" - ); - } - } - - private populateRouteParams( - params: RouteRequest, - signer?: EvmWallet - ): RouteParamsPopulated { - const { fromChain, toChain, fromToken, toToken } = params; - - const _fromChain = this.getChainData(fromChain); - const _toChain = this.getChainData(toChain); - const _fromToken = this.getTokenData(fromToken, fromChain); - const _toToken = this.getTokenData(toToken, toChain); - - const fromProvider = ethersAdapter.rpcProvider(_fromChain.rpc); - - const fromIsNative = _fromToken.address === nativeTokenConstant; - let fromTokenContract; - - if (!fromIsNative) { - fromTokenContract = ethersAdapter.contract( - _fromToken.address, - erc20Abi, - signer || fromProvider - ); - } - - return { - ...params, - fromChain: _fromChain, - toChain: _toChain, - fromToken: _fromToken, - toToken: _toToken, - fromTokenContract, - fromProvider, - fromIsNative - }; - } - - private validateTransactionRequest(route: RouteResponse["route"]) { - if (!route.transactionRequest) { - throw new Error("transactionRequest param not found in route object"); - } - } - public getFromAmount({ fromToken, toAmount, @@ -340,7 +285,7 @@ export class Squid extends TokensChains { }: { addresses: CosmosAddress[]; chainIds?: (string | number)[]; - }) { + }): Promise { const cosmosChains = this.chains.filter(c => c.chainType === ChainType.COSMOS && // if chainIds is not provided, return all cosmos chains @@ -406,4 +351,56 @@ export class Squid extends TokensChains { cosmosBalances }; } + + // INTERNAL PRIVATES METHODS + + private validateInit() { + if (!this.initialized) { + throw new Error( + "SquidSdk must be initialized! Please call the SquidSdk.init method" + ); + } + } + + private populateRouteParams( + params: RouteRequest, + signer?: EvmWallet + ): RouteParamsPopulated { + const { fromChain, toChain, fromToken, toToken } = params; + + const _fromChain = this.getChainData(fromChain); + const _toChain = this.getChainData(toChain); + const _fromToken = this.getTokenData(fromToken, fromChain); + const _toToken = this.getTokenData(toToken, toChain); + + const fromProvider = ethersAdapter.rpcProvider(_fromChain.rpc); + + const fromIsNative = _fromToken.address === nativeTokenConstant; + let fromTokenContract; + + if (!fromIsNative) { + fromTokenContract = ethersAdapter.contract( + _fromToken.address, + erc20Abi, + signer || fromProvider + ); + } + + return { + ...params, + fromChain: _fromChain, + toChain: _toChain, + fromToken: _fromToken, + toToken: _toToken, + fromTokenContract, + fromProvider, + fromIsNative + }; + } + + private validateTransactionRequest(route: RouteResponse["route"]) { + if (!route.transactionRequest) { + throw new Error("transactionRequest param not found in route object"); + } + } } diff --git a/src/types/index.ts b/src/types/index.ts index 065d094..da992f7 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -2,7 +2,7 @@ import { ChainData, Token, RouteRequest, - RouteResponse + RouteResponse as _RouteResponse } from "@0xsquid/squid-types"; import { SigningStargateClient } from "@cosmjs/stargate"; @@ -43,12 +43,17 @@ export type CosmosSigner = SigningStargateClient; export type ExecuteRoute = { signer: EvmWallet | CosmosSigner; - route: RouteResponse["route"]; + route: _RouteResponse["route"]; executionSettings?: ExecutionSettings; overrides?: OverrideParams; signerAddress?: string; // cosmos specific }; +export type RouteResponse = _RouteResponse & { + requestId?: string; + integratorId?: string; +}; + export type TransactionResponses = TransactionResponse | TxRaw; export type GetStatus = {