-
Notifications
You must be signed in to change notification settings - Fork 12
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
[Supplier] Implement supplier revenue share #729
Changes from 57 commits
a18ba42
676c2c4
14ea326
bae1f00
b44e07b
5f5e98b
473e042
3d01f53
2d064fd
0699a35
85e6b81
bb84ab1
498fc26
853724a
6d7151e
20b26e7
b33a013
b02af2f
7b3555a
604224d
540f5db
ac07b43
79e4c39
473e047
088e675
d8e2c70
428104b
ef62442
365ee96
d096d02
20e8ed5
b543120
fdfd9b9
4843c21
095571a
611f583
3a7c0ba
e34634b
910c85b
e092a4e
b3ac63c
1f26789
0a43775
85d84ec
7f0dcda
3bb9d22
29ba54a
391b6db
98b0446
7b78f49
e3cc89e
8034c26
9530a64
a94fa5e
d204355
d869db8
2fe7526
3a7816f
8e1df74
7dd64eb
27366fd
7a25e34
f72e9bc
905f650
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,9 +3,15 @@ | |||||||||||||
import ( | ||||||||||||||
"fmt" | ||||||||||||||
|
||||||||||||||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||||||||||||
|
||||||||||||||
sharedtypes "github.com/pokt-network/poktroll/x/shared/types" | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
const ( | ||||||||||||||
requiredRevSharePercentageSum = 100 | ||||||||||||||
) | ||||||||||||||
|
||||||||||||||
// ValidateAppServiceConfigs returns an error if any of the application service configs are invalid | ||||||||||||||
func ValidateAppServiceConfigs(services []*sharedtypes.ApplicationServiceConfig) error { | ||||||||||||||
if len(services) == 0 { | ||||||||||||||
|
@@ -78,6 +84,60 @@ | |||||||||||||
// return fmt.Errorf("endpoint.Configs must have at least one entry: %v", serviceConfig) | ||||||||||||||
// } | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if err := ValidateServiceRevShare(serviceConfig.RevShare); err != nil { | ||||||||||||||
return err | ||||||||||||||
} | ||||||||||||||
Comment on lines
+88
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Improve error message clarity in Consider providing more context in the error message returned by - return err
+ return fmt.Errorf("invalid revenue share configuration for service %v: %w", serviceConfig.Service, err) Committable suggestion
Suggested change
|
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return nil | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// ValidateServiceRevShare validates the supplier's service revenue share, | ||||||||||||||
// ensuring that the sum of the revenue share percentages is 100. | ||||||||||||||
// This function is unit tested via the supplier staking config tests. | ||||||||||||||
red-0ne marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
func ValidateServiceRevShare(revShareList []*sharedtypes.ServiceRevShare) error { | ||||||||||||||
Olshansk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
revSharePercentageSum := float32(0) | ||||||||||||||
|
||||||||||||||
if revShareList == nil || len(revShareList) == 0 { | ||||||||||||||
red-0ne marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||
return sharedtypes.ErrSharedInvalidRevShare.Wrap("no rev share configurations") | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
for _, revShare := range revShareList { | ||||||||||||||
if revShare == nil { | ||||||||||||||
return sharedtypes.ErrSharedInvalidRevShare.Wrap("rev share cannot be nil") | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if len(revShare.Address) == 0 { | ||||||||||||||
return sharedtypes.ErrSharedInvalidRevShare.Wrap("rev share address cannot be empty") | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
// Validate the revshare address | ||||||||||||||
if revShare.Address == "" { | ||||||||||||||
return sharedtypes.ErrSharedInvalidRevShare.Wrapf("rev share address cannot be empty: %v", revShare) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if _, err := sdk.AccAddressFromBech32(revShare.Address); err != nil { | ||||||||||||||
return sharedtypes.ErrSharedInvalidRevShare.Wrapf("invalid rev share address %s; (%v)", revShare.Address, err) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if revShare.RevSharePercentage <= 0 || revShare.RevSharePercentage > 100 { | ||||||||||||||
return sharedtypes.ErrSharedInvalidRevShare.Wrapf( | ||||||||||||||
"invalid rev share value %v; must be between 0 and 100", | ||||||||||||||
revShare.RevSharePercentage, | ||||||||||||||
) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
revSharePercentageSum += revShare.RevSharePercentage | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if revSharePercentageSum != requiredRevSharePercentageSum { | ||||||||||||||
return sharedtypes.ErrSharedInvalidRevShare.Wrapf( | ||||||||||||||
"invalid rev share percentage sum %v; must be equal to %v", | ||||||||||||||
revSharePercentageSum, | ||||||||||||||
requiredRevSharePercentageSum, | ||||||||||||||
) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
return nil | ||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO_IN_THIS_PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added rev share specific usage of the owner_address, other content will be available once #720 is merged.