Skip to content

Commit

Permalink
Add config check script, stone vaults and manta chain
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Jul 31, 2024
1 parent 194c35b commit 15d607e
Show file tree
Hide file tree
Showing 15 changed files with 661 additions and 466 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
node: ["21.x"]
chain: ["arbitrum", "base", "bsc", "ethereum", "kava", "mode", "linea", "optimism"]
chain: ["arbitrum", "base", "bsc", "ethereum", "kava", "linea", "manta", "mode", "optimism"]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ node_modules

subgraph.yaml
src/config.ts
random.json
src/random.ts

tests/.latest.json
49 changes: 49 additions & 0 deletions bin/check-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { VaultConfig, _getChainVaults } from "../src/vault-config"

const checkConfig = async () => {
// fetch vault config from https://api.beefy.com/vaults

type ApiVault = {
id: string
earnContractAddress: string
earningPoints?: boolean
}

const apiVaults: ApiVault[] = await fetch("https://api.beefy.finance/vaults").then((res) => res.json())
const configVaults = _getChainVaults("all")

const configVaultsByAddress = configVaults.reduce(
(acc, v) => {
acc[v.address.toLocaleLowerCase()] = v
return acc
},
{} as Record<string, VaultConfig>,
)

const configVaultById = configVaults.reduce(
(acc, v) => {
acc[v.vaultKey] = v
return acc
},
{} as Record<string, VaultConfig>,
)

const apiVaultsEarningPoints = apiVaults.filter((v) => v.earningPoints)

for (const apiVault of apiVaultsEarningPoints) {
const configVaultFoundById = configVaultById[apiVault.id]
const configVaultFoundByAddress = configVaultsByAddress[apiVault.earnContractAddress.toLocaleLowerCase()]

if (!configVaultFoundByAddress) {
console.log(`Vault ${apiVault.id} not found in config by address: ${apiVault.earnContractAddress}`)
} else if (!configVaultFoundById) {
console.log(
`Vault with address ${apiVault.earnContractAddress} has incorrect id ${configVaultFoundByAddress.vaultKey} instead of ${apiVault.id}`,
)
} else {
// OK
}
}
}

checkConfig()
6 changes: 5 additions & 1 deletion bin/prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ fi
set -e

yarn --silent run mustache config/$CHAIN.json subgraph.template.yaml > subgraph.yaml
yarn --silent run mustache config/$CHAIN.json src/config.template.ts > src/config.ts
yarn --silent run mustache config/$CHAIN.json src/config.template.ts > src/config.ts

RNG=$((1 + $RANDOM % 100000))
echo '{"random": '$RNG'}' > random.json
yarn --silent run mustache random.json src/random.template.ts > src/random.ts
10 changes: 10 additions & 0 deletions config/manta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"network": "manta-pacific-mainnet",
"indexerHintPrune": 700000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"bindConfigAddress": "0xfc69704cC3cAac545cC7577009Ea4AA04F1a61Eb",
"bindConfigBlock": 2501033,
"bindConfigEvent": "ProxyCreated(address)",
"vaultInitializedEvent": "Initialized(uint8)",
"clockTickBlocks": 50
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"test": "yarn run --silent test:lint && yarn run --silent test:unit",
"test:unit": "graph test",
"test:lint": "prettier . --check",
"check-config": "ts-node --project tsconfig.scripts.json ./bin/check-config.ts",
"infra:start": "docker compose up -d",
"infra:stop": "docker compose down",
"create-local": "graph create beefyfinance/lrt --node http://127.0.0.1:8020",
Expand All @@ -19,6 +20,7 @@
"prepare:bsc": "./bin/prepare.sh bsc",
"prepare:ethereum": "./bin/prepare.sh ethereum",
"prepare:linea": "./bin/prepare.sh linea",
"prepare:manta": "./bin/prepare.sh manta",
"prepare:mode": "./bin/prepare.sh mode",
"prepare:optimism": "./bin/prepare.sh optimism",
"prepare:kava": "./bin/prepare.sh kava"
Expand All @@ -44,4 +46,4 @@
"*.--check": "prettier --write"
},
"packageManager": "[email protected]"
}
}
2 changes: 1 addition & 1 deletion src/bind-contracts.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BeefyVaultV7 as BeefyVaultV7Template, BeefyRewardPool as BeefyRewardPoolTemplate } from "../generated/templates"
import { getChainVaults, buildVaultDataSourceContext } from "./vault-config"
import { getChainVaults, buildVaultDataSourceContext } from "./vault-config-asm"
import { ethereum, log } from "@graphprotocol/graph-ts"

export function bindAllContracts(_: ethereum.Event): void {
Expand Down
2 changes: 1 addition & 1 deletion src/config.template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Address } from "@graphprotocol/graph-ts"

export const NETWORK_NAME = "{{network}}"
export const SHARE_TOKEN_MINT_ADDRESS = Address.fromString("{{shareTokenMintAddress}}")
export const SHARE_TOKEN_MINT_ADDRESS = Address.fromString("{{shareTokenMintAddress}}")
2 changes: 2 additions & 0 deletions src/random.template.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// force the subgraph has to be different to make sure we don't fail on redeploy
export const RANDOM = "{{random}}"
101 changes: 101 additions & 0 deletions src/vault-config-asm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { Address, DataSourceContext, log, dataSource } from "@graphprotocol/graph-ts"
import { NETWORK_NAME } from "./config"
import { VaultConfig, _getChainVaults } from "./vault-config"
import { RANDOM } from "./random"

export const PLATFORM_AAVE = "AAVE"
export const PLATFORM_BALANCER_AURA = "BALANCER_AURA"
export const PLATFORM_CURVE = "CURVE"
export const PLATFORM_GAMMA = "GAMMA"
export const PLATFORM_ICHI_LYNEX = "ICHI_LYNEX"
export const PLATFORM_LYNEX = "LYNEX"
export const PLATFORM_MENDI_LENDING = "MENDI_LENDING"
export const PLATFORM_MENDI_LEVERAGE = "MENDI_LEVERAGE"
export const PLATFORM_NILE = "NILE"
export const PLATFORM_PENDLE_EQUILIBRIA = "PENDLE_EQUILIBRIA"
export const PLATFORM_SOLIDLY = "SOLIDLY"
export const PLATFORM_BEEFY_CLM = "BEEFY_CLM"
export const TRACK_ONLY_SHARE_TOKEN_BALANCE = "TRACK_ONLY_SHARE_TOKEN_BALANCE"
export const TRACK_ONLY_SHARE_AND_UNDERLYING_TOKEN_BALANCE = "TRACK_ONLY_SHARE_AND_UNDERLYING_TOKEN_BALANCE"

export function getChainVaults(): Array<VaultConfigAsm> {
const network = NETWORK_NAME as string
log.debug("getChainVaults: network={} rng={}", [network, RANDOM])

const configs = _getChainVaults(network)

const vaults = new Array<VaultConfigAsm>()
for (let i = 0; i < configs.length; i++) {
vaults.push(new VaultConfigAsm(configs[i]))
}

return vaults
}

export function isBoostAddress(address: Address): boolean {
const vaults = getChainVaults()
for (let i = 0; i < vaults.length; i++) {
for (let j = 0; j < vaults[i].boostAddresses.length; j++) {
if (vaults[i].boostAddresses[j].equals(address)) {
return true
}
}
}

return false
}
export function isRewardPoolAddress(address: Address): boolean {
const vaults = getChainVaults()
for (let i = 0; i < vaults.length; i++) {
for (let j = 0; j < vaults[i].rewardPoolsAddresses.length; j++) {
if (vaults[i].rewardPoolsAddresses[j].equals(address)) {
return true
}
}
}

return false
}

const CONTEXT_KEY_UNDERLYING_PLATFORM = "underlyingPlatform"
const CONTEXT_KEY_VAULT_KEY = "vaultKey"

export function buildVaultDataSourceContext(vault: VaultConfigAsm): DataSourceContext {
let context = new DataSourceContext()
context.setString(CONTEXT_KEY_UNDERLYING_PLATFORM, vault.underlyingPlatform)
context.setString(CONTEXT_KEY_VAULT_KEY, vault.vaultKey)
return context
}

export function getContextUnderlyingPlatform(): string {
let context = dataSource.context()
return context.getString(CONTEXT_KEY_UNDERLYING_PLATFORM)
}

export function getContextVaultKey(): string {
let context = dataSource.context()
return context.getString(CONTEXT_KEY_VAULT_KEY)
}

class VaultConfigAsm {
public vaultKey: string
public underlyingPlatform: string
public address: Address
public boostAddresses: Array<Address>
public rewardPoolsAddresses: Array<Address>

constructor(config: VaultConfig) {
this.vaultKey = config.vaultKey
this.underlyingPlatform = config.underlyingPlatform
this.address = Address.fromString(config.address)
this.boostAddresses = new Array<Address>()
this.rewardPoolsAddresses = new Array<Address>()

for (let i = 0; i < config.rewardPoolsAddresses.length; i++) {
this.rewardPoolsAddresses.push(Address.fromString(config.rewardPoolsAddresses[i]))
}
for (let i = 0; i < config.boostAddresses.length; i++) {
this.boostAddresses.push(Address.fromString(config.boostAddresses[i]))
}
}
}
Loading

0 comments on commit 15d607e

Please sign in to comment.