h_test_1 0.0.2 → 0.0.4
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/data-structures/crypto-keys/decodeUTXO.cjs +1 -1
- package/data-structures/crypto-keys/decodeUTXO.mjs +4 -4
- package/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
- package/data-structures/crypto-keys/encryptDecryptUtxo.mjs +23 -23
- package/functions/utils/publicBalance.utils.cjs +1 -1
- package/functions/utils/publicBalance.utils.mjs +7 -7
- package/functions/web3/uniswapAPI.cjs +1 -1
- package/functions/web3/uniswapAPI.mjs +20 -20
- package/package.json +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.mjs +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@solana/web3.js"),E=require("../../crypto/poseidon.cjs"),B=require("../../constants/chains.constants.cjs"),z=require("../utxo/Utxo.cjs"),_=require("./keys.cjs"),a=require("ethers"),y="solana-on-chain-utxo:",x=8,P=e=>{if(e.length!==x)throw new Error(`Expected ${x} on-chain fields, received ${e.length}`);const t=e.map((n,r)=>{const o=n instanceof Uint8Array?n:Uint8Array.from(n);if(o.length!==32)throw new Error(`Expected bytes32 length 32 at position ${r}, got ${o.length}`);return`0x${Buffer.from(o).toString("hex")}`});return`${y}${a.ethers.AbiCoder.defaultAbiCoder().encode(["bytes32[8]"],[t])}`},I=e=>e.startsWith(y),S=e=>{if(!I(e))throw new Error("Invalid encoded Solana UTXO payload");const[t]=a.ethers.AbiCoder.defaultAbiCoder().decode(["bytes32[8]"],e.slice(y.length)),n=t;if(!Array.isArray(n)||n.length!==x)throw new Error("Malformed encoded Solana UTXO payload");const[r,o,s,i,d,c,h,l]=n,m=BigInt(r),u=BigInt(i),A=a.ethers.toBeHex(BigInt(d)),g=BigInt(c),f=BigInt(h),H=BigInt(l).toString(),k=Array.from(a.ethers.getBytes(o)),w=Array.from(a.ethers.getBytes(s)),C=Uint8Array.from([...k.slice(16),...w.slice(16)]),p=new O.PublicKey(C).toBase58(),T=E.poseidonHash(BigInt(o),BigInt(s));return{amount:m,erc20TokenAddress:T,mintAddress:p,randomization:u,stealthAddress:A,H0:g,H1:f,timeStamp:H}},U=e=>{const t=a.ethers.AbiCoder.defaultAbiCoder().decode(["uint256","address","tuple(uint256, uint256, uint256, uint256)","uint256","uint256"],e),n=BigInt(t[0]),r=t[1],o=BigInt(t[2][0]),s=a.ethers.toBeHex(BigInt(t[2][1])
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@solana/web3.js"),E=require("../../crypto/poseidon.cjs"),B=require("../../constants/chains.constants.cjs"),z=require("../utxo/Utxo.cjs"),_=require("./keys.cjs"),a=require("ethers"),y="solana-on-chain-utxo:",x=8,P=e=>{if(e.length!==x)throw new Error(`Expected ${x} on-chain fields, received ${e.length}`);const t=e.map((n,r)=>{const o=n instanceof Uint8Array?n:Uint8Array.from(n);if(o.length!==32)throw new Error(`Expected bytes32 length 32 at position ${r}, got ${o.length}`);return`0x${Buffer.from(o).toString("hex")}`});return`${y}${a.ethers.AbiCoder.defaultAbiCoder().encode(["bytes32[8]"],[t])}`},I=e=>e.startsWith(y),S=e=>{if(!I(e))throw new Error("Invalid encoded Solana UTXO payload");const[t]=a.ethers.AbiCoder.defaultAbiCoder().decode(["bytes32[8]"],e.slice(y.length)),n=t;if(!Array.isArray(n)||n.length!==x)throw new Error("Malformed encoded Solana UTXO payload");const[r,o,s,i,d,c,h,l]=n,m=BigInt(r),u=BigInt(i),A=a.ethers.toBeHex(BigInt(d)),g=BigInt(c),f=BigInt(h),H=BigInt(l).toString(),k=Array.from(a.ethers.getBytes(o)),w=Array.from(a.ethers.getBytes(s)),C=Uint8Array.from([...k.slice(16),...w.slice(16)]),p=new O.PublicKey(C).toBase58(),T=E.poseidonHash(BigInt(o),BigInt(s));return{amount:m,erc20TokenAddress:T,mintAddress:p,randomization:u,stealthAddress:A,H0:g,H1:f,timeStamp:H}},U=e=>{const t=a.ethers.AbiCoder.defaultAbiCoder().decode(["uint256","address","tuple(uint256, uint256, uint256, uint256)","uint256","uint256"],e),n=BigInt(t[0]),r=t[1],o=BigInt(t[2][0]),s=a.ethers.toBeHex(BigInt(t[2][1])),i=BigInt(t[2][2]),d=BigInt(t[2][3]),c=BigInt(t[3]).toString(),h=Number(t[4]);return{amount:n,erc20TokenAddress:r,randomization:o,stealthAddress:s,H0:i,H1:d,timeStamp:c,tokenId:h}},b=(e,t,n)=>{if(B.isSolanaLike(n)){const{amount:h,erc20TokenAddress:l,mintAddress:m,randomization:u,stealthAddress:A,timeStamp:g}=S(e);return{amount:h,erc20TokenAddress:l,mintAddress:m,timeStamp:g,tokenId:0,randomization:u,shieldedPrivateKey:t,stealthAddress:A}}const{amount:r,erc20TokenAddress:o,timeStamp:s,tokenId:i,randomization:d,stealthAddress:c}=U(e);return{amount:r,erc20TokenAddress:o,timeStamp:s,tokenId:i,randomization:d,shieldedPrivateKey:t,stealthAddress:c}},$=(e,t,n)=>new z.Utxo(b(e,t,n)),q=(e,t,n)=>{const{randomization:r,H0:o,H1:s}=B.isSolanaLike(n)?S(e):U(e),i=_.UserKeys.checkSignature(r,o,s,t);if(!i)throw new Error("UTXO doesn't belong to user");return i};exports.abiDecodeUtxo=U;exports.checkUtxoSignature=q;exports.decodeSolanaOnChainUtxo=S;exports.decodeUtxo=$;exports.decodeUtxoConstructorArgs=b;exports.encodeSolanaOnChainUtxo=P;exports.isSolanaOnChainUtxo=I;
|
|
@@ -32,7 +32,7 @@ const f = "solana-on-chain-utxo:", x = 8, F = (e) => {
|
|
|
32
32
|
c,
|
|
33
33
|
m,
|
|
34
34
|
A
|
|
35
|
-
] = o, l = BigInt(r), g = BigInt(i), h = d.toBeHex(BigInt(a)), u = BigInt(c),
|
|
35
|
+
] = o, l = BigInt(r), g = BigInt(i), h = d.toBeHex(BigInt(a)), u = BigInt(c), H = BigInt(m), S = BigInt(A).toString(), p = Array.from(d.getBytes(n)), U = Array.from(d.getBytes(s)), b = Uint8Array.from([...p.slice(16), ...U.slice(16)]), w = new T(b).toBase58(), k = C(BigInt(n), BigInt(s));
|
|
36
36
|
return {
|
|
37
37
|
amount: l,
|
|
38
38
|
erc20TokenAddress: k,
|
|
@@ -40,14 +40,14 @@ const f = "solana-on-chain-utxo:", x = 8, F = (e) => {
|
|
|
40
40
|
randomization: g,
|
|
41
41
|
stealthAddress: h,
|
|
42
42
|
H0: u,
|
|
43
|
-
H1:
|
|
44
|
-
timeStamp:
|
|
43
|
+
H1: H,
|
|
44
|
+
timeStamp: S
|
|
45
45
|
};
|
|
46
46
|
}, I = (e) => {
|
|
47
47
|
const t = d.AbiCoder.defaultAbiCoder().decode(
|
|
48
48
|
["uint256", "address", "tuple(uint256, uint256, uint256, uint256)", "uint256", "uint256"],
|
|
49
49
|
e
|
|
50
|
-
), o = BigInt(t[0]), r = t[1], n = BigInt(t[2][0]), s = d.toBeHex(BigInt(t[2][1])
|
|
50
|
+
), o = BigInt(t[0]), r = t[1], n = BigInt(t[2][0]), s = d.toBeHex(BigInt(t[2][1])), i = BigInt(t[2][2]), a = BigInt(t[2][3]), c = BigInt(t[3]).toString(), m = Number(t[4]);
|
|
51
51
|
return {
|
|
52
52
|
amount: o,
|
|
53
53
|
erc20TokenAddress: r,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("ethers"),a=require("libsodium-wrappers"),l=require("../utxo/Utxo.cjs"),m=require("@solana/web3.js"),B=require("./keys.cjs"),g=e=>{const r=[Buffer.from(o.ethers.toBeHex(e.amount)),Buffer.from(e.erc20TokenAddress),Buffer.from(o.ethers.toBeHex(e.randomization)),Buffer.from(e.getStealthAddress()),Buffer.from(o.ethers.toBeHex(BigInt(e.timeStamp))),Buffer.from(o.ethers.toBeHex(e.tokenId??0))];if(e.mintAddress){const t=new m.PublicKey(e.mintAddress).toBytes();r.push(Buffer.from(t))}const n=Buffer.concat(r);return a.crypto_box_seal(n,o.ethers.getBytes(e.getEncryptionKey()))},p=(e,r)=>{const{publicKey:n,privateKey:c}=B.UserKeys.getEncryptionKeyPair(r.getShieldedPrivateKey()),d=a.crypto_box_seal_open(e,o.ethers.getBytes(n),o.ethers.getBytes(c)),t=Buffer.from(d).toString("utf-8").split("0x").filter(s=>s.length!==0).map((s,y)=>{let i;return[0,2,4,5].includes(y)?i=BigInt(`0x${s}`):[1,3,6].includes(y)&&(i=`0x${s}`),i}),f=typeof t[6]=="string"?t[6]:void 0,u=f?new m.PublicKey(Buffer.from(f.slice(2),"hex")).toString():void 0;return{amount:t[0],erc20TokenAddress:t[1],randomization:t[2],stealthAddress:t[3],shieldedPrivateKey:r.getShieldedPrivateKey(),timeStamp:t[4].toString(),tokenId:t[5]?Number(t[5]):0,mintAddress:u}},h=(e,r)=>new l.Utxo(p(e,r));exports.decryptUtxo=h;exports.decryptUtxoConstructorArgs=p;exports.encryptUtxo=g;
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import { ethers as
|
|
1
|
+
import { ethers as o } from "ethers";
|
|
2
2
|
import a from "libsodium-wrappers";
|
|
3
3
|
import { Utxo as B } from "../utxo/Utxo.mjs";
|
|
4
|
-
import { PublicKey as
|
|
4
|
+
import { PublicKey as p } from "@solana/web3.js";
|
|
5
5
|
import { UserKeys as l } from "./keys.mjs";
|
|
6
6
|
const K = (e) => {
|
|
7
|
-
const
|
|
8
|
-
Buffer.from(
|
|
9
|
-
Buffer.from(
|
|
10
|
-
Buffer.from(
|
|
7
|
+
const r = [
|
|
8
|
+
Buffer.from(o.toBeHex(e.amount)),
|
|
9
|
+
Buffer.from(e.erc20TokenAddress),
|
|
10
|
+
Buffer.from(o.toBeHex(e.randomization)),
|
|
11
11
|
Buffer.from(e.getStealthAddress()),
|
|
12
|
-
Buffer.from(
|
|
13
|
-
Buffer.from(
|
|
12
|
+
Buffer.from(o.toBeHex(BigInt(e.timeStamp))),
|
|
13
|
+
Buffer.from(o.toBeHex(e.tokenId ?? 0))
|
|
14
14
|
];
|
|
15
15
|
if (e.mintAddress) {
|
|
16
|
-
const
|
|
17
|
-
|
|
16
|
+
const t = new p(e.mintAddress).toBytes();
|
|
17
|
+
r.push(Buffer.from(t));
|
|
18
18
|
}
|
|
19
|
-
const s = Buffer.concat(
|
|
20
|
-
return a.crypto_box_seal(s,
|
|
21
|
-
}, g = (e,
|
|
22
|
-
const { publicKey: s, privateKey:
|
|
19
|
+
const s = Buffer.concat(r);
|
|
20
|
+
return a.crypto_box_seal(s, o.getBytes(e.getEncryptionKey()));
|
|
21
|
+
}, g = (e, r) => {
|
|
22
|
+
const { publicKey: s, privateKey: f } = l.getEncryptionKeyPair(r.getShieldedPrivateKey()), d = a.crypto_box_seal_open(
|
|
23
23
|
e,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
), t = Buffer.from(
|
|
27
|
-
let
|
|
28
|
-
return [0, 2, 4, 5].includes(c) ?
|
|
29
|
-
}), m = typeof t[6] == "string" ? t[6] : void 0,
|
|
24
|
+
o.getBytes(s),
|
|
25
|
+
o.getBytes(f)
|
|
26
|
+
), t = Buffer.from(d).toString("utf-8").split("0x").filter((n) => n.length !== 0).map((n, c) => {
|
|
27
|
+
let i;
|
|
28
|
+
return [0, 2, 4, 5].includes(c) ? i = BigInt(`0x${n}`) : [1, 3, 6].includes(c) && (i = `0x${n}`), i;
|
|
29
|
+
}), m = typeof t[6] == "string" ? t[6] : void 0, y = m ? new p(Buffer.from(m.slice(2), "hex")).toString() : void 0;
|
|
30
30
|
return {
|
|
31
31
|
amount: t[0],
|
|
32
32
|
erc20TokenAddress: t[1],
|
|
33
33
|
randomization: t[2],
|
|
34
34
|
stealthAddress: t[3],
|
|
35
|
-
shieldedPrivateKey:
|
|
35
|
+
shieldedPrivateKey: r.getShieldedPrivateKey(),
|
|
36
36
|
timeStamp: t[4].toString(),
|
|
37
37
|
tokenId: t[5] ? Number(t[5]) : 0,
|
|
38
38
|
// tokenId
|
|
39
|
-
mintAddress:
|
|
39
|
+
mintAddress: y
|
|
40
40
|
};
|
|
41
|
-
}, S = (e,
|
|
41
|
+
}, S = (e, r) => new B(g(e, r));
|
|
42
42
|
export {
|
|
43
43
|
S as decryptUtxo,
|
|
44
44
|
g as decryptUtxoConstructorArgs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("ethers"),p=require("../../constants/chains.constants.cjs"),g=require("../../constants/protocol.constants.cjs"),d=require("./erc20tokenFunctions.cjs"),P=require("../../externalABIs/swapAbi.cjs"),m=require("../../error-handling/logger.cjs"),w=require("../../externalABIs/index.cjs"),y=require("./ipfs.cjs"),C=require("./create-provider.cjs"),k=require("../../data-structures/http/HttpClient.cjs");require("axios");const f=require("@solana/web3.js"),b=require("@solana/spl-token"),B=n=>{const{fetchRpcUrl:e}=p.networkRegistry[n];if(!e)throw new Error(`No RPC URL configured for chain ${n}`);return C.createCustomRpcProvider(e)},R=async(n,e,t)=>{try{const s=t.erc20TokenAddress;let c;const o=new T.ethers.Contract(t.erc20TokenAddress,P.ERC20ABI,n);s!==g.zeroAddress?c=await o?.balanceOf(e):c=await n.getBalance(e);const r=c;return r<=0n?null:{token:t,balance:r}}catch{return null}},q=async(n,e)=>{const t=e.nftTokenType===g.TokenType.ERC721,s=new T.ethers.Contract(e.erc20TokenAddress,t?w.ERC721ABI:w.ERC1155ABI,n),{tokenIds:c}=e;if(!c?.length)return null;const o=await Promise.all(c.map(async r=>{try{const a=await s[t?"tokenURI":"uri"](r),l=a.startsWith("ipfs://")?y.getFormattedIpfsUrl(a,!1):a,u=t?l:l.replace("{id}",r);if(u){const i=await k.httpClient.get(u);return i?.image?.startsWith("ipfs://")&&(i.image=y.getFormattedIpfsUrl(i.image,!1)),{image:i.image,tokenId:Number(r),name:i.name}}return{tokenId:Number(r)}}catch{return{tokenId:Number(r)}}}));return{token:e,balance:c?.length?BigInt(c.length):0n,nfts:o}},E=async(n,e,t)=>{const s=t??d.getErc20TokensForChain(n),c=B(n);return(await Promise.all(s.map(async r=>d.isNFTToken(r)?q(c,r):R(c,e,r)))).filter(r=>r!==null)},N=async(n,e,t)=>{try{const s=B(n),c=new T.ethers.Contract(t,P.ERC20ABI,s);let o;return t!==g.zeroAddress?o=await c?.balanceOf(e):o=await s.getBalance(e),o}catch{return m.Logger.error(`Failed to fetch public balance for address ${e}`),null}},U=async(n,e)=>{try{return await B(n).getTransactionCount(e)}catch(t){return m.Logger.error(`Failed to fetch transaction count for address ${e} on chain ${n}`,t),null}},v=async(n,e,t)=>{const c=p.networkRegistry[n].fetchRpcUrl??"",o=C.createCustomSolanaConnection(c);return(await Promise.all(t.map(async a=>{if(d.isNFTToken(a))return{token:a,balance:1n,nfts:[{image:a.logoURI,tokenId:0,name:a.symbol}]};if(a.erc20TokenAddress===g.solanaNativeAddress){const I=BigInt(await o.getBalance(new f.PublicKey(e)));return{token:a,balance:I}}const l=new f.PublicKey(a.erc20TokenAddress),u=new f.PublicKey(e),i=await b.getAssociatedTokenAddress(l,u,!0,a.is2022Program?b.TOKEN_2022_PROGRAM_ID:b.TOKEN_PROGRAM_ID);if(!await o.getAccountInfo(i))return{token:a,balance:0n};const h=await o.getTokenAccountBalance(i),A=BigInt(h.value.amount);return{token:a,balance:A}}))).filter(a=>a.balance>0n)};exports.getPublicBalance=R;exports.getPublicBalanceByTokenAddress=N;exports.getPublicBalancesOfTokens=E;exports.getPublicTransactionCount=U;exports.getSolanaPublicBalances=v;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ethers as m } from "ethers";
|
|
2
2
|
import { networkRegistry as d } from "../../constants/chains.constants.mjs";
|
|
3
|
-
import { zeroAddress as b, solanaNativeAddress as P, TokenType as
|
|
4
|
-
import { getErc20TokensForChain as
|
|
3
|
+
import { zeroAddress as b, solanaNativeAddress as P, TokenType as h } from "../../constants/protocol.constants.mjs";
|
|
4
|
+
import { getErc20TokensForChain as A, isNFTToken as w } from "./erc20tokenFunctions.mjs";
|
|
5
5
|
import { ERC20ABI as B } from "../../externalABIs/swapAbi.mjs";
|
|
6
6
|
import { Logger as T } from "../../error-handling/logger.mjs";
|
|
7
|
-
import { ERC721ABI as
|
|
7
|
+
import { ERC721ABI as I, ERC1155ABI as E } from "../../externalABIs/index.mjs";
|
|
8
8
|
import { getFormattedIpfsUrl as p } from "./ipfs.mjs";
|
|
9
9
|
import { createCustomSolanaConnection as N, createCustomRpcProvider as U } from "./create-provider.mjs";
|
|
10
10
|
import { httpClient as k } from "../../data-structures/http/HttpClient.mjs";
|
|
@@ -22,13 +22,13 @@ const g = (n) => {
|
|
|
22
22
|
let r;
|
|
23
23
|
const o = new m.Contract(a.erc20TokenAddress, B, n);
|
|
24
24
|
s !== b ? r = await o?.balanceOf(t) : r = await n.getBalance(t);
|
|
25
|
-
const c = r
|
|
25
|
+
const c = r;
|
|
26
26
|
return c <= 0n ? null : { token: a, balance: c };
|
|
27
27
|
} catch {
|
|
28
28
|
return null;
|
|
29
29
|
}
|
|
30
30
|
}, $ = async (n, t) => {
|
|
31
|
-
const a = t.nftTokenType ===
|
|
31
|
+
const a = t.nftTokenType === h.ERC721, s = new m.Contract(t.erc20TokenAddress, a ? I : E, n), { tokenIds: r } = t;
|
|
32
32
|
if (!r?.length)
|
|
33
33
|
return null;
|
|
34
34
|
const o = await Promise.all(
|
|
@@ -51,7 +51,7 @@ const g = (n) => {
|
|
|
51
51
|
nfts: o
|
|
52
52
|
};
|
|
53
53
|
}, V = async (n, t, a) => {
|
|
54
|
-
const s = a ??
|
|
54
|
+
const s = a ?? A(n), r = g(n);
|
|
55
55
|
return (await Promise.all(
|
|
56
56
|
s.map(async (c) => w(c) ? $(r, c) : _(r, t, c))
|
|
57
57
|
)).filter((c) => c !== null);
|
|
@@ -59,7 +59,7 @@ const g = (n) => {
|
|
|
59
59
|
try {
|
|
60
60
|
const s = g(n), r = new m.Contract(a, B, s);
|
|
61
61
|
let o;
|
|
62
|
-
return a !== b ? o = await r?.balanceOf(t) : o = await s.getBalance(t), o
|
|
62
|
+
return a !== b ? o = await r?.balanceOf(t) : o = await s.getBalance(t), o;
|
|
63
63
|
} catch {
|
|
64
64
|
return T.error(`Failed to fetch public balance for address ${t}`), null;
|
|
65
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("ethers");require("../../constants/token-data/index.cjs");const u=require("../../constants/chains.constants.cjs"),g=require("../../constants/protocol.constants.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/server.constants.cjs");require("../../constants/vite.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../constants/addresses.constants.cjs");require("../../constants/token.limits.constants.cjs");require("../../constants/presale.constants.cjs");require("../../constants/activity.constants.cjs");require("../../constants/tasks.constants.cjs");require("../../constants/events.constants.cjs");const p=require("../../error-handling/error-codes.constants.cjs"),P=require("./etherFunctions.cjs");require("../../types/circom-data.types.cjs");const d=require("../../types/ethereum-network.types.cjs");require("../../types/activities.types.cjs");require("../../API/getServerURL.cjs");require("../../data-structures/http/HttpClient.cjs");require("axios");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");const h=require("../../error-handling/logError.cjs");require("../../constants/save-depths.cjs");require("../utils/mutexes.utils.cjs");require("@coral-xyz/anchor");require("@solana/web3.js");require("../../data-structures/crypto-keys/keys.cjs");const l=async(n,t,c,r)=>{const o=(await Promise.all([100,500,3e3,1e4].map(async e=>({poolAddress:await t.getPool(c,r,e),fee:e})))).filter(({poolAddress:e})=>e!==g.zeroAddress),s=await Promise.all(o.map(async e=>({poolAddress:e.poolAddress,fee:e.fee,token1Balance:await n.balanceOf(e.poolAddress)}))),a=s.map(e=>e.token1Balance).reduce((e,q)=>q>=e?q:e,0n);if(a===0n)throw new Error(p.transactionErrorCodes.UNISWAP_NOT_ENOUGH_LIQUIDITY);return s.find(e=>e.token1Balance===a)},w=async(n,t,c,r,o,s)=>{try{if(!u.networkRegistry[t].quoterV2Address)throw Error("No Quoter Contract Provided");return(await n.getContractWithFetcherByChainId(t,d.ContractType.UniswapV3QuoterContract,u.networkRegistry[t].quoterV2Address).quoteExactInputSingle.staticCall({tokenIn:c.wrappedErc20TokenAddress??c.erc20TokenAddress,tokenOut:r.wrappedErc20TokenAddress??r.erc20TokenAddress,fee:o,amountIn:s,sqrtPriceLimitX96:0})).amountOut}catch(i){throw h.logError(i),i}},A=async(n,t,c,r)=>{try{const o=n.getContractWithFetcherByChainId(t,d.ContractType.UniswapV3FactoryContract,u.networkRegistry[t].uniswapV3FactoryAddress),s=n.getContractWithFetcherByChainId(t,d.ContractType.ERC20Contract,r.wrappedErc20TokenAddress??r.erc20TokenAddress),{fee:i}=await l(s,o,c.wrappedErc20TokenAddress??c.erc20TokenAddress,r.wrappedErc20TokenAddress??r.erc20TokenAddress);return i}catch(o){throw console.log("Error in getUniswapFee",o),o}},E=async(n,t,c,r,o)=>{try{const s=await A(n,t,r,o),i=C.ethers.AbiCoder.defaultAbiCoder().encode(["uint24"],[s]),a=P.getAmountInWei(r,c);return{tokenPrice:await w(n,t,r,o,s,a),poolFee:i}}catch{throw Error(p.transactionErrorCodes.NO_UNISWAP_PRICE)}};exports.getUniswapFee=A;exports.getUniswapPrice=E;exports.getUniswapPriceHelper=w;exports.searchPoolAndFee=l;
|
|
@@ -32,27 +32,27 @@ import "../utils/mutexes.utils.mjs";
|
|
|
32
32
|
import "@coral-xyz/anchor";
|
|
33
33
|
import "@solana/web3.js";
|
|
34
34
|
import "../../data-structures/crypto-keys/keys.mjs";
|
|
35
|
-
const C = async (
|
|
35
|
+
const C = async (n, o, i, t) => {
|
|
36
36
|
const e = (await Promise.all(
|
|
37
37
|
[100, 500, 3e3, 1e4].map(async (r) => ({
|
|
38
38
|
poolAddress: await o.getPool(i, t, r),
|
|
39
39
|
fee: r
|
|
40
40
|
}))
|
|
41
|
-
)).filter(({ poolAddress: r }) => r !== u),
|
|
41
|
+
)).filter(({ poolAddress: r }) => r !== u), s = await Promise.all(
|
|
42
42
|
e.map(async (r) => ({
|
|
43
43
|
poolAddress: r.poolAddress,
|
|
44
44
|
fee: r.fee,
|
|
45
|
-
token1Balance:
|
|
45
|
+
token1Balance: await n.balanceOf(r.poolAddress)
|
|
46
46
|
}))
|
|
47
|
-
), c =
|
|
47
|
+
), c = s.map((r) => r.token1Balance).reduce((r, d) => d >= r ? d : r, 0n);
|
|
48
48
|
if (c === 0n)
|
|
49
49
|
throw new Error(l.UNISWAP_NOT_ENOUGH_LIQUIDITY);
|
|
50
|
-
return
|
|
51
|
-
},
|
|
50
|
+
return s.find((r) => r.token1Balance === c);
|
|
51
|
+
}, E = async (n, o, i, t, e, s) => {
|
|
52
52
|
try {
|
|
53
53
|
if (!p[o].quoterV2Address)
|
|
54
54
|
throw Error("No Quoter Contract Provided");
|
|
55
|
-
return (await
|
|
55
|
+
return (await n.getContractWithFetcherByChainId(
|
|
56
56
|
o,
|
|
57
57
|
m.UniswapV3QuoterContract,
|
|
58
58
|
p[o].quoterV2Address
|
|
@@ -60,24 +60,24 @@ const C = async (s, o, i, t) => {
|
|
|
60
60
|
tokenIn: i.wrappedErc20TokenAddress ?? i.erc20TokenAddress,
|
|
61
61
|
tokenOut: t.wrappedErc20TokenAddress ?? t.erc20TokenAddress,
|
|
62
62
|
fee: e,
|
|
63
|
-
amountIn:
|
|
63
|
+
amountIn: s,
|
|
64
64
|
sqrtPriceLimitX96: 0
|
|
65
|
-
})).amountOut
|
|
65
|
+
})).amountOut;
|
|
66
66
|
} catch (a) {
|
|
67
67
|
throw y(a), a;
|
|
68
68
|
}
|
|
69
|
-
},
|
|
69
|
+
}, P = async (n, o, i, t) => {
|
|
70
70
|
try {
|
|
71
|
-
const e =
|
|
71
|
+
const e = n.getContractWithFetcherByChainId(
|
|
72
72
|
o,
|
|
73
73
|
m.UniswapV3FactoryContract,
|
|
74
74
|
p[o].uniswapV3FactoryAddress
|
|
75
|
-
),
|
|
75
|
+
), s = n.getContractWithFetcherByChainId(
|
|
76
76
|
o,
|
|
77
77
|
m.ERC20Contract,
|
|
78
78
|
t.wrappedErc20TokenAddress ?? t.erc20TokenAddress
|
|
79
79
|
), { fee: a } = await C(
|
|
80
|
-
|
|
80
|
+
s,
|
|
81
81
|
e,
|
|
82
82
|
i.wrappedErc20TokenAddress ?? i.erc20TokenAddress,
|
|
83
83
|
t.wrappedErc20TokenAddress ?? t.erc20TokenAddress
|
|
@@ -86,15 +86,15 @@ const C = async (s, o, i, t) => {
|
|
|
86
86
|
} catch (e) {
|
|
87
87
|
throw console.log("Error in getUniswapFee", e), e;
|
|
88
88
|
}
|
|
89
|
-
}, tr = async (
|
|
89
|
+
}, tr = async (n, o, i, t, e) => {
|
|
90
90
|
try {
|
|
91
|
-
const
|
|
92
|
-
return { tokenPrice: await
|
|
93
|
-
|
|
91
|
+
const s = await P(n, o, t, e), a = w.AbiCoder.defaultAbiCoder().encode(["uint24"], [s]), c = f(t, i);
|
|
92
|
+
return { tokenPrice: await E(
|
|
93
|
+
n,
|
|
94
94
|
o,
|
|
95
95
|
t,
|
|
96
96
|
e,
|
|
97
|
-
|
|
97
|
+
s,
|
|
98
98
|
c
|
|
99
99
|
), poolFee: a };
|
|
100
100
|
} catch {
|
|
@@ -102,8 +102,8 @@ const C = async (s, o, i, t) => {
|
|
|
102
102
|
}
|
|
103
103
|
};
|
|
104
104
|
export {
|
|
105
|
-
|
|
105
|
+
P as getUniswapFee,
|
|
106
106
|
tr as getUniswapPrice,
|
|
107
|
-
|
|
107
|
+
E as getUniswapPriceHelper,
|
|
108
108
|
C as searchPoolAndFee
|
|
109
109
|
};
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/utxoWorkerLauncher-
|
|
1
|
+
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/utxoWorkerLauncher-RoJ0StvR.js").href:new URL("../../assets/utxoWorkerLauncher-RoJ0StvR.js",document.currentScript&&document.currentScript.src||document.baseURI).href);module.exports=e;
|