Skip to content

Commit

Permalink
Merge pull request #180 from pegnet/develop
Browse files Browse the repository at this point in the history
Version 2.0.4
  • Loading branch information
StarNeit authored Mar 12, 2021
2 parents f2fc6d4 + 17667c4 commit 08a0449
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 2 deletions.
2 changes: 2 additions & 0 deletions node/burns.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var (

GlobalOldBurnAddress = "FA1y5ZGuHSLmf2TqNf6hVMkPiNGyQpQDTFJvDLRkKQaoPo4bmbgu"

GlobalMintAddress = "FA3j16WPCiqsAFHVZcEoL85Khh5RhPCNe6PWHBKgUxrx8MAnbNoy"

// BurnRCD is the rcd representation of the burn address
BurnRCD = [32]byte{}
)
Expand Down
45 changes: 45 additions & 0 deletions node/mint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package node

import "github.com/pegnet/pegnetd/fat/fat2"

// Special structure for the mint amount
type MintSupply struct {
Ticker fat2.PTicker // token
Amount uint64 // amount of token to mint
}

var (
MintTotalSupplyMap = []MintSupply{
{fat2.PTickerPEG, 334509613},
{fat2.PTickerUSD, 3184409},
{fat2.PTickerKRW, 118},
{fat2.PTickerXAU, 1},
{fat2.PTickerXAG, 599},
{fat2.PTickerXBT, 2},
{fat2.PTickerETH, 5476},
{fat2.PTickerLTC, 2004},
{fat2.PTickerRVN, 13124813},
{fat2.PTickerXBC, 243},
{fat2.PTickerBNB, 3461},
{fat2.PTickerXLM, 45892},
{fat2.PTickerADA, 1414096},
{fat2.PTickerXMR, 682},
{fat2.PTickerDASH, 6001},
{fat2.PTickerZEC, 2696},
{fat2.PTickerEOS, 2059},
{fat2.PTickerLINK, 9110},
{fat2.PTickerATOM, 101},
{fat2.PTickerNEO, 2},
{fat2.PTickerCRO, 164},
{fat2.PTickerETC, 5},
{fat2.PTickerVET, 22400000},
{fat2.PTickerHT, 5},
{fat2.PTickerDCR, 1049},
{fat2.PTickerAUD, 9},
{fat2.PTickerNOK, 59},
{fat2.PTickerXTZ, 11117},
{fat2.PTickerDOGE, 9870},
{fat2.PTickerALGO, 457602},
{fat2.PTickerDGB, 51175},
}
)
10 changes: 10 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ var (
// V202EnhanceActivation indicates the activation of PegNet 2.0.2.
// Estimated to be Dec 3th 2020
V202EnhanceActivation uint32 = 274036

// V204EnhanceActivation indicates the activation of PegNet 2.0.4.
// Estimated to be Mar 16th 2021
V204EnhanceActivation uint32 = 288878

// V204EnhanceActivation indicates the activation that burns remaining airdrop amount.
// Estimated to be April 16th 2021
V204BurnMintedTokenActivation uint32 = 294206
)

func SetAllActivations(act uint32) {
Expand All @@ -89,6 +97,8 @@ func SetAllActivations(act uint32) {
OneWaySmallAssetsConversions = act
SprSignatureActivation = act
V202EnhanceActivation = act
V204EnhanceActivation = act
V204BurnMintedTokenActivation = act
}

type Pegnetd struct {
Expand Down
77 changes: 75 additions & 2 deletions node/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,67 @@ OuterSyncLoop:
}
}

func (d *Pegnetd) MintTokensForBalance(ctx context.Context, tx *sql.Tx, height uint32) error {
fLog := log.WithFields(log.Fields{"height": height})

FAGlobalMintAddress, err := factom.NewFAAddress(GlobalMintAddress)
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Info("error getting mint address")
return err
}

for _, tokenSupply := range MintTotalSupplyMap {
_, err := d.Pegnet.AddToBalance(tx, &FAGlobalMintAddress, tokenSupply.Ticker, tokenSupply.Amount*1e8)
if err != nil {
fLog.WithFields(log.Fields{
"token": tokenSupply.Ticker,
"amount": tokenSupply.Amount,
"error": err,
}).Info("error minting token is failed")
return err
}
}

return nil
}

func (d *Pegnetd) NullifyMintedTokens(ctx context.Context, tx *sql.Tx, height uint32) error {
fLog := log.WithFields(log.Fields{"height": height})

FAGlobalMintAddress, err := factom.NewFAAddress(GlobalMintAddress)
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Info("error getting mint address")
return err
}

// Get all balances for the address
balances, err := d.Pegnet.SelectBalances(&FAGlobalMintAddress)
if err != nil {
fLog.WithFields(log.Fields{
"err": err,
}).Info("zeroing burn | balances retrieval failed")
}

for _, tokenSupply := range MintTotalSupplyMap {
// Substract from every issuance
ticker := tokenSupply.Ticker
value, _ := balances[ticker]
_, _, err := d.Pegnet.SubFromBalance(tx, &FAGlobalMintAddress, ticker, value) // lastInd, txErr, err
if err != nil {
fLog.WithFields(log.Fields{
"ticker": ticker,
"balance": value,
}).Info("zeroing burn | substract from balance failed")
return err
}
}
return nil
}

func (d *Pegnetd) NullifyBurnAddress(ctx context.Context, tx *sql.Tx, height uint32) error {
fLog := log.WithFields(log.Fields{"height": height})

Expand Down Expand Up @@ -215,7 +276,7 @@ func (d *Pegnetd) NullifyBurnAddress(ctx context.Context, tx *sql.Tx, height uin
}).Info("zeroing burn | balances retrieval failed")
}

i := 0 // value to keep witin 0-9 range for mock tx
i := 0 // value to keep witin 0-9 range for mock tx
j := 0 // value for uniqueness
if height >= V202EnhanceActivation {
j = 50
Expand Down Expand Up @@ -278,6 +339,18 @@ func (d *Pegnetd) SyncBlock(ctx context.Context, tx *sql.Tx, height uint32) erro
return context.Canceled
}

if height == V204EnhanceActivation {
if err := d.MintTokensForBalance(ctx, tx, d.Sync.Synced+1); err != nil {
return err
}
}

if height == V204BurnMintedTokenActivation {
if err := d.NullifyMintedTokens(ctx, tx, d.Sync.Synced+1); err != nil {
return err
}
}

dblock := new(factom.DBlock)
dblock.Height = height
if err := dblock.Get(nil, d.FactomClient); err != nil {
Expand Down Expand Up @@ -1404,4 +1477,4 @@ func (d *Pegnetd) GetAssetRatesV0(oprWinners []opr.AssetUint, sprWinners []opr.A
return filteredRates, nil
}
return nil, fmt.Errorf("no winners")
}
}

0 comments on commit 08a0449

Please sign in to comment.