Skip to content
This repository was archived by the owner on Aug 22, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/strategies/erc20-quadratic-voting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# ERC20 Quadratic Voting Strategy

This strategy implements quadratic voting for ERC20 token holders. It applies the square root function to token balances, reducing the voting power of large holders while maintaining proportional representation for smaller holders.

## How it Works

The strategy calculates voting power using the formula:
```
votingPower = √(tokenBalance)
```

This means:
- A holder with 100 tokens gets √100 = 10 voting power
- A holder with 400 tokens gets √400 = 20 voting power
- A holder with 900 tokens gets √900 = 30 voting power

## Parameters

- `address`: The ERC20 token contract address
- `symbol`: Token symbol (for display purposes)
- `decimals`: Number of token decimals

## Example Configuration

```json
{
"strategies": [
[
"erc20-quadratic-voting",
{
"address": "0x6b175474e89094c44da98b954eedeac495271d0f",
"symbol": "DAI",
"decimals": 18
}
]
]
}
```

## Benefits

1. **Decentralization**: Prevents large token holders from dominating governance
2. **Fairness**: Gives smaller holders meaningful voting power
3. **Simplicity**: Easy to understand and implement
4. **Compatibility**: Works with any ERC20 token

## Limitations

1. **Sybil Vulnerability**: Can be gamed by splitting tokens across multiple addresses
2. **Reduced Incentives**: May reduce incentives for large stakeholders
3. **Complexity**: More complex than simple token-weighted voting

## Comparison with Linear Voting

| Token Balance | Linear Voting Power | Quadratic Voting Power |
|---------------|-------------------|----------------------|
| 100 tokens | 100 | 10 |
| 400 tokens | 400 | 20 |
| 900 tokens | 900 | 30 |
| 1600 tokens | 1600 | 40 |

This shows how quadratic voting reduces the power gap between large and small holders.
25 changes: 25 additions & 0 deletions src/strategies/erc20-quadratic-voting/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[
{
"name": "erc20-quadratic-voting",
"strategy": {
"name": "erc20-quadratic-voting",
"params": {
"address": "0x6b175474e89094c44da98b954eedeac495271d0f",
"symbol": "DAI",
"decimals": 18
}
},
"network": "1",
"addresses": [
"0x0000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000002"
],
"snapshot": 12345678,
"scores": {
"0x0000000000000000000000000000000000000000": 0,
"0x0000000000000000000000000000000000000001": 0,
"0x0000000000000000000000000000000000000002": 0
}
}
]
58 changes: 58 additions & 0 deletions src/strategies/erc20-quadratic-voting/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { formatUnits } from '@ethersproject/units';
import { BigNumber } from '@ethersproject/bignumber';
import { Multicaller } from '../../utils';

const ONE = BigNumber.from(1);
const TWO = BigNumber.from(2);

// Square root implementation for BigNumber
function sqrt(value: BigNumber): BigNumber {
let z = value.add(ONE).div(TWO);
let y = value;
while (z.sub(y).isNegative()) {
y = z;
z = value.div(z).add(z).div(TWO);
}
return y;
}

export const author = 'snapshot-labs';
export const version = '1.0.0';

const abi = [
'function balanceOf(address account) external view returns (uint256)'
];

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot
): Promise<Record<string, number>> {
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest';

// Validate required options
if (!options.address) {
throw new Error('Token address is required');
}
if (!options.decimals) {
throw new Error('Token decimals are required');
}

// Get token balances for all addresses
const multi = new Multicaller(network, provider, abi, { blockTag });
addresses.forEach((address) =>
multi.call(address, options.address, 'balanceOf', [address])
);
const result: Record<string, BigNumber> = await multi.execute();

// Apply quadratic voting (square root of balance)
return Object.fromEntries(
Object.entries(result).map(([address, balance]) => [
address,
parseFloat(formatUnits(sqrt(balance), options.decimals / 2))
])
);
}
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import * as erc20WithBalance from './erc20-with-balance';
import * as erc20BalanceOfDelegation from './erc20-balance-of-delegation';
import * as erc20BalanceOfWithDelegation from './erc20-balance-of-with-delegation';
import * as erc20BalanceOfQuadraticDelegation from './erc20-balance-of-quadratic-delegation';
import * as erc20QuadraticVoting from './erc20-quadratic-voting';
import * as erc20BalanceOfTopHolders from './erc20-balance-of-top-holders';
import * as erc20BalanceOfWeighted from './erc20-balance-of-weighted';
import * as erc20BalanceStarknet from './erc20-balance-starknet';
Expand Down Expand Up @@ -550,6 +551,7 @@ const strategies = {
'erc20-balance-of-delegation': erc20BalanceOfDelegation,
'erc20-balance-of-with-delegation': erc20BalanceOfWithDelegation,
'erc20-balance-of-quadratic-delegation': erc20BalanceOfQuadraticDelegation,
'erc20-quadratic-voting': erc20QuadraticVoting,
'erc20-balance-of-top-holders': erc20BalanceOfTopHolders,
'erc20-balance-of-weighted': erc20BalanceOfWeighted,
'erc20-balance-of-indexed': erc20BalanceOfIndexed,
Expand Down