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

phase 2: auto-trade reward token revenue via routes in params #955

Merged
merged 34 commits into from
Dec 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6476e39
phase 2: auto-trade reward token revenue via routes in params
ethan-stride Oct 16, 2023
44c3f65
Adding new traderoute types and keepers (#980)
ethan-stride Nov 20, 2023
126fac2
Merge branch 'main' into autoswap-revenue-tokens
sampocs Nov 21, 2023
f0f74a6
phase 2 - trade route query (#988)
sampocs Nov 27, 2023
6ce4a61
phase 2 nit comments (#986)
sampocs Nov 27, 2023
2dee6d7
phase 2 - implement create trade route (#989)
sampocs Nov 27, 2023
18733e3
phase 2 - price ICQ to Osmosis twap store (#987)
sampocs Nov 28, 2023
d4f4fa6
min_swap_amount also gates reward token transfers (#991)
ethan-stride Nov 28, 2023
b32af28
phase 2 - misc proto renaming (#992)
sampocs Nov 28, 2023
3e0917a
phase 2 - added trade config (#995)
sampocs Nov 29, 2023
ba177b9
phase 2 - set ICA addresses in callback (#994)
sampocs Nov 29, 2023
bf9655c
phase 2 - integration tests (#997)
sampocs Nov 29, 2023
a28fb9d
reward converter - fixed pfm bug (#998)
sampocs Nov 30, 2023
74cd8a2
reward converter - remove cache context wrapper and add trade route c…
sampocs Nov 30, 2023
3abaee6
reward converter - generalized scripts for integration test host zone…
sampocs Nov 30, 2023
74c2d15
reward converter - validate basic unit tests (#1002)
sampocs Dec 4, 2023
4fac08f
reward converter - OnChanOpenAck unit tests (#1004)
sampocs Dec 4, 2023
fe21ad3
reward collector - ICA message unit tests (#1005)
sampocs Dec 4, 2023
919be7d
fixed issue with merge
sampocs Dec 4, 2023
5c9250e
reward converter - added ICA address validation (#1008)
sampocs Dec 6, 2023
981bfa3
reward converter - add trade route ID to portId (#1011)
sampocs Dec 7, 2023
4d98b92
reward converter - fix timeouts (#1019)
sampocs Dec 7, 2023
913b4d7
fixed merge errors
sampocs Dec 7, 2023
6704631
reward converter - Create/Update/Delete TradeRoute unit tests (#1015)
sampocs Dec 8, 2023
9fabe9b
reward converter - pool price query unit test (#1016)
sampocs Dec 8, 2023
5cd9b9f
reward converter - unit tests on query submissions and icqcallbacks (…
sampocs Dec 8, 2023
407a510
Merge branch 'main' into autoswap-revenue-tokens
sampocs Dec 8, 2023
01eb42a
nit changes after final skim
sampocs Dec 8, 2023
40a181a
Merge branch 'autoswap-revenue-tokens' of github.com:Stride-Labs/stri…
sampocs Dec 8, 2023
1e4d060
fixed merge conflict
sampocs Dec 8, 2023
c4298c8
added guardclause to prevent transfer if pool price not set
sampocs Dec 8, 2023
7ea1544
reward converter - restore trade route ICA (#1023)
sampocs Dec 9, 2023
c75e093
nit change to create_logs
sampocs Dec 9, 2023
57c0ea1
made IG tests dynamic
sampocs Dec 9, 2023
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
path = deps/juno
url = https://github.com/CosmosContracts/juno.git
[submodule "deps/osmosis"]
# Commit: v16.1.1-no-fees
# Commit: v20.5.0-no-fees
path = deps/osmosis
url = https://github.com/Stride-Labs/osmosis.git
[submodule "deps/stargaze"]
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ upgrade-integration-tests-part-1: start-docker-all start-upgrade-integration-tes
setup-ics:
UPGRADE_HEIGHT=150 bash $(DOCKERNET_HOME)/upgrades/setup_ics.sh

###############################################################################
### LocalNet ###
###############################################################################
start-local-node:
@bash scripts/start_local_node.sh

###############################################################################
### Local to Mainnet ###
###############################################################################
Expand Down
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@ func NewStrideApp(
keys[stakeibcmoduletypes.StoreKey],
keys[stakeibcmoduletypes.MemStoreKey],
app.GetSubspace(stakeibcmoduletypes.ModuleName),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
app.AccountKeeper,
app.BankKeeper,
app.ICAControllerKeeper,
Expand Down
99 changes: 98 additions & 1 deletion app/apptesting/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/cosmos/cosmos-sdk/baseapp"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/bech32"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/cosmos/gogoproto/proto"
Expand Down Expand Up @@ -231,7 +233,10 @@ func (s *AppTestHelper) CreateICAChannel(owner string) (channelID, portID string
_, transferChannelExists := s.App.IBCKeeper.ChannelKeeper.GetChannel(s.Ctx, ibctesting.TransferPort, ibctesting.FirstChannelID)
if !transferChannelExists {
ownerSplit := strings.Split(owner, ".")
s.Require().Equal(2, len(ownerSplit), "owner should be of the form: {HostZone}.{AccountName}")
isHostZoneICA := len(ownerSplit) == 2
isTradeRouteICA := len(ownerSplit) == 3
s.Require().True(isHostZoneICA || isTradeRouteICA,
"owner should be either of the form: {chainId}.{AccountName} or {chainId}.{rewarDenom}-{hostDenom}.{accountName}")

hostChainID := ownerSplit[0]
s.CreateTransferChannel(hostChainID)
Expand Down Expand Up @@ -352,6 +357,34 @@ func (s *AppTestHelper) UpdateChannelState(portId, channelId string, channelStat
s.App.IBCKeeper.ChannelKeeper.SetChannel(s.Ctx, portId, channelId, channel)
}

// Helper function to check if an ICA was submitted by seeing if the sequence number incremented
func (s *AppTestHelper) CheckICATxSubmitted(portId, channelId string, icaFunction func() error) {
// Get the sequence before the tested funciton is run
startSequence := s.MustGetNextSequenceNumber(portId, channelId)

// Run the test function and confirm there's no error
err := icaFunction()
s.Require().NoError(err, "no error expected executing tested function")

// Check that the sequence number incremented
endSequence := s.MustGetNextSequenceNumber(portId, channelId)
s.Require().Equal(startSequence+1, endSequence, "sequence number should have incremented from tested function")
}

// Helper function to check if an ICA was NOT submitted by seeing if the sequence number did not increment
func (s *AppTestHelper) CheckICATxNotSubmitted(portId, channelId string, icaFunction func() error) {
// Get the sequence before the tested funciton is run
startSequence := s.MustGetNextSequenceNumber(portId, channelId)

// Run the test function and confirm there's no error
err := icaFunction()
s.Require().NoError(err, "no error expected executing tested function")

// Check that the sequence number did not change
endSequence := s.MustGetNextSequenceNumber(portId, channelId)
s.Require().Equal(startSequence, endSequence, "sequence number should NOT have incremented from tested function")
}

// Constructs an ICA Packet Acknowledgement compatible with ibc-go v5+
func ICAPacketAcknowledgement(t *testing.T, msgType string, msgResponses []proto.Message) channeltypes.Acknowledgement {
txMsgData := &sdk.TxMsgData{
Expand Down Expand Up @@ -409,6 +442,13 @@ func (s *AppTestHelper) GetIBCDenomTrace(denom string) transfertypes.DenomTrace
return transfertypes.ParseDenomTrace(prefixedDenom)
}

// Helper function to get the next sequence number for testing when an ICA was submitted
func (s *AppTestHelper) MustGetNextSequenceNumber(portId, channelId string) uint64 {
sequence, found := s.App.StakeibcKeeper.IBCKeeper.ChannelKeeper.GetNextSequenceSend(s.Ctx, portId, channelId)
s.Require().True(found, "sequence number for port %s and channel %s was not found", portId, channelId)
return sequence
}

// Creates and stores an IBC denom from a base denom on transfer channel-0
// This is only required for tests that use the transfer keeper and require that the IBC
// denom is present in the store
Expand Down Expand Up @@ -437,6 +477,46 @@ func (s *AppTestHelper) MockClientLatestHeight(height uint64) {
s.App.IBCKeeper.ClientKeeper.SetClientState(s.Ctx, FirstClientId, &clientState)
}

// Helper function to mock out a client and connection to test
// mapping from connection ID back to chain ID
// This also mocks out the consensus state to enable testing registering interchain accounts
func (s *AppTestHelper) MockClientAndConnection(chainId, clientId, connectionId string) {
clientHeight := clienttypes.Height{
RevisionHeight: uint64(s.Ctx.BlockHeight()),
}
clientState := tendermint.ClientState{
ChainId: chainId,
LatestHeight: clientHeight,
TrustingPeriod: time.Minute * 10,
}
s.App.IBCKeeper.ClientKeeper.SetClientState(s.Ctx, clientId, &clientState)

consensusState := tendermint.ConsensusState{
Timestamp: s.Ctx.BlockTime(),
}
s.App.IBCKeeper.ClientKeeper.SetClientConsensusState(s.Ctx, clientId, clientHeight, &consensusState)

connection := connectiontypes.ConnectionEnd{
ClientId: clientId,
Versions: []*connectiontypes.Version{connectiontypes.DefaultIBCVersion},
}
s.App.IBCKeeper.ConnectionKeeper.SetConnection(s.Ctx, connectionId, connection)
}

// Helper function to mock out an ICA address
func (s *AppTestHelper) MockICAChannel(connectionId, channelId, owner, address string) {
// Create an open channel with the ICA port
portId, _ := icatypes.NewControllerPortID(owner)
channel := channeltypes.Channel{
State: channeltypes.OPEN,
}
s.App.IBCKeeper.ChannelKeeper.SetChannel(s.Ctx, portId, channelId, channel)

// Then set the address and make the channel active
s.App.ICAControllerKeeper.SetInterchainAccountAddress(s.Ctx, connectionId, portId, address)
s.App.ICAControllerKeeper.SetActiveChannelID(s.Ctx, connectionId, portId, channelId)
}

func (s *AppTestHelper) ConfirmUpgradeSucceededs(upgradeName string, upgradeHeight int64) {
s.Ctx = s.Ctx.WithBlockHeight(upgradeHeight - 1)
plan := upgradetypes.Plan{Name: upgradeName, Height: upgradeHeight}
Expand All @@ -452,6 +532,23 @@ func (s *AppTestHelper) ConfirmUpgradeSucceededs(upgradeName string, upgradeHeig
})
}

// Returns the bank store key prefix for an address and denom
// Useful for testing balance ICQs
func (s *AppTestHelper) GetBankStoreKeyPrefix(address, denom string) []byte {
_, addressBz, err := bech32.DecodeAndConvert(address)
s.Require().NoError(err, "no error expected when bech decoding address")
return append(banktypes.CreateAccountBalancesPrefix(addressBz), []byte(denom)...)
}

// Extracts the address and denom from a bank store prefix
// Useful for testing balance ICQs as it can confirm that the serialized query request
// data has the proper address and denom
func (s *AppTestHelper) ExtractAddressAndDenomFromBankPrefix(data []byte) (address, denom string) {
addressBz, denom, err := banktypes.AddressAndDenomFromBalancesStore(data[1:]) // Remove BalancePrefix byte
s.Require().NoError(err, "no error expected when getting address and denom from balance store")
return addressBz.String(), denom
}

// Generates a valid and invalid test address (used for non-keeper tests)
func GenerateTestAddrs() (string, string) {
pk1 := ed25519.GenPrivKey().PubKey()
Expand Down
3 changes: 3 additions & 0 deletions app/proposals_whitelisting.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ var WhiteListModule = map[string]struct{}{
"/cosmos.upgrade.v1beta1.MsgCancelUpgrade": {},
"/stride.icaoracle.MsgToggleOracle": {},
"/stride.icaoracle.MsgRemoveOracle": {},
"/stride.stakeibc.MsgCreateTradeRoute": {},
"/stride.stakeibc.MsgUpdateTradeRoute": {},
"/stride.stakeibc.MsgDeleteTradeRoute": {},
}

func IsModuleWhiteList(typeUrl string) bool {
Expand Down
2 changes: 1 addition & 1 deletion deps/osmosis
Submodule osmosis updated 1238 files
6 changes: 2 additions & 4 deletions dockernet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ make build-docker build={z}
volumes:
- ./dockernet/state/{new-host-zone}2:/home/{new-host-zone}/.{new-host-zone}d

...

{new-host-zone}5:
{new-host-zone}3:
image: stridezone:{new-host-zone}
volumes:
- ./dockernet/state/{new-host-zone}5:/home/{new-host-zone}/.{new-host-zone}d
- ./dockernet/state/{new-host-zone}3:/home/{new-host-zone}/.{new-host-zone}d
...
relayer-{chain}:
image: stridezone:relayer
Expand Down
55 changes: 50 additions & 5 deletions dockernet/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ if [[ "${ALL_HOST_CHAINS:-false}" == "true" ]]; then
elif [[ "${#HOST_CHAINS[@]}" == "0" ]]; then
HOST_CHAINS=(GAIA)
fi
REWARD_CONVERTER_HOST_ZONE=${HOST_CHAINS[0]}

# DENOMS
STRD_DENOM="ustrd"
Expand Down Expand Up @@ -108,7 +109,7 @@ IBC_STARS_DENOM=$IBC_STARS_CHANNEL_3_DENOM

# CHAIN PARAMS
BLOCK_TIME='1s'
STRIDE_HOUR_EPOCH_DURATION="90s"
STRIDE_HOUR_EPOCH_DURATION="60s"
STRIDE_DAY_EPOCH_DURATION="140s"
STRIDE_EPOCH_EPOCH_DURATION="35s"
STRIDE_MINT_EPOCH_DURATION="20s"
Expand Down Expand Up @@ -336,15 +337,24 @@ STRIDE_RELAYER_MNEMONICS=(
"$RELAYER_GAIA_ICS_MNEMONIC"
"$RELAYER_DYDX_MNEMONIC"
)
# Mnemonics for connections between two non-stride chains
RELAYER_NOBLE_DYDX_MNEMONIC="sentence fruit crumble sail bar knife exact flame apart prosper hint myth clean among tiny burden depart purity select envelope identify cross physical emerge"
RELAYER_DYDX_NOBLE_MNEMONIC="aerobic breeze claw climb bounce morning tank victory eight funny employ bracket hire reduce fine flee lava domain warfare loop theme fly tattoo must"
# Mnemonics for connections between accessory chains
RELAYER_STRIDE_OSMO_MNEMONIC="father october lonely ticket leave regret pudding buffalo return asthma plastic piano beef orient ill clip right phone ready pottery helmet hip solid galaxy"
RELAYER_OSMO_STRIDE_MNEMONIC="narrow assist come feel canyon anxiety three reason satoshi inspire region little attend impulse what student dog armor economy faculty dutch distance upon calm"
RELAYER_STRIDE_NOBLE_MNEMONIC="absent confirm lumber hobby glide alter remain yard mixed fiscal series kitchen effort protect pistol hire bless police year struggle near hour wisdom jewel"
RELAYER_NOBLE_STRIDE_MNEMONIC="jar point equal question fatigue frog disorder wasp labor obtain head print orbit entire frown high sadness dash retire idea coffee rubber rough until"
RELAYER_NOBLE_OSMO_MNEMONIC="actual field visual wage orbit add human unit happy rich evil chair entire person february cactus deputy impact gasp elbow sunset brand possible fly"
RELAYER_OSMO_NOBLE_MNEMONIC="obey clinic miss grunt inflict laugh sell moral kitchen tumble gold song flavor rather horn exhaust state amazing poverty differ approve spike village device"
# Mnemonics between host zone and accessory chains when running with GAIA as the host
RELAYER_GAIA_NOBLE_MNEMONIC="aerobic breeze claw climb bounce morning tank victory eight funny employ bracket hire reduce fine flee lava domain warfare loop theme fly tattoo must"
RELAYER_NOBLE_GAIA_MNEMONIC="sentence fruit crumble sail bar knife exact flame apart prosper hint myth clean among tiny burden depart purity select envelope identify cross physical emerge"
RELAYER_GAIA_OSMO_MNEMONIC="small fire step promote fox reward book seek arctic session illegal loyal because brass spoil minute wonder jazz shoe price muffin churn evil monitor"
RELAYER_OSMO_GAIA_MNEMONIC="risk wool reason sweet current strategy female miracle squeeze that wire develop ocean rapid domain lift blame monkey sick round museum item maze trumpet"
# Mnemonics between host zone and accessory chains when running with DYDX as the host
RELAYER_NOBLE_DYDX_MNEMONIC="sentence fruit crumble sail bar knife exact flame apart prosper hint myth clean among tiny burden depart purity select envelope identify cross physical emerge"
RELAYER_DYDX_NOBLE_MNEMONIC="aerobic breeze claw climb bounce morning tank victory eight funny employ bracket hire reduce fine flee lava domain warfare loop theme fly tattoo must"
RELAYER_DYDX_OSMO_MNEMONIC="small fire step promote fox reward book seek arctic session illegal loyal because brass spoil minute wonder jazz shoe price muffin churn evil monitor"
RELAYER_OSMO_DYDX_MNEMONIC="risk wool reason sweet current strategy female miracle squeeze that wire develop ocean rapid domain lift blame monkey sick round museum item maze trumpet"


STRIDE_ADDRESS() {
# After an upgrade, the keys query can sometimes print migration info,
# so we need to filter by valid addresses using the prefix
Expand Down Expand Up @@ -512,6 +522,41 @@ GET_COUNTERPARTY_TRANSFER_CHANNEL_ID() {
$main_cmd q ibc channel end transfer $channel_id | grep -A 2 counterparty | grep channel_id | awk '{print $2}'
}

GET_LATEST_PROPOSAL_ID() {
chain="$1"

main_cmd=$(GET_VAR_VALUE ${chain}_MAIN_CMD)
$main_cmd q gov proposals | grep ' id:' | tail -1 | awk '{printf $2}' | tr -d '"'
}

WATCH_PROPOSAL_STATUS() {
chain="$1"
proposal_id="$2"

main_cmd=$(GET_VAR_VALUE ${chain}_MAIN_CMD)

# Continually polls the proposal status until it passes or fails
while true; do
status=$($main_cmd query gov proposal $proposal_id | grep "status" | awk '{printf $2}')
if [[ "$status" == "PROPOSAL_STATUS_VOTING_PERIOD" ]]; then
echo " Proposal still in progress..."
sleep 5
elif [[ "$status" == "PROPOSAL_STATUS_PASSED" ]]; then
echo " Proposal passed!"
exit 0
elif [[ "$status" == "PROPOSAL_STATUS_REJECTED" ]]; then
echo " Proposal rejected!"
exit 1
elif [[ "$status" == "PROPOSAL_STATUS_FAILED" ]]; then
echo " Proposal failed!"
exit 1
else
echo "ERROR: Unknown proposal status: $status"
exit 1
fi
done
}

TRIM_TX() {
grep -E "code:|txhash:" | sed 's/^/ /'
}
Expand Down
3 changes: 2 additions & 1 deletion dockernet/config/ica_host.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"/cosmos.distribution.v1beta1.MsgFundCommunityPool",
"/ibc.applications.transfer.v1.MsgTransfer",
"/cosmwasm.wasm.v1.MsgExecuteContract",
"/cosmwasm.wasm.v1.MsgInstantiateContract"
"/cosmwasm.wasm.v1.MsgInstantiateContract",
"/osmosis.gamm.v1beta1.MsgSwapExactAmountIn"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,36 @@ global:
memo: ""
light-cache-size: 20
chains:
stride:
type: cosmos
value:
key: stride
chain-id: STRIDE
rpc-addr: http://stride1:26657
account-prefix: stride
keyring-backend: test
gas-adjustment: 1.3
gas-prices: 0.02ustrd
coin-type: 118
debug: false
timeout: 20s
output-format: json
sign-mode: direct
gaia:
type: cosmos
value:
key: gaia
chain-id: GAIA
rpc-addr: http://gaia1:26657
account-prefix: cosmos
keyring-backend: test
gas-adjustment: 1.3
gas-prices: 0.02uatom
coin-type: 118
debug: false
timeout: 20s
output-format: json
sign-mode: direct
dydx:
type: cosmos
value:
Expand Down Expand Up @@ -50,9 +80,18 @@ chains:
output-format: json
sign-mode: direct
paths:
dydx-noble:
# Paths for accessory chains
stride-osmo:
src:
chain-id: DYDX
chain-id: STRIDE
dst:
chain-id: OSMO
src-channel-filter:
rule: ""
channel-list: []
stride-noble:
src:
chain-id: STRIDE
dst:
chain-id: NOBLE
src-channel-filter:
Expand All @@ -66,11 +105,37 @@ paths:
src-channel-filter:
rule: ""
channel-list: []
osmo-dydx:
# Paths for host chain (if running GAIA)
gaia-noble:
src:
chain-id: GAIA
dst:
chain-id: NOBLE
src-channel-filter:
rule: ""
channel-list: []
osmo-gaia:
src:
chain-id: OSMO
dst:
chain-id: GAIA
src-channel-filter:
rule: ""
channel-list: []
# Paths for host chain (if running DYDX)
dydx-noble:
src:
chain-id: DYDX
dst:
chain-id: NOBLE
src-channel-filter:
rule: ""
channel-list: []
osmo-dydx:
src:
chain-id: OSMO
dst:
chain-id: DYDX
src-channel-filter:
rule: ""
channel-list: []
Loading
Loading