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 update job id #5

Merged
merged 1 commit into from
Sep 2, 2024
Merged
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
File renamed without changes.
740 changes: 508 additions & 232 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 10 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "dca-bot-pancakeswap-cw"
name = "twap-bot-uniswap-cw"
version = "0.1.0"
authors = ["Volume Fi"]
edition = "2021"
Expand Down Expand Up @@ -27,30 +27,26 @@ incremental = false
overflow-checks = true

[features]
# for more explicit tests, cargo test --features=backtraces
backtraces = ["cosmwasm-std/backtraces"]
# use library feature to disable all instantiate/execute/query exports
library = []

[package.metadata.scripts]
optimize = """docker run --rm -v "$(pwd)":/code \
--mount type=volume,source="$(basename "$(pwd)")_cache",target=/code/target \
--mount type=volume,source=registry_cache,target=/usr/local/cargo/registry \
cosmwasm/rust-optimizer:0.14.0
cosmwasm/rust-optimizer:0.16.0
"""

[dependencies]
cosmwasm-schema = "1.3.3"
cosmwasm-std = "1.3.3"
cosmwasm-storage = "1.3.3"
cw-storage-plus = "1.1.0"
cw2 = "1.1.0"
cosmwasm-schema = "2.1.3"
cosmwasm-std = "2.1.3"
cw-storage-plus = "2.0.0"
ethabi = "18.0.0"
schemars = "0.8.12"
serde = { version = "1.0.186", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.47" }
getrandom = { version = "0.2.10", features = ["custom"] }
schemars = "0.8.21"
serde = { version = "1.0.209", default-features = false, features = ["derive"] }
thiserror = { version = "1.0.63" }
getrandom = { version = "0.2.15", features = ["custom"] }

[dev-dependencies]
cw-multi-test = "0.16.5"
cw-multi-test = "2.1.1"

2 changes: 1 addition & 1 deletion artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
f1f9c22b5f1b1cce7e83cfa5dc575a9ac677e44ad382a6e64f735ec2dea51f54 dca_bot_pancakeswap_cw.wasm
dba91085ebda9cb17978a2b1a72abba0d78402470fcc5a13b0d58d14f78d4529 twap_bot_uniswap_cw.wasm
1 change: 0 additions & 1 deletion artifacts/checksums_intermediate.txt

This file was deleted.

Binary file removed artifacts/dca_bot_pancakeswap_cw.wasm
Binary file not shown.
Binary file added artifacts/twap_bot_uniswap_cw.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion src/bin/schema.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use cosmwasm_schema::write_api;

use dca_bot_pancakeswap_cw::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};
use twap_bot_uniswap_cw::msg::{ExecuteMsg, InstantiateMsg, QueryMsg};

fn main() {
write_api! {
Expand Down
41 changes: 32 additions & 9 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::ContractError::Unauthorized;
#[cfg(not(feature = "library"))]
use cosmwasm_std::entry_point;
use cosmwasm_std::{
to_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdResult, Uint256,
to_json_binary, Binary, CosmosMsg, Deps, DepsMut, Env, MessageInfo, Response, StdResult,
Uint256,
};
use ethabi::{Address, Contract, Function, Param, ParamType, StateMutability, Token, Uint};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -51,6 +52,7 @@ pub fn execute(
ExecuteMsg::UpdateServiceFee { new_service_fee } => {
update_service_fee(deps, info, new_service_fee)
}
ExecuteMsg::UpdateJobId { new_job_id } => update_job_id(deps, info, new_job_id),
}
}

Expand Down Expand Up @@ -117,7 +119,7 @@ fn swap(deps: DepsMut, deposits: Vec<Deposit>) -> Result<Response<PalomaMsg>, Co
Ok(Response::new()
.add_message(CosmosMsg::Custom(PalomaMsg {
job_id: state.job_id,
payload: Binary(
payload: Binary::new(
contract
.function("multiple_swap")
.unwrap()
Expand Down Expand Up @@ -154,7 +156,7 @@ fn set_paloma(deps: DepsMut, info: MessageInfo) -> Result<Response<PalomaMsg>, C
Ok(Response::new()
.add_message(CosmosMsg::Custom(PalomaMsg {
job_id: state.job_id,
payload: Binary(
payload: Binary::new(
contract
.function("set_paloma")
.unwrap()
Expand Down Expand Up @@ -201,7 +203,7 @@ fn update_compass(
Ok(Response::new()
.add_message(CosmosMsg::Custom(PalomaMsg {
job_id: state.job_id,
payload: Binary(
payload: Binary::new(
contract
.function("update_compass")
.unwrap()
Expand Down Expand Up @@ -248,7 +250,7 @@ fn update_refund_wallet(
Ok(Response::new()
.add_message(CosmosMsg::Custom(PalomaMsg {
job_id: state.job_id,
payload: Binary(
payload: Binary::new(
contract
.function("update_refund_wallet")
.unwrap()
Expand Down Expand Up @@ -294,7 +296,7 @@ fn update_fee(
Ok(Response::new()
.add_message(CosmosMsg::Custom(PalomaMsg {
job_id: state.job_id,
payload: Binary(
payload: Binary::new(
contract
.function("update_fee")
.unwrap()
Expand Down Expand Up @@ -342,7 +344,7 @@ fn update_service_fee_collector(
Ok(Response::new()
.add_message(CosmosMsg::Custom(PalomaMsg {
job_id: state.job_id,
payload: Binary(
payload: Binary::new(
contract
.function("update_service_fee_collector")
.unwrap()
Expand Down Expand Up @@ -388,7 +390,7 @@ fn update_service_fee(
Ok(Response::new()
.add_message(CosmosMsg::Custom(PalomaMsg {
job_id: state.job_id,
payload: Binary(
payload: Binary::new(
contract
.function("update_service_fee")
.unwrap()
Expand All @@ -401,10 +403,31 @@ fn update_service_fee(
.add_attribute("action", "update_service_fee"))
}

fn update_job_id(
deps: DepsMut,
info: MessageInfo,
new_job_id: String,
) -> Result<Response<PalomaMsg>, ContractError> {
let state = STATE.load(deps.storage)?;
if state.owner != info.sender {
return Err(Unauthorized {});
}

STATE.update(deps.storage, |mut state| -> Result<State, ContractError> {
state.job_id = new_job_id.clone();
Ok(state)
})?;

Ok(Response::new().add_attributes(vec![
("action", "update_job_id"),
("job_id", new_job_id.as_str()),
]))
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn query(deps: Deps, _env: Env, msg: QueryMsg) -> StdResult<Binary> {
match msg {
QueryMsg::GetJobId {} => to_binary(&get_job_id(deps)?),
QueryMsg::GetJobId {} => to_json_binary(&get_job_id(deps)?),
}
}

Expand Down
1 change: 1 addition & 0 deletions src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub enum ExecuteMsg {
UpdateFee { fee: Uint256 },
UpdateServiceFeeCollector { new_service_fee_collector: String },
UpdateServiceFee { new_service_fee: Uint256 },
UpdateJobId { new_job_id: String },
}

#[cw_serde]
Expand Down
Loading