Skip to content

Commit 08a0449

Browse files
authored
Merge pull request #180 from pegnet/develop
Version 2.0.4
2 parents f2fc6d4 + 17667c4 commit 08a0449

File tree

4 files changed

+132
-2
lines changed

4 files changed

+132
-2
lines changed

node/burns.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ var (
1313

1414
GlobalOldBurnAddress = "FA1y5ZGuHSLmf2TqNf6hVMkPiNGyQpQDTFJvDLRkKQaoPo4bmbgu"
1515

16+
GlobalMintAddress = "FA3j16WPCiqsAFHVZcEoL85Khh5RhPCNe6PWHBKgUxrx8MAnbNoy"
17+
1618
// BurnRCD is the rcd representation of the burn address
1719
BurnRCD = [32]byte{}
1820
)

node/mint.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package node
2+
3+
import "github.com/pegnet/pegnetd/fat/fat2"
4+
5+
// Special structure for the mint amount
6+
type MintSupply struct {
7+
Ticker fat2.PTicker // token
8+
Amount uint64 // amount of token to mint
9+
}
10+
11+
var (
12+
MintTotalSupplyMap = []MintSupply{
13+
{fat2.PTickerPEG, 334509613},
14+
{fat2.PTickerUSD, 3184409},
15+
{fat2.PTickerKRW, 118},
16+
{fat2.PTickerXAU, 1},
17+
{fat2.PTickerXAG, 599},
18+
{fat2.PTickerXBT, 2},
19+
{fat2.PTickerETH, 5476},
20+
{fat2.PTickerLTC, 2004},
21+
{fat2.PTickerRVN, 13124813},
22+
{fat2.PTickerXBC, 243},
23+
{fat2.PTickerBNB, 3461},
24+
{fat2.PTickerXLM, 45892},
25+
{fat2.PTickerADA, 1414096},
26+
{fat2.PTickerXMR, 682},
27+
{fat2.PTickerDASH, 6001},
28+
{fat2.PTickerZEC, 2696},
29+
{fat2.PTickerEOS, 2059},
30+
{fat2.PTickerLINK, 9110},
31+
{fat2.PTickerATOM, 101},
32+
{fat2.PTickerNEO, 2},
33+
{fat2.PTickerCRO, 164},
34+
{fat2.PTickerETC, 5},
35+
{fat2.PTickerVET, 22400000},
36+
{fat2.PTickerHT, 5},
37+
{fat2.PTickerDCR, 1049},
38+
{fat2.PTickerAUD, 9},
39+
{fat2.PTickerNOK, 59},
40+
{fat2.PTickerXTZ, 11117},
41+
{fat2.PTickerDOGE, 9870},
42+
{fat2.PTickerALGO, 457602},
43+
{fat2.PTickerDGB, 51175},
44+
}
45+
)

node/node.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ var (
7272
// V202EnhanceActivation indicates the activation of PegNet 2.0.2.
7373
// Estimated to be Dec 3th 2020
7474
V202EnhanceActivation uint32 = 274036
75+
76+
// V204EnhanceActivation indicates the activation of PegNet 2.0.4.
77+
// Estimated to be Mar 16th 2021
78+
V204EnhanceActivation uint32 = 288878
79+
80+
// V204EnhanceActivation indicates the activation that burns remaining airdrop amount.
81+
// Estimated to be April 16th 2021
82+
V204BurnMintedTokenActivation uint32 = 294206
7583
)
7684

7785
func SetAllActivations(act uint32) {
@@ -89,6 +97,8 @@ func SetAllActivations(act uint32) {
8997
OneWaySmallAssetsConversions = act
9098
SprSignatureActivation = act
9199
V202EnhanceActivation = act
100+
V204EnhanceActivation = act
101+
V204BurnMintedTokenActivation = act
92102
}
93103

94104
type Pegnetd struct {

node/sync.go

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,67 @@ OuterSyncLoop:
172172
}
173173
}
174174

175+
func (d *Pegnetd) MintTokensForBalance(ctx context.Context, tx *sql.Tx, height uint32) error {
176+
fLog := log.WithFields(log.Fields{"height": height})
177+
178+
FAGlobalMintAddress, err := factom.NewFAAddress(GlobalMintAddress)
179+
if err != nil {
180+
log.WithFields(log.Fields{
181+
"error": err,
182+
}).Info("error getting mint address")
183+
return err
184+
}
185+
186+
for _, tokenSupply := range MintTotalSupplyMap {
187+
_, err := d.Pegnet.AddToBalance(tx, &FAGlobalMintAddress, tokenSupply.Ticker, tokenSupply.Amount*1e8)
188+
if err != nil {
189+
fLog.WithFields(log.Fields{
190+
"token": tokenSupply.Ticker,
191+
"amount": tokenSupply.Amount,
192+
"error": err,
193+
}).Info("error minting token is failed")
194+
return err
195+
}
196+
}
197+
198+
return nil
199+
}
200+
201+
func (d *Pegnetd) NullifyMintedTokens(ctx context.Context, tx *sql.Tx, height uint32) error {
202+
fLog := log.WithFields(log.Fields{"height": height})
203+
204+
FAGlobalMintAddress, err := factom.NewFAAddress(GlobalMintAddress)
205+
if err != nil {
206+
log.WithFields(log.Fields{
207+
"error": err,
208+
}).Info("error getting mint address")
209+
return err
210+
}
211+
212+
// Get all balances for the address
213+
balances, err := d.Pegnet.SelectBalances(&FAGlobalMintAddress)
214+
if err != nil {
215+
fLog.WithFields(log.Fields{
216+
"err": err,
217+
}).Info("zeroing burn | balances retrieval failed")
218+
}
219+
220+
for _, tokenSupply := range MintTotalSupplyMap {
221+
// Substract from every issuance
222+
ticker := tokenSupply.Ticker
223+
value, _ := balances[ticker]
224+
_, _, err := d.Pegnet.SubFromBalance(tx, &FAGlobalMintAddress, ticker, value) // lastInd, txErr, err
225+
if err != nil {
226+
fLog.WithFields(log.Fields{
227+
"ticker": ticker,
228+
"balance": value,
229+
}).Info("zeroing burn | substract from balance failed")
230+
return err
231+
}
232+
}
233+
return nil
234+
}
235+
175236
func (d *Pegnetd) NullifyBurnAddress(ctx context.Context, tx *sql.Tx, height uint32) error {
176237
fLog := log.WithFields(log.Fields{"height": height})
177238

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

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

342+
if height == V204EnhanceActivation {
343+
if err := d.MintTokensForBalance(ctx, tx, d.Sync.Synced+1); err != nil {
344+
return err
345+
}
346+
}
347+
348+
if height == V204BurnMintedTokenActivation {
349+
if err := d.NullifyMintedTokens(ctx, tx, d.Sync.Synced+1); err != nil {
350+
return err
351+
}
352+
}
353+
281354
dblock := new(factom.DBlock)
282355
dblock.Height = height
283356
if err := dblock.Get(nil, d.FactomClient); err != nil {
@@ -1404,4 +1477,4 @@ func (d *Pegnetd) GetAssetRatesV0(oprWinners []opr.AssetUint, sprWinners []opr.A
14041477
return filteredRates, nil
14051478
}
14061479
return nil, fmt.Errorf("no winners")
1407-
}
1480+
}

0 commit comments

Comments
 (0)