@cryptorubic/web3 0.14.0-alpha.solana-gas.11 → 1.0.0-alpha.no-sdk.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/package.json +1 -2
  2. package/src/index.d.ts +4 -7
  3. package/src/index.js +4 -7
  4. package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.d.ts +35 -0
  5. package/src/lib/adapter/adapters/{bitcoin-adapter.js → adapter-bitcoin/bitcoin-adapter.js} +16 -6
  6. package/src/lib/adapter/adapters/adapter-bitcoin/client/bitcoin-adapter-client.d.ts +16 -0
  7. package/src/lib/adapter/adapters/adapter-bitcoin/client/bitcoin-adapter-client.js +119 -0
  8. package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-send-tx-params.d.ts +5 -0
  9. package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-psbt-encoded-config.d.ts +5 -0
  10. package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-trade-types.d.ts +7 -0
  11. package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-transfer-encoded-config.d.ts +6 -0
  12. package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-transfer-encoded-config.js +2 -0
  13. package/src/lib/adapter/adapters/adapter-evm/client/evm-adapter-client.d.ts +80 -0
  14. package/src/lib/adapter/adapters/adapter-evm/client/evm-adapter-client.js +307 -0
  15. package/src/lib/adapter/adapters/adapter-evm/constants/proxy-hash-errors.d.ts +4 -0
  16. package/src/lib/adapter/adapters/adapter-evm/constants/proxy-hash-errors.js +705 -0
  17. package/src/lib/adapter/adapters/{evm-adapter.d.ts → adapter-evm/evm-adapter.d.ts} +25 -17
  18. package/src/lib/adapter/adapters/{evm-adapter.js → adapter-evm/evm-adapter.js} +155 -75
  19. package/src/lib/adapter/adapters/adapter-evm/models/evm-send-tx-params.d.ts +38 -0
  20. package/src/lib/adapter/adapters/adapter-evm/models/evm-send-tx-params.js +2 -0
  21. package/src/lib/adapter/adapters/adapter-evm/utils/parse-evm-error.d.ts +12 -0
  22. package/src/lib/adapter/adapters/adapter-evm/utils/parse-evm-error.js +70 -0
  23. package/src/lib/adapter/adapters/adapter-solana/client/solana-adapter-client.d.ts +15 -0
  24. package/src/lib/adapter/adapters/adapter-solana/client/solana-adapter-client.js +94 -0
  25. package/src/lib/adapter/adapters/adapter-solana/models/solana-send-tx-params.d.ts +16 -0
  26. package/src/lib/adapter/adapters/adapter-solana/models/solana-send-tx-params.js +2 -0
  27. package/src/lib/adapter/adapters/{utils/solana-utils → adapter-solana/services}/solana-tokens-service.js +8 -10
  28. package/src/lib/adapter/adapters/{solana-adapter.d.ts → adapter-solana/solana-adapter.d.ts} +23 -17
  29. package/src/lib/adapter/adapters/{solana-adapter.js → adapter-solana/solana-adapter.js} +36 -98
  30. package/src/lib/adapter/adapters/adapter-sui/client/sui-adapter-client.d.ts +15 -0
  31. package/src/lib/adapter/adapters/adapter-sui/client/sui-adapter-client.js +58 -0
  32. package/src/lib/adapter/adapters/adapter-sui/models/sui-send-tx-params.d.ts +8 -0
  33. package/src/lib/adapter/adapters/adapter-sui/models/sui-send-tx-params.js +2 -0
  34. package/src/lib/adapter/adapters/adapter-sui/sui-adapter.d.ts +29 -0
  35. package/src/lib/adapter/adapters/{sui-adapter.js → adapter-sui/sui-adapter.js} +25 -6
  36. package/src/lib/adapter/adapters/adapter-ton/client/ton-adapter-client.d.ts +41 -0
  37. package/src/lib/adapter/adapters/adapter-ton/client/ton-adapter-client.js +164 -0
  38. package/src/lib/adapter/adapters/adapter-ton/models/ton-send-tx-params.d.ts +26 -0
  39. package/src/lib/adapter/adapters/adapter-ton/models/ton-send-tx-params.js +2 -0
  40. package/src/lib/adapter/adapters/{utils → adapter-ton/services}/ton-api.service.d.ts +4 -4
  41. package/src/lib/adapter/adapters/{utils → adapter-ton/services}/ton-api.service.js +0 -5
  42. package/src/lib/adapter/adapters/adapter-ton/services/ton-client/ton-client.d.ts +6 -0
  43. package/src/lib/adapter/adapters/adapter-ton/services/ton-client/ton-client.js +18 -0
  44. package/src/lib/adapter/adapters/adapter-ton/ton-adapter.d.ts +29 -0
  45. package/src/lib/adapter/adapters/{ton-adapter.js → adapter-ton/ton-adapter.js} +40 -50
  46. package/src/lib/adapter/adapters/adapter-tron/client/tron-adapter-client.d.ts +27 -0
  47. package/src/lib/adapter/adapters/adapter-tron/client/tron-adapter-client.js +91 -0
  48. package/src/lib/adapter/adapters/adapter-tron/models/tron-send-tx-params.d.ts +13 -0
  49. package/src/lib/adapter/adapters/adapter-tron/models/tron-send-tx-params.js +2 -0
  50. package/src/lib/adapter/adapters/{tron-adapter.d.ts → adapter-tron/tron-adapter.d.ts} +21 -18
  51. package/src/lib/adapter/adapters/{tron-adapter.js → adapter-tron/tron-adapter.js} +45 -68
  52. package/src/lib/adapter/adapters/adapter-tron/utils/parse-tron-error.d.ts +2 -0
  53. package/src/lib/adapter/adapters/adapter-tron/utils/parse-tron-error.js +20 -0
  54. package/src/lib/adapter/adapters/common/abstract-adapter.d.ts +48 -0
  55. package/src/lib/adapter/adapters/common/abstract-adapter.js +67 -0
  56. package/src/lib/adapter/adapters/common/client/abstract-adapter-client.d.ts +24 -0
  57. package/src/lib/adapter/adapters/common/client/abstract-adapter-client.js +59 -0
  58. package/src/lib/adapter/adapters/models/approve-adapter.d.ts +4 -4
  59. package/src/lib/adapter/adapters/models/approve-adapter.js +3 -3
  60. package/src/lib/adapter/adapters/models/basic-transaction-options.d.ts +1 -1
  61. package/src/lib/adapter/adapters/models/evm-web3-public-models/batch-call.d.ts +5 -0
  62. package/src/lib/adapter/adapters/models/evm-web3-public-models/batch-call.js +2 -0
  63. package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-call.d.ts +4 -0
  64. package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-call.js +2 -0
  65. package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-multicall-response.d.ts +4 -0
  66. package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-multicall-response.js +2 -0
  67. package/src/lib/adapter/adapters/models/evm-web3-public-models/gas-price-viem.d.ts +18 -0
  68. package/src/lib/adapter/adapters/models/evm-web3-public-models/gas-price-viem.js +2 -0
  69. package/src/lib/adapter/adapters/models/evm-web3-public-models/gas-price.js +2 -0
  70. package/src/lib/adapter/adapters/models/evm-web3-public-models/permit2-contract-types.d.ts +10 -0
  71. package/src/lib/adapter/adapters/models/evm-web3-public-models/permit2-contract-types.js +2 -0
  72. package/src/lib/adapter/adapters/models/evm-web3-public-models/rpc-response.d.ts +5 -0
  73. package/src/lib/adapter/adapters/models/evm-web3-public-models/rpc-response.js +2 -0
  74. package/src/lib/adapter/adapters/models/old-features-models/contract-params.d.ts +23 -0
  75. package/src/lib/adapter/adapters/models/old-features-models/contract-params.js +2 -0
  76. package/src/lib/adapter/adapters/models/old-features-models/encode-transaction-options.d.ts +32 -0
  77. package/src/lib/adapter/adapters/models/old-features-models/encode-transaction-options.js +2 -0
  78. package/src/lib/adapter/adapters/models/old-features-models/is-deflation-token.d.ts +6 -0
  79. package/src/lib/adapter/adapters/models/old-features-models/is-deflation-token.js +2 -0
  80. package/src/lib/adapter/adapters/models/old-features-models/non-evm-chain-address-correct-response.d.ts +5 -0
  81. package/src/lib/adapter/adapters/models/old-features-models/non-evm-chain-address-correct-response.js +2 -0
  82. package/src/lib/adapter/adapters/models/old-features-models/swap-transaction-options.d.ts +61 -0
  83. package/src/lib/adapter/adapters/models/old-features-models/swap-transaction-options.js +2 -0
  84. package/src/lib/adapter/adapters/models/status-manager-models/tx-status-data.d.ts +8 -0
  85. package/src/lib/adapter/adapters/models/status-manager-models/tx-status-data.js +2 -0
  86. package/src/lib/adapter/adapters/models/web3-public-models/contract-multicall-response.d.ts +5 -0
  87. package/src/lib/adapter/adapters/models/web3-public-models/contract-multicall-response.js +2 -0
  88. package/src/lib/adapter/adapters/models/web3-public-models/method-data.d.ts +4 -0
  89. package/src/lib/adapter/adapters/models/web3-public-models/method-data.js +2 -0
  90. package/src/lib/adapter/adapters/models/web3-public-models/supported-token-field.d.ts +1 -0
  91. package/src/lib/adapter/adapters/models/web3-public-models/supported-token-field.js +2 -0
  92. package/src/lib/adapter/adapters/models/web3-public-models/tx-status.d.ts +10 -0
  93. package/src/lib/adapter/adapters/models/web3-public-models/tx-status.js +12 -0
  94. package/src/lib/adapter/adapters/utils/errors.d.ts +2 -0
  95. package/src/lib/adapter/adapters/utils/errors.js +10 -0
  96. package/src/lib/adapter/adapters/utils/options.d.ts +10 -0
  97. package/src/lib/adapter/adapters/utils/options.js +59 -0
  98. package/src/lib/adapter/adapters/utils/waitFor.d.ts +1 -0
  99. package/src/lib/adapter/adapters/utils/waitFor.js +6 -0
  100. package/src/lib/adapter/blockchain-adapter-factory.service.d.ts +18 -13
  101. package/src/lib/adapter/blockchain-adapter-factory.service.js +35 -66
  102. package/src/lib/adapter/constants/models/create-factory-params.d.ts +8 -0
  103. package/src/lib/adapter/constants/models/create-factory-params.js +2 -0
  104. package/src/lib/adapter/constants/models/env-type.d.ts +1 -0
  105. package/src/lib/adapter/constants/models/env-type.js +2 -0
  106. package/src/lib/adapter/constants/models/solana-web3.d.ts +1 -1
  107. package/src/lib/adapter/constants/rubic-api-link-mapping.d.ts +2 -0
  108. package/src/lib/adapter/constants/rubic-api-link-mapping.js +16 -0
  109. package/src/lib/errors/blockchain/deflation-token.error.d.ts +11 -0
  110. package/src/lib/errors/blockchain/deflation-token.error.js +16 -0
  111. package/src/lib/errors/blockchain/healthcheck.error.d.ts +8 -0
  112. package/src/lib/errors/blockchain/healthcheck.error.js +15 -0
  113. package/src/lib/errors/blockchain/invalid-address.error.d.ts +8 -0
  114. package/src/lib/errors/blockchain/invalid-address.error.js +15 -0
  115. package/src/lib/errors/blockchain/low-gas.error.d.ts +7 -0
  116. package/src/lib/errors/blockchain/low-gas.error.js +14 -0
  117. package/src/lib/errors/blockchain/transaction-reverted.error.d.ts +7 -0
  118. package/src/lib/errors/blockchain/transaction-reverted.error.js +14 -0
  119. package/src/lib/errors/blockchain/tron-insufficient-native-balance.d.ts +7 -0
  120. package/src/lib/errors/blockchain/tron-insufficient-native-balance.js +14 -0
  121. package/src/lib/errors/blockchain/tron-transaction-expired.d.ts +7 -0
  122. package/src/lib/errors/blockchain/tron-transaction-expired.js +14 -0
  123. package/src/lib/errors/blockchain/user-reject.error.d.ts +7 -0
  124. package/src/lib/errors/blockchain/user-reject.error.js +14 -0
  125. package/src/lib/errors/blockchain/wrong-from-address.error.d.ts +7 -0
  126. package/src/lib/errors/blockchain/wrong-from-address.error.js +14 -0
  127. package/src/lib/errors/blockchain/wrong-receiver-address.error.d.ts +7 -0
  128. package/src/lib/errors/blockchain/wrong-receiver-address.error.js +14 -0
  129. package/src/lib/errors/common/timeout.error.d.ts +4 -0
  130. package/src/lib/errors/common/timeout.error.js +12 -0
  131. package/src/lib/errors/cross-chain/cross-chain-is-unavailable.error.d.ts +7 -0
  132. package/src/lib/errors/cross-chain/cross-chain-is-unavailable.error.js +14 -0
  133. package/src/lib/errors/cross-chain/insufficient-funds-gas-price-value.error.d.ts +7 -0
  134. package/src/lib/errors/cross-chain/insufficient-funds-gas-price-value.error.js +14 -0
  135. package/src/lib/errors/cross-chain/low-to-slippage.error.d.ts +6 -0
  136. package/src/lib/errors/cross-chain/low-to-slippage.error.js +10 -0
  137. package/src/lib/errors/cross-chain/max-gas-price-overflow.error.d.ts +8 -0
  138. package/src/lib/errors/cross-chain/max-gas-price-overflow.error.js +15 -0
  139. package/src/lib/errors/cross-chain/too-low-amount.error.d.ts +7 -0
  140. package/src/lib/errors/cross-chain/too-low-amount.error.js +14 -0
  141. package/src/lib/errors/cross-chain/unsupported-receiver-address.error.d.ts +4 -0
  142. package/src/lib/errors/cross-chain/unsupported-receiver-address.error.js +11 -0
  143. package/src/lib/errors/cross-chain/updated-rates-error.d.ts +10 -0
  144. package/src/lib/errors/cross-chain/updated-rates-error.js +17 -0
  145. package/src/lib/errors/models/rubic-api-error.d.ts +21 -0
  146. package/src/lib/errors/models/rubic-api-error.js +2 -0
  147. package/src/lib/errors/on-chain/on-chain-is-unavailable.error.d.ts +7 -0
  148. package/src/lib/errors/on-chain/on-chain-is-unavailable.error.js +14 -0
  149. package/src/lib/errors/proxy/unapproved-contract-error.d.ts +8 -0
  150. package/src/lib/errors/proxy/unapproved-contract-error.js +15 -0
  151. package/src/lib/errors/proxy/unapproved-method-error.d.ts +8 -0
  152. package/src/lib/errors/proxy/unapproved-method-error.js +15 -0
  153. package/src/lib/errors/proxy/unlisted-error.d.ts +9 -0
  154. package/src/lib/errors/proxy/unlisted-error.js +16 -0
  155. package/src/lib/errors/rubic-sdk.error.d.ts +6 -0
  156. package/src/lib/errors/rubic-sdk.error.js +13 -0
  157. package/src/lib/errors/swap/bridgers-pair-is-unavailable.error.d.ts +7 -0
  158. package/src/lib/errors/swap/bridgers-pair-is-unavailable.error.js +14 -0
  159. package/src/lib/errors/swap/failed-to-check-for-transaction-receipt.error.d.ts +8 -0
  160. package/src/lib/errors/swap/failed-to-check-for-transaction-receipt.error.js +15 -0
  161. package/src/lib/errors/swap/insufficient-funds-oneinch.error.d.ts +9 -0
  162. package/src/lib/errors/swap/insufficient-funds-oneinch.error.js +15 -0
  163. package/src/lib/errors/swap/insufficient-funds.error.d.ts +11 -0
  164. package/src/lib/errors/swap/insufficient-funds.error.js +18 -0
  165. package/src/lib/errors/swap/insufficient-liquidity.error.d.ts +7 -0
  166. package/src/lib/errors/swap/insufficient-liquidity.error.js +14 -0
  167. package/src/lib/errors/swap/lifi-pair-is-unavailable.error.d.ts +7 -0
  168. package/src/lib/errors/swap/lifi-pair-is-unavailable.error.js +14 -0
  169. package/src/lib/errors/swap/low-slippage-deflationary-token.error.d.ts +7 -0
  170. package/src/lib/errors/swap/low-slippage-deflationary-token.error.js +14 -0
  171. package/src/lib/errors/swap/low-slippage.error.d.ts +8 -0
  172. package/src/lib/errors/swap/low-slippage.error.js +15 -0
  173. package/src/lib/errors/swap/max-amount.error.d.ts +7 -0
  174. package/src/lib/errors/swap/max-amount.error.js +14 -0
  175. package/src/lib/errors/swap/max-decimals.error.d.ts +5 -0
  176. package/src/lib/errors/swap/max-decimals.error.js +12 -0
  177. package/src/lib/errors/swap/min-amount.error.d.ts +7 -0
  178. package/src/lib/errors/swap/min-amount.error.js +14 -0
  179. package/src/lib/errors/swap/no-linked-account-erros.d.ts +4 -0
  180. package/src/lib/errors/swap/no-linked-account-erros.js +11 -0
  181. package/src/lib/errors/swap/not-supported-blockchain.d.ts +8 -0
  182. package/src/lib/errors/swap/not-supported-blockchain.js +15 -0
  183. package/src/lib/errors/swap/not-supported-region.d.ts +7 -0
  184. package/src/lib/errors/swap/not-supported-region.js +14 -0
  185. package/src/lib/errors/swap/not-supported-tokens.error.d.ts +7 -0
  186. package/src/lib/errors/swap/not-supported-tokens.error.js +14 -0
  187. package/src/lib/errors/swap/not-whitelisted-provider.error.d.ts +10 -0
  188. package/src/lib/errors/swap/not-whitelisted-provider.error.js +17 -0
  189. package/src/lib/errors/swap/simulation-failed.error.d.ts +6 -0
  190. package/src/lib/errors/swap/simulation-failed.error.js +12 -0
  191. package/src/lib/errors/swap/swap-error-on-provider-side.d.ts +7 -0
  192. package/src/lib/errors/swap/swap-error-on-provider-side.js +14 -0
  193. package/src/lib/errors/swap/swap-request.error.d.ts +7 -0
  194. package/src/lib/errors/swap/swap-request.error.js +14 -0
  195. package/src/lib/errors/swap/trade-expired.error.d.ts +4 -0
  196. package/src/lib/errors/swap/trade-expired.error.js +11 -0
  197. package/src/lib/errors/swap/unnecessary-approve.error.d.ts +7 -0
  198. package/src/lib/errors/swap/unnecessary-approve.error.js +14 -0
  199. package/src/lib/errors/swap/wallet-not-connected.error.d.ts +8 -0
  200. package/src/lib/errors/swap/wallet-not-connected.error.js +15 -0
  201. package/src/lib/errors/swap/wrong-network.error.d.ts +10 -0
  202. package/src/lib/errors/swap/wrong-network.error.js +16 -0
  203. package/src/lib/utils/web3-types/common-web3-pure.js +2 -4
  204. package/src/lib/utils/web3-types/near-web3-pure.js +1 -1
  205. package/src/lib/utils/web3-types/solana-web3-pure.js +1 -1
  206. package/src/lib/utils/web3-types/sui-web3-pure.js +2 -2
  207. package/src/lib/adapter/adapters/abstract-adapter.d.ts +0 -23
  208. package/src/lib/adapter/adapters/abstract-adapter.js +0 -61
  209. package/src/lib/adapter/adapters/bitcoin-adapter.d.ts +0 -18
  210. package/src/lib/adapter/adapters/models/adapter-factory-params.d.ts +0 -7
  211. package/src/lib/adapter/adapters/sui-adapter.d.ts +0 -17
  212. package/src/lib/adapter/adapters/ton-adapter.d.ts +0 -22
  213. package/src/lib/utils/models/solana-transaction-config.d.ts +0 -6
  214. /package/src/lib/adapter/adapters/{models/adapter-factory-params.js → adapter-bitcoin/models/btc-send-tx-params.js} +0 -0
  215. /package/src/lib/adapter/adapters/{models/gas-price.js → adapter-bitcoin/models/btc-web3-private-models/bitcoin-psbt-encoded-config.js} +0 -0
  216. /package/src/lib/{utils/models/solana-transaction-config.js → adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-trade-types.js} +0 -0
  217. /package/src/lib/adapter/adapters/{utils/solana-utils → adapter-solana/services}/solana-tokens-service.d.ts +0 -0
  218. /package/src/lib/adapter/adapters/models/{gas-price.d.ts → evm-web3-public-models/gas-price.d.ts} +0 -0
@@ -1,16 +1,31 @@
1
- import { Abi, MulticallResponse, MulticallParameters, PublicActions, PublicClient, WalletClient, WalletActions, BlockNumber, BlockTag, GetBlockReturnType } from 'viem';
2
- import { AbstractAdapter } from './abstract-adapter';
3
- import { EvmBlockchainName, ICustomLogger, Token, TokenAmount, PriceTokenAmount } from '@cryptorubic/core';
1
+ import { Abi, MulticallResponse, MulticallParameters, PublicActions, PublicClient, WalletClient, WalletActions, BlockNumber, BlockTag, GetBlockReturnType, TransactionReceipt } from 'viem';
2
+ import { AbstractAdapter } from '../common/abstract-adapter';
3
+ import { EvmBlockchainName, ICustomLogger, Token, TokenAmount, PriceTokenAmount, HttpClient } from '@cryptorubic/core';
4
4
  import BigNumber from 'bignumber.js';
5
- import { EvmAdapterOptions } from './models/evm-adapter-options';
6
- import { EvmTransactionConfig } from '../../utils/models/evm-transaction-config';
7
- import { ApproveAdapter } from './models/approve-adapter';
8
- import { AllowanceInfo } from './models/common-types';
9
- import { GasPrice } from './models/gas-price';
10
- export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicClient, WalletClient & WalletActions, EvmBlockchainName> implements ApproveAdapter<EvmTransactionConfig> {
5
+ import { EvmAdapterOptions } from '../models/evm-adapter-options';
6
+ import { EvmTransactionConfig } from '../../../utils/models/evm-transaction-config';
7
+ import { EvmSendTxParams } from './models/evm-send-tx-params';
8
+ import { AbstractAdapterClient } from '../common/client/abstract-adapter-client';
9
+ import { RubicAppAdaptersFactoryParams } from '../../constants/models/create-factory-params';
10
+ import { ApproveAdapterClient } from '../models/approve-adapter';
11
+ import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
12
+ import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
13
+ import { MethodData } from '../models/web3-public-models/method-data';
14
+ import { GasPrice } from '../models/evm-web3-public-models/gas-price';
15
+ export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicClient, WalletClient & WalletActions, EvmBlockchainName> {
16
+ readonly client: AbstractAdapterClient<WalletClient & WalletActions, EvmSendTxParams, TransactionReceipt> & ApproveAdapterClient<EvmTransactionConfig>;
11
17
  needPreswapAction(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
12
18
  handlePreswap(contractAddress: string, walletAddress: string, tokenAmount: TokenAmount): Promise<void>;
13
- constructor(adapterOptions: EvmAdapterOptions, logger?: ICustomLogger);
19
+ constructor(httpClient: HttpClient, adapterOptions: EvmAdapterOptions, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
20
+ getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
21
+ multicallContractsMethods<Output extends Web3PrimitiveType>(contractAbi: Abi, contractsData: {
22
+ contractAddress: string;
23
+ methodsData: MethodData[];
24
+ }[]): Promise<ContractMulticallResponse<Output>[][]>;
25
+ getBlockNumber(): Promise<number | {
26
+ blockNumber: number;
27
+ workchain: number;
28
+ }>;
14
29
  protected createPublicClient(rpcList: string[]): (PublicActions & PublicClient) | null;
15
30
  read<T>(address: string, abi: Abi, method: string, methodArgs?: unknown[]): Promise<T>;
16
31
  writeContract(address: string, abi: Abi, method: string, value?: string, methodArgs?: unknown[]): Promise<string>;
@@ -29,13 +44,6 @@ export declare class EvmAdapter extends AbstractAdapter<PublicActions & PublicCl
29
44
  */
30
45
  getBalance(walletAddress: string, tokenAddress?: string): Promise<BigNumber>;
31
46
  getTransactionCount(walletAddress: string): Promise<number>;
32
- getAllowance(fromTokenAddress: string, walletAddress: string, spenderAddress: string): Promise<AllowanceInfo>;
33
- encodeApprove(tokenAddress: string, spenderAddress: string, amount?: string): EvmTransactionConfig;
34
- needApprove(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean>;
35
- approve(fromAddress: string, tokenAddress: string, spenderAddress: string, amount?: string): Promise<string>;
36
- needPermit2Approve(token: TokenAmount, permit2Address: string, walletAddress: string, spenderAddress: string): Promise<boolean>;
37
- encodePermit2Approve(tokenAddress: string, spenderAddress: string, permit2Address: string, expiration: string, amount: string): EvmTransactionConfig;
38
- approveOnPermit2(fromAddress: string, tokenAddress: string, permit2Address: string, spenderAddress: string, deadline?: BigNumber, amount?: BigNumber): Promise<string>;
39
47
  /**
40
48
  * Calculates EIP-1559 specific gas details.
41
49
  * @see {@link https://github.com/ethers-io/ethers.js/blob/master/packages/abstract-provider/src.ts/index.ts#L235}
@@ -2,17 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.EvmAdapter = void 0;
4
4
  const viem_1 = require("viem");
5
- const viem_blockchain_mapping_1 = require("../constants/viem-blockchain-mapping");
6
- const erc20_token_abi_1 = require("./constants/erc20-token-abi");
7
- const abstract_adapter_1 = require("./abstract-adapter");
5
+ const viem_blockchain_mapping_1 = require("../../constants/viem-blockchain-mapping");
6
+ const erc20_token_abi_1 = require("../constants/erc20-token-abi");
7
+ const abstract_adapter_1 = require("../common/abstract-adapter");
8
8
  const core_1 = require("@cryptorubic/core");
9
9
  const bignumber_js_1 = require("bignumber.js");
10
- const web3_pure_1 = require("../../utils/web3-pure");
11
- const possible_errors_1 = require("./constants/possible-errors");
12
- const uni_v3_permit_abi_1 = require("./constants/uni-v3-permit-abi");
10
+ const web3_pure_1 = require("../../../utils/web3-pure");
11
+ const possible_errors_1 = require("../constants/possible-errors");
12
+ const evm_adapter_client_1 = require("./client/evm-adapter-client");
13
+ const rubic_sdk_error_1 = require("../../../errors/rubic-sdk.error");
13
14
  class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
14
15
  async needPreswapAction(token, contractAddress, walletAddress, amount) {
15
- return this.needApprove(token, contractAddress, walletAddress, amount);
16
+ return this.client.needApprove(token, contractAddress, walletAddress, amount);
16
17
  }
17
18
  async handlePreswap(contractAddress, walletAddress, tokenAmount) {
18
19
  const approveAmount = this.blockchain === core_1.BLOCKCHAIN_NAME.GNOSIS || this.blockchain === core_1.BLOCKCHAIN_NAME.CRONOS
@@ -24,9 +25,70 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
24
25
  : tokenAmount.blockchain;
25
26
  await this.writeContract(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'approve', '0', [approveAmount]);
26
27
  }
27
- constructor(adapterOptions, logger) {
28
+ constructor(httpClient, adapterOptions, logger, rubicAppParams) {
28
29
  super(adapterOptions.blockchain, logger);
29
30
  this.public = this.createPublicClient(adapterOptions.rpcList);
31
+ this.client = new evm_adapter_client_1.EvmAdapterClient(this, httpClient, logger, rubicAppParams);
32
+ }
33
+ async getTokensBalances(userAddress, tokensAddresses) {
34
+ const indexOfNativeCoin = tokensAddresses.findIndex((tokenAddress) => web3_pure_1.Web3Pure.isNativeAddress('ETH', tokenAddress));
35
+ const promises = [];
36
+ if (indexOfNativeCoin !== -1) {
37
+ tokensAddresses.splice(indexOfNativeCoin, 1);
38
+ promises[1] = this.getBalance(userAddress);
39
+ }
40
+ promises[0] = this.multicallContractsMethods(erc20_token_abi_1.erc20TokenAbi, tokensAddresses.map((tokenAddress) => ({
41
+ contractAddress: tokenAddress,
42
+ methodsData: [
43
+ {
44
+ methodName: 'balanceOf',
45
+ methodArguments: [userAddress]
46
+ }
47
+ ]
48
+ })));
49
+ const results = await Promise.all(promises);
50
+ const tokensBalances = results[0].map((tokenResults) => {
51
+ const { success, output } = tokenResults[0];
52
+ return success ? new bignumber_js_1.default(output) : new bignumber_js_1.default(0);
53
+ });
54
+ if (indexOfNativeCoin !== -1) {
55
+ tokensBalances.splice(indexOfNativeCoin, 0, results[1]);
56
+ }
57
+ return tokensBalances;
58
+ }
59
+ async multicallContractsMethods(contractAbi, contractsData) {
60
+ const contracts = contractsData
61
+ .map(({ contractAddress, methodsData }) => {
62
+ const wagmiContract = {
63
+ address: contractAddress,
64
+ abi: contractAbi
65
+ };
66
+ return methodsData.map(({ methodName, methodArguments }) => ({
67
+ ...wagmiContract,
68
+ functionName: methodName,
69
+ args: methodArguments
70
+ }));
71
+ })
72
+ .flat();
73
+ const outputs = await this.public.multicall({ contracts });
74
+ let outputIndex = 0;
75
+ return contractsData.map((contractData) => {
76
+ return contractData.methodsData.map(() => {
77
+ const output = outputs[outputIndex];
78
+ if (!output) {
79
+ throw new rubic_sdk_error_1.RubicSdkError('Output has to be defined');
80
+ }
81
+ outputIndex++;
82
+ return {
83
+ success: output.status === 'success',
84
+ output: output?.error ? null : output.result
85
+ };
86
+ });
87
+ });
88
+ }
89
+ async getBlockNumber() {
90
+ const blockNumber = await this.public.getBlockNumber();
91
+ return Number(blockNumber);
30
92
  }
31
93
  createPublicClient(rpcList) {
32
94
  if (!rpcList?.[0]) {
@@ -34,22 +96,21 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
34
96
  return null;
35
97
  }
36
98
  const transports = rpcList.map((rpc) => (0, viem_1.http)(rpc, {
37
- batch: { batchSize: 2_000, wait: 16 },
99
+ batch: { batchSize: 2000, wait: 16 },
38
100
  onFetchResponse: (response) => {
39
101
  this.handlePossibleError(response);
40
102
  },
41
103
  retryCount: 2,
42
104
  retryDelay: 100,
43
- timeout: 5_000
105
+ timeout: 5000
44
106
  }));
45
107
  const chain = viem_blockchain_mapping_1.viemBlockchainMapping[this.blockchain];
46
- // @ts-ignore
47
108
  return (0, viem_1.createPublicClient)({
48
109
  // @ts-ignore
49
110
  chain,
50
111
  transport: (0, viem_1.fallback)(transports, {
51
112
  rank: {
52
- interval: 1_800_000
113
+ interval: 1800000
53
114
  }
54
115
  })
55
116
  });
@@ -64,7 +125,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
64
125
  return result;
65
126
  }
66
127
  async writeContract(address, abi, method, value = '0', methodArgs = []) {
67
- const result = await this.wallet.writeContract({
128
+ const result = await this.client.clientWallet.writeContract({
68
129
  abi,
69
130
  address: address,
70
131
  account: address,
@@ -76,7 +137,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
76
137
  return result;
77
138
  }
78
139
  async write(address, to, value, data) {
79
- const result = await this.wallet.sendTransaction({
140
+ const result = await this.client.clientWallet.sendTransaction({
80
141
  account: address,
81
142
  to: to,
82
143
  value: (0, viem_1.parseEther)(value),
@@ -136,7 +197,7 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
136
197
  throw err;
137
198
  }
138
199
  }
139
- async simulateTransaction(config, from, timeout = 15_000) {
200
+ async simulateTransaction(config, from, timeout = 15000) {
140
201
  try {
141
202
  const callParams = {
142
203
  account: from,
@@ -225,66 +286,85 @@ class EvmAdapter extends abstract_adapter_1.AbstractAdapter {
225
286
  });
226
287
  return transactionCount ?? 0;
227
288
  }
228
- async getAllowance(fromTokenAddress, walletAddress, spenderAddress) {
229
- const [decimals, allowance] = await Promise.all([
230
- this.read(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'decimals'),
231
- this.read(fromTokenAddress, erc20_token_abi_1.erc20TokenAbi, 'allowance', [walletAddress, spenderAddress])
232
- ]);
233
- const allowanceWeiBN = new bignumber_js_1.default(allowance);
234
- const allowanceNonWei = core_1.Token.fromWei(allowanceWeiBN, Number(decimals));
235
- return { allowanceNonWei, allowanceWei: allowanceWeiBN };
236
- }
237
- encodeApprove(tokenAddress, spenderAddress, amount) {
238
- const amountWei = amount ?? new bignumber_js_1.default(2).pow(256).minus(1).toFixed();
239
- const tx = EvmAdapter.encodeMethodCall(tokenAddress, erc20_token_abi_1.erc20TokenAbi, 'approve', [spenderAddress, amountWei]);
240
- return {
241
- data: tx.data,
242
- to: tx.to,
243
- value: tx.value
244
- };
245
- }
246
- async needApprove(token, contractAddress, walletAddress, amount) {
247
- // Native coin in METIS can be Token required approve
248
- if (token.isNative && token.blockchain !== core_1.BLOCKCHAIN_NAME.METIS) {
249
- return false;
250
- }
251
- // Special native address for METIS native coin
252
- const fromTokenAddress = token.isNative && token.blockchain === core_1.BLOCKCHAIN_NAME.METIS ? '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000' : token.address;
253
- const { allowanceWei } = await this.getAllowance(fromTokenAddress, walletAddress, contractAddress);
254
- return allowanceWei.lt(token.weiAmount);
255
- }
256
- async approve(fromAddress, tokenAddress, spenderAddress, amount) {
257
- const config = this.encodeApprove(tokenAddress, spenderAddress, amount);
258
- return this.write(fromAddress, config.to, config.value, config.data);
259
- }
260
- async needPermit2Approve(token, permit2Address, walletAddress, spenderAddress) {
261
- const res = await this.read(permit2Address, uni_v3_permit_abi_1.UNI_V3_PERMIT_2_ABI, 'allowance', [
262
- walletAddress,
263
- token.address,
264
- spenderAddress
265
- ]);
266
- const [amount, expiration, _nonce] = res;
267
- return token.weiAmount.gt(amount) || new bignumber_js_1.default(Date.now()).gt(Number(expiration) * 1000);
268
- }
269
- encodePermit2Approve(tokenAddress, spenderAddress, permit2Address, expiration, amount) {
270
- const tx = EvmAdapter.encodeMethodCall(permit2Address, uni_v3_permit_abi_1.UNI_V3_PERMIT_2_ABI, 'approve', [
271
- tokenAddress,
272
- spenderAddress,
273
- amount,
274
- expiration
275
- ]);
276
- return {
277
- data: tx.data,
278
- value: tx.value,
279
- to: tx.to
280
- };
281
- }
282
- async approveOnPermit2(fromAddress, tokenAddress, permit2Address, spenderAddress, deadline = new bignumber_js_1.default(1_000_000), amount) {
283
- const approveAmount = amount ? amount : new bignumber_js_1.default(2).pow(256).minus(1);
284
- const expiration = new bignumber_js_1.default(Date.now()).plus(deadline).toFixed();
285
- const tx = this.encodePermit2Approve(tokenAddress, spenderAddress, permit2Address, expiration, approveAmount.toFixed());
286
- return this.write(fromAddress, tx.to, tx.value, tx.data);
287
- }
289
+ // public async getAllowance(fromTokenAddress: string, walletAddress: string, spenderAddress: string): Promise<AllowanceInfo> {
290
+ // const [decimals, allowance] = await Promise.all([
291
+ // this.read<string>(fromTokenAddress, erc20TokenAbi, 'decimals'),
292
+ // this.read<string>(fromTokenAddress, erc20TokenAbi, 'allowance', [walletAddress, spenderAddress])
293
+ // ]);
294
+ // const allowanceWeiBN = new BigNumber(allowance);
295
+ // const allowanceNonWei = Token.fromWei(allowanceWeiBN, Number(decimals));
296
+ // return { allowanceNonWei, allowanceWei: allowanceWeiBN };
297
+ // }
298
+ // public encodeApprove(tokenAddress: string, spenderAddress: string, amount?: string): EvmTransactionConfig {
299
+ // const amountWei = amount ?? new BigNumber(2).pow(256).minus(1).toFixed();
300
+ // const tx = EvmAdapter.encodeMethodCall(tokenAddress, erc20TokenAbi, 'approve', [spenderAddress, amountWei]);
301
+ // return {
302
+ // data: tx.data,
303
+ // to: tx.to,
304
+ // value: tx.value
305
+ // };
306
+ // }
307
+ // public async needApprove(token: TokenAmount, contractAddress: string, walletAddress: string, amount: string): Promise<boolean> {
308
+ // // Native coin in METIS can be Token required approve
309
+ // if (token.isNative && token.blockchain !== BLOCKCHAIN_NAME.METIS) {
310
+ // return false;
311
+ // }
312
+ // // Special native address for METIS native coin
313
+ // const fromTokenAddress =
314
+ // token.isNative && token.blockchain === BLOCKCHAIN_NAME.METIS ? '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000' : token.address;
315
+ // const { allowanceWei } = await this.getAllowance(fromTokenAddress, walletAddress, contractAddress);
316
+ // return allowanceWei.lt(token.weiAmount);
317
+ // }
318
+ // public async approve(fromAddress: string, tokenAddress: string, spenderAddress: string, amount?: string): Promise<string> {
319
+ // const config = this.encodeApprove(tokenAddress, spenderAddress, amount);
320
+ // return this.write(fromAddress, config.to, config.value, config.data);
321
+ // }
322
+ // public async needPermit2Approve(
323
+ // token: TokenAmount,
324
+ // permit2Address: string,
325
+ // walletAddress: string,
326
+ // spenderAddress: string
327
+ // ): Promise<boolean> {
328
+ // const res = await this.read<Permit2AllowanceContractResponse>(permit2Address, UNI_V3_PERMIT_2_ABI, 'allowance', [
329
+ // walletAddress,
330
+ // token.address,
331
+ // spenderAddress
332
+ // ]);
333
+ // const [amount, expiration, _nonce] = res;
334
+ // return token.weiAmount.gt(amount) || new BigNumber(Date.now()).gt(Number(expiration) * 1000);
335
+ // }
336
+ // public encodePermit2Approve(
337
+ // tokenAddress: string,
338
+ // spenderAddress: string,
339
+ // permit2Address: string,
340
+ // expiration: string,
341
+ // amount: string
342
+ // ): EvmTransactionConfig {
343
+ // const tx = EvmAdapter.encodeMethodCall(permit2Address, UNI_V3_PERMIT_2_ABI, 'approve', [
344
+ // tokenAddress,
345
+ // spenderAddress,
346
+ // amount,
347
+ // expiration
348
+ // ]);
349
+ // return {
350
+ // data: tx.data,
351
+ // value: tx.value,
352
+ // to: tx.to
353
+ // };
354
+ // }
355
+ // public async approveOnPermit2(
356
+ // fromAddress: string,
357
+ // tokenAddress: string,
358
+ // permit2Address: string,
359
+ // spenderAddress: string,
360
+ // deadline: BigNumber = new BigNumber(1_000_000),
361
+ // amount?: BigNumber
362
+ // ): Promise<string> {
363
+ // const approveAmount = amount ? amount : new BigNumber(2).pow(256).minus(1);
364
+ // const expiration = new BigNumber(Date.now()).plus(deadline).toFixed();
365
+ // const tx = this.encodePermit2Approve(tokenAddress, spenderAddress, permit2Address, expiration, approveAmount.toFixed());
366
+ // return this.write(fromAddress, tx.to, tx.value, tx.data);
367
+ // }
288
368
  /**
289
369
  * Calculates EIP-1559 specific gas details.
290
370
  * @see {@link https://github.com/ethers-io/ethers.js/blob/master/packages/abstract-provider/src.ts/index.ts#L235}
@@ -0,0 +1,38 @@
1
+ import BigNumber from 'bignumber.js';
2
+ import { BasicSendTransactionOptions } from '../../models/basic-transaction-options';
3
+ import { EIP1559Gas, SingleGasPrice } from '../../models/evm-web3-public-models/gas-price';
4
+ export interface EvmSendTxParams {
5
+ txOptions: EvmTransactionOptions;
6
+ }
7
+ export interface EvmTransactionOptions extends EvmBasicTransactionOptions {
8
+ /**
9
+ * Encoded data, which will be executed in transaction.
10
+ */
11
+ data?: string;
12
+ /**
13
+ * Native token amount in wei.
14
+ */
15
+ value?: BigNumber | string | bigint;
16
+ /**
17
+ * Use in case of eip-155
18
+ */
19
+ chainId?: string;
20
+ /**
21
+ * gasLimit multiplier (to change ratio for specific chain)
22
+ */
23
+ gasLimitRatio?: number;
24
+ /**
25
+ * Address send transaction to
26
+ */
27
+ to?: string;
28
+ }
29
+ export interface EvmBasicTransactionOptions extends BasicSendTransactionOptions {
30
+ /**
31
+ * Transaction gas limit.
32
+ */
33
+ gas?: string;
34
+ /**
35
+ * Transaction gas price options.
36
+ */
37
+ gasPriceOptions?: EIP1559Gas | SingleGasPrice;
38
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,12 @@
1
+ import { RubicSdkError } from 'packages/web3/src/lib/errors/rubic-sdk.error';
2
+ /**
3
+ * Type of errors, thrown by web3 methods.
4
+ */
5
+ export interface Web3Error extends Error {
6
+ code: number;
7
+ }
8
+ /**
9
+ * Parses web3 error by its code or message.
10
+ * @param err Web3 error to parse.
11
+ */
12
+ export declare function parseEvmError(err: Web3Error): RubicSdkError;
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseEvmError = parseEvmError;
4
+ const low_gas_error_1 = require("packages/web3/src/lib/errors/blockchain/low-gas.error");
5
+ const transaction_reverted_error_1 = require("packages/web3/src/lib/errors/blockchain/transaction-reverted.error");
6
+ const user_reject_error_1 = require("packages/web3/src/lib/errors/blockchain/user-reject.error");
7
+ const insufficient_funds_gas_price_value_error_1 = require("packages/web3/src/lib/errors/cross-chain/insufficient-funds-gas-price-value.error");
8
+ const rubic_sdk_error_1 = require("packages/web3/src/lib/errors/rubic-sdk.error");
9
+ const failed_to_check_for_transaction_receipt_error_1 = require("packages/web3/src/lib/errors/swap/failed-to-check-for-transaction-receipt.error");
10
+ const low_slippage_error_1 = require("packages/web3/src/lib/errors/swap/low-slippage.error");
11
+ const proxy_hash_errors_1 = require("../constants/proxy-hash-errors");
12
+ const low_slippage_deflationary_token_error_1 = require("packages/web3/src/lib/errors/swap/low-slippage-deflationary-token.error");
13
+ const errors_1 = require("../../utils/errors");
14
+ /**
15
+ * Parses web3 error by its code or message.
16
+ * @param err Web3 error to parse.
17
+ */
18
+ function parseEvmError(err) {
19
+ if (err.message.includes('Transaction has been reverted by the EVM')) {
20
+ return new transaction_reverted_error_1.TransactionRevertedError();
21
+ }
22
+ if (err.message.includes('execution reverted: UNIV3R: min return')) {
23
+ return new low_slippage_error_1.LowSlippageError();
24
+ }
25
+ if (err.message.includes('execution reverted: Address: low-level call with value failed') || err.message.includes('Low native value')) {
26
+ return new insufficient_funds_gas_price_value_error_1.InsufficientFundsGasPriceValueError();
27
+ }
28
+ if (err.message.includes('Failed to check for transaction receipt')) {
29
+ return new failed_to_check_for_transaction_receipt_error_1.FailedToCheckForTransactionReceiptError();
30
+ }
31
+ if (err.code === -32603) {
32
+ return new low_gas_error_1.LowGasError();
33
+ }
34
+ if (err.code === 4001 ||
35
+ err.message.toLowerCase().includes('user denied transaction signature') ||
36
+ err.message.toLowerCase().includes('user rejected the request')) {
37
+ return new user_reject_error_1.UserRejectError();
38
+ }
39
+ try {
40
+ const error = tryParseProxyError(err);
41
+ if (error) {
42
+ return error;
43
+ }
44
+ if (err.message.includes('0x6c544f')) {
45
+ return new insufficient_funds_gas_price_value_error_1.InsufficientFundsGasPriceValueError();
46
+ }
47
+ if (err.message.includes('0xf32bec2f') ||
48
+ err.message.includes('execution reverted: Received amount of tokens are less then expected') ||
49
+ err.message.includes('0x275c273c')) {
50
+ return new low_slippage_deflationary_token_error_1.LowSlippageDeflationaryTokenError();
51
+ }
52
+ const errorMessage = JSON.parse(err.message.slice(24)).message;
53
+ if (errorMessage) {
54
+ return new Error(errorMessage);
55
+ }
56
+ }
57
+ catch {
58
+ /* empty */
59
+ }
60
+ return (0, errors_1.parseError)(err);
61
+ }
62
+ function tryParseProxyError(err) {
63
+ if ('data' in err) {
64
+ const error = proxy_hash_errors_1.proxyHashErrors.find((error) => error.hash === err.data);
65
+ if (error) {
66
+ return new rubic_sdk_error_1.RubicSdkError(error.text);
67
+ }
68
+ }
69
+ return undefined;
70
+ }
@@ -0,0 +1,15 @@
1
+ import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
2
+ import { SolanaWeb3 } from '../../../constants/models/solana-web3';
3
+ import { RubicAppAdaptersFactoryParams } from '../../../constants/models/create-factory-params';
4
+ import { SolanaSendTxParams } from '../models/solana-send-tx-params';
5
+ import { Connection } from '@solana/web3.js';
6
+ import { AbstractAdapterClient } from '../../common/client/abstract-adapter-client';
7
+ import { TxStatus } from '../../models/web3-public-models/tx-status';
8
+ export declare class SolanaAdapterClient extends AbstractAdapterClient<SolanaWeb3, SolanaSendTxParams, string> {
9
+ private readonly connection;
10
+ constructor(connection: Connection, httpClient: HttpClient, logger?: ICustomLogger, rubicAppParams?: RubicAppAdaptersFactoryParams);
11
+ getBlockchainName(): Promise<BlockchainName>;
12
+ getTransactionStatus(txHash: string): Promise<TxStatus>;
13
+ sendTransaction(params: SolanaSendTxParams): Promise<string>;
14
+ private waitForTxConfirmation;
15
+ }
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SolanaAdapterClient = void 0;
4
+ const core_1 = require("@cryptorubic/core");
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const waitFor_1 = require("../../utils/waitFor");
7
+ const timeout_error_1 = require("../../../../errors/common/timeout.error");
8
+ const js_base64_1 = require("js-base64");
9
+ const user_reject_error_1 = require("../../../../errors/blockchain/user-reject.error");
10
+ const errors_1 = require("../../utils/errors");
11
+ const abstract_adapter_client_1 = require("../../common/client/abstract-adapter-client");
12
+ const tx_status_1 = require("../../models/web3-public-models/tx-status");
13
+ class SolanaAdapterClient extends abstract_adapter_client_1.AbstractAdapterClient {
14
+ constructor(connection, httpClient, logger, rubicAppParams) {
15
+ super(httpClient, logger, rubicAppParams);
16
+ this.connection = connection;
17
+ }
18
+ getBlockchainName() {
19
+ return Promise.resolve(core_1.BLOCKCHAIN_NAME.SOLANA);
20
+ }
21
+ async getTransactionStatus(txHash) {
22
+ try {
23
+ const transaction = await this.connection.getTransaction(txHash, {
24
+ maxSupportedTransactionVersion: 1
25
+ });
26
+ if (transaction?.meta?.err) {
27
+ return tx_status_1.TX_STATUS.FAIL;
28
+ }
29
+ if (transaction?.blockTime) {
30
+ return tx_status_1.TX_STATUS.SUCCESS;
31
+ }
32
+ return tx_status_1.TX_STATUS.PENDING;
33
+ }
34
+ catch {
35
+ return tx_status_1.TX_STATUS.PENDING;
36
+ }
37
+ }
38
+ async sendTransaction(params) {
39
+ try {
40
+ const decodedData = js_base64_1.Base64.toUint8Array(params.txOptions.data);
41
+ const tx = web3_js_1.VersionedTransaction.deserialize(decodedData);
42
+ const signedTx = await this.clientWallet.signTransaction(tx);
43
+ const txBase64 = js_base64_1.Base64.fromUint8Array(signedTx.serialize());
44
+ let signature;
45
+ if (params.txOptions?.sponsorParams) {
46
+ const response = await this.httpClient.post(`${this.apiUrl}/api/utility/solana/relay`, {
47
+ txBase64,
48
+ tradeId: params.txOptions.sponsorParams.tradeId
49
+ });
50
+ signature = response.signature;
51
+ }
52
+ else {
53
+ try {
54
+ const simulation = await this.connection.simulateTransaction(signedTx, {
55
+ sigVerify: true,
56
+ replaceRecentBlockhash: false
57
+ });
58
+ console.log(simulation);
59
+ }
60
+ catch (err) {
61
+ console.log(err);
62
+ }
63
+ signature = await this.connection.sendRawTransaction(signedTx.serialize(), {
64
+ maxRetries: 3,
65
+ skipPreflight: false
66
+ });
67
+ }
68
+ params.txOptions.onTransactionHash?.(signature);
69
+ await this.waitForTxConfirmation(signature);
70
+ return signature;
71
+ }
72
+ catch (err) {
73
+ console.error(`[SolanaWeb3Private_sendTransaction] Error: ${err}`, { name: err.name, stack: err.stack });
74
+ if (err.message.includes('User rejected')) {
75
+ throw new user_reject_error_1.UserRejectError();
76
+ }
77
+ throw (0, errors_1.parseError)(err);
78
+ }
79
+ }
80
+ async waitForTxConfirmation(signature) {
81
+ const deadline = Date.now() + 3 * 60 * 1000;
82
+ let fetchedTx = null;
83
+ while (!fetchedTx && Date.now() < deadline) {
84
+ await (0, waitFor_1.waitFor)(5000);
85
+ fetchedTx = await this.connection.getTransaction(signature, {
86
+ commitment: 'confirmed',
87
+ maxSupportedTransactionVersion: 1
88
+ });
89
+ }
90
+ if (!fetchedTx || fetchedTx.meta?.err)
91
+ throw new timeout_error_1.TimeoutError();
92
+ }
93
+ }
94
+ exports.SolanaAdapterClient = SolanaAdapterClient;
@@ -0,0 +1,16 @@
1
+ import { BasicSendTransactionOptions } from '../../models/basic-transaction-options';
2
+ export interface SolanaSendTxParams {
3
+ txOptions: SolanaTransactionOptions;
4
+ calculateConsumedParams?: boolean;
5
+ additionalData?: string[];
6
+ }
7
+ export interface SolanaTransactionOptions extends BasicSendTransactionOptions {
8
+ /**
9
+ * Encoded data, which will be executed in transaction.
10
+ */
11
+ data?: string;
12
+ sponsorParams?: {
13
+ tradeId: string;
14
+ feePayer: string;
15
+ };
16
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,18 +3,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SolanaTokensService = void 0;
4
4
  const spl_token_1 = require("@solana/spl-token");
5
5
  const utl_sdk_1 = require("@solflare-wallet/utl-sdk");
6
- const timeout_1 = require("../timeout");
6
+ const timeout_1 = require("../../utils/timeout");
7
7
  class SolanaTokensService {
8
- httpClient;
9
- connection;
10
- // key - address of token, value - idx of token in initial tokensAddress
11
- tokensOrder = {};
12
- initialMints = [];
13
- apiEndpoint = 'https://x-api.rubic.exchange/sol_token_list';
14
- newTokensEndpoint = 'https://api.rubic.exchange/api/v2';
15
- xApiKey = 'sndfje3u4b3fnNSDNFUSDNVSunw345842hrnfd3b4nt4';
16
8
  constructor(connection, httpClient) {
17
9
  this.httpClient = httpClient;
10
+ // key - address of token, value - idx of token in initial tokensAddress
11
+ this.tokensOrder = {};
12
+ this.initialMints = [];
13
+ this.apiEndpoint = 'https://x-api.rubic.exchange/sol_token_list';
14
+ this.newTokensEndpoint = 'https://api.rubic.exchange/api/v2';
15
+ this.xApiKey = 'sndfje3u4b3fnNSDNFUSDNVSunw345842hrnfd3b4nt4';
18
16
  this.connection = connection;
19
17
  }
20
18
  async fetchTokensData(mints) {
@@ -59,7 +57,7 @@ class SolanaTokensService {
59
57
  }
60
58
  async fetchTokensFromOldBackend(mints, prevFetchedTokens) {
61
59
  const tokensAddresses = mints.map((mint) => mint.toString());
62
- const { content: tokensFromOlbBackend } = await (0, timeout_1.withTimeout)(this.getTokensListOld(tokensAddresses), 3_000, 'Api Timeout!').catch(() => ({ content: [] }));
60
+ const { content: tokensFromOlbBackend } = await (0, timeout_1.withTimeout)(this.getTokensListOld(tokensAddresses), 3000, 'Api Timeout!').catch(() => ({ content: [] }));
63
61
  const notSortedTokensList = [...prevFetchedTokens, ...tokensFromOlbBackend];
64
62
  const notFetchedMints = this.getNotFetchedTokensList(notSortedTokensList);
65
63
  return {