Skip to content

Commit

Permalink
Add GitPoap & Degenscore Data Provider (#1555)
Browse files Browse the repository at this point in the history
Co-authored-by: mme <9083787+mme022@users.noreply.github.com>
Co-authored-by: 3Vis <francescotrevisan3@gmail.com>
Co-authored-by: 3Vis <31535611+3Vis3@users.noreply.github.com>
  • Loading branch information
4 people committed Mar 18, 2023
1 parent 09f4bc9 commit a0d9aeb
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 0 deletions.
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({_score: 900});
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;
29 changes: 29 additions & 0 deletions group-generators/generators/gitpoap/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.GitPoapProvider();
const addresses = await degenscoreProvider.getGitPoapHoldersByEventId({gitPoapEventId: "37428"});
return [
{
name: "poap-holder-of-37428",
description: "Get all POAP holder of the event id 37428",
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 (_: any) =>
new DegenScoreProvider().getBeaconOwnersWithScoreCount(_),
},
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

0 comments on commit a0d9aeb

Please sign in to comment.