Skip to content

Commit

Permalink
Merge pull request #15 from PaimaStudios/erc6551
Browse files Browse the repository at this point in the history
Add erc6551 docs
  • Loading branch information
SebastienGllmt authored Oct 15, 2023
2 parents 8506794 + 6548d15 commit 68456ee
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
extensions:
- name: "Bar"
type: "erc20"
contractAddress: "0xFE...11"
contractAddress: "0x01...ef"
startBlockHeight: 4567123
```
Expand Down Expand Up @@ -43,10 +43,10 @@ export async function getFungibleTokenBalance(
extensions:
- name: "Foo"
type: "erc20-deposit"
contractAddress: "0xFE...10"
contractAddress: "0x01...ef"
startBlockHeight: 4567123
scheduledPrefix: "dp"
depositAddress: "0xAB...CD"
depositAddress: "0x23...cd"
```

### Meaning
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
extensions:
- name: "My NFT Contract"
type: "erc721"
contractAddress: "0x01...EF"
contractAddress: "0x01...ef"
startBlockHeight: 7654321
scheduledPrefix: "newnft"
```
Expand Down Expand Up @@ -85,7 +85,7 @@ There is no separate nft burn event in the ERC721 contract, but a burn is just a
```yaml
- name: "NFT transfer"
type: generic
contractAddress: "0x01...EF"
contractAddress: "0x01...ef"
startBlockHeight: 7654321
abiPath: "./abis/ERC721.json"
eventSignature: "Transfer(address,address,uint256)"
Expand Down
47 changes: 47 additions & 0 deletions docs/home/3-react-to-events/2-chain-data-extensions/4-ERC6551.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# ERC6551 CDEs

- [ERC6551 Registry](#erc6551-registry), keeping track of registrations of Token-Bound Accounts (TBAs) on the chain

## ERC6551 Registry

### Example

```yaml
extensions:
- name: "ERC6551 Registry"
type: "erc6551-registry"
contractAddress: "0x01...ef" # optional. Uses the standardized ERC6551 registry by default
implementation: "0x01...ef" # optional. Filters to only TBAs created with a specific implementation
tokenContract: "0x01...ef" # optional. Filters to only TBAs for a specific NFT collection
tokenId: "1234" # optional. Filters to only TBAs for a specific token ID in the collection
salt: "1234" # optional. Filters to only TBAs generated with a specific salt. Note: this is not an `indexed` field in the contract, so this will not lower the number of RPC calls
startBlockHeight: 7654321
```
### Meaning
ERC6551 uses a [global registry](https://eips.ethereum.org/EIPS/eip-6551#registry) that where all TBAs are registered. This address is constant among all chains, and acts as an easy way to know all the TBAs deployed to the chain
This extension allows you to track all the TBAs that exist so that your game can easily aggregate state across different accounts owned by the same player, and it can allow you to treat specific kinds of TBA (ex: where the owner is a specific NFT for your game or a specific tool like [AWNS](https://www.stp.network)) differently.
### Utility functions
- `getErc6551AccountOwner`, fetch the NFT that owns this account:

```ts
export async function getErc6551AccountOwner(
readonlyDBConn: PoolClient,
cdeName: string,
accountCreated: string
): Promise<TokenIdPair | null>;
```

- `getAllOwnedErc6551Accounts`, fetch all accounts owned by this NFT. This call is NOT recursive:

```ts
export async function getErc6551AccountOwner(
readonlyDBConn: PoolClient,
cdeName: string,
nft: TokenIdPair
): Promise<string[]>;
```

0 comments on commit 68456ee

Please sign in to comment.