@swapkit/plugins 4.0.8 → 4.0.10
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/chainflip/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var
|
|
1
|
+
var P={};k(P,{assetIdentifierToChainflipTicker:()=>b,ChainflipPlugin:()=>_,ChainflipBroker:()=>T});module.exports=D(P);var h=require("@polkadot/keyring"),f=require("@polkadot/util"),s=require("@swapkit/helpers"),b=new Map([["ARB.ETH","ArbEth"],["ARB.USDC-0XAF88D065E77C8CC2239327C5EDB3A432268E5831","ArbUsdc"],["BTC.BTC","Btc"],["DOT.DOT","Dot"],["ETH.ETH","Eth"],["ETH.FLIP-0X826180541412D574CF1336D22C0C0A287822678A","Flip"],["ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48","Usdc"],["ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7","Usdt"],["SOL.SOL","Sol"],["SOL.USDC-EPJFWDD5AUFQSSQEM2QN1XZYBAPC8G4WEGGKZWYTDT1V","SolUsdc"]]),S=(e)=>()=>{let r=e.api.tx.swapping?.registerAsBroker?.();if(!r)throw new s.SwapKitError("chainflip_broker_register");return e.signAndBroadcast({address:e.getAddress(),tx:r})},B=(e)=>({feeAsset:r,recipient:t})=>{let o=r.chain===s.Chain.Polkadot,a=s.wrapWithThrow(()=>{return o?e.encodeAddress(e.decodeAddress(t),"hex"):t},"chainflip_broker_recipient_error");return new Promise((d)=>{let n=e.api.tx?.swapping?.withdraw?.(r.ticker.toLowerCase(),{[r.chain.toLowerCase()]:a});if(!n)throw new s.SwapKitError("chainflip_broker_withdraw");e.signAndBroadcast({callback:(p)=>{if(!p.status?.isFinalized)return;let l=p.events.find((x)=>x.event.method==="WithdrawalRequested");if(!l)throw new s.SwapKitError("chainflip_channel_error","Could not find 'WithdrawalRequested' event");let{event:{data:{egressId:u,egressAsset:c,egressAmount:m,egressFee:A,destinationAddress:C}}}=l.toHuman();d({destinationAddress:C,egressAmount:m,egressAsset:c,egressFee:A,egressId:u})},tx:n})})},E=(e)=>async({evmToolbox:r,stateChainAccount:t,assetValue:o})=>{let{chainflipGateway:a}=await import("@swapkit/helpers/contracts"),d=s.AssetValue.from({asset:"ETH.FLIP"});if(!o.eqAsset(d))throw new s.SwapKitError("chainflip_broker_fund_only_flip_supported");if(!e.validateAddress(t))throw new s.SwapKitError("chainflip_broker_fund_invalid_address");let n=f.isHex(t)?t:f.u8aToHex(h.decodeAddress(t));return r.call({abi:a,contractAddress:"0x6995ab7c4d7f4b03f467cf4c8e920427d9621dbd",funcName:"fundStateChainAccount",funcParams:[n,o.getBaseValue("string")]})},T=(e)=>({fundStateChainAccount:E(e),registerAsBroker:S(e),withdrawFee:B(e)});var i=require("@swapkit/helpers"),g=require("@swapkit/helpers/api");var _=w({methods:({getWallet:e})=>({swap:async function r(t){if(!(t?.route?.buyAsset&&t.route.meta.chainflip))throw new i.SwapKitError("core_swap_invalid_params",{...t});let{route:{buyAsset:o,sellAsset:a,sellAmount:d,destinationAddress:n,meta:{chainflip:p}},maxBoostFeeBps:l=0}=t;if(!(a&&o))throw new i.SwapKitError("core_swap_asset_not_recognized");let u=await i.AssetValue.from({asset:a,asyncTokenLookup:!0,value:d}),c=e(u.chain);if(!c)throw new i.SwapKitError("core_wallet_connection_not_found");let{depositAddress:m}=await g.SwapKitApi.getChainflipDepositChannel({...p,destinationAddress:n||p.destinationAddress,maxBoostFeeBps:l||p.maxBoostFeeBps});return await c.transfer({assetValue:u,isProgramDerivedAddress:!0,recipient:m,sender:c.address})}}),name:"chainflip",properties:{supportedSwapkitProviders:[i.ProviderName.CHAINFLIP,i.ProviderName.CHAINFLIP_STREAMING]}});
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=31509877533C119B64756E2164756E21
|
|
4
4
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["../src/chainflip/broker.ts", "../src/chainflip/plugin.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { decodeAddress } from \"@polkadot/keyring\";\nimport { isHex, u8aToHex } from \"@polkadot/util\";\nimport { AssetValue, Chain, SwapKitError, wrapWithThrow } from \"@swapkit/helpers\";\nimport type { getEvmToolbox } from \"@swapkit/toolboxes/evm\";\nimport type { getSubstrateToolbox } from \"@swapkit/toolboxes/substrate\";\n\nimport type { WithdrawFeeResponse } from \"./types\";\n\ntype ChainflipToolbox = Awaited<ReturnType<typeof getSubstrateToolbox<Chain.Chainflip>>>;\n\nexport const assetIdentifierToChainflipTicker = new Map<string, string>([\n [\"ARB.ETH\", \"ArbEth\"],\n [\"ARB.USDC-0XAF88D065E77C8CC2239327C5EDB3A432268E5831\", \"ArbUsdc\"],\n [\"BTC.BTC\", \"Btc\"],\n [\"DOT.DOT\", \"Dot\"],\n [\"ETH.ETH\", \"Eth\"],\n [\"ETH.FLIP-0X826180541412D574CF1336D22C0C0A287822678A\", \"Flip\"],\n [\"ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48\", \"Usdc\"],\n [\"ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7\", \"Usdt\"],\n [\"SOL.SOL\", \"Sol\"],\n [\"SOL.USDC-EPJFWDD5AUFQSSQEM2QN1XZYBAPC8G4WEGGKZWYTDT1V\", \"SolUsdc\"],\n]);\n\nconst registerAsBroker = (toolbox: ChainflipToolbox) => () => {\n const extrinsic = toolbox.api.tx.swapping?.registerAsBroker?.();\n\n if (!extrinsic) {\n throw new SwapKitError(\"chainflip_broker_register\");\n }\n\n return toolbox.signAndBroadcast({ address: toolbox.getAddress(), tx: extrinsic });\n};\n\nconst withdrawFee =\n (toolbox: ChainflipToolbox) =>\n ({ feeAsset, recipient }: { feeAsset: AssetValue; recipient: string }) => {\n const isFeeChainPolkadot = feeAsset.chain === Chain.Polkadot;\n\n const recipientAddress = wrapWithThrow(() => {\n return isFeeChainPolkadot ? toolbox.encodeAddress(toolbox.decodeAddress(recipient), \"hex\") : recipient;\n }, \"chainflip_broker_recipient_error\");\n\n return new Promise<WithdrawFeeResponse>((resolve) => {\n const extrinsic = toolbox.api.tx?.swapping?.withdraw?.(feeAsset.ticker.toLowerCase(), {\n [feeAsset.chain.toLowerCase()]: recipientAddress,\n });\n\n if (!extrinsic) {\n throw new SwapKitError(\"chainflip_broker_withdraw\");\n }\n\n toolbox.signAndBroadcast({\n callback: (result) => {\n if (!result.status?.isFinalized) {\n return;\n }\n\n const withdrawEvent = result.events.find((event) => event.event.method === \"WithdrawalRequested\");\n\n if (!withdrawEvent) {\n throw new SwapKitError(\"chainflip_channel_error\", \"Could not find 'WithdrawalRequested' event\");\n }\n const {\n event: {\n data: { egressId, egressAsset, egressAmount, egressFee, destinationAddress },\n },\n } = withdrawEvent.toHuman() as any;\n resolve({ destinationAddress, egressAmount, egressAsset, egressFee, egressId });\n },\n tx: extrinsic,\n });\n });\n };\n\nconst fundStateChainAccount =\n (chainflipToolbox: ChainflipToolbox) =>\n async ({\n evmToolbox,\n stateChainAccount,\n assetValue,\n }: {\n evmToolbox: Awaited<ReturnType<typeof getEvmToolbox>>;\n stateChainAccount: string;\n assetValue: AssetValue;\n }) => {\n const { chainflipGateway } = await import(\"@swapkit/helpers/contracts\");\n\n const flipAssetValue = AssetValue.from({ asset: \"ETH.FLIP\" });\n\n if (!assetValue.eqAsset(flipAssetValue)) {\n throw new SwapKitError(\"chainflip_broker_fund_only_flip_supported\");\n }\n\n if (!chainflipToolbox.validateAddress(stateChainAccount)) {\n throw new SwapKitError(\"chainflip_broker_fund_invalid_address\");\n }\n\n const hexAddress = isHex(stateChainAccount) ? stateChainAccount : u8aToHex(decodeAddress(stateChainAccount));\n\n return evmToolbox.call<string>({\n abi: chainflipGateway,\n contractAddress: \"0x6995ab7c4d7f4b03f467cf4c8e920427d9621dbd\",\n funcName: \"fundStateChainAccount\",\n funcParams: [hexAddress, assetValue.getBaseValue(\"string\")],\n });\n };\n\nexport const ChainflipBroker = (chainflipToolbox: ChainflipToolbox) => ({\n fundStateChainAccount: fundStateChainAccount(chainflipToolbox),\n registerAsBroker: registerAsBroker(chainflipToolbox),\n withdrawFee: withdrawFee(chainflipToolbox),\n});\n",
|
|
6
|
-
"import { AssetValue, type CryptoChain, ProviderName, SwapKitError } from \"@swapkit/helpers\";\nimport { SwapKitApi } from \"@swapkit/helpers/api\";\nimport { createPlugin } from \"../utils\";\nimport type { RequestSwapDepositAddressParams } from \"./types\";\n\nexport const ChainflipPlugin = createPlugin({\n methods: ({ getWallet }) => ({\n swap: async function chainflipSwap(swapParams: RequestSwapDepositAddressParams) {\n if (!(swapParams?.route?.buyAsset && swapParams.route.meta.chainflip)) {\n throw new SwapKitError(\"core_swap_invalid_params\", { ...swapParams });\n }\n\n const {\n route: {\n buyAsset: buyAssetString,\n sellAsset: sellAssetString,\n sellAmount,\n destinationAddress: recipient,\n meta: { chainflip },\n },\n maxBoostFeeBps = 0,\n } = swapParams;\n\n if (!(sellAssetString && buyAssetString)) {\n throw new SwapKitError(\"core_swap_asset_not_recognized\");\n }\n\n const sellAsset = await AssetValue.from({ asset: sellAssetString, asyncTokenLookup: true, value: sellAmount });\n\n const wallet = getWallet(sellAsset.chain as CryptoChain);\n\n if (!wallet) {\n throw new SwapKitError(\"core_wallet_connection_not_found\");\n }\n\n const { depositAddress } = await SwapKitApi.getChainflipDepositChannel({\n ...chainflip,\n destinationAddress: recipient || chainflip.destinationAddress,\n maxBoostFeeBps: maxBoostFeeBps || chainflip.maxBoostFeeBps,\n });\n\n
|
|
6
|
+
"import { AssetValue, type Chain, type CryptoChain, ProviderName, SwapKitError } from \"@swapkit/helpers\";\nimport { SwapKitApi } from \"@swapkit/helpers/api\";\nimport { createPlugin } from \"../utils\";\nimport type { RequestSwapDepositAddressParams } from \"./types\";\n\nexport const ChainflipPlugin = createPlugin({\n methods: ({ getWallet }) => ({\n swap: async function chainflipSwap(swapParams: RequestSwapDepositAddressParams) {\n if (!(swapParams?.route?.buyAsset && swapParams.route.meta.chainflip)) {\n throw new SwapKitError(\"core_swap_invalid_params\", { ...swapParams });\n }\n\n const {\n route: {\n buyAsset: buyAssetString,\n sellAsset: sellAssetString,\n sellAmount,\n destinationAddress: recipient,\n meta: { chainflip },\n },\n maxBoostFeeBps = 0,\n } = swapParams;\n\n if (!(sellAssetString && buyAssetString)) {\n throw new SwapKitError(\"core_swap_asset_not_recognized\");\n }\n\n const sellAsset = await AssetValue.from({ asset: sellAssetString, asyncTokenLookup: true, value: sellAmount });\n\n const wallet = getWallet(sellAsset.chain as Exclude<CryptoChain, Chain.Radix>);\n\n if (!wallet) {\n throw new SwapKitError(\"core_wallet_connection_not_found\");\n }\n\n const { depositAddress } = await SwapKitApi.getChainflipDepositChannel({\n ...chainflip,\n destinationAddress: recipient || chainflip.destinationAddress,\n maxBoostFeeBps: maxBoostFeeBps || chainflip.maxBoostFeeBps,\n });\n\n const tx = await wallet.transfer({\n assetValue: sellAsset,\n isProgramDerivedAddress: true,\n recipient: depositAddress,\n sender: wallet.address,\n });\n\n return tx;\n },\n }),\n name: \"chainflip\",\n properties: { supportedSwapkitProviders: [ProviderName.CHAINFLIP, ProviderName.CHAINFLIP_STREAMING] },\n});\n"
|
|
7
7
|
],
|
|
8
|
-
"mappings": "uHAA8B,IAA9B,+BACA,4BACA,8BAQa,EAAmC,IAAI,IAAoB,CACtE,CAAC,UAAW,QAAQ,EACpB,CAAC,sDAAuD,SAAS,EACjE,CAAC,UAAW,KAAK,EACjB,CAAC,UAAW,KAAK,EACjB,CAAC,UAAW,KAAK,EACjB,CAAC,sDAAuD,MAAM,EAC9D,CAAC,sDAAuD,MAAM,EAC9D,CAAC,sDAAuD,MAAM,EAC9D,CAAC,UAAW,KAAK,EACjB,CAAC,wDAAyD,SAAS,CACrE,CAAC,EAEK,EAAmB,CAAC,IAA8B,IAAM,CAC5D,IAAM,EAAY,EAAQ,IAAI,GAAG,UAAU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AAM,IAAI,eAAa,gCAAgC,EAGzD,IAAM,EAAY,MAAM,aAAW,KAAK,CAAE,MAAO,EAAiB,iBAAkB,GAAM,MAAO,CAAW,CAAC,EAEvG,EAAS,EAAU,EAAU,KAA0C,EAE7E,IAAK,EACH,MAAM,IAAI,eAAa,kCAAkC,EAG3D,IAAQ,kBAAmB,MAAM,aAAW,2BAA2B,IAClE,EACH,mBAAoB,GAAa,EAAU,mBAC3C,eAAgB,GAAkB,EAAU,cAC9C,CAAC,EASD,OAPW,MAAM,EAAO,SAAS,CAC/B,WAAY,EACZ,wBAAyB,GACzB,UAAW,EACX,OAAQ,EAAO,OACjB,CAAC,EAIL,GACA,KAAM,YACN,WAAY,CAAE,0BAA2B,CAAC,eAAa,UAAW,eAAa,mBAAmB,CAAE,CACtG,CAAC",
|
|
9
|
+
"debugId": "31509877533C119B64756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
package/dist/chainflip/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as C,b as x,c as h}from"../chunk-m8bk80cn.js";import{decodeAddress as y}from"@polkadot/keyring";import{isHex as b,u8aToHex as S}from"@polkadot/util";import{AssetValue as B,Chain as E,SwapKitError as d,wrapWithThrow as T}from"@swapkit/helpers";var I=new Map([["ARB.ETH","ArbEth"],["ARB.USDC-0XAF88D065E77C8CC2239327C5EDB3A432268E5831","ArbUsdc"],["BTC.BTC","Btc"],["DOT.DOT","Dot"],["ETH.ETH","Eth"],["ETH.FLIP-0X826180541412D574CF1336D22C0C0A287822678A","Flip"],["ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48","Usdc"],["ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7","Usdt"],["SOL.SOL","Sol"],["SOL.USDC-EPJFWDD5AUFQSSQEM2QN1XZYBAPC8G4WEGGKZWYTDT1V","SolUsdc"]]),_=(e)=>()=>{let s=e.api.tx.swapping?.registerAsBroker?.();if(!s)throw new d("chainflip_broker_register");return e.signAndBroadcast({address:e.getAddress(),tx:s})},D=(e)=>({feeAsset:s,recipient:t})=>{let r=s.chain===E.Polkadot,i=T(()=>{return r?e.encodeAddress(e.decodeAddress(t),"hex"):t},"chainflip_broker_recipient_error");return new Promise((n)=>{let o=e.api.tx?.swapping?.withdraw?.(s.ticker.toLowerCase(),{[s.chain.toLowerCase()]:i});if(!o)throw new d("chainflip_broker_withdraw");e.signAndBroadcast({callback:(a)=>{if(!a.status?.isFinalized)return;let c=a.events.find((g)=>g.event.method==="WithdrawalRequested");if(!c)throw new d("chainflip_channel_error","Could not find 'WithdrawalRequested' event");let{event:{data:{egressId:l,egressAsset:p,egressAmount:u,egressFee:m,destinationAddress:w}}}=c.toHuman();n({destinationAddress:w,egressAmount:u,egressAsset:p,egressFee:m,egressId:l})},tx:o})})},k=(e)=>async({evmToolbox:s,stateChainAccount:t,assetValue:r})=>{let{chainflipGateway:i}=await import("@swapkit/helpers/contracts"),n=B.from({asset:"ETH.FLIP"});if(!r.eqAsset(n))throw new d("chainflip_broker_fund_only_flip_supported");if(!e.validateAddress(t))throw new d("chainflip_broker_fund_invalid_address");let o=b(t)?t:S(y(t));return s.call({abi:i,contractAddress:"0x6995ab7c4d7f4b03f467cf4c8e920427d9621dbd",funcName:"fundStateChainAccount",funcParams:[o,r.getBaseValue("string")]})},V=(e)=>({fundStateChainAccount:k(e),registerAsBroker:_(e),withdrawFee:D(e)});import{AssetValue as P,ProviderName as A,SwapKitError as f}from"@swapkit/helpers";import{SwapKitApi as F}from"@swapkit/helpers/api";var M=h({methods:({getWallet:e})=>({swap:async function s(t){if(!(t?.route?.buyAsset&&t.route.meta.chainflip))throw new f("core_swap_invalid_params",{...t});let{route:{buyAsset:r,sellAsset:i,sellAmount:n,destinationAddress:o,meta:{chainflip:a}},maxBoostFeeBps:c=0}=t;if(!(i&&r))throw new f("core_swap_asset_not_recognized");let l=await P.from({asset:i,asyncTokenLookup:!0,value:n}),p=e(l.chain);if(!p)throw new f("core_wallet_connection_not_found");let{depositAddress:u}=await F.getChainflipDepositChannel({...a,destinationAddress:o||a.destinationAddress,maxBoostFeeBps:c||a.maxBoostFeeBps});return await p.transfer({assetValue:l,isProgramDerivedAddress:!0,recipient:u,sender:p.address})}}),name:"chainflip",properties:{supportedSwapkitProviders:[A.CHAINFLIP,A.CHAINFLIP_STREAMING]}});export{I as assetIdentifierToChainflipTicker,M as ChainflipPlugin,V as ChainflipBroker};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=5FB82D923FB7ED6864756E2164756E21
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
"sources": ["../src/chainflip/broker.ts", "../src/chainflip/plugin.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"import { decodeAddress } from \"@polkadot/keyring\";\nimport { isHex, u8aToHex } from \"@polkadot/util\";\nimport { AssetValue, Chain, SwapKitError, wrapWithThrow } from \"@swapkit/helpers\";\nimport type { getEvmToolbox } from \"@swapkit/toolboxes/evm\";\nimport type { getSubstrateToolbox } from \"@swapkit/toolboxes/substrate\";\n\nimport type { WithdrawFeeResponse } from \"./types\";\n\ntype ChainflipToolbox = Awaited<ReturnType<typeof getSubstrateToolbox<Chain.Chainflip>>>;\n\nexport const assetIdentifierToChainflipTicker = new Map<string, string>([\n [\"ARB.ETH\", \"ArbEth\"],\n [\"ARB.USDC-0XAF88D065E77C8CC2239327C5EDB3A432268E5831\", \"ArbUsdc\"],\n [\"BTC.BTC\", \"Btc\"],\n [\"DOT.DOT\", \"Dot\"],\n [\"ETH.ETH\", \"Eth\"],\n [\"ETH.FLIP-0X826180541412D574CF1336D22C0C0A287822678A\", \"Flip\"],\n [\"ETH.USDC-0XA0B86991C6218B36C1D19D4A2E9EB0CE3606EB48\", \"Usdc\"],\n [\"ETH.USDT-0XDAC17F958D2EE523A2206206994597C13D831EC7\", \"Usdt\"],\n [\"SOL.SOL\", \"Sol\"],\n [\"SOL.USDC-EPJFWDD5AUFQSSQEM2QN1XZYBAPC8G4WEGGKZWYTDT1V\", \"SolUsdc\"],\n]);\n\nconst registerAsBroker = (toolbox: ChainflipToolbox) => () => {\n const extrinsic = toolbox.api.tx.swapping?.registerAsBroker?.();\n\n if (!extrinsic) {\n throw new SwapKitError(\"chainflip_broker_register\");\n }\n\n return toolbox.signAndBroadcast({ address: toolbox.getAddress(), tx: extrinsic });\n};\n\nconst withdrawFee =\n (toolbox: ChainflipToolbox) =>\n ({ feeAsset, recipient }: { feeAsset: AssetValue; recipient: string }) => {\n const isFeeChainPolkadot = feeAsset.chain === Chain.Polkadot;\n\n const recipientAddress = wrapWithThrow(() => {\n return isFeeChainPolkadot ? toolbox.encodeAddress(toolbox.decodeAddress(recipient), \"hex\") : recipient;\n }, \"chainflip_broker_recipient_error\");\n\n return new Promise<WithdrawFeeResponse>((resolve) => {\n const extrinsic = toolbox.api.tx?.swapping?.withdraw?.(feeAsset.ticker.toLowerCase(), {\n [feeAsset.chain.toLowerCase()]: recipientAddress,\n });\n\n if (!extrinsic) {\n throw new SwapKitError(\"chainflip_broker_withdraw\");\n }\n\n toolbox.signAndBroadcast({\n callback: (result) => {\n if (!result.status?.isFinalized) {\n return;\n }\n\n const withdrawEvent = result.events.find((event) => event.event.method === \"WithdrawalRequested\");\n\n if (!withdrawEvent) {\n throw new SwapKitError(\"chainflip_channel_error\", \"Could not find 'WithdrawalRequested' event\");\n }\n const {\n event: {\n data: { egressId, egressAsset, egressAmount, egressFee, destinationAddress },\n },\n } = withdrawEvent.toHuman() as any;\n resolve({ destinationAddress, egressAmount, egressAsset, egressFee, egressId });\n },\n tx: extrinsic,\n });\n });\n };\n\nconst fundStateChainAccount =\n (chainflipToolbox: ChainflipToolbox) =>\n async ({\n evmToolbox,\n stateChainAccount,\n assetValue,\n }: {\n evmToolbox: Awaited<ReturnType<typeof getEvmToolbox>>;\n stateChainAccount: string;\n assetValue: AssetValue;\n }) => {\n const { chainflipGateway } = await import(\"@swapkit/helpers/contracts\");\n\n const flipAssetValue = AssetValue.from({ asset: \"ETH.FLIP\" });\n\n if (!assetValue.eqAsset(flipAssetValue)) {\n throw new SwapKitError(\"chainflip_broker_fund_only_flip_supported\");\n }\n\n if (!chainflipToolbox.validateAddress(stateChainAccount)) {\n throw new SwapKitError(\"chainflip_broker_fund_invalid_address\");\n }\n\n const hexAddress = isHex(stateChainAccount) ? stateChainAccount : u8aToHex(decodeAddress(stateChainAccount));\n\n return evmToolbox.call<string>({\n abi: chainflipGateway,\n contractAddress: \"0x6995ab7c4d7f4b03f467cf4c8e920427d9621dbd\",\n funcName: \"fundStateChainAccount\",\n funcParams: [hexAddress, assetValue.getBaseValue(\"string\")],\n });\n };\n\nexport const ChainflipBroker = (chainflipToolbox: ChainflipToolbox) => ({\n fundStateChainAccount: fundStateChainAccount(chainflipToolbox),\n registerAsBroker: registerAsBroker(chainflipToolbox),\n withdrawFee: withdrawFee(chainflipToolbox),\n});\n",
|
|
6
|
-
"import { AssetValue, type CryptoChain, ProviderName, SwapKitError } from \"@swapkit/helpers\";\nimport { SwapKitApi } from \"@swapkit/helpers/api\";\nimport { createPlugin } from \"../utils\";\nimport type { RequestSwapDepositAddressParams } from \"./types\";\n\nexport const ChainflipPlugin = createPlugin({\n methods: ({ getWallet }) => ({\n swap: async function chainflipSwap(swapParams: RequestSwapDepositAddressParams) {\n if (!(swapParams?.route?.buyAsset && swapParams.route.meta.chainflip)) {\n throw new SwapKitError(\"core_swap_invalid_params\", { ...swapParams });\n }\n\n const {\n route: {\n buyAsset: buyAssetString,\n sellAsset: sellAssetString,\n sellAmount,\n destinationAddress: recipient,\n meta: { chainflip },\n },\n maxBoostFeeBps = 0,\n } = swapParams;\n\n if (!(sellAssetString && buyAssetString)) {\n throw new SwapKitError(\"core_swap_asset_not_recognized\");\n }\n\n const sellAsset = await AssetValue.from({ asset: sellAssetString, asyncTokenLookup: true, value: sellAmount });\n\n const wallet = getWallet(sellAsset.chain as CryptoChain);\n\n if (!wallet) {\n throw new SwapKitError(\"core_wallet_connection_not_found\");\n }\n\n const { depositAddress } = await SwapKitApi.getChainflipDepositChannel({\n ...chainflip,\n destinationAddress: recipient || chainflip.destinationAddress,\n maxBoostFeeBps: maxBoostFeeBps || chainflip.maxBoostFeeBps,\n });\n\n
|
|
6
|
+
"import { AssetValue, type Chain, type CryptoChain, ProviderName, SwapKitError } from \"@swapkit/helpers\";\nimport { SwapKitApi } from \"@swapkit/helpers/api\";\nimport { createPlugin } from \"../utils\";\nimport type { RequestSwapDepositAddressParams } from \"./types\";\n\nexport const ChainflipPlugin = createPlugin({\n methods: ({ getWallet }) => ({\n swap: async function chainflipSwap(swapParams: RequestSwapDepositAddressParams) {\n if (!(swapParams?.route?.buyAsset && swapParams.route.meta.chainflip)) {\n throw new SwapKitError(\"core_swap_invalid_params\", { ...swapParams });\n }\n\n const {\n route: {\n buyAsset: buyAssetString,\n sellAsset: sellAssetString,\n sellAmount,\n destinationAddress: recipient,\n meta: { chainflip },\n },\n maxBoostFeeBps = 0,\n } = swapParams;\n\n if (!(sellAssetString && buyAssetString)) {\n throw new SwapKitError(\"core_swap_asset_not_recognized\");\n }\n\n const sellAsset = await AssetValue.from({ asset: sellAssetString, asyncTokenLookup: true, value: sellAmount });\n\n const wallet = getWallet(sellAsset.chain as Exclude<CryptoChain, Chain.Radix>);\n\n if (!wallet) {\n throw new SwapKitError(\"core_wallet_connection_not_found\");\n }\n\n const { depositAddress } = await SwapKitApi.getChainflipDepositChannel({\n ...chainflip,\n destinationAddress: recipient || chainflip.destinationAddress,\n maxBoostFeeBps: maxBoostFeeBps || chainflip.maxBoostFeeBps,\n });\n\n const tx = await wallet.transfer({\n assetValue: sellAsset,\n isProgramDerivedAddress: true,\n recipient: depositAddress,\n sender: wallet.address,\n });\n\n return tx;\n },\n }),\n name: \"chainflip\",\n properties: { supportedSwapkitProviders: [ProviderName.CHAINFLIP, ProviderName.CHAINFLIP_STREAMING] },\n});\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EAAU,EAAU,KAA0C,EAE7E,IAAK,EACH,MAAM,IAAI,EAAa,kCAAkC,EAG3D,IAAQ,kBAAmB,MAAM,EAAW,2BAA2B,IAClE,EACH,mBAAoB,GAAa,EAAU,mBAC3C,eAAgB,GAAkB,EAAU,cAC9C,CAAC,EASD,OAPW,MAAM,EAAO,SAAS,CAC/B,WAAY,EACZ,wBAAyB,GACzB,UAAW,EACX,OAAQ,EAAO,OACjB,CAAC,EAIL,GACA,KAAM,YACN,WAAY,CAAE,0BAA2B,CAAC,EAAa,UAAW,EAAa,mBAAmB,CAAE,CACtG,CAAC",
|
|
9
|
+
"debugId": "5FB82D923FB7ED6864756E2164756E21",
|
|
10
10
|
"names": []
|
|
11
11
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/chainflip/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/chainflip/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,YAAY,EAAgB,MAAM,kBAAkB,CAAC;AAGxG,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE/D,eAAO,MAAM,eAAe;;;;2BAEuB,+BAA+B;;CA8ChF,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"@polkadot/keyring": "~13.5.0",
|
|
5
5
|
"@polkadot/util": "~13.5.0",
|
|
6
6
|
"@solana/web3.js": "~1.98.0",
|
|
7
|
-
"@swapkit/helpers": "4.0.
|
|
8
|
-
"@swapkit/toolboxes": "4.0.
|
|
7
|
+
"@swapkit/helpers": "4.0.9",
|
|
8
|
+
"@swapkit/toolboxes": "4.0.9",
|
|
9
9
|
"ts-pattern": "~5.8.0"
|
|
10
10
|
},
|
|
11
11
|
"description": "SwapKit Plugin - Chainflip",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"type-check:go": "tsgo"
|
|
62
62
|
},
|
|
63
63
|
"type": "module",
|
|
64
|
-
"version": "4.0.
|
|
64
|
+
"version": "4.0.10"
|
|
65
65
|
}
|