@keplr-wallet/hooks-evm 0.13.15-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/.eslintrc.json +14 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +18 -0
- package/build/index.js.map +1 -0
- package/build/tx/amount.d.ts +27 -0
- package/build/tx/amount.js +238 -0
- package/build/tx/amount.js.map +1 -0
- package/build/tx/chain.d.ts +10 -0
- package/build/tx/chain.js +37 -0
- package/build/tx/chain.js.map +1 -0
- package/build/tx/errors.d.ts +30 -0
- package/build/tx/errors.js +84 -0
- package/build/tx/errors.js.map +1 -0
- package/build/tx/evm-fee-utils.d.ts +28 -0
- package/build/tx/evm-fee-utils.js +133 -0
- package/build/tx/evm-fee-utils.js.map +1 -0
- package/build/tx/fee.d.ts +61 -0
- package/build/tx/fee.js +523 -0
- package/build/tx/fee.js.map +1 -0
- package/build/tx/gas-simulator.d.ts +89 -0
- package/build/tx/gas-simulator.js +465 -0
- package/build/tx/gas-simulator.js.map +1 -0
- package/build/tx/gas.d.ts +12 -0
- package/build/tx/gas.js +84 -0
- package/build/tx/gas.js.map +1 -0
- package/build/tx/index.d.ts +13 -0
- package/build/tx/index.js +30 -0
- package/build/tx/index.js.map +1 -0
- package/build/tx/internal.d.ts +3 -0
- package/build/tx/internal.js +3 -0
- package/build/tx/internal.js.map +1 -0
- package/build/tx/name-service-ens.d.ts +40 -0
- package/build/tx/name-service-ens.js +189 -0
- package/build/tx/name-service-ens.js.map +1 -0
- package/build/tx/name-service.d.ts +20 -0
- package/build/tx/name-service.js +20 -0
- package/build/tx/name-service.js.map +1 -0
- package/build/tx/recipient.d.ts +35 -0
- package/build/tx/recipient.js +131 -0
- package/build/tx/recipient.js.map +1 -0
- package/build/tx/send-tx.d.ts +13 -0
- package/build/tx/send-tx.js +24 -0
- package/build/tx/send-tx.js.map +1 -0
- package/build/tx/sender.d.ts +12 -0
- package/build/tx/sender.js +73 -0
- package/build/tx/sender.js.map +1 -0
- package/build/tx/types.d.ts +102 -0
- package/build/tx/types.js +3 -0
- package/build/tx/types.js.map +1 -0
- package/build/tx/validate.d.ts +11 -0
- package/build/tx/validate.js +37 -0
- package/build/tx/validate.js.map +1 -0
- package/package.json +40 -0
- package/src/index.ts +1 -0
- package/src/tx/amount.ts +273 -0
- package/src/tx/chain.ts +31 -0
- package/src/tx/errors.ts +79 -0
- package/src/tx/evm-fee-utils.ts +217 -0
- package/src/tx/fee.ts +622 -0
- package/src/tx/gas-simulator.ts +567 -0
- package/src/tx/gas.ts +93 -0
- package/src/tx/index.ts +13 -0
- package/src/tx/internal.ts +4 -0
- package/src/tx/name-service-ens.ts +207 -0
- package/src/tx/name-service.ts +39 -0
- package/src/tx/recipient.ts +166 -0
- package/src/tx/send-tx.ts +55 -0
- package/src/tx/sender.ts +82 -0
- package/src/tx/types.ts +153 -0
- package/src/tx/validate.ts +55 -0
- package/tsconfig.check.json +90 -0
- package/tsconfig.json +12 -0
package/.eslintrc.json
ADDED
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./tx";
|
package/build/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./tx"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uCAAqB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { IAmountConfig, IFeeConfig, ISenderConfig, UIProperties } from "./types";
|
|
2
|
+
import { TxChainSetter } from "./chain";
|
|
3
|
+
import { ChainGetter } from "@keplr-wallet/stores";
|
|
4
|
+
import { AppCurrency } from "@keplr-wallet/types";
|
|
5
|
+
import { CoinPretty } from "@keplr-wallet/unit";
|
|
6
|
+
import { QueriesStore } from "./internal";
|
|
7
|
+
export declare class AmountConfig extends TxChainSetter implements IAmountConfig {
|
|
8
|
+
protected readonly queriesStore: QueriesStore;
|
|
9
|
+
protected readonly senderConfig: ISenderConfig;
|
|
10
|
+
protected _currency?: AppCurrency;
|
|
11
|
+
protected _value: string;
|
|
12
|
+
protected _fraction: number;
|
|
13
|
+
protected _feeConfig: IFeeConfig | undefined;
|
|
14
|
+
constructor(chainGetter: ChainGetter, queriesStore: QueriesStore, initialChainId: string, senderConfig: ISenderConfig);
|
|
15
|
+
get feeConfig(): IFeeConfig | undefined;
|
|
16
|
+
setFeeConfig(feeConfig: IFeeConfig | undefined): void;
|
|
17
|
+
get value(): string;
|
|
18
|
+
setValue(value: string): void;
|
|
19
|
+
get amount(): CoinPretty[];
|
|
20
|
+
get currency(): AppCurrency;
|
|
21
|
+
setCurrency(currency: AppCurrency | undefined): void;
|
|
22
|
+
get fraction(): number;
|
|
23
|
+
setFraction(fraction: number): void;
|
|
24
|
+
canUseCurrency(currency: AppCurrency): boolean;
|
|
25
|
+
get uiProperties(): UIProperties;
|
|
26
|
+
}
|
|
27
|
+
export declare const useAmountConfig: (chainGetter: ChainGetter, queriesStore: QueriesStore, chainId: string, senderConfig: ISenderConfig) => AmountConfig;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.useAmountConfig = exports.AmountConfig = void 0;
|
|
10
|
+
const chain_1 = require("./chain");
|
|
11
|
+
const mobx_1 = require("mobx");
|
|
12
|
+
const errors_1 = require("./errors");
|
|
13
|
+
const unit_1 = require("@keplr-wallet/unit");
|
|
14
|
+
const react_1 = require("react");
|
|
15
|
+
class AmountConfig extends chain_1.TxChainSetter {
|
|
16
|
+
constructor(chainGetter, queriesStore, initialChainId, senderConfig) {
|
|
17
|
+
super(chainGetter, initialChainId);
|
|
18
|
+
this.queriesStore = queriesStore;
|
|
19
|
+
this.senderConfig = senderConfig;
|
|
20
|
+
this._currency = undefined;
|
|
21
|
+
this._value = "";
|
|
22
|
+
this._fraction = 0;
|
|
23
|
+
this._feeConfig = undefined;
|
|
24
|
+
(0, mobx_1.makeObservable)(this);
|
|
25
|
+
}
|
|
26
|
+
get feeConfig() {
|
|
27
|
+
return this._feeConfig;
|
|
28
|
+
}
|
|
29
|
+
setFeeConfig(feeConfig) {
|
|
30
|
+
this._feeConfig = feeConfig;
|
|
31
|
+
}
|
|
32
|
+
get value() {
|
|
33
|
+
var _a;
|
|
34
|
+
if (this.fraction > 0) {
|
|
35
|
+
let result = (_a = this.queriesStore
|
|
36
|
+
.get(this.chainId)
|
|
37
|
+
.queryBalances.getQueryEthereumHexAddress(this.senderConfig.sender)
|
|
38
|
+
.getBalance(this.currency)) === null || _a === void 0 ? void 0 : _a.balance;
|
|
39
|
+
if (!result) {
|
|
40
|
+
return "0";
|
|
41
|
+
}
|
|
42
|
+
if (this.feeConfig && this.feeConfig.maxFee) {
|
|
43
|
+
if (this.currency.coinMinimalDenom ===
|
|
44
|
+
this.feeConfig.maxFee.currency.coinMinimalDenom) {
|
|
45
|
+
result = result.sub(this.feeConfig.maxFee);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (result.toDec().lte(new unit_1.Dec(0))) {
|
|
49
|
+
return "0";
|
|
50
|
+
}
|
|
51
|
+
return result
|
|
52
|
+
.mul(new unit_1.Dec(this.fraction))
|
|
53
|
+
.trim(true)
|
|
54
|
+
.locale(false)
|
|
55
|
+
.hideDenom(true)
|
|
56
|
+
.toString();
|
|
57
|
+
}
|
|
58
|
+
return this._value;
|
|
59
|
+
}
|
|
60
|
+
setValue(value) {
|
|
61
|
+
if (value.startsWith(".")) {
|
|
62
|
+
value = "0" + value;
|
|
63
|
+
}
|
|
64
|
+
this._value = value;
|
|
65
|
+
this.setFraction(0);
|
|
66
|
+
}
|
|
67
|
+
get amount() {
|
|
68
|
+
let amount;
|
|
69
|
+
try {
|
|
70
|
+
if (this.value.trim() === "") {
|
|
71
|
+
amount = new unit_1.Dec(0);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
amount = new unit_1.Dec(this.value);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
catch (_a) {
|
|
78
|
+
amount = new unit_1.Dec(0);
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
return [
|
|
82
|
+
new unit_1.CoinPretty(this.currency, amount
|
|
83
|
+
.mul(unit_1.DecUtils.getTenExponentN(this.currency.coinDecimals))
|
|
84
|
+
.truncate()),
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
catch (_b) {
|
|
88
|
+
return [new unit_1.CoinPretty(this.currency, new unit_1.Dec(0))];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
get currency() {
|
|
92
|
+
var _a;
|
|
93
|
+
const u = this.modularChainInfo.unwrapped;
|
|
94
|
+
if (u.type !== "evm" && u.type !== "ethermint") {
|
|
95
|
+
throw new Error("Chain is not an EVM compatible chain");
|
|
96
|
+
}
|
|
97
|
+
if (this._currency) {
|
|
98
|
+
const allCurrencies = [
|
|
99
|
+
u.evm.nativeCurrency,
|
|
100
|
+
...((_a = u.evm.tokens) !== null && _a !== void 0 ? _a : []),
|
|
101
|
+
];
|
|
102
|
+
const find = allCurrencies.find((cur) => cur.coinMinimalDenom === this._currency.coinMinimalDenom);
|
|
103
|
+
if (find) {
|
|
104
|
+
return find;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return u.evm.nativeCurrency;
|
|
108
|
+
}
|
|
109
|
+
setCurrency(currency) {
|
|
110
|
+
var _a;
|
|
111
|
+
if ((currency === null || currency === void 0 ? void 0 : currency.coinMinimalDenom) !== ((_a = this._currency) === null || _a === void 0 ? void 0 : _a.coinMinimalDenom)) {
|
|
112
|
+
this._value = "";
|
|
113
|
+
this.setFraction(0);
|
|
114
|
+
}
|
|
115
|
+
this._currency = currency;
|
|
116
|
+
}
|
|
117
|
+
get fraction() {
|
|
118
|
+
return this._fraction;
|
|
119
|
+
}
|
|
120
|
+
setFraction(fraction) {
|
|
121
|
+
this._fraction = fraction;
|
|
122
|
+
}
|
|
123
|
+
canUseCurrency(currency) {
|
|
124
|
+
var _a;
|
|
125
|
+
const u = this.modularChainInfo.unwrapped;
|
|
126
|
+
if (u.type !== "evm" && u.type !== "ethermint") {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
const allCurrencies = [
|
|
130
|
+
u.evm.nativeCurrency,
|
|
131
|
+
...((_a = u.evm.tokens) !== null && _a !== void 0 ? _a : []),
|
|
132
|
+
];
|
|
133
|
+
return (allCurrencies.find((cur) => cur.coinMinimalDenom === currency.coinMinimalDenom) != null);
|
|
134
|
+
}
|
|
135
|
+
get uiProperties() {
|
|
136
|
+
if (!this.currency) {
|
|
137
|
+
return {
|
|
138
|
+
error: new Error("Currency to send not set"),
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (this.value.trim() === "") {
|
|
142
|
+
return {
|
|
143
|
+
error: new errors_1.EmptyAmountError("Amount is empty"),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const dec = new unit_1.Dec(this.value);
|
|
148
|
+
if (dec.equals(new unit_1.Dec(0))) {
|
|
149
|
+
return {
|
|
150
|
+
error: new errors_1.ZeroAmountError("Amount is zero"),
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
if (dec.lt(new unit_1.Dec(0))) {
|
|
154
|
+
return {
|
|
155
|
+
error: new errors_1.NegativeAmountError("Enter a positive number"),
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
new unit_1.CoinPretty(this.currency, dec.mul(unit_1.DecUtils.getTenExponentN(this.currency.coinDecimals)).truncate());
|
|
159
|
+
}
|
|
160
|
+
catch (_a) {
|
|
161
|
+
return {
|
|
162
|
+
error: new errors_1.InvalidNumberAmountError("Enter a valid number"),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
for (const amount of this.amount) {
|
|
166
|
+
const bal = this.queriesStore
|
|
167
|
+
.get(this.chainId)
|
|
168
|
+
.queryBalances.getQueryEthereumHexAddress(this.senderConfig.sender)
|
|
169
|
+
.getBalance(amount.currency);
|
|
170
|
+
if (!bal) {
|
|
171
|
+
return {
|
|
172
|
+
warning: new Error(`Can't parse the balance for ${amount.currency.coinMinimalDenom}`),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
if (bal.error) {
|
|
176
|
+
return {
|
|
177
|
+
warning: new Error("Failed to fetch balance"),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (!bal.response) {
|
|
181
|
+
return {
|
|
182
|
+
loadingState: "loading-block",
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
if (bal.balance.toDec().lt(amount.toDec())) {
|
|
186
|
+
return {
|
|
187
|
+
error: new errors_1.InsufficientAmountError("Insufficient balance"),
|
|
188
|
+
loadingState: bal.isFetching ? "loading" : undefined,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return {};
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
__decorate([
|
|
196
|
+
mobx_1.observable.ref
|
|
197
|
+
], AmountConfig.prototype, "_currency", void 0);
|
|
198
|
+
__decorate([
|
|
199
|
+
mobx_1.observable
|
|
200
|
+
], AmountConfig.prototype, "_value", void 0);
|
|
201
|
+
__decorate([
|
|
202
|
+
mobx_1.observable
|
|
203
|
+
], AmountConfig.prototype, "_fraction", void 0);
|
|
204
|
+
__decorate([
|
|
205
|
+
mobx_1.observable.ref
|
|
206
|
+
], AmountConfig.prototype, "_feeConfig", void 0);
|
|
207
|
+
__decorate([
|
|
208
|
+
mobx_1.action
|
|
209
|
+
], AmountConfig.prototype, "setFeeConfig", null);
|
|
210
|
+
__decorate([
|
|
211
|
+
mobx_1.computed
|
|
212
|
+
], AmountConfig.prototype, "value", null);
|
|
213
|
+
__decorate([
|
|
214
|
+
mobx_1.action
|
|
215
|
+
], AmountConfig.prototype, "setValue", null);
|
|
216
|
+
__decorate([
|
|
217
|
+
mobx_1.computed
|
|
218
|
+
], AmountConfig.prototype, "amount", null);
|
|
219
|
+
__decorate([
|
|
220
|
+
mobx_1.computed
|
|
221
|
+
], AmountConfig.prototype, "currency", null);
|
|
222
|
+
__decorate([
|
|
223
|
+
mobx_1.action
|
|
224
|
+
], AmountConfig.prototype, "setCurrency", null);
|
|
225
|
+
__decorate([
|
|
226
|
+
mobx_1.action
|
|
227
|
+
], AmountConfig.prototype, "setFraction", null);
|
|
228
|
+
__decorate([
|
|
229
|
+
mobx_1.computed
|
|
230
|
+
], AmountConfig.prototype, "uiProperties", null);
|
|
231
|
+
exports.AmountConfig = AmountConfig;
|
|
232
|
+
const useAmountConfig = (chainGetter, queriesStore, chainId, senderConfig) => {
|
|
233
|
+
const [txConfig] = (0, react_1.useState)(() => new AmountConfig(chainGetter, queriesStore, chainId, senderConfig));
|
|
234
|
+
txConfig.setChain(chainId);
|
|
235
|
+
return txConfig;
|
|
236
|
+
};
|
|
237
|
+
exports.useAmountConfig = useAmountConfig;
|
|
238
|
+
//# sourceMappingURL=amount.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amount.js","sourceRoot":"","sources":["../../src/tx/amount.ts"],"names":[],"mappings":";;;;;;;;;AAMA,mCAAwC;AAExC,+BAAoE;AAEpE,qCAMkB;AAClB,6CAA+D;AAC/D,iCAAiC;AAGjC,MAAa,YAAa,SAAQ,qBAAa;IAa7C,YACE,WAAwB,EACL,YAA0B,EAC7C,cAAsB,EACH,YAA2B;QAE9C,KAAK,CAAC,WAAW,EAAE,cAAc,CAAC,CAAC;QAJhB,iBAAY,GAAZ,YAAY,CAAc;QAE1B,iBAAY,GAAZ,YAAY,CAAe;QAftC,cAAS,GAAiB,SAAS,CAAC;QAGpC,WAAM,GAAW,EAAE,CAAC;QAGpB,cAAS,GAAW,CAAC,CAAC;QAGtB,eAAU,GAA2B,SAAS,CAAC;QAUvD,IAAA,qBAAc,EAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAGD,YAAY,CAAC,SAAiC;QAC5C,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAGD,IAAI,KAAK;;QACP,IAAI,IAAI,CAAC,QAAQ,GAAG,CAAC,EAAE;YACrB,IAAI,MAAM,GAAG,MAAA,IAAI,C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@keplr-wallet/stores";
|
|
2
|
+
import { ITxChainSetter } from "./types";
|
|
3
|
+
export declare class TxChainSetter implements ITxChainSetter {
|
|
4
|
+
protected readonly chainGetter: ChainGetter;
|
|
5
|
+
protected _chainId: string;
|
|
6
|
+
constructor(chainGetter: ChainGetter, initialChainId: string);
|
|
7
|
+
get modularChainInfo(): IModularChainInfoImpl;
|
|
8
|
+
get chainId(): string;
|
|
9
|
+
setChain(chainId: string): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TxChainSetter = void 0;
|
|
10
|
+
const mobx_1 = require("mobx");
|
|
11
|
+
class TxChainSetter {
|
|
12
|
+
constructor(chainGetter, initialChainId) {
|
|
13
|
+
this.chainGetter = chainGetter;
|
|
14
|
+
this._chainId = initialChainId;
|
|
15
|
+
(0, mobx_1.makeObservable)(this);
|
|
16
|
+
}
|
|
17
|
+
get modularChainInfo() {
|
|
18
|
+
return this.chainGetter.getModularChain(this.chainId);
|
|
19
|
+
}
|
|
20
|
+
get chainId() {
|
|
21
|
+
return this._chainId;
|
|
22
|
+
}
|
|
23
|
+
setChain(chainId) {
|
|
24
|
+
this._chainId = chainId;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
__decorate([
|
|
28
|
+
mobx_1.observable
|
|
29
|
+
], TxChainSetter.prototype, "_chainId", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
mobx_1.computed
|
|
32
|
+
], TxChainSetter.prototype, "modularChainInfo", null);
|
|
33
|
+
__decorate([
|
|
34
|
+
mobx_1.action
|
|
35
|
+
], TxChainSetter.prototype, "setChain", null);
|
|
36
|
+
exports.TxChainSetter = TxChainSetter;
|
|
37
|
+
//# sourceMappingURL=chain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chain.js","sourceRoot":"","sources":["../../src/tx/chain.ts"],"names":[],"mappings":";;;;;;;;;AAAA,+BAAoE;AAIpE,MAAa,aAAa;IAIxB,YACqB,WAAwB,EAC3C,cAAsB;QADH,gBAAW,GAAX,WAAW,CAAa;QAG3C,IAAI,CAAC,QAAQ,GAAG,cAAc,CAAC;QAE/B,IAAA,qBAAc,EAAC,IAAI,CAAC,CAAC;IACvB,CAAC;IAGD,IAAI,gBAAgB;QAClB,OAAO,IAAI,CAAC,WAAW,CAAC,eAAe,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,OAAO;QACT,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAGD,QAAQ,CAAC,OAAe;QACtB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;IAC1B,CAAC;CACF;AAxBW;IADT,iBAAU;+CACgB;AAY3B;IADC,eAAQ;qDAGR;AAOD;IADC,aAAM;6CAGN;AAzBH,sCA0BC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare class EmptyAddressError extends Error {
|
|
2
|
+
constructor(m: string);
|
|
3
|
+
}
|
|
4
|
+
export declare class InvalidHexError extends Error {
|
|
5
|
+
constructor(m: string);
|
|
6
|
+
}
|
|
7
|
+
export declare class EmptyAmountError extends Error {
|
|
8
|
+
constructor(m: string);
|
|
9
|
+
}
|
|
10
|
+
export declare class InvalidNumberAmountError extends Error {
|
|
11
|
+
constructor(m: string);
|
|
12
|
+
}
|
|
13
|
+
export declare class ZeroAmountError extends Error {
|
|
14
|
+
constructor(m: string);
|
|
15
|
+
}
|
|
16
|
+
export declare class NegativeAmountError extends Error {
|
|
17
|
+
constructor(m: string);
|
|
18
|
+
}
|
|
19
|
+
export declare class InsufficientAmountError extends Error {
|
|
20
|
+
constructor(m: string);
|
|
21
|
+
}
|
|
22
|
+
export declare class InsufficientFeeError extends Error {
|
|
23
|
+
constructor(m: string);
|
|
24
|
+
}
|
|
25
|
+
export declare class ENSIsFetchingError extends Error {
|
|
26
|
+
constructor(m: string);
|
|
27
|
+
}
|
|
28
|
+
export declare class ENSFailedToFetchError extends Error {
|
|
29
|
+
constructor(m: string);
|
|
30
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ENSFailedToFetchError = exports.ENSIsFetchingError = exports.InsufficientFeeError = exports.InsufficientAmountError = exports.NegativeAmountError = exports.ZeroAmountError = exports.InvalidNumberAmountError = exports.EmptyAmountError = exports.InvalidHexError = exports.EmptyAddressError = void 0;
|
|
4
|
+
class EmptyAddressError extends Error {
|
|
5
|
+
constructor(m) {
|
|
6
|
+
super(m);
|
|
7
|
+
// Set the prototype explicitly.
|
|
8
|
+
Object.setPrototypeOf(this, EmptyAddressError.prototype);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.EmptyAddressError = EmptyAddressError;
|
|
12
|
+
class InvalidHexError extends Error {
|
|
13
|
+
constructor(m) {
|
|
14
|
+
super(m);
|
|
15
|
+
// Set the prototype explicitly.
|
|
16
|
+
Object.setPrototypeOf(this, InvalidHexError.prototype);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.InvalidHexError = InvalidHexError;
|
|
20
|
+
class EmptyAmountError extends Error {
|
|
21
|
+
constructor(m) {
|
|
22
|
+
super(m);
|
|
23
|
+
// Set the prototype explicitly.
|
|
24
|
+
Object.setPrototypeOf(this, EmptyAmountError.prototype);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.EmptyAmountError = EmptyAmountError;
|
|
28
|
+
class InvalidNumberAmountError extends Error {
|
|
29
|
+
constructor(m) {
|
|
30
|
+
super(m);
|
|
31
|
+
// Set the prototype explicitly.
|
|
32
|
+
Object.setPrototypeOf(this, InvalidNumberAmountError.prototype);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.InvalidNumberAmountError = InvalidNumberAmountError;
|
|
36
|
+
class ZeroAmountError extends Error {
|
|
37
|
+
constructor(m) {
|
|
38
|
+
super(m);
|
|
39
|
+
// Set the prototype explicitly.
|
|
40
|
+
Object.setPrototypeOf(this, ZeroAmountError.prototype);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.ZeroAmountError = ZeroAmountError;
|
|
44
|
+
class NegativeAmountError extends Error {
|
|
45
|
+
constructor(m) {
|
|
46
|
+
super(m);
|
|
47
|
+
// Set the prototype explicitly.
|
|
48
|
+
Object.setPrototypeOf(this, NegativeAmountError.prototype);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.NegativeAmountError = NegativeAmountError;
|
|
52
|
+
class InsufficientAmountError extends Error {
|
|
53
|
+
constructor(m) {
|
|
54
|
+
super(m);
|
|
55
|
+
// Set the prototype explicitly.
|
|
56
|
+
Object.setPrototypeOf(this, InsufficientAmountError.prototype);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.InsufficientAmountError = InsufficientAmountError;
|
|
60
|
+
class InsufficientFeeError extends Error {
|
|
61
|
+
constructor(m) {
|
|
62
|
+
super(m);
|
|
63
|
+
// Set the prototype explicitly.
|
|
64
|
+
Object.setPrototypeOf(this, InsufficientFeeError.prototype);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.InsufficientFeeError = InsufficientFeeError;
|
|
68
|
+
class ENSIsFetchingError extends Error {
|
|
69
|
+
constructor(m) {
|
|
70
|
+
super(m);
|
|
71
|
+
// Set the prototype explicitly.
|
|
72
|
+
Object.setPrototypeOf(this, ENSIsFetchingError.prototype);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.ENSIsFetchingError = ENSIsFetchingError;
|
|
76
|
+
class ENSFailedToFetchError extends Error {
|
|
77
|
+
constructor(m) {
|
|
78
|
+
super(m);
|
|
79
|
+
// Set the prototype explicitly.
|
|
80
|
+
Object.setPrototypeOf(this, ENSFailedToFetchError.prototype);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.ENSFailedToFetchError = ENSFailedToFetchError;
|
|
84
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/tx/errors.ts"],"names":[],"mappings":";;;AAAA,MAAa,iBAAkB,SAAQ,KAAK;IAC1C,YAAY,CAAS;QACnB,KAAK,CAAC,CAAC,CAAC,CAAC;QACT,gCAAgC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAC3D,CAAC;CACF;AAND,8CAMC;AAED,MAAa,eAAgB,SAAQ,KAAK;IACxC,YAAY,CAAS;QACnB,KAAK,CAAC,CAAC,CAAC,CAAC;QACT,gCAAgC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,eAAe,CAAC,SAAS,CAAC,CAAC;IACzD,CAAC;CACF;AAND,0CAMC;AAED,MAAa,gBAAiB,SAAQ,KAAK;IACzC,YAAY,CAAS;QACnB,KAAK,CAAC,CAAC,CAAC,CAAC;QACT,gCAAgC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAC1D,CAAC;CACF;AAND,4CAMC;AAED,MAAa,wBAAyB,SAAQ,KAAK;IACjD,YAAY,CAAS;QACnB,KAAK,CAAC,CAAC,CAAC,CAAC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CAAgC;QAChC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,qBAAqB,CAAC,SAAS,CAAC,CAAC;IAC/D,CAAC;CACF;AAND,sDAMC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Dec } from "@keplr-wallet/unit";
|
|
2
|
+
import { EthereumQueriesImpl } from "@keplr-wallet/stores-eth";
|
|
3
|
+
import { FeeType } from "./types";
|
|
4
|
+
export declare const GWEI: Dec;
|
|
5
|
+
export declare const ETH_FEE_HISTORY_BLOCK_COUNT = 20;
|
|
6
|
+
export declare const ETH_FEE_HISTORY_REWARD_PERCENTILES: number[];
|
|
7
|
+
export declare const MAX_PRIORITY_FEE_UPPER_BOUND: Dec;
|
|
8
|
+
export declare const MAX_PRIORITY_FEE_UPPER_BOUND_FOR_POLYGON: Dec;
|
|
9
|
+
export declare const ETH_FEE_SETTINGS_BY_FEE_TYPE: Record<FeeType, {
|
|
10
|
+
percentile: number;
|
|
11
|
+
baseFeePercentageMultiplier: Dec;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const ETH_FEE_HISTORY_NEWEST_BLOCK = "latest";
|
|
14
|
+
export type EIP1559TxFees = {
|
|
15
|
+
maxPriorityFeePerGas?: Dec;
|
|
16
|
+
maxFeePerGas?: Dec;
|
|
17
|
+
gasPrice?: Dec;
|
|
18
|
+
};
|
|
19
|
+
export declare function getMaxPriorityFeeUpperBound(chainId: string): Dec;
|
|
20
|
+
export declare function calculateOptimalMaxPriorityFeePerGas(ethereumQueries: EthereumQueriesImpl, feeType: FeeType, chainId: string): Dec;
|
|
21
|
+
export type EIP1559QueryUIState = {
|
|
22
|
+
warning?: Error;
|
|
23
|
+
isLoading: boolean;
|
|
24
|
+
isBlocked: boolean;
|
|
25
|
+
};
|
|
26
|
+
export declare function getEIP1559QueryUIState(ethereumQueries: EthereumQueriesImpl, chainId: string): EIP1559QueryUIState;
|
|
27
|
+
export declare function getL1DataFeeToAdd(hasOpStackFeature: boolean, l1DataFee: Dec | undefined): Dec;
|
|
28
|
+
export declare function computeEIP1559TxFees(ethereumQueries: EthereumQueriesImpl, feeType: FeeType, chainId: string, customMaxPriorityFeePerGas?: Dec): EIP1559TxFees;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.computeEIP1559TxFees = exports.getL1DataFeeToAdd = exports.getEIP1559QueryUIState = exports.calculateOptimalMaxPriorityFeePerGas = exports.getMaxPriorityFeeUpperBound = exports.ETH_FEE_HISTORY_NEWEST_BLOCK = exports.ETH_FEE_SETTINGS_BY_FEE_TYPE = exports.MAX_PRIORITY_FEE_UPPER_BOUND_FOR_POLYGON = exports.MAX_PRIORITY_FEE_UPPER_BOUND = exports.ETH_FEE_HISTORY_REWARD_PERCENTILES = exports.ETH_FEE_HISTORY_BLOCK_COUNT = exports.GWEI = void 0;
|
|
4
|
+
const unit_1 = require("@keplr-wallet/unit");
|
|
5
|
+
// --- Constants ---
|
|
6
|
+
exports.GWEI = new unit_1.Dec(Math.pow(10, 9));
|
|
7
|
+
exports.ETH_FEE_HISTORY_BLOCK_COUNT = 20;
|
|
8
|
+
exports.ETH_FEE_HISTORY_REWARD_PERCENTILES = [20, 40, 60];
|
|
9
|
+
exports.MAX_PRIORITY_FEE_UPPER_BOUND = new unit_1.Dec(20).mul(exports.GWEI);
|
|
10
|
+
exports.MAX_PRIORITY_FEE_UPPER_BOUND_FOR_POLYGON = new unit_1.Dec(100).mul(exports.GWEI);
|
|
11
|
+
exports.ETH_FEE_SETTINGS_BY_FEE_TYPE = {
|
|
12
|
+
low: {
|
|
13
|
+
percentile: exports.ETH_FEE_HISTORY_REWARD_PERCENTILES[0],
|
|
14
|
+
baseFeePercentageMultiplier: new unit_1.Dec(1),
|
|
15
|
+
},
|
|
16
|
+
average: {
|
|
17
|
+
percentile: exports.ETH_FEE_HISTORY_REWARD_PERCENTILES[1],
|
|
18
|
+
baseFeePercentageMultiplier: new unit_1.Dec(1.25),
|
|
19
|
+
},
|
|
20
|
+
high: {
|
|
21
|
+
percentile: exports.ETH_FEE_HISTORY_REWARD_PERCENTILES[2],
|
|
22
|
+
baseFeePercentageMultiplier: new unit_1.Dec(1.5),
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
exports.ETH_FEE_HISTORY_NEWEST_BLOCK = "latest";
|
|
26
|
+
// --- Pure Functions ---
|
|
27
|
+
function getMaxPriorityFeeUpperBound(chainId) {
|
|
28
|
+
return chainId === "eip155:137"
|
|
29
|
+
? exports.MAX_PRIORITY_FEE_UPPER_BOUND_FOR_POLYGON
|
|
30
|
+
: exports.MAX_PRIORITY_FEE_UPPER_BOUND;
|
|
31
|
+
}
|
|
32
|
+
exports.getMaxPriorityFeeUpperBound = getMaxPriorityFeeUpperBound;
|
|
33
|
+
function calculateOptimalMaxPriorityFeePerGas(ethereumQueries, feeType, chainId) {
|
|
34
|
+
const feeHistoryQuery = ethereumQueries.queryEthereumFeeHistory.getQueryByFeeHistoryParams(exports.ETH_FEE_HISTORY_BLOCK_COUNT, exports.ETH_FEE_HISTORY_NEWEST_BLOCK, exports.ETH_FEE_HISTORY_REWARD_PERCENTILES);
|
|
35
|
+
const reasonableMaxPriorityFeePerGas = feeHistoryQuery.reasonableMaxPriorityFeePerGas;
|
|
36
|
+
const maxPriorityFeePerGas = ethereumQueries.queryEthereumMaxPriorityFee.maxPriorityFeePerGas;
|
|
37
|
+
if (reasonableMaxPriorityFeePerGas &&
|
|
38
|
+
reasonableMaxPriorityFeePerGas.length > 0) {
|
|
39
|
+
const percentile = exports.ETH_FEE_SETTINGS_BY_FEE_TYPE[feeType].percentile;
|
|
40
|
+
const targetPercentileData = reasonableMaxPriorityFeePerGas.find((item) => item.percentile === percentile);
|
|
41
|
+
if (targetPercentileData) {
|
|
42
|
+
const historyBasedFee = new unit_1.Dec(targetPercentileData.value);
|
|
43
|
+
const networkSuggestedFee = new unit_1.Dec(BigInt(maxPriorityFeePerGas !== null && maxPriorityFeePerGas !== void 0 ? maxPriorityFeePerGas : "0x0"));
|
|
44
|
+
const higherFee = historyBasedFee.gt(networkSuggestedFee)
|
|
45
|
+
? historyBasedFee
|
|
46
|
+
: networkSuggestedFee;
|
|
47
|
+
const upperBound = getMaxPriorityFeeUpperBound(chainId);
|
|
48
|
+
if (higherFee.gt(upperBound)) {
|
|
49
|
+
return upperBound;
|
|
50
|
+
}
|
|
51
|
+
return higherFee;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (maxPriorityFeePerGas) {
|
|
55
|
+
const multiplier = exports.ETH_FEE_SETTINGS_BY_FEE_TYPE[feeType].baseFeePercentageMultiplier;
|
|
56
|
+
return new unit_1.Dec(BigInt(maxPriorityFeePerGas)).mul(multiplier);
|
|
57
|
+
}
|
|
58
|
+
return new unit_1.Dec(0);
|
|
59
|
+
}
|
|
60
|
+
exports.calculateOptimalMaxPriorityFeePerGas = calculateOptimalMaxPriorityFeePerGas;
|
|
61
|
+
function getEIP1559QueryUIState(ethereumQueries, chainId) {
|
|
62
|
+
let warning;
|
|
63
|
+
let isLoading = false;
|
|
64
|
+
const blockQuery = ethereumQueries.queryEthereumBlock.getQueryByBlockNumberOrTag(exports.ETH_FEE_HISTORY_NEWEST_BLOCK);
|
|
65
|
+
if (blockQuery.error) {
|
|
66
|
+
warning = new Error(`Failed to fetch latest block. chain id: ${chainId}`);
|
|
67
|
+
}
|
|
68
|
+
if (blockQuery.isFetching) {
|
|
69
|
+
isLoading = true;
|
|
70
|
+
}
|
|
71
|
+
if (!blockQuery.response) {
|
|
72
|
+
return { warning, isLoading, isBlocked: true };
|
|
73
|
+
}
|
|
74
|
+
const feeHistoryQuery = ethereumQueries.queryEthereumFeeHistory.getQueryByFeeHistoryParams(exports.ETH_FEE_HISTORY_BLOCK_COUNT, exports.ETH_FEE_HISTORY_NEWEST_BLOCK, exports.ETH_FEE_HISTORY_REWARD_PERCENTILES);
|
|
75
|
+
const maxPriorityFeePerGasQuery = ethereumQueries.queryEthereumMaxPriorityFee;
|
|
76
|
+
if (feeHistoryQuery.error && maxPriorityFeePerGasQuery.error) {
|
|
77
|
+
warning = new Error(`Failed to fetch both fee history and max priority fee. chain id: ${chainId}`);
|
|
78
|
+
}
|
|
79
|
+
if (feeHistoryQuery.isFetching || maxPriorityFeePerGasQuery.isFetching) {
|
|
80
|
+
isLoading = true;
|
|
81
|
+
}
|
|
82
|
+
if (!feeHistoryQuery.response || !maxPriorityFeePerGasQuery.response) {
|
|
83
|
+
return { warning, isLoading, isBlocked: true };
|
|
84
|
+
}
|
|
85
|
+
const gasPriceQuery = ethereumQueries.queryEthereumGasPrice;
|
|
86
|
+
if (gasPriceQuery.error) {
|
|
87
|
+
warning = new Error(`Failed to fetch gas price. chain id: ${chainId}`);
|
|
88
|
+
}
|
|
89
|
+
if (gasPriceQuery.isFetching) {
|
|
90
|
+
isLoading = true;
|
|
91
|
+
}
|
|
92
|
+
if (!gasPriceQuery.response) {
|
|
93
|
+
return { warning, isLoading, isBlocked: true };
|
|
94
|
+
}
|
|
95
|
+
return { warning, isLoading, isBlocked: false };
|
|
96
|
+
}
|
|
97
|
+
exports.getEIP1559QueryUIState = getEIP1559QueryUIState;
|
|
98
|
+
// --- L1 Data Fee ---
|
|
99
|
+
function getL1DataFeeToAdd(hasOpStackFeature, l1DataFee) {
|
|
100
|
+
return hasOpStackFeature ? l1DataFee !== null && l1DataFee !== void 0 ? l1DataFee : new unit_1.Dec(0) : new unit_1.Dec(0);
|
|
101
|
+
}
|
|
102
|
+
exports.getL1DataFeeToAdd = getL1DataFeeToAdd;
|
|
103
|
+
// --- Fee Computation ---
|
|
104
|
+
function computeEIP1559TxFees(ethereumQueries, feeType, chainId, customMaxPriorityFeePerGas) {
|
|
105
|
+
var _a;
|
|
106
|
+
const block = ethereumQueries.queryEthereumBlock.getQueryByBlockNumberOrTag(exports.ETH_FEE_HISTORY_NEWEST_BLOCK).block;
|
|
107
|
+
const latestBaseFeePerGas = parseInt((_a = block === null || block === void 0 ? void 0 : block.baseFeePerGas) !== null && _a !== void 0 ? _a : "0");
|
|
108
|
+
if (latestBaseFeePerGas !== 0) {
|
|
109
|
+
const multiplier = exports.ETH_FEE_SETTINGS_BY_FEE_TYPE[feeType].baseFeePercentageMultiplier;
|
|
110
|
+
const baseFeePerGasDec = new unit_1.Dec(latestBaseFeePerGas);
|
|
111
|
+
const baseFeePerGasWithMargin = baseFeePerGasDec.mul(multiplier);
|
|
112
|
+
const maxPriorityFeePerGas = customMaxPriorityFeePerGas !== null && customMaxPriorityFeePerGas !== void 0 ? customMaxPriorityFeePerGas : calculateOptimalMaxPriorityFeePerGas(ethereumQueries, feeType, chainId);
|
|
113
|
+
const maxFeePerGas = baseFeePerGasWithMargin.add(maxPriorityFeePerGas);
|
|
114
|
+
return {
|
|
115
|
+
maxPriorityFeePerGas: maxPriorityFeePerGas.truncateDec(),
|
|
116
|
+
maxFeePerGas: maxFeePerGas.truncateDec(),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
const gasPrice = ethereumQueries.queryEthereumGasPrice.gasPrice;
|
|
121
|
+
if (gasPrice != null) {
|
|
122
|
+
const multipliedGasPrice = new unit_1.Dec(BigInt(gasPrice)).mul(exports.ETH_FEE_SETTINGS_BY_FEE_TYPE[feeType].baseFeePercentageMultiplier);
|
|
123
|
+
return {
|
|
124
|
+
gasPrice: multipliedGasPrice,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return {
|
|
129
|
+
gasPrice: new unit_1.Dec(0),
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
exports.computeEIP1559TxFees = computeEIP1559TxFees;
|
|
133
|
+
//# sourceMappingURL=evm-fee-utils.js.map
|