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

restaking-v2: added restaking program with tests #346

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
02f4aef
added restaking program with tests
dhruvja Jun 15, 2024
be2e588
added restaking-v2 program to config
dhruvja Jun 16, 2024
6f16a24
added restaking-v2 program to config
dhruvja Jun 16, 2024
c5fd07c
add fee payer account for initializing accounts
dhruvja Jun 18, 2024
1abae32
fmt
dhruvja Jun 18, 2024
b7b1a5d
set remainder to the first validator
dhruvja Jun 19, 2024
142110b
use extend instead of append
dhruvja Jun 19, 2024
a1edae5
add docs
dhruvja Jul 2, 2024
59c57e5
add support for oracles
dhruvja Jul 8, 2024
c0fc9ef
deref instead of clone
dhruvja Jul 8, 2024
a2d2c3c
fix clippy
dhruvja Jul 8, 2024
7077206
fmt
dhruvja Jul 8, 2024
b263140
fix clippy
dhruvja Jul 8, 2024
1f951b3
use into iter
dhruvja Jul 10, 2024
b894ff2
not use ref in find
dhruvja Jul 10, 2024
8ad8b62
throw err without if else branching
dhruvja Jul 10, 2024
66d22df
use decimals in the eq instead of calculating before
dhruvja Jul 10, 2024
ccfc142
fmt
dhruvja Jul 10, 2024
33101f9
fmt
dhruvja Jul 15, 2024
48483d7
use lazy evaluation
dhruvja Jul 15, 2024
f11a065
store price with exponent
dhruvja Jul 15, 2024
f200f48
fmt
dhruvja Jul 16, 2024
b1969e4
revert change to restaking.ts file
dhruvja Jul 16, 2024
dd164a0
fix clippy
dhruvja Jul 16, 2024
eb3b581
update delegations during deposit/withdraw
dhruvja Jul 23, 2024
20547b9
check for duplicates in the ix payload
dhruvja Jul 23, 2024
cfbd6e8
proper calculation when updating the stake
dhruvja Jul 23, 2024
9a6a233
use proper conversions when calculating the amount from the price
dhruvja Jul 23, 2024
0c9ebeb
remove unused update_frequency attr
dhruvja Jul 23, 2024
83cf557
ignore the remainder
dhruvja Jul 23, 2024
6ee16e3
fix clippy
dhruvja Jul 23, 2024
6318686
add fee payer to send transfer method
dhruvja Jul 29, 2024
89ea265
Merge branch 'master' of https://github.com/ComposableFi/emulated-lig…
dhruvja Aug 6, 2024
a0deea5
remove guest chain program id
dhruvja Aug 15, 2024
f0e4ca4
remove remainder from amount when depositing
dhruvja Aug 15, 2024
7a49524
add pause flag for tokens
dhruvja Aug 15, 2024
5b52f9b
remove fee payer
dhruvja Aug 21, 2024
1044781
increase maximum age for oracle
dhruvja Sep 2, 2024
f190512
add a method to reallocate common state
dhruvja Sep 4, 2024
025a490
make decimals as 6
dhruvja Sep 12, 2024
360e64e
fix multiplication overflow
dhruvja Oct 10, 2024
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
19 changes: 13 additions & 6 deletions Anchor.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
[toolchain]

[features]
seeds = false
skip-lint = false

[programs.devnet]
restaking = "8n3FHwYxFgQCQc2FNFkwDUf9mcqupxXcCvgfHbApMLv3"
restaking_v2 = "H69iS4rPnrRAMciLJcpEY3tRtFro7Mo7a2YAU8Q1busv"
solana_ibc = "2HLLVco5HvwWriNbUhmVwA2pCetRkpgrqwnjcsZdyTKT"

[programs.localnet]
restaking = "8n3FHwYxFgQCQc2FNFkwDUf9mcqupxXcCvgfHbApMLv3"
restaking_v2 = "H69iS4rPnrRAMciLJcpEY3tRtFro7Mo7a2YAU8Q1busv"
solana_ibc = "2HLLVco5HvwWriNbUhmVwA2pCetRkpgrqwnjcsZdyTKT"

[registry]
url = "https://api.apr.dev"

[provider]
cluster = "localnet"
wallet = "~/.config/solana/id.json"
cluster = "Localnet"
wallet = "/Users/dhruvjain/.config/solana/id.json"

[workspace]
members = [
"solana/restaking/programs/restaking",
"solana/solana-ibc/programs/solana-ibc"
]
members = ["solana/restaking/programs/restaking", "solana/solana-ibc/programs/solana-ibc", "solana/restaking-v2/programs/restaking-v2"]

[scripts]
test = "./solana-test.sh"
Expand All @@ -39,3 +40,9 @@ rpc_port = 8899

[[test.validator.clone]]
address = "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"

[[test.validator.clone]]
address = "Dpw1EAVrSB1ibxiDQyTAW6Zip3J4Btk2x4SgApQCeFbX"

[[test.validator.clone]]
address = "7UVimffxr9ow1uXYxsr4LHAcV58mLzhmwaeKvJ1pjLiE"
74 changes: 74 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"common/*",
"solana/allocator",
"solana/restaking/programs/*",
"solana/restaking-v2/programs/*",
"solana/signature-verifier",
"solana/solana-ibc/programs/*",
"solana/trie",
Expand All @@ -30,6 +31,7 @@ codegen-units = 1
[workspace.dependencies]
anchor-lang = { version = "0.29.0", features = ["init-if-needed"] }
anchor-spl = "0.29.0"
anchor-gen = "0.3.1"
ascii = "1.1.0"
bs58 = { version = "0.5.0", features = ["alloc"] }
base64 = { version = "0.21", default-features = false, features = ["alloc"] }
Expand Down Expand Up @@ -67,6 +69,7 @@ pretty_assertions = "1.4.0"
primitive-types = "0.12.2"
prost = { version = "0.12.3", default-features = false }
prost-build = { version = "0.12.3", default-features = false }
pyth-solana-receiver-sdk ="0.1.0"
rand = { version = "0.8.5" }
reqwest = "0.12.3"
# TODO(mina86): Change to "1" once we update the toolchain. Building
Expand Down
1 change: 1 addition & 0 deletions solana-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ cd ../..
solana program deploy target/deploy/write.so
solana program deploy target/deploy/sigverify.so
cargo test --lib -- --nocapture --include-ignored ::anchor
cargo test --lib -- --nocapture --include-ignored ::restaking
find solana/restaking/tests/ -name '*.ts' \
-exec yarn run ts-mocha -p ./tsconfig.json -t 1000000 {} +
23 changes: 23 additions & 0 deletions solana/restaking-v2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Restaking V2

This program was built to make it easier to keep track of deposits to the restaking vaults and make use of fungible receipt tokens as opposed to using NFTs in previous version which had a few drawbacks for it to be used as an yield for the rollup.

The drawbacks of the previous restaking program
- The depositors were given an NFT as a receipt token which meant that there were no partial withdrawals.
- Since the users could choose the validator to which they deposit to, the token deposited to one validator is different from the token deposited to another validator. Which means if the token is restaked and bridged to the rollup, then there would be a token for each validator even if they are same token.

For example: JitoSOL deposited to validator A and B would be different on rollup even though it is the same token on Solana.

So the new restaking program was built specifically to support restaking of tokens before bridging to rollup and use fungible receipt tokens.
These are changes which were introduced in the new version.
- Users cannot choose which validator they delegate their stake to since their stake is equally divided among the validators specified in the program.
- If one of the validator gets slashed, the amount is slashed equally among the validators.
- A fungible receipt token is issued instead of a non fungible one.
- There is no unbonding period since all the validators get slashed equally.
- Allow deposits of tokens other than LSTs with the use of oracles.

This program can only be called by the bridge contract. If people just want to restake directly and dont want to bridge, they can do it via restaking-v1 program.

## Oracles

For tokens others than LSTs which have a different value than SOL, we need to use oracle to get their current price and then update the stake. But since the stake is recorded in lamports in the guest chain, everytime the price changes we would need to update the stake. To do this, we store the delegations of the particular token locally and get the price on every interval set during initialization. Every time the price is updated, we calculate the difference and update the price on the guest chain. This would make sure that the stake on guest chain is always up to date. Whenever new deposits are made, it would use the stored price rather than from the oracle. But if the price is stale then the deposit would be rejected. This is a better way of updating the stake using oracle where we need to update it once for all the deposits for a particular token during an interval.
12 changes: 12 additions & 0 deletions solana/restaking-v2/migrations/deploy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Migrations are an early feature. Currently, they're nothing more than this
// single deploy script that's invoked from the CLI, injecting a provider
// configured from the workspace's Anchor.toml.

const anchor = require("@coral-xyz/anchor");

module.exports = async function (provider) {
// Configure client to use the provider.
anchor.setProvider(provider);

// Add your deploy script here.
};
32 changes: 32 additions & 0 deletions solana/restaking-v2/programs/restaking-v2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "restaking_v2"
version = "0.1.0"
description = "Created with Anchor"
edition = "2021"

[lib]
crate-type = ["cdylib", "lib"]
name = "restaking_v2"

[features]
# added so that we can compile this along with `solana-ibc` with mocks features. Currently unused.
mocks = []
no-entrypoint = []
no-idl = []
no-log-ix-name = []
cpi = ["no-entrypoint"]
default = []

[dependencies]
anchor-lang = { workspace = true, features = ["init-if-needed"] }
anchor-spl = { workspace = true, features = ["metadata"] }
solana-ibc = { workspace = true, features = ["cpi"] }
solana-program.workspace = true
solana-signature-verifier.workspace = true
pyth-solana-receiver-sdk.workspace = true

[dev-dependencies]
anchor-client.workspace = true
anyhow.workspace = true
spl-associated-token-account.workspace = true
spl-token.workspace = true
2 changes: 2 additions & 0 deletions solana/restaking-v2/programs/restaking-v2/Xargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.bpfel-unknown-unknown.dependencies.std]
features = []
Loading