-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat: add distribute revenue pools #318
Conversation
I haven't created a function that distributes revenue to Curator yet. |
} | ||
|
||
return &shareToken, nil | ||
k.addSalesHistory(ctx, pool.PoolId, pool.Round, seller, cert.UnsignedCert.DataHash) |
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.
If the seller sold the data, it store the sales history.
x/datapool/keeper/pool.go
Outdated
} | ||
|
||
k.SetDataValidationCertificate(ctx, cert) | ||
|
||
k.increaseCurNumAndUpdatePool(ctx, pool) | ||
|
||
shareToken := types.GetAccumPoolShareToken(pool.PoolId, 1) | ||
err = k.bankKeeper.SendCoinsFromModuleToAccount(ctx, types.ModuleName, seller, sdk.NewCoins(shareToken)) | ||
err = k.addInstantRevenueDistribute(ctx, poolID) |
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.
When a seller sells data, it performs a revenue distribution function.
x/datapool/keeper/pool.go
Outdated
@@ -545,6 +520,11 @@ func (k Keeper) BuyDataPass(ctx sdk.Context, buyer sdk.AccAddress, poolID, round | |||
|
|||
k.increaseNumIssuedNFT(ctx, pool) | |||
|
|||
err = k.addInstantRevenueDistribute(ctx, poolID) |
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.
When a Buyer purchases a DataPass, a revenue distribution function is performed.
x/datapool/keeper/pool_distribute.go
Outdated
func (k Keeper) SetSalesHistory(ctx sdk.Context, poolID, round uint64, salesHistory *types.SalesHistory) { | ||
key := types.GetKeyPrefixSalesHistory( | ||
poolID, | ||
round, | ||
) | ||
store := ctx.KVStore(k.storeKey) | ||
store.Set(key, k.cdc.MustMarshalBinaryLengthPrefixed(salesHistory)) | ||
} |
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.
The sales information history is stored in the form of an array. The reason is to distribute revenue in the order in which they are sold.
If you store sales information one by one, they are sorted by key and the order is changed.
For example,
- PoolID: 1
- Round: 1
- Address :
- panacea1a
- panacea1b
- panacea1c
- panacea1d
This is the case where 4 sellers are selling data. (The number on the left is the input order.)
- 1/1/panacea1b
- 1/1/panacea1d
- 1/1/panacea1c
- 1/1/panacea1a
If you search in kvStore, it is searched in the following order.
- 1/1/panacea1a
- 1/1/panacea1b
- 1/1/panacea1c
- 1/1/panacea1d
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.
If there is another good way, please let me know.
x/datapool/keeper/pool_distribute.go
Outdated
return nil | ||
} | ||
|
||
func (k Keeper) getAvailablePoolCoinAmount(ctx sdk.Context, pool *types.Pool) (*sdk.Int, error) { |
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.
This responds to the remaining balance excluding deposits in the current pool.
x/datapool/keeper/pool_distribute.go
Outdated
} | ||
|
||
// calculate the revenue to be sent to each seller(totalSalesBalance / totalShareTokenAmount) | ||
eachDistributionAmount := k.getEachDistributionAmount(pool) |
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.
Calculate the revenue to be distributed to each seller.
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.
please rename this to getDistributionPerSeller
or getDistributionPerSale
.
x/datapool/keeper/pool_distribute.go
Outdated
if err != nil { | ||
return sdkerrors.Wrap(types.ErrRevenueDistribute, err.Error()) | ||
} | ||
*salesInfo.PaidCoin = salesInfo.PaidCoin.Add(paymentCoin) |
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.
Store the distributed amount in the sales history.
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.
I'm very thankful for your hard works due to the change of our design.
It was not that simple to implement the distribution of revenue. There were so many things to consider.
I left some comments 🙏
e2166a8
to
1b9f915
Compare
I have applied everything that has been discussed. |
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.
Thank you for quickly reflecting the �corrections.
I left some minor comments.
efb0831
to
da19591
Compare
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.
It looks good to me 👍
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.
LGTM 👍
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.
lgtm
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.
LGTM
k.SetInstantRevenueDistribution(ctx, instantRevenueDistribution) | ||
} | ||
|
||
func (k Keeper) DistributionRevenuePools(ctx sdk.Context) error { |
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.
We use verb for name of funcs.
So, I think that verb is proper for this func as well, DistributeRevenuePools()
or DistributePoolsRevenue()
.
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.
thanks
Closes #278
The following features have been added.
shareToken
has been deleted.