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

Feat/injective tf #224

Merged
merged 6 commits into from
Oct 27, 2023
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
58 changes: 54 additions & 4 deletions .github/workflows/ci-test-fmt-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ env:
CARGO_TERM_COLOR: always

jobs:
test_and_check:
name: Test and check
test_and_check-token_factory_feature:
name: Test and check Token factory feature
runs-on: ubuntu-latest

steps:
Expand Down Expand Up @@ -43,11 +43,11 @@ jobs:
override: true
components: rustfmt, clippy

- name: Run cargo-tarpaulin
- name: Run cargo-tarpaulin token_factory feature
uses: actions-rs/[email protected]
with:
version: "0.15.0"
args: '--features "injective token_factory" --locked -- --test-threads 4'
args: '--features "token_factory" --locked -- --test-threads 4'

- name: Upload to codecov.io
uses: codecov/codecov-action@v3
Expand Down Expand Up @@ -75,3 +75,53 @@ jobs:
chmod +x ./scripts/build_schemas.sh
./scripts/build_schemas.sh true
shell: bash

test_and_check-token_injective_feature:
name: Test and check Injective feature
runs-on: ubuntu-latest

steps:
# Cancel any existing runs to save on CI time
# - name: Cancel Previous Runs
# uses: styfle/[email protected]
# with:
# access_token: ${{ github.token }}
# Checkout code, with submodules using PAT
- name: Checkout sources
uses: actions/checkout@v3

# Use Rust Cache to speed up subsequent jobs with no cargo lock changes
- name: Use Rust cache
uses: Swatinem/rust-cache@v2
with:
key: "test"

# Install rust
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: 1.70.0
override: true
components: rustfmt, clippy

- name: Run cargo-tarpaulin injective feature
uses: actions-rs/[email protected]
with:
version: "0.15.0"
args: '--features "injective" --locked -- --test-threads 4'

- name: Run cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --locked -- -D warnings

#- name: Run cosmwasm linter
# run: cargo dylint cw_lint --workspace

- name: Run cargo fmt
uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
8 changes: 5 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ use cosmwasm_std::{
use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg};

use crate::contract::{MAX_AMP, MAX_AMP_CHANGE, MIN_AMP, MIN_RAMP_BLOCKS};
#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))]
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
use cosmwasm_std::coins;
#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))]
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
use white_whale::pool_network::asset::is_factory_token;
use white_whale::pool_network::asset::{
Asset, AssetInfo, AssetInfoRaw, TrioInfoRaw, MINIMUM_LIQUIDITY_AMOUNT,
};
#[cfg(feature = "token_factory")]
use white_whale::pool_network::denom::{Coin, MsgBurn, MsgMint};
#[cfg(feature = "injective")]
use white_whale::pool_network::denom_injective::{Coin, MsgBurn, MsgMint};
#[cfg(feature = "osmosis_token_factory")]
use white_whale::pool_network::denom_osmosis::{Coin, MsgBurn, MsgMint};
use white_whale::pool_network::swap;
Expand Down Expand Up @@ -672,7 +682,11 @@ fn mint_lp_token_msg(
sender: String,
amount: Uint128,
) -> Result<Vec<CosmosMsg>, ContractError> {
#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))]
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
if is_factory_token(liquidity_token.as_str()) {
let mut messages = vec![];
messages.push(<MsgMint as Into<CosmosMsg>>::into(MsgMint {
Expand All @@ -699,7 +713,11 @@ fn mint_lp_token_msg(
})])
}

#[cfg(all(not(feature = "token_factory"), not(feature = "osmosis_token_factory")))]
#[cfg(all(
not(feature = "token_factory"),
not(feature = "osmosis_token_factory"),
not(feature = "injective")
))]
Ok(vec![CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: liquidity_token,
msg: to_binary(&Cw20ExecuteMsg::Mint { recipient, amount })?,
Expand All @@ -714,7 +732,11 @@ fn burn_lp_token_msg(
sender: String,
amount: Uint128,
) -> Result<CosmosMsg, ContractError> {
#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))]
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
if is_factory_token(liquidity_token.as_str()) {
Ok(<MsgBurn as Into<CosmosMsg>>::into(MsgBurn {
sender,
Expand All @@ -731,7 +753,11 @@ fn burn_lp_token_msg(
}))
}

#[cfg(all(not(feature = "token_factory"), not(feature = "osmosis_token_factory")))]
#[cfg(all(
not(feature = "token_factory"),
not(feature = "osmosis_token_factory"),
not(feature = "injective")
))]
Ok(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: liquidity_token,
msg: to_binary(&Cw20ExecuteMsg::Burn { amount })?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ use cosmwasm_std::{
use cw20::MinterResponse;
use cw_storage_plus::Item;

#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))]
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
use cosmwasm_std::CosmosMsg;
use white_whale::pool_network::asset::{is_factory_token, Asset, AssetInfo, AssetInfoRaw};
#[cfg(feature = "token_factory")]
use white_whale::pool_network::denom::MsgCreateDenom;
#[cfg(feature = "injective")]
use white_whale::pool_network::denom_injective::MsgCreateDenom;
#[cfg(feature = "osmosis_token_factory")]
use white_whale::pool_network::denom_osmosis::MsgCreateDenom;
use white_whale::pool_network::querier::query_token_info;
Expand Down Expand Up @@ -207,7 +213,11 @@ pub fn instantiate_fees(

/// Gets the total supply of the given liquidity token
pub fn get_total_share(deps: &Deps, liquidity_token: String) -> StdResult<Uint128> {
#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))]
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
let total_share = if is_factory_token(liquidity_token.as_str()) {
//bank query total
deps.querier.query_supply(&liquidity_token)?.amount
Expand All @@ -218,7 +228,11 @@ pub fn get_total_share(deps: &Deps, liquidity_token: String) -> StdResult<Uint12
)?
.total_supply
};
#[cfg(all(not(feature = "token_factory"), not(feature = "osmosis_token_factory")))]
#[cfg(all(
not(feature = "token_factory"),
not(feature = "osmosis_token_factory"),
not(feature = "injective")
))]
let total_share = query_token_info(
&deps.querier,
deps.api.addr_validate(liquidity_token.as_str())?,
Expand Down Expand Up @@ -253,7 +267,11 @@ pub fn create_lp_token(
Ok(trio_info)
})?;

#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))]
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
return Ok(
Response::new().add_message(<MsgCreateDenom as Into<CosmosMsg>>::into(
MsgCreateDenom {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "terraswap-pair"
version = "1.3.2"
version = "1.3.3"
authors = [
"Terraform Labs, PTE.",
"DELIGHT LABS",
Expand Down Expand Up @@ -45,3 +45,7 @@ thiserror.workspace = true
protobuf.workspace = true
white-whale.workspace = true
cosmwasm-schema.workspace = true

[dev-dependencies]
cw-multi-test.workspace = true
cw20-base.workspace = true
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,26 @@ use cosmwasm_std::{
};
use cw20::{Cw20ExecuteMsg, Cw20ReceiveMsg};

#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))]
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
use cosmwasm_std::coins;
#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))]
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
use white_whale::pool_network::asset::is_factory_token;
use white_whale::pool_network::asset::{
get_total_share, has_factory_token, Asset, AssetInfo, AssetInfoRaw, PairInfoRaw,
MINIMUM_LIQUIDITY_AMOUNT,
};
#[cfg(feature = "token_factory")]
use white_whale::pool_network::denom::{Coin, MsgBurn, MsgMint};
#[cfg(feature = "injective")]
use white_whale::pool_network::denom_injective::{Coin, MsgBurn, MsgMint};
#[cfg(feature = "osmosis_token_factory")]
use white_whale::pool_network::denom_osmosis::{Coin, MsgBurn, MsgMint};
use white_whale::pool_network::pair::{Config, Cw20HookMsg, FeatureToggle, PoolFee};
Expand Down Expand Up @@ -577,7 +587,11 @@ fn mint_lp_token_msg(
sender: String,
amount: Uint128,
) -> Result<Vec<CosmosMsg>, ContractError> {
#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))]
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
if is_factory_token(liquidity_token.as_str()) {
let mut messages = vec![];
messages.push(<MsgMint as Into<CosmosMsg>>::into(MsgMint {
Expand All @@ -604,7 +618,11 @@ fn mint_lp_token_msg(
})])
}

#[cfg(all(not(feature = "token_factory"), not(feature = "osmosis_token_factory")))]
#[cfg(all(
not(feature = "token_factory"),
not(feature = "osmosis_token_factory"),
not(feature = "injective")
))]
Ok(vec![CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: liquidity_token,
msg: to_binary(&Cw20ExecuteMsg::Mint { recipient, amount })?,
Expand All @@ -619,7 +637,11 @@ fn burn_lp_token_msg(
sender: String,
amount: Uint128,
) -> Result<CosmosMsg, ContractError> {
#[cfg(any(feature = "token_factory", feature = "osmosis_token_factory"))]
#[cfg(any(
feature = "token_factory",
feature = "osmosis_token_factory",
feature = "injective"
))]
if is_factory_token(liquidity_token.as_str()) {
Ok(<MsgBurn as Into<CosmosMsg>>::into(MsgBurn {
sender,
Expand All @@ -635,7 +657,11 @@ fn burn_lp_token_msg(
funds: vec![],
}))
}
#[cfg(all(not(feature = "token_factory"), not(feature = "osmosis_token_factory")))]
#[cfg(all(
not(feature = "token_factory"),
not(feature = "osmosis_token_factory"),
not(feature = "injective")
))]
Ok(CosmosMsg::Wasm(WasmMsg::Execute {
contract_addr: liquidity_token,
msg: to_binary(&Cw20ExecuteMsg::Burn { amount })?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,18 @@ pub fn migrate(mut deps: DepsMut, _env: Env, _msg: MigrateMsg) -> Result<Respons
});
}

#[cfg(feature = "injective")]
if storage_version <= Version::parse("1.1.0")? {
migrations::migrate_to_v13x(deps.branch())?;
}

#[cfg(not(feature = "injective"))]
if storage_version <= Version::parse("1.0.4")? {
migrations::migrate_to_v110(deps.branch())?;
} else if storage_version == Version::parse("1.1.0")? {
migrations::migrate_to_v120(deps.branch())?;
}
#[cfg(not(feature = "injective"))]
if storage_version == Version::parse("1.2.0")? {
migrations::migrate_to_v130(deps.branch())?;
}
Expand Down
Loading
Loading