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

chore: osmoutils, twap, downtime-detector, ibc-hooks cherry-pick to v14 #3925

Merged
merged 30 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ad0c311
Upgrade IBC to v4.2.0 (#3838)
nicolaslara Dec 23, 2022
e8c3c6c
feat(x/twap): modify cli to add geometric option (#3812)
p0mvn Dec 22, 2022
a2fc2c8
Make wasm hooks importable (#3850)
nicolaslara Dec 23, 2022
129cbcb
refactor(x/twap): handle spot price error case in the context of geom…
p0mvn Dec 23, 2022
8196036
test(x/twap): add randomized geometric twap test on a balancer pool (…
p0mvn Dec 23, 2022
c7c0222
Basic geometric twap e2e test (#3835)
hieuvubk Dec 23, 2022
1afb23e
feat(x/twap): whitelist GeometricTwap and GeometricTwapToNow (#3852)
p0mvn Dec 23, 2022
c12bfa3
fix(scripts): proto gen for osmoutils (#3854)
p0mvn Dec 24, 2022
168ccda
fix(scripts): proto gen osmoutils path (#3859)
p0mvn Dec 27, 2022
de76db0
added packet timeouts to wasm hooks (#3862)
nicolaslara Dec 29, 2022
8f88f7d
add negative to cli (#3888)
czarcas7ic Dec 30, 2022
f4c7d47
Making osmoutils compile on chains that don't use our SDK fork (#3899)
nicolaslara Jan 2, 2023
19e4a9d
remove deprecation from arithmetic & geometric twap to now query (#3917)
iboss-ptk Jan 4, 2023
952b2d7
Add types & boilerplate for the Downtime detector module (#3609)
ValarDragon Dec 6, 2022
7ec5e4e
Add downtime detector module (#3688)
ValarDragon Dec 14, 2022
ecde767
Initial by hand fixes
czarcas7ic Jan 4, 2023
1500176
feat(osmomath): Exp2 function (#3708)
p0mvn Dec 16, 2022
048a2a5
[x/TWAP] Expose a geometric TWAP API (#3529)
stackman27 Dec 1, 2022
7ade440
fix twap by hand
czarcas7ic Jan 4, 2023
ea3af42
change to gamm
czarcas7ic Jan 4, 2023
813a6e8
fix balancer test
czarcas7ic Jan 4, 2023
640dfb9
bump to v14 upgrade
czarcas7ic Jan 4, 2023
f7ded6c
e2e fix
czarcas7ic Jan 4, 2023
da63fa8
add remaining diff from main to ibc-rate-limit
czarcas7ic Jan 5, 2023
7d25928
update contracts test
czarcas7ic Jan 5, 2023
f864dcf
osmomath: `AddMut` and `QuoMut` (#3779)
pysel Dec 22, 2022
35ab94e
Modify CHANGELOG
mattverse Jan 5, 2023
09ccc37
Whitelist EstimateSwapExactAmountOut (#3693)
byeongsu-hong Dec 13, 2022
3a4aac2
updated rate limit contract
nicolaslara Jan 5, 2023
d5dda29
Fix rust checks (#3576)
nicolaslara Nov 30, 2022
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
18 changes: 15 additions & 3 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (
ibcratelimit "github.com/osmosis-labs/osmosis/v13/x/ibc-rate-limit"
ibcratelimittypes "github.com/osmosis-labs/osmosis/v13/x/ibc-rate-limit/types"
ibchooks "github.com/osmosis-labs/osmosis/x/ibc-hooks"
ibchookskeeper "github.com/osmosis-labs/osmosis/x/ibc-hooks/keeper"
ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types"

icahost "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/host/keeper"
Expand Down Expand Up @@ -101,8 +103,10 @@ type AppKeepers struct {
AuthzKeeper *authzkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
DistrKeeper *distrkeeper.Keeper
DowntimeKeeper *downtimedetector.Keeper
SlashingKeeper *slashingkeeper.Keeper
IBCKeeper *ibckeeper.Keeper
IBCHooksKeeper *ibchookskeeper.Keeper
ICAHostKeeper *icahostkeeper.Keeper
TransferKeeper *ibctransferkeeper.Keeper
EvidenceKeeper *evidencekeeper.Keeper
Expand Down Expand Up @@ -212,7 +216,13 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
appKeepers.ScopedIBCKeeper,
)

appKeepers.WireICS20PreWasmKeeper(appCodec, bApp)
// Configure the hooks keeper
hooksKeeper := ibchookskeeper.NewKeeper(
appKeepers.keys[ibchookstypes.StoreKey],
)
appKeepers.IBCHooksKeeper = &hooksKeeper

appKeepers.WireICS20PreWasmKeeper(appCodec, bApp, appKeepers.IBCHooksKeeper)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for adding these manually instead of cherry picking #3589 ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might have just been my confusion dealing with multiple cherry picks


icaHostKeeper := icahostkeeper.NewKeeper(
appCodec, appKeepers.keys[icahosttypes.StoreKey],
Expand Down Expand Up @@ -393,9 +403,10 @@ func (appKeepers *AppKeepers) InitNormalKeepers(
// appkeepers.WasmHooks AND appKeepers.RateLimitingICS4Wrapper
func (appKeepers *AppKeepers) WireICS20PreWasmKeeper(
appCodec codec.Codec,
bApp *baseapp.BaseApp) {
bApp *baseapp.BaseApp,
hooksKeeper *ibchookskeeper.Keeper) {
// Setup the ICS4Wrapper used by the hooks middleware
wasmHooks := ibchooks.NewWasmHooks(nil) // The contract keeper needs to be set later
wasmHooks := ibchooks.NewWasmHooks(hooksKeeper, nil) // The contract keeper needs to be set later
appKeepers.Ics20WasmHooks = &wasmHooks
appKeepers.HooksICS4Wrapper = ibchooks.NewICS4Middleware(
appKeepers.IBCKeeper.ChannelKeeper,
Expand Down Expand Up @@ -599,5 +610,6 @@ func KVStoreKeys() []string {
superfluidtypes.StoreKey,
wasm.StoreKey,
tokenfactorytypes.StoreKey,
ibchookstypes.StoreKey,
}
}
6 changes: 4 additions & 2 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"

ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types"

ica "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts"
icatypes "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts/types"

Expand Down Expand Up @@ -79,7 +81,7 @@ import (
var moduleAccountPermissions = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
ibc_hooks.ModuleName: nil,
ibchookstypes.ModuleName: nil,
icatypes.ModuleName: nil,
minttypes.ModuleName: {authtypes.Minter, authtypes.Burner},
minttypes.DeveloperVestingModuleAcctName: nil,
Expand Down Expand Up @@ -228,7 +230,7 @@ func OrderInitGenesis(allModuleNames []string) []string {
// wasm after ibc transfer
wasm.ModuleName,
// ibc_hooks after auth keeper
ibc_hooks.ModuleName,
ibchookstypes.ModuleName,
}
}

Expand Down
4 changes: 3 additions & 1 deletion app/upgrades/v13/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"testing"

ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types"

ibcratelimittypes "github.com/osmosis-labs/osmosis/v13/x/ibc-rate-limit/types"

"github.com/cosmos/cosmos-sdk/store/prefix"
Expand Down Expand Up @@ -65,7 +67,7 @@ func (suite *UpgradeTestSuite) TestUpgrade() {
upgradeStoreKey := suite.App.AppKeepers.GetKey(upgradetypes.StoreKey)
store := suite.Ctx.KVStore(upgradeStoreKey)
versionStore := prefix.NewStore(store, []byte{upgradetypes.VersionMapByte})
versionStore.Delete([]byte(ibc_hooks.ModuleName))
versionStore.Delete([]byte(ibchookstypes.ModuleName))

hasAcc := suite.App.AccountKeeper.HasAccount(suite.Ctx, ibc_hooks.WasmHookModuleAccountAddr)
suite.Require().False(hasAcc)
Expand Down
5 changes: 1 addition & 4 deletions app/upgrades/v14/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ import (

"github.com/osmosis-labs/osmosis/v13/app/upgrades"
downtimetypes "github.com/osmosis-labs/osmosis/v13/x/downtime-detector/types"
protorevtypes "github.com/osmosis-labs/osmosis/v13/x/protorev/types"
swaproutertypes "github.com/osmosis-labs/osmosis/v13/x/swaprouter/types"
valsetpreftypes "github.com/osmosis-labs/osmosis/v13/x/valset-pref/types"
)

// UpgradeName defines the on-chain upgrade name for the Osmosis v14 upgrade.
Expand All @@ -19,7 +16,7 @@ var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{valsetpreftypes.StoreKey, protorevtypes.StoreKey, swaproutertypes.StoreKey, downtimetypes.StoreKey, ibchookstypes.StoreKey},
Added: []string{downtimetypes.StoreKey, ibchookstypes.StoreKey},
Deleted: []string{},
},
}
21 changes: 21 additions & 0 deletions app/upgrades/v14/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package v14

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/osmosis-labs/osmosis/v13/app/keepers"
"github.com/osmosis-labs/osmosis/v13/app/upgrades"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
bpm upgrades.BaseAppParamManager,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, vm)
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ require (
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.34.24
github.com/tendermint/tm-db v0.6.8-0.20220506192307-f628bb5dc95b
go.uber.org/multierr v1.9.0
github.com/tidwall/btree v1.6.0
go.uber.org/multierr v1.9.0
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e
google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e
google.golang.org/grpc v1.50.1
Expand Down
41 changes: 41 additions & 0 deletions proto/osmosis/twap/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,46 @@ message ArithmeticTwapToNowResponse {
];
}

message GeometricTwapRequest {
uint64 pool_id = 1;
string base_asset = 2;
string quote_asset = 3;
google.protobuf.Timestamp start_time = 4 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true,
(gogoproto.moretags) = "yaml:\"start_time\""
];
google.protobuf.Timestamp end_time = 5 [
(gogoproto.nullable) = true,
(gogoproto.stdtime) = true,
(gogoproto.moretags) = "yaml:\"end_time\""
];
}
message GeometricTwapResponse {
string geometric_twap = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"geometric_twap\"",
(gogoproto.nullable) = false
];
}

message GeometricTwapToNowRequest {
uint64 pool_id = 1;
string base_asset = 2;
string quote_asset = 3;
google.protobuf.Timestamp start_time = 4 [
(gogoproto.nullable) = false,
(gogoproto.stdtime) = true,
(gogoproto.moretags) = "yaml:\"start_time\""
];
}
message GeometricTwapToNowResponse {
string geometric_twap = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.moretags) = "yaml:\"geometric_twap\"",
(gogoproto.nullable) = false
];
}

message ParamsRequest {}
message ParamsResponse { Params params = 1 [ (gogoproto.nullable) = false ]; }
12 changes: 12 additions & 0 deletions proto/osmosis/twap/v1beta1/query.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ queries:
query_func: "k.GetArithmeticTwapToNow"
cli:
cmd: "ArithmeticTwapToNow"
GeometricTwap:
proto_wrapper:
default_values:
Req.end_time: "ctx.BlockTime()"
query_func: "k.GetGeometricTwap"
cli:
cmd: "ArithmeticTwap"
GeometricTwapToNow:
proto_wrapper:
query_func: "k.GetGeometricTwapToNow"
cli:
cmd: "GeometricTwapToNow"
Params:
proto_wrapper:
query_func: "k.GetParams"
Expand Down
8 changes: 5 additions & 3 deletions proto/osmosis/twap/v1beta1/twap_record.proto
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ message TwapRecord {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// string geometric_twap_accumulator = 7 [(gogoproto.customtype) =
// "github.com/cosmos/cosmos-sdk/types.Dec",
// (gogoproto.nullable) = false];

string geometric_twap_accumulator = 10 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

// This field contains the time in which the last spot price error occured.
// It is used to alert the caller if they are getting a potentially erroneous
Expand Down
Binary file added tests/ibc-hooks/bytecode/crosschain_swaps.wasm
Binary file not shown.
Binary file added tests/ibc-hooks/bytecode/echo.wasm
Binary file not shown.
Binary file added tests/ibc-hooks/bytecode/swaprouter.wasm
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,40 @@ pub fn instantiate(
.add_attribute("count", msg.count.to_string()))
}

pub mod utils {
use cosmwasm_std::Addr;

use super::*;

pub fn update_counter(
deps: DepsMut,
sender: Addr,
update_counter: &dyn Fn(&Option<Counter>) -> i32,
update_funds: &dyn Fn(&Option<Counter>) -> Vec<Coin>,
) -> Result<bool, ContractError> {
COUNTERS
.update(
deps.storage,
sender.clone(),
|state| -> Result<_, ContractError> {
match state {
None => Ok(Counter {
count: update_counter(&None),
total_funds: update_funds(&None),
owner: sender,
}),
Some(counter) => Ok(Counter {
count: update_counter(&Some(counter.clone())),
total_funds: update_funds(&Some(counter)),
owner: sender,
}),
}
},
)
.map(|_r| true)
}
}

#[cfg_attr(not(feature = "library"), entry_point)]
pub fn execute(
deps: DepsMut,
Expand All @@ -53,25 +87,18 @@ pub mod execute {
use super::*;

pub fn increment(deps: DepsMut, info: MessageInfo) -> Result<Response, ContractError> {
COUNTERS.update(
deps.storage,
info.sender.clone(),
|state| -> Result<_, ContractError> {
match state {
None => Ok(Counter {
count: 0,
total_funds: vec![],
owner: info.sender.clone(),
}),
Some(counter) => Ok(Counter {
count: counter.count + 1,
total_funds: naive_add_coins(&info.funds, &counter.total_funds),
owner: info.sender.clone(),
}),
}
utils::update_counter(
deps,
info.sender,
&|counter| match counter {
None => 0,
Some(counter) => counter.count + 1,
},
&|counter| match counter {
None => info.funds.clone(),
Some(counter) => naive_add_coins(&info.funds, &counter.total_funds),
},
)?;

Ok(Response::new().add_attribute("action", "increment"))
}

Expand Down Expand Up @@ -114,8 +141,9 @@ pub mod sudo {
None => 1,
Some(counter) => counter.count + 1,
},
&|_counter| vec![],
)?;
Ok(Response::new().add_attribute("action", "reset"))
Ok(Response::new().add_attribute("action", "ack"))
}

pub(crate) fn ibc_timeout(deps: DepsMut, contract: Addr) -> Result<Response, ContractError> {
Expand All @@ -141,7 +169,6 @@ pub fn naive_add_coins(lhs: &Vec<Coin>, rhs: &Vec<Coin>) -> Vec<Coin> {
coins.insert(coin.denom.clone(), coin.amount);
}


for coin in rhs {
coins
.entry(coin.denom.clone())
Expand Down Expand Up @@ -295,12 +322,20 @@ mod tests {

// beneficiary can release it
let unauth_info = mock_info("anyone", &coins(2, "token"));
let msg = ExecuteMsg::Reset { count: 5 };
let res = execute(deps.as_mut(), mock_env(), unauth_info, msg);
match res {
Err(ContractError::Unauthorized {}) => {}
_ => panic!("Must return unauthorized error"),
}
let msg = ExecuteMsg::Reset { count: 7 };
let _res = execute(deps.as_mut(), mock_env(), unauth_info, msg);

// should be 7
let res = query(
deps.as_ref(),
mock_env(),
QueryMsg::GetCount {
addr: Addr::unchecked("anyone"),
},
)
.unwrap();
let value: GetCountResponse = from_binary(&res).unwrap();
assert_eq!(7, value.count);

// only the original creator can reset the counter
let auth_info = mock_info("creator", &coins(2, "token"));
Expand All @@ -319,4 +354,42 @@ mod tests {
let value: GetCountResponse = from_binary(&res).unwrap();
assert_eq!(5, value.count);
}

#[test]
fn acks() {
let mut deps = mock_dependencies();
let env = mock_env();
let get_msg = QueryMsg::GetCount {
addr: Addr::unchecked(env.clone().contract.address),
};

// No acks
query(deps.as_ref(), env.clone(), get_msg.clone()).unwrap_err();

let msg = SudoMsg::ReceiveAck {
channel: format!("channel-0"),
sequence: 1,
ack: String::new(),
success: true,
};
let _res = sudo(deps.as_mut(), env.clone(), msg).unwrap();

// should increase counter by 1
let res = query(deps.as_ref(), env.clone(), get_msg.clone()).unwrap();
let value: GetCountResponse = from_binary(&res).unwrap();
assert_eq!(1, value.count);

let msg = SudoMsg::ReceiveAck {
channel: format!("channel-0"),
sequence: 1,
ack: String::new(),
success: true,
};
let _res = sudo(deps.as_mut(), env.clone(), msg).unwrap();

// should increase counter by 1
let res = query(deps.as_ref(), env, get_msg).unwrap();
let value: GetCountResponse = from_binary(&res).unwrap();
assert_eq!(2, value.count);
}
}
Loading