Skip to content

Commit

Permalink
feat: index transfer events
Browse files Browse the repository at this point in the history
  • Loading branch information
rabi-siddique committed May 29, 2024
1 parent f5e4ccb commit 31796b1
Show file tree
Hide file tree
Showing 8 changed files with 490 additions and 11 deletions.
13 changes: 13 additions & 0 deletions genesis-local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"balances": [
{
"address": "agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl",
"coins": [
{
"denom": "ubld",
"amount": "999999995000000000"
}
]
}
]
}
130 changes: 130 additions & 0 deletions genesis-main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
{
"balances": [
{
"address": "agoric1qc3r5tlh9ldvcg54lj8ukrwhytpffkmjxav87c",
"coins": [
{
"denom": "ubld",
"amount": "1000000"
}
]
},
{
"address": "agoric18du3gnu9qqgrcfln804g8gcmruv2gjwgs7mj3l",
"coins": [
{
"denom": "ubld",
"amount": "497000000"
}
]
},
{
"address": "agoric18c72hdqrcc4hkpewvpf7grrx8rawk0045g3tm0",
"coins": [
{
"amount": "200000000000000",
"denom": "ubld"
}
]
},
{
"address": "agoric18m9lqhqas8qrwafj92kta0ek2q96kwvyt84793",
"coins": [
{
"amount": "49999400000000",
"denom": "ubld"
}
]
},
{
"address": "agoric1grgelyng2v6v3t8z87wu3sxgt9m5s03x7dax7m",
"coins": [
{
"amount": "1000000",
"denom": "ubld"
}
]
},
{
"address": "agoric1gmru5vv2zrz9m0d3vwjz6fcchw9ddmq9w3s2qy",
"coins": [
{
"amount": "1000000",
"denom": "ubld"
}
]
},
{
"address": "agoric1fl48vsnmsdzcv85q5d2q4z5ajdha8yu38xtsfp",
"coins": [
{
"amount": "100000000",
"denom": "ubld"
}
]
},
{
"address": "agoric1w89nsqmcjfw9la2x8pk5k8pwwsgh8mhqs53tsr",
"coins": [
{
"amount": "300000000000000",
"denom": "ubld"
}
]
},
{
"address": "agoric10fz6uxxlg7pdkscgpzcny4z6lzhqcluyqhr8au",
"coins": [
{
"amount": "30000000000000",
"denom": "ubld"
}
]
},
{
"address": "agoric10mmdskqh6nv8tzd4lhzpevwlky35m43s45ssg5",
"coins": [
{
"amount": "125000000000000",
"denom": "ubld"
}
]
},
{
"address": "agoric1kxquj9rnprhyaq2laulgqznz7t6yqmw6wm5ucx",
"coins": [
{
"amount": "45000000000000",
"denom": "ubld"
}
]
},
{
"address": "agoric1euw2t0lxgeerlpj0tcy77f9syrmgx26ehdx3sq",
"coins": [
{
"amount": "100000000000000",
"denom": "ubld"
}
]
},
{
"address": "agoric1a0fktnlglcpj3pkzwftnr63uqr42mmcskuhakj",
"coins": [
{
"amount": "25000000000000",
"denom": "ubld"
}
]
},
{
"address": "agoric179gfr279yh3zhdw7aw85t7kj4vcsazdckzd42e",
"coins": [
{
"amount": "125000000000000",
"denom": "ubld"
}
]
}
]
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"pub": "subql publish",
"codegen": "subql codegen",
"start:docker": "docker-compose pull && docker-compose up --remove-orphans",
"dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans",
"dev": "network=local && subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans",
"prepack": "rm -rf dist && npm run build",
"test": "jest",
"subql": "subql codegen --help",
Expand Down
34 changes: 32 additions & 2 deletions project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ const project: CosmosProject = {
},
network: {
// chainId: "agoriclocal",
// endpoint: ["http://host.docker.internal:26657/"],
// endpoint: ["http://agoric-subql_agd_1:26657/"],
// chainId: "agoric-emerynet-8",
// endpoint: ["https://emerynet.rpc.agoric.net:443"],
chainId: "agoric-3",
endpoint: ["https://main-a.rpc.agoric.net:443"],

Expand Down Expand Up @@ -50,6 +52,20 @@ const project: CosmosProject = {
]),
},
dataSources: [
{
kind: CosmosDatasourceKind.Runtime,
startBlock: 1,
endBlock: 1,
mapping: {
file: "./dist/index.js",
handlers: [
{
kind: CosmosHandlerKind.Block,
handler: "initiateBalancesTable",
},
],
},
},
{
kind: CosmosDatasourceKind.Runtime,
// First block of mainnet is 2115669
Expand Down Expand Up @@ -107,11 +123,25 @@ const project: CosmosProject = {
type: "state_change",
},
},
{
handler: "handleBalanceEvent",
kind: CosmosHandlerKind.Event,
filter: {
type: "coin_received",
},
},
{
handler: "handleBalanceEvent",
kind: CosmosHandlerKind.Event,
filter: {
type: "coin_spent",
},
},
],
},
},
],
};

// Must set default to the project instance
export default project;
export default project;
17 changes: 13 additions & 4 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,6 @@ type ReserveMetrics @entity {
allocations: [ReserveAllocationMetrics] @derivedFrom(field: "reserveMetrics")
}

type Account @entity {
id: ID!
}

type IBCChannel @entity {
id: ID!
channelName: String!
Expand All @@ -268,3 +264,16 @@ type IBCTransfer @entity {
amount: String!
transferType: TransferType!
}

type Balance @entity {
id: ID!
address: String @index
balance: BigInt
denom: String @index
account: Account!
}

type Account @entity {
id: ID!
balances: [Balance] @derivedFrom(field: "account")
}
18 changes: 18 additions & 0 deletions src/mappings/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,24 @@ export const VAULT_STATES = {
LIQUIDATED: "liquidated",
};

export const BALANCE_FIELDS = {
amount: 'amount',
// Bank Events
coinbase: 'minter',
coin_received: 'receiver',
coin_spent: 'spender',
transfer_recipient: 'recipient',
transfer_sender: 'sender',
burn: "burner",
// Distribution Events
rewards: 'validator',
commission: 'validator',
proposer_reward: 'validator',
withdraw_rewards: 'validator',
withdraw_commission: 'validator',

};

export const VALUE_KEY = b64encode("value");
export const STORE_KEY = b64encode("store");
export const VSTORAGE_VALUE = b64encode("vstorage");
Expand Down
Loading

0 comments on commit 31796b1

Please sign in to comment.