From c94e50a0e4feb6a133adb1983ec2a06192d80491 Mon Sep 17 00:00:00 2001 From: jelysn Date: Tue, 26 Sep 2023 10:31:38 +0800 Subject: [PATCH] hermes connection between mars and elys localnet and resolve issues --- docs/static/openapi.yml | 3 - mars.yml | 403 ++++++++++++++++++++++ scripts/examples/transferhook/README.md | 51 +++ scripts/examples/transferhook/config.toml | 132 +++++++ x/amm/keeper/abci.go | 7 +- x/amm/module.go | 3 +- x/transferhook/types/params.pb.go | 1 - 7 files changed, 594 insertions(+), 6 deletions(-) create mode 100644 mars.yml create mode 100644 scripts/examples/transferhook/README.md create mode 100644 scripts/examples/transferhook/config.toml diff --git a/docs/static/openapi.yml b/docs/static/openapi.yml index cd1089762..1a46b37fa 100644 --- a/docs/static/openapi.yml +++ b/docs/static/openapi.yml @@ -41450,7 +41450,6 @@ paths: properties: amm_active: type: boolean - title: turn off each module description: >- QueryParamsResponse is response type for the Query/Params RPC method. @@ -83096,7 +83095,6 @@ definitions: properties: amm_active: type: boolean - title: turn off each module description: Params defines the parameters for the module. elys.transferhook.QueryParamsResponse: type: object @@ -83107,7 +83105,6 @@ definitions: properties: amm_active: type: boolean - title: turn off each module description: QueryParamsResponse is response type for the Query/Params RPC method. ibc.applications.fee.v1.Fee: type: object diff --git a/mars.yml b/mars.yml new file mode 100644 index 000000000..8cdf75968 --- /dev/null +++ b/mars.yml @@ -0,0 +1,403 @@ +version: 1 +accounts: + - name: treasury2 + coins: + - 100000000uatom + - 100000000uusdt + - 9000000000000000uelys + - 100000000ueden + mnemonic: attend copy blast obey agent clinic monkey blur doctor sibling impact stomach judge rubber actress forest wage silent sick key divide exotic junk velvet + - name: seed2 + coins: + - 9000000000000000uelys +build: + main: cmd/elysd +client: + openapi: + path: docs/static/openapi.yml +faucet: + name: seed2 + coins: + - 1000000000000000uelys + host: :4501 +validators: + - name: treasury2 + bonded: 100000000uelys + home: $HOME/.mars + app: + api: + address: :1318 + grpc: + address: :9092 + grpc-web: + address: :9093 + config: + moniker: "elys2val" + p2p: + laddr: :26658 + rpc: + laddr: :26659 + pprof_laddr: :6061 +genesis: + app_state: + crisis: + constant_fee: + denom: uelys + gov: + deposit_params: + max_deposit_period: 20s + min_deposit: + - amount: "10000000" + denom: uelys + params: + burn_proposal_deposit_prevote: false + burn_vote_quorum: false + burn_vote_veto: true + max_deposit_period: 20s + min_deposit: + - amount: "10000000" + denom: uelys + min_initial_deposit_ratio: "0.000000000000000000" + quorum: "0.334000000000000000" + threshold: "0.500000000000000000" + veto_threshold: "0.334000000000000000" + voting_period: 20s + tally_params: + quorum: "0.334000000000000000" + threshold: "0.500000000000000000" + veto_threshold: "0.334000000000000000" + voting_params: + voting_period: 20s + mint: + params: + mint_denom: uelys + inflation_rate_change: "0.0" + inflation_max: "0.0" + inflation_min: "0.0" + slashing: + params: + signed_blocks_window: "30000" + min_signed_per_window: "0.05" + downtime_jail_duration: 600s + slash_fraction_double_sign: "0.05" + slash_fraction_downtime: "0.0001" + staking: + params: + bond_denom: uelys + unbonding_time: 1209600s + bank: + denom_metadata: + - base: uelys + denom_units: + - denom: uelys + exponent: 0 + aliases: + - microelys + - denom: melys + exponent: 3 + aliases: + - millielys + - denom: elys + exponent: 6 + aliases: [] + name: elys + symbol: elys + description: Native Elys token definition + display: elys + - base: ueden + denom_units: + - denom: ueden + exponent: 0 + aliases: + - microeden + - denom: meden + exponent: 3 + aliases: + - millieden + - denom: eden + exponent: 6 + aliases: [] + name: eden + symbol: eden + description: Eden token definition + display: eden + assetprofile: + entryList: + - address: "" + authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 + baseDenom: uelys + decimals: "6" + denom: uelys + displayName: ELYS + displaySymbol: "" + externalSymbol: "" + ibcChannelId: "" + ibcCounterpartyChainId: "" + ibcCounterpartyChannelId: "" + ibcCounterpartyDenom: "" + network: "" + path: "" + permissions: [] + transferLimit: "" + unitDenom: "" + commitEnabled: false + withdrawEnabled: true + - address: "" + authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 + baseDenom: cusdc + decimals: "6" + denom: cusdc + displayName: USDC + displaySymbol: "" + externalSymbol: "" + ibcChannelId: "" + ibcCounterpartyChainId: "" + ibcCounterpartyChannelId: "" + ibcCounterpartyDenom: "" + network: "" + path: "" + permissions: [] + transferLimit: "" + unitDenom: "" + commitEnabled: false + withdrawEnabled: true + - address: "" + authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 + baseDenom: ueden + decimals: "6" + denom: ueden + displayName: EDEN + displaySymbol: "" + externalSymbol: "" + ibcChannelId: "" + ibcCounterpartyChainId: "" + ibcCounterpartyChannelId: "" + ibcCounterpartyDenom: "" + network: "" + path: "" + permissions: [] + transferLimit: "" + unitDenom: "" + commitEnabled: true + withdrawEnabled: true + - address: "" + authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 + baseDenom: uedenb + decimals: "6" + denom: uedenb + displayName: EDEN-BOOST + displaySymbol: "" + externalSymbol: "" + ibcChannelId: "" + ibcCounterpartyChainId: "" + ibcCounterpartyChannelId: "" + ibcCounterpartyDenom: "" + network: "" + path: "" + permissions: [] + transferLimit: "" + unitDenom: "" + commitEnabled: true + withdrawEnabled: false + epochs: + epochs: + - identifier: week + duration: "168h" + currentEpoch: "0" + currentEpochStartHeight: "0" + epochCountingStarted: false + - identifier: day + duration: "24h" + currentEpoch: "0" + currentEpochStartHeight: "0" + epochCountingStarted: false + - identifier: hour + duration: "1h" + currentEpoch: "0" + currentEpochStartHeight: "0" + epochCountingStarted: false + - identifier: band_epoch + duration: "15s" + currentEpoch: "0" + currentEpochStartHeight: "0" + epochCountingStarted: false + - identifier: tenseconds + duration: "10s" + currentEpoch: "0" + currentEpochStartHeight: "0" + epochCountingStarted: false + commitment: + params: + vesting_infos: + - base_denom: ueden + vesting_denom: uelys + epoch_identifier: tenseconds + num_epochs: "10" + vest_now_factor: "90" + incentive: + params: + lp_incentives: + - amount: "10000000" + epoch_identifier: week + start_time: "2023-04-20T12:34:56.789Z" + num_epochs: "50" + current_epoch: "0" + eden_boost_apr: "100" + stake_incentives: + - amount: "10000000" + epoch_identifier: week + start_time: "2023-04-20T12:34:56.789Z" + num_epochs: "50" + current_epoch: "0" + eden_boost_apr: "100" + community_tax: "0.02" + withdraw_addr_enabled: true + reward_portion_for_lps: "0.65" + pool_infos: [] + fee_pool: + community_pool: + - amount: "0" + denom: uelys + tokenomics: + airdropList: + - intent: AtomStakers + amount: 9999999 + authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 + - intent: RowanStakersLP + amount: 9999999 + authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 + - intent: Juno + amount: 9999999 + authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 + - intent: Osmo + amount: 9999999 + authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 + - intent: Evmos + amount: 9999999 + authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 + genesisInflation: + inflation: + lmRewards: 9999999 + icsStakingRewards: 9999999 + communityFund: 9999999 + strategicReserve: 9999999 + teamTokensVested: 9999999 + seedVesting: 9999999 + strategicSalesVesting: 9999999 + authority: elys10d07y265gmmuvt4z0w9aw880jnsr700j6z2zm3 + timeBasedInflationList: + - startBlockHeight: 1 + endBlockHeight: 6307200 + description: 1st Year Inflation + inflation: + lmRewards: 9999999 + icsStakingRewards: 9999999 + communityFund: 9999999 + strategicReserve: 9999999 + teamTokensVested: 9999999 + - startBlockHeight: 6307201 + endBlockHeight: 12614401 + description: 2nd Year Inflation + inflation: + lmRewards: 9999999 + icsStakingRewards: 9999999 + communityFund: 9999999 + strategicReserve: 9999999 + teamTokensVested: 9999999 + - startBlockHeight: 12614402 + endBlockHeight: 18921602 + description: 3rd Year Inflation + inflation: + lmRewards: 9999999 + icsStakingRewards: 9999999 + communityFund: 9999999 + strategicReserve: 9999999 + teamTokensVested: 9999999 + oracle: + assetInfos: + - denom: "satoshi" + display: "BTC" + bandTicker: "BTC" + elysTicker: "BTC" + decimal: 9 + - denom: "wei" + display: "ETH" + bandTicker: "ETH" + elysTicker: "ETH" + decimal: 18 + - denom: "uatom" + display: "ATOM" + bandTicker: "ATOM" + elysTicker: "ATOM" + decimal: 6 + - denom: "uusdt" + display: "USDT" + bandTicker: "USDT" + elysTicker: "USDT" + decimal: 6 + params: + ask_count: "4" + band_channel_source: "channel-0" + band_epoch: "band_epoch" + client_id: "band_price_id" + execute_gas: "600000" + fee_limit: + - amount: "30" + denom: "uband" + min_count: "3" + multiplier: "18" + oracle_script_id: "37" + prepare_gas: "600000" + price_expiry_time: "86400" + portId: "oracle" + priceFeeders: + - feeder: "elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w" + is_active: true + prices: + - asset: USDT + price: "1.00" + provider: elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w + source: elys + timestamp: "1694743319" + - asset: USDC + price: "1.00" + provider: elys12tzylat4udvjj56uuhu3vj2n4vgp7cf9fwna9w + source: elys + timestamp: "1694743319" + burner: + params: + epochIdentifier: day + historyList: + - timestamp: "2023-04-21 14:57:03.612566186 +0000 UTC" + denom: "uelys" + amount: "1000000" + - timestamp: "2023-04-21 14:57:03.612566186 +0000 UTC" + denom: "ueden" + amount: "1000000" + parameter: + anteHandlerParam: + minCommissionRate: "0.05" + maxVotingPower: "0.66" + minSelfDelegation: "1" + margin: + params: + leverage_max: "10" + interest_rate_max: "0.00000027" + interest_rate_min: "0.00000003" + interest_rate_increase: "0.000000000333333333" + interest_rate_decrease: "0.000000000333333333" + health_gain_factor: "0.000000022" + epoch_length: 1 + removal_queue_threshold: "0.35" + max_open_positions: 9999 + pool_open_threshold: "1.0" + force_close_fund_percentage: "1.0" + force_close_fund_address: "elys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrec2l" + incremental_interest_payment_fund_percentage: "0.35" + incremental_interest_payment_fund_address: "elys1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqnrec2l" + sq_modifier: "10000000000000000000000000" + safety_factor: "1.05" + incremental_interest_payment_enabled: true + whitelisting_enabled: false + invariant_check_epoch: day + chain_id: marstestnet-1 diff --git a/scripts/examples/transferhook/README.md b/scripts/examples/transferhook/README.md new file mode 100644 index 000000000..896b848af --- /dev/null +++ b/scripts/examples/transferhook/README.md @@ -0,0 +1,51 @@ +# Local network connection + +### Start mars chain + +ignite chain serve --verbose --reset-once -c mars.yml + +### Start elys chain + +ignite chain serve --verbose --reset-once + +### Start relayer + +#### Configure and setup hermes + +```sh +hermes --config ./scripts/examples/transferhook/config.toml keys delete --chain marstestnet-1 --all +echo "attend copy blast obey agent clinic monkey blur doctor sibling impact stomach judge rubber actress forest wage silent sick key divide exotic junk velvet" > mars.txt +hermes --config ./scripts/examples/transferhook/config.toml keys add --chain marstestnet-1 --mnemonic-file=mars.txt + +hermes --config ./scripts/examples/transferhook/config.toml keys delete --chain elystestnet-1 --all +echo "olympic slide park figure frost benefit deer reform fly pull price airport submit monitor silk insect uphold convince pupil project ignore roof warfare slight" > elys.txt +hermes --config ./scripts/examples/transferhook/config.toml keys add --chain elystestnet-1 --mnemonic-file=elys.txt + +hermes --config ./scripts/examples/transferhook/config.toml create connection --a-chain elystestnet-1 --b-chain marstestnet-1 + +hermes --config ./scripts/examples/transferhook/config.toml create channel --a-chain elystestnet-1 --a-port transfer --b-port transfer --a-connection connection-0 + +hermes --config ./scripts/examples/transferhook/config.toml start +``` + +#### Try to send with memo + +```sh +elysd keys add acc1 --keyring-backend=test +ACC1=elys1jfmgwygyf9u3sx6xm36xlxf85v977k5c7l8w3q + +elysd tx ibc-transfer transfer transfer channel-0 $ACC1 10000uatom --chain-id=elystestnet-1 --from=treasury --keyring-backend=test -y --node=http://localhost:26657 +elysd query bank balances $ACC1 --node=http://localhost:26659 + +ATOM_IBC=ibc/27394FB092D2ECCD56123C74F36E4C1F926001CEADA9CA97EA622B25F41E5EB2 +elysd tx ibc-transfer transfer transfer channel-0 $ACC1 100$ATOM_IBC --chain-id=marstestnet-1 --from=acc1 --keyring-backend=test -y --node=http://localhost:26659 + +elysd tx amm create-pool 10uatom,10uusdt 10000uatom,10000uusdt 0.00 0.00 --from=treasury --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 + +# swap with transferhook +elysd tx ibc-transfer transfer transfer channel-0 '{"transferhook":{"receiver":"'$ACC1'","amm":{"action":"Swap","routes":[{"pool_id":0,"token_out_denom": "uusdt"}]}}}' 100$ATOM_IBC --chain-id=marstestnet-1 --from=acc1 --keyring-backend=test -y --node=http://localhost:26659 +elysd query bank balances $ACC1 --node=http://localhost:26657 + +elysd tx amm swap-exact-amount-in 10uatom 1 0 uusdt --from=acc1 --keyring-backend=test --chain-id=elystestnet-1 --yes --gas=1000000 +elysd query bank balances $ACC1 --node=http://localhost:26657 +``` diff --git a/scripts/examples/transferhook/config.toml b/scripts/examples/transferhook/config.toml new file mode 100644 index 000000000..83f7b566f --- /dev/null +++ b/scripts/examples/transferhook/config.toml @@ -0,0 +1,132 @@ +# The global section has parameters that apply globally to the relayer operation. +[global] + +# Specify the verbosity for the relayer logging output. Default: 'info' +# Valid options are 'error', 'warn', 'info', 'debug', 'trace'. +log_level = 'trace' + + +# Specify the mode to be used by the relayer. [Required] +[mode] + +# Specify the client mode. +[mode.clients] + +# Whether or not to enable the client workers. [Required] +enabled = true + +# Whether or not to enable periodic refresh of clients. [Default: true] +# Note: Even if this is disabled, clients will be refreshed automatically if +# there is activity on a connection or channel they are involved with. +refresh = true + +# Whether or not to enable misbehaviour detection for clients. [Default: false] +misbehaviour = true + +# Specify the connections mode. +[mode.connections] + +# Whether or not to enable the connection workers for handshake completion. [Required] +enabled = true + +# Specify the channels mode. +[mode.channels] + +# Whether or not to enable the channel workers for handshake completion. [Required] +enabled = true + +# Specify the packets mode. +[mode.packets] + +# Whether or not to enable the packet workers. [Required] +enabled = true + +# Parametrize the periodic packet clearing feature. +# Interval (in number of blocks) at which pending packets +# should be eagerly cleared. A value of '0' will disable +# periodic packet clearing. [Default: 100] +clear_interval = 100 + +# Whether or not to clear packets on start. [Default: false] +clear_on_start = true + +# Toggle the transaction confirmation mechanism. +# The tx confirmation mechanism periodically queries the `/tx_search` RPC +# endpoint to check that previously-submitted transactions +# (to any chain in this config file) have delivered successfully. +# Experimental feature. Affects telemetry if set to false. +# [Default: true] +tx_confirmation = true + +# The REST section defines parameters for Hermes' built-in RESTful API. +# https://hermes.informal.systems/rest.html +[rest] + +# Whether or not to enable the REST service. Default: false +enabled = true + +# Specify the IPv4/6 host over which the built-in HTTP server will serve the RESTful +# API requests. Default: 127.0.0.1 +host = '127.0.0.1' + +# Specify the port over which the built-in HTTP server will serve the restful API +# requests. Default: 3000 +port = 3000 + + +# The telemetry section defines parameters for Hermes' built-in telemetry capabilities. +# https://hermes.informal.systems/telemetry.html +[telemetry] + +# Whether or not to enable the telemetry service. Default: false +enabled = false + +# Specify the IPv4/6 host over which the built-in HTTP server will serve the metrics +# gathered by the telemetry service. Default: 127.0.0.1 +host = '127.0.0.1' + +# Specify the port over which the built-in HTTP server will serve the metrics gathered +# by the telemetry service. Default: 3001 +port = 3001 + +[[chains]] +id = 'marstestnet-1' +rpc_addr = 'http://127.0.0.1:26659' +grpc_addr = 'http://127.0.0.1:9092' +websocket_addr = 'ws://127.0.0.1:26659/websocket' +rpc_timeout = '10s' +account_prefix = 'elys' +key_name = 'mars' +store_prefix = 'ibc' +default_gas = 100000 +max_gas = 3000000 +gas_price = { price = 0.01, denom = 'uelys' } +gas_multiplier = 1.5 +max_msg_num = 30 +max_tx_size = 2097152 +clock_drift = '5s' +max_block_time = '10s' +trusting_period = '600s' +trust_threshold = { numerator = '1', denominator = '3' } +address_type = { derivation = 'cosmos' } + +[[chains]] +id = 'elystestnet-1' +rpc_addr = 'http://127.0.0.1:26657' +grpc_addr = 'http://127.0.0.1:9090' +websocket_addr = 'ws://127.0.0.1:26657/websocket' +rpc_timeout = '10s' +account_prefix = 'elys' +key_name = 'elys' +store_prefix = 'ibc' +default_gas = 100000 +max_gas = 3000000 +gas_price = { price = 0.01, denom = 'uelys' } +gas_multiplier = 1.5 +max_msg_num = 30 +max_tx_size = 2097152 +clock_drift = '5s' +max_block_time = '10s' +trusting_period = '600s' +trust_threshold = { numerator = '1', denominator = '3' } +address_type = { derivation = 'cosmos' } diff --git a/x/amm/keeper/abci.go b/x/amm/keeper/abci.go index 48b49f084..de78074ae 100644 --- a/x/amm/keeper/abci.go +++ b/x/amm/keeper/abci.go @@ -1,6 +1,7 @@ package keeper import ( + "encoding/json" "strings" "time" @@ -166,5 +167,9 @@ func (k Keeper) ExecuteSwapRequests(ctx sdk.Context) []sdk.Msg { func (k Keeper) EndBlocker(ctx sdk.Context) { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) - k.ExecuteSwapRequests(ctx) + msgs := k.ExecuteSwapRequests(ctx) + if len(msgs) > 0 { + bz, _ := json.Marshal(msgs) + k.Logger(ctx).Info("Executed swap requests: " + string(bz)) + } } diff --git a/x/amm/module.go b/x/amm/module.go index 739a57245..32be53d28 100644 --- a/x/amm/module.go +++ b/x/amm/module.go @@ -144,6 +144,7 @@ func (AppModule) ConsensusVersion() uint64 { return 1 } func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} // EndBlock contains the logic that is automatically triggered at the end of each block -func (am AppModule) EndBlock(_ sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { +func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { + am.keeper.EndBlocker(ctx) return []abci.ValidatorUpdate{} } diff --git a/x/transferhook/types/params.pb.go b/x/transferhook/types/params.pb.go index de41335a3..a6c3fcf3a 100644 --- a/x/transferhook/types/params.pb.go +++ b/x/transferhook/types/params.pb.go @@ -25,7 +25,6 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // Params defines the parameters for the module. type Params struct { - // turn off each module AmmActive bool `protobuf:"varint,1,opt,name=amm_active,json=ammActive,proto3" json:"amm_active,omitempty"` }