Skip to content
This repository was archived by the owner on Dec 10, 2025. It is now read-only.

updated aaveTokenV2 with transfer cost reduction#4

Open
dhadrien wants to merge 27 commits into
masterfrom
tmp/delegation-gas
Open

updated aaveTokenV2 with transfer cost reduction#4
dhadrien wants to merge 27 commits into
masterfrom
tmp/delegation-gas

Conversation

@dhadrien
Copy link
Copy Markdown

@dhadrien dhadrien commented Feb 26, 2021

Improvement goal:

Currently every token transfer triggers 4 snapshots which can be costly in gas

  • Proposition and Voting powers of sender
  • Proposition and Voting powers of receiver

We propose to decrease gas cost for most transfers.

Intended new behaviour

We propose to disable by default power snapshots for:

  • User that did not delegate their power
  • Did not receive delegation power (they can be delegatee of someone that has no power)
    => The overall condition is that their current balance Of Token == their power.
    Note: They will not be able to participate in governance.

Users that want to participate in governance can opt in to keep the same behaviour as before the change.

Technical description

An account can delegate to:

  • 0x00 = "don't snapshot if possible, snapshots still on" (DEFAULT)
  • Itself "Always snapshot me"
  • Delegate to someone
  • 0xFF = "snapshot off" (Set by the contract itself, correspond to 0x00 + right condition: power = balance)

Every token transfers or delegation event can toggle snapshot for a user:

Example:

  • User 1 delegates prop and voting to 0x00, balance of Aave = 10 AAVE
  • User 2 (balance = 2) delegates prop power to User 1
  • User 1 Proposition power = 12 AAVE
  • User 1 Voting Power = 10 AAVE (no delegation received)

Event 1: User 1 received 3 AAVE from User 3

  • User 1 Balance After = 13 AAVE
  • User 1 Prop power after = 15 != balance, delegatee remains 0x00, snapshot on, Actual Power remains 15
  • User 1 Voting power after = 13 = balance, delegatee becomes 0xFF, snapshot Off and Actual Voting Power = 0;

Event 2: User 2 delegates to User 4

  • User 1 balance after = 13 AAVE
  • User 1 Prop power after = 13 = balance => delegatee of User 1 0xFF, snapshot Off, Actual Prop Power = 0
  • (User 1 Actual Voting Power still = 0)

Event 3: User 4 delegates voting power to User1. Balance of User 4 = 0 AAVE

  • User 1 prop and voting delegateee still 0xFF, nothing happens, both actual powers = 0

Event 4: User 4 receives 7 AAVE Tokens

  • User 1 balance after still = 13 AAVE
  • User 1 Voting power after = 20 AAVE => delegatee becomes 0x00, snapshot On, Actual Voting Power = 20
  • User 1 Prop power after = 13 = balance, nothing changes. Delegatee still 0xFF, snapshot Off, Actual Prop Power = 0

Event 5 : User 1 delegates to itself for both power

=> Snapshot On for both powers

Note: to avoid some edge cases where users would be snapshot off while still receiving power the system follow this property:

  • User 1, that is snapshot off will be turned on whenever they lose delegated power, even if they lose 0 power.
    e.g
    • If User 1 that has no balance and delegate to someone, they will be turned on, though user 1 bal = user 1 power
    • if User 2 was delegating to User 1 with no balance and now User 2 delegates to User 3, User 1 will be turned on (they lost 0 power, user 1 power = user 1 bal)

@dhadrien dhadrien force-pushed the tmp/delegation-gas branch 2 times, most recently from 388be9e to 9e7b33e Compare March 1, 2021 15:21
@dhadrien dhadrien force-pushed the tmp/delegation-gas branch from 9e7b33e to 9392f15 Compare March 1, 2021 15:27
@dhadrien
Copy link
Copy Markdown
Author

dhadrien commented Mar 2, 2021

------------- V2 --------------------------------------------------
  ** Transfers Between Holders:
    - Total Gas : 22099357
    - Tx Number: 138
    - Average: 160140.26811594202
  ** Transfers Holders <> New Holders:
    - Total Gas : 25194046
    - Tx Number: 138
    - Average: 182565.5507246377
------------- V2.5 SNAPSHOTS OFF ----------------------------------
  ** Transfers Between Holders:
    - Total Gas : 7840304
    - Tx Number: 138
    - Average: 56813.79710144927
  ** Transfers Holders <> New Holders:
    - Total Gas : 7818744
    - Tx Number: 138
    - Average: 56657.565217391304
------------- V2.5 SNAPSHOTS ON (BY OPTIN DELEGATION) -------------
  ** Transfers Between Holders:
    - Total Gas : 15685682
    - Tx Number: 138
    - Average: 113664.36231884058
  ** Transfers Holders <> New Holders:
    - Total Gas : 14830652
    - Tx Number: 138
    - Average: 107468.49275362318

Comment thread test/delegation.spec.ts Outdated
expect(await aaveInstance.isSnapshotted(users[2].address, '0')).to.be.equal(true);
});

it('User 1 tries to delegate proposition power to user 3', async () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove "tries to", since it actually does it (same in next case)
same for these cases in delegationWithSnapshot

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants