Skip to content

Commit c725b57

Browse files
codchenphilipsu522
andauthored
Add message type to associate CW contract address (#1681)
* Add message type to associate CW contract address * fix test * bump sei-wasmd to fix ignite --------- Co-authored-by: Philip Su <[email protected]>
1 parent 16a2b18 commit c725b57

18 files changed

+592
-72
lines changed

app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ func New(
590590

591591
app.EvmKeeper = *evmkeeper.NewKeeper(keys[evmtypes.StoreKey], memKeys[evmtypes.MemStoreKey],
592592
app.GetSubspace(evmtypes.ModuleName), app.BankKeeper, &app.AccountKeeper, &app.StakingKeeper,
593-
app.TransferKeeper, wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper))
593+
app.TransferKeeper, wasmkeeper.NewDefaultPermissionKeeper(app.WasmKeeper), &app.WasmKeeper)
594594
app.evmRPCConfig, err = evmrpc.ReadConfig(appOpts)
595595
if err != nil {
596596
panic(fmt.Sprintf("error reading EVM config due to %s", err))

contracts/test/CW20toERC20PointerTest.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {getAdmin, queryWasm, executeWasm, deployEvmContract, setupSigners, deployErc20PointerForCw20, deployWasm, WASM,
1+
const {getAdmin, queryWasm, executeWasm, associateWasm, deployEvmContract, setupSigners, deployErc20PointerForCw20, deployWasm, WASM,
22
registerPointerForCw20
33
} = require("./lib")
44
const { expect } = require("chai");
@@ -102,6 +102,7 @@ describe("CW20 to ERC20 Pointer", function () {
102102
});
103103

104104
it("transfer to contract address should succeed", async function() {
105+
await associateWasm(cw20Pointer);
105106
const respBefore = await queryWasm(cw20Pointer, "balance", {address: admin.seiAddress})
106107
const balanceBefore = respBefore.data.balance;
107108

contracts/test/lib.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,12 @@ async function executeWasm(contractAddress, msg, coins = "0usei") {
349349
return JSON.parse(output);
350350
}
351351

352+
async function associateWasm(contractAddress) {
353+
const command = `seid tx evm associate-contract-address ${contractAddress} --from ${adminKeyName} --gas=5000000 --fees=1000000usei -y --broadcast-mode block -o json`;
354+
const output = await execute(command);
355+
return JSON.parse(output);
356+
}
357+
352358
async function isDocker() {
353359
return new Promise((resolve, reject) => {
354360
exec("docker ps --filter 'name=sei-node-0' --format '{{.Names}}'", (error, stdout, stderr) => {
@@ -427,6 +433,7 @@ module.exports = {
427433
isDocker,
428434
testAPIEnabled,
429435
incrementPointerVersion,
436+
associateWasm,
430437
WASM,
431438
ABI,
432439
};

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ require (
344344
)
345345

346346
replace (
347-
github.com/CosmWasm/wasmd => github.com/sei-protocol/sei-wasmd v0.1.4
347+
github.com/CosmWasm/wasmd => github.com/sei-protocol/sei-wasmd v0.1.5
348348
github.com/confio/ics23/go => github.com/cosmos/cosmos-sdk/ics23/go v0.8.0
349349
github.com/cosmos/cosmos-sdk => github.com/sei-protocol/sei-cosmos v0.3.13
350350
github.com/cosmos/iavl => github.com/sei-protocol/sei-iavl v0.1.9

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,8 +1359,8 @@ github.com/sei-protocol/sei-tendermint v0.3.3 h1:zH6xxrSRwHERaj/AcCR76U9daVY3Ub8
13591359
github.com/sei-protocol/sei-tendermint v0.3.3/go.mod h1:4LSlJdhl3nf3OmohliwRNUFLOB1XWlrmSodrIP7fLh4=
13601360
github.com/sei-protocol/sei-tm-db v0.0.5 h1:3WONKdSXEqdZZeLuWYfK5hP37TJpfaUa13vAyAlvaQY=
13611361
github.com/sei-protocol/sei-tm-db v0.0.5/go.mod h1:Cpa6rGyczgthq7/0pI31jys2Fw0Nfrc+/jKdP1prVqY=
1362-
github.com/sei-protocol/sei-wasmd v0.1.4 h1:StDThZwOJvLebeK1zTot8pByPd4kdM3AsBaKxLpDQPQ=
1363-
github.com/sei-protocol/sei-wasmd v0.1.4/go.mod h1:tv+4SYNzpryEPU1dV44+JFB5dIqpDAEx32RngGFgDeI=
1362+
github.com/sei-protocol/sei-wasmd v0.1.5 h1:+yO7mihwVTG34DGr/bF1bRwszUfDeN1EnMBZEY67l3k=
1363+
github.com/sei-protocol/sei-wasmd v0.1.5/go.mod h1:vd2qO4GOslLnmlsoAk+zE4D8/OQC1AkTqDY8QBOV09U=
13641364
github.com/sei-protocol/tm-db v0.0.4 h1:7Y4EU62Xzzg6wKAHEotm7SXQR0aPLcGhKHkh3qd0tnk=
13651365
github.com/sei-protocol/tm-db v0.0.4/go.mod h1:PWsIWOTwdwC7Ow/GUvx8HgUJTO691pBuorIQD8JvwAs=
13661366
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=

proto/evm/tx.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ service Msg {
1212
rpc EVMTransaction(MsgEVMTransaction) returns (MsgEVMTransactionResponse);
1313
rpc Send(MsgSend) returns (MsgSendResponse);
1414
rpc RegisterPointer(MsgRegisterPointer) returns (MsgRegisterPointerResponse);
15+
rpc AssociateContractAddress(MsgAssociateContractAddress) returns (MsgAssociateContractAddressResponse);
1516
}
1617

1718
message MsgEVMTransaction {
@@ -65,3 +66,10 @@ message MsgRegisterPointer {
6566
message MsgRegisterPointerResponse {
6667
string pointer_address = 1;
6768
}
69+
70+
message MsgAssociateContractAddress {
71+
string sender = 1;
72+
string address = 2;
73+
}
74+
75+
message MsgAssociateContractAddressResponse {}

x/evm/client/cli/native_tx.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,32 @@ func RegisterEvmPointerCmd() *cobra.Command {
148148

149149
return cmd
150150
}
151+
152+
func AssociateContractAddressCmd() *cobra.Command {
153+
cmd := &cobra.Command{
154+
Use: "associate-contract-address [cw-address]",
155+
Short: `Set address association for a CosmWasm contract.`,
156+
Args: cobra.ExactArgs(1),
157+
RunE: func(cmd *cobra.Command, args []string) error {
158+
clientCtx, err := client.GetClientTxContext(cmd)
159+
if err != nil {
160+
return err
161+
}
162+
163+
addr, err := sdk.AccAddressFromBech32(args[0])
164+
if err != nil {
165+
return err
166+
}
167+
msg := types.NewMsgAssociateContractAddress(clientCtx.GetFromAddress(), addr)
168+
if err := msg.ValidateBasic(); err != nil {
169+
return err
170+
}
171+
172+
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
173+
},
174+
}
175+
176+
flags.AddTxFlagsToCmd(cmd)
177+
178+
return cmd
179+
}

x/evm/client/cli/tx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ func GetTxCmd() *cobra.Command {
6868
cmd.AddCommand(NewAddERCNativePointerProposalTxCmd())
6969
cmd.AddCommand(NewAddERCCW20PointerProposalTxCmd())
7070
cmd.AddCommand(NewAddERCCW721PointerProposalTxCmd())
71+
cmd.AddCommand(AssociateContractAddressCmd())
7172

7273
return cmd
7374
}

x/evm/handler.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ func NewHandler(k *keeper.Keeper) sdk.Handler {
2727
case *types.MsgRegisterPointer:
2828
res, err := msgServer.RegisterPointer(sdk.WrapSDKContext(ctx), msg)
2929
return sdk.WrapServiceResult(ctx, res, err)
30+
case *types.MsgAssociateContractAddress:
31+
res, err := msgServer.AssociateContractAddress(sdk.WrapSDKContext(ctx), msg)
32+
return sdk.WrapServiceResult(ctx, res, err)
3033
default:
3134
errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg)
3235
return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg)

x/evm/keeper/address.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package keeper
22

33
import (
4-
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
54
"github.com/cosmos/cosmos-sdk/store/prefix"
65
sdk "github.com/cosmos/cosmos-sdk/types"
76
"github.com/ethereum/go-ethereum/common"
@@ -29,12 +28,6 @@ func (k *Keeper) DeleteAddressMapping(ctx sdk.Context, seiAddress sdk.AccAddress
2928
}
3029

3130
func (k *Keeper) GetEVMAddress(ctx sdk.Context, seiAddress sdk.AccAddress) (common.Address, bool) {
32-
// CW address has a different length and should always be considered associated
33-
// Note that this association is one-way since CW address is longer than EOA address
34-
// and would need to be cropped.
35-
if len(seiAddress) == wasmtypes.ContractAddrLen {
36-
return common.BytesToAddress(seiAddress), true
37-
}
3831
store := ctx.KVStore(k.storeKey)
3932
bz := store.Get(types.SeiAddressToEVMAddressKey(seiAddress))
4033
addr := common.Address{}

0 commit comments

Comments
 (0)