Skip to content

Commit

Permalink
Add sentio compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Nov 25, 2024
1 parent 81112bc commit bd6882a
Show file tree
Hide file tree
Showing 13 changed files with 935 additions and 43 deletions.
9 changes: 9 additions & 0 deletions bin/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ function publish_goldsky {
goldsky subgraph deploy $SUBGRAPH/0.0.1 --path .
}

function publish_sentio {
SUBGRAPH=$1
echo "publishing $SUBGRAPH to sentio"
npx @sentio/cli graph deploy --name $SUBGRAPH
}

function publish {
CHAIN=$1
PROVIDER=$2
Expand All @@ -48,6 +54,9 @@ function publish {
"goldsky")
publish_goldsky beefy-clm-$CHAIN-dev
;;
"sentio")
publish_sentio beefy-clm-$CHAIN
;;
esac
}

Expand Down
35 changes: 35 additions & 0 deletions config/opera.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"network": "manta-pacific-mainnet",

"multicall3Address": "0xcA11bde05977b3631167028862bE2a173976CA11",
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",

"clmManagerFactoryAddress": "0x91BB303E972995EbE5f593BCddBb6F5Ef49Dbcbd",
"clmManagerFactoryStartBlock": 2501033,
"clmStrategyFactoryAddress": "0x448a3539a591dE3Fb9D5AAE407471D21d40cD315",
"clmStrategyFactoryStartBlock": 2501044,
"rewardPoolFactoryAddress": "0x9818dF1Bdce8D0E79B982e2C3a93ac821b3c17e0",
"rewardPoolFactoryStartBlock": 2501035,
"beefyClassicVaultFactoryAddress": "0xfc69704cC3cAac545cC7577009Ea4AA04F1a61Eb",
"beefyClassicVaultFactoryStartBlock": 2501033,
"beefyClassicBoostFactoryAddress": "0x0000000000000000000000000000000000000000",
"beefyClassicBoostFactoryStartBlock": 2501033,
"clockTickBlocks": 50,

"wrappedNativeAddress": "0x0Dc808adcE2099A9F62AA87D9670745AbA741746",
"wrappedNativeDecimals": 18,

"priceOracleType": "pyth",
"chainlinkNativePriceFeedAddress": "0x0000000000000000000000000000000000000000",
"chainlinkNativePriceFeedDecimals": 8,
"pythPriceFeedAddress": "0xA2aa501b19aff244D90cc15a4Cf739D2725B5729",
"pythNativePriceId": "0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace",
"umbrellaRegistryAddress": "0x4A28406ECe8FfD7A91789738A5AC15DAC44bfA1B",
"umbrellaRegistryPriceFeedName": "WRBTC-rUSDT",
"umbrellaRegistryPriceFeedNameBytes32": "0xd2a0ad2667ba45a57ce6a98d6f51a4a4d256d704f578b3b90d7ee12e2f6af854",
"umbrellaRegistryPriceFeedDecimals": 8,

"beefySwapperAddress": "0x07f1ad98b725Af45485646aC431b7757f50C598A",
"beefyOracleAddress": "0x2AfB174c22D9eE334895C4e300ab93154d800aA0"
}
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"prepare:linea": "./bin/prepare.sh linea",
"prepare:manta": "./bin/prepare.sh manta",
"prepare:moonbeam": "./bin/prepare.sh moonbeam",
"prepare:opera": "./bin/prepare.sh opera",
"prepare:optimism": "./bin/prepare.sh optimism",
"prepare:polygon": "./bin/prepare.sh polygon",
"prepare:zksync": "./bin/prepare.sh zksync",
Expand All @@ -38,7 +39,7 @@
"license": "MIT",
"devDependencies": {
"@graphprotocol/graph-cli": "^0.73.0",
"@graphprotocol/graph-ts": "^0.35.1",
"@graphprotocol/graph-ts": "0.32.0",
"assemblyscript-prettier": "^3.0.1",
"husky": "^9.0.11",
"lint-staged": ">=10",
Expand All @@ -49,7 +50,10 @@
"typescript": "^5.3.3"
},
"lint-staged": {
"*.*": "prettier --write"
"*.{js,ts,json,md}": "prettier --write"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"dependencies": {
"@sentio/cli": "^2.22.1"
}
}
5 changes: 2 additions & 3 deletions src/classic/compound.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BigInt, ethereum, log } from "@graphprotocol/graph-ts"
import { StratHarvest as HarvestEvent } from "../../generated/templates/ClassicStrategy/ClassicStrategy"
import { getTransaction } from "../common/entity/transaction"
import { getAndSaveTransaction } from "../common/entity/transaction"
import { ClassicHarvestEvent } from "../../generated/schema"
import { getEventIdentifier } from "../common/utils/event"
import { getClassic, getClassicStrategy, hasClassicBeenRemoved, isClassicInitialized } from "./entity/classic"
Expand All @@ -24,8 +24,7 @@ function _handleClassicStrategyHarvest(event: ethereum.Event, compoundedAmount:
return
}

let tx = getTransaction(event.block, event.transaction)
tx.save()
let tx = getAndSaveTransaction(event.block, event.transaction)

///////
// fetch data on chain
Expand Down
5 changes: 2 additions & 3 deletions src/classic/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
Transfer as RewardPoolTransferEvent,
RewardPaid as RewardPoolRewardPaidEvent,
} from "../../generated/templates/ClmRewardPool/RewardPool"
import { getTransaction } from "../common/entity/transaction"
import { getAndSaveTransaction } from "../common/entity/transaction"
import { getInvestor } from "../common/entity/investor"
import { Classic, ClassicPositionInteraction } from "../../generated/schema"
import { BURN_ADDRESS, SHARE_TOKEN_MINT_ADDRESS } from "../config"
Expand Down Expand Up @@ -271,8 +271,7 @@ function updateUserPosition(
const investor = getInvestor(investorAddress)
const position = getClassicPosition(classic, investor)

let tx = getTransaction(event.block, event.transaction)
tx.save()
let tx = getAndSaveTransaction(event.block, event.transaction)

///////
// fetch data on chain and update clm
Expand Down
8 changes: 3 additions & 5 deletions src/classic/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import {
removeClassicAndDependencies,
} from "./entity/classic"
import { Classic } from "../../generated/schema"
import { getTransaction } from "../common/entity/transaction"
import { getAndSaveTransaction } from "../common/entity/transaction"
import { fetchAndSaveTokenData } from "../common/utils/token"
import { PRODUCT_LIFECYCLE_PAUSED, PRODUCT_LIFECYCLE_RUNNING } from "../common/entity/lifecycle"
import { ADDRESS_ZERO } from "../common/utils/address"
Expand All @@ -41,8 +41,7 @@ import { fetchClassicUnderlyingCLM } from "./utils/classic-data"
export function handleClassicVaultOrStrategyCreated(event: VaultOrStrategyCreated): void {
const address = event.params.proxy

const tx = getTransaction(event.block, event.transaction)
tx.save()
const tx = getAndSaveTransaction(event.block, event.transaction)

// test if we are creating a vault or a strategy
const vaultContract = ClassicVaultContract.bind(address)
Expand Down Expand Up @@ -245,8 +244,7 @@ export function handleClassicVaultUpgradeStrategy(event: ClassicVaultUpgradeStra
newStrategy.vault = classic.id
newStrategy.classic = classic.id
if (newStrategy.createdWith.equals(ADDRESS_ZERO)) {
const tx = getTransaction(event.block, event.transaction)
tx.save()
const tx = getAndSaveTransaction(event.block, event.transaction)
newStrategy.createdWith = tx.id
}
newStrategy.save()
Expand Down
8 changes: 3 additions & 5 deletions src/clm/compound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
ClaimedRewards as CLMClaimedRewardsEvent,
} from "../../generated/templates/ClmStrategy/ClmStrategy"
import { getClmStrategy, getCLM, isClmInitialized } from "./entity/clm"
import { getTransaction } from "../common/entity/transaction"
import { getAndSaveTransaction } from "../common/entity/transaction"
import { ClmHarvestEvent, ClmManagerCollectionEvent } from "../../generated/schema"
import { ZERO_BI } from "../common/utils/decimal"
import { getEventIdentifier } from "../common/utils/event"
Expand Down Expand Up @@ -47,8 +47,7 @@ function handleClmStrategyHarvest(
return
}

let tx = getTransaction(event.block, event.transaction)
tx.save()
let tx = getAndSaveTransaction(event.block, event.transaction)

///////
// fetch data on chain
Expand Down Expand Up @@ -116,8 +115,7 @@ function handleClmStrategyFees(
return
}

let tx = getTransaction(event.block, event.transaction)
tx.save()
let tx = getAndSaveTransaction(event.block, event.transaction)

///////
// fetch data on chain
Expand Down
5 changes: 2 additions & 3 deletions src/clm/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
RewardPaid as RewardPoolRewardPaidEvent,
} from "../../generated/templates/ClmRewardPool/RewardPool"
import { getClmRewardPool, getCLM, isClmInitialized } from "./entity/clm"
import { getTransaction } from "../common/entity/transaction"
import { getAndSaveTransaction } from "../common/entity/transaction"
import { getInvestor } from "../common/entity/investor"
import { getClmPosition } from "./entity/position"
import { CLM, ClmPositionInteraction, ClmRewardPool } from "../../generated/schema"
Expand Down Expand Up @@ -160,8 +160,7 @@ function updateUserPosition(
const investor = getInvestor(investorAddress)
const position = getClmPosition(clm, investor)

let tx = getTransaction(event.block, event.transaction)
tx.save()
let tx = getAndSaveTransaction(event.block, event.transaction)

///////
// fetch data on chain and update clm
Expand Down
5 changes: 2 additions & 3 deletions src/clm/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from "../../generated/templates/ClmStrategy/ClmStrategy"
import { ProxyCreated as CLMManagerCreatedEvent } from "../../generated/ClmManagerFactory/ClmManagerFactory"
import { GlobalPause as ClmStrategyFactoryGlobalPauseEvent } from "../../generated/ClmStrategyFactory/ClmStrategyFactory"
import { getTransaction } from "../common/entity/transaction"
import { getAndSaveTransaction } from "../common/entity/transaction"
import { fetchAndSaveTokenData } from "../common/utils/token"
import { getBeefyCLProtocol } from "../common/entity/protocol"
import {
Expand All @@ -26,8 +26,7 @@ import {
} from "../common/entity/lifecycle"

export function handleClmManagerCreated(event: CLMManagerCreatedEvent): void {
const tx = getTransaction(event.block, event.transaction)
tx.save()
const tx = getAndSaveTransaction(event.block, event.transaction)

const managerAddress = event.params.proxy

Expand Down
3 changes: 2 additions & 1 deletion src/common/entity/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import { ethereum } from "@graphprotocol/graph-ts"
import { Transaction } from "../../../generated/schema"
import { ADDRESS_ZERO } from "../utils/address"

export function getTransaction(block: ethereum.Block, transaction: ethereum.Transaction): Transaction {
export function getAndSaveTransaction(block: ethereum.Block, transaction: ethereum.Transaction): Transaction {
let transactionId = transaction.hash
let tx = Transaction.load(transactionId)
if (!tx) {
tx = new Transaction(transactionId)
tx.blockNumber = block.number
tx.blockTimestamp = block.timestamp
tx.sender = transaction.from || ADDRESS_ZERO
tx.save()
}
return tx
}
5 changes: 5 additions & 0 deletions src/common/utils/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { Address, BigInt, Bytes } from "@graphprotocol/graph-ts"
import { getToken } from "../entity/token"

export function fetchAndSaveTokenData(tokenAddress: Bytes): Token {
let tokenExists = Token.load(tokenAddress)
if (tokenExists) {
return tokenExists
}

const tokenContract = IERC20Contract.bind(Address.fromBytes(tokenAddress))
// use individual calls as there is a good change other subgraph has requested
// this token's metadata and it's already in the graph-node cache
Expand Down
5 changes: 2 additions & 3 deletions src/reward-pool/lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
AddReward as RewardPoolAddRewardEvent,
RemoveReward as RewardPoolRemoveRewardEvent,
} from "../../generated/RewardPoolFactory/RewardPool"
import { getTransaction } from "../common/entity/transaction"
import { getAndSaveTransaction } from "../common/entity/transaction"
import { fetchAndSaveTokenData } from "../common/utils/token"
import { ZERO_BI } from "../common/utils/decimal"
import { getCLM, getClmRewardPool, isClmManagerAddress, isClmRewardPool, removeClmRewardPool } from "../clm/entity/clm"
Expand Down Expand Up @@ -52,8 +52,7 @@ export function handleRewardPoolInitialized(event: RewardPoolInitialized): void
}
const stakedTokenAddress = stakedTokenAddressRes.value

const tx = getTransaction(event.block, event.transaction)
tx.save()
const tx = getAndSaveTransaction(event.block, event.transaction)

const rewardPoolToken = fetchAndSaveTokenData(rewardPoolAddress)

Expand Down
Loading

0 comments on commit bd6882a

Please sign in to comment.