Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add multisend support, fix counts on reinserts #259

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions packages/subgraph/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@
"codegen": "yarn && graph codegen",
"test": "yarn && yarn prep:test && yarn codegen && graph test",
"build": "yarn && yarn prepare && graph build",
"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",
"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",
"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",
"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",
"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",
"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",
"deploy-mainnet": "yarn && yarn prep:mainnet && yarn codegen && graph build --network mainnet && graph deploy --studio graph-ebo-ethereum",
"deploy-arbitrum": "yarn && yarn prep:arbitrum && yarn codegen && graph build --network arbitrum-one && graph deploy --studio graph-ebo-arbitrum",
"deploy-sepolia": "yarn && yarn prep:sepolia && yarn codegen && graph build --network sepolia && graph deploy --studio graph-ebo-sepolia",
"deploy-arbitrum-sepolia": "yarn && yarn prep:arbitrum-sepolia && yarn codegen && graph build --network arbitrum-sepolia && graph deploy --studio graph-ebo-arbitrum-sepolia",
"create-local": "graph create --node http://127.0.0.1:8020/ edgeandnode/block-oracle",
"remove-local": "graph remove --node http://127.0.0.1:8020/ edgeandnode/block-oracle",
"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",
"prep:local": "mustache ./config/local.json subgraph.template.yaml > subgraph.yaml && mustache ./config/local.json src/constants.template.ts > src/constants.ts",
"prep:test": "mustache ./config/test.json subgraph.template.yaml > subgraph.yaml && mustache ./config/test.json src/constants.template.ts > src/constants.ts",
"prep:mainnet": "mustache ./config/mainnet.json subgraph.template.yaml > subgraph.yaml && mustache ./config/mainnet.json src/constants.template.ts > src/constants.ts",
"prep:arbitrum": "mustache ./config/arbitrum.json subgraph.template.yaml > subgraph.yaml && mustache ./config/arbitrum.json src/constants.template.ts > src/constants.ts",
"prep:goerli": "mustache ./config/goerli.json subgraph.template.yaml > subgraph.yaml && mustache ./config/goerli.json src/constants.template.ts > src/constants.ts",
"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",
"prep:sepolia": "mustache ./config/sepolia.json subgraph.template.yaml > subgraph.yaml && mustache ./config/sepolia.json src/constants.template.ts > src/constants.ts",
"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"
},
Expand Down
4 changes: 4 additions & 0 deletions packages/subgraph/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ let EVENT_SIGNATURE =
"SafeMultiSigTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes,bytes)";
let EVENT_DATA_TYPES =
"(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes,bytes)";
let LOG_EVENT_SIGNATURE = "Log(bytes)"

// For some reason it's erroring when trying to parse the calldata
export class SafeExecutionContext {
Expand Down Expand Up @@ -270,6 +271,9 @@ export function getEventFromReceipt(
// maybe also check that the data contains the selector for the EBO 0xa1dce332
// but we require the parsing of the calldata to work for that
desiredLog = logs[i];
} else if(isEventLog(topics[0], LOG_EVENT_SIGNATURE)) {
// try with a previous value for multisend cases
return getEventFromReceipt(event, eventSignature, logIndex.minus(BIGINT_ONE))
}
}
}
Expand Down
41 changes: 28 additions & 13 deletions packages/subgraph/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ export function handleLogCrossChainEpochOracle(event: Log): void {
event.transaction.from.toHexString()
])
}
// Support for Multisend type of transactions ONLY for EventfulDataEdge impl
let payloadId = [event.transaction.hash.toHexString(), event.logIndex.toString()].join("-")
processPayload(
safeExecutionContext != null ? safeExecutionContext.multisigAddress.toHexString() : event.transaction.from.toHexString(),
data,
event.transaction.hash.toHexString(),
payloadId,
event.block.number
);
}
Expand All @@ -62,19 +64,19 @@ export function handleCrossChainEpochOracle(
export function processPayload(
submitter: string,
payloadBytes: Bytes,
txHash: string,
payloadId: string,
blockNumber: BigInt
): void {
log.warning(
"Processing payload. Submitter: {}, txHash: {}, blockNumber: {}",
[submitter, txHash, blockNumber.toString()]
"Processing payload. Submitter: {}, payloadId: {}, blockNumber: {}",
[submitter, payloadId, blockNumber.toString()]
);
// Start the StoreCache
let cache = new StoreCache();

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

// Handle message block
let messageBlock = cache.getMessageBlock([txHash, i].join("-"));
let messageBlock = cache.getMessageBlock([payloadId, i].join("-"));
messageBlock.payload = payload.id;
processMessageBlock(cache, messageBlock, reader, payload.submitter);
if (!reader.ok) {
Expand All @@ -117,8 +119,8 @@ export function processPayload(
payload.save();
cache.commitChanges();
log.warning(
"Processed payload. Submitter: {}, txHash: {}, blockNumber: {}",
[submitter, txHash, blockNumber.toString()]
"Processed payload. Submitter: {}, payloadId: {}, blockNumber: {}",
[submitter, payloadId, blockNumber.toString()]
);
}

Expand Down Expand Up @@ -439,6 +441,7 @@ function executeRegisterNetworksMessage(
networks = networksMapped.flat();

let numInsertions = decodeU64(reader) as i32;
let numReinsertions = 0;
if (!reader.ok) {
return;
}
Expand All @@ -453,8 +456,13 @@ function executeRegisterNetworksMessage(
if (!cache.isNetworkAlreadyRegistered(chainId)) {
let network = cache.getNetwork(chainId);
network.alias = PRELOADED_ALIASES.keys().includes(network.id) ? PRELOADED_ALIASES.get(network.id).toString() : ""
network.addedAt = message.id;
network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed
if(network.removedAt == null) {
network.addedAt = message.id;
} else {
numReinsertions += 1;
network.lastUpdatedAt = message.id;
network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed
}
networks.push(network);
} else {
reader.fail("Network {} is already registered.".replace("{}", chainId));
Expand All @@ -465,6 +473,7 @@ function executeRegisterNetworksMessage(
globalState.activeNetworkCount += numInsertions;
globalState.activeNetworkCount -= numRemovals;
globalState.networkCount += numInsertions;
globalState.networkCount -= numReinsertions;

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

Expand Down Expand Up @@ -538,6 +547,7 @@ function executeRegisterNetworksAndAliasesMessage(
networks = networksMapped.flat();

let numInsertions = decodeU64(reader) as i32;
let numReinsertions = 0;
if (!reader.ok) {
return;
}
Expand All @@ -552,9 +562,13 @@ function executeRegisterNetworksAndAliasesMessage(

if (!cache.isNetworkAlreadyRegistered(chainId)) {
let network = cache.getNetwork(chainId);
network.addedAt = message.id;
network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed

if(network.removedAt == null) {
network.addedAt = message.id;
} else {
numReinsertions += 1;
network.lastUpdatedAt = message.id;
network.removedAt = null; // unsetting to make sure that if the network existed before, it's no longer flagged as removed
}
// Get manifest alias for that CAIP2 id
let alias = decodeString(reader);
if (!reader.ok) {
Expand All @@ -572,6 +586,7 @@ function executeRegisterNetworksAndAliasesMessage(
globalState.activeNetworkCount += numInsertions;
globalState.activeNetworkCount -= numRemovals;
globalState.networkCount += numInsertions;
globalState.networkCount -= numReinsertions;

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

Expand Down
Loading