2022-09-27 03:20:09 +00:00
|
|
|
package pulse
|
|
|
|
|
|
|
|
import (
|
|
|
|
_ "embed"
|
|
|
|
"math/big"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/core/state"
|
|
|
|
"github.com/ethereum/go-ethereum/log"
|
|
|
|
"github.com/ethereum/go-ethereum/params"
|
|
|
|
"github.com/holiman/uint256"
|
|
|
|
)
|
|
|
|
|
2023-05-11 23:04:36 +00:00
|
|
|
// see https://gitlab.com/pulsechaincom/compressed-allocations/-/tags/Mainnet
|
2022-09-27 03:20:09 +00:00
|
|
|
//
|
2023-05-11 23:04:36 +00:00
|
|
|
//go:embed sacrifice_credits_mainnet.bin
|
|
|
|
var mainnetRawCredits []byte
|
|
|
|
|
|
|
|
// see https://gitlab.com/pulsechaincom/compressed-allocations/-/tags/Testnet-V4
|
|
|
|
//
|
|
|
|
//go:embed sacrifice_credits_testnet_v4.bin
|
|
|
|
var testnetV4RawCredits []byte
|
2022-09-27 03:20:09 +00:00
|
|
|
|
2022-10-06 16:34:44 +00:00
|
|
|
// Applies the sacrifice credits for the PrimordialPulse fork.
|
2023-05-11 23:04:36 +00:00
|
|
|
func applySacrificeCredits(state *state.StateDB, treasury *params.Treasury, chainID *big.Int) {
|
|
|
|
rawCredits := mainnetRawCredits
|
|
|
|
if chainID.Cmp(params.PulseChainTestnetV4Config.ChainID) == 0 {
|
|
|
|
rawCredits = testnetV4RawCredits
|
|
|
|
}
|
|
|
|
|
2022-09-27 03:20:09 +00:00
|
|
|
if treasury != nil {
|
|
|
|
log.Info("Applying PrimordialPulse treasury allocation 💸")
|
|
|
|
state.AddBalance(common.HexToAddress(treasury.Addr), uint256.MustFromBig((*big.Int)(treasury.Balance)))
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("Applying PrimordialPulse sacrifice credits 💸")
|
|
|
|
for ptr := 0; ptr < len(rawCredits); {
|
|
|
|
byteCount := int(rawCredits[ptr])
|
|
|
|
ptr++
|
|
|
|
|
|
|
|
record := rawCredits[ptr : ptr+byteCount]
|
|
|
|
ptr += byteCount
|
|
|
|
|
|
|
|
addr := common.BytesToAddress(record[:20])
|
|
|
|
credit := new(uint256.Int).SetBytes(record[20:])
|
|
|
|
state.AddBalance(addr, credit)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("Finished applying PrimordialPulse sacrifice credits 🤑")
|
|
|
|
}
|