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

Handle MinPriceLib #308

Merged
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
24 changes: 24 additions & 0 deletions abis-supplemental/MinPriceLib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"_format": "hh-sol-artifact-1",
"contractName": "MinPriceLib",
"sourceName": "contracts/libs/v0.8.x/minter-libs/MinPriceLib.sol",
"abi": [
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint256",
"name": "minMintFee",
"type": "uint256"
}
],
"name": "MinMintFeeUpdated",
"type": "event"
}
],
"bytecode": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220fd94d5ad7380cbc6b28763797313de44be00d82998064d18e865734e3de0af9e64736f6c63430008160033",
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220fd94d5ad7380cbc6b28763797313de44be00d82998064d18e865734e3de0af9e64736f6c63430008160033",
"linkReferences": {},
"deployedLinkReferences": {}
}
5 changes: 5 additions & 0 deletions config/generic.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
"address": ""
}
],
"minPriceLibContracts": [
{
"address": ""
}
],
"maxInvocationsLibContracts": [
{
"address": ""
Expand Down
33 changes: 33 additions & 0 deletions src/min-price-lib-mapping.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { MinMintFeeUpdated } from "../generated/MinPriceLib/MinPriceLib";
import { loadOrCreateMinter } from "./helpers";
import { setMinterExtraMinterDetailsValue } from "./extra-minter-details-helpers";

///////////////////////////////////////////////////////////////////////////////
// EVENT HANDLERS start here
///////////////////////////////////////////////////////////////////////////////

/**
* Handles the update of contract-level min mint fee.
* Loads or creates the minter, updates the minter's extra minter details with
* the updated value, and induces a sync of the minter entity.
* @param event The event carrying new min mint fee value.
*/
export function handleMinMintFeeUpdated(event: MinMintFeeUpdated): void {
// load minter
const minter = loadOrCreateMinter(event.address, event.block.timestamp);

// update minter entity
setMinterExtraMinterDetailsValue(
"minMintFee",
event.params.minMintFee.toString(),
minter
);

// update minter's updatedAt timestamp to induce a sync, and save
minter.updatedAt = event.block.timestamp;
minter.save();
}

///////////////////////////////////////////////////////////////////////////////
// EVENT HANDLERS end here
///////////////////////////////////////////////////////////////////////////////
51 changes: 51 additions & 0 deletions subgraph.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,57 @@ dataSources:
handler: handlePricePerTokenReset
file: ./src/set-price-lib-mapping.ts
{{/setPriceLibContracts}}
{{#minPriceLibContracts}}
- kind: ethereum/contract
name: 'MinPriceLib{{#address}}-{{address}}{{/address}}'
network: {{network}}
source:
address: "{{#address}}{{address}}{{/address}}{{^address}}0x0000000000000000000000000000000000000000{{/address}}"
abi: MinPriceLib
{{#startBlock}}startBlock: {{startBlock}}{{/startBlock}}
mapping:
kind: ethereum/events
apiVersion: 0.0.5
language: wasm/assemblyscript
entities:
- Project
- ProjectScript
- Token
- Contract
- Account
- AccountProject
- Whitelisting
- MinterFilter
- Minter
- ProjectMinterConfiguration
abis:
- name: MinPriceLib
file: ./abis/MinPriceLib.json
- name: ISharedMinterV0
file: ./abis/ISharedMinterV0.json
- name: IFilteredMinterV2
file: ./abis/IFilteredMinterV2.json
- name: IFilteredMinterDALinV1
file: ./abis/IFilteredMinterDALinV1.json
- name: IFilteredMinterDAExpV1
file: ./abis/IFilteredMinterDAExpV1.json
- name: IFilteredMinterDAExpSettlementV1
file: ./abis/IFilteredMinterDAExpSettlementV1.json
- name: IFilteredMinterV2
file: ./abis/IFilteredMinterV2.json
- name: IFilteredMinterHolderV2
file: ./abis/IFilteredMinterHolderV2.json
- name: IFilteredMinterMerkleV2
file: ./abis/IFilteredMinterMerkleV2.json
- name: IFilteredMinterSEAV0
file: ./abis/IFilteredMinterSEAV0.json
- name: ERC20
file: ./abis/ERC20.json
eventHandlers:
- event: MinMintFeeUpdated(uint256)
handler: handleMinMintFeeUpdated
file: ./src/min-price-lib-mapping.ts
{{/minPriceLibContracts}}
{{#maxInvocationsLibContracts}}
- kind: ethereum/contract
name: 'MaxInvocationsLib{{#address}}-{{address}}{{/address}}'
Expand Down
62 changes: 62 additions & 0 deletions tests/e2e/runner/__tests__/minter-suite-v2/min-price-lib.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { describe, test, expect } from "@jest/globals";
import {
getSubgraphConfig,
createSubgraphClient,
getAccounts,
waitUntilSubgraphIsSynced,
getMinterDetails,
} from "../utils/helpers";

import { MinterMinPriceV0__factory } from "../../contracts/factories/MinterMinPriceV0__factory";
// hide nuisance logs about event overloading
import { Logger } from "@ethersproject/logger";
Logger.setLogLevel(Logger.levels.ERROR);

// waiting for subgraph to sync can take longer than the default 5s timeout
// @dev For this file specifically, one test takes >60s due to hard-coded minimum
// auction duration on SEA minter
jest.setTimeout(100 * 1000);

const config = getSubgraphConfig();

const client = createSubgraphClient();
const { deployer } = getAccounts();

// get min price lib contract from the subgraph config
if (!config.minPriceLibContracts) {
throw new Error("No minPriceLibContracts in config");
}
const minterMinPriceV0Address = config.minPriceLibContracts[0].address;
const minterMinPriceV0Contract = new MinterMinPriceV0__factory(deployer).attach(
minterMinPriceV0Address
);

describe("MinPriceLib event handling", () => {
beforeAll(async () => {
await waitUntilSubgraphIsSynced(client);
});

describe("Indexed after setup", () => {
test("created new Minter during deployment and allowlisting", async () => {
const targetId = minterMinPriceV0Address.toLowerCase();
const minterRes = await getMinterDetails(client, targetId);
expect(minterRes.id).toBe(targetId);
});
});

describe("MinMintFeeUpdated", () => {
// this is a minter-level, value set in the constructor and other function(s),
// so we can inspect it by checking the Minter entity in the subgraph
// that was created during deployment
test("value was populated during deployment", async () => {
// query public constant for the expected value (>0)
const expectedValue = await minterMinPriceV0Contract.minMintFee();
expect(expectedValue.gt(0)).toBe(true);
// validate minter's extraMinterDetails in subgraph
const targetId = minterMinPriceV0Address.toLowerCase();
const minterRes = await getMinterDetails(client, targetId);
const extraMinterDetails = JSON.parse(minterRes.extraMinterDetails);
expect(extraMinterDetails.minMintFee).toBe(expectedValue.toString());
});
});
});
1 change: 1 addition & 0 deletions tests/e2e/runner/__tests__/subgraph-config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type SubgraphConfig = Partial<{
maxInvocationsLibContracts: { address: string }[];
merkleLibContracts: { address: string }[];
holderLibContracts: { address: string }[];
minPriceLibContracts: { address: string }[];
SEALibContracts: { address: string }[];
RAMLibContracts: { address: string }[];
DALibContracts: { address: string }[];
Expand Down
Loading
Loading