Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't generate Mana from storage deposit #469

Merged
merged 6 commits into from
Aug 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions builder/output_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
iotago "github.com/iotaledger/iota.go/v4"
)

// NewBasicOutputBuilder creates a new BasicOutputBuilder with the required target address and deposit amount.
func NewBasicOutputBuilder(targetAddr iotago.Address, deposit iotago.BaseToken) *BasicOutputBuilder {
// NewBasicOutputBuilder creates a new BasicOutputBuilder with the required target address and base token amount.
func NewBasicOutputBuilder(targetAddr iotago.Address, amount iotago.BaseToken) *BasicOutputBuilder {
return &BasicOutputBuilder{output: &iotago.BasicOutput{
Amount: deposit,
Amount: amount,
NativeTokens: iotago.NativeTokens{},
Conditions: iotago.BasicOutputUnlockConditions{
&iotago.AddressUnlockCondition{Address: targetAddr},
Expand All @@ -32,9 +32,9 @@ type BasicOutputBuilder struct {
output *iotago.BasicOutput
}

// Deposit sets the deposit of the output.
func (builder *BasicOutputBuilder) Deposit(deposit iotago.BaseToken) *BasicOutputBuilder {
builder.output.Amount = deposit
// Amount sets the base token amount of the output.
func (builder *BasicOutputBuilder) Amount(amount iotago.BaseToken) *BasicOutputBuilder {
builder.output.Amount = amount

return builder
}
Expand Down Expand Up @@ -121,10 +121,10 @@ func (builder *BasicOutputBuilder) Build() (*iotago.BasicOutput, error) {
return builder.output, nil
}

// NewAccountOutputBuilder creates a new AccountOutputBuilder with the required state controller/governor addresses and deposit amount.
func NewAccountOutputBuilder(stateCtrl iotago.Address, govAddr iotago.Address, deposit iotago.BaseToken) *AccountOutputBuilder {
// NewAccountOutputBuilder creates a new AccountOutputBuilder with the required state controller/governor addresses and base token amount.
func NewAccountOutputBuilder(stateCtrl iotago.Address, govAddr iotago.Address, amount iotago.BaseToken) *AccountOutputBuilder {
return &AccountOutputBuilder{output: &iotago.AccountOutput{
Amount: deposit,
Amount: amount,
NativeTokens: iotago.NativeTokens{},
Conditions: iotago.AccountOutputUnlockConditions{
&iotago.StateControllerAddressUnlockCondition{Address: stateCtrl},
Expand Down Expand Up @@ -152,9 +152,9 @@ type AccountOutputBuilder struct {
govCtrlReq bool
}

// Deposit sets the deposit of the output.
func (builder *AccountOutputBuilder) Deposit(deposit iotago.BaseToken) *AccountOutputBuilder {
builder.output.Amount = deposit
// Amount sets the base token amount of the output.
func (builder *AccountOutputBuilder) Amount(amount iotago.BaseToken) *AccountOutputBuilder {
builder.output.Amount = amount
builder.stateCtrlReq = true

return builder
Expand Down Expand Up @@ -324,9 +324,9 @@ func (builder *AccountOutputBuilder) StateTransition() *accountStateTransition {
return &accountStateTransition{builder: builder}
}

// Deposit sets the deposit of the output.
func (trans *accountStateTransition) Deposit(deposit iotago.BaseToken) *accountStateTransition {
return trans.builder.Deposit(deposit).StateTransition()
// Amount sets the base token amount of the output.
func (trans *accountStateTransition) Amount(amount iotago.BaseToken) *accountStateTransition {
return trans.builder.Amount(amount).StateTransition()
}

// StateMetadata sets the state metadata of the output.
Expand Down Expand Up @@ -540,10 +540,10 @@ func (trans *stakingTransition) Builder() *AccountOutputBuilder {
return trans.builder
}

// NewFoundryOutputBuilder creates a new FoundryOutputBuilder with the account address, serial number, token scheme and deposit amount.
func NewFoundryOutputBuilder(accountAddr *iotago.AccountAddress, tokenScheme iotago.TokenScheme, deposit iotago.BaseToken) *FoundryOutputBuilder {
// NewFoundryOutputBuilder creates a new FoundryOutputBuilder with the account address, serial number, token scheme and base token amount.
func NewFoundryOutputBuilder(accountAddr *iotago.AccountAddress, tokenScheme iotago.TokenScheme, amount iotago.BaseToken) *FoundryOutputBuilder {
return &FoundryOutputBuilder{output: &iotago.FoundryOutput{
Amount: deposit,
Amount: amount,
TokenScheme: tokenScheme,
NativeTokens: iotago.NativeTokens{},
Conditions: iotago.FoundryOutputUnlockConditions{
Expand All @@ -569,9 +569,9 @@ type FoundryOutputBuilder struct {
output *iotago.FoundryOutput
}

// Deposit sets the deposit of the output.
func (builder *FoundryOutputBuilder) Deposit(deposit iotago.BaseToken) *FoundryOutputBuilder {
builder.output.Amount = deposit
// Amount sets the base token amount of the output.
func (builder *FoundryOutputBuilder) Amount(amount iotago.BaseToken) *FoundryOutputBuilder {
builder.output.Amount = amount

return builder
}
Expand Down Expand Up @@ -632,10 +632,10 @@ func (builder *FoundryOutputBuilder) Build() (*iotago.FoundryOutput, error) {
return builder.output, nil
}

// NewNFTOutputBuilder creates a new NFTOutputBuilder with the address and deposit amount.
func NewNFTOutputBuilder(targetAddr iotago.Address, deposit iotago.BaseToken) *NFTOutputBuilder {
// NewNFTOutputBuilder creates a new NFTOutputBuilder with the address and base token amount.
func NewNFTOutputBuilder(targetAddr iotago.Address, amount iotago.BaseToken) *NFTOutputBuilder {
return &NFTOutputBuilder{output: &iotago.NFTOutput{
Amount: deposit,
Amount: amount,
NativeTokens: iotago.NativeTokens{},
Conditions: iotago.NFTOutputUnlockConditions{
&iotago.AddressUnlockCondition{Address: targetAddr},
Expand All @@ -660,9 +660,9 @@ type NFTOutputBuilder struct {
output *iotago.NFTOutput
}

// Deposit sets the deposit of the output.
func (builder *NFTOutputBuilder) Deposit(deposit iotago.BaseToken) *NFTOutputBuilder {
builder.output.Amount = deposit
// Amount sets the base token amount of the output.
func (builder *NFTOutputBuilder) Amount(amount iotago.BaseToken) *NFTOutputBuilder {
builder.output.Amount = amount

return builder
}
Expand Down Expand Up @@ -780,10 +780,10 @@ func (builder *NFTOutputBuilder) Build() (*iotago.NFTOutput, error) {
return builder.output, nil
}

// NewDelegationOutputBuilder creates a new DelegationOutputBuilder with the account address, serial number, token scheme and deposit amount.
func NewDelegationOutputBuilder(validatorID iotago.AccountID, addr iotago.Address, deposit iotago.BaseToken) *DelegationOutputBuilder {
// NewDelegationOutputBuilder creates a new DelegationOutputBuilder with the account address, serial number, token scheme and base token amount.
func NewDelegationOutputBuilder(validatorID iotago.AccountID, addr iotago.Address, amount iotago.BaseToken) *DelegationOutputBuilder {
return &DelegationOutputBuilder{output: &iotago.DelegationOutput{
Amount: deposit,
Amount: amount,
DelegatedAmount: 0,
DelegationID: iotago.DelegationID{},
ValidatorID: validatorID,
Expand All @@ -808,9 +808,9 @@ type DelegationOutputBuilder struct {
output *iotago.DelegationOutput
}

// Deposit sets the deposit of the output.
func (builder *DelegationOutputBuilder) Deposit(deposit iotago.BaseToken) *DelegationOutputBuilder {
builder.output.Amount = deposit
// Amount sets the base token amount of the output.
func (builder *DelegationOutputBuilder) Amount(amount iotago.BaseToken) *DelegationOutputBuilder {
builder.output.Amount = amount

return builder
}
Expand Down
40 changes: 20 additions & 20 deletions builder/output_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func TestBasicOutputBuilder(t *testing.T) {
var (
targetAddr = tpkg.RandEd25519Address()
deposit iotago.BaseToken = 1337
amount iotago.BaseToken = 1337
nt = tpkg.RandNativeToken()
expirationTarget = tpkg.RandEd25519Address()
metadata = []byte("123456")
Expand All @@ -25,7 +25,7 @@ func TestBasicOutputBuilder(t *testing.T) {
timelock := slotTimeProvider.SlotFromTime(time.Now().Add(5 * time.Minute))
expiration := slotTimeProvider.SlotFromTime(time.Now().Add(10 * time.Minute))

basicOutput, err := builder.NewBasicOutputBuilder(targetAddr, deposit).
basicOutput, err := builder.NewBasicOutputBuilder(targetAddr, amount).
NativeToken(nt).
Timelock(timelock).
Expiration(expirationTarget, expiration).
Expand All @@ -51,7 +51,7 @@ func TestAccountOutputBuilder(t *testing.T) {
var (
stateCtrl = tpkg.RandEd25519Address()
gov = tpkg.RandEd25519Address()
deposit iotago.BaseToken = 1337
amount iotago.BaseToken = 1337
nt = tpkg.RandNativeToken()
metadata = []byte("123456")
immMetadata = []byte("654321")
Expand All @@ -64,11 +64,11 @@ func TestAccountOutputBuilder(t *testing.T) {
newBlockIssuerKey2 = tpkg.Rand32ByteArray()
)

accountOutput, err := builder.NewAccountOutputBuilder(stateCtrl, gov, deposit).
accountOutput, err := builder.NewAccountOutputBuilder(stateCtrl, gov, amount).
NativeToken(nt).
Metadata(metadata).
StateMetadata(metadata).
Staking(deposit, 1, 1000).
Staking(amount, 1, 1000).
BlockIssuer(iotago.BlockIssuerKeys{blockIssuerKey1, blockIssuerKey2, blockIssuerKey3}, 100000).
ImmutableMetadata(immMetadata).
ImmutableSender(immSender).
Expand Down Expand Up @@ -96,7 +96,7 @@ func TestAccountOutputBuilder(t *testing.T) {
ExpirySlot: 100000,
},
&iotago.StakingFeature{
StakedAmount: deposit,
StakedAmount: amount,
FixedCost: 1,
StartEpoch: 1000,
EndEpoch: math.MaxUint64,
Expand All @@ -109,13 +109,13 @@ func TestAccountOutputBuilder(t *testing.T) {
}
require.Equal(t, expected, accountOutput)

const newDeposit iotago.BaseToken = 7331
const newAmount iotago.BaseToken = 7331
//nolint:forcetypeassert // we can safely assume that this is an AccountOutput
expectedCpy := expected.Clone().(*iotago.AccountOutput)
expectedCpy.Amount = newDeposit
expectedCpy.Amount = newAmount
expectedCpy.StateIndex++
updatedOutput, err := builder.NewAccountOutputBuilderFromPrevious(accountOutput).StateTransition().
Deposit(newDeposit).Builder().Build()
Amount(newAmount).Builder().Build()
require.NoError(t, err)
require.Equal(t, expectedCpy, updatedOutput)

Expand Down Expand Up @@ -151,7 +151,7 @@ func TestAccountOutputBuilder(t *testing.T) {
ExpirySlot: 1500,
},
&iotago.StakingFeature{
StakedAmount: deposit,
StakedAmount: amount,
FixedCost: 1,
StartEpoch: 1000,
EndEpoch: 2000,
Expand All @@ -169,14 +169,14 @@ func TestDelegationOutputBuilder(t *testing.T) {
var (
address = tpkg.RandEd25519Address()
updatedAddress = tpkg.RandEd25519Address()
deposit iotago.BaseToken = 1337
updatedDeposit iotago.BaseToken = 127
amount iotago.BaseToken = 1337
updatedAmount iotago.BaseToken = 127
validatorID = tpkg.RandAccountID()
delegationID = tpkg.RandDelegationID()
)

delegationOutput, err := builder.NewDelegationOutputBuilder(validatorID, address, deposit).
DelegatedAmount(deposit).
delegationOutput, err := builder.NewDelegationOutputBuilder(validatorID, address, amount).
DelegatedAmount(amount).
StartEpoch(1000).
Build()
require.NoError(t, err)
Expand All @@ -196,8 +196,8 @@ func TestDelegationOutputBuilder(t *testing.T) {

updatedOutput, err := builder.NewDelegationOutputBuilderFromPrevious(delegationOutput).
DelegationID(delegationID).
DelegatedAmount(updatedDeposit).
Deposit(updatedDeposit).
DelegatedAmount(updatedAmount).
Amount(updatedAmount).
EndEpoch(1500).
Address(updatedAddress).
Build()
Expand All @@ -220,7 +220,7 @@ func TestDelegationOutputBuilder(t *testing.T) {
func TestFoundryOutputBuilder(t *testing.T) {
var (
accountAddr = tpkg.RandAccountAddress()
deposit iotago.BaseToken = 1337
amount iotago.BaseToken = 1337
tokenScheme = &iotago.SimpleTokenScheme{
MintedTokens: big.NewInt(0),
MeltedTokens: big.NewInt(0),
Expand All @@ -231,7 +231,7 @@ func TestFoundryOutputBuilder(t *testing.T) {
immMetadata = []byte("654321")
)

foundryOutput, err := builder.NewFoundryOutputBuilder(accountAddr, tokenScheme, deposit).
foundryOutput, err := builder.NewFoundryOutputBuilder(accountAddr, tokenScheme, amount).
NativeToken(nt).
Metadata(metadata).
ImmutableMetadata(immMetadata).
Expand All @@ -257,13 +257,13 @@ func TestFoundryOutputBuilder(t *testing.T) {
func TestNFTOutputBuilder(t *testing.T) {
var (
targetAddr = tpkg.RandAccountAddress()
deposit iotago.BaseToken = 1337
amount iotago.BaseToken = 1337
nt = tpkg.RandNativeToken()
metadata = []byte("123456")
immMetadata = []byte("654321")
)

nftOutput, err := builder.NewNFTOutputBuilder(targetAddr, deposit).
nftOutput, err := builder.NewNFTOutputBuilder(targetAddr, amount).
NativeToken(nt).
Metadata(metadata).
ImmutableMetadata(immMetadata).
Expand Down
14 changes: 7 additions & 7 deletions mana_decay_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (p *ManaDecayProvider) StoredManaWithDecay(storedMana Mana, slotIndexCreate
}

// PotentialManaWithDecay calculates the generated potential mana and applies the decay to the result.
func (p *ManaDecayProvider) PotentialManaWithDecay(deposit BaseToken, slotIndexCreated SlotIndex, slotIndexTarget SlotIndex) (Mana, error) {
func (p *ManaDecayProvider) PotentialManaWithDecay(amount BaseToken, slotIndexCreated SlotIndex, slotIndexTarget SlotIndex) (Mana, error) {
epochIndexCreated := p.timeProvider.EpochFromSlot(slotIndexCreated)
epochIndexTarget := p.timeProvider.EpochFromSlot(slotIndexTarget)

Expand All @@ -165,24 +165,24 @@ func (p *ManaDecayProvider) PotentialManaWithDecay(deposit BaseToken, slotIndexC
epochIndexDiff := epochIndexTarget - epochIndexCreated
switch epochIndexDiff {
case 0:
return p.generateMana(deposit, slotIndexTarget-slotIndexCreated), nil
return p.generateMana(amount, slotIndexTarget-slotIndexCreated), nil

case 1:
manaDecayed := p.decay(p.generateMana(deposit, p.timeProvider.SlotsBeforeNextEpoch(slotIndexCreated)), 1)
manaGenerated := p.generateMana(deposit, p.timeProvider.SlotsSinceEpochStart(slotIndexTarget))
manaDecayed := p.decay(p.generateMana(amount, p.timeProvider.SlotsBeforeNextEpoch(slotIndexCreated)), 1)
manaGenerated := p.generateMana(amount, p.timeProvider.SlotsSinceEpochStart(slotIndexTarget))
return safemath.SafeAdd(manaDecayed, manaGenerated)

default:
c := Mana(fixedPointMultiplication32(uint64(deposit), p.decayFactorEpochsSum, p.decayFactorEpochsSumExponent+p.generationRateExponent-p.slotsPerEpochExponent))
c := Mana(fixedPointMultiplication32(uint64(amount), p.decayFactorEpochsSum, p.decayFactorEpochsSumExponent+p.generationRateExponent-p.slotsPerEpochExponent))

//nolint:golint,revive,nosnakecase,stylecheck // taken from the formula, lets keep it that way
potentialMana_n := p.decay(p.generateMana(deposit, p.timeProvider.SlotsBeforeNextEpoch(slotIndexCreated)), epochIndexDiff)
potentialMana_n := p.decay(p.generateMana(amount, p.timeProvider.SlotsBeforeNextEpoch(slotIndexCreated)), epochIndexDiff)

//nolint:golint,revive,nosnakecase,stylecheck // taken from the formula, lets keep it that way
potentialMana_n_1 := p.decay(c, epochIndexDiff-1)

//nolint:golint,revive,nosnakecase,stylecheck // taken from the formula, lets keep it that way
potentialMana_0, err := safemath.SafeAdd(c, p.generateMana(deposit, p.timeProvider.SlotsSinceEpochStart(slotIndexTarget)))
potentialMana_0, err := safemath.SafeAdd(c, p.generateMana(amount, p.timeProvider.SlotsSinceEpochStart(slotIndexTarget)))
if err != nil {
return 0, err
}
Expand Down
Loading