@keplr-wallet/stores 0.9.17 → 0.9.18-rc.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.
- package/build/account/base.d.ts +22 -38
- package/build/account/base.js +37 -178
- package/build/account/base.js.map +1 -1
- package/build/account/base.spec.js +4 -6
- package/build/account/base.spec.js.map +1 -1
- package/build/account/cosmos.d.ts +59 -28
- package/build/account/cosmos.js +267 -130
- package/build/account/cosmos.js.map +1 -1
- package/build/account/cosmwasm.d.ts +20 -27
- package/build/account/cosmwasm.js +39 -39
- package/build/account/cosmwasm.js.map +1 -1
- package/build/account/index.d.ts +0 -2
- package/build/account/index.js +0 -2
- package/build/account/index.js.map +1 -1
- package/build/account/secret.d.ts +20 -26
- package/build/account/secret.js +45 -24
- package/build/account/secret.js.map +1 -1
- package/build/account/store.d.ts +16 -27
- package/build/account/store.js +6 -22
- package/build/account/store.js.map +1 -1
- package/build/common/index.d.ts +1 -0
- package/build/common/index.js +1 -0
- package/build/common/index.js.map +1 -1
- package/build/common/merge.d.ts +55 -0
- package/build/common/merge.js +41 -0
- package/build/common/merge.js.map +1 -0
- package/build/common/merge.spec.d.ts +1 -0
- package/build/common/merge.spec.js +26 -0
- package/build/common/merge.spec.js.map +1 -0
- package/build/common/query/index.d.ts +10 -0
- package/build/common/query/index.js +15 -7
- package/build/common/query/index.js.map +1 -1
- package/build/common/query/query.spec.d.ts +11 -0
- package/build/common/query/query.spec.js +125 -0
- package/build/common/query/query.spec.js.map +1 -0
- package/build/ibc/currency-registrar.d.ts +8 -16
- package/build/ibc/currency-registrar.js.map +1 -1
- package/build/price/index.d.ts +1 -2
- package/build/price/index.js +2 -3
- package/build/price/index.js.map +1 -1
- package/build/query/chain-rpc-query.d.ts +18 -0
- package/build/query/chain-rpc-query.js +50 -0
- package/build/query/chain-rpc-query.js.map +1 -0
- package/build/query/cosmos/account/index.js +6 -2
- package/build/query/cosmos/account/index.js.map +1 -1
- package/build/query/cosmos/account/types.d.ts +9 -4
- package/build/query/cosmos/balance/index.js +3 -3
- package/build/query/cosmos/balance/index.js.map +1 -1
- package/build/query/cosmos/balance/types.d.ts +1 -2
- package/build/query/cosmos/distribution/params.js +2 -2
- package/build/query/cosmos/distribution/params.js.map +1 -1
- package/build/query/cosmos/distribution/types.d.ts +2 -2
- package/build/query/cosmos/governance/params.js +3 -3
- package/build/query/cosmos/governance/params.js.map +1 -1
- package/build/query/cosmos/governance/proposal.d.ts +4 -4
- package/build/query/cosmos/governance/proposal.js +16 -37
- package/build/query/cosmos/governance/proposal.js.map +1 -1
- package/build/query/cosmos/governance/proposals.d.ts +4 -4
- package/build/query/cosmos/governance/proposals.js +6 -3
- package/build/query/cosmos/governance/proposals.js.map +1 -1
- package/build/query/cosmos/governance/types.d.ts +26 -58
- package/build/query/cosmos/governance/vote.d.ts +3 -3
- package/build/query/cosmos/governance/vote.js +12 -18
- package/build/query/cosmos/governance/vote.js.map +1 -1
- package/build/query/cosmos/index.d.ts +0 -1
- package/build/query/cosmos/index.js +0 -1
- package/build/query/cosmos/index.js.map +1 -1
- package/build/query/cosmos/queries.d.ts +8 -9
- package/build/query/cosmos/queries.js +14 -13
- package/build/query/cosmos/queries.js.map +1 -1
- package/build/query/cosmos/staking/delegations.d.ts +3 -3
- package/build/query/cosmos/staking/delegations.js +9 -36
- package/build/query/cosmos/staking/delegations.js.map +1 -1
- package/build/query/cosmos/staking/params.d.ts +5 -0
- package/build/query/cosmos/staking/params.js +34 -1
- package/build/query/cosmos/staking/params.js.map +1 -1
- package/build/query/cosmos/staking/pool.d.ts +3 -0
- package/build/query/cosmos/staking/pool.js +30 -1
- package/build/query/cosmos/staking/pool.js.map +1 -1
- package/build/query/cosmos/staking/rewards.js +9 -9
- package/build/query/cosmos/staking/rewards.js.map +1 -1
- package/build/query/cosmos/staking/types.d.ts +18 -33
- package/build/query/cosmos/staking/types.js +1 -0
- package/build/query/cosmos/staking/types.js.map +1 -1
- package/build/query/cosmos/staking/unbonding-delegations.js +3 -3
- package/build/query/cosmos/staking/unbonding-delegations.js.map +1 -1
- package/build/query/cosmos/staking/validators.js +14 -20
- package/build/query/cosmos/staking/validators.js.map +1 -1
- package/build/query/cosmos/status/index.d.ts +50 -0
- package/build/query/cosmos/status/index.js +24 -0
- package/build/query/cosmos/status/index.js.map +1 -0
- package/build/query/cosmos/supply/inflation.d.ts +3 -3
- package/build/query/cosmos/supply/inflation.js +5 -11
- package/build/query/cosmos/supply/inflation.js.map +1 -1
- package/build/query/cosmos/supply/minting.js +1 -1
- package/build/query/cosmos/supply/minting.js.map +1 -1
- package/build/query/cosmos/supply/supply.d.ts +5 -5
- package/build/query/cosmos/supply/supply.js +1 -9
- package/build/query/cosmos/supply/supply.js.map +1 -1
- package/build/query/cosmos/supply/types.d.ts +2 -8
- package/build/query/cosmwasm/queries.d.ts +6 -9
- package/build/query/cosmwasm/queries.js +12 -11
- package/build/query/cosmwasm/queries.js.map +1 -1
- package/build/query/queries.d.ts +20 -11
- package/build/query/queries.js +13 -12
- package/build/query/queries.js.map +1 -1
- package/build/query/secret-wasm/queries.d.ts +8 -8
- package/build/query/secret-wasm/queries.js +12 -11
- package/build/query/secret-wasm/queries.js.map +1 -1
- package/package.json +7 -7
- package/src/account/base.spec.ts +5 -7
- package/src/account/base.ts +35 -305
- package/src/account/cosmos.ts +452 -185
- package/src/account/cosmwasm.ts +70 -74
- package/src/account/index.ts +0 -2
- package/src/account/secret.ts +79 -53
- package/src/account/store.ts +43 -57
- package/src/common/index.ts +1 -0
- package/src/common/merge.spec.ts +47 -0
- package/src/common/merge.ts +91 -0
- package/src/common/query/index.ts +28 -7
- package/src/common/query/query.spec.ts +122 -0
- package/src/ibc/currency-registrar.ts +10 -9
- package/src/price/index.ts +1 -2
- package/src/query/chain-rpc-query.ts +66 -0
- package/src/query/cosmos/account/index.ts +12 -2
- package/src/query/cosmos/account/types.ts +9 -5
- package/src/query/cosmos/balance/index.ts +8 -3
- package/src/query/cosmos/balance/types.ts +3 -2
- package/src/query/cosmos/distribution/params.ts +2 -2
- package/src/query/cosmos/distribution/types.ts +2 -2
- package/src/query/cosmos/governance/params.ts +3 -3
- package/src/query/cosmos/governance/proposal.ts +25 -51
- package/src/query/cosmos/governance/proposals.ts +13 -6
- package/src/query/cosmos/governance/types.ts +57 -73
- package/src/query/cosmos/governance/vote.ts +16 -26
- package/src/query/cosmos/index.ts +0 -1
- package/src/query/cosmos/queries.ts +35 -16
- package/src/query/cosmos/staking/delegations.ts +15 -48
- package/src/query/cosmos/staking/params.ts +29 -1
- package/src/query/cosmos/staking/pool.ts +33 -1
- package/src/query/cosmos/staking/rewards.ts +9 -9
- package/src/query/cosmos/staking/types.ts +30 -45
- package/src/query/cosmos/staking/unbonding-delegations.ts +3 -3
- package/src/query/cosmos/staking/validators.ts +15 -28
- package/src/query/cosmos/status/index.ts +67 -0
- package/src/query/cosmos/supply/inflation.ts +8 -13
- package/src/query/cosmos/supply/minting.ts +1 -1
- package/src/query/cosmos/supply/supply.ts +11 -24
- package/src/query/cosmos/supply/types.ts +2 -11
- package/src/query/cosmwasm/queries.ts +25 -19
- package/src/query/queries.ts +64 -29
- package/src/query/secret-wasm/queries.ts +28 -24
- package/build/account/all.d.ts +0 -25
- package/build/account/all.js +0 -27
- package/build/account/all.js.map +0 -1
- package/build/account/cosmos-secret.d.ts +0 -23
- package/build/account/cosmos-secret.js +0 -25
- package/build/account/cosmos-secret.js.map +0 -1
- package/build/query/cosmos/block/index.d.ts +0 -25
- package/build/query/cosmos/block/index.js +0 -49
- package/build/query/cosmos/block/index.js.map +0 -1
- package/src/account/all.ts +0 -86
- package/src/account/cosmos-secret.ts +0 -65
- package/src/query/cosmos/block/index.ts +0 -63
package/build/account/cosmos.js
CHANGED
|
@@ -12,26 +12,30 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.
|
|
15
|
+
exports.CosmosAccountImpl = exports.defaultCosmosMsgOpts = exports.CosmosAccount = void 0;
|
|
16
16
|
const base_1 = require("./base");
|
|
17
|
+
const launchpad_1 = require("@cosmjs/launchpad");
|
|
17
18
|
const common_1 = require("@keplr-wallet/common");
|
|
18
19
|
const unit_1 = require("@keplr-wallet/unit");
|
|
19
20
|
const cosmos_1 = require("@keplr-wallet/cosmos");
|
|
20
21
|
const types_1 = require("../query/cosmos/staking/types");
|
|
21
22
|
const long_1 = __importDefault(require("long"));
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
const axios_1 = __importDefault(require("axios"));
|
|
24
|
+
var SignMode = cosmos_1.cosmos.tx.signing.v1beta1.SignMode;
|
|
25
|
+
const deepmerge_1 = __importDefault(require("deepmerge"));
|
|
26
|
+
exports.CosmosAccount = {
|
|
27
|
+
use(options) {
|
|
28
|
+
return (base, chainGetter, chainId) => {
|
|
29
|
+
const msgOptsFromCreator = options.msgOptsCreator
|
|
30
|
+
? options.msgOptsCreator(chainId)
|
|
31
|
+
: undefined;
|
|
32
|
+
return {
|
|
33
|
+
cosmos: new CosmosAccountImpl(base, chainGetter, chainId, options.queriesStore, deepmerge_1.default(exports.defaultCosmosMsgOpts, msgOptsFromCreator ? msgOptsFromCreator : {}), options),
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
exports.defaultCosmosMsgOpts = {
|
|
35
39
|
send: {
|
|
36
40
|
native: {
|
|
37
41
|
type: "cosmos-sdk/MsgSend",
|
|
@@ -64,14 +68,20 @@ AccountWithCosmos.defaultMsgOpts = {
|
|
|
64
68
|
gas: 250000,
|
|
65
69
|
},
|
|
66
70
|
};
|
|
67
|
-
class
|
|
68
|
-
constructor(base, chainGetter, chainId, queriesStore) {
|
|
71
|
+
class CosmosAccountImpl {
|
|
72
|
+
constructor(base, chainGetter, chainId, queriesStore, _msgOpts, txOpts) {
|
|
69
73
|
this.base = base;
|
|
70
74
|
this.chainGetter = chainGetter;
|
|
71
75
|
this.chainId = chainId;
|
|
72
76
|
this.queriesStore = queriesStore;
|
|
77
|
+
this._msgOpts = _msgOpts;
|
|
78
|
+
this.txOpts = txOpts;
|
|
79
|
+
this.broadcastMode = "sync";
|
|
73
80
|
this.base.registerSendTokenFn(this.processSendToken.bind(this));
|
|
74
81
|
}
|
|
82
|
+
get msgOpts() {
|
|
83
|
+
return this._msgOpts;
|
|
84
|
+
}
|
|
75
85
|
processSendToken(amount, currency, recipient, memo, stdFee, signOptions, onTxEvents) {
|
|
76
86
|
var _a, _b;
|
|
77
87
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -84,7 +94,7 @@ class CosmosAccount {
|
|
|
84
94
|
return dec.truncate().toString();
|
|
85
95
|
})();
|
|
86
96
|
const msg = {
|
|
87
|
-
type: this.
|
|
97
|
+
type: this.msgOpts.send.native.type,
|
|
88
98
|
value: {
|
|
89
99
|
from_address: this.base.bech32Address,
|
|
90
100
|
to_address: recipient,
|
|
@@ -96,23 +106,21 @@ class CosmosAccount {
|
|
|
96
106
|
],
|
|
97
107
|
},
|
|
98
108
|
};
|
|
99
|
-
yield this.
|
|
109
|
+
yield this.sendMsgs("send", {
|
|
100
110
|
aminoMsgs: [msg],
|
|
101
|
-
protoMsgs:
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
]
|
|
112
|
-
: undefined,
|
|
111
|
+
protoMsgs: [
|
|
112
|
+
{
|
|
113
|
+
type_url: "/cosmos.bank.v1beta1.MsgSend",
|
|
114
|
+
value: cosmos_1.cosmos.bank.v1beta1.MsgSend.encode({
|
|
115
|
+
fromAddress: msg.value.from_address,
|
|
116
|
+
toAddress: msg.value.to_address,
|
|
117
|
+
amount: msg.value.amount,
|
|
118
|
+
}).finish(),
|
|
119
|
+
},
|
|
120
|
+
],
|
|
113
121
|
}, memo, {
|
|
114
122
|
amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
|
|
115
|
-
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.
|
|
123
|
+
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.send.native.gas.toString(),
|
|
116
124
|
}, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
|
|
117
125
|
if (tx.code == null || tx.code === 0) {
|
|
118
126
|
// After succeeding to send token, refresh the balance.
|
|
@@ -131,6 +139,142 @@ class CosmosAccount {
|
|
|
131
139
|
return false;
|
|
132
140
|
});
|
|
133
141
|
}
|
|
142
|
+
sendMsgs(type, msgs, memo = "", fee, signOptions, onTxEvents) {
|
|
143
|
+
var _a, _b;
|
|
144
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
145
|
+
this.base.setTxTypeInProgress(type);
|
|
146
|
+
let txHash;
|
|
147
|
+
let signDoc;
|
|
148
|
+
try {
|
|
149
|
+
if (typeof msgs === "function") {
|
|
150
|
+
msgs = yield msgs();
|
|
151
|
+
}
|
|
152
|
+
const result = yield this.broadcastMsgs(msgs, fee, memo, signOptions, this.broadcastMode);
|
|
153
|
+
txHash = result.txHash;
|
|
154
|
+
signDoc = result.signDoc;
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
this.base.setTxTypeInProgress("");
|
|
158
|
+
if ((_a = this.txOpts.preTxEvents) === null || _a === void 0 ? void 0 : _a.onBroadcastFailed) {
|
|
159
|
+
this.txOpts.preTxEvents.onBroadcastFailed(this.chainId, e);
|
|
160
|
+
}
|
|
161
|
+
if (onTxEvents &&
|
|
162
|
+
"onBroadcastFailed" in onTxEvents &&
|
|
163
|
+
onTxEvents.onBroadcastFailed) {
|
|
164
|
+
onTxEvents.onBroadcastFailed(e);
|
|
165
|
+
}
|
|
166
|
+
throw e;
|
|
167
|
+
}
|
|
168
|
+
let onBroadcasted;
|
|
169
|
+
let onFulfill;
|
|
170
|
+
if (onTxEvents) {
|
|
171
|
+
if (typeof onTxEvents === "function") {
|
|
172
|
+
onFulfill = onTxEvents;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
onBroadcasted = onTxEvents.onBroadcasted;
|
|
176
|
+
onFulfill = onTxEvents.onFulfill;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
if ((_b = this.txOpts.preTxEvents) === null || _b === void 0 ? void 0 : _b.onBroadcasted) {
|
|
180
|
+
this.txOpts.preTxEvents.onBroadcasted(this.chainId, txHash);
|
|
181
|
+
}
|
|
182
|
+
if (onBroadcasted) {
|
|
183
|
+
onBroadcasted(txHash);
|
|
184
|
+
}
|
|
185
|
+
const txTracer = new cosmos_1.TendermintTxTracer(this.chainGetter.getChain(this.chainId).rpc, "/websocket", {
|
|
186
|
+
wsObject: this.txOpts.wsObject,
|
|
187
|
+
});
|
|
188
|
+
txTracer.traceTx(txHash).then((tx) => {
|
|
189
|
+
var _a;
|
|
190
|
+
txTracer.close();
|
|
191
|
+
this.base.setTxTypeInProgress("");
|
|
192
|
+
// After sending tx, the balances is probably changed due to the fee.
|
|
193
|
+
for (const feeAmount of signDoc.fee.amount) {
|
|
194
|
+
const bal = this.queries.queryBalances
|
|
195
|
+
.getQueryBech32Address(this.base.bech32Address)
|
|
196
|
+
.balances.find((bal) => bal.currency.coinMinimalDenom === feeAmount.denom);
|
|
197
|
+
if (bal) {
|
|
198
|
+
bal.fetch();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Always add the tx hash data.
|
|
202
|
+
if (tx && !tx.hash) {
|
|
203
|
+
tx.hash = Buffer.from(txHash).toString("hex");
|
|
204
|
+
}
|
|
205
|
+
if ((_a = this.txOpts.preTxEvents) === null || _a === void 0 ? void 0 : _a.onFulfill) {
|
|
206
|
+
this.txOpts.preTxEvents.onFulfill(this.chainId, tx);
|
|
207
|
+
}
|
|
208
|
+
if (onFulfill) {
|
|
209
|
+
onFulfill(tx);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
// Return the tx hash.
|
|
215
|
+
broadcastMsgs(msgs, fee, memo = "", signOptions, mode = "async") {
|
|
216
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
+
if (this.base.walletStatus !== base_1.WalletStatus.Loaded) {
|
|
218
|
+
throw new Error(`Wallet is not loaded: ${this.base.walletStatus}`);
|
|
219
|
+
}
|
|
220
|
+
const aminoMsgs = msgs.aminoMsgs;
|
|
221
|
+
const protoMsgs = msgs.protoMsgs;
|
|
222
|
+
// TODO: Make proto sign doc if `aminoMsgs` is empty or null
|
|
223
|
+
if (aminoMsgs.length === 0 || protoMsgs.length === 0) {
|
|
224
|
+
throw new Error("There is no msg to send");
|
|
225
|
+
}
|
|
226
|
+
if (aminoMsgs.length !== protoMsgs.length) {
|
|
227
|
+
throw new Error("The length of aminoMsgs and protoMsgs are different");
|
|
228
|
+
}
|
|
229
|
+
const account = yield cosmos_1.BaseAccount.fetchFromRest(this.instance, this.base.bech32Address, true);
|
|
230
|
+
const coinType = this.chainGetter.getChain(this.chainId).coinType;
|
|
231
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
232
|
+
const keplr = (yield this.base.getKeplr());
|
|
233
|
+
const signDoc = launchpad_1.makeSignDoc(aminoMsgs, fee, this.chainId, memo, account.getAccountNumber().toString(), account.getSequence().toString());
|
|
234
|
+
const signResponse = yield keplr.signAmino(this.chainId, this.base.bech32Address, signDoc, signOptions);
|
|
235
|
+
const signedTx = cosmos_1.cosmos.tx.v1beta1.TxRaw.encode({
|
|
236
|
+
bodyBytes: cosmos_1.cosmos.tx.v1beta1.TxBody.encode({
|
|
237
|
+
messages: protoMsgs,
|
|
238
|
+
memo: signResponse.signed.memo,
|
|
239
|
+
}).finish(),
|
|
240
|
+
authInfoBytes: cosmos_1.cosmos.tx.v1beta1.AuthInfo.encode({
|
|
241
|
+
signerInfos: [
|
|
242
|
+
{
|
|
243
|
+
publicKey: {
|
|
244
|
+
type_url: coinType === 60
|
|
245
|
+
? "/ethermint.crypto.v1.ethsecp256k1.PubKey"
|
|
246
|
+
: "/cosmos.crypto.secp256k1.PubKey",
|
|
247
|
+
value: cosmos_1.cosmos.crypto.secp256k1.PubKey.encode({
|
|
248
|
+
key: Buffer.from(signResponse.signature.pub_key.value, "base64"),
|
|
249
|
+
}).finish(),
|
|
250
|
+
},
|
|
251
|
+
modeInfo: {
|
|
252
|
+
single: {
|
|
253
|
+
mode: SignMode.SIGN_MODE_LEGACY_AMINO_JSON,
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
sequence: long_1.default.fromString(signResponse.signed.sequence),
|
|
257
|
+
},
|
|
258
|
+
],
|
|
259
|
+
fee: {
|
|
260
|
+
amount: signResponse.signed.fee.amount,
|
|
261
|
+
gasLimit: long_1.default.fromString(signResponse.signed.fee.gas),
|
|
262
|
+
},
|
|
263
|
+
}).finish(),
|
|
264
|
+
signatures: [Buffer.from(signResponse.signature.signature, "base64")],
|
|
265
|
+
}).finish();
|
|
266
|
+
return {
|
|
267
|
+
txHash: yield keplr.sendTx(this.chainId, signedTx, mode),
|
|
268
|
+
signDoc: signResponse.signed,
|
|
269
|
+
};
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
get instance() {
|
|
273
|
+
const chainInfo = this.chainGetter.getChain(this.chainId);
|
|
274
|
+
return axios_1.default.create(Object.assign({
|
|
275
|
+
baseURL: chainInfo.rest,
|
|
276
|
+
}, chainInfo.restConfig));
|
|
277
|
+
}
|
|
134
278
|
sendIBCTransferMsg(channel, amount, currency, recipient, memo = "", stdFee = {}, signOptions, onTxEvents) {
|
|
135
279
|
var _a, _b;
|
|
136
280
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -142,17 +286,24 @@ class CosmosAccount {
|
|
|
142
286
|
dec = dec.mul(unit_1.DecUtils.getPrecisionDec(currency.coinDecimals));
|
|
143
287
|
return dec.truncate().toString();
|
|
144
288
|
})();
|
|
145
|
-
const
|
|
146
|
-
.
|
|
147
|
-
|
|
148
|
-
yield this.base.sendMsgs("ibcTransfer", () => __awaiter(this, void 0, void 0, function* () {
|
|
289
|
+
const destinationInfo = this.queriesStore.get(channel.counterpartyChainId)
|
|
290
|
+
.cosmos.queryRPCStatus;
|
|
291
|
+
yield this.sendMsgs("ibcTransfer", () => __awaiter(this, void 0, void 0, function* () {
|
|
149
292
|
// Wait until fetching complete.
|
|
150
|
-
yield
|
|
151
|
-
if (
|
|
293
|
+
yield destinationInfo.waitFreshResponse();
|
|
294
|
+
if (!destinationInfo.network) {
|
|
295
|
+
throw new Error(`Failed to fetch the network chain id of ${channel.counterpartyChainId}`);
|
|
296
|
+
}
|
|
297
|
+
if (cosmos_1.ChainIdHelper.parse(destinationInfo.network).identifier !==
|
|
298
|
+
cosmos_1.ChainIdHelper.parse(channel.counterpartyChainId).identifier) {
|
|
299
|
+
throw new Error(`Fetched the network chain id is different with counterparty chain id (${destinationInfo.network}, ${channel.counterpartyChainId})`);
|
|
300
|
+
}
|
|
301
|
+
if (!destinationInfo.latestBlockHeight ||
|
|
302
|
+
destinationInfo.latestBlockHeight.equals(new unit_1.Int("0"))) {
|
|
152
303
|
throw new Error(`Failed to fetch the latest block of ${channel.counterpartyChainId}`);
|
|
153
304
|
}
|
|
154
305
|
const msg = {
|
|
155
|
-
type: this.
|
|
306
|
+
type: this.msgOpts.ibcTransfer.type,
|
|
156
307
|
value: {
|
|
157
308
|
source_port: channel.portId,
|
|
158
309
|
source_channel: channel.channelId,
|
|
@@ -163,9 +314,9 @@ class CosmosAccount {
|
|
|
163
314
|
sender: this.base.bech32Address,
|
|
164
315
|
receiver: recipient,
|
|
165
316
|
timeout_height: {
|
|
166
|
-
revision_number: cosmos_1.ChainIdHelper.parse(
|
|
317
|
+
revision_number: cosmos_1.ChainIdHelper.parse(destinationInfo.network).version.toString(),
|
|
167
318
|
// Set the timeout height as the current height + 150.
|
|
168
|
-
revision_height:
|
|
319
|
+
revision_height: destinationInfo.latestBlockHeight
|
|
169
320
|
.add(new unit_1.Int("150"))
|
|
170
321
|
.toString(),
|
|
171
322
|
},
|
|
@@ -197,7 +348,7 @@ class CosmosAccount {
|
|
|
197
348
|
};
|
|
198
349
|
}), memo, {
|
|
199
350
|
amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
|
|
200
|
-
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.
|
|
351
|
+
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.ibcTransfer.gas.toString(),
|
|
201
352
|
}, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
|
|
202
353
|
if (tx.code == null || tx.code === 0) {
|
|
203
354
|
// After succeeding to send token, refresh the balance.
|
|
@@ -228,7 +379,7 @@ class CosmosAccount {
|
|
|
228
379
|
let dec = new unit_1.Dec(amount);
|
|
229
380
|
dec = dec.mulTruncate(unit_1.DecUtils.getPrecisionDec(currency.coinDecimals));
|
|
230
381
|
const msg = {
|
|
231
|
-
type: this.
|
|
382
|
+
type: this.msgOpts.delegate.type,
|
|
232
383
|
value: {
|
|
233
384
|
delegator_address: this.base.bech32Address,
|
|
234
385
|
validator_address: validatorAddress,
|
|
@@ -238,23 +389,21 @@ class CosmosAccount {
|
|
|
238
389
|
},
|
|
239
390
|
},
|
|
240
391
|
};
|
|
241
|
-
yield this.
|
|
392
|
+
yield this.sendMsgs("delegate", {
|
|
242
393
|
aminoMsgs: [msg],
|
|
243
|
-
protoMsgs:
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
]
|
|
254
|
-
: undefined,
|
|
394
|
+
protoMsgs: [
|
|
395
|
+
{
|
|
396
|
+
type_url: "/cosmos.staking.v1beta1.MsgDelegate",
|
|
397
|
+
value: cosmos_1.cosmos.staking.v1beta1.MsgDelegate.encode({
|
|
398
|
+
delegatorAddress: msg.value.delegator_address,
|
|
399
|
+
validatorAddress: msg.value.validator_address,
|
|
400
|
+
amount: msg.value.amount,
|
|
401
|
+
}).finish(),
|
|
402
|
+
},
|
|
403
|
+
],
|
|
255
404
|
}, memo, {
|
|
256
405
|
amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
|
|
257
|
-
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.
|
|
406
|
+
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.delegate.gas.toString(),
|
|
258
407
|
}, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
|
|
259
408
|
if (tx.code == null || tx.code === 0) {
|
|
260
409
|
// After succeeding to delegate, refresh the validators and delegations, rewards.
|
|
@@ -286,7 +435,7 @@ class CosmosAccount {
|
|
|
286
435
|
let dec = new unit_1.Dec(amount);
|
|
287
436
|
dec = dec.mulTruncate(unit_1.DecUtils.getPrecisionDec(currency.coinDecimals));
|
|
288
437
|
const msg = {
|
|
289
|
-
type: this.
|
|
438
|
+
type: this.msgOpts.undelegate.type,
|
|
290
439
|
value: {
|
|
291
440
|
delegator_address: this.base.bech32Address,
|
|
292
441
|
validator_address: validatorAddress,
|
|
@@ -296,7 +445,7 @@ class CosmosAccount {
|
|
|
296
445
|
},
|
|
297
446
|
},
|
|
298
447
|
};
|
|
299
|
-
yield this.
|
|
448
|
+
yield this.sendMsgs("undelegate", {
|
|
300
449
|
aminoMsgs: [msg],
|
|
301
450
|
protoMsgs: [
|
|
302
451
|
{
|
|
@@ -310,7 +459,7 @@ class CosmosAccount {
|
|
|
310
459
|
],
|
|
311
460
|
}, memo, {
|
|
312
461
|
amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
|
|
313
|
-
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.
|
|
462
|
+
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.undelegate.gas.toString(),
|
|
314
463
|
}, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
|
|
315
464
|
if (tx.code == null || tx.code === 0) {
|
|
316
465
|
// After succeeding to unbond, refresh the validators and delegations, unbonding delegations, rewards.
|
|
@@ -346,7 +495,7 @@ class CosmosAccount {
|
|
|
346
495
|
let dec = new unit_1.Dec(amount);
|
|
347
496
|
dec = dec.mulTruncate(unit_1.DecUtils.getPrecisionDec(currency.coinDecimals));
|
|
348
497
|
const msg = {
|
|
349
|
-
type: this.
|
|
498
|
+
type: this.msgOpts.redelegate.type,
|
|
350
499
|
value: {
|
|
351
500
|
delegator_address: this.base.bech32Address,
|
|
352
501
|
validator_src_address: srcValidatorAddress,
|
|
@@ -357,24 +506,22 @@ class CosmosAccount {
|
|
|
357
506
|
},
|
|
358
507
|
},
|
|
359
508
|
};
|
|
360
|
-
yield this.
|
|
509
|
+
yield this.sendMsgs("redelegate", {
|
|
361
510
|
aminoMsgs: [msg],
|
|
362
|
-
protoMsgs:
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
]
|
|
374
|
-
: undefined,
|
|
511
|
+
protoMsgs: [
|
|
512
|
+
{
|
|
513
|
+
type_url: "/cosmos.staking.v1beta1.MsgBeginRedelegate",
|
|
514
|
+
value: cosmos_1.cosmos.staking.v1beta1.MsgBeginRedelegate.encode({
|
|
515
|
+
delegatorAddress: msg.value.delegator_address,
|
|
516
|
+
validatorSrcAddress: msg.value.validator_src_address,
|
|
517
|
+
validatorDstAddress: msg.value.validator_dst_address,
|
|
518
|
+
amount: msg.value.amount,
|
|
519
|
+
}).finish(),
|
|
520
|
+
},
|
|
521
|
+
],
|
|
375
522
|
}, memo, {
|
|
376
523
|
amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
|
|
377
|
-
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.
|
|
524
|
+
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.redelegate.gas.toString(),
|
|
378
525
|
}, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
|
|
379
526
|
if (tx.code == null || tx.code === 0) {
|
|
380
527
|
// After succeeding to redelegate, refresh the validators and delegations, rewards.
|
|
@@ -396,29 +543,27 @@ class CosmosAccount {
|
|
|
396
543
|
return __awaiter(this, void 0, void 0, function* () {
|
|
397
544
|
const msgs = validatorAddresses.map((validatorAddress) => {
|
|
398
545
|
return {
|
|
399
|
-
type: this.
|
|
546
|
+
type: this.msgOpts.withdrawRewards.type,
|
|
400
547
|
value: {
|
|
401
548
|
delegator_address: this.base.bech32Address,
|
|
402
549
|
validator_address: validatorAddress,
|
|
403
550
|
},
|
|
404
551
|
};
|
|
405
552
|
});
|
|
406
|
-
yield this.
|
|
553
|
+
yield this.sendMsgs("withdrawRewards", {
|
|
407
554
|
aminoMsgs: msgs,
|
|
408
|
-
protoMsgs:
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
})
|
|
418
|
-
: undefined,
|
|
555
|
+
protoMsgs: msgs.map((msg) => {
|
|
556
|
+
return {
|
|
557
|
+
type_url: "/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward",
|
|
558
|
+
value: cosmos_1.cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward.encode({
|
|
559
|
+
delegatorAddress: msg.value.delegator_address,
|
|
560
|
+
validatorAddress: msg.value.validator_address,
|
|
561
|
+
}).finish(),
|
|
562
|
+
};
|
|
563
|
+
}),
|
|
419
564
|
}, memo, {
|
|
420
565
|
amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
|
|
421
|
-
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : (this.
|
|
566
|
+
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : (this.msgOpts.withdrawRewards.gas * validatorAddresses.length).toString(),
|
|
422
567
|
}, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
|
|
423
568
|
if (tx.code == null || tx.code === 0) {
|
|
424
569
|
// After succeeding to withdraw rewards, refresh rewards.
|
|
@@ -451,50 +596,47 @@ class CosmosAccount {
|
|
|
451
596
|
}
|
|
452
597
|
})();
|
|
453
598
|
const msg = {
|
|
454
|
-
type: this.
|
|
599
|
+
type: this.msgOpts.govVote.type,
|
|
455
600
|
value: {
|
|
456
601
|
option: voteOption,
|
|
457
602
|
proposal_id: proposalId,
|
|
458
603
|
voter: this.base.bech32Address,
|
|
459
604
|
},
|
|
460
605
|
};
|
|
461
|
-
yield this.
|
|
606
|
+
yield this.sendMsgs("govVote", {
|
|
462
607
|
aminoMsgs: [msg],
|
|
463
|
-
protoMsgs:
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
},
|
|
493
|
-
]
|
|
494
|
-
: undefined,
|
|
608
|
+
protoMsgs: [
|
|
609
|
+
{
|
|
610
|
+
type_url: "/cosmos.gov.v1beta1.MsgVote",
|
|
611
|
+
value: cosmos_1.cosmos.gov.v1beta1.MsgVote.encode({
|
|
612
|
+
proposalId: long_1.default.fromString(msg.value.proposal_id),
|
|
613
|
+
voter: msg.value.voter,
|
|
614
|
+
option: (() => {
|
|
615
|
+
switch (msg.value.option) {
|
|
616
|
+
case "Yes":
|
|
617
|
+
case 1:
|
|
618
|
+
return cosmos_1.cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_YES;
|
|
619
|
+
case "Abstain":
|
|
620
|
+
case 2:
|
|
621
|
+
return cosmos_1.cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_ABSTAIN;
|
|
622
|
+
case "No":
|
|
623
|
+
case 3:
|
|
624
|
+
return cosmos_1.cosmos.gov.v1beta1.VoteOption.VOTE_OPTION_NO;
|
|
625
|
+
case "NoWithVeto":
|
|
626
|
+
case 4:
|
|
627
|
+
return cosmos_1.cosmos.gov.v1beta1.VoteOption
|
|
628
|
+
.VOTE_OPTION_NO_WITH_VETO;
|
|
629
|
+
default:
|
|
630
|
+
return cosmos_1.cosmos.gov.v1beta1.VoteOption
|
|
631
|
+
.VOTE_OPTION_UNSPECIFIED;
|
|
632
|
+
}
|
|
633
|
+
})(),
|
|
634
|
+
}).finish(),
|
|
635
|
+
},
|
|
636
|
+
],
|
|
495
637
|
}, memo, {
|
|
496
638
|
amount: (_a = stdFee.amount) !== null && _a !== void 0 ? _a : [],
|
|
497
|
-
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.
|
|
639
|
+
gas: (_b = stdFee.gas) !== null && _b !== void 0 ? _b : this.msgOpts.govVote.gas.toString(),
|
|
498
640
|
}, signOptions, this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
|
|
499
641
|
if (tx.code == null || tx.code === 0) {
|
|
500
642
|
// After succeeding to vote, refresh the proposal.
|
|
@@ -531,11 +673,6 @@ class CosmosAccount {
|
|
|
531
673
|
get queries() {
|
|
532
674
|
return this.queriesStore.get(this.chainId);
|
|
533
675
|
}
|
|
534
|
-
hasNoLegacyStdFeature() {
|
|
535
|
-
const chainInfo = this.chainGetter.getChain(this.chainId);
|
|
536
|
-
return (chainInfo.features != null &&
|
|
537
|
-
chainInfo.features.includes("no-legacy-stdTx"));
|
|
538
|
-
}
|
|
539
676
|
}
|
|
540
|
-
exports.
|
|
677
|
+
exports.CosmosAccountImpl = CosmosAccountImpl;
|
|
541
678
|
//# sourceMappingURL=cosmos.js.map
|