@swapkit/plugins 1.0.0-beta.1 → 1.0.0-beta.11
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 +2 -2
- package/dist/index.cjs.map +3 -3
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/package.json +4 -11
- package/src/types.ts +0 -3
- package/src/utils.ts +0 -4
- package/dist/kado/index.cjs +0 -20
- package/dist/kado/index.cjs.map +0 -12
- package/dist/kado/index.js +0 -20
- package/dist/kado/index.js.map +0 -12
- package/src/kado/helpers.ts +0 -117
- package/src/kado/index.ts +0 -3
- package/src/kado/plugin.ts +0 -234
- package/src/kado/types.ts +0 -225
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var e={};p(e,{loadPlugin:()=>
|
|
1
|
+
var e={};p(e,{loadPlugin:()=>o});module.exports=r(e);async function o(t){let{match:a}=await import("ts-pattern");return await a(t).with("chainflip",async()=>{let{ChainflipPlugin:i}=await import("./chainflip/index.cjs");return i}).with("thorchain",async()=>{let{ThorchainPlugin:i}=await import("./thorchain/index.cjs");return i}).with("radix",async()=>{let{RadixPlugin:i}=await import("./radix/index.cjs");return i}).with("evm",async()=>{let{EVMPlugin:i}=await import("./evm/index.cjs");return i}).with("solana",async()=>{let{SolanaPlugin:i}=await import("./solana/index.cjs");return i}).exhaustive()}
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=4C94610CE871A09064756E2164756E21
|
package/dist/index.cjs.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/utils.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { PluginName, SKPlugins } from \"./types\";\n\nexport async function loadPlugin<P extends PluginName>(pluginName: P) {\n const { match } = await import(\"ts-pattern\");\n\n const plugin = await match(pluginName as PluginName)\n .with(\"chainflip\", async () => {\n const { ChainflipPlugin } = await import(\"./chainflip\");\n return ChainflipPlugin;\n })\n .with(\"thorchain\", async () => {\n const { ThorchainPlugin } = await import(\"./thorchain\");\n return ThorchainPlugin;\n })\n .with(\"
|
|
5
|
+
"import type { PluginName, SKPlugins } from \"./types\";\n\nexport async function loadPlugin<P extends PluginName>(pluginName: P) {\n const { match } = await import(\"ts-pattern\");\n\n const plugin = await match(pluginName as PluginName)\n .with(\"chainflip\", async () => {\n const { ChainflipPlugin } = await import(\"./chainflip\");\n return ChainflipPlugin;\n })\n .with(\"thorchain\", async () => {\n const { ThorchainPlugin } = await import(\"./thorchain\");\n return ThorchainPlugin;\n })\n .with(\"radix\", async () => {\n const { RadixPlugin } = await import(\"./radix\");\n return RadixPlugin;\n })\n .with(\"evm\", async () => {\n const { EVMPlugin } = await import(\"./evm\");\n return EVMPlugin;\n })\n .with(\"solana\", async () => {\n const { SolanaPlugin } = await import(\"./solana\");\n return SolanaPlugin;\n })\n .exhaustive();\n\n return plugin as unknown as SKPlugins[P];\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "qDAEA,eAAsB,CAAgC,CAAC,EAAe,CACpE,IAAQ,SAAU,KAAa,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "qDAEA,eAAsB,CAAgC,CAAC,EAAe,CACpE,IAAQ,SAAU,KAAa,sBAyB/B,OAvBe,MAAM,EAAM,CAAwB,EAChD,KAAK,YAAa,SAAY,CAC7B,IAAQ,mBAAoB,KAAa,iCACzC,OAAO,EACR,EACA,KAAK,YAAa,SAAY,CAC7B,IAAQ,mBAAoB,KAAa,iCACzC,OAAO,EACR,EACA,KAAK,QAAS,SAAY,CACzB,IAAQ,eAAgB,KAAa,6BACrC,OAAO,EACR,EACA,KAAK,MAAO,SAAY,CACvB,IAAQ,aAAc,KAAa,2BACnC,OAAO,EACR,EACA,KAAK,SAAU,SAAY,CAC1B,IAAQ,gBAAiB,KAAa,8BACtC,OAAO,EACR,EACA,WAAW",
|
|
8
|
+
"debugId": "4C94610CE871A09064756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as n,b as t}from"./chunk-tvrdndbw.js";async function p(a){let{match:o}=await import("ts-pattern");return await o(a).with("chainflip",async()=>{let{ChainflipPlugin:i}=await import("./chainflip/index.js");return i}).with("thorchain",async()=>{let{ThorchainPlugin:i}=await import("./thorchain/index.js");return i}).with("radix",async()=>{let{RadixPlugin:i}=await import("./radix/index.js");return i}).with("evm",async()=>{let{EVMPlugin:i}=await import("./evm/index.js");return i}).with("solana",async()=>{let{SolanaPlugin:i}=await import("./solana/index.js");return i}).exhaustive()}export{p as loadPlugin};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=C99230D2E92A281864756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/utils.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import type { PluginName, SKPlugins } from \"./types\";\n\nexport async function loadPlugin<P extends PluginName>(pluginName: P) {\n const { match } = await import(\"ts-pattern\");\n\n const plugin = await match(pluginName as PluginName)\n .with(\"chainflip\", async () => {\n const { ChainflipPlugin } = await import(\"./chainflip\");\n return ChainflipPlugin;\n })\n .with(\"thorchain\", async () => {\n const { ThorchainPlugin } = await import(\"./thorchain\");\n return ThorchainPlugin;\n })\n .with(\"
|
|
5
|
+
"import type { PluginName, SKPlugins } from \"./types\";\n\nexport async function loadPlugin<P extends PluginName>(pluginName: P) {\n const { match } = await import(\"ts-pattern\");\n\n const plugin = await match(pluginName as PluginName)\n .with(\"chainflip\", async () => {\n const { ChainflipPlugin } = await import(\"./chainflip\");\n return ChainflipPlugin;\n })\n .with(\"thorchain\", async () => {\n const { ThorchainPlugin } = await import(\"./thorchain\");\n return ThorchainPlugin;\n })\n .with(\"radix\", async () => {\n const { RadixPlugin } = await import(\"./radix\");\n return RadixPlugin;\n })\n .with(\"evm\", async () => {\n const { EVMPlugin } = await import(\"./evm\");\n return EVMPlugin;\n })\n .with(\"solana\", async () => {\n const { SolanaPlugin } = await import(\"./solana\");\n return SolanaPlugin;\n })\n .exhaustive();\n\n return plugin as unknown as SKPlugins[P];\n}\n"
|
|
6
6
|
],
|
|
7
|
-
"mappings": "+CAEA,eAAsB,CAAgC,CAAC,EAAe,CACpE,IAAQ,SAAU,KAAa,
|
|
8
|
-
"debugId": "
|
|
7
|
+
"mappings": "+CAEA,eAAsB,CAAgC,CAAC,EAAe,CACpE,IAAQ,SAAU,KAAa,sBAyB/B,OAvBe,MAAM,EAAM,CAAwB,EAChD,KAAK,YAAa,SAAY,CAC7B,IAAQ,mBAAoB,KAAa,gCACzC,OAAO,EACR,EACA,KAAK,YAAa,SAAY,CAC7B,IAAQ,mBAAoB,KAAa,gCACzC,OAAO,EACR,EACA,KAAK,QAAS,SAAY,CACzB,IAAQ,eAAgB,KAAa,4BACrC,OAAO,EACR,EACA,KAAK,MAAO,SAAY,CACvB,IAAQ,aAAc,KAAa,0BACnC,OAAO,EACR,EACA,KAAK,SAAU,SAAY,CAC1B,IAAQ,gBAAiB,KAAa,6BACtC,OAAO,EACR,EACA,WAAW",
|
|
8
|
+
"debugId": "C99230D2E92A281864756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
package/package.json
CHANGED
|
@@ -3,13 +3,11 @@
|
|
|
3
3
|
"dependencies": {
|
|
4
4
|
"@polkadot/keyring": "13.4.4",
|
|
5
5
|
"@polkadot/util": "13.4.4",
|
|
6
|
-
"@
|
|
7
|
-
"@swapkit/
|
|
6
|
+
"@solana/web3.js": "1.98.2",
|
|
7
|
+
"@swapkit/helpers": "3.0.0-beta.9",
|
|
8
|
+
"@swapkit/toolboxes": "1.0.0-beta.11",
|
|
8
9
|
"ts-pattern": "5.7.0"
|
|
9
10
|
},
|
|
10
|
-
"peerDependencies": {
|
|
11
|
-
"@solana/web3.js": "1.98.0"
|
|
12
|
-
},
|
|
13
11
|
"description": "SwapKit Plugin - ChainFlip",
|
|
14
12
|
"exports": {
|
|
15
13
|
".": {
|
|
@@ -27,11 +25,6 @@
|
|
|
27
25
|
"require": "./dist/evm/index.cjs",
|
|
28
26
|
"types": "./src/evm/index.ts"
|
|
29
27
|
},
|
|
30
|
-
"./kado": {
|
|
31
|
-
"default": "./dist/kado/index.js",
|
|
32
|
-
"require": "./dist/kado/index.cjs",
|
|
33
|
-
"types": "./src/kado/index.ts"
|
|
34
|
-
},
|
|
35
28
|
"./radix": {
|
|
36
29
|
"default": "./dist/radix/index.js",
|
|
37
30
|
"require": "./dist/radix/index.cjs",
|
|
@@ -70,5 +63,5 @@
|
|
|
70
63
|
"type-check:go": "tsgo"
|
|
71
64
|
},
|
|
72
65
|
"type": "module",
|
|
73
|
-
"version": "1.0.0-beta.
|
|
66
|
+
"version": "1.0.0-beta.11"
|
|
74
67
|
}
|
package/src/types.ts
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import type { ChainflipPlugin } from "./chainflip";
|
|
2
2
|
import type { EVMPlugin } from "./evm";
|
|
3
|
-
import type { KadoPlugin } from "./kado";
|
|
4
3
|
import type { RadixPlugin } from "./radix";
|
|
5
4
|
import type { SolanaPlugin } from "./solana/plugin";
|
|
6
5
|
import type { ThorchainPlugin } from "./thorchain";
|
|
7
6
|
|
|
8
7
|
export type * from "./chainflip/types";
|
|
9
8
|
export type * from "./thorchain/types";
|
|
10
|
-
export type * from "./kado/types";
|
|
11
9
|
|
|
12
10
|
export type SKPlugins = typeof ChainflipPlugin &
|
|
13
11
|
typeof ThorchainPlugin &
|
|
14
|
-
typeof KadoPlugin &
|
|
15
12
|
typeof RadixPlugin &
|
|
16
13
|
typeof SolanaPlugin &
|
|
17
14
|
typeof EVMPlugin;
|
package/src/utils.ts
CHANGED
|
@@ -12,10 +12,6 @@ export async function loadPlugin<P extends PluginName>(pluginName: P) {
|
|
|
12
12
|
const { ThorchainPlugin } = await import("./thorchain");
|
|
13
13
|
return ThorchainPlugin;
|
|
14
14
|
})
|
|
15
|
-
.with("kado", async () => {
|
|
16
|
-
const { KadoPlugin } = await import("./kado");
|
|
17
|
-
return KadoPlugin;
|
|
18
|
-
})
|
|
19
15
|
.with("radix", async () => {
|
|
20
16
|
const { RadixPlugin } = await import("./radix");
|
|
21
17
|
return RadixPlugin;
|
package/dist/kado/index.cjs
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
var k={};P(k,{mapKadoQuoteToQuoteResponse:()=>f,SupportedKadoChain:()=>b,KadoSupportedFiatCurrencies:()=>E,KadoPlugin:()=>O,KadoChainToChain:()=>I,ChainToKadoChain:()=>h});module.exports=N(k);var t=require("@swapkit/helpers"),b={thorchain:t.Chain.THORChain,solana:t.Chain.Solana,polygon:t.Chain.Polygon,Optimism:t.Chain.Optimism,litecoin:t.Chain.Litecoin,kujira:t.Chain.Kujira,ethereum:t.Chain.Ethereum,"cosmos hub":t.Chain.Cosmos,bitcoin:t.Chain.Bitcoin,base:t.Chain.Base,Avalanche:t.Chain.Avalanche,Arbitrum:t.Chain.Arbitrum};function h(n){let r=Object.entries(b).find(([e,a])=>a===n);if(!r)throw new Error(`Chain ${n} not supported`);return r[0]}function I(n){if(!Object.keys(b).includes(n))throw new Error(`KadoChain ${n} not supported`);return b[n]}function f({quote:n,sellAsset:o,buyAsset:r}){let e=o.chain,a=r.chain,c=e===t.Chain.Fiat,{receive:u,price:p,baseAmount:s,totalFee:m,processingFee:d,networkFee:g}=n.data.quote,y=r.set(c?u.unitCount.toString():u.amount.toString()),x=c?Math.round(m.amount/u.amount*1e4):Math.round(m.amount/(p.price*s.amount)*1e4),l=Math.ceil(t.BlockTimes[e]*3),C=Math.ceil(60),K=Math.ceil(t.BlockTimes[a]),S=[{buyAsset:r.toString(),destinationAddress:"{destinationAddress}",estimatedTime:{inbound:l,swap:C,outbound:K,total:l+C+K},expectedBuyAmount:y.getValue("string"),expectedBuyAmountMaxSlippage:y.getValue("string"),providers:[t.ProviderName.KADO],sellAmount:o.getValue("string"),sellAsset:o.toString(),sourceAddress:"{sourceAddress}",totalSlippageBps:x,fees:[{asset:d.currency,amount:d.amount.toString(),type:t.FeeTypeEnum.LIQUIDITY,protocol:t.ProviderName.KADO,chain:t.Chain.Fiat},{asset:g.currency,amount:g.amount.toString(),type:t.FeeTypeEnum.NETWORK,protocol:t.ProviderName.KADO,chain:r.chain}],legs:[{provider:t.ProviderName.KADO,sellAsset:o.toString(),sellAmount:o.getValue("string"),buyAsset:r.toString(),buyAmount:u.unitCount.toString(),buyAmountMaxSlippage:u.unitCount.toString(),fees:[{asset:d.currency,amount:d.amount.toString(),type:t.FeeTypeEnum.LIQUIDITY,protocol:t.ProviderName.KADO,chain:t.Chain.Fiat},{asset:g.currency,amount:g.amount.toString(),type:t.FeeTypeEnum.NETWORK,protocol:t.ProviderName.KADO,chain:r.chain}]}],warnings:[],meta:{tags:[]}}];return{quoteId:crypto.randomUUID(),routes:S,error:n.success?void 0:n.message}}var i=require("@swapkit/helpers");var O=i.createPlugin({name:"kado",methods:()=>({createPopover:R,getAssets:T,getBlockchains:v,getKadoWidgetUrl:F,getOrderStatus:M,fetchProviderQuote:D,swap:_}),properties:{supportedSwapkitProviders:[i.ProviderName.KADO]}});function _({route:n}){if(!(n.sourceAddress&&n.destinationAddress))throw new Error("Source and destination addresses are required");let o=i.AssetValue.from({asset:n.sellAsset}),r=i.AssetValue.from({asset:n.buyAsset}),e=o.chain===i.Chain.Fiat?"buy":"sell",a=F({sellAsset:o,buyAsset:r,recipient:n.destinationAddress,sender:n.sourceAddress,type:e,mode:"minimal"});return R(a),{status:"pending",txHash:null}}async function D({sellAsset:n,buyAsset:o,fiatMethod:r="credit_card"}){try{let e=n.chain===i.Chain.Fiat,[a,c]=e?[o,n]:[n,o],u=e?"buy":"sell",p={amount:a.getValue("string"),asset:a.symbol,blockchain:h(a.chain),currency:c.symbol,fiatMethod:r,partner:"fortress",transactionType:u},s=i.SKConfig.get("apiKeys").kado;i.warnOnce(!s,"plugin(kado): No Kado API key found");let m=await i.RequestClient.get("https://api.kado.money/v2/ramp/quote",{searchParams:p,headers:{"X-Widget-Id":s}});if(!m.success)throw new Error(m.message);return f({quote:m,sellAsset:n,buyAsset:o})}catch(e){throw new Error("core_swap_quote_error")}}async function v(){let n=await i.RequestClient.get("https://api.kado.money/v1/ramp/blockchains");if(!n.success)throw new Error(n.message);return n.data.blockchains}async function T(){let n=await i.RequestClient.get("https://api.kado.money/v1/ramp/supported-assets");if(!n.success)throw new Error(n.message);return n.data.assets}async function M(n){let o=i.SKConfig.get("apiKeys").kado;i.warnOnce(!o,"plugin(kado): No Kado API key found");try{let r=await i.RequestClient.get(`https://api.kado.money/v2/public/orders/${n}`,{headers:{"X-Widget-Id":o}});if(!r.success)throw new Error(r.message);return r.data.order}catch(r){throw new Error("Failed to get order status")}}function F({sellAsset:n,buyAsset:o,recipient:r,type:e,sender:a,mode:c}){let u=i.SKConfig.get("apiKeys").kado;i.warnOnce(!u,"plugin(kado): No Kado API key found");let p=e==="buy"?{onPayAmount:n.getValue("string"),onPayCurrency:n.symbol,onRevCurrency:o.symbol,...r?{onToAddress:r}:{}}:{offPayAmount:n.getValue("string"),offPayCurrency:n.symbol,offRevCurrency:o.symbol,...a?{offFromAddress:a}:{}},s=h(e==="buy"?o.chain:n.chain).toUpperCase();return`https://app.kado.money/?${new URLSearchParams({...p,apiKey:u,network:s,product:e.toUpperCase(),mode:c}).toString()}`}function R(n){let o=document.createElement("div");o.style.cssText=`
|
|
2
|
-
position: fixed;
|
|
3
|
-
top: 0;
|
|
4
|
-
left: 0;
|
|
5
|
-
width: 100%;
|
|
6
|
-
height: 100%;
|
|
7
|
-
background: rgba(0, 0, 0, 0.5);
|
|
8
|
-
display: flex;
|
|
9
|
-
justify-content: center;
|
|
10
|
-
align-items: center;
|
|
11
|
-
z-index: 9999;
|
|
12
|
-
`;let r=document.createElement("iframe");return r.src=n,r.style.cssText=`
|
|
13
|
-
width: 440px;
|
|
14
|
-
height: 700px;
|
|
15
|
-
border: none;
|
|
16
|
-
border-radius: 12px;
|
|
17
|
-
background: white;
|
|
18
|
-
`,o.appendChild(r),document.body.appendChild(o),o.addEventListener("click",(e)=>{if(e.target===o)document.body.removeChild(o)}),o}var E=["USD","CAD","GBP","EUR","MXN","COP","INR","CHF","AUD","ARS","BRL","CLP","JPY","KRW","PEN","PHP","SGD","TRY","UYU","TWD","VND","CRC","SEK","PLN","DKK","NOK","NZD"];
|
|
19
|
-
|
|
20
|
-
//# debugId=3680F2EEFA51A34064756E2164756E21
|
package/dist/kado/index.cjs.map
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/kado/helpers.ts", "../src/kado/plugin.ts", "../src/kado/types.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { type AssetValue, BlockTimes, Chain, FeeTypeEnum, ProviderName } from \"@swapkit/helpers\";\nimport type { QuoteResponse, QuoteResponseRoute } from \"@swapkit/helpers/api\";\nimport type { KadoQuoteResponse } from \"./types\";\n\nexport const SupportedKadoChain = {\n thorchain: Chain.THORChain,\n solana: Chain.Solana,\n polygon: Chain.Polygon,\n Optimism: Chain.Optimism,\n litecoin: Chain.Litecoin,\n kujira: Chain.Kujira,\n ethereum: Chain.Ethereum,\n \"cosmos hub\": Chain.Cosmos,\n bitcoin: Chain.Bitcoin,\n base: Chain.Base,\n Avalanche: Chain.Avalanche,\n Arbitrum: Chain.Arbitrum,\n};\n\nexport function ChainToKadoChain(chain: Chain) {\n const entries = Object.entries(SupportedKadoChain);\n const found = entries.find(([_, value]) => value === chain);\n if (!found) throw new Error(`Chain ${chain} not supported`);\n return found[0];\n}\n\nexport function KadoChainToChain(kadoChain: string) {\n const found = Object.keys(SupportedKadoChain).includes(kadoChain);\n if (!found) throw new Error(`KadoChain ${kadoChain} not supported`);\n return SupportedKadoChain[kadoChain as keyof typeof SupportedKadoChain];\n}\n\nexport function mapKadoQuoteToQuoteResponse({\n quote,\n sellAsset,\n buyAsset,\n}: { quote: KadoQuoteResponse; sellAsset: AssetValue; buyAsset: AssetValue }): QuoteResponse {\n const sellAssetChain = sellAsset.chain;\n const buyAssetChain = buyAsset.chain;\n const isOnRamp = sellAssetChain === Chain.Fiat;\n const { receive, price, baseAmount, totalFee, processingFee, networkFee } = quote.data.quote;\n\n const buyAssetAmount = buyAsset.set(\n isOnRamp ? receive.unitCount.toString() : receive.amount.toString(),\n );\n const totalSlippageBps = isOnRamp\n ? Math.round((totalFee.amount / receive.amount) * 10_000)\n : Math.round((totalFee.amount / (price.price * baseAmount.amount)) * 10_000);\n\n const inbound = Math.ceil(BlockTimes[sellAssetChain] * 3);\n const swap = Math.ceil(60);\n const outbound = Math.ceil(BlockTimes[buyAssetChain]);\n const routes: QuoteResponseRoute[] = [\n {\n buyAsset: buyAsset.toString(),\n destinationAddress: \"{destinationAddress}\",\n estimatedTime: { inbound, swap, outbound, total: inbound + swap + outbound },\n expectedBuyAmount: buyAssetAmount.getValue(\"string\"),\n expectedBuyAmountMaxSlippage: buyAssetAmount.getValue(\"string\"),\n providers: [ProviderName.KADO],\n sellAmount: sellAsset.getValue(\"string\"),\n sellAsset: sellAsset.toString(),\n sourceAddress: \"{sourceAddress}\",\n totalSlippageBps,\n fees: [\n {\n asset: processingFee.currency,\n amount: processingFee.amount.toString(),\n type: FeeTypeEnum.LIQUIDITY,\n protocol: ProviderName.KADO,\n chain: Chain.Fiat,\n },\n {\n asset: networkFee.currency,\n amount: networkFee.amount.toString(),\n type: FeeTypeEnum.NETWORK,\n protocol: ProviderName.KADO,\n chain: buyAsset.chain,\n },\n ],\n legs: [\n {\n provider: ProviderName.KADO,\n sellAsset: sellAsset.toString(),\n sellAmount: sellAsset.getValue(\"string\"),\n buyAsset: buyAsset.toString(),\n buyAmount: receive.unitCount.toString(),\n buyAmountMaxSlippage: receive.unitCount.toString(),\n fees: [\n {\n asset: processingFee.currency,\n amount: processingFee.amount.toString(),\n type: FeeTypeEnum.LIQUIDITY,\n protocol: ProviderName.KADO,\n chain: Chain.Fiat,\n },\n {\n asset: networkFee.currency,\n amount: networkFee.amount.toString(),\n type: FeeTypeEnum.NETWORK,\n protocol: ProviderName.KADO,\n chain: buyAsset.chain,\n },\n ],\n },\n ],\n warnings: [],\n meta: { tags: [] },\n },\n ];\n\n return {\n quoteId: crypto.randomUUID(),\n routes,\n error: quote.success ? undefined : quote.message,\n };\n}\n",
|
|
6
|
-
"import {\n AssetValue,\n Chain,\n ProviderName,\n RequestClient,\n SKConfig,\n type SwapParams,\n createPlugin,\n warnOnce,\n} from \"@swapkit/helpers\";\nimport type { QuoteResponse, QuoteResponseRoute } from \"@swapkit/helpers/api\";\nimport { ChainToKadoChain, mapKadoQuoteToQuoteResponse } from \"./helpers\";\nimport type {\n KadoAssetsResponse,\n KadoBlockchainsResponse,\n KadoFiatCurrency,\n KadoFiatMethod,\n KadoQuoteRequest,\n KadoQuoteResponse,\n} from \"./types\";\n\nexport const KadoPlugin = createPlugin({\n name: \"kado\",\n methods: () => ({\n createPopover,\n getAssets,\n getBlockchains,\n getKadoWidgetUrl,\n getOrderStatus,\n fetchProviderQuote,\n swap,\n }),\n properties: {\n supportedSwapkitProviders: [ProviderName.KADO],\n },\n});\n\nfunction swap({ route }: SwapParams<\"evm\", QuoteResponseRoute>) {\n if (!(route.sourceAddress && route.destinationAddress)) {\n throw new Error(\"Source and destination addresses are required\");\n }\n\n const sellAsset = AssetValue.from({ asset: route.sellAsset });\n const buyAsset = AssetValue.from({ asset: route.buyAsset });\n\n // Determine if this is a buy or sell operation\n const type = sellAsset.chain === Chain.Fiat ? \"buy\" : \"sell\";\n\n const url = getKadoWidgetUrl({\n sellAsset,\n buyAsset,\n recipient: route.destinationAddress,\n sender: route.sourceAddress,\n type,\n mode: \"minimal\",\n });\n\n createPopover(url);\n\n return {\n status: \"pending\",\n txHash: null,\n };\n}\n\nasync function fetchProviderQuote({\n sellAsset,\n buyAsset,\n fiatMethod = \"credit_card\",\n}: {\n sellAsset: AssetValue;\n buyAsset: AssetValue;\n fiatMethod: KadoFiatMethod;\n}): Promise<QuoteResponse> {\n try {\n const isOnRamp = sellAsset.chain === Chain.Fiat;\n const [paymentAsset, receiveAsset] = isOnRamp ? [buyAsset, sellAsset] : [sellAsset, buyAsset];\n const transactionType = isOnRamp ? \"buy\" : \"sell\";\n\n const quoteRequest: KadoQuoteRequest = {\n amount: paymentAsset.getValue(\"string\"),\n asset: paymentAsset.symbol,\n blockchain: ChainToKadoChain(paymentAsset.chain),\n currency: receiveAsset.symbol as KadoFiatCurrency,\n fiatMethod,\n partner: \"fortress\",\n transactionType,\n };\n\n const kadoApiKey = SKConfig.get(\"apiKeys\").kado;\n warnOnce(!kadoApiKey, \"plugin(kado): No Kado API key found\");\n\n const quote = await RequestClient.get<KadoQuoteResponse>(\n \"https://api.kado.money/v2/ramp/quote\",\n { searchParams: quoteRequest, headers: { \"X-Widget-Id\": kadoApiKey } },\n );\n\n if (!quote.success) {\n throw new Error(quote.message);\n }\n\n return mapKadoQuoteToQuoteResponse({ quote, sellAsset, buyAsset });\n } catch (_) {\n throw new Error(\"core_swap_quote_error\");\n }\n}\n\nasync function getBlockchains() {\n const response = await RequestClient.get<KadoBlockchainsResponse>(\n \"https://api.kado.money/v1/ramp/blockchains\",\n );\n\n if (!response.success) {\n throw new Error(response.message);\n }\n\n return response.data.blockchains;\n}\n\nasync function getAssets() {\n const response = await RequestClient.get<KadoAssetsResponse>(\n \"https://api.kado.money/v1/ramp/supported-assets\",\n );\n\n if (!response.success) {\n throw new Error(response.message);\n }\n\n return response.data.assets;\n}\n\nasync function getOrderStatus(orderId: string) {\n const kadoApiKey = SKConfig.get(\"apiKeys\").kado;\n warnOnce(!kadoApiKey, \"plugin(kado): No Kado API key found\");\n\n try {\n const response = await RequestClient.get<{\n success: boolean;\n message: string;\n data: { order: { status: string } };\n }>(`https://api.kado.money/v2/public/orders/${orderId}`, {\n headers: { \"X-Widget-Id\": kadoApiKey },\n });\n\n if (!response.success) {\n throw new Error(response.message);\n }\n\n return response.data.order;\n } catch (_error) {\n throw new Error(\"Failed to get order status\");\n }\n}\n\nfunction getKadoWidgetUrl({\n sellAsset,\n buyAsset,\n recipient,\n type,\n sender,\n mode,\n}: {\n sellAsset: AssetValue;\n buyAsset: AssetValue;\n recipient?: string;\n sender?: string;\n type: \"buy\" | \"sell\";\n mode: \"minimal\" | \"full\";\n}) {\n const kadoApiKey = SKConfig.get(\"apiKeys\").kado;\n warnOnce(!kadoApiKey, \"plugin(kado): No Kado API key found\");\n\n const buySellParams =\n type === \"buy\"\n ? {\n onPayAmount: sellAsset.getValue(\"string\"),\n onPayCurrency: sellAsset.symbol,\n onRevCurrency: buyAsset.symbol,\n ...(recipient ? { onToAddress: recipient } : {}),\n }\n : {\n offPayAmount: sellAsset.getValue(\"string\"),\n offPayCurrency: sellAsset.symbol,\n offRevCurrency: buyAsset.symbol,\n ...(sender ? { offFromAddress: sender } : {}),\n };\n const network = ChainToKadoChain(type === \"buy\" ? buyAsset.chain : sellAsset.chain).toUpperCase();\n const urlParams = new URLSearchParams({\n ...buySellParams,\n apiKey: kadoApiKey,\n network,\n product: type.toUpperCase(),\n mode,\n });\n\n return `https://app.kado.money/?${urlParams.toString()}`;\n}\n\nfunction createPopover(url: string) {\n const overlay = document.createElement(\"div\");\n overlay.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.5);\n display: flex;\n justify-content: center;\n align-items: center;\n z-index: 9999;\n `;\n\n const iframe = document.createElement(\"iframe\");\n iframe.src = url;\n iframe.style.cssText = `\n width: 440px;\n height: 700px;\n border: none;\n border-radius: 12px;\n background: white;\n `;\n\n overlay.appendChild(iframe);\n document.body.appendChild(overlay);\n\n overlay.addEventListener(\"click\", (e) => {\n if (e.target === overlay) {\n document.body.removeChild(overlay);\n }\n });\n\n return overlay;\n}\n",
|
|
7
|
-
"import type { SupportedKadoChain } from \"./helpers\";\n\nexport const KadoSupportedFiatCurrencies = [\n \"USD\",\n \"CAD\",\n \"GBP\",\n \"EUR\",\n \"MXN\",\n \"COP\",\n \"INR\",\n \"CHF\",\n \"AUD\",\n \"ARS\",\n \"BRL\",\n \"CLP\",\n \"JPY\",\n \"KRW\",\n \"PEN\",\n \"PHP\",\n \"SGD\",\n \"TRY\",\n \"UYU\",\n \"TWD\",\n \"VND\",\n \"CRC\",\n \"SEK\",\n \"PLN\",\n \"DKK\",\n \"NOK\",\n \"NZD\",\n] as const;\n\nexport type KadoFiatCurrency = (typeof KadoSupportedFiatCurrencies)[number];\n\nexport type KadoFiatMethod =\n | \"ach\"\n | \"debit_card\"\n | \"credit_card\"\n | \"apple_pay_credit\"\n | \"apple_pay_debit\"\n | \"wire\"\n | \"sepa\"\n | \"pix\"\n | \"koywe\";\n\nexport type KadoQuoteRequest = {\n transactionType: \"buy\" | \"sell\";\n fiatMethod: KadoFiatMethod;\n partner: \"fortress\";\n amount: string;\n asset: string;\n blockchain: string;\n currency: KadoFiatCurrency;\n};\n\nexport type KadoAsset = {\n _id: string;\n name: string;\n description: string;\n label: string;\n symbol: string;\n supportedProviders: string[];\n stablecoin: boolean;\n liveOnRamp: boolean;\n createdAt: string;\n updatedAt: string;\n __v: number;\n priority: number;\n displayPrecision: number;\n usesAvaxRouter: boolean;\n squidChainId: string;\n coingeckoId: string;\n usesAxelarBridge: boolean;\n squidAssetId: string;\n address: string;\n blockExplorerURI: string;\n decimals: number;\n officialChainId: keyof typeof SupportedKadoChain;\n precision: number;\n rampProducts: string[];\n wallets: string[];\n rpcURI: string;\n usesPolygonFulfillment: boolean;\n usesOsmoRouter: boolean;\n ibcChannelIdOffRamp: number;\n ibcChannelIdOnRamp: number;\n osmoPfmChannel: number;\n osmoPfmReceiver: string;\n ibcDenom: string;\n isNative: boolean;\n avgOffRampTimeInSeconds: number;\n avgOnRampTimeInSeconds: number;\n providers: string[];\n trustekAssetId: string;\n trustekNetworkId: string;\n kycLevels: string[];\n};\n\nexport type KadoBlockchainsResponse = {\n success: boolean;\n message: string;\n data: {\n blockchains: {\n _id: string;\n supportedEnvironment: string;\n network: string;\n origin: string;\n label: string;\n associatedAssets: KadoAsset[];\n avgTransactionTimeSeconds: number;\n usesAvaxRouter: boolean;\n liveOnRamp: boolean;\n createdAt: string;\n updatedAt: string;\n __v: number;\n priority: number;\n }[];\n };\n};\n\nexport type KadoAssetsResponse = {\n success: boolean;\n message: string;\n data: {\n assets: {\n _id: string;\n name: string;\n description: string;\n label: string;\n symbol: string;\n supportedProviders: string[];\n stablecoin: boolean;\n liveOnRamp: boolean;\n createdAt: string;\n updatedAt: string;\n __v: number;\n priority: number;\n }[];\n };\n};\n\nexport type KadoQuoteResponse = {\n success: boolean;\n message: string;\n data: {\n request: {\n transactionType: string;\n fiatMethod: KadoFiatMethod;\n partner: string;\n amount: number;\n asset: string;\n blockchain: keyof typeof SupportedKadoChain;\n currency: KadoFiatCurrency;\n reverse: false;\n ipCountry: string;\n };\n quote: {\n asset: string;\n baseAmount: {\n amount: number;\n currency: KadoFiatCurrency;\n };\n price: {\n amount: number;\n price: number;\n symbol: string;\n unit: string;\n };\n bridgeFee: {\n amount: number;\n currency: KadoFiatCurrency;\n originalAmount: number;\n promotionModifier: number;\n };\n receiveAmountAfterFees: {\n originalAmount: number;\n amount: number;\n currency: KadoFiatCurrency;\n };\n receiveUnitCountAfterFees: {\n amount: number;\n currency: KadoFiatCurrency;\n };\n feeType: string;\n minValue: {\n amount: number;\n unit: string;\n };\n maxValue: {\n amount: number;\n unit: string;\n };\n receive: {\n amount: number;\n originalAmount: number;\n symbol: string;\n unit: string;\n unitCount: number;\n };\n networkFee: {\n amount: number;\n currency: KadoFiatCurrency;\n originalAmount: number;\n promotionModifier: number;\n };\n processingFee: {\n amount: number;\n currency: KadoFiatCurrency;\n originalAmount: number;\n promotionModifier: number;\n };\n totalFee: {\n amount: number;\n currency: KadoFiatCurrency;\n originalAmount: number;\n };\n smartContractFee: {\n amount: number;\n currency: KadoFiatCurrency;\n originalAmount: number;\n promotionModifier: number;\n };\n };\n };\n};\n"
|
|
8
|
-
],
|
|
9
|
-
"mappings": "gMAA8E,IAA9E,8BAIa,EAAqB,CAChC,UAAW,QAAM,UACjB,OAAQ,QAAM,OACd,QAAS,QAAM,QACf,SAAU,QAAM,SAChB,SAAU,QAAM,SAChB,OAAQ,QAAM,OACd,SAAU,QAAM,SAChB,aAAc,QAAM,OACpB,QAAS,QAAM,QACf,KAAM,QAAM,KACZ,UAAW,QAAM,UACjB,SAAU,QAAM,QAClB,EAEO,SAAS,CAAgB,CAAC,EAAc,CAE7C,IAAM,EADU,OAAO,QAAQ,CAAkB,EAC3B,KAAK,EAAE,EAAG,KAAW,IAAU,CAAK,EAC1D,IAAK,EAAO,MAAM,IAAI,MAAM,SAAS,iBAAqB,EAC1D,OAAO,EAAM,GAGR,SAAS,CAAgB,CAAC,EAAmB,CAElD,IADc,OAAO,KAAK,CAAkB,EAAE,SAAS,CAAS,EACpD,MAAM,IAAI,MAAM,aAAa,iBAAyB,EAClE,OAAO,EAAmB,GAGrB,SAAS,CAA2B,EACzC,QACA,YACA,YAC2F,CAC3F,IAAM,EAAiB,EAAU,MAC3B,EAAgB,EAAS,MACzB,EAAW,IAAmB,QAAM,MAClC,UAAS,QAAO,aAAY,WAAU,gBAAe,cAAe,EAAM,KAAK,MAEjF,EAAiB,EAAS,IAC9B,EAAW,EAAQ,UAAU,SAAS,EAAI,EAAQ,OAAO,SAAS,CACpE,EACM,EAAmB,EACrB,KAAK,MAAO,EAAS,OAAS,EAAQ,OAAU,GAAM,EACtD,KAAK,MAAO,EAAS,QAAU,EAAM,MAAQ,EAAW,QAAW,GAAM,EAEvE,EAAU,KAAK,KAAK,aAAW,GAAkB,CAAC,EAClD,EAAO,KAAK,KAAK,EAAE,EACnB,EAAW,KAAK,KAAK,aAAW,EAAc,EAC9C,EAA+B,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A;AAAA,IAaxB,IAAM,EAAS,SAAS,cAAc,QAAQ,EAmB9C,OAlBA,EAAO,IAAM,EACb,EAAO,MAAM,QAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQvB,EAAQ,YAAY,CAAM,EAC1B,SAAS,KAAK,YAAY,CAAO,EAEjC,EAAQ,iBAAiB,QAAS,CAAC,IAAM,CACvC,GAAI,EAAE,SAAW,EACf,SAAS,KAAK,YAAY,CAAO,EAEpC,EAEM,ECtOF,IAAM,EAA8B,CACzC,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,KACF",
|
|
10
|
-
"debugId": "3680F2EEFA51A34064756E2164756E21",
|
|
11
|
-
"names": []
|
|
12
|
-
}
|
package/dist/kado/index.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import"../chunk-tvrdndbw.js";import{BlockTimes as S,Chain as i,FeeTypeEnum as b,ProviderName as s}from"@swapkit/helpers";var f={thorchain:i.THORChain,solana:i.Solana,polygon:i.Polygon,Optimism:i.Optimism,litecoin:i.Litecoin,kujira:i.Kujira,ethereum:i.Ethereum,"cosmos hub":i.Cosmos,bitcoin:i.Bitcoin,base:i.Base,Avalanche:i.Avalanche,Arbitrum:i.Arbitrum};function y(n){let o=Object.entries(f).find(([r,e])=>e===n);if(!o)throw new Error(`Chain ${n} not supported`);return o[0]}function A(n){if(!Object.keys(f).includes(n))throw new Error(`KadoChain ${n} not supported`);return f[n]}function I({quote:n,sellAsset:t,buyAsset:o}){let r=t.chain,e=o.chain,m=r===i.Fiat,{receive:a,price:p,baseAmount:c,totalFee:u,processingFee:d,networkFee:g}=n.data.quote,K=o.set(m?a.unitCount.toString():a.amount.toString()),T=m?Math.round(u.amount/a.amount*1e4):Math.round(u.amount/(p.price*c.amount)*1e4),F=Math.ceil(S[r]*3),R=Math.ceil(60),x=Math.ceil(S[e]),M=[{buyAsset:o.toString(),destinationAddress:"{destinationAddress}",estimatedTime:{inbound:F,swap:R,outbound:x,total:F+R+x},expectedBuyAmount:K.getValue("string"),expectedBuyAmountMaxSlippage:K.getValue("string"),providers:[s.KADO],sellAmount:t.getValue("string"),sellAsset:t.toString(),sourceAddress:"{sourceAddress}",totalSlippageBps:T,fees:[{asset:d.currency,amount:d.amount.toString(),type:b.LIQUIDITY,protocol:s.KADO,chain:i.Fiat},{asset:g.currency,amount:g.amount.toString(),type:b.NETWORK,protocol:s.KADO,chain:o.chain}],legs:[{provider:s.KADO,sellAsset:t.toString(),sellAmount:t.getValue("string"),buyAsset:o.toString(),buyAmount:a.unitCount.toString(),buyAmountMaxSlippage:a.unitCount.toString(),fees:[{asset:d.currency,amount:d.amount.toString(),type:b.LIQUIDITY,protocol:s.KADO,chain:i.Fiat},{asset:g.currency,amount:g.amount.toString(),type:b.NETWORK,protocol:s.KADO,chain:o.chain}]}],warnings:[],meta:{tags:[]}}];return{quoteId:crypto.randomUUID(),routes:M,error:n.success?void 0:n.message}}import{AssetValue as O,Chain as _,ProviderName as E,RequestClient as h,SKConfig as l,createPlugin as N,warnOnce as C}from"@swapkit/helpers";var j=N({name:"kado",methods:()=>({createPopover:v,getAssets:B,getBlockchains:U,getKadoWidgetUrl:D,getOrderStatus:Q,fetchProviderQuote:k,swap:P}),properties:{supportedSwapkitProviders:[E.KADO]}});function P({route:n}){if(!(n.sourceAddress&&n.destinationAddress))throw new Error("Source and destination addresses are required");let t=O.from({asset:n.sellAsset}),o=O.from({asset:n.buyAsset}),r=t.chain===_.Fiat?"buy":"sell",e=D({sellAsset:t,buyAsset:o,recipient:n.destinationAddress,sender:n.sourceAddress,type:r,mode:"minimal"});return v(e),{status:"pending",txHash:null}}async function k({sellAsset:n,buyAsset:t,fiatMethod:o="credit_card"}){try{let r=n.chain===_.Fiat,[e,m]=r?[t,n]:[n,t],a=r?"buy":"sell",p={amount:e.getValue("string"),asset:e.symbol,blockchain:y(e.chain),currency:m.symbol,fiatMethod:o,partner:"fortress",transactionType:a},c=l.get("apiKeys").kado;C(!c,"plugin(kado): No Kado API key found");let u=await h.get("https://api.kado.money/v2/ramp/quote",{searchParams:p,headers:{"X-Widget-Id":c}});if(!u.success)throw new Error(u.message);return I({quote:u,sellAsset:n,buyAsset:t})}catch(r){throw new Error("core_swap_quote_error")}}async function U(){let n=await h.get("https://api.kado.money/v1/ramp/blockchains");if(!n.success)throw new Error(n.message);return n.data.blockchains}async function B(){let n=await h.get("https://api.kado.money/v1/ramp/supported-assets");if(!n.success)throw new Error(n.message);return n.data.assets}async function Q(n){let t=l.get("apiKeys").kado;C(!t,"plugin(kado): No Kado API key found");try{let o=await h.get(`https://api.kado.money/v2/public/orders/${n}`,{headers:{"X-Widget-Id":t}});if(!o.success)throw new Error(o.message);return o.data.order}catch(o){throw new Error("Failed to get order status")}}function D({sellAsset:n,buyAsset:t,recipient:o,type:r,sender:e,mode:m}){let a=l.get("apiKeys").kado;C(!a,"plugin(kado): No Kado API key found");let p=r==="buy"?{onPayAmount:n.getValue("string"),onPayCurrency:n.symbol,onRevCurrency:t.symbol,...o?{onToAddress:o}:{}}:{offPayAmount:n.getValue("string"),offPayCurrency:n.symbol,offRevCurrency:t.symbol,...e?{offFromAddress:e}:{}},c=y(r==="buy"?t.chain:n.chain).toUpperCase();return`https://app.kado.money/?${new URLSearchParams({...p,apiKey:a,network:c,product:r.toUpperCase(),mode:m}).toString()}`}function v(n){let t=document.createElement("div");t.style.cssText=`
|
|
2
|
-
position: fixed;
|
|
3
|
-
top: 0;
|
|
4
|
-
left: 0;
|
|
5
|
-
width: 100%;
|
|
6
|
-
height: 100%;
|
|
7
|
-
background: rgba(0, 0, 0, 0.5);
|
|
8
|
-
display: flex;
|
|
9
|
-
justify-content: center;
|
|
10
|
-
align-items: center;
|
|
11
|
-
z-index: 9999;
|
|
12
|
-
`;let o=document.createElement("iframe");return o.src=n,o.style.cssText=`
|
|
13
|
-
width: 440px;
|
|
14
|
-
height: 700px;
|
|
15
|
-
border: none;
|
|
16
|
-
border-radius: 12px;
|
|
17
|
-
background: white;
|
|
18
|
-
`,t.appendChild(o),document.body.appendChild(t),t.addEventListener("click",(r)=>{if(r.target===t)document.body.removeChild(t)}),t}var G=["USD","CAD","GBP","EUR","MXN","COP","INR","CHF","AUD","ARS","BRL","CLP","JPY","KRW","PEN","PHP","SGD","TRY","UYU","TWD","VND","CRC","SEK","PLN","DKK","NOK","NZD"];export{I as mapKadoQuoteToQuoteResponse,f as SupportedKadoChain,G as KadoSupportedFiatCurrencies,j as KadoPlugin,A as KadoChainToChain,y as ChainToKadoChain};
|
|
19
|
-
|
|
20
|
-
//# debugId=9108B788624D163064756E2164756E21
|
package/dist/kado/index.js.map
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/kado/helpers.ts", "../src/kado/plugin.ts", "../src/kado/types.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { type AssetValue, BlockTimes, Chain, FeeTypeEnum, ProviderName } from \"@swapkit/helpers\";\nimport type { QuoteResponse, QuoteResponseRoute } from \"@swapkit/helpers/api\";\nimport type { KadoQuoteResponse } from \"./types\";\n\nexport const SupportedKadoChain = {\n thorchain: Chain.THORChain,\n solana: Chain.Solana,\n polygon: Chain.Polygon,\n Optimism: Chain.Optimism,\n litecoin: Chain.Litecoin,\n kujira: Chain.Kujira,\n ethereum: Chain.Ethereum,\n \"cosmos hub\": Chain.Cosmos,\n bitcoin: Chain.Bitcoin,\n base: Chain.Base,\n Avalanche: Chain.Avalanche,\n Arbitrum: Chain.Arbitrum,\n};\n\nexport function ChainToKadoChain(chain: Chain) {\n const entries = Object.entries(SupportedKadoChain);\n const found = entries.find(([_, value]) => value === chain);\n if (!found) throw new Error(`Chain ${chain} not supported`);\n return found[0];\n}\n\nexport function KadoChainToChain(kadoChain: string) {\n const found = Object.keys(SupportedKadoChain).includes(kadoChain);\n if (!found) throw new Error(`KadoChain ${kadoChain} not supported`);\n return SupportedKadoChain[kadoChain as keyof typeof SupportedKadoChain];\n}\n\nexport function mapKadoQuoteToQuoteResponse({\n quote,\n sellAsset,\n buyAsset,\n}: { quote: KadoQuoteResponse; sellAsset: AssetValue; buyAsset: AssetValue }): QuoteResponse {\n const sellAssetChain = sellAsset.chain;\n const buyAssetChain = buyAsset.chain;\n const isOnRamp = sellAssetChain === Chain.Fiat;\n const { receive, price, baseAmount, totalFee, processingFee, networkFee } = quote.data.quote;\n\n const buyAssetAmount = buyAsset.set(\n isOnRamp ? receive.unitCount.toString() : receive.amount.toString(),\n );\n const totalSlippageBps = isOnRamp\n ? Math.round((totalFee.amount / receive.amount) * 10_000)\n : Math.round((totalFee.amount / (price.price * baseAmount.amount)) * 10_000);\n\n const inbound = Math.ceil(BlockTimes[sellAssetChain] * 3);\n const swap = Math.ceil(60);\n const outbound = Math.ceil(BlockTimes[buyAssetChain]);\n const routes: QuoteResponseRoute[] = [\n {\n buyAsset: buyAsset.toString(),\n destinationAddress: \"{destinationAddress}\",\n estimatedTime: { inbound, swap, outbound, total: inbound + swap + outbound },\n expectedBuyAmount: buyAssetAmount.getValue(\"string\"),\n expectedBuyAmountMaxSlippage: buyAssetAmount.getValue(\"string\"),\n providers: [ProviderName.KADO],\n sellAmount: sellAsset.getValue(\"string\"),\n sellAsset: sellAsset.toString(),\n sourceAddress: \"{sourceAddress}\",\n totalSlippageBps,\n fees: [\n {\n asset: processingFee.currency,\n amount: processingFee.amount.toString(),\n type: FeeTypeEnum.LIQUIDITY,\n protocol: ProviderName.KADO,\n chain: Chain.Fiat,\n },\n {\n asset: networkFee.currency,\n amount: networkFee.amount.toString(),\n type: FeeTypeEnum.NETWORK,\n protocol: ProviderName.KADO,\n chain: buyAsset.chain,\n },\n ],\n legs: [\n {\n provider: ProviderName.KADO,\n sellAsset: sellAsset.toString(),\n sellAmount: sellAsset.getValue(\"string\"),\n buyAsset: buyAsset.toString(),\n buyAmount: receive.unitCount.toString(),\n buyAmountMaxSlippage: receive.unitCount.toString(),\n fees: [\n {\n asset: processingFee.currency,\n amount: processingFee.amount.toString(),\n type: FeeTypeEnum.LIQUIDITY,\n protocol: ProviderName.KADO,\n chain: Chain.Fiat,\n },\n {\n asset: networkFee.currency,\n amount: networkFee.amount.toString(),\n type: FeeTypeEnum.NETWORK,\n protocol: ProviderName.KADO,\n chain: buyAsset.chain,\n },\n ],\n },\n ],\n warnings: [],\n meta: { tags: [] },\n },\n ];\n\n return {\n quoteId: crypto.randomUUID(),\n routes,\n error: quote.success ? undefined : quote.message,\n };\n}\n",
|
|
6
|
-
"import {\n AssetValue,\n Chain,\n ProviderName,\n RequestClient,\n SKConfig,\n type SwapParams,\n createPlugin,\n warnOnce,\n} from \"@swapkit/helpers\";\nimport type { QuoteResponse, QuoteResponseRoute } from \"@swapkit/helpers/api\";\nimport { ChainToKadoChain, mapKadoQuoteToQuoteResponse } from \"./helpers\";\nimport type {\n KadoAssetsResponse,\n KadoBlockchainsResponse,\n KadoFiatCurrency,\n KadoFiatMethod,\n KadoQuoteRequest,\n KadoQuoteResponse,\n} from \"./types\";\n\nexport const KadoPlugin = createPlugin({\n name: \"kado\",\n methods: () => ({\n createPopover,\n getAssets,\n getBlockchains,\n getKadoWidgetUrl,\n getOrderStatus,\n fetchProviderQuote,\n swap,\n }),\n properties: {\n supportedSwapkitProviders: [ProviderName.KADO],\n },\n});\n\nfunction swap({ route }: SwapParams<\"evm\", QuoteResponseRoute>) {\n if (!(route.sourceAddress && route.destinationAddress)) {\n throw new Error(\"Source and destination addresses are required\");\n }\n\n const sellAsset = AssetValue.from({ asset: route.sellAsset });\n const buyAsset = AssetValue.from({ asset: route.buyAsset });\n\n // Determine if this is a buy or sell operation\n const type = sellAsset.chain === Chain.Fiat ? \"buy\" : \"sell\";\n\n const url = getKadoWidgetUrl({\n sellAsset,\n buyAsset,\n recipient: route.destinationAddress,\n sender: route.sourceAddress,\n type,\n mode: \"minimal\",\n });\n\n createPopover(url);\n\n return {\n status: \"pending\",\n txHash: null,\n };\n}\n\nasync function fetchProviderQuote({\n sellAsset,\n buyAsset,\n fiatMethod = \"credit_card\",\n}: {\n sellAsset: AssetValue;\n buyAsset: AssetValue;\n fiatMethod: KadoFiatMethod;\n}): Promise<QuoteResponse> {\n try {\n const isOnRamp = sellAsset.chain === Chain.Fiat;\n const [paymentAsset, receiveAsset] = isOnRamp ? [buyAsset, sellAsset] : [sellAsset, buyAsset];\n const transactionType = isOnRamp ? \"buy\" : \"sell\";\n\n const quoteRequest: KadoQuoteRequest = {\n amount: paymentAsset.getValue(\"string\"),\n asset: paymentAsset.symbol,\n blockchain: ChainToKadoChain(paymentAsset.chain),\n currency: receiveAsset.symbol as KadoFiatCurrency,\n fiatMethod,\n partner: \"fortress\",\n transactionType,\n };\n\n const kadoApiKey = SKConfig.get(\"apiKeys\").kado;\n warnOnce(!kadoApiKey, \"plugin(kado): No Kado API key found\");\n\n const quote = await RequestClient.get<KadoQuoteResponse>(\n \"https://api.kado.money/v2/ramp/quote\",\n { searchParams: quoteRequest, headers: { \"X-Widget-Id\": kadoApiKey } },\n );\n\n if (!quote.success) {\n throw new Error(quote.message);\n }\n\n return mapKadoQuoteToQuoteResponse({ quote, sellAsset, buyAsset });\n } catch (_) {\n throw new Error(\"core_swap_quote_error\");\n }\n}\n\nasync function getBlockchains() {\n const response = await RequestClient.get<KadoBlockchainsResponse>(\n \"https://api.kado.money/v1/ramp/blockchains\",\n );\n\n if (!response.success) {\n throw new Error(response.message);\n }\n\n return response.data.blockchains;\n}\n\nasync function getAssets() {\n const response = await RequestClient.get<KadoAssetsResponse>(\n \"https://api.kado.money/v1/ramp/supported-assets\",\n );\n\n if (!response.success) {\n throw new Error(response.message);\n }\n\n return response.data.assets;\n}\n\nasync function getOrderStatus(orderId: string) {\n const kadoApiKey = SKConfig.get(\"apiKeys\").kado;\n warnOnce(!kadoApiKey, \"plugin(kado): No Kado API key found\");\n\n try {\n const response = await RequestClient.get<{\n success: boolean;\n message: string;\n data: { order: { status: string } };\n }>(`https://api.kado.money/v2/public/orders/${orderId}`, {\n headers: { \"X-Widget-Id\": kadoApiKey },\n });\n\n if (!response.success) {\n throw new Error(response.message);\n }\n\n return response.data.order;\n } catch (_error) {\n throw new Error(\"Failed to get order status\");\n }\n}\n\nfunction getKadoWidgetUrl({\n sellAsset,\n buyAsset,\n recipient,\n type,\n sender,\n mode,\n}: {\n sellAsset: AssetValue;\n buyAsset: AssetValue;\n recipient?: string;\n sender?: string;\n type: \"buy\" | \"sell\";\n mode: \"minimal\" | \"full\";\n}) {\n const kadoApiKey = SKConfig.get(\"apiKeys\").kado;\n warnOnce(!kadoApiKey, \"plugin(kado): No Kado API key found\");\n\n const buySellParams =\n type === \"buy\"\n ? {\n onPayAmount: sellAsset.getValue(\"string\"),\n onPayCurrency: sellAsset.symbol,\n onRevCurrency: buyAsset.symbol,\n ...(recipient ? { onToAddress: recipient } : {}),\n }\n : {\n offPayAmount: sellAsset.getValue(\"string\"),\n offPayCurrency: sellAsset.symbol,\n offRevCurrency: buyAsset.symbol,\n ...(sender ? { offFromAddress: sender } : {}),\n };\n const network = ChainToKadoChain(type === \"buy\" ? buyAsset.chain : sellAsset.chain).toUpperCase();\n const urlParams = new URLSearchParams({\n ...buySellParams,\n apiKey: kadoApiKey,\n network,\n product: type.toUpperCase(),\n mode,\n });\n\n return `https://app.kado.money/?${urlParams.toString()}`;\n}\n\nfunction createPopover(url: string) {\n const overlay = document.createElement(\"div\");\n overlay.style.cssText = `\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.5);\n display: flex;\n justify-content: center;\n align-items: center;\n z-index: 9999;\n `;\n\n const iframe = document.createElement(\"iframe\");\n iframe.src = url;\n iframe.style.cssText = `\n width: 440px;\n height: 700px;\n border: none;\n border-radius: 12px;\n background: white;\n `;\n\n overlay.appendChild(iframe);\n document.body.appendChild(overlay);\n\n overlay.addEventListener(\"click\", (e) => {\n if (e.target === overlay) {\n document.body.removeChild(overlay);\n }\n });\n\n return overlay;\n}\n",
|
|
7
|
-
"import type { SupportedKadoChain } from \"./helpers\";\n\nexport const KadoSupportedFiatCurrencies = [\n \"USD\",\n \"CAD\",\n \"GBP\",\n \"EUR\",\n \"MXN\",\n \"COP\",\n \"INR\",\n \"CHF\",\n \"AUD\",\n \"ARS\",\n \"BRL\",\n \"CLP\",\n \"JPY\",\n \"KRW\",\n \"PEN\",\n \"PHP\",\n \"SGD\",\n \"TRY\",\n \"UYU\",\n \"TWD\",\n \"VND\",\n \"CRC\",\n \"SEK\",\n \"PLN\",\n \"DKK\",\n \"NOK\",\n \"NZD\",\n] as const;\n\nexport type KadoFiatCurrency = (typeof KadoSupportedFiatCurrencies)[number];\n\nexport type KadoFiatMethod =\n | \"ach\"\n | \"debit_card\"\n | \"credit_card\"\n | \"apple_pay_credit\"\n | \"apple_pay_debit\"\n | \"wire\"\n | \"sepa\"\n | \"pix\"\n | \"koywe\";\n\nexport type KadoQuoteRequest = {\n transactionType: \"buy\" | \"sell\";\n fiatMethod: KadoFiatMethod;\n partner: \"fortress\";\n amount: string;\n asset: string;\n blockchain: string;\n currency: KadoFiatCurrency;\n};\n\nexport type KadoAsset = {\n _id: string;\n name: string;\n description: string;\n label: string;\n symbol: string;\n supportedProviders: string[];\n stablecoin: boolean;\n liveOnRamp: boolean;\n createdAt: string;\n updatedAt: string;\n __v: number;\n priority: number;\n displayPrecision: number;\n usesAvaxRouter: boolean;\n squidChainId: string;\n coingeckoId: string;\n usesAxelarBridge: boolean;\n squidAssetId: string;\n address: string;\n blockExplorerURI: string;\n decimals: number;\n officialChainId: keyof typeof SupportedKadoChain;\n precision: number;\n rampProducts: string[];\n wallets: string[];\n rpcURI: string;\n usesPolygonFulfillment: boolean;\n usesOsmoRouter: boolean;\n ibcChannelIdOffRamp: number;\n ibcChannelIdOnRamp: number;\n osmoPfmChannel: number;\n osmoPfmReceiver: string;\n ibcDenom: string;\n isNative: boolean;\n avgOffRampTimeInSeconds: number;\n avgOnRampTimeInSeconds: number;\n providers: string[];\n trustekAssetId: string;\n trustekNetworkId: string;\n kycLevels: string[];\n};\n\nexport type KadoBlockchainsResponse = {\n success: boolean;\n message: string;\n data: {\n blockchains: {\n _id: string;\n supportedEnvironment: string;\n network: string;\n origin: string;\n label: string;\n associatedAssets: KadoAsset[];\n avgTransactionTimeSeconds: number;\n usesAvaxRouter: boolean;\n liveOnRamp: boolean;\n createdAt: string;\n updatedAt: string;\n __v: number;\n priority: number;\n }[];\n };\n};\n\nexport type KadoAssetsResponse = {\n success: boolean;\n message: string;\n data: {\n assets: {\n _id: string;\n name: string;\n description: string;\n label: string;\n symbol: string;\n supportedProviders: string[];\n stablecoin: boolean;\n liveOnRamp: boolean;\n createdAt: string;\n updatedAt: string;\n __v: number;\n priority: number;\n }[];\n };\n};\n\nexport type KadoQuoteResponse = {\n success: boolean;\n message: string;\n data: {\n request: {\n transactionType: string;\n fiatMethod: KadoFiatMethod;\n partner: string;\n amount: number;\n asset: string;\n blockchain: keyof typeof SupportedKadoChain;\n currency: KadoFiatCurrency;\n reverse: false;\n ipCountry: string;\n };\n quote: {\n asset: string;\n baseAmount: {\n amount: number;\n currency: KadoFiatCurrency;\n };\n price: {\n amount: number;\n price: number;\n symbol: string;\n unit: string;\n };\n bridgeFee: {\n amount: number;\n currency: KadoFiatCurrency;\n originalAmount: number;\n promotionModifier: number;\n };\n receiveAmountAfterFees: {\n originalAmount: number;\n amount: number;\n currency: KadoFiatCurrency;\n };\n receiveUnitCountAfterFees: {\n amount: number;\n currency: KadoFiatCurrency;\n };\n feeType: string;\n minValue: {\n amount: number;\n unit: string;\n };\n maxValue: {\n amount: number;\n unit: string;\n };\n receive: {\n amount: number;\n originalAmount: number;\n symbol: string;\n unit: string;\n unitCount: number;\n };\n networkFee: {\n amount: number;\n currency: KadoFiatCurrency;\n originalAmount: number;\n promotionModifier: number;\n };\n processingFee: {\n amount: number;\n currency: KadoFiatCurrency;\n originalAmount: number;\n promotionModifier: number;\n };\n totalFee: {\n amount: number;\n currency: KadoFiatCurrency;\n originalAmount: number;\n };\n smartContractFee: {\n amount: number;\n currency: KadoFiatCurrency;\n originalAmount: number;\n promotionModifier: number;\n };\n };\n };\n};\n"
|
|
8
|
-
],
|
|
9
|
-
"mappings": "6BAAA,qBAA0B,WAAY,iBAAO,kBAAa,yBAInD,IAAM,EAAqB,CAChC,UAAW,EAAM,UACjB,OAAQ,EAAM,OACd,QAAS,EAAM,QACf,SAAU,EAAM,SAChB,SAAU,EAAM,SAChB,OAAQ,EAAM,OACd,SAAU,EAAM,SAChB,aAAc,EAAM,OACpB,QAAS,EAAM,QACf,KAAM,EAAM,KACZ,UAAW,EAAM,UACjB,SAAU,EAAM,QAClB,EAEO,SAAS,CAAgB,CAAC,EAAc,CAE7C,IAAM,EADU,OAAO,QAAQ,CAAkB,EAC3B,KAAK,EAAE,EAAG,KAAW,IAAU,CAAK,EAC1D,IAAK,EAAO,MAAM,IAAI,MAAM,SAAS,iBAAqB,EAC1D,OAAO,EAAM,GAGR,SAAS,CAAgB,CAAC,EAAmB,CAElD,IADc,OAAO,KAAK,CAAkB,EAAE,SAAS,CAAS,EACpD,MAAM,IAAI,MAAM,aAAa,iBAAyB,EAClE,OAAO,EAAmB,GAGrB,SAAS,CAA2B,EACzC,QACA,YACA,YAC2F,CAC3F,IAAM,EAAiB,EAAU,MAC3B,EAAgB,EAAS,MACzB,EAAW,IAAmB,EAAM,MAClC,UAAS,QAAO,aAAY,WAAU,gBAAe,cAAe,EAAM,KAAK,MAEjF,EAAiB,EAAS,IAC9B,EAAW,EAAQ,UAAU,SAAS,EAAI,EAAQ,OAAO,SAAS,CACpE,EACM,EAAmB,EACrB,KAAK,MAAO,EAAS,OAAS,EAAQ,OAAU,GAAM,EACtD,KAAK,MAAO,EAAS,QAAU,EAAM,MAAQ,EAAW,QAAW,GAAM,EAEvE,EAAU,KAAK,KAAK,EAAW,GAAkB,CAAC,EAClD,EAAO,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,cAAc,KAAK,EAC5C,EAAQ,MAAM,QAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAaxB,IAAM,EAAS,SAAS,cAAc,QAAQ,EAmB9C,OAlBA,EAAO,IAAM,EACb,EAAO,MAAM,QAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAQvB,EAAQ,YAAY,CAAM,EAC1B,SAAS,KAAK,YAAY,CAAO,EAEjC,EAAQ,iBAAiB,QAAS,CAAC,IAAM,CACvC,GAAI,EAAE,SAAW,EACf,SAAS,KAAK,YAAY,CAAO,EAEpC,EAEM,ECtOF,IAAM,EAA8B,CACzC,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,KACF",
|
|
10
|
-
"debugId": "9108B788624D163064756E2164756E21",
|
|
11
|
-
"names": []
|
|
12
|
-
}
|
package/src/kado/helpers.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import { type AssetValue, BlockTimes, Chain, FeeTypeEnum, ProviderName } from "@swapkit/helpers";
|
|
2
|
-
import type { QuoteResponse, QuoteResponseRoute } from "@swapkit/helpers/api";
|
|
3
|
-
import type { KadoQuoteResponse } from "./types";
|
|
4
|
-
|
|
5
|
-
export const SupportedKadoChain = {
|
|
6
|
-
thorchain: Chain.THORChain,
|
|
7
|
-
solana: Chain.Solana,
|
|
8
|
-
polygon: Chain.Polygon,
|
|
9
|
-
Optimism: Chain.Optimism,
|
|
10
|
-
litecoin: Chain.Litecoin,
|
|
11
|
-
kujira: Chain.Kujira,
|
|
12
|
-
ethereum: Chain.Ethereum,
|
|
13
|
-
"cosmos hub": Chain.Cosmos,
|
|
14
|
-
bitcoin: Chain.Bitcoin,
|
|
15
|
-
base: Chain.Base,
|
|
16
|
-
Avalanche: Chain.Avalanche,
|
|
17
|
-
Arbitrum: Chain.Arbitrum,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export function ChainToKadoChain(chain: Chain) {
|
|
21
|
-
const entries = Object.entries(SupportedKadoChain);
|
|
22
|
-
const found = entries.find(([_, value]) => value === chain);
|
|
23
|
-
if (!found) throw new Error(`Chain ${chain} not supported`);
|
|
24
|
-
return found[0];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function KadoChainToChain(kadoChain: string) {
|
|
28
|
-
const found = Object.keys(SupportedKadoChain).includes(kadoChain);
|
|
29
|
-
if (!found) throw new Error(`KadoChain ${kadoChain} not supported`);
|
|
30
|
-
return SupportedKadoChain[kadoChain as keyof typeof SupportedKadoChain];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function mapKadoQuoteToQuoteResponse({
|
|
34
|
-
quote,
|
|
35
|
-
sellAsset,
|
|
36
|
-
buyAsset,
|
|
37
|
-
}: { quote: KadoQuoteResponse; sellAsset: AssetValue; buyAsset: AssetValue }): QuoteResponse {
|
|
38
|
-
const sellAssetChain = sellAsset.chain;
|
|
39
|
-
const buyAssetChain = buyAsset.chain;
|
|
40
|
-
const isOnRamp = sellAssetChain === Chain.Fiat;
|
|
41
|
-
const { receive, price, baseAmount, totalFee, processingFee, networkFee } = quote.data.quote;
|
|
42
|
-
|
|
43
|
-
const buyAssetAmount = buyAsset.set(
|
|
44
|
-
isOnRamp ? receive.unitCount.toString() : receive.amount.toString(),
|
|
45
|
-
);
|
|
46
|
-
const totalSlippageBps = isOnRamp
|
|
47
|
-
? Math.round((totalFee.amount / receive.amount) * 10_000)
|
|
48
|
-
: Math.round((totalFee.amount / (price.price * baseAmount.amount)) * 10_000);
|
|
49
|
-
|
|
50
|
-
const inbound = Math.ceil(BlockTimes[sellAssetChain] * 3);
|
|
51
|
-
const swap = Math.ceil(60);
|
|
52
|
-
const outbound = Math.ceil(BlockTimes[buyAssetChain]);
|
|
53
|
-
const routes: QuoteResponseRoute[] = [
|
|
54
|
-
{
|
|
55
|
-
buyAsset: buyAsset.toString(),
|
|
56
|
-
destinationAddress: "{destinationAddress}",
|
|
57
|
-
estimatedTime: { inbound, swap, outbound, total: inbound + swap + outbound },
|
|
58
|
-
expectedBuyAmount: buyAssetAmount.getValue("string"),
|
|
59
|
-
expectedBuyAmountMaxSlippage: buyAssetAmount.getValue("string"),
|
|
60
|
-
providers: [ProviderName.KADO],
|
|
61
|
-
sellAmount: sellAsset.getValue("string"),
|
|
62
|
-
sellAsset: sellAsset.toString(),
|
|
63
|
-
sourceAddress: "{sourceAddress}",
|
|
64
|
-
totalSlippageBps,
|
|
65
|
-
fees: [
|
|
66
|
-
{
|
|
67
|
-
asset: processingFee.currency,
|
|
68
|
-
amount: processingFee.amount.toString(),
|
|
69
|
-
type: FeeTypeEnum.LIQUIDITY,
|
|
70
|
-
protocol: ProviderName.KADO,
|
|
71
|
-
chain: Chain.Fiat,
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
asset: networkFee.currency,
|
|
75
|
-
amount: networkFee.amount.toString(),
|
|
76
|
-
type: FeeTypeEnum.NETWORK,
|
|
77
|
-
protocol: ProviderName.KADO,
|
|
78
|
-
chain: buyAsset.chain,
|
|
79
|
-
},
|
|
80
|
-
],
|
|
81
|
-
legs: [
|
|
82
|
-
{
|
|
83
|
-
provider: ProviderName.KADO,
|
|
84
|
-
sellAsset: sellAsset.toString(),
|
|
85
|
-
sellAmount: sellAsset.getValue("string"),
|
|
86
|
-
buyAsset: buyAsset.toString(),
|
|
87
|
-
buyAmount: receive.unitCount.toString(),
|
|
88
|
-
buyAmountMaxSlippage: receive.unitCount.toString(),
|
|
89
|
-
fees: [
|
|
90
|
-
{
|
|
91
|
-
asset: processingFee.currency,
|
|
92
|
-
amount: processingFee.amount.toString(),
|
|
93
|
-
type: FeeTypeEnum.LIQUIDITY,
|
|
94
|
-
protocol: ProviderName.KADO,
|
|
95
|
-
chain: Chain.Fiat,
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
asset: networkFee.currency,
|
|
99
|
-
amount: networkFee.amount.toString(),
|
|
100
|
-
type: FeeTypeEnum.NETWORK,
|
|
101
|
-
protocol: ProviderName.KADO,
|
|
102
|
-
chain: buyAsset.chain,
|
|
103
|
-
},
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
warnings: [],
|
|
108
|
-
meta: { tags: [] },
|
|
109
|
-
},
|
|
110
|
-
];
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
quoteId: crypto.randomUUID(),
|
|
114
|
-
routes,
|
|
115
|
-
error: quote.success ? undefined : quote.message,
|
|
116
|
-
};
|
|
117
|
-
}
|
package/src/kado/index.ts
DELETED
package/src/kado/plugin.ts
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
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
|
-
}
|
package/src/kado/types.ts
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
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
|
-
};
|