Skip to content

Commit

Permalink
Merge pull request #108 from ethereum-attestation-service/indexer
Browse files Browse the repository at this point in the history
Add EAS Indexer service
  • Loading branch information
lbeder authored Oct 25, 2023
2 parents 9df0f78 + 460f994 commit d377d73
Show file tree
Hide file tree
Showing 25 changed files with 2,758 additions and 439 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,8 @@ jobs:
- name: Test
run: pnpm test

- name: Test Deployment
run: pnpm test:deploy

- name: Compile (Foundry)
run: forge build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ deployments/arbitrum-goerli/solcInputs/*
deployments/polygon-mumbai/solcInputs/*
deployments/linea-goerli/solcInputs/*
deployments/hardhat/*
!deployments/hardhat/.chainId

.coverage_artifacts
.coverage_contracts
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ pnpm test

### Test Coverage

#### Latest Test Coverage Report (2023-08-31)
#### Latest Test Coverage Report (2023-10-24)

* 100% Statements 313/313
* 100% Branches 160/160
* 100% Functions 105/105
* 100% Lines 450/450
* 100% Statements 349/349
* 100% Branches 172/172
* 100% Functions 120/120
* 100% Lines 491/491

```sh
----------------------------------|----------|----------|----------|----------|----------------|
Expand All @@ -199,6 +199,7 @@ File | % Stmts | % Branch | % Funcs | % Lines |U
EAS.sol | 100 | 100 | 100 | 100 | |
IEAS.sol | 100 | 100 | 100 | 100 | |
ISchemaRegistry.sol | 100 | 100 | 100 | 100 | |
Indexer.sol | 100 | 100 | 100 | 100 | |
SchemaRegistry.sol | 100 | 100 | 100 | 100 | |
Semver.sol | 100 | 100 | 100 | 100 | |
contracts/eip1271/ | 100 | 100 | 100 | 100 | |
Expand Down
41 changes: 20 additions & 21 deletions components/Contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
DataResolver__factory,
EAS__factory,
ExpirationTimeResolver__factory,
Indexer__factory,
PayingResolver__factory,
PermissionedEIP712Proxy__factory,
RecipientResolver__factory,
Expand Down Expand Up @@ -34,7 +35,6 @@ type Contract<F extends ContractFactory> = AsyncReturnType<F['deploy']>;

export interface ContractBuilder<F extends ContractFactory> {
metadata: {
contractName: string;
abi: ABI;
bytecode: string;
};
Expand All @@ -49,13 +49,11 @@ export type FactoryConstructor<F extends ContractFactory> = {
};

export const deployOrAttach = <F extends ContractFactory>(
contractName: string,
FactoryConstructor: FactoryConstructor<F>,
initialSigner?: Signer
): ContractBuilder<F> => {
return {
metadata: {
contractName,
abi: FactoryConstructor.abi as ABI,
bytecode: FactoryConstructor.bytecode
},
Expand Down Expand Up @@ -84,24 +82,25 @@ export const attachOnly = <F extends ContractFactory>(
const getContracts = (signer?: Signer) => ({
connect: (signer: Signer) => getContracts(signer),

AttestationResolver: deployOrAttach('AttestationResolver', AttestationResolver__factory, signer),
AttesterResolver: deployOrAttach('AttesterResolver', AttesterResolver__factory, signer),
DataResolver: deployOrAttach('DataResolver', DataResolver__factory, signer),
EAS: deployOrAttach('EAS', EAS__factory, signer),
ExpirationTimeResolver: deployOrAttach('ExpirationTimeResolver', ExpirationTimeResolver__factory, signer),
PayingResolver: deployOrAttach('PayingResolver', PayingResolver__factory, signer),
PermissionedEIP712Proxy: deployOrAttach('PermissionedEIP712Proxy', PermissionedEIP712Proxy__factory, signer),
RecipientResolver: deployOrAttach('RecipientResolver', RecipientResolver__factory, signer),
RevocationResolver: deployOrAttach('RevocationResolver', RevocationResolver__factory, signer),
SchemaRegistry: deployOrAttach('SchemaRegistry', SchemaRegistry__factory, signer),
TestEAS: deployOrAttach('TestEAS', TestEAS__factory, signer),
TestEIP712Proxy: deployOrAttach('TestEIP712Proxy', TestEIP712Proxy__factory, signer),
TestEIP1271Signer: deployOrAttach('TestEIP1271Signer', TestEIP1271Signer__factory, signer),
TestEIP1271Verifier: deployOrAttach('TestEIP1271Verifier', TestEIP1271Verifier__factory, signer),
TestERC20Token: deployOrAttach('TestERC20Token', TestERC20Token__factory, signer),
TestSchemaResolver: deployOrAttach('TestSchemaResolver', TestSchemaResolver__factory, signer),
TokenResolver: deployOrAttach('TokenResolver', TokenResolver__factory, signer),
ValueResolver: deployOrAttach('ValueResolver', ValueResolver__factory, signer)
AttestationResolver: deployOrAttach(AttestationResolver__factory, signer),
AttesterResolver: deployOrAttach(AttesterResolver__factory, signer),
DataResolver: deployOrAttach(DataResolver__factory, signer),
EAS: deployOrAttach(EAS__factory, signer),
ExpirationTimeResolver: deployOrAttach(ExpirationTimeResolver__factory, signer),
Indexer: deployOrAttach(Indexer__factory, signer),
PayingResolver: deployOrAttach(PayingResolver__factory, signer),
PermissionedEIP712Proxy: deployOrAttach(PermissionedEIP712Proxy__factory, signer),
RecipientResolver: deployOrAttach(RecipientResolver__factory, signer),
RevocationResolver: deployOrAttach(RevocationResolver__factory, signer),
SchemaRegistry: deployOrAttach(SchemaRegistry__factory, signer),
TestEAS: deployOrAttach(TestEAS__factory, signer),
TestEIP712Proxy: deployOrAttach(TestEIP712Proxy__factory, signer),
TestEIP1271Signer: deployOrAttach(TestEIP1271Signer__factory, signer),
TestEIP1271Verifier: deployOrAttach(TestEIP1271Verifier__factory, signer),
TestERC20Token: deployOrAttach(TestERC20Token__factory, signer),
TestSchemaResolver: deployOrAttach(TestSchemaResolver__factory, signer),
TokenResolver: deployOrAttach(TokenResolver__factory, signer),
ValueResolver: deployOrAttach(ValueResolver__factory, signer)
});
/* eslint-enable camelcase */

Expand Down
34 changes: 17 additions & 17 deletions contracts/EAS.sol
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
// Since a multi-attest call is going to make multiple attestations for multiple schemas, we'd need to collect
// all the returned UIDs into a single list.
uint256 length = multiRequests.length;
bytes32[][] memory totalUids = new bytes32[][](length);
uint256 totalUidsCount = 0;
bytes32[][] memory totalUIDs = new bytes32[][](length);
uint256 totalUIDCount = 0;

// We are keeping track of the total available ETH amount that can be sent to resolvers and will keep deducting
// from it to verify that there isn't any attempt to send too much ETH to resolvers. Please note that unless
Expand Down Expand Up @@ -156,14 +156,14 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
availableValue -= res.usedValue;

// Collect UIDs (and merge them later).
totalUids[i] = res.uids;
totalUIDs[i] = res.uids;
unchecked {
totalUidsCount += res.uids.length;
totalUIDCount += res.uids.length;
}
}

// Merge all the collected UIDs and return them as a flatten array.
return _mergeUIDs(totalUids, totalUidsCount);
return _mergeUIDs(totalUIDs, totalUIDCount);
}

/// @inheritdoc IEAS
Expand All @@ -173,8 +173,8 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
// Since a multi-attest call is going to make multiple attestations for multiple schemas, we'd need to collect
// all the returned UIDs into a single list.
uint256 length = multiDelegatedRequests.length;
bytes32[][] memory totalUids = new bytes32[][](length);
uint256 totalUidsCount = 0;
bytes32[][] memory totalUIDs = new bytes32[][](length);
uint256 totalUIDCount = 0;

// We are keeping track of the total available ETH amount that can be sent to resolvers and will keep deducting
// from it to verify that there isn't any attempt to send too much ETH to resolvers. Please note that unless
Expand Down Expand Up @@ -226,14 +226,14 @@ contract EAS is IEAS, Semver, EIP1271Verifier {
availableValue -= res.usedValue;

// Collect UIDs (and merge them later).
totalUids[i] = res.uids;
totalUIDs[i] = res.uids;
unchecked {
totalUidsCount += res.uids.length;
totalUIDCount += res.uids.length;
}
}

// Merge all the collected UIDs and return them as a flatten array.
return _mergeUIDs(totalUids, totalUidsCount);
return _mergeUIDs(totalUIDs, totalUIDCount);
}

/// @inheritdoc IEAS
Expand Down Expand Up @@ -754,18 +754,18 @@ contract EAS is IEAS, Semver, EIP1271Verifier {

/// @dev Merges lists of UIDs.
/// @param uidLists The provided lists of UIDs.
/// @param uidsCount Total UIDs count.
/// @param uidCount Total UID count.
/// @return A merged and flatten list of all the UIDs.
function _mergeUIDs(bytes32[][] memory uidLists, uint256 uidsCount) private pure returns (bytes32[] memory) {
bytes32[] memory uids = new bytes32[](uidsCount);
function _mergeUIDs(bytes32[][] memory uidLists, uint256 uidCount) private pure returns (bytes32[] memory) {
bytes32[] memory uids = new bytes32[](uidCount);

uint256 currentIndex = 0;
uint256 uidListLength = uidLists.length;
for (uint256 i = 0; i < uidListLength; i = uncheckedInc(i)) {
bytes32[] memory currentUids = uidLists[i];
uint256 currentUidsLength = currentUids.length;
for (uint256 j = 0; j < currentUidsLength; j = uncheckedInc(j)) {
uids[currentIndex] = currentUids[j];
bytes32[] memory currentUIDs = uidLists[i];
uint256 currentUIDsLength = currentUIDs.length;
for (uint256 j = 0; j < currentUIDsLength; j = uncheckedInc(j)) {
uids[currentIndex] = currentUIDs[j];

unchecked {
++currentIndex;
Expand Down
Loading

0 comments on commit d377d73

Please sign in to comment.