@keplr-wallet/stores 0.9.8 → 0.9.9-rc.0
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/all.d.ts +25 -0
- package/build/account/all.js +27 -0
- package/build/account/all.js.map +1 -0
- package/build/account/base.js +2 -1
- package/build/account/base.js.map +1 -1
- package/build/account/cosmwasm.d.ts +55 -0
- package/build/account/cosmwasm.js +153 -0
- package/build/account/cosmwasm.js.map +1 -0
- package/build/account/index.d.ts +2 -0
- package/build/account/index.js +2 -0
- package/build/account/index.js.map +1 -1
- package/build/query/cosmwasm/contract-query.d.ts +14 -0
- package/build/query/cosmwasm/contract-query.js +57 -0
- package/build/query/cosmwasm/contract-query.js.map +1 -0
- package/build/query/cosmwasm/cw20-balance.d.ts +25 -0
- package/build/query/cosmwasm/cw20-balance.js +78 -0
- package/build/query/cosmwasm/cw20-balance.js.map +1 -0
- package/build/query/cosmwasm/cw20-contract-info.d.ts +17 -0
- package/build/query/cosmwasm/cw20-contract-info.js +43 -0
- package/build/query/cosmwasm/cw20-contract-info.js.map +1 -0
- package/build/query/cosmwasm/index.d.ts +3 -0
- package/build/query/cosmwasm/index.js +29 -0
- package/build/query/cosmwasm/index.js.map +1 -0
- package/build/query/cosmwasm/queries.d.ts +18 -0
- package/build/query/cosmwasm/queries.js +21 -0
- package/build/query/cosmwasm/queries.js.map +1 -0
- package/build/query/cosmwasm/types.d.ts +9 -0
- package/build/query/cosmwasm/types.js +3 -0
- package/build/query/cosmwasm/types.js.map +1 -0
- package/build/query/index.d.ts +1 -0
- package/build/query/index.js +1 -0
- package/build/query/index.js.map +1 -1
- package/build/query/secret-wasm/contract-query.js +3 -3
- package/build/query/secret-wasm/contract-query.js.map +1 -1
- package/package.json +9 -9
- package/src/account/all.ts +86 -0
- package/src/account/base.ts +2 -1
- package/src/account/cosmwasm.ts +249 -0
- package/src/account/index.ts +2 -0
- package/src/query/cosmwasm/contract-query.ts +74 -0
- package/src/query/cosmwasm/cw20-balance.ts +115 -0
- package/src/query/cosmwasm/cw20-contract-info.ts +49 -0
- package/src/query/cosmwasm/index.ts +5 -0
- package/src/query/cosmwasm/queries.ts +50 -0
- package/src/query/cosmwasm/types.ts +10 -0
- package/src/query/index.ts +1 -0
- package/src/query/secret-wasm/contract-query.ts +3 -3
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
+
};
|
|
17
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
+
if (mod && mod.__esModule) return mod;
|
|
19
|
+
var result = {};
|
|
20
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
+
__setModuleDefault(result, mod);
|
|
22
|
+
return result;
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.CosmWasm = void 0;
|
|
26
|
+
__exportStar(require("./cw20-balance"), exports);
|
|
27
|
+
exports.CosmWasm = __importStar(require("./types"));
|
|
28
|
+
__exportStar(require("./queries"), exports);
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/query/cosmwasm/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA+B;AAE/B,oDAAoC;AAEpC,4CAA0B"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { QueriesSetBase } from "../queries";
|
|
2
|
+
import { ChainGetter } from "../../common";
|
|
3
|
+
import { KVStore } from "@keplr-wallet/common";
|
|
4
|
+
import { ObservableQueryCw20ContractInfo } from "./cw20-contract-info";
|
|
5
|
+
import { DeepReadonly } from "utility-types";
|
|
6
|
+
import { QueriesWithCosmosAndSecret } from "../secret-wasm";
|
|
7
|
+
import { Keplr } from "@keplr-wallet/types";
|
|
8
|
+
export interface HasCosmwasmQueries {
|
|
9
|
+
cosmwasm: CosmwasmQueries;
|
|
10
|
+
}
|
|
11
|
+
export declare class QueriesWithCosmosAndSecretAndCosmwasm extends QueriesWithCosmosAndSecret implements HasCosmwasmQueries {
|
|
12
|
+
cosmwasm: CosmwasmQueries;
|
|
13
|
+
constructor(kvStore: KVStore, chainId: string, chainGetter: ChainGetter, apiGetter: () => Promise<Keplr | undefined>);
|
|
14
|
+
}
|
|
15
|
+
export declare class CosmwasmQueries {
|
|
16
|
+
readonly querycw20ContractInfo: DeepReadonly<ObservableQueryCw20ContractInfo>;
|
|
17
|
+
constructor(base: QueriesSetBase, kvStore: KVStore, chainId: string, chainGetter: ChainGetter);
|
|
18
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CosmwasmQueries = exports.QueriesWithCosmosAndSecretAndCosmwasm = void 0;
|
|
4
|
+
const cw20_contract_info_1 = require("./cw20-contract-info");
|
|
5
|
+
const cw20_balance_1 = require("./cw20-balance");
|
|
6
|
+
const secret_wasm_1 = require("../secret-wasm");
|
|
7
|
+
class QueriesWithCosmosAndSecretAndCosmwasm extends secret_wasm_1.QueriesWithCosmosAndSecret {
|
|
8
|
+
constructor(kvStore, chainId, chainGetter, apiGetter) {
|
|
9
|
+
super(kvStore, chainId, chainGetter, apiGetter);
|
|
10
|
+
this.cosmwasm = new CosmwasmQueries(this, kvStore, chainId, chainGetter);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.QueriesWithCosmosAndSecretAndCosmwasm = QueriesWithCosmosAndSecretAndCosmwasm;
|
|
14
|
+
class CosmwasmQueries {
|
|
15
|
+
constructor(base, kvStore, chainId, chainGetter) {
|
|
16
|
+
base.queryBalances.addBalanceRegistry(new cw20_balance_1.ObservableQueryCw20BalanceRegistry(kvStore));
|
|
17
|
+
this.querycw20ContractInfo = new cw20_contract_info_1.ObservableQueryCw20ContractInfo(kvStore, chainId, chainGetter);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.CosmwasmQueries = CosmwasmQueries;
|
|
21
|
+
//# sourceMappingURL=queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/query/cosmwasm/queries.ts"],"names":[],"mappings":";;;AAGA,6DAAuE;AAEvE,iDAAoE;AACpE,gDAA4D;AAO5D,MAAa,qCACX,SAAQ,wCAA0B;IAIlC,YACE,OAAgB,EAChB,OAAe,EACf,WAAwB,EACxB,SAA2C;QAE3C,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;QAEhD,IAAI,CAAC,QAAQ,GAAG,IAAI,eAAe,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;IAC3E,CAAC;CACF;AAfD,sFAeC;AAED,MAAa,eAAe;IAG1B,YACE,IAAoB,EACpB,OAAgB,EAChB,OAAe,EACf,WAAwB;QAExB,IAAI,CAAC,aAAa,CAAC,kBAAkB,CACnC,IAAI,iDAAkC,CAAC,OAAO,CAAC,CAChD,CAAC;QAEF,IAAI,CAAC,qBAAqB,GAAG,IAAI,oDAA+B,CAC9D,OAAO,EACP,OAAO,EACP,WAAW,CACZ,CAAC;IACJ,CAAC;CACF;AAnBD,0CAmBC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/query/cosmwasm/types.ts"],"names":[],"mappings":""}
|
package/build/query/index.d.ts
CHANGED
package/build/query/index.js
CHANGED
|
@@ -14,5 +14,6 @@ __exportStar(require("./queries"), exports);
|
|
|
14
14
|
__exportStar(require("./chain-query"), exports);
|
|
15
15
|
__exportStar(require("./balances"), exports);
|
|
16
16
|
__exportStar(require("./cosmos"), exports);
|
|
17
|
+
__exportStar(require("./cosmwasm"), exports);
|
|
17
18
|
__exportStar(require("./secret-wasm"), exports);
|
|
18
19
|
//# sourceMappingURL=index.js.map
|
package/build/query/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/query/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,gDAA8B;AAC9B,6CAA2B;AAE3B,2CAAyB;AACzB,gDAA8B"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/query/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,gDAA8B;AAC9B,6CAA2B;AAE3B,2CAAyB;AACzB,6CAA2B;AAC3B,gDAA8B"}
|
|
@@ -93,10 +93,10 @@ class ObservableSecretContractChainQuery extends chain_query_1.ObservableChainQu
|
|
|
93
93
|
catch (e) {
|
|
94
94
|
if (!axios_1.default.isCancel(e) && ((_b = (_a = e.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.error)) {
|
|
95
95
|
const encryptedError = e.response.data.error;
|
|
96
|
-
const errorMessageRgx = /
|
|
96
|
+
const errorMessageRgx = /rpc error: code = (.+) = encrypted: (.+): (.+)/g;
|
|
97
97
|
const rgxMatches = errorMessageRgx.exec(encryptedError);
|
|
98
|
-
if (rgxMatches != null && rgxMatches.length ===
|
|
99
|
-
const errorCipherB64 = rgxMatches[
|
|
98
|
+
if (rgxMatches != null && rgxMatches.length === 4) {
|
|
99
|
+
const errorCipherB64 = rgxMatches[2];
|
|
100
100
|
const errorCipherBz = buffer_1.Buffer.from(errorCipherB64, "base64");
|
|
101
101
|
if (this.keplr && this.nonce) {
|
|
102
102
|
const decrypted = yield this.keplr
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contract-query.js","sourceRoot":"","sources":["../../../src/query/secret-wasm/contract-query.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,gDAAsD;AACtD,iDAA4D;AAG5D,+BAA2E;AAE3E,kDAA2C;AAG3C,oCAAiC;AAEjC,MAAa,kCAEX,SAAQ,kCAAuB;IAS/B,YACE,OAAgB,EAChB,OAAe,EACf,WAAwB,EACL,SAA2C,EAC3C,eAAuB;IAC1C,wDAAwD;IAC9C,GAAW,EACF,2BAAkE;QAErF,kFAAkF;QAClF,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC,CAAC;QAPtB,cAAS,GAAT,SAAS,CAAkC;QAC3C,oBAAe,GAAf,eAAe,CAAQ;QAEhC,QAAG,GAAH,GAAG,CAAQ;QACF,gCAA2B,GAA3B,2BAA2B,CAAuC;QAf7E,UAAK,GAAW,SAAS,CAAC;QAK1B,eAAU,GAAY,KAAK,CAAC;QAcpC,qBAAc,CAAC,IAAI,CAAC,CAAC;QAErB,4BAA4B;QAC5B,IAAI,CAAC,SAAS,EAAE,CAAC;QAEjB,MAAM,QAAQ,GAAG,cAAO,CAAC,GAAG,EAAE;YAC5B,gFAAgF;YAChF,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,gBAAgB,EAAE;gBACvC,IAA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AM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YAChC,OAAO;gBACL,IAAI,EAAE,GAAQ;gBACd,MAAM,EAAE,QAAQ,CAAC,MAAM;gBACvB,MAAM,EAAE,KAAK;gBACb,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC;;KACH;IAED,iFAAiF;IACjF,gDAAgD;IACtC,WAAW;QACnB,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,IAC1B,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OACzB,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;YACtB,GAAG,EAAE,kBAAkB,IAAI,CAAC,eAAe,UAAU,IAAI,CAAC,SAAS,CACjE,IAAI,CAAC,GAAG,CACT,gBAAgB;SAClB,CAAC,EAAE,CAAC;IACP,CAAC;IAGD,IAAI,gBAAgB;QAClB,MAAM,aAAa,GAAG,IAAI,CAAC,2BAA2B,CAAC,gBAAgB,CACrE,IAAI,CAAC,eAAe,CACrB,CAAC;QAEF,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE;YAC3B,OAAO,SAAS,CAAC;SAClB;QAED,qGAAqG;QACrG,+BAA+B;QAC/B,OAAO,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC;IAC5C,CAAC;CACF;AAzLC;IADC,iBAAU,CAAC,GAAG;iEACqB;AAKpC;IADC,iBAAU;sEAC2B;AAwDtC;IADC,WAAI;mEAGJ;AAGD;IADC,WAAI;8DAqBJ;AAsFD;IADC,eAAQ;0EAaR;AA5LH,gFA6LC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keplr-wallet/stores",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.9-rc.0",
|
|
4
4
|
"main": "build/index.js",
|
|
5
5
|
"author": "chainapsis",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -17,19 +17,19 @@
|
|
|
17
17
|
"lint-fix": "eslint --fix \"src/**/*\" && prettier --write \"src/**/*\""
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
|
-
"@keplr-wallet/provider-mock": "^0.9.
|
|
20
|
+
"@keplr-wallet/provider-mock": "^0.9.9-rc.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@cosmjs/encoding": "^0.24.0-alpha.25",
|
|
24
24
|
"@cosmjs/launchpad": "^0.24.0-alpha.25",
|
|
25
25
|
"@cosmjs/tendermint-rpc": "^0.24.1",
|
|
26
|
-
"@keplr-wallet/background": "^0.9.
|
|
27
|
-
"@keplr-wallet/common": "^0.9.
|
|
28
|
-
"@keplr-wallet/cosmos": "^0.9.
|
|
29
|
-
"@keplr-wallet/crypto": "^0.9.
|
|
26
|
+
"@keplr-wallet/background": "^0.9.9-rc.0",
|
|
27
|
+
"@keplr-wallet/common": "^0.9.9-rc.0",
|
|
28
|
+
"@keplr-wallet/cosmos": "^0.9.9-rc.0",
|
|
29
|
+
"@keplr-wallet/crypto": "^0.9.9-rc.0",
|
|
30
30
|
"@keplr-wallet/router": "^0.9.6",
|
|
31
|
-
"@keplr-wallet/types": "^0.9.
|
|
32
|
-
"@keplr-wallet/unit": "^0.9.
|
|
31
|
+
"@keplr-wallet/types": "^0.9.9-rc.0",
|
|
32
|
+
"@keplr-wallet/unit": "^0.9.9-rc.0",
|
|
33
33
|
"axios": "^0.21.0",
|
|
34
34
|
"buffer": "^6.0.3",
|
|
35
35
|
"deepmerge": "^4.2.2",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"p-queue": "^6.6.2",
|
|
41
41
|
"utility-types": "^3.10.0"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "2aac30ca0637e5f1f4fb4699565ab5b1cc6bdb70"
|
|
44
44
|
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { AccountSetBase, AccountSetOpts } from "./base";
|
|
2
|
+
import {
|
|
3
|
+
AccountWithCosmos,
|
|
4
|
+
CosmosAccount,
|
|
5
|
+
CosmosMsgOpts,
|
|
6
|
+
HasCosmosAccount,
|
|
7
|
+
} from "./cosmos";
|
|
8
|
+
import {
|
|
9
|
+
AccountWithSecret,
|
|
10
|
+
HasSecretAccount,
|
|
11
|
+
SecretAccount,
|
|
12
|
+
SecretMsgOpts,
|
|
13
|
+
} from "./secret";
|
|
14
|
+
import {
|
|
15
|
+
HasCosmosQueries,
|
|
16
|
+
HasCosmwasmQueries,
|
|
17
|
+
HasSecretQueries,
|
|
18
|
+
QueriesSetBase,
|
|
19
|
+
QueriesStore,
|
|
20
|
+
} from "../query";
|
|
21
|
+
import deepmerge from "deepmerge";
|
|
22
|
+
import { DeepReadonly } from "utility-types";
|
|
23
|
+
import { ChainGetter } from "../common";
|
|
24
|
+
import {
|
|
25
|
+
AccountWithCosmwasm,
|
|
26
|
+
CosmwasmAccount,
|
|
27
|
+
CosmwasmMsgOpts,
|
|
28
|
+
HasCosmwasmAccount,
|
|
29
|
+
} from "./cosmwasm";
|
|
30
|
+
|
|
31
|
+
export class AccountWithAll
|
|
32
|
+
extends AccountSetBase<
|
|
33
|
+
CosmosMsgOpts & SecretMsgOpts & CosmwasmMsgOpts,
|
|
34
|
+
HasCosmosQueries & HasSecretQueries & HasCosmwasmQueries
|
|
35
|
+
>
|
|
36
|
+
implements HasCosmosAccount, HasSecretAccount, HasCosmwasmAccount {
|
|
37
|
+
static readonly defaultMsgOpts: CosmosMsgOpts &
|
|
38
|
+
SecretMsgOpts &
|
|
39
|
+
CosmwasmMsgOpts = deepmerge(
|
|
40
|
+
AccountWithCosmos.defaultMsgOpts,
|
|
41
|
+
deepmerge(
|
|
42
|
+
AccountWithSecret.defaultMsgOpts,
|
|
43
|
+
AccountWithCosmwasm.defaultMsgOpts
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
public readonly cosmos: DeepReadonly<CosmosAccount>;
|
|
48
|
+
public readonly secret: DeepReadonly<SecretAccount>;
|
|
49
|
+
public readonly cosmwasm: DeepReadonly<CosmwasmAccount>;
|
|
50
|
+
|
|
51
|
+
constructor(
|
|
52
|
+
protected readonly eventListener: {
|
|
53
|
+
addEventListener: (type: string, fn: () => unknown) => void;
|
|
54
|
+
removeEventListener: (type: string, fn: () => unknown) => void;
|
|
55
|
+
},
|
|
56
|
+
protected readonly chainGetter: ChainGetter,
|
|
57
|
+
protected readonly chainId: string,
|
|
58
|
+
protected readonly queriesStore: QueriesStore<
|
|
59
|
+
QueriesSetBase & HasCosmosQueries & HasSecretQueries & HasCosmwasmQueries
|
|
60
|
+
>,
|
|
61
|
+
protected readonly opts: AccountSetOpts<
|
|
62
|
+
CosmosMsgOpts & SecretMsgOpts & CosmwasmMsgOpts
|
|
63
|
+
>
|
|
64
|
+
) {
|
|
65
|
+
super(eventListener, chainGetter, chainId, queriesStore, opts);
|
|
66
|
+
|
|
67
|
+
this.cosmos = new CosmosAccount(
|
|
68
|
+
this as AccountSetBase<CosmosMsgOpts, HasCosmosQueries>,
|
|
69
|
+
chainGetter,
|
|
70
|
+
chainId,
|
|
71
|
+
queriesStore
|
|
72
|
+
);
|
|
73
|
+
this.secret = new SecretAccount(
|
|
74
|
+
this as AccountSetBase<SecretMsgOpts, HasSecretQueries>,
|
|
75
|
+
chainGetter,
|
|
76
|
+
chainId,
|
|
77
|
+
queriesStore
|
|
78
|
+
);
|
|
79
|
+
this.cosmwasm = new CosmwasmAccount(
|
|
80
|
+
this as AccountSetBase<CosmwasmMsgOpts, HasCosmwasmQueries>,
|
|
81
|
+
chainGetter,
|
|
82
|
+
chainId,
|
|
83
|
+
queriesStore
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
}
|
package/src/account/base.ts
CHANGED
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { AccountSetBase, AccountSetOpts, MsgOpt } from "./base";
|
|
2
|
+
import { HasCosmwasmQueries, QueriesSetBase, QueriesStore } from "../query";
|
|
3
|
+
import { ChainGetter, CoinPrimitive } from "../common";
|
|
4
|
+
import { StdFee } from "@cosmjs/launchpad";
|
|
5
|
+
import { DenomHelper } from "@keplr-wallet/common";
|
|
6
|
+
import { Dec, DecUtils } from "@keplr-wallet/unit";
|
|
7
|
+
import { AppCurrency, KeplrSignOptions } from "@keplr-wallet/types";
|
|
8
|
+
import { DeepReadonly, Optional } from "utility-types";
|
|
9
|
+
import { cosmwasm } from "@keplr-wallet/cosmos";
|
|
10
|
+
import { Buffer } from "buffer/";
|
|
11
|
+
|
|
12
|
+
export interface HasCosmwasmAccount {
|
|
13
|
+
cosmwasm: DeepReadonly<CosmwasmAccount>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface CosmwasmMsgOpts {
|
|
17
|
+
readonly send: {
|
|
18
|
+
readonly cw20: Pick<MsgOpt, "gas">;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
readonly executeWasm: Pick<MsgOpt, "type">;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class AccountWithCosmwasm
|
|
25
|
+
extends AccountSetBase<CosmwasmMsgOpts, HasCosmwasmQueries>
|
|
26
|
+
implements HasCosmwasmAccount {
|
|
27
|
+
public readonly cosmwasm: DeepReadonly<CosmwasmAccount>;
|
|
28
|
+
|
|
29
|
+
static readonly defaultMsgOpts: CosmwasmMsgOpts = {
|
|
30
|
+
send: {
|
|
31
|
+
cw20: {
|
|
32
|
+
gas: 150000,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
executeWasm: {
|
|
37
|
+
type: "wasm/MsgExecuteContract",
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
constructor(
|
|
42
|
+
protected readonly eventListener: {
|
|
43
|
+
addEventListener: (type: string, fn: () => unknown) => void;
|
|
44
|
+
removeEventListener: (type: string, fn: () => unknown) => void;
|
|
45
|
+
},
|
|
46
|
+
protected readonly chainGetter: ChainGetter,
|
|
47
|
+
protected readonly chainId: string,
|
|
48
|
+
protected readonly queriesStore: QueriesStore<
|
|
49
|
+
QueriesSetBase & HasCosmwasmQueries
|
|
50
|
+
>,
|
|
51
|
+
protected readonly opts: AccountSetOpts<CosmwasmMsgOpts>
|
|
52
|
+
) {
|
|
53
|
+
super(eventListener, chainGetter, chainId, queriesStore, opts);
|
|
54
|
+
|
|
55
|
+
this.cosmwasm = new CosmwasmAccount(
|
|
56
|
+
this,
|
|
57
|
+
chainGetter,
|
|
58
|
+
chainId,
|
|
59
|
+
queriesStore
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export class CosmwasmAccount {
|
|
65
|
+
constructor(
|
|
66
|
+
protected readonly base: AccountSetBase<
|
|
67
|
+
CosmwasmMsgOpts,
|
|
68
|
+
HasCosmwasmQueries
|
|
69
|
+
>,
|
|
70
|
+
protected readonly chainGetter: ChainGetter,
|
|
71
|
+
protected readonly chainId: string,
|
|
72
|
+
protected readonly queriesStore: QueriesStore<
|
|
73
|
+
QueriesSetBase & HasCosmwasmQueries
|
|
74
|
+
>
|
|
75
|
+
) {
|
|
76
|
+
this.base.registerSendTokenFn(this.processSendToken.bind(this));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
protected async processSendToken(
|
|
80
|
+
amount: string,
|
|
81
|
+
currency: AppCurrency,
|
|
82
|
+
recipient: string,
|
|
83
|
+
memo: string,
|
|
84
|
+
stdFee: Partial<StdFee>,
|
|
85
|
+
signOptions?: KeplrSignOptions,
|
|
86
|
+
onTxEvents?:
|
|
87
|
+
| ((tx: any) => void)
|
|
88
|
+
| {
|
|
89
|
+
onBroadcasted?: (txHash: Uint8Array) => void;
|
|
90
|
+
onFulfill?: (tx: any) => void;
|
|
91
|
+
}
|
|
92
|
+
): Promise<boolean> {
|
|
93
|
+
const denomHelper = new DenomHelper(currency.coinMinimalDenom);
|
|
94
|
+
|
|
95
|
+
switch (denomHelper.type) {
|
|
96
|
+
case "cw20":
|
|
97
|
+
const actualAmount = (() => {
|
|
98
|
+
let dec = new Dec(amount);
|
|
99
|
+
dec = dec.mul(DecUtils.getPrecisionDec(currency.coinDecimals));
|
|
100
|
+
return dec.truncate().toString();
|
|
101
|
+
})();
|
|
102
|
+
|
|
103
|
+
if (!("type" in currency) || currency.type !== "cw20") {
|
|
104
|
+
throw new Error("Currency is not cw20");
|
|
105
|
+
}
|
|
106
|
+
await this.sendExecuteContractMsg(
|
|
107
|
+
"send",
|
|
108
|
+
currency.contractAddress,
|
|
109
|
+
{
|
|
110
|
+
transfer: {
|
|
111
|
+
recipient: recipient,
|
|
112
|
+
amount: actualAmount,
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
[],
|
|
116
|
+
memo,
|
|
117
|
+
{
|
|
118
|
+
amount: stdFee.amount ?? [],
|
|
119
|
+
gas: stdFee.gas ?? this.base.msgOpts.send.cw20.gas.toString(),
|
|
120
|
+
},
|
|
121
|
+
signOptions,
|
|
122
|
+
this.txEventsWithPreOnFulfill(onTxEvents, (tx) => {
|
|
123
|
+
if (tx.code == null || tx.code === 0) {
|
|
124
|
+
// After succeeding to send token, refresh the balance.
|
|
125
|
+
const queryBalance = this.queries.queryBalances
|
|
126
|
+
.getQueryBech32Address(this.base.bech32Address)
|
|
127
|
+
.balances.find((bal) => {
|
|
128
|
+
return (
|
|
129
|
+
bal.currency.coinMinimalDenom === currency.coinMinimalDenom
|
|
130
|
+
);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
if (queryBalance) {
|
|
134
|
+
queryBalance.fetch();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async sendExecuteContractMsg(
|
|
146
|
+
// This arg can be used to override the type of sending tx if needed.
|
|
147
|
+
type: keyof CosmwasmMsgOpts | "unknown" = "executeWasm",
|
|
148
|
+
contractAddress: string,
|
|
149
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
150
|
+
obj: object,
|
|
151
|
+
funds: CoinPrimitive[],
|
|
152
|
+
memo: string = "",
|
|
153
|
+
stdFee: Optional<StdFee, "amount">,
|
|
154
|
+
signOptions?: KeplrSignOptions,
|
|
155
|
+
onTxEvents?:
|
|
156
|
+
| ((tx: any) => void)
|
|
157
|
+
| {
|
|
158
|
+
onBroadcasted?: (txHash: Uint8Array) => void;
|
|
159
|
+
onFulfill?: (tx: any) => void;
|
|
160
|
+
}
|
|
161
|
+
): Promise<void> {
|
|
162
|
+
const msg = {
|
|
163
|
+
type: this.base.msgOpts.executeWasm.type,
|
|
164
|
+
value: {
|
|
165
|
+
sender: this.base.bech32Address,
|
|
166
|
+
contract: contractAddress,
|
|
167
|
+
msg: obj,
|
|
168
|
+
funds,
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
await this.base.sendMsgs(
|
|
173
|
+
type,
|
|
174
|
+
{
|
|
175
|
+
aminoMsgs: [msg],
|
|
176
|
+
protoMsgs: this.hasNoLegacyStdFeature()
|
|
177
|
+
? [
|
|
178
|
+
{
|
|
179
|
+
type_url: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
180
|
+
value: cosmwasm.wasm.v1.MsgExecuteContract.encode({
|
|
181
|
+
sender: msg.value.sender,
|
|
182
|
+
contract: msg.value.contract,
|
|
183
|
+
msg: Buffer.from(JSON.stringify(msg.value.msg)),
|
|
184
|
+
funds: msg.value.funds,
|
|
185
|
+
}).finish(),
|
|
186
|
+
},
|
|
187
|
+
]
|
|
188
|
+
: undefined,
|
|
189
|
+
},
|
|
190
|
+
memo,
|
|
191
|
+
{
|
|
192
|
+
amount: stdFee.amount ?? [],
|
|
193
|
+
gas: stdFee.gas,
|
|
194
|
+
},
|
|
195
|
+
signOptions,
|
|
196
|
+
this.txEventsWithPreOnFulfill(onTxEvents)
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
protected txEventsWithPreOnFulfill(
|
|
201
|
+
onTxEvents:
|
|
202
|
+
| ((tx: any) => void)
|
|
203
|
+
| {
|
|
204
|
+
onBroadcasted?: (txHash: Uint8Array) => void;
|
|
205
|
+
onFulfill?: (tx: any) => void;
|
|
206
|
+
}
|
|
207
|
+
| undefined,
|
|
208
|
+
preOnFulfill?: (tx: any) => void
|
|
209
|
+
):
|
|
210
|
+
| {
|
|
211
|
+
onBroadcasted?: (txHash: Uint8Array) => void;
|
|
212
|
+
onFulfill?: (tx: any) => void;
|
|
213
|
+
}
|
|
214
|
+
| undefined {
|
|
215
|
+
if (!onTxEvents) {
|
|
216
|
+
return;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const onBroadcasted =
|
|
220
|
+
typeof onTxEvents === "function" ? undefined : onTxEvents.onBroadcasted;
|
|
221
|
+
const onFulfill =
|
|
222
|
+
typeof onTxEvents === "function" ? onTxEvents : onTxEvents.onFulfill;
|
|
223
|
+
|
|
224
|
+
return {
|
|
225
|
+
onBroadcasted,
|
|
226
|
+
onFulfill: onFulfill
|
|
227
|
+
? (tx: any) => {
|
|
228
|
+
if (preOnFulfill) {
|
|
229
|
+
preOnFulfill(tx);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
onFulfill(tx);
|
|
233
|
+
}
|
|
234
|
+
: undefined,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
protected get queries(): DeepReadonly<QueriesSetBase & HasCosmwasmQueries> {
|
|
239
|
+
return this.queriesStore.get(this.chainId);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
protected hasNoLegacyStdFeature(): boolean {
|
|
243
|
+
const chainInfo = this.chainGetter.getChain(this.chainId);
|
|
244
|
+
return (
|
|
245
|
+
chainInfo.features != null &&
|
|
246
|
+
chainInfo.features.includes("no-legacy-stdTx")
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
}
|
package/src/account/index.ts
CHANGED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ObservableChainQuery } from "../chain-query";
|
|
2
|
+
import { KVStore } from "@keplr-wallet/common";
|
|
3
|
+
import { ChainGetter } from "../../common";
|
|
4
|
+
import { CancelToken } from "axios";
|
|
5
|
+
import { QueryResponse } from "../../common";
|
|
6
|
+
|
|
7
|
+
import { Buffer } from "buffer/";
|
|
8
|
+
|
|
9
|
+
export class ObservableCosmwasmContractChainQuery<
|
|
10
|
+
T
|
|
11
|
+
> extends ObservableChainQuery<T> {
|
|
12
|
+
constructor(
|
|
13
|
+
kvStore: KVStore,
|
|
14
|
+
chainId: string,
|
|
15
|
+
chainGetter: ChainGetter,
|
|
16
|
+
protected readonly contractAddress: string,
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
18
|
+
protected obj: object
|
|
19
|
+
) {
|
|
20
|
+
super(
|
|
21
|
+
kvStore,
|
|
22
|
+
chainId,
|
|
23
|
+
chainGetter,
|
|
24
|
+
ObservableCosmwasmContractChainQuery.getUrlFromObj(contractAddress, obj)
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
29
|
+
protected static getUrlFromObj(contractAddress: string, obj: object): string {
|
|
30
|
+
const msg = JSON.stringify(obj);
|
|
31
|
+
const query = Buffer.from(msg).toString("base64");
|
|
32
|
+
|
|
33
|
+
return `/wasm/v1/contract/${contractAddress}/smart/${query}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
37
|
+
protected setObj(obj: object) {
|
|
38
|
+
this.obj = obj;
|
|
39
|
+
|
|
40
|
+
this.setUrl(
|
|
41
|
+
ObservableCosmwasmContractChainQuery.getUrlFromObj(
|
|
42
|
+
this.contractAddress,
|
|
43
|
+
this.obj
|
|
44
|
+
)
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
protected canFetch(): boolean {
|
|
49
|
+
return this.contractAddress.length !== 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
protected async fetchResponse(
|
|
53
|
+
cancelToken: CancelToken
|
|
54
|
+
): Promise<QueryResponse<T>> {
|
|
55
|
+
const response = await super.fetchResponse(cancelToken);
|
|
56
|
+
|
|
57
|
+
const wasmResult = (response.data as unknown) as
|
|
58
|
+
| {
|
|
59
|
+
data: any;
|
|
60
|
+
}
|
|
61
|
+
| undefined;
|
|
62
|
+
|
|
63
|
+
if (!wasmResult) {
|
|
64
|
+
throw new Error("Failed to get the response from the contract");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
data: wasmResult.data as T,
|
|
69
|
+
status: response.status,
|
|
70
|
+
staled: false,
|
|
71
|
+
timestamp: Date.now(),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
}
|