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

Index currency decimals #304

Merged
merged 8 commits into from
Aug 23, 2024
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
297 changes: 297 additions & 0 deletions abis-supplemental/ERC20.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@assemblyscript/loader": "^0.19.22",
"@graphprotocol/graph-cli": "^0.56.0",
"@graphprotocol/graph-ts": "^0.27.0",
"matchstick-as": "^0.5.0"
"matchstick-as": "^0.6.0"
},
"devDependencies": {
"assemblyscript": "^0.19.22",
Expand Down
9 changes: 9 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ type Project @entity {
"Currency symbol for ERC-20"
currencySymbol: String

"Number of decimals used to get a currency's display representation (i.e. 18 for ETH)"
currencyDecimals: Int

"Artist description of the project"
description: String

Expand Down Expand Up @@ -409,6 +412,9 @@ type PrimaryPurchase @entity {

"Symbol of currency used to purchase token"
currencySymbol: String

"Number of decimals used to get a currency's display representation (i.e. 18 for ETH)"
currencyDecimals: Int
}

type MinterFilter @entity {
Expand Down Expand Up @@ -501,6 +507,9 @@ type ProjectMinterConfiguration @entity {
"currency address as defined on minter - address(0) reserved for ether"
currencyAddress: Bytes!

"number of decimals used to get a currency's display representation (i.e. 18 for ETH)"
currencyDecimals: Int!

"Defines if purchasing token to another is allowed"
purchaseToDisabled: Boolean!

Expand Down
3 changes: 3 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ export function loadOrCreateProjectMinterConfiguration(
projectMinterConfig.priceIsConfigured = false;
projectMinterConfig.currencySymbol = "ETH";
projectMinterConfig.currencyAddress = Address.zero();
projectMinterConfig.currencyDecimals = 18;
projectMinterConfig.purchaseToDisabled = false;
projectMinterConfig.extraMinterDetails = "{}";
projectMinterConfig.save();
Expand Down Expand Up @@ -924,6 +925,7 @@ export function createPrimaryPurchaseDetailsFromTokenMint<T>(
);
purchaseDetails.currencyAddress = minterConfig.currencyAddress;
purchaseDetails.currencySymbol = minterConfig.currencySymbol;
purchaseDetails.currencyDecimals = minterConfig.currencyDecimals;

purchaseDetails.save();
return purchaseDetails.id;
Expand Down Expand Up @@ -953,6 +955,7 @@ export function createPrimaryPurchaseDetailsFromTokenMint<T>(
purchaseDetails.currencyAddress =
project.currencyAddress || Address.zero();
purchaseDetails.currencySymbol = project.currencySymbol || "ETH";
purchaseDetails.currencyDecimals = project.currencyDecimals || 18;

purchaseDetails.save();
return purchaseDetails.id;
Expand Down
12 changes: 12 additions & 0 deletions src/legacy-minter-suite-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ import {

import { createTypedMapFromEntries, toJSONValue } from "./json";

import { ERC20 } from "../generated/MinterSetPriceERC20/ERC20";

// IFilteredMinterV0 events
export function handlePricePerTokenInWeiUpdated(
event: PricePerTokenInWeiUpdated
Expand Down Expand Up @@ -162,6 +164,15 @@ export function handleProjectCurrencyInfoUpdated(

projectMinterConfig.currencyAddress = event.params._currencyAddress;
projectMinterConfig.currencySymbol = event.params._currencySymbol;

const erc20Contract = ERC20.bind(event.params._currencyAddress);
const decimalsResult = erc20Contract.try_decimals();
if (!decimalsResult.reverted) {
projectMinterConfig.currencyDecimals = decimalsResult.value;
} else {
projectMinterConfig.currencyDecimals = 18;
}

projectMinterConfig.save();

project.updatedAt = event.block.timestamp;
Expand Down Expand Up @@ -1246,6 +1257,7 @@ function loadMinterProjectAndConfigLegacyMinters(
projectMinterConfig.priceIsConfigured = false;
projectMinterConfig.currencySymbol = "ETH";
projectMinterConfig.currencyAddress = Address.zero();
projectMinterConfig.currencyDecimals = 18;
projectMinterConfig.purchaseToDisabled = false;
projectMinterConfig.extraMinterDetails = "{}";
projectMinterConfig.save();
Expand Down
2 changes: 2 additions & 0 deletions src/mapping-v0-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export function handleMint(event: Mint): void {
primaryPurchaseDetails.minterAddress = event.address;
primaryPurchaseDetails.currencyAddress = Address.zero();
primaryPurchaseDetails.currencySymbol = "ETH";
primaryPurchaseDetails.currencyDecimals = 18;
primaryPurchaseDetails.save();
token.primaryPurchaseDetails = primaryPurchaseDetails.id;

Expand Down Expand Up @@ -251,6 +252,7 @@ export function handleAddProject(call: AddProjectCall): void {
project.createdAt = call.block.timestamp;
project.currencyAddress = Address.zero();
project.currencySymbol = "ETH";
project.currencyDecimals = 18;
project.dynamic = dynamic;
project.externalAssetDependencyCount = BigInt.fromI32(0);
project.externalAssetDependenciesLocked = false;
Expand Down
19 changes: 19 additions & 0 deletions src/mapping-v1-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {
createPrimaryPurchaseDetailsFromTokenMint
} from "./helpers";
import { GEN_ART_721_CORE_V1 } from "./constants";
import { ERC20 } from "../generated/MinterSetPriceERC20/ERC20";

/*** EVENT HANDLERS ***/
export function handleMint(event: Mint): void {
Expand Down Expand Up @@ -242,6 +243,14 @@ export function handleAddProject(call: AddProjectCall): void {
let maxInvocations = projectTokenInfo.value3;
let currencyAddress = projectTokenInfo.value5;
let currencySymbol = projectTokenInfo.value7;
let currencyDecimals = 18;
if (currencyAddress != Address.zero()) {
let currencyContract = ERC20.bind(currencyAddress);
let decimals = currencyContract.try_decimals();
if (!decimals.reverted) {
currencyDecimals = decimals.value;
}
}

let scriptCount = projectScriptInfo.value1;
let useHashString = projectScriptInfo.value2;
Expand All @@ -259,6 +268,7 @@ export function handleAddProject(call: AddProjectCall): void {
project.createdAt = timestamp;
project.currencySymbol = currencySymbol;
project.currencyAddress = currencyAddress;
project.currencyDecimals = currencyDecimals;
project.dynamic = dynamic;
project.externalAssetDependencyCount = BigInt.fromI32(0);
project.externalAssetDependenciesLocked = false;
Expand Down Expand Up @@ -589,6 +599,15 @@ export function handleUpdateProjectCurrencyInfo(
if (project) {
project.currencySymbol = call.inputs._currencySymbol;
project.currencyAddress = call.inputs._currencyAddress;

if (call.inputs._currencyAddress != Address.zero()) {
let currencyContract = ERC20.bind(call.inputs._currencyAddress);
let decimals = currencyContract.try_decimals();
if (!decimals.reverted) {
project.currencyDecimals = decimals.value;
}
}

project.updatedAt = call.block.timestamp;
project.save();
}
Expand Down
19 changes: 19 additions & 0 deletions src/mapping-v2-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import {
FLEX_CONTRACT_EXTERNAL_ASSET_DEP_TYPES,
GEN_ART_721_CORE_V2
} from "./constants";
import { ERC20 } from "../generated/MinterSetPriceERC20/ERC20";

/*** EVENT HANDLERS ***/
export function handleMint(event: Mint): void {
Expand Down Expand Up @@ -380,6 +381,14 @@ export function handleAddProject(call: AddProjectCall): void {
let maxInvocations = projectTokenInfo.value3;
let currencySymbol = projectTokenInfo.value7;
let currencyAddress = projectTokenInfo.value8;
let currencyDecimals = 18;
if (currencyAddress != Address.zero()) {
let currencyContract = ERC20.bind(currencyAddress);
let decimals = currencyContract.try_decimals();
if (!decimals.reverted) {
currencyDecimals = decimals.value;
}
}

let scriptCount = projectScriptInfo.value1;
let useHashString = true;
Expand All @@ -396,6 +405,7 @@ export function handleAddProject(call: AddProjectCall): void {
project.contract = contractAddress.toHexString();
project.createdAt = timestamp;
project.currencyAddress = currencyAddress;
project.currencyDecimals = currencyDecimals;
project.currencySymbol = currencySymbol;
project.dynamic = dynamic;
project.externalAssetDependencyCount = BigInt.fromI32(0);
Expand Down Expand Up @@ -621,6 +631,15 @@ export function handleUpdateProjectCurrencyInfo(
if (project) {
project.currencySymbol = call.inputs._currencySymbol;
project.currencyAddress = call.inputs._currencyAddress;
project.currencyDecimals = 18;
if (call.inputs._currencyAddress != Address.zero()) {
let currencyContract = ERC20.bind(call.inputs._currencyAddress);
let decimals = currencyContract.try_decimals();
if (!decimals.reverted) {
project.currencyDecimals = decimals.value;
}
}

project.updatedAt = call.block.timestamp;

project.save();
Expand Down
4 changes: 0 additions & 4 deletions src/mapping-v3-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,6 @@ function createProject(
let pricePerTokenInWei = BigInt.fromI32(0);
let invocations = projectStateData.value.getInvocations();
let maxInvocations = projectStateData.value.getMaxInvocations();
let currencySymbol = "ETH";
let currencyAddress = Address.zero();

let scriptCount = projectScriptDetails.value.getScriptCount();
let useHashString = true;
Expand All @@ -706,8 +704,6 @@ function createProject(
project.complete = false;
project.contract = contractAddress;
project.createdAt = timestamp;
project.currencyAddress = currencyAddress;
project.currencySymbol = currencySymbol;
project.dynamic = true;
project.externalAssetDependencyCount = BigInt.fromI32(0);
project.externalAssetDependenciesLocked = false;
Expand Down
10 changes: 10 additions & 0 deletions src/split-funds-lib-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { ProjectCurrencyInfoUpdated } from "../generated/SplitFundsLib/SplitFund
import { updateProjectIfMinterConfigIsActive } from "./helpers";

import { loadOrCreateMinterProjectAndConfigIfProject } from "./generic-minter-events-lib-mapping";
import { ERC20 } from "../generated/MinterSetPriceERC20/ERC20";

///////////////////////////////////////////////////////////////////////////////
// EVENT HANDLERS start here
Expand Down Expand Up @@ -33,6 +34,15 @@ export function handleProjectCurrencyInfoUpdated(
const projectMinterConfig = minterProjectAndConfig.projectMinterConfiguration;
projectMinterConfig.currencyAddress = event.params.currencyAddress;
projectMinterConfig.currencySymbol = event.params.currencySymbol;
projectMinterConfig.currencyDecimals = 18;
if (event.params.currencyAddress != Address.zero()) {
let currencyContract = ERC20.bind(event.params.currencyAddress);
let decimals = currencyContract.try_decimals();
if (!decimals.reverted) {
projectMinterConfig.currencyDecimals = decimals.value;
}
}

projectMinterConfig.save();

// induce sync if the project minter configuration is the active one
Expand Down
Loading