Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaituVR authored Dec 2, 2023
2 parents a679767 + 8d83db8 commit 7d5ae22
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 1 deletion.
60 changes: 59 additions & 1 deletion src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,35 @@ import * as bubblegumKids from './bubblegum-kids';
import * as clipperStakedSail from './clipper-staked-sail';
import * as plearn from './plearn';
import * as snote from './snote';
import * as streamr from './streamr';
import * as aavegotchiAgip17 from './aavegotchi-agip-17';
import * as aavegotchiAgip37GltrStakedLp from './aavegotchi-agip-37-gltr-staked-lp';
import * as aavegotchiAgip37WapGhst from './aavegotchi-agip-37-wap-ghst';
import * as agave from './agave';
import * as arrakisFinance from './arrakis-finance';
import * as ctsiStakingPool from './ctsi-staking-pool';
import * as cyberkongzV2 from './cyberkongz-v2';
import * as dextfStakedInVaults from './dextf-staked-in-vaults';
import * as genomesdao from './genomesdao';
import * as goldfinchMembership from './goldfinch-membership';
import * as goldfinchVotingPower from './goldfinch-voting-power';
import * as h2o from './h2o';
import * as hoprStakingBySeason from './hopr-staking-by-season';
import * as hoprStakingS2 from './hopr-staking-s2';
import * as ilv from './ilv';
import * as meebitsdaoDelegation from './meebitsdao-delegation';
import * as modefiStaking from './modefi-staking';
import * as orbsNetworkDelegation from './orbs-network-delegation';
import * as planetFinanceV2 from './planet-finance-v2';
import * as rariFuse from './rari-fuse';
import * as synthetixNonQuadratic_1 from './synthetix-non-quadratic_1';
import * as synthetixQuadratic from './synthetix-quadratic';
import * as synthetixQuadratic_1 from './synthetix-quadratic_1';
import * as synthetix_1 from './synthetix_1';
import * as totalAxionShares from './total-axion-shares';
import * as unipoolSameToken from './unipool-same-token';
import * as voltVotingPower from './volt-voting-power';
import * as xdaiStakersAndHolders from './xdai-stakers-and-holders';

const strategies = {
'cap-voting-power': capVotingPower,
Expand Down Expand Up @@ -758,7 +787,36 @@ const strategies = {
'bubblegum-kids': bubblegumKids,
'clipper-staked-sail': clipperStakedSail,
plearn,
snote
snote,
streamr,
'aavegotchi-agip-17': aavegotchiAgip17,
'aavegotchi-agip-37-gltr-staked-lp': aavegotchiAgip37GltrStakedLp,
'aavegotchi-agip-37-wap-ghst': aavegotchiAgip37WapGhst,
agave,
'arrakis-finance': arrakisFinance,
'ctsi-staking-pool': ctsiStakingPool,
'cyberkongz-v2': cyberkongzV2,
'dextf-staked-in-vaults': dextfStakedInVaults,
genomesdao,
'goldfinch-membership': goldfinchMembership,
'goldfinch-voting-power': goldfinchVotingPower,
h2o,
'hopr-staking-by-season': hoprStakingBySeason,
'hopr-staking-s2': hoprStakingS2,
ilv,
'meebitsdao-delegation': meebitsdaoDelegation,
'modefi-staking': modefiStaking,
'orbs-network-delegation': orbsNetworkDelegation,
'planet-finance-v2': planetFinanceV2,
'rari-fuse': rariFuse,
'synthetix-non-quadratic_1': synthetixNonQuadratic_1,
'synthetix-quadratic': synthetixQuadratic,
'synthetix-quadratic_1': synthetixQuadratic_1,
synthetix_1,
'total-axion-shares': totalAxionShares,
'unipool-same-token': unipoolSameToken,
'volt-voting-power': voltVotingPower,
'xdai-stakers-and-holders': xdaiStakersAndHolders
};

Object.keys(strategies).forEach(function (strategyName) {
Expand Down
18 changes: 18 additions & 0 deletions src/strategies/streamr/README.md
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"
}
```
36 changes: 36 additions & 0 deletions src/strategies/streamr/examples.json
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
}
]
71 changes: 71 additions & 0 deletions src/strategies/streamr/index.ts
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)))
]
)
);
}
30 changes: 30 additions & 0 deletions src/strategies/streamr/schema.json
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
}
}
}

0 comments on commit 7d5ae22

Please sign in to comment.