-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Streamr snapshot strategy | ||
|
||
The Streamr Network is a peer-to-peer network for publishing and subscribing to data in real-time. Applications use it for decentralized messaging, for example sharing data across applications or broadcasting real-time state changes to large audiences. The decentralized nature of the system makes the data transport scalable, robust, secure, tamper proof, and censorship resistant. | ||
|
||
Operators are the node running "miners" in the Streamr Network. They run Streamr nodes, subscribe to streams, and stake DATA in the Sponsorship contract(s) of those streams. When they subscribe, they help making that stream more robust. In return, they receive DATA tokens from the Sponsorship contract, in proportion to their stake. | ||
|
||
This is why part of the Operators' DATA tokens are staked in Sponsorships (through an Operator contract that they control). Only a small portion of DATA is expected to be in the Streamr Network participants' wallets, the rest is staked or delegated into the Streamr Network. | ||
|
||
'''The point of the Streamr snapshot strategy''' is to allocate voting power not only according to DATA token holding (as in the plain erc-20-balance-of strategy), but also counting in the DATA tokens the token holders control via staking and delegation (NOTE: at first, only implemented for stakers. Counting delegated DATA may be added later). | ||
|
||
## Parameters | ||
|
||
```json | ||
{ | ||
"tokenAddress": "0x3a9A81d576d83FF21f26f325066054540720fC34", | ||
"operatorFactoryAddress": "0x935734e66729b69260543Cf6e5EfeB42AC962183" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
[ | ||
{ | ||
"name": "Streamr", | ||
"strategy": { | ||
"name": "streamr", | ||
"params": { | ||
"tokenAddress": "0x3a9A81d576d83FF21f26f325066054540720fC34", | ||
"operatorFactoryAddress": "0x935734e66729b69260543Cf6e5EfeB42AC962183" | ||
} | ||
}, | ||
"network": "137", | ||
"addresses": [ | ||
"0xD6c2bF543491337D81eC9b7d96CFbC04fCB3F4a0", | ||
"0x2112a4b0F6500Bc0c1AebbAb547eaAB6862acC57", | ||
"0x488c0Ba58dAc039fAA30D91DdF86CD75B7Dbe4cD", | ||
"0x013B3576Ef573b7D1eD82Fc4C08bb9dB24EBFa4f", | ||
"0xAd6A86cC6F6e1169292e7bf325564e0B9AC812A7", | ||
"0x9bC7F7Aa4b4395391089dA8588fFb0842b5483A6", | ||
"0xab034dCE46BC70Fd1A032f883B46f6d2BC18DD1a", | ||
"0xB20C20ba1B94A2Fb746091c8D83937Ee35644251", | ||
"0x02fdB03705ed8F92fB8C5073990FC5D4d169FAF8", | ||
"0xc65394747cCCFc5e5DED39da191Bc1C3f9FDB3a2", | ||
"0x5015C1654D8829d549EE976e462bD8B7adE847C5", | ||
"0x6Fc263FF819609E5F4c3d5b8D742Fa94B8a3fEaD", | ||
"0xA39E67290f89dC2419d5F6bf7fE8cc448A80CD1A", | ||
"0x8d1BEc0692cbFC14CC53af1f0D1aBFFC79DBC04f", | ||
"0x02880624Bb0743E3144e8943E29Fd1DDe66cF72c", | ||
"0x8da1A015bb11BcC718CF1f49804282Fa5dBA75C7", | ||
"0x444d26eC73DBaC8d78299597135dA5C0234BafA1", | ||
"0x2594664714882D47aC207b4C46751649d886Bdf8", | ||
"0x41c00f648E781742A5C2CB83B34a05D11D833C4D", | ||
"0x40f076d4AbE73Be1eB21B862A578cDd583910556" | ||
], | ||
"snapshot": 50305259 | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { BigNumber } from '@ethersproject/bignumber'; | ||
import { formatEther } from '@ethersproject/units'; | ||
import { Multicaller } from '../../utils'; | ||
|
||
export const author = 'streamr-dev'; | ||
export const version = '0.1.1'; | ||
|
||
const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000'; | ||
|
||
const abi = [ | ||
'function balanceOf(address account) external view returns (uint256)', // in DATA token | ||
'function operators(address owner) external view returns (address)', // in OperatorFactory, returns operator contract address | ||
'function valueWithoutEarnings() external view returns (uint)' // in Operator contract | ||
]; | ||
|
||
type Balances = { | ||
tokens: BigNumber; | ||
staked?: BigNumber; | ||
}; | ||
|
||
export async function strategy( | ||
space, | ||
network, | ||
provider, | ||
addresses: string[], | ||
options, | ||
snapshot | ||
): Promise<Record<string, number>> { | ||
const blockTag = typeof snapshot === 'number' ? snapshot : 'latest'; | ||
|
||
// find the Operator contract deployed by the DATA token holder, will return ADDRESS_ZERO if not found | ||
const getContractOf = new Multicaller(network, provider, abi, { blockTag }); | ||
for (const tokenHolder of addresses) { | ||
getContractOf.call( | ||
tokenHolder, | ||
options.operatorFactoryAddress, | ||
'operators', | ||
[tokenHolder] | ||
); | ||
} | ||
const contractOf: Record<string, string> = await getContractOf.execute(); | ||
|
||
// get both the "cash in hand", and DATA tokens staked through the Operator contract (Operator value) | ||
const getBalances = new Multicaller(network, provider, abi, { blockTag }); | ||
for (const tokenHolder of addresses) { | ||
getBalances.call( | ||
`${tokenHolder}.tokens`, | ||
options.tokenAddress, | ||
'balanceOf', | ||
[tokenHolder] | ||
); | ||
if (contractOf[tokenHolder] != ADDRESS_ZERO) { | ||
getBalances.call( | ||
`${tokenHolder}.staked`, | ||
contractOf[tokenHolder], | ||
'valueWithoutEarnings', | ||
[] | ||
); | ||
} | ||
} | ||
const balances: Record<string, Balances> = await getBalances.execute(); | ||
|
||
return Object.fromEntries( | ||
Object.entries(balances).map( | ||
([address, { tokens, staked = BigNumber.from(0) }]) => [ | ||
address, | ||
parseFloat(formatEther(tokens.add(staked))) | ||
] | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/Strategy", | ||
"definitions": { | ||
"Strategy": { | ||
"title": "Strategy", | ||
"type": "object", | ||
"properties": { | ||
"tokenAddress": { | ||
"type": "string", | ||
"title": "DATA token address", | ||
"examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"], | ||
"pattern": "^0x[a-fA-F0-9]{40}$", | ||
"minLength": 42, | ||
"maxLength": 42 | ||
}, | ||
"operatorFactoryAddress": { | ||
"type": "string", | ||
"title": "OperatorFactory address", | ||
"examples": ["e.g. 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984"], | ||
"pattern": "^0x[a-fA-F0-9]{40}$", | ||
"minLength": 42, | ||
"maxLength": 42 | ||
} | ||
}, | ||
"required": ["tokenAddress", "operatorFactoryAddress"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |