Skip to content

Commit

Permalink
remove momp from pool; add referencePrice to liquidationAuction; remo…
Browse files Browse the repository at this point in the history
…ve kickMomp and kickerAward
  • Loading branch information
Mike committed Oct 17, 2023
1 parent 5a5c222 commit 468b4ac
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 62 deletions.
4 changes: 1 addition & 3 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ type Pool @entity {
htpIndex: Int! # current highest threshold price index
lup: BigDecimal! # current lowest utilized price
lupIndex: Int! # current lowest utilized price index
momp: BigDecimal! # most optimistic matching price

# RESERVES INFORMATION
# current reserves contractQuoteBalance + poolDebt - pool.depositSize()
Expand Down Expand Up @@ -264,6 +263,7 @@ type LiquidationAuction @entity {
bondSize: BigDecimal! # bond provided by kicker to initate auction
bondFactor: BigDecimal! # bond factor determining the reward or penalty for the kicker
neutralPrice: BigDecimal! # price at which kicker will have their bond returned without penalty or reward
referencePrice: BigDecimal! # max(HTP, NP) used in auction price curve
}

# tracks the reserve auction process across multiple takes in a single auction
Expand Down Expand Up @@ -420,7 +420,6 @@ type Flashloan @entity(immutable: true) {
type Kick @entity {
id: Bytes!
kicker: Bytes! # address of the kicker
kickMomp: BigDecimal! # pool MOMP at the time of kicking
pool: Pool! # Pool in which a kick occurred
loan: Loan! # Loan which was kicked
locked: BigDecimal! # amount of quote from the bond locked in the kick (updated on take) TODO: rename bondLocked
Expand Down Expand Up @@ -503,7 +502,6 @@ type RepayDebt @entity(immutable: true) {
type ReserveAuctionKick @entity(immutable: true) {
id: Bytes! # transaction.hash + transaction.from
kicker: Bytes # address of the taker, null if emitted as start of event
kickerAward: BigDecimal! # amount of quote rewarded to kicker for starting reserves auction
reserveAuction: ReserveAuction! # reserve auction in which the take is occuring
pool: Pool! # pool in which the auction was kicked
claimableReserves: BigDecimal! # uint256 initial amount of claimable reserves in the auction
Expand Down
1 change: 0 additions & 1 deletion src/mappings/base/base-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ export function _handleReserveAuctionKick(event: ethereum.Event, currentBurnEpoc
updatePool(pool)
addReserveAuctionToPool(pool, reserveAuction)
pool.txCount = pool.txCount.plus(ONE_BI)
reserveKick.kickerAward = reserveAuctionKickerReward(pool)

// update account state
const account = loadOrCreateAccount(addressToBytes(event.transaction.from))
Expand Down
1 change: 0 additions & 1 deletion src/mappings/erc-20-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ export function handleKick(event: KickEvent): void {
const auction = loadOrCreateLiquidationAuction(pool.id, auctionId, kick, loan)
updateLiquidationAuction(auction, auctionInfo, auctionStatus)

kick.kickMomp = wadToDecimal(auctionInfo.kickMomp)
kick.startingPrice = wadToDecimal(auctionStatus.price)
kick.pool = pool.id
kick.loan = loan.id
Expand Down
1 change: 0 additions & 1 deletion src/mappings/erc-721-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,6 @@ export function handleKick(event: KickEvent): void {
const auction = loadOrCreateLiquidationAuction(pool.id, auctionId, kick, loan)
updateLiquidationAuction(auction, auctionInfo, auctionStatus)

kick.kickMomp = wadToDecimal(auctionInfo.kickMomp)
kick.startingPrice = wadToDecimal(auctionStatus.price)
kick.pool = pool.id
kick.loan = loan.id
Expand Down
9 changes: 5 additions & 4 deletions src/utils/pool/liquidation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Address, BigDecimal, BigInt, Bytes, Value, dataSource } from "@graphprotocol/graph-ts"

import { LiquidationAuction, Kick, Loan, Pool, BucketTake } from "../../../generated/schema"
import { LiquidationAuction, Kick, Loan, Pool, BucketTake } from '../../../generated/schema';
import { ERC20Pool } from '../../../generated/templates/ERC20Pool/ERC20Pool'
import { ERC721Pool } from "../../../generated/templates/ERC721Pool/ERC721Pool"
import { PoolInfoUtils } from "../../../generated/templates/ERC20Pool/PoolInfoUtils"
Expand Down Expand Up @@ -81,6 +81,7 @@ export function updateLiquidationAuction(
liquidationAuction.bondSize = wadToDecimal(auctionInfo.bondSize)
liquidationAuction.kickTime = auctionInfo.kickTime
liquidationAuction.neutralPrice = wadToDecimal(auctionInfo.neutralPrice)
liquidationAuction.referencePrice = wadToDecimal(auctionInfo.referencePrice)
}

// update remaining quantities even if auction was settled and they are 0
Expand All @@ -96,18 +97,18 @@ export class AuctionInfo {
bondFactor: BigInt
bondSize: BigInt
kickTime: BigInt
kickMomp: BigInt
referencePrice: BigInt
neutralPrice: BigInt
head: Address
next: Address
prev: Address
alreadyTaken: bool
constructor(kicker: Address, bondFactor: BigInt, bondSize: BigInt, kickTime: BigInt, kickMomp: BigInt, neutralPrice: BigInt, head: Address, next: Address, prev: Address, alreadyTaken: bool) {
constructor(kicker: Address, bondFactor: BigInt, bondSize: BigInt, kickTime: BigInt, referencePrice: BigInt, neutralPrice: BigInt, head: Address, next: Address, prev: Address, alreadyTaken: bool) {
this.kicker = kicker
this.bondFactor = bondFactor
this.bondSize = bondSize
this.kickTime = kickTime
this.kickMomp = kickMomp
this.referencePrice = referencePrice
this.neutralPrice = neutralPrice
this.head = head
this.next = next
Expand Down
10 changes: 0 additions & 10 deletions src/utils/pool/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ export function getLenderInfoERC721Pool(poolId: Bytes, bucketIndex: BigInt, lend
)
}

// retrieve the current pool MOMP by calling PoolInfoUtils.momp()
export function getMomp(poolId: Bytes): BigDecimal {
const poolInfoUtilsAddress = poolInfoUtilsAddressTable.get(dataSource.network())!
const poolInfoUtilsContract = PoolInfoUtils.bind(poolInfoUtilsAddress)
const pool = Pool.load(poolId)
return wadToDecimal(poolInfoUtilsContract.momp(Address.fromBytes(poolId)))
}

export class RatesAndFees {
lenderInterestMargin: BigInt
borrowFeeRate: BigInt
Expand Down Expand Up @@ -239,7 +231,6 @@ export function updatePool(pool: Pool): void {
pool.htpIndex = poolPricesInfo.htpIndex.toU32()
pool.lup = wadToDecimal(poolPricesInfo.lup)
pool.lupIndex = poolPricesInfo.lupIndex.toU32()
pool.momp = getMomp(pool.id)

// update reserve auction information
const poolReservesInfo = getPoolReservesInfo(pool)
Expand Down Expand Up @@ -440,7 +431,6 @@ export function loadOrCreatePool(id: Bytes): Pool {
pool.htpIndex = 0
pool.lup = MAX_PRICE
pool.lupIndex = MAX_PRICE_INDEX
pool.momp = ZERO_BD

// reserve auction information
pool.reserves = ZERO_BD
Expand Down
30 changes: 10 additions & 20 deletions tests/erc-20-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ describe("ERC20Pool assertions", () => {
htpIndex: ZERO_BI,
lup: MAX_PRICE_BI,
lupIndex: BigInt.fromU32(MAX_PRICE_INDEX),
momp: BigInt.fromU32(623804),
reserves: ZERO_BI,
claimableReserves: ZERO_BI,
claimableReservesRemaining: ZERO_BI,
Expand Down Expand Up @@ -202,7 +201,6 @@ describe("ERC20Pool assertions", () => {
htpIndex: ZERO_BI,
lup: lup,
lupIndex: BigInt.fromU32(MAX_PRICE_INDEX), //TODO: indexToPrice(lup)
momp: BigInt.fromI32(623803),
reserves: ZERO_BI,
claimableReserves: ZERO_BI,
claimableReservesRemaining: ZERO_BI,
Expand Down Expand Up @@ -631,8 +629,8 @@ describe("ERC20Pool assertions", () => {
const kicker = Address.fromString("0x0000000000000000000000000000000000000003")
const bondFactor = ONE_WAD_BI
const kickTime = BigInt.fromI32(123)
const kickMomp = BigInt.fromI32(456)
const neutralPrice = BigInt.fromI32(456)
const referencePrice = BigInt.fromI32(456)
const head = Address.fromString("0x0000000000000000000000000000000000000000")
const next = Address.fromString("0x0000000000000000000000000000000000000000")
const prev = Address.fromString("0x0000000000000000000000000000000000000000")
Expand All @@ -643,7 +641,7 @@ describe("ERC20Pool assertions", () => {
bondFactor,
bond,
kickTime,
kickMomp,
referencePrice,
neutralPrice,
head,
next,
Expand Down Expand Up @@ -815,7 +813,7 @@ describe("ERC20Pool assertions", () => {
const bondFactor = ONE_WAD_BI
const debt = BigInt.fromString("567529276179422528643") // 567.529276179422528643 * 1e18
const kickTime = BigInt.fromI32(123)
const kickMomp = BigInt.fromI32(456)
const referencePrice = BigInt.fromI32(456)
const neutralPrice = BigInt.fromI32(456)
const head = Address.fromString("0x0000000000000000000000000000000000000000")
const next = Address.fromString("0x0000000000000000000000000000000000000000")
Expand All @@ -827,7 +825,7 @@ describe("ERC20Pool assertions", () => {
bondFactor,
bond,
kickTime,
kickMomp,
referencePrice,
neutralPrice,
head,
next,
Expand Down Expand Up @@ -864,7 +862,7 @@ describe("ERC20Pool assertions", () => {
bondFactor,
bond,
kickTime,
kickMomp,
referencePrice,
neutralPrice,
head,
next,
Expand Down Expand Up @@ -1006,7 +1004,7 @@ describe("ERC20Pool assertions", () => {
const bondFactor = ONE_WAD_BI
const debt = BigInt.fromString("567529276179422528643") // 567.529276179422528643 * 1e18
const kickTime = BigInt.fromI32(123)
const kickMomp = BigInt.fromI32(456)
const referencePrice = BigInt.fromI32(456)
const neutralPrice = BigInt.fromI32(456)
const head = Address.fromString("0x0000000000000000000000000000000000000000")
const next = Address.fromString("0x0000000000000000000000000000000000000000")
Expand All @@ -1017,7 +1015,7 @@ describe("ERC20Pool assertions", () => {
bondFactor,
bond,
kickTime,
kickMomp,
referencePrice,
neutralPrice,
head,
next,
Expand Down Expand Up @@ -1047,7 +1045,7 @@ describe("ERC20Pool assertions", () => {
bondFactor,
bond,
kickTime,
kickMomp,
referencePrice,
neutralPrice,
head,
next,
Expand Down Expand Up @@ -1201,7 +1199,7 @@ describe("ERC20Pool assertions", () => {
const bondFactor = ONE_WAD_BI
const debt = BigInt.fromString("567529276179422528643") // 567.529276179422528643 * 1e18
const kickTime = BigInt.fromI32(123)
const kickMomp = BigInt.fromI32(456)
const referencePrice = BigInt.fromI32(456)
const neutralPrice = BigInt.fromI32(456)
const head = Address.fromString("0x0000000000000000000000000000000000000000")
const next = Address.fromString("0x0000000000000000000000000000000000000000")
Expand All @@ -1212,7 +1210,7 @@ describe("ERC20Pool assertions", () => {
bondFactor,
bond,
kickTime,
kickMomp,
referencePrice,
neutralPrice,
head,
next,
Expand Down Expand Up @@ -1264,7 +1262,6 @@ describe("ERC20Pool assertions", () => {
htpIndex: ZERO_BI,
lup: MAX_PRICE_BI, //TODO: indexToPrice(lup)
lupIndex: BigInt.fromU32(MAX_PRICE_INDEX),
momp: BigInt.fromI32(623801),
reserves: ZERO_BI,
claimableReserves: claimableReserves,
claimableReservesRemaining: claimableReserves,
Expand Down Expand Up @@ -1327,12 +1324,6 @@ describe("ERC20Pool assertions", () => {
"kicker",
`${kicker.toHexString()}`
)
assert.fieldEquals(
"ReserveAuctionKick",
`${kickReserveAuctionID.toHexString()}`,
"kickerAward",
`${wadToDecimal(wmul(claimableReserves, ONE_PERCENT_BI))}`
)

assert.entityCount("ReserveAuction", 1)
assert.fieldEquals(
Expand Down Expand Up @@ -1382,7 +1373,6 @@ describe("ERC20Pool assertions", () => {
htpIndex: ZERO_BI,
lup: MAX_PRICE_BI,
lupIndex: BigInt.fromU32(MAX_PRICE_INDEX), //TODO: indexToPrice(lup)
momp: BigInt.fromI32(623802),
reserves: ZERO_BI,
claimableReserves: claimableReservesAfterTake,
claimableReservesRemaining: claimableReservesAfterTake,
Expand Down
12 changes: 4 additions & 8 deletions tests/erc-721-pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ describe("Describe entity assertions", () => {
htpIndex: ZERO_BI,
lup: MAX_PRICE_BI,
lupIndex: BigInt.fromU32(MAX_PRICE_INDEX),
momp: BigInt.fromU32(623804),
reserves: ZERO_BI,
claimableReserves: ZERO_BI,
claimableReservesRemaining: ZERO_BI,
Expand Down Expand Up @@ -187,7 +186,6 @@ describe("Describe entity assertions", () => {
htpIndex: ZERO_BI,
lup: lup,
lupIndex: BigInt.fromU32(MAX_PRICE_INDEX), //TODO: indexToPrice(lup)
momp: BigInt.fromI32(623803),
reserves: ZERO_BI,
claimableReserves: ZERO_BI,
claimableReservesRemaining: ZERO_BI,
Expand Down Expand Up @@ -579,7 +577,6 @@ describe("Describe entity assertions", () => {
htpIndex: ZERO_BI,
lup: MAX_PRICE_BI,
lupIndex: BigInt.fromU32(MAX_PRICE_INDEX),
momp: BigInt.fromU32(623804),
reserves: ZERO_BI,
claimableReserves: ZERO_BI,
claimableReservesRemaining: ZERO_BI,
Expand Down Expand Up @@ -797,7 +794,7 @@ describe("Describe entity assertions", () => {
const bondFactor = ONE_WAD_BI
const debt = BigInt.fromString("567529276179422528643") // 567.529276179422528643 * 1e18
const kickTime = BigInt.fromI32(123)
const kickMomp = BigInt.fromI32(456)
const referencePrice = BigInt.fromI32(456)
const neutralPrice = BigInt.fromI32(456)
const head = Address.fromString("0x0000000000000000000000000000000000000000")
const next = Address.fromString("0x0000000000000000000000000000000000000000")
Expand All @@ -810,7 +807,7 @@ describe("Describe entity assertions", () => {
bondFactor,
bond,
kickTime,
kickMomp,
referencePrice,
neutralPrice,
head,
next,
Expand Down Expand Up @@ -1103,7 +1100,6 @@ describe("Describe entity assertions", () => {
htpIndex: ZERO_BI,
lup: lup,
lupIndex: BigInt.fromU32(MAX_PRICE_INDEX), //TODO: indexToPrice(lup)
momp: BigInt.fromI32(623803),
reserves: ZERO_BI,
claimableReserves: ZERO_BI,
claimableReservesRemaining: ZERO_BI,
Expand Down Expand Up @@ -1193,7 +1189,7 @@ describe("Describe entity assertions", () => {
const bondFactor = ONE_WAD_BI
const debt = BigInt.fromString("567529276179422528643") // 567.529276179422528643 * 1e18
const kickTime = BigInt.fromI32(123)
const kickMomp = BigInt.fromI32(456)
const referencePrice = BigInt.fromI32(456)
const neutralPrice = BigInt.fromI32(456)
const head = Address.fromString("0x0000000000000000000000000000000000000000")
const next = Address.fromString("0x0000000000000000000000000000000000000000")
Expand All @@ -1206,7 +1202,7 @@ describe("Describe entity assertions", () => {
bondFactor,
bond,
kickTime,
kickMomp,
referencePrice,
neutralPrice,
head,
next,
Expand Down
1 change: 0 additions & 1 deletion tests/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ export function createAndHandleAddQuoteTokenEvent(poolAddress: Address, lender:
htpIndex: ZERO_BI,
lup: lup,
lupIndex: BigInt.fromU32(MAX_PRICE_INDEX), //TODO: indexToPrice(lup)
momp: BigInt.fromI32(623803),
reserves: ZERO_BI,
claimableReserves: ZERO_BI,
claimableReservesRemaining: ZERO_BI,
Expand Down
14 changes: 1 addition & 13 deletions tests/utils/mock-contract-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,6 @@ export function mockGetPoolPricesInfo(pool: Address, expectedInfo: PoolPricesInf
])
}

// mock getMomp contract calls
export function mockGetPoolMomp(pool: Address, expectedInfo: BigInt): void {
createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'momp', 'momp(address):(uint256)')
.withArgs([ethereum.Value.fromAddress(pool)])
.returns([
ethereum.Value.fromUnsignedBigInt(expectedInfo)
])
}

// mock getPoolReserves contract calls
export function mockGetPoolReserves(pool: Address, expectedInfo: ReservesInfo): void {
createMockedFunction(poolInfoUtilsAddressTable.get(dataSource.network())!, 'poolReservesInfo', 'poolReservesInfo(address):(uint256,uint256,uint256,uint256,uint256)')
Expand Down Expand Up @@ -272,7 +263,7 @@ export function mockGetAuctionInfo(borrower: Address, pool: Address, expectedInf
ethereum.Value.fromUnsignedBigInt(expectedInfo.bondFactor),
ethereum.Value.fromUnsignedBigInt(expectedInfo.bondSize),
ethereum.Value.fromUnsignedBigInt(expectedInfo.kickTime),
ethereum.Value.fromUnsignedBigInt(expectedInfo.kickMomp),
ethereum.Value.fromUnsignedBigInt(expectedInfo.referencePrice),
ethereum.Value.fromUnsignedBigInt(expectedInfo.neutralPrice),
ethereum.Value.fromAddress(expectedInfo.head),
ethereum.Value.fromAddress(expectedInfo.next),
Expand Down Expand Up @@ -360,7 +351,6 @@ export class PoolMockParams {
htpIndex: BigInt
lup: BigInt
lupIndex: BigInt
momp: BigInt
// reserves info mock params
reserves: BigInt
claimableReserves: BigInt
Expand Down Expand Up @@ -401,8 +391,6 @@ export function mockPoolInfoUtilsPoolUpdateCalls(pool: Address, params: PoolMock
)
mockGetPoolPricesInfo(pool, expectedPoolPricesInfo)

mockGetPoolMomp(pool, params.momp)

const expectedPoolReservesInfo = new ReservesInfo(
params.reserves,
params.claimableReserves,
Expand Down

0 comments on commit 468b4ac

Please sign in to comment.