Skip to content

Commit

Permalink
LPB event updates and remove RewardsManager (#67)
Browse files Browse the repository at this point in the history
* add base methods for lpb management

* reorg erc20 pool; abstract additional method

* cleanups & add approveTransferors to 721 pool

* rename LPAllowances to LPAllowanceList

* remove rewards manager

---------

Co-authored-by: Mike <[email protected]>
  • Loading branch information
MikeHathaway and Mike authored Sep 12, 2023
1 parent a37bdd6 commit 615d00b
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 614 deletions.
20 changes: 0 additions & 20 deletions networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
"address": "0x0000000000000000000000000000000000000000",
"startBlock": 17622995
},
"RewardsManager": {
"address": "0x0000000000000000000000000000000000000000",
"startBlock": 17622995
},
"GrantFund": {
"address": "0x0000000000000000000000000000000000000000",
"startBlock": 17622995
Expand All @@ -42,10 +38,6 @@
"address": "0x0000000000000000000000000000000000000000",
"startBlock": 46312499
},
"RewardsManager": {
"address": "0x0000000000000000000000000000000000000000",
"startBlock": 46312499
},
"GrantFund": {
"address": "0x0000000000000000000000000000000000000000",
"startBlock": 46312499
Expand All @@ -72,10 +64,6 @@
"address": "0x23E2EFF19bd50BfCF0364B7dCA01004D5cce41f9",
"startBlock": 9289397
},
"RewardsManager": {
"address": "0x994dE190dd763Af3126FcC8EdC139275937d800b",
"startBlock": 9289397
},
"GrantFund": {
"address": "0x881b4dFF6C72babA6f5eA60f34A61410c1EA1ec2",
"startBlock": 9297080
Expand All @@ -102,10 +90,6 @@
"address": "0x0000000000000000000000000000000000000000",
"startBlock": 38580888
},
"RewardsManager": {
"address": "0x0000000000000000000000000000000000000000",
"startBlock": 38580888
},
"GrantFund": {
"address": "0x0000000000000000000000000000000000000000",
"startBlock": 38580888
Expand All @@ -132,10 +116,6 @@
"address": "0x6548dF23A854f72335902e58a1e59B50bb3f11F1",
"startBlock": 0
},
"RewardsManager": {
"address": "0xdF7403003a16c49ebA5883bB5890d474794cea5a",
"startBlock": 0
},
"GrantFund": {
"address": "0x0b3A0ea1Fc7207d3e3ed9973025dA9d0e8fb0F3f",
"startBlock": 0
Expand Down
91 changes: 2 additions & 89 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,13 @@ type LPTransferorList @entity {

# represents a LP allowance for a single bucket
type LPAllowance @entity {
id: Bytes! # LPAllowances.id + '|' + $index
id: Bytes! # LPAllowanceList.id + '|' + $index
index: Int! # bucket index where an allowance has been granted
amount: BigDecimal! # size of the allowance (measured in LP)
}

# updated upon Increase/Decrease/RevokeLPAllowance
type LPAllowances @entity {
type LPAllowanceList @entity {
id: Bytes! # $poolAddress + '|' + $lender + '|' + $spender
pool: Pool! # pool in which LP allowances have been granted
lender: Bytes! # address of the lender who has granted an allowance
Expand Down Expand Up @@ -777,93 +777,6 @@ type RedeemPosition @entity(immutable: true) {
transactionHash: Bytes!
}

# # # # # # # # # # # # # # #
# REWARDS MANAGER ENTITIES #
# # # # # # # # # # # # # # #

type StakedPosition @entity {
id: Bytes! # byte encoded tokenId
position: Position! # pointer to associated Position entity
epochs: [EpochReward!]! # list of EpochRewards associated to a staked position
stakedEpoch: Int! # epoch in which the position was staked
lastClaimedEpoch: Int! # last epoch which the position staked or claimed rewards in
# lpAtStakeTime: BigDecimal! # the amount of LPB associated with a given index TODO: store information per index?
# rateAtStakeTime: BigDecimal! # the exchange rate at a given index at stake time
}

type EpochReward @entity {
id: Bytes! # byte encoded epoch + '|' + $StakedPosition.id
rewardsClaimed: BigDecimal! # ajna tokens claimed in this epoch
updateRewardsClaimed: BigDecimal!
totalRewardsClaimed: BigDecimal!
}

# TODO: is this entity necessary? if so referenced by index in stakedposition list
# house state tracking information about a staked position in a single bucket index
type StakedLiquidity @entity {
id: Bytes! # $lendId + '|' + $StakedPosition.id
lpAtStakeTime: BigDecimal! # the amount of LPB associated with a given index
rateAtStakeTime: BigDecimal! # the exchange rate at a given index at stake time
}

# # # # # # # # # # # # # #
# REWARDS MANAGER EVENTS #
# # # # # # # # # # # # # #

type ClaimRewards @entity(immutable: true) {
id: Bytes!
owner: Bytes! # address
pool: Pool!
tokenId: BigInt! # uint256
epochsClaimed: [BigInt!]! # uint256[]
amount: BigDecimal! # uint256
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}

type MoveStakedLiquidity @entity(immutable: true) {
id: Bytes!
tokenId: BigInt! # uint256
pool: Pool!
fromIndexes: [Int!]! # uint256
toIndexes: [Int!]! # uint256
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}

type Stake @entity(immutable: true) {
id: Bytes!
owner: Bytes! # address
pool: Pool!
tokenId: BigInt! # uint256
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}

type Unstake @entity(immutable: true) {
id: Bytes!
owner: Bytes! # address
pool: Pool!
tokenId: BigInt! # uint256
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}

type UpdateExchangeRates @entity(immutable: true) {
id: Bytes!
caller: Bytes! # address
pool: Pool!
indexesUpdated: [BigInt!]! # uint256[]
rewardsClaimed: BigInt! # uint256
blockNumber: BigInt!
blockTimestamp: BigInt!
transactionHash: Bytes!
}

# # # # # # # # # # # #
# GRANT FUND ENTITIES #
# # # # # # # # # # # #
Expand Down
74 changes: 74 additions & 0 deletions src/mappings/base/base-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import { incrementTokenTxCount as incrementTokenTxCountERC20Pool } from "../../u
import { incrementTokenTxCount as incrementTokenTxCountERC721Pool } from "../../utils/token-erc721"
import { loadOrCreateReserveAuction, reserveAuctionKickerReward } from "../../utils/pool/reserve-auction"
import { saveOrRemovePositionLend } from "../../utils/position"
import { decreaseAllowances, increaseAllowances, loadOrCreateAllowances, revokeAllowances } from "../../utils/pool/lp-allowances"
import { approveTransferors, loadOrCreateTransferors, revokeTransferors } from "../../utils/pool/lp-transferors"


/*******************************/
Expand Down Expand Up @@ -498,6 +500,78 @@ export function _handleTransferLP(erc20Event: TransferLPERC20Event | null, erc72
transferLP.save()
}

/*************************************/
/*** LPB Management Event Handlers ***/
/*************************************/

export function _handleApproveLPTransferors(event: ethereum.Event, lender: Address, transferors: Address[]): void {
const poolId = addressToBytes(event.address)
const entity = loadOrCreateTransferors(poolId, lender)
approveTransferors(entity, transferors)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
}

export function _handleDecreaseLPAllowance(event: ethereum.Event, spender: Address, indexes: BigInt[], amounts: BigInt[]): void {
const poolId = addressToBytes(event.address)
const lender = event.transaction.from
const entity = loadOrCreateAllowances(poolId, lender, spender)
decreaseAllowances(entity, indexes, amounts)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
}

export function _handleIncreaseLPAllowance(event: ethereum.Event, spender: Address, indexes: BigInt[], amounts: BigInt[]): void {
const poolId = addressToBytes(event.address)
const lender = event.transaction.from
const entity = loadOrCreateAllowances(poolId, lender, spender)
increaseAllowances(entity, indexes, amounts)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
}

export function _handleRevokeLPAllowance(event: ethereum.Event, spender: Address, indexes: BigInt[]): void {
const poolId = addressToBytes(event.address)
const lender = event.transaction.from
const entity = loadOrCreateAllowances(poolId, lender, spender)
revokeAllowances(entity, indexes)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
}

export function _handleRevokeLPTransferors(event: ethereum.Event, lender: Address, transferors: Address[]): void {
const poolId = addressToBytes(event.address)
const entity = loadOrCreateTransferors(poolId, lender)
revokeTransferors(entity, transferors)

const pool = Pool.load(poolId)!
pool.txCount = pool.txCount.plus(ONE_BI)

// save entities to the store
pool.save()
entity.save()
}

/*******************************/
/*** Reserves Event Handlers ***/
/*******************************/
Expand Down
Loading

0 comments on commit 615d00b

Please sign in to comment.