Skip to content

Fungible Tokens (spike) - #1

Merged
alexytsu merged 22 commits into
mainfrom
token/spike
Jul 18, 2022
Merged

Fungible Tokens (spike)#1
alexytsu merged 22 commits into
mainfrom
token/spike

Conversation

@alexytsu

@alexytsu alexytsu commented Jul 5, 2022

Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread fil_token/src/token/types.rs Outdated
Comment thread fil_token/src/token/mod.rs Outdated
@alexytsu

alexytsu commented Jul 8, 2022

Copy link
Copy Markdown
Collaborator Author

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 abright and anorth July 12, 2022 00:13
Comment thread fil_token/src/token/mod.rs Outdated
Comment thread fil_token/src/blockstore.rs
Comment thread fil_token/src/runtime/mod.rs Outdated
Comment thread fil_token/src/runtime/fvm.rs Outdated
Comment thread fil_token/src/token/mod.rs Outdated
Comment thread fil_token/src/token/mod.rs Outdated
Comment thread fil_token/src/token/state.rs Outdated
Comment thread fil_token/src/token/state.rs Outdated
Comment thread fil_token/src/token/types.rs Outdated
Comment thread testing/fil_token_integration/actors/wfil_token_actor/README.md
Comment thread testing/fil_token_integration/actors/wfil_token_actor/src/lib.rs
Comment thread fil_token/src/token/state.rs
Comment thread fil_token/src/token/types.rs
@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
Copy Markdown
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?

@anorth anorth left a comment

Copy link
Copy Markdown
Member

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.

Comment thread fil_token/Cargo.toml
Comment thread fil_token/src/token/mod.rs
Comment thread fil_token/src/token/mod.rs
Comment thread fil_token/src/token/mod.rs
Comment thread fil_token/src/token/mod.rs

{
// 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

anorth commented Jul 18, 2022

Copy link
Copy Markdown
Member

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.

3 participants