Skip to content

Commit

Permalink
feat: token factory remaining models
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Apr 27, 2023
1 parent c479446 commit b0ce285
Show file tree
Hide file tree
Showing 8 changed files with 445 additions and 59 deletions.
21 changes: 21 additions & 0 deletions src/core/Msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ import { MsgVerifyInvariant, CrisisMsg } from './crisis';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgLiquidStake, MsgRedeemStake } from './stride/msgs';
import { MsgCreateDenom } from './wasm/msgs/tokenfactory/MsgCreateDenom';
import { MsgBurn } from './wasm/msgs/tokenfactory/MsgBurn';
import { MsgChangeAdmin } from './wasm/msgs/tokenfactory/MsgChangeAdmin';
import { MsgMint } from './wasm/msgs/tokenfactory/MsgMint';

export type Msg =
| BankMsg
Expand Down Expand Up @@ -344,6 +347,12 @@ export namespace Msg {
);
case 'osmosis/tokenfactory/create-denom':
return MsgCreateDenom.fromAmino(data as MsgCreateDenom.Amino);
case 'osmosis/tokenfactory/burn':
return MsgBurn.fromAmino(data as MsgBurn.Amino);
case 'osmosis/tokenfactory/change-admin':
return MsgChangeAdmin.fromAmino(data as MsgChangeAdmin.Amino);
case 'osmosis/tokenfactory/mint':
return MsgMint.fromAmino(data as MsgMint.Amino);
// ibc-transfer
case 'cosmos-sdk/MsgTransfer':
return MsgTransfer.fromAmino(data as MsgTransfer.Amino, isClassic);
Expand Down Expand Up @@ -463,6 +472,12 @@ export namespace Msg {
return MsgClearContractAdmin.fromData(data, isClassic);
case '/cosmwasm.tokenfactory.v1beta1.MsgCreateDenom':
return MsgCreateDenom.fromData(data);
case '/cosmwasm.tokenfactory.v1beta1.MsgBurn':
return MsgBurn.fromData(data);
case '/cosmwasm.tokenfactory.v1beta1.MsgChangeAdmin':
return MsgChangeAdmin.fromData(data);
case '/cosmwasm.tokenfactory.v1beta1.MsgMint':
return MsgMint.fromData(data);

// ibc-transfer
case '/ibc.applications.transfer.v1.MsgTransfer':
Expand Down Expand Up @@ -621,6 +636,12 @@ export namespace Msg {
return MsgClearContractAdmin.unpackAny(proto, isClassic);
case '/cosmwasm.tokenfactory.v1beta1.MsgCreateDenom':
return MsgCreateDenom.unpackAny(proto, isClassic);
case '/cosmwasm.tokenfactory.v1beta1.MsgBurn':
return MsgBurn.unpackAny(proto, isClassic);
case '/cosmwasm.tokenfactory.v1beta1.MsgChangeAdmin':
return MsgChangeAdmin.unpackAny(proto, isClassic);
case '/cosmwasm.tokenfactory.v1beta1.MsgMint':
return MsgMint.unpackAny(proto, isClassic);

// ibc-transfer
case '/ibc.applications.transfer.v1.MsgTransfer':
Expand Down
106 changes: 56 additions & 50 deletions src/core/ibc/applications/fee/msgs/MsgRegisterCounterpartAddress.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import { JSONSerializable } from '../../../../../util/json';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgRegisterCounterpartyAddress as MsgRegisterCounterpartyAddress_pb } from '@terra-money/terra.proto/ibc/applications/fee/v1/tx';
import { MsgRegisterCounterpartyPayee as MsgRegisterCounterpartyPayee_pb } from '@terra-money/terra.proto/ibc/applications/fee/v1/tx';

/**
* MsgRegisterCounterpartyAddress defines the request type for the RegisterCounterpartyAddress rpc
*/
export class MsgRegisterCounterpartyAddress extends JSONSerializable<
/** MsgRegisterCounterpartyPayee defines the request type for the RegisterCounterpartyPayee rpc */
export class MsgRegisterCounterpartyPayee extends JSONSerializable<
any,
MsgRegisterCounterpartyAddress.Data,
MsgRegisterCounterpartyAddress.Proto
MsgRegisterCounterpartyPayee.Data,
MsgRegisterCounterpartyPayee.Proto
> {
/**
* @param address the relayer address
* @param counterparty_adress the counterparty relayer address
* @param channel_id unique channel identifier
* @param portId unique port identifier
* @param channelId unique channel identifier
* @param relayer the relayer address
* @param counterpartyPayee the counterparty payee address
*/
constructor(
public address: string,
public counterparty_address: string,
public channel_id: string
public portId: string,
public channelId: string,
public relayer: string,
public counterpartyPayee: string
) {
super();
}

public static fromAmino(
_: any,
isClassic?: boolean
): MsgRegisterCounterpartyAddress {
): MsgRegisterCounterpartyPayee {
if (isClassic) {
throw new Error('Not supported for the network');
}
Expand All @@ -42,57 +42,62 @@ export class MsgRegisterCounterpartyAddress extends JSONSerializable<
}

public static fromData(
data: MsgRegisterCounterpartyAddress.Data,
data: MsgRegisterCounterpartyPayee.Data,
isClassic?: boolean
): MsgRegisterCounterpartyAddress {
): MsgRegisterCounterpartyPayee {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { address, counterparty_address, channel_id } = data;
const { portId, channelId, relayer, counterpartyPayee } = data;

return new MsgRegisterCounterpartyAddress(
address,
counterparty_address,
channel_id
return new MsgRegisterCounterpartyPayee(
portId,
channelId,
relayer,
counterpartyPayee
);
}

public toData(isClassic?: boolean): MsgRegisterCounterpartyAddress.Data {
public toData(isClassic?: boolean): MsgRegisterCounterpartyPayee.Data {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { address, counterparty_address, channel_id } = this;
const { portId, channelId, relayer, counterpartyPayee } = this;
return {
'@type': '/ibc.applications.fee.v1.MsgRegisterCounterpartyAddress',
address,
counterparty_address,
channel_id,
'@type': '/ibc.applications.fee.v1.MsgRegisterCounterpartyPayee',
portId,
channelId,
relayer,
counterpartyPayee,
};
}

public static fromProto(
proto: MsgRegisterCounterpartyAddress.Proto,
proto: MsgRegisterCounterpartyPayee.Proto,
isClassic?: boolean
): MsgRegisterCounterpartyAddress {
): MsgRegisterCounterpartyPayee {
if (isClassic) {
throw new Error('Not supported for the network');
}
return new MsgRegisterCounterpartyAddress(
proto.address,
proto.counterpartyAddress,
proto.channelId
return new MsgRegisterCounterpartyPayee(
proto.portId,
proto.channelId,
proto.relayer,
proto.counterpartyPayee
);
}

public toProto(isClassic?: boolean): MsgRegisterCounterpartyAddress.Proto {
public toProto(isClassic?: boolean): MsgRegisterCounterpartyPayee.Proto {
if (isClassic) {
throw new Error('Not supported for the network');
}
const { address, counterparty_address, channel_id } = this;
return MsgRegisterCounterpartyAddress_pb.fromPartial({
address,
counterpartyAddress: counterparty_address,
channelId: channel_id,
const { portId, channelId, relayer, counterpartyPayee } = this;

return MsgRegisterCounterpartyPayee_pb.fromPartial({
portId,
channelId,
relayer,
counterpartyPayee,
});
}

Expand All @@ -101,8 +106,8 @@ export class MsgRegisterCounterpartyAddress extends JSONSerializable<
throw new Error('Not supported for the network');
}
return Any.fromPartial({
typeUrl: '/ibc.applications.fee.v1.MsgRegisterCounterpartyAddress',
value: MsgRegisterCounterpartyAddress_pb.encode(
typeUrl: '/ibc.applications.fee.v1.MsgRegisterCounterpartyPayee',
value: MsgRegisterCounterpartyPayee_pb.encode(
this.toProto(isClassic)
).finish(),
});
Expand All @@ -111,23 +116,24 @@ export class MsgRegisterCounterpartyAddress extends JSONSerializable<
public static unpackAny(
msgAny: Any,
isClassic?: boolean
): MsgRegisterCounterpartyAddress {
): MsgRegisterCounterpartyPayee {
if (isClassic) {
throw new Error('Not supported for the network');
}
return MsgRegisterCounterpartyAddress.fromProto(
MsgRegisterCounterpartyAddress_pb.decode(msgAny.value)
return MsgRegisterCounterpartyPayee.fromProto(
MsgRegisterCounterpartyPayee_pb.decode(msgAny.value)
);
}
}

export namespace MsgRegisterCounterpartyAddress {
export namespace MsgRegisterCounterpartyPayee {
export interface Data {
'@type': '/ibc.applications.fee.v1.MsgRegisterCounterpartyAddress';
address: string;
counterparty_address: string;
channel_id: string;
'@type': '/ibc.applications.fee.v1.MsgRegisterCounterpartyPayee';
portId: string;
channelId: string;
relayer: string;
counterpartyPayee: string;
}

export type Proto = MsgRegisterCounterpartyAddress_pb;
export type Proto = MsgRegisterCounterpartyPayee_pb;
}
18 changes: 15 additions & 3 deletions src/core/wasm/msgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { MsgUpdateContractAdmin } from './MsgUpdateContractAdmin';
import { MsgClearContractAdmin } from './MsgClearContractAdmin';
import { WasmTokenFactory } from './tokenfactory';
import { MsgCreateDenom } from './tokenfactory/MsgCreateDenom';
import { MsgMint } from './tokenfactory/MsgMint';
import { MsgBurn } from './tokenfactory/MsgBurn';
import { MsgChangeAdmin } from './tokenfactory/MsgChangeAdmin';

export * from './MsgStoreCode';
export * from './MsgMigrateCode';
Expand Down Expand Up @@ -36,7 +39,10 @@ export namespace WasmMsg {
| MsgMigrateContract.Amino
| MsgUpdateContractAdmin.Amino
| MsgClearContractAdmin.Amino
| MsgCreateDenom.Amino;
| MsgCreateDenom.Amino
| MsgBurn.Amino
| MsgChangeAdmin.Amino
| MsgMint.Amino;
export type Data =
| MsgStoreCode.Data
| MsgMigrateCode.Data
Expand All @@ -45,7 +51,10 @@ export namespace WasmMsg {
| MsgMigrateContract.Data
| MsgUpdateContractAdmin.Data
| MsgClearContractAdmin.Data
| MsgCreateDenom.Data;
| MsgCreateDenom.Data
| MsgBurn.Data
| MsgChangeAdmin.Data
| MsgMint.Data;
export type Proto =
| MsgStoreCode.Proto
| MsgMigrateCode.Proto
Expand All @@ -54,5 +63,8 @@ export namespace WasmMsg {
| MsgMigrateContract.Proto
| MsgUpdateContractAdmin.Proto
| MsgClearContractAdmin.Proto
| MsgCreateDenom.Proto;
| MsgCreateDenom.Proto
| MsgBurn.Proto
| MsgChangeAdmin.Proto
| MsgMint.Proto;
}
106 changes: 106 additions & 0 deletions src/core/wasm/msgs/tokenfactory/MsgBurn.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { JSONSerializable } from '../../../../util/json';
import { AccAddress, ValAddress } from '../../../bech32';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgBurn as MsgBurn_pb } from '@terra-money/terra.proto/cosmwasm/tokenfactory/v1beta1/tx';
import { Coin } from '@terra-money/terra.proto/cosmos/base/v1beta1/coin';

/**
* MsgBurn is the sdk.Msg type for allowing an admin account to burn
* a token. For now, we only support burning from the sender account.
*/
export class MsgBurn extends JSONSerializable<
MsgBurn.Amino,
MsgBurn.Data,
MsgBurn.Proto
> {
/**
*
* @param sender internal account or external sender address
* @param amount amount of coins to burn
*/
constructor(public sender: AccAddress, public amount?: Coin) {
super();
}

public toAmino(_?: boolean): MsgBurn.Amino {
_;
const { sender, amount } = this;

return {
type: 'osmosis/tokenfactory/burn',
value: {
sender,
amount,
},
};
}

public static fromProto(proto: MsgBurn.Proto, _?: boolean): MsgBurn {
_;
return new MsgBurn(proto.sender, proto.amount);
}

public toProto(_?: boolean): MsgBurn.Proto {
_;
const { sender, amount } = this;
return MsgBurn_pb.fromPartial({
sender,
amount,
});
}

public packAny(_?: boolean): Any {
_;
return Any.fromPartial({
typeUrl: '/cosmwasm.tokenfactory.v1beta1.MsgBurn',
value: MsgBurn_pb.encode(this.toProto()).finish(),
});
}

public static unpackAny(msgAny: Any, _?: boolean): MsgBurn {
_;
return MsgBurn.fromProto(MsgBurn_pb.decode(msgAny.value));
}

public static fromData(data: MsgBurn.Data, _?: boolean): MsgBurn {
_;
const { sender, amount } = data;
return new MsgBurn(sender, amount);
}

public toData(_?: boolean): MsgBurn.Data {
_;
const { sender, amount } = this;
return {
'@type': '/cosmwasm.tokenfactory.v1beta1.MsgBurn',
sender,
amount,
};
}

public static fromAmino(data: MsgBurn.Amino): MsgBurn {
const {
value: { sender, amount },
} = data;

return new MsgBurn(sender, amount);
}
}

export namespace MsgBurn {
export interface Amino {
type: 'osmosis/tokenfactory/burn';
value: {
sender: AccAddress;
amount?: Coin;
};
}

export interface Data {
'@type': '/cosmwasm.tokenfactory.v1beta1.MsgBurn';
sender: AccAddress;
amount?: Coin;
}

export type Proto = MsgBurn_pb;
}
Loading

0 comments on commit b0ce285

Please sign in to comment.