Skip to content

Commit

Permalink
Merge pull request #2 from VolumeFi/bugfix/fixed-array
Browse files Browse the repository at this point in the history
bugfix
  • Loading branch information
taariq authored Oct 10, 2024
2 parents 2585b02 + d622831 commit 62658e1
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 16 deletions.
Binary file modified artifacts/aave_stable_yield_chaser_vault_cw.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
04a6886d7eb71170b418488f492e85794d00f1332263452d0c9a29603d4b4089 aave_stable_yield_chaser_vault_cw.wasm
0d6c97af0fb87a56a6c5e266c9f9742ca914b75137b550ebfb6deb9b754ab375 aave_stable_yield_chaser_vault_cw.wasm
109 changes: 94 additions & 15 deletions src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ pub mod execute {
]),
internal_type: None,
},
Param {
name: "receiver".to_string(),
kind: ParamType::Address,
internal_type: None,
},
],
outputs: Vec::new(),
constant: None,
Expand Down Expand Up @@ -156,7 +151,6 @@ pub mod execute {
&env.block.time,
)?;
}

if tokens.is_empty() {
Err(AllPending {})
} else {
Expand All @@ -179,19 +173,19 @@ pub mod execute {
fn get_change_asset_tokens(new_asset: String, swap_info: SwapInfo) -> Vec<Token> {
let token_new_asset: Token = Token::Address(Address::from_str(new_asset.as_str()).unwrap());
let mut token_swap_info: Vec<Token> = Vec::new();
token_swap_info.push(Token::Array(
token_swap_info.push(Token::FixedArray(
swap_info
.route
.iter()
.map(|x| Token::Address(Address::from_str(x.as_str()).unwrap()))
.collect(),
));
token_swap_info.push(Token::Array(
token_swap_info.push(Token::FixedArray(
swap_info
.swap_params
.iter()
.map(|x| {
Token::Array(
Token::FixedArray(
x.iter()
.map(|y| Token::Uint(Uint::from_big_endian(&y.to_be_bytes())))
.collect(),
Expand All @@ -205,7 +199,7 @@ pub mod execute {
token_swap_info.push(Token::Uint(Uint::from_big_endian(
&swap_info.expected.to_be_bytes(),
)));
token_swap_info.push(Token::Array(
token_swap_info.push(Token::FixedArray(
swap_info
.pools
.iter()
Expand Down Expand Up @@ -310,19 +304,19 @@ pub mod execute {

fn get_withdraw_tokens(swap_info: SwapInfo, receiver: String) -> Vec<Token> {
let mut token_swap_info: Vec<Token> = Vec::new();
token_swap_info.push(Token::Array(
token_swap_info.push(Token::FixedArray(
swap_info
.route
.iter()
.map(|x| Token::Address(Address::from_str(x.as_str()).unwrap()))
.collect(),
));
token_swap_info.push(Token::Array(
token_swap_info.push(Token::FixedArray(
swap_info
.swap_params
.iter()
.map(|x| {
Token::Array(
Token::FixedArray(
x.iter()
.map(|y| Token::Uint(Uint::from_big_endian(&y.to_be_bytes())))
.collect(),
Expand All @@ -336,7 +330,7 @@ pub mod execute {
token_swap_info.push(Token::Uint(Uint::from_big_endian(
&swap_info.expected.to_be_bytes(),
)));
token_swap_info.push(Token::Array(
token_swap_info.push(Token::FixedArray(
swap_info
.pools
.iter()
Expand Down Expand Up @@ -704,4 +698,89 @@ pub fn query(_deps: Deps, _env: Env, _msg: QueryMsg) -> StdResult<Binary> {
}

#[cfg(test)]
mod tests {}
mod tests {
use super::*;
use crate::msg::{ExecuteMsg, SwapInfo};
use cosmwasm_std::testing::{message_info, mock_dependencies, mock_env};
use cosmwasm_std::{Addr, Uint256};

#[test]
fn test_change_asset() {
let mut deps = mock_dependencies();
let env = mock_env();
let info = message_info(&Addr::unchecked("creator"), &[]);
let msg = InstantiateMsg {
retry_delay: 10,
job_id: "job_id".to_string(),
creator: "creator".to_string(),
signers: vec!["signer".to_string()],
};

instantiate(deps.as_mut(), env.clone(), info.clone(), msg).unwrap();
let msg = ExecuteMsg::ChangeAsset {
new_asset: "0x0000000000000000000000000000000000000000".to_string(),
swap_info: SwapInfo {
route: vec![
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
],
swap_params: vec![
vec![
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
],
vec![
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
],
vec![
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
],
vec![
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
],
vec![
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
Uint256::from(0u8),
],
],
amount: Uint256::from(0u8),
expected: Uint256::from(0u8),
pools: vec![
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
"0x0000000000000000000000000000000000000000".to_string(),
],
},
};
execute(deps.as_mut(), env, info, msg).unwrap();
}
}

0 comments on commit 62658e1

Please sign in to comment.