@swapkit/plugins 4.0.0-beta.49 → 4.0.0-beta.51

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 (88) hide show
  1. package/dist/chainflip/index.cjs +2 -2
  2. package/dist/chainflip/index.cjs.map +3 -3
  3. package/dist/chainflip/index.js +2 -2
  4. package/dist/chainflip/index.js.map +3 -3
  5. package/dist/chunk-hzmkxs26.js +5 -0
  6. package/dist/chunk-hzmkxs26.js.map +10 -0
  7. package/dist/chunk-npbmqeem.js +4 -0
  8. package/dist/chunk-npbmqeem.js.map +10 -0
  9. package/dist/evm/index.cjs +2 -2
  10. package/dist/evm/index.cjs.map +3 -3
  11. package/dist/evm/index.js +2 -2
  12. package/dist/evm/index.js.map +3 -3
  13. package/dist/index.cjs +2 -2
  14. package/dist/index.cjs.map +3 -4
  15. package/dist/index.js +2 -2
  16. package/dist/index.js.map +3 -4
  17. package/dist/near/index.cjs +2 -2
  18. package/dist/near/index.cjs.map +3 -3
  19. package/dist/near/index.js +2 -2
  20. package/dist/near/index.js.map +3 -3
  21. package/dist/radix/index.cjs +2 -2
  22. package/dist/radix/index.cjs.map +3 -3
  23. package/dist/radix/index.js +2 -2
  24. package/dist/radix/index.js.map +3 -3
  25. package/dist/solana/index.cjs +2 -2
  26. package/dist/solana/index.cjs.map +3 -3
  27. package/dist/solana/index.js +2 -2
  28. package/dist/solana/index.js.map +3 -3
  29. package/dist/thorchain/index.cjs +2 -2
  30. package/dist/thorchain/index.cjs.map +3 -3
  31. package/dist/thorchain/index.js +2 -2
  32. package/dist/thorchain/index.js.map +3 -3
  33. package/dist/types/chainflip/broker.d.ts +20 -0
  34. package/dist/types/chainflip/broker.d.ts.map +1 -0
  35. package/{src/chainflip/index.ts → dist/types/chainflip/index.d.ts} +1 -0
  36. package/dist/types/chainflip/index.d.ts.map +1 -0
  37. package/dist/types/chainflip/plugin.d.ts +10 -0
  38. package/dist/types/chainflip/plugin.d.ts.map +1 -0
  39. package/dist/types/chainflip/types.d.ts +41 -0
  40. package/dist/types/chainflip/types.d.ts.map +1 -0
  41. package/dist/types/evm/index.d.ts +19 -0
  42. package/dist/types/evm/index.d.ts.map +1 -0
  43. package/{src/index.ts → dist/types/index.d.ts} +1 -0
  44. package/dist/types/index.d.ts.map +1 -0
  45. package/{src/near/index.ts → dist/types/near/index.d.ts} +1 -0
  46. package/dist/types/near/index.d.ts.map +1 -0
  47. package/dist/types/near/nearNames.d.ts +3 -0
  48. package/dist/types/near/nearNames.d.ts.map +1 -0
  49. package/dist/types/near/plugin.d.ts +19 -0
  50. package/dist/types/near/plugin.d.ts.map +1 -0
  51. package/dist/types/near/types.d.ts +11 -0
  52. package/dist/types/near/types.d.ts.map +1 -0
  53. package/dist/types/radix/index.d.ts +10 -0
  54. package/dist/types/radix/index.d.ts.map +1 -0
  55. package/{src/solana/index.ts → dist/types/solana/index.d.ts} +1 -0
  56. package/dist/types/solana/index.d.ts.map +1 -0
  57. package/dist/types/solana/plugin.d.ts +10 -0
  58. package/dist/types/solana/plugin.d.ts.map +1 -0
  59. package/{src/thorchain/index.ts → dist/types/thorchain/index.d.ts} +1 -0
  60. package/dist/types/thorchain/index.d.ts.map +1 -0
  61. package/dist/types/thorchain/plugin.d.ts +107 -0
  62. package/dist/types/thorchain/plugin.d.ts.map +1 -0
  63. package/dist/types/thorchain/shared.d.ts +21 -0
  64. package/dist/types/thorchain/shared.d.ts.map +1 -0
  65. package/dist/types/thorchain/types.d.ts +64 -0
  66. package/dist/types/thorchain/types.d.ts.map +1 -0
  67. package/{src/types.ts → dist/types/types.d.ts} +7 -9
  68. package/dist/types/types.d.ts.map +1 -0
  69. package/dist/types/utils.d.ts +11 -0
  70. package/dist/types/utils.d.ts.map +1 -0
  71. package/package.json +12 -15
  72. package/dist/chunk-fazw0jvt.js +0 -4
  73. package/dist/chunk-fazw0jvt.js.map +0 -9
  74. package/dist/chunk-wfktpptf.js +0 -5
  75. package/dist/chunk-wfktpptf.js.map +0 -9
  76. package/src/chainflip/broker.ts +0 -127
  77. package/src/chainflip/plugin.ts +0 -73
  78. package/src/chainflip/types.ts +0 -48
  79. package/src/evm/index.ts +0 -82
  80. package/src/near/nearNames.ts +0 -37
  81. package/src/near/plugin.ts +0 -192
  82. package/src/near/types.ts +0 -11
  83. package/src/radix/index.ts +0 -36
  84. package/src/solana/plugin.ts +0 -36
  85. package/src/thorchain/plugin.ts +0 -528
  86. package/src/thorchain/shared.ts +0 -17
  87. package/src/thorchain/types.ts +0 -66
  88. package/src/utils.ts +0 -34
@@ -1,48 +0,0 @@
1
- import type { AssetValue, SwapParams } from "@swapkit/helpers";
2
- import type { QuoteResponseRoute } from "@swapkit/helpers/api";
3
-
4
- export type WithdrawFeeResponse = {
5
- egressId: string;
6
- egressAsset: string;
7
- egressAmount: string;
8
- egressFee: string;
9
- destinationAddress: string;
10
- };
11
-
12
- export type DepositChannelRequest = {
13
- brokerCommissionBPS: number;
14
- ccmMetadata: ccmMetadata | null;
15
- maxBoostFeeBps?: number;
16
- affiliateFees?: AffiliateBroker[];
17
- refundParameters?: SwapRefundParameters;
18
- };
19
-
20
- export type ccmMetadata = {
21
- message: string;
22
- gasBudget: string;
23
- cfParameters: string;
24
- };
25
-
26
- export type SwapDepositResponse = {
27
- depositChannelId: string;
28
- depositAddress: string;
29
- srcChainExpiryBlock: number;
30
- sellAsset: AssetValue;
31
- buyAsset: AssetValue;
32
- recipient: string;
33
- brokerCommissionBPS: number;
34
- };
35
-
36
- export type AffiliateBroker = {
37
- brokerAddress: string;
38
- basisPoints: number;
39
- };
40
-
41
- export type SwapRefundParameters = {
42
- retryDuration: number;
43
- refundAddress: string;
44
- minPrice: string;
45
- };
46
-
47
- export type RequestSwapDepositAddressParams = Partial<SwapParams<"chainflip", QuoteResponseRoute>> &
48
- Partial<DepositChannelRequest>;
package/src/evm/index.ts DELETED
@@ -1,82 +0,0 @@
1
- import {
2
- ApproveMode,
3
- type ApproveReturnType,
4
- AssetValue,
5
- type EVMChain,
6
- EVMChains,
7
- ProviderName,
8
- SwapKitError,
9
- type SwapKitPluginParams,
10
- type SwapParams,
11
- createPlugin,
12
- } from "@swapkit/helpers";
13
- import type { EVMTransaction, QuoteResponseRoute } from "@swapkit/helpers/api";
14
-
15
- function approve<T extends ApproveMode>({
16
- approveMode,
17
- getWallet,
18
- }: { approveMode: T } & SwapKitPluginParams) {
19
- return function approveEVM({
20
- assetValue,
21
- spenderAddress,
22
- }: { spenderAddress: string; assetValue: AssetValue }) {
23
- const evmChain = assetValue.chain as EVMChain;
24
- const isEVMChain = EVMChains.includes(evmChain);
25
- const isNativeEVM = isEVMChain && assetValue.isGasAsset;
26
-
27
- if (isNativeEVM || !isEVMChain || assetValue.isSynthetic) {
28
- const isApproved = approveMode === "checkOnly" || "approved";
29
- return Promise.resolve(isApproved) as ApproveReturnType<T>;
30
- }
31
-
32
- const wallet = getWallet(evmChain);
33
- const walletAction = approveMode === "checkOnly" ? wallet.isApproved : wallet.approve;
34
-
35
- if (!(assetValue.address && wallet.address)) {
36
- throw new SwapKitError("core_approve_asset_address_or_from_not_found");
37
- }
38
-
39
- return walletAction({
40
- amount: assetValue.getBaseValue("bigint"),
41
- assetAddress: assetValue.address,
42
- from: wallet.address,
43
- spenderAddress,
44
- });
45
- };
46
- }
47
-
48
- export const EVMPlugin = createPlugin({
49
- name: "evm",
50
- properties: {
51
- supportedSwapkitProviders: [
52
- ProviderName.CAMELOT_V3,
53
- ProviderName.OPENOCEAN_V2,
54
- ProviderName.ONEINCH,
55
- ProviderName.PANCAKESWAP,
56
- ProviderName.PANGOLIN_V1,
57
- ProviderName.SUSHISWAP_V2,
58
- ProviderName.TRADERJOE_V2,
59
- ProviderName.UNISWAP_V2,
60
- ProviderName.UNISWAP_V3,
61
- ],
62
- },
63
- methods: ({ getWallet }) => ({
64
- approveAssetValue: approve({ approveMode: ApproveMode.Approve, getWallet }),
65
- isAssetValueApproved: approve({ approveMode: ApproveMode.CheckOnly, getWallet }),
66
- swap: async function evmSwap({
67
- route: { tx, sellAsset },
68
- feeOptionKey,
69
- }: SwapParams<"evm", QuoteResponseRoute>) {
70
- const assetValue = await AssetValue.from({ asset: sellAsset, asyncTokenLookup: true });
71
- const evmChain = assetValue.chain as EVMChain;
72
- const wallet = getWallet(evmChain);
73
-
74
- if (!(EVMChains.includes(evmChain) && tx)) {
75
- throw new SwapKitError("core_swap_invalid_params");
76
- }
77
-
78
- const { from, to, data, value } = tx as EVMTransaction;
79
- return wallet.sendTransaction({ from, to, data, value: BigInt(value), feeOptionKey });
80
- },
81
- }),
82
- });
@@ -1,37 +0,0 @@
1
- import { parseNearAmount } from "near-api-js/lib/utils/format";
2
-
3
- const MINIMUM_NAME_LENGTH = 2;
4
- const MAXIMUM_NAME_LENGTH = 64;
5
-
6
- export function validateNearName(name: string): boolean {
7
- if (name.length < MINIMUM_NAME_LENGTH || name.length > MAXIMUM_NAME_LENGTH) {
8
- return false;
9
- }
10
-
11
- // Only lowercase letters, numbers, and hyphens
12
- // Cannot start or end with hyphen
13
- // No consecutive hyphens
14
- return /^[a-z0-9]+(-[a-z0-9]+)*$/.test(name);
15
- }
16
-
17
- export function calculateNearNameCost(name: string): string {
18
- // Pricing based on name length
19
- // These are suggested prices, the actual minimum is ~0.00182 NEAR
20
- const length = name.length;
21
-
22
- let costInNear: string;
23
- if (length <= 2) {
24
- costInNear = "50"; // 50 NEAR for 2-char names
25
- } else if (length <= 3) {
26
- costInNear = "20"; // 20 NEAR for 3-char names
27
- } else if (length <= 4) {
28
- costInNear = "5"; // 5 NEAR for 4-char names
29
- } else if (length <= 5) {
30
- costInNear = "1"; // 1 NEAR for 5-char names
31
- } else {
32
- costInNear = "0.1"; // 0.1 NEAR for 6+ characters
33
- }
34
-
35
- // Convert NEAR to yoctoNEAR
36
- return parseNearAmount(costInNear) || "0";
37
- }
@@ -1,192 +0,0 @@
1
- import {
2
- AssetValue,
3
- Chain,
4
- type CryptoChain,
5
- ProviderName,
6
- SwapKitError,
7
- type SwapParams,
8
- createPlugin,
9
- } from "@swapkit/helpers";
10
- import { type QuoteResponseRoute, SwapKitApi } from "@swapkit/helpers/api";
11
- import type { NearWallet } from "@swapkit/toolboxes/near";
12
- import { calculateNearNameCost, validateNearName } from "./nearNames";
13
- import type { NearNameRegistrationParams } from "./types";
14
-
15
- export const NearPlugin = createPlugin({
16
- name: "near",
17
- properties: {
18
- supportedSwapkitProviders: [ProviderName.NEAR],
19
- },
20
- methods: ({ getWallet }) => ({
21
- async swap(swapParams: SwapParams<"near", QuoteResponseRoute>) {
22
- const {
23
- route: {
24
- buyAsset: buyAssetString,
25
- sellAsset: sellAssetString,
26
- sellAmount,
27
- meta: { near },
28
- },
29
- } = swapParams;
30
-
31
- if (!(sellAssetString && buyAssetString && near?.sellAsset)) {
32
- throw new SwapKitError("core_swap_asset_not_recognized");
33
- }
34
-
35
- const sellAsset = await AssetValue.from({
36
- asyncTokenLookup: true,
37
- asset: sellAssetString,
38
- value: sellAmount,
39
- });
40
-
41
- const wallet = getWallet(sellAsset.chain as Exclude<CryptoChain, Chain.Radix>);
42
-
43
- if (!wallet) {
44
- throw new SwapKitError("core_wallet_connection_not_found");
45
- }
46
-
47
- const { depositAddress } = await SwapKitApi.getNearDepositChannel(near);
48
-
49
- const tx = await wallet.transfer({
50
- assetValue: sellAsset,
51
- recipient: depositAddress,
52
- isProgramDerivedAddress: true,
53
- });
54
-
55
- return tx as string;
56
- },
57
-
58
- // NEAR Names functionality
59
- nearNames: {
60
- async resolve(name: string) {
61
- try {
62
- const normalizedName = name.toLowerCase().replace(/\.near$/, "");
63
-
64
- if (!validateNearName(normalizedName)) {
65
- throw new SwapKitError("plugin_near_invalid_name");
66
- }
67
-
68
- const wallet = getWallet(Chain.Near);
69
-
70
- if (!wallet) {
71
- throw new SwapKitError("plugin_near_no_connection");
72
- }
73
-
74
- const result = await wallet.provider.query({
75
- request_type: "call_function",
76
- finality: "final",
77
- account_id: "near",
78
- method_name: "resolve",
79
- args_base64: Buffer.from(JSON.stringify({ name: normalizedName })).toString("base64"),
80
- });
81
-
82
- const response = JSON.parse(Buffer.from((result as any).result).toString());
83
- return response?.owner || null;
84
- } catch {
85
- return null;
86
- }
87
- },
88
-
89
- async isAvailable(name: string) {
90
- const owner = await this.resolve(name);
91
- return owner === null;
92
- },
93
-
94
- async getInfo(name: string) {
95
- try {
96
- const normalizedName = name.toLowerCase().replace(/\.near$/, "");
97
-
98
- if (!validateNearName(normalizedName)) {
99
- throw new SwapKitError("plugin_near_invalid_name");
100
- }
101
-
102
- const wallet = getWallet(Chain.Near);
103
-
104
- if (!wallet) {
105
- throw new SwapKitError("plugin_near_no_connection");
106
- }
107
-
108
- const result = await wallet.provider.query({
109
- request_type: "call_function",
110
- finality: "final",
111
- account_id: "near",
112
- method_name: "get_info",
113
- args_base64: Buffer.from(JSON.stringify({ name: normalizedName })).toString("base64"),
114
- });
115
-
116
- const response = JSON.parse(Buffer.from((result as any).result).toString());
117
- return response || null;
118
- } catch {
119
- return null;
120
- }
121
- },
122
-
123
- async lookupNames(accountId: string) {
124
- try {
125
- const wallet = getWallet(Chain.Near);
126
-
127
- if (!wallet) {
128
- throw new SwapKitError("plugin_near_no_connection");
129
- }
130
-
131
- const result = await wallet.provider.query({
132
- request_type: "call_function",
133
- finality: "final",
134
- account_id: "near",
135
- method_name: "get_names_by_owner",
136
- args_base64: Buffer.from(JSON.stringify({ account_id: accountId })).toString("base64"),
137
- });
138
-
139
- const response = JSON.parse(Buffer.from((result as any).result).toString());
140
- return Array.isArray(response) ? response.map((n) => `${n}.near`) : [];
141
- } catch {
142
- return [];
143
- }
144
- },
145
-
146
- async register(params: NearNameRegistrationParams) {
147
- const { name, publicKey: publicKeyOverwrite } = params;
148
- const normalizedName = name.toLowerCase().replace(/\.near$/, "");
149
-
150
- if (!validateNearName(normalizedName)) {
151
- throw new SwapKitError("plugin_near_invalid_name");
152
- }
153
-
154
- const wallet = getWallet(Chain.Near) as NearWallet;
155
-
156
- const newPublicKey = publicKeyOverwrite || (await wallet.getPublicKey());
157
-
158
- const cost = calculateNearNameCost(normalizedName);
159
-
160
- return wallet.callFunction({
161
- contractId: "near",
162
- methodName: "create_account",
163
- args: {
164
- new_account_id: `${normalizedName}.near`,
165
- new_public_key: newPublicKey,
166
- },
167
- deposit: cost,
168
- });
169
- },
170
-
171
- transfer(name: string, newOwner: string) {
172
- const normalizedName = name.toLowerCase().replace(/\.near$/, "");
173
-
174
- if (!validateNearName(normalizedName)) {
175
- throw new SwapKitError("plugin_near_invalid_name");
176
- }
177
-
178
- const wallet = getWallet(Chain.Near) as NearWallet;
179
-
180
- return wallet.callFunction({
181
- contractId: "near",
182
- methodName: "transfer",
183
- args: {
184
- name: normalizedName,
185
- new_owner: newOwner,
186
- },
187
- deposit: "1",
188
- });
189
- },
190
- },
191
- }),
192
- });
package/src/near/types.ts DELETED
@@ -1,11 +0,0 @@
1
- export type NearNameInfo = {
2
- owner: string;
3
- price?: string;
4
- expiresAt?: string;
5
- registeredAt?: string;
6
- };
7
-
8
- export type NearNameRegistrationParams = {
9
- name: string;
10
- publicKey?: string;
11
- };
@@ -1,36 +0,0 @@
1
- import {
2
- AssetValue,
3
- Chain,
4
- ProviderName,
5
- SwapKitError,
6
- type SwapParams,
7
- createPlugin,
8
- } from "@swapkit/helpers";
9
- import type { QuoteResponseRoute } from "@swapkit/helpers/api";
10
-
11
- export const RadixPlugin = createPlugin({
12
- name: "radix",
13
- properties: { supportedSwapkitProviders: [ProviderName.CAVIAR_V1] },
14
- methods: ({ getWallet }) => ({
15
- swap: async function radixSwap({
16
- route: { tx, sellAmount, sellAsset },
17
- }: SwapParams<"radix", QuoteResponseRoute>) {
18
- const assetValue = await AssetValue.from({
19
- asyncTokenLookup: true,
20
- value: sellAmount,
21
- asset: sellAsset,
22
- });
23
-
24
- if (Chain.Radix !== assetValue.chain) {
25
- throw new SwapKitError("core_swap_invalid_params");
26
- }
27
-
28
- const wallet = getWallet(assetValue.chain);
29
- try {
30
- return wallet.signAndBroadcast({ manifest: tx as string });
31
- } catch (error) {
32
- throw new SwapKitError("core_swap_invalid_params", error);
33
- }
34
- },
35
- }),
36
- });
@@ -1,36 +0,0 @@
1
- import {
2
- AssetValue,
3
- Chain,
4
- ProviderName,
5
- SwapKitError,
6
- type SwapParams,
7
- createPlugin,
8
- } from "@swapkit/helpers";
9
- import type { QuoteResponseRoute } from "@swapkit/helpers/api";
10
-
11
- export const SolanaPlugin = createPlugin({
12
- name: "solana",
13
- properties: {
14
- supportedSwapkitProviders: [ProviderName.JUPITER],
15
- },
16
- methods: ({ getWallet }) => ({
17
- swap: async function solanaSwap({ route }: SwapParams<"solana", QuoteResponseRoute>) {
18
- const { VersionedTransaction } = await import("@solana/web3.js");
19
- const { tx, sellAsset } = route;
20
-
21
- const assetValue = await AssetValue.from({
22
- asset: sellAsset,
23
- });
24
-
25
- const chain = assetValue.chain;
26
- if (!(chain === Chain.Solana && tx)) throw new SwapKitError("core_swap_invalid_params");
27
-
28
- const wallet = getWallet(chain);
29
- const transaction = VersionedTransaction.deserialize(Buffer.from(tx as string, "base64"));
30
-
31
- const signedTransaction = await wallet.signTransaction(transaction);
32
-
33
- return wallet.broadcastTransaction(signedTransaction);
34
- },
35
- }),
36
- });