From 607a9c0a20d0063659a4dcc119e0676228a5f4b1 Mon Sep 17 00:00:00 2001 From: Stefan Adolf Date: Wed, 18 Dec 2024 18:55:27 +0100 Subject: [PATCH] tries configuering crowdsale instances as sg templates Signed-off-by: Stefan Adolf --- subgraph/networks.json | 15 +--- subgraph/schema.graphql | 2 + subgraph/src/crowdSaleMapping.ts | 4 + subgraph/src/stakedLockingCrowdSaleMapping.ts | 19 +++- subgraph/subgraph.yaml | 86 +++++++++++-------- 5 files changed, 79 insertions(+), 47 deletions(-) diff --git a/subgraph/networks.json b/subgraph/networks.json index edace0be..19438be0 100644 --- a/subgraph/networks.json +++ b/subgraph/networks.json @@ -16,10 +16,7 @@ "address": "0x8cA737E2cdaE1Ceb332bEf7ba9eA711a3a2f8037", "startBlock": 5300777 }, - "StakedLockingCrowdSale": { - "address": "0xd1cE2EA7d3b0C9cAB025A4aD762FC00315141ad7", - "startBlock": 5300777 - }, + "TermsAcceptedPermissioner": { "address": "0xC05D649368d8A5e2E98CAa205d47795de5fCB599", "startBlock": 5300776 @@ -42,10 +39,7 @@ "address": "0xf0a8d23f38e9cbbe01c4ed37f23bd519b65bc6c2", "startBlock": 18490640 }, - "StakedLockingCrowdSale": { - "address": "0x35Bce29F52f51f547998717CD598068Afa2B29B7", - "startBlock": 17481804 - }, + "TermsAcceptedPermissioner": { "address": "0xC837E02982992B701A1B5e4E21fA01cEB0a628fA", "startBlock": 17790450 @@ -68,10 +62,7 @@ "address": "0x09635F643e140090A9A8Dcd712eD6285858ceBef", "startBlock": 0 }, - "StakedLockingCrowdSale": { - "address": "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1", - "startBlock": 0 - }, + "TermsAcceptedPermissioner": { "address": "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318", "startBlock": 0 diff --git a/subgraph/schema.graphql b/subgraph/schema.graphql index 07965d53..b5c56eac 100644 --- a/subgraph/schema.graphql +++ b/subgraph/schema.graphql @@ -120,6 +120,7 @@ enum SaleState { enum SaleType { CROWDSALE + LOCKING_CROWDSALE STAKED_LOCKING_CROWDSALE } @@ -146,6 +147,7 @@ type CrowdSale @entity { contributions: [Contribution!] @derivedFrom(field: "crowdSale") feeBp: Int # the percentage fee that will be cut from the crowdsale upon its success type: SaleType! + contractInstance: ID # the address of the crowdsale contract } type Contribution @entity { diff --git a/subgraph/src/crowdSaleMapping.ts b/subgraph/src/crowdSaleMapping.ts index 0c5bdfcb..39c83c3c 100644 --- a/subgraph/src/crowdSaleMapping.ts +++ b/subgraph/src/crowdSaleMapping.ts @@ -25,6 +25,10 @@ export function handleStarted(event: StartedEvent): void { return } + if (event.receipt) { + crowdSale.contractInstance = changetype(event.receipt.contractAddress) + } + crowdSale.ipt = ipt.id crowdSale.issuer = event.params.issuer crowdSale.feeBp = event.params.feeBp diff --git a/subgraph/src/stakedLockingCrowdSaleMapping.ts b/subgraph/src/stakedLockingCrowdSaleMapping.ts index bb225e38..9c3fe608 100644 --- a/subgraph/src/stakedLockingCrowdSaleMapping.ts +++ b/subgraph/src/stakedLockingCrowdSaleMapping.ts @@ -28,7 +28,7 @@ import * as GenericCrowdSale from './genericCrowdSale' import { Contribution, CrowdSale, ERC20Token, IPT } from '../generated/schema' -import { TimelockedToken as TimelockedTokenTemplate } from '../generated/templates' +import { StakedLockingCrowdSale as StakedLockingCrowdSaleTemplate, TimelockedToken as TimelockedTokenTemplate } from '../generated/templates' import { makeERC20Token, makeTimelockedToken } from './common' export function handleStartedLegacy(event: LegacyStartedEvent): void { @@ -52,6 +52,10 @@ export function handleStartedLegacy(event: LegacyStartedEvent): void { } export function handleStarted(event: StartedEvent): void { + if (event.parameters.length < 8) { + return handleStartedLegacy(event) + } + const _plain = new PlainStartedEvent( event.address, event.logIndex, @@ -257,3 +261,16 @@ export function handleClaimedFailedSale( event.block.timestamp ) } + +export function initializeCrowdsaleTemplatesOnce(block: ethereum.Block): void { + + StakedLockingCrowdSaleTemplate.create(block.) + + let context = new DataSourceContext() + context.setBytes('ipt', Bytes.fromHexString('0x')) + context.setBytes('lockingContract', Bytes.fromHexString('0x')) + TimelockedTokenTemplate.createWithContext( + Bytes.fromHexString('0x'), + context + ) +} \ No newline at end of file diff --git a/subgraph/subgraph.yaml b/subgraph/subgraph.yaml index cbb27727..e909e3bb 100644 --- a/subgraph/subgraph.yaml +++ b/subgraph/subgraph.yaml @@ -119,52 +119,25 @@ dataSources: - event: ClaimedAuctionTokens(indexed uint256) handler: handleClaimedFailedSale file: ./src/crowdSaleMapping.ts + - kind: ethereum/contract - name: StakedLockingCrowdSale + name: InitializeCrowdsaleContracts network: foundry source: abi: StakedLockingCrowdSale - address: "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1" startBlock: 0 mapping: kind: ethereum/events apiVersion: 0.0.7 language: wasm/assemblyscript - entities: - - CrowdSale - - Contribution - - ERC20Token + file: ./src/stakedLockingCrowdSaleMapping.ts abis: - name: StakedLockingCrowdSale file: ./abis/StakedLockingCrowdSale.json - - name: IERC20Metadata - file: ./abis/IERC20Metadata.json - eventHandlers: - - event: Started(indexed uint256,indexed - address,(address,address,address,uint256,uint256,uint64,address),(address,address,uint256),address,uint256,uint256) - handler: handleStartedLegacy - - event: Started(indexed uint256,indexed - address,(address,address,address,uint256,uint256,uint64,address),(address,address,uint256),address,uint256,uint256,uint16) - handler: handleStarted - - event: Settled(indexed uint256,uint256,uint256) - handler: handleSettled - - event: Failed(indexed uint256) - handler: handleFailed - - event: Bid(indexed uint256,indexed address,uint256) - handler: handleBid - - event: Staked(indexed uint256,indexed address,uint256,uint256) - handler: handleStaked - - event: Claimed(indexed uint256,indexed address,uint256,uint256) - handler: handleClaimed - - event: ClaimedStakes(indexed uint256,indexed address,uint256,uint256) - handler: handleClaimedStakes - - event: LockingContractCreated(indexed address,indexed address) - handler: handleLockingContractCreated - - event: ClaimedFundingGoal(indexed uint256) - handler: handleClaimedSuccessfulSale - - event: ClaimedAuctionTokens(indexed uint256) - handler: handleClaimedFailedSale - file: ./src/stakedLockingCrowdSaleMapping.ts + blockHandlers: + - handler: initializeCrowdsaleTemplatesOnce + filter: + kind: once - kind: ethereum/contract name: TermsAcceptedPermissioner network: foundry @@ -228,6 +201,51 @@ templates: handler: handleScheduled - event: ScheduleReleased(indexed bytes32,indexed address,uint256) handler: handleReleased + - name: StakedLockingCrowdSale + kind: ethereum/contract + network: foundry + source: + abi: StakedLockingCrowdSale + mapping: + kind: ethereum/events + apiVersion: 0.0.7 + language: wasm/assemblyscript + file: ./src/stakedLockingCrowdSaleMapping.ts + entities: + - TimelockedToken + - CrowdSale + - Contribution + - ERC20Token + abis: + - name: StakedLockingCrowdSale + file: ./abis/StakedLockingCrowdSale.json + - name: IERC20Metadata + file: ./abis/IERC20Metadata.json + eventHandlers: + - event: Started(indexed uint256,indexed + address,(address,address,address,uint256,uint256,uint64,address),(address,address,uint256),address,uint256,uint256) + handler: handleStartedLegacy + - event: Started(indexed uint256,indexed + address,(address,address,address,uint256,uint256,uint64,address),(address,address,uint256),address,uint256,uint256,uint16) + handler: handleStarted + - event: Settled(indexed uint256,uint256,uint256) + handler: handleSettled + - event: Failed(indexed uint256) + handler: handleFailed + - event: Bid(indexed uint256,indexed address,uint256) + handler: handleBid + - event: Staked(indexed uint256,indexed address,uint256,uint256) + handler: handleStaked + - event: Claimed(indexed uint256,indexed address,uint256,uint256) + handler: handleClaimed + - event: ClaimedStakes(indexed uint256,indexed address,uint256,uint256) + handler: handleClaimedStakes + - event: LockingContractCreated(indexed address,indexed address) + handler: handleLockingContractCreated + - event: ClaimedFundingGoal(indexed uint256) + handler: handleClaimedSuccessfulSale + - event: ClaimedAuctionTokens(indexed uint256) + handler: handleClaimedFailedSale - name: IpnftMetadata kind: file/ipfs mapping: