Skip to content

Commit

Permalink
feat: index fastUsdc transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
turadg committed Jan 9, 2025
1 parent 1940c71 commit 449fd0b
Show file tree
Hide file tree
Showing 8 changed files with 971 additions and 28 deletions.
44 changes: 41 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,27 +109,65 @@ The fastest way to get support is by [searching our documentation](https://acade

## Developing

### Locally
### With A3P

1. Start up an A3P instance

```sh
docker run -p 26657:26657 -p 1317:1317 -p 9090:9090 ghcr.io/agoric/agoric-3-proposals:latest
```

2. Start up the Indexer
Or with a proposal that you've built in a3p-integration,

```sh
docker run -p 26657:26657 -p 1317:1317 -p 9090:9090 ghcr.io/agoric/agoric-3-proposals:use-fast-usdc
```

2. Confirm the data is visible with [vstorage viewer](https://vstorage.agoric.net/?endpoint=http%3A%2F%2Flocalhost%3A26657)

3. Start up the Indexer
After the A3P instance is up and running, initiate the indexer with the following command:

```sh
AGORIC_NET=docker yarn dev
```

3. Accessing the GraphQL Interface
4. Access the GraphQL playground
Once the indexer is operational, access the GraphQL interface to query indexed data:

- Open a web browser and navigate to http://localhost:3000.
- Use the provided interface to write and execute your GraphQL queries.

### With multichain-testing

Make some transactions.

```sh
cd multichain-testing && yarn
make setup # if you've never ran starship
docker pull ghcr.io/agoric/agoric-sdk:dev # to make sure you have the latest IBC hooks changes
make stop
make start FILE=config.fusdc.yaml # wait ~7 mins
yarn test:fast-usdc test/fast-usdc/fast-usdc.test.ts
```

View [published.fastUsdc](https://vstorage.agoric.net/?endpoint=http%3A%2F%2Flocalhost%3A26657&path=published.fastUsdc)

Start a fresh indexer:

```sh
scripts/restart-dev.sh
```

Play at http://localhost:3000/

Cleanup…

```sh
cd multichain-testing
make stop
```

### Troubleshooting the Indexer

If you encounter issues with the indexer:
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"author": "Agoric OpCo",
"license": "Apache-2.0",
"devDependencies": {
"@agoric/fast-usdc": "0.2.0-u18.0",
"@agoric/inter-protocol": "0.17.0-u18.6",
"@agoric/internal": "0.4.0-u18.1",
"@agoric/smart-wallet": "0.5.4-u18.5",
Expand Down
21 changes: 21 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,24 @@ type BundleInstall @entity {
compressedBundle: String!
submitter: String!
}

enum FastUsdcTransactionStatus {
OBSERVED
ADVANCING
ADVANCED
ADVANCE_FAILED
FORWARDING
FORWARDED
FORWARD_FAILED
DISBURSED
}

type FastUsdcTransaction @entity {
id: ID!
sourceAddress: String! @index
eud: String!
usdcAmount: BigInt!
status: FastUsdcTransactionStatus! @index
contractFee: BigInt
poolFee: BigInt
}
14 changes: 14 additions & 0 deletions scripts/restart-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
set -ueo pipefail

# clean
docker compose --profile default down
rm -rf .data

# build
yarn subql codegen >/dev/null
AGORIC_NET=docker yarn subql build >/dev/null
grep --silent host.docker.internal project.yaml || exit 1

# run
docker compose --profile default up --remove-orphans
122 changes: 122 additions & 0 deletions src/mappings/events/fastUsdc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
# Fast USDC events

## Transaction

Supports queries like,

```graphql
{
_metadata {
lastProcessedHeight
}
fastUsdcTransactions {
totalCount
edges {
node {
contractFee
eud
nodeId
id
poolFee
sourceAddress
status
usdcAmount
}
}
}
fastUsdcTransaction(id: "0xc81bc6105b60a234c7c50ac17816ebcd5561d366df8bf3be59ff387552761786") {
id
sourceAddress
usdcAmount
contractFee
eud
nodeId
poolFee
status
}
stateChangeEvents(last: 4) {
nodes {
id
}
}
}
```

Resulting in something like,

```json
{
"data": {
"_metadata": {
"lastProcessedHeight": 9141
},
"fastUsdcTransactions": {
"totalCount": 3,
"edges": [
{
"node": {
"contractFee": "1002000",
"eud": "agoric10rchpd57ggt73kmr5dssunm53jwz75pa8jjtav2ytcgwtr8fn0h5yalx8az423padaek6me30fmhzapsdqm8xwtevy6h5dpnd568jvms89m8v6nxxuexkut3ddnx663nxfuk5qpqjw8vq8",
"nodeId": "WyJmYXN0X3VzZGNfdHJhbnNhY3Rpb25zIiwiMzE4YzcxMDQtYzgxYS00ZTAyLTliNmYtOTBhYmFiODVkYmZkIl0=",
"id": "0xc81bc6105b60a234c7c50ac17816ebcd5561d366df8bf3be59ff387552761795",
"poolFee": "4008000",
"sourceAddress": "0x9a9eE9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9",
"status": "DISBURSED",
"usdcAmount": "2000000000"
}
},
{
"node": {
"contractFee": "1002000",
"eud": "agoric10rchpd57ggt73kmr5dssunm53jwz75pa8jjtav2ytcgwtr8fn0h5yalx8az423pav9nk7unfvvchwenhxdnrsmpevcekxu34wgekgvn4xd5r2mr5dpe8za3h0yenywtw0yehqdpsqqsqlnd2q6",
"nodeId": "WyJmYXN0X3VzZGNfdHJhbnNhY3Rpb25zIiwiNmIxZjQwODgtOTdmZC00MGJmLWE3YWItY2U3OTZmNjAzNTRhIl0=",
"id": "0xc81bc6105b60a234c7c50ac17816ebcd5561d366df8bf3be59ff387552761707",
"poolFee": "4008000",
"sourceAddress": "0x9a9eE9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9",
"status": "DISBURSED",
"usdcAmount": "1600000000"
}
},
{
"node": {
"contractFee": "1002000",
"eud": "agoric10rchpd57ggt73kmr5dssunm53jwz75pa8jjtav2ytcgwtr8fn0h5yalx8az423padehkymr9xyehvcmkxaehwv3swsu8gar6wc6rwupewq6kuunhxe58wdm6dfcrsm3jvdeku6qqyqjvq49q",
"nodeId": "WyJmYXN0X3VzZGNfdHJhbnNhY3Rpb25zIiwiOTQxMWMyYTgtYjAwYS00ZjgzLWJlY2MtMDU3OTU5YmUwYzk0Il0=",
"id": "0xc81bc6105b60a234c7c50ac17816ebcd5561d366df8bf3be59ff387552761786",
"poolFee": "4008000",
"sourceAddress": "0x9a9eE9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9",
"status": "DISBURSED",
"usdcAmount": "1000000000"
}
}
]
},
"fastUsdcTransaction": {
"id": "0xc81bc6105b60a234c7c50ac17816ebcd5561d366df8bf3be59ff387552761786",
"sourceAddress": "0x9a9eE9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9e9",
"usdcAmount": "1000000000",
"contractFee": "1002000",
"eud": "agoric10rchpd57ggt73kmr5dssunm53jwz75pa8jjtav2ytcgwtr8fn0h5yalx8az423padehkymr9xyehvcmkxaehwv3swsu8gar6wc6rwupewq6kuunhxe58wdm6dfcrsm3jvdeku6qqyqjvq49q",
"nodeId": "WyJmYXN0X3VzZGNfdHJhbnNhY3Rpb25zIiwiOTQxMWMyYTgtYjAwYS00ZjgzLWJlY2MtMDU3OTU5YmUwYzk0Il0=",
"poolFee": "4008000",
"status": "DISBURSED"
},
"stateChangeEvents": {
"nodes": [
{
"id": "6555:18:0"
},
{
"id": "303:17:1"
},
{
"id": "301:22:2"
},
{
"id": "415:18:0"
}
]
}
}
}
```
40 changes: 40 additions & 0 deletions src/mappings/events/fastUsdc.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import type { TransactionRecord } from '@agoric/fast-usdc/src/types';
import type { StreamCell } from '@agoric/internal/src/lib-chainStorage';
import type { CosmosBlock } from '@subql/types-cosmos';
import assert from 'assert';
import { FastUsdcTransaction, FastUsdcTransactionStatus } from '../../types';

export const transactionEventKit = (block: CosmosBlock, data: StreamCell, module: string, path: string) => {
async function saveTransaction(payload: TransactionRecord): Promise<Promise<any>[]> {
logger.info(`saveTransaction ${JSON.stringify(payload)}`);
// extract the segment after the last period
const id = path.split('.').pop();
assert(id, 'saveTransaction must only be called on transaction paths');

let t: FastUsdcTransaction;
if (payload.status === FastUsdcTransactionStatus.OBSERVED) {
assert(payload['evidence'], 'implied by OBSERVED');
assert.equal(payload.evidence.txHash, id, 'txHash must match path');
t = FastUsdcTransaction.create({
id,
eud: payload.evidence?.aux.recipientAddress,
sourceAddress: payload.evidence?.tx.sender,
status: payload.status,
usdcAmount: payload.evidence?.tx.amount,
});
} else {
const found = await FastUsdcTransaction.get(id);
assert(found, 'no matching transaction');
t = found;
t.status = payload.status;
if (payload.split) {
t.contractFee = payload.split.ContractFee.value;
t.poolFee = payload.split.PoolFee.value;
}
}

return [t.save()];
}

return { saveTransaction };
};
Loading

0 comments on commit 449fd0b

Please sign in to comment.