Skip to content

Commit

Permalink
fix: add lima contracts amount minted to supply (#1252)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyeshe authored Apr 5, 2023
1 parent ab276df commit 738bce2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
13 changes: 11 additions & 2 deletions lib/ae_mdw/db/hardfork_presets.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,17 @@ defmodule AeMdw.Db.HardforkPresets do
defp accounts(:minerva), do: :aec_fork_block_settings.minerva_accounts()
defp accounts(:fortuna), do: :aec_fork_block_settings.fortuna_accounts()

defp accounts(:lima),
do: :aec_fork_block_settings.lima_accounts() ++ :aec_fork_block_settings.lima_extra_accounts()
defp accounts(:lima) do
contract_account =
:aec_fork_block_settings.lima_contracts()
|> Enum.map(fn %{pubkey: pk, amount: amount} ->
{pk, amount}
end)

contract_account ++
:aec_fork_block_settings.lima_accounts() ++
:aec_fork_block_settings.lima_extra_accounts()
end

defp accounts(_hf), do: %{}

Expand Down
38 changes: 38 additions & 0 deletions priv/migrations/20230404095010_update_total_supply.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
defmodule AeMdw.Migrations.UpdateTotalSupply do
@moduledoc """
Updates totalstats total supply incrementing with the lima contracts amount.
"""

alias AeMdw.Db.WriteMutation
alias AeMdw.Db.Model
alias AeMdw.Db.State

require Model

@spec run(State.t(), boolean()) :: {:ok, non_neg_integer()}
def run(state, _from_start?) do
with [%{amount: amount}] <- :aec_fork_block_settings.lima_contracts(),
{:ok, {last_height, _mbi}} <- State.prev(state, Model.Block, nil),
%{4 => lima_height} <-
:aec_hard_forks.protocols_from_network_id(:aec_governance.get_network_id()) do
mutations =
Enum.map(lima_height..last_height, fn height ->
m_stat =
Model.total_stat(total_supply: total_supply) =
State.fetch!(state, Model.TotalStat, height)

WriteMutation.new(
Model.TotalStat,
Model.total_stat(m_stat, total_supply: total_supply + amount)
)
end)

_state = State.commit(state, mutations)

{:ok, length(mutations)}
else
_no_lima ->
{:ok, 0}
end
end
end
2 changes: 1 addition & 1 deletion test/ae_mdw/db/hardfork_presets_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ defmodule AeMdw.Db.HardforkPresetsTest do
assert HardforkPresets.mint_sum(:genesis) == 89_451_376_822_397_976_634_367_408
assert HardforkPresets.mint_sum(:minerva) == 27_051_422_546_127_651_538_826_703
assert HardforkPresets.mint_sum(:fortuna) == 72_681_157_406_723_951_132_840_970
assert HardforkPresets.mint_sum(:lima) == 57_326_570_459_001_950_946_109_814
assert HardforkPresets.mint_sum(:lima) == 86_948_638_040_240_004_719_633_952
end
end

Expand Down

0 comments on commit 738bce2

Please sign in to comment.