@cryptorubic/web3 0.0.35 → 0.0.37-alpha-1212.0
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.
- package/package.json +42 -15
- package/src/index.d.ts +130 -20
- package/src/index.js +130 -18
- package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.d.ts +40 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/bitcoin-adapter.js +177 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-send-tx-params.d.ts +5 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-psbt-encoded-config.d.ts +5 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-psbt-encoded-config.js +2 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-trade-types.d.ts +7 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-trade-types.js +2 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-transfer-encoded-config.d.ts +6 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/models/btc-web3-private-models/bitcoin-transfer-encoded-config.js +2 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/signer/bitcoin-adapter-signer.d.ts +17 -0
- package/src/lib/adapter/adapters/adapter-bitcoin/signer/bitcoin-adapter-signer.js +131 -0
- package/src/lib/adapter/adapters/adapter-evm/constants/proxy-hash-errors.d.ts +4 -0
- package/src/lib/adapter/adapters/adapter-evm/constants/proxy-hash-errors.js +705 -0
- package/src/lib/adapter/adapters/adapter-evm/evm-adapter.d.ts +120 -0
- package/src/lib/adapter/adapters/adapter-evm/evm-adapter.js +498 -0
- package/src/lib/adapter/adapters/adapter-evm/models/evm-send-tx-params.d.ts +38 -0
- package/src/lib/adapter/adapters/adapter-evm/models/evm-send-tx-params.js +2 -0
- package/src/lib/adapter/adapters/adapter-evm/signer/evm-adapter-signer.d.ts +53 -0
- package/src/lib/adapter/adapters/adapter-evm/signer/evm-adapter-signer.js +263 -0
- package/src/lib/adapter/adapters/adapter-evm/utils/parse-evm-error.d.ts +12 -0
- package/src/lib/adapter/adapters/adapter-evm/utils/parse-evm-error.js +70 -0
- package/src/lib/adapter/adapters/adapter-solana/models/solana-send-tx-params.d.ts +16 -0
- package/src/lib/adapter/adapters/adapter-solana/models/solana-send-tx-params.js +2 -0
- package/src/lib/adapter/adapters/adapter-solana/services/solana-tokens-service.d.ts +22 -0
- package/src/lib/adapter/adapters/adapter-solana/services/solana-tokens-service.js +138 -0
- package/src/lib/adapter/adapters/adapter-solana/signer/solana-adapter-signer.d.ts +17 -0
- package/src/lib/adapter/adapters/adapter-solana/signer/solana-adapter-signer.js +87 -0
- package/src/lib/adapter/adapters/adapter-solana/solana-adapter.d.ts +49 -0
- package/src/lib/adapter/adapters/adapter-solana/solana-adapter.js +231 -0
- package/src/lib/adapter/adapters/adapter-stellar/constants/fake-stellar-wallet.d.ts +1 -0
- package/src/lib/adapter/adapters/adapter-stellar/constants/fake-stellar-wallet.js +4 -0
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-client.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-client.js +2 -0
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-rpc-provider.d.ts +6 -0
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-rpc-provider.js +2 -0
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-send-tx-params.d.ts +8 -0
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-send-tx-params.js +2 -0
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-wallet.d.ts +87 -0
- package/src/lib/adapter/adapters/adapter-stellar/models/stellar-wallet.js +2 -0
- package/src/lib/adapter/adapters/adapter-stellar/signer/stellar-adapter-signer.d.ts +18 -0
- package/src/lib/adapter/adapters/adapter-stellar/signer/stellar-adapter-signer.js +75 -0
- package/src/lib/adapter/adapters/adapter-stellar/stellar-adapter.d.ts +54 -0
- package/src/lib/adapter/adapters/adapter-stellar/stellar-adapter.js +253 -0
- package/src/lib/adapter/adapters/adapter-sui/models/sui-send-tx-params.d.ts +8 -0
- package/src/lib/adapter/adapters/adapter-sui/models/sui-send-tx-params.js +2 -0
- package/src/lib/adapter/adapters/adapter-sui/signer/sui-adapter-signer.d.ts +17 -0
- package/src/lib/adapter/adapters/adapter-sui/signer/sui-adapter-signer.js +55 -0
- package/src/lib/adapter/adapters/adapter-sui/sui-adapter.d.ts +32 -0
- package/src/lib/adapter/adapters/adapter-sui/sui-adapter.js +111 -0
- package/src/lib/adapter/adapters/adapter-ton/models/ton-send-tx-params.d.ts +26 -0
- package/src/lib/adapter/adapters/adapter-ton/models/ton-send-tx-params.js +2 -0
- package/src/lib/adapter/adapters/{utils → adapter-ton/services}/ton-api.service.d.ts +8 -7
- package/src/lib/adapter/adapters/{utils → adapter-ton/services}/ton-api.service.js +39 -56
- package/src/lib/adapter/adapters/adapter-ton/signer/ton-adapter-signer.d.ts +43 -0
- package/src/lib/adapter/adapters/adapter-ton/signer/ton-adapter-signer.js +166 -0
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.d.ts +32 -0
- package/src/lib/adapter/adapters/adapter-ton/ton-adapter.js +104 -0
- package/src/lib/adapter/adapters/adapter-tron/models/tron-send-tx-params.d.ts +13 -0
- package/src/lib/adapter/adapters/adapter-tron/models/tron-send-tx-params.js +2 -0
- package/src/lib/adapter/adapters/adapter-tron/models/tron-transfer-tx-params.d.ts +7 -0
- package/src/lib/adapter/adapters/adapter-tron/models/tron-transfer-tx-params.js +2 -0
- package/src/lib/adapter/adapters/adapter-tron/models/tron-web-provider.d.ts +4 -0
- package/src/lib/adapter/adapters/adapter-tron/models/tron-web-provider.js +2 -0
- package/src/lib/adapter/adapters/adapter-tron/signer/tron-adapter-signer.d.ts +19 -0
- package/src/lib/adapter/adapters/adapter-tron/signer/tron-adapter-signer.js +81 -0
- package/src/lib/adapter/adapters/adapter-tron/tron-adapter.d.ts +57 -0
- package/src/lib/adapter/adapters/{tron-adapter.js → adapter-tron/tron-adapter.js} +142 -69
- package/src/lib/adapter/adapters/adapter-tron/utils/parse-tron-error.d.ts +2 -0
- package/src/lib/adapter/adapters/adapter-tron/utils/parse-tron-error.js +20 -0
- package/src/lib/adapter/adapters/common/abstract-adapter.d.ts +84 -0
- package/src/lib/adapter/adapters/common/abstract-adapter.js +82 -0
- package/src/lib/adapter/adapters/common/signer/abstract-adapter-signer.d.ts +22 -0
- package/src/lib/adapter/adapters/common/signer/abstract-adapter-signer.js +42 -0
- package/src/lib/adapter/adapters/constants/possible-errors.d.ts +1 -0
- package/src/lib/adapter/adapters/constants/possible-errors.js +14 -0
- package/src/lib/adapter/adapters/constants/tron-multicall-abi.d.ts +1 -1
- package/src/lib/adapter/adapters/constants/uni-v3-permit-abi.d.ts +2 -0
- package/src/lib/adapter/adapters/constants/uni-v3-permit-abi.js +72 -0
- package/src/lib/adapter/adapters/models/approve-adapter.d.ts +16 -8
- package/src/lib/adapter/adapters/models/approve-adapter.js +4 -0
- package/src/lib/adapter/adapters/models/basic-transaction-options.d.ts +7 -0
- package/src/lib/adapter/adapters/models/basic-transaction-options.js +2 -0
- package/src/lib/adapter/adapters/models/bitcoin-user-address-info.d.ts +53 -0
- package/src/lib/adapter/adapters/models/bitcoin-user-address-info.js +2 -0
- package/src/lib/adapter/adapters/models/btc-wallet-provider.d.ts +10 -0
- package/src/lib/adapter/adapters/models/btc-wallet-provider.js +2 -0
- package/src/lib/adapter/adapters/models/evm-adapter-options.d.ts +1 -1
- package/src/lib/adapter/adapters/models/evm-web3-public-models/batch-call.d.ts +5 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/batch-call.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-call.d.ts +4 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-call.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-multicall-response.d.ts +4 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/evm-multicall-response.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/gas-price-viem.d.ts +18 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/gas-price-viem.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/gas-price.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/permit2-contract-types.d.ts +10 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/permit2-contract-types.js +2 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/rpc-response.d.ts +5 -0
- package/src/lib/adapter/adapters/models/evm-web3-public-models/rpc-response.js +2 -0
- package/src/lib/adapter/adapters/models/old-features-models/contract-params.d.ts +23 -0
- package/src/lib/adapter/adapters/models/old-features-models/contract-params.js +2 -0
- package/src/lib/adapter/adapters/models/old-features-models/encode-transaction-options.d.ts +32 -0
- package/src/lib/adapter/adapters/models/old-features-models/encode-transaction-options.js +2 -0
- package/src/lib/adapter/adapters/models/old-features-models/is-deflation-token.d.ts +6 -0
- package/src/lib/adapter/adapters/models/old-features-models/is-deflation-token.js +2 -0
- package/src/lib/adapter/adapters/models/old-features-models/non-evm-chain-address-correct-response.d.ts +5 -0
- package/src/lib/adapter/adapters/models/old-features-models/non-evm-chain-address-correct-response.js +2 -0
- package/src/lib/adapter/adapters/models/old-features-models/swap-transaction-options.d.ts +65 -0
- package/src/lib/adapter/adapters/models/old-features-models/swap-transaction-options.js +2 -0
- package/src/lib/adapter/adapters/models/permit2-contract-types.d.ts +1 -0
- package/src/lib/adapter/adapters/models/permit2-contract-types.js +2 -0
- package/src/lib/adapter/adapters/models/solana-web3-types.d.ts +60 -0
- package/src/lib/adapter/adapters/models/solana-web3-types.js +2 -0
- package/src/lib/adapter/adapters/models/status-manager-models/tx-status-data.d.ts +8 -0
- package/src/lib/adapter/adapters/models/status-manager-models/tx-status-data.js +2 -0
- package/src/lib/adapter/adapters/models/token-models.d.ts +1 -0
- package/src/lib/adapter/adapters/models/token-models.js +2 -0
- package/src/lib/adapter/adapters/models/ton-adapter-config.d.ts +2 -2
- package/src/lib/adapter/adapters/models/ton-api-config.d.ts +1 -1
- package/src/lib/adapter/adapters/models/tonapi-models.d.ts +2 -2
- package/src/lib/adapter/adapters/models/web3-public-models/contract-multicall-response.d.ts +5 -0
- package/src/lib/adapter/adapters/models/web3-public-models/contract-multicall-response.js +2 -0
- package/src/lib/adapter/adapters/models/web3-public-models/method-data.d.ts +4 -0
- package/src/lib/adapter/adapters/models/web3-public-models/method-data.js +2 -0
- package/src/lib/adapter/adapters/models/web3-public-models/supported-token-field.d.ts +1 -0
- package/src/lib/adapter/adapters/models/web3-public-models/supported-token-field.js +2 -0
- package/src/lib/adapter/adapters/models/web3-public-models/tx-status.d.ts +13 -0
- package/src/lib/adapter/adapters/models/web3-public-models/tx-status.js +15 -0
- package/src/lib/adapter/adapters/utils/errors.d.ts +2 -0
- package/src/lib/adapter/adapters/utils/errors.js +10 -0
- package/src/lib/adapter/adapters/utils/options.d.ts +10 -0
- package/src/lib/adapter/adapters/utils/options.js +59 -0
- package/src/lib/adapter/adapters/utils/timeout.d.ts +1 -0
- package/src/lib/adapter/adapters/utils/timeout.js +15 -0
- package/src/lib/adapter/adapters/utils/waitFor.d.ts +1 -0
- package/src/lib/adapter/adapters/utils/waitFor.js +6 -0
- package/src/lib/adapter/blockchain-adapter-factory.service.d.ts +19 -11
- package/src/lib/adapter/blockchain-adapter-factory.service.js +58 -57
- package/src/lib/adapter/constants/chain-configs/chain-configs.d.ts +1 -1
- package/src/lib/adapter/constants/chain-configs/chain-configs.js +603 -138
- package/src/lib/adapter/constants/models/env-type.d.ts +1 -0
- package/src/lib/adapter/constants/models/env-type.js +2 -0
- package/src/lib/adapter/constants/models/solana-web3.d.ts +1 -1
- package/src/lib/adapter/constants/models/wallet-provider.d.ts +9 -3
- package/src/lib/adapter/constants/rubic-api-link-mapping.d.ts +2 -0
- package/src/lib/adapter/constants/rubic-api-link-mapping.js +16 -0
- package/src/lib/adapter/constants/viem-blockchain-mapping.d.ts +1 -1
- package/src/lib/adapter/constants/viem-blockchain-mapping.js +16 -7
- package/src/lib/adapter/models/create-factory-params.d.ts +24 -0
- package/src/lib/adapter/models/create-factory-params.js +2 -0
- package/src/lib/errors/blockchain/deflation-token.error.d.ts +11 -0
- package/src/lib/errors/blockchain/deflation-token.error.js +16 -0
- package/src/lib/errors/blockchain/healthcheck.error.d.ts +8 -0
- package/src/lib/errors/blockchain/healthcheck.error.js +15 -0
- package/src/lib/errors/blockchain/inactive-account.error.d.ts +4 -0
- package/src/lib/errors/blockchain/inactive-account.error.js +11 -0
- package/src/lib/errors/blockchain/invalid-address.error.d.ts +8 -0
- package/src/lib/errors/blockchain/invalid-address.error.js +15 -0
- package/src/lib/errors/blockchain/low-gas.error.d.ts +7 -0
- package/src/lib/errors/blockchain/low-gas.error.js +14 -0
- package/src/lib/errors/blockchain/transaction-reverted.error.d.ts +7 -0
- package/src/lib/errors/blockchain/transaction-reverted.error.js +14 -0
- package/src/lib/errors/blockchain/tron-insufficient-native-balance.d.ts +7 -0
- package/src/lib/errors/blockchain/tron-insufficient-native-balance.js +14 -0
- package/src/lib/errors/blockchain/tron-transaction-expired.d.ts +7 -0
- package/src/lib/errors/blockchain/tron-transaction-expired.js +14 -0
- package/src/lib/errors/blockchain/user-reject.error.d.ts +7 -0
- package/src/lib/errors/blockchain/user-reject.error.js +14 -0
- package/src/lib/errors/blockchain/wrong-from-address.error.d.ts +7 -0
- package/src/lib/errors/blockchain/wrong-from-address.error.js +14 -0
- package/src/lib/errors/blockchain/wrong-receiver-address.error.d.ts +7 -0
- package/src/lib/errors/blockchain/wrong-receiver-address.error.js +14 -0
- package/src/lib/errors/common/timeout.error.d.ts +4 -0
- package/src/lib/errors/common/timeout.error.js +12 -0
- package/src/lib/errors/common/tx-reverted-in-chain.error.d.ts +4 -0
- package/src/lib/errors/common/tx-reverted-in-chain.error.js +11 -0
- package/src/lib/errors/cross-chain/cross-chain-is-unavailable.error.d.ts +7 -0
- package/src/lib/errors/cross-chain/cross-chain-is-unavailable.error.js +14 -0
- package/src/lib/errors/cross-chain/insufficient-funds-gas-price-value.error.d.ts +7 -0
- package/src/lib/errors/cross-chain/insufficient-funds-gas-price-value.error.js +14 -0
- package/src/lib/errors/cross-chain/low-to-slippage.error.d.ts +6 -0
- package/src/lib/errors/cross-chain/low-to-slippage.error.js +10 -0
- package/src/lib/errors/cross-chain/max-gas-price-overflow.error.d.ts +8 -0
- package/src/lib/errors/cross-chain/max-gas-price-overflow.error.js +15 -0
- package/src/lib/errors/cross-chain/too-low-amount.error.d.ts +7 -0
- package/src/lib/errors/cross-chain/too-low-amount.error.js +14 -0
- package/src/lib/errors/cross-chain/unsupported-receiver-address.error.d.ts +4 -0
- package/src/lib/errors/cross-chain/unsupported-receiver-address.error.js +11 -0
- package/src/lib/errors/cross-chain/updated-rates-error.d.ts +10 -0
- package/src/lib/errors/cross-chain/updated-rates-error.js +17 -0
- package/src/lib/errors/models/rubic-api-error.d.ts +21 -0
- package/src/lib/errors/models/rubic-api-error.js +2 -0
- package/src/lib/errors/on-chain/on-chain-is-unavailable.error.d.ts +7 -0
- package/src/lib/errors/on-chain/on-chain-is-unavailable.error.js +14 -0
- package/src/lib/errors/proxy/unapproved-contract-error.d.ts +8 -0
- package/src/lib/errors/proxy/unapproved-contract-error.js +15 -0
- package/src/lib/errors/proxy/unapproved-method-error.d.ts +8 -0
- package/src/lib/errors/proxy/unapproved-method-error.js +15 -0
- package/src/lib/errors/proxy/unlisted-error.d.ts +9 -0
- package/src/lib/errors/proxy/unlisted-error.js +16 -0
- package/src/lib/errors/rubic-sdk.error.d.ts +6 -0
- package/src/lib/errors/rubic-sdk.error.js +13 -0
- package/src/lib/errors/swap/bridgers-pair-is-unavailable.error.d.ts +7 -0
- package/src/lib/errors/swap/bridgers-pair-is-unavailable.error.js +14 -0
- package/src/lib/errors/swap/failed-to-check-for-transaction-receipt.error.d.ts +8 -0
- package/src/lib/errors/swap/failed-to-check-for-transaction-receipt.error.js +15 -0
- package/src/lib/errors/swap/insufficient-funds-oneinch.error.d.ts +9 -0
- package/src/lib/errors/swap/insufficient-funds-oneinch.error.js +15 -0
- package/src/lib/errors/swap/insufficient-funds.error.d.ts +11 -0
- package/src/lib/errors/swap/insufficient-funds.error.js +18 -0
- package/src/lib/errors/swap/insufficient-liquidity.error.d.ts +7 -0
- package/src/lib/errors/swap/insufficient-liquidity.error.js +14 -0
- package/src/lib/errors/swap/lifi-pair-is-unavailable.error.d.ts +7 -0
- package/src/lib/errors/swap/lifi-pair-is-unavailable.error.js +14 -0
- package/src/lib/errors/swap/low-slippage-deflationary-token.error.d.ts +7 -0
- package/src/lib/errors/swap/low-slippage-deflationary-token.error.js +14 -0
- package/src/lib/errors/swap/low-slippage.error.d.ts +8 -0
- package/src/lib/errors/swap/low-slippage.error.js +15 -0
- package/src/lib/errors/swap/max-amount.error.d.ts +7 -0
- package/src/lib/errors/swap/max-amount.error.js +14 -0
- package/src/lib/errors/swap/max-decimals.error.d.ts +5 -0
- package/src/lib/errors/swap/max-decimals.error.js +12 -0
- package/src/lib/errors/swap/min-amount.error.d.ts +7 -0
- package/src/lib/errors/swap/min-amount.error.js +14 -0
- package/src/lib/errors/swap/no-linked-account-erros.d.ts +4 -0
- package/src/lib/errors/swap/no-linked-account-erros.js +11 -0
- package/src/lib/errors/swap/not-supported-blockchain.d.ts +8 -0
- package/src/lib/errors/swap/not-supported-blockchain.js +15 -0
- package/src/lib/errors/swap/not-supported-region.d.ts +7 -0
- package/src/lib/errors/swap/not-supported-region.js +14 -0
- package/src/lib/errors/swap/not-supported-tokens.error.d.ts +7 -0
- package/src/lib/errors/swap/not-supported-tokens.error.js +14 -0
- package/src/lib/errors/swap/not-whitelisted-provider.error.d.ts +10 -0
- package/src/lib/errors/swap/not-whitelisted-provider.error.js +17 -0
- package/src/lib/errors/swap/simulation-failed.error.d.ts +6 -0
- package/src/lib/errors/swap/simulation-failed.error.js +12 -0
- package/src/lib/errors/swap/swap-error-on-provider-side.d.ts +7 -0
- package/src/lib/errors/swap/swap-error-on-provider-side.js +14 -0
- package/src/lib/errors/swap/swap-request.error.d.ts +7 -0
- package/src/lib/errors/swap/swap-request.error.js +14 -0
- package/src/lib/errors/swap/trade-expired.error.d.ts +4 -0
- package/src/lib/errors/swap/trade-expired.error.js +11 -0
- package/src/lib/errors/swap/unnecessary-approve.error.d.ts +7 -0
- package/src/lib/errors/swap/unnecessary-approve.error.js +14 -0
- package/src/lib/errors/swap/wallet-not-connected.error.d.ts +8 -0
- package/src/lib/errors/swap/wallet-not-connected.error.js +15 -0
- package/src/lib/errors/swap/wrong-network.error.d.ts +10 -0
- package/src/lib/errors/swap/wrong-network.error.js +16 -0
- package/src/lib/utils/constants/changenow-api-blockchain.d.ts +1 -2
- package/src/lib/utils/constants/changenow-api-blockchain.js +1 -1
- package/src/lib/utils/constants/web3-pure-store.d.ts +2 -2
- package/src/lib/utils/constants/web3-pure-store.js +20 -18
- package/src/lib/utils/models/contract-multicall-response.d.ts +1 -1
- package/src/lib/utils/models/evm-transaction-config.d.ts +2 -0
- package/src/lib/utils/models/primitive-types.d.ts +1 -1
- package/src/lib/utils/models/stellar-transaction-config.d.ts +3 -0
- package/src/lib/utils/models/stellar-transaction-config.js +2 -0
- package/src/lib/utils/models/tron-transaction-config.d.ts +1 -1
- package/src/lib/utils/web3-pure.d.ts +2 -2
- package/src/lib/utils/web3-pure.js +6 -7
- package/src/lib/utils/web3-types/bitcoin-web3-pure.d.ts +1 -1
- package/src/lib/utils/web3-types/common-web3-pure.js +0 -2
- package/src/lib/utils/web3-types/evm-web3-pure.d.ts +1 -1
- package/src/lib/utils/web3-types/icp-web3-pure.d.ts +1 -1
- package/src/lib/utils/web3-types/near-web3-pure.d.ts +6 -0
- package/src/lib/utils/web3-types/near-web3-pure.js +24 -0
- package/src/lib/utils/web3-types/solana-web3-pure.d.ts +2 -1
- package/src/lib/utils/web3-types/solana-web3-pure.js +11 -1
- package/src/lib/utils/web3-types/stellar-web3-pure.d.ts +5 -0
- package/src/lib/utils/web3-types/stellar-web3-pure.js +30 -0
- package/src/lib/utils/web3-types/sui-web3-pure.d.ts +8 -0
- package/src/lib/utils/web3-types/sui-web3-pure.js +27 -0
- package/src/lib/utils/web3-types/ton-web3-pure.d.ts +2 -1
- package/src/lib/utils/web3-types/ton-web3-pure.js +6 -0
- package/src/lib/utils/web3-types/tron-web3-pure.d.ts +7 -8
- package/src/lib/utils/web3-types/tron-web3-pure.js +5 -5
- package/src/lib/utils/web3-types/zcash-web3-pure.d.ts +5 -0
- package/src/lib/utils/web3-types/zcash-web3-pure.js +17 -0
- package/src/lib/adapter/adapters/abstract-adapter.d.ts +0 -22
- package/src/lib/adapter/adapters/abstract-adapter.js +0 -61
- package/src/lib/adapter/adapters/evm-adapter.d.ts +0 -55
- package/src/lib/adapter/adapters/evm-adapter.js +0 -326
- package/src/lib/adapter/adapters/solana-adapter.d.ts +0 -15
- package/src/lib/adapter/adapters/solana-adapter.js +0 -59
- package/src/lib/adapter/adapters/ton-adapter.d.ts +0 -22
- package/src/lib/adapter/adapters/ton-adapter.js +0 -100
- package/src/lib/adapter/adapters/tron-adapter.d.ts +0 -35
- /package/src/lib/adapter/adapters/{models/gas-price.js → adapter-bitcoin/models/btc-send-tx-params.js} +0 -0
- /package/src/lib/adapter/adapters/models/{gas-price.d.ts → evm-web3-public-models/gas-price.d.ts} +0 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaAdapterSigner = 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 js_base64_1 = require("js-base64");
|
|
8
|
+
const user_reject_error_1 = require("../../../../errors/blockchain/user-reject.error");
|
|
9
|
+
const errors_1 = require("../../utils/errors");
|
|
10
|
+
const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
|
|
11
|
+
const tx_reverted_in_chain_error_1 = require("../../../../errors/common/tx-reverted-in-chain.error");
|
|
12
|
+
class SolanaAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
|
|
13
|
+
get publicClient() {
|
|
14
|
+
if (!this.publicRef.public) {
|
|
15
|
+
const msg = `Trying to access undefined publicClient in SolanaAdapterSigner.`;
|
|
16
|
+
this.logger?.customLog(msg);
|
|
17
|
+
throw new Error(msg);
|
|
18
|
+
}
|
|
19
|
+
return this.publicRef.public;
|
|
20
|
+
}
|
|
21
|
+
constructor(publicRef, httpClient, logger, clientParams) {
|
|
22
|
+
super(httpClient, logger, clientParams);
|
|
23
|
+
this.publicRef = publicRef;
|
|
24
|
+
}
|
|
25
|
+
async write() {
|
|
26
|
+
throw new Error('Method write is not supported');
|
|
27
|
+
}
|
|
28
|
+
getBlockchainName() {
|
|
29
|
+
return Promise.resolve(core_1.BLOCKCHAIN_NAME.SOLANA);
|
|
30
|
+
}
|
|
31
|
+
async sendTransaction(params) {
|
|
32
|
+
try {
|
|
33
|
+
const decodedData = js_base64_1.Base64.toUint8Array(params.txOptions.data);
|
|
34
|
+
const tx = web3_js_1.VersionedTransaction.deserialize(decodedData);
|
|
35
|
+
const signedTx = await this.wallet.signTransaction(tx);
|
|
36
|
+
const txBase64 = js_base64_1.Base64.fromUint8Array(signedTx.serialize());
|
|
37
|
+
let signature;
|
|
38
|
+
if (params.txOptions?.sponsorParams) {
|
|
39
|
+
const response = await this.httpClient.post(`${this.apiUrl}/api/utility/solana/relay`, {
|
|
40
|
+
data: txBase64,
|
|
41
|
+
id: params.txOptions.sponsorParams.tradeId
|
|
42
|
+
});
|
|
43
|
+
signature = response.signature;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
try {
|
|
47
|
+
const simulation = await this.publicClient.simulateTransaction(signedTx, {
|
|
48
|
+
sigVerify: true,
|
|
49
|
+
replaceRecentBlockhash: false
|
|
50
|
+
});
|
|
51
|
+
console.log(simulation);
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
console.log(err);
|
|
55
|
+
}
|
|
56
|
+
signature = await this.publicClient.sendRawTransaction(signedTx.serialize(), {
|
|
57
|
+
maxRetries: 3,
|
|
58
|
+
skipPreflight: false
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
params.txOptions.onTransactionHash?.(signature);
|
|
62
|
+
await this.waitForTxConfirmation(signature);
|
|
63
|
+
return signature;
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.error(`[SolanaWeb3Private_sendTransaction] Error: ${err}`, { name: err.name, stack: err.stack });
|
|
67
|
+
if (err.message.includes('User rejected')) {
|
|
68
|
+
throw new user_reject_error_1.UserRejectError();
|
|
69
|
+
}
|
|
70
|
+
throw (0, errors_1.parseError)(err);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async waitForTxConfirmation(signature) {
|
|
74
|
+
const deadline = Date.now() + 3 * 60 * 1000;
|
|
75
|
+
let fetchedTx = null;
|
|
76
|
+
while (!fetchedTx && Date.now() < deadline) {
|
|
77
|
+
await (0, waitFor_1.waitFor)(5000);
|
|
78
|
+
fetchedTx = await this.publicClient.getTransaction(signature, {
|
|
79
|
+
commitment: 'confirmed',
|
|
80
|
+
maxSupportedTransactionVersion: 1
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (!fetchedTx || fetchedTx.meta?.err)
|
|
84
|
+
throw new tx_reverted_in_chain_error_1.TxRevertedInBlockchainError();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.SolanaAdapterSigner = SolanaAdapterSigner;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AddressLookupTableAccount, Connection, Keypair, PublicKey, Transaction, TransactionInstruction, VersionedTransaction } from '@solana/web3.js';
|
|
2
|
+
import { HttpClient, ICustomLogger, PriceTokenAmount, SolanaBlockchainName, Token, TokenAmount } from '@cryptorubic/core';
|
|
3
|
+
import BigNumber from 'bignumber.js';
|
|
4
|
+
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
5
|
+
import { SolanaRawInstruction } from '../models/solana-web3-types';
|
|
6
|
+
import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
|
|
7
|
+
import { SolanaWeb3 } from '../../constants/models/solana-web3';
|
|
8
|
+
import { SolanaAdapterSigner } from './signer/solana-adapter-signer';
|
|
9
|
+
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
10
|
+
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
11
|
+
import { TxStatus } from '../models/web3-public-models/tx-status';
|
|
12
|
+
export declare class SolanaAdapter extends AbstractAdapter<Connection, SolanaWeb3, SolanaBlockchainName> {
|
|
13
|
+
private readonly rpcList;
|
|
14
|
+
private readonly httpClient;
|
|
15
|
+
readonly signer: SolanaAdapterSigner;
|
|
16
|
+
constructor(rpcList: string[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
17
|
+
initWeb3Client(): void;
|
|
18
|
+
callContractMethod<T extends Web3PrimitiveType = string>(): Promise<T>;
|
|
19
|
+
read<T>(): Promise<T>;
|
|
20
|
+
getTransactionStatus(txHash: string): Promise<TxStatus>;
|
|
21
|
+
/**
|
|
22
|
+
* Gets balance of multiple tokens.
|
|
23
|
+
* @param address Wallet address.
|
|
24
|
+
* @param tokensAddresses Tokens addresses.
|
|
25
|
+
*/
|
|
26
|
+
getTokensBalances(address: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
27
|
+
multicallContractsMethods<Output extends Web3PrimitiveType>(): Promise<ContractMulticallResponse<Output>[][]>;
|
|
28
|
+
getBlockNumber(): Promise<number | {
|
|
29
|
+
blockNumber: number;
|
|
30
|
+
workchain: number;
|
|
31
|
+
}>;
|
|
32
|
+
private createConection;
|
|
33
|
+
simulateTransaction(_config: object, _from: string): Promise<void>;
|
|
34
|
+
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
35
|
+
getBalance(userAddress: string, tokenAddress?: string): Promise<BigNumber>;
|
|
36
|
+
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<SolanaBlockchainName>[]>;
|
|
37
|
+
parseRawInstruction(rawInstruction: SolanaRawInstruction[], dataFormat: BufferEncoding): TransactionInstruction[];
|
|
38
|
+
parseLUTAddresses(lookupTableAddresses: string[]): Promise<AddressLookupTableAccount[]>;
|
|
39
|
+
createVersionedTransaction(instructions: TransactionInstruction[], walletAddress: string, addressLookupTableAccounts?: AddressLookupTableAccount[]): Promise<VersionedTransaction>;
|
|
40
|
+
getAtaAddress(walletAddress: string, tokenAddress: string): Promise<PublicKey>;
|
|
41
|
+
getKeypairFromSecret(pk?: string): Keypair | null;
|
|
42
|
+
getTxWithPayer(tx: VersionedTransaction, feePayer: string): Promise<VersionedTransaction>;
|
|
43
|
+
deserializeTransaction(data: string): VersionedTransaction;
|
|
44
|
+
serializeTransactionToBase58(tx: VersionedTransaction): string;
|
|
45
|
+
createTransferData(fromToken: PriceTokenAmount, walletAddress: string, receiver: string, convertToVersionedTx: boolean, allowOwnerOffCurve?: boolean): Promise<Transaction | VersionedTransaction>;
|
|
46
|
+
createNativeTransfer(fromAddress: PublicKey, toAddress: PublicKey, fromWeiAmount: string): Transaction;
|
|
47
|
+
createTokenTransfer(fromAddress: PublicKey, toAddress: PublicKey, fromTokenAddress: string, fromWeiAmount: string, allowOwnerOffCurve: boolean): Promise<Transaction>;
|
|
48
|
+
getLatestBlockhash(): Promise<string>;
|
|
49
|
+
}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SolanaAdapter = void 0;
|
|
4
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
+
const core_1 = require("@cryptorubic/core");
|
|
7
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
8
|
+
const bs58_1 = require("bs58");
|
|
9
|
+
const js_base64_1 = require("js-base64");
|
|
10
|
+
const abstract_adapter_1 = require("../common/abstract-adapter");
|
|
11
|
+
const web3_pure_1 = require("../../../utils/web3-pure");
|
|
12
|
+
const solana_tokens_service_1 = require("./services/solana-tokens-service");
|
|
13
|
+
const solana_adapter_signer_1 = require("./signer/solana-adapter-signer");
|
|
14
|
+
const tx_status_1 = require("../models/web3-public-models/tx-status");
|
|
15
|
+
class SolanaAdapter extends abstract_adapter_1.AbstractAdapter {
|
|
16
|
+
constructor(rpcList, httpClient, logger, clientParams) {
|
|
17
|
+
super(core_1.BLOCKCHAIN_NAME.SOLANA, logger);
|
|
18
|
+
this.rpcList = rpcList;
|
|
19
|
+
this.httpClient = httpClient;
|
|
20
|
+
this.signer = new solana_adapter_signer_1.SolanaAdapterSigner(this.publicRef, httpClient, logger, clientParams);
|
|
21
|
+
}
|
|
22
|
+
initWeb3Client() {
|
|
23
|
+
this.public = this.createConection(this.rpcList);
|
|
24
|
+
}
|
|
25
|
+
async callContractMethod() {
|
|
26
|
+
throw new Error('Method call is not supported');
|
|
27
|
+
}
|
|
28
|
+
async read() {
|
|
29
|
+
throw new Error('Method read is not supported');
|
|
30
|
+
}
|
|
31
|
+
async getTransactionStatus(txHash) {
|
|
32
|
+
try {
|
|
33
|
+
const transaction = await this.public.getTransaction(txHash, {
|
|
34
|
+
maxSupportedTransactionVersion: 1
|
|
35
|
+
});
|
|
36
|
+
if (transaction?.meta?.err) {
|
|
37
|
+
return tx_status_1.TX_STATUS.FAIL;
|
|
38
|
+
}
|
|
39
|
+
if (transaction?.blockTime) {
|
|
40
|
+
return tx_status_1.TX_STATUS.SUCCESS;
|
|
41
|
+
}
|
|
42
|
+
return tx_status_1.TX_STATUS.PENDING;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return tx_status_1.TX_STATUS.PENDING;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets balance of multiple tokens.
|
|
50
|
+
* @param address Wallet address.
|
|
51
|
+
* @param tokensAddresses Tokens addresses.
|
|
52
|
+
*/
|
|
53
|
+
async getTokensBalances(address, tokensAddresses) {
|
|
54
|
+
const resp = await this.public._rpcRequest('getTokenAccountsByOwner', [address, { programId: spl_token_1.TOKEN_PROGRAM_ID }, { encoding: 'jsonParsed' }]);
|
|
55
|
+
const tokenInfo = new Map(resp.result.value.map((el) => {
|
|
56
|
+
const { mint, tokenAmount } = el.account.data.parsed.info;
|
|
57
|
+
return [mint, tokenAmount.amount];
|
|
58
|
+
}));
|
|
59
|
+
const nativeSolBalance = await this.public.getBalanceAndContext(new web3_js_1.PublicKey(address), 'confirmed');
|
|
60
|
+
return tokensAddresses.map((tokenAddress) => {
|
|
61
|
+
if (tokenAddress === web3_pure_1.Web3Pure.getNativeTokenAddress(core_1.BLOCKCHAIN_NAME.SOLANA)) {
|
|
62
|
+
return new bignumber_js_1.default(nativeSolBalance.value.toString());
|
|
63
|
+
}
|
|
64
|
+
const tokenWithBalance = tokenInfo.get(tokenAddress);
|
|
65
|
+
return new bignumber_js_1.default(tokenWithBalance || NaN);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
multicallContractsMethods() {
|
|
69
|
+
throw new Error('Method not implemented.');
|
|
70
|
+
}
|
|
71
|
+
getBlockNumber() {
|
|
72
|
+
return this.public.getBlockHeight('finalized');
|
|
73
|
+
}
|
|
74
|
+
createConection(rpcList) {
|
|
75
|
+
if (!rpcList?.[0]) {
|
|
76
|
+
this.logger?.customError('RPC list is empty');
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
return new web3_js_1.Connection(rpcList[0], 'confirmed');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async simulateTransaction(_config, _from) { }
|
|
84
|
+
async checkEnoughBalance(token, walletAddress) {
|
|
85
|
+
const balance = await this.getBalance(walletAddress, token.address);
|
|
86
|
+
return balance.gte(token.tokenAmount);
|
|
87
|
+
}
|
|
88
|
+
async getBalance(userAddress, tokenAddress) {
|
|
89
|
+
const isToken = tokenAddress && !web3_pure_1.Web3Pure.isNativeAddress(core_1.CHAIN_TYPE.SOLANA, tokenAddress);
|
|
90
|
+
if (isToken) {
|
|
91
|
+
const balance = await this.getTokensBalances(userAddress, [tokenAddress]);
|
|
92
|
+
return balance?.[0] || new bignumber_js_1.default(0);
|
|
93
|
+
}
|
|
94
|
+
const balance = await this.public.getBalanceAndContext(new web3_js_1.PublicKey(userAddress), 'confirmed');
|
|
95
|
+
return new bignumber_js_1.default(balance.value.toString());
|
|
96
|
+
}
|
|
97
|
+
async callForTokensInfo(tokenAddresses) {
|
|
98
|
+
const nativeToken = core_1.nativeTokensList[core_1.BLOCKCHAIN_NAME.SOLANA];
|
|
99
|
+
const nativeTokenIndex = tokenAddresses.findIndex((address) => web3_pure_1.Web3Pure.isNativeAddress(core_1.CHAIN_TYPE.SOLANA, address));
|
|
100
|
+
const filteredTokenAddresses = tokenAddresses.filter((_, index) => index !== nativeTokenIndex);
|
|
101
|
+
// only native token in array
|
|
102
|
+
if (!filteredTokenAddresses.length && nativeTokenIndex !== -1) {
|
|
103
|
+
return [nativeToken];
|
|
104
|
+
}
|
|
105
|
+
const mints = filteredTokenAddresses.map((address) => new web3_js_1.PublicKey(address));
|
|
106
|
+
const tokensMint = await new solana_tokens_service_1.SolanaTokensService(this.public, this.httpClient).fetchTokensData(mints);
|
|
107
|
+
const tokens = tokensMint.map((token) => {
|
|
108
|
+
return new core_1.Token({
|
|
109
|
+
address: token.address.toString(),
|
|
110
|
+
blockchain: core_1.BLOCKCHAIN_NAME.SOLANA,
|
|
111
|
+
decimals: token.decimals,
|
|
112
|
+
name: token.name,
|
|
113
|
+
symbol: token.symbol
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
if (nativeTokenIndex === -1) {
|
|
117
|
+
return tokens;
|
|
118
|
+
}
|
|
119
|
+
tokens.splice(nativeTokenIndex, 0, nativeToken);
|
|
120
|
+
return tokens;
|
|
121
|
+
}
|
|
122
|
+
parseRawInstruction(rawInstruction, dataFormat) {
|
|
123
|
+
return rawInstruction.map((instruction) => {
|
|
124
|
+
return new web3_js_1.TransactionInstruction({
|
|
125
|
+
keys: instruction.keys.map((key) => ({
|
|
126
|
+
pubkey: new web3_js_1.PublicKey(key.pubkey),
|
|
127
|
+
isWritable: key.isWritable,
|
|
128
|
+
isSigner: key.isSigner
|
|
129
|
+
})),
|
|
130
|
+
data: Buffer.from(instruction.data, dataFormat),
|
|
131
|
+
programId: new web3_js_1.PublicKey(instruction.programId)
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
async parseLUTAddresses(lookupTableAddresses) {
|
|
136
|
+
const accounts = await Promise.all(lookupTableAddresses.map((address) => this.public.getAddressLookupTable(new web3_js_1.PublicKey(address)).then((v) => v.value)));
|
|
137
|
+
return accounts.filter((v) => !!v);
|
|
138
|
+
}
|
|
139
|
+
async createVersionedTransaction(instructions, walletAddress, addressLookupTableAccounts = []) {
|
|
140
|
+
const blockhash = await this.getLatestBlockhash();
|
|
141
|
+
const message = new web3_js_1.TransactionMessage({
|
|
142
|
+
instructions,
|
|
143
|
+
payerKey: new web3_js_1.PublicKey(walletAddress),
|
|
144
|
+
recentBlockhash: blockhash
|
|
145
|
+
}).compileToV0Message(addressLookupTableAccounts);
|
|
146
|
+
return new web3_js_1.VersionedTransaction(message);
|
|
147
|
+
}
|
|
148
|
+
getAtaAddress(walletAddress, tokenAddress) {
|
|
149
|
+
return (0, spl_token_1.getAssociatedTokenAddress)(new web3_js_1.PublicKey(tokenAddress), new web3_js_1.PublicKey(walletAddress));
|
|
150
|
+
}
|
|
151
|
+
getKeypairFromSecret(pk) {
|
|
152
|
+
if (!pk) {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
const array = pk.split(',').map((s) => parseInt(s, 10));
|
|
156
|
+
const secretKey = Uint8Array.from(array);
|
|
157
|
+
return web3_js_1.Keypair.fromSecretKey(secretKey);
|
|
158
|
+
}
|
|
159
|
+
async getTxWithPayer(tx, feePayer) {
|
|
160
|
+
const altAccounts = [];
|
|
161
|
+
for (const lookup of tx.message.addressTableLookups) {
|
|
162
|
+
const { value } = await this.public.getAddressLookupTable(lookup.accountKey);
|
|
163
|
+
if (value) {
|
|
164
|
+
altAccounts.push(value);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
throw new Error(`ALT not found: ${lookup.accountKey.toBase58()}`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
const decompiled = web3_js_1.TransactionMessage.decompile(tx.message, {
|
|
171
|
+
addressLookupTableAccounts: altAccounts
|
|
172
|
+
});
|
|
173
|
+
const { blockhash } = await this.public.getLatestBlockhash();
|
|
174
|
+
const newMsg = new web3_js_1.TransactionMessage({
|
|
175
|
+
instructions: decompiled.instructions,
|
|
176
|
+
payerKey: new web3_js_1.PublicKey(feePayer),
|
|
177
|
+
recentBlockhash: blockhash
|
|
178
|
+
}).compileToV0Message(altAccounts);
|
|
179
|
+
return new web3_js_1.VersionedTransaction(newMsg);
|
|
180
|
+
}
|
|
181
|
+
deserializeTransaction(data) {
|
|
182
|
+
const decodedData = data.startsWith('0x') ? Buffer.from(data.slice(2), 'hex') : js_base64_1.Base64.toUint8Array(data);
|
|
183
|
+
return web3_js_1.VersionedTransaction.deserialize(decodedData);
|
|
184
|
+
}
|
|
185
|
+
serializeTransactionToBase58(tx) {
|
|
186
|
+
return bs58_1.default.encode(tx.serialize());
|
|
187
|
+
}
|
|
188
|
+
async createTransferData(fromToken, walletAddress, receiver, convertToVersionedTx, allowOwnerOffCurve = false) {
|
|
189
|
+
const fromAddress = new web3_js_1.PublicKey(walletAddress);
|
|
190
|
+
const toAddress = new web3_js_1.PublicKey(receiver);
|
|
191
|
+
const transaction = fromToken.isNative
|
|
192
|
+
? this.createNativeTransfer(fromAddress, toAddress, fromToken.stringWeiAmount)
|
|
193
|
+
: await this.createTokenTransfer(fromAddress, toAddress, fromToken.address, fromToken.stringWeiAmount, allowOwnerOffCurve);
|
|
194
|
+
if (convertToVersionedTx) {
|
|
195
|
+
const blockhash = await this.getLatestBlockhash();
|
|
196
|
+
const message = new web3_js_1.TransactionMessage({
|
|
197
|
+
payerKey: fromAddress,
|
|
198
|
+
recentBlockhash: blockhash,
|
|
199
|
+
instructions: transaction.instructions
|
|
200
|
+
}).compileToV0Message();
|
|
201
|
+
return new web3_js_1.VersionedTransaction(message);
|
|
202
|
+
}
|
|
203
|
+
return transaction;
|
|
204
|
+
}
|
|
205
|
+
createNativeTransfer(fromAddress, toAddress, fromWeiAmount) {
|
|
206
|
+
return new web3_js_1.Transaction().add(web3_js_1.SystemProgram.transfer({
|
|
207
|
+
fromPubkey: fromAddress,
|
|
208
|
+
toPubkey: toAddress,
|
|
209
|
+
lamports: BigInt(fromWeiAmount)
|
|
210
|
+
}));
|
|
211
|
+
}
|
|
212
|
+
async createTokenTransfer(fromAddress, toAddress, fromTokenAddress, fromWeiAmount, allowOwnerOffCurve) {
|
|
213
|
+
const mintTokenAccount = new web3_js_1.PublicKey(fromTokenAddress);
|
|
214
|
+
const [fromATA, toATA] = await Promise.all([
|
|
215
|
+
(0, spl_token_1.getAssociatedTokenAddress)(mintTokenAccount, fromAddress),
|
|
216
|
+
(0, spl_token_1.getAssociatedTokenAddress)(mintTokenAccount, toAddress, allowOwnerOffCurve)
|
|
217
|
+
]);
|
|
218
|
+
const transaction = new web3_js_1.Transaction();
|
|
219
|
+
const receiverAccountInfo = await this.public.getAccountInfo(toATA);
|
|
220
|
+
if (!receiverAccountInfo) {
|
|
221
|
+
transaction.add((0, spl_token_1.createAssociatedTokenAccountInstruction)(fromAddress, toATA, toAddress, mintTokenAccount));
|
|
222
|
+
}
|
|
223
|
+
transaction.add((0, spl_token_1.createTransferInstruction)(fromATA, toATA, fromAddress, BigInt(fromWeiAmount)));
|
|
224
|
+
return transaction;
|
|
225
|
+
}
|
|
226
|
+
async getLatestBlockhash() {
|
|
227
|
+
const { blockhash } = await this.public.getLatestBlockhash();
|
|
228
|
+
return blockhash;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
exports.SolanaAdapter = SolanaAdapter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const FAKE_STELLAR_WALLET = "GA43DZREOL4ISMF3RE4ETB4DVJVTITWEWTKPGJRZW4EOZCOCNLNOUVVB";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BasicSendTransactionOptions } from '../../models/basic-transaction-options';
|
|
2
|
+
import { Transaction } from '@stellar/stellar-sdk';
|
|
3
|
+
export interface StellarSendTxParams {
|
|
4
|
+
txOptions: StellarTransactionOptions;
|
|
5
|
+
}
|
|
6
|
+
export interface StellarTransactionOptions extends BasicSendTransactionOptions {
|
|
7
|
+
transaction: string | Transaction;
|
|
8
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
export interface StellarWallet {
|
|
2
|
+
/**
|
|
3
|
+
* Function used to request the public key from the active account or
|
|
4
|
+
* specific path on a wallet.
|
|
5
|
+
*
|
|
6
|
+
* @param params
|
|
7
|
+
* @param params.path - The path to tell the wallet which position to ask. This is commonly used in hardware wallets.
|
|
8
|
+
* @param params.skipRequestAccess - Freighter separates the access request from the logic of getting the address, if this is set to true we will avoid requesting the access
|
|
9
|
+
*
|
|
10
|
+
* @return Promise<{ address: string }>
|
|
11
|
+
*/
|
|
12
|
+
getAddress(params?: {
|
|
13
|
+
path?: string;
|
|
14
|
+
skipRequestAccess?: boolean;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
address: string;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* A function to request a wallet to sign a built transaction in its XDR mode
|
|
20
|
+
*
|
|
21
|
+
* @param xdr - A Transaction or a FeeBumpTransaction
|
|
22
|
+
* @param opts - Options compatible with https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0043.md#signtransaction
|
|
23
|
+
* @param opts.networkPassphrase - The Stellar network to use when signing
|
|
24
|
+
* @param opts.address - The public key of the account that should be used to sign
|
|
25
|
+
* @param opts.path - This options is added for special cases like Hardware wallets
|
|
26
|
+
*
|
|
27
|
+
* @return Promise<{ signedTxXdr: string; signerAddress: string }>
|
|
28
|
+
*/
|
|
29
|
+
signTransaction(xdr: string, opts?: {
|
|
30
|
+
networkPassphrase?: string;
|
|
31
|
+
address?: string;
|
|
32
|
+
path?: string;
|
|
33
|
+
submit?: boolean;
|
|
34
|
+
submitUrl?: string;
|
|
35
|
+
}): Promise<{
|
|
36
|
+
signedTxXdr: string;
|
|
37
|
+
signerAddress?: string;
|
|
38
|
+
}>;
|
|
39
|
+
/**
|
|
40
|
+
* A function to request a wallet to sign an AuthEntry XDR.
|
|
41
|
+
*
|
|
42
|
+
* @param authEntry - An XDR string version of `HashIdPreimageSorobanAuthorization`
|
|
43
|
+
* @param opts - Options compatible with https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0043.md#signauthentry
|
|
44
|
+
* @param opts.networkPassphrase - The Stellar network to use when signing
|
|
45
|
+
* @param opts.address - The public key of the account that should be used to sign
|
|
46
|
+
* @param opts.path - This options is added for special cases like Hardware wallets
|
|
47
|
+
*
|
|
48
|
+
* @return - Promise<{ signedAuthEntry: string; signerAddress: string }>
|
|
49
|
+
*/
|
|
50
|
+
signAuthEntry(authEntry: string, opts?: {
|
|
51
|
+
networkPassphrase?: string;
|
|
52
|
+
address?: string;
|
|
53
|
+
path?: string;
|
|
54
|
+
}): Promise<{
|
|
55
|
+
signedAuthEntry: string;
|
|
56
|
+
signerAddress?: string;
|
|
57
|
+
}>;
|
|
58
|
+
/**
|
|
59
|
+
* A function to request a wallet to sign an AuthEntry XDR.
|
|
60
|
+
*
|
|
61
|
+
* @param message - An arbitrary string rather than a transaction or auth entry
|
|
62
|
+
* @param opts - Options compatible with https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0043.md#signmessage
|
|
63
|
+
* @param opts.networkPassphrase - The Stellar network to use when signing
|
|
64
|
+
* @param opts.address - The public key of the account that should be used to sign
|
|
65
|
+
* @param opts.path - This options is added for special cases like Hardware wallets
|
|
66
|
+
*
|
|
67
|
+
* @return - Promise<{ signedMessage: string; signerAddress: string }>
|
|
68
|
+
*/
|
|
69
|
+
signMessage(message: string, opts?: {
|
|
70
|
+
networkPassphrase?: string;
|
|
71
|
+
address?: string;
|
|
72
|
+
path?: string;
|
|
73
|
+
}): Promise<{
|
|
74
|
+
signedMessage: string;
|
|
75
|
+
signerAddress?: string;
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* A function to request the current selected network in the wallet. This comes
|
|
79
|
+
* handy when you are dealing with a wallet that doesn't allow you to specify which network to use (For example Lobstr and Rabet)
|
|
80
|
+
*
|
|
81
|
+
* @return - Promise<{ network: string; networkPassphrase: string }>
|
|
82
|
+
*/
|
|
83
|
+
getNetwork(): Promise<{
|
|
84
|
+
network: string;
|
|
85
|
+
networkPassphrase: string;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BlockchainName, HttpClient, ICustomLogger } from '@cryptorubic/core';
|
|
2
|
+
import { AbstractAdapterSigner } from '../../common/signer/abstract-adapter-signer';
|
|
3
|
+
import { StellarClient } from '../models/stellar-client';
|
|
4
|
+
import { StellarSendTxParams } from '../models/stellar-send-tx-params';
|
|
5
|
+
import { StellarWallet } from '../models/stellar-wallet';
|
|
6
|
+
import { ClientAdaptersFactoryParams } from '../../../models/create-factory-params';
|
|
7
|
+
import { xdr } from '@stellar/stellar-sdk';
|
|
8
|
+
export declare class StellarAdapterSigner extends AbstractAdapterSigner<StellarWallet, StellarSendTxParams, string> {
|
|
9
|
+
private readonly publicRef;
|
|
10
|
+
get publicClient(): StellarClient;
|
|
11
|
+
constructor(publicRef: {
|
|
12
|
+
public: StellarClient | null;
|
|
13
|
+
}, httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
14
|
+
write<T>(): Promise<T>;
|
|
15
|
+
getBlockchainName(): Promise<BlockchainName>;
|
|
16
|
+
sendTransaction(params: StellarSendTxParams): Promise<string>;
|
|
17
|
+
parseTxError(txResult: xdr.TransactionResult): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.StellarAdapterSigner = void 0;
|
|
4
|
+
const core_1 = require("@cryptorubic/core");
|
|
5
|
+
const abstract_adapter_signer_1 = require("../../common/signer/abstract-adapter-signer");
|
|
6
|
+
const stellar_sdk_1 = require("@stellar/stellar-sdk");
|
|
7
|
+
const bignumber_js_1 = require("bignumber.js");
|
|
8
|
+
const insufficient_funds_gas_price_value_error_1 = require("../../../../errors/cross-chain/insufficient-funds-gas-price-value.error");
|
|
9
|
+
class StellarAdapterSigner extends abstract_adapter_signer_1.AbstractAdapterSigner {
|
|
10
|
+
get publicClient() {
|
|
11
|
+
if (!this.publicRef.public) {
|
|
12
|
+
const msg = 'Trying to access undefined publicClient in StellarAdapterSigner';
|
|
13
|
+
this.logger?.customLog(msg);
|
|
14
|
+
throw new Error(msg);
|
|
15
|
+
}
|
|
16
|
+
return this.publicRef.public;
|
|
17
|
+
}
|
|
18
|
+
constructor(publicRef, httpClient, logger, clientParams) {
|
|
19
|
+
super(httpClient, logger, clientParams);
|
|
20
|
+
this.publicRef = publicRef;
|
|
21
|
+
}
|
|
22
|
+
async write() {
|
|
23
|
+
throw new Error('Method write is not supported');
|
|
24
|
+
}
|
|
25
|
+
getBlockchainName() {
|
|
26
|
+
return Promise.resolve(core_1.BLOCKCHAIN_NAME.STELLAR);
|
|
27
|
+
}
|
|
28
|
+
async sendTransaction(params) {
|
|
29
|
+
try {
|
|
30
|
+
const transaction = typeof params.txOptions.transaction === 'string'
|
|
31
|
+
? stellar_sdk_1.TransactionBuilder.fromXDR(params.txOptions.transaction, stellar_sdk_1.Networks.PUBLIC)
|
|
32
|
+
: params.txOptions.transaction;
|
|
33
|
+
const [preparedTransaction, accountInfo] = await Promise.all([
|
|
34
|
+
this.publicClient.prepareTransaction(transaction),
|
|
35
|
+
this.publicClient.getAccountEntry(this.walletAddress)
|
|
36
|
+
]);
|
|
37
|
+
// account has min required balance that cannot be spent
|
|
38
|
+
const minBalance = new bignumber_js_1.default(2 + accountInfo.numSubEntries()).multipliedBy(5000000);
|
|
39
|
+
const necessaryBalance = minBalance.plus(preparedTransaction.fee);
|
|
40
|
+
if (necessaryBalance.gt(accountInfo.balance().toString())) {
|
|
41
|
+
throw new insufficient_funds_gas_price_value_error_1.InsufficientFundsGasPriceValueError();
|
|
42
|
+
}
|
|
43
|
+
const { signedTxXdr } = await this.wallet.signTransaction(preparedTransaction.toXDR(), {
|
|
44
|
+
networkPassphrase: stellar_sdk_1.Networks.PUBLIC,
|
|
45
|
+
address: this.walletAddress
|
|
46
|
+
});
|
|
47
|
+
const resp = await this.publicClient.sendTransaction(stellar_sdk_1.TransactionBuilder.fromXDR(signedTxXdr, stellar_sdk_1.Networks.PUBLIC));
|
|
48
|
+
const txStatus = await this.publicClient.pollTransaction(resp.hash);
|
|
49
|
+
if (txStatus.status === 'FAILED') {
|
|
50
|
+
this.parseTxError(txStatus.resultXdr);
|
|
51
|
+
}
|
|
52
|
+
if (params.txOptions.onTransactionHash) {
|
|
53
|
+
params.txOptions.onTransactionHash?.(txStatus.txHash);
|
|
54
|
+
}
|
|
55
|
+
return txStatus.txHash;
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
console.error('Send transaction error', err);
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
parseTxError(txResult) {
|
|
63
|
+
const failedTxCode = txResult.result().switch().name;
|
|
64
|
+
if (failedTxCode === 'txInsufficientBalance') {
|
|
65
|
+
throw new insufficient_funds_gas_price_value_error_1.InsufficientFundsGasPriceValueError();
|
|
66
|
+
}
|
|
67
|
+
const failedOperation = txResult.result().results()[0];
|
|
68
|
+
const failedOperationCode = failedOperation.tr().value().switch().name;
|
|
69
|
+
if (failedOperationCode === 'changeTrustLowReserve') {
|
|
70
|
+
throw new insufficient_funds_gas_price_value_error_1.InsufficientFundsGasPriceValueError();
|
|
71
|
+
}
|
|
72
|
+
throw new Error(failedOperationCode);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.StellarAdapterSigner = StellarAdapterSigner;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BlockchainName, HttpClient, ICustomLogger, PriceTokenAmount, StellarBlockchainName, Token, TokenAmount } from '@cryptorubic/core';
|
|
2
|
+
import { AbstractAdapter } from '../common/abstract-adapter';
|
|
3
|
+
import { StellarClient } from './models/stellar-client';
|
|
4
|
+
import { StellarWallet } from './models/stellar-wallet';
|
|
5
|
+
import { TxStatus } from '../models/web3-public-models/tx-status';
|
|
6
|
+
import { Account, Horizon } from '@stellar/stellar-sdk';
|
|
7
|
+
import { ClientAdaptersFactoryParams } from '../../models/create-factory-params';
|
|
8
|
+
import { StellarAdapterSigner } from './signer/stellar-adapter-signer';
|
|
9
|
+
import BigNumber from 'bignumber.js';
|
|
10
|
+
import { Web3PrimitiveType } from '../../../utils/models/primitive-types';
|
|
11
|
+
import { Abi } from 'viem';
|
|
12
|
+
import { MethodData } from '../models/web3-public-models/method-data';
|
|
13
|
+
import { ContractMulticallResponse } from '../models/web3-public-models/contract-multicall-response';
|
|
14
|
+
import { StellarTransactionConfig } from '../../../utils/models/stellar-transaction-config';
|
|
15
|
+
import { StellarRpcProvider } from './models/stellar-rpc-provider';
|
|
16
|
+
export declare class StellarAdapter extends AbstractAdapter<StellarClient, StellarWallet, StellarBlockchainName> {
|
|
17
|
+
private readonly rpc;
|
|
18
|
+
readonly signer: StellarAdapterSigner;
|
|
19
|
+
readonly horizonClient: Horizon.Server;
|
|
20
|
+
private readonly CLASSIC_TOKEN_DECIMALS;
|
|
21
|
+
constructor(rpc: StellarRpcProvider[], httpClient: HttpClient, logger?: ICustomLogger, clientParams?: ClientAdaptersFactoryParams);
|
|
22
|
+
initWeb3Client(): void;
|
|
23
|
+
getBlockNumber(): Promise<number | {
|
|
24
|
+
blockNumber: number;
|
|
25
|
+
workchain: number;
|
|
26
|
+
}>;
|
|
27
|
+
getTokensBalances(userAddress: string, tokensAddresses: string[]): Promise<BigNumber[]>;
|
|
28
|
+
getBalance(userAddress: string, tokenAddress?: string): Promise<BigNumber>;
|
|
29
|
+
callForTokensInfo(tokenAddresses: string[] | ReadonlyArray<string>): Promise<Token<BlockchainName>[]>;
|
|
30
|
+
callForTokenInfo(tokenAddress: string): Promise<Token<BlockchainName>>;
|
|
31
|
+
checkEnoughBalance(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
32
|
+
needTrustline(token: TokenAmount | PriceTokenAmount, walletAddress: string): Promise<boolean>;
|
|
33
|
+
addTrustline(tokenAddress: string): Promise<string>;
|
|
34
|
+
encodeTrustline(tokenAddress: string, walletAddress: string): Promise<string>;
|
|
35
|
+
getTokenContractId(tokenAddress: string): string;
|
|
36
|
+
private convertTokenAddressToAsset;
|
|
37
|
+
read<T>(address: string, method: string, methodArgs?: {
|
|
38
|
+
value: string;
|
|
39
|
+
type: string;
|
|
40
|
+
}[]): Promise<T>;
|
|
41
|
+
simulateTransaction(config: StellarTransactionConfig): Promise<string>;
|
|
42
|
+
getTransactionStatus(srcTxHash: string): Promise<TxStatus>;
|
|
43
|
+
getMinWeiBalance(userAddress: string): Promise<BigNumber>;
|
|
44
|
+
getFeeFromTransaction(xdr: string): BigNumber;
|
|
45
|
+
getAccountInfo(walletAddress: string): Promise<Account>;
|
|
46
|
+
callContractMethod<T extends Web3PrimitiveType = string>(_contractAddress: string, _contractAbi: Abi | undefined, _methodName: string, _methodArguments?: {
|
|
47
|
+
value: string;
|
|
48
|
+
type: string;
|
|
49
|
+
}[], _options?: object): Promise<T>;
|
|
50
|
+
multicallContractsMethods<Output extends Web3PrimitiveType>(_contractAbi: Abi, _contractsData: {
|
|
51
|
+
contractAddress: string;
|
|
52
|
+
methodsData: MethodData[];
|
|
53
|
+
}[]): Promise<ContractMulticallResponse<Output>[][]>;
|
|
54
|
+
}
|