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

New tokenIds #583

Merged
merged 15 commits into from
Apr 20, 2023
Merged

New tokenIds #583

merged 15 commits into from
Apr 20, 2023

Conversation

zajck
Copy link
Member

@zajck zajck commented Mar 15, 2023

Replaces #582

Implements necessary changes to support tokenId = <<uint128(offerId)>>.<<uint128(exchangeId)>>
Although initially meant only for preminted vouchers, it turned out it's easier to make the change for all new vouchers.

Main reason to do this is to remove binary search in getPremintStatus, which has now constant time and space complexity.

Additinal implications:

  • max preminted range length was reduced to 2^64 which is still more than anyone realistically needs
  • no need to store array of preminted offer ids in vouchers, so _rangeOfferIds was removed. Since binary search was removed, there is no need to require that preminted offer ranges are ordered.
  • transferPremintedFrom is not needed anymore since regular transfer functions are efficient enough

@zajck zajck self-assigned this Mar 15, 2023
@zajck zajck added the enhancement New feature or request label Mar 15, 2023
@zajck zajck requested review from anajuliabit, mischat and levalleux-ludo and removed request for anajuliabit March 15, 2023 13:55
Copy link
Contributor

@anajuliabit anajuliabit left a comment

Choose a reason for hiding this comment

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

Besides what I put in the code, could you please add unit tests to validate that tokens created before and after EXCHANGE_ID_2_2_0 are burned correctly?

contracts/protocol/facets/ExchangeHandlerFacet.sol Outdated Show resolved Hide resolved
contracts/protocol/clients/voucher/BosonVoucher.sol Outdated Show resolved Hide resolved
test/protocol/OfferHandlerTest.js Outdated Show resolved Hide resolved
test/protocol/OfferHandlerTest.js Outdated Show resolved Hide resolved
Copy link
Contributor

@anajuliabit anajuliabit left a comment

Choose a reason for hiding this comment

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

forgot to choose "request changes"

Copy link
Member Author

@zajck zajck left a comment

Choose a reason for hiding this comment

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

Tests for token burning before/after the upgrade are in #498 .

contracts/protocol/clients/voucher/BosonVoucher.sol Outdated Show resolved Hide resolved
contracts/protocol/facets/ExchangeHandlerFacet.sol Outdated Show resolved Hide resolved
test/protocol/OfferHandlerTest.js Outdated Show resolved Hide resolved
test/protocol/OfferHandlerTest.js Outdated Show resolved Hide resolved
Copy link
Member

@mischat mischat left a comment

Choose a reason for hiding this comment

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

I guess, a highlevel comment. The method we added : 'extractExchangeId' states that it is needed when a tokenID is passed in instead of an exchangeID...

when i look for the usage it only seems to be used in the exchangeHandlderFacet, is this meant to be the case ?

And given that the method, in the comments, states that it takes in a tokenID and outputs an exchangeID, i feel like the naming is misleading :

protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:        _exchangeId = extractExchangeId(_exchangeId);
protocol/facets/ExchangeHandlerFacet.sol:    function extractExchangeId(uint256 _exchangeId) internal pure returns (uint256 exchangeId) {

Looking at the code, we don't seem to use these tokenIDs outside of Voucher and the Exchange handler, every other instance of tokenID seems to either be todo with token gating, token based auth, or twinning, which should be fine ...

Anyways

contracts/protocol/clients/voucher/BosonVoucher.sol Outdated Show resolved Hide resolved
scripts/config/protocol-parameters.js Show resolved Hide resolved
Copy link
Member Author

@zajck zajck left a comment

Choose a reason for hiding this comment

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

@mischat Re: extractExchangeId

That was meant more for convenience, so users could pass in either tokenId or exchangeId.
But yeah, if we really wanted to support that, I would need to do it everywhere (there are methods in dispute and orchestration handler), and also change all natspec to say "exchangeId can either be exchangeId or tokenId`.

So after your comment I changed my mind and removed extractExchangeId, since all protocol methods are clear that they expect exchangeId. Anyways, whoever is interacting only with the protocol already operates only with the correct exchangeId.
But even if they have only tokenId, they can always easiliy convert it to exchangeId.

I'm running tests locally now and will push the changes soon.

contracts/protocol/clients/voucher/BosonVoucher.sol Outdated Show resolved Hide resolved
scripts/config/protocol-parameters.js Show resolved Hide resolved
@zajck zajck requested review from anajuliabit and mischat March 17, 2023 12:07
anajuliabit
anajuliabit previously approved these changes Mar 24, 2023
@zajck zajck added the v2.2.0 label Mar 30, 2023
anajuliabit added a commit that referenced this pull request Mar 30, 2023
@zajck zajck mentioned this pull request Apr 3, 2023
@zajck zajck requested a review from anajuliabit April 19, 2023 16:58
Copy link
Member

@mischat mischat left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good to me

Copy link
Contributor

@anajuliabit anajuliabit left a comment

Choose a reason for hiding this comment

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

LGTM

@anajuliabit anajuliabit merged commit 00c26ea into main Apr 20, 2023
@zajck zajck deleted the new-tokenId branch April 20, 2023 14:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request v2.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants