Skip to content

Commit

Permalink
queries: add typescript interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoAcosta committed Oct 15, 2024
1 parent 136eac2 commit c99dbe9
Show file tree
Hide file tree
Showing 10 changed files with 413 additions and 0 deletions.
86 changes: 86 additions & 0 deletions ts-interfaces/examples/plasa-query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Plasa } from "../types/plasa"
import { StampType } from "../types/stamps"

const examplePlasaQuery: Plasa = {
data: {
contractAddress: "0x1234567890123456789012345678901234567890",
chainId: 1,
version: "1.0.0"
},
user: {
username: "alice"
},
stamps: [
{
data: {
contractAddress: "0xabcdef1234567890abcdef1234567890abcdef12",
type: StampType.AccountOwnership,
name: "Twitter Account Ownership",
symbol: "TWO",
platform: "Twitter",
totalSupply: 1000000
},
user: {
owns: true,
stampId: "123456",
mintingTimestamp: 1625097600000
},
userUsername: "alice_twitter"
},
{
data: {
contractAddress: "0x9876543210fedcba9876543210fedcba98765432",
type: StampType.FollowerSince,
name: "Early Follower",
symbol: "EF",
platform: "Twitter",
totalSupply: 5000,
followedAccount: "0x1111222233334444555566667777888899990000",
space: "CryptoNews"
},
user: {
owns: true,
stampId: "789012",
mintingTimestamp: 1625184000000,
followTimestamp: 1625097600000,
timeSinceFollow: 86400000 // 1 day in milliseconds
}
}
],
spaces: [
{
data: {
contractAddress: "0x1111222233334444555566667777888899990000",
name: "CryptoNews",
description: "Latest news and updates in the crypto space",
imageUrl: "https://example.com/crypto-news.png",
creationTimestamp: 1625000000000
},
user: {
roles: {
superAdmin: false,
admin: true,
mod: true
},
permissions: {
UpdateSpaceInfo: true,
UpdateSpaceDefaultPoints: true,
UpdateQuestionInfo: true,
UpdateQuestionDeadline: true,
UpdateQuestionPoints: true,
CreateFixedQuestion: true,
CreateOpenQuestion: true,
VetoFixedQuestion: true,
VetoOpenQuestion: true,
VetoOpenQuestionOption: true,
LiftVetoFixedQuestion: true,
LiftVetoOpenQuestion: true,
LiftVetoOpenQuestionOption: true,
AddOpenQuestionOption: true
}
}
}
]
}

console.log(JSON.stringify(examplePlasaQuery, null, 2))
62 changes: 62 additions & 0 deletions ts-interfaces/examples/question-query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Question, QuestionType } from "../types/questions"

const exampleQuestionQuery: Question = {
data: {
contractAddress: "0x1111aaaabbbbccccddddeeeeffffgggg2222hhhh",
type: QuestionType.Fixed,
title: "Should we implement EIP-1559?",
description: "Vote on whether to implement Ethereum Improvement Proposal 1559",
creator: "0x3333444455556666777788889999aaaabbbbcccc",
kickoff: 1625270400000,
deadline: 1625875200000,
isActive: true,
voteCount: 1500
},
user: {
canVote: true,
pointsAtDeadline: 950
},
options: [
{
data: {
title: "Yes, implement EIP-1559",
description: "Support the implementation of EIP-1559 to improve gas fee predictability",
proposer: "0x7777888899990000aaaabbbbccccddddeeeefffff",
voteCount: 850,
pointsCurrent: 75000,
pointsAtDeadline: 72000
},
user: {
voted: false
}
},
{
data: {
title: "No, don't implement EIP-1559",
description: "Oppose the implementation of EIP-1559 due to concerns about miner revenue",
proposer: "0xbbbbccccddddeeeefffff00001111222233334444",
voteCount: 600,
pointsCurrent: 55000,
pointsAtDeadline: 53000
},
user: {
voted: false
}
},
{
data: {
title: "Delay implementation for further research",
description: "Postpone the decision on EIP-1559 to allow for more research and discussion",
proposer: "0xddddeeeefffff000011112222333344445555666",
voteCount: 50,
pointsCurrent: 5000,
pointsAtDeadline: 4800
},
user: {
voted: false
}
}
]
}

console.log(JSON.stringify(exampleQuestionQuery, null, 2))
83 changes: 83 additions & 0 deletions ts-interfaces/examples/space-query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Space } from "../types/spaces"
import { QuestionType } from "../types/questions"

const exampleSpaceQuery: Space = {
data: {
contractAddress: "0xaaaa1111bbbb2222cccc3333dddd4444eeee5555",
name: "Crypto Governance",
description: "A space for discussing and voting on crypto governance proposals",
imageUrl: "https://example.com/crypto-governance.png",
creationTimestamp: 1620000000000
},
user: {
roles: {
superAdmin: false,
admin: true,
mod: true
},
permissions: {
UpdateSpaceInfo: true,
UpdateSpaceDefaultPoints: true,
UpdateQuestionInfo: true,
UpdateQuestionDeadline: true,
UpdateQuestionPoints: true,
CreateFixedQuestion: true,
CreateOpenQuestion: true,
VetoFixedQuestion: true,
VetoOpenQuestion: true,
VetoOpenQuestionOption: true,
LiftVetoFixedQuestion: true,
LiftVetoOpenQuestion: true,
LiftVetoOpenQuestionOption: true,
AddOpenQuestionOption: true
}
},
points: {
data: {
contractAddress: "0xffff9999gggg8888hhhh7777iiii6666jjjj5555",
name: "Governance Points",
symbol: "GP"
},
user: {
currentBalance: 1000
}
},
questions: [
{
data: {
contractAddress: "0x1111aaaabbbbccccddddeeeeffffgggg2222hhhh",
type: QuestionType.Fixed,
title: "Should we implement EIP-1559?",
description: "Vote on whether to implement Ethereum Improvement Proposal 1559",
creator: "0x3333444455556666777788889999aaaabbbbcccc",
kickoff: 1625270400000,
deadline: 1625875200000,
isActive: true,
voteCount: 1500
},
user: {
canVote: true,
pointsAtDeadline: 950
}
},
{
data: {
contractAddress: "0x4444iiiijjjjkkkkllllmmmmnnnnoooo5555pppp",
type: QuestionType.Open,
title: "What should be our next focus area?",
description: "Propose and vote on the next major focus area for our project",
creator: "0x6666777788889999aaaabbbbccccddddeeeefffff",
kickoff: 1625356800000,
deadline: 1626048000000,
isActive: true,
voteCount: 750
},
user: {
canVote: true,
pointsAtDeadline: 1000
}
}
]
}

console.log(JSON.stringify(exampleSpaceQuery, null, 2))
2 changes: 2 additions & 0 deletions ts-interfaces/types/basic.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type AccountAddress = string
export type Timestamp = number
19 changes: 19 additions & 0 deletions ts-interfaces/types/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { AccountAddress } from './basic'

export interface OptionData {
title: string
description: string
proposer: AccountAddress
voteCount: number
pointsCurrent: number
pointsAtDeadline: number
}

export interface OptionUser {
voted: boolean
}

export interface Option {
data: OptionData
user: OptionUser
}
22 changes: 22 additions & 0 deletions ts-interfaces/types/plasa.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { AccountAddress } from './basic'
import { SpacePreview } from './spaces'
import { Stamp, FollowerSinceStamp, AccountOwnershipStamp } from './stamps'

export interface PlasaData {
contractAddress: AccountAddress
chainId: number
version: string
}

export interface PlasaUser {
username: string
}

export interface Plasa {
data: PlasaData
user: PlasaUser
stamps: (Stamp | FollowerSinceStamp | AccountOwnershipStamp)[]
spaces: SpacePreview[]
}

export type ViewReturnType = Plasa
16 changes: 16 additions & 0 deletions ts-interfaces/types/points.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { AccountAddress } from './basic'

export interface PointsData {
contractAddress: AccountAddress
name: string
symbol: string
}

export interface PointsUser {
currentBalance: number
}

export interface Points {
data: PointsData
user: PointsUser
}
33 changes: 33 additions & 0 deletions ts-interfaces/types/questions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { AccountAddress, Timestamp } from './basic'
import { Option } from './options'

export enum QuestionType {
Open = 'Open',
Fixed = 'Fixed',
}

export interface QuestionData {
contractAddress: AccountAddress
type: QuestionType
title: string
description: string
creator: AccountAddress
kickoff: Timestamp
deadline: Timestamp
isActive: boolean
voteCount: number
}

export interface QuestionUser {
canVote: boolean
pointsAtDeadline: number
}

export interface QuestionPreview {
data: QuestionData
user: QuestionUser
}

export interface Question extends QuestionPreview {
options: Option[]
}
45 changes: 45 additions & 0 deletions ts-interfaces/types/spaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { AccountAddress, Timestamp } from './basic'
import { Points } from './points'
import { QuestionPreview } from './questions'

export interface SpaceData {
contractAddress: AccountAddress
name: string
description: string
imageUrl: string
creationTimestamp: Timestamp
}

export interface SpaceUser {
roles: {
superAdmin: boolean
admin: boolean
mod: boolean
}
permissions: {
UpdateSpaceInfo: boolean
UpdateSpaceDefaultPoints: boolean
UpdateQuestionInfo: boolean
UpdateQuestionDeadline: boolean
UpdateQuestionPoints: boolean
CreateFixedQuestion: boolean
CreateOpenQuestion: boolean
VetoFixedQuestion: boolean
VetoOpenQuestion: boolean
VetoOpenQuestionOption: boolean
LiftVetoFixedQuestion: boolean
LiftVetoOpenQuestion: boolean
LiftVetoOpenQuestionOption: boolean
AddOpenQuestionOption: boolean
}
}

export interface SpacePreview {
data: SpaceData
user: SpaceUser
}

export interface Space extends SpacePreview {
points: Points
questions: QuestionPreview[]
}
Loading

0 comments on commit c99dbe9

Please sign in to comment.