-
Notifications
You must be signed in to change notification settings - Fork 15
Feat/tokenscope #970
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
Merged
Merged
Feat/tokenscope #970
Changes from all commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
58e6ab0
added seaport orderfulfill event
Zimtente 61bfcf2
Merge branch 'main' into 832-seaport-sales-plugin
Zimtente eb24a13
Merge branch 'main' into 832-seaport-sales-plugin
Zimtente 9d6fae4
Merge branch 'main' into 832-seaport-sales-plugin
tk-o f8433f1
docs(changeset): Added new Plugin: TokenScope. This Plugin for now wi…
Zimtente 751754f
Merge branch 'main' into 832-seaport-sales-plugin
Zimtente 0c4485b
working on review items
Zimtente cfdc375
Merge branch 'main' into 832-seaport-sales-plugin
Zimtente b562d5f
Merge branch 'main' into 832-seaport-sales-plugin
Zimtente a78c927
last changes
Zimtente 956d9a2
remove unnecessary context param
lightwalker-eth 1dc40ea
lint
lightwalker-eth 115f41f
Rename function
lightwalker-eth 9cbf536
Fix chainId type
lightwalker-eth fa074d7
Move TokenType definition
lightwalker-eth 783b9c1
Refine isEqualChainAddress
lightwalker-eth 5a0643a
Refactor getDomainIdByTokenId and related
lightwalker-eth 5756db6
Refactor isSupportedCurrencyContract
lightwalker-eth d8aa7d8
Refine currency logic
lightwalker-eth 9c90320
Refine indexing logic
lightwalker-eth 3d12dde
Remove unnecessary .gitattributes
lightwalker-eth 6507c95
Make indexing of Seaport1.5 explicit
lightwalker-eth bcc38ae
Remove circular package dependency
lightwalker-eth f8e50dc
Refine docs
lightwalker-eth 5ece4f6
Refine docs
lightwalker-eth 6631cd8
Refine data model
lightwalker-eth eb07501
Refactorings
lightwalker-eth 5e1e97e
Refactorings
lightwalker-eth 694f225
typecheck
lightwalker-eth 1b1f2d1
Update changeset
lightwalker-eth 6841aa8
lint
lightwalker-eth da5787c
Update changeset
lightwalker-eth cc8c909
Revert changes to shell script executable permissions
lightwalker-eth cd53bf7
Advertise new tokenscope plugin
lightwalker-eth 4e3b81d
Revert chainId import changes
lightwalker-eth ce7d125
Document division of responsibilities
lightwalker-eth 2835c35
Add docs
lightwalker-eth aa29450
Refine docs
lightwalker-eth b8761f1
lint
lightwalker-eth 5bfc851
Merge branch 'main' into feat/tokenscope
lightwalker-eth b8d065a
add tokenscope plugin to alpha docs list
shrugs c7da331
refactor: move handler and lib logics to correct place
shrugs 6ef1dea
fix: streamline some conditionals
shrugs 469d36d
refactor: move stuff out of datasources, fix handler placement, refac…
shrugs 084ad4d
fix: remove console log
shrugs 13e05f3
fix: type referential error
shrugs 0626cb6
remove redundant satisfies operators
shrugs 99ede8f
Merge branch 'main' into feat/tokenscope
shrugs 66d6a4c
Refine docs
lightwalker-eth 6fb84b2
Refine docs on no-op case
lightwalker-eth 428b36d
Fix data model
lightwalker-eth fa9e488
Add validation that supported NFTs are exactly 1
lightwalker-eth 83cb1ed
Align language
lightwalker-eth 0632022
Refine language
lightwalker-eth 02e6fce
Refactor currency
lightwalker-eth 0d150b1
Refine docs
lightwalker-eth 4cf08d3
refine docs
lightwalker-eth 461c807
Constrain exports
lightwalker-eth d15e9af
Remove unused function
lightwalker-eth d02e9cf
lint
lightwalker-eth 73d04db
constrain exports
lightwalker-eth 4f6d029
Refine docs
lightwalker-eth 7c26c8d
Refine docs on hosted instances
lightwalker-eth 48689a4
fix: remove Seaport* prefix for seaport-types
shrugs 8eed36b
fix: remove unused function
shrugs 4329fda
fix: clean up currency handling
shrugs abfc68b
fix: boolean error in offer/consideration validity check
shrugs e196b4e
Merge branch 'main' into feat/tokenscope
shrugs 3dfcc2c
fix: update docstring
shrugs 522619f
fix: do not enable tokenscope just yet
shrugs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@ensnode/ensnode-schema": minor | ||
| "@ensnode/datasources": minor | ||
| "ensindexer": minor | ||
| --- | ||
|
|
||
| Initial launch of ENS TokenScope with support for indexing Seaport sales. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| import { | ||
| base, | ||
| baseSepolia, | ||
| holesky, | ||
| linea, | ||
| lineaSepolia, | ||
| mainnet, | ||
| optimism, | ||
| sepolia, | ||
| } from "viem/chains"; | ||
|
|
||
| import { AccountId, ChainId, accountIdEqual } from "@ensnode/ensnode-sdk"; | ||
| import { Address, zeroAddress } from "viem"; | ||
|
|
||
| /** | ||
| * Identifiers for supported currencies. | ||
| * | ||
| * TODO: Add support for WETH | ||
| */ | ||
| export const CurrencyIds = { | ||
| ETH: "ETH", | ||
| USDC: "USDC", | ||
| DAI: "DAI", | ||
| } as const; | ||
|
|
||
| export type CurrencyId = (typeof CurrencyIds)[keyof typeof CurrencyIds]; | ||
|
|
||
| export interface Price { | ||
| currency: CurrencyId; | ||
|
|
||
| /** | ||
| * The amount of the currency in the smallest unit of the currency. (see | ||
| * decimals of the CurrencyConfig for the currency). | ||
| * | ||
| * Guaranteed to be non-negative. | ||
| */ | ||
| amount: bigint; | ||
| } | ||
|
|
||
| export interface CurrencyInfo { | ||
| id: CurrencyId; | ||
| name: string; | ||
| decimals: number; | ||
| } | ||
|
|
||
| const currencyInfo: Record<CurrencyId, CurrencyInfo> = { | ||
| [CurrencyIds.ETH]: { | ||
| id: CurrencyIds.ETH, | ||
| name: "Ethereum", | ||
| decimals: 18, | ||
| }, | ||
| [CurrencyIds.USDC]: { | ||
| id: CurrencyIds.USDC, | ||
| name: "USDC", | ||
| decimals: 6, | ||
| }, | ||
| [CurrencyIds.DAI]: { | ||
| id: CurrencyIds.DAI, | ||
| name: "Dai Stablecoin", | ||
| decimals: 18, | ||
| }, | ||
| }; | ||
|
|
||
| export const getCurrencyInfo = (currencyId: CurrencyId): CurrencyInfo => currencyInfo[currencyId]; | ||
|
|
||
| // NOTE: this mapping currently only considers the subset of chains where we have | ||
| // supported token issuing contracts. | ||
| const KNOWN_CURRENCY_CONTRACTS: Record<ChainId, Record<CurrencyId, Address>> = { | ||
| /** mainnet namespace */ | ||
| [mainnet.id]: { | ||
| [CurrencyIds.ETH]: zeroAddress, | ||
| [CurrencyIds.USDC]: "0xA0b86a33E6417c5Dd4Baf8C54e5de49E293E9169", | ||
| [CurrencyIds.DAI]: "0x6B175474E89094C44Da98b954EedeAC495271d0F", | ||
| }, | ||
| [base.id]: { | ||
| [CurrencyIds.ETH]: zeroAddress, | ||
| [CurrencyIds.USDC]: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", | ||
| [CurrencyIds.DAI]: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb", | ||
| }, | ||
| [optimism.id]: { | ||
| [CurrencyIds.ETH]: zeroAddress, | ||
| [CurrencyIds.USDC]: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85", | ||
| [CurrencyIds.DAI]: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1", | ||
| }, | ||
| [linea.id]: { | ||
| [CurrencyIds.ETH]: zeroAddress, | ||
| [CurrencyIds.USDC]: "0x176211869cA2b568f2A7D4EE941E073a821EE1ff", | ||
| [CurrencyIds.DAI]: "0x4AF15ec2A0BD43Db75dd04E62FAA3B8EF36b00d5", | ||
| }, | ||
|
|
||
| /** sepolia namespace */ | ||
| [sepolia.id]: { | ||
| [CurrencyIds.ETH]: zeroAddress, | ||
| [CurrencyIds.USDC]: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238", | ||
| [CurrencyIds.DAI]: "0x3e622317f8C93f7328350cF0B56d9eD4C620C5d6", | ||
| }, | ||
| [baseSepolia.id]: { | ||
| [CurrencyIds.ETH]: zeroAddress, | ||
| [CurrencyIds.USDC]: "0x036CbD53842c5426634e7929541eC2318f3dCF7e", | ||
| [CurrencyIds.DAI]: "0x7368C6C68a4b2b68F90DB2e8F5E3b8E1E5e4F5c7", | ||
| }, | ||
| [lineaSepolia.id]: { | ||
| [CurrencyIds.ETH]: zeroAddress, | ||
| [CurrencyIds.USDC]: "0x176211869cA2b568f2A7D4EE941E073a821EE1ff", | ||
| [CurrencyIds.DAI]: "0x4AF15ec2A0BD43Db75dd04E62FAA3B8EF36b00d5", | ||
| }, | ||
|
|
||
| /** holesky namespace */ | ||
| [holesky.id]: { | ||
| [CurrencyIds.ETH]: zeroAddress, | ||
| [CurrencyIds.USDC]: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238", | ||
| [CurrencyIds.DAI]: "0x3e622317f8C93f7328350cF0B56d9eD4C620C5d6", | ||
| }, | ||
| } as const; | ||
|
|
||
| /** | ||
| * Gets the supported currency contracts for a given chain as a Record<CurrencyId, AccountId> | ||
| * | ||
| * @param chainId - The chain ID to get supported currency contracts for | ||
| * @returns a record of currency ids to AccountIds for the given chain | ||
| */ | ||
| const getSupportedCurrencyContractsForChain = (chainId: ChainId): Record<CurrencyId, AccountId> => { | ||
| return Object.fromEntries( | ||
| Object.entries(KNOWN_CURRENCY_CONTRACTS[chainId] ?? {}).map(([currencyId, address]) => [ | ||
| currencyId, | ||
| { chainId, address }, | ||
| ]), | ||
| ) as Record<CurrencyId, AccountId>; | ||
| }; | ||
|
|
||
| /** | ||
| * Gets the currency id for the given contract | ||
| * | ||
| * @param contract - The AccountId of the contract to get the currency id for | ||
| * @returns the currency id for the given contract in the specified namespace, or | ||
| * null if the contract is not a supported currency contract in the | ||
| * specified namespace | ||
| */ | ||
| export const getCurrencyIdForContract = (contract: AccountId): CurrencyId | null => { | ||
| const supportedCurrencyContracts = getSupportedCurrencyContractsForChain(contract.chainId); | ||
|
|
||
| const found = Object.entries(supportedCurrencyContracts).find(([, accountId]) => | ||
| accountIdEqual(accountId, contract), | ||
| ); | ||
|
|
||
| if (!found) return null; | ||
|
|
||
| return found[0] as CurrencyId; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { | ||
| DatasourceName, | ||
| ENSNamespaceId, | ||
| getENSNamespace, | ||
| maybeGetDatasource, | ||
| } from "@ensnode/datasources"; | ||
| import { AccountId, ChainId, uniq } from "@ensnode/ensnode-sdk"; | ||
|
|
||
| /** | ||
| * Gets the AccountId for the contract in the specified namespace, datasource, and | ||
| * contract name, or undefined if it is not defined or is not a single AccountId. | ||
| * | ||
| * This is useful when you want to retrieve the AccountId for a contract by its name | ||
| * where it may or may not actually be defined for the given namespace and datasource. | ||
| * | ||
| * @param namespaceId - The ENSNamespace identifier (e.g. 'mainnet', 'sepolia', 'holesky', | ||
| * 'ens-test-env') | ||
| * @param datasourceName - The name of the Datasource to search for contractName in | ||
| * @param contractName - The name of the contract to retrieve | ||
| * @returns The AccountId of the contract with the given namespace, datasource, | ||
| * and contract name, or undefined if it is not found or is not a single AccountId | ||
| */ | ||
| export const maybeGetDatasourceContract = ( | ||
| namespaceId: ENSNamespaceId, | ||
| datasourceName: DatasourceName, | ||
| contractName: string, | ||
| ): AccountId | undefined => { | ||
| const datasource = maybeGetDatasource(namespaceId, datasourceName); | ||
| if (!datasource) return undefined; | ||
|
|
||
| const address = datasource.contracts[contractName]?.address; | ||
| if (address === undefined || Array.isArray(address)) return undefined; | ||
|
|
||
| return { | ||
| chainId: datasource.chain.id, | ||
| address, | ||
| }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * An enum representing the possible CAIP-19 Asset Namespace values. | ||
| */ | ||
| export const AssetNamespaces = { | ||
| ERC721: "erc721", | ||
| ERC1155: "erc1155", | ||
| } as const; | ||
|
|
||
| export type AssetNamespace = (typeof AssetNamespaces)[keyof typeof AssetNamespaces]; | ||
|
|
||
| /** | ||
| * A uint256 value that identifies a specific token within an NFT contract. | ||
| */ | ||
| export type TokenId = bigint; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { AccountId, Node } from "@ensnode/ensnode-sdk"; | ||
| import { Address, Hex } from "viem"; | ||
|
|
||
| import { Price } from "@/lib/currencies"; | ||
| import { AssetNamespace, TokenId } from "@/lib/tokenscope/assets"; | ||
|
|
||
| export interface SupportedNFT { | ||
| assetNamespace: AssetNamespace; | ||
| contract: AccountId; | ||
| tokenId: TokenId; | ||
| domainId: Node; | ||
| } | ||
|
|
||
| export interface SupportedPayment { | ||
| price: Price; | ||
| } | ||
|
|
||
| export interface SupportedSale { | ||
| orderHash: Hex; | ||
| nft: SupportedNFT; | ||
| payment: SupportedPayment; | ||
| seller: Address; | ||
| buyer: Address; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For strict correctness it seems we should:
getCurrencyIdForContract.KNOWN_CURRENCY_CONTRACTSso that each record includes its associated namespace.getSupportedCurrencyContractsForChainso that it also takes a namespace param.