Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eigen stake #462

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/promote.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

# Skip any pushes from the act CLI
# Comment out for testing
if: ${{ github.actor != "nektos/act" }}
if: ${{ github.actor != 'nektos/act' }}

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
aws-region: ${{ env.AWS_REGION }}

- name: Install and build all package dependencies
run: npm ci
run: npm ci --omit=optional

- name: Test cdk deployment
run: npm run test:cdk
4 changes: 2 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:

# Skip any pushes with commit flag "(skip deploy)"
# Comment out for testing
if: ${{ !contains(github.event.head_commit.message, "(skip deploy)") }}
if: ${{ !contains(github.event.head_commit.message, '(skip deploy)') }}

steps:
- name: Checkout the repo with submodules
Expand All @@ -40,7 +40,7 @@ jobs:
curl -sSf https://atlasgo.sh | sh

- name: Install and build all package dependencies
run: npm ci
run: npm ci --omit=optional

- name: Deploy cdk infrastructure
run: npm run deploy:cdk
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
# curl -sSf https://atlasgo.sh | sh

- name: Install and build all package dependencies
run: npm ci
run: npm ci --omit=optional

- name: Deploy CDK infrastructure
run: npm run deploy:cdk
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/sandbox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

# Skip any pushes with commit flag "(skip deploy)"
# Comment out for testing
if: ${{ !contains(github.event.head_commit.message, "(skip deploy)") }}
if: ${{ !contains(github.event.head_commit.message, '(skip deploy)') }}

steps:
- name: Checkout the repo with submodules
Expand All @@ -43,7 +43,7 @@ jobs:
curl -sSf https://atlasgo.sh | sh

- name: Install and build all package dependencies
run: npm ci
run: npm ci --omit=optional
env:
PUBLIC_STAGE: ${{ env.STAGE }}

Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ cdk-outputs.json

services/crawler/.env

.out
.out
dist
build
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
path = services/oracle/lib/dkg
url = https://github.com/consensusnetworks/ssv-dkg.git
branch = update/makefile
[submodule "contracts/ethereum/lib/eigenlayer-contracts"]
path = contracts/ethereum/lib/eigenlayer-contracts
url = https://github.com/Layr-Labs/eigenlayer-contracts.git
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"volar.inlayHints.eventArgumentInInlineHandlers": false
"volar.inlayHints.eventArgumentInInlineHandlers": false,
"deno.enable": true,
"deno.enablePaths": [
"./services/functions/request/scripts",
"./services/functions/request/src"
]
}
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ Configure the following prerequisite global dependency versions:

> 🚩 **Using NVM**: Install [NVM](https://github.com/nvm-sh/nvm?tab=readme-ov-file#installing-and-updating) and run `nvm install --lts && nvm alias default lts/*` to set the default version to the latest LTS. You will need to rerun this command whenever the latest LTS changes.
5. [AWS CLI (v2.x)](https://aws.amazon.com/cli).
5. [Deno (v1.39.x)](https://docs.deno.com/runtime/manual/getting_started/installation).

6. [AWS CLI (v2.x)](https://aws.amazon.com/cli).

> 🚩 **Consensus Networks team only**: Create an [AWS profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) named `consensus-networks-dev`.
Expand Down
10 changes: 5 additions & 5 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.3.8"
"vue": "^3.3.13"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.2.3",
"@vitejs/plugin-vue": "^4.5.0",
"@vitejs/plugin-vue": "^4.5.2",
"rollup-plugin-polyfill-node": "^0.13.0",
"typescript": "^5.2.2",
"vite": "^5.0.0",
"vue-tsc": "^1.8.22"
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vue-tsc": "^1.8.25"
}
}
2 changes: 1 addition & 1 deletion apps/docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default withMermaid({
items: [
{ text: 'What is Casimir?', link: '/introduction/what-is-casimir' },
{ text: 'Architecture', link: '/introduction/architecture' },
{ text: 'Staking Strategies', link: '/introduction/staking-strategies' },
{ text: 'Stake Configs', link: '/introduction/stake-configs' },
{ text: 'User Accounts', link: '/introduction/user-accounts' }
]
},
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "echo \"Error: no test specified\" && exit 1"
},
"devDependencies": {
"@types/node": "^17.0.38",
"@types/node": "^20.10.5",
"dotenv": "^16.3.1",
"esno": "0.17.0",
"markdown-it-mathjax3": "^4.3.2",
Expand Down
29 changes: 23 additions & 6 deletions apps/docs/src/guide/staking.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@ Let:
- $F_t$ be the total fee percentage, which is a sum of the required ETH, LINK, and SSV fees.
- $D$ be the amount of ETH deposited by the user.
- $E$ be the amount of ETH to be allocated for the contract's operations.
- $F_a$ be the ETH amount to be swapped for LINK and SSV to facilitate the contract's functions.

Given the 5% fee, the ETH to be allocated for the contract's operations is calculated as:
$E = D \times \frac{100}{100 + F_t}$

The amount to be converted to LINK and SSV is:
$F_a = D - E$

Where:

- $F_t$ typically equals 5%.
- $D$ is the amount of ETH the user wants to deposit.
- $E$ represents the actual ETH amount that will be added to the contract after deducting the fee.
- $F_a$ is the remaining ETH that will be used to acquire LINK and SSV.

## Stake Balances

Expand All @@ -57,4 +52,26 @@ Where:

## Stake Withdrawals

You can request a withdrawal of any amount of your stake at any time. If the requested amount is available in the manager's withdrawable balance (prepooled balance plus withdrawn balance), the withdrawal is fulfilled immediately. Otherwise, the withdrawal is added to the pending withdrawals queue and fulfilled when the requested amount is available (usually within 1-4 days, depending on the amount).
You can request a withdrawal of any amount of your stake at any time. If the requested amount is available in the manager's withdrawable balance (prepooled balance plus withdrawn balance), the withdrawal is fulfilled immediately. Otherwise, the withdrawal is added to the pending withdrawals queue and fulfilled when the requested amount is available (usually within 1-4 days, depending on the amount).

## Stake Events

When your stake balance changes, the manager contract emits:

- A [stake deposited](#stake-deposited) event when you deposit ETH to the manager contract.
- A [stake rebalanced](#stake-rebalanced) event when your stake balance is updated due to a change in the total reward-to-stake ratio sum after a new report.
- A [withdrawal requested](#withdrawal-requested) event when you request a withdrawal of your stake.

### Stake Deposited

The `StakeDeposited` event is emitted when you deposit ETH to the manager contract.

```solidity
event StakeDeposited(address sender, uint256 amount)
```

The event's parameters are:

- `sender`: Address of the staker who deposited ETH.
- `amount`: Amount of ETH deposited after fees.

7 changes: 7 additions & 0 deletions apps/docs/src/introduction/stake-configs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
::: warning
This page is incomplete.
:::

# Stake Configs

The simple stake config provides secure and reliable native ETH rewards from an open registry of performant SSV operators. Casimir will deploy additonal stake configs with different registry requirements and opt-in features for stakers and operators. Our simple restake config will allow stakers and operators to participate in creating and managing native EigenLayer pods with less (or more) than 32 ETH.
11 changes: 0 additions & 11 deletions apps/docs/src/introduction/staking-strategies.md

This file was deleted.

27 changes: 13 additions & 14 deletions apps/mvp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,23 @@
"d3": "^7.8.1",
"ethers": "^5.7.2",
"feather-icons": "^4.29.0",
"sass": "^1.69.1",
"sass": "^1.69.5",
"supertokens-web-js": "^0.5.0",
"util": "^0.12.5",
"vue": "^3.2.25",
"vue": "^3.3.13",
"vue-feather": "^2.0.0",
"vue-router": "^4.0.15",
"web3": "^1.8.1",
"xlsx": "^0.18.5"
"vue-router": "^4.2.5",
"web3": "^4.3.0"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.1.0",
"@vitejs/plugin-vue": "^4.2.3",
"autoprefixer": "^10.4.14",
"postcss": "^8.4.27",
"rollup-plugin-polyfill-node": "^0.12.0",
"tailwindcss": "^3.3.3",
"typescript": "^5.1.6",
"vite": "^4.4.7",
"vue-tsc": "^1.8.7"
"@rollup/plugin-node-resolve": "^15.2.3",
"@vitejs/plugin-vue": "^4.5.2",
"autoprefixer": "^10.4.16",
"postcss": "^8.4.32",
"rollup-plugin-polyfill-node": "^0.13.0",
"tailwindcss": "^3.4.0",
"typescript": "^5.3.3",
"vite": "^5.0.10",
"vue-tsc": "^1.8.25"
}
}
45 changes: 20 additions & 25 deletions apps/mvp/src/composables/breakdownMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default function useBreakdownMetrics() {
const addresses = (user.value as UserWithAccountsAndOperators).accounts.map((account: Account) => account.address) as string[]
const currentUserStakePromises = [] as Array<Promise<ethers.BigNumber>>
addresses.forEach(address => currentUserStakePromises.push((baseManager as CasimirManager).getUserStake(address)))
addresses.forEach(address => currentUserStakePromises.push((eigenManager as CasimirManager).getUserStake(address)))
// addresses.forEach(address => currentUserStakePromises.push((eigenManager as CasimirManager).getUserStake(address)))
const settledCurrentUserStakePromises = await Promise.allSettled(currentUserStakePromises) as Array<PromiseFulfilledResult<ethers.BigNumber>>
const currentUserStake = settledCurrentUserStakePromises.filter(result => result.status === "fulfilled").map(result => result.value)
const currentUserStakeSum = currentUserStake.reduce((acc, curr) => acc.add(curr), ethers.BigNumber.from(0))
Expand All @@ -113,33 +113,28 @@ export default function useBreakdownMetrics() {
/* Get User's All Time Deposits and Withdrawals */
const userEventTotalsPromises = [] as Array<Promise<ContractEventsByAddress>>
addresses.forEach(address => {userEventTotalsPromises.push(getContractEventsTotalsByAddress(address, baseManager))})
addresses.forEach(address => {userEventTotalsPromises.push(getContractEventsTotalsByAddress(address, eigenManager))})
// addresses.forEach(address => {userEventTotalsPromises.push(getContractEventsTotalsByAddress(address, eigenManager))})
const userEventTotals = await Promise.all(userEventTotalsPromises) as Array<ContractEventsByAddress>
const userEventTotalsSum = userEventTotals.reduce((acc, curr) => {
const { StakeDeposited, WithdrawalInitiated, WithdrawalRequested, WithdrawalFulfilled } = curr
const { StakeDeposited/*, WithdrawalRequested*/, WithdrawalFulfilled } = curr
return {
StakeDeposited: acc.StakeDeposited + (StakeDeposited || 0),
WithdrawalInitiated: acc.WithdrawalInitiated + (WithdrawalInitiated || 0),
WithdrawalRequested: acc.WithdrawalRequested + (WithdrawalRequested || 0),
// WithdrawalRequested: acc.WithdrawalRequested + (WithdrawalRequested || 0),
WithdrawalFulfilled: acc.WithdrawalFulfilled + (WithdrawalFulfilled || 0)
}
}, {
StakeDeposited: 0,
WithdrawalInitiated: 0,
WithdrawalRequested: 0,
StakeDeposited: 0,
// WithdrawalRequested: 0,
WithdrawalFulfilled: 0
} as { StakeDeposited: number; WithdrawalInitiated: number, WithdrawalRequested: number, WithdrawalFulfilled: number })

} as { StakeDeposited: number/*, WithdrawalRequested: number*/, WithdrawalFulfilled: number })

const stakedDepositedETH = userEventTotalsSum.StakeDeposited
const withdrawalInitiatedETH = userEventTotalsSum.WithdrawalInitiated
const withdrawalRequestedETH = userEventTotalsSum.WithdrawalRequested
// const withdrawalRequestedETH = userEventTotalsSum.WithdrawalRequested
const withdrawalFulfilledETH = userEventTotalsSum.WithdrawalFulfilled


/* Get User's All Time Rewards */
const currentUserStakeMinusEvents =
currentUserStakeETH - stakedDepositedETH + ((withdrawalInitiatedETH) + (withdrawalRequestedETH) + (withdrawalFulfilledETH))
const currentUserStakeMinusEvents = currentUserStakeETH - (stakedDepositedETH - withdrawalFulfilledETH)

return {
eth: `${formatEthersCasimir(currentUserStakeMinusEvents)} ETH`,
usd: `$${formatEthersCasimir(currentUserStakeMinusEvents * (await getCurrentPrice({ coin: "ETH", currency: "USD" })))}`
Expand All @@ -158,8 +153,7 @@ export default function useBreakdownMetrics() {
const eventList = [
"StakeDeposited",
"StakeRebalanced",
"WithdrawalInitiated",
"WithdrawalRequested",
// "WithdrawalRequested",
"WithdrawalFulfilled"
]
const eventFilters = eventList.map(event => {
Expand Down Expand Up @@ -190,8 +184,7 @@ export default function useBreakdownMetrics() {
return {
StakeDeposited: 0,
StakeRebalanced: 0,
WithdrawalInitiated: 0,
WithdrawalRequested: 0,
// WithdrawalRequested: 0,
WithdrawalFulfilled: 0
}
}
Expand Down Expand Up @@ -222,7 +215,7 @@ export default function useBreakdownMetrics() {
} catch (error) {
console.log("Error occurred while fetching stake:", error)
return {
eth: "0ETH",
eth: "0 ETH",
usd: "$0.00"
}
}
Expand Down Expand Up @@ -281,9 +274,11 @@ export default function useBreakdownMetrics() {
listeningForContractEvents.value = true
try {
(baseManager as CasimirManager).on("StakeDeposited", stakeDepositedListener);
(baseManager as CasimirManager).on("WithdrawalInitiated", withdrawalInitiatedListener);
(baseManager as CasimirManager).on("StakeRebalanced", stakeRebalancedListener);
(baseManager as CasimirManager).on("WithdrawalFulfilled", withdrawalFulfilledListener);
(eigenManager as CasimirManager).on("StakeDeposited", stakeDepositedListener);
(eigenManager as CasimirManager).on("WithdrawalInitiated", withdrawalInitiatedListener)
(eigenManager as CasimirManager).on("StakeRebalanced", stakeRebalancedListener);
(eigenManager as CasimirManager).on("WithdrawalFulfilled", withdrawalFulfilledListener)
} catch (err) {
console.log(`There was an error in listenForStakeWithdrawEvents: ${err}`)
}
Expand All @@ -305,15 +300,15 @@ export default function useBreakdownMetrics() {
if (!breakdownMetricsComposableInitialized.value) return
(baseManager as CasimirManager).removeListener("StakeDeposited", stakeDepositedListener);
(baseManager as CasimirManager).removeListener("StakeRebalanced", stakeRebalancedListener);
(baseManager as CasimirManager).removeListener("WithdrawalInitiated", withdrawalInitiatedListener);
(baseManager as CasimirManager).removeListener("WithdrawalFulfilled", withdrawalFulfilledListener);
(eigenManager as CasimirManager).removeListener("StakeDeposited", stakeDepositedListener);
(eigenManager as CasimirManager).removeListener("StakeRebalanced", stakeRebalancedListener);
(eigenManager as CasimirManager).removeListener("WithdrawalInitiated", withdrawalInitiatedListener)
(eigenManager as CasimirManager).removeListener("WithdrawalFulfilled", withdrawalFulfilledListener)
}

const stakeDepositedListener = async () => await refreshBreakdown()
const stakeRebalancedListener = async () => await refreshBreakdown()
const withdrawalInitiatedListener = async () => await refreshBreakdown()
const withdrawalFulfilledListener = async () => await refreshBreakdown()

return {
currentStaked: readonly(currentStaked),
Expand Down
Loading
Loading