Skip to content

Commit

Permalink
idk misc
Browse files Browse the repository at this point in the history
  • Loading branch information
kent-3 committed Dec 22, 2024
1 parent 6b3eef3 commit 4675a12
Show file tree
Hide file tree
Showing 9 changed files with 307 additions and 231 deletions.
379 changes: 192 additions & 187 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ leptos_meta = { version = "0.7.0" }

# gRPC
tonic = { version = "0.12.2", default-features = false }
prost = { version = "0.13.4" }

# Web support
console_error_panic_hook = "0.1.7"
Expand Down Expand Up @@ -98,9 +99,9 @@ secretrs = { git = "https://github.com/kent-3/secret-rust", branch = "sdk-upgrad

# [patch."https://github.com/securesecrets/shade.git"]
# shade-protocol = { path = "../shade/packages/shade_protocol" }
#
# [patch."https://github.com/kent-3/secret-clients.git"]
# rsecret = { path = "../secret-clients/rsecret" }

[patch."https://github.com/kent-3/secret-clients.git"]
rsecret = { path = "../secret-clients/rsecret" }

[patch."https://github.com/kent-3/liquidity-book.git"]
lb-interfaces = { path = "../liquidity-book/packages/lb_interfaces" }
Expand Down
48 changes: 47 additions & 1 deletion public/lb_contracts_dev.json
Original file line number Diff line number Diff line change
@@ -1 +1,47 @@
{"admin_auth":{"address":"secret1wy2zy8a6s883hyj9zartjrgltwh54d4xkg6hkw","code_hash":"99d0cf3119b5bf51cf2d97c5c0ea23a267bbbc46934c3d87f265756a55103c0f","code_id":32},"query_auth":{"address":"secret1vtvj4wkzkcgw0md09qx40rk8vaq8n0pee46uz2","code_hash":"ed32ac91e689afd6a6be6e21276df0c727803b288c4de5836bd6eab2d2cfb4d0","code_id":33},"snip20":{"address":"secret1vwrl64g3rekcmqa2vd8hkl6d67lupn8jcnh5f5","code_hash":"af74387e276be8874f07bec3a87023ee49b0e7ebe08178c49d0a49c3c98ed60e","code_id":35},"snip25":{"address":"secret16em8ptlwzm783lrme0cf4f8v7h5xkzn8aalzgm","code_hash":"9a00ca4ad505e9be7e6e6dddf8d939b7ec7e9ac8e109c8681f10db9cacb36d42","code_id":36},"lb_factory":{"address":"secret1nfkddac5l0e2k4gwk0m7hyx4qru4wlkmgdrq5d","code_hash":"91e0e3e9767ae5054e46d8d22337d8c56f2253a520366a2c09045a34cf191606","code_id":37},"lb_pair":{"address":"secret1rup2tx3hhwtv3ky9006lava9cc2p7as8ek7l88","code_hash":"6b4c948986af352d513f3604da32f613c8bac204550942ac548474d17ac3c10b","code_id":38},"lb_token":{"address":"","code_hash":"54386fc68452f78974896f5807d02b1d0203a952d5427b15a21f3bc8ee2aeb18","code_id":39},"lb_router":{"address":"","code_hash":"c4fb05ac146334275f752b20e75f2c05775d1ad0486ebaa73f2f0f641926c38e","code_id":40},"lb_staking":{"address":"","code_hash":"4e6d5a05e0364eebecc867488f96388fbc54b800799c7b4b915f0fd5c4755d02","code_id":41}}
{
"admin_auth": {
"address": "secret1d5kpamqxv8unxad42c870qqyxzamtqvtu30yn5",
"code_hash": "99d0cf3119b5bf51cf2d97c5c0ea23a267bbbc46934c3d87f265756a55103c0f",
"code_id": 1
},
"query_auth": {
"address": "secret1g6a95raxwh8ury5nklfhhgk3v2f9060myjk04d",
"code_hash": "ed32ac91e689afd6a6be6e21276df0c727803b288c4de5836bd6eab2d2cfb4d0",
"code_id": 2
},
"snip20": {
"address": "secret1dppxlcxnj0pyvzsfrkuc36s9rdd3w9rzfcv40s",
"code_hash": "af74387e276be8874f07bec3a87023ee49b0e7ebe08178c49d0a49c3c98ed60e",
"code_id": 4
},
"snip25": {
"address": "secret1dn9wkuysmxax5gda9a6pshxaxnqwt2e23p764p",
"code_hash": "9a00ca4ad505e9be7e6e6dddf8d939b7ec7e9ac8e109c8681f10db9cacb36d42",
"code_id": 5
},
"lb_factory": {
"address": "secret1u5raanjhtam07qzyy5tpmesv3xw9x3223f5cdd",
"code_hash": "194a58d4a2948d7b5119d1b0552e35ab54b385846353396206b850904e778cc2",
"code_id": 6
},
"lb_pair": {
"address": "secret1qj7uvg473qya08kn99xvqx2dpuwj328658nypz",
"code_hash": "3913e96685abebc11ae75e49ab8feef02027a738d5a9b8b6acc4dbcb1761f935",
"code_id": 7
},
"lb_token": {
"address": "",
"code_hash": "9fb9197c1478004a73762aa9cfd4b33737a360b3b3a187ae832153aed1175d58",
"code_id": 8
},
"lb_router": {
"address": "secret1q595z8f6v5uhfptturs7vvftp4vdz4efwp8tmx",
"code_hash": "fa121f27a67ed4ea167d6bcd111f39c9dcd7c71ad811f00c9f2a0c214ed2f9bf",
"code_id": 9
},
"lb_quoter": {
"address": "secret16tsxhkx32pj8qxcvpj8deufpnm3mlgpc9h25h9",
"code_hash": "22b5eb4d88d5a27fecc1176d2768dc2171e92c107c22da56778860c8e1a64077",
"code_id": 10
}
}
3 changes: 2 additions & 1 deletion src/batch_query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use tracing::{debug, info, trace};
pub static BATCH_QUERY_ROUTER: LazyLock<ContractInfo> = LazyLock::new(|| {
if CHAIN_ID == "secretdev-1" {
ContractInfo {
address: Addr::unchecked("secret1qhvwkm7d24sj7qs52raln2qqleuz68pwr7nv7w"),
// FIXME: this address needs to be updated manually
address: Addr::unchecked("secret1rgqxfst0frq5mgmw3e5pzajpre4qwepc2uh22m"),
code_hash: "1c7e86ba4fdb6760e70bf08a7df7f44b53eb0b23290e3e69ca96140810d4f432"
.to_string(),
}
Expand Down
10 changes: 5 additions & 5 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ pub struct Token {
// WARN: This key is randomly generated when localsecret is started for the first time.
// Reuse containers to avoid needing changing this every time.
pub static DEVNET_IO_PUBKEY: [u8; 32] =
hex!("c74e52edac6cdffb50f876927140766fb81b1aa7ae89804a1666df84d9cf9e73");
hex!("c8a3ef51d2d4a285ce2a97ccf60a7372fb978e41768556ba4450ecc26247ac4b");

// pub static CHAIN_ID: &str = "secretdev-1";
// pub static GRPC_URL: &str = "http://localhost:1317";
pub static CHAIN_ID: &str = "secretdev-1";
pub static GRPC_URL: &str = "http://localhost:1317";

pub static CHAIN_ID: &str = "pulsar-3";
// pub static CHAIN_ID: &str = "pulsar-3";
// pub static GRPC_URL: &str = "https://api.pulsar.scrttestnet.com";
pub static GRPC_URL: &str = "https://grpc.testnet.secretsaturn.net";
// pub static GRPC_URL: &str = "https://grpc.testnet.secretsaturn.net";

// pub static CHAIN_ID: &str = "secret-4";
// pub static LCD_URL: &str = "https://lcd.mainnet.secretsaturn.net";
Expand Down
16 changes: 5 additions & 11 deletions src/keplr/signers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,16 @@ use std::rc::Rc;
use tracing::{debug, trace};
use web_sys::js_sys;

#[derive(Debug)]
#[derive(Debug, Clone)]
pub struct KeplrOfflineSigner {
inner: keplr_sys::KeplrOfflineSigner,
}

impl Clone for KeplrOfflineSigner {
fn clone(&self) -> Self {
KeplrOfflineSigner {
inner: self.inner.clone().into(),
}
}
inner: SendWrapper<Rc<keplr_sys::KeplrOfflineSigner>>,
}

impl From<keplr_sys::KeplrOfflineSigner> for KeplrOfflineSigner {
fn from(value: keplr_sys::KeplrOfflineSigner) -> Self {
Self { inner: value }
Self {
inner: SendWrapper::new(Rc::new(value)),
}
}
}

Expand Down
17 changes: 12 additions & 5 deletions src/liquidity_book/constants/addrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct DeployedContracts {
pub lb_pair: DeployedContractInfo,
pub lb_token: DeployedContractInfo,
pub lb_router: DeployedContractInfo,
pub lb_staking: DeployedContractInfo,
pub lb_quoter: DeployedContractInfo,
}

// TODO: don't rely on this. this module should not depend on the main crate.
Expand Down Expand Up @@ -65,11 +65,18 @@ pub static LB_PAIR: LazyLock<Arc<ContractInfo>> = LazyLock::new(|| {
.into()
});

// NOTE: This should not be a static value, but it is here for dev purposes.
pub static LB_STAKING: LazyLock<Arc<ContractInfo>> = LazyLock::new(|| {
pub static LB_ROUTER: LazyLock<Arc<ContractInfo>> = LazyLock::new(|| {
ContractInfo {
address: LB_CONTRACTS.lb_router.address.clone(),
code_hash: LB_CONTRACTS.lb_router.code_hash.clone(),
}
.into()
});

pub static LB_QUOTER: LazyLock<Arc<ContractInfo>> = LazyLock::new(|| {
ContractInfo {
address: LB_CONTRACTS.lb_staking.address.clone(),
code_hash: LB_CONTRACTS.lb_staking.code_hash.clone(),
address: LB_CONTRACTS.lb_quoter.address.clone(),
code_hash: LB_CONTRACTS.lb_quoter.code_hash.clone(),
}
.into()
});
50 changes: 36 additions & 14 deletions src/routes/pool/add_liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ use crate::{
keplr::Keplr,
liquidity_book::{
constants::{
addrs::{LB_CONTRACTS, LB_FACTORY, LB_PAIR},
addrs::{LB_CONTRACTS, LB_FACTORY, LB_PAIR, LB_ROUTER},
liquidity_config::{
LiquidityConfiguration, LiquidityShape, BID_ASK, CURVE, SPOT_UNIFORM, WIDE,
},
},
contract_interfaces::{
lb_factory,
// TODO: rename all LB* to Lb*
lb_pair::{self, LbPair, LbPairInformation, LiquidityParameters},
lb_router,
},
utils::{get_id_from_price, get_price_from_id},
Querier,
Expand All @@ -21,21 +21,28 @@ use crate::{
utils::{alert, latest_block},
};
use cosmwasm_std::{Addr, ContractInfo, Uint128, Uint64};
use lb_interfaces::lb_factory::{LbPairInformationResponse, QueryMsg::GetLbPairInformation};
use lb_libraries::math::liquidity_configurations::LiquidityConfigurations;
use lb_interfaces::lb_router::CreateLbPairResponse;
use lb_interfaces::{
lb_factory::{LbPairInformationResponse, QueryMsg::GetLbPairInformation},
lb_router::AddLiquidityResponse,
};
use leptos::logging::*;
use leptos::prelude::*;
use leptos_router::{
components::A,
hooks::{query_signal_with_options, use_params, use_params_map, use_query_map},
NavigateOptions,
};
use prost::Message;
use rsecret::{
query::tendermint::TendermintQuerier,
secret_client::CreateTxSenderOptions,
secret_client::TxResponse,
tx::{compute::MsgExecuteContractRaw, ComputeServiceClient},
TxOptions,
};
use secretrs::compute::MsgExecuteContractResponse;
use secretrs::tx::Msg;
use secretrs::AccountId;
use send_wrapper::SendWrapper;
use shade_protocol::swap::core::TokenType;
Expand Down Expand Up @@ -158,9 +165,9 @@ pub fn AddLiquidity() -> impl IntoView {
let lb_pair_information = lb_pair_information
.get()
.expect("Unverified LB Pair information");
// FIXME: The tokens are backwards!
let token_x = lb_pair_information.lb_pair.token_y;
let token_y = lb_pair_information.lb_pair.token_x;
// FIXME: The tokens are not always in the expected order!
let token_x = lb_pair_information.lb_pair.token_x;
let token_y = lb_pair_information.lb_pair.token_y;
let bin_step = lb_pair_information.bin_step;

let amount_x = token_x_amount.get();
Expand Down Expand Up @@ -203,7 +210,6 @@ pub fn AddLiquidity() -> impl IntoView {
token_x,
token_y,
bin_step,
// This Uint128 buisiness seems unneccesary
amount_x: Uint128::from_str(&amount_x).unwrap(),
amount_y: Uint128::from_str(&amount_y).unwrap(),
amount_x_min: Uint128::from(amount_x_min),
Expand All @@ -214,6 +220,8 @@ pub fn AddLiquidity() -> impl IntoView {
delta_ids,
distribution_x,
distribution_y,
to: "todo".to_string(),
refund_to: "todo".to_string(),
deadline,
};

Expand All @@ -237,7 +245,8 @@ pub fn AddLiquidity() -> impl IntoView {

let key = Keplr::get_key(&chain_id).await?;
keplr.enabled.set(true);
let wallet = Keplr::get_offline_signer_only_amino(&chain_id);
// let wallet = Keplr::get_offline_signer_only_amino(&chain_id);
let wallet = Keplr::get_offline_signer(&chain_id);
let enigma_utils = Keplr::get_enigma_utils(&chain_id).into();

// TODO: I guess I need to make this type use Strings instead of &'static str, because the
Expand All @@ -259,21 +268,23 @@ pub fn AddLiquidity() -> impl IntoView {
.await
.map(|block| block.header.time.unix_timestamp() as u64)
.map_err(Error::from)?;

liquidity_parameters.deadline = (latest_block_time + 100).into();
liquidity_parameters.to = key.bech32_address.clone().into();
liquidity_parameters.refund_to = key.bech32_address.clone().into();

let lb_pair_contract = lb_pair_information.await.lb_pair.contract;
let lb_router_contract = &LB_ROUTER;

let msg = MsgExecuteContractRaw {
// sender: AccountId::new("secret", &key.address)?,
sender: AccountId::from_str(key.bech32_address.as_ref())?,
contract: AccountId::from_str(lb_pair_contract.address.as_ref())?,
msg: lb_pair::ExecuteMsg::AddLiquidity {
contract: AccountId::from_str(lb_router_contract.address.as_ref())?,
msg: lb_router::ExecuteMsg::AddLiquidity {
liquidity_parameters,
},
sent_funds: vec![],
};

debug!("{:#?}", lb_pair_information.get());
debug!("{:#?}", msg);

let tx_options = TxOptions {
Expand All @@ -282,7 +293,7 @@ pub fn AddLiquidity() -> impl IntoView {
};

let tx = compute_service_client
.execute_contract(msg, lb_pair_contract.code_hash, tx_options)
.execute_contract(msg, lb_router_contract.code_hash.clone(), tx_options)
.await
.map_err(Error::from)
.inspect(|tx_response| info!("{tx_response:?}"))
Expand All @@ -292,6 +303,17 @@ pub fn AddLiquidity() -> impl IntoView {
error!("{}", tx.raw_log);
}

debug!("hello");
let data = MsgExecuteContractResponse::from_any(&tx.data[0])
.inspect_err(|e| error! {"{e}"})?
.data;
debug!("hello");
let add_liquidity_response = serde_json::from_slice::<AddLiquidityResponse>(&data)?;
debug!("hello");

debug!("X: {}", add_liquidity_response.amount_x_added);
debug!("Y: {}", add_liquidity_response.amount_y_added);

Ok(())
})
});
Expand Down
8 changes: 4 additions & 4 deletions src/routes/pool/pool_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::{
contract_interfaces::{
lb_factory,
lb_pair::{
ActiveIdResponse, BinResponse, LbPairInformation, NextNonEmptyBinResponse,
QueryMsg, TotalSupplyResponse,
ActiveIdResponse, BinResponse, LbPairInformation, LbTokenSupplyResponse,
NextNonEmptyBinResponse, QueryMsg,
},
},
Querier,
Expand Down Expand Up @@ -201,11 +201,11 @@ pub fn PoolManager() -> impl IntoView {
// TODO: Figure out why this number is so huge, for example:
// 12243017097593870802128434755484640756287535340
async fn query_total_supply(lb_pair_contract: &ContractInfo, id: u32) -> Result<String, Error> {
QueryMsg::TotalSupply { id }
QueryMsg::GetLbTokenSupply { id }
.do_query(lb_pair_contract)
.await
.inspect(|response| trace!("{:?}", response))
.and_then(|response| Ok(serde_json::from_str::<TotalSupplyResponse>(&response)?))
.and_then(|response| Ok(serde_json::from_str::<LbTokenSupplyResponse>(&response)?))
.map(|x| x.total_supply.to_string())
}

Expand Down

0 comments on commit 4675a12

Please sign in to comment.