Skip to content

Commit

Permalink
Merge branch 'main' into build-an-oapp
Browse files Browse the repository at this point in the history
  • Loading branch information
alijnmerchant21 authored Sep 5, 2024
2 parents 703c70e + 3396066 commit 035d69b
Show file tree
Hide file tree
Showing 13 changed files with 488 additions and 189 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* Added Keybase Id field (16 symbols)
* (x/act) [#631](https://github.com/warden-protocol/wardenprotocol/631) Add pruning of timed-out actions
* (x/warden) Make `KeychainFees` fields non-nullable, use an empty list of coins to indicate no fees
* (evm) Resolve dependencies issues. For go-ethereum use [evmos fork](https://github.com/evmos/go-ethereum/releases/tag/v1.10.26-evmos-rc2) patched with [c1b68f1d05a7ee8eee1bde3c4054f49f5d3e3b9f](https://github.com/ethereum/go-ethereum/pull/24911) from original repository to support slinky.
* (evm) To adopt ethsecp256k1 use fork of evmos's cosmos-sdk. Fork patched runtime/module adding into ProvideApp two arguments to customize registering interface registry and legacy amino codec.
* (evm) Introduce award denomination to adjust units with Ethereum
* (evm) Using ethsecp256k1 signature for all transactions. Users should reimport their seeds to get new addresses.
* (x/act) Introduce Votes and Approve/Reject expressions for Actions
* (x/act) Add expected expressions to MsgAddAction

### Features (non-breaking)

* (x/act) Add support for sdk.Coins fields in autogenerated CLI commands for new actions
* (x/warden) Add the ability for the user to specify the maximum keychain fee size to be deducted
* (evm) Resolve dependencies issues. For go-ethereum use [evmos fork](https://github.com/evmos/go-ethereum/releases/tag/v1.10.26-evmos-rc2) patched with [c1b68f1d05a7ee8eee1bde3c4054f49f5d3e3b9f](https://github.com/ethereum/go-ethereum/pull/24911) from original repository to support slinky.
* (evm) To adopt ethsecp256k1 use fork of evmos's cosmos-sdk. Fork patched runtime/module adding into ProvideApp two arguments to customize registering interface registry and legacy amino codec.
* (evm) Introduce award denomination to adjust units with Ethereum
* (evm) Using ethsecp256k1 signature for all transactions. Users should reimport their seeds to get new addresses.
* (x/warden) Return error if analyzer's address is not bech32
* (wardend) Validate bech32 format in add-genesis-keychain and add-genesis-space

Expand Down
293 changes: 243 additions & 50 deletions api/warden/act/v1beta1/tx.pulsar.go

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions cmd/faucet/faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ type Faucet struct {
}

const (
mutexLocked = 1
workers = 2
uwardConversion = 1000000
dailyHours = 24
mutexLocked = 1
workers = 2
dailyHours = 24
)

func execute(cmdString string) (Out, error) {
Expand Down Expand Up @@ -150,8 +149,8 @@ func InitFaucet(logger zerolog.Logger) (Faucet, error) {
Mutex: &sync.Mutex{},
Batch: []string{},
log: logger,
TokensAvailable: float64(cfg.DailyLimit) / uwardConversion,
DailySupply: float64(cfg.DailyLimit) / uwardConversion,
TokensAvailable: float64(cfg.DailyLimit),
DailySupply: float64(cfg.DailyLimit),
Amount: float64(amount),
}

Expand Down Expand Up @@ -231,9 +230,10 @@ func (f *Faucet) Send(addr string, force bool) (string, int, error) {
send = "multi-send"
}

f.log.Info().Msgf("sending %s%s to %v", f.config.Amount, f.config.Denom, f.Batch)
f.log.Info().Msgf("sending %s WARD to %v", f.config.Amount, f.Batch)

amount := f.config.Amount + f.config.Denom
amount := f.config.Amount + strings.Repeat("0", f.config.Decimals) + f.config.Denom
f.log.Info().Msg(amount)

cmd := strings.Join([]string{
f.config.CliName,
Expand All @@ -255,6 +255,7 @@ func (f *Faucet) Send(addr string, force bool) (string, int, error) {
"-o",
"json",
}, " ")
f.log.Info().Msg(cmd)

out, err := execute(cmd)
if err != nil {
Expand All @@ -278,7 +279,7 @@ func (f *Faucet) Send(addr string, force bool) (string, int, error) {
)
}

f.TokensAvailable = (f.TokensAvailable - float64(len(f.Batch))*f.Amount/uwardConversion)
f.TokensAvailable = (f.TokensAvailable - float64(len(f.Batch))*f.Amount)
f.log.Info().Msgf("tokens available: %f", f.TokensAvailable)
dailySupply.Set(f.TokensAvailable)

Expand Down
9 changes: 5 additions & 4 deletions cmd/faucet/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@ type Config struct {
ChainID string `env:"CHAIN_ID" envDefault:"buenavista-1" mapstructure:"CHAIN_ID"`
CliName string `env:"CLI_NAME" envDefault:"wardend" mapstructure:"CLI_NAME"`
AccountName string `env:"ACCOUNT_NAME" envDefault:"faucet" mapstructure:"ACCOUNT_NAME"`
Denom string `env:"DENOM" envDefault:"uward" mapstructure:"DENOM"`
Amount string `env:"AMOUNT" envDefault:"1000000" mapstructure:"AMOUNT"`
Fees string `env:"FEES" envDefault:"25uward" mapstructure:"FEES"`
Denom string `env:"DENOM" envDefault:"award" mapstructure:"DENOM"`
Amount string `env:"AMOUNT" envDefault:"1" mapstructure:"AMOUNT"`
Fees string `env:"FEES" envDefault:"25000000000000award" mapstructure:"FEES"`
KeyringBackend string `env:"KEYRING" envDefault:"test" mapstructure:"KEYRING"`
BatchInterval time.Duration `env:"BATCH_INTERVAL" envDefault:"5s" mapstructure:"BATCH_INTERVAL"`
DailyLimit int64 `env:"DAILY_LIMIT" envDefault:"100000000" mapstructure:"DAILY_LIMIT"`
DailyLimit int64 `env:"DAILY_LIMIT" envDefault:"100000" mapstructure:"DAILY_LIMIT"`
BatchLimit int `env:"BATCH_LIMIT" envDefault:"10" mapstructure:"BATCH_LIMIT"`
TXRetry int `env:"TX_RETRY" envDefault:"10" mapstructure:"TX_RETRY"`
Chain string `env:"CHAIN" envDefault:"Buenavista" mapstructure:"CHAIN"`
Decimals int `env:"DECIMALS" envDefault:"18" mapstructure:"DECIMALS"`
}

func LoadConfig() (Config, error) {
Expand Down
5 changes: 5 additions & 0 deletions proto/warden/act/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import "gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "warden/act/v1beta1/params.proto";
import "warden/act/v1beta1/action_vote.proto";
import "shield/ast/ast.proto";

option go_package = "github.com/warden-protocol/wardenprotocol/warden/x/act/types/v1beta1";

Expand Down Expand Up @@ -68,6 +69,10 @@ message MsgNewAction {
google.protobuf.Any message = 2;
// action_timeout_height is the block height up until this action can be executed.
uint64 action_timeout_height = 3;
// expected_approve_expression is the expected approval expression the action is created with
.shield.ast.Expression expected_approve_expression = 4 [(gogoproto.nullable) = false];
// expected_reject_expression is the expected reject expression the action is created with
.shield.ast.Expression expected_reject_expression = 5 [(gogoproto.nullable) = false];
}

message MsgNewActionResponse {
Expand Down
4 changes: 2 additions & 2 deletions spaceward/src/config/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ export const wardenprotocoldevnet: Chain = {
status: "live",
network_type: "testnet",
pretty_name: "Warden Protocol (devnet)",
chain_id: "warden",
chain_id: "devnet_12345-1",
bech32_prefix: "warden",
daemon_name: "wardend",
node_home: "$HOME/.warden",
key_algos: ["secp256k1", "ethsecp256k1"],
key_algos: ["ethsecp256k1"],
slip44: 60,
fees: {
fee_tokens: [
Expand Down
12 changes: 4 additions & 8 deletions spaceward/src/features/actions/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useChain } from "@cosmos-kit/react";
import { cosmos } from "@wardenprotocol/wardenjs";
import { createPersistantState } from "../../hooks/state";
import { useNewAction } from "../../hooks/useAction";
import { getSigningClient, TxOptions } from "../../hooks/useClient";
import { TxOptions, useTx } from "../../hooks/useClient";
import { env } from "../../env";
import { Action } from "@wardenprotocol/wardenjs/codegen/warden/act/v1beta1/action";
import { TransactionLike } from "ethers";
Expand Down Expand Up @@ -60,11 +60,9 @@ export const useActionsState = createPersistantState<
export function useEnqueueAction<Data>(
getMessage: ReturnType<typeof useNewAction<Data>>["getMessage"],
) {
const { address, getOfflineSignerDirect: getOfflineSigner } = useChain(
env.cosmoskitChainName,
);

const { address } = useChain(env.cosmoskitChainName);
const { setData } = useActionsState();
const { sign } = useTx();

async function addAction(
data: Parameters<typeof getMessage>[0],
Expand Down Expand Up @@ -100,11 +98,9 @@ export function useEnqueueAction<Data>(
}

const storeId = getActionId();
const signer = getOfflineSigner();
const client = await getSigningClient(signer);
const msg = getMessage(data, actionTimeoutHeight);
const fee = opts.fee || defaultFee;
const signedTx = await client.sign(address, [msg], fee, "");
const signedTx = await sign([msg], { fee });

setData({
[storeId]: {
Expand Down
31 changes: 20 additions & 11 deletions spaceward/src/hooks/useClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ export function useTx() {
const { address, getOfflineSignerDirect: getOfflineSigner, chain } = useChain(env.cosmoskitChainName);
const { toast } = useToast();

const sign = async (msgs: EncodeObject[], options: TxOptions) => {
const signer = getOfflineSigner();
const client = await getSigningClient(signer);

const fee = options.fee || defaultFee;
const txBody = TxBody.fromPartial({
messages: msgs,
memo: '',
});

return await buildTxRaw(chain.chain_id, client, signer, txBody, fee);
}

const tx = async (msgs: EncodeObject[], options: TxOptions) => {
if (!address) {
toast({
Expand All @@ -52,17 +65,13 @@ export function useTx() {
return;
}

let signed: Uint8Array;
const signer = getOfflineSigner();
const client = await getSigningClient(signer);

let signed: Uint8Array;
try {
const fee = options.fee || defaultFee;
const txBody = TxBody.fromPartial({
messages: msgs,
memo: '',
});
signed = await buildTxRaw(chain.chain_id, client, signer, txBody, fee);
const txRaw = await sign(msgs, options);
signed = TxRaw.encode(txRaw).finish();
} catch (e: unknown) {
console.error(e);
toast({
Expand All @@ -79,7 +88,7 @@ export function useTx() {
duration: 999999,
});

if (client && signed) {
if (signed) {
try {
const res = await client.broadcastTx(signed);
if (isDeliverTxSuccess(res)) {
Expand Down Expand Up @@ -122,7 +131,7 @@ export function useTx() {
}
};

return { tx };
return { tx, sign };
}

export function useQueryHooks() {
Expand Down Expand Up @@ -176,11 +185,11 @@ async function buildTxRaw(
const signDoc = makeSignDoc(txBodyBytes, authInfoBytes, chainId, Number(account.accountNumber));
const { signature, signed } = await signer.signDirect(signerAddress, signDoc);

return TxRaw.encode({
return TxRaw.fromPartial({
bodyBytes: signed.bodyBytes,
authInfoBytes: signed.authInfoBytes,
signatures: [fromBase64(signature.signature)],
}).finish();
});
}

async function fetchAccount(address: string) {
Expand Down
5 changes: 4 additions & 1 deletion warden/x/act/keeper/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/warden-protocol/wardenprotocol/shield"
"github.com/warden-protocol/wardenprotocol/shield/ast"
"github.com/warden-protocol/wardenprotocol/shield/object"
"github.com/warden-protocol/wardenprotocol/warden/x/act/cosmoshield"
types "github.com/warden-protocol/wardenprotocol/warden/x/act/types/v1beta1"
Expand Down Expand Up @@ -133,7 +134,7 @@ type actionCreatorKey struct{}
// AddAction creates a new action.
// The action is created with the provided creator as the first approver.
// This function also tries to execute the action immediately if it's ready.
func (k Keeper) AddAction(ctx context.Context, creator string, msg sdk.Msg, timeoutHeight uint64) (*types.Action, error) {
func (k Keeper) AddAction(ctx context.Context, creator string, msg sdk.Msg, timeoutHeight uint64, expectedApproveExpression ast.Expression, expectedRejectExpression ast.Expression) (*types.Action, error) {
if err := k.validateActionMsgSigners(msg); err != nil {
return nil, err
}
Expand All @@ -144,6 +145,8 @@ func (k Keeper) AddAction(ctx context.Context, creator string, msg sdk.Msg, time
return nil, errors.Wrapf(types.ErrNoRuleRegistryHandler, "%v", err)
}

// todo: check that expressions from rulesRegistry (templateRegistry) match with expected

wrappedMsg, err := codectypes.NewAnyWithValue(msg)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion warden/x/act/keeper/msg_server_new_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (k msgServer) NewAction(ctx context.Context, msg *types.MsgNewAction) (*typ
return nil, fmt.Errorf("can't unpack any: %w", err)
}

act, err := k.AddAction(ctx, msg.Creator, message, msg.ActionTimeoutHeight)
act, err := k.AddAction(ctx, msg.Creator, message, msg.ActionTimeoutHeight, msg.ExpectedApproveExpression, msg.ExpectedRejectExpression)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 035d69b

Please sign in to comment.