Updated on 2026-08-14
This commit is contained in:
parent
328271bc26
commit
8b6944e3e4
31 changed files with 1464 additions and 818 deletions
|
|
@ -2,10 +2,7 @@ package com.tangem.lib.visa;
|
|||
|
||||
import org.web3j.abi.EventEncoder;
|
||||
import org.web3j.abi.TypeReference;
|
||||
import org.web3j.abi.datatypes.Address;
|
||||
import org.web3j.abi.datatypes.Event;
|
||||
import org.web3j.abi.datatypes.Function;
|
||||
import org.web3j.abi.datatypes.Utf8String;
|
||||
import org.web3j.abi.datatypes.*;
|
||||
import org.web3j.abi.datatypes.generated.Uint256;
|
||||
import org.web3j.abi.datatypes.generated.Uint8;
|
||||
import org.web3j.crypto.Credentials;
|
||||
|
|
@ -32,10 +29,10 @@ import io.reactivex.Flowable;
|
|||
* <p>Auto generated code.
|
||||
* <p><strong>Do not modify!</strong>
|
||||
* <p>Please use the <a href="https://docs.web3j.io/command_line.html">web3j command line tools</a>,
|
||||
* or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
|
||||
* or the org.web3j.codegen.SolidityFunctionWrapperGenerator in the
|
||||
* <a href="https://github.com/web3j/web3j/tree/master/codegen">codegen module</a> to update.
|
||||
*
|
||||
* <p>Generated with web3j version 1.5.0.
|
||||
* <p>Generated with web3j version 1.5.2.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
class ERC20 extends Contract {
|
||||
|
|
@ -113,6 +110,16 @@ class ERC20 extends Contract {
|
|||
return typedResponse;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ERC20 load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
|
||||
return new ERC20(contractAddress, web3j, credentials, gasPrice, gasLimit);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ERC20 load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
|
||||
return new ERC20(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
|
||||
}
|
||||
|
||||
public static List<TransferEventResponse> getTransferEvents(TransactionReceipt transactionReceipt) {
|
||||
List<EventValuesWithLog> valueList = staticExtractEventParametersWithLog(TRANSFER_EVENT, transactionReceipt);
|
||||
ArrayList<TransferEventResponse> responses = new ArrayList<TransferEventResponse>(valueList.size());
|
||||
|
|
@ -127,16 +134,6 @@ class ERC20 extends Contract {
|
|||
return responses;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ERC20 load(String contractAddress, Web3j web3j, Credentials credentials, BigInteger gasPrice, BigInteger gasLimit) {
|
||||
return new ERC20(contractAddress, web3j, credentials, gasPrice, gasLimit);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static ERC20 load(String contractAddress, Web3j web3j, TransactionManager transactionManager, BigInteger gasPrice, BigInteger gasLimit) {
|
||||
return new ERC20(contractAddress, web3j, transactionManager, gasPrice, gasLimit);
|
||||
}
|
||||
|
||||
public static TransferEventResponse getTransferEventFromLog(Log log) {
|
||||
EventValuesWithLog eventValues = staticExtractEventParametersWithLog(TRANSFER_EVENT, log);
|
||||
TransferEventResponse typedResponse = new TransferEventResponse();
|
||||
|
|
@ -147,14 +144,6 @@ class ERC20 extends Contract {
|
|||
return typedResponse;
|
||||
}
|
||||
|
||||
public static ERC20 load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
|
||||
return new ERC20(contractAddress, web3j, credentials, contractGasProvider);
|
||||
}
|
||||
|
||||
public static ERC20 load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
|
||||
return new ERC20(contractAddress, web3j, transactionManager, contractGasProvider);
|
||||
}
|
||||
|
||||
public Flowable<TransferEventResponse> transferEventFlowable(EthFilter filter) {
|
||||
return web3j.ethLogFlowable(filter).map(log -> getTransferEventFromLog(log));
|
||||
}
|
||||
|
|
@ -165,6 +154,14 @@ class ERC20 extends Contract {
|
|||
return transferEventFlowable(filter);
|
||||
}
|
||||
|
||||
public static ERC20 load(String contractAddress, Web3j web3j, Credentials credentials, ContractGasProvider contractGasProvider) {
|
||||
return new ERC20(contractAddress, web3j, credentials, contractGasProvider);
|
||||
}
|
||||
|
||||
public static ERC20 load(String contractAddress, Web3j web3j, TransactionManager transactionManager, ContractGasProvider contractGasProvider) {
|
||||
return new ERC20(contractAddress, web3j, transactionManager, contractGasProvider);
|
||||
}
|
||||
|
||||
public Flowable<ApprovalEventResponse> approvalEventFlowable(EthFilter filter) {
|
||||
return web3j.ethLogFlowable(filter).map(log -> getApprovalEventFromLog(log));
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -7,7 +7,6 @@ import com.tangem.lib.visa.model.VisaBalancesAndLimits.Limits
|
|||
import com.tangem.lib.visa.utils.toBigDecimal
|
||||
import com.tangem.lib.visa.utils.toInstant
|
||||
import com.tangem.utils.coroutines.CoroutineDispatcherProvider
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.joda.time.Instant
|
||||
import org.web3j.protocol.Web3j
|
||||
import org.web3j.tx.TransactionManager
|
||||
|
|
@ -18,39 +17,40 @@ internal class DefaultVisaContractInfoProvider(
|
|||
private val transactionManager: TransactionManager,
|
||||
private val gasProvider: ContractGasProvider,
|
||||
private val bridgeProcessorAddress: String,
|
||||
private val paymentAccountRegistryAddress: String,
|
||||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
) : VisaContractInfoProvider {
|
||||
|
||||
override suspend fun getBalancesAndLimits(walletAddress: String): VisaBalancesAndLimits {
|
||||
return withContext(dispatchers.io) {
|
||||
val tangemBridgeProcessor = TangemBridgeProcessor.load(
|
||||
/* contractAddress = */ bridgeProcessorAddress,
|
||||
/* web3j = */ web3j,
|
||||
/* transactionManager = */ transactionManager,
|
||||
/* contractGasProvider = */ gasProvider,
|
||||
)
|
||||
|
||||
parZip(
|
||||
dispatchers.io,
|
||||
{ loadPaymentAccount(walletAddress, tangemBridgeProcessor) },
|
||||
{ loadPaymentTokenInfo(tangemBridgeProcessor) },
|
||||
{ paymentAccount, paymentToken ->
|
||||
fetchBalancesAndLimits(paymentAccount, paymentToken)
|
||||
},
|
||||
)
|
||||
}
|
||||
return parZip(
|
||||
dispatchers.io,
|
||||
{ loadPaymentAccount(walletAddress) },
|
||||
{ loadPaymentTokenInfo() },
|
||||
{ paymentAccount, paymentToken ->
|
||||
fetchBalancesAndLimits(paymentAccount, paymentToken)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
private fun loadPaymentAccount(
|
||||
walletAddress: String,
|
||||
tangemBridgeProcessor: TangemBridgeProcessor,
|
||||
): TangemPaymentAccount {
|
||||
val paymentAccountAddress = tangemBridgeProcessor.getPaymentAccount(walletAddress).send()
|
||||
private fun loadPaymentAccount(walletAddress: String): TangemPaymentAccount {
|
||||
val paymentAccountRegistry = TangemPaymentAccountRegistry.load(
|
||||
/* contractAddress = */ paymentAccountRegistryAddress,
|
||||
/* web3j = */ web3j,
|
||||
/* transactionManager = */ transactionManager,
|
||||
/* contractGasProvider = */ gasProvider,
|
||||
)
|
||||
val paymentAccountAddress = paymentAccountRegistry.paymentAccountByCard(walletAddress).send()
|
||||
|
||||
return TangemPaymentAccount.load(paymentAccountAddress, web3j, transactionManager, gasProvider)
|
||||
}
|
||||
|
||||
private fun loadPaymentTokenInfo(tangemBridgeProcessor: TangemBridgeProcessor): PaymentTokenInfo {
|
||||
private fun loadPaymentTokenInfo(): PaymentTokenInfo {
|
||||
val tangemBridgeProcessor = TangemBridgeProcessor.load(
|
||||
/* contractAddress = */ bridgeProcessorAddress,
|
||||
/* web3j = */ web3j,
|
||||
/* transactionManager = */ transactionManager,
|
||||
/* contractGasProvider = */ gasProvider,
|
||||
)
|
||||
val paymentTokenContractAddress = tangemBridgeProcessor.paymentToken().send()
|
||||
val paymentTokenContract = ERC20.load(paymentTokenContractAddress, web3j, transactionManager, gasProvider)
|
||||
val paymentTokenDecimals = paymentTokenContract.decimals().send()
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ interface VisaContractInfoProvider {
|
|||
private val dispatchers: CoroutineDispatcherProvider,
|
||||
private val baseUrl: String = VisaConfig.BASE_RPC_URL,
|
||||
private val bridgeProcessorAddress: String = VisaConfig.BRIDGE_PROCESSOR_CONTRACT_ADDRESS,
|
||||
private val paymentAccountRegistryAddress: String = VisaConfig.PAYMENT_ACCOUNT_REGISTRY_ADDRESS,
|
||||
private val chainId: Long = VisaConfig.CHAIN_ID,
|
||||
private val networkTimeoutSeconds: Long = VisaConfig.NETWORK_TIMEOUT_SECONDS,
|
||||
private val decimals: Int = VisaConfig.DECIMALS,
|
||||
|
|
@ -45,6 +46,7 @@ interface VisaContractInfoProvider {
|
|||
transactionManager = transactionManager,
|
||||
gasProvider = gasProvider,
|
||||
bridgeProcessorAddress = bridgeProcessorAddress,
|
||||
paymentAccountRegistryAddress = paymentAccountRegistryAddress,
|
||||
dispatchers = dispatchers,
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ package com.tangem.lib.visa.utils
|
|||
|
||||
internal object VisaConfig {
|
||||
|
||||
const val BASE_RPC_URL = "https://rpc-mumbai.maticvigil.com/"
|
||||
const val BRIDGE_PROCESSOR_CONTRACT_ADDRESS = "0x62119697e78178512bfcc456ae6d1b7dee9fbaa6"
|
||||
const val BASE_RPC_URL = "https://polygon-mumbai.g.alchemy.com/v2/_1qqjXgBC_IikaXChnna8KTcV2eMMIQG/"
|
||||
const val BRIDGE_PROCESSOR_CONTRACT_ADDRESS = "0xe32ecbbc1ec17fa9c160569cd613ad568ca50279"
|
||||
const val PAYMENT_ACCOUNT_REGISTRY_ADDRESS = "0x3f4ae01073d1a9d5a92315fe118e57d1cdec7c44"
|
||||
const val CHAIN_ID = 80_001L
|
||||
const val DECIMALS = 9
|
||||
const val GAS_LIMIT = 500_000_000L
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue