Skip to content

Commit

Permalink
fixing creator erc20 balance allocation (#319)
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiacodes authored and fforbeck committed Sep 22, 2021
1 parent 64d30c1 commit b097ef7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
13 changes: 7 additions & 6 deletions subgraph/mappings/dao-registry-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,6 @@ export function handleExtensionAdded(event: ExtensionAdded): void {

let extension = Extension.load(daoExtensionId);

loadOrCreateExtensionEntity(
event.address,
event.params.extensionId,
event.params.extensionAddress
);

if (extension == null) {
extension = new Extension(daoExtensionId);
}
Expand All @@ -216,6 +210,13 @@ export function handleExtensionAdded(event: ExtensionAdded): void {
// create 1-1 relationship with extensions and its dao
extension.tributeDao = daoAddress;
extension.save();

loadOrCreateExtensionEntity(
event.address,
event.params.extensionId,
event.params.extensionAddress,
event.transaction.from
);
}

export function handleExtensionRemoved(event: ExtensionRemoved): void {
Expand Down
6 changes: 3 additions & 3 deletions subgraph/mappings/extensions/bank-extension-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function internalTransfer(
}
}

function internalERC20Balance(
export function internalERC20Balance(
daoAddress: Address,
memberAddress: Address
): void {
Expand All @@ -112,10 +112,10 @@ function internalERC20Balance(
Address.fromString(erc20Extension.extensionAddress.toHexString())
);

// erc20 symbol
// erc20 token details
let name = erc20ExtensionRegistry.name();
let symbol = erc20ExtensionRegistry.symbol();
let totalSupply = erc20ExtensionRegistry.totalSupply();
let name = erc20ExtensionRegistry.name();

let balance = erc20ExtensionRegistry.balanceOf(memberAddress);

Expand Down
22 changes: 20 additions & 2 deletions subgraph/mappings/helpers/extension-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ import {
} from "../../generated/templates";
import { Bank, NFTCollection } from "../../generated/schema";

import { BANK_EXTENSION_ID, NFT_EXTENSION_ID } from "./constants";
import { internalERC20Balance } from "../extensions/bank-extension-mapping";
import {
BANK_EXTENSION_ID,
NFT_EXTENSION_ID,
ERC20_EXTENSION_ID,
} from "./constants";

export function loadOrCreateExtensionEntity(
daoAddress: Address,
extensionId: Bytes,
extensionAddress: Address
extensionAddress: Address,
transactionFrom: Address
): void {
if (BANK_EXTENSION_ID.toString() == extensionId.toHexString()) {
log.info("INFO BANK_EXTENSION_ID, extensionId: {}", [
Expand All @@ -29,6 +35,12 @@ export function loadOrCreateExtensionEntity(
NFTExtensionTemplate.create(extensionAddress);

nft(daoAddress, extensionAddress);
} else if (ERC20_EXTENSION_ID.toString() == extensionId.toHexString()) {
log.info("INFO ERC20_EXTENSION_ID, extensionId: {}", [
extensionId.toHexString(),
]);

erc20(daoAddress, transactionFrom);
}
}

Expand Down Expand Up @@ -65,3 +77,9 @@ function nft(daoAddress: Address, extensionAddress: Address): void {
nftCollection.save();
}
}

// if extension is an `erc20` assign to its dao, add creator with balance
function erc20(daoAddress: Address, transactionFrom: Address): void {
// add creator to token holder entity with initial balance
internalERC20Balance(daoAddress, transactionFrom);
}
2 changes: 2 additions & 0 deletions subgraph/subgraph-deployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ ${couponOnboardingYAML({
file: ../build/contracts/VotingContract.json
- name: IVoting
file: ../build/contracts/IVoting.json
- name: ERC20Extension
file: ../build/contracts/ERC20Extension.json
eventHandlers:
- event: SubmittedProposal(bytes32,uint256)
handler: handleSubmittedProposal
Expand Down
2 changes: 2 additions & 0 deletions subgraph/subgraph-tests/helpers/YAML.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ export const getYAML = ({ daoFactoryAddress }: GetYAMLType): string => {
file: ../build/contracts/VotingContract.json
- name: IVoting
file: ../build/contracts/IVoting.json
- name: ERC20Extension
file: ../build/contracts/ERC20Extension.json
eventHandlers:
- event: SubmittedProposal(bytes32,uint256)
handler: handleSubmittedProposal
Expand Down
6 changes: 4 additions & 2 deletions subgraph/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ dataSources:
name: DaoFactory
network: mainnet
source:
address: "0x495654405E2f080E4EE7E892EBd5Ac21255197D5"
address: "0xfa6186d6058f619d2B81d4F33aE89AB9b8988026"
abi: DaoFactory
startBlock: 34
startBlock: 17
mapping:
kind: ethereum/events
apiVersion: 0.0.4
Expand Down Expand Up @@ -66,6 +66,8 @@ templates:
file: ../build/contracts/VotingContract.json
- name: IVoting
file: ../build/contracts/IVoting.json
- name: ERC20Extension
file: ../build/contracts/ERC20Extension.json
eventHandlers:
- event: SubmittedProposal(bytes32,uint256)
handler: handleSubmittedProposal
Expand Down

0 comments on commit b097ef7

Please sign in to comment.