Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC 0.6.0 cleanup #381

Merged
merged 66 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
38efbae
Bump cairo-lang to 0.13.0
DelevoXDG Dec 22, 2023
09e24da
executeV3 should still pass forFeeEstimate=true, even though it's not…
DelevoXDG Dec 27, 2023
a0ffc28
Review changes
DelevoXDG Dec 27, 2023
edf3bf5
Add DeprecatedTransaction
DelevoXDG Dec 29, 2023
771b8ee
Use correct estimateFee in executeV3
DelevoXDG Jan 23, 2024
83e32be
Update test_variables.env.example
DelevoXDG Jan 23, 2024
f251ac2
Merge main
DelevoXDG Jan 23, 2024
6ca5ce7
Merge main (2)
DelevoXDG Jan 23, 2024
6fb1f02
Unify JsonRpcError (#393)
DelevoXDG Jan 23, 2024
f31a865
Update JsonRpcError tests
DelevoXDG Jan 23, 2024
a9bd483
Add v1 postfixes to Account methods
DelevoXDG Jan 23, 2024
03ca644
Rename ExecutionParamsV3->InvokeParamsV3
DelevoXDG Jan 23, 2024
d80fa3b
Fix typo
DelevoXDG Jan 23, 2024
9d34fc3
Deployer: support deploying using invoke v3
DelevoXDG Jan 23, 2024
3b9830c
Update StandardDeployerTest
DelevoXDG Jan 23, 2024
1028aa8
Remove contract_with_constructor (no longer needed)
DelevoXDG Jan 23, 2024
7aeb6b3
Adjust network test
DelevoXDG Jan 23, 2024
5b0670e
Rename JsonRpcErrorPolymorphicSerializer.kt to JsonRpcErrorSerializer.kt
DelevoXDG Jan 23, 2024
9beae7b
Make DeployTransaction conform to DeprecatedTransaction
DelevoXDG Jan 23, 2024
b47cb7b
Replace simulationFlags with boolean flag in Accoubnt.estimateFee met…
DelevoXDG Jan 24, 2024
a012d86
Don't SKIP_VALIDATE by default in Provider.getEstimateFee
DelevoXDG Jan 24, 2024
6ec156f
Fix declare v3 payload for fee estimate
DelevoXDG Jan 24, 2024
08c872f
Adjust tests
DelevoXDG Jan 24, 2024
fb4ab0c
Test all numbers
DelevoXDG Jan 30, 2024
769ef7d
Remove redundant supress
DelevoXDG Jan 30, 2024
be34b16
Merge branch 'main' into rpc-0.6.0-cleanup
DelevoXDG Jan 30, 2024
b3adcb6
Fix StandardAccountTest
DelevoXDG Jan 30, 2024
c242ba2
Update AccountTest
DelevoXDG Jan 30, 2024
4194557
Make TransactionHashCalculator: resourceBoundsForFee and dataAvailabi…
DelevoXDG Jan 30, 2024
5d9f0f5
Add `calculate data availability modes` test
DelevoXDG Jan 30, 2024
963ee55
Improve naming of TransactionHashCalculator helpers
DelevoXDG Jan 30, 2024
b186aa3
Make prepareResourceBoundsForFee private
DelevoXDG Jan 30, 2024
03ef203
Update TransactionHashCalculatorTest
DelevoXDG Jan 30, 2024
2f23cd3
Make ResourceBoundsMapping primary constructor private
DelevoXDG Jan 30, 2024
538d6c9
Update TransactionFactory
DelevoXDG Jan 30, 2024
07d61a6
Format
DelevoXDG Jan 30, 2024
21c2f84
Restrict usage of v3 fields in TransactionPayload
DelevoXDG Jan 30, 2024
94bbe40
Restrict usage of v3 fields in TransactionFactory
DelevoXDG Jan 30, 2024
afc17f7
Fix #400
DelevoXDG Jan 30, 2024
070a332
Fix Provider description innacuracies; Simplify signatures
DelevoXDG Jan 30, 2024
cf03495
Add DeclareEstimateTest:
DelevoXDG Jan 30, 2024
9311d0e
Update estimateMessageFee post-cairo0 solution comment
DelevoXDG Jan 30, 2024
33106df
Remove needless param
DelevoXDG Jan 30, 2024
7cbf30f
add missing v1
DelevoXDG Jan 30, 2024
b79b428
Nest declare tests
DelevoXDG Jan 30, 2024
e00ce36
Nest estimate deploy account tests
DelevoXDG Jan 30, 2024
bcb2a50
Remove SKIP_VALIDATE estimate declare fee tests
DelevoXDG Jan 30, 2024
974da75
Add `estimate fee with skip validate flag` flag; Streamline invoke es…
DelevoXDG Jan 30, 2024
102be37
Add simulate v3 tests
DelevoXDG Jan 30, 2024
eeb024a
Nest deploy account tests; Add and streamline forFeeEstimate uses and…
DelevoXDG Jan 30, 2024
7d33ec4
Nest simulate transactions tests
DelevoXDG Jan 30, 2024
5203cd5
Move `simulate invoke v1 and deploy account v1 transactions` to Simul…
DelevoXDG Jan 30, 2024
9fd79f5
Format
DelevoXDG Jan 30, 2024
ccbfb36
Merge branch 'main' into rpc-0.6.0-cleanup
DelevoXDG Jan 31, 2024
ee92c05
Update StarknetChainId (follow SN_NAME for every StarknetChainId.NAME)
DelevoXDG Jan 31, 2024
e045b9e
starknet -> Starknet
DelevoXDG Jan 31, 2024
617e53f
Fix function signature
DelevoXDG Jan 31, 2024
9b919e3
Improve DeprecatedTransaction and TransactionV3 interfaces
DelevoXDG Jan 31, 2024
762ad65
Initialize hash to null in fromPayload
DelevoXDG Jan 31, 2024
eaf7a65
Remove unused fromPayload methods
DelevoXDG Jan 31, 2024
494e598
Format
DelevoXDG Jan 31, 2024
098a867
Bump devnet
DelevoXDG Jan 31, 2024
031391b
StandardAccount: reorder estimateFeeV(1|3) methods
DelevoXDG Jan 31, 2024
f85e0e4
Move down prepareSimulationFlagsForFeeEstimate
DelevoXDG Jan 31, 2024
2bb8262
Remove DeployAccountParamsV3 constructor with resourceBounds; Use @Jv…
DelevoXDG Jan 31, 2024
2616060
Merge branch 'main' into rpc-0.6.0-cleanup
DelevoXDG Feb 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 60 additions & 50 deletions lib/src/main/kotlin/com/swmansion/starknet/account/Account.kt

Large diffs are not rendered by default.

158 changes: 72 additions & 86 deletions lib/src/main/kotlin/com/swmansion/starknet/account/StandardAccount.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class StandardAccount(
.add(version.value)
.toFelt
}
private val defaultFeeEstimateSimulationFlags: Set<SimulationFlagForEstimateFee> by lazy {
setOf(SimulationFlagForEstimateFee.SKIP_VALIDATE)
}

/**
* @param provider a provider used to interact with Starknet
Expand All @@ -49,7 +46,7 @@ class StandardAccount(
cairoVersion,
)

override fun sign(calls: List<Call>, params: ExecutionParams, forFeeEstimate: Boolean): InvokeTransactionV1Payload {
override fun signV1(calls: List<Call>, params: ExecutionParams, forFeeEstimate: Boolean): InvokeTransactionV1Payload {
val calldata = AccountCalldataTransformer.callsToExecuteCalldata(calls, cairoVersion)
val signVersion = when (forFeeEstimate) {
true -> estimateVersion(Felt.ONE)
Expand All @@ -69,7 +66,7 @@ class StandardAccount(
return signedTransaction.toPayload()
}

override fun sign(calls: List<Call>, params: ExecutionParamsV3, forFeeEstimate: Boolean): InvokeTransactionV3Payload {
override fun signV3(calls: List<Call>, params: InvokeParamsV3, forFeeEstimate: Boolean): InvokeTransactionV3Payload {
val calldata = AccountCalldataTransformer.callsToExecuteCalldata(calls, cairoVersion)
val signVersion = when (forFeeEstimate) {
true -> estimateVersion(Felt(3))
Expand All @@ -82,19 +79,14 @@ class StandardAccount(
nonce = params.nonce,
version = signVersion,
resourceBounds = params.resourceBounds,
tip = params.tip,
paymasterData = params.paymasterData,
accountDeploymentData = params.accountDeploymentData,
nonceDataAvailabilityMode = params.nonceDataAvailabilityMode,
feeDataAvailabilityMode = params.feeDataAvailabilityMode,
)

val signedTransaction = tx.copy(signature = signer.signTransaction(tx))

return signedTransaction.toPayload()
}

override fun signDeployAccount(
override fun signDeployAccountV1(
classHash: Felt,
calldata: Calldata,
salt: Felt,
Expand All @@ -121,7 +113,7 @@ class StandardAccount(
return signedTransaction.toPayload()
}

override fun signDeployAccount(
override fun signDeployAccountV3(
classHash: Felt,
calldata: Calldata,
salt: Felt,
Expand All @@ -141,17 +133,13 @@ class StandardAccount(
version = signVersion,
nonce = params.nonce,
resourceBounds = params.resourceBounds,
tip = params.tip,
paymasterData = params.paymasterData,
nonceDataAvailabilityMode = params.nonceDataAvailabilityMode,
feeDataAvailabilityMode = params.feeDataAvailabilityMode,
)
val signedTransaction = tx.copy(signature = signer.signTransaction(tx))

return signedTransaction.toPayload()
}

override fun signDeclare(
override fun signDeclareV1(
contractDefinition: Cairo0ContractDefinition,
classHash: Felt,
params: ExecutionParams,
Expand All @@ -175,7 +163,7 @@ class StandardAccount(
return signedTransaction.toPayload()
}

override fun signDeclare(
override fun signDeclareV2(
sierraContractDefinition: Cairo1ContractDefinition,
casmContractDefinition: CasmContractDefinition,
params: ExecutionParams,
Expand All @@ -199,7 +187,7 @@ class StandardAccount(
return signedTransaction.toPayload()
}

override fun signDeclare(
override fun signDeclareV3(
sierraContractDefinition: Cairo1ContractDefinition,
casmContractDefinition: CasmContractDefinition,
params: DeclareParamsV3,
Expand All @@ -216,12 +204,7 @@ class StandardAccount(
nonce = params.nonce,
version = signVersion,
resourceBounds = params.resourceBounds,
tip = params.tip,
paymasterData = params.paymasterData,
accountDeploymentData = params.accountDeploymentData,
casmContractDefinition = casmContractDefinition,
nonceDataAvailabilityMode = params.nonceDataAvailabilityMode,
feeDataAvailabilityMode = params.feeDataAvailabilityMode,
)
val signedTransaction = tx.copy(signature = signer.signTransaction(tx))

Expand Down Expand Up @@ -277,51 +260,51 @@ class StandardAccount(
throw e
}

override fun execute(calls: List<Call>, maxFee: Felt): Request<InvokeFunctionResponse> {
override fun executeV1(calls: List<Call>, maxFee: Felt): Request<InvokeFunctionResponse> {
return getNonce().compose { nonce ->
val signParams = ExecutionParams(nonce = nonce, maxFee = maxFee)
val payload = sign(calls, signParams)
val payload = signV1(calls, signParams)

return@compose provider.invokeFunction(payload)
}
}

override fun executeV3(calls: List<Call>, l1ResourceBounds: ResourceBounds): Request<InvokeFunctionResponse> {
return getNonce().compose { nonce ->
val signParams = ExecutionParamsV3(
val signParams = InvokeParamsV3(
nonce = nonce,
l1ResourceBounds = l1ResourceBounds,
)
val payload = sign(calls, signParams, false)
val payload = signV3(calls, signParams, false)

return@compose provider.invokeFunction(payload)
}
}

override fun execute(calls: List<Call>): Request<InvokeFunctionResponse> {
return estimateFee(calls).compose { estimateFee ->
override fun executeV1(calls: List<Call>): Request<InvokeFunctionResponse> {
return estimateFeeV1(calls).compose { estimateFee ->
val maxFee = estimateFee.first().toMaxFee()
execute(calls, maxFee)
executeV1(calls, maxFee)
}
}

override fun executeV3(calls: List<Call>): Request<InvokeFunctionResponse> {
return estimateFee(calls).compose { estimateFee ->
return estimateFeeV3(calls).compose { estimateFee ->
val resourceBounds = estimateFee.first().toResourceBounds()
executeV3(calls, resourceBounds.l1Gas)
}
}

override fun execute(call: Call, maxFee: Felt): Request<InvokeFunctionResponse> {
return execute(listOf(call), maxFee)
override fun executeV1(call: Call, maxFee: Felt): Request<InvokeFunctionResponse> {
return executeV1(listOf(call), maxFee)
}

override fun executeV3(call: Call, l1ResourceBounds: ResourceBounds): Request<InvokeFunctionResponse> {
return executeV3(listOf(call), l1ResourceBounds)
}

override fun execute(call: Call): Request<InvokeFunctionResponse> {
return execute(listOf(call))
override fun executeV1(call: Call): Request<InvokeFunctionResponse> {
return executeV1(listOf(call))
}

override fun executeV3(call: Call): Request<InvokeFunctionResponse> {
Expand All @@ -336,72 +319,59 @@ class StandardAccount(

override fun getNonce(blockNumber: Int) = provider.getNonce(address, blockNumber)

override fun estimateFee(call: Call): Request<List<EstimateFeeResponse>> {
return estimateFee(listOf(call))
override fun estimateFeeV1(call: Call): Request<List<EstimateFeeResponse>> {
return estimateFeeV1(listOf(call))
}

override fun estimateFee(call: Call, simulationFlags: Set<SimulationFlagForEstimateFee>): Request<List<EstimateFeeResponse>> {
return estimateFee(listOf(call), simulationFlags)
override fun estimateFeeV1(call: Call, skipValidate: Boolean): Request<List<EstimateFeeResponse>> {
return estimateFeeV1(listOf(call), skipValidate)
}

override fun estimateFee(call: Call, blockTag: BlockTag): Request<List<EstimateFeeResponse>> {
return estimateFee(listOf(call), blockTag)
override fun estimateFeeV1(call: Call, blockTag: BlockTag): Request<List<EstimateFeeResponse>> {
return estimateFeeV1(listOf(call), blockTag)
}

override fun estimateFee(
override fun estimateFeeV1(
call: Call,
blockTag: BlockTag,
simulationFlags: Set<SimulationFlagForEstimateFee>,
): Request<List<EstimateFeeResponse>> {
return estimateFee(listOf(call), blockTag, simulationFlags)
}

override fun estimateFee(calls: List<Call>): Request<List<EstimateFeeResponse>> {
return estimateFee(calls, BlockTag.PENDING)
}

override fun estimateFeeV3(calls: List<Call>): Request<List<EstimateFeeResponse>> {
return estimateFeeV3(calls, BlockTag.PENDING, defaultFeeEstimateSimulationFlags)
}

override fun estimateFee(
calls: List<Call>,
simulationFlags: Set<SimulationFlagForEstimateFee>,
skipValidate: Boolean,
): Request<List<EstimateFeeResponse>> {
return estimateFee(calls, BlockTag.PENDING, simulationFlags)
return estimateFeeV1(listOf(call), blockTag, skipValidate)
}

override fun estimateFeeV3(
calls: List<Call>,
simulationFlags: Set<SimulationFlagForEstimateFee>,
): Request<List<EstimateFeeResponse>> {
return estimateFeeV3(calls, BlockTag.PENDING, simulationFlags)
override fun estimateFeeV1(calls: List<Call>): Request<List<EstimateFeeResponse>> {
return estimateFeeV1(calls, BlockTag.PENDING, false)
}

override fun estimateFeeV3(calls: List<Call>, blockTag: BlockTag): Request<List<EstimateFeeResponse>> {
return estimateFeeV3(calls, blockTag)
override fun estimateFeeV1(calls: List<Call>, skipValidate: Boolean): Request<List<EstimateFeeResponse>> {
return estimateFeeV1(calls, BlockTag.PENDING, skipValidate)
}

override fun estimateFee(calls: List<Call>, blockTag: BlockTag): Request<List<EstimateFeeResponse>> {
return estimateFee(calls, blockTag, defaultFeeEstimateSimulationFlags)
override fun estimateFeeV1(calls: List<Call>, blockTag: BlockTag): Request<List<EstimateFeeResponse>> {
return estimateFeeV1(calls, blockTag, false)
}

override fun estimateFee(
override fun estimateFeeV1(
calls: List<Call>,
blockTag: BlockTag,
simulationFlags: Set<SimulationFlagForEstimateFee>,
skipValidate: Boolean,
): Request<List<EstimateFeeResponse>> {
return getNonce(blockTag).compose { nonce ->
val payload = buildEstimateFeePayload(calls, nonce)
val simulationFlags = prepareSimulationFlagsForFeeEstimate(skipValidate)
val payload = buildEstimateFeeV1Payload(calls, nonce)
return@compose provider.getEstimateFee(payload, blockTag, simulationFlags)
}
}

override fun estimateFeeV3(call: Call): Request<List<EstimateFeeResponse>> {
return estimateFeeV3(listOf(call))
}

override fun estimateFeeV3(
call: Call,
simulationFlags: Set<SimulationFlagForEstimateFee>,
skipValidate: Boolean,
): Request<List<EstimateFeeResponse>> {
return estimateFeeV3(listOf(call), simulationFlags)
return estimateFeeV3(listOf(call), skipValidate)
}

override fun estimateFeeV3(call: Call, blockTag: BlockTag): Request<List<EstimateFeeResponse>> {
Expand All @@ -411,25 +381,46 @@ class StandardAccount(
override fun estimateFeeV3(
call: Call,
blockTag: BlockTag,
simulationFlags: Set<SimulationFlagForEstimateFee>,
skipValidate: Boolean,
): Request<List<EstimateFeeResponse>> {
return estimateFeeV3(listOf(call), blockTag, simulationFlags)
return estimateFeeV3(listOf(call), blockTag, skipValidate)
}

override fun estimateFeeV3(calls: List<Call>): Request<List<EstimateFeeResponse>> {
return estimateFeeV3(calls, BlockTag.PENDING, false)
}

override fun estimateFeeV3(calls: List<Call>, skipValidate: Boolean): Request<List<EstimateFeeResponse>> {
return estimateFeeV3(calls, BlockTag.PENDING, skipValidate)
}

override fun estimateFeeV3(calls: List<Call>, blockTag: BlockTag): Request<List<EstimateFeeResponse>> {
return estimateFeeV3(calls, blockTag, false)
}

override fun estimateFeeV3(
calls: List<Call>,
blockTag: BlockTag,
simulationFlags: Set<SimulationFlagForEstimateFee>,
skipValidate: Boolean,
): Request<List<EstimateFeeResponse>> {
return getNonce(blockTag).compose { nonce ->
val payload = buildEstimateFeeV3Payload(calls, nonce)
val simulationFlags = prepareSimulationFlagsForFeeEstimate(skipValidate)
return@compose provider.getEstimateFee(payload, blockTag, simulationFlags)
}
}

private fun buildEstimateFeePayload(calls: List<Call>, nonce: Felt): List<TransactionPayload> {
private fun prepareSimulationFlagsForFeeEstimate(skipValidate: Boolean): Set<SimulationFlagForEstimateFee> {
return if (skipValidate) {
setOf(SimulationFlagForEstimateFee.SKIP_VALIDATE)
} else {
emptySet()
}
}

private fun buildEstimateFeeV1Payload(calls: List<Call>, nonce: Felt): List<TransactionPayload> {
val executionParams = ExecutionParams(nonce = nonce, maxFee = Felt.ZERO)
val payload = sign(calls, executionParams, true)
val payload = signV1(calls, executionParams, true)

val signedTransaction = TransactionFactory.makeInvokeV1Transaction(
senderAddress = payload.senderAddress,
Expand All @@ -444,11 +435,11 @@ class StandardAccount(
}

private fun buildEstimateFeeV3Payload(calls: List<Call>, nonce: Felt): List<TransactionPayload> {
val executionParams = ExecutionParamsV3(
val executionParams = InvokeParamsV3(
nonce = nonce,
l1ResourceBounds = ResourceBounds.ZERO,
)
val payload = sign(calls, executionParams, false)
val payload = signV3(calls, executionParams, true)

val signedTransaction = TransactionFactory.makeInvokeV3Transaction(
senderAddress = payload.senderAddress,
Expand All @@ -458,11 +449,6 @@ class StandardAccount(
signature = payload.signature,
version = payload.version,
resourceBounds = payload.resourceBounds,
tip = payload.tip,
paymasterData = payload.paymasterData,
accountDeploymentData = payload.accountDeploymentData,
nonceDataAvailabilityMode = payload.nonceDataAvailabilityMode,
feeDataAvailabilityMode = payload.feeDataAvailabilityMode,
)
return listOf(signedTransaction.toPayload())
}
Expand Down
Loading
Loading