Skip to content

Commit 2579c14

Browse files
committed
feat: add multisend support, fix counts on reinserts
1 parent e1b8924 commit 2579c14

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

packages/subgraph/package.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@
66
"codegen": "yarn && graph codegen",
77
"test": "yarn && yarn prep:test && yarn codegen && graph test",
88
"build": "yarn && yarn prepare && graph build",
9-
"deploy-mainnet": "yarn && yarn prep:mainnet && yarn codegen && graph build --network mainnet && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/mainnet-epoch-block-oracle",
10-
"deploy-arbitrum": "yarn && yarn prep:arbitrum && yarn codegen && graph build --network arbitrum-one && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/arbitrum-epoch-block-oracle",
11-
"deploy-goerli": "yarn && yarn prep:goerli && yarn codegen && graph build --network goerli && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/goerli-epoch-block-oracle",
12-
"deploy-arbitrum-goerli": "yarn && yarn prep:arbitrum-goerli && yarn codegen && graph build --network arbitrum-goerli && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/arb-goerli-epoch-block-oracle",
13-
"deploy-sepolia": "yarn && yarn prep:sepolia && yarn codegen && graph build --network sepolia && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/sepolia-epoch-block-oracle",
14-
"deploy-arbitrum-sepolia": "yarn && yarn prep:arbitrum-sepolia && yarn codegen && graph build --network arbitrum-sepolia && graph deploy --node https://api.thegraph.com/deploy/ graphprotocol/arbitrum-sepolia-ebo",
9+
"deploy-mainnet": "yarn && yarn prep:mainnet && yarn codegen && graph build --network mainnet && graph deploy --studio graph-ebo-ethereum",
10+
"deploy-arbitrum": "yarn && yarn prep:arbitrum && yarn codegen && graph build --network arbitrum-one && graph deploy --studio graph-ebo-arbitrum",
11+
"deploy-sepolia": "yarn && yarn prep:sepolia && yarn codegen && graph build --network sepolia && graph deploy --studio graph-ebo-sepolia",
12+
"deploy-arbitrum-sepolia": "yarn && yarn prep:arbitrum-sepolia && yarn codegen && graph build --network arbitrum-sepolia && graph deploy --studio graph-ebo-arbitrum-sepolia",
1513
"create-local": "graph create --node http://127.0.0.1:8020/ edgeandnode/block-oracle",
1614
"remove-local": "graph remove --node http://127.0.0.1:8020/ edgeandnode/block-oracle",
1715
"deploy-local": "yarn codegen && graph deploy --node http://127.0.0.1:8020/ --ipfs http://localhost:${IPFS_PORT} edgeandnode/block-oracle --version-label 0.1.0",
1816
"prep:local": "mustache ./config/local.json subgraph.template.yaml > subgraph.yaml && mustache ./config/local.json src/constants.template.ts > src/constants.ts",
1917
"prep:test": "mustache ./config/test.json subgraph.template.yaml > subgraph.yaml && mustache ./config/test.json src/constants.template.ts > src/constants.ts",
2018
"prep:mainnet": "mustache ./config/mainnet.json subgraph.template.yaml > subgraph.yaml && mustache ./config/mainnet.json src/constants.template.ts > src/constants.ts",
2119
"prep:arbitrum": "mustache ./config/arbitrum.json subgraph.template.yaml > subgraph.yaml && mustache ./config/arbitrum.json src/constants.template.ts > src/constants.ts",
22-
"prep:goerli": "mustache ./config/goerli.json subgraph.template.yaml > subgraph.yaml && mustache ./config/goerli.json src/constants.template.ts > src/constants.ts",
23-
"prep:arbitrum-goerli": "mustache ./config/arbitrum-goerli.json subgraph.template.yaml > subgraph.yaml && mustache ./config/arbitrum-goerli.json src/constants.template.ts > src/constants.ts",
2420
"prep:sepolia": "mustache ./config/sepolia.json subgraph.template.yaml > subgraph.yaml && mustache ./config/sepolia.json src/constants.template.ts > src/constants.ts",
2521
"prep:arbitrum-sepolia": "mustache ./config/arbitrum-sepolia.json subgraph.template.yaml > subgraph.yaml && mustache ./config/arbitrum-sepolia.json src/constants.template.ts > src/constants.ts"
2622
},

packages/subgraph/src/helpers.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ let EVENT_SIGNATURE =
5353
"SafeMultiSigTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes,bytes)";
5454
let EVENT_DATA_TYPES =
5555
"(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes,bytes)";
56+
let LOG_EVENT_SIGNATURE = "Log(bytes)"
5657

5758
// For some reason it's erroring when trying to parse the calldata
5859
export class SafeExecutionContext {
@@ -270,6 +271,9 @@ export function getEventFromReceipt(
270271
// maybe also check that the data contains the selector for the EBO 0xa1dce332
271272
// but we require the parsing of the calldata to work for that
272273
desiredLog = logs[i];
274+
} else if(isEventLog(topics[0], LOG_EVENT_SIGNATURE)) {
275+
// try with a previous value for multisend cases
276+
return getEventFromReceipt(event, eventSignature, logIndex.minus(BIGINT_ONE))
273277
}
274278
}
275279
}

packages/subgraph/src/mapping.ts

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ export function handleLogCrossChainEpochOracle(event: Log): void {
4040
event.transaction.from.toHexString()
4141
])
4242
}
43+
// Support for Multisend type of transactions ONLY for EventfulDataEdge impl
44+
let payloadId = [event.transaction.hash.toHexString(), event.logIndex.toString()].join("-")
4345
processPayload(
4446
safeExecutionContext != null ? safeExecutionContext.multisigAddress.toHexString() : event.transaction.from.toHexString(),
4547
data,
46-
event.transaction.hash.toHexString(),
48+
payloadId,
4749
event.block.number
4850
);
4951
}
@@ -62,19 +64,19 @@ export function handleCrossChainEpochOracle(
6264
export function processPayload(
6365
submitter: string,
6466
payloadBytes: Bytes,
65-
txHash: string,
67+
payloadId: string,
6668
blockNumber: BigInt
6769
): void {
6870
log.warning(
69-
"Processing payload. Submitter: {}, txHash: {}, blockNumber: {}",
70-
[submitter, txHash, blockNumber.toString()]
71+
"Processing payload. Submitter: {}, payloadId: {}, blockNumber: {}",
72+
[submitter, payloadId, blockNumber.toString()]
7173
);
7274
// Start the StoreCache
7375
let cache = new StoreCache();
7476

7577
// This is the only thing not handled through the store cache since we want all
7678
// Payload entity to persist (to provide context for validity of the payload)
77-
let payload = new Payload(txHash);
79+
let payload = new Payload(payloadId);
7880
payload.data = payloadBytes;
7981
payload.submitter = submitter;
8082
payload.valid = true;
@@ -99,7 +101,7 @@ export function processPayload(
99101
]);
100102

101103
// Handle message block
102-
let messageBlock = cache.getMessageBlock([txHash, i].join("-"));
104+
let messageBlock = cache.getMessageBlock([payloadId, i].join("-"));
103105
messageBlock.payload = payload.id;
104106
processMessageBlock(cache, messageBlock, reader, payload.submitter);
105107
if (!reader.ok) {
@@ -117,8 +119,8 @@ export function processPayload(
117119
payload.save();
118120
cache.commitChanges();
119121
log.warning(
120-
"Processed payload. Submitter: {}, txHash: {}, blockNumber: {}",
121-
[submitter, txHash, blockNumber.toString()]
122+
"Processed payload. Submitter: {}, payloadId: {}, blockNumber: {}",
123+
[submitter, payloadId, blockNumber.toString()]
122124
);
123125
}
124126

@@ -439,6 +441,7 @@ function executeRegisterNetworksMessage(
439441
networks = networksMapped.flat();
440442

441443
let numInsertions = decodeU64(reader) as i32;
444+
let numReinsertions = 0;
442445
if (!reader.ok) {
443446
return;
444447
}
@@ -453,8 +456,13 @@ function executeRegisterNetworksMessage(
453456
if (!cache.isNetworkAlreadyRegistered(chainId)) {
454457
let network = cache.getNetwork(chainId);
455458
network.alias = PRELOADED_ALIASES.keys().includes(network.id) ? PRELOADED_ALIASES.get(network.id).toString() : ""
456-
network.addedAt = message.id;
457-
network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed
459+
if(network.removedAt == null) {
460+
network.addedAt = message.id;
461+
} else {
462+
numReinsertions += 1;
463+
network.lastUpdatedAt = message.id;
464+
network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed
465+
}
458466
networks.push(network);
459467
} else {
460468
reader.fail("Network {} is already registered.".replace("{}", chainId));
@@ -465,6 +473,7 @@ function executeRegisterNetworksMessage(
465473
globalState.activeNetworkCount += numInsertions;
466474
globalState.activeNetworkCount -= numRemovals;
467475
globalState.networkCount += numInsertions;
476+
globalState.networkCount -= numReinsertions;
468477

469478
commitNetworkChanges(removedNetworks, networks, globalState, message.id);
470479

@@ -538,6 +547,7 @@ function executeRegisterNetworksAndAliasesMessage(
538547
networks = networksMapped.flat();
539548

540549
let numInsertions = decodeU64(reader) as i32;
550+
let numReinsertions = 0;
541551
if (!reader.ok) {
542552
return;
543553
}
@@ -552,9 +562,13 @@ function executeRegisterNetworksAndAliasesMessage(
552562

553563
if (!cache.isNetworkAlreadyRegistered(chainId)) {
554564
let network = cache.getNetwork(chainId);
555-
network.addedAt = message.id;
556-
network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed
557-
565+
if(network.removedAt == null) {
566+
network.addedAt = message.id;
567+
} else {
568+
numReinsertions += 1;
569+
network.lastUpdatedAt = message.id;
570+
network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed
571+
}
558572
// Get manifest alias for that CAIP2 id
559573
let alias = decodeString(reader);
560574
if (!reader.ok) {
@@ -572,6 +586,7 @@ function executeRegisterNetworksAndAliasesMessage(
572586
globalState.activeNetworkCount += numInsertions;
573587
globalState.activeNetworkCount -= numRemovals;
574588
globalState.networkCount += numInsertions;
589+
globalState.networkCount -= numReinsertions;
575590

576591
commitNetworkChanges(removedNetworks, networks, globalState, message.id);
577592

0 commit comments

Comments
 (0)