Skip to content

Commit

Permalink
Complete foundry integration
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Jul 28, 2023
1 parent 9ed809c commit 172d416
Show file tree
Hide file tree
Showing 46 changed files with 930 additions and 2,664 deletions.
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged && npm run docgen && git add contracts/ethereum/docs
npx lint-staged
10 changes: 5 additions & 5 deletions apps/web/src/composables/contracts.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ref } from 'vue'
import { ethers } from 'ethers'
import { CasimirManager, CasimirViews } from '@casimir/ethereum/build/artifacts/types'
import CasimirManagerJson from '@casimir/ethereum/build/artifacts/src/v1/CasimirManager.sol/CasimirManager.json'
import CasimirViewsJson from '@casimir/ethereum/build/artifacts/src/v1/CasimirManager.sol/CasimirManager.json'
import { CasimirManager, CasimirViews } from '@casimir/ethereum/build/@types'
import ICasimirManagerAbi from '@casimir/ethereum/build/abi/ICasimirManager.json'
import ICasimirViewsAbi from '@casimir/ethereum/build/abi/ICasimirManager.json'
import useEnvironment from './environment'
import useEthers from '@/composables/ethers'
import useLedger from '@/composables/ledger'
Expand All @@ -29,8 +29,8 @@ const totalWalletBalance = ref<BreakdownAmount>({

const { ethereumUrl, managerAddress, viewsAddress } = useEnvironment()
const provider = new ethers.providers.JsonRpcProvider(ethereumUrl)
const manager: CasimirManager & ethers.Contract = new ethers.Contract(managerAddress, CasimirManagerJson.abi) as CasimirManager
const views: CasimirViews & ethers.Contract = new ethers.Contract(viewsAddress, CasimirViewsJson.abi) as CasimirViews
const manager: CasimirManager & ethers.Contract = new ethers.Contract(managerAddress, ICasimirManagerAbi) as CasimirManager
const views: CasimirViews & ethers.Contract = new ethers.Contract(viewsAddress, ICasimirViewsAbi) as CasimirViews

export default function useContracts() {
const { ethersProviderList, getEthersBalance, getEthersBrowserSigner } = useEthers()
Expand Down
5 changes: 4 additions & 1 deletion common/ssv/src/interfaces/ScannerOptions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { ethers } from 'ethers'

export interface ScannerOptions {
ethereumUrl: string
ethereumUrl?: string
provider?: ethers.providers.JsonRpcProvider
ssvNetworkAddress: string
ssvNetworkViewsAddress: string
}
16 changes: 10 additions & 6 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/artifacts/types'
import ISSVNetworkJson from '@casimir/ethereum/build/artifacts/scripts/resources/ssv-network/contracts/ISSVNetwork.sol/ISSVNetwork.json'
import ISSVNetworkViewsJson from '@casimir/ethereum/build/artifacts/scripts/resources/ssv-network/contracts/ISSVNetworkViews.sol/ISSVNetworkViews.json'
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 { ClusterDetailsInput } from '../interfaces/ClusterDetailsInput'
import { ClusterDetails } from '../interfaces/ClusterDetails'
import { Cluster } from '@casimir/types'
Expand All @@ -24,9 +24,13 @@ export class Scanner {
ssvNetworkViews: ISSVNetworkViews & ethers.Contract

constructor(options: ScannerOptions) {
this.provider = new ethers.providers.JsonRpcProvider(options.ethereumUrl)
this.ssvNetwork = new ethers.Contract(options.ssvNetworkAddress, ISSVNetworkJson.abi, this.provider) as ISSVNetwork & ethers.Contract
this.ssvNetworkViews = new ethers.Contract(options.ssvNetworkViewsAddress, ISSVNetworkViewsJson.abi, this.provider) as ISSVNetworkViews & ethers.Contract
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
}

/**
Expand Down
5 changes: 4 additions & 1 deletion common/uniswap/src/interfaces/FactoryOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { ethers } from 'ethers'

export interface FactoryOptions {
ethereumUrl: string
ethereumUrl?: string
provider?: ethers.providers.JsonRpcProvider
uniswapV3FactoryAddress: string
}
16 changes: 10 additions & 6 deletions common/uniswap/src/providers/factory.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { ethers } from 'ethers'
import { FactoryOptions } from '../interfaces/FactoryOptions'
import { PriceInput } from '../interfaces/PriceInput'
import IUniswapV3FactoryJson from '@casimir/ethereum/build/artifacts/@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol/IUniswapV3Factory.json'
import IUniswapV3PoolStateJson from '@casimir/ethereum/build/artifacts/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolState.sol/IUniswapV3PoolState.json'
import { IUniswapV3Factory, IUniswapV3PoolState } from '@casimir/ethereum/build/artifacts/types'
import IUniswapV3FactoryAbi from '@casimir/ethereum/build/abi/IUniswapV3Factory.json'
import IUniswapV3PoolStateAbi from '@casimir/ethereum/build/abi/IUniswapV3PoolState.json'
import { IUniswapV3Factory, IUniswapV3PoolState } from '@casimir/ethereum/build/@types'

export class Factory {
provider: ethers.providers.JsonRpcProvider
uniswapV3Factory: IUniswapV3Factory & ethers.Contract

constructor(options: FactoryOptions) {
this.provider = new ethers.providers.JsonRpcProvider(options.ethereumUrl)
this.uniswapV3Factory = new ethers.Contract(options.uniswapV3FactoryAddress, IUniswapV3FactoryJson.abi, this.provider) as IUniswapV3Factory & ethers.Contract
if (options.provider) {
this.provider = options.provider
} else {
this.provider = new ethers.providers.JsonRpcProvider(options.ethereumUrl)
}
this.uniswapV3Factory = new ethers.Contract(options.uniswapV3FactoryAddress, IUniswapV3FactoryAbi, this.provider) as IUniswapV3Factory & ethers.Contract
}

/**
Expand All @@ -22,7 +26,7 @@ export class Factory {
getSwapPrice = async (input: PriceInput): Promise<number> => {
const { tokenIn, tokenOut, uniswapFeeTier } = input
const poolAddress = await this.uniswapV3Factory.getPool(tokenIn, tokenOut, uniswapFeeTier)
const poolContract = new ethers.Contract(poolAddress, IUniswapV3PoolStateJson.abi, this.provider) as IUniswapV3PoolState & ethers.Contract
const poolContract = new ethers.Contract(poolAddress, IUniswapV3PoolStateAbi, this.provider) as IUniswapV3PoolState & ethers.Contract
const slot0 = await poolContract.slot0()
const tick = slot0.tick
return 1.0001 ** tick
Expand Down
Loading

0 comments on commit 172d416

Please sign in to comment.