Skip to content

Commit

Permalink
Separate EVM and Cardano primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Jan 6, 2024
1 parent f757ca1 commit 74a83e4
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"label": "EVM Primitives"
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
# Cardano Primitives

- [Stake Delegation](#stake-delegation).
- [Delayed asset](#delayed-asset).

## Stake Delegation {#stake-delegation}
# Pool Delegation {#stake-delegation}

### Example

Expand Down Expand Up @@ -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<CardanoAssetUtxo[]>;
export declare function getCardanoAssetUtxosByPolicyId(
readonlyDBConn: Pool,
address: string,
policyId: string
): Promise<CardanoAssetUtxo[]>;
```
Original file line number Diff line number Diff line change
@@ -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<CardanoAssetUtxo[]>;
export declare function getCardanoAssetUtxosByPolicyId(
readonlyDBConn: Pool,
address: string,
policyId: string
): Promise<CardanoAssetUtxo[]>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"label": "Cardano Primitives"
}
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand Down

0 comments on commit 74a83e4

Please sign in to comment.