-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: deploy both GLM and GNT for subgraph, automate networks.json
For testnet and mainnet tokens are not deployed. Tests care only about GLM. Subgraph assumes existance of two tokens - this is why both are deployed for 'token' tag, effectively for 'hardhat' and 'localhost' networks. Please note that src/*.ts files stays, since lots of execution paths (linters etc) check if this files are there
- Loading branch information
Pawel Peregud
committed
Aug 23, 2023
1 parent
46753a4
commit bfda4a0
Showing
10 changed files
with
245 additions
and
42 deletions.
There are no files selected for viewing
11 changes: 10 additions & 1 deletion
11
contracts-v1/deploy/0010_deploy_token.ts → contracts-v1/deploy/0010_deploy_tokens.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
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
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
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
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 |
---|---|---|
@@ -1,30 +1,43 @@ | ||
{ | ||
"sepolia": { | ||
"Deposits": { | ||
"address": "0x044465B505aeE0B790b180750E263e3F83a682e8", | ||
"startBlock": 3771656 | ||
}, | ||
"Epochs": { | ||
"address": "0x86A032e5e5bEaaEB8eb0F625bEB5426D8B526719", | ||
"startBlock": 3771656 | ||
}, | ||
"Vault": { | ||
"address": "0xd3C9777a8cafE46583B5425C10196503c4428ddC", | ||
"startBlock": 3771656 | ||
} | ||
}, | ||
"localhost": { | ||
"Deposits": { | ||
"address": "0x044465B505aeE0B790b180750E263e3F83a682e8", | ||
"startBlock": 3771656 | ||
}, | ||
"Epochs": { | ||
"address": "0x86A032e5e5bEaaEB8eb0F625bEB5426D8B526719", | ||
"startBlock": 3771656 | ||
}, | ||
"Vault": { | ||
"address": "0xd3C9777a8cafE46583B5425C10196503c4428ddC", | ||
"startBlock": 3771656 | ||
} | ||
} | ||
"localhost" : { | ||
"Deposits" : { | ||
"address" : "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9" | ||
}, | ||
"Epochs" : { | ||
"address" : "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0" | ||
}, | ||
"GLM" : { | ||
"address" : "0x7DD9c5Cba05E151C895FDe1CF355C9A1D5DA6429" | ||
}, | ||
"GNT" : { | ||
"address" : "0xa74476443119A942dE498590Fe1f2454d7D4aC0d" | ||
}, | ||
"Vault" : { | ||
"address" : "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853" | ||
} | ||
}, | ||
"mainnet" : { | ||
"GLM" : { | ||
"address" : "0x7DD9c5Cba05E151C895FDe1CF355C9A1D5DA6429" | ||
}, | ||
"GNT" : { | ||
"address" : "0xa74476443119A942dE498590Fe1f2454d7D4aC0d" | ||
} | ||
}, | ||
"sepolia" : { | ||
"Deposits" : { | ||
"address" : "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9", | ||
"startBlock" : 8415400 | ||
}, | ||
"Epochs" : { | ||
"address" : "0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0", | ||
"startBlock" : 8415400 | ||
}, | ||
"GLM" : { | ||
"address" : "0x71432DD1ae7DB41706ee6a22148446087BdD0906" | ||
}, | ||
"GNT" : { | ||
"address" : "0xE6de13D64F6036E4E3f5fC84B5EB620C5C7c1050" | ||
} | ||
} | ||
} |
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,85 @@ | ||
import { Address, BigInt, BigDecimal } from '@graphprotocol/graph-ts'; | ||
|
||
import { Locked as LockedEvent, Unlocked as UnlockedEvent } from '../generated/Deposits/Deposits'; | ||
import { ERC20 } from '../generated/Deposits/ERC20'; | ||
import { Locked, Unlocked, LockedSummaryLatest, LockedSummarySnapshot } from '../generated/schema'; | ||
|
||
export function addLockedSummary<T>(event: T): void { | ||
const burnAddress = Address.fromString('0x0000000000000000000000000000000000000000'); | ||
|
||
// Load GLM and GNT contracts | ||
// eslint-disable-next-line no-template-curly-in-string | ||
const glmContract = ERC20.bind(Address.fromString('${GLM_CONTRACT_ADDRESS}')); | ||
// eslint-disable-next-line no-template-curly-in-string | ||
const gntContract = ERC20.bind(Address.fromString('${GNT_CONTRACT_ADDRESS}')); | ||
// Calculate current total supply | ||
const glmSupply = glmContract.totalSupply().minus(glmContract.balanceOf(burnAddress)); | ||
const gntSupply = gntContract.totalSupply().minus(gntContract.balanceOf(burnAddress)); | ||
const totalSupply = glmSupply.plus(gntSupply); | ||
|
||
// Load latest locked summary | ||
let latestLockedSummary = LockedSummaryLatest.load('latest'); | ||
if (latestLockedSummary == null) { | ||
latestLockedSummary = new LockedSummaryLatest('latest'); | ||
latestLockedSummary.lockedTotal = BigInt.fromI32(0); | ||
latestLockedSummary.lockedRatio = BigDecimal.fromString('0'); | ||
} | ||
|
||
// Calculate total locked and locked ratio | ||
let lockedTotal: BigInt; | ||
if (event instanceof LockedEvent) { | ||
lockedTotal = latestLockedSummary.lockedTotal.plus(event.params.amount); | ||
} else if (event instanceof UnlockedEvent) { | ||
lockedTotal = latestLockedSummary.lockedTotal.minus(event.params.amount); | ||
} else { | ||
throw new Error('event must be of LockedEvent or UnlockEvent type'); | ||
} | ||
const lockedRatio = lockedTotal.divDecimal(totalSupply.toBigDecimal()); | ||
|
||
// Save LockedSummaryLatest | ||
latestLockedSummary.lockedTotal = lockedTotal; | ||
latestLockedSummary.lockedRatio = lockedRatio; | ||
latestLockedSummary.glmSupply = totalSupply; | ||
latestLockedSummary.blockNumber = event.block.number.toI32(); | ||
latestLockedSummary.transactionHash = event.transaction.hash; | ||
latestLockedSummary.timestamp = event.block.timestamp.toI32(); | ||
latestLockedSummary.save(); | ||
|
||
// Save LockedSummarySnapshot | ||
const lockedSummarySnapshot = new LockedSummarySnapshot( | ||
event.transaction.hash.concatI32(event.logIndex.toI32()), | ||
); | ||
lockedSummarySnapshot.lockedTotal = lockedTotal; | ||
lockedSummarySnapshot.lockedRatio = lockedRatio; | ||
lockedSummarySnapshot.glmSupply = totalSupply; | ||
lockedSummarySnapshot.blockNumber = event.block.number.toI32(); | ||
lockedSummarySnapshot.transactionHash = event.transaction.hash; | ||
lockedSummarySnapshot.timestamp = event.block.timestamp.toI32(); | ||
lockedSummarySnapshot.save(); | ||
} | ||
|
||
export function handleLocked(event: LockedEvent): void { | ||
const lockedEntity = new Locked(event.transaction.hash.concatI32(event.logIndex.toI32())); | ||
lockedEntity.depositBefore = event.params.depositBefore; | ||
lockedEntity.amount = event.params.amount; | ||
lockedEntity.user = event.params.user; | ||
lockedEntity.blockNumber = event.block.number.toI32(); | ||
lockedEntity.transactionHash = event.transaction.hash; | ||
lockedEntity.timestamp = event.block.timestamp.toI32(); | ||
lockedEntity.save(); | ||
|
||
addLockedSummary(event); | ||
} | ||
|
||
export function handleUnlocked(event: UnlockedEvent): void { | ||
const unlockedEntity = new Unlocked(event.transaction.hash.concatI32(event.logIndex.toI32())); | ||
unlockedEntity.depositBefore = event.params.depositBefore; | ||
unlockedEntity.amount = event.params.amount; | ||
unlockedEntity.user = event.params.user; | ||
unlockedEntity.blockNumber = event.block.number.toI32(); | ||
unlockedEntity.transactionHash = event.transaction.hash; | ||
unlockedEntity.timestamp = event.block.timestamp.toI32(); | ||
unlockedEntity.save(); | ||
|
||
addLockedSummary(event); | ||
} |
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
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,35 @@ | ||
import { Address, ethereum, log, Bytes } from '@graphprotocol/graph-ts'; | ||
|
||
import { Epochs } from '../generated/Epochs/Epochs'; | ||
import { Epoch } from '../generated/schema'; | ||
|
||
export function handleBlock(block: ethereum.Block): void { | ||
const epochsContract = Epochs.bind( | ||
// eslint-disable-next-line no-template-curly-in-string | ||
Address.fromString('${EPOCHS_CONTRACT_ADDRESS}'), | ||
); | ||
const currentEpoch = epochsContract.try_getCurrentEpoch(); | ||
if (currentEpoch.reverted) { | ||
log.info('Call to getCurrentEpoch() reverted!', []); | ||
return; | ||
} | ||
|
||
const epochNo = currentEpoch.value.toI32(); | ||
let epoch = Epoch.load(Bytes.fromI32(epochNo)); | ||
if (epoch == null) { | ||
epoch = new Epoch(Bytes.fromI32(epochNo)); | ||
|
||
const decisionWindow = epochsContract.getDecisionWindow(); | ||
const duration = epochsContract.getEpochDuration(); | ||
const epochEnd = epochsContract.getCurrentEpochEnd(); | ||
const epochStart = epochEnd.minus(duration); | ||
|
||
epoch.epoch = epochNo; | ||
epoch.fromTs = epochStart; | ||
epoch.toTs = epochEnd; | ||
epoch.duration = duration; | ||
epoch.decisionWindow = decisionWindow; | ||
|
||
epoch.save(); | ||
} | ||
} |
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
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,17 @@ | ||
import { Withdrawal } from '../generated/schema'; | ||
import { Withdrawn } from '../generated/Vault/Vault'; | ||
|
||
export function handleWithdrawn(event: Withdrawn): void { | ||
const id = event.transaction.hash.concatI32(event.logIndex.toI32()); | ||
const entity = new Withdrawal(id); | ||
|
||
entity.amount = event.params.amount; | ||
entity.user = event.params.user; | ||
entity.epoch = event.params.epoch.toI32(); | ||
|
||
entity.blockNumber = event.block.number.toI32(); | ||
entity.transactionHash = event.transaction.hash; | ||
entity.timestamp = event.block.timestamp.toI32(); | ||
|
||
entity.save(); | ||
} |