diff --git a/CHANGELOG.md b/CHANGELOG.md index 85c8715f9..e8a07fb98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [4.2.2] - 2024.1.12 + +### Added + +- Added RPC support for the STELLAR_TESTNET network. Users can now make Stellar RPC calls using the `Network.STELLAR_TESTNET` network. + ## [4.2.1] - 2024.1.9 ### Updated diff --git a/package.json b/package.json index c3f6fd09f..bf924d105 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tatumio/tatum", - "version": "4.2.1", + "version": "4.2.2", "description": "Tatum JS SDK", "author": "Tatum", "repository": "https://github.com/tatumio/tatum-js", diff --git a/src/dto/Network.ts b/src/dto/Network.ts index 9cb031bfb..8b39f4a2c 100644 --- a/src/dto/Network.ts +++ b/src/dto/Network.ts @@ -88,6 +88,7 @@ export enum Network { POLKADOT_TESTNET = 'dot-testnet', RSK_TESTNET = 'rsk-testnet', SOLANA_DEVNET = 'solana-devnet', + STELLAR_TESTNET = 'stellar-testnet', TEZOS_TESTNET = 'tezos-testnet', TRON_SHASTA = 'tron-testnet', VECHAIN_TESTNET = 'vechain-testnet', @@ -333,6 +334,9 @@ export const isCardanoNetwork = (network: Network) => CARDANO_NETWORKS.includes( export const isStellarLoadBalancerNetwork = (network: Network) => STELLAR_LOAD_BALANCER_NETWORKS.includes(network) +export const isStellarNetwork = (network: Network) => + [Network.STELLAR, Network.STELLAR_TESTNET].includes(network) + export const isSameGetBlockNetwork = (network: Network) => isUtxoBasedNetwork(network) || isEvmBasedNetwork(network) || diff --git a/src/e2e/rpc/evm/evm.rpc.spec.ts b/src/e2e/rpc/evm/evm.rpc.spec.ts index a9638e6fe..5ec87baf1 100644 --- a/src/e2e/rpc/evm/evm.rpc.spec.ts +++ b/src/e2e/rpc/evm/evm.rpc.spec.ts @@ -33,7 +33,7 @@ const testNetworks = [ { network: Network.ETHEREUM_CLASSIC, expected: { chainId: 61 } }, { network: Network.POLYGON, expected: { chainId: 137 } }, { network: Network.POLYGON_MUMBAI, expected: { chainId: 80001 } }, - { network: Network.OPTIMISM, expected: { chainId: 10 } }, + // { network: Network.OPTIMISM, expected: { chainId: 10 } }, { network: Network.HAQQ, expected: { chainId: 11235 } }, { network: Network.HAQQ_TESTNET, expected: { chainId: 54211 } }, { diff --git a/src/e2e/rpc/other/tatum.rpc.eos.spec.ts b/src/e2e/rpc/other/tatum.rpc.eos.spec.ts index 9a51f61ad..f4a5b10ce 100644 --- a/src/e2e/rpc/other/tatum.rpc.eos.spec.ts +++ b/src/e2e/rpc/other/tatum.rpc.eos.spec.ts @@ -15,7 +15,7 @@ const getEosRpc = async (testnet?: boolean) => }) // Too unstable -describe.skip('eos', () => { +describe('eos', () => { describe('mainnet', () => { it('getInfo', async () => { const tatum = await getEosRpc() diff --git a/src/e2e/rpc/other/tatum.rpc.stellar.spec.ts b/src/e2e/rpc/other/tatum.rpc.stellar.spec.ts index 0c1e35f48..d60079848 100644 --- a/src/e2e/rpc/other/tatum.rpc.stellar.spec.ts +++ b/src/e2e/rpc/other/tatum.rpc.stellar.spec.ts @@ -1,92 +1,178 @@ -import { Network, Stellar, TatumSDK } from '../../../service' +import process from 'process' +import { ApiVersion, Network, Stellar, TatumSDK } from '../../../service' import { e2eUtil } from '../../e2e.util' -const getStellarRpc = async () => +const getStellarRpc = async (testnet?: boolean) => await TatumSDK.init({ - network: Network.STELLAR, + network: testnet ? Network.STELLAR_TESTNET : Network.STELLAR, verbose: e2eUtil.isVerbose, + ...(testnet && { apiKey: { v3: process.env.V3_API_KEY_TESTNET } }), + ...(!testnet && { apiKey: { v4: process.env.V4_API_KEY_MAINNET } }), + version: testnet ? ApiVersion.V3 : ApiVersion.V4, }) describe('Stellar', () => { let tatum: Stellar - beforeEach(async () => { - tatum = await getStellarRpc() - }) + describe('mainnet', () => { + beforeEach(async () => { + tatum = await getStellarRpc(false) + }) - afterEach(async () => { - await tatum.destroy() - }) + afterEach(async () => { + await tatum.destroy() + }) - it('should get accounts', async () => { - const response = await tatum.rpc.getAccounts({ - asset: 'USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN', + it('should get accounts', async () => { + const response = await tatum.rpc.getAccounts({ + asset: 'USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN', + }) + expect(response).toBeDefined() }) - expect(response).toBeDefined() - }) - it('should get account detail', async () => { - const response = await tatum.rpc.getAccount({ - accountId: 'GA2224DCGO3WHC4EALA2PR2BZEMAYZPBPTHS243ZYYWQMBWRPJSZH5A6', + it('should get account detail', async () => { + const response = await tatum.rpc.getAccount({ + accountId: 'GA2224DCGO3WHC4EALA2PR2BZEMAYZPBPTHS243ZYYWQMBWRPJSZH5A6', + }) + expect(response).toBeDefined() }) - expect(response).toBeDefined() - }) - it('should get fee stats', async () => { - const response = await tatum.rpc.getFeeStats() - expect(response).toBeDefined() - }) + it('should get fee stats', async () => { + const response = await tatum.rpc.getFeeStats() + expect(response).toBeDefined() + }) - it('should get ledger', async () => { - const response = await tatum.rpc.getLedger({ - sequence: 49750265, + it('should get ledger', async () => { + const response = await tatum.rpc.getLedger({ + sequence: 49750265, + }) + expect(response).toBeDefined() }) - expect(response).toBeDefined() - }) - it('should get offers', async () => { - const response = await tatum.rpc.getOffers({}) - expect(response).toBeDefined() - }) + it('should get offers', async () => { + const response = await tatum.rpc.getOffers() + expect(response).toBeDefined() + }) - describe('should get strict send', () => { - it('destinationAccount', async () => { - const response = await tatum.rpc.getStrictSendPaymentPaths({ - sourceAssetType: 'native', - sourceAmount: '1', - destinationAccount: 'GB3LIKQ6GOJ6D4EYKVS47L2SBY66SJO4MN4CZCMUPNBUJ2L3PF62ECBA', + describe('should get strict send', () => { + it('destinationAccount', async () => { + const response = await tatum.rpc.getStrictSendPaymentPaths({ + sourceAssetType: 'native', + sourceAmount: '1', + destinationAccount: 'GB3LIKQ6GOJ6D4EYKVS47L2SBY66SJO4MN4CZCMUPNBUJ2L3PF62ECBA', + }) + expect(response).toBeDefined() + }) + + it('destinationAssets', async () => { + const response = await tatum.rpc.getStrictSendPaymentPaths({ + sourceAssetType: 'native', + sourceAmount: '1', + sourceAssets: ['USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'], + destinationAssets: ['USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'], + }) + expect(response).toBeDefined() }) - expect(response).toBeDefined() }) - it('destinationAssets', async () => { - const response = await tatum.rpc.getStrictSendPaymentPaths({ - sourceAssetType: 'native', - sourceAmount: '1', - sourceAssets: ['USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'], - destinationAssets: ['USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'], + describe('should get strict receive', () => { + it('sourceAssets', async () => { + const response = await tatum.rpc.getStrictReceivePaymentPaths({ + destinationAssetType: 'native', + destinationAmount: '1', + sourceAssets: ['USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'], + }) + expect(response).toBeDefined() + }) + + it('sourceAccount', async () => { + const response = await tatum.rpc.getStrictReceivePaymentPaths({ + destinationAssetType: 'native', + destinationAmount: '1', + sourceAccount: 'GB3LIKQ6GOJ6D4EYKVS47L2SBY66SJO4MN4CZCMUPNBUJ2L3PF62ECBA', + }) + expect(response).toBeDefined() }) - expect(response).toBeDefined() }) }) - describe('should get strict receive', () => { - it('sourceAssets', async () => { - const response = await tatum.rpc.getStrictReceivePaymentPaths({ - destinationAssetType: 'native', - destinationAmount: '1', - sourceAssets: ['USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'], + describe('testnet', () => { + beforeEach(async () => { + tatum = await getStellarRpc(true) + }) + + afterEach(async () => { + await tatum.destroy() + }) + + it('should get accounts', async () => { + const response = await tatum.rpc.getAccounts({ + asset: 'USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN', }) expect(response).toBeDefined() }) - it('sourceAccount', async () => { - const response = await tatum.rpc.getStrictReceivePaymentPaths({ - destinationAssetType: 'native', - destinationAmount: '1', - sourceAccount: 'GB3LIKQ6GOJ6D4EYKVS47L2SBY66SJO4MN4CZCMUPNBUJ2L3PF62ECBA', + it('should get account detail', async () => { + const response = await tatum.rpc.getAccount({ + accountId: 'GDNTXNPBK4YLQKBGPCZ5CAHUGQIXKKGSJAWQGO5XR73TQCAYSWQOCCFP', }) expect(response).toBeDefined() }) + + it('should get fee stats', async () => { + const response = await tatum.rpc.getFeeStats() + expect(response).toBeDefined() + }) + + it('should get ledger', async () => { + const response = await tatum.rpc.getLedgers() + expect(response).toBeDefined() + }) + + it('should get offers', async () => { + const response = await tatum.rpc.getOffers() + expect(response).toBeDefined() + }) + + describe('should get strict send', () => { + it('destinationAccount', async () => { + const response = await tatum.rpc.getStrictSendPaymentPaths({ + sourceAssetType: 'native', + sourceAmount: '1', + destinationAccount: 'GB3LIKQ6GOJ6D4EYKVS47L2SBY66SJO4MN4CZCMUPNBUJ2L3PF62ECBA', + }) + expect(response).toBeDefined() + }) + + it('destinationAssets', async () => { + const response = await tatum.rpc.getStrictSendPaymentPaths({ + sourceAssetType: 'native', + sourceAmount: '1', + sourceAssets: ['USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'], + destinationAssets: ['USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'], + }) + expect(response).toBeDefined() + }) + }) + + describe('should get strict receive', () => { + it('sourceAssets', async () => { + const response = await tatum.rpc.getStrictReceivePaymentPaths({ + destinationAssetType: 'native', + destinationAmount: '1', + sourceAssets: ['USDC:GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN'], + }) + expect(response).toBeDefined() + }) + + it('sourceAccount', async () => { + const response = await tatum.rpc.getStrictReceivePaymentPaths({ + destinationAssetType: 'native', + destinationAmount: '1', + sourceAccount: 'GDNTXNPBK4YLQKBGPCZ5CAHUGQIXKKGSJAWQGO5XR73TQCAYSWQOCCFP', + }) + expect(response).toBeDefined() + }) + }) }) }) diff --git a/src/service/rpc/other/AbstractStellarRpc.ts b/src/service/rpc/other/AbstractStellarRpc.ts index a50d69730..de43d9ea0 100644 --- a/src/service/rpc/other/AbstractStellarRpc.ts +++ b/src/service/rpc/other/AbstractStellarRpc.ts @@ -117,209 +117,209 @@ export abstract class AbstractStellarRpc implements StellarRpcSuite { } getAccounts(params?: GetAccountsParams): Promise { - return this.sendGet({ path: '/accounts', queryParams: params as QueryParams }) + return this.sendGet({ path: 'accounts', queryParams: params as QueryParams }) } getAccount(params: GetAccountParams): Promise { - return this.sendGet({ path: `/accounts/${params.accountId}` }) + return this.sendGet({ path: `accounts/${params.accountId}` }) } getAccountTransactions(params: GetAccountTransactionsParams): Promise { const { accountId, ...rest } = params - return this.sendGet({ path: `/accounts/${accountId}/transactions`, queryParams: rest }) + return this.sendGet({ path: `accounts/${accountId}/transactions`, queryParams: rest }) } getAccountOperations(params: GetOperationsByAccountIdParams): Promise { const { accountId, ...rest } = params - return this.sendGet({ path: `/accounts/${accountId}/operations`, queryParams: rest }) + return this.sendGet({ path: `accounts/${accountId}/operations`, queryParams: rest }) } getAccountPayments(params: GetAccountPaymentsParams): Promise { const { accountId, ...rest } = params - return this.sendGet({ path: `/accounts/${accountId}/payments`, queryParams: rest }) + return this.sendGet({ path: `accounts/${accountId}/payments`, queryParams: rest }) } getAccountEffects(params: GetAccountEffectsParams): Promise { const { accountId, ...rest } = params - return this.sendGet({ path: `/accounts/${accountId}/effects`, queryParams: rest }) + return this.sendGet({ path: `accounts/${accountId}/effects`, queryParams: rest }) } getAccountOffers(params: GetOffersByAccountIdParams): Promise { const { accountId, ...rest } = params - return this.sendGet({ path: `/accounts/${accountId}/offers`, queryParams: rest }) + return this.sendGet({ path: `accounts/${accountId}/offers`, queryParams: rest }) } getAccountTrades(params: GetAccountTradesParams): Promise { const { accountId, ...rest } = params - return this.sendGet({ path: `/accounts/${accountId}/trades`, queryParams: rest }) + return this.sendGet({ path: `accounts/${accountId}/trades`, queryParams: rest }) } getAccountData(params: GetAccountDataParams): Promise<{ value: string }> { const { accountId, ...rest } = params - return this.sendGet({ path: `/accounts/${accountId}/data/${rest.key}` }) + return this.sendGet({ path: `accounts/${accountId}/data/${rest.key}` }) } getAssets(params?: GetAssetsParams): Promise { - return this.sendGet({ path: '/assets', queryParams: params as QueryParams }) + return this.sendGet({ path: 'assets', queryParams: params as QueryParams }) } getClaimableBalances(params?: GetClaimableBalancesParams): Promise { - return this.sendGet({ path: '/claimable_balances', queryParams: params as QueryParams }) + return this.sendGet({ path: 'claimable_balances', queryParams: params as QueryParams }) } getClaimableBalance(params: GetClaimableBalanceParams): Promise { - return this.sendGet({ path: `/claimable_balances/${params.claimableBalanceId}` }) + return this.sendGet({ path: `claimable_balances/${params.claimableBalanceId}` }) } getClaimableTransactions(params: GetClaimableTransactionsParams): Promise { const { claimableBalanceId, ...rest } = params - return this.sendGet({ path: `/claimable_balances/${claimableBalanceId}/transactions`, queryParams: rest }) + return this.sendGet({ path: `claimable_balances/${claimableBalanceId}/transactions`, queryParams: rest }) } getClaimableOperations(params: GetClaimableOperationsParams): Promise { const { claimableBalanceId, ...rest } = params - return this.sendGet({ path: `/claimable_balances/${claimableBalanceId}/operations`, queryParams: rest }) + return this.sendGet({ path: `claimable_balances/${claimableBalanceId}/operations`, queryParams: rest }) } getEffects(params?: GetEffectsParams): Promise { - return this.sendGet({ path: '/effects', queryParams: params as QueryParams }) + return this.sendGet({ path: 'effects', queryParams: params as QueryParams }) } getFeeStats(): Promise { - return this.sendGet({ path: '/fee_stats' }) + return this.sendGet({ path: 'fee_stats' }) } getLiquidityPools(params?: GetLiquidityPoolsParams): Promise { - return this.sendGet({ path: '/liquidity_pools', queryParams: params as QueryParams }) + return this.sendGet({ path: 'liquidity_pools', queryParams: params as QueryParams }) } getLiquidityPool(params: GetLiquidityPoolParams): Promise { const { liquidityPoolId, ...rest } = params - return this.sendGet({ path: `/liquidity_pools/${liquidityPoolId}`, queryParams: rest }) + return this.sendGet({ path: `liquidity_pools/${liquidityPoolId}`, queryParams: rest }) } getLiquidityPoolEffects(params: GetLiquidityPoolEffectsParams): Promise { const { liquidityPoolId, ...rest } = params - return this.sendGet({ path: `/liquidity_pools/${liquidityPoolId}/effects`, queryParams: rest }) + return this.sendGet({ path: `liquidity_pools/${liquidityPoolId}/effects`, queryParams: rest }) } getLiquidityPoolTrades(params: GetLiquidityPoolTradesParams): Promise { const { liquidityPoolId, ...rest } = params - return this.sendGet({ path: `/liquidity_pools/${liquidityPoolId}/trades`, queryParams: rest }) + return this.sendGet({ path: `liquidity_pools/${liquidityPoolId}/trades`, queryParams: rest }) } getLiquidityPoolTransactions(params: GetLiquidityPoolTransactionsParams): Promise { const { liquidityPoolId, ...rest } = params - return this.sendGet({ path: `/liquidity_pools/${liquidityPoolId}/transactions`, queryParams: rest }) + return this.sendGet({ path: `liquidity_pools/${liquidityPoolId}/transactions`, queryParams: rest }) } getLiquidityPoolOperations(params: GetLiquidityPoolOperationsParams): Promise { const { liquidityPoolId, ...rest } = params - return this.sendGet({ path: `/liquidity_pools/${liquidityPoolId}/operations`, queryParams: rest }) + return this.sendGet({ path: `liquidity_pools/${liquidityPoolId}/operations`, queryParams: rest }) } getLedger(params: GetLedgerParams): Promise { const { sequence, ...rest } = params - return this.sendGet({ path: `/ledgers/${sequence}`, queryParams: rest }) + return this.sendGet({ path: `ledgers/${sequence}`, queryParams: rest }) } getLedgerTransactions(params: GetLedgerTransactionsParams): Promise { const { sequence, ...rest } = params - return this.sendGet({ path: `/ledgers/${sequence}/transactions`, queryParams: rest }) + return this.sendGet({ path: `ledgers/${sequence}/transactions`, queryParams: rest }) } getLedgerPayments(params: GetLedgerPaymentsParams): Promise { const { sequence, ...rest } = params - return this.sendGet({ path: `/ledgers/${sequence}/payments`, queryParams: rest }) + return this.sendGet({ path: `ledgers/${sequence}/payments`, queryParams: rest }) } getLedgerOperations(params: GetLedgerOperationsParams): Promise { const { sequence, ...rest } = params - return this.sendGet({ path: `/ledgers/${sequence}/operations`, queryParams: rest }) + return this.sendGet({ path: `ledgers/${sequence}/operations`, queryParams: rest }) } getLedgerEffects(params: GetLedgerEffectsParams): Promise<(Links & Effect)[]> { const { sequence, ...rest } = params - return this.sendGet({ path: `/ledgers/${sequence}/effects`, queryParams: rest }) + return this.sendGet({ path: `ledgers/${sequence}/effects`, queryParams: rest }) } getLedgers(params?: BaseParams): Promise { - return this.sendGet({ path: '/ledgers', queryParams: params as QueryParams }) + return this.sendGet({ path: 'ledgers', queryParams: params as QueryParams }) } getOffers(params?: GetOffersParams): Promise { - return this.sendGet({ path: '/offers', queryParams: params as QueryParams }) + return this.sendGet({ path: 'offers', queryParams: params as QueryParams }) } getOffer(params: GetOfferParams): Promise { const { offerId, ...rest } = params - return this.sendGet({ path: `/offers/${offerId}`, queryParams: rest }) + return this.sendGet({ path: `offers/${offerId}`, queryParams: rest }) } getOfferTrades(params: GetOfferTradesParams): Promise { const { offerId, ...rest } = params - return this.sendGet({ path: `/offers/${offerId}/trades`, queryParams: rest }) + return this.sendGet({ path: `offers/${offerId}/trades`, queryParams: rest }) } getOrderBook(params: GetOrderBookParams): Promise { const { sellingAssetType, ...rest } = params - return this.sendGet({ path: `/order_book/${sellingAssetType}`, queryParams: rest as QueryParams }) + return this.sendGet({ path: `order_book/${sellingAssetType}`, queryParams: rest as QueryParams }) } getTradeAggregations(params: GetTradeAggregationsParams): Promise { const { baseAssetType, counterAssetType, ...rest } = params return this.sendGet({ - path: `/trade_aggregations/${baseAssetType}${counterAssetType}`, + path: `trade_aggregations/${baseAssetType}${counterAssetType}`, queryParams: rest as QueryParams, }) } getTrades(params?: GetTradesParams): Promise { - return this.sendGet({ path: '/trades', queryParams: params as QueryParams }) + return this.sendGet({ path: 'trades', queryParams: params as QueryParams }) } getTransaction(params: GetTransactionParams): Promise { const { transactionHash, ...rest } = params - return this.sendGet({ path: `/transactions/${transactionHash}`, queryParams: rest }) + return this.sendGet({ path: `transactions/${transactionHash}`, queryParams: rest }) } getTransactionOperations(params: GetTransactionOperationsParams): Promise { const { transactionHash, ...rest } = params - return this.sendGet({ path: `/transactions/${transactionHash}/operations`, queryParams: rest }) + return this.sendGet({ path: `transactions/${transactionHash}/operations`, queryParams: rest }) } getTransactionEffects(params: GetTransactionEffectsParams): Promise { const { transactionHash, ...rest } = params - return this.sendGet({ path: `/transactions/${transactionHash}/effects`, queryParams: rest }) + return this.sendGet({ path: `transactions/${transactionHash}/effects`, queryParams: rest }) } getTransactions(params?: GetTransactionsParams): Promise { - return this.sendGet({ path: '/transactions', queryParams: params as QueryParams }) + return this.sendGet({ path: 'transactions', queryParams: params as QueryParams }) } getOperation(params: GetOperationParams): Promise { const { id, ...rest } = params - return this.sendGet({ path: `/operations/${id}`, queryParams: rest }) + return this.sendGet({ path: `operations/${id}`, queryParams: rest }) } getOperationEffects(params: GetOperationEffectsParams): Promise { const { id, ...rest } = params - return this.sendGet({ path: `/operations/${id}/effects`, queryParams: rest }) + return this.sendGet({ path: `operations/${id}/effects`, queryParams: rest }) } getOperations(params?: GetOperationsParams): Promise { - return this.sendGet({ path: '/operations', queryParams: params as QueryParams }) + return this.sendGet({ path: 'operations', queryParams: params as QueryParams }) } getPayments(params?: GetPaymentsParams): Promise { - return this.sendGet({ path: '/payments', queryParams: params as QueryParams }) + return this.sendGet({ path: 'payments', queryParams: params as QueryParams }) } getStrictReceivePaymentPaths(params: GetStrictReceivePaymentPathsParams): Promise { const { sourceAssets, ...rest } = params const sourceAssetsString = sourceAssets?.join(',') return this.sendGet({ - path: `/paths/strict-receive`, + path: `paths/strict-receive`, queryParams: { ...rest, ...(sourceAssetsString && { sourceAssets: sourceAssetsString }), @@ -332,7 +332,7 @@ export abstract class AbstractStellarRpc implements StellarRpcSuite { const destinationAssetsString = destinationAssets?.join(',') const sourceAssetsString = sourceAssets?.join(',') return this.sendGet({ - path: `/paths/strict-send`, + path: `paths/strict-send`, queryParams: { ...rest, ...(destinationAssetsString && { destinationAssets: destinationAssetsString }), @@ -342,6 +342,6 @@ export abstract class AbstractStellarRpc implements StellarRpcSuite { } submitTransaction(params: SubmitTransactionParams): Promise { - return this.sendPost({ path: '/transactions', queryParams: params as unknown as QueryParams }) + return this.sendPost({ path: 'transactions', queryParams: params as unknown as QueryParams }) } } diff --git a/src/service/rpc/other/StellarRpc.ts b/src/service/rpc/other/StellarRpc.ts new file mode 100644 index 000000000..0feb42810 --- /dev/null +++ b/src/service/rpc/other/StellarRpc.ts @@ -0,0 +1,44 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +import { GetI } from 'src/dto/GetI' +import { Container, Service } from 'typedi' +import { TatumConnector } from '../../../connector/tatum.connector' +import { PostI } from '../../../dto/PostI' +import { StellarRpcSuite } from '../../../dto/rpc/StellarRpcSuite' +import { CONFIG, Utils } from '../../../util' +import { TatumConfig } from '../../tatum' +import { AbstractStellarRpc } from './AbstractStellarRpc' + +@Service({ + factory: (data: { id: string }) => { + return new StellarRpc(data.id) + }, + transient: true, +}) +export class StellarRpc extends AbstractStellarRpc implements StellarRpcSuite { + protected readonly connector: TatumConnector + protected readonly config: TatumConfig + + constructor(id: string) { + super() + this.connector = Container.of(id).get(TatumConnector) + this.config = Container.of(id).get(CONFIG) + } + + public destroy() { + // Do nothing + } + + protected post(post: PostI): Promise { + const basePath = Utils.getV3RpcUrl(this.config) + return this.connector.post({ ...post, basePath }) + } + + protected get(get: GetI): Promise { + const basePath = Utils.getV3RpcUrl(this.config) + return this.connector.get({ ...get, basePath }) + } + + getRpcNodeUrl(): string { + return Utils.getV3RpcUrl(this.config) + } +} diff --git a/src/util/constant.ts b/src/util/constant.ts index ee8794d93..ece1f4763 100644 --- a/src/util/constant.ts +++ b/src/util/constant.ts @@ -141,6 +141,7 @@ export const Constant = { [Network.TEZOS]: 6, [Network.TEZOS_TESTNET]: 6, [Network.STELLAR]: 6, + [Network.STELLAR_TESTNET]: 6, [Network.OASIS]: 18, [Network.OASIS_TESTNET]: 18, [Network.OPTIMISM]: 18, @@ -240,6 +241,7 @@ export const Constant = { [Network.TEZOS]: 'XTZ', [Network.TEZOS_TESTNET]: 'XTZ', [Network.STELLAR]: 'XLM', + [Network.STELLAR_TESTNET]: 'XLM', [Network.OASIS]: 'ROSE', [Network.OASIS_TESTNET]: 'ROSE', [Network.OPTIMISM]: 'OPT', diff --git a/src/util/util.shared.ts b/src/util/util.shared.ts index b092e5a49..fcf7c7ead 100644 --- a/src/util/util.shared.ts +++ b/src/util/util.shared.ts @@ -18,6 +18,7 @@ import { isSameGetBlockNetwork, isSolanaNetwork, isStellarLoadBalancerNetwork, + isStellarNetwork, isTezosNetwork, isTronLoadBalancerNetwork, isTronNetwork, @@ -95,6 +96,7 @@ import { EosLoadBalancerRpc } from '../service/rpc/other/EosLoadBalancerRpc' import { EosRpc } from '../service/rpc/other/EosRpc' import { SolanaLoadBalancerRpc } from '../service/rpc/other/SolanaLoadBalancerRpc' import { StellarLoadBalancerRpc } from '../service/rpc/other/StellarLoadBalancerRpc' +import { StellarRpc } from '../service/rpc/other/StellarRpc' import { TezosLoadBalancerRpc } from '../service/rpc/other/TezosLoadBalancerRpc' import { XrpLoadBalancerRpc } from '../service/rpc/other/XrpLoadBalancerRpc' import { UtxoLoadBalancerRpc } from '../service/rpc/utxo/UtxoLoadBalancerRpc' @@ -111,6 +113,10 @@ export const Utils = { return Container.of(id).get(StellarLoadBalancerRpc) as T } + if (isStellarNetwork(network)) { + return Container.of(id).get(StellarRpc) as T + } + if (isCardanoNetwork(network)) { return Container.of(id).get(CardanoLoadBalancerRpc) as T } @@ -695,6 +701,7 @@ export const Utils = { case Network.CARDANO_ROSETTA_PREPROD: return new CardanoRosetta(id) as T case Network.STELLAR: + case Network.STELLAR_TESTNET: return new Stellar(id) as T default: return new FullSdk(id) as T