# PlanManager
# Overview
The Plan Manager Contract tracks and maintains all the Plans and PlanTemplates. It is the place Indexer create and publish a Plan for a specific deployment. And also the place Consumer can search and take these Plan.
# Terminology
Plan: Plan is created by an Indexer, a service agreement will be created once a consumer accept a plan. PlanTemplate: PlanTemplate is create and maintenance by owner, we provide a set of PlanTemplates for Indexer to create the Plan.
# STATES
# settings
ISettings contract which stores SubQuery network contracts address
contract ISettings settings
# limit
the limit of the plan that Indexer can create
uint256 limit
# nextTemplateId
The id for next plan template
uint256 nextTemplateId
# nextPlanId
The id for next plan, start from 1, PurchaseOfferMarket will use 0.
uint256 nextPlanId
# templates
TemplateId => Template
mapping(uint256 => struct PlanTemplate) templates
# plans
PlanId => Plan
mapping(uint256 => struct Plan) plans
# limits
indexer => deploymentId => already plan number
mapping(address => mapping(bytes32 => uint256)) limits
# v2templates
TemplateId => Template
mapping(uint256 => struct PlanTemplateV2) v2templates
# EVENTS
# PlanTemplateCreated
Emitted when owner create a PlanTemplate.
event PlanTemplateCreated(uint256 templateId)
# PlanTemplateMetadataChanged
Emitted when owner change the Metadata of a PlanTemplate.
event PlanTemplateMetadataChanged(uint256 templateId, bytes32 metadata)
# PlanTemplateStatusChanged
Emitted when owner change the status of a PlanTemplate. active or not
event PlanTemplateStatusChanged(uint256 templateId, bool active)
# PlanCreated
Emitted when Indexer create a Plan.
event PlanCreated(uint256 planId, address creator, bytes32 deploymentId, uint256 planTemplateId, uint256 price)
# PlanRemoved
Emitted when Indexer remove a Plan.
event PlanRemoved(uint256 planId)
# FUNCTIONS
# initialize
Initialize this contract to set the limit be 5 which any indexer can create 5 plans.
function initialize(contract ISettings _settings) external
# setSettings
Update setting state.
function setSettings(contract ISettings _settings) external
Name | Type | Description |
---|---|---|
_settings | contract ISettings | ISettings contract |
# setIndexerPlanLimit
Set the indexer plan limit.
function setIndexerPlanLimit(uint256 _limit) external
Name | Type | Description |
---|---|---|
_limit | uint256 | limit to set |
# createPlanTemplate
Allow admin to create a PlanTemplate.
function createPlanTemplate(uint256 period, uint256 dailyReqCap, uint256 rateLimit, address priceToken, bytes32 metadata) external
Name | Type | Description |
---|---|---|
period | uint256 | plan period |
dailyReqCap | uint256 | daily request limit |
rateLimit | uint256 | request rate limit |
priceToken | address | |
metadata | bytes32 | plan metadata |
# updatePlanTemplateMetadata
Allow admin to update the Metadata of a PlanTemplate.
function updatePlanTemplateMetadata(uint256 templateId, bytes32 metadata) external
Name | Type | Description |
---|---|---|
templateId | uint256 | plan template id |
metadata | bytes32 | metadata to update |
# updatePlanTemplateStatus
Allow Owner to update the status of a PlanTemplate.
function updatePlanTemplateStatus(uint256 templateId, bool active) external
Name | Type | Description |
---|---|---|
templateId | uint256 | plan template id |
active | bool | plan template active or not |
# createPlan
Allow Indexer to create a Plan basing on a specific plan template.
function createPlan(uint256 price, uint256 templateId, bytes32 deploymentId) external
Name | Type | Description |
---|---|---|
price | uint256 | plan price |
templateId | uint256 | plan template id |
deploymentId | bytes32 | project deployment Id on plan |
# removePlan
Allow Indexer to remove actived Plan.
function removePlan(uint256 planId) external
Name | Type | Description |
---|---|---|
planId | uint256 | Plan id to remove |
# acceptPlan
Allow Consumer to accept a plan created by an indexer. Consumer transfer token to ServiceAgreementRegistry contract and a service agreement will be created when they accept the plan.
function acceptPlan(uint256 planId, bytes32 deploymentId) external
Name | Type | Description |
---|---|---|
planId | uint256 | plan Id to accept |
deploymentId | bytes32 | project deployment Id |
# getPlan
Get a specific plan
function getPlan(uint256 planId) external view returns (struct Plan)
Name | Type | Description |
---|---|---|
planId | uint256 | plan id |
# getLimits
function getLimits(address indexer, bytes32 deploymentId) external view returns (uint256)
# getPlanTemplate
Get a specific plan templates
function getPlanTemplate(uint256 templateId) public view returns (struct PlanTemplateV2)
Name | Type | Description |
---|---|---|
templateId | uint256 | plan template id |