-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GitPoap & Degenscore Data Provider (#1555)
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
1 parent
09f4bc9
commit a0d9aeb
Showing
9 changed files
with
308 additions
and
0 deletions.
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
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; |
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,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
75
group-generators/helpers/data-providers/degenscore/index.ts
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,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; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
group-generators/helpers/data-providers/degenscore/interface-schema.json
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,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
63
group-generators/helpers/data-providers/degenscore/types.ts
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,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; | ||
}; |
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,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; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
group-generators/helpers/data-providers/gitpoap/interface-schema.json
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,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" | ||
} | ||
] | ||
} | ||
] | ||
} |
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,5 @@ | ||
export type GitPoapEventId = { gitPoapEventId: string } | ||
|
||
export type GitPoapAddresses = { | ||
addresses: string[], | ||
} |
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