From 74a83e4ead6fbc7672c64366aa4b939fb6bf9b94 Mon Sep 17 00:00:00 2001 From: Sebastien Guillemot Date: Sat, 6 Jan 2024 11:28:40 +0900 Subject: [PATCH] Separate EVM and Cardano primitives --- .../{ => 10-evm}/2-ERC20.md | 0 .../{ => 10-evm}/3-ERC721.md | 0 .../{ => 10-evm}/4-ERC6551.md | 0 .../{ => 10-evm}/999-Generic.md | 0 .../10-evm/_category_.json | 3 + .../10-stakepools.md} | 71 +------------------ .../20-cardano/20-delayed-state.md | 71 +++++++++++++++++++ .../20-cardano/_category_.json | 3 + .../2000-create-your-own.md | 2 +- .../3-funnel-types/4-carp-funnel.md | 2 +- 10 files changed, 80 insertions(+), 72 deletions(-) rename docs/home/300-react-to-events/2-primitive-catalogue/{ => 10-evm}/2-ERC20.md (100%) rename docs/home/300-react-to-events/2-primitive-catalogue/{ => 10-evm}/3-ERC721.md (100%) rename docs/home/300-react-to-events/2-primitive-catalogue/{ => 10-evm}/4-ERC6551.md (100%) rename docs/home/300-react-to-events/2-primitive-catalogue/{ => 10-evm}/999-Generic.md (100%) create mode 100644 docs/home/300-react-to-events/2-primitive-catalogue/10-evm/_category_.json rename docs/home/300-react-to-events/2-primitive-catalogue/{1000-cardano.md => 20-cardano/10-stakepools.md} (52%) create mode 100644 docs/home/300-react-to-events/2-primitive-catalogue/20-cardano/20-delayed-state.md create mode 100644 docs/home/300-react-to-events/2-primitive-catalogue/20-cardano/_category_.json diff --git a/docs/home/300-react-to-events/2-primitive-catalogue/2-ERC20.md b/docs/home/300-react-to-events/2-primitive-catalogue/10-evm/2-ERC20.md similarity index 100% rename from docs/home/300-react-to-events/2-primitive-catalogue/2-ERC20.md rename to docs/home/300-react-to-events/2-primitive-catalogue/10-evm/2-ERC20.md diff --git a/docs/home/300-react-to-events/2-primitive-catalogue/3-ERC721.md b/docs/home/300-react-to-events/2-primitive-catalogue/10-evm/3-ERC721.md similarity index 100% rename from docs/home/300-react-to-events/2-primitive-catalogue/3-ERC721.md rename to docs/home/300-react-to-events/2-primitive-catalogue/10-evm/3-ERC721.md diff --git a/docs/home/300-react-to-events/2-primitive-catalogue/4-ERC6551.md b/docs/home/300-react-to-events/2-primitive-catalogue/10-evm/4-ERC6551.md similarity index 100% rename from docs/home/300-react-to-events/2-primitive-catalogue/4-ERC6551.md rename to docs/home/300-react-to-events/2-primitive-catalogue/10-evm/4-ERC6551.md diff --git a/docs/home/300-react-to-events/2-primitive-catalogue/999-Generic.md b/docs/home/300-react-to-events/2-primitive-catalogue/10-evm/999-Generic.md similarity index 100% rename from docs/home/300-react-to-events/2-primitive-catalogue/999-Generic.md rename to docs/home/300-react-to-events/2-primitive-catalogue/10-evm/999-Generic.md diff --git a/docs/home/300-react-to-events/2-primitive-catalogue/10-evm/_category_.json b/docs/home/300-react-to-events/2-primitive-catalogue/10-evm/_category_.json new file mode 100644 index 00000000..134c5b5f --- /dev/null +++ b/docs/home/300-react-to-events/2-primitive-catalogue/10-evm/_category_.json @@ -0,0 +1,3 @@ +{ + "label": "EVM Primitives" + } \ No newline at end of file diff --git a/docs/home/300-react-to-events/2-primitive-catalogue/1000-cardano.md b/docs/home/300-react-to-events/2-primitive-catalogue/20-cardano/10-stakepools.md similarity index 52% rename from docs/home/300-react-to-events/2-primitive-catalogue/1000-cardano.md rename to docs/home/300-react-to-events/2-primitive-catalogue/20-cardano/10-stakepools.md index cf2733e6..0dc47b3d 100644 --- a/docs/home/300-react-to-events/2-primitive-catalogue/1000-cardano.md +++ b/docs/home/300-react-to-events/2-primitive-catalogue/20-cardano/10-stakepools.md @@ -1,9 +1,4 @@ -# Cardano Primitives - -- [Stake Delegation](#stake-delegation). -- [Delayed asset](#delayed-asset). - -## Stake Delegation {#stake-delegation} +# Pool Delegation {#stake-delegation} ### Example @@ -81,67 +76,3 @@ if (stakingCred) { getCardanoAddressDelegation(dbConn, walletAddress); ``` - -## Delayed asset {#delayed-asset} - -### Example - -```yaml -extensions: - - name: "delayed-asset1" - type: cardano-delayed-asset - fingerprints: - - "asset1c43p68zwjezc7aaaaaaaaaaaaaaaaaaaaaaaaa" - - "asset1c43p68zwjezc7bbbbbbbbbbbbbbbbbbbbbbbbb" - - "asset1c43p68zwjezc7ccccccccccccccccccccccccc" - policyIds: - - "919d4c2c9455016289341b1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" - - "919d4c2c9455016289341b1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" - startSlot: 22505578 - stopSlot: 32815924 -``` - -### Meaning - -- `startSlot` is required and means that only events after that slot (exclusive) - will be considered. This should be a slot that happened before the first - transaction involving the assets. -- `stopSlot` is optional, and it stops the indexing at that point. -- `fingerprints` and `policyIds` select the assets to be indexed. It's not -necessary to provide both. -- `fingerprints` takes the cip14 fingerprint in bech32, and indexes a single -asset (per entry in the array). -- `policyIds` will instead index all the assets in that policy. - -### Utility functions - -There are two functions that can be used to get the utxo entries for an address. -Depending on whether the filtering is done by fingerprint or by policy id. Note -that this doesn't necessarily return one entry per utxo, since each entry is for -a single asset. This means there may be more than one entry in the array with -the same `txId-outputIndex` pair. This can happen when filtering by policy id, -because an output have more than one asset. In that case, the `assetName` can -be used to discriminate. - -```ts -export interface CardanoAssetUtxo { - txId: string; - outputIndex: number; - amount: string; - policyId: string; - assetName: string; -} - -export declare function getCardanoAssetUtxosByFingerprint( - readonlyDBConn: Pool, - address: string, - cip14Fingerprint: string -): Promise; - - -export declare function getCardanoAssetUtxosByPolicyId( - readonlyDBConn: Pool, - address: string, - policyId: string -): Promise; -``` diff --git a/docs/home/300-react-to-events/2-primitive-catalogue/20-cardano/20-delayed-state.md b/docs/home/300-react-to-events/2-primitive-catalogue/20-cardano/20-delayed-state.md new file mode 100644 index 00000000..524f7fa0 --- /dev/null +++ b/docs/home/300-react-to-events/2-primitive-catalogue/20-cardano/20-delayed-state.md @@ -0,0 +1,71 @@ +# Delayed State + +Different blockchains may have different block times & finality, so trying to guarantee the state of blockchain A from blockchain B often requires timelock systems like [projected data](../../../700-multichain-support/1-projected-nfts/1-introduction.mdx). + +However, not all use-cases care about having the data entirely up-to-date. For example, NFT-gated features should work even if your knowledge of whether or not the user owns an NFT is 5 minutes delayed. That is to say, delayed data is **not** guaranteed to be up-to-date (hence *delayed*) + +This delay is also generically unavoidable with chains that don't have instant finality like Cardano as we generally want our app to update only with changes that have been finalized (which takes time). + +## Delayed asset {#delayed-asset} + +### Example + +```yaml +extensions: + - name: "delayed-asset1" + type: cardano-delayed-asset + fingerprints: + - "asset1c43p68zwjezc7aaaaaaaaaaaaaaaaaaaaaaaaa" + - "asset1c43p68zwjezc7bbbbbbbbbbbbbbbbbbbbbbbbb" + - "asset1c43p68zwjezc7ccccccccccccccccccccccccc" + policyIds: + - "919d4c2c9455016289341b1aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" + - "919d4c2c9455016289341b1bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + startSlot: 22505578 + stopSlot: 32815924 +``` + +### Meaning + +- `startSlot` is required and means that only events after that slot (exclusive) + will be considered. This should be a slot that happened before the first + transaction involving the assets. +- `stopSlot` is optional, and it stops the indexing at that point. +- `fingerprints` and `policyIds` select the assets to be indexed. It's not +necessary to provide both. +- `fingerprints` takes the cip14 fingerprint in bech32, and indexes a single +asset (per entry in the array). +- `policyIds` will instead index all the assets in that policy. + +### Utility functions + +There are two functions that can be used to get the utxo entries for an address. +Depending on whether the filtering is done by fingerprint or by policy id. Note +that this doesn't necessarily return one entry per utxo, since each entry is for +a single asset. This means there may be more than one entry in the array with +the same `txId-outputIndex` pair. This can happen when filtering by policy id, +because an output have more than one asset. In that case, the `assetName` can +be used to discriminate. + +```ts +export interface CardanoAssetUtxo { + txId: string; + outputIndex: number; + amount: string; + policyId: string; + assetName: string; +} + +export declare function getCardanoAssetUtxosByFingerprint( + readonlyDBConn: Pool, + address: string, + cip14Fingerprint: string +): Promise; + + +export declare function getCardanoAssetUtxosByPolicyId( + readonlyDBConn: Pool, + address: string, + policyId: string +): Promise; +``` diff --git a/docs/home/300-react-to-events/2-primitive-catalogue/20-cardano/_category_.json b/docs/home/300-react-to-events/2-primitive-catalogue/20-cardano/_category_.json new file mode 100644 index 00000000..33417403 --- /dev/null +++ b/docs/home/300-react-to-events/2-primitive-catalogue/20-cardano/_category_.json @@ -0,0 +1,3 @@ +{ + "label": "Cardano Primitives" + } \ No newline at end of file diff --git a/docs/home/300-react-to-events/2-primitive-catalogue/2000-create-your-own.md b/docs/home/300-react-to-events/2-primitive-catalogue/2000-create-your-own.md index 821891fc..ec926745 100644 --- a/docs/home/300-react-to-events/2-primitive-catalogue/2000-create-your-own.md +++ b/docs/home/300-react-to-events/2-primitive-catalogue/2000-create-your-own.md @@ -1,6 +1,6 @@ # Create your own Primitive -Although custom Primitives do not have to be added to Paima (people can just use the [generic Primitive](./999-Generic.md), adding a Primitive to Paima itself helps both with usability and with type inference. +Although custom Primitives do not always have to be added to Paima (people can just use the [Generic EVM Primitive](./10-evm/999-Generic.md)), adding a Primitive to Paima itself helps both with usability and with type inference. To add a custom Primitive to Paima, you need to do the following: diff --git a/docs/home/300-react-to-events/3-funnel-types/4-carp-funnel.md b/docs/home/300-react-to-events/3-funnel-types/4-carp-funnel.md index be76a61e..0d82fb68 100644 --- a/docs/home/300-react-to-events/3-funnel-types/4-carp-funnel.md +++ b/docs/home/300-react-to-events/3-funnel-types/4-carp-funnel.md @@ -1,6 +1,6 @@ # Carp funnel -This funnel allows using Cardano Primitives. It's enabled when the `CARP_URL` variable is present. Additionally, `CARDANO_NETWORK` needs to be set in order to be able to deterministically associate Cardano slots with the EVM blocks, and `CARDANO_CONFIRMATION_DEPTH` needs to be set so that the funnel can know when a block is considered stable. +This funnel allows using Cardano Primitives leveraging [Carp](https://dcspark.github.io/carp/docs/intro). It's enabled when the `CARP_URL` variable is present. Additionally, `CARDANO_NETWORK` needs to be set in order to be able to deterministically associate Cardano slots with the EVM blocks, and `CARDANO_CONFIRMATION_DEPTH` needs to be set so that the funnel can know when a block is considered stable. ## Requirements