@swapkit/helpers 1.0.0-rc.22 → 1.0.0-rc.24
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/dist/index.cjs +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.es.js +310 -302
- package/package.json +1 -1
- package/src/helpers/asset.ts +24 -7
- package/src/modules/assetValue.ts +5 -4
package/package.json
CHANGED
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"repository": "https://github.com/thorswap/SwapKit.git",
|
|
43
43
|
"type": "module",
|
|
44
44
|
"types": "./dist/index.d.ts",
|
|
45
|
-
"version": "1.0.0-rc.
|
|
45
|
+
"version": "1.0.0-rc.24",
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "vite build",
|
|
48
48
|
"clean": "rm -rf dist vite.config.ts.* .turbo node_modules",
|
package/src/helpers/asset.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { EVMChain } from '@swapkit/types';
|
|
2
|
-
import { BaseDecimal, Chain, ChainToRPC, FeeOption } from '@swapkit/types';
|
|
2
|
+
import { BaseDecimal, Chain, ChainToRPC, EVMChainList, FeeOption } from '@swapkit/types';
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { RequestClient } from '../index.ts';
|
|
5
5
|
|
|
6
6
|
const getDecimalMethodHex = '0x313ce567';
|
|
7
7
|
|
|
@@ -186,8 +186,25 @@ const potentialScamRegex = new RegExp(
|
|
|
186
186
|
/(.)\1{6}|\.ORG|\.NET|\.FINANCE|\.COM|WWW|HTTP|\\\\|\/\/|[\s$%:[\]]/,
|
|
187
187
|
'gmi',
|
|
188
188
|
);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
);
|
|
189
|
+
|
|
190
|
+
const evmAssetHasAddress = (assetString: string) => {
|
|
191
|
+
const [chain, symbol] = assetString.split('.') as [EVMChain, string];
|
|
192
|
+
if (!EVMChainList.includes(chain as EVMChain)) return true;
|
|
193
|
+
const [, address] = symbol.split('-') as [string, string?];
|
|
194
|
+
|
|
195
|
+
return isGasAsset({ chain: chain as Chain, symbol }) || !!address;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
export const filterAssets = (
|
|
199
|
+
tokens: {
|
|
200
|
+
value: string;
|
|
201
|
+
decimal: number;
|
|
202
|
+
chain: Chain;
|
|
203
|
+
symbol: string;
|
|
204
|
+
}[],
|
|
205
|
+
) =>
|
|
206
|
+
tokens.filter((token) => {
|
|
207
|
+
const assetString = `${token.chain}.${token.symbol}`;
|
|
208
|
+
|
|
209
|
+
return !potentialScamRegex.test(assetString) && evmAssetHasAddress(assetString);
|
|
210
|
+
});
|
|
@@ -76,16 +76,15 @@ export class AssetValue extends BigIntArithmetics {
|
|
|
76
76
|
type: ReturnType<typeof getAssetType>;
|
|
77
77
|
|
|
78
78
|
constructor(params: AssetValueParams) {
|
|
79
|
+
const identifier =
|
|
80
|
+
'identifier' in params ? params.identifier : `${params.chain}.${params.symbol}`;
|
|
79
81
|
super(
|
|
80
82
|
params.value instanceof BigIntArithmetics
|
|
81
83
|
? params.value
|
|
82
84
|
: { decimal: params.decimal, value: params.value },
|
|
83
85
|
);
|
|
84
86
|
|
|
85
|
-
const identifier =
|
|
86
|
-
'identifier' in params ? params.identifier : `${params.chain}.${params.symbol}`;
|
|
87
87
|
const assetInfo = getAssetInfo(identifier);
|
|
88
|
-
|
|
89
88
|
this.type = getAssetType(assetInfo);
|
|
90
89
|
this.chain = assetInfo.chain;
|
|
91
90
|
this.ticker = assetInfo.ticker;
|
|
@@ -127,11 +126,13 @@ export class AssetValue extends BigIntArithmetics {
|
|
|
127
126
|
|
|
128
127
|
const parsedValue = safeValue(value, decimal);
|
|
129
128
|
|
|
130
|
-
|
|
129
|
+
const asset = tokenIdentifier
|
|
131
130
|
? new AssetValue({ decimal, identifier: tokenIdentifier, value: parsedValue })
|
|
132
131
|
: isSynthetic
|
|
133
132
|
? new AssetValue({ decimal: 8, identifier: assetString, value: parsedValue })
|
|
134
133
|
: undefined;
|
|
134
|
+
|
|
135
|
+
return asset;
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
static async fromIdentifier(
|