@swapkit/core 1.0.0-rc.166 → 1.0.0-rc.167
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.js +6618 -4
- package/dist/index.js.map +29 -4
- package/package.json +15 -15
- package/src/client.ts +112 -1
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@swapkit/api": "1.0.0-rc.
|
|
5
|
-
"@swapkit/helpers": "1.0.0-rc.
|
|
4
|
+
"@swapkit/api": "1.0.0-rc.80",
|
|
5
|
+
"@swapkit/helpers": "1.0.0-rc.112"
|
|
6
6
|
},
|
|
7
7
|
"description": "SwapKit - Core",
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
10
|
-
"@swapkit/toolbox-cosmos": "1.0.0-rc.
|
|
11
|
-
"@swapkit/toolbox-evm": "1.0.0-rc.
|
|
12
|
-
"@swapkit/toolbox-substrate": "1.0.0-rc.
|
|
13
|
-
"@swapkit/toolbox-utxo": "1.0.0-rc.
|
|
9
|
+
"@swapkit/tokens": "1.0.0-rc.54",
|
|
10
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.139",
|
|
11
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.119",
|
|
12
|
+
"@swapkit/toolbox-substrate": "1.0.0-rc.47",
|
|
13
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.123",
|
|
14
14
|
"bun-types": "1.1.8"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@swapkit/api": "1.0.0-rc.
|
|
18
|
-
"@swapkit/helpers": "1.0.0-rc.
|
|
19
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
20
|
-
"@swapkit/toolbox-cosmos": "1.0.0-rc.
|
|
21
|
-
"@swapkit/toolbox-evm": "1.0.0-rc.
|
|
22
|
-
"@swapkit/toolbox-substrate": "1.0.0-rc.
|
|
23
|
-
"@swapkit/toolbox-utxo": "1.0.0-rc.
|
|
17
|
+
"@swapkit/api": "1.0.0-rc.80",
|
|
18
|
+
"@swapkit/helpers": "1.0.0-rc.112",
|
|
19
|
+
"@swapkit/tokens": "1.0.0-rc.54",
|
|
20
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.139",
|
|
21
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.119",
|
|
22
|
+
"@swapkit/toolbox-substrate": "1.0.0-rc.47",
|
|
23
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.123"
|
|
24
24
|
},
|
|
25
25
|
"files": [
|
|
26
26
|
"src/",
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
},
|
|
46
46
|
"type": "module",
|
|
47
47
|
"types": "./src/index.ts",
|
|
48
|
-
"version": "1.0.0-rc.
|
|
48
|
+
"version": "1.0.0-rc.167"
|
|
49
49
|
}
|
package/src/client.ts
CHANGED
|
@@ -7,10 +7,13 @@ import {
|
|
|
7
7
|
type ConnectConfig,
|
|
8
8
|
type EVMChain,
|
|
9
9
|
EVMChains,
|
|
10
|
-
type
|
|
10
|
+
type FeeOption,
|
|
11
|
+
ProviderName as PluginNameEnum,
|
|
11
12
|
SwapKitError,
|
|
12
13
|
type SwapParams,
|
|
14
|
+
type UTXOChain,
|
|
13
15
|
type WalletChain,
|
|
16
|
+
isGasAsset,
|
|
14
17
|
} from "@swapkit/helpers";
|
|
15
18
|
import {
|
|
16
19
|
type BaseEVMWallet,
|
|
@@ -20,10 +23,12 @@ import {
|
|
|
20
23
|
|
|
21
24
|
import {
|
|
22
25
|
type TransferParams as CosmosTransferParams,
|
|
26
|
+
estimateTransactionFee as cosmosTransactionFee,
|
|
23
27
|
cosmosValidateAddress,
|
|
24
28
|
} from "@swapkit/toolbox-cosmos";
|
|
25
29
|
import { substrateValidateAddress } from "@swapkit/toolbox-substrate";
|
|
26
30
|
import { type UTXOTransferParams, utxoValidateAddress } from "@swapkit/toolbox-utxo";
|
|
31
|
+
import { lowercasedContractAbiMapping } from "./aggregator/contracts/index.ts";
|
|
27
32
|
import {
|
|
28
33
|
getExplorerAddressUrl as getAddressUrl,
|
|
29
34
|
getExplorerTxUrl as getTxUrl,
|
|
@@ -304,6 +309,111 @@ export function SwapKit<
|
|
|
304
309
|
delete connectedWallets[chain];
|
|
305
310
|
}
|
|
306
311
|
|
|
312
|
+
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO clean this up
|
|
313
|
+
async function estimateTransactionFee<T extends PluginName>({
|
|
314
|
+
type,
|
|
315
|
+
feeOptionKey,
|
|
316
|
+
params,
|
|
317
|
+
}: (
|
|
318
|
+
| { type: "swap"; params: SwapParams<T> & { assetValue: AssetValue } }
|
|
319
|
+
| {
|
|
320
|
+
type: "transfer";
|
|
321
|
+
params: UTXOTransferParams | EVMTransferParams | CosmosTransferParams;
|
|
322
|
+
}
|
|
323
|
+
| {
|
|
324
|
+
type: "approve";
|
|
325
|
+
params: {
|
|
326
|
+
assetValue: AssetValue;
|
|
327
|
+
contractAddress: string | PluginName;
|
|
328
|
+
feeOptionKey?: FeeOption;
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
) & {
|
|
332
|
+
feeOptionKey: FeeOption;
|
|
333
|
+
}): Promise<AssetValue | undefined> {
|
|
334
|
+
const { assetValue } = params;
|
|
335
|
+
const chain = params.assetValue.chain as WalletChain;
|
|
336
|
+
if (!connectedWallets[chain]) throw new SwapKitError("core_wallet_connection_not_found");
|
|
337
|
+
switch (chain) {
|
|
338
|
+
case Chain.Arbitrum:
|
|
339
|
+
case Chain.Avalanche:
|
|
340
|
+
case Chain.Ethereum:
|
|
341
|
+
case Chain.BinanceSmartChain:
|
|
342
|
+
case Chain.Polygon: {
|
|
343
|
+
const wallet = connectedWallets[chain as Exclude<EVMChain, Chain.Optimism>];
|
|
344
|
+
if (type === "transfer") {
|
|
345
|
+
const txObject = await wallet.createTransferTx(params);
|
|
346
|
+
return wallet.estimateTransactionFee(txObject, feeOptionKey);
|
|
347
|
+
}
|
|
348
|
+
if (type === "approve" && !isGasAsset(assetValue)) {
|
|
349
|
+
wallet.estimateTransactionFee(
|
|
350
|
+
await wallet.createApprovalTx({
|
|
351
|
+
assetAddress: assetValue.address as string,
|
|
352
|
+
spenderAddress: params.contractAddress as string,
|
|
353
|
+
amount: assetValue.getBaseValue("bigint"),
|
|
354
|
+
from: wallet.address,
|
|
355
|
+
}),
|
|
356
|
+
feeOptionKey,
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
if (type === "swap") {
|
|
360
|
+
const plugin = params.route.providers[0] as PluginNameEnum;
|
|
361
|
+
if (plugin === PluginNameEnum.CHAINFLIP) {
|
|
362
|
+
const txObject = await wallet.createTransferTx({
|
|
363
|
+
from: wallet.address,
|
|
364
|
+
recipient: wallet.address,
|
|
365
|
+
assetValue,
|
|
366
|
+
});
|
|
367
|
+
return wallet.estimateTransactionFee(txObject, feeOptionKey);
|
|
368
|
+
}
|
|
369
|
+
const {
|
|
370
|
+
route: { evmTransactionDetails },
|
|
371
|
+
} = params;
|
|
372
|
+
if (
|
|
373
|
+
!(
|
|
374
|
+
evmTransactionDetails &&
|
|
375
|
+
lowercasedContractAbiMapping[evmTransactionDetails.contractAddress]
|
|
376
|
+
)
|
|
377
|
+
)
|
|
378
|
+
return undefined;
|
|
379
|
+
wallet.estimateCall({
|
|
380
|
+
contractAddress: evmTransactionDetails.contractAddress,
|
|
381
|
+
// biome-ignore lint/style/noNonNullAssertion: TS cant infer the type
|
|
382
|
+
abi: lowercasedContractAbiMapping[evmTransactionDetails.contractAddress]!,
|
|
383
|
+
funcName: evmTransactionDetails.contractMethod,
|
|
384
|
+
funcParams: evmTransactionDetails.contractParams,
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
return AssetValue.fromChainOrSignature(chain, 0);
|
|
388
|
+
}
|
|
389
|
+
case Chain.Bitcoin:
|
|
390
|
+
case Chain.BitcoinCash:
|
|
391
|
+
case Chain.Dogecoin:
|
|
392
|
+
case Chain.Dash:
|
|
393
|
+
case Chain.Litecoin: {
|
|
394
|
+
const wallet = connectedWallets[chain as UTXOChain];
|
|
395
|
+
return wallet.estimateTransactionFee({
|
|
396
|
+
...params,
|
|
397
|
+
feeOptionKey,
|
|
398
|
+
from: wallet.address,
|
|
399
|
+
recipient: wallet.address,
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
case Chain.THORChain:
|
|
403
|
+
case Chain.Maya:
|
|
404
|
+
case Chain.Kujira:
|
|
405
|
+
case Chain.Cosmos: {
|
|
406
|
+
return cosmosTransactionFee(params);
|
|
407
|
+
}
|
|
408
|
+
case Chain.Polkadot: {
|
|
409
|
+
const wallet = connectedWallets[chain as Chain.Polkadot];
|
|
410
|
+
return wallet.estimateTransactionFee({ ...params, recipient: wallet.address });
|
|
411
|
+
}
|
|
412
|
+
default:
|
|
413
|
+
return undefined;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
307
417
|
return {
|
|
308
418
|
...availablePlugins,
|
|
309
419
|
...connectWalletMethods,
|
|
@@ -317,6 +427,7 @@ export function SwapKit<
|
|
|
317
427
|
getAllWallets,
|
|
318
428
|
getWalletWithBalance,
|
|
319
429
|
isAssetValueApproved,
|
|
430
|
+
estimateTransactionFee,
|
|
320
431
|
swap,
|
|
321
432
|
transfer,
|
|
322
433
|
validateAddress,
|