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

Fungible Tokens (spike) #1

Merged
merged 22 commits into from
Jul 18, 2022
Merged

Fungible Tokens (spike) #1

merged 22 commits into from
Jul 18, 2022

Conversation

alexytsu
Copy link
Collaborator

@alexytsu alexytsu commented Jul 5, 2022

No description provided.

fil_token/src/token/types.rs Outdated Show resolved Hide resolved
fil_token/src/token/mod.rs Outdated Show resolved Hide resolved
@alexytsu
Copy link
Collaborator Author

alexytsu commented Jul 8, 2022

I think in general, this impl is too much of an implementation of a token rather than a library that would let other's build their own tokens. Not sure what the right balance should be in terms of inversion of control.

@alexytsu alexytsu requested review from anorth and abright July 12, 2022 00:13
fil_token/src/token/mod.rs Outdated Show resolved Hide resolved
fil_token/src/blockstore.rs Show resolved Hide resolved
fil_token/src/runtime/mod.rs Outdated Show resolved Hide resolved
fil_token/src/runtime/fvm.rs Outdated Show resolved Hide resolved
fil_token/src/token/mod.rs Outdated Show resolved Hide resolved
fil_token/src/token/mod.rs Outdated Show resolved Hide resolved
fil_token/src/token/state.rs Outdated Show resolved Hide resolved
fil_token/src/token/state.rs Outdated Show resolved Hide resolved
fil_token/src/token/types.rs Outdated Show resolved Hide resolved
fil_token/src/token/state.rs Show resolved Hide resolved
fil_token/src/token/types.rs Show resolved Hide resolved
@alexytsu alexytsu requested a review from anorth July 18, 2022 01:44
@alexytsu alexytsu marked this pull request as ready for review July 18, 2022 01:45
@alexytsu
Copy link
Collaborator Author

I'm not sure in general if my use of ActorID is appropriate as I don't understand the implications of a "reorg".

@anorth do you see filecoin-project/FIPs#379 as a necessary building block for standard tokens?

Copy link
Member

@anorth anorth left a comment

Choose a reason for hiding this comment

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

This is great progress, we should merge it and keep iterating. And perhaps start using the issue tracker to track the many emerging items that we can't address all at once in code review.

One consideration for improving the API is efficiency of state writes for bulk operations. The current API will force some unnecessary state.save() calls for intermediate states. E.g. intialising and then minting to a bunch of accounts up front, or making multiple transfers (from some non-standard token method). This API is pretty good for the basic cases and we want to keep them easy. We should think about how/whether to change this API to aid batching, or add an alternative style for less common but more complex calls. Maybe a closure that executes over state object, or a builder-style API that can abstract over it while batching.

The same then applies to the state API, which need not be so user-friendly (our lib is the main user) but wants to avoid serialising state objects unnecessarily. A closure pattern could ork here. There's some amount of necessary serialisation internal to HAMT and similar structures, though.

fil_token/Cargo.toml Show resolved Hide resolved
fil_token/src/token/mod.rs Show resolved Hide resolved
fil_token/src/token/mod.rs Show resolved Hide resolved
fil_token/src/token/mod.rs Show resolved Hide resolved
fil_token/src/token/mod.rs Show resolved Hide resolved

{
// TODO: helper functions for saving hamts?, this can probably be done more efficiently rather than
// getting the root allowance map again, by abstracting the nested hamt structure
Copy link
Member

Choose a reason for hiding this comment

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

This looks close to what I expect, except for loading the root allowances map again. You should just load it explicitly at the top because we'll need to update it.


/// Increase the allowance between owner and spender by the specified value
///
/// Caller must ensure that value is non-negative.
Copy link
Member

Choose a reason for hiding this comment

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

Here again how about a single change_allowancefunction

if let Some(mut map) = allowance_map {
map.delete(&spender)?;
if map.is_empty() {
let mut root_allowance_map = self.get_allowances_map(bs)?;
Copy link
Member

Choose a reason for hiding this comment

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

Similar to above, just get this root map explicitly at the start rather than hiding it in get_owner_allowance_map

)
})?;

if new_allowance.lt(&TokenAmount::zero()) {
Copy link
Member

Choose a reason for hiding this comment

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

is_negative

/// Burn tokens from the caller's account, decreasing the total supply
///
/// When burning tokens:
/// - Any holder MUST be allowed to burn their own tokens
Copy link
Member

Choose a reason for hiding this comment

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

Some of these rules are probably not strictly necessary for some interesting tokens

@anorth
Copy link
Member

anorth commented Jul 18, 2022

I'm not sure in general if my use of ActorID is appropriate as I don't understand the implications of a "reorg".

I think it's fine.

@anorth do you see filecoin-project/FIPs#379 as a necessary building block for standard tokens?

No, these are independent.

@alexytsu alexytsu merged commit b66ef6a into main Jul 18, 2022
@alexytsu alexytsu deleted the token/spike branch July 18, 2022 05:02
arajasek pushed a commit that referenced this pull request Jan 13, 2023
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.

None yet

3 participants