-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
1,212 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/). | ||
|
||
## [1.0.0] - 2024-08-23 | ||
|
||
### Changed | ||
|
||
- Restructure of architecture to improve organisation of helper functions and also to enable re-use with multiple projects |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
mod address_generator; | ||
mod chain_mock; | ||
mod mocks; | ||
mod multi_test; | ||
mod test_tube; | ||
pub mod utils; | ||
|
||
pub use address_generator::{generate_inj_address, InjectiveAddressGenerator, StorageAwareInjectiveAddressGenerator}; | ||
pub use chain_mock::*; | ||
pub use mocks::*; | ||
pub use multi_test::*; | ||
pub use test_tube::*; | ||
pub use utils::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use crate::utils::human_to_dec; | ||
|
||
use injective_cosmwasm::{DerivativeMarket, MarketId, MarketMidPriceAndTOBResponse, MarketStatus, OracleType, SpotMarket}; | ||
use injective_math::FPDecimal; | ||
|
||
pub const MOCKED_MARKET_ID: &str = "0x01edfab47f124748dc89998eb33144af734484ba07099014594321729a0ca16b"; | ||
pub const MOCKED_SUBACCOUNT_ID: &str = "0x427aee334987c52fa7b567b2662bdbb68614e48c000000000000000000000001"; | ||
pub const MOCKED_FEE_RECIPIENT: &str = "0x01edfab47f124748dc89998eb33144af734484ba07099014594321729a0ca16b"; | ||
|
||
pub const MOCK_EXCHANGE_DECIMALS: i32 = 18i32; | ||
pub const MOCK_BASE_DECIMALS: i32 = 18i32; | ||
pub const MOCK_ATOM_DECIMALS: i32 = 8i32; | ||
pub const MOCK_QUOTE_DECIMALS: i32 = 6i32; | ||
|
||
pub const MOCK_ATOM_DENOM: &str = "atom"; | ||
pub const MOCK_GAS_DENOM: &str = "inj"; | ||
pub const MOCK_BASE_DENOM: &str = "ubase"; | ||
pub const MOCK_QUOTE_DENOM: &str = "usdt"; | ||
pub const MOCK_USDC_DENOM: &str = "usdc"; | ||
|
||
// Mock INJ Market | ||
pub fn mock_spot_market(market_id: &str) -> SpotMarket { | ||
SpotMarket { | ||
ticker: String::from("INJ:USDT"), | ||
base_denom: String::from("inj"), | ||
quote_denom: String::from("usdt"), | ||
market_id: MarketId::unchecked(market_id), | ||
maker_fee_rate: FPDecimal::ZERO, | ||
taker_fee_rate: FPDecimal::ZERO, | ||
status: MarketStatus::Active, | ||
min_price_tick_size: FPDecimal::must_from_str("0.000000000000001000"), | ||
min_quantity_tick_size: FPDecimal::must_from_str("10000000000000.0"), // 0.00001 @ 18dp | ||
relayer_fee_share_rate: FPDecimal::must_from_str("0.4"), | ||
} | ||
} | ||
|
||
// Mock INJ Market | ||
pub fn mock_derivative_market(market_id: &str) -> DerivativeMarket { | ||
DerivativeMarket { | ||
ticker: String::from("INJ:USDT"), | ||
oracle_base: String::from("inj"), | ||
oracle_quote: String::from("usdt"), | ||
oracle_type: OracleType::PriceFeed, | ||
oracle_scale_factor: 0u32, | ||
quote_denom: String::from("usdt"), | ||
market_id: MarketId::unchecked(market_id), | ||
initial_margin_ratio: FPDecimal::must_from_str("0.195"), | ||
maintenance_margin_ratio: FPDecimal::must_from_str("0.05"), | ||
maker_fee_rate: FPDecimal::ZERO, | ||
taker_fee_rate: FPDecimal::ZERO, | ||
isPerpetual: true, | ||
status: MarketStatus::Active, | ||
min_price_tick_size: FPDecimal::must_from_str("1000.0"), // 0.001 | ||
min_quantity_tick_size: FPDecimal::must_from_str("0.001"), // 0.001 | ||
} | ||
} | ||
|
||
pub fn mock_mid_price_tob() -> MarketMidPriceAndTOBResponse { | ||
MarketMidPriceAndTOBResponse { | ||
mid_price: Some(human_to_dec("10.0", MOCK_QUOTE_DECIMALS - MOCK_BASE_DECIMALS)), | ||
best_buy_price: Some(human_to_dec("9.95", MOCK_QUOTE_DECIMALS - MOCK_BASE_DECIMALS)), | ||
best_sell_price: Some(human_to_dec("10.05", MOCK_QUOTE_DECIMALS - MOCK_BASE_DECIMALS)), | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
mod address_generator; | ||
mod chain_mock; | ||
|
||
pub use address_generator::{generate_inj_address, InjectiveAddressGenerator, StorageAwareInjectiveAddressGenerator}; | ||
pub use chain_mock::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use injective_std::{ | ||
shim::{Any, Timestamp}, | ||
types::cosmos::{ | ||
authz::v1beta1::{GenericAuthorization, Grant, MsgGrant, MsgRevoke, MsgRevokeResponse}, | ||
bank::v1beta1::SendAuthorization, | ||
base::v1beta1::Coin as BaseCoin, | ||
}, | ||
}; | ||
use injective_test_tube::{Account, Authz, ExecuteResponse, InjectiveTestApp, Module, Runner, SigningAccount}; | ||
use prost::Message; | ||
|
||
pub fn create_generic_authorization(app: &InjectiveTestApp, granter: &SigningAccount, grantee: String, msg: String, expiration: Option<Timestamp>) { | ||
let authz = Authz::new(app); | ||
|
||
let mut buf = vec![]; | ||
GenericAuthorization::encode(&GenericAuthorization { msg }, &mut buf).unwrap(); | ||
|
||
authz | ||
.grant( | ||
MsgGrant { | ||
granter: granter.address(), | ||
grantee, | ||
grant: Some(Grant { | ||
authorization: Some(Any { | ||
type_url: GenericAuthorization::TYPE_URL.to_string(), | ||
value: buf.clone(), | ||
}), | ||
expiration, | ||
}), | ||
}, | ||
granter, | ||
) | ||
.unwrap(); | ||
} | ||
|
||
pub fn revoke_authorization(app: &InjectiveTestApp, granter: &SigningAccount, grantee: String, msg_type_url: String) { | ||
let _res: ExecuteResponse<MsgRevokeResponse> = app | ||
.execute_multiple( | ||
&[( | ||
MsgRevoke { | ||
granter: granter.address(), | ||
grantee, | ||
msg_type_url, | ||
}, | ||
MsgRevoke::TYPE_URL, | ||
)], | ||
granter, | ||
) | ||
.unwrap(); | ||
} | ||
|
||
pub fn create_send_authorization(app: &InjectiveTestApp, granter: &SigningAccount, grantee: String, amount: BaseCoin, expiration: Option<Timestamp>) { | ||
let authz = Authz::new(app); | ||
|
||
let mut buf = vec![]; | ||
SendAuthorization::encode( | ||
&SendAuthorization { | ||
spend_limit: vec![amount], | ||
allow_list: vec![], | ||
}, | ||
&mut buf, | ||
) | ||
.unwrap(); | ||
|
||
authz | ||
.grant( | ||
MsgGrant { | ||
granter: granter.address(), | ||
grantee, | ||
grant: Some(Grant { | ||
authorization: Some(Any { | ||
type_url: SendAuthorization::TYPE_URL.to_string(), | ||
value: buf.clone(), | ||
}), | ||
expiration, | ||
}), | ||
}, | ||
granter, | ||
) | ||
.unwrap(); | ||
} | ||
|
||
pub fn execute_grid_authorizations(app: &InjectiveTestApp, granter: &SigningAccount, grantee: String, msgs: Vec<String>) { | ||
for msg in msgs { | ||
create_generic_authorization(app, granter, grantee.clone(), msg, None); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use cosmwasm_std::Uint128; | ||
use injective_std::types::cosmos::{ | ||
bank::v1beta1::{MsgSend, QueryBalanceRequest}, | ||
base::v1beta1::Coin, | ||
}; | ||
use injective_test_tube::{Account, Bank, InjectiveTestApp, SigningAccount}; | ||
use std::str::FromStr; | ||
|
||
pub fn send(bank: &Bank<InjectiveTestApp>, amount: &str, denom: &str, from: &SigningAccount, to: &SigningAccount) { | ||
bank.send( | ||
MsgSend { | ||
from_address: from.address(), | ||
to_address: to.address(), | ||
amount: vec![Coin { | ||
amount: amount.to_string(), | ||
denom: denom.to_string(), | ||
}], | ||
}, | ||
from, | ||
) | ||
.unwrap(); | ||
} | ||
|
||
pub fn query_balance(bank: &Bank<InjectiveTestApp>, address: String, denom: String) -> Uint128 { | ||
let response = bank.query_balance(&QueryBalanceRequest { address, denom }).unwrap(); | ||
|
||
match response.balance { | ||
Some(balance) => Uint128::from_str(&balance.amount).unwrap(), | ||
None => Uint128::zero(), | ||
} | ||
} |
Oops, something went wrong.