Skip to content

Commit

Permalink
Feature/token allow list (#197)
Browse files Browse the repository at this point in the history
* Token factory allow list proto changes

* change set

* include bank proto changes

* add comment to proto
  • Loading branch information
dssei authored Oct 10, 2024
1 parent 54da516 commit efe151c
Show file tree
Hide file tree
Showing 12 changed files with 593 additions and 33 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-trains-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sei-js/proto': minor
---

New gRPC methods to fetch token allow list
7 changes: 7 additions & 0 deletions packages/proto/proto/cosmos/bank/v1beta1/bank.proto
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,10 @@ message Metadata {
// Since: cosmos-sdk 0.43
string symbol = 6;
}

// AllowList represents a list of allowed addresses to transact the denom.
message AllowList {
option (gogoproto.equal) = true;

repeated string addresses = 1 [ (gogoproto.moretags) = "yaml:\"addresses\"" ];
}
34 changes: 26 additions & 8 deletions packages/proto/proto/tokenfactory/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ service Query {
// DenomAuthorityMetadata defines a gRPC query method for fetching
// DenomAuthorityMetadata for a particular denom.
rpc DenomAuthorityMetadata(QueryDenomAuthorityMetadataRequest)
returns (QueryDenomAuthorityMetadataResponse) {
returns (QueryDenomAuthorityMetadataResponse) {
option (google.api.http).get =
"/sei-protocol/seichain/tokenfactory/denoms/{denom}/authority_metadata";
"/sei-protocol/seichain/tokenfactory/denoms/{denom}/authority_metadata";
}

// DenomsMetadata defines a gRPC query method for fetching
Expand All @@ -35,9 +35,14 @@ service Query {
// DenomsFromCreator defines a gRPC query method for fetching all
// denominations created by a specific admin/creator.
rpc DenomsFromCreator(QueryDenomsFromCreatorRequest)
returns (QueryDenomsFromCreatorResponse) {
returns (QueryDenomsFromCreatorResponse) {
option (google.api.http).get =
"/sei-protocol/seichain/tokenfactory/denoms_from_creator/{creator}";
"/sei-protocol/seichain/tokenfactory/denoms_from_creator/{creator}";
}

// DenomAllowList defines a gRPC query method for fetching the denom allow list
rpc DenomAllowList(QueryDenomAllowListRequest) returns (QueryDenomAllowListResponse) {
option (google.api.http).get = "/sei-protocol/seichain/tokenfactory/denoms/allow_list";
}

}
Expand All @@ -48,13 +53,13 @@ message QueryParamsRequest {}
// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
Params params = 1 [(gogoproto.nullable) = false];
}

// QueryDenomAuthorityMetadataRequest defines the request structure for the
// DenomAuthorityMetadata gRPC query.
message QueryDenomAuthorityMetadataRequest {
string denom = 1 [ (gogoproto.moretags) = "yaml:\"denom\"" ];
string denom = 1 [(gogoproto.moretags) = "yaml:\"denom\""];
}

// QueryDenomAuthorityMetadataResponse defines the response structure for the
Expand All @@ -69,13 +74,13 @@ message QueryDenomAuthorityMetadataResponse {
// QueryDenomsFromCreatorRequest defines the request structure for the
// DenomsFromCreator gRPC query.
message QueryDenomsFromCreatorRequest {
string creator = 1 [ (gogoproto.moretags) = "yaml:\"creator\"" ];
string creator = 1 [(gogoproto.moretags) = "yaml:\"creator\""];
}

// QueryDenomsFromCreatorRequest defines the response structure for the
// DenomsFromCreator gRPC query.
message QueryDenomsFromCreatorResponse {
repeated string denoms = 1 [ (gogoproto.moretags) = "yaml:\"denoms\"" ];
repeated string denoms = 1 [(gogoproto.moretags) = "yaml:\"denoms\""];
}

// QueryDenomMetadataRequest is the request type for the DenomMetadata gRPC method.
Expand All @@ -90,3 +95,16 @@ message QueryDenomMetadataResponse {
// metadata describes and provides all the client information for the requested token.
cosmos.bank.v1beta1.Metadata metadata = 1 [(gogoproto.nullable) = false];
}

// QueryDenomAllowListRequest is the request type for the DenomAllowList gRPC method
message QueryDenomAllowListRequest {
// denom is the coin denom to query the allowlist for.
string denom = 1;
}

// QueryDenomAllowListResponse is the response type for the DenomAllowList gRPC
// method.
message QueryDenomAllowListResponse {
// allow_list provides addresses allowed for the requested token.
cosmos.bank.v1beta1.AllowList allow_list = 1 [(gogoproto.nullable) = false];
}
32 changes: 14 additions & 18 deletions packages/proto/proto/tokenfactory/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ option go_package = "github.com/sei-protocol/sei-chain/x/tokenfactory/types";
// Msg defines the tokefactory module's gRPC message service.
service Msg {
rpc CreateDenom(MsgCreateDenom) returns (MsgCreateDenomResponse);
rpc UpdateDenom(MsgUpdateDenom) returns (MsgUpdateDenomResponse);
rpc Mint(MsgMint) returns (MsgMintResponse);
rpc Burn(MsgBurn) returns (MsgBurnResponse);
rpc ChangeAdmin(MsgChangeAdmin) returns (MsgChangeAdminResponse);
rpc SetDenomMetadata(MsgSetDenomMetadata)
returns (MsgSetDenomMetadataResponse);

// ForceTransfer is deactivated for now because we need to think through edge
// cases rpc ForceTransfer(MsgForceTransfer) returns
// (MsgForceTransferResponse);
}

// MsgCreateDenom defines the message structure for the CreateDenom gRPC service
Expand All @@ -34,6 +31,7 @@ message MsgCreateDenom {
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
// subdenom can be up to 44 "alphanumeric" characters long.
string subdenom = 2 [ (gogoproto.moretags) = "yaml:\"subdenom\"" ];
cosmos.bank.v1beta1.AllowList allow_list = 3 [ (gogoproto.moretags) = "yaml:\"allow_list\"", (gogoproto.nullable) = true ];
}

// MsgCreateDenomResponse is the return value of MsgCreateDenom
Expand Down Expand Up @@ -79,20 +77,6 @@ message MsgChangeAdmin {
// MsgChangeAdmin message.
message MsgChangeAdminResponse {}

// message MsgForceTransfer {
// string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
// cosmos.base.v1beta1.Coin amount = 2 [
// (gogoproto.moretags) = "yaml:\"amount\"",
// (gogoproto.nullable) = false
// ];
// string transferFromAddress = 3
// [ (gogoproto.moretags) = "yaml:\"transfer_from_address\"" ];
// string transferToAddress = 4
// [ (gogoproto.moretags) = "yaml:\"transfer_to_address\"" ];
// }

// message MsgForceTransferResponse {}

// MsgSetDenomMetadata is the sdk.Msg type for allowing an admin account to set
// the denom's bank metadata
message MsgSetDenomMetadata {
Expand All @@ -103,3 +87,15 @@ message MsgSetDenomMetadata {
// MsgSetDenomMetadataResponse defines the response structure for an executed
// MsgSetDenomMetadata message.
message MsgSetDenomMetadataResponse {}

// MsgUpdateDenom is the sdk.Msg allowing an admin to update the denom
message MsgUpdateDenom {
string sender = 1 [ (gogoproto.moretags) = "yaml:\"sender\"" ];
// subdenom can be up to 44 "alphanumeric" characters long.
string subdenom = 2 [ (gogoproto.moretags) = "yaml:\"subdenom\"" ];
cosmos.bank.v1beta1.AllowList allow_list = 3 [ (gogoproto.moretags) = "yaml:\"allow_list\"", (gogoproto.nullable) = true ];
}


// MsgUpdateDenomResponse defines the response structure for an executed MsgUpdateDenom message.
message MsgUpdateDenomResponse {}
91 changes: 91 additions & 0 deletions packages/proto/src/codegen/cosmos/bank/v1beta1/bank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,26 @@ export interface MetadataSDKType {
name: string;
symbol: string;
}
/** AllowList represents a list of allowed addresses to transact the denom. */
export interface AllowList {
addresses: string[];
}
export interface AllowListProtoMsg {
typeUrl: "/cosmos.bank.v1beta1.AllowList";
value: Uint8Array;
}
/** AllowList represents a list of allowed addresses to transact the denom. */
export interface AllowListAmino {
addresses?: string[];
}
export interface AllowListAminoMsg {
type: "cosmos-sdk/AllowList";
value: AllowListAmino;
}
/** AllowList represents a list of allowed addresses to transact the denom. */
export interface AllowListSDKType {
addresses: string[];
}
function createBaseParams(): Params {
return {
sendEnabled: [],
Expand Down Expand Up @@ -896,4 +916,75 @@ export const Metadata = {
value: Metadata.encode(message).finish()
};
}
};
function createBaseAllowList(): AllowList {
return {
addresses: []
};
}
export const AllowList = {
typeUrl: "/cosmos.bank.v1beta1.AllowList",
encode(message: AllowList, writer: BinaryWriter = BinaryWriter.create()): BinaryWriter {
for (const v of message.addresses) {
writer.uint32(10).string(v!);
}
return writer;
},
decode(input: BinaryReader | Uint8Array, length?: number): AllowList {
const reader = input instanceof BinaryReader ? input : new BinaryReader(input);
let end = length === undefined ? reader.len : reader.pos + length;
const message = createBaseAllowList();
while (reader.pos < end) {
const tag = reader.uint32();
switch (tag >>> 3) {
case 1:
message.addresses.push(reader.string());
break;
default:
reader.skipType(tag & 7);
break;
}
}
return message;
},
fromPartial(object: Partial<AllowList>): AllowList {
const message = createBaseAllowList();
message.addresses = object.addresses?.map(e => e) || [];
return message;
},
fromAmino(object: AllowListAmino): AllowList {
const message = createBaseAllowList();
message.addresses = object.addresses?.map(e => e) || [];
return message;
},
toAmino(message: AllowList): AllowListAmino {
const obj: any = {};
if (message.addresses) {
obj.addresses = message.addresses.map(e => e);
} else {
obj.addresses = message.addresses;
}
return obj;
},
fromAminoMsg(object: AllowListAminoMsg): AllowList {
return AllowList.fromAmino(object.value);
},
toAminoMsg(message: AllowList): AllowListAminoMsg {
return {
type: "cosmos-sdk/AllowList",
value: AllowList.toAmino(message)
};
},
fromProtoMsg(message: AllowListProtoMsg): AllowList {
return AllowList.decode(message.value);
},
toProto(message: AllowList): Uint8Array {
return AllowList.encode(message).finish();
},
toProtoMsg(message: AllowList): AllowListProtoMsg {
return {
typeUrl: "/cosmos.bank.v1beta1.AllowList",
value: AllowList.encode(message).finish()
};
}
};
16 changes: 15 additions & 1 deletion packages/proto/src/codegen/tokenfactory/query.lcd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import {
QueryDenomMetadataRequest,
QueryDenomMetadataResponseSDKType,
QueryDenomsFromCreatorRequest,
QueryDenomsFromCreatorResponseSDKType
QueryDenomsFromCreatorResponseSDKType,
QueryDenomAllowListRequest,
QueryDenomAllowListResponseSDKType
} from './query';
export class LCDQueryClient {
req: LCDClient;
Expand All @@ -17,6 +19,7 @@ export class LCDQueryClient {
this.denomAuthorityMetadata = this.denomAuthorityMetadata.bind(this);
this.denomMetadata = this.denomMetadata.bind(this);
this.denomsFromCreator = this.denomsFromCreator.bind(this);
this.denomAllowList = this.denomAllowList.bind(this);
}
/* Params defines a gRPC query method that returns the tokenfactory module's
parameters. */
Expand Down Expand Up @@ -48,4 +51,15 @@ export class LCDQueryClient {
const endpoint = `sei-protocol/seichain/tokenfactory/denoms_from_creator/${params.creator}`;
return await this.req.get<QueryDenomsFromCreatorResponseSDKType>(endpoint);
}
/* DenomAllowList defines a gRPC query method for fetching the denom allow list */
async denomAllowList(params: QueryDenomAllowListRequest): Promise<QueryDenomAllowListResponseSDKType> {
const options: any = {
params: {}
};
if (typeof params?.denom !== 'undefined') {
options.params.denom = params.denom;
}
const endpoint = `sei-protocol/seichain/tokenfactory/denoms/allow_list`;
return await this.req.get<QueryDenomAllowListResponseSDKType>(endpoint, options);
}
}
15 changes: 14 additions & 1 deletion packages/proto/src/codegen/tokenfactory/query.rpc.Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
QueryDenomMetadataRequest,
QueryDenomMetadataResponse,
QueryDenomsFromCreatorRequest,
QueryDenomsFromCreatorResponse
QueryDenomsFromCreatorResponse,
QueryDenomAllowListRequest,
QueryDenomAllowListResponse
} from './query';
/** Query defines the gRPC querier service. */
export interface Query {
Expand All @@ -33,6 +35,8 @@ export interface Query {
* denominations created by a specific admin/creator.
*/
denomsFromCreator(request: QueryDenomsFromCreatorRequest): Promise<QueryDenomsFromCreatorResponse>;
/** DenomAllowList defines a gRPC query method for fetching the denom allow list */
denomAllowList(request: QueryDenomAllowListRequest): Promise<QueryDenomAllowListResponse>;
}
export class QueryClientImpl implements Query {
private readonly rpc: TxRpc;
Expand All @@ -42,6 +46,7 @@ export class QueryClientImpl implements Query {
this.denomAuthorityMetadata = this.denomAuthorityMetadata.bind(this);
this.denomMetadata = this.denomMetadata.bind(this);
this.denomsFromCreator = this.denomsFromCreator.bind(this);
this.denomAllowList = this.denomAllowList.bind(this);
}
params(request: QueryParamsRequest = {}): Promise<QueryParamsResponse> {
const data = QueryParamsRequest.encode(request).finish();
Expand All @@ -63,6 +68,11 @@ export class QueryClientImpl implements Query {
const promise = this.rpc.request('seiprotocol.seichain.tokenfactory.Query', 'DenomsFromCreator', data);
return promise.then((data) => QueryDenomsFromCreatorResponse.decode(new BinaryReader(data)));
}
denomAllowList(request: QueryDenomAllowListRequest): Promise<QueryDenomAllowListResponse> {
const data = QueryDenomAllowListRequest.encode(request).finish();
const promise = this.rpc.request('seiprotocol.seichain.tokenfactory.Query', 'DenomAllowList', data);
return promise.then((data) => QueryDenomAllowListResponse.decode(new BinaryReader(data)));
}
}
export const createRpcQueryExtension = (base: QueryClient) => {
const rpc = createProtobufRpcClient(base);
Expand All @@ -79,6 +89,9 @@ export const createRpcQueryExtension = (base: QueryClient) => {
},
denomsFromCreator(request: QueryDenomsFromCreatorRequest): Promise<QueryDenomsFromCreatorResponse> {
return queryService.denomsFromCreator(request);
},
denomAllowList(request: QueryDenomAllowListRequest): Promise<QueryDenomAllowListResponse> {
return queryService.denomAllowList(request);
}
};
};
Loading

0 comments on commit efe151c

Please sign in to comment.