@pioneer-platform/helpers 4.8.0 → 4.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/lib/helpers/asset.d.ts +3 -2
- package/lib/helpers/asset.js +89 -88
- package/lib/helpers/liquidity.js +2 -2
- package/lib/helpers/memo.d.ts +2 -2
- package/lib/helpers/memo.js +9 -9
- package/lib/helpers/validators.js +2 -2
- package/lib/modules/assetValue.d.ts +2 -2
- package/lib/modules/assetValue.js +19 -18
- package/lib/modules/bigIntArithmetics.js +2 -2
- package/package.json +4 -4
- package/src/helpers/asset.ts +3 -2
- package/src/helpers/liquidity.ts +1 -1
- package/src/helpers/memo.ts +2 -2
- package/src/helpers/validators.ts +1 -1
- package/src/modules/assetValue.ts +5 -4
- package/src/modules/bigIntArithmetics.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @pioneer-platform/helpers
|
|
2
2
|
|
|
3
|
+
## 4.8.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- change address work
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
- @pioneer-platform/tokens@0.8.2
|
|
10
|
+
|
|
11
|
+
## 4.8.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- clean packages
|
|
16
|
+
- Updated dependencies
|
|
17
|
+
- @pioneer-platform/tokens@0.8.1
|
|
18
|
+
|
|
3
19
|
## 4.8.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/lib/helpers/asset.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Chain
|
|
1
|
+
import { Chain } from '@pioneer-platform/pioneer-caip';
|
|
2
|
+
import { FeeOption } from '@pioneer-platform/pioneer-types';
|
|
2
3
|
export type CommonAssetString = 'MAYA.MAYA' | 'ETH.THOR' | 'ETH.vTHOR' | Chain;
|
|
3
4
|
export declare const getDecimal: ({ chain, symbol }: {
|
|
4
5
|
chain: Chain;
|
|
5
6
|
symbol: string;
|
|
6
|
-
}) => Promise<
|
|
7
|
+
}) => Promise<any>;
|
|
7
8
|
export declare const gasFeeMultiplier: Record<FeeOption, number>;
|
|
8
9
|
export declare const isGasAsset: ({ chain, symbol }: {
|
|
9
10
|
chain: Chain;
|
package/lib/helpers/asset.js
CHANGED
|
@@ -10,12 +10,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.filterAssets = exports.assetFromString = exports.getAssetType = exports.getCommonAssetInfo = exports.isGasAsset = exports.gasFeeMultiplier = exports.getDecimal = void 0;
|
|
13
|
-
const
|
|
13
|
+
const pioneer_caip_1 = require("@pioneer-platform/pioneer-caip");
|
|
14
|
+
const pioneer_types_1 = require("@pioneer-platform/pioneer-types");
|
|
14
15
|
const index_1 = require("../index");
|
|
15
16
|
const getDecimalMethodHex = '0x313ce567';
|
|
16
17
|
const getContractDecimals = (_a) => __awaiter(void 0, [_a], void 0, function* ({ chain, to }) {
|
|
17
18
|
try {
|
|
18
|
-
const { result } = yield index_1.RequestClient.post(
|
|
19
|
+
const { result } = yield index_1.RequestClient.post(pioneer_caip_1.ChainToRPC[chain], {
|
|
19
20
|
headers: {
|
|
20
21
|
accept: '*/*',
|
|
21
22
|
'content-type': 'application/json',
|
|
@@ -33,76 +34,76 @@ const getContractDecimals = (_a) => __awaiter(void 0, [_a], void 0, function* ({
|
|
|
33
34
|
catch (error) {
|
|
34
35
|
console.error(error);
|
|
35
36
|
// @ts-ignore
|
|
36
|
-
return
|
|
37
|
+
return pioneer_caip_1.BaseDecimal[chain];
|
|
37
38
|
}
|
|
38
39
|
});
|
|
39
40
|
const getETHAssetDecimal = (symbol) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
-
if (symbol ===
|
|
41
|
-
return
|
|
41
|
+
if (symbol === pioneer_caip_1.Chain.Ethereum)
|
|
42
|
+
return pioneer_caip_1.BaseDecimal.ETH;
|
|
42
43
|
const [, address] = symbol.split('-');
|
|
43
44
|
return (address === null || address === void 0 ? void 0 : address.startsWith('0x'))
|
|
44
|
-
? getContractDecimals({ chain:
|
|
45
|
-
:
|
|
45
|
+
? getContractDecimals({ chain: pioneer_caip_1.Chain.Ethereum, to: address })
|
|
46
|
+
: pioneer_caip_1.BaseDecimal.ETH;
|
|
46
47
|
});
|
|
47
48
|
const getAVAXAssetDecimal = (symbol) => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
49
|
const [, address] = symbol.split('-');
|
|
49
50
|
return (address === null || address === void 0 ? void 0 : address.startsWith('0x'))
|
|
50
|
-
? getContractDecimals({ chain:
|
|
51
|
-
:
|
|
51
|
+
? getContractDecimals({ chain: pioneer_caip_1.Chain.Avalanche, to: address.toLowerCase() })
|
|
52
|
+
: pioneer_caip_1.BaseDecimal.AVAX;
|
|
52
53
|
});
|
|
53
54
|
const getBSCAssetDecimal = (symbol) => __awaiter(void 0, void 0, void 0, function* () {
|
|
54
|
-
if (symbol ===
|
|
55
|
-
return
|
|
56
|
-
return
|
|
55
|
+
if (symbol === pioneer_caip_1.Chain.BinanceSmartChain)
|
|
56
|
+
return pioneer_caip_1.BaseDecimal.BSC;
|
|
57
|
+
return pioneer_caip_1.BaseDecimal.BSC;
|
|
57
58
|
});
|
|
58
59
|
const getDecimal = (_a) => __awaiter(void 0, [_a], void 0, function* ({ chain, symbol }) {
|
|
59
60
|
switch (chain) {
|
|
60
|
-
case
|
|
61
|
+
case pioneer_caip_1.Chain.Ethereum:
|
|
61
62
|
return getETHAssetDecimal(symbol);
|
|
62
|
-
case
|
|
63
|
+
case pioneer_caip_1.Chain.Avalanche:
|
|
63
64
|
return getAVAXAssetDecimal(symbol);
|
|
64
|
-
case
|
|
65
|
+
case pioneer_caip_1.Chain.BinanceSmartChain:
|
|
65
66
|
return getBSCAssetDecimal(symbol);
|
|
66
67
|
default:
|
|
67
68
|
// @ts-ignore
|
|
68
|
-
return
|
|
69
|
+
return pioneer_caip_1.BaseDecimal[chain];
|
|
69
70
|
}
|
|
70
71
|
});
|
|
71
72
|
exports.getDecimal = getDecimal;
|
|
72
73
|
exports.gasFeeMultiplier = {
|
|
73
|
-
[
|
|
74
|
-
[
|
|
75
|
-
[
|
|
74
|
+
[pioneer_types_1.FeeOption.Average]: 1.2,
|
|
75
|
+
[pioneer_types_1.FeeOption.Fast]: 1.5,
|
|
76
|
+
[pioneer_types_1.FeeOption.Fastest]: 2,
|
|
76
77
|
};
|
|
77
78
|
const isGasAsset = ({ chain, symbol }) => {
|
|
78
79
|
switch (chain) {
|
|
79
|
-
case
|
|
80
|
-
case
|
|
81
|
-
case
|
|
82
|
-
case
|
|
83
|
-
case
|
|
84
|
-
case
|
|
85
|
-
case
|
|
86
|
-
case
|
|
87
|
-
case
|
|
88
|
-
case
|
|
80
|
+
case pioneer_caip_1.Chain.Bitcoin:
|
|
81
|
+
case pioneer_caip_1.Chain.BitcoinCash:
|
|
82
|
+
case pioneer_caip_1.Chain.Dash:
|
|
83
|
+
case pioneer_caip_1.Chain.Digibyte:
|
|
84
|
+
case pioneer_caip_1.Chain.Zcash:
|
|
85
|
+
case pioneer_caip_1.Chain.Ripple:
|
|
86
|
+
case pioneer_caip_1.Chain.Litecoin:
|
|
87
|
+
case pioneer_caip_1.Chain.Dogecoin:
|
|
88
|
+
case pioneer_caip_1.Chain.Ethereum:
|
|
89
|
+
case pioneer_caip_1.Chain.Avalanche:
|
|
89
90
|
return symbol === chain;
|
|
90
|
-
case
|
|
91
|
-
case
|
|
92
|
-
case
|
|
91
|
+
case pioneer_caip_1.Chain.Arbitrum:
|
|
92
|
+
case pioneer_caip_1.Chain.Optimism:
|
|
93
|
+
case pioneer_caip_1.Chain.Base:
|
|
93
94
|
return 'ETH' === symbol;
|
|
94
95
|
// @ts-ignore
|
|
95
|
-
case
|
|
96
|
+
case pioneer_caip_1.Chain.Mayachain:
|
|
96
97
|
return symbol === 'CACAO';
|
|
97
|
-
case
|
|
98
|
+
case pioneer_caip_1.Chain.Kujira:
|
|
98
99
|
return symbol === 'KUJI';
|
|
99
|
-
case
|
|
100
|
+
case pioneer_caip_1.Chain.Cosmos:
|
|
100
101
|
return symbol === 'ATOM';
|
|
101
|
-
case
|
|
102
|
+
case pioneer_caip_1.Chain.Polygon:
|
|
102
103
|
return symbol === 'MATIC';
|
|
103
|
-
case
|
|
104
|
+
case pioneer_caip_1.Chain.BinanceSmartChain:
|
|
104
105
|
return symbol === 'BNB';
|
|
105
|
-
case
|
|
106
|
+
case pioneer_caip_1.Chain.THORChain:
|
|
106
107
|
return symbol === 'RUNE';
|
|
107
108
|
}
|
|
108
109
|
};
|
|
@@ -113,36 +114,36 @@ const getCommonAssetInfo = (assetString) => {
|
|
|
113
114
|
return { identifier: 'ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044', decimal: 18 };
|
|
114
115
|
case 'ETH.vTHOR':
|
|
115
116
|
return { identifier: 'ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d', decimal: 18 };
|
|
116
|
-
case
|
|
117
|
-
return { identifier: 'GAIA.ATOM', decimal:
|
|
118
|
-
case
|
|
119
|
-
return { identifier: 'THOR.RUNE', decimal:
|
|
120
|
-
case
|
|
121
|
-
return { identifier: 'BSC.BNB', decimal:
|
|
117
|
+
case pioneer_caip_1.Chain.Cosmos:
|
|
118
|
+
return { identifier: 'GAIA.ATOM', decimal: pioneer_caip_1.BaseDecimal[assetString] };
|
|
119
|
+
case pioneer_caip_1.Chain.THORChain:
|
|
120
|
+
return { identifier: 'THOR.RUNE', decimal: pioneer_caip_1.BaseDecimal[assetString] };
|
|
121
|
+
case pioneer_caip_1.Chain.BinanceSmartChain:
|
|
122
|
+
return { identifier: 'BSC.BNB', decimal: pioneer_caip_1.BaseDecimal[assetString] };
|
|
122
123
|
// @ts-ignore
|
|
123
|
-
case
|
|
124
|
-
return { identifier: 'MAYA.CACAO', decimal:
|
|
124
|
+
case pioneer_caip_1.Chain.Mayachain:
|
|
125
|
+
return { identifier: 'MAYA.CACAO', decimal: pioneer_caip_1.BaseDecimal.MAYA };
|
|
125
126
|
case 'MAYA.MAYA':
|
|
126
127
|
return { identifier: 'MAYA.MAYA', decimal: 4 };
|
|
127
|
-
case
|
|
128
|
+
case pioneer_caip_1.Chain.Arbitrum:
|
|
128
129
|
return { identifier: 'ARB.ETH', decimal: 18 };
|
|
129
|
-
case
|
|
130
|
+
case pioneer_caip_1.Chain.Base:
|
|
130
131
|
return { identifier: 'BASE.ETH', decimal: 18 };
|
|
131
|
-
case
|
|
132
|
+
case pioneer_caip_1.Chain.Optimism:
|
|
132
133
|
return { identifier: 'OP.ETH', decimal: 18 };
|
|
133
|
-
case
|
|
134
|
+
case pioneer_caip_1.Chain.Avalanche:
|
|
134
135
|
return { identifier: 'AVAX.ETH', decimal: 18 };
|
|
135
|
-
case
|
|
136
|
-
case
|
|
137
|
-
case
|
|
138
|
-
case
|
|
139
|
-
case
|
|
140
|
-
case
|
|
141
|
-
case
|
|
142
|
-
case
|
|
143
|
-
case
|
|
144
|
-
case
|
|
145
|
-
return { identifier: `${assetString}.${assetString}`, decimal:
|
|
136
|
+
case pioneer_caip_1.Chain.Ripple:
|
|
137
|
+
case pioneer_caip_1.Chain.Kujira:
|
|
138
|
+
case pioneer_caip_1.Chain.BitcoinCash:
|
|
139
|
+
case pioneer_caip_1.Chain.Zcash:
|
|
140
|
+
case pioneer_caip_1.Chain.Dash:
|
|
141
|
+
case pioneer_caip_1.Chain.Litecoin:
|
|
142
|
+
case pioneer_caip_1.Chain.Dogecoin:
|
|
143
|
+
case pioneer_caip_1.Chain.Polygon:
|
|
144
|
+
case pioneer_caip_1.Chain.Bitcoin:
|
|
145
|
+
case pioneer_caip_1.Chain.Ethereum:
|
|
146
|
+
return { identifier: `${assetString}.${assetString}`, decimal: pioneer_caip_1.BaseDecimal[assetString] };
|
|
146
147
|
}
|
|
147
148
|
};
|
|
148
149
|
exports.getCommonAssetInfo = getCommonAssetInfo;
|
|
@@ -150,35 +151,35 @@ const getAssetType = ({ chain, symbol }) => {
|
|
|
150
151
|
if (symbol.includes('/'))
|
|
151
152
|
return 'Synth';
|
|
152
153
|
switch (chain) {
|
|
153
|
-
case
|
|
154
|
-
case
|
|
155
|
-
case
|
|
156
|
-
case
|
|
157
|
-
case
|
|
158
|
-
case
|
|
154
|
+
case pioneer_caip_1.Chain.Bitcoin:
|
|
155
|
+
case pioneer_caip_1.Chain.BitcoinCash:
|
|
156
|
+
case pioneer_caip_1.Chain.Dogecoin:
|
|
157
|
+
case pioneer_caip_1.Chain.Dash:
|
|
158
|
+
case pioneer_caip_1.Chain.Zcash:
|
|
159
|
+
case pioneer_caip_1.Chain.Litecoin:
|
|
159
160
|
// @ts-ignore
|
|
160
|
-
case
|
|
161
|
-
case
|
|
161
|
+
case pioneer_caip_1.Chain.Mayachain:
|
|
162
|
+
case pioneer_caip_1.Chain.THORChain:
|
|
162
163
|
return 'Native';
|
|
163
|
-
case
|
|
164
|
+
case pioneer_caip_1.Chain.Osmosis:
|
|
164
165
|
return 'Native';
|
|
165
|
-
case
|
|
166
|
-
return symbol === 'ATOM' ? 'Native' :
|
|
167
|
-
case
|
|
168
|
-
return symbol ===
|
|
169
|
-
case
|
|
170
|
-
case
|
|
171
|
-
return symbol ===
|
|
172
|
-
case
|
|
173
|
-
return symbol ===
|
|
174
|
-
case
|
|
175
|
-
return symbol ===
|
|
176
|
-
case
|
|
177
|
-
return symbol ===
|
|
178
|
-
case
|
|
179
|
-
return [
|
|
180
|
-
case
|
|
181
|
-
return [
|
|
166
|
+
case pioneer_caip_1.Chain.Cosmos:
|
|
167
|
+
return symbol === 'ATOM' ? 'Native' : pioneer_caip_1.Chain.Cosmos;
|
|
168
|
+
case pioneer_caip_1.Chain.Kujira:
|
|
169
|
+
return symbol === pioneer_caip_1.Chain.Kujira ? 'Native' : pioneer_caip_1.Chain.Kujira;
|
|
170
|
+
case pioneer_caip_1.Chain.BinanceSmartChain:
|
|
171
|
+
case pioneer_caip_1.Chain.Ethereum:
|
|
172
|
+
return symbol === pioneer_caip_1.Chain.Ethereum ? 'Native' : 'ERC20';
|
|
173
|
+
case pioneer_caip_1.Chain.Avalanche:
|
|
174
|
+
return symbol === pioneer_caip_1.Chain.Avalanche ? 'Native' : pioneer_caip_1.Chain.Avalanche;
|
|
175
|
+
case pioneer_caip_1.Chain.Polygon:
|
|
176
|
+
return symbol === pioneer_caip_1.Chain.Polygon ? 'Native' : 'POLYGON';
|
|
177
|
+
case pioneer_caip_1.Chain.Base:
|
|
178
|
+
return symbol === pioneer_caip_1.Chain.Ethereum ? 'Native' : 'ERC20';
|
|
179
|
+
case pioneer_caip_1.Chain.Arbitrum:
|
|
180
|
+
return [pioneer_caip_1.Chain.Ethereum, pioneer_caip_1.Chain.Arbitrum].includes(symbol) ? 'Native' : 'ARBITRUM';
|
|
181
|
+
case pioneer_caip_1.Chain.Optimism:
|
|
182
|
+
return [pioneer_caip_1.Chain.Ethereum, pioneer_caip_1.Chain.Optimism].includes(symbol) ? 'Native' : 'OPTIMISM';
|
|
182
183
|
}
|
|
183
184
|
};
|
|
184
185
|
exports.getAssetType = getAssetType;
|
|
@@ -194,7 +195,7 @@ exports.assetFromString = assetFromString;
|
|
|
194
195
|
const potentialScamRegex = new RegExp(/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/, 'gmi');
|
|
195
196
|
const evmAssetHasAddress = (assetString) => {
|
|
196
197
|
const [chain, symbol] = assetString.split('.');
|
|
197
|
-
if (!
|
|
198
|
+
if (!pioneer_caip_1.EVMChainList.includes(chain))
|
|
198
199
|
return true;
|
|
199
200
|
const [, address] = symbol.split('-');
|
|
200
201
|
return (0, exports.isGasAsset)({ chain: chain, symbol }) || !!address;
|
package/lib/helpers/liquidity.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLiquiditySlippage = exports.getEstimatedPoolShare = exports.getSymmetricWithdraw = exports.getSymmetricPoolShare = exports.getAsymmetricAssetWithdrawAmount = exports.getAsymmetricRuneWithdrawAmount = exports.getAsymmetricAssetShare = exports.getAsymmetricRuneShare = void 0;
|
|
4
|
-
const
|
|
4
|
+
const pioneer_caip_1 = require("@pioneer-platform/pioneer-caip");
|
|
5
5
|
const index_1 = require("../index");
|
|
6
6
|
/**
|
|
7
7
|
* Ref: https://gitlab.com/thorchain/thornode/-/issues/657
|
|
@@ -44,7 +44,7 @@ const getAsymmetricRuneWithdrawAmount = ({ percent, runeDepth, liquidityUnits, p
|
|
|
44
44
|
exports.getAsymmetricRuneWithdrawAmount = getAsymmetricRuneWithdrawAmount;
|
|
45
45
|
const getAsymmetricAssetWithdrawAmount = ({ percent, assetDepth, liquidityUnits, poolUnits, }) => (0, exports.getAsymmetricAssetShare)({ assetDepth, liquidityUnits, poolUnits }).mul(percent);
|
|
46
46
|
exports.getAsymmetricAssetWithdrawAmount = getAsymmetricAssetWithdrawAmount;
|
|
47
|
-
const toTCSwapKitNumber = (value) => index_1.SwapKitNumber.fromBigInt(BigInt(value),
|
|
47
|
+
const toTCSwapKitNumber = (value) => index_1.SwapKitNumber.fromBigInt(BigInt(value), pioneer_caip_1.BaseDecimal.THOR);
|
|
48
48
|
const getSymmetricPoolShare = ({ liquidityUnits, poolUnits, runeDepth, assetDepth, }) => ({
|
|
49
49
|
assetAmount: toTCSwapKitNumber(assetDepth).mul(liquidityUnits).div(poolUnits),
|
|
50
50
|
runeAmount: toTCSwapKitNumber(runeDepth).mul(liquidityUnits).div(poolUnits),
|
package/lib/helpers/memo.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Chain } from '@
|
|
2
|
-
import { MemoType } from '@
|
|
1
|
+
import type { Chain } from '@pioneer-platform/pioneer-caip';
|
|
2
|
+
import { MemoType } from '@pioneer-platform/pioneer-types';
|
|
3
3
|
export type ThornameRegisterParam = {
|
|
4
4
|
name: string;
|
|
5
5
|
chain: string;
|
package/lib/helpers/memo.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMemoFor = void 0;
|
|
4
|
-
const
|
|
4
|
+
const pioneer_types_1 = require("@pioneer-platform/pioneer-types");
|
|
5
5
|
const getShortenedSymbol = ({ symbol, ticker, chain, }) => (chain === 'ETH' && ticker !== 'ETH' ? `${ticker}-${symbol.slice(-3)}` : symbol);
|
|
6
6
|
const getMemoFor = (memoType, options) => {
|
|
7
7
|
switch (memoType) {
|
|
8
|
-
case
|
|
9
|
-
case
|
|
8
|
+
case pioneer_types_1.MemoType.LEAVE:
|
|
9
|
+
case pioneer_types_1.MemoType.BOND: {
|
|
10
10
|
const { address } = options;
|
|
11
11
|
return `${memoType}:${address}`;
|
|
12
12
|
}
|
|
13
|
-
case
|
|
13
|
+
case pioneer_types_1.MemoType.UNBOND: {
|
|
14
14
|
const { address, unbondAmount } = options;
|
|
15
15
|
return `${memoType}:${address}:${unbondAmount * Math.pow(10, 8)}`;
|
|
16
16
|
}
|
|
17
|
-
case
|
|
17
|
+
case pioneer_types_1.MemoType.THORNAME_REGISTER: {
|
|
18
18
|
const { name, chain, address, owner } = options;
|
|
19
19
|
return `${memoType}:${name}:${chain}:${address}${owner ? `:${owner}` : ''}`;
|
|
20
20
|
}
|
|
21
|
-
case
|
|
21
|
+
case pioneer_types_1.MemoType.DEPOSIT: {
|
|
22
22
|
const { chain, symbol, address, singleSide } = options;
|
|
23
23
|
return singleSide
|
|
24
24
|
? `${memoType}:${chain}/${symbol}::t:0`
|
|
25
25
|
: `${memoType}:${chain}.${symbol}:${address || ''}:t:0`;
|
|
26
26
|
}
|
|
27
|
-
case
|
|
27
|
+
case pioneer_types_1.MemoType.WITHDRAW: {
|
|
28
28
|
const { chain, ticker, symbol, basisPoints, targetAssetString, singleSide } = options;
|
|
29
29
|
const target = !singleSide && targetAssetString ? `:${targetAssetString}` : '';
|
|
30
30
|
const shortenedSymbol = getShortenedSymbol({ chain, symbol, ticker });
|
|
31
31
|
const assetDivider = singleSide ? '/' : '.';
|
|
32
32
|
return `${memoType}:${chain}${assetDivider}${shortenedSymbol}:${basisPoints}${target}`;
|
|
33
33
|
}
|
|
34
|
-
case
|
|
35
|
-
case
|
|
34
|
+
case pioneer_types_1.MemoType.OPEN_LOAN:
|
|
35
|
+
case pioneer_types_1.MemoType.CLOSE_LOAN: {
|
|
36
36
|
const { asset, address } = options;
|
|
37
37
|
return `${memoType}:${asset}:${address}`; //:${minAmount ? `${minAmount}` : ''}:t:0`;
|
|
38
38
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validateIdentifier = void 0;
|
|
4
|
-
const
|
|
5
|
-
const supportedChains = Object.values(
|
|
4
|
+
const pioneer_caip_1 = require("@pioneer-platform/pioneer-caip");
|
|
5
|
+
const supportedChains = Object.values(pioneer_caip_1.Chain);
|
|
6
6
|
const validateIdentifier = (identifier = '') => {
|
|
7
7
|
const uppercasedIdentifier = identifier.toUpperCase();
|
|
8
8
|
const [chain] = uppercasedIdentifier.split('.');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CoinGeckoList, MayaList, PancakeswapETHList, PancakeswapList, PangolinList, PioneerList, StargateARBList, SushiswapList, ThorchainList, TraderjoeList, UniswapList, WoofiList } from '@
|
|
2
|
-
import { Chain } from '@
|
|
1
|
+
import type { CoinGeckoList, MayaList, PancakeswapETHList, PancakeswapList, PangolinList, PioneerList, StargateARBList, SushiswapList, ThorchainList, TraderjoeList, UniswapList, WoofiList } from '@pioneer-platform/tokens';
|
|
2
|
+
import { Chain } from '@pioneer-platform/pioneer-caip';
|
|
3
3
|
import type { CommonAssetString } from '../helpers/asset';
|
|
4
4
|
import { getAssetType } from '../helpers/asset';
|
|
5
5
|
import type { NumberPrimitives } from './bigIntArithmetics';
|
|
@@ -55,7 +55,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
55
55
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
56
56
|
exports.getMinAmountByChain = exports.AssetValue = void 0;
|
|
57
57
|
exports.safeValue = safeValue;
|
|
58
|
-
const
|
|
58
|
+
const pioneer_caip_1 = require("@pioneer-platform/pioneer-caip");
|
|
59
59
|
const asset_1 = require("../helpers/asset");
|
|
60
60
|
const validators_1 = require("../helpers/validators");
|
|
61
61
|
const bigIntArithmetics_1 = require("./bigIntArithmetics");
|
|
@@ -87,7 +87,7 @@ const getStaticToken = (identifier) => {
|
|
|
87
87
|
throw new Error('Static assets not loaded, call await AssetValue.loadStaticAssets() first');
|
|
88
88
|
}
|
|
89
89
|
const tokenInfo = staticTokensMap.get(identifier.toUpperCase());
|
|
90
|
-
return tokenInfo || { decimal:
|
|
90
|
+
return tokenInfo || { decimal: pioneer_caip_1.BaseDecimal.THOR, identifier: '' };
|
|
91
91
|
}
|
|
92
92
|
catch (error) {
|
|
93
93
|
console.error(tag + 'Error in getStaticToken:', error);
|
|
@@ -266,7 +266,7 @@ class AssetValue extends bigIntArithmetics_1.BigIntArithmetics {
|
|
|
266
266
|
try {
|
|
267
267
|
return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
268
268
|
try {
|
|
269
|
-
const _a = yield Promise.resolve().then(() => __importStar(require('@
|
|
269
|
+
const _a = yield Promise.resolve().then(() => __importStar(require('@pioneer-platform/tokens'))), { ThorchainList: _ThorchainList, NativeList } = _a, tokensPackage = __rest(_a, ["ThorchainList", "NativeList"]);
|
|
270
270
|
const tokensMap = [NativeList, ...Object.values(tokensPackage)].reduce((acc, { tokens }) => {
|
|
271
271
|
if (!tokens) {
|
|
272
272
|
console.warn(tag + "No tokens found in the current package, skipping.");
|
|
@@ -275,7 +275,8 @@ class AssetValue extends bigIntArithmetics_1.BigIntArithmetics {
|
|
|
275
275
|
// @ts-ignore
|
|
276
276
|
tokens.forEach((_a) => {
|
|
277
277
|
var { identifier, chain } = _a, rest = __rest(_a, ["identifier", "chain"]);
|
|
278
|
-
|
|
278
|
+
// @ts-ignore - BaseDecimal uses string keys but is typed as enum
|
|
279
|
+
const decimal = 'decimals' in rest ? rest.decimals : pioneer_caip_1.BaseDecimal[chain];
|
|
279
280
|
acc.set(identifier, { identifier, decimal });
|
|
280
281
|
});
|
|
281
282
|
return acc;
|
|
@@ -288,7 +289,7 @@ class AssetValue extends bigIntArithmetics_1.BigIntArithmetics {
|
|
|
288
289
|
reject({
|
|
289
290
|
ok: false,
|
|
290
291
|
error,
|
|
291
|
-
message: "Couldn't load static assets. Ensure you have installed @
|
|
292
|
+
message: "Couldn't load static assets. Ensure you have installed @pioneer-platform/tokens package",
|
|
292
293
|
});
|
|
293
294
|
}
|
|
294
295
|
}));
|
|
@@ -305,21 +306,21 @@ const getMinAmountByChain = (chain) => {
|
|
|
305
306
|
try {
|
|
306
307
|
const asset = AssetValue.fromChainOrSignature(chain);
|
|
307
308
|
switch (chain) {
|
|
308
|
-
case
|
|
309
|
-
case
|
|
310
|
-
case
|
|
311
|
-
case
|
|
312
|
-
case
|
|
309
|
+
case pioneer_caip_1.Chain.Bitcoin:
|
|
310
|
+
case pioneer_caip_1.Chain.Litecoin:
|
|
311
|
+
case pioneer_caip_1.Chain.Dash:
|
|
312
|
+
case pioneer_caip_1.Chain.Zcash:
|
|
313
|
+
case pioneer_caip_1.Chain.BitcoinCash:
|
|
313
314
|
return asset.set(0.00010001);
|
|
314
|
-
case
|
|
315
|
+
case pioneer_caip_1.Chain.Dogecoin:
|
|
315
316
|
return asset.set(1.00000001);
|
|
316
|
-
case
|
|
317
|
-
case
|
|
318
|
-
case
|
|
319
|
-
case
|
|
317
|
+
case pioneer_caip_1.Chain.Base:
|
|
318
|
+
case pioneer_caip_1.Chain.Arbitrum:
|
|
319
|
+
case pioneer_caip_1.Chain.Avalanche:
|
|
320
|
+
case pioneer_caip_1.Chain.Ethereum:
|
|
320
321
|
return asset.set(0.00000001);
|
|
321
|
-
case
|
|
322
|
-
case
|
|
322
|
+
case pioneer_caip_1.Chain.THORChain:
|
|
323
|
+
case pioneer_caip_1.Chain.Mayachain:
|
|
323
324
|
return asset.set(0.0000000001);
|
|
324
325
|
default:
|
|
325
326
|
return asset.set(0.00000001);
|
|
@@ -336,7 +337,7 @@ const getAssetInfo = (identifier) => {
|
|
|
336
337
|
try {
|
|
337
338
|
const isSynthetic = identifier.slice(0, 14).includes('/');
|
|
338
339
|
const [synthChain, synthSymbol] = identifier.split('.').pop().split('/');
|
|
339
|
-
const adjustedIdentifier = identifier.includes('.') && !isSynthetic ? identifier : `${
|
|
340
|
+
const adjustedIdentifier = identifier.includes('.') && !isSynthetic ? identifier : `${pioneer_caip_1.Chain.THORChain}.${synthSymbol}`;
|
|
340
341
|
const [chain, symbol] = adjustedIdentifier.split('.');
|
|
341
342
|
const [ticker, address] = (isSynthetic ? synthSymbol : symbol).split('-');
|
|
342
343
|
return {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BigIntArithmetics = exports.toMultiplier = void 0;
|
|
4
4
|
exports.formatBigIntToSafeValue = formatBigIntToSafeValue;
|
|
5
|
-
const
|
|
5
|
+
const pioneer_caip_1 = require("@pioneer-platform/pioneer-caip");
|
|
6
6
|
const TAG = " | BigIntArithmetics | ";
|
|
7
7
|
const DEFAULT_DECIMAL = 8;
|
|
8
8
|
const bigintPow = (base, exponent) => {
|
|
@@ -326,7 +326,7 @@ class BigIntArithmetics {
|
|
|
326
326
|
getBaseValue(type) {
|
|
327
327
|
let tag = TAG + " | getBaseValue | ";
|
|
328
328
|
try {
|
|
329
|
-
const divisor = this.decimalMultiplier / (0, exports.toMultiplier)(this.decimal ||
|
|
329
|
+
const divisor = this.decimalMultiplier / (0, exports.toMultiplier)(this.decimal || pioneer_caip_1.BaseDecimal.THOR);
|
|
330
330
|
const baseValue = this.bigIntValue / divisor;
|
|
331
331
|
switch (type) {
|
|
332
332
|
case 'number':
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pioneer-platform/helpers",
|
|
3
|
-
"version": "4.8.
|
|
3
|
+
"version": "4.8.2",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
"refresh": "rm -rf ./node_modules ./package-lock.json && pnpm install"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
16
|
+
"@pioneer-platform/pioneer-caip": "workspace:*",
|
|
17
|
+
"@pioneer-platform/pioneer-types": "workspace:*",
|
|
18
|
+
"@pioneer-platform/tokens": "workspace:*",
|
|
19
19
|
"@noble/hashes": "^1.4.0",
|
|
20
20
|
"@pioneer-platform/loggerdog": "^8.11.0",
|
|
21
21
|
"@types/node": "^18.15.11",
|
package/src/helpers/asset.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { EVMChain } from '@
|
|
2
|
-
import { BaseDecimal, Chain, ChainToRPC, EVMChainList
|
|
1
|
+
import type { EVMChain } from '@pioneer-platform/pioneer-caip';
|
|
2
|
+
import { BaseDecimal, Chain, ChainToRPC, EVMChainList } from '@pioneer-platform/pioneer-caip';
|
|
3
|
+
import { FeeOption } from '@pioneer-platform/pioneer-types';
|
|
3
4
|
|
|
4
5
|
import { RequestClient } from '../index';
|
|
5
6
|
|
package/src/helpers/liquidity.ts
CHANGED
package/src/helpers/memo.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Chain } from '@
|
|
2
|
-
import { MemoType } from '@
|
|
1
|
+
import type { Chain } from '@pioneer-platform/pioneer-caip';
|
|
2
|
+
import { MemoType } from '@pioneer-platform/pioneer-types';
|
|
3
3
|
|
|
4
4
|
export type ThornameRegisterParam = {
|
|
5
5
|
name: string;
|
|
@@ -11,8 +11,8 @@ import type {
|
|
|
11
11
|
TraderjoeList,
|
|
12
12
|
UniswapList,
|
|
13
13
|
WoofiList,
|
|
14
|
-
} from '@
|
|
15
|
-
import { BaseDecimal, Chain } from '@
|
|
14
|
+
} from '@pioneer-platform/tokens';
|
|
15
|
+
import { BaseDecimal, Chain } from '@pioneer-platform/pioneer-caip';
|
|
16
16
|
|
|
17
17
|
import type { CommonAssetString } from '../helpers/asset';
|
|
18
18
|
import { getAssetType, getCommonAssetInfo, getDecimal, isGasAsset } from '../helpers/asset';
|
|
@@ -282,7 +282,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
|
282
282
|
ThorchainList: _ThorchainList,
|
|
283
283
|
NativeList,
|
|
284
284
|
...tokensPackage
|
|
285
|
-
} = await import('@
|
|
285
|
+
} = await import('@pioneer-platform/tokens');
|
|
286
286
|
|
|
287
287
|
const tokensMap = [NativeList, ...Object.values(tokensPackage)].reduce(
|
|
288
288
|
(acc, { tokens }: any) => {
|
|
@@ -293,6 +293,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
|
293
293
|
|
|
294
294
|
// @ts-ignore
|
|
295
295
|
tokens.forEach(({ identifier, chain, ...rest }) => {
|
|
296
|
+
// @ts-ignore - BaseDecimal uses string keys but is typed as enum
|
|
296
297
|
const decimal = 'decimals' in rest ? rest.decimals : BaseDecimal[chain as Chain];
|
|
297
298
|
|
|
298
299
|
acc.set(identifier as TokenNames, { identifier, decimal });
|
|
@@ -311,7 +312,7 @@ export class AssetValue extends BigIntArithmetics {
|
|
|
311
312
|
reject({
|
|
312
313
|
ok: false,
|
|
313
314
|
error,
|
|
314
|
-
message: "Couldn't load static assets. Ensure you have installed @
|
|
315
|
+
message: "Couldn't load static assets. Ensure you have installed @pioneer-platform/tokens package",
|
|
315
316
|
});
|
|
316
317
|
}
|
|
317
318
|
},
|