@subwallet/extension-base 1.3.29-0 → 1.3.30-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/background/KoniTypes.d.ts +4 -4
- package/background/errors/SwapError.js +1 -1
- package/cjs/background/errors/SwapError.js +1 -1
- package/cjs/constants/blocked-actions.js +2 -2
- package/cjs/constants/remind-notification-time.js +3 -3
- package/cjs/core/logic-validation/swap.js +63 -4
- package/cjs/core/utils.js +9 -3
- package/cjs/koni/background/handlers/Extension.js +5 -82
- package/cjs/packageInfo.js +1 -1
- package/cjs/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/cjs/services/chain-service/constants.js +1 -1
- package/cjs/services/earning-service/handlers/base.js +6 -3
- package/cjs/services/earning-service/handlers/native-staking/base.js +4 -1
- package/cjs/services/earning-service/handlers/native-staking/dtao.js +68 -50
- package/cjs/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/cjs/services/earning-service/service.js +2 -1
- package/cjs/services/fee-service/utils/index.js +16 -4
- package/cjs/services/inapp-notification-service/index.js +19 -13
- package/cjs/services/swap-service/handler/asset-hub/handler.js +61 -314
- package/cjs/services/swap-service/handler/base-handler.js +393 -231
- package/cjs/services/swap-service/handler/chainflip-handler.js +18 -40
- package/cjs/services/swap-service/handler/hydradx-handler.js +77 -269
- package/cjs/services/swap-service/handler/simpleswap-handler.js +27 -48
- package/cjs/services/swap-service/handler/uniswap-handler.js +33 -54
- package/cjs/services/swap-service/index.js +154 -143
- package/cjs/services/swap-service/utils.js +107 -17
- package/cjs/services/transaction-service/index.js +1 -1
- package/cjs/types/swap/index.js +13 -1
- package/cjs/utils/swap.js +5 -1
- package/constants/blocked-actions.d.ts +1 -1
- package/constants/blocked-actions.js +1 -1
- package/constants/remind-notification-time.d.ts +1 -1
- package/constants/remind-notification-time.js +1 -1
- package/core/logic-validation/swap.d.ts +15 -0
- package/core/logic-validation/swap.js +60 -4
- package/core/utils.js +9 -3
- package/koni/background/handlers/Extension.d.ts +0 -1
- package/koni/background/handlers/Extension.js +6 -83
- package/package.json +6 -12
- package/packageInfo.js +1 -1
- package/services/balance-service/transfer/xcm/availBridge.js +6 -6
- package/services/base/types.d.ts +0 -4
- package/services/chain-service/constants.js +1 -1
- package/services/earning-service/handlers/base.d.ts +4 -3
- package/services/earning-service/handlers/base.js +6 -4
- package/services/earning-service/handlers/native-staking/base.js +4 -1
- package/services/earning-service/handlers/native-staking/dtao.d.ts +9 -6
- package/services/earning-service/handlers/native-staking/dtao.js +69 -48
- package/services/earning-service/handlers/native-staking/tao.js +12 -2
- package/services/earning-service/service.d.ts +2 -1
- package/services/earning-service/service.js +2 -1
- package/services/fee-service/utils/index.d.ts +1 -0
- package/services/fee-service/utils/index.js +14 -4
- package/services/inapp-notification-service/index.js +13 -7
- package/services/swap-service/handler/asset-hub/handler.d.ts +2 -9
- package/services/swap-service/handler/asset-hub/handler.js +64 -317
- package/services/swap-service/handler/base-handler.d.ts +6 -9
- package/services/swap-service/handler/base-handler.js +391 -229
- package/services/swap-service/handler/chainflip-handler.d.ts +2 -4
- package/services/swap-service/handler/chainflip-handler.js +15 -37
- package/services/swap-service/handler/hydradx-handler.d.ts +3 -10
- package/services/swap-service/handler/hydradx-handler.js +78 -270
- package/services/swap-service/handler/simpleswap-handler.d.ts +2 -4
- package/services/swap-service/handler/simpleswap-handler.js +24 -45
- package/services/swap-service/handler/uniswap-handler.d.ts +4 -6
- package/services/swap-service/handler/uniswap-handler.js +25 -46
- package/services/swap-service/index.d.ts +8 -14
- package/services/swap-service/index.js +141 -129
- package/services/swap-service/utils.d.ts +11 -3
- package/services/swap-service/utils.js +96 -15
- package/services/transaction-service/index.js +2 -2
- package/types/service-base.d.ts +2 -3
- package/types/swap/index.d.ts +25 -9
- package/types/swap/index.js +10 -0
- package/types/transaction/process.d.ts +19 -0
- package/types/yield/actions/join/submit.d.ts +4 -1
- package/types/yield/actions/others.d.ts +2 -0
- package/utils/swap.d.ts +3 -0
- package/utils/swap.js +3 -0
- package/cjs/services/swap-service/interface.js +0 -14
- package/services/swap-service/interface.d.ts +0 -9
- package/services/swap-service/interface.js +0 -8
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"./cjs/detectPackage.js"
|
|
18
18
|
],
|
|
19
19
|
"type": "module",
|
|
20
|
-
"version": "1.3.
|
|
20
|
+
"version": "1.3.30-0",
|
|
21
21
|
"main": "./cjs/index.js",
|
|
22
22
|
"module": "./index.js",
|
|
23
23
|
"types": "./index.d.ts",
|
|
@@ -1886,11 +1886,6 @@
|
|
|
1886
1886
|
"require": "./cjs/services/swap-service/handler/uniswap-handler.js",
|
|
1887
1887
|
"default": "./services/swap-service/handler/uniswap-handler.js"
|
|
1888
1888
|
},
|
|
1889
|
-
"./services/swap-service/interface": {
|
|
1890
|
-
"types": "./services/swap-service/interface.d.ts",
|
|
1891
|
-
"require": "./cjs/services/swap-service/interface.js",
|
|
1892
|
-
"default": "./services/swap-service/interface.js"
|
|
1893
|
-
},
|
|
1894
1889
|
"./services/swap-service/utils": {
|
|
1895
1890
|
"types": "./services/swap-service/utils.d.ts",
|
|
1896
1891
|
"require": "./cjs/services/swap-service/utils.js",
|
|
@@ -2642,7 +2637,6 @@
|
|
|
2642
2637
|
"@ethereumjs/common": "^4.1.0",
|
|
2643
2638
|
"@ethereumjs/tx": "^5.1.0",
|
|
2644
2639
|
"@ethersproject/abi": "^5.7.0",
|
|
2645
|
-
"@galacticcouncil/sdk": "^5.1.0",
|
|
2646
2640
|
"@gear-js/api": "^0.38.1",
|
|
2647
2641
|
"@json-rpc-tools/utils": "^1.7.6",
|
|
2648
2642
|
"@metamask/eth-sig-util": "^7.0.3",
|
|
@@ -2670,12 +2664,12 @@
|
|
|
2670
2664
|
"@sora-substrate/type-definitions": "^1.17.7",
|
|
2671
2665
|
"@substrate/connect": "^0.8.9",
|
|
2672
2666
|
"@subwallet/chain-list": "0.2.102",
|
|
2673
|
-
"@subwallet/extension-base": "^1.3.
|
|
2674
|
-
"@subwallet/extension-chains": "^1.3.
|
|
2675
|
-
"@subwallet/extension-dapp": "^1.3.
|
|
2676
|
-
"@subwallet/extension-inject": "^1.3.
|
|
2667
|
+
"@subwallet/extension-base": "^1.3.30-0",
|
|
2668
|
+
"@subwallet/extension-chains": "^1.3.30-0",
|
|
2669
|
+
"@subwallet/extension-dapp": "^1.3.30-0",
|
|
2670
|
+
"@subwallet/extension-inject": "^1.3.30-0",
|
|
2677
2671
|
"@subwallet/keyring": "^0.1.9",
|
|
2678
|
-
"@subwallet/subwallet-api-sdk": "^1.3.
|
|
2672
|
+
"@subwallet/subwallet-api-sdk": "^1.3.30-0",
|
|
2679
2673
|
"@subwallet/ui-keyring": "^0.1.9",
|
|
2680
2674
|
"@ton/core": "^0.56.3",
|
|
2681
2675
|
"@ton/crypto": "^3.2.0",
|
package/packageInfo.js
CHANGED
|
@@ -7,5 +7,5 @@ export const packageInfo = {
|
|
|
7
7
|
name: '@subwallet/extension-base',
|
|
8
8
|
path: (import.meta && import.meta.url) ? new URL(import.meta.url).pathname.substring(0, new URL(import.meta.url).pathname.lastIndexOf('/') + 1) : 'auto',
|
|
9
9
|
type: 'esm',
|
|
10
|
-
version: '1.3.
|
|
10
|
+
version: '1.3.30-0'
|
|
11
11
|
};
|
|
@@ -55,12 +55,12 @@ export async function getClaimTxOnAvail(notification, substrateApi) {
|
|
|
55
55
|
const chainApi = await substrateApi.isReady;
|
|
56
56
|
const chainSlug = chainApi.chainSlug;
|
|
57
57
|
const metadata = notification.metadata;
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const proof = await getClaimProofOnAvail(chainSlug,
|
|
61
|
-
return chainApi.api.tx.vector.execute(
|
|
58
|
+
const latestEthHeadSlot = await getLatestEthHeadSlot(chainSlug);
|
|
59
|
+
const latestBlockHash = await getLatestBlockHash(chainSlug, latestEthHeadSlot);
|
|
60
|
+
const proof = await getClaimProofOnAvail(chainSlug, latestBlockHash, metadata.messageId);
|
|
61
|
+
return chainApi.api.tx.vector.execute(latestEthHeadSlot, getAddressMessage(notification), proof.accountProof, proof.storageProof);
|
|
62
62
|
}
|
|
63
|
-
async function
|
|
63
|
+
async function getLatestEthHeadSlot(chainSlug) {
|
|
64
64
|
try {
|
|
65
65
|
const api = getAvailBridgeApi(chainSlug);
|
|
66
66
|
const rawResponse = await fetch(`${api}/eth/head`);
|
|
@@ -71,7 +71,7 @@ async function getLastestEthHeadSlot(chainSlug) {
|
|
|
71
71
|
throw e;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
|
-
async function
|
|
74
|
+
async function getLatestBlockHash(chainSlug, slot) {
|
|
75
75
|
try {
|
|
76
76
|
const api = getAvailBridgeApi(chainSlug);
|
|
77
77
|
const rawResponse = await fetch(`${api}/beacon/slot/${slot}`);
|
package/services/base/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { OptimalProcessParams, OptimalProcessResult } from '@subwallet/extension-base/types/service-base';
|
|
2
1
|
import { PromiseHandler } from '@subwallet/extension-base/utils/promise';
|
|
3
2
|
export declare enum ServiceStatus {
|
|
4
3
|
NOT_INITIALIZED = "not_initialized",
|
|
@@ -33,6 +32,3 @@ export interface CronServiceInterface {
|
|
|
33
32
|
startCron: () => Promise<void>;
|
|
34
33
|
stopCron: () => Promise<void>;
|
|
35
34
|
}
|
|
36
|
-
export interface ServiceWithProcessInterface {
|
|
37
|
-
generateOptimalProcess(params: OptimalProcessParams): Promise<OptimalProcessResult>;
|
|
38
|
-
}
|
|
@@ -278,7 +278,7 @@ export const _XCM_CHAIN_GROUP = {
|
|
|
278
278
|
// default is xTokens pallet
|
|
279
279
|
};
|
|
280
280
|
|
|
281
|
-
export const SUFFICIENT_CHAIN = ['astar', 'calamari', 'parallel', 'darwinia2', 'crabParachain', 'pangolin', 'statemint', 'moonriver', 'shiden', 'moonbeam', 'statemine', 'liberland', 'dentnet', 'phala', 'crust', 'dbcchain', 'rococo_assethub'
|
|
281
|
+
export const SUFFICIENT_CHAIN = ['astar', 'calamari', 'parallel', 'darwinia2', 'crabParachain', 'pangolin', 'statemint', 'moonriver', 'shiden', 'moonbeam', 'statemine', 'liberland', 'dentnet', 'phala', 'crust', 'dbcchain', 'rococo_assethub'];
|
|
282
282
|
export const _XCM_TYPE = {
|
|
283
283
|
RP: `${_SubstrateChainType.RELAYCHAIN}-${_SubstrateChainType.PARACHAIN}`,
|
|
284
284
|
// DMP
|
|
@@ -4,6 +4,7 @@ import { ChainType, ExtrinsicType } from '@subwallet/extension-base/background/K
|
|
|
4
4
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
5
5
|
import { _EvmApi, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
6
6
|
import { BasePoolInfo, BaseYieldPoolMetadata, EarningRewardHistoryItem, EarningRewardItem, HandleYieldStepData, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, RequestEarningSlippage, ResponseEarlyValidateYield, StakeCancelWithdrawalParams, SubmitYieldJoinData, TransactionData, UnstakingInfo, YieldPoolInfo, YieldPoolMethodInfo, YieldPoolTarget, YieldPoolType, YieldPositionInfo, YieldStepBaseInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
|
|
7
|
+
import { EarningSlippageResult } from './native-staking/dtao';
|
|
7
8
|
/**
|
|
8
9
|
* @class BasePoolHandler
|
|
9
10
|
* @description Base pool handler
|
|
@@ -101,11 +102,11 @@ export default abstract class BasePoolHandler {
|
|
|
101
102
|
/** Validate param to leave the pool */
|
|
102
103
|
abstract validateYieldLeave(amount: string, address: string, fastLeave: boolean, selectedTarget?: string, slug?: string, poolInfo?: YieldPoolInfo): Promise<TransactionError[]>;
|
|
103
104
|
/** Create `transaction` to leave the pool normal (default unstake) */
|
|
104
|
-
protected abstract handleYieldUnstake(amount: string, address: string, selectedTarget?: string, netuid?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
105
|
+
protected abstract handleYieldUnstake(amount: string, address: string, selectedTarget?: string, netuid?: number, slippage?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
105
106
|
/** Create `transaction` to leave the pool fast (swap token) */
|
|
106
107
|
protected abstract handleYieldRedeem(amount: string, address: string, selectedTarget?: string): Promise<[ExtrinsicType, TransactionData]>;
|
|
107
108
|
/** Create `transaction` to leave the pool */
|
|
108
|
-
handleYieldLeave(fastLeave: boolean, amount: string, address: string, selectedTarget?: string, netuid?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
109
|
+
handleYieldLeave(fastLeave: boolean, amount: string, address: string, selectedTarget?: string, netuid?: number, slippage?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
109
110
|
/** Create `transaction` to withdraw unstaked amount */
|
|
110
111
|
abstract handleYieldWithdraw(address: string, unstakingInfo: UnstakingInfo): Promise<TransactionData>;
|
|
111
112
|
/** Create `transaction` to cancel unstake */
|
|
@@ -114,5 +115,5 @@ export default abstract class BasePoolHandler {
|
|
|
114
115
|
abstract handleYieldClaimReward(address: string, bondReward?: boolean): Promise<TransactionData>;
|
|
115
116
|
/** Check handler can handle slug */
|
|
116
117
|
canHandleSlug(slug: string): boolean;
|
|
117
|
-
getEarningSlippage(params: RequestEarningSlippage): Promise<
|
|
118
|
+
getEarningSlippage(params: RequestEarningSlippage): Promise<EarningSlippageResult>;
|
|
118
119
|
}
|
|
@@ -7,7 +7,6 @@ import { DEFAULT_YIELD_FIRST_STEP } from '@subwallet/extension-base/services/ear
|
|
|
7
7
|
import { createClaimNotification, createWithdrawNotifications } from '@subwallet/extension-base/services/inapp-notification-service/utils';
|
|
8
8
|
import { formatNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
9
9
|
import { BN, BN_TEN } from '@polkadot/util';
|
|
10
|
-
|
|
11
10
|
/**
|
|
12
11
|
* @class BasePoolHandler
|
|
13
12
|
* @description Base pool handler
|
|
@@ -249,11 +248,11 @@ export default class BasePoolHandler {
|
|
|
249
248
|
/** Validate param to join the pool */
|
|
250
249
|
|
|
251
250
|
/** Create `transaction` to leave the pool */
|
|
252
|
-
async handleYieldLeave(fastLeave, amount, address, selectedTarget, netuid) {
|
|
251
|
+
async handleYieldLeave(fastLeave, amount, address, selectedTarget, netuid, slippage) {
|
|
253
252
|
if (fastLeave) {
|
|
254
253
|
return this.handleYieldRedeem(amount, address, selectedTarget);
|
|
255
254
|
} else {
|
|
256
|
-
return this.handleYieldUnstake(amount, address, selectedTarget, netuid);
|
|
255
|
+
return this.handleYieldUnstake(amount, address, selectedTarget, netuid, slippage);
|
|
257
256
|
}
|
|
258
257
|
}
|
|
259
258
|
|
|
@@ -268,7 +267,10 @@ export default class BasePoolHandler {
|
|
|
268
267
|
return this.slug === slug;
|
|
269
268
|
}
|
|
270
269
|
getEarningSlippage(params) {
|
|
271
|
-
return Promise.resolve(
|
|
270
|
+
return Promise.resolve({
|
|
271
|
+
slippage: 0,
|
|
272
|
+
rate: 1
|
|
273
|
+
});
|
|
272
274
|
}
|
|
273
275
|
/* Other actions */
|
|
274
276
|
}
|
|
@@ -102,7 +102,10 @@ export default class BaseNativeStakingPoolHandler extends BasePoolHandler {
|
|
|
102
102
|
address,
|
|
103
103
|
slug,
|
|
104
104
|
selectedValidators,
|
|
105
|
-
|
|
105
|
+
subnetData: {
|
|
106
|
+
netuid: netuid || 0,
|
|
107
|
+
slippage: 0
|
|
108
|
+
}
|
|
106
109
|
};
|
|
107
110
|
const positionInfo = await this.getPoolPosition(address);
|
|
108
111
|
const [, fee] = await this.createJoinExtrinsic(data, positionInfo);
|
|
@@ -2,10 +2,9 @@ import { _ChainInfo } from '@subwallet/chain-list/types';
|
|
|
2
2
|
import { TransactionError } from '@subwallet/extension-base/background/errors/TransactionError';
|
|
3
3
|
import { ExtrinsicType } from '@subwallet/extension-base/background/KoniTypes';
|
|
4
4
|
import KoniState from '@subwallet/extension-base/koni/background/handlers/State';
|
|
5
|
-
import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
|
|
6
5
|
import BaseParaStakingPoolHandler from '@subwallet/extension-base/services/earning-service/handlers/native-staking/base-para';
|
|
7
6
|
import { BaseYieldPositionInfo, OptimalYieldPath, RequestEarningSlippage, StakeCancelWithdrawalParams, SubmitJoinNativeStaking, TransactionData, UnstakingInfo, ValidatorInfo, YieldPoolInfo, YieldPoolMethodInfo, YieldPoolType, YieldPositionInfo, YieldTokenBaseInfo } from '@subwallet/extension-base/types';
|
|
8
|
-
import
|
|
7
|
+
import BigN from 'bignumber.js';
|
|
9
8
|
export interface SubnetData {
|
|
10
9
|
netuid: number;
|
|
11
10
|
name: string;
|
|
@@ -13,11 +12,12 @@ export interface SubnetData {
|
|
|
13
12
|
ownerHotkey: string;
|
|
14
13
|
maxAllowedValidators: number;
|
|
15
14
|
taoIn: number;
|
|
15
|
+
taoInEmission: number;
|
|
16
16
|
}
|
|
17
17
|
interface TaoStakingStakeOption {
|
|
18
18
|
owner: string;
|
|
19
19
|
amount: string;
|
|
20
|
-
rate?:
|
|
20
|
+
rate?: BigN;
|
|
21
21
|
identity?: string;
|
|
22
22
|
}
|
|
23
23
|
export interface RawDelegateState {
|
|
@@ -36,8 +36,11 @@ export interface TestnetBittensorDelegateInfo {
|
|
|
36
36
|
nominators: Nominators;
|
|
37
37
|
returnPer1000: number;
|
|
38
38
|
}
|
|
39
|
+
export interface EarningSlippageResult {
|
|
40
|
+
slippage: number;
|
|
41
|
+
rate: number;
|
|
42
|
+
}
|
|
39
43
|
export declare const DEFAULT_DTAO_MINBOND = "600000";
|
|
40
|
-
export declare const getAlphaToTaoMapping: (substrateApi: _SubstrateApi) => Promise<Record<number, string>>;
|
|
41
44
|
export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHandler {
|
|
42
45
|
handleYieldWithdraw(address: string, unstakingInfo: UnstakingInfo): Promise<TransactionData>;
|
|
43
46
|
handleYieldCancelUnstake(params: StakeCancelWithdrawalParams): Promise<TransactionData>;
|
|
@@ -51,7 +54,7 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
51
54
|
readonly availableMethod: YieldPoolMethodInfo;
|
|
52
55
|
constructor(state: KoniState, chain: string);
|
|
53
56
|
canHandleSlug(slug: string): boolean;
|
|
54
|
-
getEarningSlippage(params: RequestEarningSlippage): Promise<
|
|
57
|
+
getEarningSlippage(params: RequestEarningSlippage): Promise<EarningSlippageResult>;
|
|
55
58
|
get maintainBalance(): string;
|
|
56
59
|
private init;
|
|
57
60
|
protected getDescription(): string;
|
|
@@ -63,7 +66,7 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
63
66
|
getPoolTargets(): Promise<ValidatorInfo[]>;
|
|
64
67
|
createJoinExtrinsic(data: SubmitJoinNativeStaking, positionInfo?: YieldPositionInfo, bondDest?: string): Promise<[TransactionData, YieldTokenBaseInfo]>;
|
|
65
68
|
validateYieldJoin(data: SubmitJoinNativeStaking, path: OptimalYieldPath): Promise<TransactionError[]>;
|
|
66
|
-
handleYieldUnstake(amount: string, address: string, selectedTarget?: string, netuid?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
69
|
+
handleYieldUnstake(amount: string, address: string, selectedTarget?: string, netuid?: number, slippage?: number): Promise<[ExtrinsicType, TransactionData]>;
|
|
67
70
|
validateYieldLeave(amount: string, address: string, fastLeave: boolean, selectedTarget?: string, slug?: string, poolInfo?: YieldPoolInfo): Promise<TransactionError[]>;
|
|
68
71
|
}
|
|
69
72
|
export {};
|
|
@@ -9,31 +9,38 @@ import { _getAssetDecimals, _getAssetSymbol } from '@subwallet/extension-base/se
|
|
|
9
9
|
import BaseParaStakingPoolHandler from '@subwallet/extension-base/services/earning-service/handlers/native-staking/base-para';
|
|
10
10
|
import { BasicTxErrorType, EarningStatus, YieldPoolType } from '@subwallet/extension-base/types';
|
|
11
11
|
import { formatNumber, reformatAddress } from '@subwallet/extension-base/utils';
|
|
12
|
-
import BigN
|
|
12
|
+
import BigN from 'bignumber.js';
|
|
13
13
|
import { t } from 'i18next';
|
|
14
|
-
import { BN,
|
|
14
|
+
import { BN, BN_ZERO } from '@polkadot/util';
|
|
15
15
|
import { calculateReward } from "../../utils/index.js";
|
|
16
16
|
import { BittensorCache } from "./tao.js";
|
|
17
17
|
const DEFAULT_BITTENSOR_SLIPPAGE = 0.005;
|
|
18
18
|
export const DEFAULT_DTAO_MINBOND = '600000';
|
|
19
|
-
|
|
19
|
+
const getAlphaToTaoMapping = async substrateApi => {
|
|
20
20
|
const allSubnets = (await substrateApi.api.call.subnetInfoRuntimeApi.getAllDynamicInfo()).toJSON();
|
|
21
|
-
if (!allSubnets) {
|
|
21
|
+
if (!allSubnets || allSubnets.length === 0) {
|
|
22
22
|
return {};
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
const result = Object.create(null);
|
|
25
|
+
for (const subnet of allSubnets) {
|
|
25
26
|
const netuid = subnet === null || subnet === void 0 ? void 0 : subnet.netuid;
|
|
27
|
+
if (netuid === undefined) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
26
30
|
const taoIn = subnet !== null && subnet !== void 0 && subnet.taoIn ? new BigN(subnet.taoIn) : new BigN(0);
|
|
27
31
|
const alphaIn = subnet !== null && subnet !== void 0 && subnet.alphaIn ? new BigN(subnet.alphaIn) : new BigN(0);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
36
|
-
}
|
|
32
|
+
result[netuid] = netuid === 0 || alphaIn.lte(0) ? '1' : taoIn.dividedBy(alphaIn).toString();
|
|
33
|
+
}
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
const getAlphaToTaoRate = async (substrateApi, netuid) => {
|
|
37
|
+
const subnetInfo = (await substrateApi.api.call.subnetInfoRuntimeApi.getDynamicInfo(netuid)).toJSON();
|
|
38
|
+
if (!subnetInfo) {
|
|
39
|
+
return '1';
|
|
40
|
+
}
|
|
41
|
+
const taoIn = subnetInfo.taoIn ? new BigN(subnetInfo.taoIn) : new BigN(0);
|
|
42
|
+
const alphaIn = subnetInfo.alphaIn ? new BigN(subnetInfo.alphaIn) : new BigN(0);
|
|
43
|
+
return netuid === 0 || alphaIn.lte(0) ? '1' : taoIn.dividedBy(alphaIn).toString();
|
|
37
44
|
};
|
|
38
45
|
export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHandler {
|
|
39
46
|
/* Unimplemented function */
|
|
@@ -73,30 +80,40 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
73
80
|
async getEarningSlippage(params) {
|
|
74
81
|
const substrateApi = await this.substrateApi.isReady;
|
|
75
82
|
const subnetInfo = (await substrateApi.api.call.subnetInfoRuntimeApi.getDynamicInfo(params.netuid)).toJSON();
|
|
76
|
-
const alphaIn = new
|
|
77
|
-
const taoIn = new
|
|
83
|
+
const alphaIn = new BigN((subnetInfo === null || subnetInfo === void 0 ? void 0 : subnetInfo.alphaIn) || 0);
|
|
84
|
+
const taoIn = new BigN((subnetInfo === null || subnetInfo === void 0 ? void 0 : subnetInfo.taoIn) || 0);
|
|
78
85
|
const k = alphaIn.multipliedBy(taoIn);
|
|
79
|
-
const value = new
|
|
86
|
+
const value = new BigN(params.value);
|
|
87
|
+
const rate = taoIn.dividedBy(alphaIn);
|
|
80
88
|
if (params.type === ExtrinsicType.STAKING_BOND) {
|
|
81
89
|
const newTaoIn = taoIn.plus(value);
|
|
82
90
|
const newAlphaIn = k.dividedBy(newTaoIn);
|
|
83
91
|
const alphaReturned = alphaIn.minus(newAlphaIn);
|
|
84
92
|
const alphaIdeal = value.multipliedBy(alphaIn).dividedBy(taoIn);
|
|
85
93
|
const slippage = alphaIdeal.minus(alphaReturned).dividedBy(alphaIdeal);
|
|
86
|
-
return
|
|
94
|
+
return {
|
|
95
|
+
slippage: slippage.plus(0.0001).toNumber(),
|
|
96
|
+
rate: rate.toNumber()
|
|
97
|
+
};
|
|
87
98
|
} else if (params.type === ExtrinsicType.STAKING_UNBOND) {
|
|
88
99
|
const newAlphaIn = alphaIn.plus(value);
|
|
89
100
|
const newTaoReserve = k.dividedBy(newAlphaIn);
|
|
90
101
|
const taoReturned = taoIn.minus(newTaoReserve);
|
|
91
102
|
const taoIdeal = value.multipliedBy(taoIn).dividedBy(alphaIn);
|
|
92
103
|
const slippage = taoIdeal.minus(taoReturned).dividedBy(taoIdeal);
|
|
93
|
-
return
|
|
104
|
+
return {
|
|
105
|
+
slippage: slippage.plus(0.0001).toNumber(),
|
|
106
|
+
rate: rate.toNumber()
|
|
107
|
+
};
|
|
94
108
|
}
|
|
95
|
-
return
|
|
109
|
+
return {
|
|
110
|
+
slippage: 0,
|
|
111
|
+
rate: 1
|
|
112
|
+
};
|
|
96
113
|
}
|
|
97
114
|
get maintainBalance() {
|
|
98
|
-
const ed = new
|
|
99
|
-
const calculateMaintainBalance = new
|
|
115
|
+
const ed = new BigN(this.nativeToken.minAmount || '0');
|
|
116
|
+
const calculateMaintainBalance = new BigN(15).multipliedBy(ed).dividedBy(10);
|
|
100
117
|
const maintainBalance = calculateMaintainBalance;
|
|
101
118
|
return maintainBalance.toString();
|
|
102
119
|
}
|
|
@@ -123,7 +140,8 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
123
140
|
symbol,
|
|
124
141
|
ownerHotkey: dynInfo.ownerHotkey,
|
|
125
142
|
maxAllowedValidators: extraInfo ? extraInfo.maxAllowedValidators : 0,
|
|
126
|
-
taoIn: dynInfo.taoIn
|
|
143
|
+
taoIn: dynInfo.taoIn,
|
|
144
|
+
taoInEmission: dynInfo.taoInEmission
|
|
127
145
|
};
|
|
128
146
|
});
|
|
129
147
|
this.subnetData = mergedData;
|
|
@@ -153,7 +171,8 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
153
171
|
const netuid = subnet.netuid.toString().padStart(2, '0');
|
|
154
172
|
const subnetSlug = `${this.slug}__subnet_${netuid.padStart(2, '0')}`;
|
|
155
173
|
const subnetName = `${subnet.name || 'Unknown'} ${netuid}`;
|
|
156
|
-
const bnTaoIn = new
|
|
174
|
+
const bnTaoIn = new BigN(subnet.taoIn);
|
|
175
|
+
const emission = new BigN(subnet.taoInEmission).dividedBy(new BigN(10).pow(new BigN(7)));
|
|
157
176
|
const data = {
|
|
158
177
|
...this.baseInfo,
|
|
159
178
|
type: this.type,
|
|
@@ -182,7 +201,8 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
182
201
|
eraTime: 24,
|
|
183
202
|
era: 0,
|
|
184
203
|
unstakingPeriod: 1.2,
|
|
185
|
-
tvl: bnTaoIn.toString()
|
|
204
|
+
tvl: bnTaoIn.toString(),
|
|
205
|
+
totalApy: emission.toNumber()
|
|
186
206
|
}
|
|
187
207
|
};
|
|
188
208
|
callback(data);
|
|
@@ -350,7 +370,7 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
350
370
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
351
371
|
async getDevnetPoolTargets() {
|
|
352
372
|
const testnetDelegate = (await this.substrateApi.api.call.delegateInfoRuntimeApi.getDelegates()).toJSON();
|
|
353
|
-
const bnMinBond = new
|
|
373
|
+
const bnMinBond = new BigN(DEFAULT_DTAO_MINBOND);
|
|
354
374
|
const filteredDelegates = testnetDelegate.filter(delegate => {
|
|
355
375
|
return delegate.returnPer1000 !== 0;
|
|
356
376
|
});
|
|
@@ -371,14 +391,14 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
371
391
|
async getMainnetPoolTargets() {
|
|
372
392
|
const _topValidator = await this.bittensorCache.get();
|
|
373
393
|
const topValidator = _topValidator;
|
|
374
|
-
const bnMinBond = new
|
|
394
|
+
const bnMinBond = new BigN(DEFAULT_DTAO_MINBOND);
|
|
375
395
|
const validatorList = topValidator.data;
|
|
376
396
|
const validatorAddresses = Object.keys(validatorList);
|
|
377
397
|
const results = await Promise.all(validatorAddresses.map(i => {
|
|
378
398
|
const address = validatorList[i].hotkey.ss58;
|
|
379
|
-
const bnTotalStake = new
|
|
380
|
-
const bnOwnStake = new
|
|
381
|
-
const otherStake = bnTotalStake.
|
|
399
|
+
const bnTotalStake = new BigN(validatorList[i].stake);
|
|
400
|
+
const bnOwnStake = new BigN(validatorList[i].validator_stake);
|
|
401
|
+
const otherStake = bnTotalStake.minus(bnOwnStake);
|
|
382
402
|
const nominatorCount = validatorList[i].nominators;
|
|
383
403
|
const commission = validatorList[i].take;
|
|
384
404
|
const roundedCommission = (parseFloat(commission) * 100).toFixed(0);
|
|
@@ -419,15 +439,18 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
419
439
|
async createJoinExtrinsic(data, positionInfo, bondDest = 'Staked') {
|
|
420
440
|
const {
|
|
421
441
|
amount,
|
|
422
|
-
|
|
423
|
-
|
|
442
|
+
selectedValidators: targetValidators,
|
|
443
|
+
subnetData
|
|
424
444
|
} = data;
|
|
445
|
+
const {
|
|
446
|
+
netuid,
|
|
447
|
+
slippage
|
|
448
|
+
} = subnetData;
|
|
425
449
|
const chainApi = await this.substrateApi.isReady;
|
|
426
|
-
const binaryAmount = new
|
|
427
|
-
const
|
|
428
|
-
const
|
|
429
|
-
const
|
|
430
|
-
const BNlimitPrice = new BN(limitPrice.integerValue(BigNumber.ROUND_CEIL).toFixed());
|
|
450
|
+
const binaryAmount = new BigN(amount);
|
|
451
|
+
const alphaToTaoPrice = new BigN(await getAlphaToTaoRate(this.substrateApi, netuid));
|
|
452
|
+
const limitPrice = alphaToTaoPrice.multipliedBy(10 ** _getAssetDecimals(this.nativeToken)).multipliedBy(1 + (slippage || DEFAULT_BITTENSOR_SLIPPAGE));
|
|
453
|
+
const BNlimitPrice = new BigN(limitPrice.integerValue(BigN.ROUND_CEIL).toFixed());
|
|
431
454
|
const selectedValidatorInfo = targetValidators[0];
|
|
432
455
|
const hotkey = selectedValidatorInfo.address;
|
|
433
456
|
const extrinsic = chainApi.api.tx.subtensorModule.addStakeLimit(hotkey, netuid, binaryAmount, BNlimitPrice, false);
|
|
@@ -444,7 +467,7 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
444
467
|
const {
|
|
445
468
|
amount
|
|
446
469
|
} = data;
|
|
447
|
-
if (new
|
|
470
|
+
if (new BigN(amount).lt(new BigN(DEFAULT_DTAO_MINBOND))) {
|
|
448
471
|
return [new TransactionError(BasicTxErrorType.INVALID_PARAMS, t(`Insufficient stake. You need to stake at least ${formatNumber(DEFAULT_DTAO_MINBOND, _getAssetDecimals(this.nativeToken))} ${_getAssetSymbol(this.nativeToken)} to earn rewards`))];
|
|
449
472
|
}
|
|
450
473
|
return baseErrors;
|
|
@@ -454,16 +477,15 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
454
477
|
|
|
455
478
|
/* Leave pool action */
|
|
456
479
|
|
|
457
|
-
async handleYieldUnstake(amount, address, selectedTarget, netuid) {
|
|
480
|
+
async handleYieldUnstake(amount, address, selectedTarget, netuid, slippage) {
|
|
458
481
|
const apiPromise = await this.substrateApi.isReady;
|
|
459
|
-
const binaryAmount = new BN(amount);
|
|
460
|
-
const price = await getAlphaToTaoMapping(this.substrateApi);
|
|
461
|
-
const alphaToTaoPrice = new BigN(price[netuid]);
|
|
462
|
-
const limitPrice = alphaToTaoPrice.multipliedBy(10 ** _getAssetDecimals(this.nativeToken)).multipliedBy(1 - DEFAULT_BITTENSOR_SLIPPAGE);
|
|
463
|
-
const BNlimitPrice = new BN(limitPrice.integerValue(BigNumber.ROUND_CEIL).toFixed());
|
|
464
482
|
if (!selectedTarget) {
|
|
465
483
|
return Promise.reject(new TransactionError(BasicTxErrorType.INVALID_PARAMS));
|
|
466
484
|
}
|
|
485
|
+
const binaryAmount = new BigN(amount);
|
|
486
|
+
const alphaToTaoPrice = new BigN(await getAlphaToTaoRate(this.substrateApi, netuid || 0));
|
|
487
|
+
const limitPrice = alphaToTaoPrice.multipliedBy(10 ** _getAssetDecimals(this.nativeToken)).multipliedBy(1 - (slippage || DEFAULT_BITTENSOR_SLIPPAGE));
|
|
488
|
+
const BNlimitPrice = new BigN(limitPrice.integerValue(BigN.ROUND_CEIL).toFixed());
|
|
467
489
|
const extrinsic = apiPromise.api.tx.subtensorModule.removeStakeLimit(selectedTarget, netuid, binaryAmount, BNlimitPrice, false);
|
|
468
490
|
return [ExtrinsicType.STAKING_UNBOND, extrinsic];
|
|
469
491
|
}
|
|
@@ -477,10 +499,9 @@ export default class SubnetTaoStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
477
499
|
return [new TransactionError(BasicTxErrorType.INVALID_PARAMS)];
|
|
478
500
|
}
|
|
479
501
|
const netuid = (_poolInfo$metadata$su = poolInfo.metadata.subnetData) === null || _poolInfo$metadata$su === void 0 ? void 0 : _poolInfo$metadata$su.netuid;
|
|
480
|
-
const
|
|
481
|
-
const minUnstake = new BigN(DEFAULT_DTAO_MINBOND).dividedBy(
|
|
482
|
-
|
|
483
|
-
const formattedMinUnstake = minUnstake.dividedBy(1000000).integerValue(BigNumber.ROUND_CEIL).dividedBy(1000);
|
|
502
|
+
const alphaToTaoPrice = new BigN(await getAlphaToTaoRate(this.substrateApi, netuid || 0));
|
|
503
|
+
const minUnstake = new BigN(DEFAULT_DTAO_MINBOND).dividedBy(alphaToTaoPrice);
|
|
504
|
+
const formattedMinUnstake = minUnstake.dividedBy(1000000).integerValue(BigN.ROUND_CEIL).dividedBy(1000);
|
|
484
505
|
if (new BigN(amount).lt(formattedMinUnstake.multipliedBy(10 ** _getAssetDecimals(this.nativeToken)))) {
|
|
485
506
|
var _poolInfo$metadata$su2;
|
|
486
507
|
return [new TransactionError(BasicTxErrorType.INVALID_PARAMS, t(`Amount too low. You need to unstake at least ${formattedMinUnstake.toString()} ${((_poolInfo$metadata$su2 = poolInfo.metadata.subnetData) === null || _poolInfo$metadata$su2 === void 0 ? void 0 : _poolInfo$metadata$su2.subnetSymbol) || ''}`))];
|
|
@@ -61,7 +61,7 @@ export class BittensorCache {
|
|
|
61
61
|
async fetchData() {
|
|
62
62
|
const apiKey = bittensorApiKey();
|
|
63
63
|
try {
|
|
64
|
-
const resp = await fetch('https://api.taostats.io/api/validator/latest/v1?limit=
|
|
64
|
+
const resp = await fetch('https://api.taostats.io/api/validator/latest/v1?limit=50', {
|
|
65
65
|
method: 'GET',
|
|
66
66
|
headers: {
|
|
67
67
|
'Content-Type': 'application/json',
|
|
@@ -173,8 +173,17 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
173
173
|
const minDelegatorStake = (await substrateApi.api.query.subtensorModule.nominatorMinRequiredStake()).toPrimitive() || 0;
|
|
174
174
|
const maxValidatorPerNominator = (await substrateApi.api.query.subtensorModule.maxAllowedValidators(0)).toPrimitive();
|
|
175
175
|
const taoIn = (await substrateApi.api.query.subtensorModule.subnetTAO(0)).toPrimitive();
|
|
176
|
+
const _topValidator = await this.bittensorCache.get();
|
|
177
|
+
const validators = _topValidator.data;
|
|
178
|
+
let highestApr = validators[0];
|
|
179
|
+
for (let i = 1; i < validators.length; i++) {
|
|
180
|
+
if (parseFloat(validators[i].apr) > parseFloat(highestApr.apr)) {
|
|
181
|
+
highestApr = validators[i];
|
|
182
|
+
}
|
|
183
|
+
}
|
|
176
184
|
const bnTaoIn = new BN(taoIn);
|
|
177
185
|
const BNminDelegatorStake = new BigN(minDelegatorStake.toString());
|
|
186
|
+
const apr = this.chain === 'bittensor' ? Number(highestApr.apr) * 100 : 0;
|
|
178
187
|
const data = {
|
|
179
188
|
...this.baseInfo,
|
|
180
189
|
type: this.type,
|
|
@@ -196,7 +205,8 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand
|
|
|
196
205
|
eraTime: 24,
|
|
197
206
|
era: 0,
|
|
198
207
|
unstakingPeriod: 1.2,
|
|
199
|
-
tvl: bnTaoIn.toString()
|
|
208
|
+
tvl: bnTaoIn.toString(),
|
|
209
|
+
totalApy: apr
|
|
200
210
|
}
|
|
201
211
|
};
|
|
202
212
|
callback(data);
|
|
@@ -6,6 +6,7 @@ import { PersistDataServiceInterface, ServiceStatus, StoppableServiceInterface }
|
|
|
6
6
|
import { EarningRewardHistoryItem, EarningRewardItem, EarningRewardJson, HandleYieldStepData, HandleYieldStepParams, OptimalYieldPath, OptimalYieldPathParams, RequestEarlyValidateYield, RequestEarningSlippage, RequestStakeCancelWithdrawal, RequestStakeClaimReward, RequestYieldLeave, RequestYieldWithdrawal, ResponseEarlyValidateYield, TransactionData, ValidateYieldProcessParams, YieldPoolInfo, YieldPoolTarget, YieldPositionInfo } from '@subwallet/extension-base/types';
|
|
7
7
|
import { PromiseHandler } from '@subwallet/extension-base/utils';
|
|
8
8
|
import { BehaviorSubject } from 'rxjs';
|
|
9
|
+
import { EarningSlippageResult } from './handlers/native-staking/dtao';
|
|
9
10
|
import { BasePoolHandler } from './handlers';
|
|
10
11
|
export default class EarningService implements StoppableServiceInterface, PersistDataServiceInterface {
|
|
11
12
|
protected readonly state: KoniState;
|
|
@@ -98,6 +99,6 @@ export default class EarningService implements StoppableServiceInterface, Persis
|
|
|
98
99
|
handleYieldWithdraw(params: RequestYieldWithdrawal): Promise<TransactionData>;
|
|
99
100
|
handleYieldCancelUnstake(params: RequestStakeCancelWithdrawal): Promise<TransactionData>;
|
|
100
101
|
handleYieldClaimReward(params: RequestStakeClaimReward): Promise<TransactionData>;
|
|
101
|
-
yieldGetEarningSlippage(params: RequestEarningSlippage): Promise<
|
|
102
|
+
yieldGetEarningSlippage(params: RequestEarningSlippage): Promise<EarningSlippageResult>;
|
|
102
103
|
resetWallet(): Promise<void>;
|
|
103
104
|
}
|
|
@@ -755,8 +755,9 @@ export default class EarningService {
|
|
|
755
755
|
} = params;
|
|
756
756
|
const handler = this.getPoolHandler(slug);
|
|
757
757
|
const netuid = (_params$poolInfo$meta = params.poolInfo.metadata.subnetData) === null || _params$poolInfo$meta === void 0 ? void 0 : _params$poolInfo$meta.netuid;
|
|
758
|
+
const slippage = params.slippage;
|
|
758
759
|
if (handler) {
|
|
759
|
-
return handler.handleYieldLeave(params.fastLeave, params.amount, params.address, params.selectedTarget, netuid);
|
|
760
|
+
return handler.handleYieldLeave(params.fastLeave, params.amount, params.address, params.selectedTarget, netuid, slippage);
|
|
760
761
|
} else {
|
|
761
762
|
return Promise.reject(new TransactionError(BasicTxErrorType.INTERNAL_ERROR));
|
|
762
763
|
}
|
|
@@ -11,4 +11,5 @@ export declare const fetchOnlineFeeData: (chainId: number, networkKey: string, u
|
|
|
11
11
|
export declare const recalculateGasPrice: (_price: string, chain: string) => string;
|
|
12
12
|
export declare const getEIP1559GasFee: (baseFee: BigN, maxPriorityFee: BigN, blockNumber: number, blockTime: number) => EvmEIP1559FeeOption;
|
|
13
13
|
export declare const calculateGasFeeParams: (web3: _EvmApi, networkKey: string, useOnline?: boolean, useInfura?: boolean) => Promise<EvmFeeInfo>;
|
|
14
|
+
export declare const enforceMinOneTip: (feeOptionDetail: EvmEIP1559FeeOption) => EvmEIP1559FeeOption;
|
|
14
15
|
export declare const calculateToAmountByReservePool: (api: ApiPromise, fromToken: _ChainAsset, toToken: _ChainAsset, fromAmount: string) => Promise<string>;
|
|
@@ -10,7 +10,7 @@ const INFURA_API_KEY = process.env.INFURA_API_KEY || '';
|
|
|
10
10
|
const INFURA_API_KEY_SECRET = process.env.INFURA_API_KEY_SECRET || '';
|
|
11
11
|
const INFURA_AUTH = 'Basic ' + Buffer.from(INFURA_API_KEY + ':' + INFURA_API_KEY_SECRET).toString('base64');
|
|
12
12
|
export const FEE_COVERAGE_PERCENTAGE_SPECIAL_CASE = 105; // percentage
|
|
13
|
-
|
|
13
|
+
const EIP1559_MIN_PRIORITY_FEE = '1';
|
|
14
14
|
export const parseInfuraFee = (info, threshold) => {
|
|
15
15
|
const base = new BigN(info.estimatedBaseFee).multipliedBy(BN_WEI);
|
|
16
16
|
const thresholdBN = new BigN(threshold.busyThreshold).multipliedBy(BN_WEI);
|
|
@@ -161,15 +161,18 @@ export const calculateGasFeeParams = async (web3, networkKey, useOnline = true,
|
|
|
161
161
|
const slowPriorityFee = history.reward.reduce((previous, rewards) => previous.plus(rewards[0]), BN_ZERO).dividedBy(numBlock).decimalPlaces(0);
|
|
162
162
|
const averagePriorityFee = history.reward.reduce((previous, rewards) => previous.plus(rewards[1]), BN_ZERO).dividedBy(numBlock).decimalPlaces(0);
|
|
163
163
|
const fastPriorityFee = history.reward.reduce((previous, rewards) => previous.plus(rewards[2]), BN_ZERO).dividedBy(numBlock).decimalPlaces(0);
|
|
164
|
+
if (slowPriorityFee.eq(0) && averagePriorityFee.eq(0) && fastPriorityFee.eq(0)) {
|
|
165
|
+
throw new Error('Fee rates are currently same for all levels');
|
|
166
|
+
}
|
|
164
167
|
return {
|
|
165
168
|
type: 'evm',
|
|
166
169
|
gasPrice: undefined,
|
|
167
170
|
baseGasFee: baseGasFee.toString(),
|
|
168
171
|
busyNetwork,
|
|
169
172
|
options: {
|
|
170
|
-
slow: getEIP1559GasFee(baseGasFee, slowPriorityFee, 10, blockTime),
|
|
171
|
-
average: getEIP1559GasFee(baseGasFee, averagePriorityFee, 5, blockTime),
|
|
172
|
-
fast: getEIP1559GasFee(baseGasFee, fastPriorityFee, 3, blockTime),
|
|
173
|
+
slow: enforceMinOneTip(getEIP1559GasFee(baseGasFee, slowPriorityFee, 10, blockTime)),
|
|
174
|
+
average: enforceMinOneTip(getEIP1559GasFee(baseGasFee, averagePriorityFee, 5, blockTime)),
|
|
175
|
+
fast: enforceMinOneTip(getEIP1559GasFee(baseGasFee, fastPriorityFee, 3, blockTime)),
|
|
173
176
|
default: busyNetwork ? 'average' : 'slow'
|
|
174
177
|
}
|
|
175
178
|
};
|
|
@@ -185,6 +188,13 @@ export const calculateGasFeeParams = async (web3, networkKey, useOnline = true,
|
|
|
185
188
|
};
|
|
186
189
|
}
|
|
187
190
|
};
|
|
191
|
+
export const enforceMinOneTip = feeOptionDetail => {
|
|
192
|
+
if (feeOptionDetail.maxPriorityFeePerGas === '0') {
|
|
193
|
+
feeOptionDetail.maxPriorityFeePerGas = EIP1559_MIN_PRIORITY_FEE;
|
|
194
|
+
return feeOptionDetail;
|
|
195
|
+
}
|
|
196
|
+
return feeOptionDetail;
|
|
197
|
+
};
|
|
188
198
|
export const calculateToAmountByReservePool = async (api, fromToken, toToken, fromAmount) => {
|
|
189
199
|
const reserve = await getReserveForPool(api, fromToken, toToken);
|
|
190
200
|
return estimateTokensForPool(fromAmount, reserve);
|