Skip to content

Commit

Permalink
Merge pull request #99 from iotaledger/feat/add-mana-payout
Browse files Browse the repository at this point in the history
Add mana payouts
  • Loading branch information
muXxer authored Oct 24, 2023
2 parents fb93426 + cbe3995 commit a208dd3
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 91 deletions.
2 changes: 1 addition & 1 deletion components/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
Name = "inx-faucet"

// Version of the app.
Version = "2.0.0-alpha.4"
Version = "2.0.0-alpha.5"
)

func App() *app.App {
Expand Down
14 changes: 10 additions & 4 deletions components/faucet/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,10 @@ func provide(c *dig.Container) error {
return unlockableBalance, nil
}

getLatestSlot := func() iotago.SlotIndex {
return iotago.SlotIndex(deps.NodeBridge.NodeStatus().LastAcceptedBlockSlot)
}

submitTransactionPayload := func(ctx context.Context, builder *builder.TransactionBuilder, signer iotago.AddressSigner, storedManaOutputIndex int, numPoWWorkers ...int) (iotago.BlockPayload, iotago.BlockID, error) {
Component.LogDebug("sending transaction payload...")
signedTx, blockCreatedResponse, err := deps.BlockIssuerClient.SendPayloadWithTransactionBuilder(ctx, builder, signer, storedManaOutputIndex, numPoWWorkers...)
Expand All @@ -269,16 +273,18 @@ func provide(c *dig.Container) error {
fetchTransactionMetadata,
collectUnlockableFaucetOutputs,
computeUnlockableAddressBalance,
getLatestSlot,
submitTransactionPayload,
deps.NodeBridge.APIProvider(),
faucetAddressRestricted,
faucetSigner,
faucet.WithLogger(Component.Logger()),
faucet.WithTokenName(deps.NodeBridge.NodeConfig.BaseToken.Name),
faucet.WithAmount(iotago.BaseToken(ParamsFaucet.Amount)),
faucet.WithSmallAmount(iotago.BaseToken(ParamsFaucet.SmallAmount)),
faucet.WithMaxAddressBalance(iotago.BaseToken(ParamsFaucet.MaxAddressBalance)),
faucet.WithMaxOutputCount(ParamsFaucet.MaxOutputCount),
faucet.WithBaseTokenAmount(iotago.BaseToken(ParamsFaucet.BaseTokenAmount)),
faucet.WithBaseTokenAmountSmall(iotago.BaseToken(ParamsFaucet.BaseTokenAmountSmall)),
faucet.WithBaseTokenAmountMaxTarget(iotago.BaseToken(ParamsFaucet.BaseTokenAmountMaxTarget)),
faucet.WithManaAmount(iotago.Mana(ParamsFaucet.ManaAmount)),
faucet.WithManaAmountMinFaucet(iotago.Mana(ParamsFaucet.ManaAmountMinFaucet)),
faucet.WithTagMessage(ParamsFaucet.TagMessage),
faucet.WithBatchTimeout(ParamsFaucet.BatchTimeout),
faucet.WithPoWWorkerCount(ParamsFaucet.PoW.WorkerCount),
Expand Down
22 changes: 10 additions & 12 deletions components/faucet/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import (
"time"

"github.com/iotaledger/hive.go/app"
iotago "github.com/iotaledger/iota.go/v4"
)

type ParametersFaucet struct {
Amount uint64 `default:"1000000000" usage:"the amount of funds the requester receives"`
SmallAmount uint64 `default:"100000000" usage:"the amount of funds the requester receives if the target address has more funds than the faucet amount and less than maximum"`
MaxAddressBalance uint64 `default:"2000000000" usage:"the maximum allowed amount of funds on the target address"`
MaxOutputCount int `usage:"the maximum output count per faucet message"`
TagMessage string `default:"FAUCET" usage:"the faucet transaction tag payload"`
BatchTimeout time.Duration `default:"2s" usage:"the maximum duration for collecting faucet batches"`
BindAddress string `default:"localhost:8091" usage:"the bind address on which the faucet website can be accessed from"`
RateLimit struct {
BaseTokenAmount uint64 `default:"1000000000" usage:"the amount of funds the requester receives"`
BaseTokenAmountSmall uint64 `default:"100000000" usage:"the amount of funds the requester receives if the target address has more funds than the faucet amount and less than maximum"`
BaseTokenAmountMaxTarget uint64 `default:"5000000000" usage:"the maximum allowed amount of funds on the target address"`
ManaAmount uint64 `default:"1000" usage:"the amount of mana the requester receives"`
ManaAmountMinFaucet uint64 `default:"1000000" usage:"the minimum amount of mana the faucet needs to hold before mana payouts become active"`
TagMessage string `default:"FAUCET" usage:"the faucet transaction tag payload"`
BatchTimeout time.Duration `default:"2s" usage:"the maximum duration for collecting faucet batches"`
BindAddress string `default:"localhost:8091" usage:"the bind address on which the faucet website can be accessed from"`
RateLimit struct {
Enabled bool `default:"true" usage:"whether the rate limiting should be enabled"`
Period time.Duration `default:"5m" usage:"the period for rate limiting"`
MaxRequests int `default:"10" usage:"the maximum number of requests per period"`
Expand All @@ -29,9 +29,7 @@ type ParametersFaucet struct {
DebugRequestLoggerEnabled bool `default:"false" usage:"whether the debug logging for requests should be enabled"`
}

var ParamsFaucet = &ParametersFaucet{
MaxOutputCount: iotago.MaxOutputsCount,
}
var ParamsFaucet = &ParametersFaucet{}

var params = &app.ComponentParams{
Params: map[string]any{
Expand Down
9 changes: 5 additions & 4 deletions config_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
"targetNetworkName": ""
},
"faucet": {
"amount": 1000000000,
"smallAmount": 100000000,
"maxAddressBalance": 2000000000,
"maxOutputCount": 128,
"baseTokenAmount": 1000000000,
"baseTokenAmountSmall": 100000000,
"baseTokenAmountMaxTarget": 5000000000,
"manaAmount": 1000,
"manaAmountMinFaucet": 1000000,
"tagMessage": "FAUCET",
"batchTimeout": "2s",
"bindAddress": "localhost:8091",
Expand Down
18 changes: 10 additions & 8 deletions configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ Example:

| Name | Description | Type | Default value |
| ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------- | ------- | ---------------- |
| amount | The amount of funds the requester receives | uint | 1000000000 |
| smallAmount | The amount of funds the requester receives if the target address has more funds than the faucet amount and less than maximum | uint | 100000000 |
| maxAddressBalance | The maximum allowed amount of funds on the target address | uint | 2000000000 |
| maxOutputCount | The maximum output count per faucet message | int | 128 |
| baseTokenAmount | The amount of funds the requester receives | uint | 1000000000 |
| baseTokenAmountSmall | The amount of funds the requester receives if the target address has more funds than the faucet amount and less than maximum | uint | 100000000 |
| baseTokenAmountMaxTarget | The maximum allowed amount of funds on the target address | uint | 5000000000 |
| manaAmount | The amount of mana the requester receives | uint | 1000 |
| manaAmountMinFaucet | The minimum amount of mana the faucet needs to hold before mana payouts become active | uint | 1000000 |
| tagMessage | The faucet transaction tag payload | string | "FAUCET" |
| batchTimeout | The maximum duration for collecting faucet batches | string | "2s" |
| bindAddress | The bind address on which the faucet website can be accessed from | string | "localhost:8091" |
Expand Down Expand Up @@ -163,10 +164,11 @@ Example:
```json
{
"faucet": {
"amount": 1000000000,
"smallAmount": 100000000,
"maxAddressBalance": 2000000000,
"maxOutputCount": 128,
"baseTokenAmount": 1000000000,
"baseTokenAmountSmall": 100000000,
"baseTokenAmountMaxTarget": 5000000000,
"manaAmount": 1000,
"manaAmountMinFaucet": 1000000,
"tagMessage": "FAUCET",
"batchTimeout": "2s",
"bindAddress": "localhost:8091",
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
github.com/iotaledger/hive.go/app v0.0.0-20231020115340-13da292c580b
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231020115340-13da292c580b
github.com/iotaledger/hive.go/crypto v0.0.0-20231020115340-13da292c580b
github.com/iotaledger/hive.go/ds v0.0.0-20231020115340-13da292c580b
github.com/iotaledger/hive.go/ierrors v0.0.0-20231020115340-13da292c580b
Expand All @@ -12,7 +13,7 @@ require (
github.com/iotaledger/hive.go/runtime v0.0.0-20231020115340-13da292c580b
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023191159-38919c4705e0
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231023190837-6e7b2cdfd4fd
github.com/iotaledger/iota.go/v4 v4.0.0-20231023205010-58a0b5c7fe6d
github.com/iotaledger/iota.go/v4 v4.0.0-20231024164621-0979b0d351d5
github.com/labstack/echo/v4 v4.11.2
go.uber.org/dig v1.17.1
golang.org/x/time v0.3.0
Expand Down Expand Up @@ -43,7 +44,6 @@ require (
github.com/holiman/uint256 v1.2.3 // indirect
github.com/iancoleman/orderedmap v0.3.0 // indirect
github.com/iotaledger/hive.go/constraints v0.0.0-20231020115340-13da292c580b // indirect
github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231020115340-13da292c580b // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-rc.1.0.20231020115340-13da292c580b // indirect
github.com/iotaledger/hive.go/stringify v0.0.0-20231020115340-13da292c580b // indirect
github.com/knadh/koanf v1.5.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023191159-38919c4705e0 h1:/8pbF
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231023191159-38919c4705e0/go.mod h1:My1SB4vZj42EgTDNJ/dgW8lUpLNmvtzu8f89J5y2kP0=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231023190837-6e7b2cdfd4fd h1:hh5mAnnaZHOYAi4CIqR9K/mv786ex9AQgpisbJ4ZMow=
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231023190837-6e7b2cdfd4fd/go.mod h1:MK0SHfNicBmcaZb3qS3tA8NEJIWKNbcNtNNKuSDKqXY=
github.com/iotaledger/iota.go/v4 v4.0.0-20231023205010-58a0b5c7fe6d h1:vGfZmcCCloTzim6TysS3fXxc9xsTfXoVB6bsedZgp7A=
github.com/iotaledger/iota.go/v4 v4.0.0-20231023205010-58a0b5c7fe6d/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/iotaledger/iota.go/v4 v4.0.0-20231024164621-0979b0d351d5 h1:KowbaCoCa9frRjn1JSNlWdp2TVmFcdrEVRvCyMce4Ig=
github.com/iotaledger/iota.go/v4 v4.0.0-20231024164621-0979b0d351d5/go.mod h1:jqbLYq4a/FwuiPBqFfkAwwxU8vs3+kReRq2/tyX5qRA=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
Expand Down
Loading

0 comments on commit a208dd3

Please sign in to comment.