Skip to content

Commit

Permalink
Fix empty contract bug
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejearley committed Oct 26, 2023
1 parent 741cb4e commit 28c2241
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 42 deletions.
3 changes: 2 additions & 1 deletion apps/docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export default withMermaid({
items: [
{ text: 'Address Registry', link: '/reference/address-registry' },
{ text: 'Solidity API', link: '/reference/solidity-api' },
{ text: 'Contract Source', link: 'https://github.com/consensusnetworks/casimir/tree/master/contracts/ethereum/src/v1' }
{ text: 'Contract Source', link: 'https://github.com/consensusnetworks/casimir/tree/master/contracts/ethereum/src/v1' },
{ text: 'Hacken Audit', link: `${process.env.DOCS_URL}/hacken-audit.pdf` }
]
}
],
Expand Down
Binary file added apps/docs/src/public/hacken-audit.pdf
Binary file not shown.
46 changes: 21 additions & 25 deletions apps/web/src/composables/operators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export default function useOperators() {
const loadingRegisteredOperators = ref(false)
const loadingRegisteredOperatorsError = ref(false)

const nonregisteredDefaultOperators = ref<Operator[]>([])
const nonregisteredBaseOperators = ref<Operator[]>([])
const nonregisteredEigenOperators = ref<Operator[]>([])
const registeredDefaultOperators = ref<Operator[]>([])
const registeredBaseOperators = ref<Operator[]>([])
const registeredEigenOperators = ref<Operator[]>([])

async function addOperator({ address, nodeUrl }: { address: string, nodeUrl: string }) {
Expand All @@ -57,14 +57,14 @@ export default function useOperators() {
loadingAddOperator.value = false
return { error, message }
} catch (error: any) {
throw new Error(error.message || 'Error adding operator')
loadingAddOperatorError.value = true
throw new Error(error.message || 'Error adding operator')
}
}

async function getUserOperators(): Promise<void> {
const userAddresses = user.value?.accounts.map((account: Account) => account.address) as string[]

const scanner = new Scanner({
ethereumUrl,
ssvNetworkAddress,
Expand All @@ -77,27 +77,23 @@ export default function useOperators() {
ssvOperators.push(...userOperators)
}

const defaultCasimirOperators = await _getRegisteredOperators(ssvOperators, 'default')
const eigenCasimirOperators = await _getRegisteredOperators(ssvOperators, 'eigen')
registeredBaseOperators.value = await _getRegisteredOperators(ssvOperators, 'base') as Array<RegisteredOperator>
registeredEigenOperators.value = await _getRegisteredOperators(ssvOperators, 'eigen') as Array<RegisteredOperator>

const nonregDefaultOperators = ssvOperators.filter((operator: any) => {
const idRegistered = defaultCasimirOperators.find((registeredOperator: any) => registeredOperator.id === operator.id)
nonregisteredBaseOperators.value = ssvOperators.filter((operator: any) => {
const idRegistered = registeredBaseOperators.value.find((registeredOperator: any) => registeredOperator.id === operator.id)
return !idRegistered
})
const nonregEigenOperators = ssvOperators.filter((operator: any) => {
const idRegistered = eigenCasimirOperators.find((registeredOperator: any) => registeredOperator.id === operator.id)
}) as Array<Operator>
nonregisteredEigenOperators.value = ssvOperators.filter((operator: any) => {
const idRegistered = registeredEigenOperators.value.find((registeredOperator: any) => registeredOperator.id === operator.id)
return !idRegistered
})

nonregisteredDefaultOperators.value = nonregDefaultOperators as Array<Operator>
nonregisteredEigenOperators.value = nonregEigenOperators as Array<Operator>
registeredDefaultOperators.value = defaultCasimirOperators as Array<RegisteredOperator>
registeredEigenOperators.value = eigenCasimirOperators as Array<RegisteredOperator>
}) as Array<Operator>
}

async function _getRegisteredOperators(ssvOperators: Operator[], type: 'default' | 'eigen'): Promise<RegisteredOperator[]> {
async function _getRegisteredOperators(ssvOperators: Operator[], type: 'base' | 'eigen'): Promise<RegisteredOperator[]> {
const casimirOperators: RegisteredOperator[] = []
const registry = type === 'default' ? baseRegistry : eigenRegistry
const registry = type === 'base' ? baseRegistry : eigenRegistry
if (registry.address === ethers.constants.AddressZero) return casimirOperators
for (const operator of ssvOperators) {
const { active, collateral, poolCount, resharing } = await (registry as CasimirRegistry).getOperator(operator.id)
const registered = active || collateral.gt(0) || poolCount.gt(0) || resharing
Expand Down Expand Up @@ -129,10 +125,10 @@ export default function useOperators() {
return casimirOperators
}

async function _getPools(operatorId: number, type: 'default' | 'eigen'): Promise<PoolConfig[]> {
async function _getPools(operatorId: number, type: 'base' | 'eigen'): Promise<PoolConfig[]> {
const pools: PoolConfig[] = []

const defaultPoolIds = [
const basePoolIds = [
...await (baseManager as CasimirManager).getPendingPoolIds(),
...await (baseManager as CasimirManager).getStakedPoolIds()
]
Expand All @@ -141,8 +137,8 @@ export default function useOperators() {
...await (eigenManager as CasimirManager).getStakedPoolIds()
]

const poolIds = type === 'default' ? defaultPoolIds : eigenPoolIds
const views = type === 'default' ? baseViews : eigenViews
const poolIds = type === 'base' ? basePoolIds : eigenPoolIds
const views = type === 'base' ? baseViews : eigenViews

for (const poolId of poolIds) {
const poolConfig = await (views as CasimirViews).getPoolConfig(poolId)
Expand Down Expand Up @@ -227,9 +223,9 @@ export default function useOperators() {
}

return {
nonregisteredDefaultOperators: readonly(nonregisteredDefaultOperators),
nonregisteredBaseOperators: readonly(nonregisteredBaseOperators),
nonregisteredEigenOperators: readonly(nonregisteredEigenOperators),
registeredDefaultOperators: readonly(registeredDefaultOperators),
registeredBaseOperators: readonly(registeredBaseOperators),
registeredEigenOperators: readonly(registeredEigenOperators),
loadingAddOperator: readonly(loadingAddOperator),
loadingAddOperatorError: readonly(loadingAddOperatorError),
Expand Down
26 changes: 13 additions & 13 deletions apps/web/src/pages/operators/Operator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const { convertString } = useFormat()
const {
initializeOperatorComposable,
registerOperatorWithCasimir,
nonregisteredDefaultOperators,
nonregisteredBaseOperators,
nonregisteredEigenOperators,
registeredDefaultOperators,
registeredBaseOperators,
registeredEigenOperators,
loadingInitializeOperators,
loadingAddOperator
Expand All @@ -36,18 +36,18 @@ const onSelectWalletBlur = () => {
}, 200)
}
const operatorType = ref<'default' | 'eigen'>('default')
const operatorType = ref<'base' | 'eigen'>('base')
const eigenIsShining = ref(true) // Determines if the shine effect is active
const eigenIsToggled = ref(false) // Determines the toggle state
const toggleBackgroundColor = ref('#eee') // Initial color
function toggleEigenLayerSupport() {
eigenIsToggled.value = !eigenIsToggled.value
toggleBackgroundColor.value = eigenIsToggled.value ? 'green' : '#eee'
operatorType.value = eigenIsToggled.value ? 'eigen' : 'default'
operatorType.value = eigenIsToggled.value ? 'eigen' : 'base'
// Update stakeType
// stakeType.value = eigenIsToggled.value ? 'eigen' : 'default'
// stakeType.value = eigenIsToggled.value ? 'eigen' : 'base'
}
const selectedOperatorID = ref()
Expand Down Expand Up @@ -148,9 +148,9 @@ watch(selectedWallet, async () =>{
if (selectedWallet.value.address === '') {
availableOperatorIDs.value = []
} else if(operatorType.value === 'default') {
if (nonregisteredDefaultOperators.value && nonregisteredDefaultOperators.value.length > 0) {
availableOperatorIDs.value = [...nonregisteredDefaultOperators.value].filter((operator: any) => operator.ownerAddress === selectedWallet.value.address).map((operator: any) => operator.id)
} else if(operatorType.value === 'base') {
if (nonregisteredBaseOperators.value && nonregisteredBaseOperators.value.length > 0) {
availableOperatorIDs.value = [...nonregisteredBaseOperators.value].filter((operator: any) => operator.ownerAddress === selectedWallet.value.address).map((operator: any) => operator.id)
} else if (nonregisteredEigenOperators.value && nonregisteredEigenOperators.value.length > 0) {
availableOperatorIDs.value = [...nonregisteredEigenOperators.value].filter((operator: any) => operator.ownerAddress === selectedWallet.value.address).map((operator: any) => operator.id)
} else {
Expand All @@ -159,9 +159,9 @@ watch(selectedWallet, async () =>{
}
})
watch([registeredDefaultOperators, registeredEigenOperators], () => {
watch([registeredBaseOperators, registeredEigenOperators], () => {
openAddOperatorModal.value = false
tableData.value = [...registeredDefaultOperators.value, ...registeredEigenOperators.value].map((operator: any) => {
tableData.value = [...registeredBaseOperators.value, ...registeredEigenOperators.value].map((operator: any) => {
return {
id: operator.id,
walletAddress: operator.ownerAddress,
Expand Down Expand Up @@ -384,7 +384,7 @@ watch([loadingSessionLogin || loadingInitializeOperators], () =>{
<p class="text-sm">
Learn how to set up a Casimir operator using
<a
:href="docsUrl"
:href="`${docsUrl}/guide/operating`"
target="_blank"
class="text-primary underline"
>
Expand Down Expand Up @@ -441,7 +441,7 @@ watch([loadingSessionLogin || loadingInitializeOperators], () =>{
class="z-[3] absolute top-[110%] left-0 w-full border rounded-[8px] border-[#D0D5DD] p-[15px] bg-white max-h-[200px] overflow-auto"
>
<h6 class="text-[16px]">
Your Connected4Wallets
Your Connected Wallets
</h6>
<button
v-for="act in user.accounts"
Expand Down Expand Up @@ -521,7 +521,7 @@ watch([loadingSessionLogin || loadingInitializeOperators], () =>{
class="z-[3] absolute top-[110%] left-0 w-full border rounded-[8px] border-[#D0D5DD] p-[15px] bg-white max-h-[200px] overflow-auto"
>
<h6 class="text-[16px]">
Avaliable Operators34
Available Operators
</h6>
<div
v-if="availableOperatorIDs.length === 0"
Expand Down
5 changes: 2 additions & 3 deletions services/users/src/routes/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import express from 'express'
import { verifySession } from 'supertokens-node/recipe/session/framework/express'
import { SessionRequest } from 'supertokens-node/framework/express'
import useDB from '../providers/db'
import { UserWithAccountsAndOperators } from '@casimir/types'

const router = express.Router()
const { addAccount, addOperator, getAccounts, getUserByAddress, getUserById, updateUserAddress, updateUserAgreedToTermsOfService, removeAccount } = useDB()

router.get('/', verifySession(), async (req: SessionRequest, res: express.Response) => {
try {
const id = req.session?.getUserId() as string
console.log('getting user by id :>> ', id)
const user = await getUserById(id)
console.log('user in user home route :>> ', user)
const message = user ? 'User found' : 'User not found'
res.setHeader('Content-Type', 'application/json')
res.status(200)
Expand Down Expand Up @@ -129,7 +128,7 @@ router.get('/check-secondary-address/:address', async (req: express.Request, res
const users = await Promise.all(accounts.map(async account => {
const { userId } = account
const user = await getUserById(userId)
const { address, walletProvider } = user
const { address, walletProvider } = user as UserWithAccountsAndOperators
return {
address: maskAddress(address),
walletProvider,
Expand Down

0 comments on commit 28c2241

Please sign in to comment.