Skip to content

Commit

Permalink
feat: deploy to production and move out osgno and deposit events
Browse files Browse the repository at this point in the history
  • Loading branch information
Wagalidoom committed Sep 10, 2024
1 parent 1bf2d52 commit 8705829
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 72 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"doall": "yarn clean && yarn codegen && yarn build && yarn build:gc",
"deploy": "graph deploy --studio gno-vote-weight---ethereum",
"deploy:gc": "graph deploy --studio gno-vote-weight---gc -o build-gc subgraph-gnosis-chain.yaml",
"deployProd": "graph deploy --studio gno-vote-weight-ethereum",
"deployProd:gc": "graph deploy --studio gno-vote-weight-gc -o build-gc subgraph-gnosis-chain.yaml",
"test": "graph test"
},
"dependencies": {
Expand Down
21 changes: 11 additions & 10 deletions src/deposit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@ import { loadOrCreate as loadOrCreateUser } from "./helpers/user";
import { ONE_GNO } from "./constants";
import { Address, Bytes } from "@graphprotocol/graph-ts";

// HANDLE FOR DEPOSIT, NEED FURTHER TESTS
export function handleDeposit(event: DepositEvent): void {
const withdrawalCredentials = event.params.withdrawal_credentials;
// const withdrawalCredentials = event.params.withdrawal_credentials;

if (withdrawalCredentials.length != 32) {
return;
}
// if (withdrawalCredentials.length != 32) {
// return;
// }

const addressBytes = withdrawalCredentials.subarray(12, 32);
const userAddress = Address.fromBytes(Bytes.fromUint8Array(addressBytes));
// const addressBytes = withdrawalCredentials.subarray(12, 32);
// const userAddress = Address.fromBytes(Bytes.fromUint8Array(addressBytes));

const entry = loadOrCreateUser(userAddress);
entry.deposit = entry.deposit.plus(ONE_GNO);
entry.voteWeight = entry.voteWeight.plus(ONE_GNO);
entry.save();
// const entry = loadOrCreateUser(userAddress);
// entry.deposit = entry.deposit.plus(ONE_GNO);
// entry.voteWeight = entry.voteWeight.plus(ONE_GNO);
// entry.save();
}
34 changes: 18 additions & 16 deletions src/gno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,27 @@ export function handleTransfer(event: Transfer): void {
saveOrRemoveUser(userFrom);
}

// HANDLE FOR DEPOSIT WITHDRAWAL CLAIM, NEED FURTHER TESTS

// Decreasing deposit balance to prevent untracked withdrawal from deposit contract
// Temporary solution as this approach does not fully account for rewards generated by the validator
if (from.toHexString() == DEPOSIT_ADDRESS.toHexString()) {
const userTo = loadOrCreateUser(to);
// if (from.toHexString() == DEPOSIT_ADDRESS.toHexString()) {
// const userTo = loadOrCreateUser(to);

if (userTo.deposit > ZERO_BI) {
// To avoid a negative result that could throw an error
if (userTo.deposit <= event.params.value) {
userTo.voteWeight = userTo.voteWeight.minus(userTo.deposit);
userTo.voteWeight = userTo.voteWeight.plus(event.params.value);
userTo.deposit = ZERO_BI;
} else {
userTo.voteWeight = userTo.voteWeight.minus(event.params.value);
userTo.deposit = userTo.deposit.minus(event.params.value);
}
userTo.gno = userTo.gno.plus(event.params.value);
saveOrRemoveUser(userTo);
}
}
// if (userTo.deposit > ZERO_BI) {
// // To avoid a negative result that could throw an error
// if (userTo.deposit <= event.params.value) {
// userTo.voteWeight = userTo.voteWeight.minus(userTo.deposit);
// userTo.voteWeight = userTo.voteWeight.plus(event.params.value);
// userTo.deposit = ZERO_BI;
// } else {
// userTo.voteWeight = userTo.voteWeight.minus(event.params.value);
// userTo.deposit = userTo.deposit.minus(event.params.value);
// }
// userTo.gno = userTo.gno.plus(event.params.value);
// saveOrRemoveUser(userTo);
// }
// }


if (to.toHexString() != ADDRESS_ZERO.toHexString()) {
Expand Down
41 changes: 21 additions & 20 deletions src/osgno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@ import { VaultState } from "../generated/schema";
import { BigInt } from "@graphprotocol/graph-ts";
import { loadOrCreateVault } from "./helpers/osgnoVault";

// HANDLE FOR OSGNO, NEED FURTHER TESTS
export function handleTransfer(event: Transfer): void {
const to = event.params.to;
const from = event.params.from;
// const to = event.params.to;
// const from = event.params.from;

if (from.toHexString() != ADDRESS_ZERO.toHexString()) {
const userFrom = loadOrCreateUser(from);
userFrom.osgnoShare = userFrom.osgnoShare.minus(event.params.value);
const newAsset = convertToAssets(userFrom.osgnoShare, event.block.timestamp);
userFrom.voteWeight = userFrom.voteWeight.plus(userFrom.osgnoAsset);
userFrom.osgnoAsset = newAsset;
userFrom.voteWeight = userFrom.voteWeight.minus(userFrom.osgnoAsset);
saveOrRemoveUser(userFrom);
}
// if (from.toHexString() != ADDRESS_ZERO.toHexString()) {
// const userFrom = loadOrCreateUser(from);
// userFrom.osgnoShare = userFrom.osgnoShare.minus(event.params.value);
// const newAsset = convertToAssets(userFrom.osgnoShare, event.block.timestamp);
// userFrom.voteWeight = userFrom.voteWeight.plus(userFrom.osgnoAsset);
// userFrom.osgnoAsset = newAsset;
// userFrom.voteWeight = userFrom.voteWeight.minus(userFrom.osgnoAsset);
// saveOrRemoveUser(userFrom);
// }

if (to.toHexString() != ADDRESS_ZERO.toHexString()) {
const userTo = loadOrCreateUser(to);
userTo.osgnoShare = userTo.osgnoShare.plus(event.params.value);
const newAsset = convertToAssets(userTo.osgnoShare, event.block.timestamp);
userTo.voteWeight = userTo.voteWeight.minus(userTo.osgnoAsset);
userTo.osgnoAsset = newAsset;
userTo.voteWeight = userTo.voteWeight.plus(userTo.osgnoAsset);
userTo.save();
}
// if (to.toHexString() != ADDRESS_ZERO.toHexString()) {
// const userTo = loadOrCreateUser(to);
// userTo.osgnoShare = userTo.osgnoShare.plus(event.params.value);
// const newAsset = convertToAssets(userTo.osgnoShare, event.block.timestamp);
// userTo.voteWeight = userTo.voteWeight.minus(userTo.osgnoAsset);
// userTo.osgnoAsset = newAsset;
// userTo.voteWeight = userTo.voteWeight.plus(userTo.osgnoAsset);
// userTo.save();
// }
}

function convertToAssets(shares: BigInt, timestamp: BigInt): BigInt {
Expand Down
53 changes: 27 additions & 26 deletions src/osgnoVault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,49 @@ import {
} from "./helpers/user";
import { loadOrCreateVault } from "./helpers/osgnoVault";

// HANDLE FOR OSGNO VAULT, NEED FURTHER TESTS
export function handleBurn(event: Burn): void {
const owner = loadOrCreateUser(event.params.owner);
owner.osgnoShare = owner.osgnoShare.minus(event.params.shares);
owner.osgnoAsset = owner.osgnoAsset.minus(event.params.assets);
owner.voteWeight = owner.voteWeight.minus(event.params.assets);
saveOrRemoveUser(owner);
// const owner = loadOrCreateUser(event.params.owner);
// owner.osgnoShare = owner.osgnoShare.minus(event.params.shares);
// owner.osgnoAsset = owner.osgnoAsset.minus(event.params.assets);
// owner.voteWeight = owner.voteWeight.minus(event.params.assets);
// saveOrRemoveUser(owner);
}

export function handleMint(event: Mint): void {
const receiver = loadOrCreateUser(event.params.receiver);
receiver.osgnoShare = receiver.osgnoShare.plus(event.params.shares);
receiver.osgnoAsset = receiver.osgnoAsset.plus(event.params.assets);
receiver.voteWeight = receiver.voteWeight.plus(event.params.assets);
saveOrRemoveUser(receiver);
// const receiver = loadOrCreateUser(event.params.receiver);
// receiver.osgnoShare = receiver.osgnoShare.plus(event.params.shares);
// receiver.osgnoAsset = receiver.osgnoAsset.plus(event.params.assets);
// receiver.voteWeight = receiver.voteWeight.plus(event.params.assets);
// saveOrRemoveUser(receiver);
}

export function handleStateUpdated(event: StateUpdated): void {
let vaultState = loadOrCreateVault();
// let vaultState = loadOrCreateVault();

const profitAccrued = event.params.profitAccrued;
const treasuryShares = event.params.treasuryShares;
const treasuryAssets = event.params.treasuryAssets;
// const profitAccrued = event.params.profitAccrued;
// const treasuryShares = event.params.treasuryShares;
// const treasuryAssets = event.params.treasuryAssets;

const newTotalAssets = vaultState._totalAssets.plus(profitAccrued);
// const newTotalAssets = vaultState._totalAssets.plus(profitAccrued);

vaultState.profitAccrued = profitAccrued;
vaultState._totalAssets = newTotalAssets;
vaultState._totalShares = vaultState._totalShares.plus(treasuryShares);
vaultState.lastUpdatedTimeStamp = event.block.timestamp;
// vaultState.profitAccrued = profitAccrued;
// vaultState._totalAssets = newTotalAssets;
// vaultState._totalShares = vaultState._totalShares.plus(treasuryShares);
// vaultState.lastUpdatedTimeStamp = event.block.timestamp;

vaultState.save();
// vaultState.save();
}


export function handleAvgRewardPerSecondUpdated(event: AvgRewardPerSecondUpdated): void {
let vaultState = loadOrCreateVault();
vaultState.avgRewardPerSecond = event.params.avgRewardPerSecond;
vaultState.save();
// let vaultState = loadOrCreateVault();
// vaultState.avgRewardPerSecond = event.params.avgRewardPerSecond;
// vaultState.save();
}

export function handleFeePercentUpdated(event: FeePercentUpdated): void {
let vaultState = loadOrCreateVault();
vaultState.feePercent = event.params.feePercent;
vaultState.save();
// let vaultState = loadOrCreateVault();
// vaultState.feePercent = event.params.feePercent;
// vaultState.save();
}

0 comments on commit 8705829

Please sign in to comment.