@swapkit/core 4.5.0 → 4.6.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # @swapkit/core
2
2
 
3
+ ## 4.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#332](https://github.com/swapkit/sdk/pull/332) [`d099d5f`](https://github.com/swapkit/sdk/commit/d099d5f95289e25a053cb0575f464c18419eebf0) Thanks [@towanTG](https://github.com/towanTG)! - `approveAssetValue` and `isAssetValueApproved` take **either the route or an explicit assetValue + spender/plugin address** — a route carries everything: the approval subject (a Stellar trustline belongs to the buy asset; an EVM allowance covers `sellAsset`/`sellAmount`), the spender (`meta.approvalAddress`), and the plugin (resolved the same way `swap()` resolves it: swapkit-routed providers and direct-signing wallets go to the swapkit plugin, everything else by the route's provider).
8
+
9
+ ```ts
10
+ // POST /swap returned 200 with approvalTx { txType: "STELLAR", tx } and no tx:
11
+ const approved = await swapKit.isAssetValueApproved(route); // hasTrustline on the buy asset
12
+ if (!approved) {
13
+ await swapKit.approveAssetValue(route); // receiving wallet signs route.approvalTx.tx
14
+ }
15
+
16
+ const refreshedRoute = await SwapKitApi.getRouteWithTx({
17
+ routeId,
18
+ sourceAddress,
19
+ destinationAddress,
20
+ }); // re-POST /swap
21
+ await swapKit.swap({ route: refreshedRoute });
22
+ ```
23
+
24
+ The explicit form is unchanged: `approveAssetValue(assetValue, spenderOrPluginName)`. EVM allowance behavior is untouched.
25
+
26
+ ## 4.5.1
27
+
28
+ ### Patch Changes
29
+
30
+ - [#331](https://github.com/swapkit/sdk/pull/331) [`f740a74`](https://github.com/swapkit/sdk/commit/f740a742a0cf879b4e56bb73647d21642bc22e9d) Thanks [@towanTG](https://github.com/towanTG)! - Add client-side support for the Stellar trustline approval flow: swap response types model the `approvalTx` union (EVM | Stellar changeTrust XDR) and `nextActions`, `approveAssetValue`/`isAssetValueApproved` switch between EVM allowances and Stellar trustlines (checking via the new Stellar toolbox `hasTrustline({ address, assetValue })`, approving by signing the API-provided changeTrust XDR with the destination wallet). The swap method itself is unchanged — integrators approve first, re-fetch the route, then swap. (via @swapkit/helpers@4.19.0)
31
+ - Update generated token lists. (via @swapkit/helpers@4.19.0)
32
+ - [#329](https://github.com/swapkit/sdk/pull/329) [`55d9edc`](https://github.com/swapkit/sdk/commit/55d9edcc603e0139588c905e41a59eaaa3275cda) Thanks [@towanTG](https://github.com/towanTG)! - Update NEAR provider token list: add Stellar assets (XLM.XLM, XLM.USDC) and latest NEAR-intents listings (SWEAT, GMX, KAITO, AAVE, LINK, UNI, and more); remove BTC.BTC(OMNI) (via @swapkit/helpers@4.19.0)
33
+
3
34
  ## 4.5.0
4
35
 
5
36
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- var{defineProperty:B,getOwnPropertyNames:K,getOwnPropertyDescriptor:t}=Object,M=Object.prototype.hasOwnProperty;function b(J){return this[J]}var k=(J,L,I)=>{var U=K(L);for(let $ of U)if(!M.call(J,$)&&$!=="default")B(J,$,{get:b.bind(L,$),enumerable:!0});if(I){for(let $ of U)if(!M.call(I,$)&&$!=="default")B(I,$,{get:b.bind(L,$),enumerable:!0});return I}};var l=(J)=>{var L=(C??=new WeakMap).get(J),I;if(L)return L;if(L=B({},"__esModule",{value:!0}),J&&typeof J==="object"||typeof J==="function"){for(var U of K(J))if(!M.call(L,U))B(L,U,{get:b.bind(J,U),enumerable:!(I=t(J,U))||I.enumerable})}return C.set(J,L),L},C;var a=(J)=>J;function e(J,L){this[J]=a.bind(null,L)}var jj=(J,L)=>{for(var I in L)B(J,I,{get:L[I],enumerable:!0,configurable:!0,set:e.bind(L,I)})};var F={};jj(F,{SwapKit:()=>zj});module.exports=l(F);var q=require("@swapkit/helpers"),y=require("@swapkit/helpers/api");k(F,require("@swapkit/helpers"),module.exports);var qj=[q.ProviderName.FLASHNET,q.ProviderName.MAYAN];function zj({config:J,plugins:L,wallets:I}={}){if(J)q.SKConfig.set(J);let U={},$=Object.entries(L||{}).reduce((j,[G,z])=>{let H=z({getWallet:Q});return j[G]=H,j},{}),E=Object.entries(I||{}).reduce((j,[G,z])=>{let H=z.connectWallet({addChain:A});return j[G]=H,j},{});function T(j){let G=j&&$[j],z=Object.values($).find((Z)=>Z.supportedSwapkitProviders?.includes(j)),H=G||z;if(!H)throw new q.SwapKitError("core_plugin_not_found");return H}function A(j){let G=Q(j.chain),z=j?.balance||G?.balance||[q.AssetValue.from({chain:j.chain})],H={...G,...j,balance:z};return U[j.chain]=H,H}function P({assetValue:j,type:G="checkOnly",contractAddress:z}){let H=$[z];if(H){if(G===q.ApproveMode.CheckOnly&&"isAssetValueApproved"in H)return H.isAssetValueApproved({assetValue:j});if(G===q.ApproveMode.Approve&&"approveAssetValue"in H)return H.approveAssetValue({assetValue:j});throw new q.SwapKitError({errorKey:"core_approve_asset_target_invalid",info:{message:`Target ${String(z)} cannot be used for approve operation`}})}let Z=j.chain,X=q.EVMChains.includes(Z);if(X&&j.isGasAsset||!X||j.isSynthetic)return Promise.resolve(G==="checkOnly"?!0:"approved");let R=Q(Z),Y=G==="checkOnly"?R.isApproved:R.approve;if(!Y)throw new q.SwapKitError("core_wallet_connection_not_found");if(!(j.address&&R.address&&typeof z==="string"))throw new q.SwapKitError("core_approve_asset_address_or_from_not_found");return Y({amount:j.getBaseValue("bigint"),assetAddress:j.address,from:R.address,spenderAddress:z})}function Q(j){return U[j]}function V(){return{...U}}function W(j){return Q(j)?.address||""}function m(j,G){return P({assetValue:j,contractAddress:G,type:q.ApproveMode.Approve})}function w(j,G){return P({assetValue:j,contractAddress:G,type:q.ApproveMode.CheckOnly})}function f(j){Q(j)?.disconnect?.(),delete U[j]}function h(){for(let j of Object.keys(U))f(j)}function g(j,G){return G?N(j).then(({balance:z})=>z):Q(j)?.balance||[]}async function N(j,G=!0){let z=Q(j);if(!z)throw new q.SwapKitError("core_wallet_connection_not_found");let H=await z.getBalance?.(z.address,G);return z.balance=H||[q.AssetValue.from({chain:j})],z}function d({route:j,pluginName:G,...z}){let H=q.AssetValue.from({asset:j.sellAsset}).chain,Z=Q(H);if(!Z)throw new q.SwapKitError("core_wallet_connection_not_found");let X=j.providers.some((Y)=>qj.includes(Y));if(Z.supportsDirectSigning&&j.tx||X){let Y=T("swapkit");if("swap"in Y)return Y.swap({...z,route:j})}let R=T(G||j.providers[0]);if("swap"in R)return R.swap({...z,route:j});throw new q.SwapKitError("core_plugin_swap_not_found")}function u({assetValue:j,...G}){let z=j.chain;if([q.Chain.Radix].includes(z)||!Q(z))throw new q.SwapKitError("core_wallet_connection_not_found");return Q(z).transfer({...G,assetValue:j})}function o({chain:j,message:G}){let z=Q(j);if(!z)throw new q.SwapKitError("core_wallet_connection_not_found");if("signMessage"in z)return z.signMessage?.(G);throw new q.SwapKitError({errorKey:"core_wallet_sign_message_not_supported",info:{chain:j,wallet:z.walletType}})}function p({chain:j,domain:G,primaryType:z,types:H,value:Z}){let X=Q(j);if(!X)throw new q.SwapKitError("core_wallet_connection_not_found");if("signTypedData"in X&&typeof X.signTypedData==="function")return X.signTypedData({domain:G,primaryType:z,types:H,value:Z});throw new q.SwapKitError({errorKey:"core_wallet_sign_typed_data_not_supported",info:{chain:j,wallet:X.walletType}})}async function c({address:j,chain:G,message:z,signature:H}){if(G!==q.Chain.THORChain)throw new q.SwapKitError({errorKey:"core_verify_message_not_supported",info:{chain:G}});let{getCosmosToolbox:Z}=await import("@swapkit/toolboxes/cosmos");return Z(G).verifySignature({address:j,message:z,signature:H})}async function r({type:j,feeOptionKey:G,params:z}){let{assetValue:H}=z,{chain:Z}=H;if(!Q(Z))throw new q.SwapKitError("core_wallet_connection_not_found");let X=q.AssetValue.from({chain:Z}),{match:O}=await import("ts-pattern");return await O(Z).returnType().with(...q.EVMChains,(Y)=>{let{address:_,...D}=Q(Y),S=O(j).with("transfer",()=>D.createTransferTx(z)).with("approve",(n)=>{let{contractAddress:x}=z;return D.createApprovalTx({amount:H.getBaseValue("bigint"),assetAddress:H.address,from:_,spenderAddress:x})}).with("swap",(n)=>{let{route:{providers:[x],tx:s}}=z;if(x&&[q.ProviderName.CHAINFLIP,q.ProviderName.CHAINFLIP_STREAMING].includes(x))return D.createTransferTx({assetValue:H,recipient:_,sender:_});let v=s;return{...v,value:y.parseTransactionValue(v.value)}}).otherwise(()=>{return});if(!S)return X;return D.estimateTransactionFee({...S,feeOption:G})}).with(...q.CosmosChains,async()=>{let{estimateTransactionFee:Y}=await import("@swapkit/toolboxes/cosmos");return Y(z)}).with(...q.UTXOChains,(Y)=>{let{address:_,...D}=Q(Y);return D.estimateTransactionFee({...z,feeOptionKey:G,recipient:_,sender:_})}).with(q.Chain.Tron,q.Chain.Ton,q.Chain.Polkadot,(Y)=>{let{address:_,...D}=Q(Y);return D.estimateTransactionFee({...z,recipient:_,sender:_})}).with(q.Chain.Aptos,q.Chain.Cardano,q.Chain.Ripple,q.Chain.Stellar,q.Chain.Sui,(Y)=>Q(Y).estimateTransactionFee()).otherwise(()=>X)}async function i({address:j,chain:G}){try{let{getAddressValidator:z}=await import("@swapkit/toolboxes");return(await z())({address:j,chain:G})}catch{return!1}}return{...$,...E,approveAssetValue:m,disconnectAll:h,disconnectChain:f,estimateTransactionFee:r,getAddress:W,getAllWallets:V,getBalance:g,getWallet:Q,getWalletWithBalance:N,isAssetValueApproved:w,signMessage:o,signTypedData:p,swap:d,transfer:u,validateAddress:i,verifyMessage:c}}
1
+ var{defineProperty:O,getOwnPropertyNames:E,getOwnPropertyDescriptor:jj}=Object,x=Object.prototype.hasOwnProperty;function P(J){return this[J]}var B=(J,L,$)=>{var I=E(L);for(let X of I)if(!x.call(J,X)&&X!=="default")O(J,X,{get:P.bind(L,X),enumerable:!0});if($){for(let X of I)if(!x.call($,X)&&X!=="default")O($,X,{get:P.bind(L,X),enumerable:!0});return $}};var qj=(J)=>{var L=(S??=new WeakMap).get(J),$;if(L)return L;if(L=O({},"__esModule",{value:!0}),J&&typeof J==="object"||typeof J==="function"){for(var I of E(J))if(!x.call(L,I))O(L,I,{get:P.bind(J,I),enumerable:!($=jj(J,I))||$.enumerable})}return S.set(J,L),L},S;var zj=(J)=>J;function Gj(J,L){this[J]=zj.bind(null,L)}var Hj=(J,L)=>{for(var $ in L)O(J,$,{get:L[$],enumerable:!0,configurable:!0,set:Gj.bind(L,$)})};var k={};Hj(k,{resolveRoutePluginName:()=>v,getRouteApprovalAssetValue:()=>V,SwapKit:()=>Lj});module.exports=qj(k);var q=require("@swapkit/helpers"),y=require("@swapkit/helpers/api");B(k,require("@swapkit/helpers"),module.exports);var Jj=[q.ProviderName.FLASHNET,q.ProviderName.MAYAN];function v({pluginName:J,providers:L,useDirectSigning:$}){return L.some((X)=>Jj.includes(X))||$?"swapkit":J||L[0]}function V(J){let L="approvalTx"in J?J.approvalTx:void 0;return L!==void 0&&"txType"in L&&L.txType==="STELLAR"?q.AssetValue.from({asset:J.buyAsset}):q.AssetValue.from({asset:J.sellAsset,value:J.sellAmount})}function Lj({config:J,plugins:L,wallets:$}={}){if(J)q.SKConfig.set(J);let I={},X=Object.entries(L||{}).reduce((j,[G,z])=>{let H=z({getWallet:Y});return j[G]=H,j},{}),W=Object.entries($||{}).reduce((j,[G,z])=>{let H=z.connectWallet({addChain:w});return j[G]=H,j},{});function A(j){let G=j&&X[j],z=Object.values(X).find((Q)=>Q.supportedSwapkitProviders?.includes(j)),H=G||z;if(!H)throw new q.SwapKitError("core_plugin_not_found");return H}function w(j){let G=Y(j.chain),z=j?.balance||G?.balance||[q.AssetValue.from({chain:j.chain})],H={...G,...j,balance:z};return I[j.chain]=H,H}function T({pluginName:j,route:G,useDirectSigning:z}){return A(v({pluginName:j,providers:G.providers,useDirectSigning:z}))}function m({assetValue:j,plugin:G,route:z,spenderAddress:H,type:Q}){if(Q===q.ApproveMode.CheckOnly&&"isAssetValueApproved"in G)return G.isAssetValueApproved({assetValue:j,route:z,spenderAddress:H});if(Q===q.ApproveMode.Approve&&"approveAssetValue"in G)return G.approveAssetValue({assetValue:j,route:z,spenderAddress:H});throw new q.SwapKitError({errorKey:"core_approve_asset_target_invalid",info:{message:`Target ${String(H??z?.providers[0])} cannot be used for approve operation`}})}function b({assetValue:j,type:G="checkOnly",contractAddress:z,route:H}){let Q=j??(H?V(H):void 0);if(!Q)throw new q.SwapKitError("core_approve_asset_target_invalid");let Z=z??H?.meta.approvalAddress,R=H?T({route:H,useDirectSigning:Boolean(Y(Q.chain)?.supportsDirectSigning)}):Z&&X[Z];if(R)return m({assetValue:Q,plugin:R,route:H,spenderAddress:Z,type:G});let f=Q.chain,_=q.EVMChains.includes(f);if(_&&Q.isGasAsset||!_||Q.isSynthetic)return Promise.resolve(G==="checkOnly"?!0:"approved");let U=Y(f),D=G==="checkOnly"?U.isApproved:U.approve;if(!D)throw new q.SwapKitError("core_wallet_connection_not_found");if(!(Q.address&&U.address&&typeof Z==="string"))throw new q.SwapKitError("core_approve_asset_address_or_from_not_found");return D({amount:Q.getBaseValue("bigint"),assetAddress:Q.address,from:U.address,spenderAddress:Z})}function Y(j){return I[j]}function h(){return{...I}}function d(j){return Y(j)?.address||""}function g(j,G){return j instanceof q.AssetValue?b({assetValue:j,contractAddress:G,type:q.ApproveMode.Approve}):b({route:j,type:q.ApproveMode.Approve})}function u(j,G){return j instanceof q.AssetValue?b({assetValue:j,contractAddress:G,type:q.ApproveMode.CheckOnly}):b({route:j,type:q.ApproveMode.CheckOnly})}function K(j){Y(j)?.disconnect?.(),delete I[j]}function c(){for(let j of Object.keys(I))K(j)}function o(j,G){return G?N(j).then(({balance:z})=>z):Y(j)?.balance||[]}async function N(j,G=!0){let z=Y(j);if(!z)throw new q.SwapKitError("core_wallet_connection_not_found");let H=await z.getBalance?.(z.address,G);return z.balance=H||[q.AssetValue.from({chain:j})],z}function p({route:j,pluginName:G,...z}){let H=q.AssetValue.from({asset:j.sellAsset}).chain,Q=Y(H);if(!Q)throw new q.SwapKitError("core_wallet_connection_not_found");let Z=T({pluginName:G,route:j,useDirectSigning:Boolean(Q.supportsDirectSigning&&j.tx)});if("swap"in Z)return Z.swap({...z,route:j});throw new q.SwapKitError("core_plugin_swap_not_found")}function i({assetValue:j,...G}){let z=j.chain;if([q.Chain.Radix].includes(z)||!Y(z))throw new q.SwapKitError("core_wallet_connection_not_found");return Y(z).transfer({...G,assetValue:j})}function n({chain:j,message:G}){let z=Y(j);if(!z)throw new q.SwapKitError("core_wallet_connection_not_found");if("signMessage"in z)return z.signMessage?.(G);throw new q.SwapKitError({errorKey:"core_wallet_sign_message_not_supported",info:{chain:j,wallet:z.walletType}})}function r({chain:j,domain:G,primaryType:z,types:H,value:Q}){let Z=Y(j);if(!Z)throw new q.SwapKitError("core_wallet_connection_not_found");if("signTypedData"in Z&&typeof Z.signTypedData==="function")return Z.signTypedData({domain:G,primaryType:z,types:H,value:Q});throw new q.SwapKitError({errorKey:"core_wallet_sign_typed_data_not_supported",info:{chain:j,wallet:Z.walletType}})}async function s({address:j,chain:G,message:z,signature:H}){if(G!==q.Chain.THORChain)throw new q.SwapKitError({errorKey:"core_verify_message_not_supported",info:{chain:G}});let{getCosmosToolbox:Q}=await import("@swapkit/toolboxes/cosmos");return Q(G).verifySignature({address:j,message:z,signature:H})}async function l({type:j,feeOptionKey:G,params:z}){let{assetValue:H}=z,{chain:Q}=H;if(!Y(Q))throw new q.SwapKitError("core_wallet_connection_not_found");let Z=q.AssetValue.from({chain:Q}),{match:R}=await import("ts-pattern");return await R(Q).returnType().with(...q.EVMChains,(_)=>{let{address:F,...U}=Y(_),D=R(j).with("transfer",()=>U.createTransferTx(z)).with("approve",(a)=>{let{contractAddress:M}=z;return U.createApprovalTx({amount:H.getBaseValue("bigint"),assetAddress:H.address,from:F,spenderAddress:M})}).with("swap",(a)=>{let{route:{providers:[M],tx:e}}=z;if(M&&[q.ProviderName.CHAINFLIP,q.ProviderName.CHAINFLIP_STREAMING].includes(M))return U.createTransferTx({assetValue:H,recipient:F,sender:F});let C=e;return{...C,value:y.parseTransactionValue(C.value)}}).otherwise(()=>{return});if(!D)return Z;return U.estimateTransactionFee({...D,feeOption:G})}).with(...q.CosmosChains,async()=>{let{estimateTransactionFee:_}=await import("@swapkit/toolboxes/cosmos");return _(z)}).with(...q.UTXOChains,(_)=>{let{address:F,...U}=Y(_);return U.estimateTransactionFee({...z,feeOptionKey:G,recipient:F,sender:F})}).with(q.Chain.Tron,q.Chain.Ton,q.Chain.Polkadot,(_)=>{let{address:F,...U}=Y(_);return U.estimateTransactionFee({...z,recipient:F,sender:F})}).with(q.Chain.Aptos,q.Chain.Cardano,q.Chain.Ripple,q.Chain.Stellar,q.Chain.Sui,(_)=>Y(_).estimateTransactionFee()).otherwise(()=>Z)}async function t({address:j,chain:G}){try{let{getAddressValidator:z}=await import("@swapkit/toolboxes");return(await z())({address:j,chain:G})}catch{return!1}}return{...X,...W,approveAssetValue:g,disconnectAll:c,disconnectChain:K,estimateTransactionFee:l,getAddress:d,getAllWallets:h,getBalance:o,getWallet:Y,getWalletWithBalance:N,isAssetValueApproved:u,signMessage:n,signTypedData:r,swap:p,transfer:i,validateAddress:t,verifyMessage:s}}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- var k=((U)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(U,{get:(M,b)=>(typeof require<"u"?require:M)[b]}):U)(function(U){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+U+'" is not supported')});import{ApproveMode as B,AssetValue as O,Chain as Z,CosmosChains as n,EVMChains as C,ProviderName as x,SKConfig as s,SwapKitError as Y,UTXOChains as t}from"@swapkit/helpers";import{parseTransactionValue as l}from"@swapkit/helpers/api";export*from"@swapkit/helpers";var a=[x.FLASHNET,x.MAYAN];function zj({config:U,plugins:M,wallets:b}={}){if(U)s.set(U);let _={},R=Object.entries(M||{}).reduce((j,[z,q])=>{let G=q({getWallet:H});return j[z]=G,j},{}),K=Object.entries(b||{}).reduce((j,[z,q])=>{let G=q.connectWallet({addChain:y});return j[z]=G,j},{});function T(j){let z=j&&R[j],q=Object.values(R).find((L)=>L.supportedSwapkitProviders?.includes(j)),G=z||q;if(!G)throw new Y("core_plugin_not_found");return G}function y(j){let z=H(j.chain),q=j?.balance||z?.balance||[O.from({chain:j.chain})],G={...z,...j,balance:q};return _[j.chain]=G,G}function P({assetValue:j,type:z="checkOnly",contractAddress:q}){let G=R[q];if(G){if(z===B.CheckOnly&&"isAssetValueApproved"in G)return G.isAssetValueApproved({assetValue:j});if(z===B.Approve&&"approveAssetValue"in G)return G.approveAssetValue({assetValue:j});throw new Y({errorKey:"core_approve_asset_target_invalid",info:{message:`Target ${String(q)} cannot be used for approve operation`}})}let L=j.chain,Q=C.includes(L);if(Q&&j.isGasAsset||!Q||j.isSynthetic)return Promise.resolve(z==="checkOnly"?!0:"approved");let X=H(L),J=z==="checkOnly"?X.isApproved:X.approve;if(!J)throw new Y("core_wallet_connection_not_found");if(!(j.address&&X.address&&typeof q==="string"))throw new Y("core_approve_asset_address_or_from_not_found");return J({amount:j.getBaseValue("bigint"),assetAddress:j.address,from:X.address,spenderAddress:q})}function H(j){return _[j]}function E(){return{..._}}function A(j){return H(j)?.address||""}function V(j,z){return P({assetValue:j,contractAddress:z,type:B.Approve})}function W(j,z){return P({assetValue:j,contractAddress:z,type:B.CheckOnly})}function f(j){H(j)?.disconnect?.(),delete _[j]}function m(){for(let j of Object.keys(_))f(j)}function w(j,z){return z?N(j).then(({balance:q})=>q):H(j)?.balance||[]}async function N(j,z=!0){let q=H(j);if(!q)throw new Y("core_wallet_connection_not_found");let G=await q.getBalance?.(q.address,z);return q.balance=G||[O.from({chain:j})],q}function h({route:j,pluginName:z,...q}){let G=O.from({asset:j.sellAsset}).chain,L=H(G);if(!L)throw new Y("core_wallet_connection_not_found");let Q=j.providers.some((J)=>a.includes(J));if(L.supportsDirectSigning&&j.tx||Q){let J=T("swapkit");if("swap"in J)return J.swap({...q,route:j})}let X=T(z||j.providers[0]);if("swap"in X)return X.swap({...q,route:j});throw new Y("core_plugin_swap_not_found")}function g({assetValue:j,...z}){let q=j.chain;if([Z.Radix].includes(q)||!H(q))throw new Y("core_wallet_connection_not_found");return H(q).transfer({...z,assetValue:j})}function d({chain:j,message:z}){let q=H(j);if(!q)throw new Y("core_wallet_connection_not_found");if("signMessage"in q)return q.signMessage?.(z);throw new Y({errorKey:"core_wallet_sign_message_not_supported",info:{chain:j,wallet:q.walletType}})}function u({chain:j,domain:z,primaryType:q,types:G,value:L}){let Q=H(j);if(!Q)throw new Y("core_wallet_connection_not_found");if("signTypedData"in Q&&typeof Q.signTypedData==="function")return Q.signTypedData({domain:z,primaryType:q,types:G,value:L});throw new Y({errorKey:"core_wallet_sign_typed_data_not_supported",info:{chain:j,wallet:Q.walletType}})}async function o({address:j,chain:z,message:q,signature:G}){if(z!==Z.THORChain)throw new Y({errorKey:"core_verify_message_not_supported",info:{chain:z}});let{getCosmosToolbox:L}=await import("@swapkit/toolboxes/cosmos");return L(z).verifySignature({address:j,message:q,signature:G})}async function p({type:j,feeOptionKey:z,params:q}){let{assetValue:G}=q,{chain:L}=G;if(!H(L))throw new Y("core_wallet_connection_not_found");let Q=O.from({chain:L}),{match:D}=await import("ts-pattern");return await D(L).returnType().with(...C,(J)=>{let{address:$,...I}=H(J),S=D(j).with("transfer",()=>I.createTransferTx(q)).with("approve",(r)=>{let{contractAddress:F}=q;return I.createApprovalTx({amount:G.getBaseValue("bigint"),assetAddress:G.address,from:$,spenderAddress:F})}).with("swap",(r)=>{let{route:{providers:[F],tx:i}}=q;if(F&&[x.CHAINFLIP,x.CHAINFLIP_STREAMING].includes(F))return I.createTransferTx({assetValue:G,recipient:$,sender:$});let v=i;return{...v,value:l(v.value)}}).otherwise(()=>{return});if(!S)return Q;return I.estimateTransactionFee({...S,feeOption:z})}).with(...n,async()=>{let{estimateTransactionFee:J}=await import("@swapkit/toolboxes/cosmos");return J(q)}).with(...t,(J)=>{let{address:$,...I}=H(J);return I.estimateTransactionFee({...q,feeOptionKey:z,recipient:$,sender:$})}).with(Z.Tron,Z.Ton,Z.Polkadot,(J)=>{let{address:$,...I}=H(J);return I.estimateTransactionFee({...q,recipient:$,sender:$})}).with(Z.Aptos,Z.Cardano,Z.Ripple,Z.Stellar,Z.Sui,(J)=>H(J).estimateTransactionFee()).otherwise(()=>Q)}async function c({address:j,chain:z}){try{let{getAddressValidator:q}=await import("@swapkit/toolboxes");return(await q())({address:j,chain:z})}catch{return!1}}return{...R,...K,approveAssetValue:V,disconnectAll:m,disconnectChain:f,estimateTransactionFee:p,getAddress:A,getAllWallets:E,getBalance:w,getWallet:H,getWalletWithBalance:N,isAssetValueApproved:W,signMessage:d,signTypedData:u,swap:h,transfer:g,validateAddress:c,verifyMessage:o}}export{zj as SwapKit};
1
+ var f=((Q)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(Q,{get:(X,F)=>(typeof require<"u"?require:X)[F]}):Q)(function(Q){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+Q+'" is not supported')});import{ApproveMode as R,AssetValue as _,Chain as U,CosmosChains as l,EVMChains as S,ProviderName as x,SKConfig as t,SwapKitError as Y,UTXOChains as a}from"@swapkit/helpers";import{parseTransactionValue as e}from"@swapkit/helpers/api";export*from"@swapkit/helpers";var jj=[x.FLASHNET,x.MAYAN];function qj({pluginName:Q,providers:X,useDirectSigning:F}){return X.some((B)=>jj.includes(B))||F?"swapkit":Q||X[0]}function zj(Q){let X="approvalTx"in Q?Q.approvalTx:void 0;return X!==void 0&&"txType"in X&&X.txType==="STELLAR"?_.from({asset:Q.buyAsset}):_.from({asset:Q.sellAsset,value:Q.sellAmount})}function Lj({config:Q,plugins:X,wallets:F}={}){if(Q)t.set(Q);let k={},B=Object.entries(X||{}).reduce((j,[z,q])=>{let G=q({getWallet:J});return j[z]=G,j},{}),E=Object.entries(F||{}).reduce((j,[z,q])=>{let G=q.connectWallet({addChain:v});return j[z]=G,j},{});function y(j){let z=j&&B[j],q=Object.values(B).find((H)=>H.supportedSwapkitProviders?.includes(j)),G=z||q;if(!G)throw new Y("core_plugin_not_found");return G}function v(j){let z=J(j.chain),q=j?.balance||z?.balance||[_.from({chain:j.chain})],G={...z,...j,balance:q};return k[j.chain]=G,G}function T({pluginName:j,route:z,useDirectSigning:q}){return y(qj({pluginName:j,providers:z.providers,useDirectSigning:q}))}function V({assetValue:j,plugin:z,route:q,spenderAddress:G,type:H}){if(H===R.CheckOnly&&"isAssetValueApproved"in z)return z.isAssetValueApproved({assetValue:j,route:q,spenderAddress:G});if(H===R.Approve&&"approveAssetValue"in z)return z.approveAssetValue({assetValue:j,route:q,spenderAddress:G});throw new Y({errorKey:"core_approve_asset_target_invalid",info:{message:`Target ${String(G??q?.providers[0])} cannot be used for approve operation`}})}function b({assetValue:j,type:z="checkOnly",contractAddress:q,route:G}){let H=j??(G?zj(G):void 0);if(!H)throw new Y("core_approve_asset_target_invalid");let L=q??G?.meta.approvalAddress,D=G?T({route:G,useDirectSigning:Boolean(J(H.chain)?.supportsDirectSigning)}):L&&B[L];if(D)return V({assetValue:H,plugin:D,route:G,spenderAddress:L,type:z});let P=H.chain,$=S.includes(P);if($&&H.isGasAsset||!$||H.isSynthetic)return Promise.resolve(z==="checkOnly"?!0:"approved");let Z=J(P),O=z==="checkOnly"?Z.isApproved:Z.approve;if(!O)throw new Y("core_wallet_connection_not_found");if(!(H.address&&Z.address&&typeof L==="string"))throw new Y("core_approve_asset_address_or_from_not_found");return O({amount:H.getBaseValue("bigint"),assetAddress:H.address,from:Z.address,spenderAddress:L})}function J(j){return k[j]}function W(){return{...k}}function A(j){return J(j)?.address||""}function w(j,z){return j instanceof _?b({assetValue:j,contractAddress:z,type:R.Approve}):b({route:j,type:R.Approve})}function m(j,z){return j instanceof _?b({assetValue:j,contractAddress:z,type:R.CheckOnly}):b({route:j,type:R.CheckOnly})}function K(j){J(j)?.disconnect?.(),delete k[j]}function h(){for(let j of Object.keys(k))K(j)}function d(j,z){return z?N(j).then(({balance:q})=>q):J(j)?.balance||[]}async function N(j,z=!0){let q=J(j);if(!q)throw new Y("core_wallet_connection_not_found");let G=await q.getBalance?.(q.address,z);return q.balance=G||[_.from({chain:j})],q}function g({route:j,pluginName:z,...q}){let G=_.from({asset:j.sellAsset}).chain,H=J(G);if(!H)throw new Y("core_wallet_connection_not_found");let L=T({pluginName:z,route:j,useDirectSigning:Boolean(H.supportsDirectSigning&&j.tx)});if("swap"in L)return L.swap({...q,route:j});throw new Y("core_plugin_swap_not_found")}function u({assetValue:j,...z}){let q=j.chain;if([U.Radix].includes(q)||!J(q))throw new Y("core_wallet_connection_not_found");return J(q).transfer({...z,assetValue:j})}function c({chain:j,message:z}){let q=J(j);if(!q)throw new Y("core_wallet_connection_not_found");if("signMessage"in q)return q.signMessage?.(z);throw new Y({errorKey:"core_wallet_sign_message_not_supported",info:{chain:j,wallet:q.walletType}})}function o({chain:j,domain:z,primaryType:q,types:G,value:H}){let L=J(j);if(!L)throw new Y("core_wallet_connection_not_found");if("signTypedData"in L&&typeof L.signTypedData==="function")return L.signTypedData({domain:z,primaryType:q,types:G,value:H});throw new Y({errorKey:"core_wallet_sign_typed_data_not_supported",info:{chain:j,wallet:L.walletType}})}async function p({address:j,chain:z,message:q,signature:G}){if(z!==U.THORChain)throw new Y({errorKey:"core_verify_message_not_supported",info:{chain:z}});let{getCosmosToolbox:H}=await import("@swapkit/toolboxes/cosmos");return H(z).verifySignature({address:j,message:q,signature:G})}async function i({type:j,feeOptionKey:z,params:q}){let{assetValue:G}=q,{chain:H}=G;if(!J(H))throw new Y("core_wallet_connection_not_found");let L=_.from({chain:H}),{match:D}=await import("ts-pattern");return await D(H).returnType().with(...S,($)=>{let{address:I,...Z}=J($),O=D(j).with("transfer",()=>Z.createTransferTx(q)).with("approve",(r)=>{let{contractAddress:M}=q;return Z.createApprovalTx({amount:G.getBaseValue("bigint"),assetAddress:G.address,from:I,spenderAddress:M})}).with("swap",(r)=>{let{route:{providers:[M],tx:s}}=q;if(M&&[x.CHAINFLIP,x.CHAINFLIP_STREAMING].includes(M))return Z.createTransferTx({assetValue:G,recipient:I,sender:I});let C=s;return{...C,value:e(C.value)}}).otherwise(()=>{return});if(!O)return L;return Z.estimateTransactionFee({...O,feeOption:z})}).with(...l,async()=>{let{estimateTransactionFee:$}=await import("@swapkit/toolboxes/cosmos");return $(q)}).with(...a,($)=>{let{address:I,...Z}=J($);return Z.estimateTransactionFee({...q,feeOptionKey:z,recipient:I,sender:I})}).with(U.Tron,U.Ton,U.Polkadot,($)=>{let{address:I,...Z}=J($);return Z.estimateTransactionFee({...q,recipient:I,sender:I})}).with(U.Aptos,U.Cardano,U.Ripple,U.Stellar,U.Sui,($)=>J($).estimateTransactionFee()).otherwise(()=>L)}async function n({address:j,chain:z}){try{let{getAddressValidator:q}=await import("@swapkit/toolboxes");return(await q())({address:j,chain:z})}catch{return!1}}return{...B,...E,approveAssetValue:w,disconnectAll:h,disconnectChain:K,estimateTransactionFee:i,getAddress:A,getAllWallets:W,getBalance:d,getWallet:J,getWalletWithBalance:N,isAssetValueApproved:m,signMessage:c,signTypedData:o,swap:g,transfer:u,validateAddress:n,verifyMessage:p}}export{qj as resolveRoutePluginName,zj as getRouteApprovalAssetValue,Lj as SwapKit};
@@ -1,4 +1,4 @@
1
- import { AssetValue, Chain, type ChainWallet, type ConditionalAssetValueReturn, type FeeOption, type GenericTransferParams, type SKConfigState, type SwapParams } from "@swapkit/helpers";
1
+ import { AssetValue, Chain, type ChainWallet, type ConditionalAssetValueReturn, type FeeOption, type GenericTransferParams, ProviderName as PluginNameEnum, type SKConfigState, type SwapParams } from "@swapkit/helpers";
2
2
  import { type QuoteResponseRoute, type SwapRouteV2Response } from "@swapkit/helpers/api";
3
3
  import type { createPlugin } from "@swapkit/plugins";
4
4
  import type { FullWallet } from "@swapkit/toolboxes";
@@ -10,12 +10,18 @@ export type SwapKitParams<P, W> = {
10
10
  wallets?: W;
11
11
  };
12
12
  type SwapRoute = QuoteResponseRoute | SwapRouteV2Response;
13
+ export declare function resolveRoutePluginName({ pluginName, providers, useDirectSigning, }: {
14
+ pluginName?: string;
15
+ providers: readonly PluginNameEnum[];
16
+ useDirectSigning: boolean;
17
+ }): string | undefined;
18
+ export declare function getRouteApprovalAssetValue(route: SwapRoute): AssetValue;
13
19
  export declare function SwapKit<Plugins extends ReturnType<typeof createPlugin>, Wallets extends ReturnType<typeof createWallet>>({ config, plugins, wallets }?: {
14
20
  config?: SKConfigState;
15
21
  plugins?: Plugins;
16
22
  wallets?: Wallets;
17
23
  }): (keyof Plugins extends infer T extends keyof Plugins ? { [key in T]: ReturnType<Plugins[key]>; } : never) & { [key_1 in keyof Wallets]: ReturnType<Wallets[key_1]["connectWallet"]>; } & {
18
- approveAssetValue: (assetValue: AssetValue, contractAddress: string | keyof Plugins) => Promise<string>;
24
+ approveAssetValue: (target: AssetValue | SwapRoute, contractAddress?: string | keyof Plugins) => Promise<string>;
19
25
  disconnectAll: () => void;
20
26
  disconnectChain: <T_1 extends Chain>(chain: T_1) => void;
21
27
  estimateTransactionFee: <P extends keyof Plugins, T_1 extends "swap" | "transfer" | "approve">({ type, feeOptionKey, params, }: {
@@ -4930,6 +4936,10 @@ export declare function SwapKit<Plugins extends ReturnType<typeof createPlugin>,
4930
4936
  estimateTransactionFee: () => Promise<AssetValue>;
4931
4937
  getAddress: () => Promise<string>;
4932
4938
  getBalance: (checkAddress?: string) => Promise<AssetValue[]>;
4939
+ hasTrustline: ({ address, assetValue }: {
4940
+ address: string;
4941
+ assetValue: AssetValue;
4942
+ }) => Promise<boolean>;
4933
4943
  signAndBroadcastTransaction: (transaction: {
4934
4944
  toXDR: () => string;
4935
4945
  }) => Promise<string>;
@@ -5491,7 +5501,7 @@ export declare function SwapKit<Plugins extends ReturnType<typeof createPlugin>,
5491
5501
  getBalance: <T_1 extends Chain, R extends boolean>(chain: T_1, refresh?: R) => ConditionalAssetValueReturn<R>;
5492
5502
  getWallet: <T_1 extends Chain>(chain: T_1) => FullWallet[T_1];
5493
5503
  getWalletWithBalance: <T_1 extends Chain>(chain: T_1, scamFilter?: boolean) => Promise<FullWallet[T_1]>;
5494
- isAssetValueApproved: (assetValue: AssetValue, contractAddress: string | keyof Plugins) => Promise<boolean>;
5504
+ isAssetValueApproved: (target: AssetValue | SwapRoute, contractAddress?: string | keyof Plugins) => Promise<boolean>;
5495
5505
  signMessage: ({ chain, message }: {
5496
5506
  chain: Chain;
5497
5507
  message: string;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "author": "swapkit-dev",
3
3
  "dependencies": {
4
- "@swapkit/helpers": "4.18.0",
5
- "@swapkit/plugins": "4.6.64",
6
- "@swapkit/toolboxes": "4.25.0",
7
- "@swapkit/wallet-core": "4.3.17"
4
+ "@swapkit/helpers": "4.19.0",
5
+ "@swapkit/plugins": "4.7.0",
6
+ "@swapkit/toolboxes": "4.26.0",
7
+ "@swapkit/wallet-core": "4.3.18"
8
8
  },
9
9
  "description": "SwapKit - Core",
10
10
  "devDependencies": {
@@ -36,5 +36,5 @@
36
36
  "type-check:go": "tsgo"
37
37
  },
38
38
  "type": "module",
39
- "version": "4.5.0"
39
+ "version": "4.6.0"
40
40
  }