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

Add ability to bind a contract interface to a token pool #1123

Merged
merged 10 commits into from
Jan 5, 2023

Conversation

awrichar
Copy link
Contributor

@awrichar awrichar commented Dec 28, 2022

Part of FIR-16.
Depends on hyperledger/firefly-tokens-erc20-erc721#106.

Discussion about the overall architecture/usefulness of this proposed feature should be directed to FIR-16, while discussion here should focus on specific technical details of the current proposed approach.

This adds the ability for FireFly to provide ABI details to a token connector, making it easier for the token connector to know the shape of the underlying contract it is dealing with (vs. having to probe/guess at the methods available).

Notes

  • This feature is only useful to users who have significant knowledge of the underlying token contract that sits on the other side of their token connector.
  • It's likely to be most useful when creating a pool against a pre-deployed contract - ie when passing config.address. Worth mentioning that FireFly doesn't really "know" you can create pools against pre-deployed contracts (as config is opaque), but it's up to the user to understand the combination of features that are useful here.
  • Theoretically you could create a factory contract that deploys custom ERC20/ERC721 instances, and then you'd need to pass interface on every pool creation even while relying on the factory sitting on the other side of the token connector to do the deploy. Seems like a less useful combo, but calling it out here for completeness.

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
@codecov-commenter
Copy link

codecov-commenter commented Dec 29, 2022

Codecov Report

Merging #1123 (a7c5193) into main (f1b10e9) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1123   +/-   ##
=======================================
  Coverage   99.34%   99.34%           
=======================================
  Files         303      303           
  Lines       19695    19789   +94     
=======================================
+ Hits        19566    19660   +94     
  Misses        120      120           
  Partials        9        9           
Impacted Files Coverage Δ
pkg/core/tokenpool.go 100.00% <ø> (ø)
internal/assets/manager.go 100.00% <100.00%> (ø)
internal/assets/operations.go 100.00% <100.00%> (ø)
internal/assets/token_pool.go 100.00% <100.00%> (ø)
internal/contracts/manager.go 95.91% <100.00%> (+0.08%) ⬆️
internal/database/sqlcommon/tokenpool_sql.go 100.00% <100.00%> (ø)
internal/events/token_pool_created.go 100.00% <100.00%> (ø)
internal/orchestrator/orchestrator.go 100.00% <100.00%> (ø)
internal/tokens/fftokens/fftokens.go 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
@awrichar awrichar marked this pull request as ready for review January 4, 2023 06:08
type tokenInterface struct {
Format core.TokenInterfaceFormat `json:"format"`
ABI []*abi.Entry `json:"abi,omitempty"`
Methods []*fftypes.FFIMethod `json:"methods,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think ffi would be less confusing for the name of this parameter if possible.

As on the other end of the token connector where it talks to EVMConnect/EthConnect etc. the methods array is going to represent an array of ABI-style methods. Also where abi is used above, I think it's actually an array of ABI methods (not the whole ABI).

@@ -643,13 +662,68 @@ func (ft *FFTokens) ActivateTokenPool(ctx context.Context, nsOpID string, pool *
return false, nil
}

func (ft *FFTokens) MintTokens(ctx context.Context, nsOpID string, poolLocator string, mint *core.TokenTransfer) error {
func (ft *FFTokens) prepareABI(ctx context.Context, methods []*fftypes.FFIMethod) ([]*abi.Entry, error) {
abiMethods := make([]*abi.Entry, len(methods))
Copy link
Contributor

Choose a reason for hiding this comment

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

This line confirms for me the comment earlier - that the abi field of the payload passed to the Token connector is not the full ABI, but rather the array of ABI-formatted Methods.

... all to say, I feel quite strongly we need to rename methods to ffi in the payload to the token connector (or rename both to abiMethods/ffiMethods)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or should it be called methods in both cases (and the format param tells you how to decode it)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since it's not really an abi or ffi, it's always a list of methods encoded in abi or ffi format.

Copy link
Contributor

@peterbroadhurst peterbroadhurst left a comment

Choose a reason for hiding this comment

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

One change requested on the FF <-> FFTokens API interface that I got stuck on, but looks great!

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
Copy link
Contributor

@peterbroadhurst peterbroadhurst left a comment

Choose a reason for hiding this comment

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

👍 - leaving merge coordination with you due to the pre-reqs

Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
Signed-off-by: Andrew Richardson <andrew.richardson@kaleido.io>
@awrichar awrichar merged commit 2b5771c into hyperledger:main Jan 5, 2023
@awrichar awrichar deleted the pool-abi branch January 5, 2023 23:31
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