From 6973f9fdc32d988287db247a558694e7872ebdea Mon Sep 17 00:00:00 2001 From: tki Date: Mon, 25 Jul 2022 17:43:52 +0200 Subject: [PATCH 01/20] Update contract ABIs --- abis/IPollenDAO.json | 157 ++++++++++++++++++++++++++++++++++------- abis/Leagues.json | 97 ++++++++++++++----------- abis/LockedPollen.json | 38 +++++----- abis/Minter.json | 50 +++++++++++++ abis/Portfolio.json | 82 +++++++++++++++++++++ 5 files changed, 340 insertions(+), 84 deletions(-) diff --git a/abis/IPollenDAO.json b/abis/IPollenDAO.json index 17a54d9..5dfdfb4 100644 --- a/abis/IPollenDAO.json +++ b/abis/IPollenDAO.json @@ -426,6 +426,32 @@ "name": "QuorumChanged", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "rebalanceFee", + "type": "uint256" + } + ], + "name": "RebalanceFeeSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "rebalanceFeeVault", + "type": "address" + } + ], + "name": "RebalanceFeeVaultSet", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -728,6 +754,11 @@ "name": "weights", "type": "uint256[]" }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, { "internalType": "bool", "name": "tokenType", @@ -801,6 +832,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [], + "name": "getBoostingScale", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -869,6 +913,16 @@ "internalType": "uint256", "name": "benchMarkRef", "type": "uint256" + }, + { + "internalType": "uint256", + "name": "shortsValue", + "type": "uint256" + }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" } ], "stateMutability": "view", @@ -885,6 +939,16 @@ "internalType": "uint256[]", "name": "prices", "type": "uint256[]" + }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "shortsValue", + "type": "uint256" } ], "name": "getPortfolioValue", @@ -982,6 +1046,30 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "uint256", + "name": "currentValue", + "type": "uint256" + } + ], + "name": "getRewardRate", + "outputs": [ + { + "internalType": "uint256", + "name": "rate", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [], "name": "getTimeLock", @@ -1320,6 +1408,11 @@ "name": "weights", "type": "uint256[]" }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, { "internalType": "uint256", "name": "amount", @@ -1333,7 +1426,7 @@ ], "name": "rebalancePortfolio", "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "payable", "type": "function" }, { @@ -1374,6 +1467,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_newBoostingScale", + "type": "uint256" + } + ], + "name": "setBoostingScale", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -1449,6 +1555,32 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "rebalanceFee", + "type": "uint256" + } + ], + "name": "setRebalanceFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "rebalanceFeeVault", + "type": "address" + } + ], + "name": "setRebalanceFeeVault", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -1514,29 +1646,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "address", - "name": "to", - "type": "address" - }, - { - "internalType": "address", - "name": "tokenAddr", - "type": "address" - } - ], - "name": "transferFunds", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { diff --git a/abis/Leagues.json b/abis/Leagues.json index b91493c..fcc813d 100644 --- a/abis/Leagues.json +++ b/abis/Leagues.json @@ -1,20 +1,4 @@ [ - { - "inputs": [ - { - "internalType": "address", - "name": "plnAddress", - "type": "address" - }, - { - "internalType": "string", - "name": "uri_", - "type": "string" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, { "anonymous": false, "inputs": [ @@ -141,6 +125,31 @@ "name": "NewLeague", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "oldAdmin", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newAdmin", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "leagueId", + "type": "uint256" + } + ], + "name": "TransferAdminRole", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -215,31 +224,6 @@ "name": "TransferSingle", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "address", - "name": "oldAdmin", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "newAdmin", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "leagueId", - "type": "uint256" - } - ], - "name": "TrasnferAdminRole", - "type": "event" - }, { "anonymous": false, "inputs": [ @@ -346,6 +330,24 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "string", + "name": "uri_", + "type": "string" + }, + { + "internalType": "address", + "name": "plnAddress", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { @@ -443,6 +445,19 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "pln", + "outputs": [ + { + "internalType": "contract IERC20", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { diff --git a/abis/LockedPollen.json b/abis/LockedPollen.json index f80fafe..c7ff134 100644 --- a/abis/LockedPollen.json +++ b/abis/LockedPollen.json @@ -271,25 +271,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "claims", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, { "inputs": [], "name": "decimals", @@ -340,6 +321,25 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "getAvailableRewards", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { diff --git a/abis/Minter.json b/abis/Minter.json index 26dcf58..f02bbd9 100644 --- a/abis/Minter.json +++ b/abis/Minter.json @@ -122,6 +122,43 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [], + "name": "getBoostingScale", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "uint256", + "name": "currentValue", + "type": "uint256" + } + ], + "name": "getRewardRate", + "outputs": [ + { + "internalType": "uint256", + "name": "rate", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, { "inputs": [ { @@ -224,6 +261,19 @@ "stateMutability": "view", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_newBoostingScale", + "type": "uint256" + } + ], + "name": "setBoostingScale", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { diff --git a/abis/Portfolio.json b/abis/Portfolio.json index 09f9bfe..c900a71 100644 --- a/abis/Portfolio.json +++ b/abis/Portfolio.json @@ -206,6 +206,32 @@ "name": "PortfolioReopened", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "rebalanceFee", + "type": "uint256" + } + ], + "name": "RebalanceFeeSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "rebalanceFeeVault", + "type": "address" + } + ], + "name": "RebalanceFeeVaultSet", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -270,6 +296,11 @@ "name": "weights", "type": "uint256[]" }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, { "internalType": "bool", "name": "tokenType", @@ -374,6 +405,16 @@ "internalType": "uint256", "name": "benchMarkRef", "type": "uint256" + }, + { + "internalType": "uint256", + "name": "shortsValue", + "type": "uint256" + }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" } ], "stateMutability": "view", @@ -390,6 +431,16 @@ "internalType": "uint256[]", "name": "prices", "type": "uint256[]" + }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "shortsValue", + "type": "uint256" } ], "name": "getPortfolioValue", @@ -509,6 +560,11 @@ "name": "weights", "type": "uint256[]" }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, { "internalType": "uint256", "name": "amount", @@ -569,6 +625,32 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "rebalanceFee", + "type": "uint256" + } + ], + "name": "setRebalanceFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "rebalanceFeeVault", + "type": "address" + } + ], + "name": "setRebalanceFeeVault", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { From 6b7b5fff9988899498095f8b75a3b270bdb233b6 Mon Sep 17 00:00:00 2001 From: tki Date: Mon, 25 Jul 2022 17:44:05 +0200 Subject: [PATCH 02/20] Update contracts --- config/fuji.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/fuji.json b/config/fuji.json index 0a447a8..c942f3a 100644 --- a/config/fuji.json +++ b/config/fuji.json @@ -1,6 +1,6 @@ { "network": "fuji", - "pollenDAO": "0x6055ebcC2Dd95a29A4DEd739Eb8EE48696aFCdC3", - "leagues": "0xBaACD1e56737d26B13721Af6C20FfE00b66860DC", + "pollenDAO": "0xcED52786fEa563946b7b8D95f3BEBB8F8cD4eB2A", + "leagues": "0x064f38cFC9F4831238161DbEcbDFFC18B2d1DEB6", "startBlock": "11300000" } From f72c556a7266e37bd320e0416aaebda21db0339f Mon Sep 17 00:00:00 2001 From: tki Date: Tue, 26 Jul 2022 21:07:59 +0200 Subject: [PATCH 03/20] Update contracts --- config/fuji.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/fuji.json b/config/fuji.json index c942f3a..02a2db5 100644 --- a/config/fuji.json +++ b/config/fuji.json @@ -1,6 +1,6 @@ { "network": "fuji", - "pollenDAO": "0xcED52786fEa563946b7b8D95f3BEBB8F8cD4eB2A", - "leagues": "0x064f38cFC9F4831238161DbEcbDFFC18B2d1DEB6", + "pollenDAO": "0xEd493673Cc1EdB1234CE92967F28537F46F25337", + "leagues": "0x16692b0614588A930E1260c22f77D06985195eF0", "startBlock": "11300000" } From ee22123e802fe743b9ad301b73edefb551661ebc Mon Sep 17 00:00:00 2001 From: tki Date: Tue, 26 Jul 2022 21:13:07 +0200 Subject: [PATCH 04/20] Fix event typo --- src/mappings/leagues.ts | 5 ++--- subgraph.template.yaml | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/mappings/leagues.ts b/src/mappings/leagues.ts index 21aa980..27b600b 100644 --- a/src/mappings/leagues.ts +++ b/src/mappings/leagues.ts @@ -1,13 +1,12 @@ import { log, store, Address, BigInt, BigDecimal } from '@graphprotocol/graph-ts' -// TODO: fix "Trasnfer" typo in .sol import { NewLeague, Invited, JoinedLeague, LeftLeague, MemberRemoved, - TrasnferAdminRole, + TransferAdminRole, } from '../../generated/Leagues/Leagues' import { League, Member, Invitation } from '../../generated/schema' @@ -73,7 +72,7 @@ export function handleLeftLeague(event: LeftLeague): void { removeMembership(event.params.user, event.params.leagueId) } -export function handleTransferAdminRole(event: TrasnferAdminRole): void { +export function handleTransferAdminRole(event: TransferAdminRole): void { let newAdmin = event.params.newAdmin.toHexString() let leagueId = event.params.leagueId.toHexString() let league = League.load(leagueId) diff --git a/subgraph.template.yaml b/subgraph.template.yaml index a32c28f..99ba84d 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -94,7 +94,7 @@ dataSources: handler: handleJoinedLeague - event: LeftLeague(indexed address,uint256) handler: handleLeftLeague - - event: TrasnferAdminRole(indexed address,indexed address,uint256) + - event: TransferAdminRole(indexed address,indexed address,uint256) handler: handleTransferAdminRole - event: MemberRemoved(indexed address,indexed uint256) handler: handleMemberRemoved From 490ad2ea08aebd0ae99ec0fa390d2ed27d12bca4 Mon Sep 17 00:00:00 2001 From: tki Date: Wed, 27 Jul 2022 12:27:04 +0200 Subject: [PATCH 05/20] Calc portfolio value with shorts; fix typecasting --- schema.graphql | 1 + src/mappings/portfolio.ts | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/schema.graphql b/schema.graphql index cbd43fd..a11e696 100644 --- a/schema.graphql +++ b/schema.graphql @@ -30,6 +30,7 @@ type PortfolioAllocation @entity { asset: Asset! amount: BigInt! weight: BigInt! + isShort: Boolean! initialUsdPrice: BigInt! } diff --git a/src/mappings/portfolio.ts b/src/mappings/portfolio.ts index fbea678..69931d3 100644 --- a/src/mappings/portfolio.ts +++ b/src/mappings/portfolio.ts @@ -338,6 +338,7 @@ function mapAllocations( entryId: string, assets: Address[], weights: BigInt[], + shorts: bool[], amounts: BigInt[], quoterContract: Quoter ): string[] { @@ -350,10 +351,13 @@ function mapAllocations( let allocation = new PortfolioAllocation(asset.id + '-' + entryId) let price = quoterContract.quotePrice(0, Address.fromString(asset.id)) + // dance around bool -> Bool typecasting... + let shortInt = shorts[i] ? BigInt.fromI32(1) : BigInt.fromI32(0) allocation.initialUsdPrice = price.value0 allocation.asset = asset.id allocation.weight = weights[i] + allocation.isShort = shortInt.equals(BigInt.fromI32(1)) allocation.amount = amounts[i] allocation.save() @@ -413,8 +417,8 @@ function createPortfolioEntry( return null } else { let entry = new PortfolioEntry(creator.toHexString() + '-' + timestamp.toHexString()) - let benchmarkValue = contract.try_getBenchMarkValue() + if (benchmarkValue.reverted) { log.error('Failed to get benchmark value', []) entry.benchmarkValue = BigInt.zero() @@ -427,8 +431,16 @@ function createPortfolioEntry( entry.vePlnStake = vePlnStake let assetAmounts = storedPortfolio.value.value0 + let shorts = storedPortfolio.value.value7 + let shortsValue = storedPortfolio.value.value6 + let assets = contract.getAssets() - entry.initialValue = getPortfolioValue(contractAddress, assetAmounts) + entry.initialValue = getPortfolioValue( + contractAddress, + assetAmounts, + shorts, + shortsValue + ) let quoterContract = Quoter.bind(contractAddress) @@ -436,6 +448,7 @@ function createPortfolioEntry( entry.id, assets, weights, + shorts, assetAmounts, quoterContract ) @@ -522,13 +535,20 @@ function createPortfolio( function getPortfolioValue( portfolioContractAddr: Address, - assetAmounts: BigInt[] + assetAmounts: BigInt[], + shorts: boolean[], + shortsValue: BigInt ): BigInt { let contract = PortfolioContract.bind(portfolioContractAddr) let assets = contract.getAssets() let prices = contract.getPrices(assetAmounts, assets) - let portfolioValue = contract.try_getPortfolioValue(assetAmounts, prices) + let portfolioValue = contract.try_getPortfolioValue( + assetAmounts, + prices, + shorts, + shortsValue + ) if (portfolioValue.reverted) { log.error('Failed to calculate portfolio value', []) return BigInt.zero() From b2ca2cb9ca437a9db6dd1346b4008fed7f2c4401 Mon Sep 17 00:00:00 2001 From: tki Date: Wed, 27 Jul 2022 20:11:07 +0200 Subject: [PATCH 06/20] Update fuji contracts --- config/fuji.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/fuji.json b/config/fuji.json index 02a2db5..efcb939 100644 --- a/config/fuji.json +++ b/config/fuji.json @@ -1,6 +1,6 @@ { "network": "fuji", - "pollenDAO": "0xEd493673Cc1EdB1234CE92967F28537F46F25337", - "leagues": "0x16692b0614588A930E1260c22f77D06985195eF0", + "pollenDAO": "0x65D26B5faCf4Bcf4d8C933355E23628aD26bE450", + "leagues": "0x199C53012E5222D9a3FE7aF2b43b50A304b89643", "startBlock": "11300000" } From 349b2dae1b11935b5cb97c1eb1630f777e9a8275 Mon Sep 17 00:00:00 2001 From: tki Date: Fri, 5 Aug 2022 15:02:16 +0200 Subject: [PATCH 07/20] Use beta contracts --- config/fuji.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/fuji.json b/config/fuji.json index efcb939..0a447a8 100644 --- a/config/fuji.json +++ b/config/fuji.json @@ -1,6 +1,6 @@ { "network": "fuji", - "pollenDAO": "0x65D26B5faCf4Bcf4d8C933355E23628aD26bE450", - "leagues": "0x199C53012E5222D9a3FE7aF2b43b50A304b89643", + "pollenDAO": "0x6055ebcC2Dd95a29A4DEd739Eb8EE48696aFCdC3", + "leagues": "0xBaACD1e56737d26B13721Af6C20FfE00b66860DC", "startBlock": "11300000" } From a43655daf89269569f52d84b4f3ca61e61f7b38f Mon Sep 17 00:00:00 2001 From: tki Date: Sun, 7 Aug 2022 11:33:15 +0200 Subject: [PATCH 08/20] Update contracts --- config/fuji.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/fuji.json b/config/fuji.json index 0a447a8..ad14452 100644 --- a/config/fuji.json +++ b/config/fuji.json @@ -1,6 +1,6 @@ { "network": "fuji", - "pollenDAO": "0x6055ebcC2Dd95a29A4DEd739Eb8EE48696aFCdC3", - "leagues": "0xBaACD1e56737d26B13721Af6C20FfE00b66860DC", + "pollenDAO": "0x4AFaF24DB2E83deacC607AF3025032bDa8427C83", + "leagues": "0xae1C484374ECC55cf4cA6dE2e8b31ab635D44FE5", "startBlock": "11300000" } From 69bf57416667c4176f85de83b4c4615ce6cefae3 Mon Sep 17 00:00:00 2001 From: tki Date: Sun, 7 Aug 2022 13:28:38 +0200 Subject: [PATCH 09/20] Add proposal voting support --- schema.graphql | 17 ++++++++ src/mappings/governance.ts | 82 ++++++++++++++++++++++++++++++++++++++ src/utils/constants.ts | 1 + subgraph.template.yaml | 31 ++++++++++++++ 4 files changed, 131 insertions(+) create mode 100644 src/mappings/governance.ts diff --git a/schema.graphql b/schema.graphql index a11e696..8608b29 100644 --- a/schema.graphql +++ b/schema.graphql @@ -219,3 +219,20 @@ type Invitation @entity { user: String! league: League! } + +"---Governance entities---" +type Proposal @entity { + id: ID! + submitter: String! + executer: String! + timestamp: BigInt! + yes: BigInt! + no: BigInt! +} + +type VotingTerms @entity { + id: ID! + period: BigInt! + quorum: BigInt! + timelock: BigInt! +} diff --git a/src/mappings/governance.ts b/src/mappings/governance.ts new file mode 100644 index 0000000..c26bee5 --- /dev/null +++ b/src/mappings/governance.ts @@ -0,0 +1,82 @@ +import { log, store, Address, BigInt, BigDecimal, Value } from '@graphprotocol/graph-ts' +import { VOTING_TERMS_ID } from '../utils/constants' + +import { + NewProposal, + QuorumChanged, + TimeLockChanged, + VotingPeriodChanged, + Voted, +} from '../../generated/Governance/Governance' + +import { Proposal, VotingTerms } from '../../generated/schema' + +export function handleNewProposal(event: NewProposal) { + let id = event.params.id.toHexString() + let submitter = event.params.submitter.toHexString() + let executer = event.params.executer.toHexString() + let timestamp = event.block.timestamp + + let proposal = new Proposal(id) + proposal.submitter = submitter + proposal.executer = executer + proposal.timestamp = timestamp + proposal.yes = BigInt.zero() + proposal.no = BigInt.zero() + + proposal.save() + + log.info('New proposal {} {} {}', [id, submitter, executer]) +} + +export function handleVoted(event: Voted) { + let voter = event.params.voter.toHexString() + let proposalId = event.params.proposalId.toHexString() + let voteType = event.params.vote ? 'yes' : 'no' + let amount = event.params.amount + + let proposal = Proposal.load(proposalId) + + if (proposal) { + if (voteType === 'yes') proposal.yes = proposal.yes.plus(amount) + if (voteType === 'no') proposal.no = proposal.no.plus(amount) + + proposal.save() + } else { + log.error('No proposal found {}, voter: {}', [proposalId, voter]) + } +} + +export function handleVotingPeriodChanged(event: VotingPeriodChanged) { + let newVotingPeriod = event.params.newVotingPeriod + updateTerms('period', newVotingPeriod) +} + +export function handleQuorumChanged(event: QuorumChanged) { + let newQuorum = event.params.newQuorum + updateTerms('quorum', newQuorum) +} + +export function handleTimeLockChanged(event: TimeLockChanged) { + let newTimeLock = event.params.newTimeLock + updateTerms('quorum', newTimeLock) +} + +function updateTerms(term: string, value: BigInt): void { + let terms = VotingTerms.load(VOTING_TERMS_ID) + + if (terms) { + terms.set(term, Value.fromBigInt(value)) + } else { + terms = new VotingTerms(VOTING_TERMS_ID) + + terms.quorum = BigInt.zero() + terms.timelock = BigInt.zero() + terms.period = BigInt.zero() + + terms.set(term, Value.fromBigInt(value)) + } + terms.save() + + log.info('Voting term changed {}: {}', [term, value.toString()]) +} diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 2d167be..6a41be5 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -13,3 +13,4 @@ export let ONE_BD = BigDecimal.fromString('1') export let BI_18 = BigInt.fromI32(18) export let USER_OVERVIEW_STATS_ID = '1' +export let VOTING_TERMS_ID = '1' diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 99ba84d..c225eed 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -98,3 +98,34 @@ dataSources: handler: handleTransferAdminRole - event: MemberRemoved(indexed address,indexed uint256) handler: handleMemberRemoved + + - kind: ethereum/contract + name: Governance + network: {{ network }} + source: + address: '{{ pollenDAO }}' + abi: Governance + startBlock: {{ startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + file: ./src/mappings/governance.ts + entities: + - Proposal + abis: + - name: Governance + file: ./abis/Governance.json + eventHandlers: + - event: NewProposal(indexed address,address,uint256) + handler: handleNewProposal + - event: Voted(indexed address,address,uint256) + handler: handleVoted + - event: ClaimedTokens(indexed address,uint256,uint256) + handler: handleClaimedTokens + - event: QuorumChanged(uint256) + handler: handleQuorumChanged + - event: TimeLockChanged(uint256) + handler: handleTimeLockChanged + - event: VotingPeriodChanged(uint256) + handler: handleVotingPeriodChanged From 8b1af548d66349fa55076ecf1245c51f728bbe70 Mon Sep 17 00:00:00 2001 From: tki Date: Sun, 7 Aug 2022 13:40:21 +0200 Subject: [PATCH 10/20] Make it build --- src/mappings/governance.ts | 12 ++++++------ subgraph.template.yaml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/mappings/governance.ts b/src/mappings/governance.ts index c26bee5..6c919e5 100644 --- a/src/mappings/governance.ts +++ b/src/mappings/governance.ts @@ -1,4 +1,4 @@ -import { log, store, Address, BigInt, BigDecimal, Value } from '@graphprotocol/graph-ts' +import { log, BigInt, Value } from '@graphprotocol/graph-ts' import { VOTING_TERMS_ID } from '../utils/constants' import { @@ -11,7 +11,7 @@ import { import { Proposal, VotingTerms } from '../../generated/schema' -export function handleNewProposal(event: NewProposal) { +export function handleNewProposal(event: NewProposal): void { let id = event.params.id.toHexString() let submitter = event.params.submitter.toHexString() let executer = event.params.executer.toHexString() @@ -29,7 +29,7 @@ export function handleNewProposal(event: NewProposal) { log.info('New proposal {} {} {}', [id, submitter, executer]) } -export function handleVoted(event: Voted) { +export function handleVoted(event: Voted): void { let voter = event.params.voter.toHexString() let proposalId = event.params.proposalId.toHexString() let voteType = event.params.vote ? 'yes' : 'no' @@ -47,17 +47,17 @@ export function handleVoted(event: Voted) { } } -export function handleVotingPeriodChanged(event: VotingPeriodChanged) { +export function handleVotingPeriodChanged(event: VotingPeriodChanged): void { let newVotingPeriod = event.params.newVotingPeriod updateTerms('period', newVotingPeriod) } -export function handleQuorumChanged(event: QuorumChanged) { +export function handleQuorumChanged(event: QuorumChanged): void { let newQuorum = event.params.newQuorum updateTerms('quorum', newQuorum) } -export function handleTimeLockChanged(event: TimeLockChanged) { +export function handleTimeLockChanged(event: TimeLockChanged): void { let newTimeLock = event.params.newTimeLock updateTerms('quorum', newTimeLock) } diff --git a/subgraph.template.yaml b/subgraph.template.yaml index c225eed..d74830a 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -119,7 +119,7 @@ dataSources: eventHandlers: - event: NewProposal(indexed address,address,uint256) handler: handleNewProposal - - event: Voted(indexed address,address,uint256) + - event: Voted(indexed address,uint256,bool,uint256) handler: handleVoted - event: ClaimedTokens(indexed address,uint256,uint256) handler: handleClaimedTokens From 470538683aa88efc733171b954e89664e477649f Mon Sep 17 00:00:00 2001 From: tki Date: Wed, 31 Aug 2022 20:47:42 +0200 Subject: [PATCH 11/20] Fix voting terms; update contracts --- config/fuji.json | 4 ++-- schema.graphql | 2 +- src/mappings/governance.ts | 16 +++++++--------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/config/fuji.json b/config/fuji.json index ad14452..79f494a 100644 --- a/config/fuji.json +++ b/config/fuji.json @@ -1,6 +1,6 @@ { "network": "fuji", - "pollenDAO": "0x4AFaF24DB2E83deacC607AF3025032bDa8427C83", - "leagues": "0xae1C484374ECC55cf4cA6dE2e8b31ab635D44FE5", + "pollenDAO": "0x74Be1B7fdF080e913f1B358aB30cF1758c185cc0", + "leagues": "0x7AeD63c02ADF0cFe02988Bc217907Af8EBF51101", "startBlock": "11300000" } diff --git a/schema.graphql b/schema.graphql index 8608b29..f866b74 100644 --- a/schema.graphql +++ b/schema.graphql @@ -230,7 +230,7 @@ type Proposal @entity { no: BigInt! } -type VotingTerms @entity { +type VotingTerm @entity { id: ID! period: BigInt! quorum: BigInt! diff --git a/src/mappings/governance.ts b/src/mappings/governance.ts index 6c919e5..4a840d0 100644 --- a/src/mappings/governance.ts +++ b/src/mappings/governance.ts @@ -9,7 +9,7 @@ import { Voted, } from '../../generated/Governance/Governance' -import { Proposal, VotingTerms } from '../../generated/schema' +import { Proposal, VotingTerm } from '../../generated/schema' export function handleNewProposal(event: NewProposal): void { let id = event.params.id.toHexString() @@ -59,23 +59,21 @@ export function handleQuorumChanged(event: QuorumChanged): void { export function handleTimeLockChanged(event: TimeLockChanged): void { let newTimeLock = event.params.newTimeLock - updateTerms('quorum', newTimeLock) + updateTerms('timelock', newTimeLock) } function updateTerms(term: string, value: BigInt): void { - let terms = VotingTerms.load(VOTING_TERMS_ID) + let terms = VotingTerm.load(VOTING_TERMS_ID) - if (terms) { - terms.set(term, Value.fromBigInt(value)) - } else { - terms = new VotingTerms(VOTING_TERMS_ID) + if (terms == null) { + terms = new VotingTerm(VOTING_TERMS_ID) terms.quorum = BigInt.zero() terms.timelock = BigInt.zero() terms.period = BigInt.zero() - - terms.set(term, Value.fromBigInt(value)) } + + terms.set(term, Value.fromBigInt(value)) terms.save() log.info('Voting term changed {}: {}', [term, value.toString()]) From 94d4ade6c210d499056de2a780f057a3a54cbfe3 Mon Sep 17 00:00:00 2001 From: tki Date: Sun, 4 Sep 2022 11:22:38 +0200 Subject: [PATCH 12/20] Use old contracts ABIs --- abis/IPollenDAO.json | 84 +------------------------------------------- abis/Portfolio.json | 82 ------------------------------------------ 2 files changed, 1 insertion(+), 165 deletions(-) diff --git a/abis/IPollenDAO.json b/abis/IPollenDAO.json index 5dfdfb4..04d36f6 100644 --- a/abis/IPollenDAO.json +++ b/abis/IPollenDAO.json @@ -426,32 +426,6 @@ "name": "QuorumChanged", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "rebalanceFee", - "type": "uint256" - } - ], - "name": "RebalanceFeeSet", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "rebalanceFeeVault", - "type": "address" - } - ], - "name": "RebalanceFeeVaultSet", - "type": "event" - }, { "anonymous": false, "inputs": [ @@ -754,11 +728,6 @@ "name": "weights", "type": "uint256[]" }, - { - "internalType": "bool[]", - "name": "isShort", - "type": "bool[]" - }, { "internalType": "bool", "name": "tokenType", @@ -913,16 +882,6 @@ "internalType": "uint256", "name": "benchMarkRef", "type": "uint256" - }, - { - "internalType": "uint256", - "name": "shortsValue", - "type": "uint256" - }, - { - "internalType": "bool[]", - "name": "isShort", - "type": "bool[]" } ], "stateMutability": "view", @@ -939,16 +898,6 @@ "internalType": "uint256[]", "name": "prices", "type": "uint256[]" - }, - { - "internalType": "bool[]", - "name": "isShort", - "type": "bool[]" - }, - { - "internalType": "uint256", - "name": "shortsValue", - "type": "uint256" } ], "name": "getPortfolioValue", @@ -1408,11 +1357,6 @@ "name": "weights", "type": "uint256[]" }, - { - "internalType": "bool[]", - "name": "isShort", - "type": "bool[]" - }, { "internalType": "uint256", "name": "amount", @@ -1426,7 +1370,7 @@ ], "name": "rebalancePortfolio", "outputs": [], - "stateMutability": "payable", + "stateMutability": "nonpayable", "type": "function" }, { @@ -1555,32 +1499,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "rebalanceFee", - "type": "uint256" - } - ], - "name": "setRebalanceFee", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "rebalanceFeeVault", - "type": "address" - } - ], - "name": "setRebalanceFeeVault", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { diff --git a/abis/Portfolio.json b/abis/Portfolio.json index c900a71..09f9bfe 100644 --- a/abis/Portfolio.json +++ b/abis/Portfolio.json @@ -206,32 +206,6 @@ "name": "PortfolioReopened", "type": "event" }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "rebalanceFee", - "type": "uint256" - } - ], - "name": "RebalanceFeeSet", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "rebalanceFeeVault", - "type": "address" - } - ], - "name": "RebalanceFeeVaultSet", - "type": "event" - }, { "anonymous": false, "inputs": [ @@ -296,11 +270,6 @@ "name": "weights", "type": "uint256[]" }, - { - "internalType": "bool[]", - "name": "isShort", - "type": "bool[]" - }, { "internalType": "bool", "name": "tokenType", @@ -405,16 +374,6 @@ "internalType": "uint256", "name": "benchMarkRef", "type": "uint256" - }, - { - "internalType": "uint256", - "name": "shortsValue", - "type": "uint256" - }, - { - "internalType": "bool[]", - "name": "isShort", - "type": "bool[]" } ], "stateMutability": "view", @@ -431,16 +390,6 @@ "internalType": "uint256[]", "name": "prices", "type": "uint256[]" - }, - { - "internalType": "bool[]", - "name": "isShort", - "type": "bool[]" - }, - { - "internalType": "uint256", - "name": "shortsValue", - "type": "uint256" } ], "name": "getPortfolioValue", @@ -560,11 +509,6 @@ "name": "weights", "type": "uint256[]" }, - { - "internalType": "bool[]", - "name": "isShort", - "type": "bool[]" - }, { "internalType": "uint256", "name": "amount", @@ -625,32 +569,6 @@ "stateMutability": "nonpayable", "type": "function" }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "rebalanceFee", - "type": "uint256" - } - ], - "name": "setRebalanceFee", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "rebalanceFeeVault", - "type": "address" - } - ], - "name": "setRebalanceFeeVault", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, { "inputs": [ { From d30d25dba280dfe896123b277d7c00cb75d93f91 Mon Sep 17 00:00:00 2001 From: tki Date: Sun, 4 Sep 2022 11:23:51 +0200 Subject: [PATCH 13/20] Rm Leagues handlers --- subgraph.template.yaml | 31 ------------------------------- 1 file changed, 31 deletions(-) diff --git a/subgraph.template.yaml b/subgraph.template.yaml index d74830a..19d52f3 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -68,37 +68,6 @@ dataSources: - event: WithdrawWithReward(indexed address,indexed address,uint256,uint256,uint256,bool) handler: handleWithdrawWithReward - - kind: ethereum/contract - name: Leagues - network: {{ network }} - source: - address: '{{ leagues }}' - abi: Leagues - startBlock: {{ startBlock }} - mapping: - kind: ethereum/events - apiVersion: 0.0.7 - language: wasm/assemblyscript - file: ./src/mappings/leagues.ts - entities: - - Leagues - abis: - - name: Leagues - file: ./abis/Leagues.json - eventHandlers: - - event: NewLeague(indexed address,uint256,string) - handler: handleNewLeague - - event: Invited(indexed address,indexed uint256) - handler: handleInvited - - event: JoinedLeague(indexed address,indexed uint256) - handler: handleJoinedLeague - - event: LeftLeague(indexed address,uint256) - handler: handleLeftLeague - - event: TransferAdminRole(indexed address,indexed address,uint256) - handler: handleTransferAdminRole - - event: MemberRemoved(indexed address,indexed uint256) - handler: handleMemberRemoved - - kind: ethereum/contract name: Governance network: {{ network }} From efacf2c26b7d084e5cd8ff0c07d85eb8c897123a Mon Sep 17 00:00:00 2001 From: tki Date: Sun, 4 Sep 2022 12:17:15 +0200 Subject: [PATCH 14/20] Rm shorts --- schema.graphql | 1 - src/mappings/portfolio.ts | 28 ++++------------------------ 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/schema.graphql b/schema.graphql index f866b74..214215b 100644 --- a/schema.graphql +++ b/schema.graphql @@ -30,7 +30,6 @@ type PortfolioAllocation @entity { asset: Asset! amount: BigInt! weight: BigInt! - isShort: Boolean! initialUsdPrice: BigInt! } diff --git a/src/mappings/portfolio.ts b/src/mappings/portfolio.ts index 69931d3..fbea678 100644 --- a/src/mappings/portfolio.ts +++ b/src/mappings/portfolio.ts @@ -338,7 +338,6 @@ function mapAllocations( entryId: string, assets: Address[], weights: BigInt[], - shorts: bool[], amounts: BigInt[], quoterContract: Quoter ): string[] { @@ -351,13 +350,10 @@ function mapAllocations( let allocation = new PortfolioAllocation(asset.id + '-' + entryId) let price = quoterContract.quotePrice(0, Address.fromString(asset.id)) - // dance around bool -> Bool typecasting... - let shortInt = shorts[i] ? BigInt.fromI32(1) : BigInt.fromI32(0) allocation.initialUsdPrice = price.value0 allocation.asset = asset.id allocation.weight = weights[i] - allocation.isShort = shortInt.equals(BigInt.fromI32(1)) allocation.amount = amounts[i] allocation.save() @@ -417,8 +413,8 @@ function createPortfolioEntry( return null } else { let entry = new PortfolioEntry(creator.toHexString() + '-' + timestamp.toHexString()) - let benchmarkValue = contract.try_getBenchMarkValue() + let benchmarkValue = contract.try_getBenchMarkValue() if (benchmarkValue.reverted) { log.error('Failed to get benchmark value', []) entry.benchmarkValue = BigInt.zero() @@ -431,16 +427,8 @@ function createPortfolioEntry( entry.vePlnStake = vePlnStake let assetAmounts = storedPortfolio.value.value0 - let shorts = storedPortfolio.value.value7 - let shortsValue = storedPortfolio.value.value6 - let assets = contract.getAssets() - entry.initialValue = getPortfolioValue( - contractAddress, - assetAmounts, - shorts, - shortsValue - ) + entry.initialValue = getPortfolioValue(contractAddress, assetAmounts) let quoterContract = Quoter.bind(contractAddress) @@ -448,7 +436,6 @@ function createPortfolioEntry( entry.id, assets, weights, - shorts, assetAmounts, quoterContract ) @@ -535,20 +522,13 @@ function createPortfolio( function getPortfolioValue( portfolioContractAddr: Address, - assetAmounts: BigInt[], - shorts: boolean[], - shortsValue: BigInt + assetAmounts: BigInt[] ): BigInt { let contract = PortfolioContract.bind(portfolioContractAddr) let assets = contract.getAssets() let prices = contract.getPrices(assetAmounts, assets) - let portfolioValue = contract.try_getPortfolioValue( - assetAmounts, - prices, - shorts, - shortsValue - ) + let portfolioValue = contract.try_getPortfolioValue(assetAmounts, prices) if (portfolioValue.reverted) { log.error('Failed to calculate portfolio value', []) return BigInt.zero() From 0950e47e69c7bb6b7b0a270125f3938322a58e00 Mon Sep 17 00:00:00 2001 From: tki Date: Sun, 4 Sep 2022 12:19:49 +0200 Subject: [PATCH 15/20] Use old contracts addresses --- config/fuji.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/fuji.json b/config/fuji.json index 79f494a..324b81f 100644 --- a/config/fuji.json +++ b/config/fuji.json @@ -1,6 +1,6 @@ { "network": "fuji", - "pollenDAO": "0x74Be1B7fdF080e913f1B358aB30cF1758c185cc0", - "leagues": "0x7AeD63c02ADF0cFe02988Bc217907Af8EBF51101", + "pollenDAO": "0x3CD4Ce9618022a4b9B5EDD5Cfb034D06593a7Ca7", + "leagues": "0x0000000000000000000000000000000000000000", "startBlock": "11300000" } From 1f3f3ed94be6c84de67e211df044b6e5e0b4fcd0 Mon Sep 17 00:00:00 2001 From: tki Date: Sun, 4 Sep 2022 12:24:28 +0200 Subject: [PATCH 16/20] Revert "Use old contracts ABIs" This reverts commit 94d4ade6c210d499056de2a780f057a3a54cbfe3. --- abis/IPollenDAO.json | 84 +++++++++++++++++++++++++++++++++++++++++++- abis/Portfolio.json | 82 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+), 1 deletion(-) diff --git a/abis/IPollenDAO.json b/abis/IPollenDAO.json index 04d36f6..5dfdfb4 100644 --- a/abis/IPollenDAO.json +++ b/abis/IPollenDAO.json @@ -426,6 +426,32 @@ "name": "QuorumChanged", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "rebalanceFee", + "type": "uint256" + } + ], + "name": "RebalanceFeeSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "rebalanceFeeVault", + "type": "address" + } + ], + "name": "RebalanceFeeVaultSet", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -728,6 +754,11 @@ "name": "weights", "type": "uint256[]" }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, { "internalType": "bool", "name": "tokenType", @@ -882,6 +913,16 @@ "internalType": "uint256", "name": "benchMarkRef", "type": "uint256" + }, + { + "internalType": "uint256", + "name": "shortsValue", + "type": "uint256" + }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" } ], "stateMutability": "view", @@ -898,6 +939,16 @@ "internalType": "uint256[]", "name": "prices", "type": "uint256[]" + }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "shortsValue", + "type": "uint256" } ], "name": "getPortfolioValue", @@ -1357,6 +1408,11 @@ "name": "weights", "type": "uint256[]" }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, { "internalType": "uint256", "name": "amount", @@ -1370,7 +1426,7 @@ ], "name": "rebalancePortfolio", "outputs": [], - "stateMutability": "nonpayable", + "stateMutability": "payable", "type": "function" }, { @@ -1499,6 +1555,32 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "rebalanceFee", + "type": "uint256" + } + ], + "name": "setRebalanceFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "rebalanceFeeVault", + "type": "address" + } + ], + "name": "setRebalanceFeeVault", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { diff --git a/abis/Portfolio.json b/abis/Portfolio.json index 09f9bfe..c900a71 100644 --- a/abis/Portfolio.json +++ b/abis/Portfolio.json @@ -206,6 +206,32 @@ "name": "PortfolioReopened", "type": "event" }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint256", + "name": "rebalanceFee", + "type": "uint256" + } + ], + "name": "RebalanceFeeSet", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "rebalanceFeeVault", + "type": "address" + } + ], + "name": "RebalanceFeeVaultSet", + "type": "event" + }, { "anonymous": false, "inputs": [ @@ -270,6 +296,11 @@ "name": "weights", "type": "uint256[]" }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, { "internalType": "bool", "name": "tokenType", @@ -374,6 +405,16 @@ "internalType": "uint256", "name": "benchMarkRef", "type": "uint256" + }, + { + "internalType": "uint256", + "name": "shortsValue", + "type": "uint256" + }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" } ], "stateMutability": "view", @@ -390,6 +431,16 @@ "internalType": "uint256[]", "name": "prices", "type": "uint256[]" + }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, + { + "internalType": "uint256", + "name": "shortsValue", + "type": "uint256" } ], "name": "getPortfolioValue", @@ -509,6 +560,11 @@ "name": "weights", "type": "uint256[]" }, + { + "internalType": "bool[]", + "name": "isShort", + "type": "bool[]" + }, { "internalType": "uint256", "name": "amount", @@ -569,6 +625,32 @@ "stateMutability": "nonpayable", "type": "function" }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "rebalanceFee", + "type": "uint256" + } + ], + "name": "setRebalanceFee", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "rebalanceFeeVault", + "type": "address" + } + ], + "name": "setRebalanceFeeVault", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, { "inputs": [ { From 9e032e3f0926f068461000923855f00412e6d838 Mon Sep 17 00:00:00 2001 From: tki Date: Sun, 4 Sep 2022 12:24:47 +0200 Subject: [PATCH 17/20] Revert "Rm Leagues handlers" This reverts commit d30d25dba280dfe896123b277d7c00cb75d93f91. --- subgraph.template.yaml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/subgraph.template.yaml b/subgraph.template.yaml index 19d52f3..d74830a 100644 --- a/subgraph.template.yaml +++ b/subgraph.template.yaml @@ -68,6 +68,37 @@ dataSources: - event: WithdrawWithReward(indexed address,indexed address,uint256,uint256,uint256,bool) handler: handleWithdrawWithReward + - kind: ethereum/contract + name: Leagues + network: {{ network }} + source: + address: '{{ leagues }}' + abi: Leagues + startBlock: {{ startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + file: ./src/mappings/leagues.ts + entities: + - Leagues + abis: + - name: Leagues + file: ./abis/Leagues.json + eventHandlers: + - event: NewLeague(indexed address,uint256,string) + handler: handleNewLeague + - event: Invited(indexed address,indexed uint256) + handler: handleInvited + - event: JoinedLeague(indexed address,indexed uint256) + handler: handleJoinedLeague + - event: LeftLeague(indexed address,uint256) + handler: handleLeftLeague + - event: TransferAdminRole(indexed address,indexed address,uint256) + handler: handleTransferAdminRole + - event: MemberRemoved(indexed address,indexed uint256) + handler: handleMemberRemoved + - kind: ethereum/contract name: Governance network: {{ network }} From c8b2943d180be330e3ee884292c7565a8f0542dd Mon Sep 17 00:00:00 2001 From: tki Date: Sun, 4 Sep 2022 12:25:45 +0200 Subject: [PATCH 18/20] Revert "Rm shorts" This reverts commit efacf2c26b7d084e5cd8ff0c07d85eb8c897123a. --- schema.graphql | 1 + src/mappings/portfolio.ts | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/schema.graphql b/schema.graphql index 214215b..f866b74 100644 --- a/schema.graphql +++ b/schema.graphql @@ -30,6 +30,7 @@ type PortfolioAllocation @entity { asset: Asset! amount: BigInt! weight: BigInt! + isShort: Boolean! initialUsdPrice: BigInt! } diff --git a/src/mappings/portfolio.ts b/src/mappings/portfolio.ts index fbea678..69931d3 100644 --- a/src/mappings/portfolio.ts +++ b/src/mappings/portfolio.ts @@ -338,6 +338,7 @@ function mapAllocations( entryId: string, assets: Address[], weights: BigInt[], + shorts: bool[], amounts: BigInt[], quoterContract: Quoter ): string[] { @@ -350,10 +351,13 @@ function mapAllocations( let allocation = new PortfolioAllocation(asset.id + '-' + entryId) let price = quoterContract.quotePrice(0, Address.fromString(asset.id)) + // dance around bool -> Bool typecasting... + let shortInt = shorts[i] ? BigInt.fromI32(1) : BigInt.fromI32(0) allocation.initialUsdPrice = price.value0 allocation.asset = asset.id allocation.weight = weights[i] + allocation.isShort = shortInt.equals(BigInt.fromI32(1)) allocation.amount = amounts[i] allocation.save() @@ -413,8 +417,8 @@ function createPortfolioEntry( return null } else { let entry = new PortfolioEntry(creator.toHexString() + '-' + timestamp.toHexString()) - let benchmarkValue = contract.try_getBenchMarkValue() + if (benchmarkValue.reverted) { log.error('Failed to get benchmark value', []) entry.benchmarkValue = BigInt.zero() @@ -427,8 +431,16 @@ function createPortfolioEntry( entry.vePlnStake = vePlnStake let assetAmounts = storedPortfolio.value.value0 + let shorts = storedPortfolio.value.value7 + let shortsValue = storedPortfolio.value.value6 + let assets = contract.getAssets() - entry.initialValue = getPortfolioValue(contractAddress, assetAmounts) + entry.initialValue = getPortfolioValue( + contractAddress, + assetAmounts, + shorts, + shortsValue + ) let quoterContract = Quoter.bind(contractAddress) @@ -436,6 +448,7 @@ function createPortfolioEntry( entry.id, assets, weights, + shorts, assetAmounts, quoterContract ) @@ -522,13 +535,20 @@ function createPortfolio( function getPortfolioValue( portfolioContractAddr: Address, - assetAmounts: BigInt[] + assetAmounts: BigInt[], + shorts: boolean[], + shortsValue: BigInt ): BigInt { let contract = PortfolioContract.bind(portfolioContractAddr) let assets = contract.getAssets() let prices = contract.getPrices(assetAmounts, assets) - let portfolioValue = contract.try_getPortfolioValue(assetAmounts, prices) + let portfolioValue = contract.try_getPortfolioValue( + assetAmounts, + prices, + shorts, + shortsValue + ) if (portfolioValue.reverted) { log.error('Failed to calculate portfolio value', []) return BigInt.zero() From af3eff37695c8d4f4754fdca626b5a1d7105df16 Mon Sep 17 00:00:00 2001 From: tki Date: Mon, 5 Sep 2022 12:01:25 +0200 Subject: [PATCH 19/20] Revert "Use old contracts addresses" This reverts commit 0950e47e69c7bb6b7b0a270125f3938322a58e00. --- config/fuji.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/fuji.json b/config/fuji.json index 324b81f..79f494a 100644 --- a/config/fuji.json +++ b/config/fuji.json @@ -1,6 +1,6 @@ { "network": "fuji", - "pollenDAO": "0x3CD4Ce9618022a4b9B5EDD5Cfb034D06593a7Ca7", - "leagues": "0x0000000000000000000000000000000000000000", + "pollenDAO": "0x74Be1B7fdF080e913f1B358aB30cF1758c185cc0", + "leagues": "0x7AeD63c02ADF0cFe02988Bc217907Af8EBF51101", "startBlock": "11300000" } From bf8952ce315df0c995d776ec5f9991abbc1641d9 Mon Sep 17 00:00:00 2001 From: tki Date: Tue, 18 Oct 2022 12:33:07 +0200 Subject: [PATCH 20/20] Update graph commands --- package.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 6919644..eacc452 100644 --- a/package.json +++ b/package.json @@ -10,13 +10,13 @@ "prepare:avalanche": "mustache config/avalanche.json subgraph.template.yaml > subgraph.yaml", "prepare:local": "mustache config/localhost.json subgraph.template.yaml > subgraph.yaml", "prepare:fuji": "mustache config/fuji.json subgraph.template.yaml > subgraph.yaml", - "deploy:rinkeby": "graph deploy --node https://api.thegraph.com/deploy/ PollenDeFi/pollen-v3-rinkeby", - "deploy:avalanche": "graph deploy --node https://api.thegraph.com/deploy/ PollenDeFi/pollen-v3", - "deploy:fuji": "graph deploy --node https://api.thegraph.com/deploy/ PollenDeFi/pollen-v3-fuji", - "deploy:staging:fuji": "graph deploy --node https://api.thegraph.com/deploy/ PollenDeFi/pollen-v3-fuji-staging", - "create-local": "graph create --node http://localhost:8020/ PollenDeFi/pollen-subgraph-v3", - "remove-local": "graph remove --node http://localhost:8020/ PollenDeFi/pollen-subgraph-v3", - "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 PollenDeFi/pollen-subgraph-v3" + "deploy:rinkeby": "graph deploy --node https://api.thegraph.com/deploy/ pollendefi/pollen-v3-rinkeby", + "deploy:avalanche": "graph deploy --node https://api.thegraph.com/deploy/ pollendefi/pollen-v3", + "deploy:fuji": "graph deploy --node https://api.thegraph.com/deploy/ pollendefi/pollen-v3-fuji", + "deploy:staging:fuji": "graph deploy --node https://api.thegraph.com/deploy/ pollendefi/pollen-v3-fuji-staging", + "create-local": "graph create --node http://localhost:8020/ pollendefi/pollen-subgraph-v3", + "remove-local": "graph remove --node http://localhost:8020/ pollendefi/pollen-subgraph-v3", + "deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 pollendefi/pollen-subgraph-v3" }, "dependencies": { "@graphprotocol/graph-cli": "^0.26.1",