@swapkit/plugins 0.0.0-nightly-20250304130539

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 (44) hide show
  1. package/dist/chainflip/index.cjs +3 -0
  2. package/dist/chainflip/index.cjs.map +11 -0
  3. package/dist/chainflip/index.js +3 -0
  4. package/dist/chainflip/index.js.map +11 -0
  5. package/dist/chunk-fazw0jvt.js +3 -0
  6. package/dist/chunk-fazw0jvt.js.map +9 -0
  7. package/dist/chunk-tvrdndbw.js +4 -0
  8. package/dist/chunk-tvrdndbw.js.map +9 -0
  9. package/dist/evm/index.cjs +3 -0
  10. package/dist/evm/index.cjs.map +10 -0
  11. package/dist/evm/index.js +3 -0
  12. package/dist/evm/index.js.map +10 -0
  13. package/dist/index.cjs +3 -0
  14. package/dist/index.cjs.map +9 -0
  15. package/dist/index.js +2 -0
  16. package/dist/index.js.map +9 -0
  17. package/dist/kado/index.cjs +20 -0
  18. package/dist/kado/index.cjs.map +12 -0
  19. package/dist/kado/index.js +20 -0
  20. package/dist/kado/index.js.map +12 -0
  21. package/dist/radix/index.cjs +3 -0
  22. package/dist/radix/index.cjs.map +10 -0
  23. package/dist/radix/index.js +3 -0
  24. package/dist/radix/index.js.map +10 -0
  25. package/dist/thorchain/index.cjs +3 -0
  26. package/dist/thorchain/index.cjs.map +11 -0
  27. package/dist/thorchain/index.js +3 -0
  28. package/dist/thorchain/index.js.map +11 -0
  29. package/package.json +64 -0
  30. package/src/chainflip/broker.ts +127 -0
  31. package/src/chainflip/index.ts +3 -0
  32. package/src/chainflip/plugin.ts +73 -0
  33. package/src/chainflip/types.ts +48 -0
  34. package/src/evm/index.ts +82 -0
  35. package/src/index.ts +17 -0
  36. package/src/kado/helpers.ts +117 -0
  37. package/src/kado/index.ts +3 -0
  38. package/src/kado/plugin.ts +234 -0
  39. package/src/kado/types.ts +225 -0
  40. package/src/radix/index.ts +36 -0
  41. package/src/thorchain/index.ts +3 -0
  42. package/src/thorchain/plugin.ts +492 -0
  43. package/src/thorchain/shared.ts +23 -0
  44. package/src/thorchain/types.ts +83 -0
@@ -0,0 +1,234 @@
1
+ import {
2
+ AssetValue,
3
+ Chain,
4
+ ProviderName,
5
+ RequestClient,
6
+ SKConfig,
7
+ type SwapParams,
8
+ createPlugin,
9
+ warnOnce,
10
+ } from "@swapkit/helpers";
11
+ import type { QuoteResponse, QuoteResponseRoute } from "@swapkit/helpers/api";
12
+ import { ChainToKadoChain, mapKadoQuoteToQuoteResponse } from "./helpers";
13
+ import type {
14
+ KadoAssetsResponse,
15
+ KadoBlockchainsResponse,
16
+ KadoFiatCurrency,
17
+ KadoFiatMethod,
18
+ KadoQuoteRequest,
19
+ KadoQuoteResponse,
20
+ } from "./types";
21
+
22
+ export const KadoPlugin = createPlugin({
23
+ name: "kado",
24
+ methods: () => ({
25
+ createPopover,
26
+ getAssets,
27
+ getBlockchains,
28
+ getKadoWidgetUrl,
29
+ getOrderStatus,
30
+ fetchProviderQuote,
31
+ swap,
32
+ }),
33
+ properties: {
34
+ supportedSwapkitProviders: [ProviderName.KADO],
35
+ },
36
+ });
37
+
38
+ function swap({ route }: SwapParams<"evm", QuoteResponseRoute>) {
39
+ if (!(route.sourceAddress && route.destinationAddress)) {
40
+ throw new Error("Source and destination addresses are required");
41
+ }
42
+
43
+ const sellAsset = AssetValue.from({ asset: route.sellAsset });
44
+ const buyAsset = AssetValue.from({ asset: route.buyAsset });
45
+
46
+ // Determine if this is a buy or sell operation
47
+ const type = sellAsset.chain === Chain.Fiat ? "buy" : "sell";
48
+
49
+ const url = getKadoWidgetUrl({
50
+ sellAsset,
51
+ buyAsset,
52
+ recipient: route.destinationAddress,
53
+ sender: route.sourceAddress,
54
+ type,
55
+ mode: "minimal",
56
+ });
57
+
58
+ createPopover(url);
59
+
60
+ return {
61
+ status: "pending",
62
+ txHash: null,
63
+ };
64
+ }
65
+
66
+ async function fetchProviderQuote({
67
+ sellAsset,
68
+ buyAsset,
69
+ fiatMethod = "credit_card",
70
+ }: {
71
+ sellAsset: AssetValue;
72
+ buyAsset: AssetValue;
73
+ fiatMethod: KadoFiatMethod;
74
+ }): Promise<QuoteResponse> {
75
+ try {
76
+ const isOnRamp = sellAsset.chain === Chain.Fiat;
77
+ const [paymentAsset, receiveAsset] = isOnRamp ? [buyAsset, sellAsset] : [sellAsset, buyAsset];
78
+ const transactionType = isOnRamp ? "buy" : "sell";
79
+
80
+ const quoteRequest: KadoQuoteRequest = {
81
+ amount: paymentAsset.getValue("string"),
82
+ asset: paymentAsset.symbol,
83
+ blockchain: ChainToKadoChain(paymentAsset.chain),
84
+ currency: receiveAsset.symbol as KadoFiatCurrency,
85
+ fiatMethod,
86
+ partner: "fortress",
87
+ transactionType,
88
+ };
89
+
90
+ const kadoApiKey = SKConfig.get("apiKeys").kado;
91
+ warnOnce(!kadoApiKey, "plugin(kado): No Kado API key found");
92
+
93
+ const quote = await RequestClient.get<KadoQuoteResponse>(
94
+ "https://api.kado.money/v2/ramp/quote",
95
+ { searchParams: quoteRequest, headers: { "X-Widget-Id": kadoApiKey } },
96
+ );
97
+
98
+ if (!quote.success) {
99
+ throw new Error(quote.message);
100
+ }
101
+
102
+ return mapKadoQuoteToQuoteResponse({ quote, sellAsset, buyAsset });
103
+ } catch (_) {
104
+ throw new Error("core_swap_quote_error");
105
+ }
106
+ }
107
+
108
+ async function getBlockchains() {
109
+ const response = await RequestClient.get<KadoBlockchainsResponse>(
110
+ "https://api.kado.money/v1/ramp/blockchains",
111
+ );
112
+
113
+ if (!response.success) {
114
+ throw new Error(response.message);
115
+ }
116
+
117
+ return response.data.blockchains;
118
+ }
119
+
120
+ async function getAssets() {
121
+ const response = await RequestClient.get<KadoAssetsResponse>(
122
+ "https://api.kado.money/v1/ramp/supported-assets",
123
+ );
124
+
125
+ if (!response.success) {
126
+ throw new Error(response.message);
127
+ }
128
+
129
+ return response.data.assets;
130
+ }
131
+
132
+ async function getOrderStatus(orderId: string) {
133
+ const kadoApiKey = SKConfig.get("apiKeys").kado;
134
+ warnOnce(!kadoApiKey, "plugin(kado): No Kado API key found");
135
+
136
+ try {
137
+ const response = await RequestClient.get<{
138
+ success: boolean;
139
+ message: string;
140
+ data: { order: { status: string } };
141
+ }>(`https://api.kado.money/v2/public/orders/${orderId}`, {
142
+ headers: { "X-Widget-Id": kadoApiKey },
143
+ });
144
+
145
+ if (!response.success) {
146
+ throw new Error(response.message);
147
+ }
148
+
149
+ return response.data.order;
150
+ } catch (_error) {
151
+ throw new Error("Failed to get order status");
152
+ }
153
+ }
154
+
155
+ function getKadoWidgetUrl({
156
+ sellAsset,
157
+ buyAsset,
158
+ recipient,
159
+ type,
160
+ sender,
161
+ mode,
162
+ }: {
163
+ sellAsset: AssetValue;
164
+ buyAsset: AssetValue;
165
+ recipient?: string;
166
+ sender?: string;
167
+ type: "buy" | "sell";
168
+ mode: "minimal" | "full";
169
+ }) {
170
+ const kadoApiKey = SKConfig.get("apiKeys").kado;
171
+ warnOnce(!kadoApiKey, "plugin(kado): No Kado API key found");
172
+
173
+ const buySellParams =
174
+ type === "buy"
175
+ ? {
176
+ onPayAmount: sellAsset.getValue("string"),
177
+ onPayCurrency: sellAsset.symbol,
178
+ onRevCurrency: buyAsset.symbol,
179
+ ...(recipient ? { onToAddress: recipient } : {}),
180
+ }
181
+ : {
182
+ offPayAmount: sellAsset.getValue("string"),
183
+ offPayCurrency: sellAsset.symbol,
184
+ offRevCurrency: buyAsset.symbol,
185
+ ...(sender ? { offFromAddress: sender } : {}),
186
+ };
187
+ const network = ChainToKadoChain(type === "buy" ? buyAsset.chain : sellAsset.chain).toUpperCase();
188
+ const urlParams = new URLSearchParams({
189
+ ...buySellParams,
190
+ apiKey: kadoApiKey,
191
+ network,
192
+ product: type.toUpperCase(),
193
+ mode,
194
+ });
195
+
196
+ return `https://app.kado.money/?${urlParams.toString()}`;
197
+ }
198
+
199
+ function createPopover(url: string) {
200
+ const overlay = document.createElement("div");
201
+ overlay.style.cssText = `
202
+ position: fixed;
203
+ top: 0;
204
+ left: 0;
205
+ width: 100%;
206
+ height: 100%;
207
+ background: rgba(0, 0, 0, 0.5);
208
+ display: flex;
209
+ justify-content: center;
210
+ align-items: center;
211
+ z-index: 9999;
212
+ `;
213
+
214
+ const iframe = document.createElement("iframe");
215
+ iframe.src = url;
216
+ iframe.style.cssText = `
217
+ width: 440px;
218
+ height: 700px;
219
+ border: none;
220
+ border-radius: 12px;
221
+ background: white;
222
+ `;
223
+
224
+ overlay.appendChild(iframe);
225
+ document.body.appendChild(overlay);
226
+
227
+ overlay.addEventListener("click", (e) => {
228
+ if (e.target === overlay) {
229
+ document.body.removeChild(overlay);
230
+ }
231
+ });
232
+
233
+ return overlay;
234
+ }
@@ -0,0 +1,225 @@
1
+ import type { SupportedKadoChain } from "./helpers";
2
+
3
+ export const KadoSupportedFiatCurrencies = [
4
+ "USD",
5
+ "CAD",
6
+ "GBP",
7
+ "EUR",
8
+ "MXN",
9
+ "COP",
10
+ "INR",
11
+ "CHF",
12
+ "AUD",
13
+ "ARS",
14
+ "BRL",
15
+ "CLP",
16
+ "JPY",
17
+ "KRW",
18
+ "PEN",
19
+ "PHP",
20
+ "SGD",
21
+ "TRY",
22
+ "UYU",
23
+ "TWD",
24
+ "VND",
25
+ "CRC",
26
+ "SEK",
27
+ "PLN",
28
+ "DKK",
29
+ "NOK",
30
+ "NZD",
31
+ ] as const;
32
+
33
+ export type KadoFiatCurrency = (typeof KadoSupportedFiatCurrencies)[number];
34
+
35
+ export type KadoFiatMethod =
36
+ | "ach"
37
+ | "debit_card"
38
+ | "credit_card"
39
+ | "apple_pay_credit"
40
+ | "apple_pay_debit"
41
+ | "wire"
42
+ | "sepa"
43
+ | "pix"
44
+ | "koywe";
45
+
46
+ export type KadoQuoteRequest = {
47
+ transactionType: "buy" | "sell";
48
+ fiatMethod: KadoFiatMethod;
49
+ partner: "fortress";
50
+ amount: string;
51
+ asset: string;
52
+ blockchain: string;
53
+ currency: KadoFiatCurrency;
54
+ };
55
+
56
+ export type KadoAsset = {
57
+ _id: string;
58
+ name: string;
59
+ description: string;
60
+ label: string;
61
+ symbol: string;
62
+ supportedProviders: string[];
63
+ stablecoin: boolean;
64
+ liveOnRamp: boolean;
65
+ createdAt: string;
66
+ updatedAt: string;
67
+ __v: number;
68
+ priority: number;
69
+ displayPrecision: number;
70
+ usesAvaxRouter: boolean;
71
+ squidChainId: string;
72
+ coingeckoId: string;
73
+ usesAxelarBridge: boolean;
74
+ squidAssetId: string;
75
+ address: string;
76
+ blockExplorerURI: string;
77
+ decimals: number;
78
+ officialChainId: keyof typeof SupportedKadoChain;
79
+ precision: number;
80
+ rampProducts: string[];
81
+ wallets: string[];
82
+ rpcURI: string;
83
+ usesPolygonFulfillment: boolean;
84
+ usesOsmoRouter: boolean;
85
+ ibcChannelIdOffRamp: number;
86
+ ibcChannelIdOnRamp: number;
87
+ osmoPfmChannel: number;
88
+ osmoPfmReceiver: string;
89
+ ibcDenom: string;
90
+ isNative: boolean;
91
+ avgOffRampTimeInSeconds: number;
92
+ avgOnRampTimeInSeconds: number;
93
+ providers: string[];
94
+ trustekAssetId: string;
95
+ trustekNetworkId: string;
96
+ kycLevels: string[];
97
+ };
98
+
99
+ export type KadoBlockchainsResponse = {
100
+ success: boolean;
101
+ message: string;
102
+ data: {
103
+ blockchains: {
104
+ _id: string;
105
+ supportedEnvironment: string;
106
+ network: string;
107
+ origin: string;
108
+ label: string;
109
+ associatedAssets: KadoAsset[];
110
+ avgTransactionTimeSeconds: number;
111
+ usesAvaxRouter: boolean;
112
+ liveOnRamp: boolean;
113
+ createdAt: string;
114
+ updatedAt: string;
115
+ __v: number;
116
+ priority: number;
117
+ }[];
118
+ };
119
+ };
120
+
121
+ export type KadoAssetsResponse = {
122
+ success: boolean;
123
+ message: string;
124
+ data: {
125
+ assets: {
126
+ _id: string;
127
+ name: string;
128
+ description: string;
129
+ label: string;
130
+ symbol: string;
131
+ supportedProviders: string[];
132
+ stablecoin: boolean;
133
+ liveOnRamp: boolean;
134
+ createdAt: string;
135
+ updatedAt: string;
136
+ __v: number;
137
+ priority: number;
138
+ }[];
139
+ };
140
+ };
141
+
142
+ export type KadoQuoteResponse = {
143
+ success: boolean;
144
+ message: string;
145
+ data: {
146
+ request: {
147
+ transactionType: string;
148
+ fiatMethod: KadoFiatMethod;
149
+ partner: string;
150
+ amount: number;
151
+ asset: string;
152
+ blockchain: keyof typeof SupportedKadoChain;
153
+ currency: KadoFiatCurrency;
154
+ reverse: false;
155
+ ipCountry: string;
156
+ };
157
+ quote: {
158
+ asset: string;
159
+ baseAmount: {
160
+ amount: number;
161
+ currency: KadoFiatCurrency;
162
+ };
163
+ price: {
164
+ amount: number;
165
+ price: number;
166
+ symbol: string;
167
+ unit: string;
168
+ };
169
+ bridgeFee: {
170
+ amount: number;
171
+ currency: KadoFiatCurrency;
172
+ originalAmount: number;
173
+ promotionModifier: number;
174
+ };
175
+ receiveAmountAfterFees: {
176
+ originalAmount: number;
177
+ amount: number;
178
+ currency: KadoFiatCurrency;
179
+ };
180
+ receiveUnitCountAfterFees: {
181
+ amount: number;
182
+ currency: KadoFiatCurrency;
183
+ };
184
+ feeType: string;
185
+ minValue: {
186
+ amount: number;
187
+ unit: string;
188
+ };
189
+ maxValue: {
190
+ amount: number;
191
+ unit: string;
192
+ };
193
+ receive: {
194
+ amount: number;
195
+ originalAmount: number;
196
+ symbol: string;
197
+ unit: string;
198
+ unitCount: number;
199
+ };
200
+ networkFee: {
201
+ amount: number;
202
+ currency: KadoFiatCurrency;
203
+ originalAmount: number;
204
+ promotionModifier: number;
205
+ };
206
+ processingFee: {
207
+ amount: number;
208
+ currency: KadoFiatCurrency;
209
+ originalAmount: number;
210
+ promotionModifier: number;
211
+ };
212
+ totalFee: {
213
+ amount: number;
214
+ currency: KadoFiatCurrency;
215
+ originalAmount: number;
216
+ };
217
+ smartContractFee: {
218
+ amount: number;
219
+ currency: KadoFiatCurrency;
220
+ originalAmount: number;
221
+ promotionModifier: number;
222
+ };
223
+ };
224
+ };
225
+ };
@@ -0,0 +1,36 @@
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
+ });
@@ -0,0 +1,3 @@
1
+ export { ThorchainPlugin, MayachainPlugin } from "./plugin";
2
+ export { validateAddressType } from "./shared";
3
+ export * from "./types";