Skip to content

Instantly share code, notes, and snippets.

@Jannis
Created September 26, 2019 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jannis/938d0d23650e1631cab69ea722bc76a5 to your computer and use it in GitHub Desktop.
Save Jannis/938d0d23650e1631cab69ea722bc76a5 to your computer and use it in GitHub Desktop.
diff --git a/schema.graphql b/schema.graphql
index 2b16914..0cb8249 100644
--- a/schema.graphql
+++ b/schema.graphql
@@ -4,13 +4,12 @@ type CreatedToken @entity {
creator: ID!
timestamp: BigInt!
contractAddress: Bytes! # address
- synthetics: [Synthetic!]! @derivedFrom(field: "count")
+ synthetic: Synthetic
}
type Synthetic @entity {
id: ID!
- count: [CreatedToken]!
- # count: [CreatedToken!]! @derivedFrom(field: "contractAddress" )
+ token: CreatedToken! @derivedFrom(field: "synthetic")
creator: Bytes!
symbol: String! # string
newNav: BigInt! # int256
@@ -18,4 +17,4 @@ type Synthetic @entity {
timestamp: BigInt!
name: String! # string
totalSupply: BigDecimal!
-}
\ No newline at end of file
+}
diff --git a/src/mappingSynthetic.ts b/src/mappingSynthetic.ts
index eec553d..037f858 100644
--- a/src/mappingSynthetic.ts
+++ b/src/mappingSynthetic.ts
@@ -1,4 +1,4 @@
-import { BigInt, Address } from "@graphprotocol/graph-ts"
+import { BigInt, Address, log } from '@graphprotocol/graph-ts'
import {
Synthetic as SyntheticContract,
NavUpdated,
@@ -12,14 +12,9 @@ import {
Deposited,
Withdrawal,
Transfer,
- Approval
-} from "../generated/templates/Synthetic/Synthetic"
-import { Synthetic } from "../generated/schema"
-
-function getSyntheticContractInstance (address: Address):
-SyntheticContract {
- return SyntheticContract.bind(address)
-}
+ Approval,
+} from '../generated/templates/Synthetic/Synthetic'
+import { Synthetic } from '../generated/schema'
export function handleNavUpdated(event: NavUpdated): void {
// Entities can be loaded from the store using a string ID; this ID
@@ -35,14 +30,8 @@ export function handleNavUpdated(event: NavUpdated): void {
// entity.count = BigInt.fromI32(0)
// }
- let syntheticContract = getSyntheticContractInstance(event.address)
-
- let contractId = event.transaction.from.toHex()
- let entity = new Synthetic(syntheticContract._address.toHexString())
-
-
- // BigInt and BigDecimal math are supported
- // entity.count = entity.count.plus(BigInt.fromI32(1))
+ log.warning('Creating synthetic: {}', [event.address.toHex()])
+ let entity = new Synthetic(event.address.toHex())
// Entity fields can be set based on event parameters
entity.symbol = event.params.symbol
@@ -52,7 +41,7 @@ export function handleNavUpdated(event: NavUpdated): void {
entity.timestamp = event.block.timestamp
// Entities can be written to the store with `.save()`
- // let syntheticContract = getSyntheticContractInstance(event.address)
+ let syntheticContract = SyntheticContract.bind(event.address)
entity.name = syntheticContract.name()
entity.totalSupply = syntheticContract.totalSupply().toBigDecimal()
diff --git a/src/mappingTokenizedDerivativeCreator.ts b/src/mappingTokenizedDerivativeCreator.ts
index 52f09db..d5b33c0 100644
--- a/src/mappingTokenizedDerivativeCreator.ts
+++ b/src/mappingTokenizedDerivativeCreator.ts
@@ -1,12 +1,12 @@
-import { BigInt } from "@graphprotocol/graph-ts"
+import { BigInt, log } from '@graphprotocol/graph-ts'
import {
TokenizedDerivativeCreator,
- CreatedTokenizedDerivative as CreatedTokenizedDerivativeEvent
-} from "../generated/TokenizedDerivativeCreator/TokenizedDerivativeCreator"
+ CreatedTokenizedDerivative as CreatedTokenizedDerivativeEvent,
+} from '../generated/TokenizedDerivativeCreator/TokenizedDerivativeCreator'
-import { Synthetic } from "../generated/templates"
+import { Synthetic } from '../generated/templates'
-import { CreatedToken } from "../generated/schema"
+import { CreatedToken } from '../generated/schema'
export function handleCreatedTokenizedDerivative(
event: CreatedTokenizedDerivativeEvent
@@ -19,20 +19,14 @@ export function handleCreatedTokenizedDerivative(
// `null` checks allow to create entities on demand
// if (entity == null) {
- let contractId = event.transaction.hash.toHex()
- let entity = new CreatedToken(contractId)
-
- // Entity fields can be set using simple assignments
- entity.count = BigInt.fromI32(0)
- // }
-
- // BigInt and BigDecimal math are supported
- entity.count = entity.count.plus(BigInt.fromI32(1))
+ let entity = new CreatedToken(event.params.contractAddress.toHex())
// Entity fields can be set based on event parameters
entity.contractAddress = event.params.contractAddress
entity.creator = event.transaction.from.toHex()
entity.timestamp = event.block.timestamp
+ log.warning('Creating token with synthetic {}', [event.params.contractAddress.toHex()])
+ entity.synthetic = event.params.contractAddress.toHex()
// Entities can be written to the store with `.save()`
entity.save()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment