Skip to content

Commit

Permalink
updated authz ica to include expiration and updated trade script to u…
Browse files Browse the repository at this point in the history
…se authz
  • Loading branch information
sampocs committed Mar 21, 2024
1 parent e0dae0d commit 13a1e65
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dockernet/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ KEYS_LOGS=$DOCKERNET_HOME/logs/keys.log

# List of hosts enabled
# HOST_CHAINS have liquid staking support, ACCESSORY_CHAINS do not
HOST_CHAINS=(DYDX)
HOST_CHAINS=()
ACCESSORY_CHAINS=(NOBLE OSMO)

# If no host zones are specified above:
Expand Down
17 changes: 14 additions & 3 deletions dockernet/scripts/community-pool-staking/trade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ set -eu
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
source ${SCRIPT_DIR}/../../config.sh

# Simulates a trade by sending the native token to the trade account
# We'll send the amount that should have been sent from the ICA, which has the rebate excluded
TRADE_AMOUNT=997500

trade_account=$($STRIDE_MAIN_CMD q stakeibc list-trade-routes | grep trade_account -A 3 | grep address | awk '{print $2}')
host_denom_on_trade=$($STRIDE_MAIN_CMD q stakeibc list-trade-routes | grep host_denom_on_trade | awk '{print $2}')
$OSMO_MAIN_CMD tx bank send ${OSMO_VAL_PREFIX}1 $trade_account 997500${host_denom_on_trade} --from ${OSMO_VAL_PREFIX}1 -y
reward_denom_on_trade=$($STRIDE_MAIN_CMD q stakeibc list-trade-routes | grep reward_denom_on_trade | awk '{print $2}')

tx_file=${STATE}/${OSMO_NODE_PREFIX}1/swap_tx.json
$OSMO_MAIN_CMD tx gamm swap-exact-amount-in ${TRADE_AMOUNT}${reward_denom_on_trade} 1 \
--swap-route-pool-ids 1 --swap-route-denoms $host_denom_on_trade \
--from $trade_account --generate-only > tx_file
sleep 5

echo "Executing swap through authz..."
$OSMO_MAIN_CMD tx authz exec tx.json --from ${OSMO_VAL_PREFIX}1 -y | TRIM_TX
sleep 1
rm -f $tx_file
6 changes: 5 additions & 1 deletion x/stakeibc/keeper/reward_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ func (k Keeper) BuildTradeAuthzMsg(
switch permissionChange {
case types.AuthzPermissionChange_GRANT:
authorization := authz.NewGenericAuthorization(swapMsgTypeUrl)
grant, err := authz.NewGrant(ctx.BlockTime(), authorization, nil)
expiration := ctx.BlockTime().Add(time.Hour * 24 * 365 * 100) // 100 years

grant, err := authz.NewGrant(ctx.BlockTime(), authorization, &expiration)
if err != nil {
return nil, errorsmod.Wrapf(err, "unable to build grant struct")
}
Expand All @@ -206,12 +208,14 @@ func (k Keeper) BuildTradeAuthzMsg(
Grantee: grantee,
Grant: grant,
}}

case types.AuthzPermissionChange_REVOKE:
authzMsg = []proto.Message{&authz.MsgRevoke{
Granter: tradeRoute.TradeAccount.Address,
Grantee: grantee,
MsgTypeUrl: swapMsgTypeUrl,
}}

default:
return nil, errors.New("invalid permission change")
}
Expand Down

0 comments on commit 13a1e65

Please sign in to comment.