Skip to content

Commit

Permalink
Merge pull request #44 from reown-com/develop
Browse files Browse the repository at this point in the history
BOM_1.1.2
  • Loading branch information
jakubuid authored Jan 17, 2025
2 parents 16afc9c + 6bdd041 commit 4a408d4
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 85 deletions.
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import org.apache.http.entity.StringEntity
import org.apache.http.impl.client.HttpClients
import org.apache.http.util.EntityUtils
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.sonarqube.gradle.SonarExtension
import java.net.URL
import java.util.Base64
import javax.xml.parsers.DocumentBuilderFactory

Expand Down
16 changes: 8 additions & 8 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const val KEY_PUBLISH_ARTIFACT_ID = "PUBLISH_ARTIFACT_ID"
const val KEY_SDK_NAME = "SDK_NAME"

//Latest versions
const val BOM_VERSION = "1.1.1"
const val FOUNDATION_VERSION = "1.1.1"
const val CORE_VERSION = "1.1.1"
const val SIGN_VERSION = "1.1.1"
const val NOTIFY_VERSION = "1.1.1"
const val WALLETKIT_VERSION = "1.1.1"
const val APPKIT_VERSION = "1.1.1"
const val MODAL_CORE_VERSION = "1.1.1"
const val BOM_VERSION = "1.1.2"
const val FOUNDATION_VERSION = "1.1.2"
const val CORE_VERSION = "1.1.2"
const val SIGN_VERSION = "1.1.2"
const val NOTIFY_VERSION = "1.1.2"
const val WALLETKIT_VERSION = "1.1.2"
const val APPKIT_VERSION = "1.1.2"
const val MODAL_CORE_VERSION = "1.1.2"

//Artifact ids
const val ANDROID_BOM = "android-bom"
Expand Down
2 changes: 1 addition & 1 deletion product/walletkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ android {

dependencies {
implementation("net.java.dev.jna:jna:5.15.0@aar")
implementation("com.github.reown-com:yttrium:0.4.11")
implementation("com.github.reown-com:yttrium:0.5.2")

implementation(platform(libs.firebase.bom))
implementation(libs.firebase.messaging)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

@ExperimentalCoroutinesApi
class GetTransactionDetailsUseCaseTest {
class GetCallDetailsUseCaseTest {
private val chainAbstractionClient: ChainAbstractionClient = mockk()
private val getTransactionDetailsUseCase = GetTransactionDetailsUseCase(chainAbstractionClient)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import uniffi.yttrium.FundingMetadata
import uniffi.yttrium.InitialTransactionMetadata
import uniffi.yttrium.Metadata
import uniffi.yttrium.PrepareResponse
import uniffi.yttrium.RouteResponseAvailable
import uniffi.yttrium.RouteResponseError
import uniffi.yttrium.RouteResponseNotRequired
import uniffi.yttrium.RouteResponseSuccess
import uniffi.yttrium.PrepareResponseAvailable
import uniffi.yttrium.PrepareResponseError
import uniffi.yttrium.PrepareResponseNotRequired
import uniffi.yttrium.PrepareResponseSuccess
import uniffi.yttrium.Transaction
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine
Expand All @@ -29,8 +29,8 @@ class PrepareChainAbstractionUseCaseTest {
@Test
fun shouldCallOnSuccessWithAvailableResult() = runTest {
val successResult = PrepareResponse.Success(
RouteResponseSuccess.Available(
RouteResponseAvailable(
PrepareResponseSuccess.Available(
PrepareResponseAvailable(
orchestrationId = "123",
initialTransaction = transaction,
metadata = Metadata(
Expand All @@ -42,7 +42,7 @@ class PrepareChainAbstractionUseCaseTest {
)
)
)
coEvery { chainAbstractionClient.prepare(any()) } returns successResult
coEvery { chainAbstractionClient.prepare(any(), any(), any()) } returns successResult

val result = async {
suspendCoroutine { continuation ->
Expand All @@ -63,8 +63,8 @@ class PrepareChainAbstractionUseCaseTest {

@Test
fun shouldCallOnSuccessWithNotRequiredResult() = runTest {
val successResult = PrepareResponse.Success(RouteResponseSuccess.NotRequired(RouteResponseNotRequired(initialTransaction = transaction, transactions = emptyList<Transaction>())))
coEvery { chainAbstractionClient.prepare(any()) } returns successResult
val successResult = PrepareResponse.Success(PrepareResponseSuccess.NotRequired(PrepareResponseNotRequired(initialTransaction = transaction, transactions = emptyList())))
coEvery { chainAbstractionClient.prepare(any(), any(), any()) } returns successResult

val result = async {
suspendCoroutine { continuation ->
Expand All @@ -85,9 +85,9 @@ class PrepareChainAbstractionUseCaseTest {

@Test
fun shouldCallOnErrorWithNoRoutesAvailableError() = runTest {
val errorResult = PrepareResponse.Error(RouteResponseError(BridgingError.NO_ROUTES_AVAILABLE))
val errorResult = PrepareResponse.Error(PrepareResponseError(BridgingError.NO_ROUTES_AVAILABLE))

coEvery { chainAbstractionClient.prepare(any()) } returns errorResult
coEvery { chainAbstractionClient.prepare(any(), any(), any()) } returns errorResult

val result = async {
suspendCoroutine { continuation ->
Expand All @@ -108,9 +108,9 @@ class PrepareChainAbstractionUseCaseTest {

@Test
fun shouldCallOnErrorWithInsufficientFundsError() = runTest {
val errorResult = PrepareResponse.Error(RouteResponseError(BridgingError.INSUFFICIENT_FUNDS))
val errorResult = PrepareResponse.Error(PrepareResponseError(BridgingError.INSUFFICIENT_FUNDS))

coEvery { chainAbstractionClient.prepare(any()) } returns errorResult
coEvery { chainAbstractionClient.prepare(any(), any(), any()) } returns errorResult

val result = async {
suspendCoroutine { continuation ->
Expand All @@ -131,7 +131,7 @@ class PrepareChainAbstractionUseCaseTest {

@Test
fun shouldCallOnErrorWithUnknownErrorOnException() = runTest {
coEvery { chainAbstractionClient.prepare(any()) } throws RuntimeException("Some unexpected error")
coEvery { chainAbstractionClient.prepare(any(), any(), any()) } throws RuntimeException("Some unexpected error")

val result = async {
suspendCoroutine { continuation ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.reown.walletkit.client

@RequiresOptIn(
message = "This API is experimental and may change in a future release.",
message = "This API is experimental and may change in a future release, use carefully.",
level = RequiresOptIn.Level.WARNING
)
@Retention(AnnotationRetention.BINARY)
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
annotation class ChainAbstractionExperimentalApi

@RequiresOptIn(
message = "This API is experimental and may change in a future release.",
message = "This API is experimental and may change in a future release, use carefully.",
level = RequiresOptIn.Level.WARNING
)
@Retention(AnnotationRetention.BINARY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package com.reown.walletkit.client

import com.reown.android.internal.common.signing.cacao.CacaoType
import com.reown.sign.client.Sign
import com.squareup.moshi.Moshi
import uniffi.uniffi_yttrium.Eip1559Estimation
import uniffi.uniffi_yttrium.OwnerSignature
import uniffi.uniffi_yttrium.PreparedSendTransaction
import uniffi.uniffi_yttrium.FfiTransaction
import uniffi.yttrium.Amount
import uniffi.yttrium.Call
import uniffi.yttrium.DoSendTransactionParams
import uniffi.yttrium.FeeEstimatedTransaction
import uniffi.yttrium.FundingMetadata
import uniffi.yttrium.InitialTransaction
import uniffi.yttrium.InitialTransactionMetadata
import uniffi.yttrium.OwnerSignature
import uniffi.yttrium.PrepareResponseAvailable
import uniffi.yttrium.PreparedSendTransaction
import uniffi.yttrium.Metadata as YMetadata
import uniffi.yttrium.Transaction
import uniffi.yttrium.RouteResponseAvailable
import uniffi.yttrium.TransactionFee
import uniffi.yttrium.TxnDetails
import uniffi.yttrium.UiFields
Expand Down Expand Up @@ -297,16 +298,20 @@ internal fun Sign.Model.ConnectionState.Reason.toWallet(): Wallet.Model.Connecti
}

@JvmSynthetic
internal fun PreparedSendTransaction.toWallet(): Wallet.Params.PrepareSendTransactionsResult = Wallet.Params.PrepareSendTransactionsResult(hash, doSendTransactionParams)
internal fun PreparedSendTransaction.toWallet(moshi: Moshi): Wallet.Params.PrepareSendTransactionsResult {
val jsonParams = moshi.adapter(DoSendTransactionParams::class.java).toJson(doSendTransactionParams)
return Wallet.Params.PrepareSendTransactionsResult(hash = hash, doSendTransactionParams = jsonParams, eip712Domain = domain)
}


@JvmSynthetic
internal fun Wallet.Params.Transaction.toYttrium(): FfiTransaction = FfiTransaction(to = to, value = value, data = data)
internal fun Wallet.Params.Call.toYttrium(): Call = Call(to = to, value = value, input = data)

@JvmSynthetic
internal fun Wallet.Params.OwnerSignature.toYttrium(): OwnerSignature = OwnerSignature(owner = address, signature = signature)

@JvmSynthetic
internal fun RouteResponseAvailable.toWallet(): Wallet.Model.PrepareSuccess.Available =
internal fun PrepareResponseAvailable.toWallet(): Wallet.Model.PrepareSuccess.Available =
Wallet.Model.PrepareSuccess.Available(
fulfilmentId = orchestrationId,
checkIn = metadata.checkIn.toLong(),
Expand All @@ -317,8 +322,8 @@ internal fun RouteResponseAvailable.toWallet(): Wallet.Model.PrepareSuccess.Avai
)

@JvmSynthetic
internal fun Wallet.Model.PrepareSuccess.Available.toYttrium(): RouteResponseAvailable =
RouteResponseAvailable(
internal fun Wallet.Model.PrepareSuccess.Available.toYttrium(): PrepareResponseAvailable =
PrepareResponseAvailable(
fulfilmentId,
metadata = YMetadata(
checkIn = checkIn.toULong(),
Expand Down Expand Up @@ -348,15 +353,6 @@ private fun InitialTransactionMetadata.toWallet(): Wallet.Model.InitialTransacti
decimals = decimals.toInt()
)

@JvmSynthetic
fun Wallet.Model.InitialTransaction.toInitialYttrium(): InitialTransaction = InitialTransaction(
from = from,
to = to,
value = value,
chainId = chainId,
input = input,
)

@JvmSynthetic
fun Transaction.toWallet(): Wallet.Model.Transaction = Wallet.Model.Transaction(
from = from,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ object Wallet {

data class DecryptMessage(val topic: String, val encryptedMessage: String) : Params()
data class GetSmartAccountAddress(val owner: Account) : Params()
data class PrepareSendTransactions(val transactions: List<Transaction>, val owner: Account) : Params()
data class PrepareSendTransactions(val calls: List<Call>, val owner: Account) : Params()
data class DoSendTransactions(val owner: Account, val signatures: List<OwnerSignature>, val doSendTransactionParams: String) : Params()
data class PrepareSendTransactionsResult(var hash: String, var doSendTransactionParams: String) : Params()
data class PrepareSendTransactionsResult(var hash: String, var doSendTransactionParams: String, val eip712Domain: String, ) : Params()
data class DoSendTransactionsResult(var userOperationHash: String) : Params()
data class WaitForUserOperationReceipt(var owner: Account, var userOperationHash: String) : Params()
data class OwnerSignature(val address: String, val signature: String) : Params()
data class Account(val address: String) : Params()
data class Transaction(val to: String, val value: String, val data: String) : Params()
data class Call(val to: String, val value: String, val data: String) : Params()
}

sealed class Model {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.reown.walletkit.client

import com.reown.android.Core
import com.reown.android.CoreInterface
import com.reown.android.internal.common.di.AndroidCommonDITags
import com.reown.android.internal.common.scope
import com.reown.android.internal.common.wcKoinApp
import com.reown.sign.client.Sign
Expand All @@ -15,7 +16,10 @@ import com.reown.walletkit.use_cases.EstimateGasUseCase
import com.reown.walletkit.use_cases.ChainAbstractionStatusUseCase
import com.reown.walletkit.use_cases.GetERC20TokenBalanceUseCase
import com.reown.walletkit.use_cases.GetTransactionDetailsUseCase
import com.squareup.moshi.Moshi
import kotlinx.coroutines.*
import org.koin.core.qualifier.named
import uniffi.yttrium.DoSendTransactionParams
import java.util.*

object WalletKit {
Expand All @@ -26,6 +30,7 @@ object WalletKit {
private val estimateGasUseCase: EstimateGasUseCase by wcKoinApp.koin.inject()
private val getTransactionDetailsUseCase: GetTransactionDetailsUseCase by wcKoinApp.koin.inject()
private val getERC20TokenBalanceUseCase: GetERC20TokenBalanceUseCase by wcKoinApp.koin.inject()
private val moshi: Moshi = wcKoinApp.koin.get<Moshi.Builder>(named(AndroidCommonDITags.MOSHI)).build()

interface WalletDelegate {
fun onSessionProposal(sessionProposal: Wallet.Model.SessionProposal, verifyContext: Wallet.Model.VerifyContext)
Expand Down Expand Up @@ -307,8 +312,9 @@ object WalletKit {

val client = safeInteractor.getOrCreate(Account(params.owner.address))
scope.launch {
async { client.prepareSendTransactions(params.transactions.map { it.toYttrium() }).toWallet() }
async { client.prepareSendTransactions(params.calls.map { it.toYttrium() }) }
.await()
.toWallet(moshi)
.let(onSuccess)
}
}
Expand All @@ -319,8 +325,9 @@ object WalletKit {
check(::safeInteractor.isInitialized) { "Smart Accounts are not enabled" }

val client = safeInteractor.getOrCreate(Account(params.owner.address))
val doSendParams = moshi.adapter(DoSendTransactionParams::class.java).fromJson(params.doSendTransactionParams) ?: throw IllegalStateException("Failed to parse DoSendTransactionParams")
scope.launch {
async { client.doSendTransactions(params.signatures.map { it.toYttrium() }, params.doSendTransactionParams) }
async { client.doSendTransactions(params.signatures.map { it.toYttrium() }, doSendParams) }
.await()
.let { userOpHash -> onSuccess(Wallet.Params.DoSendTransactionsResult(userOpHash)) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package com.reown.walletkit.smart_account
import com.reown.android.internal.common.model.ProjectId
import com.reown.android.internal.common.wcKoinApp
import uniffi.uniffi_yttrium.FfiAccountClient
import uniffi.uniffi_yttrium.FfiAccountClientConfig

import uniffi.yttrium.Config
import uniffi.yttrium.Endpoint
import uniffi.yttrium.Endpoints
Expand All @@ -31,14 +29,6 @@ class SafeInteractor(private val pimlicoApiKey: String) {
paymaster = Endpoint(baseUrl = pimlicoUrl, apiKey = ""),
)
val config = Config(endpoints)
val accountConfig = FfiAccountClientConfig(
ownerAddress = account.address,
chainId = account.reference.toULong(),
config = config,
privateKey = "ff89825a799afce0d5deaa079cdde227072ec3f62973951683ac8cc033000000", //todo: remove sign service, just placeholder
safe = true,
signerType = "PrivateKey" //todo: remove sign service
)
return FfiAccountClient(accountConfig)
return FfiAccountClient(owner = account.address, chainId = account.reference.toULong(), config = config)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package com.reown.walletkit.use_cases

import com.reown.android.internal.common.scope
import com.reown.walletkit.client.Wallet
import com.reown.walletkit.client.toInitialYttrium
import com.reown.walletkit.client.toWallet
import kotlinx.coroutines.async
import kotlinx.coroutines.launch
import uniffi.uniffi_yttrium.ChainAbstractionClient
import uniffi.yttrium.BridgingError
import uniffi.yttrium.Call
import uniffi.yttrium.PrepareResponse
import uniffi.yttrium.RouteResponseSuccess
import uniffi.yttrium.PrepareResponseSuccess

class PrepareChainAbstractionUseCase(private val chainAbstractionClient: ChainAbstractionClient) {
operator fun invoke(
Expand All @@ -21,7 +21,8 @@ class PrepareChainAbstractionUseCase(private val chainAbstractionClient: ChainAb
try {
val result = async {
try {
chainAbstractionClient.prepare(initialTransaction.toInitialYttrium())
val call = Call(initialTransaction.to, initialTransaction.value, initialTransaction.input)
chainAbstractionClient.prepare(initialTransaction.chainId, initialTransaction.from, call)
} catch (e: Exception) {
return@async onError(Wallet.Model.PrepareError.Unknown(e.message ?: "Unknown error"))
}
Expand All @@ -30,11 +31,11 @@ class PrepareChainAbstractionUseCase(private val chainAbstractionClient: ChainAb
when (result) {
is PrepareResponse.Success -> {
when (result.v1) {
is RouteResponseSuccess.Available ->
onSuccess((result.v1 as RouteResponseSuccess.Available).v1.toWallet())
is PrepareResponseSuccess.Available ->
onSuccess((result.v1 as PrepareResponseSuccess.Available).v1.toWallet())

is RouteResponseSuccess.NotRequired ->
onSuccess(Wallet.Model.PrepareSuccess.NotRequired((result.v1 as RouteResponseSuccess.NotRequired).v1.initialTransaction.toWallet()))
is PrepareResponseSuccess.NotRequired ->
onSuccess(Wallet.Model.PrepareSuccess.NotRequired((result.v1 as PrepareResponseSuccess.NotRequired).v1.initialTransaction.toWallet()))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

fun createBlockChainApiService(projectId: String, chainId: String): BlockChainApiService {
val rpcUrl: String = when (chainId) {
"eip155:10" -> "https://rpc.walletconnect.com"//"https://mainnet.optimism.io"
"eip155:8453" -> "https://mainnet.base.org"
"eip155:42161" -> "https://rpc.walletconnect.com"//""https://arbitrum.llamarpc.com"
else -> "https://rpc.walletconnect.com"
}
val rpcUrl = "https://rpc.walletconnect.com"
// when (chainId) {
// "eip155:10" -> "https://rpc.walletconnect.com"//"https://mainnet.optimism.io"
// "eip155:8453" -> "https://mainnet.base.org"
// "eip155:42161" -> "https://rpc.walletconnect.com"//""https://arbitrum.llamarpc.com"
// else -> "https://rpc.walletconnect.com"
// }

val httpClient = OkHttpClient.Builder()

Expand Down
Loading

0 comments on commit 4a408d4

Please sign in to comment.