Skip to content

Commit afb8a09

Browse files
committed
Add slinky marketmap module
1 parent a7f0ea4 commit afb8a09

17 files changed

+960
-3
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@initia/initia.js",
3-
"version": "0.2.6",
3+
"version": "0.2.7",
44
"description": "The JavaScript SDK for Initia",
55
"license": "MIT",
66
"author": "InitiaLabs",

src/client/lcd/LCDClient.ts

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
IbcTransferAPI,
1919
IbcPermAPI,
2020
InterTxAPI,
21+
MarketmapAPI,
2122
MoveAPI,
2223
MstakingAPI,
2324
OpchildAPI,
@@ -101,6 +102,7 @@ export class LCDClient {
101102
public ibcTransfer: IbcTransferAPI;
102103
public ibcPerm: IbcPermAPI;
103104
public interTx: InterTxAPI;
105+
public marketmap: MarketmapAPI;
104106
public move: MoveAPI;
105107
public mstaking: MstakingAPI;
106108
public opchild: OpchildAPI;
@@ -153,6 +155,7 @@ export class LCDClient {
153155
this.ibcTransfer = new IbcTransferAPI(this.apiRequester);
154156
this.ibcPerm = new IbcPermAPI(this.apiRequester);
155157
this.interTx = new InterTxAPI(this.apiRequester);
158+
this.marketmap = new MarketmapAPI(this.apiRequester);
156159
this.move = new MoveAPI(this.apiRequester);
157160
this.mstaking = new MstakingAPI(this.apiRequester);
158161
this.opchild = new OpchildAPI(this.apiRequester);

src/client/lcd/api/MarketmapAPI.ts

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { BaseAPI } from './BaseAPI';
2+
import { APIParams } from '../APIRequester';
3+
import { CurrencyPair, Market, MarketmapParams } from '../../../core';
4+
5+
export interface MarketMap {
6+
markets: { [ticker: string]: Market };
7+
}
8+
9+
export namespace MarketMap {
10+
export interface Data {
11+
markets: { [ticker: string]: Market.Data };
12+
}
13+
}
14+
15+
export class MarketmapAPI extends BaseAPI {
16+
public async marketMap(params: APIParams = {}): Promise<MarketMap> {
17+
return this.c
18+
.get<{ market_map: MarketMap.Data }>(
19+
`/slinky/marketmap/v1/marketmap`,
20+
params
21+
)
22+
.then(d => {
23+
const markets: { [ticker: string]: Market } = {};
24+
for (const [ticker, market] of Object.entries(d.market_map.markets)) {
25+
markets[ticker] = Market.fromData(market);
26+
}
27+
return { markets };
28+
});
29+
}
30+
31+
public async market(
32+
pair: CurrencyPair,
33+
params: APIParams = {}
34+
): Promise<Market> {
35+
return this.c
36+
.get<{ market: Market.Data }>(`/slinky/marketmap/v1/market`, {
37+
...params,
38+
'currency_pair.Base': pair.Base,
39+
'currency_pair.Quote': pair.Quote,
40+
})
41+
.then(d => Market.fromData(d.market));
42+
}
43+
44+
public async lastUpdated(params: APIParams = {}): Promise<number> {
45+
return this.c
46+
.get<{ last_updated: string }>(
47+
`/slinky/marketmap/v1/last_updated`,
48+
params
49+
)
50+
.then(d => Number.parseInt(d.last_updated));
51+
}
52+
53+
public async parameters(params: APIParams = {}): Promise<MarketmapParams> {
54+
return this.c
55+
.get<{ params: MarketmapParams.Data }>(
56+
`/slinky/marketmap/v1/params`,
57+
params
58+
)
59+
.then(d => MarketmapParams.fromData(d.params));
60+
}
61+
}

src/client/lcd/api/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export * from './IbcNftAPI';
1616
export * from './IbcTransferAPI';
1717
export * from './IbcPermAPI';
1818
export * from './InterTxAPI';
19+
export * from './MarketmapAPI';
1920
export * from './MoveAPI';
2021
export * from './MstakingAPI';
2122
export * from './OpchildAPI';

src/core/Msg.ts

+41
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ import {
122122
MsgUpdateIbcConnectionParams,
123123
} from './ibc/core/connection/msgs';
124124
import { InterTxMsg, MsgRegisterAccount, MsgSubmitTx } from './intertx';
125+
import {
126+
MarketmapMsg,
127+
MsgCreateMarkets,
128+
MsgUpdateMarkets,
129+
MsgRemoveMarketAuthorities,
130+
MsgUpdateMarketmapParams,
131+
} from './marketmap/msgs';
125132
import {
126133
MoveMsg,
127134
MsgPublish,
@@ -240,6 +247,7 @@ export type Msg =
240247
| IbcClientMsg
241248
| IbcConnectionMsg
242249
| InterTxMsg
250+
| MarketmapMsg
243251
| MoveMsg
244252
| MstakingMsg
245253
| OpchildMsg
@@ -272,6 +280,7 @@ export namespace Msg {
272280
| IbcPermMsg.Amino
273281
| IbcTransferMsg.Amino
274282
| InterTxMsg.Amino
283+
| MarketmapMsg.Amino
275284
| MoveMsg.Amino
276285
| MstakingMsg.Amino
277286
| OpchildMsg.Amino
@@ -308,6 +317,7 @@ export namespace Msg {
308317
| IbcClientMsg.Data
309318
| IbcConnectionMsg.Data
310319
| InterTxMsg.Data
320+
| MarketmapMsg.Data
311321
| MoveMsg.Data
312322
| MstakingMsg.Data
313323
| OpchildMsg.Data
@@ -344,6 +354,7 @@ export namespace Msg {
344354
| IbcClientMsg.Proto
345355
| IbcConnectionMsg.Proto
346356
| InterTxMsg.Proto
357+
| MarketmapMsg.Proto
347358
| MoveMsg.Proto
348359
| MstakingMsg.Proto
349360
| OpchildMsg.Proto
@@ -521,6 +532,16 @@ export namespace Msg {
521532
case 'intertx/MsgSubmitTx':
522533
return MsgSubmitTx.fromAmino(data);
523534

535+
// marketmap
536+
case 'slinky/x/marketmap/MsgCreateMarkets':
537+
return MsgCreateMarkets.fromAmino(data);
538+
case 'slinky/x/marketmap/MsgUpdateMarkets':
539+
return MsgUpdateMarkets.fromAmino(data);
540+
case 'slinky/x/marketmap/MsgRemoveMarketAuthorities':
541+
return MsgRemoveMarketAuthorities.fromAmino(data);
542+
case 'slinky/x/marketmap/MsgParams':
543+
return MsgUpdateMarketmapParams.fromAmino(data);
544+
524545
// move
525546
case 'move/MsgPublish':
526547
return MsgPublish.fromAmino(data);
@@ -921,6 +942,16 @@ export namespace Msg {
921942
case '/initia.intertx.v1.MsgSubmitTx':
922943
return MsgSubmitTx.fromData(data);
923944

945+
// marketmap
946+
case '/slinky.marketmap.v1.MsgCreateMarkets':
947+
return MsgCreateMarkets.fromData(data);
948+
case '/slinky.marketmap.v1.MsgUpdateMarkets':
949+
return MsgUpdateMarkets.fromData(data);
950+
case '/slinky.marketmap.v1.MsgRemoveMarketAuthorities':
951+
return MsgRemoveMarketAuthorities.fromData(data);
952+
case '/slinky.marketmap.v1.MsgParams':
953+
return MsgUpdateMarketmapParams.fromData(data);
954+
924955
// move
925956
case '/initia.move.v1.MsgPublish':
926957
return MsgPublish.fromData(data);
@@ -1324,6 +1355,16 @@ export namespace Msg {
13241355
case '/initia.intertx.v1.MsgSubmitTx':
13251356
return MsgSubmitTx.unpackAny(proto);
13261357

1358+
// marketmap
1359+
case '/slinky.marketmap.v1.MsgCreateMarkets':
1360+
return MsgCreateMarkets.unpackAny(proto);
1361+
case '/slinky.marketmap.v1.MsgUpdateMarkets':
1362+
return MsgUpdateMarkets.unpackAny(proto);
1363+
case '/slinky.marketmap.v1.MsgRemoveMarketAuthorities':
1364+
return MsgRemoveMarketAuthorities.unpackAny(proto);
1365+
case '/slinky.marketmap.v1.MsgParams':
1366+
return MsgUpdateMarketmapParams.unpackAny(proto);
1367+
13271368
// move
13281369
case '/initia.move.v1.MsgPublish':
13291370
return MsgPublish.unpackAny(proto);

src/core/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export * from './group';
2525
export * from './ibc';
2626
export * from './ibchooks';
2727
export * from './intertx';
28+
export * from './marketmap';
2829
export * from './move';
2930
export * from './mstaking';
3031
export * from './opchild';

src/core/marketmap/Market.ts

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { JSONSerializable } from '../../util/json';
2+
import { ProviderConfig } from './ProviderConfig';
3+
import { Ticker } from './Ticker';
4+
import { Market as Market_pb } from '@initia/initia.proto/slinky/marketmap/v1/market';
5+
6+
export class Market extends JSONSerializable<
7+
Market.Amino,
8+
Market.Data,
9+
Market.Proto
10+
> {
11+
/**
12+
* @param ticker the price feed for a given asset pair
13+
* @param provider_configs the list of provider-specific configs for this Market
14+
*/
15+
constructor(
16+
public ticker: Ticker,
17+
public provider_configs: ProviderConfig[]
18+
) {
19+
super();
20+
}
21+
22+
public static fromAmino(data: Market.Amino): Market {
23+
const { ticker, provider_configs } = data;
24+
return new Market(
25+
Ticker.fromAmino(ticker),
26+
provider_configs.map(ProviderConfig.fromAmino)
27+
);
28+
}
29+
30+
public toAmino(): Market.Amino {
31+
const { ticker, provider_configs } = this;
32+
return {
33+
ticker: ticker.toAmino(),
34+
provider_configs: provider_configs.map(config => config.toAmino()),
35+
};
36+
}
37+
38+
public static fromData(data: Market.Data): Market {
39+
const { ticker, provider_configs } = data;
40+
return new Market(
41+
Ticker.fromData(ticker),
42+
provider_configs.map(ProviderConfig.fromData)
43+
);
44+
}
45+
46+
public toData(): Market.Data {
47+
const { ticker, provider_configs } = this;
48+
return {
49+
ticker: ticker.toData(),
50+
provider_configs: provider_configs.map(config => config.toData()),
51+
};
52+
}
53+
54+
public static fromProto(proto: Market.Proto): Market {
55+
return new Market(
56+
Ticker.fromProto(proto.ticker as Ticker.Proto),
57+
proto.providerConfigs.map(ProviderConfig.fromProto)
58+
);
59+
}
60+
61+
public toProto(): Market.Proto {
62+
const { ticker, provider_configs } = this;
63+
return Market_pb.fromPartial({
64+
ticker: ticker.toProto(),
65+
providerConfigs: provider_configs.map(config => config.toProto()),
66+
});
67+
}
68+
}
69+
70+
export namespace Market {
71+
export interface Amino {
72+
ticker: Ticker.Amino;
73+
provider_configs: ProviderConfig.Amino[];
74+
}
75+
76+
export interface Data {
77+
ticker: Ticker.Data;
78+
provider_configs: ProviderConfig.Data[];
79+
}
80+
81+
export type Proto = Market_pb;
82+
}

src/core/marketmap/MarketmapParams.ts

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { AccAddress } from '../bech32';
2+
import { JSONSerializable } from '../../util/json';
3+
import { Params as Params_pb } from '@initia/initia.proto/slinky/marketmap/v1/params';
4+
5+
export class MarketmapParams extends JSONSerializable<
6+
MarketmapParams.Amino,
7+
MarketmapParams.Data,
8+
MarketmapParams.Proto
9+
> {
10+
/**
11+
* @param market_authorities the list of authority accounts that are able to control updating the marketmap
12+
* @param admin the address that can remove addresses from the MarketAuthorities list
13+
*/
14+
constructor(
15+
public market_authorities: AccAddress[],
16+
public admin: AccAddress
17+
) {
18+
super();
19+
}
20+
21+
public static fromAmino(data: MarketmapParams.Amino): MarketmapParams {
22+
return new MarketmapParams(data.market_authorities, data.admin);
23+
}
24+
25+
public toAmino(): MarketmapParams.Amino {
26+
const { market_authorities, admin } = this;
27+
return { market_authorities, admin };
28+
}
29+
30+
public static fromData(data: MarketmapParams.Data): MarketmapParams {
31+
return new MarketmapParams(data.market_authorities, data.admin);
32+
}
33+
34+
public toData(): MarketmapParams.Data {
35+
const { market_authorities, admin } = this;
36+
return { market_authorities, admin };
37+
}
38+
39+
public static fromProto(data: MarketmapParams.Proto): MarketmapParams {
40+
return new MarketmapParams(data.marketAuthorities, data.admin);
41+
}
42+
43+
public toProto(): MarketmapParams.Proto {
44+
const { market_authorities, admin } = this;
45+
return Params_pb.fromPartial({
46+
marketAuthorities: market_authorities,
47+
admin,
48+
});
49+
}
50+
}
51+
52+
export namespace MarketmapParams {
53+
export interface Amino {
54+
market_authorities: AccAddress[];
55+
admin: AccAddress;
56+
}
57+
58+
export interface Data {
59+
market_authorities: AccAddress[];
60+
admin: AccAddress;
61+
}
62+
63+
export type Proto = Params_pb;
64+
}

0 commit comments

Comments
 (0)