Skip to content

Commit

Permalink
Update ssv contracts and usage to jato v2
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Sep 11, 2023
1 parent 1562361 commit d555ec6
Show file tree
Hide file tree
Showing 40 changed files with 919 additions and 875 deletions.
5 changes: 2 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
[submodule "contracts/ethereum/scripts/resources/ssv-network"]
path = contracts/ethereum/scripts/resources/ssv-network
url = https://github.com/bloxapp/ssv-network.git
branch = contract-v3
branch = jato-v2
[submodule "contracts/ethereum/lib/forge-std"]
path = contracts/ethereum/lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "services/oracle/scripts/resources/rockx-dkg-cli"]
path = services/oracle/scripts/resources/rockx-dkg-cli
url = https://github.com/RockX-SG/rockx-dkg-cli.git
branch = main
url = https://github.com/RockX-SG/rockx-dkg-cli.git
12 changes: 6 additions & 6 deletions apps/web/src/composables/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const totalWalletBalance = ref<BreakdownAmount>({
eth: '0 ETH'
})

const { ethereumUrl, managerAddress, registryAddress, ssvNetworkAddress, ssvNetworkViewsAddress, viewsAddress } = useEnvironment()
const { ethereumUrl, managerAddress, registryAddress, ssvNetworkAddress, ssvViewsAddress, viewsAddress } = useEnvironment()
const provider = new ethers.providers.JsonRpcProvider(ethereumUrl)
const manager: CasimirManager & ethers.Contract = new ethers.Contract(managerAddress, CasimirManagerAbi, provider) as CasimirManager
const views: CasimirViews & ethers.Contract = new ethers.Contract(viewsAddress, CasimirViewsAbi, provider) as CasimirViews
Expand Down Expand Up @@ -230,7 +230,7 @@ export default function useContracts() {
const scanner = new Scanner({
ethereumUrl,
ssvNetworkAddress,
ssvNetworkViewsAddress
ssvViewsAddress
})

const ssvOperators: Operator[] = []
Expand All @@ -251,10 +251,10 @@ export default function useContracts() {
'655': 'https://nodes.casimir.co/eth/goerli/dkg/2',
'656': 'https://nodes.casimir.co/eth/goerli/dkg/3',
'657': 'https://nodes.casimir.co/eth/goerli/dkg/4',
'658': 'https://nodes.casimir.co/eth/goerli/dkg/5',
'659': 'https://nodes.casimir.co/eth/goerli/dkg/6',
'660': 'https://nodes.casimir.co/eth/goerli/dkg/7',
'661': 'https://nodes.casimir.co/eth/goerli/dkg/8'
'156': 'https://nodes.casimir.co/eth/goerli/dkg/5',
'157': 'https://nodes.casimir.co/eth/goerli/dkg/6',
'158': 'https://nodes.casimir.co/eth/goerli/dkg/7',
'159': 'https://nodes.casimir.co/eth/goerli/dkg/8'
}
const url = operatorStore[operator.id.toString() as keyof typeof operatorStore]
casimirOperators.push({
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/composables/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function useEnvironment() {
const walletConnectUrl = 'https://bridge.walletconnect.org'
const cryptoCompareApiKey = import.meta.env.PUBLIC_CRYPTO_COMPARE_API_KEY || ''
const ssvNetworkAddress = import.meta.env.PUBLIC_SSV_NETWORK_ADDRESS
const ssvNetworkViewsAddress = import.meta.env.PUBLIC_SSV_NETWORK_VIEWS_ADDRESS
const ssvViewsAddress = import.meta.env.PUBLIC_SSV_VIEWS_ADDRESS

return {
domain,
Expand All @@ -26,7 +26,7 @@ export default function useEnvironment() {
registryAddress,
speculosUrl,
ssvNetworkAddress,
ssvNetworkViewsAddress,
ssvViewsAddress,
usersUrl,
viewsAddress,
walletConnectUrl,
Expand Down
2 changes: 1 addition & 1 deletion common/data/notebooks/dkg.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"metadata": {},
"outputs": [
{
Expand Down
6 changes: 3 additions & 3 deletions common/data/notebooks/ethereum.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Casimir mainnet node is fully synced\n",
"Casimir mainnet node is not responding\n",
"Casimir goerli node is fully synced\n",
"Casimir hardhat node is fully synced\n"
"Casimir hardhat node is not responding\n"
]
}
],
Expand Down
8 changes: 4 additions & 4 deletions common/data/src/mock/operator.store.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"655": "https://nodes.casimir.co/eth/goerli/dkg/2",
"656": "https://nodes.casimir.co/eth/goerli/dkg/3",
"657": "https://nodes.casimir.co/eth/goerli/dkg/4",
"658": "https://nodes.casimir.co/eth/goerli/dkg/5",
"659": "https://nodes.casimir.co/eth/goerli/dkg/6",
"660": "https://nodes.casimir.co/eth/goerli/dkg/7",
"661": "https://nodes.casimir.co/eth/goerli/dkg/8"
"156": "https://nodes.casimir.co/eth/goerli/dkg/5",
"157": "https://nodes.casimir.co/eth/goerli/dkg/6",
"158": "https://nodes.casimir.co/eth/goerli/dkg/7",
"159": "https://nodes.casimir.co/eth/goerli/dkg/8"
}
136 changes: 68 additions & 68 deletions common/data/src/mock/validator.store.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion common/ssv/src/interfaces/Cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export interface Cluster {
validatorCount: number | ethers.BigNumber
networkFeeIndex: number | ethers.BigNumber
index: number | ethers.BigNumber
balance: number | ethers.BigNumber
active: boolean
balance: number | ethers.BigNumber
}
2 changes: 1 addition & 1 deletion common/ssv/src/interfaces/ScannerOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ export interface ScannerOptions {
ethereumUrl?: string
provider?: ethers.providers.JsonRpcProvider
ssvNetworkAddress: string
ssvNetworkViewsAddress: string
ssvViewsAddress: string
}
60 changes: 30 additions & 30 deletions common/ssv/src/providers/scanner.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ethers } from 'ethers'
import { ISSVNetwork, ISSVNetworkViews } from '@casimir/ethereum/build/@types'
import ISSVNetworkAbi from '@casimir/ethereum/build/abi/ISSVNetwork.json'
import ISSVNetworkViewsAbi from '@casimir/ethereum/build/abi/ISSVNetworkViews.json'
import { ISSVClusters, ISSVViews } from '@casimir/ethereum/build/@types'
import ISSVClustersAbi from '@casimir/ethereum/build/abi/ISSVClusters.json'
import ISSVViewsAbi from '@casimir/ethereum/build/abi/ISSVViews.json'
import { GetClusterInput } from '../interfaces/GetClusterInput'
import { Cluster } from '../interfaces/Cluster'
import { Operator } from '../interfaces/Operator'
Expand All @@ -12,17 +12,17 @@ export class Scanner {
WEEK = this.DAY * 7
MONTH = this.DAY * 30
provider: ethers.providers.JsonRpcProvider
ssvNetwork: ISSVNetwork & ethers.Contract
ssvNetworkViews: ISSVNetworkViews & ethers.Contract
ssvClusters: ISSVClusters & ethers.Contract
ssvViews: ISSVViews & ethers.Contract

constructor(options: ScannerOptions) {
if (options.provider) {
this.provider = options.provider
} else {
this.provider = new ethers.providers.JsonRpcProvider(options.ethereumUrl)
}
this.ssvNetwork = new ethers.Contract(options.ssvNetworkAddress, ISSVNetworkAbi, this.provider) as ISSVNetwork & ethers.Contract
this.ssvNetworkViews = new ethers.Contract(options.ssvNetworkViewsAddress, ISSVNetworkViewsAbi, this.provider) as ISSVNetworkViews & ethers.Contract
this.ssvClusters = new ethers.Contract(options.ssvNetworkAddress, ISSVClustersAbi, this.provider) as ISSVClusters & ethers.Contract
this.ssvViews = new ethers.Contract(options.ssvViewsAddress, ISSVViewsAbi, this.provider) as ISSVViews & ethers.Contract
}

/**
Expand All @@ -33,12 +33,12 @@ export class Scanner {
async getCluster(input: GetClusterInput): Promise<Cluster> {
const { ownerAddress, operatorIds } = input
const eventFilters = [
this.ssvNetwork.filters.ClusterDeposited(ownerAddress),
this.ssvNetwork.filters.ClusterWithdrawn(ownerAddress),
this.ssvNetwork.filters.ValidatorAdded(ownerAddress),
this.ssvNetwork.filters.ValidatorRemoved(ownerAddress),
this.ssvNetwork.filters.ClusterLiquidated(ownerAddress),
this.ssvNetwork.filters.ClusterReactivated(ownerAddress)
this.ssvClusters.filters.ClusterDeposited(ownerAddress),
this.ssvClusters.filters.ClusterWithdrawn(ownerAddress),
this.ssvClusters.filters.ValidatorAdded(ownerAddress),
this.ssvClusters.filters.ValidatorRemoved(ownerAddress),
this.ssvClusters.filters.ClusterLiquidated(ownerAddress),
this.ssvClusters.filters.ClusterReactivated(ownerAddress)
]
let step = this.MONTH
const latestBlockNumber = await this.provider.getBlockNumber()
Expand All @@ -50,7 +50,7 @@ export class Scanner {
try {
const items = []
for (const filter of eventFilters) {
const filteredItems = await this.ssvNetwork.queryFilter(filter, fromBlock, toBlock)
const filteredItems = await this.ssvClusters.queryFilter(filter, fromBlock, toBlock)
items.push(...filteredItems)
}
for (const item of items) {
Expand All @@ -64,15 +64,15 @@ export class Scanner {
validatorCount,
networkFeeIndex,
index,
balance,
active
active,
balance
] = args.cluster
cluster = {
validatorCount,
networkFeeIndex,
index,
balance,
active
active,
balance
}
}
}
Expand All @@ -90,8 +90,8 @@ export class Scanner {
validatorCount: 0,
networkFeeIndex: 0,
index: 0,
balance: 0,
active: true
active: true,
balance: 0
}
return cluster
}
Expand All @@ -102,10 +102,10 @@ export class Scanner {
* @returns {Promise<number>} Owner validator nonce
*/
async getNonce(ownerAddress: string): Promise<number> {
const eventFilter = this.ssvNetwork.filters.ValidatorAdded(ownerAddress)
const eventFilter = this.ssvClusters.filters.ValidatorAdded(ownerAddress)
const fromBlock = 0
const toBlock = 'latest'
const items = await this.ssvNetwork.queryFilter(eventFilter, fromBlock, toBlock)
const items = await this.ssvClusters.queryFilter(eventFilter, fromBlock, toBlock)
return items.length
}

Expand All @@ -115,13 +115,13 @@ export class Scanner {
* @returns {Promise<ethers.BigNumber>} Validator fee
*/
async getRequiredFee(operatorIds: number[]): Promise<ethers.BigNumber> {
const feeSum = await this.ssvNetworkViews.getNetworkFee()
let feeSum = await this.ssvViews.getNetworkFee()
for (const operatorId of operatorIds) {
const operatorFee = await this.ssvNetworkViews.getOperatorFee(operatorId)
feeSum.add(operatorFee)
const operatorFee = await this.ssvViews.getOperatorFee(operatorId)
feeSum = feeSum.add(operatorFee)
}
const liquidationThresholdPeriod = await this.ssvNetworkViews.getLiquidationThresholdPeriod()
return feeSum.mul(liquidationThresholdPeriod).mul(12)
const liquidationThresholdPeriod = await this.ssvViews.getLiquidationThresholdPeriod()
return feeSum.mul(liquidationThresholdPeriod).mul(6)
}

/**
Expand All @@ -130,13 +130,13 @@ export class Scanner {
* @returns {Promise<Operator[]>} The owner's operators
*/
async getOperators(ownerAddress: string): Promise<Operator[]> {
const eventFilter = this.ssvNetwork.filters.OperatorAdded(null, ownerAddress)
const eventFilter = this.ssvClusters.filters.OperatorAdded(null, ownerAddress)
const operators: Operator[] = []
const items = await this.ssvNetwork.queryFilter(eventFilter, 0, 'latest')
const items = await this.ssvClusters.queryFilter(eventFilter, 0, 'latest')
for (const item of items) {
const { args } = item
const { operatorId } = args
const { fee, validatorCount, isPrivate } = await this.ssvNetworkViews.getOperatorById(operatorId)
const { fee, validatorCount, isPrivate } = await this.ssvViews.getOperatorById(operatorId)
operators.push({
id: operatorId.toNumber(),
fee,
Expand Down
2 changes: 1 addition & 1 deletion contracts/ethereum/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Vendor contracts and interfaces are located in the [src/v1/vendor](./src/v1/vend
| ReentrancyGuard | Secures against reentrancy |
| SSVNetwork | Registers SSV validators |
| SSVNetworkCore | Provides base SSV logic and types |
| SSVNetworkViews | Provides read-only access to SSV network state |
| SSVViews | Provides read-only access to SSV network state |
| SwapRouter | Routes token swaps |
| UniswapV3Factory | Provides access to Uniswap V3 pools |
| UniswapV3PoolState | Provides access to Uniswap V3 pool state |
Expand Down
6 changes: 3 additions & 3 deletions contracts/ethereum/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const externalEnv = {
LINK_REGISTRY_ADDRESS: '0x02777053d6764996e594c3E88AF1D58D5363a2e6',
LINK_TOKEN_ADDRESS: '0x514910771AF9Ca656af840dff83E8264EcF986CA',
SSV_NETWORK_ADDRESS: '',
SSV_NETWORK_VIEWS_ADDRESS: '',
SSV_VIEWS_ADDRESS: '',
SSV_TOKEN_ADDRESS: '0x9D65fF81a3c488d585bBfb0Bfe3c7707c7917f54',
SWAP_FACTORY_ADDRESS: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
SWAP_ROUTER_ADDRESS: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
Expand All @@ -51,8 +51,8 @@ const externalEnv = {
LINK_REGISTRAR_ADDRESS: '0x57A4a13b35d25EE78e084168aBaC5ad360252467',
LINK_REGISTRY_ADDRESS: '0xE16Df59B887e3Caa439E0b29B42bA2e7976FD8b2',
LINK_TOKEN_ADDRESS: '0x326C977E6efc84E512bB9C30f76E30c160eD06FB',
SSV_NETWORK_ADDRESS: '0xAfdb141Dd99b5a101065f40e3D7636262dce65b3',
SSV_NETWORK_VIEWS_ADDRESS: '0x8dB45282d7C4559fd093C26f677B3837a5598914',
SSV_NETWORK_ADDRESS: '0xC3CD9A0aE89Fff83b71b58b6512D43F8a41f363D',
SSV_VIEWS_ADDRESS: '0xAE2C84c48272F5a1746150ef333D5E5B51F68763',
SSV_TOKEN_ADDRESS: '0x3a9f01091C446bdE031E39ea8354647AFef091E7',
SWAP_FACTORY_ADDRESS: '0x1F98431c8aD98523631AE4a59f267346ea31F984',
SWAP_ROUTER_ADDRESS: '0xE592427A0AEce92De3Edee1F18E0157C05861564',
Expand Down
8 changes: 4 additions & 4 deletions contracts/ethereum/helpers/oracle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const linkTokenAddress = process.env.LINK_TOKEN_ADDRESS as string
if (!linkTokenAddress) throw new Error('No link token address provided')
const ssvNetworkAddress = process.env.SSV_NETWORK_ADDRESS as string
if (!ssvNetworkAddress) throw new Error('No ssv network address provided')
const ssvNetworkViewsAddress = process.env.SSV_NETWORK_VIEWS_ADDRESS as string
if (!ssvNetworkViewsAddress) throw new Error('No ssv network views address provided')
const ssvViewsAddress = process.env.SSV_VIEWS_ADDRESS as string
if (!ssvViewsAddress) throw new Error('No ssv views address provided')
const ssvTokenAddress = process.env.SSV_TOKEN_ADDRESS as string
if (!ssvTokenAddress) throw new Error('No ssv token address provided')
const uniswapV3FactoryAddress = process.env.UNISWAP_V3_FACTORY_ADDRESS as string
Expand Down Expand Up @@ -42,7 +42,7 @@ export async function initiateDepositHandler({ manager, signer }: { manager: Cas
const scanner = new Scanner({
provider: ethers.provider,
ssvNetworkAddress,
ssvNetworkViewsAddress
ssvViewsAddress
})

const cluster = await scanner.getCluster({
Expand Down Expand Up @@ -176,7 +176,7 @@ export async function reportCompletedExitsHandler({ manager, views, signer, args
const scanner = new Scanner({
provider: ethers.provider,
ssvNetworkAddress,
ssvNetworkViewsAddress
ssvViewsAddress
})

const cluster = await scanner.getCluster({
Expand Down
2 changes: 1 addition & 1 deletion contracts/ethereum/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ void async function () {
linkRegistryAddress: process.env.LINK_REGISTRY_ADDRESS,
linkTokenAddress: process.env.LINK_TOKEN_ADDRESS,
ssvNetworkAddress: process.env.SSV_NETWORK_ADDRESS,
ssvNetworkViewsAddress: process.env.SSV_NETWORK_VIEWS_ADDRESS,
ssvViewsAddress: process.env.SSV_VIEWS_ADDRESS,
ssvTokenAddress: process.env.SSV_TOKEN_ADDRESS,
swapFactoryAddress: process.env.SWAP_FACTORY_ADDRESS,
swapRouterAddress: process.env.SWAP_ROUTER_ADDRESS,
Expand Down
12 changes: 6 additions & 6 deletions contracts/ethereum/scripts/dev.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CasimirManager, CasimirRegistry, ISSVNetworkViews, CasimirViews, CasimirUpkeep, FunctionsOracleFactory, FunctionsBillingRegistry } from '../build/@types'
import { CasimirManager, CasimirRegistry, ISSVViews, CasimirViews, CasimirUpkeep, FunctionsOracleFactory, FunctionsBillingRegistry } from '../build/@types'
import { ethers, network } from 'hardhat'
import { fulfillReport, runUpkeep } from '@casimir/ethereum/helpers/upkeep'
import { round } from '@casimir/ethereum/helpers/math'
import { time, setBalance } from '@nomicfoundation/hardhat-network-helpers'
import ISSVNetworkViewsAbi from '../build/abi/ISSVNetworkViews.json'
import ISSVViewsAbi from '../build/abi/ISSVViews.json'
import { fetchRetry } from '@casimir/fetch'
import { run } from '@casimir/shell'
import { PoolStatus } from '@casimir/types'
Expand Down Expand Up @@ -67,7 +67,7 @@ void async function () {
linkRegistryAddress: process.env.LINK_REGISTRY_ADDRESS,
linkTokenAddress: process.env.LINK_TOKEN_ADDRESS,
ssvNetworkAddress: process.env.SSV_NETWORK_ADDRESS,
ssvNetworkViewsAddress: process.env.SSV_NETWORK_VIEWS_ADDRESS,
ssvViewsAddress: process.env.SSV_VIEWS_ADDRESS,
ssvTokenAddress: process.env.SSV_TOKEN_ADDRESS,
swapFactoryAddress: process.env.SWAP_FACTORY_ADDRESS,
swapRouterAddress: process.env.SWAP_ROUTER_ADDRESS,
Expand All @@ -94,14 +94,14 @@ void async function () {

const registry = await ethers.getContractAt('CasimirRegistry', registryAddress) as CasimirRegistry
const upkeep = await ethers.getContractAt('CasimirUpkeep', upkeepAddress) as CasimirUpkeep
const ssvNetworkViews = await ethers.getContractAt(ISSVNetworkViewsAbi, process.env.SSV_NETWORK_VIEWS_ADDRESS as string) as ISSVNetworkViews
const ssvViewsAddress = await ethers.getContractAt(ISSVViewsAbi, process.env.SSV_VIEWS_ADDRESS as string) as ISSVViews

const preregisteredOperatorIds = process.env.PREREGISTERED_OPERATOR_IDS?.split(',').map(id => parseInt(id)) || [654, 655, 656, 657]
const preregisteredOperatorIds = process.env.PREREGISTERED_OPERATOR_IDS?.split(',').map(id => parseInt(id)) || [156, 157, 158, 159]
if (preregisteredOperatorIds.length < 4) throw new Error('Not enough operator ids provided')
const messengerUrl = process.env.MESSENGER_URL || 'https://nodes.casimir.co/eth/goerli/dkg/messenger'
const preregisteredBalance = ethers.utils.parseEther('10')
for (const operatorId of preregisteredOperatorIds) {
const [operatorOwnerAddress] = await ssvNetworkViews.getOperatorById(operatorId)
const [operatorOwnerAddress] = await ssvViewsAddress.getOperatorById(operatorId)
const currentBalance = await ethers.provider.getBalance(operatorOwnerAddress)
const nextBalance = currentBalance.add(preregisteredBalance)
await setBalance(operatorOwnerAddress, nextBalance)
Expand Down
2 changes: 1 addition & 1 deletion contracts/ethereum/scripts/resources/ssv-network
Loading

0 comments on commit d555ec6

Please sign in to comment.