@swapkit/core 4.4.25 → 4.4.26
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 +1 -1
- package/dist/index.js +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var{defineProperty:B,getOwnPropertyNames:K,getOwnPropertyDescriptor:s}=Object,
|
|
1
|
+
var{defineProperty:B,getOwnPropertyNames:K,getOwnPropertyDescriptor:s}=Object,M=Object.prototype.hasOwnProperty;function T(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:T.bind(L,$),enumerable:!0});if(I){for(let $ of U)if(!M.call(I,$)&&$!=="default")B(I,$,{get:T.bind(L,$),enumerable:!0});return I}};var t=(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:T.bind(J,U),enumerable:!(I=s(J,U))||I.enumerable})}return C.set(J,L),L},C;var l=(J)=>J;function a(J,L){this[J]=l.bind(null,L)}var e=(J,L)=>{for(var I in L)B(J,I,{get:L[I],enumerable:!0,configurable:!0,set:a.bind(L,I)})};var F={};e(F,{SwapKit:()=>qj});module.exports=t(F);var q=require("@swapkit/helpers");k(F,require("@swapkit/helpers"),module.exports);var jj=[q.ProviderName.FLASHNET,q.ProviderName.MAYAN];function qj({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},{}),y=Object.entries(I||{}).reduce((j,[G,z])=>{let H=z.connectWallet({addChain:E});return j[G]=H,j},{});function b(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 E(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 A(){return{...U}}function V(j){return Q(j)?.address||""}function W(j,G){return P({assetValue:j,contractAddress:G,type:q.ApproveMode.Approve})}function m(j,G){return P({assetValue:j,contractAddress:G,type:q.ApproveMode.CheckOnly})}function f(j){Q(j)?.disconnect?.(),delete U[j]}function w(){for(let j of Object.keys(U))f(j)}function h(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 g({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)=>jj.includes(Y));if(Z.supportsDirectSigning&&j.tx||X){let Y=b("swapkit");if("swap"in Y)return Y.swap({...z,route:j})}let R=b(G||j.providers[0]);if("swap"in R)return R.swap({...z,route:j});throw new q.SwapKitError("core_plugin_swap_not_found")}function d({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 u({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 o({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 p({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 c({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",(i)=>{let{contractAddress:x}=z;return D.createApprovalTx({amount:H.getBaseValue("bigint"),assetAddress:H.address,from:_,spenderAddress:x})}).with("swap",(i)=>{let{route:{providers:[x],tx:n}}=z;if(x&&[q.ProviderName.CHAINFLIP,q.ProviderName.CHAINFLIP_STREAMING].includes(x))return D.createTransferTx({assetValue:H,recipient:_,sender:_});let v=n;return{...v,value:BigInt(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 r({address:j,chain:G}){try{let{getAddressValidator:z}=await import("@swapkit/toolboxes");return(await z())({address:j,chain:G})}catch{return!1}}return{...$,...y,approveAssetValue:W,disconnectAll:w,disconnectChain:f,estimateTransactionFee:c,getAddress:V,getAllWallets:A,getBalance:h,getWallet:Q,getWalletWithBalance:N,isAssetValueApproved:m,signMessage:u,signTypedData:o,swap:g,transfer:d,validateAddress:r,verifyMessage:p}}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var k=((
|
|
1
|
+
var k=((U)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(U,{get:(M,T)=>(typeof require<"u"?require:M)[T]}):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";export*from"@swapkit/helpers";var l=[x.FLASHNET,x.MAYAN];function jj({config:U,plugins:M,wallets:T}={}){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(T||{}).reduce((j,[z,q])=>{let G=q.connectWallet({addChain:y});return j[z]=G,j},{});function b(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)=>l.includes(J));if(L.supportsDirectSigning&&j.tx||Q){let J=b("swapkit");if("swap"in J)return J.swap({...q,route:j})}let X=b(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:BigInt(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{jj as SwapKit};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-dev",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@swapkit/helpers": "4.13.
|
|
5
|
-
"@swapkit/plugins": "4.6.
|
|
6
|
-
"@swapkit/toolboxes": "4.15.
|
|
7
|
-
"@swapkit/wallet-core": "4.
|
|
4
|
+
"@swapkit/helpers": "4.13.9",
|
|
5
|
+
"@swapkit/plugins": "4.6.40",
|
|
6
|
+
"@swapkit/toolboxes": "4.15.13",
|
|
7
|
+
"@swapkit/wallet-core": "4.3.0"
|
|
8
8
|
},
|
|
9
9
|
"description": "SwapKit - Core",
|
|
10
|
-
"devDependencies": { "@stricahq/typhonjs": "3.0
|
|
10
|
+
"devDependencies": { "@stricahq/typhonjs": "3.1.0", "cosmjs-types": "0.11.0", "ts-pattern": "5.9.0" },
|
|
11
11
|
"exports": {
|
|
12
12
|
".": { "import": "./dist/index.js", "require": "./dist/index.cjs", "types": "./dist/types/index.d.ts" }
|
|
13
13
|
},
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"homepage": "https://github.com/swapkit/SwapKit",
|
|
16
16
|
"license": "SEE LICENSE IN LICENSE",
|
|
17
17
|
"name": "@swapkit/core",
|
|
18
|
-
"peerDependencies": { "@stricahq/typhonjs": "3.0
|
|
18
|
+
"peerDependencies": { "@stricahq/typhonjs": "3.1.0", "cosmjs-types": "0.11.0", "ts-pattern": "5.9.0" },
|
|
19
19
|
"publishConfig": { "access": "public" },
|
|
20
20
|
"repository": { "directory": "packages/core", "type": "git", "url": "git+https://github.com/swapkit/SwapKit.git" },
|
|
21
21
|
"scripts": {
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"type-check:go": "tsgo"
|
|
27
27
|
},
|
|
28
28
|
"type": "module",
|
|
29
|
-
"version": "4.4.
|
|
29
|
+
"version": "4.4.26"
|
|
30
30
|
}
|