generated from proofoftom/buidler-waffle-typechain-quasar
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create recipient registry entity and template by registry type
- Loading branch information
Showing
5 changed files
with
149 additions
and
27 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
76 changes: 76 additions & 0 deletions
76
subgraph/src/recipientRegistry/RecipientRegistryFactory.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,76 @@ | ||
import { Address } from '@graphprotocol/graph-ts' | ||
import { OptimisticRecipientRegistry as OptimisticRecipientRegistryContract} from '../../generated/FundingRoundFactory/OptimisticRecipientRegistry' | ||
import { SimpleRecipientRegistry as SimpleRecipientRegistryContract } from '../../generated/FundingRoundFactory/SimpleRecipientRegistry' | ||
import { KlerosRecipientRegistry as KlerosRecipientRegistryContract } from '../../generated/FundingRoundFactory/KlerosRecipientRegistry' | ||
|
||
import { RecipientRegistry } from '../../generated/schema' | ||
import { RecipientRegistryType, getRecipientRegistryType } from './RecipientRegistryType' | ||
|
||
export class RecipientRegistryCreateParams { | ||
recipientRegistryAddress: Address | ||
fundingRoundFactoryId: string | ||
createdAt: string | ||
} | ||
|
||
class RecipientRegistryFactoryOptimistic { | ||
static create(params: RecipientRegistryCreateParams): RecipientRegistry { | ||
let recipientRegistryId = params.recipientRegistryAddress.toHexString() | ||
let recipientRegistry = new RecipientRegistry(recipientRegistryId) | ||
|
||
let optimisticRegistry = OptimisticRecipientRegistryContract.bind(params.recipientRegistryAddress) | ||
recipientRegistry.baseDeposit = optimisticRegistry.baseDeposit() | ||
recipientRegistry.challengePeriodDuration = optimisticRegistry.challengePeriodDuration() | ||
recipientRegistry.owner = optimisticRegistry.owner() | ||
|
||
recipientRegistry.controller = optimisticRegistry.controller() | ||
recipientRegistry.maxRecipients = optimisticRegistry.maxRecipients() | ||
recipientRegistry.fundingRoundFactory = params.fundingRoundFactoryId | ||
recipientRegistry.createdAt = params.createdAt | ||
|
||
return recipientRegistry | ||
} | ||
} | ||
|
||
class RecipientRegistryFactorySimple { | ||
static create(params: RecipientRegistryCreateParams): RecipientRegistry { | ||
let recipientRegistryId = params.recipientRegistryAddress.toHexString() | ||
let recipientRegistry = new RecipientRegistry(recipientRegistryId) | ||
|
||
let simpleRegistry = SimpleRecipientRegistryContract.bind(params.recipientRegistryAddress) | ||
recipientRegistry.owner = simpleRegistry.owner() | ||
recipientRegistry.controller = simpleRegistry.controller() | ||
recipientRegistry.maxRecipients = simpleRegistry.maxRecipients() | ||
recipientRegistry.fundingRoundFactory = params.fundingRoundFactoryId | ||
recipientRegistry.createdAt = params.createdAt | ||
|
||
return recipientRegistry | ||
} | ||
} | ||
|
||
class RecipientRegistryFactoryKleros { | ||
static create(params: RecipientRegistryCreateParams): RecipientRegistry { | ||
let recipientRegistryId = params.recipientRegistryAddress.toHexString() | ||
let recipientRegistry = new RecipientRegistry(recipientRegistryId) | ||
|
||
let klerosRegistry = KlerosRecipientRegistryContract.bind(params.recipientRegistryAddress) | ||
recipientRegistry.controller = klerosRegistry.controller() | ||
recipientRegistry.maxRecipients = klerosRegistry.maxRecipients() | ||
recipientRegistry.fundingRoundFactory = params.fundingRoundFactoryId | ||
recipientRegistry.createdAt = params.createdAt | ||
|
||
return recipientRegistry | ||
} | ||
} | ||
|
||
export class RecipientRegistryFactory { | ||
static create(params: RecipientRegistryCreateParams): RecipientRegistry { | ||
let type = getRecipientRegistryType(params.recipientRegistryAddress) | ||
if( type == RecipientRegistryType.Optimistic ) { | ||
return RecipientRegistryFactoryOptimistic.create(params) | ||
} else if ( type == RecipientRegistryType.Kleros ) { | ||
return RecipientRegistryFactoryKleros.create(params) | ||
} else { | ||
return RecipientRegistryFactorySimple.create(params) | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
subgraph/src/recipientRegistry/RecipientRegistryTemplate.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,24 @@ | ||
import { RecipientRegistryType, getRecipientRegistryType } from "./RecipientRegistryType"; | ||
import { Address } from '@graphprotocol/graph-ts' | ||
import { | ||
OptimisticRecipientRegistry as OptimisticRecipientRegistryTemplate, | ||
SimpleRecipientRegistry as SimpleRecipientRegistryTemplate, | ||
KlerosRecipientRegistry as KlerosRecipientRegistryTemplate, | ||
} from '../../generated/templates' | ||
|
||
|
||
export class RecipientRegistryTemplate { | ||
static create(registryAddress: Address): void { | ||
let type = getRecipientRegistryType(registryAddress) | ||
switch( type ) { | ||
case RecipientRegistryType.Kleros: | ||
KlerosRecipientRegistryTemplate.create(registryAddress) | ||
break; | ||
case RecipientRegistryType.Optimistic: | ||
OptimisticRecipientRegistryTemplate.create(registryAddress) | ||
break; | ||
default: | ||
SimpleRecipientRegistryTemplate.create(registryAddress) | ||
} | ||
} | ||
} |
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,34 @@ | ||
import { Address } from '@graphprotocol/graph-ts' | ||
import { OptimisticRecipientRegistry as OptimisticRecipientRegistryContract} from '../../generated/FundingRoundFactory/OptimisticRecipientRegistry' | ||
import { KlerosRecipientRegistry as KlerosRecipientRegistryContract } from '../../generated/FundingRoundFactory/KlerosRecipientRegistry' | ||
|
||
export enum RecipientRegistryType { | ||
Simple = 0, | ||
Kleros, | ||
Optimistic, | ||
} | ||
|
||
/** | ||
* Determine the type of the registry given the registry address | ||
* Currently, we check for availability of a method to determine the type | ||
* | ||
* TODO: future recipient registry contract should have a type property | ||
* | ||
* @param registryAddress the recipient registry address | ||
* @returns RecipientRegistryType of Simple, Kleros, Optimistic | ||
*/ | ||
export function getRecipientRegistryType(registryAddress: Address): RecipientRegistryType { | ||
let klerosRegistry = KlerosRecipientRegistryContract.bind(registryAddress) | ||
let tcr = klerosRegistry.try_tcr() | ||
if( !tcr.reverted ) { | ||
return RecipientRegistryType.Kleros | ||
} | ||
|
||
let optimisticRegistry = OptimisticRecipientRegistryContract.bind(registryAddress) | ||
let challengePeriodDuration = optimisticRegistry.try_challengePeriodDuration() | ||
if( !challengePeriodDuration.reverted ) { | ||
return RecipientRegistryType.Optimistic | ||
} | ||
|
||
return RecipientRegistryType.Simple | ||
} |
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