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

Add GitPoap & Degenscore Data Provider #1555

Merged
merged 24 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8edd121
space for degenscore
0xmme Mar 17, 2023
6386cc5
added function to fetch tokenholders from etherscan
0xmme Mar 17, 2023
1177a98
added the first draft of functions
0xmme Mar 17, 2023
2914970
added functionality to retrieve addresses matching criteria
0xmme Mar 17, 2023
98d590d
finished degenscore provider
0xmme Mar 17, 2023
f4f757b
feat: add gitpoap as data provider
Mar 17, 2023
6881252
chore: make unused function private
Mar 17, 2023
18fe54a
Merge pull request #4 from mme022/gitpoap
markus0x1 Mar 17, 2023
f22e7d3
changed to retrieve beacons first, holders to itsecond
0xmme Mar 17, 2023
68572d9
Merge branch 'sismo-core:main' into data-provider-degenscore
0xmme Mar 17, 2023
e7a33e9
added fixes to return users and count function
0xmme Mar 17, 2023
87e8c6b
Merge branch 'data-provider-degenscore' of https://github.com/mme022/…
0xmme Mar 17, 2023
bfbeb2c
fix schema
3Vis3 Mar 17, 2023
48ff526
Merge pull request #3 from mme022/data-provider-degenscore
3Vis3 Mar 17, 2023
39b7462
chore: remove unnecessary function
Mar 18, 2023
d46e8e7
chore: remove comments
Mar 18, 2023
dcf874c
feat: add defillama json rpc
Mar 18, 2023
fb3d2f5
added group for degenscore
0xmme Mar 18, 2023
0599a75
removed old comments
0xmme Mar 18, 2023
c358427
Update interface-schema.json
0xmme Mar 18, 2023
4056e32
fixed the arguments to fit factory specs
0xmme Mar 18, 2023
8b21fef
fixed gitpoap arguments to fit factory specs
Mar 18, 2023
61f7d4c
refactor: create type for input args
Mar 18, 2023
b3ba22f
fix some test
Mar 18, 2023
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
29 changes: 29 additions & 0 deletions group-generators/generators/degenscore-over-900/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { dataProviders } from "@group-generators/helpers/data-providers";
import { GroupWithData, Tags, ValueType } from "topics/group";
import {
GenerationContext,
GenerationFrequency,
GroupGenerator,
} from "topics/group-generator";

const generator: GroupGenerator = {
generationFrequency: GenerationFrequency.Weekly,

generate: async (context: GenerationContext): Promise<GroupWithData[]> => {
const degenscoreProvider = new dataProviders.DegenScoreProvider();
const addresses = await degenscoreProvider.getBeaconOwnersWithScore(900);
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to change this part of your group, getBeaconOwnersWithScore require a type Score

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed with b3ba22f

return [
{
name: "degens-score-over-900",
description: "Get all degens with a score of minimum 900",
specs: "",
timestamp: context.timestamp,
data: addresses,
valueType: ValueType.Info,
tags: [Tags.User],
},
];
},
};

export default generator;
75 changes: 75 additions & 0 deletions group-generators/helpers/data-providers/degenscore/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import axios from "axios";
// eslint-disable-next-line no-restricted-imports
import { ethers } from "ethers";
// eslint-disable-next-line import/no-unresolved, @typescript-eslint/no-unused-vars
import { BeaconResponse, Score } from "./types";
import { FetchedData } from "topics/group";

export class DegenScoreProvider {
url: string;
headers: {
authorization: string;
accept: string;
};

provider: ethers.providers.JsonRpcProvider;

constructor() {
this.provider = new ethers.providers.JsonRpcProvider(
"https://eth.llamarpc.com"
);
}

public async getBeaconOwnersWithScore({ _score }: Score) {
// fetch Beacons from API
const data: BeaconResponse = await this.getBeacons();

const enrichedData: any = {};

// Add holder of each beacon
data["beacons"].map(async (elem: any) => {
const holder = await this.getTokenHolder(elem["address"]);
enrichedData[holder] = elem["primaryTraits"]["degen_score"];
});

// filter for score over preset
const returnData: FetchedData = {};
Object.keys(enrichedData).forEach((holder: string) => {
if (enrichedData[holder] >= _score) {
returnData[holder] = 1;
}
});
return returnData;
}

public async getBeaconOwnersWithScoreCount({ _score }: Score) {
const data = await this.getBeaconOwnersWithScore({ _score: _score });
return Object.keys(data).length;
}

private async getBeacons() {
const { data: res } = await axios({
url: "https://beacon.degenscore.com/v1/beacons/",
method: "get",
});
return res;
}

private async getTokenHolder(beaconId: number): Promise<string> {
const abi = [
"function ownerOfBeacon(uint128) public view returns (string)",
];
const beaconInterface = new ethers.utils.Interface(abi);
const beaconRequestData = beaconInterface.encodeFunctionData(
"ownerOfBeacon",
[beaconId]
);
const tokenHolder = await this.provider.send("eth_call", [
{
to: "0x0521FA0bf785AE9759C7cB3CBE7512EbF20Fbdaa",
data: beaconRequestData,
},
]);
return tokenHolder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "DegenScore",
"iconUrl": "",
"providerClassName": "DegenScoreProvider",
"functions": [
{
"name": "Get holders of beacon",
"functionName": "getBeaconOwnersWithScore",
"countFunctionName": "getBeaconOwnersWithScoreCount",
"description": "Returns all holders of a beacon above a min score and with a specific trait",
"args": [
{
"name": "Score",
"argName": "_score",
"type": "string",
"example": "730",
"description": "A minimum beacon score"
}
]
}
]
}
63 changes: 63 additions & 0 deletions group-generators/helpers/data-providers/degenscore/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export type Score = { _score: number }

export type TokenHolder = {
TokenHolderAddress: string;
TokenHolderQuantity: string;
};

export type EtherscanResponse = {
status: string;
message: string;
result: TokenHolder[];
};

export type DegenScoreTrait = {
name: string;
description: string;
image: string;
value: string | number;
valueType: string;
traitType: string;
rarity: string;
id: string;
tags: { id: string; value: string }[];
};

export type TraitInfoResponse = {
name: string;
description: string;
image: string;
properties: {
valueType: string;
};
};

export type BeaconInfoResponse = {
name: string;
description: string;
image: string;
properties: any;
updatedAt: string;
isConfirmed: boolean;
external_url: string;
animation_url: string;
traits: DegenScoreTrait;
};

export type BeaconResponse = {
beacons: [
{
address: string;
primaryTraits: {
degenScore: string;
};
updatedAt: string;
}
];
};

export type UserBeaconData = {
owner_address: string;
balance: string;
beaconData: BeaconInfoResponse;
};
49 changes: 49 additions & 0 deletions group-generators/helpers/data-providers/gitpoap/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import axios from "axios";
import { GitPoapAddresses, GitPoapEventId } from "./types";
import { FetchedData } from "topics/group";

export class GitPoapProvider {
url: string;


public constructor() {
this.url = "https://public-api.gitpoap.io/";
}

private async getGitPoap(endpoint: string): Promise<any> {
const { data: res } = await axios({
url: this.url + endpoint,
method: "get",
});
return res;
}


public async getGitPoapHoldersByEventId({gitPoapEventId }: GitPoapEventId ): Promise<FetchedData> {
const dataProfiles: FetchedData = {};
let holdersAddress: string[];
try {
const req: GitPoapAddresses= await this.getGitPoap("/v1/gitpoaps/" + gitPoapEventId + "/addresses");
holdersAddress = req.addresses;
} catch (error) {
throw new Error("Error fetching total number of users: " + error);
}

await Promise.all(holdersAddress)
.then((addresses) => {
addresses.forEach((address) => {
if (address != "") {
dataProfiles[address] = 1;
}
});
});

return dataProfiles;
}

public async getGitPoapHoldersByEventIdCount({gitPoapEventId }: GitPoapEventId ): Promise<number> {
const holders = this.getGitPoapHoldersByEventId({gitPoapEventId });
return Object(holders).keys().length;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "GitPOAP",
"iconUrl": "",
"providerClassName": "GitPoapProvider",
"functions": [
{
"name": "Get GitPOAP holders given an GitPOAPEventID",
"functionName": "getGitPoapHoldersByEventId",
"countFunctionName": "getGitPoapHoldersByEventIdCount",
"description": "Returns all Ethereum Addresses which have received a GitPoap with a given eventId",
"args": [
{
"name": "gitPoapEventId",
"argName": "gitPoapEventId",
"type": "string",
"example": "37428",
"description": "Event id of the GitPOAP token"
}
]
}
]
}
5 changes: 5 additions & 0 deletions group-generators/helpers/data-providers/gitpoap/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type GitPoapEventId = { gitPoapEventId: string }

export type GitPoapAddresses = {
addresses: string[],
}
14 changes: 14 additions & 0 deletions group-generators/helpers/data-providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { BigQueryProvider } from "./big-query/big-query";
import { DegenScoreProvider } from "./degenscore";
import { EnsProvider } from "./ens";
import { EthLeaderboardProvider } from "./eth-leaderboard";
import { FarcasterProvider } from "./farcaster";
import { GithubProvider } from "./github";
import githubInterfaceSchema from "./github/interface-schema.json";
import { GitPoapProvider } from "./gitpoap";
import gitPoapInterfaceSchema from "./gitpoap/interface-schema.json";
import { GraphQLProvider } from "./graphql";
import { HiveProvider } from "./hive";
import HiveInterfaceSchema from "./hive/interface-schema.json";
Expand Down Expand Up @@ -38,7 +41,9 @@ export const dataProviders = {
EnsProvider,
EthLeaderboardProvider,
FarcasterProvider,
DegenScoreProvider,
GithubProvider,
GitPoapProvider,
GraphQLProvider,
HiveProvider,
JsonRpcProvider,
Expand All @@ -58,6 +63,7 @@ export const dataProviders = {

export const dataProvidersInterfacesSchemas = [
githubInterfaceSchema,
gitPoapInterfaceSchema,
HiveInterfaceSchema,
lensInterfaceSchema,
poapInterfaceSchema,
Expand All @@ -69,12 +75,20 @@ export const dataProvidersInterfacesSchemas = [
];

export const dataProvidersAPIEndpoints = {
DegenScoreProvider: {
getBeaconOwnersWithScoreCount: async ({ score }: { score: number }) =>
new DegenScoreProvider().getBeaconOwnersWithScoreCount(score),
},
GithubProvider: {
getRepositoriesContributorsCount: async (_: any) =>
new GithubProvider().getRepositoriesContributorsCount(_),
getRepositoriesStargazersCount: async (_: any) =>
new GithubProvider().getRepositoriesStargazersCount(_),
},
GitPoapProvider: {
getGitPoapHoldersByEventIdCount: async (_: any) =>
new GitPoapProvider().getGitPoapHoldersByEventIdCount(_),
},
LensProvider: {
getFollowersCount: async (_: any) =>
new LensProvider().getFollowersCount(_),
Expand Down