-
Notifications
You must be signed in to change notification settings - Fork 205
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
MartinGbz
merged 24 commits into
sismo-core:gitpoap-degenscore-dp-merge
from
0xmme:main
Mar 18, 2023
Merged
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
8edd121
space for degenscore
0xmme 6386cc5
added function to fetch tokenholders from etherscan
0xmme 1177a98
added the first draft of functions
0xmme 2914970
added functionality to retrieve addresses matching criteria
0xmme 98d590d
finished degenscore provider
0xmme f4f757b
feat: add gitpoap as data provider
6881252
chore: make unused function private
18fe54a
Merge pull request #4 from mme022/gitpoap
markus0x1 f22e7d3
changed to retrieve beacons first, holders to itsecond
0xmme 68572d9
Merge branch 'sismo-core:main' into data-provider-degenscore
0xmme e7a33e9
added fixes to return users and count function
0xmme 87e8c6b
Merge branch 'data-provider-degenscore' of https://github.com/mme022/…
0xmme bfbeb2c
fix schema
3Vis3 48ff526
Merge pull request #3 from mme022/data-provider-degenscore
3Vis3 39b7462
chore: remove unnecessary function
d46e8e7
chore: remove comments
dcf874c
feat: add defillama json rpc
fb3d2f5
added group for degenscore
0xmme 0599a75
removed old comments
0xmme c358427
Update interface-schema.json
0xmme 4056e32
fixed the arguments to fit factory specs
0xmme 8b21fef
fixed gitpoap arguments to fit factory specs
61f7d4c
refactor: create type for input args
b3ba22f
fix some test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(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; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 typeScore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed with b3ba22f