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

External stacking locks #57

Merged
merged 47 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
f2f9fec
Update to latest sylvia v0.5.0
maurolacy Jun 13, 2023
16806f2
Update lock file
maurolacy Jun 13, 2023
f903fa8
Fix: Add missing import
maurolacy Jun 13, 2023
2abbff2
Transactional remote staking first impl
maurolacy Jun 13, 2023
4dce85f
Locking approach (serialized txs) for staking
maurolacy Jun 15, 2023
762bd3a
Locking approach (serialized txs) for staking
maurolacy Jun 15, 2023
fdf33c9
Add tx id to cross staking api / msg
maurolacy Jun 15, 2023
8dcc0ce
Fix: remove double unlock write
maurolacy Jun 15, 2023
cf34bca
Unify local and remote stake
maurolacy Jun 16, 2023
338629e
Lock user info as well
maurolacy Jun 16, 2023
6ea02a5
Add commit / rollback tx to vault api
maurolacy Jun 16, 2023
e5a24e0
Commit / rollback tx harnessing
maurolacy Jun 16, 2023
761876a
Add commit / rollback vault api helpers
maurolacy Jun 16, 2023
2ead451
Fix: unlock user on commit
maurolacy Jun 16, 2023
5c418bf
Fix: proper lien user in commit / rollback
maurolacy Jun 16, 2023
72e2159
Transactional cross stake tests work (1st take)
maurolacy Jun 16, 2023
40f6005
Fix syntax / details
maurolacy Jun 16, 2023
6185e56
Fix clippy warning
maurolacy Jun 16, 2023
effac89
Fix: receive virtual stake msg proper
maurolacy Jun 16, 2023
384c12b
Fix staking test
maurolacy Jun 16, 2023
7fcda86
Add all pending txs query
maurolacy Jun 16, 2023
2b43371
Use pending txs query to get tx id
maurolacy Jun 16, 2023
a7c28ad
Report pending txs in descending order (newest first)
maurolacy Jun 16, 2023
4ef5fdb
Fix: range limits
maurolacy Jun 16, 2023
6f7eb40
Fix unstaking test
maurolacy Jun 16, 2023
e0bf55e
Fix distribution test
maurolacy Jun 16, 2023
8150e89
Fix clippy warnings
maurolacy Jun 16, 2023
c2b18f8
Manual commit_tx call for staking tests
maurolacy Jun 16, 2023
a6be2e9
Add staking txs / locks test
maurolacy Jun 16, 2023
223551e
Add query vault balance check
maurolacy Jun 16, 2023
ab37898
Fix: error filtering
maurolacy Jun 16, 2023
17fcf86
Add all accounts checks with locked items
maurolacy Jun 16, 2023
a2a21b3
Fix: user unlocking in rollback tx
maurolacy Jun 16, 2023
bece088
Add rollback tx test
maurolacy Jun 16, 2023
8860a9e
Fix: skip write locked accounts
maurolacy Jun 17, 2023
fec475a
Idiomatic filter / maps
maurolacy Jun 17, 2023
a58f7c1
Add pending tx query
maurolacy Jun 19, 2023
856b74f
Move Tx to sync package
maurolacy Jun 21, 2023
f92fb83
Adapt vault to new Tx format
maurolacy Jun 21, 2023
7d8b268
Adapt vault tests to new Tx format
maurolacy Jun 21, 2023
8fd2445
Adapt external-staking tests to new Tx format
maurolacy Jun 21, 2023
5ca9e4a
Add FIXME
maurolacy Jun 21, 2023
a0d54cf
Refactor max lien recalculation
maurolacy Jun 21, 2023
12fb25d
write access lien directly
maurolacy Jun 21, 2023
d8c98f4
Refactor / rename pending txs query for clarity
maurolacy Jun 21, 2023
b0c52d2
Fix clippy warnings
maurolacy Jun 21, 2023
4fcc337
Fix: pending txs renaming
maurolacy Jun 21, 2023
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
10 changes: 6 additions & 4 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ mesh-converter = { path = "./contracts/consumer/converter" }
mesh-simple-price-feed = { path = "./contracts/consumer/simple-price-feed" }
mesh-virtual-staking = { path = "./contracts/consumer/virtual-staking" }

sylvia = "0.4.2"
sylvia = "0.5.0"
cosmwasm-schema = "1.2"
cosmwasm-std = { version = "1.2", features = ["ibc3", "cosmwasm_1_2"] }
cosmwasm-storage = "1.2"
Expand Down
1 change: 1 addition & 0 deletions contracts/provider/external-staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ anyhow = { workspace = true }
mesh-vault = { workspace = true, features = ["mt"] }
mesh-native-staking-proxy = { workspace = true, features = ["mt"] }
mesh-native-staking = { workspace = true, features = ["mt"] }
mesh-sync = { workspace = true }

[[bin]]
name = "schema"
Expand Down
4 changes: 3 additions & 1 deletion contracts/provider/external-staking/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ pub mod cross_staking {
ctx: ExecCtx,
owner: String,
amount: Coin,
tx_id: u64,
msg: Binary,
) -> Result<Response, Self::Error> {
let config = self.config.load(ctx.deps.storage)?;
Expand Down Expand Up @@ -434,7 +435,8 @@ pub mod cross_staking {
let resp = Response::new()
.add_attribute("action", "receive_virtual_stake")
.add_attribute("owner", owner)
.add_attribute("amount", amount.amount.to_string());
.add_attribute("amount", amount.amount.to_string())
.add_attribute("tx_id", tx_id.to_string());

Ok(resp)
}
Expand Down
79 changes: 77 additions & 2 deletions contracts/provider/external-staking/src/multitest.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
use anyhow::Result as AnyResult;

use cosmwasm_std::{coin, coins, to_binary, Addr, Decimal};
use mesh_native_staking::contract::multitest_utils::CodeId as NativeStakingCodeId;
use mesh_native_staking::contract::InstantiateMsg as NativeStakingInstantiateMsg;
use mesh_native_staking_proxy::contract::multitest_utils::CodeId as NativeStakingProxyCodeId;
use mesh_vault::contract::multitest_utils::{CodeId as VaultCodeId, VaultContractProxy};
use mesh_vault::contract::test_utils::VaultApi;
use mesh_vault::msg::StakingInitInfo;

use mesh_sync::Tx;

use cw_multi_test::App as MtApp;
use sylvia::multitest::App;

Expand All @@ -13,8 +18,6 @@ use crate::contract::multitest_utils::{CodeId, ExternalStakingContractProxy};
use crate::error::ContractError;
use crate::msg::{ReceiveVirtualStake, StakeInfo};

use anyhow::Result as AnyResult;

const OSMO: &str = "osmo";
const STAR: &str = "star";

Expand Down Expand Up @@ -127,6 +130,14 @@ fn staking() {
.call(users[0])
.unwrap();

let last_tx = get_last_pending_tx_id(&vault).unwrap();
maurolacy marked this conversation as resolved.
Show resolved Hide resolved
// Hardcoded commit_tx call (lack of IBC support yet)
vault
.vault_api_proxy()
.commit_tx(last_tx)
.call(contract.contract_addr.as_str())
.unwrap();

vault
.stake_remote(
contract.contract_addr.to_string(),
Expand All @@ -139,6 +150,12 @@ fn staking() {
.call(users[0])
.unwrap();

vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(contract.contract_addr.as_str())
.unwrap();

vault
.stake_remote(
contract.contract_addr.to_string(),
Expand All @@ -151,6 +168,12 @@ fn staking() {
.call(users[0])
.unwrap();

vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(contract.contract_addr.as_str())
.unwrap();

vault
.stake_remote(
contract.contract_addr.to_string(),
Expand All @@ -163,6 +186,12 @@ fn staking() {
.call(users[1])
.unwrap();

vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(contract.contract_addr.as_str())
.unwrap();

vault
.stake_remote(
contract.contract_addr.to_string(),
Expand All @@ -174,6 +203,11 @@ fn staking() {
)
.call(users[1])
.unwrap();
vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(contract.contract_addr.as_str())
.unwrap();

// All tokens should be only on the vault contract
assert_eq!(app.app().wrap().query_all_balances(users[0]).unwrap(), []);
Expand Down Expand Up @@ -250,6 +284,14 @@ fn staking() {
);
}

#[track_caller]
fn get_last_pending_tx_id(vault: &VaultContractProxy) -> Option<u64> {
let txs = vault.all_pending_txs_desc(None, None).unwrap().txs;
txs.first().map(|tx| match tx {
Tx::InFlightStaking { id, .. } => *id,
})
}

#[test]
fn unstaking() {
let users = ["user1", "user2"];
Expand Down Expand Up @@ -300,6 +342,13 @@ fn unstaking() {
)
.call(users[0])
.unwrap();
let last_tx = get_last_pending_tx_id(&vault).unwrap();
// Hardcoded commit_tx call (lack of IBC support yet)
vault
.vault_api_proxy()
.commit_tx(last_tx)
.call(contract.contract_addr.as_str())
.unwrap();

vault
.stake_remote(
Expand All @@ -312,6 +361,11 @@ fn unstaking() {
)
.call(users[0])
.unwrap();
vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(contract.contract_addr.as_str())
.unwrap();

vault
.stake_remote(
Expand All @@ -324,6 +378,11 @@ fn unstaking() {
)
.call(users[1])
.unwrap();
vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(contract.contract_addr.as_str())
.unwrap();

// Properly unstake some tokens
// users[0] unstakes 50 from validators[0] - 150 left staken in 2 batches
Expand Down Expand Up @@ -583,6 +642,12 @@ fn distribution() {
)
.call(users[0])
.unwrap();
// Hardcoded commit_tx call (lack of IBC support yet)
vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(contract.contract_addr.as_str())
.unwrap();

vault
.stake_remote(
Expand All @@ -595,6 +660,11 @@ fn distribution() {
)
.call(users[0])
.unwrap();
vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(contract.contract_addr.as_str())
.unwrap();

vault
.stake_remote(
Expand All @@ -607,6 +677,11 @@ fn distribution() {
)
.call(users[1])
.unwrap();
vault
.vault_api_proxy()
.commit_tx(get_last_pending_tx_id(&vault).unwrap())
.call(contract.contract_addr.as_str())
.unwrap();

// Start with equal distribution:
// 20 tokens for users[0]
Expand Down
3 changes: 3 additions & 0 deletions contracts/provider/native-staking/src/local_staking_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use crate::contract::{NativeStakingContract, MAX_SLASH_PERCENTAGE, REPLY_ID_INST
use crate::error::ContractError;
use crate::msg::StakeMsg;

// FIXME: Move to sylvia contract macro
use crate::contract::BoundQuerier;

#[contract]
#[messages(local_staking_api as LocalStakingApi)]
impl LocalStakingApi for NativeStakingContract<'_> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ use mesh_native_staking_proxy::native_staking_callback::{self, NativeStakingCall
use crate::contract::NativeStakingContract;
use crate::error::ContractError;

// FIXME: Move to sylvia contract macro
use crate::contract::BoundQuerier;

#[contract]
#[messages(native_staking_callback as NativeStakingCallback)]
impl NativeStakingCallback for NativeStakingContract<'_> {
Expand Down
1 change: 1 addition & 0 deletions contracts/provider/vault/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mt = ["library", "sylvia/mt"]

[dependencies]
mesh-apis = { workspace = true }
mesh-sync = { workspace = true }

sylvia = { workspace = true }
cosmwasm-schema = { workspace = true }
Expand Down
Loading