From 48293677256ed53463ba224f88d0b7f614bb8674 Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 13 May 2020 17:16:10 +0300 Subject: [PATCH 1/4] Arc v20 --- docker-compose.yml | 2 +- ops/mappings.json | 117 +++++++++++------- ops/templates.json | 31 +++-- package-lock.json | 22 ++-- package.json | 4 +- src/domain/dao.ts | 1 + src/domain/schema.graphql | 1 + src/mappings/Avatar/datasource.yaml | 2 - src/mappings/Avatar/mapping.ts | 17 ++- src/mappings/DAOFactory/mapping.ts | 22 +++- src/mappings/UpgradeScheme/mapping.ts | 2 +- src/mappings/Vault/datasource.yaml | 7 ++ src/mappings/Vault/mapping.ts | 14 +++ src/mappings/Vault/schema.graphql | 0 .../Avatar.spec.ts | 12 +- .../CommonSchemes.spec.ts | 16 +++ .../Competition.spec.ts | 0 .../ContributionReward.spec.ts | 0 .../Controller.spec.ts | 0 .../DAOFactory.spec.ts | 0 .../GenericScheme.spec.ts | 6 +- .../GenesisProtocol.spec.ts | 6 +- .../Reputation.spec.ts | 4 +- .../SchemeFactory.spec.ts | 0 .../SchemeRegistrar.spec.ts | 0 .../Subscription.spec.ts | 0 .../SubscriptionLoop.spec.ts | 0 .../UpgradeScheme.spec.ts | 4 +- .../contractsInfo.spec.ts | 0 .../domain.spec.ts | 0 .../{0.1.1-rc.18 => 0.1.1-rc.20}/ipfs.spec.ts | 0 test/{0.1.1-rc.18 => 0.1.1-rc.20}/util.ts | 16 +-- 32 files changed, 190 insertions(+), 116 deletions(-) create mode 100644 src/mappings/Vault/datasource.yaml create mode 100644 src/mappings/Vault/mapping.ts create mode 100644 src/mappings/Vault/schema.graphql rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/Avatar.spec.ts (76%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/CommonSchemes.spec.ts (97%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/Competition.spec.ts (100%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/ContributionReward.spec.ts (100%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/Controller.spec.ts (100%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/DAOFactory.spec.ts (100%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/GenericScheme.spec.ts (97%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/GenesisProtocol.spec.ts (97%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/Reputation.spec.ts (98%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/SchemeFactory.spec.ts (100%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/SchemeRegistrar.spec.ts (100%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/Subscription.spec.ts (100%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/SubscriptionLoop.spec.ts (100%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/UpgradeScheme.spec.ts (98%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/contractsInfo.spec.ts (100%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/domain.spec.ts (100%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/ipfs.spec.ts (100%) rename test/{0.1.1-rc.18 => 0.1.1-rc.20}/util.ts (96%) diff --git a/docker-compose.yml b/docker-compose.yml index c76a4831..befe2b36 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,6 +31,6 @@ services: environment: POSTGRES_PASSWORD: letmein ganache: - image: 'daostack/migration-experimental:0.1.1-rc.18-v0' + image: 'daostack/migration-experimental:0.1.1-rc.20-v0' ports: - '8545:8545' diff --git a/ops/mappings.json b/ops/mappings.json index 0375de1e..b6d4d72e 100644 --- a/ops/mappings.json +++ b/ops/mappings.json @@ -7,112 +7,119 @@ "contractName": "DAOToken", "dao": "package", "mapping": "DAOToken", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "Reputation", "contractName": "Reputation", "dao": "package", "mapping": "Reputation", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "Avatar", "contractName": "Avatar", "dao": "package", "mapping": "Avatar", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" + }, + { + "name": "Vault", + "contractName": "Vault", + "dao": "package", + "mapping": "Vault", + "arcVersion": "0.1.1-rc.20" }, { "name": "Controller", "contractName": "Controller", "dao": "package", "mapping": "Controller", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "GenesisProtocol", "contractName": "GenesisProtocol", "dao": "package", "mapping": "GenesisProtocol", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "DAORegistry", "contractName": "DAORegistryInstance", "dao": "package", "mapping": "DAORegistry", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "DAOFactory", "contractName": "DAOFactoryInstance", "dao": "package", "mapping": "DAOFactory", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "ContributionReward", "contractName": "ContributionReward", "dao": "package", "mapping": "ContributionReward", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "ContributionRewardExt", "contractName": "ContributionRewardExt", "dao": "package", "mapping": "ContributionRewardExt", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "Competition", "contractName": "Competition", "dao": "package", "mapping": "Competition", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "SchemeFactory", "contractName": "SchemeFactory", "dao": "package", "mapping": "SchemeFactory", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "SchemeRegistrar", "contractName": "SchemeRegistrar", "dao": "package", "mapping": "SchemeRegistrar", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "GenericScheme", "contractName": "GenericScheme", "dao": "package", "mapping": "GenericScheme", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "UpgradeScheme", "contractName": "UpgradeScheme", "dao": "package", "mapping": "UpgradeScheme", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "JoinAndQuit", "contractName": "JoinAndQuit", "dao": "package", "mapping": "JoinAndQuit", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "FundingRequest", "contractName": "FundingRequest", "dao": "package", "mapping": "FundingRequest", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" } ] }, @@ -124,112 +131,119 @@ "contractName": "DAOToken", "dao": "package", "mapping": "DAOToken", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "Reputation", "contractName": "Reputation", "dao": "package", "mapping": "Reputation", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "Avatar", "contractName": "Avatar", "dao": "package", "mapping": "Avatar", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" + }, + { + "name": "Vault", + "contractName": "Vault", + "dao": "package", + "mapping": "Vault", + "arcVersion": "0.1.1-rc.20" }, { "name": "Controller", "contractName": "Controller", "dao": "package", "mapping": "Controller", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "GenesisProtocol", "contractName": "GenesisProtocol", "dao": "package", "mapping": "GenesisProtocol", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "DAORegistry", "contractName": "DAORegistryInstance", "dao": "package", "mapping": "DAORegistry", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "DAOFactory", "contractName": "DAOFactoryInstance", "dao": "package", "mapping": "DAOFactory", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "ContributionReward", "contractName": "ContributionReward", "dao": "package", "mapping": "ContributionReward", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "ContributionRewardExt", "contractName": "ContributionRewardExt", "dao": "package", "mapping": "ContributionRewardExt", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "Competition", "contractName": "Competition", "dao": "package", "mapping": "Competition", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "SchemeFactory", "contractName": "SchemeFactory", "dao": "package", "mapping": "SchemeFactory", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "SchemeRegistrar", "contractName": "SchemeRegistrar", "dao": "package", "mapping": "SchemeRegistrar", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "GenericScheme", "contractName": "GenericScheme", "dao": "package", "mapping": "GenericScheme", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "UpgradeScheme", "contractName": "UpgradeScheme", "dao": "package", "mapping": "UpgradeScheme", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "JoinAndQuit", "contractName": "JoinAndQuit", "dao": "package", "mapping": "JoinAndQuit", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "FundingRequest", "contractName": "FundingRequest", "dao": "package", "mapping": "FundingRequest", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" } ] }, @@ -241,112 +255,119 @@ "contractName": "DAOToken", "dao": "package", "mapping": "DAOToken", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "Reputation", "contractName": "Reputation", "dao": "package", "mapping": "Reputation", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "Avatar", "contractName": "Avatar", "dao": "package", "mapping": "Avatar", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" + }, + { + "name": "Vault", + "contractName": "Vault", + "dao": "package", + "mapping": "Vault", + "arcVersion": "0.1.1-rc.20" }, { "name": "Controller", "contractName": "Controller", "dao": "package", "mapping": "Controller", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "GenesisProtocol", "contractName": "GenesisProtocol", "dao": "package", "mapping": "GenesisProtocol", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "DAORegistry", "contractName": "DAORegistryInstance", "dao": "package", "mapping": "DAORegistry", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "DAOFactory", "contractName": "DAOFactoryInstance", "dao": "package", "mapping": "DAOFactory", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "ContributionReward", "contractName": "ContributionReward", "dao": "package", "mapping": "ContributionReward", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "ContributionRewardExt", "contractName": "ContributionRewardExt", "dao": "package", "mapping": "ContributionRewardExt", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "Competition", "contractName": "Competition", "dao": "package", "mapping": "Competition", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "SchemeFactory", "contractName": "SchemeFactory", "dao": "package", "mapping": "SchemeFactory", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "SchemeRegistrar", "contractName": "SchemeRegistrar", "dao": "package", "mapping": "SchemeRegistrar", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "GenericScheme", "contractName": "GenericScheme", "dao": "package", "mapping": "GenericScheme", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "UpgradeScheme", "contractName": "UpgradeScheme", "dao": "package", "mapping": "UpgradeScheme", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "JoinAndQuit", "contractName": "JoinAndQuit", "dao": "package", "mapping": "JoinAndQuit", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" }, { "name": "FundingRequest", "contractName": "FundingRequest", "dao": "package", "mapping": "FundingRequest", - "arcVersion": "0.1.1-rc.18" + "arcVersion": "0.1.1-rc.20" } ] } diff --git a/ops/templates.json b/ops/templates.json index 50307324..08914fe9 100644 --- a/ops/templates.json +++ b/ops/templates.json @@ -3,67 +3,72 @@ { "name": "Avatar", "mapping": "Avatar", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" + }, + { + "name": "Vault", + "mapping": "Vault", + "start_arcVersion": "0.1.1-rc.20" }, { "name": "Controller", "mapping": "Controller", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" }, { "name": "DAOToken", "mapping": "DAOToken", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" }, { "name": "Reputation", "mapping": "Reputation", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" }, { "name": "ContributionReward", "mapping": "ContributionReward", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" }, { "name": "ContributionRewardExt", "mapping": "ContributionRewardExt", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" }, { "name": "Competition", "mapping": "Competition", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" }, { "name": "GenericScheme", "mapping": "GenericScheme", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" }, { "name": "UpgradeScheme", "mapping": "UpgradeScheme", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" }, { "name": "JoinAndQuit", "mapping": "JoinAndQuit", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" }, { "name": "FundingRequest", "mapping": "FundingRequest", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" }, { "name": "SchemeFactory", "mapping": "SchemeFactory", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" }, { "name": "SchemeRegistrar", "mapping": "SchemeRegistrar", - "start_arcVersion": "0.1.1-rc.18" + "start_arcVersion": "0.1.1-rc.20" } ] } diff --git a/package-lock.json b/package-lock.json index 1f8d92d1..7d4710a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@daostack/subgraph-experimental", - "version": "0.1.1-rc.7-v8", + "version": "0.1.1-rc.8-v0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -182,9 +182,9 @@ } }, "@daostack/arc-experimental": { - "version": "0.1.1-rc.18", - "resolved": "https://registry.npmjs.org/@daostack/arc-experimental/-/arc-experimental-0.1.1-rc.18.tgz", - "integrity": "sha512-cp9c8juwfg+Lo3Cz5lYZnGwbKAV+gQ25eW0LXrIOxTHKclc9z/nz5MFT2zjxnlSN5Iy1Xot2fwyx3tiQe/DaXQ==", + "version": "0.1.1-rc.20", + "resolved": "https://registry.npmjs.org/@daostack/arc-experimental/-/arc-experimental-0.1.1-rc.20.tgz", + "integrity": "sha512-o/uRZc/A3/QHFWIk6GJrJIIuatB3j02iMkk1/IEVTVlw7M257+cM/9gUMPU9y+pT/olYth3QrdSmNv0XqtAlwQ==", "dev": true, "requires": { "@daostack/infra-experimental": "0.0.1-rc.16", @@ -1537,12 +1537,12 @@ } }, "@daostack/migration-experimental": { - "version": "0.1.1-rc.18-v0", - "resolved": "https://registry.npmjs.org/@daostack/migration-experimental/-/migration-experimental-0.1.1-rc.18-v0.tgz", - "integrity": "sha512-r8+540LQmkbJECxBqs5EQEuTRiE7+PseE9S0mWxZ6uejkkUHx5ErhimSjW8+I/z143vGgDX2O2pV+I+WpKkFnw==", + "version": "0.1.1-rc.20-v0", + "resolved": "https://registry.npmjs.org/@daostack/migration-experimental/-/migration-experimental-0.1.1-rc.20-v0.tgz", + "integrity": "sha512-5c3MYwj1qefMn78JZJg/wkGrPtqkLBc/btZFdpRl5m4H1vBGdblIrJfrXjr/hkTySXklOrUGhM1u5S3gdAk6Iw==", "dev": true, "requires": { - "@daostack/arc-experimental": "0.1.1-rc.18", + "@daostack/arc-experimental": "0.1.1-rc.20", "@daostack/arc-hive": "0.0.1-rc.5", "ethereumjs-wallet": "^0.6.3", "fstream": "^1.0.12", @@ -2033,9 +2033,9 @@ }, "dependencies": { "@types/node": { - "version": "12.12.38", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.38.tgz", - "integrity": "sha512-75eLjX0pFuTcUXnnWmALMzzkYorjND0ezNEycaKesbUBg9eGZp4GHPuDmkRc4mQQvIpe29zrzATNRA6hkYqwmA==", + "version": "12.12.39", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.39.tgz", + "integrity": "sha512-pADGfwnDkr6zagDwEiCVE4yQrv7XDkoeVa4OfA9Ju/zRTk6YNDLGtQbkdL4/56mCQQCs4AhNrBIag6jrp7ZuOg==", "dev": true }, "aes-js": { diff --git a/package.json b/package.json index 2b10466b..90c0ff2a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@daostack/subgraph-experimental", - "version": "0.1.1-rc.7-v8", + "version": "0.1.1-rc.8-v0", "author": "DAOstack (https://www.daostack.io)", "license": "GPL-3.0", "description": "A caching layer for daostack using The Graph", @@ -32,7 +32,7 @@ "test:watch": "npm run test -- --watch" }, "devDependencies": { - "@daostack/migration-experimental": "0.1.1-rc.18-v0", + "@daostack/migration-experimental": "0.1.1-rc.20-v0", "@types/jest": "^23.3.7", "@types/mocha": "^5.2.5", "babel-eslint": "^10.0.1", diff --git a/src/domain/dao.ts b/src/domain/dao.ts index b93109f7..0bac659c 100644 --- a/src/domain/dao.ts +++ b/src/domain/dao.ts @@ -10,6 +10,7 @@ export function getDAO(id: string): DAO { dao.numberOfPreBoostedProposals = BigInt.fromI32(0); dao.numberOfBoostedProposals = BigInt.fromI32(0); dao.numberOfExpiredInQueueProposals = BigInt.fromI32(0); + dao.ethBalance = BigInt.fromI32(0); } return dao; diff --git a/src/domain/schema.graphql b/src/domain/schema.graphql index ad487810..f863fc90 100644 --- a/src/domain/schema.graphql +++ b/src/domain/schema.graphql @@ -29,6 +29,7 @@ type DAO @entity { error: String metadata: String! metadataHash: String! + ethBalance: BigInt! } type GPQueue @entity { diff --git a/src/mappings/Avatar/datasource.yaml b/src/mappings/Avatar/datasource.yaml index e5130090..2261d685 100644 --- a/src/mappings/Avatar/datasource.yaml +++ b/src/mappings/Avatar/datasource.yaml @@ -1,8 +1,6 @@ entities: - AvatarContract - - Vault eventHandlers: - # TODO: Add send and receive ETH with Vault support - event: OwnershipTransferred(indexed address,indexed address) handler: handleOwnershipTransferred - event: MetaData(string) diff --git a/src/mappings/Avatar/mapping.ts b/src/mappings/Avatar/mapping.ts index d9826afd..ac3b5935 100644 --- a/src/mappings/Avatar/mapping.ts +++ b/src/mappings/Avatar/mapping.ts @@ -9,8 +9,9 @@ import { Avatar, MetaData, OwnershipTransferred } from '../../types/Avatar/Avata import { AvatarContract } from '../../types/schema'; import * as domain from '../../domain'; +import { getDAO } from '../../domain/dao'; -function handleAvatarBalance( +export function handleAvatarBalance( address: Address, value: BigInt, received: boolean, @@ -26,16 +27,12 @@ function handleAvatarBalance( avatar.balance = avatar.balance.minus(value); } - store.set('AvatarContract', avatar.id, avatar); -} - -// export function handleSendEth(event: SendEther): void { -// handleAvatarBalance(event.address, event.params._amountInWei, false); -// } + avatar.save(); -// export function handleReceiveEth(event: ReceiveEther): void { -// handleAvatarBalance(event.address, event.params._value, true); -// } + let dao = getDAO(address.toHex()); + dao.ethBalance = avatar.balance; + dao.save(); +} export function handleOwnershipTransferred(event: OwnershipTransferred): void { let avatar = AvatarContract.load(event.address.toHex()); diff --git a/src/mappings/DAOFactory/mapping.ts b/src/mappings/DAOFactory/mapping.ts index fb5eaa76..42ca8e39 100644 --- a/src/mappings/DAOFactory/mapping.ts +++ b/src/mappings/DAOFactory/mapping.ts @@ -9,13 +9,14 @@ import { insertNewDAO } from '../../domain/dao'; import { addNewDAOEvent } from '../../domain/event'; import { insertReputation } from '../../domain/reputation'; import { insertToken, updateTokenTotalSupply } from '../../domain/token'; +import { Avatar } from '../../types/Controller/Avatar'; import { DAOToken } from '../../types/Controller/DAOToken'; import { Reputation } from '../../types/Controller/Reputation'; import { DAOFactory, NewOrg, ProxyCreated } from '../../types/DAOFactory/DAOFactory'; import { ControllerOrganization, DAOFactoryContract, ReputationContract, ReputationHolder, TokenContract, } from '../../types/schema'; -import { createTemplate, fetchTemplateName, hexToAddress, setContractInfo } from '../../utils'; +import { createTemplate, equalStrings, fetchTemplateName, hexToAddress, setContractInfo } from '../../utils'; function getDAOFactoryContract(address: Address): DAOFactoryContract { let daoFactory = DAOFactoryContract.load(address.toHex()) as DAOFactoryContract; @@ -85,14 +86,23 @@ export function handleProxyCreated(event: ProxyCreated): void { let fullVersion = event.params._version; let version = '0.1.1-rc.' + fullVersion[2].toString(); + addContract(event.params._proxy, event.params._contractName, version); + + if (equalStrings(event.params._contractName, 'Avatar')) { + let avatar = Avatar.bind(event.params._proxy); + addContract(avatar.vault(), 'Vault', version); + } +} + +function addContract(proxy: Address, contractName: string, version: string): void { setContractInfo( - event.params._proxy.toHex(), - event.params._contractName, - event.params._contractName + event.params._proxy.toHex(), + proxy.toHex(), + contractName, + contractName + proxy.toHex(), version.toString(), ); - let schemeTemplate = fetchTemplateName(event.params._contractName, version); + let schemeTemplate = fetchTemplateName(contractName, version); if (schemeTemplate == null) { // We're missing a template version in the subgraph @@ -101,5 +111,5 @@ export function handleProxyCreated(event: ProxyCreated): void { // Tell the subgraph to start indexing events from the: // Avatar, Controller, DAOToken, and Reputation contracts - createTemplate(schemeTemplate, event.params._proxy); + createTemplate(schemeTemplate, proxy); } diff --git a/src/mappings/UpgradeScheme/mapping.ts b/src/mappings/UpgradeScheme/mapping.ts index 81079843..c269308f 100644 --- a/src/mappings/UpgradeScheme/mapping.ts +++ b/src/mappings/UpgradeScheme/mapping.ts @@ -68,7 +68,7 @@ export function handleProposalExecuted( let v0 = v0Int.toString(); let v1 = v1Int.toString(); let v2 = v2Int.toString(); - // 0.1.1-rc.18 + // 0.1.1-rc.20 contractInfo.version = v0 + '.' + v1 + '.' + v1 + '-rc.' + v2; contractInfo.name = (proposal.contractsNames as Bytes[])[i].toString(); contractInfo.save(); diff --git a/src/mappings/Vault/datasource.yaml b/src/mappings/Vault/datasource.yaml new file mode 100644 index 00000000..461e5171 --- /dev/null +++ b/src/mappings/Vault/datasource.yaml @@ -0,0 +1,7 @@ +entities: + - AvatarContract +eventHandlers: + - event: ReceiveEther(indexed address,uint256) + handler: handleReceiveEther + - event: SendEther(indexed address,uint256) + handler: handleSendEther \ No newline at end of file diff --git a/src/mappings/Vault/mapping.ts b/src/mappings/Vault/mapping.ts new file mode 100644 index 00000000..986f61ff --- /dev/null +++ b/src/mappings/Vault/mapping.ts @@ -0,0 +1,14 @@ +import { ReceiveEther, SendEther, Vault } from '../../types/Vault/Vault'; +import { handleAvatarBalance } from '../Avatar/mapping'; + +export function handleReceiveEther(event: ReceiveEther): void { + let vault = Vault.bind(event.address); + let avatar = vault.owner(); + handleAvatarBalance(avatar, event.params._value, true); +} + +export function handleSendEther(event: SendEther): void { + let vault = Vault.bind(event.address); + let avatar = vault.owner(); + handleAvatarBalance(avatar, event.params._value, false); +} diff --git a/src/mappings/Vault/schema.graphql b/src/mappings/Vault/schema.graphql new file mode 100644 index 00000000..e69de29b diff --git a/test/0.1.1-rc.18/Avatar.spec.ts b/test/0.1.1-rc.20/Avatar.spec.ts similarity index 76% rename from test/0.1.1-rc.18/Avatar.spec.ts rename to test/0.1.1-rc.20/Avatar.spec.ts index 5bfdfbd1..653964dc 100755 --- a/test/0.1.1-rc.18/Avatar.spec.ts +++ b/test/0.1.1-rc.20/Avatar.spec.ts @@ -1,17 +1,22 @@ -import { getContractAddresses, getOrgName, getWeb3, sendQuery, waitUntilTrue } from './util'; +import { getArcVersion, getContractAddresses, getOptions, getOrgName, getWeb3, sendQuery } from './util'; +const Avatar = require('@daostack/migration-experimental/contracts/' + getArcVersion() + '/Avatar.json'); describe('Avatar', () => { let web3; let addresses; + let opts; const orgName = getOrgName(); beforeAll(async () => { web3 = await getWeb3(); addresses = getContractAddresses(); + opts = await getOptions(web3); }); it('Sanity', async () => { const accounts = web3.eth.accounts.wallet; + const avatar = new web3.eth.Contract(Avatar.abi, addresses.Avatar, opts); + const vault = await avatar.methods.vault().call(); const avatarQuery = `{ avatarContract(id: "${addresses.Avatar.toLowerCase()}") { @@ -26,7 +31,7 @@ describe('Avatar', () => { } }`; const { avatarContract } = await sendQuery(avatarQuery, 5000); - let balance = await web3.eth.getBalance(addresses.Avatar.toLowerCase()); + let balance = await web3.eth.getBalance(vault); expect(avatarContract).toEqual({ id: addresses.Avatar.toLowerCase(), address: addresses.Avatar.toLowerCase(), @@ -43,10 +48,9 @@ describe('Avatar', () => { to: addresses.Avatar, value: web3.utils.toWei('1'), gas: 2000000, - data: '0xABCD', }); - balance = await web3.eth.getBalance(addresses.Avatar.toLowerCase()); + balance = await web3.eth.getBalance(vault); const newAvatar = (await sendQuery(avatarQuery, 5000)).avatarContract; expect(newAvatar).toEqual({ id: addresses.Avatar.toLowerCase(), diff --git a/test/0.1.1-rc.18/CommonSchemes.spec.ts b/test/0.1.1-rc.20/CommonSchemes.spec.ts similarity index 97% rename from test/0.1.1-rc.18/CommonSchemes.spec.ts rename to test/0.1.1-rc.20/CommonSchemes.spec.ts index 098f33ae..96cffeb9 100644 --- a/test/0.1.1-rc.18/CommonSchemes.spec.ts +++ b/test/0.1.1-rc.20/CommonSchemes.spec.ts @@ -245,6 +245,17 @@ describe('JoinAndQuit Scheme', () => { let vault = await avatar.methods.vault().call(); let refund = await web3.eth.getBalance((vault)); + const getDao = `{ + dao(id: "${addresses.Avatar.toLowerCase()}") { + ethBalance + } + }`; + + let dao = (await sendQuery(getDao)).dao; + expect(dao).toContainEqual({ + ethBalance: refund, + }); + const getRageQuits = `{ rageQuitteds { dao { @@ -263,6 +274,11 @@ describe('JoinAndQuit Scheme', () => { rageQuitter: accounts[7].address.toLowerCase(), refund: refund.toString(), }); + + dao = (await sendQuery(getDao)).dao; + expect(dao).toContainEqual({ + ethBalance: '0', + }); }, 100000); it('FundingRequest proposal', async () => { diff --git a/test/0.1.1-rc.18/Competition.spec.ts b/test/0.1.1-rc.20/Competition.spec.ts similarity index 100% rename from test/0.1.1-rc.18/Competition.spec.ts rename to test/0.1.1-rc.20/Competition.spec.ts diff --git a/test/0.1.1-rc.18/ContributionReward.spec.ts b/test/0.1.1-rc.20/ContributionReward.spec.ts similarity index 100% rename from test/0.1.1-rc.18/ContributionReward.spec.ts rename to test/0.1.1-rc.20/ContributionReward.spec.ts diff --git a/test/0.1.1-rc.18/Controller.spec.ts b/test/0.1.1-rc.20/Controller.spec.ts similarity index 100% rename from test/0.1.1-rc.18/Controller.spec.ts rename to test/0.1.1-rc.20/Controller.spec.ts diff --git a/test/0.1.1-rc.18/DAOFactory.spec.ts b/test/0.1.1-rc.20/DAOFactory.spec.ts similarity index 100% rename from test/0.1.1-rc.18/DAOFactory.spec.ts rename to test/0.1.1-rc.20/DAOFactory.spec.ts diff --git a/test/0.1.1-rc.18/GenericScheme.spec.ts b/test/0.1.1-rc.20/GenericScheme.spec.ts similarity index 97% rename from test/0.1.1-rc.18/GenericScheme.spec.ts rename to test/0.1.1-rc.20/GenericScheme.spec.ts index 8bf7752f..71e49a54 100644 --- a/test/0.1.1-rc.18/GenericScheme.spec.ts +++ b/test/0.1.1-rc.20/GenericScheme.spec.ts @@ -7,9 +7,9 @@ import { waitUntilTrue, } from './util'; -const ActionMock = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/ActionMock.json'); -const GenericScheme = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/GenericScheme.json'); -const GenesisProtocol = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/GenesisProtocol.json'); +const ActionMock = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/ActionMock.json'); +const GenericScheme = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/GenericScheme.json'); +const GenesisProtocol = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/GenesisProtocol.json'); describe('Generic Scheme', () => { let web3; diff --git a/test/0.1.1-rc.18/GenesisProtocol.spec.ts b/test/0.1.1-rc.20/GenesisProtocol.spec.ts similarity index 97% rename from test/0.1.1-rc.18/GenesisProtocol.spec.ts rename to test/0.1.1-rc.20/GenesisProtocol.spec.ts index 711c3be2..f90c6f2c 100644 --- a/test/0.1.1-rc.18/GenesisProtocol.spec.ts +++ b/test/0.1.1-rc.20/GenesisProtocol.spec.ts @@ -9,9 +9,9 @@ import { waitUntilTrue, } from './util'; -const ContributionReward = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/ContributionReward.json'); -const DAOToken = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/DAOToken.json'); -const GenesisProtocol = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/GenesisProtocol.json'); +const ContributionReward = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/ContributionReward.json'); +const DAOToken = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/DAOToken.json'); +const GenesisProtocol = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/GenesisProtocol.json'); describe('GenesisProtocol', () => { let web3; diff --git a/test/0.1.1-rc.18/Reputation.spec.ts b/test/0.1.1-rc.20/Reputation.spec.ts similarity index 98% rename from test/0.1.1-rc.18/Reputation.spec.ts rename to test/0.1.1-rc.20/Reputation.spec.ts index 79b0dafe..a59bc993 100644 --- a/test/0.1.1-rc.18/Reputation.spec.ts +++ b/test/0.1.1-rc.20/Reputation.spec.ts @@ -1,7 +1,7 @@ import { getContractAddresses, getOptions, getWeb3, prepareReputation, sendQuery, waitUntilTrue } from './util'; -const Controller = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/Controller.json'); -const Reputation = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/Reputation.json'); +const Controller = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/Controller.json'); +const Reputation = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/Reputation.json'); describe('Reputation', () => { let web3; diff --git a/test/0.1.1-rc.18/SchemeFactory.spec.ts b/test/0.1.1-rc.20/SchemeFactory.spec.ts similarity index 100% rename from test/0.1.1-rc.18/SchemeFactory.spec.ts rename to test/0.1.1-rc.20/SchemeFactory.spec.ts diff --git a/test/0.1.1-rc.18/SchemeRegistrar.spec.ts b/test/0.1.1-rc.20/SchemeRegistrar.spec.ts similarity index 100% rename from test/0.1.1-rc.18/SchemeRegistrar.spec.ts rename to test/0.1.1-rc.20/SchemeRegistrar.spec.ts diff --git a/test/0.1.1-rc.18/Subscription.spec.ts b/test/0.1.1-rc.20/Subscription.spec.ts similarity index 100% rename from test/0.1.1-rc.18/Subscription.spec.ts rename to test/0.1.1-rc.20/Subscription.spec.ts diff --git a/test/0.1.1-rc.18/SubscriptionLoop.spec.ts b/test/0.1.1-rc.20/SubscriptionLoop.spec.ts similarity index 100% rename from test/0.1.1-rc.18/SubscriptionLoop.spec.ts rename to test/0.1.1-rc.20/SubscriptionLoop.spec.ts diff --git a/test/0.1.1-rc.18/UpgradeScheme.spec.ts b/test/0.1.1-rc.20/UpgradeScheme.spec.ts similarity index 98% rename from test/0.1.1-rc.18/UpgradeScheme.spec.ts rename to test/0.1.1-rc.20/UpgradeScheme.spec.ts index 87b434dd..9bdd912b 100644 --- a/test/0.1.1-rc.18/UpgradeScheme.spec.ts +++ b/test/0.1.1-rc.20/UpgradeScheme.spec.ts @@ -9,8 +9,8 @@ import { waitUntilTrue, } from './util'; -const UpgradeScheme = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/UpgradeScheme.json'); -const GenesisProtocol = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/GenesisProtocol.json'); +const UpgradeScheme = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/UpgradeScheme.json'); +const GenesisProtocol = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/GenesisProtocol.json'); describe('Generic Scheme', () => { let web3; diff --git a/test/0.1.1-rc.18/contractsInfo.spec.ts b/test/0.1.1-rc.20/contractsInfo.spec.ts similarity index 100% rename from test/0.1.1-rc.18/contractsInfo.spec.ts rename to test/0.1.1-rc.20/contractsInfo.spec.ts diff --git a/test/0.1.1-rc.18/domain.spec.ts b/test/0.1.1-rc.20/domain.spec.ts similarity index 100% rename from test/0.1.1-rc.18/domain.spec.ts rename to test/0.1.1-rc.20/domain.spec.ts diff --git a/test/0.1.1-rc.18/ipfs.spec.ts b/test/0.1.1-rc.20/ipfs.spec.ts similarity index 100% rename from test/0.1.1-rc.18/ipfs.spec.ts rename to test/0.1.1-rc.20/ipfs.spec.ts diff --git a/test/0.1.1-rc.18/util.ts b/test/0.1.1-rc.20/util.ts similarity index 96% rename from test/0.1.1-rc.18/util.ts rename to test/0.1.1-rc.20/util.ts index a13180c2..57e0804f 100644 --- a/test/0.1.1-rc.18/util.ts +++ b/test/0.1.1-rc.20/util.ts @@ -54,7 +54,7 @@ export async function getWeb3() { export function getContractAddresses() { const addresses = require(`@daostack/migration-experimental/migration.json`); - let arcVersion = '0.1.1-rc.18'; + let arcVersion = '0.1.1-rc.20'; return { ...addresses.private.package[arcVersion], @@ -74,7 +74,7 @@ export function getContractAddresses() { } export function getArcVersion() { - return '0.1.1-rc.18'; + return '0.1.1-rc.20'; } export function getPackageVersion() { @@ -82,7 +82,7 @@ export function getPackageVersion() { } export function getOrgName() { - return require(`@daostack/migration-experimental/migration.json`).private.dao['0.1.1-rc.18'].name; + return require(`@daostack/migration-experimental/migration.json`).private.dao['0.1.1-rc.20'].name; } export async function getOptions(web3) { @@ -156,9 +156,9 @@ export async function waitUntilSynced() { } export async function registerAdminAccountScheme(web3, addresses, opts, accounts) { - const Controller = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/Controller.json'); - const SchemeRegistrar = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/SchemeRegistrar.json'); - const GenesisProtocol = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/GenesisProtocol.json'); + const Controller = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/Controller.json'); + const SchemeRegistrar = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/SchemeRegistrar.json'); + const GenesisProtocol = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/GenesisProtocol.json'); const controller = new web3.eth.Contract(Controller.abi, addresses.Controller, opts); const genesisProtocol = new web3.eth.Contract(GenesisProtocol.abi, addresses.GenesisProtocol, opts); @@ -183,8 +183,8 @@ export async function registerAdminAccountScheme(web3, addresses, opts, accounts } export async function prepareReputation(web3, addresses, opts, accounts) { - const Controller = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/Controller.json'); - const Reputation = require('@daostack/migration-experimental/contracts/0.1.1-rc.18/Reputation.json'); + const Controller = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/Controller.json'); + const Reputation = require('@daostack/migration-experimental/contracts/0.1.1-rc.20/Reputation.json'); await registerAdminAccountScheme(web3, addresses, opts, accounts); const controller = new web3.eth.Contract(Controller.abi, addresses.Controller, opts); From 522443696733145fd6061b02f7b76ddfcb7b303c Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 13 May 2020 17:28:34 +0300 Subject: [PATCH 2/4] Update CommonSchemes.spec.ts --- test/0.1.1-rc.20/CommonSchemes.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/0.1.1-rc.20/CommonSchemes.spec.ts b/test/0.1.1-rc.20/CommonSchemes.spec.ts index 96cffeb9..6f808347 100644 --- a/test/0.1.1-rc.20/CommonSchemes.spec.ts +++ b/test/0.1.1-rc.20/CommonSchemes.spec.ts @@ -252,7 +252,7 @@ describe('JoinAndQuit Scheme', () => { }`; let dao = (await sendQuery(getDao)).dao; - expect(dao).toContainEqual({ + expect(dao).toEqual({ ethBalance: refund, }); @@ -276,7 +276,7 @@ describe('JoinAndQuit Scheme', () => { }); dao = (await sendQuery(getDao)).dao; - expect(dao).toContainEqual({ + expect(dao).toEqual({ ethBalance: '0', }); }, 100000); From 2c295e7d03fe87a332721a697b05a2f6ef80cac8 Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 13 May 2020 17:40:23 +0300 Subject: [PATCH 3/4] Update CommonSchemes.spec.ts --- test/0.1.1-rc.20/CommonSchemes.spec.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/0.1.1-rc.20/CommonSchemes.spec.ts b/test/0.1.1-rc.20/CommonSchemes.spec.ts index 6f808347..1afb3cbc 100644 --- a/test/0.1.1-rc.20/CommonSchemes.spec.ts +++ b/test/0.1.1-rc.20/CommonSchemes.spec.ts @@ -240,22 +240,22 @@ describe('JoinAndQuit Scheme', () => { voter: accounts[2].address, }); - await rageQuit({ quitter: accounts[7].address }); - - let vault = await avatar.methods.vault().call(); - let refund = await web3.eth.getBalance((vault)); - const getDao = `{ dao(id: "${addresses.Avatar.toLowerCase()}") { ethBalance } }`; + let vault = await avatar.methods.vault().call(); let dao = (await sendQuery(getDao)).dao; expect(dao).toEqual({ - ethBalance: refund, + ethBalance: await web3.eth.getBalance((vault)), }); + await rageQuit({ quitter: accounts[7].address }); + + let refund = await web3.eth.getBalance((vault)); + const getRageQuits = `{ rageQuitteds { dao { @@ -277,7 +277,7 @@ describe('JoinAndQuit Scheme', () => { dao = (await sendQuery(getDao)).dao; expect(dao).toEqual({ - ethBalance: '0', + ethBalance: refund, }); }, 100000); From a9c85059258482fcbe0c568324c6d077f8b9458c Mon Sep 17 00:00:00 2001 From: benk10 Date: Wed, 13 May 2020 17:58:23 +0300 Subject: [PATCH 4/4] Update DAOFactory.spec.ts --- test/0.1.1-rc.20/DAOFactory.spec.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/0.1.1-rc.20/DAOFactory.spec.ts b/test/0.1.1-rc.20/DAOFactory.spec.ts index 2ebcb9d8..beeccb38 100644 --- a/test/0.1.1-rc.20/DAOFactory.spec.ts +++ b/test/0.1.1-rc.20/DAOFactory.spec.ts @@ -227,12 +227,6 @@ describe('DAOFactory', () => { }, }, schemes: [ - { - address: addresses.DAOFactoryInstance.toLowerCase(), - contributionRewardParams: null, - name: 'DAOFactoryInstance', - isRegistered: false, - }, { address: contributionRewardAddress.toLowerCase(), contributionRewardParams: { @@ -241,6 +235,12 @@ describe('DAOFactory', () => { name: 'ContributionReward', isRegistered: true, }, + { + address: addresses.DAOFactoryInstance.toLowerCase(), + contributionRewardParams: null, + name: 'DAOFactoryInstance', + isRegistered: false, + }, ], metadata, metadataHash,