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

OpenSea V2 -> V1 compatibility #3654

Merged
merged 25 commits into from
Dec 15, 2023
Merged

OpenSea V2 -> V1 compatibility #3654

merged 25 commits into from
Dec 15, 2023

Conversation

bergeron
Copy link
Contributor

@bergeron bergeron commented Dec 12, 2023

Explanation

Moves to using OpenSea V2 API, but modifies the responses to keep compatibility with the existing controller state schema.

References

Changelog

@metamask/controller-utils

  • BREAKING: OPENSEA_PROXY_URL now points to OpenSea's v2 API. OPENSEA_API_URL + OPENSEA_TEST_API_URL have been removed.

@metamask/assets-controllers

  • BREAKING:
    • NftDetectionController constructor now requires the NftController.getNftApi function.
    • NFT controllers will no longer return last_sale information for NFTs fetched after the OpenSea V2 update

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@bergeron bergeron requested a review from mcmire December 12, 2023 22:53
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

I think there was just one field missing from mapOpenSeaNftV2ToV1 that I noticed, but this looks good to me so far otherwise! A lot of the comments below are just about improving types.

packages/assets-controllers/src/NftController.ts Outdated Show resolved Hide resolved
packages/assets-controllers/src/NftDetectionController.ts Outdated Show resolved Hide resolved
packages/assets-controllers/src/NftDetectionController.ts Outdated Show resolved Hide resolved
packages/assets-controllers/src/assetsUtil.ts Outdated Show resolved Hide resolved
packages/assets-controllers/src/NftController.ts Outdated Show resolved Hide resolved
packages/assets-controllers/src/assetsUtil.ts Outdated Show resolved Hide resolved
packages/assets-controllers/src/assetsUtil.ts Outdated Show resolved Hide resolved
packages/assets-controllers/src/assetsUtil.ts Show resolved Hide resolved
packages/assets-controllers/src/assetsUtil.ts Outdated Show resolved Hide resolved
@bergeron
Copy link
Contributor Author

bergeron commented Dec 13, 2023

I will strongly type the v2 responses. It could be convenient to generate these from swagger / use the OpenSea typescript SDK. But I've noticed at least 3 places where the spec is wrong, and for quickness i'll just add some types since its only a couple models.

@bergeron bergeron marked this pull request as ready for review December 14, 2023 20:16
@bergeron bergeron requested a review from a team as a code owner December 14, 2023 20:16
tokenId: nftV2.identifier,
}),
undefined,
1000,
Copy link
Contributor Author

@bergeron bergeron Dec 14, 2023

Choose a reason for hiding this comment

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

In all these examples I found, OS falls back to the original, non-CDN URL when you fetch the NFT individually. V1 also did this when listing, but in a separate field image_original_url, which is how those used to render.

Alternatively we could fetch metadata_url and grab the image field, but was more anonying to handle ipfs, arweave. The timeout was more for when I was doing that approach and may not be needed.

Copy link
Member

@Gudahtt Gudahtt Dec 15, 2023

Choose a reason for hiding this comment

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

Good call on not fetching the metadata. That would have had complicated privacy implications (for metadata URLs that aren't IPFS, at least)

@@ -231,22 +306,30 @@ export class NftController extends BaseControllerV1<NftConfig, NftState> {

private readonly messagingSystem: NftControllerMessenger;

private getNftApi({
getNftApi({
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, exposing this for another controller to use is typically something we'd avoid. Lately we've been trying to extract network calls from controllers altogether, moving them to separate "API service" classes.

But this seems OK for now, we can refactor this later.

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

This looks great! Thanks so much for taking care of this.

packages/controller-utils/src/constants.ts Show resolved Hide resolved
@bergeron bergeron merged commit 3ed517b into main Dec 15, 2023
136 checks passed
@bergeron bergeron deleted the brian/opensea-v2-to-v1 branch December 15, 2023 22:00
Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

const nftDetails: OpenSeaV2GetNftResponse | undefined =
await safelyExecute(() =>
timeoutFetch(
this.getNftApi({
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, this could mean a lot more network requests.

I wonder if we could cache these somehow to prevent this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. Although it's not the common case. Saw no occurrences in most wallets, and only on a few tokens when it does occur. I could tally more stats on the %. Also the && metadata_url avoids doing it some cases where it wouldn't return anything useful.

Copy link
Member

@Gudahtt Gudahtt Dec 15, 2023

Choose a reason for hiding this comment

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

Good point! OK, maybe we highlight it to the mobile and extension teams as a risk, and we can add caching later if necessary

Copy link
Contributor Author

@bergeron bergeron Dec 15, 2023

Choose a reason for hiding this comment

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

Was testing occurrences with a script like this:

let next = '', account = '';
do {
  const nfts = await(
    await fetch(
      `https://api.opensea.io/api/v2/chain/ethereum/account/${account}/nfts?limit=200&next=${next}`,
      { headers: { 'x-api-key': '' } }
    )).json();

  for (nft of nfts.nfts) {
    if (!nft.image_url && nft.metadata_url) {
      console.log(nft);
    }
  }
  next = nfts.next;
} while (next);

bergeron added a commit to MetaMask/metamask-extension that referenced this pull request Dec 18, 2023
## **Description**

Updates the assets controllers package to version 22.0.0. This brings in
[PR 3654](MetaMask/core#3654) to migrate from
OpenSea V1 to V2 API.

## **Related issues**

Fixes: MetaMask/MetaMask-planning#1841

## **Manual testing steps**

1. Import a wallet containing NFTs on mainnet
2. Manually import an NFT owner by the wallet, verify it appears
3. Enable NFT autodetection in settings, verify the rest of the NFTs
appear
4. Verify descriptions, collection/token images are correct
5. Send an NFT, verify it works

## **Screenshots/Recordings**

No visible differences

### **Before**

### **After**

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [x] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
chrisleewilcox added a commit to MetaMask/metamask-mobile that referenced this pull request Dec 19, 2023
## **Description**

Migrate to OpenSea V2 API because V1 is being deprecated. Patches this
change from core: MetaMask/core#3654


## **Related issues**

Fixes: MetaMask/MetaMask-planning#1841

## **Manual testing steps**

1. Import a wallet containing NFTs on mainnet
2. Manually import an NFT owner by the wallet, verify it appears
3. Enable NFT autodetection in settings, verify the rest of the NFTs
appear
4. Verify descriptions, collection/token images are correct
5. Send an NFT, verify it works

## **Screenshots/Recordings**

No visible differences between before and after.

### **Before**

<!-- [screenshots/recordings] -->

### **After**



https://github.com/MetaMask/metamask-mobile/assets/3500406/88217ecb-c4e2-473f-a360-c40a8f34d331



## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [x] I’ve properly set the pull request status:
  - [] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Chris Wilcox <chris.wilcox@consensys.net>
danjm pushed a commit to MetaMask/metamask-extension that referenced this pull request Dec 19, 2023
Updates the assets controllers package to version 22.0.0. This brings in
[PR 3654](MetaMask/core#3654) to migrate from
OpenSea V1 to V2 API.

Fixes: MetaMask/MetaMask-planning#1841

1. Import a wallet containing NFTs on mainnet
2. Manually import an NFT owner by the wallet, verify it appears
3. Enable NFT autodetection in settings, verify the rest of the NFTs
appear
4. Verify descriptions, collection/token images are correct
5. Send an NFT, verify it works

No visible differences

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [x] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
chrisleewilcox added a commit to MetaMask/metamask-mobile that referenced this pull request Dec 19, 2023
## **Description**

This is a release version of this PR:
#8135

Migrate to OpenSea V2 API because V1 is being deprecated. Patches this
change from core: MetaMask/core#3654


## **Related issues**

Fixes: MetaMask/MetaMask-planning#1841

## **Manual testing steps**

1. Import a wallet containing NFTs on mainnet
2. Manually import an NFT owner by the wallet, verify it appears
3. Enable NFT autodetection in settings, verify the rest of the NFTs
appear
4. Verify descriptions, collection/token images are correct
5. Send an NFT, verify it works

## **Screenshots/Recordings**

No visible differences between before and after.

### **Before**

<!-- [screenshots/recordings] -->

### **After**



https://github.com/MetaMask/metamask-mobile/assets/3500406/88217ecb-c4e2-473f-a360-c40a8f34d331



## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [x] I’ve properly set the pull request status:
  - [] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Chris Wilcox <chris.wilcox@consensys.net>
danjm pushed a commit to MetaMask/metamask-extension that referenced this pull request Dec 20, 2023
Updates the assets controllers package to version 22.0.0. This brings in
[PR 3654](MetaMask/core#3654) to migrate from
OpenSea V1 to V2 API.

Fixes: MetaMask/MetaMask-planning#1841

1. Import a wallet containing NFTs on mainnet
2. Manually import an NFT owner by the wallet, verify it appears
3. Enable NFT autodetection in settings, verify the rest of the NFTs
appear
4. Verify descriptions, collection/token images are correct
5. Send an NFT, verify it works

No visible differences

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [x] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
danjm pushed a commit to MetaMask/metamask-extension that referenced this pull request Dec 20, 2023
Updates the assets controllers package to version 22.0.0. This brings in
[PR 3654](MetaMask/core#3654) to migrate from
OpenSea V1 to V2 API.

Fixes: MetaMask/MetaMask-planning#1841

1. Import a wallet containing NFTs on mainnet
2. Manually import an NFT owner by the wallet, verify it appears
3. Enable NFT autodetection in settings, verify the rest of the NFTs
appear
4. Verify descriptions, collection/token images are correct
5. Send an NFT, verify it works

No visible differences

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [x] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
danjm pushed a commit to MetaMask/metamask-extension that referenced this pull request Dec 22, 2023
Updates the assets controllers package to version 22.0.0. This brings in
[PR 3654](MetaMask/core#3654) to migrate from
OpenSea V1 to V2 API.

Fixes: MetaMask/MetaMask-planning#1841

1. Import a wallet containing NFTs on mainnet
2. Manually import an NFT owner by the wallet, verify it appears
3. Enable NFT autodetection in settings, verify the rest of the NFTs
appear
4. Verify descriptions, collection/token images are correct
5. Send an NFT, verify it works

No visible differences

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [x] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [x] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
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