carbon-js-sdk 0.10.2-rc8 → 0.10.3

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.
@@ -21,7 +21,7 @@ declare class InsightsQueryClient {
21
21
  Pools(req?: Insights.QueryGetPoolsRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetPoolsResponse>>;
22
22
  PoolHistory(query: Insights.QueryGetPoolHistoryRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetPoolHistoryResponse>>;
23
23
  PerpPoolHistory(query: Insights.QueryGetPerpPoolHistoryRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetPerpPoolHistoryResponse>>;
24
- PerpPool7DApy(query: Insights.QueryPerpPool7DaysAPY): Promise<Insights.InsightsQueryResponse<Insights.QueryPerpPool7DaysAPYResponse>>;
24
+ PerpPoolApy(query: Insights.QueryPerpPoolAPY): Promise<Insights.InsightsQueryResponse<Insights.QueryPerpPoolAPYResponse>>;
25
25
  PoolVolume(req: Insights.QueryGetPoolVolumeRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetPoolVolumeResponse>>;
26
26
  PoolsVolume(req?: Insights.QueryGetPoolsVolumeRequest): Promise<Insights.InsightsQueryResponse<Insights.QueryGetPoolsVolumeResponse>>;
27
27
  UserRewardsClaimHistory(req: Insights.QueryGetUserRewardsClaimHistoryRequest): Promise<InsightsQueryResponse<Insights.QueryGetUserRewardsClaimHistoryResponse>>;
@@ -173,7 +173,7 @@ class InsightsQueryClient {
173
173
  return response.data;
174
174
  });
175
175
  }
176
- PerpPool7DApy(query) {
176
+ PerpPoolApy(query) {
177
177
  var _a, _b;
178
178
  return __awaiter(this, void 0, void 0, function* () {
179
179
  const routeParams = { id: query.id };
@@ -91,18 +91,19 @@ export interface PositionHistoryEntry {
91
91
  export interface QueryGetPerpPoolHistoryRequest extends QueryByPageRequest {
92
92
  address: string;
93
93
  }
94
- export interface QueryPerpPool7DaysAPY extends QueryByPageRequest {
94
+ export interface QueryPerpPoolAPY extends QueryByPageRequest {
95
95
  id: number;
96
96
  }
97
- export interface PerpPool7DaysAPYEntry {
98
- latestPrice: number;
99
- previousPrice: number;
100
- apy: number;
101
- from: string;
102
- to: string;
103
- }
104
- export interface QueryPerpPool7DaysAPYResponse {
105
- entries: PerpPool7DaysAPYEntry[];
97
+ export interface PerpPoolAPYEntry {
98
+ denom: string;
99
+ annualizedApy1day: number | null;
100
+ annualizedApy7days: number | null;
101
+ annualizedApy14days: number | null;
102
+ annualizedApy30days: number | null;
103
+ annualizedApy90days: number | null;
104
+ }
105
+ export interface QueryPerpPoolAPYResponse {
106
+ entries: PerpPoolAPYEntry[];
106
107
  meta: PageMeta;
107
108
  }
108
109
  export interface PerpPositionHistoryEntry {
package/lib/util/tx.d.ts CHANGED
@@ -3,6 +3,7 @@ import * as CosmosModels from "../codec/cosmos-models";
3
3
  import { StdFee } from "@cosmjs/amino";
4
4
  import { SignerData } from "@cosmjs/stargate";
5
5
  import { SWTHAddressOptions } from "./address";
6
+ import { EncodeObject } from "@cosmjs/proto-signing";
6
7
  export { StdSignDoc } from "@cosmjs/amino";
7
8
  export interface TxBody extends Omit<CosmosModels.Tx.TxBody, "messages"> {
8
9
  messages: unknown[];
@@ -634,3 +635,5 @@ export declare const TxMinGasPriceTypeDefaultKey = "swth";
634
635
  export declare const TxGasCostTypeMap: {
635
636
  [x: string]: string;
636
637
  };
638
+ export declare const useSignDirectForMetamask: (messages: readonly EncodeObject[]) => boolean;
639
+ export declare const isLibMsg: (typeUrl: string) => boolean;
package/lib/util/tx.js CHANGED
@@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
19
19
  return result;
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
- exports.TxGasCostTypeMap = exports.TxMinGasPriceTypeDefaultKey = exports.TxGasCostTypeDefaultKey = exports.DEFAULT_SIGN_OPTS = exports.Types = exports.CarbonCustomError = exports.ErrorType = exports.BroadcastTxMode = exports.getSender = exports.decode = void 0;
22
+ exports.isLibMsg = exports.useSignDirectForMetamask = exports.TxGasCostTypeMap = exports.TxMinGasPriceTypeDefaultKey = exports.TxGasCostTypeDefaultKey = exports.DEFAULT_SIGN_OPTS = exports.Types = exports.CarbonCustomError = exports.ErrorType = exports.BroadcastTxMode = exports.getSender = exports.decode = void 0;
23
23
  const codec_1 = require("../codec");
24
24
  const CosmosModels = __importStar(require("../codec/cosmos-models"));
25
25
  const constant_1 = require("../constant");
@@ -135,3 +135,23 @@ exports.TxGasCostTypeMap = {
135
135
  [codec_1.TxTypes.MsgStakePoolToken]: "stake_pool_token",
136
136
  [codec_1.TxTypes.MsgUnstakePoolToken]: "unstake_pool_token",
137
137
  };
138
+ const LibPackages = ['ibc', 'cosmos', 'alliance'];
139
+ const BacklistedMessages = [];
140
+ // to use signDirect for metamask signing if messages are from libraries (cosmos-sdk, ibc, alliance).
141
+ // Reasons:
142
+ // 1. There is decoding issue with MsgGrantAllowance in amino
143
+ // 2. For Ibc MsgTransfer, there is an overflow issue with timeouttimestamp overflow (from uint32) during unmarshalJSON, even though it is defined as uint64
144
+ // (This can be resolved from the client side by use sendIBCTransfer instead of sendIBCTransferV2) but using signDirect here fixes it too.
145
+ // 3. Ethermint is still using legacyMsg.getSigners() to verify many amino signed eip712 txs. However, getSigners() is deprecated and not implmented in messages from cosmos-sdk anymore.
146
+ // 4. as of comsos-sdk v0.50 --> very few messages are using legacyDec so we can safely use signDirect
147
+ const useSignDirectForMetamask = (messages) => {
148
+ const typeUrls = messages.map(m => m.typeUrl);
149
+ return !!Object.values(codec_1.TxTypes).find(typeUrl => exports.isLibMsg(typeUrl) && typeUrls.includes(typeUrl));
150
+ };
151
+ exports.useSignDirectForMetamask = useSignDirectForMetamask;
152
+ const isLibMsg = (typeUrl) => {
153
+ // /ibc.core.client.v1.UpgradeProposal --> ibc
154
+ const pkg = typeUrl.split('.')[0].substring(1);
155
+ return LibPackages.includes(pkg) && !BacklistedMessages.includes(typeUrl);
156
+ };
157
+ exports.isLibMsg = isLibMsg;
@@ -17,6 +17,7 @@ const codec_1 = require("../codec");
17
17
  const tx_1 = require("../codec/cosmos/tx/v1beta1/tx");
18
18
  const web3_1 = require("../codec/ethermint/types/v1/web3");
19
19
  const ethermint_1 = require("../util/ethermint");
20
+ const tx_2 = require("../util/tx");
20
21
  const amino_1 = require("@cosmjs/amino");
21
22
  const encoding_1 = require("@cosmjs/encoding");
22
23
  const math_1 = require("@cosmjs/math");
@@ -94,8 +95,11 @@ class CarbonSigningClient extends stargate_1.StargateClient {
94
95
  if (this.signer.legacyEip712SignMode) {
95
96
  return this.signLegacyEip712(signerAddress, messages, fee, memo, signerData);
96
97
  }
98
+ // workaround to use signDirect
99
+ if (tx_2.useSignDirectForMetamask(messages))
100
+ return this.signDirect(signerAddress, messages, fee, memo, signerData, granterAddress);
97
101
  // Use amino sigining for metamask as there is a bug with signDirect signature verification
98
- // ethermint verifies sign direct dec type as shifted by 18dp when it should be unshifted (verified with keplr)
102
+ // ethermint verifies sign direct legacyDec type as shifted by 18dp when it should be unshifted (verified with keplr)
99
103
  // therefore the alternative which works here would be to use signamino where the verification is not broken on ethermint.
100
104
  return this.signAmino(signerAddress, messages, fee, memo, signerData, granterAddress);
101
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-js-sdk",
3
- "version": "0.10.2-rc8",
3
+ "version": "0.10.3",
4
4
  "description": "TypeScript SDK for Carbon blockchain",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",