Skip to content

Commit

Permalink
Merge pull request #53 from timewave-computer/ls-permisionless-transfer
Browse files Browse the repository at this point in the history
ls permissionless transfer
  • Loading branch information
uditvira authored Jul 13, 2023
2 parents 48022a1 + aada06c commit 4d2c2ed
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 43 deletions.
2 changes: 1 addition & 1 deletion contracts/depositor/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ExecuteDeps<'a> = DepsMut<'a, NeutronQuery>;
// const DEFAULT_TIMEOUT_HEIGHT: u64 = 10000000;
const NEUTRON_DENOM: &str = "untrn";
const ATOM_DENOM: &str = "uatom";
const INTERCHAIN_ACCOUNT_ID: &str = "test";
const INTERCHAIN_ACCOUNT_ID: &str = "gaia-ica";

const CONTRACT_NAME: &str = "crates.io:covenant-depositor";
const CONTRACT_VERSION: &str = env!("CARGO_PKG_VERSION");
Expand Down
32 changes: 15 additions & 17 deletions contracts/ls/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub fn execute(
.debug(format!("WASMDEBUG: execute: received msg: {:?}", msg).as_str());
match msg {
ExecuteMsg::Tick {} => try_tick(deps, env, info),
ExecuteMsg::Transfer { amount } => try_execute_transfer(deps, env, info, amount),
ExecuteMsg::Received {} => try_handle_received(),
}
}
Expand All @@ -94,16 +95,11 @@ fn try_tick(deps: DepsMut, env: Env, info: MessageInfo) -> NeutronResult<Respons
verify_clock(&info.sender, &CLOCK_ADDRESS.load(deps.storage)?)?;

let current_state = CONTRACT_STATE.load(deps.storage)?;
let ica_address: Result<String, StdError> = ICA_ADDRESS.load(deps.storage);
let _gaia_account_address = match ica_address {
Ok(addr) => addr,
Err(_) => "todo".to_string(),
};


// here we want to make sure that ica is created
match current_state {
ContractState::Instantiated => try_register_stride_ica(deps, env),
ContractState::ICACreated => try_execute_transfer(deps, env, info),
ContractState::Complete => try_completed(deps),
ContractState::ICACreated => Ok(Response::default()),
}
}

Expand All @@ -122,10 +118,12 @@ fn try_register_stride_ica(deps: DepsMut, env: Env) -> NeutronResult<Response<Ne
.add_message(register))
}

// permisionless transfer
fn try_execute_transfer(
deps: DepsMut,
_env: Env,
_info: MessageInfo,
amount: Uint128,
) -> NeutronResult<Response<NeutronMsg>> {
let fee = IbcFee {
recv_fee: vec![], // must be empty
Expand All @@ -150,7 +148,7 @@ fn try_execute_transfer(

let coin = Coin {
denom,
amount: "10".to_string(),
amount: amount.to_string(),
};

let msg = MsgTransfer {
Expand All @@ -159,11 +157,8 @@ fn try_execute_transfer(
token: Some(coin),
sender: address,
receiver: lp_receiver.clone(),
timeout_height: Some(Height {
revision_number: 2,
revision_height: 800,
}),
timeout_timestamp: 0,
timeout_height: None,
timeout_timestamp: 10000,
};

// Serialize the Transfer message
Expand Down Expand Up @@ -664,10 +659,13 @@ pub fn reply(deps: DepsMut, env: Env, msg: Reply) -> StdResult<Response> {
}
}

pub fn handle_transfer_reply(deps: DepsMut, _env: Env, _msg: Reply) -> StdResult<Response> {
pub fn handle_transfer_reply(deps: DepsMut, _env: Env, msg: Reply) -> StdResult<Response> {
deps.api.debug("WASMDEBUG: transfer reply");

CONTRACT_STATE.save(deps.storage, &ContractState::Complete)?;
// if transfer errors, we roll back to instantiated state
// this will force an attempt to re-register the ICA
if msg.result.is_err() {
CONTRACT_STATE.save(deps.storage, &ContractState::Instantiated)?;
}

Ok(Response::default().add_attribute("method", "handle_transfer_reply"))
}
3 changes: 2 additions & 1 deletion contracts/ls/src/msg.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Addr, Binary};
use cosmwasm_std::{Addr, Binary, Uint128};
use covenant_clock_derive::clocked;

use crate::state::ContractState;
Expand Down Expand Up @@ -38,6 +38,7 @@ impl PresetLsFields {
#[cw_serde]
pub enum ExecuteMsg {
Received {},
Transfer { amount: Uint128 },
}

#[cw_serde]
Expand Down
1 change: 0 additions & 1 deletion contracts/ls/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ pub const IBC_PORT_ID: Item<String> = Item::new("ibc_port_id");
pub enum ContractState {
Instantiated,
ICACreated,
Complete,
}

pub const CONTRACT_STATE: Item<ContractState> = Item::new("contract_state");
Expand Down
20 changes: 3 additions & 17 deletions stride-covenant/tests/interchaintest/ics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,23 +838,9 @@ func TestICS(t *testing.T) {
}

// For LPer, we need to first gather astroport information
assets := []AstroportAsset{
AstroportAsset{
Info: AssetInfo{
NativeToken: &NativeToken{
Denom: neutronAtomIbcDenom,
},
},
Amount: "10",
},
AstroportAsset{
Info: AssetInfo{
NativeToken: &NativeToken{
Denom: neutronStatomDenom,
},
},
Amount: "10",
},
assets := AssetData{
NativeAssetDenom: "uatom",
LsAssetDenom: "stuatom",
}

// slippageTolerance := "0.01"
Expand Down
17 changes: 11 additions & 6 deletions stride-covenant/tests/interchaintest/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,17 @@ type PresetDepositorFields struct {
}

type PresetLpFields struct {
SlippageTolerance string `json:"slippage_tolerance,omitempty"`
Autostake bool `json:"autostake,omitempty"`
Assets []AstroportAsset `json:"assets"`
LpPosition string `json:"lp_position"`
LpCode uint64 `json:"lp_code"`
Label string `json:"label"`
SlippageTolerance string `json:"slippage_tolerance,omitempty"`
Autostake bool `json:"autostake,omitempty"`
Assets AssetData `json:"assets"`
LpPosition string `json:"lp_position"`
LpCode uint64 `json:"lp_code"`
Label string `json:"label"`
}

type AssetData struct {
NativeAssetDenom string `json:"native_asset_denom"`
LsAssetDenom string `json:"ls_asset_denom"`
}

// ----- Covenant Queries ------
Expand Down

0 comments on commit 4d2c2ed

Please sign in to comment.