Skip to content

Commit

Permalink
fix(fee): default gas and storage limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Awea committed Jun 10, 2024
1 parent 10c1455 commit 93eb060
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 6 additions & 2 deletions lib/fee.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ defmodule Tezex.Fee do

@default_transaction_gas_limit 1451
@default_transaction_storage_limit 257
@hard_gas_limit_per_operation 1_040_000
@hard_storage_limit_per_operation 60000
@minimal_fees 100
@minimal_mutez_per_byte 1
@minimal_nanotez_per_gas_unit 100
@reserve 10

@hard_gas_limit_per_operation 1_040_000
def hard_gas_limit_per_operation, do: @hard_gas_limit_per_operation

@hard_storage_limit_per_operation 60000
def hard_storage_limit_per_operation, do: @hard_storage_limit_per_operation

# size of serialized branch and signature + safe reserve
@extra_size 32 + 64
def extra_size, do: @extra_size
Expand Down
10 changes: 8 additions & 2 deletions lib/rpc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,21 @@ defmodule Tezex.Rpc do

@spec prepare_operation(list(op()), nonempty_binary(), integer(), nonempty_binary()) :: op()
def prepare_operation(contents, wallet_address, counter, branch) do
hard_gas_limit_per_content = div(Fee.hard_gas_limit_per_operation(), length(contents))
hard_storage_limit_per_content = div(Fee.hard_storage_limit_per_operation(), length(contents))

contents =
contents
|> Enum.with_index(counter)
|> Enum.map(fn {content, counter} ->
gas_limit = min(hard_gas_limit_per_content, Fee.default_gas_limit(content))
storage_limit = min(hard_storage_limit_per_content, Fee.default_storage_limit(content))

Map.merge(content, %{
"counter" => Integer.to_string(counter),
"source" => wallet_address,
"gas_limit" => Integer.to_string(Fee.default_gas_limit(content)),
"storage_limit" => Integer.to_string(Fee.default_storage_limit(content)),
"gas_limit" => Integer.to_string(gas_limit),
"storage_limit" => Integer.to_string(storage_limit),
"fee" => "0"
})
end)
Expand Down

0 comments on commit 93eb060

Please sign in to comment.