@swapkit/plugins 4.2.10 → 4.6.19

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.
Files changed (107) hide show
  1. package/dist/LICENSE +246 -0
  2. package/dist/chunk-k2pk60qs.js +1 -0
  3. package/dist/chunk-nbtnyjp9.js +2 -0
  4. package/dist/src/chainflip/index.cjs +1 -0
  5. package/dist/src/chainflip/index.js +1 -0
  6. package/dist/src/evm/index.cjs +1 -0
  7. package/dist/src/evm/index.js +1 -0
  8. package/dist/src/garden/index.cjs +1 -0
  9. package/dist/src/garden/index.js +1 -0
  10. package/dist/src/harbor/index.cjs +1 -0
  11. package/dist/src/harbor/index.js +1 -0
  12. package/dist/src/index.cjs +1 -0
  13. package/dist/src/index.js +1 -0
  14. package/dist/src/near/index.cjs +1 -0
  15. package/dist/src/near/index.js +1 -0
  16. package/dist/src/radix/index.cjs +1 -0
  17. package/dist/src/radix/index.js +1 -0
  18. package/dist/{solana → src/solana}/index.cjs +1 -4
  19. package/dist/src/solana/index.js +1 -0
  20. package/dist/src/swapkit/index.cjs +1 -0
  21. package/dist/src/swapkit/index.js +1 -0
  22. package/dist/src/thorchain/index.cjs +1 -0
  23. package/dist/src/thorchain/index.js +1 -0
  24. package/dist/types/chainflip/broker.d.ts +3 -3
  25. package/dist/types/chainflip/broker.d.ts.map +1 -1
  26. package/dist/types/chainflip/plugin.d.ts.map +1 -1
  27. package/dist/types/chainflip/types.d.ts +4 -1
  28. package/dist/types/chainflip/types.d.ts.map +1 -1
  29. package/dist/types/evm/index.d.ts +7 -5
  30. package/dist/types/evm/index.d.ts.map +1 -1
  31. package/dist/types/garden/plugin.d.ts +6 -4
  32. package/dist/types/garden/plugin.d.ts.map +1 -1
  33. package/dist/types/harbor/index.d.ts +20 -0
  34. package/dist/types/harbor/index.d.ts.map +1 -0
  35. package/dist/types/index.d.ts +2 -0
  36. package/dist/types/index.d.ts.map +1 -1
  37. package/dist/types/near/plugin.d.ts +7 -1
  38. package/dist/types/near/plugin.d.ts.map +1 -1
  39. package/dist/types/near/types.d.ts +17 -0
  40. package/dist/types/near/types.d.ts.map +1 -1
  41. package/dist/types/radix/index.d.ts +2 -2
  42. package/dist/types/radix/index.d.ts.map +1 -1
  43. package/dist/types/swapkit/index.d.ts +2 -0
  44. package/dist/types/swapkit/index.d.ts.map +1 -0
  45. package/dist/types/swapkit/plugin.d.ts +20 -0
  46. package/dist/types/swapkit/plugin.d.ts.map +1 -0
  47. package/dist/types/types.d.ts +3 -1
  48. package/dist/types/types.d.ts.map +1 -1
  49. package/dist/types/utils.d.ts +5 -3
  50. package/dist/types/utils.d.ts.map +1 -1
  51. package/package.json +41 -39
  52. package/dist/chainflip/index.cjs +0 -4
  53. package/dist/chainflip/index.cjs.map +0 -11
  54. package/dist/chainflip/index.js +0 -4
  55. package/dist/chainflip/index.js.map +0 -11
  56. package/dist/chunk-g305pte1.js +0 -4
  57. package/dist/chunk-g305pte1.js.map +0 -10
  58. package/dist/chunk-ykf9bj9d.js +0 -5
  59. package/dist/chunk-ykf9bj9d.js.map +0 -10
  60. package/dist/evm/index.cjs +0 -4
  61. package/dist/evm/index.cjs.map +0 -10
  62. package/dist/evm/index.js +0 -4
  63. package/dist/evm/index.js.map +0 -10
  64. package/dist/garden/index.cjs +0 -4
  65. package/dist/garden/index.cjs.map +0 -10
  66. package/dist/garden/index.js +0 -4
  67. package/dist/garden/index.js.map +0 -10
  68. package/dist/index.cjs +0 -4
  69. package/dist/index.cjs.map +0 -10
  70. package/dist/index.js +0 -4
  71. package/dist/index.js.map +0 -10
  72. package/dist/near/index.cjs +0 -4
  73. package/dist/near/index.cjs.map +0 -11
  74. package/dist/near/index.js +0 -4
  75. package/dist/near/index.js.map +0 -11
  76. package/dist/radix/index.cjs +0 -4
  77. package/dist/radix/index.cjs.map +0 -10
  78. package/dist/radix/index.js +0 -4
  79. package/dist/radix/index.js.map +0 -10
  80. package/dist/solana/index.cjs.map +0 -10
  81. package/dist/solana/index.js +0 -4
  82. package/dist/solana/index.js.map +0 -10
  83. package/dist/thorchain/index.cjs +0 -4
  84. package/dist/thorchain/index.cjs.map +0 -11
  85. package/dist/thorchain/index.js +0 -4
  86. package/dist/thorchain/index.js.map +0 -11
  87. package/src/chainflip/broker.ts +0 -112
  88. package/src/chainflip/index.ts +0 -3
  89. package/src/chainflip/plugin.ts +0 -52
  90. package/src/chainflip/types.ts +0 -37
  91. package/src/evm/index.ts +0 -45
  92. package/src/garden/index.ts +0 -1
  93. package/src/garden/plugin.ts +0 -54
  94. package/src/index.ts +0 -37
  95. package/src/near/index.ts +0 -2
  96. package/src/near/nearNames.ts +0 -37
  97. package/src/near/plugin.ts +0 -216
  98. package/src/near/types.ts +0 -9
  99. package/src/radix/index.ts +0 -24
  100. package/src/solana/index.ts +0 -1
  101. package/src/solana/plugin.ts +0 -26
  102. package/src/thorchain/index.ts +0 -3
  103. package/src/thorchain/plugin.ts +0 -492
  104. package/src/thorchain/shared.ts +0 -17
  105. package/src/thorchain/types.ts +0 -59
  106. package/src/types.ts +0 -22
  107. package/src/utils.ts +0 -42
@@ -1,492 +0,0 @@
1
- import {
2
- ApproveMode,
3
- type ApproveReturnType,
4
- AssetValue,
5
- Chain,
6
- type ErrorKeys,
7
- type EVMChain,
8
- EVMChains,
9
- FeeOption,
10
- getChainConfig,
11
- getMemoForDeposit,
12
- getMemoForLeaveAndBond,
13
- getMemoForNamePreferredAssetRegister,
14
- getMemoForNameRegister,
15
- getMemoForTcyClaim,
16
- getMemoForTcyStake,
17
- getMemoForUnbond,
18
- getMemoForWithdraw,
19
- getMinAmountByChain,
20
- MemoType,
21
- ProviderName,
22
- SwapKitError,
23
- type SwapParams,
24
- type TCLikeChain,
25
- wrapWithThrow,
26
- } from "@swapkit/helpers";
27
- import {
28
- type InboundAddressesItem,
29
- type QuoteResponseRoute,
30
- SwapKitApi,
31
- type THORNodeType,
32
- } from "@swapkit/helpers/api";
33
- import {
34
- MayaArbitrumVaultAbi,
35
- MayaEthereumVaultAbi,
36
- TCAvalancheDepositABI,
37
- TCBaseDepositABI,
38
- TCBscDepositABI,
39
- TCEthereumVaultAbi,
40
- } from "@swapkit/helpers/contracts";
41
- import type { SwapKitPluginParams } from "../types";
42
- import { createPlugin } from "../utils";
43
- import { prepareTxParams, validateAddressType } from "./shared";
44
- import type {
45
- AddLiquidityParams,
46
- AddLiquidityPartParams,
47
- CoreTxParams,
48
- CreateLiquidityParams,
49
- NodeActionParams,
50
- RegisterThornameParams,
51
- WithdrawParams,
52
- } from "./types";
53
-
54
- const gasFeeMultiplier: Record<FeeOption, number> = {
55
- [FeeOption.Average]: 1.2,
56
- [FeeOption.Fast]: 1.5,
57
- [FeeOption.Fastest]: 2,
58
- };
59
-
60
- const TCSpecificAbi = {
61
- [Chain.Avalanche]: TCAvalancheDepositABI,
62
- [Chain.Base]: TCBaseDepositABI,
63
- [Chain.BinanceSmartChain]: TCBscDepositABI,
64
- [Chain.Ethereum]: TCEthereumVaultAbi,
65
- };
66
-
67
- const MayaSpecificAbi = { [Chain.Arbitrum]: MayaArbitrumVaultAbi, [Chain.Ethereum]: MayaEthereumVaultAbi };
68
-
69
- export const ThorchainPlugin = createPlugin({
70
- methods: createTCBasedPlugin(Chain.THORChain),
71
- name: "thorchain",
72
- properties: { supportedSwapkitProviders: [ProviderName.THORCHAIN, ProviderName.THORCHAIN_STREAMING] as const },
73
- });
74
-
75
- export const MayachainPlugin = createPlugin({
76
- methods: createTCBasedPlugin(Chain.Maya),
77
- name: "mayachain",
78
- properties: { supportedSwapkitProviders: [ProviderName.MAYACHAIN, ProviderName.MAYACHAIN_STREAMING] as const },
79
- });
80
-
81
- function getInboundDataFunction(type?: THORNodeType) {
82
- return async function getInboundDataByChain<T extends Chain>(chain: T) {
83
- if ((type === "thorchain" && chain === Chain.THORChain) || (type === "mayachain" && chain === Chain.Maya)) {
84
- return {
85
- address: "",
86
- chain,
87
- dust_threshold: "0",
88
- gas_rate: "0",
89
- halted: false,
90
- router: "",
91
- } as InboundAddressesItem;
92
- }
93
-
94
- const inboundData = await SwapKitApi.thornode.getInboundAddresses(type);
95
- const chainAddressData = inboundData.find((item) => item.chain === chain);
96
-
97
- if (!chainAddressData) throw new SwapKitError("core_inbound_data_not_found");
98
- if (chainAddressData?.halted) throw new SwapKitError("core_chain_halted");
99
-
100
- return chainAddressData;
101
- };
102
- }
103
-
104
- function createTCBasedPlugin<T extends TCLikeChain>(pluginChain: T) {
105
- return function plugin({ getWallet }: SwapKitPluginParams) {
106
- const pluginType = pluginChain === Chain.Maya ? "mayachain" : "thorchain";
107
- const getInboundDataByChain = getInboundDataFunction(pluginType);
108
-
109
- async function approve<T extends ApproveMode>({
110
- assetValue,
111
- type = "checkOnly" as T,
112
- }: {
113
- type: T;
114
- assetValue: AssetValue;
115
- }) {
116
- const router = (await getInboundDataByChain(assetValue.chain)).router as string;
117
-
118
- const chain = assetValue.chain as EVMChain;
119
-
120
- const isEVMChain = EVMChains.includes(chain as EVMChain);
121
- const isNativeEVM = isEVMChain && assetValue.isGasAsset;
122
-
123
- if (isNativeEVM || !isEVMChain || assetValue.isSynthetic) {
124
- return Promise.resolve(type === "checkOnly" ? true : "approved") as ApproveReturnType<T>;
125
- }
126
-
127
- const wallet = getWallet(chain);
128
-
129
- if (!wallet) {
130
- throw new SwapKitError("core_wallet_connection_not_found");
131
- }
132
-
133
- const walletAction = type === "checkOnly" ? wallet.isApproved : wallet.approve;
134
-
135
- if (!(assetValue.address && wallet.address)) {
136
- throw new SwapKitError("core_approve_asset_address_or_from_not_found");
137
- }
138
-
139
- return walletAction({
140
- amount: assetValue.getBaseValue("bigint"),
141
- assetAddress: assetValue.address,
142
- from: wallet.address,
143
- spenderAddress: router,
144
- });
145
- }
146
-
147
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO
148
- async function deposit({ assetValue, recipient, router, ...rest }: CoreTxParams & { router?: string }) {
149
- const abis = pluginType === "thorchain" ? TCSpecificAbi : MayaSpecificAbi;
150
- const { chain, symbol, ticker } = assetValue;
151
-
152
- const wallet = getWallet(chain);
153
- if (!wallet) {
154
- throw new SwapKitError("core_wallet_connection_not_found");
155
- }
156
- const { address } = wallet;
157
- const isAddressValidated = validateAddressType({ address, chain });
158
- if (!isAddressValidated) {
159
- throw new SwapKitError("core_transaction_invalid_sender_address");
160
- }
161
-
162
- const params = prepareTxParams({ assetValue, from: address, recipient, router, ...rest });
163
-
164
- try {
165
- const abi = abis?.[chain as keyof typeof abis];
166
-
167
- if (!abi) {
168
- const wallet = getWallet(chain as TCLikeChain);
169
- const shouldDeposit = pluginChain === chain && recipient === "";
170
- // @Towan: Is that the same action? :)
171
- return shouldDeposit ? wallet.deposit(params) : wallet.transfer(params);
172
- }
173
-
174
- const { getChecksumAddressFromAsset } = await import("@swapkit/toolboxes/evm");
175
- const wallet = getWallet(chain as EVMChain);
176
-
177
- return wallet.call<string>({
178
- abi,
179
- contractAddress: router || ((await getInboundDataByChain(chain)).router as string),
180
- funcName: "depositWithExpiry",
181
- funcParams: [
182
- recipient,
183
- getChecksumAddressFromAsset({ chain, symbol, ticker }, chain as EVMChain),
184
- assetValue.getBaseValue("string"),
185
- params.memo,
186
- rest.expiration || Number.parseInt(`${(Date.now() + 15 * 60 * 1000) / 1000}`, 10),
187
- ],
188
- txOverrides: {
189
- from: params.from,
190
- value: assetValue.isGasAsset ? assetValue.getBaseValue("bigint") : undefined,
191
- },
192
- });
193
- } catch (error) {
194
- const errorMessage =
195
- // @ts-expect-error Fine to use error as string
196
- typeof error === "string" ? error.toLowerCase() : error?.message.toLowerCase();
197
- const isInsufficientFunds = errorMessage?.includes("insufficient funds");
198
- const isGas = errorMessage?.includes("gas");
199
- const isServer = errorMessage?.includes("server");
200
- const isUserRejected = errorMessage?.includes("user rejected");
201
- const errorKey: ErrorKeys = isInsufficientFunds
202
- ? "core_transaction_deposit_insufficient_funds_error"
203
- : isGas
204
- ? "core_transaction_deposit_gas_error"
205
- : isServer
206
- ? "core_transaction_deposit_server_error"
207
- : isUserRejected
208
- ? "core_transaction_user_rejected"
209
- : "core_transaction_deposit_error";
210
-
211
- throw new SwapKitError(errorKey, error);
212
- }
213
- }
214
-
215
- async function depositToProtocol({ memo, assetValue }: { assetValue: AssetValue; memo: string }) {
216
- const mimir = await SwapKitApi.thornode.getMimirInfo(pluginType);
217
-
218
- // check if trading is halted or not
219
- if (mimir.HALTCHAINGLOBAL >= 1 || mimir.HALTTHORCHAIN >= 1) {
220
- throw new SwapKitError("thorchain_chain_halted");
221
- }
222
-
223
- return deposit({ assetValue, memo, recipient: "" });
224
- }
225
-
226
- async function depositToPool({
227
- assetValue,
228
- memo,
229
- feeOptionKey = FeeOption.Fast,
230
- }: {
231
- assetValue: AssetValue;
232
- memo: string;
233
- feeOptionKey?: FeeOption;
234
- }) {
235
- const { gas_rate = "0", router, address: poolAddress } = await getInboundDataByChain(assetValue.chain);
236
-
237
- return deposit({
238
- assetValue,
239
- feeRate: Number.parseInt(gas_rate, 10) * gasFeeMultiplier[feeOptionKey],
240
- memo,
241
- recipient: poolAddress,
242
- router,
243
- });
244
- }
245
-
246
- function approveAssetValue({ assetValue }: { assetValue: AssetValue }) {
247
- return approve({ assetValue, type: ApproveMode.Approve });
248
- }
249
-
250
- function isAssetValueApproved({ assetValue }: { assetValue: AssetValue }) {
251
- return approve({ assetValue, type: ApproveMode.CheckOnly });
252
- }
253
-
254
- function registerName({ assetValue, ...params }: RegisterThornameParams) {
255
- return depositToProtocol({ assetValue, memo: getMemoForNameRegister(params) });
256
- }
257
-
258
- function registerPreferredAsset({
259
- assetValue,
260
- payoutAddress,
261
- name,
262
- ownerAddress,
263
- }: {
264
- assetValue: AssetValue;
265
- payoutAddress?: string;
266
- name: string;
267
- ownerAddress: string;
268
- }) {
269
- const payout = payoutAddress || getWallet(assetValue.chain)?.address;
270
-
271
- if (!payout) {
272
- throw new SwapKitError("thorchain_preferred_asset_payout_required");
273
- }
274
-
275
- return depositToProtocol({
276
- assetValue: AssetValue.from({ chain: pluginChain }),
277
- memo: getMemoForNamePreferredAssetRegister({
278
- asset: assetValue.toString(),
279
- chain: assetValue.chain,
280
- name,
281
- owner: ownerAddress,
282
- payout,
283
- }),
284
- });
285
- }
286
-
287
- function nodeAction({ type, assetValue, address }: NodeActionParams) {
288
- const memo =
289
- type === MemoType.UNBOND
290
- ? getMemoForUnbond({ address, unbondAmount: assetValue.getBaseValue("number") })
291
- : getMemoForLeaveAndBond({ address, type });
292
-
293
- const assetToTransfer = type === MemoType.BOND ? assetValue : getMinAmountByChain(pluginChain);
294
- return depositToProtocol({ assetValue: assetToTransfer, memo });
295
- }
296
-
297
- async function createLiquidity({ baseAssetValue, assetValue }: CreateLiquidityParams) {
298
- if (baseAssetValue.lte(0) || assetValue.lte(0)) {
299
- throw new SwapKitError("core_transaction_create_liquidity_invalid_params");
300
- }
301
-
302
- const assetAddress = getWallet(assetValue.chain).address;
303
- const baseAssetAddress = getWallet(pluginChain).address;
304
-
305
- const baseAssetTx = await wrapWithThrow(() => {
306
- return depositToPool({
307
- assetValue: baseAssetValue,
308
- memo: getMemoForDeposit({ ...assetValue, address: assetAddress }),
309
- });
310
- }, "core_transaction_create_liquidity_base_error");
311
-
312
- const assetTx = await wrapWithThrow(() => {
313
- return depositToPool({ assetValue, memo: getMemoForDeposit({ ...assetValue, address: baseAssetAddress }) });
314
- }, "core_transaction_create_liquidity_asset_error");
315
-
316
- return { assetTx, baseAssetTx };
317
- }
318
-
319
- function addLiquidityPart({ assetValue, poolAddress, address, symmetric }: AddLiquidityPartParams) {
320
- if (symmetric && !address) {
321
- throw new SwapKitError("core_transaction_add_liquidity_invalid_params");
322
- }
323
- const memo = getMemoForDeposit({
324
- address: symmetric ? address : "",
325
- chain: poolAddress.split(".")[0] as Chain,
326
- symbol: poolAddress.split(".")[1] as string,
327
- });
328
-
329
- return depositToPool({ assetValue, memo });
330
- }
331
-
332
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO
333
- async function addLiquidity({
334
- baseAssetValue,
335
- assetValue,
336
- baseAssetAddr,
337
- assetAddr,
338
- isPendingSymmAsset,
339
- mode = "sym",
340
- }: AddLiquidityParams) {
341
- const { chain, symbol } = assetValue;
342
- const isSym = mode === "sym";
343
- const baseTransfer = baseAssetValue?.gt(0) && (isSym || mode === "baseAsset");
344
- const assetTransfer = assetValue?.gt(0) && (isSym || mode === "asset");
345
- const includeBaseAddress = isPendingSymmAsset || baseTransfer;
346
- const baseAssetWalletAddress = getWallet(pluginChain).address;
347
-
348
- const baseAddress = includeBaseAddress ? baseAssetAddr || baseAssetWalletAddress : "";
349
- const assetAddress = isSym || mode === "asset" ? assetAddr || getWallet(chain).address : "";
350
-
351
- if (!(baseTransfer || assetTransfer)) {
352
- throw new SwapKitError("core_transaction_add_liquidity_invalid_params");
353
- }
354
- if (includeBaseAddress && !baseAddress) {
355
- throw new SwapKitError("core_transaction_add_liquidity_base_address");
356
- }
357
-
358
- const baseAssetTx =
359
- baseTransfer && baseAssetValue
360
- ? await wrapWithThrow(() => {
361
- return depositToPool({
362
- assetValue: baseAssetValue,
363
- memo: getMemoForDeposit({ address: assetAddress, chain, symbol }),
364
- });
365
- }, "core_transaction_add_liquidity_base_error")
366
- : undefined;
367
-
368
- const assetTx =
369
- assetTransfer && assetValue
370
- ? await wrapWithThrow(() => {
371
- return depositToPool({ assetValue, memo: getMemoForDeposit({ address: baseAddress, chain, symbol }) });
372
- }, "core_transaction_add_liquidity_asset_error")
373
- : undefined;
374
-
375
- return { assetTx, baseAssetTx };
376
- }
377
-
378
- function withdraw({ memo, assetValue, percent, from, to }: WithdrawParams) {
379
- const targetAsset =
380
- to === "baseAsset" && from !== "baseAsset"
381
- ? AssetValue.from({ chain: pluginChain })
382
- : (from === "sym" && to === "sym") || from === "baseAsset" || from === "asset"
383
- ? undefined
384
- : assetValue;
385
-
386
- const value = getMinAmountByChain(from === "asset" ? assetValue.chain : pluginChain);
387
- const memoString =
388
- memo ||
389
- getMemoForWithdraw({
390
- basisPoints: Math.min(10000, Math.round(percent * 100)),
391
- chain: assetValue.chain,
392
- symbol: assetValue.symbol,
393
- targetAsset: targetAsset?.toString(),
394
- ticker: assetValue.ticker,
395
- });
396
-
397
- return depositToPool({ assetValue: value, memo: memoString });
398
- }
399
-
400
- async function claimTcy({ chain, thorAddress }: { chain: Chain; thorAddress: string }) {
401
- const inboundData = await getInboundDataByChain(chain);
402
- const dust_threshold = inboundData.dust_threshold;
403
- const { baseDecimal: chainDecimal } = getChainConfig(chain);
404
- const { baseDecimal: tcDecimal } = getChainConfig(Chain.THORChain);
405
-
406
- return deposit({
407
- assetValue: AssetValue.from({
408
- chain,
409
- fromBaseDecimal: Math.min(chainDecimal, tcDecimal),
410
- value: chain !== Chain.THORChain ? dust_threshold : 0,
411
- }),
412
- memo: getMemoForTcyClaim(MemoType.CLAIM_TCY, { address: thorAddress }),
413
- recipient: inboundData.address,
414
- router: inboundData.router,
415
- });
416
- }
417
-
418
- function stakeTcyAction(
419
- params: { type: "unstake"; unstakeBps: number } | { type: "stake"; assetValue: AssetValue },
420
- ) {
421
- if (params.type === "stake") {
422
- if (params.assetValue.toString() !== "THOR.TCY") {
423
- throw new SwapKitError("thorchain_asset_is_not_tcy");
424
- }
425
-
426
- return deposit({
427
- assetValue: params.assetValue,
428
- memo: getMemoForTcyStake(MemoType.STAKE_TCY, {}),
429
- recipient: "",
430
- });
431
- }
432
-
433
- return deposit({
434
- assetValue: AssetValue.from({ chain: Chain.THORChain }),
435
- memo: getMemoForTcyStake(MemoType.UNSTAKE_TCY, { unstakeBps: params.unstakeBps }),
436
- recipient: "",
437
- });
438
- }
439
-
440
- async function swap({ feeOptionKey, route }: SwapParams<typeof pluginType, QuoteResponseRoute>) {
441
- const { memo, expiration, targetAddress } = route;
442
-
443
- const assetValue = await AssetValue.from({
444
- asset: route.sellAsset,
445
- asyncTokenLookup: true,
446
- value: route.sellAmount,
447
- });
448
-
449
- if (!assetValue) {
450
- throw new SwapKitError("core_swap_asset_not_recognized");
451
- }
452
-
453
- const isRecipientValidated = validateAddressType({
454
- address: route.destinationAddress,
455
- chain: AssetValue.from({ asset: route.buyAsset }).chain,
456
- });
457
-
458
- if (!isRecipientValidated) {
459
- throw new SwapKitError("core_transaction_invalid_recipient_address");
460
- }
461
-
462
- const { address: recipient } = await getInboundDataByChain(assetValue.chain);
463
-
464
- return deposit({
465
- assetValue,
466
- expiration: Number(expiration),
467
- feeOptionKey,
468
- memo,
469
- recipient,
470
- router: targetAddress,
471
- });
472
- }
473
-
474
- return {
475
- addLiquidity,
476
- addLiquidityPart,
477
- approveAssetValue,
478
- claimTcy,
479
- createLiquidity,
480
- deposit,
481
- depositToPool,
482
- getInboundDataByChain,
483
- isAssetValueApproved,
484
- nodeAction,
485
- registerName,
486
- registerPreferredAsset,
487
- stakeTcyAction,
488
- swap,
489
- withdraw,
490
- };
491
- };
492
- }
@@ -1,17 +0,0 @@
1
- import { Chain } from "@swapkit/helpers";
2
- import type { CoreTxParams } from "./types";
3
-
4
- export function validateAddressType({ chain, address }: { chain?: Chain; address?: string }) {
5
- if (!address) return false;
6
-
7
- return chain === Chain.Bitcoin ? !address.startsWith("bc1p") : true;
8
- }
9
-
10
- export function prepareTxParams({
11
- assetValue,
12
- from,
13
- memo = "",
14
- ...restTxParams
15
- }: CoreTxParams & { from: string; router?: string }) {
16
- return { ...restTxParams, assetValue, from, memo };
17
- }
@@ -1,59 +0,0 @@
1
- import type { AssetValue, FeeOption, MemoType } from "@swapkit/helpers";
2
-
3
- export type AddLiquidityPartParams = {
4
- assetValue: AssetValue;
5
- address?: string;
6
- poolAddress: string;
7
- symmetric: boolean;
8
- };
9
-
10
- export type AddLiquidityParams = {
11
- assetAddr?: string;
12
- assetValue: AssetValue;
13
- baseAssetAddr?: string;
14
- baseAssetValue: AssetValue;
15
- isPendingSymmAsset?: boolean;
16
- mode?: "sym" | "baseAsset" | "asset";
17
- };
18
-
19
- export type CreateLiquidityParams = { baseAssetValue: AssetValue; assetValue: AssetValue };
20
-
21
- export type CoreTxParams = {
22
- assetValue: AssetValue;
23
- recipient: string;
24
- memo?: string;
25
- feeOptionKey?: FeeOption;
26
- feeRate?: number;
27
- data?: string;
28
- from?: string;
29
- expiration?: number;
30
- };
31
-
32
- export type NodeActionParams = { address: string } & (
33
- | { type: MemoType.BOND | MemoType.UNBOND; assetValue: AssetValue }
34
- | { type: MemoType.LEAVE; assetValue?: undefined }
35
- );
36
-
37
- export type RegisterThornameParams = {
38
- assetValue: AssetValue;
39
- name: string;
40
- chain: string;
41
- address: string;
42
- owner?: string;
43
- preferredAsset?: string;
44
- };
45
-
46
- export type RegisterPreferredAssetParams = {
47
- assetValue: AssetValue;
48
- name: string;
49
- chain: string;
50
- address: string;
51
- owner: string;
52
- };
53
-
54
- type CommonWithdrawParams = { assetValue: AssetValue; memo?: string; percent: number };
55
-
56
- export type WithdrawParams = CommonWithdrawParams & {
57
- from: "sym" | "baseAsset" | "asset";
58
- to: "sym" | "baseAsset" | "asset";
59
- };
package/src/types.ts DELETED
@@ -1,22 +0,0 @@
1
- import type { Chain } from "@swapkit/helpers";
2
- import type { FullWallet } from "@swapkit/toolboxes";
3
- import type { ChainflipPlugin } from "./chainflip";
4
- import type { EVMPlugin } from "./evm";
5
- import type { NearPlugin } from "./near";
6
- import type { RadixPlugin } from "./radix";
7
- import type { SolanaPlugin } from "./solana/plugin";
8
- import type { ThorchainPlugin } from "./thorchain";
9
-
10
- export type * from "./chainflip/types";
11
- export type * from "./thorchain/types";
12
-
13
- export type SKPlugins = typeof ChainflipPlugin &
14
- typeof ThorchainPlugin &
15
- typeof RadixPlugin &
16
- typeof SolanaPlugin &
17
- typeof EVMPlugin &
18
- typeof NearPlugin;
19
-
20
- export type PluginName = keyof SKPlugins;
21
-
22
- export type SwapKitPluginParams = { getWallet: <T extends Chain>(chain: T) => FullWallet[T] };
package/src/utils.ts DELETED
@@ -1,42 +0,0 @@
1
- import type { ApproveMode, ApproveReturnType, EVMChain, ProviderName } from "@swapkit/helpers";
2
- import { type AssetValue, EVMChains, SwapKitError } from "@swapkit/helpers";
3
- import type { SwapKitPluginParams } from "./types";
4
-
5
- export function createPlugin<
6
- const Name extends string,
7
- T extends (params: SwapKitPluginParams) => Record<string, unknown>,
8
- K extends { supportedSwapkitProviders?: readonly ProviderName[] },
9
- >({ name, properties, methods }: { name: Name; properties?: K; methods: T }) {
10
- function plugin(pluginParams: SwapKitPluginParams) {
11
- return { ...methods(pluginParams), ...properties } as K & ReturnType<T>;
12
- }
13
-
14
- return { [name]: plugin } as { [key in Name]: typeof plugin };
15
- }
16
-
17
- export function approve<T extends ApproveMode>({ approveMode, getWallet }: { approveMode: T } & SwapKitPluginParams) {
18
- return function approve({ assetValue, spenderAddress }: { spenderAddress: string; assetValue: AssetValue }) {
19
- const evmChain = assetValue.chain as EVMChain;
20
- const isEVMChain = EVMChains.includes(evmChain);
21
- const isNativeEVM = isEVMChain && assetValue.isGasAsset;
22
-
23
- if (isNativeEVM || !isEVMChain || assetValue.isSynthetic) {
24
- const isApproved = approveMode === "checkOnly" || "approved";
25
- return Promise.resolve(isApproved) as ApproveReturnType<T>;
26
- }
27
-
28
- const wallet = getWallet(evmChain);
29
- const walletAction = approveMode === "checkOnly" ? wallet.isApproved : wallet.approve;
30
-
31
- if (!(assetValue.address && wallet.address)) {
32
- throw new SwapKitError("core_approve_asset_address_or_from_not_found");
33
- }
34
-
35
- return walletAction({
36
- amount: assetValue.getBaseValue("bigint"),
37
- assetAddress: assetValue.address,
38
- from: wallet.address,
39
- spenderAddress,
40
- });
41
- };
42
- }