carbon-js-sdk 0.6.1-test2 → 0.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/lib/CarbonSDK.js +3 -3
  2. package/lib/clients/GrpcQueryClient.d.ts +6 -10
  3. package/lib/clients/GrpcQueryClient.js +7 -54
  4. package/lib/clients/NEOClient.js +3 -11
  5. package/lib/codec/perpsliquidity/event.d.ts +115 -0
  6. package/lib/codec/perpsliquidity/event.js +657 -0
  7. package/lib/codec/perpsliquidity/genesis.d.ts +36 -0
  8. package/lib/codec/perpsliquidity/genesis.js +163 -0
  9. package/lib/codec/perpsliquidity/market.d.ts +84 -0
  10. package/lib/codec/perpsliquidity/market.js +431 -0
  11. package/lib/codec/perpsliquidity/params.d.ts +27 -0
  12. package/lib/codec/perpsliquidity/params.js +129 -0
  13. package/lib/codec/perpsliquidity/pool.d.ts +119 -0
  14. package/lib/codec/perpsliquidity/pool.js +774 -0
  15. package/lib/codec/perpsliquidity/query.d.ts +246 -0
  16. package/lib/codec/perpsliquidity/query.js +1125 -0
  17. package/lib/codec/perpsliquidity/tx.d.ts +203 -0
  18. package/lib/codec/perpsliquidity/tx.js +973 -0
  19. package/lib/codec/subaccount/legacy.d.ts +19 -0
  20. package/lib/codec/subaccount/legacy.js +72 -0
  21. package/lib/modules/erc20.d.ts +30 -0
  22. package/lib/modules/erc20.js +81 -0
  23. package/lib/modules/perpsliquidity.d.ts +49 -0
  24. package/lib/modules/perpsliquidity.js +118 -0
  25. package/lib/provider/amino/types/erc20.d.ts +4 -0
  26. package/lib/provider/amino/types/erc20.js +40 -0
  27. package/lib/provider/amino/types/perpsliquidity.d.ts +4 -0
  28. package/lib/provider/amino/types/perpsliquidity.js +73 -0
  29. package/lib/provider/metamask/error.d.ts +2 -0
  30. package/lib/provider/metamask/error.js +18 -0
  31. package/package.json +1 -1
package/lib/CarbonSDK.js CHANGED
@@ -71,10 +71,10 @@ class CarbonSDK {
71
71
  this.evmChainId = (_f = (_e = opts.evmChainId) !== null && _e !== void 0 ? _e : constant_1.CarbonEvmChainIDs[this.network]) !== null && _f !== void 0 ? _f : constant_1.CarbonEvmChainIDs[constant_1.Network.MainNet];
72
72
  let grpcClient;
73
73
  if (opts.useTmAbciQuery !== true && this.networkConfig.grpcUrl) {
74
- const hasNodeGrpc = GrpcQueryClient_1.default.hasNodeGrpc();
75
- const grpcUrl = hasNodeGrpc ? this.networkConfig.grpcUrl : this.networkConfig.grpcWebUrl;
76
74
  const transport = typeof window === "undefined" ? grpc_web_node_http_transport_1.NodeHttpTransport() : undefined;
77
- grpcClient = (_g = opts.grpcQueryClient) !== null && _g !== void 0 ? _g : new GrpcQueryClient_1.default(grpcUrl, { transport });
75
+ grpcClient = (_g = opts.grpcQueryClient) !== null && _g !== void 0 ? _g : new GrpcQueryClient_1.default(this.networkConfig.grpcWebUrl, {
76
+ transport,
77
+ });
78
78
  }
79
79
  this.query = new clients_1.CarbonQueryClient({
80
80
  tmClient: this.tmClient,
@@ -5,22 +5,18 @@ export declare class GrpcWebError extends Error {
5
5
  metadata: grpc.Metadata;
6
6
  constructor(message: string, code: grpc.Code, metadata: grpc.Metadata);
7
7
  }
8
+ /**
9
+ * Uses grpc-web module on cosmos-sdk to simulate gRPC queries
10
+ * throught HTTP/1.1.
11
+ * see https://github.com/cosmos/cosmos-sdk/issues/7345
12
+ */
8
13
  export declare class GrpcQueryClient implements ProtobufRpcClient {
9
14
  private host;
10
15
  private options;
11
- private useGrpcJs;
12
16
  constructor(host: string, options?: {
13
17
  transport?: grpc.TransportFactory;
14
18
  metadata?: grpc.Metadata;
15
19
  });
16
- static hasNodeGrpc(): boolean;
17
- request(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
18
- _requestGrpc(service: string, method: string, data: Uint8Array): Promise<Uint8Array>;
19
- /**
20
- * Uses grpc-web module on cosmos-sdk to simulate gRPC queries
21
- * throught HTTP/1.1.
22
- * see https://github.com/cosmos/cosmos-sdk/issues/7345
23
- */
24
- _requestGrpcWeb(serviceName: string, methodName: string, data: Uint8Array): Promise<Uint8Array>;
20
+ request(serviceName: string, methodName: string, data: Uint8Array): Promise<Uint8Array>;
25
21
  }
26
22
  export default GrpcQueryClient;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GrpcQueryClient = exports.GrpcWebError = void 0;
4
4
  const grpc_web_1 = require("@improbable-eng/grpc-web");
5
- const grpc_web_node_http_transport_1 = require("@improbable-eng/grpc-web-node-http-transport");
6
5
  class GrpcWebError extends Error {
7
6
  constructor(message, code, metadata) {
8
7
  super(message);
@@ -11,63 +10,17 @@ class GrpcWebError extends Error {
11
10
  }
12
11
  }
13
12
  exports.GrpcWebError = GrpcWebError;
14
- const passThrough = (incoming) => incoming;
15
- const passThroughBuffer = (incoming) => Buffer.from(incoming);
13
+ /**
14
+ * Uses grpc-web module on cosmos-sdk to simulate gRPC queries
15
+ * throught HTTP/1.1.
16
+ * see https://github.com/cosmos/cosmos-sdk/issues/7345
17
+ */
16
18
  class GrpcQueryClient {
17
19
  constructor(host, options = {}) {
18
20
  this.host = host;
19
21
  this.options = options;
20
- this.useGrpcJs = GrpcQueryClient.hasNodeGrpc() && typeof window === "undefined";
21
22
  }
22
- static hasNodeGrpc() {
23
- try {
24
- return require("@grpc/grpc-js").version; // eslint-disable-line
25
- }
26
- catch (error) {
27
- return false;
28
- }
29
- }
30
- request(service, method, data) {
31
- return this.useGrpcJs ? this._requestGrpc(service, method, data) : this._requestGrpcWeb(service, method, data);
32
- }
33
- _requestGrpc(service, method, data) {
34
- var _a, _b;
35
- const path = ["", service, method].join("/");
36
- try {
37
- const { credentials, makeGenericClientConstructor } = require("@grpc/grpc-js"); // eslint-disable-line
38
- const client = new (makeGenericClientConstructor({
39
- runQuery: {
40
- path,
41
- requestStream: false,
42
- responseStream: false,
43
- requestSerialize: passThroughBuffer,
44
- requestDeserialize: passThrough,
45
- responseSerialize: passThroughBuffer,
46
- responseDeserialize: passThrough,
47
- }
48
- }, service))(this.host, credentials.createSsl());
49
- return new Promise((resolve, reject) => {
50
- client.runQuery(data, (error, value) => {
51
- if (error)
52
- reject(error);
53
- else
54
- resolve(value);
55
- });
56
- });
57
- }
58
- catch (error) {
59
- if ((_b = (_a = error === null || error === void 0 ? void 0 : error.message) === null || _a === void 0 ? void 0 : _a.startsWith) === null || _b === void 0 ? void 0 : _b.call(_a, "Cannot find module '@grpc/grpc-js'")) {
60
- throw new Error("Please install @grpc/grpc-js, refer to README.md for more information.");
61
- }
62
- throw error;
63
- }
64
- }
65
- /**
66
- * Uses grpc-web module on cosmos-sdk to simulate gRPC queries
67
- * throught HTTP/1.1.
68
- * see https://github.com/cosmos/cosmos-sdk/issues/7345
69
- */
70
- _requestGrpcWeb(serviceName, methodName, data) {
23
+ request(serviceName, methodName, data) {
71
24
  return new Promise((resolve, reject) => {
72
25
  grpc_web_1.grpc.unary({
73
26
  methodName,
@@ -82,7 +35,7 @@ class GrpcQueryClient {
82
35
  request: Object.assign(Object.assign({}, data), { toObject: () => data, serializeBinary: () => data }),
83
36
  host: this.host,
84
37
  metadata: this.options.metadata,
85
- transport: grpc_web_node_http_transport_1.NodeHttpTransport(),
38
+ transport: this.options.transport,
86
39
  debug: false,
87
40
  onEnd: function (response) {
88
41
  if (response.status === grpc_web_1.grpc.Code.OK) {
@@ -32,7 +32,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
32
32
  };
33
33
  Object.defineProperty(exports, "__esModule", { value: true });
34
34
  exports.NEOClient = void 0;
35
- const CarbonSDK_1 = __importDefault(require("../CarbonSDK"));
36
35
  const constant_1 = require("../constant");
37
36
  const util_1 = require("../util");
38
37
  const address_1 = require("../util/address");
@@ -139,9 +138,7 @@ class NEOClient {
139
138
  nonce,
140
139
  ]);
141
140
  const rpcUrl = yield this.getProviderUrl();
142
- const apiProvider = networkConfig.network === CarbonSDK_1.default.Network.MainNet
143
- ? new neon_js_1.api.neonDB.instance("https://api.switcheo.network")
144
- : new neon_js_1.api.neoCli.instance(rpcUrl);
141
+ const apiProvider = new neon_js_1.api.neoCli.instance(rpcUrl);
145
142
  return neon_js_1.api.doInvoke({
146
143
  api: apiProvider,
147
144
  url: rpcUrl,
@@ -221,9 +218,7 @@ class NEOClient {
221
218
  ];
222
219
  sb.emitAppCall(scriptHash, "lock", data);
223
220
  const rpcUrl = yield this.getProviderUrl();
224
- const apiProvider = networkConfig.network === CarbonSDK_1.default.Network.MainNet
225
- ? new neon_js_1.api.neonDB.instance("https://api.switcheo.network")
226
- : new neon_js_1.api.neoCli.instance(rpcUrl);
221
+ const apiProvider = new neon_js_1.api.neoCli.instance(rpcUrl);
227
222
  let invokeTxConfig = {
228
223
  account: Object.assign(Object.assign({}, new Neon.wallet.Account("")), {
229
224
  // overwrite the address and public key to values provided by the ledger.
@@ -285,10 +280,7 @@ class NEOClient {
285
280
  args: [],
286
281
  };
287
282
  const script = Neon.sc.createScript(props);
288
- const networkConfig = this.getNetworkConfig();
289
- const apiProvider = networkConfig.network === CarbonSDK_1.default.Network.MainNet
290
- ? new neon_js_1.api.neonDB.instance("https://api.switcheo.network")
291
- : new neon_js_1.api.neoCli.instance(rpcUrl);
283
+ const apiProvider = new neon_js_1.api.neoCli.instance(rpcUrl);
292
284
  const config = {
293
285
  api: apiProvider,
294
286
  url: rpcUrl,
@@ -0,0 +1,115 @@
1
+ import Long from "long";
2
+ import _m0 from "protobufjs/minimal";
3
+ import { PlPool } from "./pool";
4
+ import { MarketConfig } from "./market";
5
+ export declare const protobufPackage = "Switcheo.carbon.perpsliquidity";
6
+ export interface SetPoolEvent {
7
+ pool?: PlPool;
8
+ type: string;
9
+ }
10
+ export interface NewPoolEvent {
11
+ pool?: PlPool;
12
+ }
13
+ export interface UpdatePoolEvent {
14
+ pool?: PlPool;
15
+ }
16
+ export interface RegisterToPoolEvent {
17
+ poolId: Long;
18
+ marketId: string;
19
+ }
20
+ export interface DeregisterFromPoolEvent {
21
+ poolId: Long;
22
+ marketId: string;
23
+ }
24
+ export interface SetMarketConfigEvent {
25
+ marketConfig?: MarketConfig;
26
+ }
27
+ export interface DepositToPoolEvent {
28
+ poolId: Long;
29
+ denom: string;
30
+ amount: string;
31
+ shareDenom: string;
32
+ shareAmount: string;
33
+ initialShareAmountBurnt: string;
34
+ depositor: string;
35
+ }
36
+ export interface WithdrawFromPoolEvent {
37
+ poolId: Long;
38
+ denom: string;
39
+ amount: string;
40
+ shareDenom: string;
41
+ shareAmount: string;
42
+ withdrawer: string;
43
+ }
44
+ export interface UpdateMarketUtilizationMultiplierEvent {
45
+ market: string;
46
+ multiplier: string;
47
+ }
48
+ export declare const SetPoolEvent: {
49
+ encode(message: SetPoolEvent, writer?: _m0.Writer): _m0.Writer;
50
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): SetPoolEvent;
51
+ fromJSON(object: any): SetPoolEvent;
52
+ toJSON(message: SetPoolEvent): unknown;
53
+ fromPartial(object: DeepPartial<SetPoolEvent>): SetPoolEvent;
54
+ };
55
+ export declare const NewPoolEvent: {
56
+ encode(message: NewPoolEvent, writer?: _m0.Writer): _m0.Writer;
57
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): NewPoolEvent;
58
+ fromJSON(object: any): NewPoolEvent;
59
+ toJSON(message: NewPoolEvent): unknown;
60
+ fromPartial(object: DeepPartial<NewPoolEvent>): NewPoolEvent;
61
+ };
62
+ export declare const UpdatePoolEvent: {
63
+ encode(message: UpdatePoolEvent, writer?: _m0.Writer): _m0.Writer;
64
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): UpdatePoolEvent;
65
+ fromJSON(object: any): UpdatePoolEvent;
66
+ toJSON(message: UpdatePoolEvent): unknown;
67
+ fromPartial(object: DeepPartial<UpdatePoolEvent>): UpdatePoolEvent;
68
+ };
69
+ export declare const RegisterToPoolEvent: {
70
+ encode(message: RegisterToPoolEvent, writer?: _m0.Writer): _m0.Writer;
71
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): RegisterToPoolEvent;
72
+ fromJSON(object: any): RegisterToPoolEvent;
73
+ toJSON(message: RegisterToPoolEvent): unknown;
74
+ fromPartial(object: DeepPartial<RegisterToPoolEvent>): RegisterToPoolEvent;
75
+ };
76
+ export declare const DeregisterFromPoolEvent: {
77
+ encode(message: DeregisterFromPoolEvent, writer?: _m0.Writer): _m0.Writer;
78
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): DeregisterFromPoolEvent;
79
+ fromJSON(object: any): DeregisterFromPoolEvent;
80
+ toJSON(message: DeregisterFromPoolEvent): unknown;
81
+ fromPartial(object: DeepPartial<DeregisterFromPoolEvent>): DeregisterFromPoolEvent;
82
+ };
83
+ export declare const SetMarketConfigEvent: {
84
+ encode(message: SetMarketConfigEvent, writer?: _m0.Writer): _m0.Writer;
85
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): SetMarketConfigEvent;
86
+ fromJSON(object: any): SetMarketConfigEvent;
87
+ toJSON(message: SetMarketConfigEvent): unknown;
88
+ fromPartial(object: DeepPartial<SetMarketConfigEvent>): SetMarketConfigEvent;
89
+ };
90
+ export declare const DepositToPoolEvent: {
91
+ encode(message: DepositToPoolEvent, writer?: _m0.Writer): _m0.Writer;
92
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): DepositToPoolEvent;
93
+ fromJSON(object: any): DepositToPoolEvent;
94
+ toJSON(message: DepositToPoolEvent): unknown;
95
+ fromPartial(object: DeepPartial<DepositToPoolEvent>): DepositToPoolEvent;
96
+ };
97
+ export declare const WithdrawFromPoolEvent: {
98
+ encode(message: WithdrawFromPoolEvent, writer?: _m0.Writer): _m0.Writer;
99
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): WithdrawFromPoolEvent;
100
+ fromJSON(object: any): WithdrawFromPoolEvent;
101
+ toJSON(message: WithdrawFromPoolEvent): unknown;
102
+ fromPartial(object: DeepPartial<WithdrawFromPoolEvent>): WithdrawFromPoolEvent;
103
+ };
104
+ export declare const UpdateMarketUtilizationMultiplierEvent: {
105
+ encode(message: UpdateMarketUtilizationMultiplierEvent, writer?: _m0.Writer): _m0.Writer;
106
+ decode(input: _m0.Reader | Uint8Array, length?: number | undefined): UpdateMarketUtilizationMultiplierEvent;
107
+ fromJSON(object: any): UpdateMarketUtilizationMultiplierEvent;
108
+ toJSON(message: UpdateMarketUtilizationMultiplierEvent): unknown;
109
+ fromPartial(object: DeepPartial<UpdateMarketUtilizationMultiplierEvent>): UpdateMarketUtilizationMultiplierEvent;
110
+ };
111
+ declare type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
112
+ export declare type DeepPartial<T> = T extends Builtin ? T : T extends Long ? string | number | Long : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
113
+ [K in keyof T]?: DeepPartial<T[K]>;
114
+ } : Partial<T>;
115
+ export {};