-
Notifications
You must be signed in to change notification settings - Fork 8
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(nfts): AccountBalance
deposit
#413
feat(nfts): AccountBalance
deposit
#413
Conversation
AccountBalance
deposit
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## chungquantin/feat-nfts #413 +/- ##
==========================================================
+ Coverage 70.93% 71.38% +0.45%
==========================================================
Files 72 72
Lines 13313 13561 +248
Branches 13313 13561 +248
==========================================================
+ Hits 9443 9680 +237
- Misses 3600 3608 +8
- Partials 270 273 +3
|
0299590
to
1a58df1
Compare
1a58df1
to
5ecb661
Compare
[sc-1989] |
72cddd5
to
5015e90
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.
Looking nice and clean! Have made some improvement suggestions, mostly minor, along with a few general questions.
Note that I did not review the tests yet owing to time. I took a quick look at https://app.codecov.io/gh/r0gue-io/pop-node/pull/413 and it seems as though there is some stuff added which is not covered by tests. They might be false positives, but please could you double check? I will check the tests on the next pass and then we should be good to go from my perspective.
@@ -795,19 +799,21 @@ impl<T: frame_system::Config> WeightInfo for SubstrateWeight<T> { | |||
/// Storage: `Nfts::ItemConfigOf` (r:2 w:0) | |||
/// Proof: `Nfts::ItemConfigOf` (`max_values`: None, `max_size`: Some(48), added: 2523, mode: `MaxEncodedLen`) | |||
/// Storage: `Nfts::AccountBalance` (r:2 w:2) | |||
/// Proof: `Nfts::AccountBalance` (`max_values`: None, `max_size`: Some(72), added: 2547, mode: `MaxEncodedLen`) | |||
/// Proof: `Nfts::AccountBalance` (`max_values`: None, `max_size`: Some(120), added: 2595, mode: `MaxEncodedLen`) | |||
/// Storage: `System::Account` (r:1 w:1) |
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.
As above.
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.
Question: Interesting to see that there is only 1 read and 1 write to the System::Account
. From my understanding, the do_transfer
is called twice from A to B and then B to A so it must be 2 reads and 2 writes.
Answer: Confirmed that this is correct. The claim_swap() method is called by caller
while caller
is allowlisted. Hence, there is no read / write taken on the caller account. Break it down we have:
- Transfer from
caller
todestination
: Readdestination
and write todest
because it has sufficient balance. - Transfer from
destination
tocaller
: Readcaller
and write to thecaller
because it has sufficient balance. (ignore read / write)
I'll dedicate more time later to do a proper review, but reserve and unreserve logic seems solid. Before I was more of the opinion of centralizing the responsibilities for the existence of the assets into the minter / owner of the collection. But I gotta say that I'm pretty convinced with the current approach. For instance moving |
29988be
to
d3ae740
Compare
08c9259
to
6c8d5b6
Compare
dc2c68f
to
4b4cd22
Compare
6c8d5b6
to
df965e1
Compare
5417599
to
1159074
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.
Overall pretty clean! Was nice diving into the NFT pallets some. However, there is a security flaw introduced with transfer
. Please review comments.
Also, can we please rename the PR title to feat(nfts): AccountBalance deposit
. We are introducing new functionality, so it should be a feature.
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.
Great work! 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.
Nice! Wasn't able to find much to change ;) Left two tiny comments. After those, I am good to approve.
d5b1a02
to
fefb7bc
Compare
AccountBalance
depositAccountBalance
deposit
fefb7bc
to
f4c02f7
Compare
f4c02f7
to
1aa79f3
Compare
Problem
This PR addresses the deposit issue with the
AccountBalance
storage type as outlined in #387. Currently, storage for eachAccountBalance
record created does not reserve the necessary deposit. Below are the cases whereAccountBalance
records are created or destroyed:Related Functions
do_mint
: Creates anAccountBalance
record formint_to
when a new collection item is minted.do_transfer
: Transfers a collection item from the owner to thedest
account. If thedest
account does not have enough balance (including does not exist), anAccountBalance
record is created. If the sender'sAccountBalance
becomes zero after the transfer, theirAccountBalance
record is removed.do_burn
: Removes theAccountBalance
of the owner, if they only have one item and that item is burned.do_mint_pre_signed
: Callsdo_mint
.do_buy_item
: Callsdo_transfer
to transfer an item from the seller to the buyer.do_claim_swap
: Callsdo_transfer
twice—once to transfer from A to B, and then from B to A.Solution
Refactor the
AccountBalance
storage value type to store a tuple(u32, AccountDepositOf<T>)
, representing:u32
: Tracks the total number of items in thecollection
owned by theaccount
.AccountDepositOf<T>
: A tuple of(AccountId, DepositBalance)
AccountId
: The depositor who reserves funds for creating theAccountBalance
record.DepositBalance
: The amount reserved from thedepositor
for creating theAccountBalance
record.Reserve Logic
do_mint
:Depositor
= Collection owner.mint_to
account, the collection owner reserves the funds to create theAccountBalance
record.AccountBalance
, the value ofAccountBalance
is simply incremented.do_transfer
:Depositor
= Provideddepositor
or the transferred collection item owner.AccountBalance
of the sender and increments that of the recipient.dest
), thedepositor
or the collection item owner (if provided) reserves the funds to create theAccountBalance
record.AccountBalance
record.do_buy_item
: Calldo_transfer
with thecaller
as the buyer account.do_claim_swap
:do_transfer
operations:do_transfer
with thedepositor
as thereceive_item.owner
do_transfer
with thecaller
as thesend_item.owner
Unreserve Logic
do_transfer
:AccountBalance
of the sender account.AccountBalance
value reaches zero, theAccountBalance
is removed, and the deposited funds are unreserved and returned to thedepositor
.do_burn
:AccountBalance
of the item owner.AccountBalance
value reaches zero, theAccountBalance
is removed, and the deposited funds are unreserved and returned to thedepositor
.