aragon / osx

Aragon OSx Protocol
GNU Affero General Public License v3.0
85 stars 43 forks source link

Fix/negative subgraph balances main #548

Closed jordaniza closed 8 months ago

jordaniza commented 8 months ago

Description

Task ID: OS-1075

Preview Subgraph can be found here

Type of change

Addresses a bug causing token voting plugins created with pre-existing governance tokens to record inaccurate initial state. Full details of the issue are here, but the code changes in this PR:

  1. Add functionality in getOrCreateMember to conditionally instantiate new TokenVotingMembers with the existing Voting Power, Delegation and ERC20 Balance of the governance token. The conditional incurs the performance hits from eth_call during instantiation, but after the entity is created, we use simple diffs to keep the subgraph performant.
  2. If the user is instantiated for the first time, do not add/subtract the balance as this causes a double counting issue.
  3. If the user belongs to an existing entity, ensure that the usual behaviour occurs (current balance +/- transfer value)
  4. Address a related issue in several places, where the composite key memberId (${pluginAddress}_${userAddress}) would often have the userAddress and pluginAddress swapped. This is not an exhaustive fix and we should check this across the codebase.
  5. Add matchstick tests as needed.
  6. Grab the contract address from the event and use it to fetch the initial balance and delegation status.

I also added a declaration file to provide some missing typings for assemblyScript.

Checklist: