Skip to content

Commit

Permalink
feat: ica/icq api and models definition
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Oct 24, 2023
1 parent c56fb62 commit 30098f1
Show file tree
Hide file tree
Showing 9 changed files with 364 additions and 8 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@terra-money/feather.js",
"version": "2.0.0-beta.1",
"version": "2.0.0-beta.2",
"description": "The JavaScript SDK for Terra and Feather chains",
"license": "MIT",
"author": "Terraform Labs, PTE.",
Expand Down Expand Up @@ -87,7 +87,7 @@
"dependencies": {
"@ethersproject/bytes": "^5.7.0",
"@terra-money/legacy.proto": "npm:@terra-money/terra.proto@^0.1.7",
"@terra-money/terra.proto": "^4.0.3",
"@terra-money/terra.proto": "^4.0.4",
"assert": "^2.0.0",
"axios": "^0.27.2",
"bech32": "^2.0.0",
Expand Down
6 changes: 6 additions & 0 deletions src/client/lcd/LCDClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { AllianceAPI } from './api/AllianceAPI';
import { PobAPI } from './api/PobAPI';
import { FeeshareAPI } from './api/FeeshareAPI';
import { GovV1API } from './api/GovV1API';
import { ICAv1API } from './api/ICAv1API';
import { ICQv1API } from './api/ICQv1API';

export interface LCDClientConfig {
/**
Expand Down Expand Up @@ -114,6 +116,8 @@ export class LCDClient {
public wasm: WasmAPI;
public tx: TxAPI;
public ibc: IbcAPI;
public icaV1: ICAv1API;
public icqV1: ICQv1API;
public ibcTransfer: IbcTransferAPI;
public pob: PobAPI;
public feeshare: FeeshareAPI;
Expand Down Expand Up @@ -157,6 +161,8 @@ export class LCDClient {
this.tendermint = new TendermintAPI(this);
this.wasm = new WasmAPI(this);
this.ibc = new IbcAPI(this);
this.icaV1 = new ICAv1API(this);
this.icqV1 = new ICQv1API(this);
this.ibcTransfer = new IbcTransferAPI(this);
this.tx = new TxAPI(this);
this.pob = new PobAPI(this);
Expand Down
61 changes: 61 additions & 0 deletions src/client/lcd/api/ICAv1API.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { Params as HostParams } from '@terra-money/terra.proto/ibc/applications/interchain_accounts/host/v1/host';
import { Params as ControllerParams } from '@terra-money/terra.proto/ibc/applications/interchain_accounts/controller/v1/controller';
import { APIParams } from '../APIRequester';
import { LCDClient } from '../LCDClient';
import { BaseAPI } from './BaseAPI';
import { AccAddress } from 'core';

export class ICAv1API extends BaseAPI {
constructor(public lcd: LCDClient) {
super(lcd.apiRequesters, lcd.config);
}

/**
* Query interchain account host module params
*
* @tags Query
* @name params
* @request GET:/ibc/apps/interchain_accounts/host/v1/params
*/
public async hostParams(chainId: string, params: Partial<APIParams> = {}) {
return this.getReqFromChainID(chainId).get<{ params: HostParams }>(
`/ibc/apps/interchain_accounts/host/v1/params`,
params
);
}

/**
* Query interchain account controller module params
*
* @tags Query
* @name params
* @request GET:/ibc/apps/interchain_accounts/controller/v1/params
*/
public async controllerParams(
chainId: string,
params: Partial<APIParams> = {}
) {
return this.getReqFromChainID(chainId).get<{ params: ControllerParams }>(
`/ibc/apps/interchain_accounts/controller/v1/params`,
params
);
}

/**
* Returns the interchain account address for a given owner address on a given connection
*
* @tags Query
* @name params
* @request GET:/ibc/apps/interchain_accounts/controller/v1/owners/${ownerAddr}/connections/${connectionId}
*/
public async controllerAccountAddress(
ownerAddr: AccAddress,
connectionId: string,
params: Partial<APIParams> = {}
) {
return this.getReqFromAddress(ownerAddr).get<{ params: ControllerParams }>(
`/ibc/apps/interchain_accounts/controller/v1/owners/${ownerAddr}/connections/${connectionId}`,
params
);
}
}
25 changes: 25 additions & 0 deletions src/client/lcd/api/ICQv1API.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Params } from '@terra-money/terra.proto/icq/v1/icq';
import { APIParams } from '../APIRequester';
import { LCDClient } from '../LCDClient';
import { BaseAPI } from './BaseAPI';

export class ICQv1API extends BaseAPI {
constructor(public lcd: LCDClient) {
super(lcd.apiRequesters, lcd.config);
}

/**
* Query all parameters associated with the icq module.
*
* @tags Query
* @name params
* @summary Query icq module params
* @request GET:/async-icq/v1/params
*/
public async params(chainId: string, params: Partial<APIParams> = {}) {
return this.getReqFromChainID(chainId).get<{ params: Params }>(
`/async-icq/v1/params`,
params
);
}
}
21 changes: 21 additions & 0 deletions src/core/Msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ import {
MsgRegisterFeeShare,
MsgUpdateFeeShare,
} from './feeshare';
import {
ICAMsg,
MsgRegisterInterchainAccount,
MsgSendTx,
} from './ica/controller/v1/msgs';

export type Msg =
| BankMsg
Expand All @@ -127,6 +132,7 @@ export type Msg =
| IbcClientMsg
| IbcConnectionMsg
| IbcChannelMsg
| ICAMsg
| AllianceMsg
| CustomMsg
| CrisisMsg
Expand Down Expand Up @@ -169,6 +175,7 @@ export namespace Msg {
| IbcClientMsg.Data
| IbcConnectionMsg.Data
| IbcChannelMsg.Data
| ICAMsg.Data
| AllianceMsg.Data
| CustomMsg.Data
| CrisisMsg.Data
Expand All @@ -188,6 +195,7 @@ export namespace Msg {
| VestingMsg.Proto
| WasmMsg.Proto
| IbcTransferMsg.Proto
| ICAMsg.Proto
| IbcClientMsg.Proto
| IbcConnectionMsg.Proto
| IbcChannelMsg.Proto
Expand Down Expand Up @@ -492,6 +500,7 @@ export namespace Msg {
return MsgAminoCustom.fromAmino(data as any, isClassic);
}
}

export function fromData(data: Msg.Data, isClassic?: boolean): Msg {
switch (data['@type']) {
// alliance
Expand Down Expand Up @@ -616,6 +625,12 @@ export namespace Msg {
case '/ibc.applications.transfer.v1.MsgTransfer':
return MsgTransfer.fromData(data, isClassic);

// ibc ica
case '/ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccount':
return MsgRegisterInterchainAccount.fromData(data, isClassic);
case '/ibc.applications.interchain_accounts.controller.v1.MsgSendTx':
return MsgSendTx.fromData(data, isClassic);

// ibc-client
case '/ibc.core.client.v1.MsgCreateClient':
return MsgCreateClient.fromData(data, isClassic);
Expand Down Expand Up @@ -814,6 +829,12 @@ export namespace Msg {
case '/ibc.applications.transfer.v1.MsgTransfer':
return MsgTransfer.unpackAny(proto, isClassic);

// ibc ica
case '/ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccount':
return MsgRegisterInterchainAccount.unpackAny(proto, isClassic);
case '/ibc.applications.interchain_accounts.controller.v1.MsgSendTx':
return MsgSendTx.unpackAny(proto, isClassic);

// ibc-client
case '/ibc.core.client.v1.MsgCreateClient':
return MsgCreateClient.unpackAny(proto, isClassic);
Expand Down
119 changes: 119 additions & 0 deletions src/core/ica/controller/v1/msgs/MsgRegisterInterchainAccount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
import { AccAddress } from '../../../../bech32';
import { Any } from '@terra-money/legacy.proto/google/protobuf/any';
import { JSONSerializable } from '../../../../../util/json';
import { MsgRegisterInterchainAccount as MsgRegisterInterchainAccount_pb } from '@terra-money/terra.proto/ibc/applications/interchain_accounts/controller/v1/tx';

/**
* A basic message for sending [[Coins]] between Terra accounts.
*/
export class MsgRegisterInterchainAccount extends JSONSerializable<
MsgRegisterInterchainAccount.Amino,
MsgRegisterInterchainAccount.Data,
MsgRegisterInterchainAccount.Proto
> {
/**
* @param owner sender's address
* @param connectionId ibc connection id
* @param version of the interchain account
*/
constructor(
public owner: AccAddress,
public connectionId: string,
public version: string
) {
super();
}

public static fromAmino(
data: MsgRegisterInterchainAccount.Amino,
_?: boolean
): MsgRegisterInterchainAccount {
_;
data;
throw new Error('Amino not supported on MsgRegisterInterchainAccount');
}

public toAmino(_?: boolean): MsgRegisterInterchainAccount.Amino {
_;
throw new Error('Amino not supported on MsgRegisterInterchainAccount');
}

public static fromData(
data: MsgRegisterInterchainAccount.Data,
_?: boolean
): MsgRegisterInterchainAccount {
_;
const { owner, connection_id, version } = data;

return new MsgRegisterInterchainAccount(owner, connection_id, version);
}

public toData(_?: boolean): MsgRegisterInterchainAccount.Data {
_;
const { owner, connectionId, version } = this;
return {
'@type':
'/ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccount',
owner: owner,
connection_id: connectionId,
version: version,
};
}

public static fromProto(
proto: MsgRegisterInterchainAccount.Proto,
_?: boolean
): MsgRegisterInterchainAccount {
_;
return new MsgRegisterInterchainAccount(
proto.owner,
proto.connectionId,
proto.version
);
}

public toProto(_?: boolean): MsgRegisterInterchainAccount.Proto {
_;
const { owner, connectionId, version } = this;
return MsgRegisterInterchainAccount_pb.fromPartial({
owner,
connectionId,
version,
});
}

public packAny(isClassic?: boolean): Any {
return Any.fromPartial({
typeUrl:
'/ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccount',
value: MsgRegisterInterchainAccount_pb.encode(
this.toProto(isClassic)
).finish(),
});
}

public static unpackAny(
msgAny: Any,
isClassic?: boolean
): MsgRegisterInterchainAccount {
return MsgRegisterInterchainAccount.fromProto(
MsgRegisterInterchainAccount_pb.decode(msgAny.value),
isClassic
);
}
}

export namespace MsgRegisterInterchainAccount {
export interface Amino {
value: {};
}

export interface Data {
'@type': '/ibc.applications.interchain_accounts.controller.v1.MsgRegisterInterchainAccount';
owner: AccAddress;
connection_id: string;
version: string;
}

export type Proto = MsgRegisterInterchainAccount_pb;
}
Loading

0 comments on commit 30098f1

Please sign in to comment.