@swapkit/toolboxes 4.24.1 → 4.25.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 +9 -0
- package/dist/src/aleo/index.cjs +1 -0
- package/dist/src/aleo/index.js +1 -0
- package/dist/src/cosmos/index.cjs +1 -1
- package/dist/src/cosmos/index.js +1 -1
- package/dist/src/index.cjs +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/near/index.cjs +1 -1
- package/dist/src/near/index.js +1 -1
- package/dist/src/ripple/index.cjs +1 -1
- package/dist/src/ripple/index.js +1 -1
- package/dist/types/aleo/helpers.d.ts +62 -0
- package/dist/types/aleo/index.d.ts +3 -0
- package/dist/types/aleo/toolbox.d.ts +40 -0
- package/dist/types/aleo/types.d.ts +32 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/types.d.ts +2 -0
- package/dist/types/utxo/hdWallet.d.ts +1 -1
- package/package.json +9 -2
package/dist/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ga as t}from"../chunk-xbdjxeqd.js";import{AssetValue as
|
|
1
|
+
import{ga as t}from"../chunk-xbdjxeqd.js";import{AssetValue as W,Chain as o,CosmosChains as x,EVMChains as c,FeeOption as k,SwapKitError as v,UTXOChains as b}from"@swapkit/helpers";async function E(){let{match:l}=await import("ts-pattern"),{validateAleoAddress:r}=await import("./aleo/index.js"),{validateAptosAddress:i}=await import("./aptos/index.js"),{validateEVMAddress:e}=await import("./evm/index.js"),{validateCardanoAddress:a}=await import("./cardano/index.js"),{getCosmosAddressValidator:s}=await import("./cosmos/index.js"),{validateHyperCoreAddress:T}=await import("./hypercore/index.js"),{validateSolanaAddress:p}=await import("./solana/index.js"),{validateStarknetAddress:C}=await import("./starknet/index.js"),{validateSuiAddress:h}=await import("./sui/index.js"),{validateTonAddress:u}=await import("./ton/index.js"),{getUTXOAddressValidator:d}=await import("./utxo/index.js"),{validateNearAddress:f}=await import("./near/index.js"),{validateRadixAddress:g}=await import("./radix/index.js"),{validateRippleAddress:w}=await import("./ripple/index.js"),{validateTronAddress:S}=await import("./tron/index.js"),{validateStellarAddress:P}=await import("./stellar/index.js");return function({address:n,chain:A}){return l(A).with(...c,()=>e(n)).with(...b,(m)=>{return d(m)(n)}).with(...x,(m)=>{return s(m)(n)}).with(o.Aleo,()=>r(n)).with(o.Aptos,()=>i(n)).with(o.Radix,()=>g(n)).with(o.Hype,()=>T(n)).with(o.Near,()=>f(n)).with(o.Ripple,()=>w(n)).with(o.Solana,()=>p(n)).with(o.Stellar,()=>P(n)).with(o.Starknet,()=>C(n)).with(o.Sui,()=>h(n)).with(o.Ton,()=>u(n)).with(o.Tron,()=>S(n)).with(o.Cardano,()=>a(n)).otherwise(()=>!1)}}function H(l){return async function(i){let{match:e}=await import("ts-pattern");return e(l).returnType().with(...c,async(a)=>{let s=await y(a),T=await s.createTransaction(i),p="feeOptionKey"in i?i.feeOptionKey:k.Fast;return s.estimateTransactionFee({...T,feeOption:p})}).with(o.Bitcoin,o.BitcoinCash,o.Dogecoin,o.Dash,o.Litecoin,o.Solana,o.Ripple,o.Tron,o.Near,o.Cardano,o.Hype,async(a)=>{return(await y(a)).estimateTransactionFee(i)}).with(o.Aptos,async()=>{let{getAptosToolbox:a}=await import("./aptos/index.js");return a().estimateTransactionFee(i)}).with(o.Aleo,async()=>{let{getAleoToolbox:a}=await import("./aleo/index.js");return a().estimateTransactionFee(i)}).with(o.Starknet,async()=>{let{getStarknetToolbox:a}=await import("./starknet/index.js");return(await a()).estimateTransactionFee(i)}).with(o.Stellar,async()=>{let{getStellarToolbox:a}=await import("./stellar/index.js");return a().estimateTransactionFee()}).with(o.Sui,async()=>{let{getSuiToolbox:a}=await import("./sui/index.js");return a().estimateTransactionFee(i)}).with(o.Ton,async()=>{let{getTONToolbox:a}=await import("./ton/index.js");return a().estimateTransactionFee(i)}).with(...x,async()=>{let{estimateTransactionFee:a}=await import("./cosmos/index.js");return a(i)}).otherwise(async()=>W.from({chain:l}))}}async function y(l,r){let{match:i}=await import("ts-pattern");return i(l).returnType().with(...c,async()=>{let{getEvmToolboxAsync:e}=await import("../chunk-ap5mzmjf.js");return await e(l,r)}).with(...b,async()=>{let{getUtxoToolbox:e}=await import("./utxo/index.js");return e(l,r)}).with(...x,async()=>{let{getCosmosToolbox:e}=await import("./cosmos/index.js");return e(l,r)}).with(o.Aleo,async()=>{let{getAleoToolbox:e}=await import("./aleo/index.js");return e(r)}).with(o.Aptos,async()=>{let{getAptosToolbox:e}=await import("./aptos/index.js");return e(r)}).with(o.Hype,async()=>{let{getHyperCoreToolbox:e}=await import("./hypercore/index.js");return e(r)}).with(o.Radix,async()=>{let{getRadixToolbox:e}=await import("./radix/index.js");return e(r)}).with(o.Ripple,async()=>{let{getRippleToolbox:e}=await import("./ripple/index.js");return e(r)}).with(o.Solana,async()=>{let{getSolanaToolbox:e}=await import("./solana/index.js");return e(r)}).with(o.Stellar,async()=>{let{getStellarToolbox:e}=await import("./stellar/index.js");return e(r)}).with(o.Starknet,async()=>{let{getStarknetToolbox:e}=await import("./starknet/index.js");return e(r)}).with(o.Sui,async()=>{let{getSuiToolbox:e}=await import("./sui/index.js");return e(r)}).with(o.Tron,async()=>{let{getTronToolbox:e}=await import("./tron/index.js");return e(r)}).with(o.Near,async()=>{let{getNearToolbox:e}=await import("./near/index.js");return e(r)}).with(o.Cardano,async()=>{let{getCardanoToolbox:e}=await import("./cardano/index.js");return e(r)}).with(o.Ton,async()=>{let{getTONToolbox:e}=await import("./ton/index.js");return e(r)}).otherwise(()=>{throw new v("toolbox_not_supported",{chain:l})})}export{y as getToolbox,H as getFeeEstimator,E as getAddressValidator};
|
package/dist/src/near/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var pE=Object.create;var{getPrototypeOf:dE,defineProperty:b,getOwnPropertyNames:jE,getOwnPropertyDescriptor:nE}=Object,BE=Object.prototype.hasOwnProperty;function FE(O){return this[O]}var iE,oE,TO=(O,C,x)=>{var T=O!=null&&typeof O==="object";if(T){var Z=C?iE??=new WeakMap:oE??=new WeakMap,M=Z.get(O);if(M)return M}x=O!=null?pE(dE(O)):{};let J=C||!O||!O.__esModule?b(x,"default",{value:O,enumerable:!0}):x;for(let z of jE(O))if(!BE.call(J,z))b(J,z,{get:FE.bind(O,z),enumerable:!0});if(T)Z.set(O,J);return J},cE=(O)=>{var C=(zE??=new WeakMap).get(O),x;if(C)return C;if(C=b({},"__esModule",{value:!0}),O&&typeof O==="object"||typeof O==="function"){for(var T of jE(O))if(!BE.call(C,T))b(C,T,{get:FE.bind(O,T),enumerable:!(x=nE(O,T))||x.enumerable})}return zE.set(O,C),C},zE;var sE=(O)=>O;function tE(O,C){this[O]=sE.bind(null,C)}var rE=(O,C)=>{for(var x in C)b(O,x,{get:C[x],enumerable:!0,configurable:!0,set:tE.bind(C,x)})};var D=(O,C)=>()=>(O&&(C=O(O=0)),C);function K(O){return O.length>=2&&O.length<=64&&/^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/.test(O)}async function p(O){let{KeyPair:C}=await import("@near-js/crypto"),x=O.index||0,T=O.derivationPath?g.derivationPathToString(O.derivationPath.slice(0,3)):`m/44'/397'/${x}'`,{parseSeedPhrase:Z}=await import("near-seed-phrase"),{secretKey:M}=Z(O.phrase,T),J=C.fromString(M);return fE(J)}async function s(O){let{KeyPair:C}=await import("@near-js/crypto"),x=C.fromString(O);return fE(x)}async function fE(O){let{KeyPairSigner:C}=await import("@near-js/signers");class x extends C{#E;constructor(T){super(T);this.#E=T}getAddress(){let T=this.#E.getPublicKey(),Z=Buffer.from(T.data).toString("hex");return Promise.resolve(Z)}}return new x(O)}async function d(O,C){let T=(await O.query({account_id:C,finality:"final",request_type:"view_access_key_list"})).keys.find((z)=>z.access_key.permission==="FullAccess");if(!T)throw new g.SwapKitError("toolbox_near_no_public_key_found");let{PublicKey:Z}=await import("@near-js/crypto"),M=Z.fromString(T.public_key);return{nonce:T.access_key.nonce||0,publicKey:M}}var g;var t=D(()=>{g=require("@swapkit/helpers")});function r(O){return"recipient"in O&&"amount"in O&&!("contractId"in O)}function a(O){return"contractId"in O&&"methodName"in O}function e(O){return"actions"in O}function EE(O){return"newAccountId"in O}function OE(O){return"contractCode"in O}function _E(O){return"customEstimator"in O}function NE(O){let C=0;for(let x of O)switch(x.enum){case"transfer":C+=Number(q.SIMPLE_TRANSFER);break;case"functionCall":C+=Number(q.CONTRACT_CALL);break;case"createAccount":C+=Number(q.ACCOUNT_CREATION);break;case"deployContract":C+=Number(q.CONTRACT_DEPLOYMENT);break;case"addKey":C+=Number(q.ACCESS_KEY_ADDITION);break;case"deleteKey":C+=Number(q.ACCESS_KEY_DELETION);break;case"stake":C+=Number(q.STAKE);break;default:C+=Number(q.CONTRACT_CALL)}return C.toString()}function CE(O){if(O==="ft_transfer"||O==="ft_transfer_call")return q.TOKEN_TRANSFER;if(O==="storage_deposit")return q.STORAGE_DEPOSIT;return q.CONTRACT_CALL}function aE(O){return(BigInt(O)*BigInt(1000000000000)).toString()}function eE(O){return(BigInt(O)/BigInt(1000000000000)).toString()}var q;var LE=D(()=>{q={ACCESS_KEY_ADDITION:"5",ACCESS_KEY_DELETION:"5",ACCOUNT_CREATION:"30",CONTRACT_CALL:"150",CONTRACT_DEPLOYMENT:"200",SIMPLE_TRANSFER:"1",STAKE:"10",STORAGE_DEPOSIT:"150",TOKEN_TRANSFER:"150"}});async function RE({account:O,contractId:C,viewMethods:x,changeMethods:T}){let{Contract:Z}=await import("@near-js/accounts");return new Z(O,C,{changeMethods:T,useLocalViewExecution:!0,viewMethods:x})}function ZO(){function O(){let C=Date.now(),x=xE||C;return xE=x,C>xE?C:x+1}return EO+O().toString(36)}function HE(O){return async function(x,T=!0){let Z=await AE.SwapKitApi.getChainBalance({address:x,chain:O,scamFilter:T}),{baseDecimal:M}=y.getChainConfig(O),J=Z.map(({identifier:F,value:S,decimal:P})=>{return new y.AssetValue({decimal:P||M,identifier:F,value:S})});if(!J.some((F)=>F.isGasAsset))return[y.AssetValue.from({chain:O}),...J];return J}}var y,AE,EO,xE=0;var GE=D(()=>{y=require("@swapkit/helpers"),AE=require("@swapkit/helpers/api"),EO=typeof process<"u"&&process.pid?process.pid.toString(36):""});function LO(O){let C;async function x(){if(C)return C;return C=await I.match(O).with({phrase:I.P.string},async(E)=>{return await p(E)}).with({signer:I.P.any},({signer:E})=>E).otherwise(()=>{return}),C}async function T(){let{JsonRpcProvider:E}=await import("@near-js/providers"),_=await Y.getRPCUrl(Y.Chain.Near);return new E({url:_})}async function Z(E){let{Account:_}=await import("@near-js/accounts"),N=await T(),L=await x(),R=E||await M();return new _(R,N,L)}async function M(){let E=await x();if(!E)throw new Y.SwapKitError("toolbox_near_no_signer");return await E.getAddress()}async function J(E,_){return(_||await T()).callFunction(E.contractId,"storage_balance_of",{account_id:E.accountId},{finality:"final"})}async function z(E,_){try{let N=await _.callFunction(E,"storage_balance_bounds",{},{finality:"final"});return N?.min?BigInt(N.min):wE}catch{return wE}}function F(E){return(E*(TE+CO)+TE-1n)/TE}function S(E,_){return BigInt(E)*BigInt(_.runtime_config.storage_amount_per_byte)}function P(E,_){if(E<=0n)throw new Y.SwapKitError({errorKey:"toolbox_sweep_amount_too_low",info:_});return E}async function n(E){return await(E||await T()).experimental_protocolConfig({finality:"final"})}async function kE(E,_,N){let R=await(N||await T()).callFunction(E,"ft_balance_of",{account_id:_},{finality:"final"});return BigInt(R||"0")}async function VE(E){if(!await x())throw new Y.SwapKitError("toolbox_near_no_signer");let{assetValue:N,recipient:L,memo:R,sweep:Q}=E,W=await M(),X=await QE({assetValue:N,memo:R,recipient:L,sender:W,sweep:Q});return qE(X)}async function bE({assetValue:E,attachedDeposit:_,memo:N,provider:L,recipient:R,sender:Q,sweep:W}){let X=E.address;if(!X)throw new Y.SwapKitError("toolbox_near_missing_contract_address");let $=await J({accountId:R,contractId:X},L),U=$?0n:await z(X,L),j=$?_O:OO,A=BigInt(_||"1"),H=E.getBaseValue("bigint");if(W){let[G,w,k,v]=await Promise.all([kE(X,Q,L),L.viewAccount(Q,{finality:"final"}),n(L),c(L)]);H=P(G,{asset:E.toString(),balance:G.toString()});let u=S(w.storage_usage,k),V=w.amount-u,l=U,UE=(j+($?0n:DE))*F(v)+l+A;if(V<UE)throw new Y.SwapKitError("toolbox_sweep_amount_too_low",{asset:E.toString(),availableNear:V.toString(),reason:"Insufficient NEAR to cover token transfer gas and storage deposit",requiredNear:UE.toString()})}let B=[];if(!$)B.push(await h({args:{account_id:R},attachedDeposit:U.toString(),gas:DE.toString(),methodName:"storage_deposit"}));return B.push(await h({args:{amount:H.toString(),memo:N||null,receiver_id:R},attachedDeposit:A.toString(),gas:j.toString(),methodName:"ft_transfer"})),XE({actions:B,receiverId:X,sender:Q})}async function KE({assetValue:E,attachedDeposit:_,memo:N,provider:L,recipient:R,sender:Q,sweep:W}){let{publicKey:X,nonce:$}=await d(L,Q),U=E.getBaseValue("bigint");if(W){let[k,v]=await Promise.all([L.viewAccount(Q,{finality:"final"}),n(L)]),u=await JE({assetValue:E,memo:N,recipient:R,sweep:W},v),V=S(k.storage_usage,v),l=0n;if(N&&_){let ME=await c(L);l=NO*F(ME)+BigInt(_)}U=P(k.amount-u.getBaseValue("bigint")-V-l,{asset:E.toString(),balance:k.amount.toString(),fee:u.getBaseValue("bigint").toString(),storageStakeReserve:V.toString()})}let{actionCreators:j,createTransaction:A}=await import("@near-js/transactions"),{baseDecode:H}=await import("@near-js/utils"),B=[j.transfer(U)];if(N&&_)B.push(j.functionCall("memo",{memo:N},BigInt("250000000000000"),BigInt(_)));let G=await L.block({finality:"final"}),w=H(G.header.hash);return A(Q,X,R,$+1,B,w)}async function QE({recipient:E,assetValue:_,memo:N,attachedDeposit:L,sender:R,functionCall:Q,sweep:W}){if(!K(E))throw new Y.SwapKitError("toolbox_near_invalid_address",{recipient:E});if(!K(R))throw new Y.SwapKitError("toolbox_near_invalid_address",{sender:R});if(Q)return WE({...Q,sender:R});if(W&&!await x())throw new Y.SwapKitError("toolbox_near_no_signer");let X=await T(),$={assetValue:_,attachedDeposit:L,memo:N,provider:X,recipient:E,sender:R,sweep:W};return _.isGasAsset?KE($):bE($)}function yE(E){let _=E.encode();return Buffer.from(_).toString("base64")}async function WE({args:E,attachedDeposit:_,contractId:N,gas:L,methodName:R,sender:Q}){let W=await h({args:E,attachedDeposit:_,gas:L,methodName:R});return XE({actions:[W],receiverId:N,sender:Q})}async function XE({actions:E,receiverId:_,sender:N}){let L=await T(),{publicKey:R,nonce:Q}=await d(L,N),{createTransaction:W}=await import("@near-js/transactions"),{baseDecode:X}=await import("@near-js/utils"),$=await L.block({finality:"final"}),U=X($.header.hash);return W(N,R,_,Q+1,E,U)}async function h(E){let{actionCreators:_}=await import("@near-js/transactions");return _.functionCall(E.methodName,Buffer.from(JSON.stringify(E.args)),BigInt(E.gas),BigInt(E.attachedDeposit))}async function ZE(E){let _=await x();if(!_)throw new Y.SwapKitError("toolbox_near_no_signer");await SE(E);let[N,L]=await _.signTransaction(E);return L}async function SE(E){let _=E.publicKey;if(_.toString?.().startsWith("ed25519:")||_.toString?.().startsWith("secp256k1:"))return;let{KeyType:N,PublicKey:L}=await import("@near-js/crypto"),R=_.data||_.ed25519Key?.data,Q=_.secp256k1Key?.data;if(R){E.publicKey=new L({data:Uint8Array.from(R),keyType:N.ED25519});return}if(Q)E.publicKey=new L({data:Uint8Array.from(Q),keyType:N.SECP256K1})}function i(E){if(typeof E==="string")return E;if(Array.isArray(E))return E.map(i).find(Boolean);if(!(E&&typeof E==="object"))return;let _=E;return _.transaction?.hash||_.transaction_outcome?.id}function o(E){return E instanceof Error?E.message:String(E)}async function $E(E){let N=await(await T()).sendTransaction(E),L=i(N);if(!L)throw new Y.SwapKitError("toolbox_near_transfer_failed",{result:N});return L}async function qE(E){let _=await x();if(!_)throw new Y.SwapKitError("toolbox_near_no_signer");let N;try{N=await ZE(E)}catch(L){let R;try{R=_.signAndSendTransaction?await _.signAndSendTransaction({actions:E.actions,receiverId:E.receiverId,signerId:E.signerId}):await _.signAndSendTransactions?.({transactions:[E]})}catch(W){throw new Y.SwapKitError({errorKey:"toolbox_near_sign_transaction_failed",info:{directSignError:o(L),signAndSendError:o(W)}},W)}let Q=i(R);if(Q)return Q;throw L}return $E(N)}async function JE(E,_){let N=await x();if("assetValue"in E){if(E.sweep&&!N)throw new Y.SwapKitError("toolbox_near_no_signer");try{let[R,Q]=await Promise.all([c(),_?Promise.resolve(_):n()]),{runtime_config:W}=Q,{execution:X,send_sir:$}=W.transaction_costs.action_receipt_creation_config,{execution:U,send_sir:j}=W.transaction_costs.action_creation_config.transfer_cost,A=BigInt(j)+BigInt(U),H=BigInt($)+BigInt(X),B=A+H,G=E.sweep?F(R):R,w=B*G;return Y.AssetValue.from({chain:Y.Chain.Near,value:w})}catch(R){throw new Y.SwapKitError({errorKey:"toolbox_fee_estimation_failed",info:{chain:Y.Chain.Near,message:o(R)}},R)}}let L=N?await Z():void 0;return m(E,L)}async function c(E){let N=await(E||await T()).gasPrice(null);return BigInt(N.gas_price)}async function PE(E,_,N){if(!await x())throw new Y.SwapKitError("toolbox_near_no_signer");let R=await Z(),{formatNearAmount:Q}=await import("@near-js/utils"),{PublicKey:W}=await import("@near-js/crypto"),X=Q(N)||"0";return(await R.createAccount(E,W.fromString(_),BigInt(X))).transaction.hash}async function hE(E){let _=await x();try{if(!_)throw new Y.SwapKitError("toolbox_near_no_signer");let{actionCreators:N}=await import("@near-js/transactions"),{contractId:L,methodName:R,args:Q,deposit:W}=E,X=await Z(),$=await m({args:Q||{},contractId:L,methodName:R}),U=N.functionCall(R,Q||{},$.getBaseValue("bigint"),BigInt(W||"1"));return(await X.signAndSendTransaction({actions:[U],receiverId:L})).transaction_outcome.id}catch(N){throw new Y.SwapKitError("toolbox_near_transfer_failed",{error:N})}}async function mE(E){let _=await Z();return RE({account:_,changeMethods:E.changeMethods,contractId:E.contractId,viewMethods:E.viewMethods})}async function vE(E){if(!await x())throw new Y.SwapKitError("toolbox_near_no_signer");if(E.actions.length===0)throw new Y.SwapKitError("toolbox_near_empty_batch");return(await(await Z()).signAndSendTransaction({actions:E.actions,receiverId:E.receiverId})).transaction.hash}async function m(E,_){let N=await I.match(E).when(r,()=>q.SIMPLE_TRANSFER).when(a,(R)=>CE(R.methodName)).when(e,(R)=>NE(R.actions)).when(EE,()=>q.ACCOUNT_CREATION).when(OE,()=>q.CONTRACT_DEPLOYMENT).when(_E,(R)=>{if(!_)throw new Y.SwapKitError("toolbox_near_no_account");return R.customEstimator(_)}).otherwise(()=>{throw new Y.SwapKitError("toolbox_near_invalid_gas_params")}),L=BigInt(N)*BigInt(1000000000000);return Y.AssetValue.from({chain:Y.Chain.Near,value:L})}function uE(E,_){return console.warn("NEAR toolbox: estimateGas is deprecated, use estimateGasLimit instead"),m(E,_)}async function lE(){let E=await T();try{return(await E.gasPrice(null)).gas_price||"100000000"}catch{return"100000000"}}async function gE(){let E=await x();return E?(await E.getPublicKey()).toString():""}return{broadcastTransaction:$E,callFunction:hE,createAction:h,createContract:mE,createContractFunctionCall:WE,createSubAccount:PE,createTransaction:QE,estimateGas:uE,estimateGasLimit:m,estimateTransactionFee:JE,executeBatchTransaction:vE,getAddress:M,getBalance:HE(Y.Chain.Near),getGasPrice:lE,getNearProvider:T,getPublicKey:gE,getSignerFromPhrase:p,getSignerFromPrivateKey:s,serializeTransaction:yE,signAndBroadcastTransaction:qE,signTransaction:ZE,transfer:VE,validateAddress:K}}var Y,I,wE=1250000000000000000000n,DE=150000000000000n,OO=150000000000000n,_O=250000000000000n,NO=250000000000000n,CO=500n,TE=10000n;var YE=D(()=>{GE();t();LE();Y=require("@swapkit/helpers"),I=require("ts-pattern")});var IE=D(()=>{YE()});var RO={};rE(RO,{validateNearAddress:()=>K,tgasToGas:()=>aE,isSimpleTransfer:()=>r,isCustomEstimator:()=>_E,isContractDeployment:()=>OE,isContractCall:()=>a,isBatchTransaction:()=>e,isAccountCreation:()=>EE,getNearToolbox:()=>LO,getNearSignerFromPrivateKey:()=>s,getNearSignerFromPhrase:()=>p,getFullAccessPublicKey:()=>d,getContractMethodGas:()=>CE,gasToTGas:()=>eE,estimateBatchGas:()=>NE,createNearContract:()=>RE,GAS_COSTS:()=>q});module.exports=cE(RO);var xO=D(()=>{t();LE();YE();IE()});xO();
|
|
1
|
+
var pE=Object.create;var{getPrototypeOf:dE,defineProperty:b,getOwnPropertyNames:UE,getOwnPropertyDescriptor:nE}=Object,jE=Object.prototype.hasOwnProperty;function zE(O){return this[O]}var oE,iE,MO=(O,_,T)=>{var M=O!=null&&typeof O==="object";if(M){var Q=_?oE??=new WeakMap:iE??=new WeakMap,$=Q.get(O);if($)return $}T=O!=null?pE(dE(O)):{};let Z=_||!O||!O.__esModule?b(T,"default",{value:O,enumerable:!0}):T;for(let J of UE(O))if(!jE.call(Z,J))b(Z,J,{get:zE.bind(O,J),enumerable:!0});if(M)Q.set(O,Z);return Z},cE=(O)=>{var _=(JE??=new WeakMap).get(O),T;if(_)return _;if(_=b({},"__esModule",{value:!0}),O&&typeof O==="object"||typeof O==="function"){for(var M of UE(O))if(!jE.call(_,M))b(_,M,{get:zE.bind(O,M),enumerable:!(T=nE(O,M))||T.enumerable})}return JE.set(O,_),_},JE;var tE=(O)=>O;function sE(O,_){this[O]=tE.bind(null,_)}var rE=(O,_)=>{for(var T in _)b(O,T,{get:_[T],enumerable:!0,configurable:!0,set:sE.bind(_,T)})};var G=(O,_)=>()=>(O&&(_=O(O=0)),_);function y(O){return O.length>=2&&O.length<=64&&/^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/.test(O)}async function p(O){let{KeyPair:_}=await import("@near-js/crypto"),T=O.index||0,M=O.derivationPath?g.derivationPathToString(O.derivationPath.slice(0,3)):`m/44'/397'/${T}'`,{parseSeedPhrase:Q}=await import("near-seed-phrase"),{secretKey:$}=Q(O.phrase,M),Z=_.fromString($);return FE(Z)}async function t(O){let{KeyPair:_}=await import("@near-js/crypto"),T=_.fromString(O);return FE(T)}async function FE(O){let{KeyPairSigner:_}=await import("@near-js/signers");class T extends _{#E;constructor(M){super(M);this.#E=M}getAddress(){let M=this.#E.getPublicKey(),Q=Buffer.from(M.data).toString("hex");return Promise.resolve(Q)}}return new T(O)}async function d(O,_){let M=(await O.query({account_id:_,finality:"final",request_type:"view_access_key_list"})).keys.find((J)=>J.access_key.permission==="FullAccess");if(!M)throw new g.SwapKitError("toolbox_near_no_public_key_found");let{PublicKey:Q}=await import("@near-js/crypto"),$=Q.fromString(M.public_key);return{nonce:M.access_key.nonce||0,publicKey:$}}var g;var s=G(()=>{g=require("@swapkit/helpers")});function r(O){return"recipient"in O&&"amount"in O&&!("contractId"in O)}function a(O){return"contractId"in O&&"methodName"in O}function e(O){return"actions"in O}function EE(O){return"newAccountId"in O}function OE(O){return"contractCode"in O}function NE(O){return"customEstimator"in O}function CE(O){let _=0;for(let T of O)switch(T.enum){case"transfer":_+=Number(X.SIMPLE_TRANSFER);break;case"functionCall":_+=Number(X.CONTRACT_CALL);break;case"createAccount":_+=Number(X.ACCOUNT_CREATION);break;case"deployContract":_+=Number(X.CONTRACT_DEPLOYMENT);break;case"addKey":_+=Number(X.ACCESS_KEY_ADDITION);break;case"deleteKey":_+=Number(X.ACCESS_KEY_DELETION);break;case"stake":_+=Number(X.STAKE);break;default:_+=Number(X.CONTRACT_CALL)}return _.toString()}function _E(O){if(O==="ft_transfer"||O==="ft_transfer_call")return X.TOKEN_TRANSFER;if(O==="storage_deposit")return X.STORAGE_DEPOSIT;return X.CONTRACT_CALL}function aE(O){return(BigInt(O)*BigInt(1000000000000)).toString()}function eE(O){return(BigInt(O)/BigInt(1000000000000)).toString()}var X;var xE=G(()=>{X={ACCESS_KEY_ADDITION:"5",ACCESS_KEY_DELETION:"5",ACCOUNT_CREATION:"30",CONTRACT_CALL:"150",CONTRACT_DEPLOYMENT:"200",SIMPLE_TRANSFER:"1",STAKE:"10",STORAGE_DEPOSIT:"150",TOKEN_TRANSFER:"150"}});async function LE({account:O,contractId:_,viewMethods:T,changeMethods:M}){let{Contract:Q}=await import("@near-js/accounts");return new Q(O,_,{changeMethods:M,useLocalViewExecution:!0,viewMethods:T})}function QO(){function O(){let _=Date.now(),T=TE||_;return TE=T,_>TE?_:T+1}return EO+O().toString(36)}function AE(O){return async function(T,M=!0){let Q=await IE.SwapKitApi.getChainBalance({address:T,chain:O,scamFilter:M}),{baseDecimal:$}=K.getChainConfig(O),Z=Q.map(({identifier:z,value:S,decimal:P})=>{return new K.AssetValue({decimal:P||$,identifier:z,value:S})});if(!Z.some((z)=>z.isGasAsset))return[K.AssetValue.from({chain:O}),...Z];return Z}}var K,IE,EO,TE=0;var wE=G(()=>{K=require("@swapkit/helpers"),IE=require("@swapkit/helpers/api"),EO=typeof process<"u"&&process.pid?process.pid.toString(36):""});function xO(O){let _;async function T(){if(_)return _;return _=await D.match(O).with({phrase:D.P.string},async(E)=>{return await p(E)}).with({signer:D.P.any},({signer:E})=>E).otherwise(()=>{return}),_}async function M(){let{JsonRpcProvider:E}=await import("@near-js/providers"),N=await R.getRPCUrl(R.Chain.Near);return new E({url:N})}async function Q(E){let{Account:N}=await import("@near-js/accounts"),C=await M(),x=await T(),L=E||await $();return new N(L,C,x)}async function $(){let E=await T();if(!E)throw new R.SwapKitError("toolbox_near_no_signer");return await E.getAddress()}async function Z(E,N){return(N||await M()).callFunction(E.contractId,"storage_balance_of",{account_id:E.accountId},{finality:"final"})}async function J(E,N){try{let C=await N.callFunction(E,"storage_balance_bounds",{},{finality:"final"});return C?.min?BigInt(C.min):HE}catch{return HE}}function z(E){return(E*(ME+_O)+ME-1n)/ME}function S(E,N){return BigInt(E)*BigInt(N.runtime_config.storage_amount_per_byte)}function P(E,N){if(E<=0n)throw new R.SwapKitError({errorKey:"toolbox_sweep_amount_too_low",info:N});return E}async function n(E){return await(E||await M()).experimental_protocolConfig({finality:"final"})}async function kE(E,N,C){let L=await(C||await M()).callFunction(E,"ft_balance_of",{account_id:N},{finality:"final"});return BigInt(L||"0")}async function VE(E){if(!await T())throw new R.SwapKitError("toolbox_near_no_signer");let{assetValue:C,recipient:x,memo:L,sweep:Y}=E,f=await $(),B=await YE({assetValue:C,memo:L,recipient:x,sender:f,sweep:Y});return XE(B)}async function bE({assetValue:E,attachedDeposit:N,memo:C,provider:x,recipient:L,sender:Y,sweep:f}){let B=E.address;if(!B)throw new R.SwapKitError("toolbox_near_missing_contract_address");let W=await Z({accountId:L,contractId:B},x),q=W?0n:await J(B,x),U=W?NO:OO,I=BigInt(N||"1"),A=E.getBaseValue("bigint");if(f){let[w,H,k,u]=await Promise.all([kE(B,Y,x),x.viewAccount(Y,{finality:"final"}),n(x),c(x)]);A=P(w,{asset:E.toString(),balance:w.toString()});let v=S(H.storage_usage,k),V=H.amount-v,l=q,qE=(U+(W?0n:GE))*z(u)+l+I;if(V<qE)throw new R.SwapKitError("toolbox_sweep_amount_too_low",{asset:E.toString(),availableNear:V.toString(),reason:"Insufficient NEAR to cover token transfer gas and storage deposit",requiredNear:qE.toString()})}let j=[];if(!W)j.push(await h({args:{account_id:L},attachedDeposit:q.toString(),gas:GE.toString(),methodName:"storage_deposit"}));return j.push(await h({args:{amount:A.toString(),memo:C||null,receiver_id:L},attachedDeposit:I.toString(),gas:U.toString(),methodName:"ft_transfer"})),BE({actions:j,receiverId:B,sender:Y})}async function yE({assetValue:E,attachedDeposit:N,memo:C,provider:x,recipient:L,sender:Y,sweep:f}){let{publicKey:B,nonce:W}=await d(x,Y),q=E.getBaseValue("bigint");if(f){let[k,u]=await Promise.all([x.viewAccount(Y,{finality:"final"}),n(x)]),v=await ZE({assetValue:E,memo:C,recipient:L,sweep:f},u),V=S(k.storage_usage,u),l=0n;if(C&&N){let $E=await c(x);l=CO*z($E)+BigInt(N)}q=P(k.amount-v.getBaseValue("bigint")-V-l,{asset:E.toString(),balance:k.amount.toString(),fee:v.getBaseValue("bigint").toString(),storageStakeReserve:V.toString()})}let{actionCreators:U,createTransaction:I}=await import("@near-js/transactions"),{baseDecode:A}=await import("@near-js/utils"),j=[U.transfer(q)];if(C&&N)j.push(U.functionCall("memo",{memo:C},BigInt("250000000000000"),BigInt(N)));let w=await x.block({finality:"final"}),H=A(w.header.hash);return I(Y,B,L,W+1,j,H)}async function YE({recipient:E,assetValue:N,memo:C,attachedDeposit:x,sender:L,functionCall:Y,sweep:f}){if(!y(E))throw new R.SwapKitError("toolbox_near_invalid_address",{recipient:E});if(!y(L))throw new R.SwapKitError("toolbox_near_invalid_address",{sender:L});if(Y)return fE({...Y,sender:L});if(f&&!await T())throw new R.SwapKitError("toolbox_near_no_signer");let B=await M(),W={assetValue:N,attachedDeposit:x,memo:C,provider:B,recipient:E,sender:L,sweep:f};return N.isGasAsset?yE(W):bE(W)}function KE(E){let N=E.encode();return Buffer.from(N).toString("base64")}async function fE({args:E,attachedDeposit:N,contractId:C,gas:x,methodName:L,sender:Y}){let f=await h({args:E,attachedDeposit:N,gas:x,methodName:L});return BE({actions:[f],receiverId:C,sender:Y})}async function BE({actions:E,receiverId:N,sender:C}){let x=await M(),{publicKey:L,nonce:Y}=await d(x,C),{createTransaction:f}=await import("@near-js/transactions"),{baseDecode:B}=await import("@near-js/utils"),W=await x.block({finality:"final"}),q=B(W.header.hash);return f(C,L,N,Y+1,E,q)}async function h(E){let{actionCreators:N}=await import("@near-js/transactions");return N.functionCall(E.methodName,Buffer.from(JSON.stringify(E.args)),BigInt(E.gas),BigInt(E.attachedDeposit))}async function QE(E){let N=await T();if(!N)throw new R.SwapKitError("toolbox_near_no_signer");await SE(E);let[C,x]=await N.signTransaction(E);return x}async function SE(E){let N=E.publicKey;if(N.toString?.().startsWith("ed25519:")||N.toString?.().startsWith("secp256k1:"))return;let{KeyType:C,PublicKey:x}=await import("@near-js/crypto"),L=N.data||N.ed25519Key?.data,Y=N.secp256k1Key?.data;if(L){E.publicKey=new x({data:Uint8Array.from(L),keyType:C.ED25519});return}if(Y)E.publicKey=new x({data:Uint8Array.from(Y),keyType:C.SECP256K1})}function o(E){if(typeof E==="string")return E;if(Array.isArray(E))return E.map(o).find(Boolean);if(!(E&&typeof E==="object"))return;let N=E;return N.transaction?.hash||N.transaction_outcome?.id}function i(E){return E instanceof Error?E.message:String(E)}async function WE(E){let C=await(await M()).sendTransaction(E),x=o(C);if(!x)throw new R.SwapKitError("toolbox_near_transfer_failed",{result:C});return x}async function XE(E){let N=await T();if(!N)throw new R.SwapKitError("toolbox_near_no_signer");let C;try{C=await QE(E)}catch(x){let L;try{L=N.signAndSendTransaction?await N.signAndSendTransaction({actions:E.actions,receiverId:E.receiverId,signerId:E.signerId}):await N.signAndSendTransactions?.({transactions:[E]})}catch(f){throw new R.SwapKitError({errorKey:"toolbox_near_sign_transaction_failed",info:{directSignError:i(x),signAndSendError:i(f)}},f)}let Y=o(L);if(Y)return Y;throw x}return WE(C)}async function ZE(E,N){let C=await T();if("assetValue"in E){if(E.sweep&&!C)throw new R.SwapKitError("toolbox_near_no_signer");try{let[L,Y]=await Promise.all([c(),N?Promise.resolve(N):n()]),{runtime_config:f}=Y,{execution:B,send_sir:W}=f.transaction_costs.action_receipt_creation_config,{execution:q,send_sir:U}=f.transaction_costs.action_creation_config.transfer_cost,I=BigInt(U)+BigInt(q),A=BigInt(W)+BigInt(B),j=I+A,w=E.sweep?z(L):L,H=j*w;return R.AssetValue.from({chain:R.Chain.Near,value:H})}catch(L){throw new R.SwapKitError({errorKey:"toolbox_fee_estimation_failed",info:{chain:R.Chain.Near,message:i(L)}},L)}}let x=C?await Q():void 0;return m(E,x)}async function c(E){let C=await(E||await M()).gasPrice(null);return BigInt(C.gas_price)}async function PE(E,N,C){if(!await T())throw new R.SwapKitError("toolbox_near_no_signer");let L=await Q(),{formatNearAmount:Y}=await import("@near-js/utils"),{PublicKey:f}=await import("@near-js/crypto"),B=Y(C)||"0";return(await L.createAccount(E,f.fromString(N),BigInt(B))).transaction.hash}async function hE(E){let N=await T();try{if(!N)throw new R.SwapKitError("toolbox_near_no_signer");let{actionCreators:C}=await import("@near-js/transactions"),{contractId:x,methodName:L,args:Y,deposit:f}=E,B=await Q(),W=await m({args:Y||{},contractId:x,methodName:L}),q=C.functionCall(L,Y||{},W.getBaseValue("bigint"),BigInt(f||"1"));return(await B.signAndSendTransaction({actions:[q],receiverId:x})).transaction_outcome.id}catch(C){throw new R.SwapKitError("toolbox_near_transfer_failed",{error:C})}}async function mE(E){let N=await Q();return LE({account:N,changeMethods:E.changeMethods,contractId:E.contractId,viewMethods:E.viewMethods})}async function uE(E){if(!await T())throw new R.SwapKitError("toolbox_near_no_signer");if(E.actions.length===0)throw new R.SwapKitError("toolbox_near_empty_batch");return(await(await Q()).signAndSendTransaction({actions:E.actions,receiverId:E.receiverId})).transaction.hash}async function m(E,N){let C=await D.match(E).when(r,()=>X.SIMPLE_TRANSFER).when(a,(L)=>_E(L.methodName)).when(e,(L)=>CE(L.actions)).when(EE,()=>X.ACCOUNT_CREATION).when(OE,()=>X.CONTRACT_DEPLOYMENT).when(NE,(L)=>{if(!N)throw new R.SwapKitError("toolbox_near_no_account");return L.customEstimator(N)}).otherwise(()=>{throw new R.SwapKitError("toolbox_near_invalid_gas_params")}),x=BigInt(C)*BigInt(1000000000000);return R.AssetValue.from({chain:R.Chain.Near,value:x})}function vE(E,N){return console.warn("NEAR toolbox: estimateGas is deprecated, use estimateGasLimit instead"),m(E,N)}async function lE(){let E=await M();try{return(await E.gasPrice(null)).gas_price||"100000000"}catch{return"100000000"}}async function gE(){let E=await T();return E?(await E.getPublicKey()).toString():""}return{broadcastTransaction:WE,callFunction:hE,createAction:h,createContract:mE,createContractFunctionCall:fE,createSubAccount:PE,createTransaction:YE,estimateGas:vE,estimateGasLimit:m,estimateTransactionFee:ZE,executeBatchTransaction:uE,getAddress:$,getBalance:AE(R.Chain.Near),getGasPrice:lE,getNearProvider:M,getPublicKey:gE,getSignerFromPhrase:p,getSignerFromPrivateKey:t,serializeTransaction:KE,signAndBroadcastTransaction:XE,signTransaction:QE,transfer:VE,validateAddress:y}}var R,D,HE=1250000000000000000000n,GE=150000000000000n,OO=150000000000000n,NO=250000000000000n,CO=250000000000000n,_O=500n,ME=10000n;var RE=G(()=>{wE();s();xE();R=require("@swapkit/helpers"),D=require("ts-pattern")});var DE=G(()=>{RE()});var LO={};rE(LO,{validateNearAddress:()=>y,tgasToGas:()=>aE,isSimpleTransfer:()=>r,isCustomEstimator:()=>NE,isContractDeployment:()=>OE,isContractCall:()=>a,isBatchTransaction:()=>e,isAccountCreation:()=>EE,getNearToolbox:()=>xO,getNearSignerFromPrivateKey:()=>t,getNearSignerFromPhrase:()=>p,getFullAccessPublicKey:()=>d,getContractMethodGas:()=>_E,gasToTGas:()=>eE,estimateBatchGas:()=>CE,createNearContract:()=>LE,GAS_COSTS:()=>X});module.exports=cE(LO);var TO=G(()=>{s();xE();RE();DE()});TO();
|
package/dist/src/near/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fa as ME}from"../../chunk-nvfkjbyq.js";import{ga as Z}from"../../chunk-xbdjxeqd.js";import{derivationPathToString as VE,SwapKitError as bE}from"@swapkit/helpers";function y(R){return R.length>=2&&R.length<=64&&/^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/.test(R)}async function l(R){let{KeyPair:C}=await import("@near-js/crypto"),x=R.index||0,T=R.derivationPath?VE(R.derivationPath.slice(0,3)):`m/44'/397'/${x}'`,{parseSeedPhrase:q}=await import("near-seed-phrase"),{secretKey:j}=q(R.phrase,T),k=C.fromString(j);return _E(k)}async function OE(R){let{KeyPair:C}=await import("@near-js/crypto"),x=C.fromString(R);return _E(x)}async function _E(R){let{KeyPairSigner:C}=await import("@near-js/signers");class x extends C{#E;constructor(T){super(T);this.#E=T}getAddress(){let T=this.#E.getPublicKey(),q=Buffer.from(T.data).toString("hex");return Promise.resolve(q)}}return new x(R)}async function g(R,C){let T=(await R.query({account_id:C,finality:"final",request_type:"view_access_key_list"})).keys.find((S)=>S.access_key.permission==="FullAccess");if(!T)throw new bE("toolbox_near_no_public_key_found");let{PublicKey:q}=await import("@near-js/crypto"),j=q.fromString(T.public_key);return{nonce:T.access_key.nonce||0,publicKey:j}}var J={ACCESS_KEY_ADDITION:"5",ACCESS_KEY_DELETION:"5",ACCOUNT_CREATION:"30",CONTRACT_CALL:"150",CONTRACT_DEPLOYMENT:"200",SIMPLE_TRANSFER:"1",STAKE:"10",STORAGE_DEPOSIT:"150",TOKEN_TRANSFER:"150"};function NE(R){return"recipient"in R&&"amount"in R&&!("contractId"in R)}function LE(R){return"contractId"in R&&"methodName"in R}function RE(R){return"actions"in R}function YE(R){return"newAccountId"in R}function CE(R){return"contractCode"in R}function xE(R){return"customEstimator"in R}function TE(R){let C=0;for(let x of R)switch(x.enum){case"transfer":C+=Number(J.SIMPLE_TRANSFER);break;case"functionCall":C+=Number(J.CONTRACT_CALL);break;case"createAccount":C+=Number(J.ACCOUNT_CREATION);break;case"deployContract":C+=Number(J.CONTRACT_DEPLOYMENT);break;case"addKey":C+=Number(J.ACCESS_KEY_ADDITION);break;case"deleteKey":C+=Number(J.ACCESS_KEY_DELETION);break;case"stake":C+=Number(J.STAKE);break;default:C+=Number(J.CONTRACT_CALL)}return C.toString()}function QE(R){if(R==="ft_transfer"||R==="ft_transfer_call")return J.TOKEN_TRANSFER;if(R==="storage_deposit")return J.STORAGE_DEPOSIT;return J.CONTRACT_CALL}function uE(R){return(BigInt(R)*BigInt(1000000000000)).toString()}function lE(R){return(BigInt(R)/BigInt(1000000000000)).toString()}async function WE({account:R,contractId:C,viewMethods:x,changeMethods:T}){let{Contract:q}=await import("@near-js/accounts");return new q(R,C,{changeMethods:T,useLocalViewExecution:!0,viewMethods:x})}import{AssetValue as XE,Chain as D,getRPCUrl as KE,SwapKitError as W}from"@swapkit/helpers";import{match as ZE,P as $E}from"ts-pattern";var JE=1250000000000000000000n,qE=150000000000000n,yE=150000000000000n,SE=250000000000000n,PE=250000000000000n,hE=500n,p=10000n;function tE(R){let C;async function x(){if(C)return C;return C=await ZE(R).with({phrase:$E.string},async(E)=>{return await l(E)}).with({signer:$E.any},({signer:E})=>E).otherwise(()=>{return}),C}async function T(){let{JsonRpcProvider:E}=await import("@near-js/providers"),O=await KE(D.Near);return new E({url:O})}async function q(E){let{Account:O}=await import("@near-js/accounts"),_=await T(),N=await x(),L=E||await j();return new O(L,_,N)}async function j(){let E=await x();if(!E)throw new W("toolbox_near_no_signer");return await E.getAddress()}async function k(E,O){return(O||await T()).callFunction(E.contractId,"storage_balance_of",{account_id:E.accountId},{finality:"final"})}async function S(E,O){try{let _=await O.callFunction(E,"storage_balance_bounds",{},{finality:"final"});return _?.min?BigInt(_.min):JE}catch{return JE}}function P(E){return(E*(p+hE)+p-1n)/p}function d(E,O){return BigInt(E)*BigInt(O.runtime_config.storage_amount_per_byte)}function i(E,O){if(E<=0n)throw new W({errorKey:"toolbox_sweep_amount_too_low",info:O});return E}async function h(E){return await(E||await T()).experimental_protocolConfig({finality:"final"})}async function UE(E,O,_){let L=await(_||await T()).callFunction(E,"ft_balance_of",{account_id:O},{finality:"final"});return BigInt(L||"0")}async function zE(E){if(!await x())throw new W("toolbox_near_no_signer");let{assetValue:_,recipient:N,memo:L,sweep:Y}=E,Q=await j(),X=await o({assetValue:_,memo:L,recipient:N,sender:Q,sweep:Y});return r(X)}async function jE({assetValue:E,attachedDeposit:O,memo:_,provider:N,recipient:L,sender:Y,sweep:Q}){let X=E.address;if(!X)throw new W("toolbox_near_missing_contract_address");let $=await k({accountId:L,contractId:X},N),M=$?0n:await S(X,N),U=$?SE:yE,F=BigInt(O||"1"),B=E.getBaseValue("bigint");if(Q){let[H,G,A,V]=await Promise.all([UE(X,Y,N),N.viewAccount(Y,{finality:"final"}),h(N),u(N)]);B=i(H,{asset:E.toString(),balance:H.toString()});let b=d(G.storage_usage,A),I=G.amount-b,K=M,EE=(U+($?0n:qE))*P(V)+K+F;if(I<EE)throw new W("toolbox_sweep_amount_too_low",{asset:E.toString(),availableNear:I.toString(),reason:"Insufficient NEAR to cover token transfer gas and storage deposit",requiredNear:EE.toString()})}let z=[];if(!$)z.push(await w({args:{account_id:L},attachedDeposit:M.toString(),gas:qE.toString(),methodName:"storage_deposit"}));return z.push(await w({args:{amount:B.toString(),memo:_||null,receiver_id:L},attachedDeposit:F.toString(),gas:U.toString(),methodName:"ft_transfer"})),c({actions:z,receiverId:X,sender:Y})}async function FE({assetValue:E,attachedDeposit:O,memo:_,provider:N,recipient:L,sender:Y,sweep:Q}){let{publicKey:X,nonce:$}=await g(N,Y),M=E.getBaseValue("bigint");if(Q){let[A,V]=await Promise.all([N.viewAccount(Y,{finality:"final"}),h(N)]),b=await a({assetValue:E,memo:_,recipient:L,sweep:Q},V),I=d(A.storage_usage,V),K=0n;if(_&&O){let e=await u(N);K=PE*P(e)+BigInt(O)}M=i(A.amount-b.getBaseValue("bigint")-I-K,{asset:E.toString(),balance:A.amount.toString(),fee:b.getBaseValue("bigint").toString(),storageStakeReserve:I.toString()})}let{actionCreators:U,createTransaction:F}=await import("@near-js/transactions"),{baseDecode:B}=await import("@near-js/utils"),z=[U.transfer(M)];if(_&&O)z.push(U.functionCall("memo",{memo:_},BigInt("250000000000000"),BigInt(O)));let H=await N.block({finality:"final"}),G=B(H.header.hash);return F(Y,X,L,$+1,z,G)}async function o({recipient:E,assetValue:O,memo:_,attachedDeposit:N,sender:L,functionCall:Y,sweep:Q}){if(!y(E))throw new W("toolbox_near_invalid_address",{recipient:E});if(!y(L))throw new W("toolbox_near_invalid_address",{sender:L});if(Y)return n({...Y,sender:L});if(Q&&!await x())throw new W("toolbox_near_no_signer");let X=await T(),$={assetValue:O,attachedDeposit:N,memo:_,provider:X,recipient:E,sender:L,sweep:Q};return O.isGasAsset?FE($):jE($)}function BE(E){let O=E.encode();return Buffer.from(O).toString("base64")}async function n({args:E,attachedDeposit:O,contractId:_,gas:N,methodName:L,sender:Y}){let Q=await w({args:E,attachedDeposit:O,gas:N,methodName:L});return c({actions:[Q],receiverId:_,sender:Y})}async function c({actions:E,receiverId:O,sender:_}){let N=await T(),{publicKey:L,nonce:Y}=await g(N,_),{createTransaction:Q}=await import("@near-js/transactions"),{baseDecode:X}=await import("@near-js/utils"),$=await N.block({finality:"final"}),M=X($.header.hash);return Q(_,L,O,Y+1,E,M)}async function w(E){let{actionCreators:O}=await import("@near-js/transactions");return O.functionCall(E.methodName,Buffer.from(JSON.stringify(E.args)),BigInt(E.gas),BigInt(E.attachedDeposit))}async function s(E){let O=await x();if(!O)throw new W("toolbox_near_no_signer");await HE(E);let[_,N]=await O.signTransaction(E);return N}async function HE(E){let O=E.publicKey;if(O.toString?.().startsWith("ed25519:")||O.toString?.().startsWith("secp256k1:"))return;let{KeyType:_,PublicKey:N}=await import("@near-js/crypto"),L=O.data||O.ed25519Key?.data,Y=O.secp256k1Key?.data;if(L){E.publicKey=new N({data:Uint8Array.from(L),keyType:_.ED25519});return}if(Y)E.publicKey=new N({data:Uint8Array.from(Y),keyType:_.SECP256K1})}function v(E){if(typeof E==="string")return E;if(Array.isArray(E))return E.map(v).find(Boolean);if(!(E&&typeof E==="object"))return;let O=E;return O.transaction?.hash||O.transaction_outcome?.id}function m(E){return E instanceof Error?E.message:String(E)}async function t(E){let _=await(await T()).sendTransaction(E),N=v(_);if(!N)throw new W("toolbox_near_transfer_failed",{result:_});return N}async function r(E){let O=await x();if(!O)throw new W("toolbox_near_no_signer");let _;try{_=await s(E)}catch(N){let L;try{L=O.signAndSendTransaction?await O.signAndSendTransaction({actions:E.actions,receiverId:E.receiverId,signerId:E.signerId}):await O.signAndSendTransactions?.({transactions:[E]})}catch(Q){throw new W({errorKey:"toolbox_near_sign_transaction_failed",info:{directSignError:m(N),signAndSendError:m(Q)}},Q)}let Y=v(L);if(Y)return Y;throw N}return t(_)}async function a(E,O){let _=await x();if("assetValue"in E){if(E.sweep&&!_)throw new W("toolbox_near_no_signer");try{let[L,Y]=await Promise.all([u(),O?Promise.resolve(O):h()]),{runtime_config:Q}=Y,{execution:X,send_sir:$}=Q.transaction_costs.action_receipt_creation_config,{execution:M,send_sir:U}=Q.transaction_costs.action_creation_config.transfer_cost,F=BigInt(U)+BigInt(M),B=BigInt($)+BigInt(X),z=F+B,H=E.sweep?P(L):L,G=z*H;return XE.from({chain:D.Near,value:G})}catch(L){throw new W({errorKey:"toolbox_fee_estimation_failed",info:{chain:D.Near,message:m(L)}},L)}}let N=_?await q():void 0;return f(E,N)}async function u(E){let _=await(E||await T()).gasPrice(null);return BigInt(_.gas_price)}async function GE(E,O,_){if(!await x())throw new W("toolbox_near_no_signer");let L=await q(),{formatNearAmount:Y}=await import("@near-js/utils"),{PublicKey:Q}=await import("@near-js/crypto"),X=Y(_)||"0";return(await L.createAccount(E,Q.fromString(O),BigInt(X))).transaction.hash}async function AE(E){let O=await x();try{if(!O)throw new W("toolbox_near_no_signer");let{actionCreators:_}=await import("@near-js/transactions"),{contractId:N,methodName:L,args:Y,deposit:Q}=E,X=await q(),$=await f({args:Y||{},contractId:N,methodName:L}),M=_.functionCall(L,Y||{},$.getBaseValue("bigint"),BigInt(Q||"1"));return(await X.signAndSendTransaction({actions:[M],receiverId:N})).transaction_outcome.id}catch(_){throw new W("toolbox_near_transfer_failed",{error:_})}}async function IE(E){let O=await q();return WE({account:O,changeMethods:E.changeMethods,contractId:E.contractId,viewMethods:E.viewMethods})}async function DE(E){if(!await x())throw new W("toolbox_near_no_signer");if(E.actions.length===0)throw new W("toolbox_near_empty_batch");return(await(await q()).signAndSendTransaction({actions:E.actions,receiverId:E.receiverId})).transaction.hash}async function f(E,O){let _=await ZE(E).when(NE,()=>J.SIMPLE_TRANSFER).when(LE,(L)=>QE(L.methodName)).when(RE,(L)=>TE(L.actions)).when(YE,()=>J.ACCOUNT_CREATION).when(CE,()=>J.CONTRACT_DEPLOYMENT).when(xE,(L)=>{if(!O)throw new W("toolbox_near_no_account");return L.customEstimator(O)}).otherwise(()=>{throw new W("toolbox_near_invalid_gas_params")}),N=BigInt(_)*BigInt(1000000000000);return XE.from({chain:D.Near,value:N})}function kE(E,O){return console.warn("NEAR toolbox: estimateGas is deprecated, use estimateGasLimit instead"),f(E,O)}async function wE(){let E=await T();try{return(await E.gasPrice(null)).gas_price||"100000000"}catch{return"100000000"}}async function fE(){let E=await x();return E?(await E.getPublicKey()).toString():""}return{broadcastTransaction:t,callFunction:AE,createAction:w,createContract:IE,createContractFunctionCall:n,createSubAccount:GE,createTransaction:o,estimateGas:kE,estimateGasLimit:f,estimateTransactionFee:a,executeBatchTransaction:DE,getAddress:j,getBalance:ME(D.Near),getGasPrice:wE,getNearProvider:T,getPublicKey:fE,getSignerFromPhrase:l,getSignerFromPrivateKey:OE,serializeTransaction:BE,signAndBroadcastTransaction:r,signTransaction:s,transfer:zE,validateAddress:y}}export{y as validateNearAddress,uE as tgasToGas,NE as isSimpleTransfer,xE as isCustomEstimator,CE as isContractDeployment,LE as isContractCall,RE as isBatchTransaction,YE as isAccountCreation,tE as getNearToolbox,OE as getNearSignerFromPrivateKey,l as getNearSignerFromPhrase,g as getFullAccessPublicKey,QE as getContractMethodGas,lE as gasToTGas,TE as estimateBatchGas,WE as createNearContract,J as GAS_COSTS};
|
|
1
|
+
import{fa as qE}from"../../chunk-nvfkjbyq.js";import{ga as X}from"../../chunk-xbdjxeqd.js";import{derivationPathToString as VE,SwapKitError as bE}from"@swapkit/helpers";function y(x){return x.length>=2&&x.length<=64&&/^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/.test(x)}async function l(x){let{KeyPair:M}=await import("@near-js/crypto"),R=x.index||0,T=x.derivationPath?VE(x.derivationPath.slice(0,3)):`m/44'/397'/${R}'`,{parseSeedPhrase:J}=await import("near-seed-phrase"),{secretKey:z}=J(x.phrase,T),w=M.fromString(z);return NE(w)}async function OE(x){let{KeyPair:M}=await import("@near-js/crypto"),R=M.fromString(x);return NE(R)}async function NE(x){let{KeyPairSigner:M}=await import("@near-js/signers");class R extends M{#E;constructor(T){super(T);this.#E=T}getAddress(){let T=this.#E.getPublicKey(),J=Buffer.from(T.data).toString("hex");return Promise.resolve(J)}}return new R(x)}async function g(x,M){let T=(await x.query({account_id:M,finality:"final",request_type:"view_access_key_list"})).keys.find((S)=>S.access_key.permission==="FullAccess");if(!T)throw new bE("toolbox_near_no_public_key_found");let{PublicKey:J}=await import("@near-js/crypto"),z=J.fromString(T.public_key);return{nonce:T.access_key.nonce||0,publicKey:z}}var $={ACCESS_KEY_ADDITION:"5",ACCESS_KEY_DELETION:"5",ACCOUNT_CREATION:"30",CONTRACT_CALL:"150",CONTRACT_DEPLOYMENT:"200",SIMPLE_TRANSFER:"1",STAKE:"10",STORAGE_DEPOSIT:"150",TOKEN_TRANSFER:"150"};function _E(x){return"recipient"in x&&"amount"in x&&!("contractId"in x)}function CE(x){return"contractId"in x&&"methodName"in x}function xE(x){return"actions"in x}function LE(x){return"newAccountId"in x}function ME(x){return"contractCode"in x}function RE(x){return"customEstimator"in x}function TE(x){let M=0;for(let R of x)switch(R.enum){case"transfer":M+=Number($.SIMPLE_TRANSFER);break;case"functionCall":M+=Number($.CONTRACT_CALL);break;case"createAccount":M+=Number($.ACCOUNT_CREATION);break;case"deployContract":M+=Number($.CONTRACT_DEPLOYMENT);break;case"addKey":M+=Number($.ACCESS_KEY_ADDITION);break;case"deleteKey":M+=Number($.ACCESS_KEY_DELETION);break;case"stake":M+=Number($.STAKE);break;default:M+=Number($.CONTRACT_CALL)}return M.toString()}function YE(x){if(x==="ft_transfer"||x==="ft_transfer_call")return $.TOKEN_TRANSFER;if(x==="storage_deposit")return $.STORAGE_DEPOSIT;return $.CONTRACT_CALL}function uE(x){return(BigInt(x)*BigInt(1000000000000)).toString()}function lE(x){return(BigInt(x)/BigInt(1000000000000)).toString()}async function QE({account:x,contractId:M,viewMethods:R,changeMethods:T}){let{Contract:J}=await import("@near-js/accounts");return new J(x,M,{changeMethods:T,useLocalViewExecution:!0,viewMethods:R})}import{AssetValue as WE,Chain as G,getRPCUrl as KE,SwapKitError as Q}from"@swapkit/helpers";import{match as XE,P as ZE}from"ts-pattern";var $E=1250000000000000000000n,JE=150000000000000n,yE=150000000000000n,SE=250000000000000n,PE=250000000000000n,hE=500n,p=10000n;function tE(x){let M;async function R(){if(M)return M;return M=await XE(x).with({phrase:ZE.string},async(E)=>{return await l(E)}).with({signer:ZE.any},({signer:E})=>E).otherwise(()=>{return}),M}async function T(){let{JsonRpcProvider:E}=await import("@near-js/providers"),O=await KE(G.Near);return new E({url:O})}async function J(E){let{Account:O}=await import("@near-js/accounts"),N=await T(),_=await R(),C=E||await z();return new O(C,N,_)}async function z(){let E=await R();if(!E)throw new Q("toolbox_near_no_signer");return await E.getAddress()}async function w(E,O){return(O||await T()).callFunction(E.contractId,"storage_balance_of",{account_id:E.accountId},{finality:"final"})}async function S(E,O){try{let N=await O.callFunction(E,"storage_balance_bounds",{},{finality:"final"});return N?.min?BigInt(N.min):$E}catch{return $E}}function P(E){return(E*(p+hE)+p-1n)/p}function d(E,O){return BigInt(E)*BigInt(O.runtime_config.storage_amount_per_byte)}function n(E,O){if(E<=0n)throw new Q({errorKey:"toolbox_sweep_amount_too_low",info:O});return E}async function h(E){return await(E||await T()).experimental_protocolConfig({finality:"final"})}async function UE(E,O,N){let C=await(N||await T()).callFunction(E,"ft_balance_of",{account_id:O},{finality:"final"});return BigInt(C||"0")}async function jE(E){if(!await R())throw new Q("toolbox_near_no_signer");let{assetValue:N,recipient:_,memo:C,sweep:L}=E,Y=await z(),W=await o({assetValue:N,memo:C,recipient:_,sender:Y,sweep:L});return r(W)}async function zE({assetValue:E,attachedDeposit:O,memo:N,provider:_,recipient:C,sender:L,sweep:Y}){let W=E.address;if(!W)throw new Q("toolbox_near_missing_contract_address");let Z=await w({accountId:C,contractId:W},_),q=Z?0n:await S(W,_),U=Z?SE:yE,B=BigInt(O||"1"),F=E.getBaseValue("bigint");if(Y){let[I,f,H,V]=await Promise.all([UE(W,L,_),_.viewAccount(L,{finality:"final"}),h(_),u(_)]);F=n(I,{asset:E.toString(),balance:I.toString()});let b=d(f.storage_usage,H),A=f.amount-b,K=q,EE=(U+(Z?0n:JE))*P(V)+K+B;if(A<EE)throw new Q("toolbox_sweep_amount_too_low",{asset:E.toString(),availableNear:A.toString(),reason:"Insufficient NEAR to cover token transfer gas and storage deposit",requiredNear:EE.toString()})}let j=[];if(!Z)j.push(await k({args:{account_id:C},attachedDeposit:q.toString(),gas:JE.toString(),methodName:"storage_deposit"}));return j.push(await k({args:{amount:F.toString(),memo:N||null,receiver_id:C},attachedDeposit:B.toString(),gas:U.toString(),methodName:"ft_transfer"})),c({actions:j,receiverId:W,sender:L})}async function BE({assetValue:E,attachedDeposit:O,memo:N,provider:_,recipient:C,sender:L,sweep:Y}){let{publicKey:W,nonce:Z}=await g(_,L),q=E.getBaseValue("bigint");if(Y){let[H,V]=await Promise.all([_.viewAccount(L,{finality:"final"}),h(_)]),b=await a({assetValue:E,memo:N,recipient:C,sweep:Y},V),A=d(H.storage_usage,V),K=0n;if(N&&O){let e=await u(_);K=PE*P(e)+BigInt(O)}q=n(H.amount-b.getBaseValue("bigint")-A-K,{asset:E.toString(),balance:H.amount.toString(),fee:b.getBaseValue("bigint").toString(),storageStakeReserve:A.toString()})}let{actionCreators:U,createTransaction:B}=await import("@near-js/transactions"),{baseDecode:F}=await import("@near-js/utils"),j=[U.transfer(q)];if(N&&O)j.push(U.functionCall("memo",{memo:N},BigInt("250000000000000"),BigInt(O)));let I=await _.block({finality:"final"}),f=F(I.header.hash);return B(L,W,C,Z+1,j,f)}async function o({recipient:E,assetValue:O,memo:N,attachedDeposit:_,sender:C,functionCall:L,sweep:Y}){if(!y(E))throw new Q("toolbox_near_invalid_address",{recipient:E});if(!y(C))throw new Q("toolbox_near_invalid_address",{sender:C});if(L)return i({...L,sender:C});if(Y&&!await R())throw new Q("toolbox_near_no_signer");let W=await T(),Z={assetValue:O,attachedDeposit:_,memo:N,provider:W,recipient:E,sender:C,sweep:Y};return O.isGasAsset?BE(Z):zE(Z)}function FE(E){let O=E.encode();return Buffer.from(O).toString("base64")}async function i({args:E,attachedDeposit:O,contractId:N,gas:_,methodName:C,sender:L}){let Y=await k({args:E,attachedDeposit:O,gas:_,methodName:C});return c({actions:[Y],receiverId:N,sender:L})}async function c({actions:E,receiverId:O,sender:N}){let _=await T(),{publicKey:C,nonce:L}=await g(_,N),{createTransaction:Y}=await import("@near-js/transactions"),{baseDecode:W}=await import("@near-js/utils"),Z=await _.block({finality:"final"}),q=W(Z.header.hash);return Y(N,C,O,L+1,E,q)}async function k(E){let{actionCreators:O}=await import("@near-js/transactions");return O.functionCall(E.methodName,Buffer.from(JSON.stringify(E.args)),BigInt(E.gas),BigInt(E.attachedDeposit))}async function s(E){let O=await R();if(!O)throw new Q("toolbox_near_no_signer");await IE(E);let[N,_]=await O.signTransaction(E);return _}async function IE(E){let O=E.publicKey;if(O.toString?.().startsWith("ed25519:")||O.toString?.().startsWith("secp256k1:"))return;let{KeyType:N,PublicKey:_}=await import("@near-js/crypto"),C=O.data||O.ed25519Key?.data,L=O.secp256k1Key?.data;if(C){E.publicKey=new _({data:Uint8Array.from(C),keyType:N.ED25519});return}if(L)E.publicKey=new _({data:Uint8Array.from(L),keyType:N.SECP256K1})}function m(E){if(typeof E==="string")return E;if(Array.isArray(E))return E.map(m).find(Boolean);if(!(E&&typeof E==="object"))return;let O=E;return O.transaction?.hash||O.transaction_outcome?.id}function v(E){return E instanceof Error?E.message:String(E)}async function t(E){let N=await(await T()).sendTransaction(E),_=m(N);if(!_)throw new Q("toolbox_near_transfer_failed",{result:N});return _}async function r(E){let O=await R();if(!O)throw new Q("toolbox_near_no_signer");let N;try{N=await s(E)}catch(_){let C;try{C=O.signAndSendTransaction?await O.signAndSendTransaction({actions:E.actions,receiverId:E.receiverId,signerId:E.signerId}):await O.signAndSendTransactions?.({transactions:[E]})}catch(Y){throw new Q({errorKey:"toolbox_near_sign_transaction_failed",info:{directSignError:v(_),signAndSendError:v(Y)}},Y)}let L=m(C);if(L)return L;throw _}return t(N)}async function a(E,O){let N=await R();if("assetValue"in E){if(E.sweep&&!N)throw new Q("toolbox_near_no_signer");try{let[C,L]=await Promise.all([u(),O?Promise.resolve(O):h()]),{runtime_config:Y}=L,{execution:W,send_sir:Z}=Y.transaction_costs.action_receipt_creation_config,{execution:q,send_sir:U}=Y.transaction_costs.action_creation_config.transfer_cost,B=BigInt(U)+BigInt(q),F=BigInt(Z)+BigInt(W),j=B+F,I=E.sweep?P(C):C,f=j*I;return WE.from({chain:G.Near,value:f})}catch(C){throw new Q({errorKey:"toolbox_fee_estimation_failed",info:{chain:G.Near,message:v(C)}},C)}}let _=N?await J():void 0;return D(E,_)}async function u(E){let N=await(E||await T()).gasPrice(null);return BigInt(N.gas_price)}async function fE(E,O,N){if(!await R())throw new Q("toolbox_near_no_signer");let C=await J(),{formatNearAmount:L}=await import("@near-js/utils"),{PublicKey:Y}=await import("@near-js/crypto"),W=L(N)||"0";return(await C.createAccount(E,Y.fromString(O),BigInt(W))).transaction.hash}async function HE(E){let O=await R();try{if(!O)throw new Q("toolbox_near_no_signer");let{actionCreators:N}=await import("@near-js/transactions"),{contractId:_,methodName:C,args:L,deposit:Y}=E,W=await J(),Z=await D({args:L||{},contractId:_,methodName:C}),q=N.functionCall(C,L||{},Z.getBaseValue("bigint"),BigInt(Y||"1"));return(await W.signAndSendTransaction({actions:[q],receiverId:_})).transaction_outcome.id}catch(N){throw new Q("toolbox_near_transfer_failed",{error:N})}}async function AE(E){let O=await J();return QE({account:O,changeMethods:E.changeMethods,contractId:E.contractId,viewMethods:E.viewMethods})}async function GE(E){if(!await R())throw new Q("toolbox_near_no_signer");if(E.actions.length===0)throw new Q("toolbox_near_empty_batch");return(await(await J()).signAndSendTransaction({actions:E.actions,receiverId:E.receiverId})).transaction.hash}async function D(E,O){let N=await XE(E).when(_E,()=>$.SIMPLE_TRANSFER).when(CE,(C)=>YE(C.methodName)).when(xE,(C)=>TE(C.actions)).when(LE,()=>$.ACCOUNT_CREATION).when(ME,()=>$.CONTRACT_DEPLOYMENT).when(RE,(C)=>{if(!O)throw new Q("toolbox_near_no_account");return C.customEstimator(O)}).otherwise(()=>{throw new Q("toolbox_near_invalid_gas_params")}),_=BigInt(N)*BigInt(1000000000000);return WE.from({chain:G.Near,value:_})}function wE(E,O){return console.warn("NEAR toolbox: estimateGas is deprecated, use estimateGasLimit instead"),D(E,O)}async function kE(){let E=await T();try{return(await E.gasPrice(null)).gas_price||"100000000"}catch{return"100000000"}}async function DE(){let E=await R();return E?(await E.getPublicKey()).toString():""}return{broadcastTransaction:t,callFunction:HE,createAction:k,createContract:AE,createContractFunctionCall:i,createSubAccount:fE,createTransaction:o,estimateGas:wE,estimateGasLimit:D,estimateTransactionFee:a,executeBatchTransaction:GE,getAddress:z,getBalance:qE(G.Near),getGasPrice:kE,getNearProvider:T,getPublicKey:DE,getSignerFromPhrase:l,getSignerFromPrivateKey:OE,serializeTransaction:FE,signAndBroadcastTransaction:r,signTransaction:s,transfer:jE,validateAddress:y}}export{y as validateNearAddress,uE as tgasToGas,_E as isSimpleTransfer,RE as isCustomEstimator,ME as isContractDeployment,CE as isContractCall,xE as isBatchTransaction,LE as isAccountCreation,tE as getNearToolbox,OE as getNearSignerFromPrivateKey,l as getNearSignerFromPhrase,g as getFullAccessPublicKey,YE as getContractMethodGas,lE as gasToTGas,TE as estimateBatchGas,QE as createNearContract,$ as GAS_COSTS};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var z5=Object.create;var{getPrototypeOf:$5,defineProperty:k,getOwnPropertyNames:u,getOwnPropertyDescriptor:j5}=Object,p=Object.prototype.hasOwnProperty;function o(f){return this[f]}var q5,v5,k5=(f,U,q)=>{var W=f!=null&&typeof f==="object";if(W){var B=U?q5??=new WeakMap:v5??=new WeakMap,X=B.get(f);if(X)return X}q=f!=null?z5($5(f)):{};let D=U||!f||!f.__esModule?k(q,"default",{value:f,enumerable:!0}):q;for(let Q of u(f))if(!p.call(D,Q))k(D,Q,{get:o.bind(f,Q),enumerable:!0});if(W)B.set(f,D);return D},W5=(f)=>{var U=(x??=new WeakMap).get(f),q;if(U)return U;if(U=k({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function"){for(var W of u(f))if(!p.call(U,W))k(U,W,{get:o.bind(f,W),enumerable:!(q=j5(f,W))||q.enumerable})}return x.set(f,U),U},x;var Z5=(f)=>f;function B5(f,U){this[f]=Z5.bind(null,U)}var J5=(f,U)=>{for(var q in U)k(f,q,{get:U[q],enumerable:!0,configurable:!0,set:B5.bind(U,q)})};var S=(f,U)=>()=>(f&&(U=f(f=0)),U);function P(f){return/^[0-9A-Fa-f]{40}$/.test(f)}function N(f){if(P(f))return f.toUpperCase();if(f.length<=3){let q=Buffer.from(f.padEnd(3,"\x00")).toString("hex");return`00${"0".repeat(22)}${q}${"0".repeat(10)}`.toUpperCase()}let U=Buffer.from(f).toString("hex").toUpperCase();if(U.length>40)throw new c.SwapKitError({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:f,reason:"Currency exceeds maximum length (20 bytes)"}});return U.padEnd(40,"0")}function Y5(f){if(!P(f))return f;if(f.toUpperCase().startsWith("00")){let U=f.slice(24,30);try{let q=Buffer.from(U,"hex").toString("ascii").replace(/\0/g,"");if(/^[A-Za-z0-9?!@#$%^&*<>(){}[\]|]+$/.test(q)&&q.length>0)return q}catch{}return f.toUpperCase()}try{let U=f.replace(/0+$/,""),q=U.length%2===0?U:`${U}0`,W=Buffer.from(q,"hex").toString("utf8");if(/^[\x20-\x7E]+$/.test(W))return W}catch{}return f.toUpperCase()}function b(f){if(P(f))return f.toUpperCase();if(f.length<=3)return f;return N(f)}var c;var I=S(()=>{c=require("@swapkit/helpers")});async function M5(f,U){let q=b(f),W=E.find((B)=>b(B.currency)===q&&B.issuer===U);if(W)return W;try{let B=await K.RequestClient.get(`https://api.xrplmeta.org/token/${f}:${U}`);if(B)return{currency:f,decimals:15,description:B.desc,domain:B.domain,icon:B.icon,issuer:U,name:B.name,verified:B.self_assessment?.is_regulated||B.self_assessment?.is_licensed}}catch(B){K.warnOnce({condition:!0,id:`xrpl_token_lookup_${f}_${U}`,warning:`Failed to fetch XRPL token info for ${f}:${U}: ${B}`})}return{currency:f,decimals:15,issuer:U,verified:!1}}function X5(f){return E.filter((U)=>U.issuer===f)}function Q5(f,U){let q=b(f);return E.some((W)=>b(W.currency)===q&&W.issuer===U)}var K,E;var d=S(()=>{I();K=require("@swapkit/helpers"),E=[{currency:"USD",decimals:15,domain:"circle.com",issuer:"rcEGREd8NmkKRE8GE424sksyt1tJVFZwu",name:"Circle USDC",verified:!0},{currency:"RLUSD",decimals:15,domain:"ripple.com",issuer:"rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De",name:"Ripple USD",verified:!0},{currency:"USD",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp USD",verified:!0},{currency:"BTC",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp BTC",verified:!0},{currency:"EUR",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp EUR",verified:!0},{currency:"USD",decimals:15,domain:"gatehub.net",issuer:"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq",name:"GateHub USD",verified:!0},{currency:"EUR",decimals:15,domain:"gatehub.net",issuer:"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq",name:"GateHub EUR",verified:!0},{currency:"BTC",decimals:15,domain:"gatehub.net",issuer:"rchGBxcD1A1C2tdxF6papQYZ8kjRKMYcL",name:"GateHub BTC",verified:!0},{currency:"ETH",decimals:15,domain:"gatehub.net",issuer:"rcA8X3TVMST1n3CJeAdGk1RdRCHii7N2h",name:"GateHub ETH",verified:!0},{currency:"SOLO",decimals:15,domain:"sologenic.com",issuer:"rsoLo2S1kiGeCcn6hCUXVrCpGMWLrRrLZz",name:"Sologenic",verified:!0}]});var D5={};J5(D5,{validateRippleAddress:()=>L,parseXrplTokenIdentifier:()=>C,normalizeCurrency:()=>b,isKnownToken:()=>Q5,isHexCurrency:()=>P,hexToCurrency:()=>Y5,getXrplTokenInfo:()=>M5,getRippleToolbox:()=>N5,getKnownTokensByIssuer:()=>X5,formatXrplTokenIdentifier:()=>t,currencyToHex:()=>N,XRPL_TOKEN_ERROR_CODES:()=>y,XRPL_KNOWN_TOKENS:()=>E});module.exports=W5(D5);function i(f){if(typeof f!=="object"||f===null||!("data"in f))return!1;let{data:U}=f;return typeof U==="object"&&U!==null&&"error_code"in U&&U.error_code===_5.ACCOUNT_NOT_FOUND}function C(f){let U=f.match(/^XRP\.([A-Fa-f0-9]{40}|[\x20-\x7E]{1,20})-([a-zA-Z0-9]{25,34})$/);if(!U?.[1]||!U?.[2])return null;if(!L(U[2]))return null;return{currency:U[1],issuer:U[2]}}function t(f,U){return`${G.Chain.Ripple}.${f}-${U}`}async function l(f){if(f.isGasAsset){let{xrpToDrops:q}=await import("xrpl");return q(f.getValue("string"))}let U=C(f.toString());if(!U)throw new G.SwapKitError({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:f.toString()}});return{currency:U.currency,issuer:U.issuer,value:f.getValue("string")}}function n(f){let U,q=()=>{return U??=import("xrpl").then(({Wallet:W})=>W.fromMnemonic(f)),U};return{getAddress:async()=>(await q()).address,signTransaction:async(W)=>(await q()).sign(W)}}function L(f){return w.isValidClassicAddress(f)||w.isValidXAddress(f)}function N5(f={}){let U;async function q(){if(U)return U;return U=await F.match(f).with({phrase:F.P.string},({phrase:m})=>n(m)).with({signer:F.P.any},({signer:m})=>m).otherwise(()=>{return}),U}let W;async function B(){let m=await G.getRPCUrl(G.Chain.Ripple);if(!m)throw new G.SwapKitError({errorKey:"toolbox_ripple_rpc_not_configured",info:{chain:G.Chain.Ripple}});let{Client:z}=await import("xrpl"),j=new z(m);return await j.connect(),j}async function X(){if(W){let m=await W.catch(()=>null);if(m?.isConnected())return m}return W=B(),W}async function D(m){let z=await m.request({command:"server_state"}),j=z.result.state.validated_ledger??z.result.state.closed_ledger;if(!j||!Number.isSafeInteger(j.reserve_base)||j.reserve_base<0||!Number.isSafeInteger(j.reserve_inc)||j.reserve_inc<0)throw new G.SwapKitError({errorKey:"toolbox_ripple_get_balance_error",info:{reason:"XRPL reserve data is unavailable or invalid"}});return{baseReserveDrops:BigInt(j.reserve_base),ownerReserveDrops:BigInt(j.reserve_inc)}}let Q=async()=>{let m=await q();if(!m)throw new G.SwapKitError({errorKey:"toolbox_ripple_signer_not_found"});return m.getAddress()},a=async(m)=>{let z=m||await Q(),{baseDecimal:j}=G.getChainConfig(G.Chain.Ripple),v=await X();try{let[$,Z]=await Promise.all([v.request({account:z,command:"account_info"}),v.request({account:z,command:"account_lines"})]),M=$.result.account_data.Balance,J=[G.AssetValue.from({chain:G.Chain.Ripple,fromBaseDecimal:j,value:M})];for(let Y of Z.result.lines){let _=t(Y.currency,Y.account);if(Number.parseFloat(Y.balance)!==0)J.push(G.AssetValue.from({asset:_,asyncTokenLookup:!1,value:Y.balance}))}return J}catch($){if(i($))return[G.AssetValue.from({chain:G.Chain.Ripple,value:0})];throw new G.SwapKitError({errorKey:"toolbox_ripple_get_balance_error",info:{address:z,error:$}})}},T=async()=>{let{baseDecimal:m}=G.getChainConfig(G.Chain.Ripple),v=(await(await X()).request({command:"fee"})).result.drops.open_ledger_fee;return G.AssetValue.from({chain:G.Chain.Ripple,fromBaseDecimal:m,value:v})};async function V(m){let z=m||await Q(),j=await X();try{return(await j.request({account:z,command:"account_lines"})).result.lines.map(($)=>({account:$.account,authorized:$.authorized??!1,balance:$.balance,currency:$.currency,freeze:$.freeze??!1,freezePeer:$.freeze_peer??!1,limit:$.limit,limitPeer:$.limit_peer,noRipple:$.no_ripple??!1,noRipplePeer:$.no_ripple_peer??!1,peerAuthorized:$.peer_authorized??!1,qualityIn:$.quality_in??0,qualityOut:$.quality_out??0}))}catch(v){if(i(v))return[];throw new G.SwapKitError({errorKey:"toolbox_ripple_get_trust_lines_error",info:{address:z,error:v}})}}async function s({address:m,currency:z,issuer:j}){let v=await V(m),$=N(z);return v.some((Z)=>{return N(Z.currency)===$&&Z.account===j})}async function h({currency:m,issuer:z,limit:j,sender:v}){let $=v||await Q();if(!L(z))throw new G.SwapKitError({errorKey:"core_transaction_invalid_recipient_address",info:{address:z}});let Z=Number.parseFloat(j);if(Number.isNaN(Z)||Z<0)throw new G.SwapKitError({errorKey:"toolbox_ripple_invalid_trust_line_limit",info:{limit:j}});let M=await X(),J={Account:$,LimitAmount:{currency:m,issuer:z,value:j},TransactionType:"TrustSet"};return M.autofill(J)}async function r(m,z){let[j,v,$]=await Promise.all([m.request({account:z,command:"account_info"}),D(m),T()]),{Balance:Z,OwnerCount:M}=j.result.account_data,J=$.getBaseValue("bigint"),Y=BigInt(Z)-v.baseReserveDrops-BigInt(M)*v.ownerReserveDrops-J;if(Y<=0n)throw new G.SwapKitError({errorKey:"toolbox_sweep_amount_too_low",info:{asset:G.Chain.Ripple,balance:Z,baseReserve:v.baseReserveDrops.toString(),fee:J.toString(),ownerCount:M,ownerReserve:v.ownerReserveDrops.toString()}});let{baseDecimal:_}=G.getChainConfig(G.Chain.Ripple),H=G.AssetValue.from({chain:G.Chain.Ripple,fromBaseDecimal:_,value:Y.toString()});return{amount:await l(H),fee:J.toString()}}async function e(m,z){let j=C(m.toString());if(!j)throw new G.SwapKitError({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:m.toString()}});let v=await X(),$="0",Z;while(!0){let M=await v.request({account:z,command:"account_lines",peer:j.issuer,...Z!==void 0&&{marker:Z}}),J=M.result.lines.find((_)=>_.account===j.issuer&&N(_.currency)===N(j.currency));if(J){$=J.balance;break}let Y=M.result.marker;if(Y===void 0||Y===null)break;Z=Y}if(!Number.isFinite(Number($))||Number($)<=0)throw new G.SwapKitError({errorKey:"toolbox_sweep_amount_too_low",info:{asset:m.toString(),balance:$}});return{currency:j.currency,issuer:j.issuer,value:$}}async function g({assetValue:m,recipient:z,memo:j,sender:v,sweep:$,destinationTag:Z,extendBySeconds:M=150}){if(!L(z))throw new G.SwapKitError({errorKey:"core_transaction_invalid_recipient_address"});let J=v||await Q();if(m.chain!==G.Chain.Ripple)throw new G.SwapKitError({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:m.toString()}});let Y=$&&m.isGasAsset?await r(await X(),J):void 0,_=Y?Y.amount:$?await e(m,J):await l(m),H={Account:J,Amount:_,Destination:z,TransactionType:"Payment",...Y&&{Fee:Y.fee},...Z!==void 0&&{DestinationTag:Z}};if(j)H.Memos=[{Memo:{MemoData:Buffer.from(j).toString("hex")}}];let A=await(await X()).autofill(H);if(A.LastLedgerSequence&&M>0)A.LastLedgerSequence+=Math.ceil(M/4);return A}async function O(m){let z=await q();if(!z)throw new G.SwapKitError({errorKey:"toolbox_ripple_signer_not_found"});return z.signTransaction(m)}async function R(m){let j=await(await X()).submitAndWait(m),{result:v}=j;if(v.validated)return v.hash;let $=v.meta?.TransactionResult,Z=F.match($).with(y.tecNO_LINE,()=>"No trust line exists for this token").with(y.tecPATH_DRY,()=>"Payment path could not deliver funds").with(y.tecFROZEN,()=>"Token is frozen").otherwise(()=>{return});throw new G.SwapKitError({errorKey:"toolbox_ripple_broadcast_error",info:{chain:G.Chain.Ripple,...Z?{reason:Z}:{txResult:$}}})}let f5=async(m)=>{try{let z=await O(m);return R(z.tx_blob)}catch(z){if(z instanceof G.SwapKitError)throw z;throw new G.SwapKitError({errorKey:"toolbox_ripple_broadcast_error",info:{chain:G.Chain.Ripple,error:z}})}};async function U5({assetValue:m,memo:z,recipient:j,sweep:v}){let $=await q();if(!$)throw new G.SwapKitError({errorKey:"toolbox_ripple_signer_not_found"});let Z=await $.getAddress(),M=await g({assetValue:m,memo:z,recipient:j,sender:Z,sweep:v}),J=await O(M);return R(J.tx_blob)}async function m5(m){let z=await q();if(!z)throw new G.SwapKitError({errorKey:"toolbox_ripple_signer_not_found"});let j=await z.getAddress(),v=await h({...m,sender:j}),$=await O(v);return R($.tx_blob)}function G5(){let m=W;if(W=null,m)m.then((z)=>{if(z?.isConnected())return z.disconnect();return}).catch((z)=>{console.warn("XRPL Cleanup failed silently:",z)})}return{broadcastTransaction:R,createSigner:n,createTransaction:g,disconnect:G5,estimateTransactionFee:T,getAddress:Q,getBalance:a,getTrustLines:V,hasTrustLine:s,setTrustLine:h,setTrustLineAndBroadcast:m5,signAndBroadcastTransaction:f5,signTransaction:O,transfer:U5,validateAddress:L}}var G,w,F,_5,y;var b5=S(()=>{I();G=require("@swapkit/helpers"),w=require("ripple-address-codec"),F=require("ts-pattern");I();d();_5={ACCOUNT_NOT_FOUND:19};y={tecFROZEN:"tecFROZEN",tecNO_AUTH:"tecNO_AUTH",tecNO_DST:"tecNO_DST",tecNO_LINE:"tecNO_LINE",tecPATH_DRY:"tecPATH_DRY",tecUNFUNDED_OFFER:"tecUNFUNDED_OFFER"}});b5();
|
|
1
|
+
var z5=Object.create;var{getPrototypeOf:$5,defineProperty:k,getOwnPropertyNames:u,getOwnPropertyDescriptor:j5}=Object,p=Object.prototype.hasOwnProperty;function o(f){return this[f]}var q5,W5,k5=(f,U,q)=>{var Z=f!=null&&typeof f==="object";if(Z){var B=U?q5??=new WeakMap:W5??=new WeakMap,X=B.get(f);if(X)return X}q=f!=null?z5($5(f)):{};let D=U||!f||!f.__esModule?k(q,"default",{value:f,enumerable:!0}):q;for(let Q of u(f))if(!p.call(D,Q))k(D,Q,{get:o.bind(f,Q),enumerable:!0});if(Z)B.set(f,D);return D},Z5=(f)=>{var U=(x??=new WeakMap).get(f),q;if(U)return U;if(U=k({},"__esModule",{value:!0}),f&&typeof f==="object"||typeof f==="function"){for(var Z of u(f))if(!p.call(U,Z))k(U,Z,{get:o.bind(f,Z),enumerable:!(q=j5(f,Z))||q.enumerable})}return x.set(f,U),U},x;var v5=(f)=>f;function B5(f,U){this[f]=v5.bind(null,U)}var J5=(f,U)=>{for(var q in U)k(f,q,{get:U[q],enumerable:!0,configurable:!0,set:B5.bind(U,q)})};var S=(f,U)=>()=>(f&&(U=f(f=0)),U);function P(f){return/^[0-9A-Fa-f]{40}$/.test(f)}function N(f){if(P(f))return f.toUpperCase();if(f.length<=3){let q=Buffer.from(f.padEnd(3,"\x00")).toString("hex");return`00${"0".repeat(22)}${q}${"0".repeat(10)}`.toUpperCase()}let U=Buffer.from(f).toString("hex").toUpperCase();if(U.length>40)throw new c.SwapKitError({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:f,reason:"Currency exceeds maximum length (20 bytes)"}});return U.padEnd(40,"0")}function Y5(f){if(!P(f))return f;if(f.toUpperCase().startsWith("00")){let U=f.slice(24,30);try{let q=Buffer.from(U,"hex").toString("ascii").replace(/\0/g,"");if(/^[A-Za-z0-9?!@#$%^&*<>(){}[\]|]+$/.test(q)&&q.length>0)return q}catch{}return f.toUpperCase()}try{let U=f.replace(/0+$/,""),q=U.length%2===0?U:`${U}0`,Z=Buffer.from(q,"hex").toString("utf8");if(/^[\x20-\x7E]+$/.test(Z))return Z}catch{}return f.toUpperCase()}function F(f){if(P(f))return f.toUpperCase();if(f.length<=3)return f;return N(f)}var c;var I=S(()=>{c=require("@swapkit/helpers")});async function M5(f,U){let q=F(f),Z=E.find((B)=>F(B.currency)===q&&B.issuer===U);if(Z)return Z;try{let B=await K.RequestClient.get(`https://api.xrplmeta.org/token/${f}:${U}`);if(B)return{currency:f,decimals:15,description:B.desc,domain:B.domain,icon:B.icon,issuer:U,name:B.name,verified:B.self_assessment?.is_regulated||B.self_assessment?.is_licensed}}catch(B){K.warnOnce({condition:!0,id:`xrpl_token_lookup_${f}_${U}`,warning:`Failed to fetch XRPL token info for ${f}:${U}: ${B}`})}return{currency:f,decimals:15,issuer:U,verified:!1}}function X5(f){return E.filter((U)=>U.issuer===f)}function Q5(f,U){let q=F(f);return E.some((Z)=>F(Z.currency)===q&&Z.issuer===U)}var K,E;var d=S(()=>{I();K=require("@swapkit/helpers"),E=[{currency:"USD",decimals:15,domain:"circle.com",issuer:"rcEGREd8NmkKRE8GE424sksyt1tJVFZwu",name:"Circle USDC",verified:!0},{currency:"RLUSD",decimals:15,domain:"ripple.com",issuer:"rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De",name:"Ripple USD",verified:!0},{currency:"USD",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp USD",verified:!0},{currency:"BTC",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp BTC",verified:!0},{currency:"EUR",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp EUR",verified:!0},{currency:"USD",decimals:15,domain:"gatehub.net",issuer:"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq",name:"GateHub USD",verified:!0},{currency:"EUR",decimals:15,domain:"gatehub.net",issuer:"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq",name:"GateHub EUR",verified:!0},{currency:"BTC",decimals:15,domain:"gatehub.net",issuer:"rchGBxcD1A1C2tdxF6papQYZ8kjRKMYcL",name:"GateHub BTC",verified:!0},{currency:"ETH",decimals:15,domain:"gatehub.net",issuer:"rcA8X3TVMST1n3CJeAdGk1RdRCHii7N2h",name:"GateHub ETH",verified:!0},{currency:"SOLO",decimals:15,domain:"sologenic.com",issuer:"rsoLo2S1kiGeCcn6hCUXVrCpGMWLrRrLZz",name:"Sologenic",verified:!0}]});var D5={};J5(D5,{validateRippleAddress:()=>L,parseXrplTokenIdentifier:()=>C,normalizeCurrency:()=>F,isKnownToken:()=>Q5,isHexCurrency:()=>P,hexToCurrency:()=>Y5,getXrplTokenInfo:()=>M5,getRippleToolbox:()=>N5,getKnownTokensByIssuer:()=>X5,formatXrplTokenIdentifier:()=>t,currencyToHex:()=>N,XRPL_TOKEN_ERROR_CODES:()=>y,XRPL_KNOWN_TOKENS:()=>E});module.exports=Z5(D5);function i(f){if(typeof f!=="object"||f===null||!("data"in f))return!1;let{data:U}=f;return typeof U==="object"&&U!==null&&"error_code"in U&&U.error_code===_5.ACCOUNT_NOT_FOUND}function C(f){let U=f.match(/^XRP\.([A-Fa-f0-9]{40}|[\x20-\x7E]{1,20})-([a-zA-Z0-9]{25,34})$/);if(!U?.[1]||!U?.[2])return null;if(!L(U[2]))return null;return{currency:U[1],issuer:U[2]}}function t(f,U){return`${G.Chain.Ripple}.${f}-${U}`}async function l(f){if(f.isGasAsset){let{xrpToDrops:q}=await import("xrpl");return q(f.getValue("string"))}let U=C(f.toString());if(!U)throw new G.SwapKitError({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:f.toString()}});return{currency:U.currency,issuer:U.issuer,value:f.getValue("string")}}function n(f){let U,q=()=>{return U??=import("xrpl").then(({Wallet:Z})=>Z.fromMnemonic(f)),U};return{getAddress:async()=>(await q()).address,signTransaction:async(Z)=>(await q()).sign(Z)}}function L(f){return w.isValidClassicAddress(f)||w.isValidXAddress(f)}function N5(f={}){let U;async function q(){if(U)return U;return U=await b.match(f).with({phrase:b.P.string},({phrase:m})=>n(m)).with({signer:b.P.any},({signer:m})=>m).otherwise(()=>{return}),U}let Z;async function B(){let m=await G.getRPCUrl(G.Chain.Ripple);if(!m)throw new G.SwapKitError({errorKey:"toolbox_ripple_rpc_not_configured",info:{chain:G.Chain.Ripple}});let{Client:z}=await import("xrpl"),j=new z(m);return await j.connect(),j}async function X(){if(Z){let m=await Z.catch(()=>null);if(m?.isConnected())return m}return Z=B(),Z}async function D(m){let z=await m.request({command:"server_state"}),j=z.result.state.validated_ledger??z.result.state.closed_ledger;if(!j||!Number.isSafeInteger(j.reserve_base)||j.reserve_base<0||!Number.isSafeInteger(j.reserve_inc)||j.reserve_inc<0)throw new G.SwapKitError({errorKey:"toolbox_ripple_get_balance_error",info:{reason:"XRPL reserve data is unavailable or invalid"}});return{baseReserveDrops:BigInt(j.reserve_base),ownerReserveDrops:BigInt(j.reserve_inc)}}let Q=async()=>{let m=await q();if(!m)throw new G.SwapKitError({errorKey:"toolbox_ripple_signer_not_found"});return m.getAddress()},a=async(m)=>{let z=m||await Q(),{baseDecimal:j}=G.getChainConfig(G.Chain.Ripple),W=await X();try{let[$,v]=await Promise.all([W.request({account:z,command:"account_info"}),W.request({account:z,command:"account_lines"})]),M=$.result.account_data.Balance,J=[G.AssetValue.from({chain:G.Chain.Ripple,fromBaseDecimal:j,value:M})];for(let Y of v.result.lines){let _=t(Y.currency,Y.account);if(Number.parseFloat(Y.balance)!==0)J.push(G.AssetValue.from({asset:_,asyncTokenLookup:!1,value:Y.balance}))}return J}catch($){if(i($))return[G.AssetValue.from({chain:G.Chain.Ripple,value:0})];throw new G.SwapKitError({errorKey:"toolbox_ripple_get_balance_error",info:{address:z,error:$}})}},T=async()=>{let{baseDecimal:m}=G.getChainConfig(G.Chain.Ripple),W=(await(await X()).request({command:"fee"})).result.drops.open_ledger_fee;return G.AssetValue.from({chain:G.Chain.Ripple,fromBaseDecimal:m,value:W})};async function V(m){let z=m||await Q(),j=await X();try{return(await j.request({account:z,command:"account_lines"})).result.lines.map(($)=>({account:$.account,authorized:$.authorized??!1,balance:$.balance,currency:$.currency,freeze:$.freeze??!1,freezePeer:$.freeze_peer??!1,limit:$.limit,limitPeer:$.limit_peer,noRipple:$.no_ripple??!1,noRipplePeer:$.no_ripple_peer??!1,peerAuthorized:$.peer_authorized??!1,qualityIn:$.quality_in??0,qualityOut:$.quality_out??0}))}catch(W){if(i(W))return[];throw new G.SwapKitError({errorKey:"toolbox_ripple_get_trust_lines_error",info:{address:z,error:W}})}}async function s({address:m,currency:z,issuer:j}){let W=await V(m),$=N(z);return W.some((v)=>{return N(v.currency)===$&&v.account===j})}async function h({currency:m,issuer:z,limit:j,sender:W}){let $=W||await Q();if(!L(z))throw new G.SwapKitError({errorKey:"core_transaction_invalid_recipient_address",info:{address:z}});let v=Number.parseFloat(j);if(Number.isNaN(v)||v<0)throw new G.SwapKitError({errorKey:"toolbox_ripple_invalid_trust_line_limit",info:{limit:j}});let M=await X(),J={Account:$,LimitAmount:{currency:m,issuer:z,value:j},TransactionType:"TrustSet"};return M.autofill(J)}async function r(m,z){let[j,W,$]=await Promise.all([m.request({account:z,command:"account_info"}),D(m),T()]),{Balance:v,OwnerCount:M}=j.result.account_data,J=$.getBaseValue("bigint"),Y=BigInt(v)-W.baseReserveDrops-BigInt(M)*W.ownerReserveDrops-J;if(Y<=0n)throw new G.SwapKitError({errorKey:"toolbox_sweep_amount_too_low",info:{asset:G.Chain.Ripple,balance:v,baseReserve:W.baseReserveDrops.toString(),fee:J.toString(),ownerCount:M,ownerReserve:W.ownerReserveDrops.toString()}});let{baseDecimal:_}=G.getChainConfig(G.Chain.Ripple),H=G.AssetValue.from({chain:G.Chain.Ripple,fromBaseDecimal:_,value:Y.toString()});return{amount:await l(H),fee:J.toString()}}async function e(m,z){let j=C(m.toString());if(!j)throw new G.SwapKitError({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:m.toString()}});let W=await X(),$="0",v;while(!0){let M=await W.request({account:z,command:"account_lines",peer:j.issuer,...v!==void 0&&{marker:v}}),J=M.result.lines.find((_)=>_.account===j.issuer&&N(_.currency)===N(j.currency));if(J){$=J.balance;break}let Y=M.result.marker;if(Y===void 0||Y===null)break;v=Y}if(!Number.isFinite(Number($))||Number($)<=0)throw new G.SwapKitError({errorKey:"toolbox_sweep_amount_too_low",info:{asset:m.toString(),balance:$}});return{currency:j.currency,issuer:j.issuer,value:$}}async function g({assetValue:m,recipient:z,memo:j,sender:W,sweep:$,destinationTag:v,extendBySeconds:M=150}){if(!L(z))throw new G.SwapKitError({errorKey:"core_transaction_invalid_recipient_address"});let J=W||await Q();if(m.chain!==G.Chain.Ripple)throw new G.SwapKitError({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:m.toString()}});let Y=$&&m.isGasAsset?await r(await X(),J):void 0,_=Y?Y.amount:$?await e(m,J):await l(m),H={Account:J,Amount:_,Destination:z,TransactionType:"Payment",...Y&&{Fee:Y.fee},...v!==void 0&&{DestinationTag:v}};if(j)H.Memos=[{Memo:{MemoData:Buffer.from(j).toString("hex")}}];let A=await(await X()).autofill(H);if(A.LastLedgerSequence&&M>0)A.LastLedgerSequence+=Math.ceil(M/4);return A}async function O(m){let z=await q();if(!z)throw new G.SwapKitError({errorKey:"toolbox_ripple_signer_not_found"});return z.signTransaction(m)}async function R(m){let j=await(await X()).submitAndWait(m),{result:W}=j;if(W.validated)return W.hash;let $=W.meta?.TransactionResult,v=b.match($).with(y.tecNO_LINE,()=>"No trust line exists for this token").with(y.tecPATH_DRY,()=>"Payment path could not deliver funds").with(y.tecFROZEN,()=>"Token is frozen").otherwise(()=>{return});throw new G.SwapKitError({errorKey:"toolbox_ripple_broadcast_error",info:{chain:G.Chain.Ripple,...v?{reason:v}:{txResult:$}}})}let f5=async(m)=>{try{let z=await O(m);return R(z.tx_blob)}catch(z){if(z instanceof G.SwapKitError)throw z;throw new G.SwapKitError({errorKey:"toolbox_ripple_broadcast_error",info:{chain:G.Chain.Ripple,error:z}})}};async function U5({assetValue:m,memo:z,recipient:j,sweep:W}){let $=await q();if(!$)throw new G.SwapKitError({errorKey:"toolbox_ripple_signer_not_found"});let v=await $.getAddress(),M=await g({assetValue:m,memo:z,recipient:j,sender:v,sweep:W}),J=await O(M);return R(J.tx_blob)}async function m5(m){let z=await q();if(!z)throw new G.SwapKitError({errorKey:"toolbox_ripple_signer_not_found"});let j=await z.getAddress(),W=await h({...m,sender:j}),$=await O(W);return R($.tx_blob)}function G5(){let m=Z;if(Z=null,m)m.then((z)=>{if(z?.isConnected())return z.disconnect();return}).catch((z)=>{console.warn("XRPL Cleanup failed silently:",z)})}return{broadcastTransaction:R,createSigner:n,createTransaction:g,disconnect:G5,estimateTransactionFee:T,getAddress:Q,getBalance:a,getTrustLines:V,hasTrustLine:s,setTrustLine:h,setTrustLineAndBroadcast:m5,signAndBroadcastTransaction:f5,signTransaction:O,transfer:U5,validateAddress:L}}var G,w,b,_5,y;var F5=S(()=>{I();G=require("@swapkit/helpers"),w=require("ripple-address-codec"),b=require("ts-pattern");I();d();_5={ACCOUNT_NOT_FOUND:19};y={tecFROZEN:"tecFROZEN",tecNO_AUTH:"tecNO_AUTH",tecNO_DST:"tecNO_DST",tecNO_LINE:"tecNO_LINE",tecPATH_DRY:"tecPATH_DRY",tecUNFUNDED_OFFER:"tecUNFUNDED_OFFER"}});F5();
|
package/dist/src/ripple/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ga as y}from"../../chunk-xbdjxeqd.js";import{AssetValue as F,Chain as X,getChainConfig as K,getRPCUrl as f5,SwapKitError as Z}from"@swapkit/helpers";import{isValidClassicAddress as U5,isValidXAddress as m5}from"ripple-address-codec";import{match as T,P as V}from"ts-pattern";import{SwapKitError as s}from"@swapkit/helpers";function P(f){return/^[0-9A-Fa-f]{40}$/.test(f)}function N(f){if(P(f))return f.toUpperCase();if(f.length<=3){let v=Buffer.from(f.padEnd(3,"\x00")).toString("hex");return`00${"0".repeat(22)}${v}${"0".repeat(10)}`.toUpperCase()}let G=Buffer.from(f).toString("hex").toUpperCase();if(G.length>40)throw new s({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:f,reason:"Currency exceeds maximum length (20 bytes)"}});return G.padEnd(40,"0")}function q5(f){if(!P(f))return f;if(f.toUpperCase().startsWith("00")){let G=f.slice(24,30);try{let v=Buffer.from(G,"hex").toString("ascii").replace(/\0/g,"");if(/^[A-Za-z0-9?!@#$%^&*<>(){}[\]|]+$/.test(v)&&v.length>0)return v}catch{}return f.toUpperCase()}try{let G=f.replace(/0+$/,""),v=G.length%2===0?G:`${G}0`,W=Buffer.from(v,"hex").toString("utf8");if(/^[\x20-\x7E]+$/.test(W))return W}catch{}return f.toUpperCase()}function b(f){if(P(f))return f.toUpperCase();if(f.length<=3)return f;return N(f)}import{RequestClient as r,warnOnce as e}from"@swapkit/helpers";var I=[{currency:"USD",decimals:15,domain:"circle.com",issuer:"rcEGREd8NmkKRE8GE424sksyt1tJVFZwu",name:"Circle USDC",verified:!0},{currency:"RLUSD",decimals:15,domain:"ripple.com",issuer:"rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De",name:"Ripple USD",verified:!0},{currency:"USD",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp USD",verified:!0},{currency:"BTC",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp BTC",verified:!0},{currency:"EUR",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp EUR",verified:!0},{currency:"USD",decimals:15,domain:"gatehub.net",issuer:"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq",name:"GateHub USD",verified:!0},{currency:"EUR",decimals:15,domain:"gatehub.net",issuer:"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq",name:"GateHub EUR",verified:!0},{currency:"BTC",decimals:15,domain:"gatehub.net",issuer:"rchGBxcD1A1C2tdxF6papQYZ8kjRKMYcL",name:"GateHub BTC",verified:!0},{currency:"ETH",decimals:15,domain:"gatehub.net",issuer:"rcA8X3TVMST1n3CJeAdGk1RdRCHii7N2h",name:"GateHub ETH",verified:!0},{currency:"SOLO",decimals:15,domain:"sologenic.com",issuer:"rsoLo2S1kiGeCcn6hCUXVrCpGMWLrRrLZz",name:"Sologenic",verified:!0}];async function B5(f,G){let v=b(f),W=I.find((M)=>b(M.currency)===v&&M.issuer===G);if(W)return W;try{let M=await r.get(`https://api.xrplmeta.org/token/${f}:${G}`);if(M)return{currency:f,decimals:15,description:M.desc,domain:M.domain,icon:M.icon,issuer:G,name:M.name,verified:M.self_assessment?.is_regulated||M.self_assessment?.is_licensed}}catch(M){e({condition:!0,id:`xrpl_token_lookup_${f}_${G}`,warning:`Failed to fetch XRPL token info for ${f}:${G}: ${M}`})}return{currency:f,decimals:15,issuer:G,verified:!1}}function J5(f){return I.filter((G)=>G.issuer===f)}function Y5(f,G){let v=b(f);return I.some((W)=>b(W.currency)===v&&W.issuer===G)}var G5={ACCOUNT_NOT_FOUND:19};function h(f){if(typeof f!=="object"||f===null||!("data"in f))return!1;let{data:G}=f;return typeof G==="object"&&G!==null&&"error_code"in G&&G.error_code===G5.ACCOUNT_NOT_FOUND}var E={tecFROZEN:"tecFROZEN",tecNO_AUTH:"tecNO_AUTH",tecNO_DST:"tecNO_DST",tecNO_LINE:"tecNO_LINE",tecPATH_DRY:"tecPATH_DRY",tecUNFUNDED_OFFER:"tecUNFUNDED_OFFER"};function u(f){let G=f.match(/^XRP\.([A-Fa-f0-9]{40}|[\x20-\x7E]{1,20})-([a-zA-Z0-9]{25,34})$/);if(!G?.[1]||!G?.[2])return null;if(!R(G[2]))return null;return{currency:G[1],issuer:G[2]}}function z5(f,G){return`${X.Ripple}.${f}-${G}`}async function g(f){if(f.isGasAsset){let{xrpToDrops:v}=await import("xrpl");return v(f.getValue("string"))}let G=u(f.toString());if(!G)throw new Z({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:f.toString()}});return{currency:G.currency,issuer:G.issuer,value:f.getValue("string")}}function x(f){let G,v=()=>{return G??=import("xrpl").then(({Wallet:W})=>W.fromMnemonic(f)),G};return{getAddress:async()=>(await v()).address,signTransaction:async(W)=>(await v()).sign(W)}}function R(f){return U5(f)||m5(f)}function D5(f={}){let G;async function v(){if(G)return G;return G=await T(f).with({phrase:V.string},({phrase:U})=>x(U)).with({signer:V.any},({signer:U})=>U).otherwise(()=>{return}),G}let W;async function M(){let U=await f5(X.Ripple);if(!U)throw new Z({errorKey:"toolbox_ripple_rpc_not_configured",info:{chain:X.Ripple}});let{Client:m}=await import("xrpl"),$=new m(U);return await $.connect(),$}async function Q(){if(W){let U=await W.catch(()=>null);if(U?.isConnected())return U}return W=M(),W}async function p(U){let m=await U.request({command:"server_state"}),$=m.result.state.validated_ledger??m.result.state.closed_ledger;if(!$||!Number.isSafeInteger($.reserve_base)||$.reserve_base<0||!Number.isSafeInteger($.reserve_inc)||$.reserve_inc<0)throw new Z({errorKey:"toolbox_ripple_get_balance_error",info:{reason:"XRPL reserve data is unavailable or invalid"}});return{baseReserveDrops:BigInt($.reserve_base),ownerReserveDrops:BigInt($.reserve_inc)}}let D=async()=>{let U=await v();if(!U)throw new Z({errorKey:"toolbox_ripple_signer_not_found"});return U.getAddress()},o=async(U)=>{let m=U||await D(),{baseDecimal:$}=K(X.Ripple),j=await Q();try{let[z,q]=await Promise.all([j.request({account:m,command:"account_info"}),j.request({account:m,command:"account_lines"})]),Y=z.result.account_data.Balance,B=[F.from({chain:X.Ripple,fromBaseDecimal:$,value:Y})];for(let J of q.result.lines){let _=z5(J.currency,J.account);if(Number.parseFloat(J.balance)!==0)B.push(F.from({asset:_,asyncTokenLookup:!1,value:J.balance}))}return B}catch(z){if(h(z))return[F.from({chain:X.Ripple,value:0})];throw new Z({errorKey:"toolbox_ripple_get_balance_error",info:{address:m,error:z}})}},w=async()=>{let{baseDecimal:U}=K(X.Ripple),j=(await(await Q()).request({command:"fee"})).result.drops.open_ledger_fee;return F.from({chain:X.Ripple,fromBaseDecimal:U,value:j})};async function A(U){let m=U||await D(),$=await Q();try{return(await $.request({account:m,command:"account_lines"})).result.lines.map((z)=>({account:z.account,authorized:z.authorized??!1,balance:z.balance,currency:z.currency,freeze:z.freeze??!1,freezePeer:z.freeze_peer??!1,limit:z.limit,limitPeer:z.limit_peer,noRipple:z.no_ripple??!1,noRipplePeer:z.no_ripple_peer??!1,peerAuthorized:z.peer_authorized??!1,qualityIn:z.quality_in??0,qualityOut:z.quality_out??0}))}catch(j){if(h(j))return[];throw new Z({errorKey:"toolbox_ripple_get_trust_lines_error",info:{address:m,error:j}})}}async function c({address:U,currency:m,issuer:$}){let j=await A(U),z=N(m);return j.some((q)=>{return N(q.currency)===z&&q.account===$})}async function S({currency:U,issuer:m,limit:$,sender:j}){let z=j||await D();if(!R(m))throw new Z({errorKey:"core_transaction_invalid_recipient_address",info:{address:m}});let q=Number.parseFloat($);if(Number.isNaN(q)||q<0)throw new Z({errorKey:"toolbox_ripple_invalid_trust_line_limit",info:{limit:$}});let Y=await Q(),B={Account:z,LimitAmount:{currency:U,issuer:m,value:$},TransactionType:"TrustSet"};return Y.autofill(B)}async function d(U,m){let[$,j,z]=await Promise.all([U.request({account:m,command:"account_info"}),p(U),w()]),{Balance:q,OwnerCount:Y}=$.result.account_data,B=z.getBaseValue("bigint"),J=BigInt(q)-j.baseReserveDrops-BigInt(Y)*j.ownerReserveDrops-B;if(J<=0n)throw new Z({errorKey:"toolbox_sweep_amount_too_low",info:{asset:X.Ripple,balance:q,baseReserve:j.baseReserveDrops.toString(),fee:B.toString(),ownerCount:Y,ownerReserve:j.ownerReserveDrops.toString()}});let{baseDecimal:_}=K(X.Ripple),O=F.from({chain:X.Ripple,fromBaseDecimal:_,value:J.toString()});return{amount:await g(O),fee:B.toString()}}async function i(U,m){let $=u(U.toString());if(!$)throw new Z({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:U.toString()}});let j=await Q(),z="0",q;while(!0){let Y=await j.request({account:m,command:"account_lines",peer:$.issuer,...q!==void 0&&{marker:q}}),B=Y.result.lines.find((_)=>_.account===$.issuer&&N(_.currency)===N($.currency));if(B){z=B.balance;break}let J=Y.result.marker;if(J===void 0||J===null)break;q=J}if(!Number.isFinite(Number(z))||Number(z)<=0)throw new Z({errorKey:"toolbox_sweep_amount_too_low",info:{asset:U.toString(),balance:z}});return{currency:$.currency,issuer:$.issuer,value:z}}async function C({assetValue:U,recipient:m,memo:$,sender:j,sweep:z,destinationTag:q,extendBySeconds:Y=150}){if(!R(m))throw new Z({errorKey:"core_transaction_invalid_recipient_address"});let B=j||await D();if(U.chain!==X.Ripple)throw new Z({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:U.toString()}});let J=z&&U.isGasAsset?await d(await Q(),B):void 0,_=J?J.amount:z?await i(U,B):await g(U),O={Account:B,Amount:_,Destination:m,TransactionType:"Payment",...J&&{Fee:J.fee},...q!==void 0&&{DestinationTag:q}};if($)O.Memos=[{Memo:{MemoData:Buffer.from($).toString("hex")}}];let H=await(await Q()).autofill(O);if(H.LastLedgerSequence&&Y>0)H.LastLedgerSequence+=Math.ceil(Y/4);return H}async function k(U){let m=await v();if(!m)throw new Z({errorKey:"toolbox_ripple_signer_not_found"});return m.signTransaction(U)}async function L(U){let $=await(await Q()).submitAndWait(U),{result:j}=$;if(j.validated)return j.hash;let z=j.meta?.TransactionResult,q=T(z).with(E.tecNO_LINE,()=>"No trust line exists for this token").with(E.tecPATH_DRY,()=>"Payment path could not deliver funds").with(E.tecFROZEN,()=>"Token is frozen").otherwise(()=>{return});throw new Z({errorKey:"toolbox_ripple_broadcast_error",info:{chain:X.Ripple,...q?{reason:q}:{txResult:z}}})}let l=async(U)=>{try{let m=await k(U);return L(m.tx_blob)}catch(m){if(m instanceof Z)throw m;throw new Z({errorKey:"toolbox_ripple_broadcast_error",info:{chain:X.Ripple,error:m}})}};async function n({assetValue:U,memo:m,recipient:$,sweep:j}){let z=await v();if(!z)throw new Z({errorKey:"toolbox_ripple_signer_not_found"});let q=await z.getAddress(),Y=await C({assetValue:U,memo:m,recipient:$,sender:q,sweep:j}),B=await k(Y);return L(B.tx_blob)}async function t(U){let m=await v();if(!m)throw new Z({errorKey:"toolbox_ripple_signer_not_found"});let $=await m.getAddress(),j=await S({...U,sender:$}),z=await k(j);return L(z.tx_blob)}function a(){let U=W;if(W=null,U)U.then((m)=>{if(m?.isConnected())return m.disconnect();return}).catch((m)=>{console.warn("XRPL Cleanup failed silently:",m)})}return{broadcastTransaction:L,createSigner:x,createTransaction:C,disconnect:a,estimateTransactionFee:w,getAddress:D,getBalance:o,getTrustLines:A,hasTrustLine:c,setTrustLine:S,setTrustLineAndBroadcast:t,signAndBroadcastTransaction:l,signTransaction:k,transfer:n,validateAddress:R}}export{R as validateRippleAddress,u as parseXrplTokenIdentifier,b as normalizeCurrency,Y5 as isKnownToken,P as isHexCurrency,q5 as hexToCurrency,B5 as getXrplTokenInfo,D5 as getRippleToolbox,J5 as getKnownTokensByIssuer,z5 as formatXrplTokenIdentifier,N as currencyToHex,E as XRPL_TOKEN_ERROR_CODES,I as XRPL_KNOWN_TOKENS};
|
|
1
|
+
import{ga as y}from"../../chunk-xbdjxeqd.js";import{AssetValue as b,Chain as X,getChainConfig as K,getRPCUrl as f5,SwapKitError as v}from"@swapkit/helpers";import{isValidClassicAddress as U5,isValidXAddress as m5}from"ripple-address-codec";import{match as T,P as V}from"ts-pattern";import{SwapKitError as s}from"@swapkit/helpers";function P(f){return/^[0-9A-Fa-f]{40}$/.test(f)}function N(f){if(P(f))return f.toUpperCase();if(f.length<=3){let W=Buffer.from(f.padEnd(3,"\x00")).toString("hex");return`00${"0".repeat(22)}${W}${"0".repeat(10)}`.toUpperCase()}let G=Buffer.from(f).toString("hex").toUpperCase();if(G.length>40)throw new s({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:f,reason:"Currency exceeds maximum length (20 bytes)"}});return G.padEnd(40,"0")}function q5(f){if(!P(f))return f;if(f.toUpperCase().startsWith("00")){let G=f.slice(24,30);try{let W=Buffer.from(G,"hex").toString("ascii").replace(/\0/g,"");if(/^[A-Za-z0-9?!@#$%^&*<>(){}[\]|]+$/.test(W)&&W.length>0)return W}catch{}return f.toUpperCase()}try{let G=f.replace(/0+$/,""),W=G.length%2===0?G:`${G}0`,Z=Buffer.from(W,"hex").toString("utf8");if(/^[\x20-\x7E]+$/.test(Z))return Z}catch{}return f.toUpperCase()}function F(f){if(P(f))return f.toUpperCase();if(f.length<=3)return f;return N(f)}import{RequestClient as r,warnOnce as e}from"@swapkit/helpers";var I=[{currency:"USD",decimals:15,domain:"circle.com",issuer:"rcEGREd8NmkKRE8GE424sksyt1tJVFZwu",name:"Circle USDC",verified:!0},{currency:"RLUSD",decimals:15,domain:"ripple.com",issuer:"rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De",name:"Ripple USD",verified:!0},{currency:"USD",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp USD",verified:!0},{currency:"BTC",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp BTC",verified:!0},{currency:"EUR",decimals:15,domain:"bitstamp.net",issuer:"rvYAfWj5gh67oV6fW32ZzP3Aw4Eubs59B",name:"Bitstamp EUR",verified:!0},{currency:"USD",decimals:15,domain:"gatehub.net",issuer:"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq",name:"GateHub USD",verified:!0},{currency:"EUR",decimals:15,domain:"gatehub.net",issuer:"rhub8VRN55s94qWKDv6jmDy1pUykJzF3wq",name:"GateHub EUR",verified:!0},{currency:"BTC",decimals:15,domain:"gatehub.net",issuer:"rchGBxcD1A1C2tdxF6papQYZ8kjRKMYcL",name:"GateHub BTC",verified:!0},{currency:"ETH",decimals:15,domain:"gatehub.net",issuer:"rcA8X3TVMST1n3CJeAdGk1RdRCHii7N2h",name:"GateHub ETH",verified:!0},{currency:"SOLO",decimals:15,domain:"sologenic.com",issuer:"rsoLo2S1kiGeCcn6hCUXVrCpGMWLrRrLZz",name:"Sologenic",verified:!0}];async function B5(f,G){let W=F(f),Z=I.find((M)=>F(M.currency)===W&&M.issuer===G);if(Z)return Z;try{let M=await r.get(`https://api.xrplmeta.org/token/${f}:${G}`);if(M)return{currency:f,decimals:15,description:M.desc,domain:M.domain,icon:M.icon,issuer:G,name:M.name,verified:M.self_assessment?.is_regulated||M.self_assessment?.is_licensed}}catch(M){e({condition:!0,id:`xrpl_token_lookup_${f}_${G}`,warning:`Failed to fetch XRPL token info for ${f}:${G}: ${M}`})}return{currency:f,decimals:15,issuer:G,verified:!1}}function J5(f){return I.filter((G)=>G.issuer===f)}function Y5(f,G){let W=F(f);return I.some((Z)=>F(Z.currency)===W&&Z.issuer===G)}var G5={ACCOUNT_NOT_FOUND:19};function h(f){if(typeof f!=="object"||f===null||!("data"in f))return!1;let{data:G}=f;return typeof G==="object"&&G!==null&&"error_code"in G&&G.error_code===G5.ACCOUNT_NOT_FOUND}var E={tecFROZEN:"tecFROZEN",tecNO_AUTH:"tecNO_AUTH",tecNO_DST:"tecNO_DST",tecNO_LINE:"tecNO_LINE",tecPATH_DRY:"tecPATH_DRY",tecUNFUNDED_OFFER:"tecUNFUNDED_OFFER"};function u(f){let G=f.match(/^XRP\.([A-Fa-f0-9]{40}|[\x20-\x7E]{1,20})-([a-zA-Z0-9]{25,34})$/);if(!G?.[1]||!G?.[2])return null;if(!R(G[2]))return null;return{currency:G[1],issuer:G[2]}}function z5(f,G){return`${X.Ripple}.${f}-${G}`}async function g(f){if(f.isGasAsset){let{xrpToDrops:W}=await import("xrpl");return W(f.getValue("string"))}let G=u(f.toString());if(!G)throw new v({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:f.toString()}});return{currency:G.currency,issuer:G.issuer,value:f.getValue("string")}}function x(f){let G,W=()=>{return G??=import("xrpl").then(({Wallet:Z})=>Z.fromMnemonic(f)),G};return{getAddress:async()=>(await W()).address,signTransaction:async(Z)=>(await W()).sign(Z)}}function R(f){return U5(f)||m5(f)}function D5(f={}){let G;async function W(){if(G)return G;return G=await T(f).with({phrase:V.string},({phrase:U})=>x(U)).with({signer:V.any},({signer:U})=>U).otherwise(()=>{return}),G}let Z;async function M(){let U=await f5(X.Ripple);if(!U)throw new v({errorKey:"toolbox_ripple_rpc_not_configured",info:{chain:X.Ripple}});let{Client:m}=await import("xrpl"),$=new m(U);return await $.connect(),$}async function Q(){if(Z){let U=await Z.catch(()=>null);if(U?.isConnected())return U}return Z=M(),Z}async function p(U){let m=await U.request({command:"server_state"}),$=m.result.state.validated_ledger??m.result.state.closed_ledger;if(!$||!Number.isSafeInteger($.reserve_base)||$.reserve_base<0||!Number.isSafeInteger($.reserve_inc)||$.reserve_inc<0)throw new v({errorKey:"toolbox_ripple_get_balance_error",info:{reason:"XRPL reserve data is unavailable or invalid"}});return{baseReserveDrops:BigInt($.reserve_base),ownerReserveDrops:BigInt($.reserve_inc)}}let D=async()=>{let U=await W();if(!U)throw new v({errorKey:"toolbox_ripple_signer_not_found"});return U.getAddress()},o=async(U)=>{let m=U||await D(),{baseDecimal:$}=K(X.Ripple),j=await Q();try{let[z,q]=await Promise.all([j.request({account:m,command:"account_info"}),j.request({account:m,command:"account_lines"})]),Y=z.result.account_data.Balance,B=[b.from({chain:X.Ripple,fromBaseDecimal:$,value:Y})];for(let J of q.result.lines){let _=z5(J.currency,J.account);if(Number.parseFloat(J.balance)!==0)B.push(b.from({asset:_,asyncTokenLookup:!1,value:J.balance}))}return B}catch(z){if(h(z))return[b.from({chain:X.Ripple,value:0})];throw new v({errorKey:"toolbox_ripple_get_balance_error",info:{address:m,error:z}})}},w=async()=>{let{baseDecimal:U}=K(X.Ripple),j=(await(await Q()).request({command:"fee"})).result.drops.open_ledger_fee;return b.from({chain:X.Ripple,fromBaseDecimal:U,value:j})};async function A(U){let m=U||await D(),$=await Q();try{return(await $.request({account:m,command:"account_lines"})).result.lines.map((z)=>({account:z.account,authorized:z.authorized??!1,balance:z.balance,currency:z.currency,freeze:z.freeze??!1,freezePeer:z.freeze_peer??!1,limit:z.limit,limitPeer:z.limit_peer,noRipple:z.no_ripple??!1,noRipplePeer:z.no_ripple_peer??!1,peerAuthorized:z.peer_authorized??!1,qualityIn:z.quality_in??0,qualityOut:z.quality_out??0}))}catch(j){if(h(j))return[];throw new v({errorKey:"toolbox_ripple_get_trust_lines_error",info:{address:m,error:j}})}}async function c({address:U,currency:m,issuer:$}){let j=await A(U),z=N(m);return j.some((q)=>{return N(q.currency)===z&&q.account===$})}async function S({currency:U,issuer:m,limit:$,sender:j}){let z=j||await D();if(!R(m))throw new v({errorKey:"core_transaction_invalid_recipient_address",info:{address:m}});let q=Number.parseFloat($);if(Number.isNaN(q)||q<0)throw new v({errorKey:"toolbox_ripple_invalid_trust_line_limit",info:{limit:$}});let Y=await Q(),B={Account:z,LimitAmount:{currency:U,issuer:m,value:$},TransactionType:"TrustSet"};return Y.autofill(B)}async function d(U,m){let[$,j,z]=await Promise.all([U.request({account:m,command:"account_info"}),p(U),w()]),{Balance:q,OwnerCount:Y}=$.result.account_data,B=z.getBaseValue("bigint"),J=BigInt(q)-j.baseReserveDrops-BigInt(Y)*j.ownerReserveDrops-B;if(J<=0n)throw new v({errorKey:"toolbox_sweep_amount_too_low",info:{asset:X.Ripple,balance:q,baseReserve:j.baseReserveDrops.toString(),fee:B.toString(),ownerCount:Y,ownerReserve:j.ownerReserveDrops.toString()}});let{baseDecimal:_}=K(X.Ripple),O=b.from({chain:X.Ripple,fromBaseDecimal:_,value:J.toString()});return{amount:await g(O),fee:B.toString()}}async function i(U,m){let $=u(U.toString());if(!$)throw new v({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:U.toString()}});let j=await Q(),z="0",q;while(!0){let Y=await j.request({account:m,command:"account_lines",peer:$.issuer,...q!==void 0&&{marker:q}}),B=Y.result.lines.find((_)=>_.account===$.issuer&&N(_.currency)===N($.currency));if(B){z=B.balance;break}let J=Y.result.marker;if(J===void 0||J===null)break;q=J}if(!Number.isFinite(Number(z))||Number(z)<=0)throw new v({errorKey:"toolbox_sweep_amount_too_low",info:{asset:U.toString(),balance:z}});return{currency:$.currency,issuer:$.issuer,value:z}}async function C({assetValue:U,recipient:m,memo:$,sender:j,sweep:z,destinationTag:q,extendBySeconds:Y=150}){if(!R(m))throw new v({errorKey:"core_transaction_invalid_recipient_address"});let B=j||await D();if(U.chain!==X.Ripple)throw new v({errorKey:"toolbox_ripple_asset_not_supported",info:{asset:U.toString()}});let J=z&&U.isGasAsset?await d(await Q(),B):void 0,_=J?J.amount:z?await i(U,B):await g(U),O={Account:B,Amount:_,Destination:m,TransactionType:"Payment",...J&&{Fee:J.fee},...q!==void 0&&{DestinationTag:q}};if($)O.Memos=[{Memo:{MemoData:Buffer.from($).toString("hex")}}];let H=await(await Q()).autofill(O);if(H.LastLedgerSequence&&Y>0)H.LastLedgerSequence+=Math.ceil(Y/4);return H}async function k(U){let m=await W();if(!m)throw new v({errorKey:"toolbox_ripple_signer_not_found"});return m.signTransaction(U)}async function L(U){let $=await(await Q()).submitAndWait(U),{result:j}=$;if(j.validated)return j.hash;let z=j.meta?.TransactionResult,q=T(z).with(E.tecNO_LINE,()=>"No trust line exists for this token").with(E.tecPATH_DRY,()=>"Payment path could not deliver funds").with(E.tecFROZEN,()=>"Token is frozen").otherwise(()=>{return});throw new v({errorKey:"toolbox_ripple_broadcast_error",info:{chain:X.Ripple,...q?{reason:q}:{txResult:z}}})}let l=async(U)=>{try{let m=await k(U);return L(m.tx_blob)}catch(m){if(m instanceof v)throw m;throw new v({errorKey:"toolbox_ripple_broadcast_error",info:{chain:X.Ripple,error:m}})}};async function n({assetValue:U,memo:m,recipient:$,sweep:j}){let z=await W();if(!z)throw new v({errorKey:"toolbox_ripple_signer_not_found"});let q=await z.getAddress(),Y=await C({assetValue:U,memo:m,recipient:$,sender:q,sweep:j}),B=await k(Y);return L(B.tx_blob)}async function t(U){let m=await W();if(!m)throw new v({errorKey:"toolbox_ripple_signer_not_found"});let $=await m.getAddress(),j=await S({...U,sender:$}),z=await k(j);return L(z.tx_blob)}function a(){let U=Z;if(Z=null,U)U.then((m)=>{if(m?.isConnected())return m.disconnect();return}).catch((m)=>{console.warn("XRPL Cleanup failed silently:",m)})}return{broadcastTransaction:L,createSigner:x,createTransaction:C,disconnect:a,estimateTransactionFee:w,getAddress:D,getBalance:o,getTrustLines:A,hasTrustLine:c,setTrustLine:S,setTrustLineAndBroadcast:t,signAndBroadcastTransaction:l,signTransaction:k,transfer:n,validateAddress:R}}export{R as validateRippleAddress,u as parseXrplTokenIdentifier,F as normalizeCurrency,Y5 as isKnownToken,P as isHexCurrency,q5 as hexToCurrency,B5 as getXrplTokenInfo,D5 as getRippleToolbox,J5 as getKnownTokensByIssuer,z5 as formatXrplTokenIdentifier,N as currencyToHex,E as XRPL_TOKEN_ERROR_CODES,I as XRPL_KNOWN_TOKENS};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { type AssetValue, type ErrorKeys, SwapKitError } from "@swapkit/helpers";
|
|
2
|
+
import type { AleoRecord } from "./types";
|
|
3
|
+
export declare const ALEO_ADDRESS_REGEX: RegExp;
|
|
4
|
+
export declare const ALEO_PROGRAM_ID_REGEX: RegExp;
|
|
5
|
+
export declare const ALEO_TRANSACTION_ID_REGEX: RegExp;
|
|
6
|
+
export declare const ALEO_HD_KEY: Uint8Array<ArrayBuffer>;
|
|
7
|
+
export declare const HARDENED_OFFSET = 2147483648;
|
|
8
|
+
export declare const MICRO_CREDITS_PER_CREDIT = 1000000;
|
|
9
|
+
export declare const NATIVE_PROGRAM_ID = "credits.aleo";
|
|
10
|
+
export declare const TRANSFER_PUBLIC_FUNCTION = "transfer_public";
|
|
11
|
+
export declare const ALEO_TRANSFER_PUBLIC_FEE = 1000000;
|
|
12
|
+
export declare const ALEO_TOKEN_TRANSFER_PUBLIC_FEE = 2000000;
|
|
13
|
+
export type AleoNetworkClientLike = {
|
|
14
|
+
getConfirmedTransaction: (transactionId: string) => Promise<unknown>;
|
|
15
|
+
getProgramMappingValue: (programId: string, mappingName: string, key: string) => Promise<unknown>;
|
|
16
|
+
getTransaction: (transactionId: string) => Promise<unknown>;
|
|
17
|
+
getTransitionId: (inputOrOutputId: string) => Promise<unknown>;
|
|
18
|
+
submitTransaction: (transaction: string) => Promise<string>;
|
|
19
|
+
};
|
|
20
|
+
export declare function extractAleoRecordCiphertexts(transaction: unknown, programId?: string): string[];
|
|
21
|
+
export declare function sumUnspentRecords(records: Array<Pick<AleoRecord, "microcredits" | "spent">>): bigint;
|
|
22
|
+
export declare function getAleoError(errorKey: ErrorKeys, error?: unknown): SwapKitError;
|
|
23
|
+
export declare function getAleoMasterSeed(seed: Uint8Array): {
|
|
24
|
+
chainCode: Uint8Array<ArrayBuffer>;
|
|
25
|
+
key: Uint8Array<ArrayBuffer>;
|
|
26
|
+
};
|
|
27
|
+
export declare function deriveAleoChildKey(parent: {
|
|
28
|
+
chainCode: Uint8Array;
|
|
29
|
+
key: Uint8Array;
|
|
30
|
+
}, index: number): {
|
|
31
|
+
chainCode: Uint8Array<ArrayBuffer>;
|
|
32
|
+
key: Uint8Array<ArrayBuffer>;
|
|
33
|
+
};
|
|
34
|
+
export declare function deriveAleoPath(path: string, seed: Uint8Array): {
|
|
35
|
+
chainCode: Uint8Array<ArrayBuffer>;
|
|
36
|
+
key: Uint8Array<ArrayBuffer>;
|
|
37
|
+
};
|
|
38
|
+
export declare function validateAleoAddress(address: string): boolean;
|
|
39
|
+
export declare function validateAleoAddressWithChecksum(address: string): Promise<boolean>;
|
|
40
|
+
export declare function validateAleoProgramId(programId: string): boolean;
|
|
41
|
+
export declare function parseAleoMappingValue(value: unknown, integerType: "u64" | "u128"): bigint;
|
|
42
|
+
export declare function getAleoTransferRoute(assetValue: AssetValue): {
|
|
43
|
+
readonly amount: `${bigint}u64`;
|
|
44
|
+
readonly functionName: "transfer_public";
|
|
45
|
+
readonly isTokenTransfer: false;
|
|
46
|
+
readonly programName: "credits.aleo";
|
|
47
|
+
} | {
|
|
48
|
+
readonly amount: `${bigint}u128`;
|
|
49
|
+
readonly functionName: "transfer_public";
|
|
50
|
+
readonly isTokenTransfer: true;
|
|
51
|
+
readonly programName: string;
|
|
52
|
+
};
|
|
53
|
+
export declare function getConfiguredAleoUrls(): string[];
|
|
54
|
+
export declare function isNotFoundError(error: unknown): boolean;
|
|
55
|
+
export declare function isRecord(value: unknown): value is Record<string, unknown>;
|
|
56
|
+
export declare function isAleoTokenTransferResponse(response: unknown): boolean;
|
|
57
|
+
export declare function parseAleoTransactionStatus(response: unknown, transactionId: string): "accepted" | "pending";
|
|
58
|
+
export declare function getAleoTransactionStatus(transactionId: string): Promise<"accepted" | "pending">;
|
|
59
|
+
export declare function waitForAleoTransaction(transactionId: string, { intervalMs, timeoutMs }?: {
|
|
60
|
+
intervalMs?: number;
|
|
61
|
+
timeoutMs?: number;
|
|
62
|
+
}): Promise<"accepted">;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { AssetValue, type DerivationPathArray } from "@swapkit/helpers";
|
|
2
|
+
import { validateAleoAddress } from "./helpers";
|
|
3
|
+
import type { AleoChainSigner, AleoCreateTransactionParams, AleoRecord, AleoToolboxParams, AleoTransaction, AleoTransferParams, AleoUnsignedTransaction } from "./types";
|
|
4
|
+
declare function createSigner(phrase: string, derivationPath?: DerivationPathArray): AleoChainSigner;
|
|
5
|
+
export declare function getAleoToolbox(params?: AleoToolboxParams): {
|
|
6
|
+
broadcastTransaction: (transaction: AleoTransaction) => Promise<string>;
|
|
7
|
+
createSigner: typeof createSigner;
|
|
8
|
+
createTransaction: ({ assetValue, priorityFee, recipient, sender }: AleoCreateTransactionParams) => Promise<{
|
|
9
|
+
functionName: "transfer_public";
|
|
10
|
+
inputs: [string, string];
|
|
11
|
+
priorityFee: number;
|
|
12
|
+
programName: string;
|
|
13
|
+
sender: string;
|
|
14
|
+
}>;
|
|
15
|
+
estimateTransactionFee: ({ assetValue, priorityFee }: AleoTransferParams) => AssetValue;
|
|
16
|
+
getAddress: () => Promise<string>;
|
|
17
|
+
getBalance: (address: string, scamFilter?: boolean) => Promise<AssetValue[]>;
|
|
18
|
+
getBalanceFromRpc: (address: string) => Promise<AssetValue[]>;
|
|
19
|
+
getBalances: () => Promise<AssetValue[]>;
|
|
20
|
+
getBalanceWithFallback: (address: string, scamFilter?: boolean) => Promise<AssetValue[]>;
|
|
21
|
+
getRecords: ({ transactionIds }: {
|
|
22
|
+
transactionIds: string[];
|
|
23
|
+
}) => Promise<AleoRecord[]>;
|
|
24
|
+
getShieldedBalance: ({ transactionIds }: {
|
|
25
|
+
transactionIds: string[];
|
|
26
|
+
}) => Promise<AssetValue>;
|
|
27
|
+
signAndBroadcastTransaction: (transaction: AleoUnsignedTransaction) => Promise<string>;
|
|
28
|
+
signTransaction: (transaction: AleoUnsignedTransaction) => Promise<AleoTransaction>;
|
|
29
|
+
transfer: (params: AleoTransferParams) => Promise<string>;
|
|
30
|
+
unshield: ({ transactionId, feeRecordCredits, }: {
|
|
31
|
+
transactionId: string;
|
|
32
|
+
feeRecordCredits?: number;
|
|
33
|
+
}) => Promise<{
|
|
34
|
+
publicBalance: AssetValue;
|
|
35
|
+
splitTransactionId: string | undefined;
|
|
36
|
+
unshieldTransactionId: string;
|
|
37
|
+
}>;
|
|
38
|
+
validateAddress: typeof validateAleoAddress;
|
|
39
|
+
};
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { ChainSigner, DerivationPathArray, GenericCreateTransactionParams, GenericTransferParams } from "@swapkit/helpers";
|
|
2
|
+
import type { getAleoToolbox } from "./toolbox";
|
|
3
|
+
export type AleoWallet = ReturnType<typeof getAleoToolbox>;
|
|
4
|
+
export type AleoChainSigner = ChainSigner<AleoUnsignedTransaction, AleoTransaction>;
|
|
5
|
+
export type AleoToolboxParams = {
|
|
6
|
+
phrase?: string;
|
|
7
|
+
derivationPath?: DerivationPathArray;
|
|
8
|
+
} | {
|
|
9
|
+
signer?: AleoChainSigner;
|
|
10
|
+
};
|
|
11
|
+
export type AleoCreateTransactionParams = Omit<GenericCreateTransactionParams, "feeRate"> & {
|
|
12
|
+
priorityFee?: number;
|
|
13
|
+
};
|
|
14
|
+
export type AleoTransferParams = Omit<GenericTransferParams, "feeRate"> & {
|
|
15
|
+
priorityFee?: number;
|
|
16
|
+
};
|
|
17
|
+
export type AleoTransaction = string | {
|
|
18
|
+
toString: () => string;
|
|
19
|
+
};
|
|
20
|
+
export type AleoRecord = {
|
|
21
|
+
microcredits: bigint;
|
|
22
|
+
plaintext: string;
|
|
23
|
+
spent: boolean;
|
|
24
|
+
transactionId: string;
|
|
25
|
+
};
|
|
26
|
+
export type AleoUnsignedTransaction = {
|
|
27
|
+
functionName: string;
|
|
28
|
+
inputs: [string, string];
|
|
29
|
+
priorityFee: number;
|
|
30
|
+
programName: string;
|
|
31
|
+
sender: string;
|
|
32
|
+
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AssetValue, Chain, type CosmosChain, type EVMChain, type GenericCreateTransactionParams, type UTXOChain } from "@swapkit/helpers";
|
|
2
|
+
import type { AleoCreateTransactionParams, getAleoToolbox } from "./aleo";
|
|
2
3
|
import type { AptosCreateTransactionParams, getAptosToolbox } from "./aptos";
|
|
3
4
|
import type { getCardanoToolbox } from "./cardano";
|
|
4
5
|
import type { getCosmosToolbox } from "./cosmos";
|
|
@@ -29,6 +30,7 @@ export type Toolboxes = {
|
|
|
29
30
|
} & {
|
|
30
31
|
[key in CosmosChain]: ReturnType<typeof getCosmosToolbox>;
|
|
31
32
|
} & {
|
|
33
|
+
[Chain.Aleo]: ReturnType<typeof getAleoToolbox>;
|
|
32
34
|
[Chain.Aptos]: ReturnType<typeof getAptosToolbox>;
|
|
33
35
|
[Chain.Hype]: ReturnType<typeof getHyperCoreToolbox>;
|
|
34
36
|
[Chain.Radix]: ReturnType<typeof getRadixToolbox>;
|
|
@@ -49,6 +51,7 @@ export type ToolboxParams = {
|
|
|
49
51
|
} & {
|
|
50
52
|
[key in CosmosChain]: Parameters<typeof getCosmosToolbox>[1];
|
|
51
53
|
} & {
|
|
54
|
+
[Chain.Aleo]: Parameters<typeof getAleoToolbox>[0];
|
|
52
55
|
[Chain.Aptos]: Parameters<typeof getAptosToolbox>[0];
|
|
53
56
|
[Chain.Hype]: Parameters<typeof getHyperCoreToolbox>[0];
|
|
54
57
|
[Chain.Radix]: Parameters<typeof getRadixToolbox>[0];
|
|
@@ -69,6 +72,7 @@ type CreateTransactionParams = {
|
|
|
69
72
|
} & {
|
|
70
73
|
[key in CosmosChain]: GenericCreateTransactionParams;
|
|
71
74
|
} & {
|
|
75
|
+
[Chain.Aleo]: AleoCreateTransactionParams;
|
|
72
76
|
[Chain.Aptos]: AptosCreateTransactionParams;
|
|
73
77
|
[Chain.Hype]: GenericCreateTransactionParams;
|
|
74
78
|
[Chain.Radix]: GenericCreateTransactionParams;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type BaseWallet, Chain } from "@swapkit/helpers";
|
|
2
|
+
import type { AleoWallet } from "./aleo";
|
|
2
3
|
import type { AptosWallet } from "./aptos";
|
|
3
4
|
import type { CardanoWallet } from "./cardano";
|
|
4
5
|
import type { CosmosWallets, ThorchainWallets } from "./cosmos";
|
|
@@ -16,6 +17,7 @@ import type { TONWallet } from "./ton";
|
|
|
16
17
|
import type { TronWallet } from "./tron";
|
|
17
18
|
import type { UTXOToolboxes } from "./utxo";
|
|
18
19
|
type OtherWallets = {
|
|
20
|
+
[Chain.Aleo]: AleoWallet;
|
|
19
21
|
[Chain.Aptos]: AptosWallet;
|
|
20
22
|
[Chain.Hype]: HyperCoreWallet;
|
|
21
23
|
[Chain.Radix]: RadixWallet;
|
|
@@ -15,7 +15,7 @@ export declare function assertDerivationIndex(name: string, value: number): void
|
|
|
15
15
|
export declare function getUTXOAccountPath({ accountIndex, chain, derivationPath, }: HDWalletAccountParams & {
|
|
16
16
|
chain: UTXOChain;
|
|
17
17
|
derivationPath?: DerivationPathArray;
|
|
18
|
-
}): [44, 118, 0, 0, 0] | [44, 931, 0, 0, 0] | [number, number, number, number, number] | [44, 637, 0, 0, 0] | [44, 60, 0, 0, 0] | [44, 397, 0, 0, 0] | [0, 0, 0, 0, 0] | [44, 144, 0, 0, 0] | [44, 501, 0, 0, 0] | [8797555, 1, 0, 0, 0] | [44, 607, 0, 0, 0] | [44, 195, 0, 0, 0] | [44, 148, 0, 0, 0] | [44, 784, 0, 0, 0] | [1852, 1815, 0, 0, 0] | [44, 9004, 0, 0, 0] | [number, number, number, number, (number | undefined)?] | [44, 145, 0, 0, 0] | [84, 2, 0, 0, 0] | [44, 3, 0, 0, 0] | [44, 5, 0, 0, 0] | [44, 133, 0, 0, 0];
|
|
18
|
+
}): [44, 118, 0, 0, 0] | [44, 931, 0, 0, 0] | [number, number, number, number, number] | [44, 683, 0, 0] | [44, 637, 0, 0, 0] | [44, 60, 0, 0, 0] | [44, 397, 0, 0, 0] | [0, 0, 0, 0, 0] | [44, 144, 0, 0, 0] | [44, 501, 0, 0, 0] | [8797555, 1, 0, 0, 0] | [44, 607, 0, 0, 0] | [44, 195, 0, 0, 0] | [44, 148, 0, 0, 0] | [44, 784, 0, 0, 0] | [1852, 1815, 0, 0, 0] | [44, 9004, 0, 0, 0] | [number, number, number, number, (number | undefined)?] | [44, 145, 0, 0, 0] | [84, 2, 0, 0, 0] | [44, 3, 0, 0, 0] | [44, 5, 0, 0, 0] | [44, 133, 0, 0, 0];
|
|
19
19
|
export declare function getUTXOAddressPath({ accountIndex, change, chain, derivationPath, index, }: HDWalletAccountParams & {
|
|
20
20
|
change?: boolean;
|
|
21
21
|
chain: UTXOChain;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"dependencies": { "@swapkit/helpers": "4.
|
|
2
|
+
"dependencies": { "@swapkit/helpers": "4.18.0", "@swapkit/utxo-signer": "2.2.3" },
|
|
3
3
|
"description": "SwapKit - Toolboxes",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@aptos-labs/ts-sdk": "7.0.1",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"@polkadot/types": "16.5.6",
|
|
26
26
|
"@polkadot/util": "14.0.3",
|
|
27
27
|
"@polkadot/util-crypto": "14.0.3",
|
|
28
|
+
"@provablehq/sdk": "0.11.3",
|
|
28
29
|
"@radixdlt/babylon-gateway-api-sdk": "1.10.1",
|
|
29
30
|
"@radixdlt/radix-dapp-toolkit": "2.3.0",
|
|
30
31
|
"@scure/base": "2.2.0",
|
|
@@ -56,6 +57,11 @@
|
|
|
56
57
|
},
|
|
57
58
|
"exports": {
|
|
58
59
|
".": { "default": "./dist/src/index.js", "require": "./dist/src/index.cjs", "types": "./dist/types/index.d.ts" },
|
|
60
|
+
"./aleo": {
|
|
61
|
+
"default": "./dist/src/aleo/index.js",
|
|
62
|
+
"require": "./dist/src/aleo/index.cjs",
|
|
63
|
+
"types": "./dist/types/aleo/index.d.ts"
|
|
64
|
+
},
|
|
59
65
|
"./aptos": {
|
|
60
66
|
"default": "./dist/src/aptos/index.js",
|
|
61
67
|
"require": "./dist/src/aptos/index.cjs",
|
|
@@ -162,6 +168,7 @@
|
|
|
162
168
|
"@polkadot/rpc-provider": "16.5.6",
|
|
163
169
|
"@polkadot/util": "14.0.3",
|
|
164
170
|
"@polkadot/util-crypto": "14.0.3",
|
|
171
|
+
"@provablehq/sdk": "0.11.3",
|
|
165
172
|
"@radixdlt/babylon-gateway-api-sdk": "1.10.1",
|
|
166
173
|
"@radixdlt/radix-dapp-toolkit": "2.3.0",
|
|
167
174
|
"@scure/base": "2.2.0",
|
|
@@ -198,5 +205,5 @@
|
|
|
198
205
|
"type-check:go": "tsgo"
|
|
199
206
|
},
|
|
200
207
|
"type": "module",
|
|
201
|
-
"version": "4.
|
|
208
|
+
"version": "4.25.0"
|
|
202
209
|
}
|