Skip to content
This repository has been archived by the owner on Sep 12, 2022. It is now read-only.

[TCFMM-10] Add FA2 entrypoints to manage positions #9

Merged
merged 1 commit into from Sep 4, 2021

Conversation

rinn7e
Copy link
Member

@rinn7e rinn7e commented Aug 13, 2021

Description

Problem: Currently, the contract lacks support for FA2 entrypoints.
We should add this.

Solution: Add support for FA2 entrypoints: transer, balance_of,
and update_operator.

Related issue(s)

Resolves TCFMM-10
Depends on #8

✅ Checklist for your Pull Request

Related changes (conditional)

  • Tests
    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from
      silently reappearing again.
  • Documentation
    • I checked whether I should update the docs and did so if necessary:

Stylistic guide (mandatory)

@rinn7e rinn7e changed the title @rinn7e [TCFMM-10] Add FA2 entrypoints to manage positions [TCFMM-10] Add FA2 entrypoints to manage positions Aug 13, 2021
@rinn7e
Copy link
Member Author

rinn7e commented Aug 13, 2021

@dcastro @Martoon-00 This PR is ready for review. A few things to note/ask is that:

  • I've removed admin, we probably tackled this in a separate issue.
  • Currently, we tracked the owner of a position in 2 place: positions and ledger. This requires updating both of the map when we change the owner. I'm thinking of combining them somehow, let me know if what you think about this.
  • Related to error message, should we turn FA2 error message to error code as well or not.

Copy link
Member

@Martoon-00 Martoon-00 left a comment

Choose a reason for hiding this comment

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

Generally looks good to me 👍

Only one thing that worries me: swap_position effectively performs many of the checks that are already performed in transfer_item.

I think we should remove duplications in one function or another, and in swap_position state clearly what preconditions should hold upon calling it (e.g. whether amt must be 1, 0 or 1, or do not mention anything if we completely check amt inside).

@Martoon-00
Copy link
Member

Regarding your points, I personally think everything is properly done now.

@rinn7e rinn7e force-pushed the rinn7e/tcfmm-9-nat-errors branch 2 times, most recently from bb6c9e6 to 3aab852 Compare August 19, 2021 09:44
@rinn7e
Copy link
Member Author

rinn7e commented Aug 19, 2021

I think we should remove duplications in one function or another.

@Martoon-00 Make sense, I've move all the amt check to swap_position, and rename this function to change_position_owner instead to avoid confusion. Let me know what you think about this.

ligo/token/fa2.mligo Outdated Show resolved Hide resolved
ligo/token/fa2.mligo Outdated Show resolved Hide resolved
@Martoon-00
Copy link
Member

Looks good to me 👍

The last point: since you already seemed to rebase on top of the Errors PR, shouldn't you replace failwith "impossible" with throwing nat codes? Or you left this for the moment when the Errors PR gets merged?

@rinn7e
Copy link
Member Author

rinn7e commented Aug 20, 2021

Looks good to me 👍

The last point: since you already seemed to rebase on top of the Errors PR, shouldn't you replace failwith "impossible" with throwing nat codes? Or you left this for the moment when the Errors PR gets merged?

Since FA2 has its own error standard, should we turn it into error nat or not? It may not play well with other FA2 contract client (Not sure if it is that important or not anyway). What do you think about this?

@Martoon-00
Copy link
Member

Looks good to me +1
The last point: since you already seemed to rebase on top of the Errors PR, shouldn't you replace failwith "impossible" with throwing nat codes? Or you left this for the moment when the Errors PR gets merged?

Since FA2 has its own error standard, should we turn it into error nat or not? It may not play well with other FA2 contract client (Not sure if it is that important or not anyway). What do you think about this?

It's indeed tricky in general case, but I think for internal errors we are free to choose any desired format.

@rinn7e
Copy link
Member Author

rinn7e commented Aug 20, 2021

It's indeed tricky in general case, but I think for internal errors we are free to choose any desired format.

My bad, I thought you referred to FA2 errors 🤦. I've updated this now.

ligo/main.mligo Outdated Show resolved Hide resolved
ligo/token/fa2.mligo Outdated Show resolved Hide resolved
@rinn7e rinn7e force-pushed the rinn7e/tcfmm-10-fa2 branch 2 times, most recently from 4075214 to 499e986 Compare August 21, 2021 02:57
Copy link
Member

@Martoon-00 Martoon-00 left a comment

Choose a reason for hiding this comment

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

Now looks great 👍

Thanks for addressing my comments.

ligo/types.mligo Outdated Show resolved Hide resolved
ligo/token/fa2.mligo Outdated Show resolved Hide resolved
ligo/token/fa2.mligo Outdated Show resolved Hide resolved
@rinn7e rinn7e force-pushed the rinn7e/tcfmm-9-nat-errors branch 3 times, most recently from 9dc992a to 8a78ba5 Compare August 25, 2021 12:41
Base automatically changed from rinn7e/tcfmm-9-nat-errors to master August 25, 2021 12:43
@rinn7e rinn7e requested a review from pasqu4le August 31, 2021 03:59
Copy link
Member

@Martoon-00 Martoon-00 left a comment

Choose a reason for hiding this comment

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

Sorry for the later rereview, left a couple of minor comments.

The change of the structure looks good, nice that it could be made simpler.

ligo/token/fa2.mligo Show resolved Hide resolved
Add_operator p -> (Some unit, p)
| Remove_operator p -> ((None : unit option), p)
in
let _ = get_position_index (operator_param.token_id, store) in
Copy link
Member

Choose a reason for hiding this comment

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

This check is also better to be documented I think. AFAIU FA2 does not mention that Update_operators can throw an error when token_id does not yet exist.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Martoon-00 Strange that in tzip-12, Update_operators does not throw error for that. Do you know any reason why? Should we adhere to the tzip-12 (no error thrown, just leave storage not updated) or keep the error but update our spec?

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure too. I remember one contract that allowed a user to reserve a sequence of token_ids and later mint money at them, for such a contract it could be reasonable to allow setting operators in advance.

For our contract, setting an operator in advance does not make sense I think, so throwing an error seems justified.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see. In our use case, when setting an operator of an owner, that means he can transfer any of the owner positions right? In this case, ensuring a position exist or not may not be necessary.

ligo/main.mligo Outdated Show resolved Hide resolved
ligo/token/fa2.mligo Outdated Show resolved Hide resolved
scripts/generate_error_code.hs Outdated Show resolved Hide resolved
ligo/token/fa2.mligo Outdated Show resolved Hide resolved
ligo/token/fa2.mligo Outdated Show resolved Hide resolved
Problem: Currently, the contract lacks support for FA2 entrypoints.
We should add this.

Solution: Add support for FA2 entrypoints: `transer`, `balance_of`,
and `update_operator`.
@rinn7e rinn7e merged commit 7d8868b into master Sep 4, 2021
@rinn7e rinn7e deleted the rinn7e/tcfmm-10-fa2 branch September 4, 2021 06:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
3 participants