Skip to content

Commit 75f3708

Browse files
committed
feat: index transfer events
1 parent 49d5bd3 commit 75f3708

8 files changed

+503
-27
lines changed

genesis-local.json

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"balances": [
3+
{
4+
"address": "agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl",
5+
"coins": [
6+
{
7+
"denom": "ubld",
8+
"amount": "999999995000000000"
9+
}
10+
]
11+
}
12+
]
13+
}

genesis-main.json

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"balances": [
3+
{
4+
"address": "agoric1qc3r5tlh9ldvcg54lj8ukrwhytpffkmjxav87c",
5+
"coins": [
6+
{
7+
"denom": "ubld",
8+
"amount": "1000000"
9+
}
10+
]
11+
},
12+
{
13+
"address": "agoric18du3gnu9qqgrcfln804g8gcmruv2gjwgs7mj3l",
14+
"coins": [
15+
{
16+
"denom": "ubld",
17+
"amount": "497000000"
18+
}
19+
]
20+
},
21+
{
22+
"address": "agoric18c72hdqrcc4hkpewvpf7grrx8rawk0045g3tm0",
23+
"coins": [
24+
{
25+
"amount": "200000000000000",
26+
"denom": "ubld"
27+
}
28+
]
29+
},
30+
{
31+
"address": "agoric18m9lqhqas8qrwafj92kta0ek2q96kwvyt84793",
32+
"coins": [
33+
{
34+
"amount": "49999400000000",
35+
"denom": "ubld"
36+
}
37+
]
38+
},
39+
{
40+
"address": "agoric1grgelyng2v6v3t8z87wu3sxgt9m5s03x7dax7m",
41+
"coins": [
42+
{
43+
"amount": "1000000",
44+
"denom": "ubld"
45+
}
46+
]
47+
},
48+
{
49+
"address": "agoric1gmru5vv2zrz9m0d3vwjz6fcchw9ddmq9w3s2qy",
50+
"coins": [
51+
{
52+
"amount": "1000000",
53+
"denom": "ubld"
54+
}
55+
]
56+
},
57+
{
58+
"address": "agoric1fl48vsnmsdzcv85q5d2q4z5ajdha8yu38xtsfp",
59+
"coins": [
60+
{
61+
"amount": "100000000",
62+
"denom": "ubld"
63+
}
64+
]
65+
},
66+
{
67+
"address": "agoric1w89nsqmcjfw9la2x8pk5k8pwwsgh8mhqs53tsr",
68+
"coins": [
69+
{
70+
"amount": "300000000000000",
71+
"denom": "ubld"
72+
}
73+
]
74+
},
75+
{
76+
"address": "agoric10fz6uxxlg7pdkscgpzcny4z6lzhqcluyqhr8au",
77+
"coins": [
78+
{
79+
"amount": "30000000000000",
80+
"denom": "ubld"
81+
}
82+
]
83+
},
84+
{
85+
"address": "agoric10mmdskqh6nv8tzd4lhzpevwlky35m43s45ssg5",
86+
"coins": [
87+
{
88+
"amount": "125000000000000",
89+
"denom": "ubld"
90+
}
91+
]
92+
},
93+
{
94+
"address": "agoric1kxquj9rnprhyaq2laulgqznz7t6yqmw6wm5ucx",
95+
"coins": [
96+
{
97+
"amount": "45000000000000",
98+
"denom": "ubld"
99+
}
100+
]
101+
},
102+
{
103+
"address": "agoric1euw2t0lxgeerlpj0tcy77f9syrmgx26ehdx3sq",
104+
"coins": [
105+
{
106+
"amount": "100000000000000",
107+
"denom": "ubld"
108+
}
109+
]
110+
},
111+
{
112+
"address": "agoric1a0fktnlglcpj3pkzwftnr63uqr42mmcskuhakj",
113+
"coins": [
114+
{
115+
"amount": "25000000000000",
116+
"denom": "ubld"
117+
}
118+
]
119+
},
120+
{
121+
"address": "agoric179gfr279yh3zhdw7aw85t7kj4vcsazdckzd42e",
122+
"coins": [
123+
{
124+
"amount": "125000000000000",
125+
"denom": "ubld"
126+
}
127+
]
128+
}
129+
]
130+
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"pub": "subql publish",
99
"codegen": "subql codegen",
1010
"start:docker": "docker-compose pull && docker-compose up --remove-orphans",
11-
"dev": "subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans",
11+
"dev": "network=local && subql codegen && subql build && docker-compose pull && docker-compose up --remove-orphans",
1212
"prepack": "rm -rf dist && npm run build",
1313
"test": "jest",
1414
"subql": "subql codegen --help",

project.ts

+32-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ const project: CosmosProject = {
2121
},
2222
network: {
2323
// chainId: "agoriclocal",
24-
// endpoint: ["http://host.docker.internal:26657/"],
24+
// endpoint: ["http://agoric-subql_agd_1:26657/"],
25+
// chainId: "agoric-emerynet-8",
26+
// endpoint: ["https://emerynet.rpc.agoric.net:443"],
2527
chainId: "agoric-3",
2628
endpoint: ["https://main-a.rpc.agoric.net:443"],
2729

@@ -50,6 +52,20 @@ const project: CosmosProject = {
5052
]),
5153
},
5254
dataSources: [
55+
{
56+
kind: CosmosDatasourceKind.Runtime,
57+
startBlock: 1,
58+
endBlock: 1,
59+
mapping: {
60+
file: "./dist/index.js",
61+
handlers: [
62+
{
63+
kind: CosmosHandlerKind.Block,
64+
handler: "initiateBalancesTable",
65+
},
66+
],
67+
},
68+
},
5369
{
5470
kind: CosmosDatasourceKind.Runtime,
5571
// First block of mainnet is 2115669
@@ -107,11 +123,25 @@ const project: CosmosProject = {
107123
type: "state_change",
108124
},
109125
},
126+
{
127+
handler: "handleBalanceEvent",
128+
kind: CosmosHandlerKind.Event,
129+
filter: {
130+
type: "coin_received",
131+
},
132+
},
133+
{
134+
handler: "handleBalanceEvent",
135+
kind: CosmosHandlerKind.Event,
136+
filter: {
137+
type: "coin_spent",
138+
},
139+
},
110140
],
111141
},
112142
},
113143
],
114144
};
115145

116146
// Must set default to the project instance
117-
export default project;
147+
export default project;

schema.graphql

+14-4
Original file line numberDiff line numberDiff line change
@@ -266,10 +266,6 @@ type ReserveMetrics @entity {
266266
allocations: [ReserveAllocationMetrics] @derivedFrom(field: "reserveMetrics")
267267
}
268268

269-
type Account @entity {
270-
id: ID!
271-
}
272-
273269
type IBCChannel @entity {
274270
id: ID!
275271
channelName: String!
@@ -293,6 +289,7 @@ type IBCTransfer @entity {
293289
transferType: TransferType!
294290
}
295291

292+
<<<<<<< HEAD
296293
type VaultStatesDaily @entity {
297294
id: ID!
298295
blockHeightLast: BigInt!
@@ -302,4 +299,17 @@ type VaultStatesDaily @entity {
302299
liquidating: BigInt!
303300
liquidated: BigInt!
304301
liquidatedClosed: BigInt!
302+
=======
303+
type Balance @entity {
304+
id: ID!
305+
address: String @index
306+
balance: BigInt
307+
denom: String @index
308+
account: Account!
309+
}
310+
311+
type Account @entity {
312+
id: ID!
313+
balances: [Balance] @derivedFrom(field: "account")
314+
>>>>>>> 31796b18 (feat: index transfer events)
305315
}

src/mappings/constants.ts

+38-20
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,41 @@ export const VAULT_STATES = {
3131
LIQUIDATED_CLOSED: 'liquidatedClosed',
3232
};
3333

34-
export const VALUE_KEY = b64encode('value');
35-
export const STORE_KEY = b64encode('store');
36-
export const VSTORAGE_VALUE = b64encode('vstorage');
37-
export const KEY_KEY = b64encode('key');
38-
export const STORE_NAME_KEY = b64encode('store_name');
39-
export const SUBKEY_KEY = b64encode('store_subkey');
40-
export const UNPROVED_VALUE_KEY = b64encode('unproved_value');
41-
export const PACKET_DATA_KEY = 'packet_data';
42-
export const PACKET_SRC_CHANNEL_KEY = 'packet_src_channel';
43-
export const PACKET_DST_CHANNEL_KEY = 'packet_dst_channel';
44-
export const PACKET_SRC_PORT_KEY = 'packet_src_port';
45-
export const PACKET_DST_PORT_KEY = 'packet_dst_port';
46-
export const ACTION_KEY = b64encode('action');
47-
export const IBC_MESSAGE_TRANSFER_VALUE = b64encode('/ibc.applications.transfer.v1.MsgTransfer');
48-
export const IBC_MESSAGE_RECEIVE_PACKET_VALUE = b64encode('/ibc.core.channel.v1.MsgRecvPacket');
49-
export const RECEPIENT_KEY = b64encode('recipient');
50-
export const SENDER_KEY = b64encode('sender');
51-
export const RECEIVER_KEY = b64encode('receiver');
52-
export const AMOUNT_KEY = b64encode('amount');
53-
export const TRANSFER_PORT_VALUE = 'transfer';
34+
export const BALANCE_FIELDS = {
35+
amount: 'amount',
36+
// Bank Events
37+
coinbase: 'minter',
38+
coin_received: 'receiver',
39+
coin_spent: 'spender',
40+
transfer_recipient: 'recipient',
41+
transfer_sender: 'sender',
42+
burn: "burner",
43+
// Distribution Events
44+
rewards: 'validator',
45+
commission: 'validator',
46+
proposer_reward: 'validator',
47+
withdraw_rewards: 'validator',
48+
withdraw_commission: 'validator',
49+
50+
};
51+
52+
export const VALUE_KEY = b64encode("value");
53+
export const STORE_KEY = b64encode("store");
54+
export const VSTORAGE_VALUE = b64encode("vstorage");
55+
export const KEY_KEY = b64encode("key");
56+
export const STORE_NAME_KEY = b64encode("store_name");
57+
export const SUBKEY_KEY = b64encode("store_subkey");
58+
export const UNPROVED_VALUE_KEY = b64encode("unproved_value");
59+
export const PACKET_DATA_KEY = "packet_data";
60+
export const PACKET_SRC_CHANNEL_KEY = "packet_src_channel";
61+
export const PACKET_DST_CHANNEL_KEY = "packet_dst_channel";
62+
export const PACKET_SRC_PORT_KEY = "packet_src_port";
63+
export const PACKET_DST_PORT_KEY = "packet_dst_port";
64+
export const ACTION_KEY = b64encode("action");
65+
export const IBC_MESSAGE_TRANSFER_VALUE = b64encode("/ibc.applications.transfer.v1.MsgTransfer");
66+
export const IBC_MESSAGE_RECEIVE_PACKET_VALUE = b64encode("/ibc.core.channel.v1.MsgRecvPacket");
67+
export const RECEPIENT_KEY = b64encode("recipient");
68+
export const SENDER_KEY = b64encode("sender");
69+
export const RECEIVER_KEY = b64encode("receiver");
70+
export const AMOUNT_KEY = b64encode("amount");
71+
export const TRANSFER_PORT_VALUE = "transfer";

0 commit comments

Comments
 (0)