Skip to content

Commit

Permalink
Merge pull request #60 from terra-money/feat/tokenfactory
Browse files Browse the repository at this point in the history
feat: token factory refact packaging and extend models
  • Loading branch information
emidev98 authored Nov 14, 2023
2 parents d8a00ad + 88ffcad commit d6f0b54
Show file tree
Hide file tree
Showing 19 changed files with 510 additions and 66 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion 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.9",
"version": "2.0.0-beta.12",
"description": "The JavaScript SDK for Terra and Feather chains",
"license": "MIT",
"author": "Terraform Labs, PTE.",
Expand Down
1 change: 0 additions & 1 deletion src/client/lcd/api/TokenFactoryAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { APIParams } from '../APIRequester';
import { LCDClient } from '../LCDClient';
import { BaseAPI } from './BaseAPI';
import { QueryParamsResponse } from '@terra-money/terra.proto/osmosis/tokenfactory/v1beta1/query';
Expand Down
54 changes: 46 additions & 8 deletions src/core/Msg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ import {
MsgClearContractAdmin,
WasmMsg,
} from './wasm/msgs';
import {
MsgBurn,
MsgChangeAdmin,
MsgCreateDenom,
MsgMint,
MsgSetBeforeSendHook,
TokenFactoryMsg,
} from './tokenfactory';
import { JAXMsgExecuteContract, JAXMsgStoreCode, JaxMsg } from './jax/msgs';
import { MsgTransfer, IbcTransferMsg } from './ibc/applications/transfer';
import {
Expand Down Expand Up @@ -100,10 +108,6 @@ import {
} from './ibc/msgs/channel';
import { MsgVerifyInvariant, CrisisMsg } from './crisis';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
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';
import { MsgAuctionBid } from './pob/MsgAuctionBid';
import {
FeeshareMsg,
Expand All @@ -116,6 +120,8 @@ import {
MsgRegisterInterchainAccount,
MsgSendTx,
} from './ica/controller/v1/msgs';
import { MsgForceTransfer } from './tokenfactory/MsgForceTransfer';
import { MsgSetDenomMetadata } from './tokenfactory/MsgSetDenomMetadata';

export type Msg =
| BankMsg
Expand All @@ -138,7 +144,8 @@ export type Msg =
| CrisisMsg
| JaxMsg
| MsgAuctionBid
| FeeshareMsg;
| FeeshareMsg
| TokenFactoryMsg;

export namespace Msg {
export type Amino =
Expand All @@ -158,7 +165,8 @@ export namespace Msg {
| CrisisMsg.Amino
| JaxMsg.Amino
| MsgAuctionBid.Amino
| FeeshareMsg.Amino;
| FeeshareMsg.Amino
| TokenFactoryMsg.Amino;

export type Data =
| BankMsg.Data
Expand All @@ -181,7 +189,8 @@ export namespace Msg {
| CrisisMsg.Data
| JaxMsg.Data
| MsgAuctionBid.Data
| FeeshareMsg.Data;
| FeeshareMsg.Data
| TokenFactoryMsg.Data;

export type Proto =
| BankMsg.Proto
Expand All @@ -203,7 +212,8 @@ export namespace Msg {
| CrisisMsg.Proto
| JaxMsg.Proto
| MsgAuctionBid.Proto
| FeeshareMsg.Proto;
| FeeshareMsg.Proto
| TokenFactoryMsg.Proto;

export function fromAmino(data: Msg.Amino, isClassic?: boolean): Msg {
switch (data.type) {
Expand Down Expand Up @@ -444,6 +454,8 @@ export namespace Msg {
data as MsgClearContractAdmin.Amino,
isClassic
);

//token-factory
case 'osmosis/tokenfactory/create-denom':
return MsgCreateDenom.fromAmino(data as MsgCreateDenom.Amino);
case 'osmosis/tokenfactory/burn':
Expand All @@ -452,9 +464,19 @@ export namespace Msg {
return MsgChangeAdmin.fromAmino(data as MsgChangeAdmin.Amino);
case 'osmosis/tokenfactory/mint':
return MsgMint.fromAmino(data as MsgMint.Amino);
case 'osmosis/tokenfactory/set-beforesend-hook':
return MsgSetBeforeSendHook.fromAmino(
data as MsgSetBeforeSendHook.Amino
);
case 'osmosis/tokenfactory/force-transfer':
return MsgForceTransfer.fromAmino(data as MsgForceTransfer.Amino);
case 'osmosis/tokenfactory/set-metadata':
return MsgSetDenomMetadata.fromAmino(data as MsgSetDenomMetadata.Amino);

// ibc-transfer
case 'cosmos-sdk/MsgTransfer':
return MsgTransfer.fromAmino(data as MsgTransfer.Amino, isClassic);

// crisis
case 'crisis/MsgVerifyInvariant':
case 'cosmos-sdk/MsgVerifyInvariant':
Expand Down Expand Up @@ -612,6 +634,8 @@ export namespace Msg {
case '/terra.wasm.v1beta1.MsgClearContractAdmin':
case '/cosmwasm.wasm.v1.MsgClearAdmin':
return MsgClearContractAdmin.fromData(data, isClassic);

// token factory
case '/osmosis.tokenfactory.v1beta1.MsgCreateDenom':
return MsgCreateDenom.fromData(data);
case '/osmosis.tokenfactory.v1beta1.MsgBurn':
Expand All @@ -620,6 +644,12 @@ export namespace Msg {
return MsgChangeAdmin.fromData(data);
case '/osmosis.tokenfactory.v1beta1.MsgMint':
return MsgMint.fromData(data);
case '/osmosis.tokenfactory.v1beta1.MsgSetBeforeSendHook':
return MsgSetBeforeSendHook.fromData(data);
case '/osmosis.tokenfactory.v1beta1.MsgForceTransfer':
return MsgForceTransfer.fromData(data);
case '/osmosis.tokenfactory.v1beta1.MsgSetDenomMetadata':
return MsgSetDenomMetadata.fromData(data);

// ibc-transfer
case '/ibc.applications.transfer.v1.MsgTransfer':
Expand Down Expand Up @@ -816,6 +846,8 @@ export namespace Msg {
case '/terra.wasm.v1beta1.MsgClearContractAdmin':
case '/cosmwasm.wasm.v1.MsgClearAdmin':
return MsgClearContractAdmin.unpackAny(proto, isClassic);

// token factory
case '/osmosis.tokenfactory.v1beta1.MsgCreateDenom':
return MsgCreateDenom.unpackAny(proto, isClassic);
case '/osmosis.tokenfactory.v1beta1.MsgBurn':
Expand All @@ -824,6 +856,12 @@ export namespace Msg {
return MsgChangeAdmin.unpackAny(proto, isClassic);
case '/osmosis.tokenfactory.v1beta1.MsgMint':
return MsgMint.unpackAny(proto, isClassic);
case '/osmosis.tokenfactory.v1beta1.MsgSetBeforeSendHook':
return MsgSetBeforeSendHook.unpackAny(proto);
case '/osmosis.tokenfactory.v1beta1.MsgForceTransfer':
return MsgForceTransfer.unpackAny(proto);
case '/osmosis.tokenfactory.v1beta1.MsgSetDenomMetadata':
return MsgSetDenomMetadata.unpackAny(proto);

// ibc-transfer
case '/ibc.applications.transfer.v1.MsgTransfer':
Expand Down
3 changes: 3 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,8 @@ export * from './ibc/applications/transfer';
// Feeshare
export * from './feeshare';

// token factory
export * from './tokenfactory';

// bech32 types
export * from './bech32';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Coin } from '../../../Coin';
import { Coin } from '../Coin';
import { MsgBurn } from './MsgBurn';

describe('MsgBurn', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { JSONSerializable } from '../../../../util/json';
import { AccAddress } from '../../../bech32';
import { JSONSerializable } from '../../util/json';
import { AccAddress } 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 '../../../Coin';
import { MsgBurn as MsgBurn_pb } from '@terra-money/terra.proto/osmosis/tokenfactory/v1beta1/tx';
import { Coin } from '../Coin';

/**
* MsgBurn is the sdk.Msg type for allowing an admin account to burn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JSONSerializable } from '../../../../util/json';
import { AccAddress } from '../../../bech32';
import { JSONSerializable } from '../../util/json';
import { AccAddress } from '../bech32';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgChangeAdmin as MsgChangeAdmin_pb } from '@terra-money/terra.proto/cosmwasm/tokenfactory/v1beta1/tx';
import { MsgChangeAdmin as MsgChangeAdmin_pb } from '@terra-money/terra.proto/osmosis/tokenfactory/v1beta1/tx';

// MsgChangeAdmin is the sdk.Msg type for allowing an admin account to reassign
// adminship of a denom to a new account
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JSONSerializable } from '../../../../util/json';
import { AccAddress } from '../../../bech32';
import { JSONSerializable } from '../../util/json';
import { AccAddress } from '../bech32';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgCreateDenom as MsgCreateDenom_pb } from '@terra-money/terra.proto/cosmwasm/tokenfactory/v1beta1/tx';
import { MsgCreateDenom as MsgCreateDenom_pb } from '@terra-money/terra.proto/osmosis/tokenfactory/v1beta1/tx';

/**
* MsgCreateDenom defines the message structure for the CreateDenom gRPC service
Expand Down
144 changes: 144 additions & 0 deletions src/core/tokenfactory/MsgForceTransfer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
import { DenomUnit } from '@terra-money/terra.proto/cosmos/bank/v1beta1/bank';
import { JSONSerializable } from '../../util/json';
import { AccAddress } from '../bech32';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { Metadata } from '@terra-money/terra.proto/cosmos/bank/v1beta1/bank';
import { MsgForceTransfer as MsgForceTransfer_pb } from '@terra-money/terra.proto/osmosis/tokenfactory/v1beta1/tx';
import { Coin } from '../Coin';

/**
* MsgForceTransfer allows setting the metadata
* for an already existing denom
*/
export class MsgForceTransfer extends JSONSerializable<
MsgForceTransfer.Amino,
MsgForceTransfer.Data,
MsgForceTransfer.Proto
> {
/**
*
* @param sender internal account or external sender address
* @param metadata the cosmwasm contract address
*/
constructor(
public sender: AccAddress,
public amount: Coin,
public transferFromAddress: AccAddress,
public transferToAddress: AccAddress
) {
super();
}

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

return {
type: 'osmosis/tokenfactory/force-transfer',
value: {
sender,
amount: amount.toAmino(),
transferFromAddress,
transferToAddress,
},
};
}

public static fromProto(
proto: MsgForceTransfer.Proto,
_?: boolean
): MsgForceTransfer {
_;
return new MsgForceTransfer(
proto.sender,
Coin.fromProto(proto.amount as Coin.Proto),
proto.transferFromAddress,
proto.transferToAddress
);
}

public toProto(_?: boolean): MsgForceTransfer.Proto {
_;
const { sender, amount, transferFromAddress, transferToAddress } = this;
return MsgForceTransfer_pb.fromPartial({
sender,
amount: amount?.toProto(),
transferFromAddress,
transferToAddress,
});
}

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

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

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

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

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

return new MsgForceTransfer(
sender,
Coin.fromAmino(amount),
transferFromAddress,
transferToAddress
);
}
}

export namespace MsgForceTransfer {
export interface Amino {
type: 'osmosis/tokenfactory/force-transfer';
value: {
sender: AccAddress;
amount: Coin.Amino;
transferFromAddress: AccAddress;
transferToAddress: AccAddress;
};
}

export interface Data {
'@type': '/osmosis.tokenfactory.v1beta1.MsgForceTransfer';
sender: AccAddress;
amount: Coin.Data;
transferFromAddress: AccAddress;
transferToAddress: AccAddress;
}

export type Proto = MsgForceTransfer_pb;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Coin } from '../../../Coin';
import { Coin } from '../Coin';
import { MsgMint } from './MsgMint';

describe('MsgMint', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { JSONSerializable } from '../../../../util/json';
import { AccAddress } from '../../../bech32';
import { JSONSerializable } from '../../util/json';
import { AccAddress } from '../bech32';
import { Any } from '@terra-money/terra.proto/google/protobuf/any';
import { MsgMint as MsgMint_pb } from '@terra-money/terra.proto/cosmwasm/tokenfactory/v1beta1/tx';
import { Coin } from '../../../Coin';
import { MsgMint as MsgMint_pb } from '@terra-money/terra.proto/osmosis/tokenfactory/v1beta1/tx';
import { Coin } from '../Coin';

/**
* MsgMint is the sdk.Msg type for allowing an admin account to mint
Expand Down
Loading

0 comments on commit d6f0b54

Please sign in to comment.