Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[karma-discord-roles] feature: add karma-discord-roles #1210

Merged
merged 9 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions src/strategies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ import * as erc721CollateralHeld from './erc721-collateral-held';
import * as starlayVeBalanceOfLockerId from './starlay-ve-balance-of-locker-id';
import * as winrStaking from './winr-staking';
import * as spaceid from './spaceid';
import * as karmaDiscordRoles from './karma-discord-roles';
import * as seedifyHoldStakingFarming from './seedify-cumulative-voting-power-hodl-staking-farming';

const strategies = {
Expand Down Expand Up @@ -900,6 +901,7 @@ const strategies = {
'starlay-ve-balance-of-locker-id': starlayVeBalanceOfLockerId,
'winr-staking': winrStaking,
spaceid,
'karma-discord-roles': karmaDiscordRoles,
'seedify-cumulative-voting-power-hodl-staking-farming':
seedifyHoldStakingFarming
};
Expand Down
41 changes: 41 additions & 0 deletions src/strategies/karma-discord-roles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# karma-discord-roles

**Karma Discord role strategy can be used by DAOs to provide voting power to contributors with a specific role on Discord.**

## Prerequisites

Below are the prerequisites to enable this strategy for your Snapshot space.

1. For this strategy to work, the DAO needs to be set up in Karma's platform. Send us an email at dao@karmahq.xyz for onboarding on to Karma.

2. Have Karma Discord Bot installed in your Discord server. You can install the bot through the following link: (https://discord.com/api/oauth2/authorize?client_id=986699463164846100&permissions=1101927561248&scope=bot%20applications.commands).

## Usage

json
{
"name": <daoName>,
"roles": [<list of discord roles>]
}

**Example 1**
json
{
"name": "Karma",
"roles": ["Moderator"]
}

This will assign voting power of 1 to anyone in Karma's discord server who has "Moderator" role assigned to them.

**Example 2**
json
{
"name": "Karma",
"roles": ["Moderator"],
"addresses": [
"0xa768f5F340e89698465Fc7C12F31cB485fAf98B2"
]
}
This will assign voting power of 1 to anyone in Karma's discord server who has "Moderator" role assigned to them. It will also assign voting power to any address in "addresses" list.

If you have trouble setting up the strategy, please email us at dao@karmahq.xyz.
21 changes: 21 additions & 0 deletions src/strategies/karma-discord-roles/examples.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[
{
"name": "Example query",
"strategy": {
"name": "karma-discord-roles",
"params": {
"name": "apecoin",
"roles": ["Assembly"]
}
},
"network": "1",
"addresses": [
"0x10cCD4136471c7c266a9Fc4569622989Fb4caB99",
"0x95e1eeb014eeB6c8709f2Ce4F19B847138fd5685",
"0x7B124228eC8e9C9C9ddC3278bb0ee4a6dAa5dDee"
],

"snapshot": 11437846
}
]

46 changes: 46 additions & 0 deletions src/strategies/karma-discord-roles/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import fetch from 'cross-fetch';
import { getAddress } from '@ethersproject/address';

export const author = 'KarmaHq';
Arthh marked this conversation as resolved.
Show resolved Hide resolved
export const version = '2.0.0';
Arthh marked this conversation as resolved.
Show resolved Hide resolved

const KARMA_API = 'https://api.karmahq.xyz/api/dao/discordUsers';

export async function strategy(
space,
network,
provider,
addresses,
options,
snapshot

Check warning on line 15 in src/strategies/karma-discord-roles/index.ts

View workflow job for this annotation

GitHub Actions / build_lint (16.10.x)

'snapshot' is defined but never used
): Promise<{
[k: string]: any;
}> {
const { name, roles } = options;

if (!name || !roles) return {};

const response = await fetch(`${KARMA_API}/${name}/${roles.join(',')}`, {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
}
});

const parsedResponse = !response.ok ? [] : await response.json();
const delegates = parsedResponse.data?.delegates || [];

const votingPower = {};

const userAddresses = delegates.map((user) => user.publicAddress);
const paramAddresses = addresses.length ? addresses : [];
const allAddresses = [...userAddresses, ...paramAddresses];

allAddresses.forEach((address) => {
const checksumAddress = getAddress(address);
votingPower[checksumAddress] = 1;
});
ChaituVR marked this conversation as resolved.
Show resolved Hide resolved

return votingPower;
}
24 changes: 24 additions & 0 deletions src/strategies/karma-discord-roles/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$ref": "#/definitions/Strategy",
"definitions": {
"Strategy": {
"title": "Strategy",
"type": "object",
"properties": {
"name": {
"type": "string",
"title": "DAO Name",
"examples": ["e.g. apecoin, ens, gitcoin"],
},
"roles": {
"type": "array",
"title": "Discord Roles",
"examples": ["e.g. Assembly, Trader, Moderator"]
}
},
"required": ["name","roles"],
"additionalProperties": false
}
}
}
Loading