Skip to content

Commit

Permalink
Make factory contract entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Oct 19, 2023
1 parent 1c30ebd commit df04f36
Show file tree
Hide file tree
Showing 62 changed files with 2,521 additions and 2,485 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
"typescript"
],
"css.lint.unknownAtRules": "ignore",
"jupyter.notebookFileRoot": "${fileDirname}",
"volar.inlayHints.eventArgumentInInlineHandlers": false
}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ echo "USE_SECRETS=false" > .env
| `ETHEREUM_RPC_URL` | Ethereum RPC network URL | `http://127.0.0.1:8545` |
| `NETWORK` | Network name (`mainnet || testnet || hardhat || localhost`) | `localhost` |
| `FORK` | Fork network name (`mainnet || testnet || hardhat`) | `testnet` |
| `MANAGER_ADDRESS` | Manager contract address | (predicted manager address) |
| `VIEWS_ADDRESS` | Views contract address | (predicted views address) |
| `FACTORY_ADDRESS` | Base factory contract address | (predicted factory address) |
| `CRYPTO_COMPARE_API_KEY` | CryptoCompare API key | `` |
| `TUNNEL` | Whether to tunnel local network RPC URLs (for remote wallets) | `false` |
| `MOCK_SERVICES` | Whether to mock backend services | `true` |
Expand Down
12 changes: 3 additions & 9 deletions apps/web/src/composables/environment.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
export default function useEnvironment() {
const domain = window.location.host
const origin = window.location.origin
const managerAddress = import.meta.env.PUBLIC_MANAGER_ADDRESS
if (!managerAddress) throw new Error('No manager address provided')
const viewsAddress = import.meta.env.PUBLIC_VIEWS_ADDRESS
if (!viewsAddress) throw new Error('No views address provided')
const registryAddress = import.meta.env.PUBLIC_REGISTRY_ADDRESS
if (!registryAddress) throw new Error('No registry address provided')
const factoryAddress = import.meta.env.PUBLIC_FACTORY_ADDRESS
if (!factoryAddress) throw new Error('No factory address provided')
const usersUrl = import.meta.env.PUBLIC_USERS_URL || 'http://localhost:4000'
const ethereumUrl = import.meta.env.PUBLIC_ETHEREUM_RPC_URL || 'http://127.0.0.1:8545'
const ledgerType = import.meta.env.PUBLIC_SPECULOS_URL ? 'speculos' : 'usb'
Expand All @@ -22,13 +18,11 @@ export default function useEnvironment() {
ethereumUrl,
origin,
ledgerType,
managerAddress,
registryAddress,
factoryAddress,
speculosUrl,
ssvNetworkAddress,
ssvViewsAddress,
usersUrl,
viewsAddress,
walletConnectProjectId
}
}
8 changes: 4 additions & 4 deletions apps/web/src/composables/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,11 @@ export default function useOperators() {
]

for (const poolId of poolIds) {
const poolDetails = await views.getPool(poolId)
const poolConfig = await views.getPoolConfig(poolId)
const pool = {
...poolDetails,
operatorIds: poolDetails.operatorIds.map(id => id.toNumber()),
reshares: poolDetails.reshares.toNumber()
...poolConfig,
operatorIds: poolConfig.operatorIds.map(id => id.toNumber()),
reshares: poolConfig.reshares.toNumber()
}
if (pool.operatorIds.includes(operatorId)) {
pools.push(pool)
Expand Down
12 changes: 5 additions & 7 deletions common/env/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@ import MOCK_VALIDATORS from './mock/validators.json'

const ETHEREUM_CONTRACTS = {
TESTNET: {
MANAGER_ADDRESS: '0xFBA09a098014b414A4aBD2C1Ca43383Ad63f8492',
REGISTRY_ADDRESS: '0x5c118E76cCfBEAd615BBB2B485c0729c69CEac1a',
UPKEEP_ADDRESS: '0x449AcFeb4769C283dcB94ae09779A3233A9c3653',
VIEWS_ADDRESS: '0x1EcF11435187dCb07aA758Db006cA98EA381817b',
FACTORY_ADDRESS: '0xFBA09a098014b414A4aBD2C1Ca43383Ad63f8492',

FUNCTIONS_BILLING_REGISTRY_ADDRESS: '0x736fe8342E7BA5bF50757D266391b675394D9458',
FUNCTIONS_ORACLE_ADDRESS: '0x599E62F28a185c2F68c6DC82CD7dDd450C44d587',
FUNCTIONS_ORACLE_FACTORY_ADDRESS: '0x45b277aD532172c9DDc079729F233875fD8B649D',

MANAGER_BEACON_ADDRESS: '',
POOL_BEACON_ADDRESS: '0x443d84cB8b116B9620F6807280160E8C6d6D4b5e',
REGISTRY_BEACON_ADDRESS: '0x8E1539E198CB13dB0abce5CBB62a34eA2E0aF513',
UPKEEP_BEACON_ADDRESS: '0xEeBc166D29A19cA47d2D15B2f0c3Fe1211F50821',

BEACON_DEPOSIT_ADDRESS: '0xff50ed3d0ec03aC01D4C79aAd74928BFF48a7b2b',
DAO_ORACLE_ADDRESS: '',
DEPOSIT_CONTRACT_ADDRESS: '0xff50ed3d0ec03aC01D4C79aAd74928BFF48a7b2b',
KEEPER_REGISTRAR_ADDRESS: '0x57A4a13b35d25EE78e084168aBaC5ad360252467',
KEEPER_REGISTRY_ADDRESS: '0xE16Df59B887e3Caa439E0b29B42bA2e7976FD8b2',
LINK_ETH_FEED_ADDRESS: '0xb4c4a493AB6356497713A78FFA6c60FB53517c63',
Expand All @@ -42,8 +40,8 @@ enum ETHEREUM_RPC_URL {

const ETHEREUM_SIGNERS = {
TESTNET: {
OWNER_ADDRESS: '0x5FbDB2315678afecb367f032d93F642f64180aa3',
DAO_ORACLE_ADDRESS: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512'
DAO_ORACLE_ADDRESS: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
OWNER_ADDRESS: '0x5FbDB2315678afecb367f032d93F642f64180aa3'
}
}

Expand Down
57 changes: 1 addition & 56 deletions common/env/src/mock/validators.json

Large diffs are not rendered by default.

60 changes: 31 additions & 29 deletions common/events/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ethers } from 'ethers'
export function getEventsIterable(input: {
contractFilters: {
abi: string[]
address: string
addresses: string[]
events: string[]
}[]
ethereumUrl?: string
Expand All @@ -16,36 +16,38 @@ export function getEventsIterable(input: {
const queue: ethers.Event[][] = []
const enqueue = (...args: ethers.Event[]) => queue.push(args)
for (const filter of input.contractFilters) {
const contract = new ethers.Contract(
filter.address,
filter.abi,
provider
) as ethers.Contract
if (input.startBlock !== undefined) {
for (const event of filter.events) {
const historicalEvents = await contract.queryFilter(
event,
input.startBlock,
'latest'
)
for (const historicalEvent of historicalEvents) {
enqueue(historicalEvent)
for (const address of filter.addresses) {
const contract = new ethers.Contract(
address,
filter.abi,
provider
) as ethers.Contract
if (input.startBlock !== undefined) {
for (const event of filter.events) {
const historicalEvents = await contract.queryFilter(
event,
input.startBlock,
'latest'
)
for (const historicalEvent of historicalEvents) {
enqueue(historicalEvent)
}
}
}
}
for (const event of filter.events) {
contract.on(event, enqueue)
while (true) {
if (queue.length === 0) {
await new Promise<void>((resolve) => {
const waitListener = () => {
contract.off(event, waitListener)
resolve()
}
contract.on(event, waitListener)
})
} else {
yield queue.shift()
for (const event of filter.events) {
contract.on(event, enqueue)
while (true) {
if (queue.length === 0) {
await new Promise<void>((resolve) => {
const waitListener = () => {
contract.off(event, waitListener)
resolve()
}
contract.on(event, waitListener)
})
} else {
yield queue.shift()
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions common/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { LoginCredentials } from './interfaces/LoginCredentials'
import { MessageRequest } from './interfaces/MessageRequest'
import { Operator } from './interfaces/Operator'
import { OperatorAddedSuccess } from './interfaces/OperatorAddedSuccess'
import { Pool } from './interfaces/Pool'
import { PoolConfig } from './interfaces/PoolConfig'
import { PoolStatus } from './interfaces/PoolStatus'
import { ProviderString } from './interfaces/ProviderString'
import { SignInWithEthereumCredentials } from './interfaces/SignInWithEthereumCredentials'
Expand Down Expand Up @@ -62,7 +62,7 @@ export type {
MessageRequest,
Operator,
OperatorAddedSuccess,
Pool,
PoolConfig,
ProviderString,
SignInWithEthereumCredentials,
TransactionRequest,
Expand Down
1 change: 0 additions & 1 deletion common/types/src/interfaces/Account.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BalanceSnapshot } from './BalanceSnapshot'
import { ProviderString } from './ProviderString'
import { Currency } from './Currency'
import { Pool } from './Pool'

export interface Account {
/** The address of the current account */
Expand Down
6 changes: 3 additions & 3 deletions common/types/src/interfaces/ContractEventsByAddress.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export interface ContractEventsByAddress {
CompletedExitReportsRequested?: number;
DepositActivated?: number;
DepositInitiated?: number;
DepositRequested?: number;
PoolActivated?: number;
PoolInitiated?: number;
InitiationRequested?: number;
ExitCompleted?: number;
ExitRequested?: number;
ForcedExitReportsRequested?: number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ethers } from 'ethers'

export interface Pool {
id: number;
export interface PoolConfig {
poolAddress: string;
balance: ethers.BigNumber;
publicKey: string;
operatorIds: number[];
publicKey: string;
reshares: number;
status: number;
}
1 change: 1 addition & 0 deletions common/types/src/interfaces/PoolStatus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export enum PoolStatus {
INACTIVE,
PENDING,
ACTIVE,
EXITING_FORCED,
Expand Down
6 changes: 3 additions & 3 deletions common/types/src/interfaces/RegisteredOperator.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { PoolConfig } from './PoolConfig'
import { Operator } from '@casimir/ssv'
import { Pool } from './Pool'

export interface RegisteredOperator extends Operator {
active: boolean
collateral: string
poolCount: number
pools: Pool[]
url: string
pools: PoolConfig[]
resharing: boolean
url: string
}
15 changes: 15 additions & 0 deletions contracts/ethereum/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"overrides": [
{
"files": "*.sol",
"options": {
"printWidth": 120,
"tabWidth": 4,
"useTabs": false,
"singleQuote": false,
"bracketSpacing": false,
"explicitTypes": "preserve"
}
}
]
}
5 changes: 3 additions & 2 deletions contracts/ethereum/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ src = 'src/v1'
out = 'build/foundry'
libs = ['lib', 'node_modules']
test = 'test'
cache_path = 'build/foundry/cache'
cache_path = 'build/foundry/cache'
solc_version = 'none'

[doc]
title = 'Casimir Ethereum Docs'
out = 'build/foundry/docs'
out = 'build/foundry/docs'
8 changes: 3 additions & 5 deletions contracts/ethereum/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import '@nomiclabs/hardhat-ethers'
import '@nomicfoundation/hardhat-toolbox'
import '@openzeppelin/hardhat-upgrades'
import 'hardhat-abi-exporter'
import 'hardhat-contract-sizer'
import 'hardhat-preprocessor'
import { ETHEREUM_CONTRACTS, ETHEREUM_RPC_URL, ETHEREUM_SIGNERS, HARDHAT_NETWORK_KEY } from '@casimir/env'
import './tasks/query'
Expand All @@ -30,7 +31,7 @@ const forkConfig = { url: forkUrl, blockNumber: parseInt(process.env.ETHEREUM_FO
const hardhatKey = hardhatNetwork?.toUpperCase() as keyof typeof HARDHAT_NETWORK_KEY
const networkKey = HARDHAT_NETWORK_KEY[hardhatKey] || 'TESTNET'

process.env.BEACON_DEPOSIT_ADDRESS = ETHEREUM_CONTRACTS[networkKey].BEACON_DEPOSIT_ADDRESS
process.env.DEPOSIT_CONTRACT_ADDRESS = ETHEREUM_CONTRACTS[networkKey].DEPOSIT_CONTRACT_ADDRESS
process.env.KEEPER_REGISTRAR_ADDRESS = ETHEREUM_CONTRACTS[networkKey].KEEPER_REGISTRAR_ADDRESS
process.env.KEEPER_REGISTRY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].KEEPER_REGISTRY_ADDRESS
process.env.LINK_ETH_FEED_ADDRESS = ETHEREUM_CONTRACTS[networkKey].LINK_ETH_FEED_ADDRESS
Expand All @@ -46,10 +47,7 @@ if (hardhatNetwork !== 'localhost') {
process.env.ETHEREUM_RPC_URL = process.env.ETHEREUM_RPC_URL || ETHEREUM_RPC_URL[networkKey]
process.env.OWNER_ADDRESS = ETHEREUM_SIGNERS[networkKey].OWNER_ADDRESS
process.env.DAO_ORACLE_ADDRESS = ETHEREUM_SIGNERS[networkKey].DAO_ORACLE_ADDRESS
process.env.MANAGER_ADDRESS = ETHEREUM_CONTRACTS[networkKey].MANAGER_ADDRESS
process.env.REGISTRY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].REGISTRY_ADDRESS
process.env.UPKEEP_ADDRESS = ETHEREUM_CONTRACTS[networkKey].UPKEEP_ADDRESS
process.env.VIEWS_ADDRESS = ETHEREUM_CONTRACTS[networkKey].VIEWS_ADDRESS
process.env.FACTORY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].FACTORY_ADDRESS
process.env.FUNCTIONS_BILLING_REGISTRY_ADDRESS = ETHEREUM_CONTRACTS[networkKey].FUNCTIONS_BILLING_REGISTRY_ADDRESS
process.env.FUNCTIONS_ORACLE_ADDRESS = ETHEREUM_CONTRACTS[networkKey].FUNCTIONS_ORACLE_ADDRESS
}
Expand Down
Loading

0 comments on commit df04f36

Please sign in to comment.