-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add L1FeeProvider for rollups with smart contract who can provide L1 fee
- Loading branch information
Showing
3 changed files
with
76 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
ethereumkit/src/main/java/io/horizontalsystems/ethereumkit/core/rollup/L1FeeProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.horizontalsystems.ethereumkit.core.rollup | ||
|
||
import io.horizontalsystems.ethereumkit.contracts.ContractMethod | ||
import io.horizontalsystems.ethereumkit.core.EthereumKit | ||
import io.horizontalsystems.ethereumkit.core.TransactionBuilder | ||
import io.horizontalsystems.ethereumkit.models.Address | ||
import io.horizontalsystems.ethereumkit.models.GasPrice | ||
import io.horizontalsystems.ethereumkit.models.RawTransaction | ||
import io.horizontalsystems.ethereumkit.spv.core.toBigInteger | ||
import io.reactivex.Single | ||
import java.math.BigInteger | ||
|
||
class L1FeeProvider( | ||
private val evmKit: EthereumKit, | ||
private val contractAddress: Address | ||
) { | ||
|
||
class L1FeeMethod(val transaction: ByteArray) : ContractMethod() { | ||
override val methodSignature = "getL1Fee(bytes)" | ||
override fun getArguments() = listOf(transaction) | ||
} | ||
|
||
fun getL1Fee(gasPrice: GasPrice, gasLimit: Long, to: Address, value: BigInteger, data: ByteArray, nonce: Long?): Single<BigInteger> { | ||
val rawTransaction = RawTransaction(gasPrice, gasLimit, to, value, nonce ?: 1, data) | ||
val encoded = TransactionBuilder.encode(rawTransaction, null, evmKit.chain.id) | ||
val data = L1FeeMethod(encoded).encodedABI() | ||
|
||
return evmKit.call(contractAddress, data) | ||
.map { it.sliceArray(IntRange(0, 31)).toBigInteger() } | ||
} | ||
|
||
} |