Skip to content
This repository has been archived by the owner on Mar 5, 2020. It is now read-only.

Commit

Permalink
Stake more properly, and float 10 EOS my friend..
Browse files Browse the repository at this point in the history
Into a single operation.
  • Loading branch information
abourget committed Jun 2, 2018
1 parent 1a1bfc8 commit 8af4ad8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 61 deletions.
73 changes: 18 additions & 55 deletions bios/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ var operationsRegistry = map[string]Operation{
"producers.enrich": &OpEnrichProducers{},
"system.setprods": &OpSetProds{},
"snapshot.create_accounts": &OpSnapshotCreateAccounts{},
"snapshot.transfer": &OpSnapshotTransfer{},
"snapshot.load_unregistered": &OpInjectUnregdSnapshot{},
"system.resign_accounts": &OpResignAccounts{},
"system.create_voters": &OpCreateVoters{},
Expand Down Expand Up @@ -237,11 +236,19 @@ func (op *OpIssueToken) Actions(b *BIOS) (out []*eos.Action, err error) {

//

type OpCreateProducers struct{}
type OpCreateProducers struct {
IsMainnet bool
}

func (op *OpCreateProducers) ResetTestnetOptions() {}
func (op *OpCreateProducers) ResetTestnetOptions() {
op.IsMainnet = true
}

func (op *OpCreateProducers) Actions(b *BIOS) (out []*eos.Action, err error) {
if op.IsMainnet {
return
}

for _, prod := range b.ShuffledProducers {
prodName := prod.Discovery.TargetAccountName
if prodName == AN("eosio") {
Expand Down Expand Up @@ -373,18 +380,21 @@ func (op *OpSnapshotCreateAccounts) Actions(b *BIOS) (out []*eos.Action, err err
out = append(out, system.NewNewAccount(AN("eosio"), destAccount, destPubKey))
}

cpuStake, netStake := splitSnapshotStakes(hodler.Balance)
cpuStake, netStake, rest := splitSnapshotStakes(hodler.Balance)

// special case `transfer` for `b1` ?
out = append(out, system.NewDelegateBW(AN("eosio"), destAccount, cpuStake, netStake, false))
out = append(out, system.NewDelegateBW(AN("eosio"), destAccount, cpuStake, netStake, true))
out = append(out, system.NewBuyRAMBytes(AN("eosio"), destAccount, uint32(op.BuyRAM)))
out = append(out, nil) // end transaction

memo := "Welcome " + hodler.EthereumAddress[len(hodler.EthereumAddress)-6:]
out = append(out, token.NewTransfer(AN("eosio"), destAccount, rest, memo), nil)
}

return
}

func splitSnapshotStakes(balance eos.Asset) (cpu, net eos.Asset) {
func splitSnapshotStakes(balance eos.Asset) (cpu, net, xfer eos.Asset) {
if balance.Amount < 5000 {
return
}
Expand All @@ -399,7 +409,7 @@ func splitSnapshotStakes(balance eos.Asset) (cpu, net eos.Asset) {
remainder := eos.NewEOSAsset(balance.Amount - cpu.Amount - net.Amount)

if remainder.Amount <= 100000 /* 10.0 EOS */ {
return
return cpu, net, remainder
}

remainder.Amount -= 100000 // keep them floating, unstaked
Expand All @@ -408,54 +418,7 @@ func splitSnapshotStakes(balance eos.Asset) (cpu, net eos.Asset) {
cpu.Amount += firstHalf
net.Amount += remainder.Amount - firstHalf

return
}

//

type OpSnapshotTransfer struct {
TestnetTruncateSnapshot int `json:"TESTNET_TRUNCATE_SNAPSHOT"`
}

func (op *OpSnapshotTransfer) ResetTestnetOptions() {
op.TestnetTruncateSnapshot = 0
}

func (op *OpSnapshotTransfer) Actions(b *BIOS) (out []*eos.Action, err error) {
snapshotFile, err := b.GetContentsCacheRef("snapshot.csv")
if err != nil {
return nil, err
}

rawSnapshot, err := b.Network.ReadFromCache(snapshotFile)
if err != nil {
return nil, fmt.Errorf("reading snapshot file: %s", err)
}

snapshotData, err := NewSnapshot(rawSnapshot)
if err != nil {
return nil, fmt.Errorf("loading snapshot csv: %s", err)
}

if len(snapshotData) == 0 {
return nil, fmt.Errorf("snapshot is empty or not loaded")
}

for idx, hodler := range snapshotData {
if trunc := op.TestnetTruncateSnapshot; trunc != 0 {
if idx == trunc {
b.Log.Debugf("- DEBUG: truncated snapshot to %d rows\n", trunc)
break
}
}

destAccount := AN(hodler.AccountName)

memo := "Welcome " + hodler.EthereumAddress[len(hodler.EthereumAddress)-6:]
out = append(out, token.NewTransfer(AN("eosio"), destAccount, hodler.Balance, memo), nil)
}

return
return cpu, net, eos.NewEOSAsset(100000)
}

//
Expand Down
10 changes: 9 additions & 1 deletion bios/ops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,50 @@ func TestSnapshotDelegationAmounts(t *testing.T) {
balance eos.Asset
cpuStake eos.Asset
netStake eos.Asset
xfer eos.Asset
}{
{
eos.NewEOSAsset(10000), // 1.0 EOS
eos.NewEOSAsset(2500),
eos.NewEOSAsset(2500),
eos.NewEOSAsset(5000), // 0.5 EOS
},
{
eos.NewEOSAsset(100000), // 10.0 EOS
eos.NewEOSAsset(2500), // 0.25 EOS
eos.NewEOSAsset(2500), // 0.25 EOS
eos.NewEOSAsset(95000), // 9.5 EOS
},
{
eos.NewEOSAsset(105000), // 10.5 EOS
eos.NewEOSAsset(2500), // 0.25 EOS
eos.NewEOSAsset(2500), // 0.25 EOS
eos.NewEOSAsset(100000), // 10.0 EOS
},
{
eos.NewEOSAsset(107000), // 10.7 EOS
eos.NewEOSAsset(3500), // 0.35 EOS
eos.NewEOSAsset(3500), // 0.35 EOS
eos.NewEOSAsset(100000), // 10.0 EOS
},
{
eos.NewEOSAsset(120000), // 12.0 EOS
eos.NewEOSAsset(10000), // 0.25 + 0.75 EOS
eos.NewEOSAsset(10000), // 0.25 + 0.75 EOS
eos.NewEOSAsset(100000), // 10.0 EOS
},
{
eos.NewEOSAsset(99990000), // 9999.0 EOS
eos.NewEOSAsset(49945000), // 4994.5 EOS
eos.NewEOSAsset(49945000), // 4994.5 EOS, 10.0 EOS remaining :) yessir!
eos.NewEOSAsset(100000), // 10.0 EOS
},
}

for idx, test := range tests {
cpuStake, netStake := splitSnapshotStakes(test.balance)
cpuStake, netStake, xfer := splitSnapshotStakes(test.balance)
assert.Equal(t, test.cpuStake, cpuStake, fmt.Sprintf("idx=%d", idx))
assert.Equal(t, test.netStake, netStake, fmt.Sprintf("idx=%d", idx))
assert.Equal(t, test.xfer, xfer, fmt.Sprintf("idx=%d", idx))
}
}
5 changes: 0 additions & 5 deletions files/boot_sequence.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,6 @@ boot_sequence:
buy_ram_bytes: 8192
TESTNET_TRUNCATE_SNAPSHOT: 1000

- op: snapshot.transfer
label: Injecting ERC-20 snapshot balances
data:
TESTNET_TRUNCATE_SNAPSHOT: 1000

- op: snapshot.load_unregistered
label: Saving unregistered addresses in eosio.unregd account, for the future.
data:
Expand Down

0 comments on commit 8af4ad8

Please sign in to comment.