diff --git a/package-lock.json b/package-lock.json index f03c45b..574639f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@initia/initia.js", - "version": "0.2.6", + "version": "0.2.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@initia/initia.js", - "version": "0.2.6", + "version": "0.2.7", "license": "MIT", "dependencies": { "@initia/initia.proto": "^0.2.0", diff --git a/package.json b/package.json index 933703f..5a1b9dd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@initia/initia.js", - "version": "0.2.6", + "version": "0.2.7", "description": "The JavaScript SDK for Initia", "license": "MIT", "author": "InitiaLabs", diff --git a/src/client/lcd/LCDClient.ts b/src/client/lcd/LCDClient.ts index 84d3e1b..6debdf6 100644 --- a/src/client/lcd/LCDClient.ts +++ b/src/client/lcd/LCDClient.ts @@ -18,6 +18,7 @@ import { IbcTransferAPI, IbcPermAPI, InterTxAPI, + MarketmapAPI, MoveAPI, MstakingAPI, OpchildAPI, @@ -101,6 +102,7 @@ export class LCDClient { public ibcTransfer: IbcTransferAPI; public ibcPerm: IbcPermAPI; public interTx: InterTxAPI; + public marketmap: MarketmapAPI; public move: MoveAPI; public mstaking: MstakingAPI; public opchild: OpchildAPI; @@ -153,6 +155,7 @@ export class LCDClient { this.ibcTransfer = new IbcTransferAPI(this.apiRequester); this.ibcPerm = new IbcPermAPI(this.apiRequester); this.interTx = new InterTxAPI(this.apiRequester); + this.marketmap = new MarketmapAPI(this.apiRequester); this.move = new MoveAPI(this.apiRequester); this.mstaking = new MstakingAPI(this.apiRequester); this.opchild = new OpchildAPI(this.apiRequester); diff --git a/src/client/lcd/api/MarketmapAPI.ts b/src/client/lcd/api/MarketmapAPI.ts new file mode 100644 index 0000000..c4169e4 --- /dev/null +++ b/src/client/lcd/api/MarketmapAPI.ts @@ -0,0 +1,61 @@ +import { BaseAPI } from './BaseAPI'; +import { APIParams } from '../APIRequester'; +import { CurrencyPair, Market, MarketmapParams } from '../../../core'; + +export interface MarketMap { + markets: { [ticker: string]: Market }; +} + +export namespace MarketMap { + export interface Data { + markets: { [ticker: string]: Market.Data }; + } +} + +export class MarketmapAPI extends BaseAPI { + public async marketMap(params: APIParams = {}): Promise { + return this.c + .get<{ market_map: MarketMap.Data }>( + `/slinky/marketmap/v1/marketmap`, + params + ) + .then(d => { + const markets: { [ticker: string]: Market } = {}; + for (const [ticker, market] of Object.entries(d.market_map.markets)) { + markets[ticker] = Market.fromData(market); + } + return { markets }; + }); + } + + public async market( + pair: CurrencyPair, + params: APIParams = {} + ): Promise { + return this.c + .get<{ market: Market.Data }>(`/slinky/marketmap/v1/market`, { + ...params, + 'currency_pair.Base': pair.Base, + 'currency_pair.Quote': pair.Quote, + }) + .then(d => Market.fromData(d.market)); + } + + public async lastUpdated(params: APIParams = {}): Promise { + return this.c + .get<{ last_updated: string }>( + `/slinky/marketmap/v1/last_updated`, + params + ) + .then(d => Number.parseInt(d.last_updated)); + } + + public async parameters(params: APIParams = {}): Promise { + return this.c + .get<{ params: MarketmapParams.Data }>( + `/slinky/marketmap/v1/params`, + params + ) + .then(d => MarketmapParams.fromData(d.params)); + } +} diff --git a/src/client/lcd/api/index.ts b/src/client/lcd/api/index.ts index 38386ec..917077e 100644 --- a/src/client/lcd/api/index.ts +++ b/src/client/lcd/api/index.ts @@ -16,6 +16,7 @@ export * from './IbcNftAPI'; export * from './IbcTransferAPI'; export * from './IbcPermAPI'; export * from './InterTxAPI'; +export * from './MarketmapAPI'; export * from './MoveAPI'; export * from './MstakingAPI'; export * from './OpchildAPI'; diff --git a/src/core/Msg.ts b/src/core/Msg.ts index c7f40fa..eda7825 100644 --- a/src/core/Msg.ts +++ b/src/core/Msg.ts @@ -122,6 +122,13 @@ import { MsgUpdateIbcConnectionParams, } from './ibc/core/connection/msgs'; import { InterTxMsg, MsgRegisterAccount, MsgSubmitTx } from './intertx'; +import { + MarketmapMsg, + MsgCreateMarkets, + MsgUpdateMarkets, + MsgRemoveMarketAuthorities, + MsgUpdateMarketmapParams, +} from './marketmap/msgs'; import { MoveMsg, MsgPublish, @@ -240,6 +247,7 @@ export type Msg = | IbcClientMsg | IbcConnectionMsg | InterTxMsg + | MarketmapMsg | MoveMsg | MstakingMsg | OpchildMsg @@ -272,6 +280,7 @@ export namespace Msg { | IbcPermMsg.Amino | IbcTransferMsg.Amino | InterTxMsg.Amino + | MarketmapMsg.Amino | MoveMsg.Amino | MstakingMsg.Amino | OpchildMsg.Amino @@ -308,6 +317,7 @@ export namespace Msg { | IbcClientMsg.Data | IbcConnectionMsg.Data | InterTxMsg.Data + | MarketmapMsg.Data | MoveMsg.Data | MstakingMsg.Data | OpchildMsg.Data @@ -344,6 +354,7 @@ export namespace Msg { | IbcClientMsg.Proto | IbcConnectionMsg.Proto | InterTxMsg.Proto + | MarketmapMsg.Proto | MoveMsg.Proto | MstakingMsg.Proto | OpchildMsg.Proto @@ -521,6 +532,16 @@ export namespace Msg { case 'intertx/MsgSubmitTx': return MsgSubmitTx.fromAmino(data); + // marketmap + case 'slinky/x/marketmap/MsgCreateMarkets': + return MsgCreateMarkets.fromAmino(data); + case 'slinky/x/marketmap/MsgUpdateMarkets': + return MsgUpdateMarkets.fromAmino(data); + case 'slinky/x/marketmap/MsgRemoveMarketAuthorities': + return MsgRemoveMarketAuthorities.fromAmino(data); + case 'slinky/x/marketmap/MsgParams': + return MsgUpdateMarketmapParams.fromAmino(data); + // move case 'move/MsgPublish': return MsgPublish.fromAmino(data); @@ -921,6 +942,16 @@ export namespace Msg { case '/initia.intertx.v1.MsgSubmitTx': return MsgSubmitTx.fromData(data); + // marketmap + case '/slinky.marketmap.v1.MsgCreateMarkets': + return MsgCreateMarkets.fromData(data); + case '/slinky.marketmap.v1.MsgUpdateMarkets': + return MsgUpdateMarkets.fromData(data); + case '/slinky.marketmap.v1.MsgRemoveMarketAuthorities': + return MsgRemoveMarketAuthorities.fromData(data); + case '/slinky.marketmap.v1.MsgParams': + return MsgUpdateMarketmapParams.fromData(data); + // move case '/initia.move.v1.MsgPublish': return MsgPublish.fromData(data); @@ -1324,6 +1355,16 @@ export namespace Msg { case '/initia.intertx.v1.MsgSubmitTx': return MsgSubmitTx.unpackAny(proto); + // marketmap + case '/slinky.marketmap.v1.MsgCreateMarkets': + return MsgCreateMarkets.unpackAny(proto); + case '/slinky.marketmap.v1.MsgUpdateMarkets': + return MsgUpdateMarkets.unpackAny(proto); + case '/slinky.marketmap.v1.MsgRemoveMarketAuthorities': + return MsgRemoveMarketAuthorities.unpackAny(proto); + case '/slinky.marketmap.v1.MsgParams': + return MsgUpdateMarketmapParams.unpackAny(proto); + // move case '/initia.move.v1.MsgPublish': return MsgPublish.unpackAny(proto); diff --git a/src/core/index.ts b/src/core/index.ts index 903df26..bf6c39d 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -25,6 +25,7 @@ export * from './group'; export * from './ibc'; export * from './ibchooks'; export * from './intertx'; +export * from './marketmap'; export * from './move'; export * from './mstaking'; export * from './opchild'; diff --git a/src/core/marketmap/Market.ts b/src/core/marketmap/Market.ts new file mode 100644 index 0000000..ad6d054 --- /dev/null +++ b/src/core/marketmap/Market.ts @@ -0,0 +1,82 @@ +import { JSONSerializable } from '../../util/json'; +import { ProviderConfig } from './ProviderConfig'; +import { Ticker } from './Ticker'; +import { Market as Market_pb } from '@initia/initia.proto/slinky/marketmap/v1/market'; + +export class Market extends JSONSerializable< + Market.Amino, + Market.Data, + Market.Proto +> { + /** + * @param ticker the price feed for a given asset pair + * @param provider_configs the list of provider-specific configs for this Market + */ + constructor( + public ticker: Ticker, + public provider_configs: ProviderConfig[] + ) { + super(); + } + + public static fromAmino(data: Market.Amino): Market { + const { ticker, provider_configs } = data; + return new Market( + Ticker.fromAmino(ticker), + provider_configs.map(ProviderConfig.fromAmino) + ); + } + + public toAmino(): Market.Amino { + const { ticker, provider_configs } = this; + return { + ticker: ticker.toAmino(), + provider_configs: provider_configs.map(config => config.toAmino()), + }; + } + + public static fromData(data: Market.Data): Market { + const { ticker, provider_configs } = data; + return new Market( + Ticker.fromData(ticker), + provider_configs.map(ProviderConfig.fromData) + ); + } + + public toData(): Market.Data { + const { ticker, provider_configs } = this; + return { + ticker: ticker.toData(), + provider_configs: provider_configs.map(config => config.toData()), + }; + } + + public static fromProto(proto: Market.Proto): Market { + return new Market( + Ticker.fromProto(proto.ticker as Ticker.Proto), + proto.providerConfigs.map(ProviderConfig.fromProto) + ); + } + + public toProto(): Market.Proto { + const { ticker, provider_configs } = this; + return Market_pb.fromPartial({ + ticker: ticker.toProto(), + providerConfigs: provider_configs.map(config => config.toProto()), + }); + } +} + +export namespace Market { + export interface Amino { + ticker: Ticker.Amino; + provider_configs: ProviderConfig.Amino[]; + } + + export interface Data { + ticker: Ticker.Data; + provider_configs: ProviderConfig.Data[]; + } + + export type Proto = Market_pb; +} diff --git a/src/core/marketmap/MarketmapParams.ts b/src/core/marketmap/MarketmapParams.ts new file mode 100644 index 0000000..c95ec83 --- /dev/null +++ b/src/core/marketmap/MarketmapParams.ts @@ -0,0 +1,64 @@ +import { AccAddress } from '../bech32'; +import { JSONSerializable } from '../../util/json'; +import { Params as Params_pb } from '@initia/initia.proto/slinky/marketmap/v1/params'; + +export class MarketmapParams extends JSONSerializable< + MarketmapParams.Amino, + MarketmapParams.Data, + MarketmapParams.Proto +> { + /** + * @param market_authorities the list of authority accounts that are able to control updating the marketmap + * @param admin the address that can remove addresses from the MarketAuthorities list + */ + constructor( + public market_authorities: AccAddress[], + public admin: AccAddress + ) { + super(); + } + + public static fromAmino(data: MarketmapParams.Amino): MarketmapParams { + return new MarketmapParams(data.market_authorities, data.admin); + } + + public toAmino(): MarketmapParams.Amino { + const { market_authorities, admin } = this; + return { market_authorities, admin }; + } + + public static fromData(data: MarketmapParams.Data): MarketmapParams { + return new MarketmapParams(data.market_authorities, data.admin); + } + + public toData(): MarketmapParams.Data { + const { market_authorities, admin } = this; + return { market_authorities, admin }; + } + + public static fromProto(data: MarketmapParams.Proto): MarketmapParams { + return new MarketmapParams(data.marketAuthorities, data.admin); + } + + public toProto(): MarketmapParams.Proto { + const { market_authorities, admin } = this; + return Params_pb.fromPartial({ + marketAuthorities: market_authorities, + admin, + }); + } +} + +export namespace MarketmapParams { + export interface Amino { + market_authorities: AccAddress[]; + admin: AccAddress; + } + + export interface Data { + market_authorities: AccAddress[]; + admin: AccAddress; + } + + export type Proto = Params_pb; +} diff --git a/src/core/marketmap/ProviderConfig.ts b/src/core/marketmap/ProviderConfig.ts new file mode 100644 index 0000000..3bc9414 --- /dev/null +++ b/src/core/marketmap/ProviderConfig.ts @@ -0,0 +1,118 @@ +import { JSONSerializable } from '../../util/json'; +import { CurrencyPair } from '../oracle'; +import { ProviderConfig as ProviderConfig_pb } from '@initia/initia.proto/slinky/marketmap/v1/market'; + +export class ProviderConfig extends JSONSerializable< + ProviderConfig.Amino, + ProviderConfig.Data, + ProviderConfig.Proto +> { + /** + * @param name the name of the provider for which the configuration is being set + * @param off_chain_ticker the off-chain representation of the ticker + * @param normalize_by_pair the currency pair for this ticker to be normalized by + * @param invert boolean indicating if the BASE and QUOTE of the market should be inverted + * @param metadata_JSON the string of JSON that encodes any extra configuration for the given provider config + */ + constructor( + public name: string, + public off_chain_ticker: string, + public normalize_by_pair: CurrencyPair | undefined, + public invert: boolean, + public metadata_JSON: string + ) { + super(); + } + + public static fromAmino(data: ProviderConfig.Amino): ProviderConfig { + const { name, off_chain_ticker, normalize_by_pair, invert, metadata_JSON } = + data; + return new ProviderConfig( + name, + off_chain_ticker, + normalize_by_pair ? CurrencyPair.fromAmino(normalize_by_pair) : undefined, + invert, + metadata_JSON + ); + } + + public toAmino(): ProviderConfig.Amino { + const { name, off_chain_ticker, normalize_by_pair, invert, metadata_JSON } = + this; + return { + name, + off_chain_ticker, + normalize_by_pair: normalize_by_pair?.toAmino(), + invert, + metadata_JSON, + }; + } + + public static fromData(data: ProviderConfig.Data): ProviderConfig { + const { name, off_chain_ticker, normalize_by_pair, invert, metadata_JSON } = + data; + return new ProviderConfig( + name, + off_chain_ticker, + normalize_by_pair ? CurrencyPair.fromData(normalize_by_pair) : undefined, + invert, + metadata_JSON + ); + } + + public toData(): ProviderConfig.Data { + const { name, off_chain_ticker, normalize_by_pair, invert, metadata_JSON } = + this; + return { + name, + off_chain_ticker, + normalize_by_pair: normalize_by_pair?.toData(), + invert, + metadata_JSON, + }; + } + + public static fromProto(proto: ProviderConfig.Proto): ProviderConfig { + return new ProviderConfig( + proto.name, + proto.offChainTicker, + proto.normalizeByPair + ? CurrencyPair.fromProto(proto.normalizeByPair) + : undefined, + proto.invert, + proto.metadataJSON + ); + } + + public toProto(): ProviderConfig.Proto { + const { name, off_chain_ticker, normalize_by_pair, invert, metadata_JSON } = + this; + return ProviderConfig_pb.fromPartial({ + name, + offChainTicker: off_chain_ticker, + normalizeByPair: normalize_by_pair?.toProto(), + invert, + metadataJSON: metadata_JSON, + }); + } +} + +export namespace ProviderConfig { + export interface Amino { + name: string; + off_chain_ticker: string; + normalize_by_pair?: CurrencyPair.Amino; + invert: boolean; + metadata_JSON: string; + } + + export interface Data { + name: string; + off_chain_ticker: string; + normalize_by_pair?: CurrencyPair.Data; + invert: boolean; + metadata_JSON: string; + } + + export type Proto = ProviderConfig_pb; +} diff --git a/src/core/marketmap/Ticker.ts b/src/core/marketmap/Ticker.ts new file mode 100644 index 0000000..9342a5a --- /dev/null +++ b/src/core/marketmap/Ticker.ts @@ -0,0 +1,142 @@ +import { JSONSerializable } from '../../util/json'; +import { CurrencyPair } from '../oracle'; +import { Ticker as Ticker_pb } from '@initia/initia.proto/slinky/marketmap/v1/market'; +import Long from 'long'; + +export class Ticker extends JSONSerializable< + Ticker.Amino, + Ticker.Data, + Ticker.Proto +> { + /** + * @param currency_pair the currency pair for this ticker + * @param decimals the number of decimal places for the ticker + * @param min_provider_count the minimum number of providers required to consider the ticker valid + * @param enabled the flag that denotes if the Ticker is enabled for price fetching by an oracle + * @param metadata_JSON the string of JSON that encodes any extra configuration for the given ticker + */ + constructor( + public currency_pair: CurrencyPair, + public decimals: number, + public min_provider_count: number, + public enabled: boolean, + public metadata_JSON: string + ) { + super(); + } + + public static fromAmino(data: Ticker.Amino): Ticker { + const { + currency_pair, + decimals, + min_provider_count, + enabled, + metadata_JSON, + } = data; + return new Ticker( + CurrencyPair.fromAmino(currency_pair), + Number.parseInt(decimals), + Number.parseInt(min_provider_count), + enabled, + metadata_JSON + ); + } + + public toAmino(): Ticker.Amino { + const { + currency_pair, + decimals, + min_provider_count, + enabled, + metadata_JSON, + } = this; + return { + currency_pair: currency_pair.toAmino(), + decimals: decimals.toString(), + min_provider_count: min_provider_count.toString(), + enabled, + metadata_JSON, + }; + } + + public static fromData(data: Ticker.Data): Ticker { + const { + currency_pair, + decimals, + min_provider_count, + enabled, + metadata_JSON, + } = data; + return new Ticker( + CurrencyPair.fromData(currency_pair), + Number.parseInt(decimals), + Number.parseInt(min_provider_count), + enabled, + metadata_JSON + ); + } + + public toData(): Ticker.Data { + const { + currency_pair, + decimals, + min_provider_count, + enabled, + metadata_JSON, + } = this; + return { + currency_pair: currency_pair.toData(), + decimals: decimals.toString(), + min_provider_count: min_provider_count.toString(), + enabled, + metadata_JSON, + }; + } + + public static fromProto(proto: Ticker.Proto): Ticker { + return new Ticker( + CurrencyPair.fromProto(proto.currencyPair as CurrencyPair.Proto), + proto.decimals.toNumber(), + proto.minProviderCount.toNumber(), + proto.enabled, + proto.metadataJSON + ); + } + + public toProto(): Ticker.Proto { + const { + currency_pair, + decimals, + min_provider_count, + enabled, + metadata_JSON, + } = this; + return Ticker_pb.fromPartial({ + currencyPair: currency_pair, + decimals: Long.fromNumber(decimals), + minProviderCount: Long.fromNumber(min_provider_count), + enabled, + metadataJSON: metadata_JSON, + }); + } +} + +export namespace Ticker { + export interface Amino { + currency_pair: CurrencyPair.Amino; + decimals: string; + min_provider_count: string; + enabled: boolean; + metadata_JSON: string; + } + + export interface Data { + currency_pair: CurrencyPair.Data; + decimals: string; + min_provider_count: string; + enabled: boolean; + metadata_JSON: string; + } + + export type Proto = Ticker_pb; +} diff --git a/src/core/marketmap/index.ts b/src/core/marketmap/index.ts new file mode 100644 index 0000000..b6ca969 --- /dev/null +++ b/src/core/marketmap/index.ts @@ -0,0 +1,5 @@ +export * from './msgs'; +export * from './Market'; +export * from './ProviderConfig'; +export * from './Ticker'; +export * from './MarketmapParams'; diff --git a/src/core/marketmap/msgs/MsgCreateMarkets.ts b/src/core/marketmap/msgs/MsgCreateMarkets.ts new file mode 100644 index 0000000..4f28987 --- /dev/null +++ b/src/core/marketmap/msgs/MsgCreateMarkets.ts @@ -0,0 +1,98 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgCreateMarkets as MsgCreateMarkets_pb } from '@initia/initia.proto/slinky/marketmap/v1/tx'; +import { Market } from '../Market'; + +export class MsgCreateMarkets extends JSONSerializable< + MsgCreateMarkets.Amino, + MsgCreateMarkets.Data, + MsgCreateMarkets.Proto +> { + /** + * @param authority the signer of this transaction + * @param create_markets the list of all markets to be created for the given transaction + */ + constructor(public authority: AccAddress, public create_markets: Market[]) { + super(); + } + + public static fromAmino(data: MsgCreateMarkets.Amino): MsgCreateMarkets { + const { + value: { authority, create_markets }, + } = data; + return new MsgCreateMarkets( + authority, + create_markets.map(Market.fromAmino) + ); + } + + public toAmino(): MsgCreateMarkets.Amino { + const { authority, create_markets } = this; + return { + type: 'slinky/x/marketmap/MsgCreateMarkets', + value: { + authority, + create_markets: create_markets.map(msg => msg.toAmino()), + }, + }; + } + + public static fromData(data: MsgCreateMarkets.Data): MsgCreateMarkets { + const { authority, create_markets } = data; + return new MsgCreateMarkets(authority, create_markets.map(Market.fromData)); + } + + public toData(): MsgCreateMarkets.Data { + const { authority, create_markets } = this; + return { + '@type': '/slinky.marketmap.v1.MsgCreateMarkets', + authority, + create_markets: create_markets.map(msg => msg.toData()), + }; + } + + public static fromProto(data: MsgCreateMarkets.Proto): MsgCreateMarkets { + return new MsgCreateMarkets( + data.authority, + data.createMarkets.map(Market.fromProto) + ); + } + + public toProto(): MsgCreateMarkets.Proto { + const { authority, create_markets } = this; + return MsgCreateMarkets_pb.fromPartial({ + authority, + createMarkets: create_markets.map(c => c.toProto()), + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/slinky.marketmap.v1.MsgCreateMarkets', + value: MsgCreateMarkets_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgCreateMarkets { + return MsgCreateMarkets.fromProto(MsgCreateMarkets_pb.decode(msgAny.value)); + } +} + +export namespace MsgCreateMarkets { + export interface Amino { + type: 'slinky/x/marketmap/MsgCreateMarkets'; + value: { + authority: AccAddress; + create_markets: Market.Amino[]; + }; + } + + export interface Data { + '@type': '/slinky.marketmap.v1.MsgCreateMarkets'; + authority: AccAddress; + create_markets: Market.Data[]; + } + + export type Proto = MsgCreateMarkets_pb; +} diff --git a/src/core/marketmap/msgs/MsgRemoveMarketAuthorities.ts b/src/core/marketmap/msgs/MsgRemoveMarketAuthorities.ts new file mode 100644 index 0000000..4b5d6bd --- /dev/null +++ b/src/core/marketmap/msgs/MsgRemoveMarketAuthorities.ts @@ -0,0 +1,99 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgRemoveMarketAuthorities as MsgRemoveMarketAuthorities_pb } from '@initia/initia.proto/slinky/marketmap/v1/tx'; + +export class MsgRemoveMarketAuthorities extends JSONSerializable< + MsgRemoveMarketAuthorities.Amino, + MsgRemoveMarketAuthorities.Data, + MsgRemoveMarketAuthorities.Proto +> { + /** + * @param remove_addresses the list of addresses to remove + * @param admin the authority that is the x/marketmap Admin account + */ + constructor(public remove_addresses: AccAddress[], public admin: AccAddress) { + super(); + } + + public static fromAmino( + data: MsgRemoveMarketAuthorities.Amino + ): MsgRemoveMarketAuthorities { + const { + value: { remove_addresses, admin }, + } = data; + return new MsgRemoveMarketAuthorities(remove_addresses, admin); + } + + public toAmino(): MsgRemoveMarketAuthorities.Amino { + const { remove_addresses, admin } = this; + return { + type: 'slinky/x/marketmap/MsgRemoveMarketAuthorities', + value: { + remove_addresses, + admin, + }, + }; + } + + public static fromData( + data: MsgRemoveMarketAuthorities.Data + ): MsgRemoveMarketAuthorities { + const { remove_addresses, admin } = data; + return new MsgRemoveMarketAuthorities(remove_addresses, admin); + } + + public toData(): MsgRemoveMarketAuthorities.Data { + const { remove_addresses, admin } = this; + return { + '@type': '/slinky.marketmap.v1.MsgRemoveMarketAuthorities', + remove_addresses, + admin, + }; + } + + public static fromProto( + data: MsgRemoveMarketAuthorities.Proto + ): MsgRemoveMarketAuthorities { + return new MsgRemoveMarketAuthorities(data.removeAddresses, data.admin); + } + + public toProto(): MsgRemoveMarketAuthorities.Proto { + const { remove_addresses, admin } = this; + return MsgRemoveMarketAuthorities_pb.fromPartial({ + removeAddresses: remove_addresses, + admin, + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/slinky.marketmap.v1.MsgRemoveMarketAuthorities', + value: MsgRemoveMarketAuthorities_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgRemoveMarketAuthorities { + return MsgRemoveMarketAuthorities.fromProto( + MsgRemoveMarketAuthorities_pb.decode(msgAny.value) + ); + } +} + +export namespace MsgRemoveMarketAuthorities { + export interface Amino { + type: 'slinky/x/marketmap/MsgRemoveMarketAuthorities'; + value: { + remove_addresses: AccAddress[]; + admin: AccAddress; + }; + } + + export interface Data { + '@type': '/slinky.marketmap.v1.MsgRemoveMarketAuthorities'; + remove_addresses: AccAddress[]; + admin: AccAddress; + } + + export type Proto = MsgRemoveMarketAuthorities_pb; +} diff --git a/src/core/marketmap/msgs/MsgUpdateMarketmapParams.ts b/src/core/marketmap/msgs/MsgUpdateMarketmapParams.ts new file mode 100644 index 0000000..87480da --- /dev/null +++ b/src/core/marketmap/msgs/MsgUpdateMarketmapParams.ts @@ -0,0 +1,109 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { MarketmapParams } from '../MarketmapParams'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgParams as MsgParams_pb } from '@initia/initia.proto/slinky/marketmap/v1/tx'; + +export class MsgUpdateMarketmapParams extends JSONSerializable< + MsgUpdateMarketmapParams.Amino, + MsgUpdateMarketmapParams.Data, + MsgUpdateMarketmapParams.Proto +> { + /** + * @param authority the address that controls the module + * @param params params defines the x/hook parameters to update + */ + constructor(public authority: AccAddress, public params: MarketmapParams) { + super(); + } + + public static fromAmino( + data: MsgUpdateMarketmapParams.Amino + ): MsgUpdateMarketmapParams { + const { + value: { authority, params }, + } = data; + return new MsgUpdateMarketmapParams( + authority, + MarketmapParams.fromAmino(params) + ); + } + + public toAmino(): MsgUpdateMarketmapParams.Amino { + const { authority, params } = this; + return { + type: 'slinky/x/marketmap/MsgParams', + value: { + authority, + params: params.toAmino(), + }, + }; + } + + public static fromData( + data: MsgUpdateMarketmapParams.Data + ): MsgUpdateMarketmapParams { + const { authority, params } = data; + return new MsgUpdateMarketmapParams( + authority, + MarketmapParams.fromData(params) + ); + } + + public toData(): MsgUpdateMarketmapParams.Data { + const { authority, params } = this; + return { + '@type': '/slinky.marketmap.v1.MsgParams', + authority, + params: params.toData(), + }; + } + + public static fromProto( + data: MsgUpdateMarketmapParams.Proto + ): MsgUpdateMarketmapParams { + return new MsgUpdateMarketmapParams( + data.authority, + MarketmapParams.fromProto(data.params as MarketmapParams.Proto) + ); + } + + public toProto(): MsgUpdateMarketmapParams.Proto { + const { authority, params } = this; + return MsgParams_pb.fromPartial({ + authority, + params: params.toProto(), + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/slinky.marketmap.v1.MsgParams', + value: MsgParams_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgUpdateMarketmapParams { + return MsgUpdateMarketmapParams.fromProto( + MsgParams_pb.decode(msgAny.value) + ); + } +} + +export namespace MsgUpdateMarketmapParams { + export interface Amino { + type: 'slinky/x/marketmap/MsgParams'; + value: { + authority: AccAddress; + params: MarketmapParams.Amino; + }; + } + + export interface Data { + '@type': '/slinky.marketmap.v1.MsgParams'; + authority: AccAddress; + params: MarketmapParams.Data; + } + + export type Proto = MsgParams_pb; +} diff --git a/src/core/marketmap/msgs/MsgUpdateMarkets.ts b/src/core/marketmap/msgs/MsgUpdateMarkets.ts new file mode 100644 index 0000000..fd4fbda --- /dev/null +++ b/src/core/marketmap/msgs/MsgUpdateMarkets.ts @@ -0,0 +1,98 @@ +import { JSONSerializable } from '../../../util/json'; +import { AccAddress } from '../../bech32'; +import { Any } from '@initia/initia.proto/google/protobuf/any'; +import { MsgUpdateMarkets as MsgUpdateMarkets_pb } from '@initia/initia.proto/slinky/marketmap/v1/tx'; +import { Market } from '../Market'; + +export class MsgUpdateMarkets extends JSONSerializable< + MsgUpdateMarkets.Amino, + MsgUpdateMarkets.Data, + MsgUpdateMarkets.Proto +> { + /** + * @param authority the signer of this transaction + * @param update_markets the list of all markets to be updated for the given transaction + */ + constructor(public authority: AccAddress, public update_markets: Market[]) { + super(); + } + + public static fromAmino(data: MsgUpdateMarkets.Amino): MsgUpdateMarkets { + const { + value: { authority, update_markets }, + } = data; + return new MsgUpdateMarkets( + authority, + update_markets.map(Market.fromAmino) + ); + } + + public toAmino(): MsgUpdateMarkets.Amino { + const { authority, update_markets } = this; + return { + type: 'slinky/x/marketmap/MsgUpdateMarkets', + value: { + authority, + update_markets: update_markets.map(msg => msg.toAmino()), + }, + }; + } + + public static fromData(data: MsgUpdateMarkets.Data): MsgUpdateMarkets { + const { authority, update_markets } = data; + return new MsgUpdateMarkets(authority, update_markets.map(Market.fromData)); + } + + public toData(): MsgUpdateMarkets.Data { + const { authority, update_markets } = this; + return { + '@type': '/slinky.marketmap.v1.MsgUpdateMarkets', + authority, + update_markets: update_markets.map(msg => msg.toData()), + }; + } + + public static fromProto(data: MsgUpdateMarkets.Proto): MsgUpdateMarkets { + return new MsgUpdateMarkets( + data.authority, + data.updateMarkets.map(Market.fromProto) + ); + } + + public toProto(): MsgUpdateMarkets.Proto { + const { authority, update_markets } = this; + return MsgUpdateMarkets_pb.fromPartial({ + authority, + updateMarkets: update_markets.map(c => c.toProto()), + }); + } + + public packAny(): Any { + return Any.fromPartial({ + typeUrl: '/slinky.marketmap.v1.MsgUpdateMarkets', + value: MsgUpdateMarkets_pb.encode(this.toProto()).finish(), + }); + } + + public static unpackAny(msgAny: Any): MsgUpdateMarkets { + return MsgUpdateMarkets.fromProto(MsgUpdateMarkets_pb.decode(msgAny.value)); + } +} + +export namespace MsgUpdateMarkets { + export interface Amino { + type: 'slinky/x/marketmap/MsgUpdateMarkets'; + value: { + authority: AccAddress; + update_markets: Market.Amino[]; + }; + } + + export interface Data { + '@type': '/slinky.marketmap.v1.MsgUpdateMarkets'; + authority: AccAddress; + update_markets: Market.Data[]; + } + + export type Proto = MsgUpdateMarkets_pb; +} diff --git a/src/core/marketmap/msgs/index.ts b/src/core/marketmap/msgs/index.ts new file mode 100644 index 0000000..e137d96 --- /dev/null +++ b/src/core/marketmap/msgs/index.ts @@ -0,0 +1,35 @@ +import { MsgCreateMarkets } from './MsgCreateMarkets'; +import { MsgUpdateMarkets } from './MsgUpdateMarkets'; +import { MsgRemoveMarketAuthorities } from './MsgRemoveMarketAuthorities'; +import { MsgUpdateMarketmapParams } from './MsgUpdateMarketmapParams'; + +export * from './MsgCreateMarkets'; +export * from './MsgUpdateMarkets'; +export * from './MsgRemoveMarketAuthorities'; +export * from './MsgUpdateMarketmapParams'; + +export type MarketmapMsg = + | MsgCreateMarkets + | MsgUpdateMarkets + | MsgRemoveMarketAuthorities + | MsgUpdateMarketmapParams; + +export namespace MarketmapMsg { + export type Amino = + | MsgCreateMarkets.Amino + | MsgUpdateMarkets.Amino + | MsgRemoveMarketAuthorities.Amino + | MsgUpdateMarketmapParams.Amino; + + export type Data = + | MsgCreateMarkets.Data + | MsgUpdateMarkets.Data + | MsgRemoveMarketAuthorities.Data + | MsgUpdateMarketmapParams.Data; + + export type Proto = + | MsgCreateMarkets.Proto + | MsgUpdateMarkets.Proto + | MsgRemoveMarketAuthorities.Proto + | MsgUpdateMarketmapParams.Proto; +}