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

feat: add distribute revenue pools #318

Merged
merged 22 commits into from
May 19, 2022
Merged

feat: add distribute revenue pools #318

merged 22 commits into from
May 19, 2022

Conversation

gyuguen
Copy link
Contributor

@gyuguen gyuguen commented Apr 27, 2022

Closes #278
The following features have been added.

  • shareToken has been deleted.
  • The revenue distribution function is executed in accordance with the following conditions.
    • When a seller sells data
    • When a buyer buys a DataPass
  • Seller receives a distribution of proceeds in the order in which data is sold.
  • Improved to use commonly available test codes.

@gyuguen
Copy link
Contributor Author

gyuguen commented Apr 27, 2022

I haven't created a function that distributes revenue to Curator yet.
I'll add that feature in this next PR.

}

return &shareToken, nil
k.addSalesHistory(ctx, pool.PoolId, pool.Round, seller, cert.UnsignedCert.DataHash)
Copy link
Contributor Author

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.

}

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)
Copy link
Contributor Author

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.

@@ -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)
Copy link
Contributor Author

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.

Comment on lines 28 to 35
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))
}
Copy link
Contributor Author

@gyuguen gyuguen Apr 27, 2022

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/1/panacea1b
  2. 1/1/panacea1d
  3. 1/1/panacea1c
  4. 1/1/panacea1a

If you search in kvStore, it is searched in the following order.

  1. 1/1/panacea1a
  2. 1/1/panacea1b
  3. 1/1/panacea1c
  4. 1/1/panacea1d

Copy link
Contributor Author

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.

return nil
}

func (k Keeper) getAvailablePoolCoinAmount(ctx sdk.Context, pool *types.Pool) (*sdk.Int, error) {
Copy link
Contributor Author

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.

}

// calculate the revenue to be sent to each seller(totalSalesBalance / totalShareTokenAmount)
eachDistributionAmount := k.getEachDistributionAmount(pool)
Copy link
Contributor Author

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.

Copy link
Contributor

@youngjoon-lee youngjoon-lee May 12, 2022

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.

if err != nil {
return sdkerrors.Wrap(types.ErrRevenueDistribute, err.Error())
}
*salesInfo.PaidCoin = salesInfo.PaidCoin.Add(paymentCoin)
Copy link
Contributor Author

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.

Copy link
Contributor

@0xHansLee 0xHansLee left a 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 🙏

x/datapool/keeper/pool_distribute.go Outdated Show resolved Hide resolved
x/datapool/keeper/pool_distribute.go Outdated Show resolved Hide resolved
x/datapool/types/keys.go Outdated Show resolved Hide resolved
@gyuguen
Copy link
Contributor Author

gyuguen commented Apr 29, 2022

I have applied everything that has been discussed.

@gyuguen gyuguen requested a review from 0xHansLee April 29, 2022 09:25
Copy link
Contributor

@0xHansLee 0xHansLee left a 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.

x/datapool/keeper/pool_distribute.go Outdated Show resolved Hide resolved
x/datapool/keeper/pool_distribute.go Outdated Show resolved Hide resolved
x/datapool/keeper/pool_distribute.go Outdated Show resolved Hide resolved
@gyuguen gyuguen added this to the Data Pool Model milestone May 2, 2022
Copy link
Contributor

@0xHansLee 0xHansLee left a 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 👍

Copy link

@inchori inchori left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Contributor

@youngjoon-lee youngjoon-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@0xHansLee 0xHansLee left a 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 {
Copy link
Contributor

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().

Copy link
Contributor

@youngjoon-lee youngjoon-lee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@gyuguen gyuguen merged commit c3ef8c5 into master May 19, 2022
@gyuguen gyuguen deleted the ft/278/pool_activation branch May 19, 2022 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the pool activation
4 participants