Skip to content

Commit

Permalink
tries configuering crowdsale instances as sg templates
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Adolf <[email protected]>
  • Loading branch information
elmariachi111 committed Dec 18, 2024
1 parent def2bed commit 1395968
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 47 deletions.
15 changes: 3 additions & 12 deletions subgraph/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
"address": "0x8cA737E2cdaE1Ceb332bEf7ba9eA711a3a2f8037",
"startBlock": 5300777
},
"StakedLockingCrowdSale": {
"address": "0xd1cE2EA7d3b0C9cAB025A4aD762FC00315141ad7",
"startBlock": 5300777
},

"TermsAcceptedPermissioner": {
"address": "0xC05D649368d8A5e2E98CAa205d47795de5fCB599",
"startBlock": 5300776
Expand All @@ -42,10 +39,7 @@
"address": "0xf0a8d23f38e9cbbe01c4ed37f23bd519b65bc6c2",
"startBlock": 18490640
},
"StakedLockingCrowdSale": {
"address": "0x35Bce29F52f51f547998717CD598068Afa2B29B7",
"startBlock": 17481804
},

"TermsAcceptedPermissioner": {
"address": "0xC837E02982992B701A1B5e4E21fA01cEB0a628fA",
"startBlock": 17790450
Expand All @@ -68,10 +62,7 @@
"address": "0x09635F643e140090A9A8Dcd712eD6285858ceBef",
"startBlock": 0
},
"StakedLockingCrowdSale": {
"address": "0x959922bE3CAee4b8Cd9a407cc3ac1C251C2007B1",
"startBlock": 0
},

"TermsAcceptedPermissioner": {
"address": "0x8A791620dd6260079BF849Dc5567aDC3F2FdC318",
"startBlock": 0
Expand Down
2 changes: 2 additions & 0 deletions subgraph/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ enum SaleState {

enum SaleType {
CROWDSALE
LOCKING_CROWDSALE
STAKED_LOCKING_CROWDSALE
}

Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions subgraph/src/crowdSaleMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export function handleStarted(event: StartedEvent): void {
return
}

if (event.receipt) {
crowdSale.contractInstance = changetype<string>(event.receipt.contractAddress)
}

crowdSale.ipt = ipt.id
crowdSale.issuer = event.params.issuer
crowdSale.feeBp = event.params.feeBp
Expand Down
19 changes: 18 additions & 1 deletion subgraph/src/stakedLockingCrowdSaleMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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
)
}
86 changes: 52 additions & 34 deletions subgraph/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 1395968

Please sign in to comment.