@hinkal/common 0.1.33 → 0.1.35
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/constants/chains.constants.cjs +1 -1
- package/constants/chains.constants.mjs +29 -29
- package/constants/fees.constants.cjs +1 -1
- package/constants/fees.constants.mjs +22 -22
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +1 -0
- package/data-structures/Hinkal/Hinkal.mjs +13 -10
- package/data-structures/Hinkal/IHinkal.d.ts +2 -1
- package/data-structures/Hinkal/hinkalActionBeefy.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionBeefy.mjs +18 -20
- package/data-structures/Hinkal/hinkalActionConvex.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionConvex.mjs +18 -21
- package/data-structures/Hinkal/hinkalActionLidoEth.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionLidoEth.mjs +31 -31
- package/data-structures/Hinkal/hinkalActionPendle.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionPendle.mjs +77 -80
- package/data-structures/Hinkal/hinkalActionPendleLP.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionPendleLP.mjs +34 -34
- package/data-structures/Hinkal/hinkalActionStake.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionStake.mjs +48 -52
- package/data-structures/Hinkal/hinkalActionVolatile.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionVolatile.mjs +38 -44
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.mjs +27 -28
- package/data-structures/event-service/AbstractCommitmentsSnapshotService.cjs +1 -4
- package/data-structures/event-service/AbstractCommitmentsSnapshotService.mjs +11 -16
- package/data-structures/transactions-manager/TransactionsManager.cjs +1 -1
- package/data-structures/transactions-manager/TransactionsManager.mjs +66 -74
- package/data-structures/transactions-manager/history/getVolatileData.cjs +1 -1
- package/data-structures/transactions-manager/history/getVolatileData.mjs +13 -13
- package/data-structures/volatile-helper/VolatileHelper.cjs +1 -1
- package/data-structures/volatile-helper/VolatileHelper.mjs +60 -60
- package/functions/pre-transaction/getFlatFees.cjs +1 -1
- package/functions/pre-transaction/getFlatFees.mjs +42 -42
- package/functions/pre-transaction/process-gas-estimates.cjs +1 -1
- package/functions/pre-transaction/process-gas-estimates.mjs +17 -26
- package/functions/protocols/pendle.helpers.cjs +1 -1
- package/functions/protocols/pendle.helpers.mjs +27 -27
- package/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/functions/snarkjs/constructGeneralZkProof.mjs +35 -37
- package/functions/utils/cacheFunctions.cjs +1 -1
- package/functions/utils/cacheFunctions.mjs +27 -30
- package/functions/web3/events/getShieldedBalance.cjs +2 -2
- package/functions/web3/events/getShieldedBalance.mjs +25 -25
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +15 -15
- package/functions/web3/runContractFunction.cjs +1 -1
- package/functions/web3/runContractFunction.mjs +37 -37
- package/functions/web3/uniswapAPI.cjs +1 -1
- package/functions/web3/uniswapAPI.mjs +28 -28
- package/package.json +1 -1
- package/types/relayer.types.d.ts +22 -0
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.mjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLogic.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLogic.mjs +16 -17
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("async-mutex"),q=require("../../../constants/token-data/ERC20Registry.cjs"),I=require("../../utils/erc20tokenFunctions.cjs"),p=require("../../utils/caseInsensitive.utils.cjs"),k=require("../../utils/volatile-patcher.utils.cjs"),U=require("../../../data-structures/utxo/Utxo.cjs"),w=require("../../../data-structures/custom-token-registry/CustomTokenRegistry.cjs"),x=require("../../../data-structures/volatile-helper/VolatileHelper.cjs"),P=require("../etherFunctions.cjs"),S=require("../../../error-handling/customErrors/ErrorWithAmount.cjs"),y=require("./getInputUtxoAndBalance.cjs"),b=new A.Mutex,v=async
|
|
2
|
-
Please try again with ${g.symbol}`;throw new S.ErrorWithAmount(f,T)}e.push(
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("async-mutex"),q=require("../../../constants/token-data/ERC20Registry.cjs"),I=require("../../utils/erc20tokenFunctions.cjs"),p=require("../../utils/caseInsensitive.utils.cjs"),k=require("../../utils/volatile-patcher.utils.cjs"),U=require("../../../data-structures/utxo/Utxo.cjs"),w=require("../../../data-structures/custom-token-registry/CustomTokenRegistry.cjs"),x=require("../../../data-structures/volatile-helper/VolatileHelper.cjs"),P=require("../etherFunctions.cjs"),S=require("../../../error-handling/customErrors/ErrorWithAmount.cjs"),y=require("./getInputUtxoAndBalance.cjs"),b=new A.Mutex,v=async i=>{const r=await b.acquire(),{inputUtxos:a}=await y.getInputUtxoAndBalance({hinkal:i,sliceIfMore6:!1}),n=i.getCurrentChainId(),u=[...q.getERC20Registry(n),...w.customTokenRegistry.getCustomTokens(n)];await k.patchRegistry(n);const h=u.map(e=>({token:e,balance:a.reduce((t,c)=>{const s=e.isVolatile?e.sharedAddress:e.erc20TokenAddress;return p.caseInsensitiveEqual(s,c.erc20TokenAddress)?t+c.amount:t},0n),timestamp:a.filter(t=>p.caseInsensitiveEqual(t.erc20TokenAddress,e.erc20TokenAddress))[0]?.timeStamp,nfts:a.filter(t=>p.caseInsensitiveEqual(t.erc20TokenAddress,e.erc20TokenAddress)&&t.tokenId!==0).map(t=>({tokenId:t.tokenId,timestamp:t.timeStamp}))})),m=await Promise.all(h.map(async e=>{if(!e.token.isVolatile)return e;e.token?.sharedAddress||console.log("VolatileToken must have a corresponding sharedAddress");let t=0n;return e.balance>0n&&(t=await x.VolatileHelper.getVolatileTokenBalance(n,e.token.sharedAddress,e.balance)),{...e,balance:BigInt(t)}}));return r(),m},E=async(i,r,a,n=6,u=r.map(()=>0),h=!1)=>{const{userKeys:m}=i,e=[],t=[];let c=0;for(let s=0;s<r.length;s+=1)if(h===!1){const{inputUtxos:o}=await y.getInputUtxoAndBalance({hinkal:i,erc20TokenAddress:r[s],tokenId:u[s],sliceIfMore6:!1});c=Math.max(o.length,c),t.push(o)}else t.push([]);return c===2?t:(t.forEach((s,o)=>{if(s.length>n){const d=s.slice(0,n),l=d.reduce((g,f)=>g+f.amount,0n);if(a[o]<0n&&l<-a[o]){const g=I.getERC20Token(r[o],i.getCurrentChainId()),f=Number(P.getAmountWithPrecision(l,g,2)),T=`Unfortunately your transaction did not go through due to UTXOs limitations.
|
|
2
|
+
Please try again with ${g.symbol}`;throw new S.ErrorWithAmount(f,T)}e.push(d)}else if(s.length<=n){const d=[...s];let l=n-s.length;for(;l>0;)l-=1,d.push(new U.Utxo({amount:0n,erc20TokenAddress:r[o],shieldedPrivateKey:m.getShieldedPrivateKey(),tokenId:u[o]}));e.push(d)}}),e)};exports.addPaddingToUtxos=E;exports.getShieldedBalance=v;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Mutex as A } from "async-mutex";
|
|
2
2
|
import { getERC20Registry as w } from "../../../constants/token-data/ERC20Registry.mjs";
|
|
3
3
|
import { getERC20Token as k } from "../../utils/erc20tokenFunctions.mjs";
|
|
4
|
-
import { caseInsensitiveEqual as
|
|
4
|
+
import { caseInsensitiveEqual as g } from "../../utils/caseInsensitive.utils.mjs";
|
|
5
5
|
import { patchRegistry as I } from "../../utils/volatile-patcher.utils.mjs";
|
|
6
6
|
import { Utxo as U } from "../../../data-structures/utxo/Utxo.mjs";
|
|
7
7
|
import { customTokenRegistry as P } from "../../../data-structures/custom-token-registry/CustomTokenRegistry.mjs";
|
|
@@ -9,20 +9,20 @@ import { VolatileHelper as b } from "../../../data-structures/volatile-helper/Vo
|
|
|
9
9
|
import { getAmountWithPrecision as x } from "../etherFunctions.mjs";
|
|
10
10
|
import { ErrorWithAmount as S } from "../../../error-handling/customErrors/ErrorWithAmount.mjs";
|
|
11
11
|
import { getInputUtxoAndBalance as T } from "./getInputUtxoAndBalance.mjs";
|
|
12
|
-
const C = new A(), O = async (
|
|
13
|
-
const n = await C.acquire(), { inputUtxos:
|
|
12
|
+
const C = new A(), O = async (i) => {
|
|
13
|
+
const n = await C.acquire(), { inputUtxos: a } = await T({ hinkal: i, sliceIfMore6: !1 }), s = i.getCurrentChainId(), c = [...w(s), ...P.getCustomTokens(s)];
|
|
14
14
|
await I(s);
|
|
15
15
|
const p = c.map((e) => ({
|
|
16
16
|
token: e,
|
|
17
|
-
balance:
|
|
17
|
+
balance: a.reduce((t, d) => {
|
|
18
18
|
const o = e.isVolatile ? e.sharedAddress : e.erc20TokenAddress;
|
|
19
|
-
return
|
|
19
|
+
return g(o, d.erc20TokenAddress) ? t + d.amount : t;
|
|
20
20
|
}, 0n),
|
|
21
|
-
timestamp:
|
|
22
|
-
(t) =>
|
|
21
|
+
timestamp: a.filter(
|
|
22
|
+
(t) => g(t.erc20TokenAddress, e.erc20TokenAddress)
|
|
23
23
|
)[0]?.timeStamp,
|
|
24
|
-
nfts:
|
|
25
|
-
(t) =>
|
|
24
|
+
nfts: a.filter(
|
|
25
|
+
(t) => g(t.erc20TokenAddress, e.erc20TokenAddress) && t.tokenId !== 0
|
|
26
26
|
).map((t) => ({ tokenId: t.tokenId, timestamp: t.timeStamp }))
|
|
27
27
|
})), u = await Promise.all(
|
|
28
28
|
p.map(async (e) => {
|
|
@@ -41,34 +41,34 @@ const C = new A(), O = async (a) => {
|
|
|
41
41
|
})
|
|
42
42
|
);
|
|
43
43
|
return n(), u;
|
|
44
|
-
}, X = async (
|
|
45
|
-
const { userKeys: u } =
|
|
46
|
-
let
|
|
44
|
+
}, X = async (i, n, a, s = 6, c = n.map(() => 0), p = !1) => {
|
|
45
|
+
const { userKeys: u } = i, e = [], t = [];
|
|
46
|
+
let d = 0;
|
|
47
47
|
for (let o = 0; o < n.length; o += 1)
|
|
48
48
|
if (p === !1) {
|
|
49
49
|
const { inputUtxos: r } = await T({
|
|
50
|
-
hinkal:
|
|
50
|
+
hinkal: i,
|
|
51
51
|
erc20TokenAddress: n[o],
|
|
52
52
|
tokenId: c[o],
|
|
53
53
|
sliceIfMore6: !1
|
|
54
54
|
});
|
|
55
|
-
|
|
55
|
+
d = Math.max(r.length, d), t.push(r);
|
|
56
56
|
} else
|
|
57
57
|
t.push([]);
|
|
58
|
-
return
|
|
58
|
+
return d === 2 ? t : (t.forEach((o, r) => {
|
|
59
59
|
if (o.length > s) {
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
62
|
-
const f = k(n[r],
|
|
60
|
+
const m = o.slice(0, s), l = m.reduce((f, h) => f + h.amount, 0n);
|
|
61
|
+
if (a[r] < 0n && l < -a[r]) {
|
|
62
|
+
const f = k(n[r], i.getCurrentChainId()), h = Number(x(l, f, 2)), y = `Unfortunately your transaction did not go through due to UTXOs limitations.
|
|
63
63
|
Please try again with ${f.symbol}`;
|
|
64
|
-
throw new S(
|
|
64
|
+
throw new S(h, y);
|
|
65
65
|
}
|
|
66
|
-
e.push(
|
|
66
|
+
e.push(m);
|
|
67
67
|
} else if (o.length <= s) {
|
|
68
|
-
const
|
|
69
|
-
let
|
|
70
|
-
for (;
|
|
71
|
-
|
|
68
|
+
const m = [...o];
|
|
69
|
+
let l = s - o.length;
|
|
70
|
+
for (; l > 0; )
|
|
71
|
+
l -= 1, m.push(
|
|
72
72
|
new U({
|
|
73
73
|
amount: 0n,
|
|
74
74
|
erc20TokenAddress: n[r],
|
|
@@ -76,7 +76,7 @@ const C = new A(), O = async (a) => {
|
|
|
76
76
|
tokenId: c[r]
|
|
77
77
|
})
|
|
78
78
|
);
|
|
79
|
-
e.push(
|
|
79
|
+
e.push(m);
|
|
80
80
|
}
|
|
81
81
|
}), e);
|
|
82
82
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("../../../constants/protocol.constants.cjs"),T=require("../../../types/ethereum-network.types.cjs"),A=require("./approveToken.cjs"),q=require("../../utils/time.utils.cjs"),S=async(s,e,o,t,i,n,l,h)=>{const a=s.getContractWithSigner(T.ContractType.HinkalContract),p=await s.getEthereumAddress(),v=l??a,d=h??a,g="transact";e>0n&&o.erc20TokenAddress!==u.zeroAddress&&await A.approveTokenToHinkal(s,v,e,o);const c={value:e>0n&&o.erc20TokenAddress===u.zeroAddress?BigInt(e).toString():void 0};let r;try{r=(await d.estimateGas[g](t[0],t[1],t[2],n,i,{...c,from:p})).toNumber()}catch(y){console.log("hinkalDeposit: gas estimation error: ",{err:y})}const m=r&&r>=0?Math.ceil(r*12/10):void 0;return c.gasLimit=m,await q.waitLittle(),await d[g](t[0],t[1],t[2],n,i,c)};exports.transactCallDirect=S;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import { zeroAddress as
|
|
2
|
-
import { ContractType as
|
|
3
|
-
import { approveTokenToHinkal as
|
|
4
|
-
import { waitLittle as
|
|
5
|
-
const
|
|
6
|
-
const a = s.getContractWithSigner(
|
|
7
|
-
|
|
1
|
+
import { zeroAddress as g } from "../../../constants/protocol.constants.mjs";
|
|
2
|
+
import { ContractType as T } from "../../../types/ethereum-network.types.mjs";
|
|
3
|
+
import { approveTokenToHinkal as y } from "./approveToken.mjs";
|
|
4
|
+
import { waitLittle as u } from "../../utils/time.utils.mjs";
|
|
5
|
+
const S = async (s, r, e, t, c, n, p, f) => {
|
|
6
|
+
const a = s.getContractWithSigner(T.HinkalContract), h = await s.getEthereumAddress(), v = p ?? a, d = f ?? a, m = "transact";
|
|
7
|
+
r > 0n && e.erc20TokenAddress !== g && await y(s, v, r, e);
|
|
8
8
|
const i = {
|
|
9
|
-
value: r > 0n && e.erc20TokenAddress ===
|
|
9
|
+
value: r > 0n && e.erc20TokenAddress === g ? BigInt(r).toString() : void 0
|
|
10
10
|
};
|
|
11
11
|
let o;
|
|
12
12
|
try {
|
|
13
|
-
o = (await d.estimateGas[
|
|
13
|
+
o = (await d.estimateGas[m](
|
|
14
14
|
t[0],
|
|
15
15
|
t[1],
|
|
16
16
|
t[2],
|
|
17
17
|
n,
|
|
18
18
|
c,
|
|
19
19
|
{ ...i, from: h }
|
|
20
|
-
)).toNumber()
|
|
21
|
-
} catch (
|
|
22
|
-
console.log("hinkalDeposit: gas estimation error: ", { err:
|
|
20
|
+
)).toNumber();
|
|
21
|
+
} catch (A) {
|
|
22
|
+
console.log("hinkalDeposit: gas estimation error: ", { err: A });
|
|
23
23
|
}
|
|
24
|
-
const
|
|
25
|
-
return i.gasLimit =
|
|
24
|
+
const x = o && o >= 0 ? Math.ceil(o * 12 / 10) : void 0;
|
|
25
|
+
return i.gasLimit = x, await u(), await d[m](
|
|
26
26
|
t[0],
|
|
27
27
|
t[1],
|
|
28
28
|
t[2],
|
|
@@ -32,5 +32,5 @@ const H = async (s, r, e, t, c, n, f, p) => {
|
|
|
32
32
|
);
|
|
33
33
|
};
|
|
34
34
|
export {
|
|
35
|
-
|
|
35
|
+
S as transactCallDirect
|
|
36
36
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../error-handling/error-codes.constants.cjs");require("ethers");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../error-handling/error-codes.constants.cjs");require("ethers");const m=require("../../error-handling/get-error.message.cjs");require("axios");require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs");require("../../constants/reorg-depths.constants.cjs");const l=5e4,d=1,w=11,P=15,g=async(t,s)=>{try{const r=await t.getFeeData(),a=s===0?w:P;return r.gasPrice?.mul(a).div(10)??void 0}catch(r){console.log("getGasPrice error: ",{err:r});return}},q=(t,s,r)=>new Promise((a,o)=>{const n=setTimeout(()=>{o(new Error(c.transactionErrorCodes.TRANSACTION_TIMEOUT))},r);t.wait(s).then(e=>{clearTimeout(n),a(e)}).catch(e=>{clearTimeout(n),o(e)})}),T=async({contractFunction:t,args:s,gasPrice:r,gasLimit:a,nonce:o,confirmations:n,waitTime:e})=>{const i=await t(...s,{type:0,gasLimit:a,gasPrice:r,nonce:o});return await q(i,n??d,e??l)},E=async({provider:t,contractFunction:s,args:r,gasLimit:a,nonce:o,confirmations:n})=>{try{const e=await g(t,0);return await T({contractFunction:s,args:r,gasPrice:e,gasLimit:a,nonce:o,confirmations:n})}catch(e){const i=m.getErrorMessage(e);if(i===c.UserFriendlyErrorCodes.MAX_FEE_GAS_ERROR||i===c.transactionErrorCodes.TRANSACTION_TIMEOUT){console.log("Timeout Hit: Increase gas");const u=await g(t,1);return await T({contractFunction:s,args:r,gasPrice:u,gasLimit:a,nonce:o,confirmations:n})}throw e}};exports.runContractFunction=E;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { UserFriendlyErrorCodes as
|
|
1
|
+
import { UserFriendlyErrorCodes as g, transactionErrorCodes as T } from "../../error-handling/error-codes.constants.mjs";
|
|
2
2
|
import "ethers";
|
|
3
|
-
import { getErrorMessage as
|
|
3
|
+
import { getErrorMessage as p } from "../../error-handling/get-error.message.mjs";
|
|
4
4
|
import "axios";
|
|
5
5
|
import "../../constants/chains.constants.mjs";
|
|
6
6
|
import "../../constants/vite.constants.mjs";
|
|
@@ -9,70 +9,70 @@ import "../../types/transactions.types.mjs";
|
|
|
9
9
|
import "../../types/curve.types.mjs";
|
|
10
10
|
import "circomlibjs";
|
|
11
11
|
import "../../constants/reorg-depths.constants.mjs";
|
|
12
|
-
const
|
|
12
|
+
const w = 5e4, l = 1, P = 11, d = 15, m = async (o, e) => {
|
|
13
13
|
try {
|
|
14
|
-
const t = await
|
|
15
|
-
return
|
|
14
|
+
const t = await o.getFeeData(), a = e === 0 ? P : d;
|
|
15
|
+
return t.gasPrice?.mul(a).div(10) ?? void 0;
|
|
16
16
|
} catch (t) {
|
|
17
17
|
console.log("getGasPrice error: ", { err: t });
|
|
18
18
|
return;
|
|
19
19
|
}
|
|
20
|
-
}, E = (
|
|
21
|
-
const
|
|
22
|
-
|
|
20
|
+
}, E = (o, e, t) => new Promise((a, s) => {
|
|
21
|
+
const i = setTimeout(() => {
|
|
22
|
+
s(new Error(T.TRANSACTION_TIMEOUT));
|
|
23
23
|
}, t);
|
|
24
|
-
|
|
25
|
-
clearTimeout(
|
|
26
|
-
}).catch((
|
|
27
|
-
clearTimeout(
|
|
24
|
+
o.wait(e).then((r) => {
|
|
25
|
+
clearTimeout(i), a(r);
|
|
26
|
+
}).catch((r) => {
|
|
27
|
+
clearTimeout(i), s(r);
|
|
28
28
|
});
|
|
29
29
|
}), u = async ({
|
|
30
|
-
contractFunction:
|
|
30
|
+
contractFunction: o,
|
|
31
31
|
args: e,
|
|
32
32
|
gasPrice: t,
|
|
33
|
-
gasLimit:
|
|
34
|
-
nonce:
|
|
35
|
-
confirmations:
|
|
36
|
-
waitTime:
|
|
33
|
+
gasLimit: a,
|
|
34
|
+
nonce: s,
|
|
35
|
+
confirmations: i,
|
|
36
|
+
waitTime: r
|
|
37
37
|
}) => {
|
|
38
|
-
const
|
|
38
|
+
const n = await o(...e, {
|
|
39
39
|
type: 0,
|
|
40
|
-
gasLimit:
|
|
40
|
+
gasLimit: a,
|
|
41
41
|
gasPrice: t,
|
|
42
|
-
nonce:
|
|
42
|
+
nonce: s
|
|
43
43
|
});
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
return await E(
|
|
45
|
+
n,
|
|
46
|
+
i ?? l,
|
|
47
|
+
r ?? w
|
|
48
48
|
);
|
|
49
49
|
}, N = async ({
|
|
50
|
-
provider:
|
|
50
|
+
provider: o,
|
|
51
51
|
contractFunction: e,
|
|
52
52
|
args: t,
|
|
53
|
-
gasLimit:
|
|
54
|
-
nonce:
|
|
55
|
-
confirmations:
|
|
53
|
+
gasLimit: a,
|
|
54
|
+
nonce: s,
|
|
55
|
+
confirmations: i
|
|
56
56
|
}) => {
|
|
57
57
|
try {
|
|
58
|
-
const
|
|
59
|
-
|
|
58
|
+
const r = await m(
|
|
59
|
+
o,
|
|
60
60
|
0
|
|
61
61
|
/* Initial */
|
|
62
62
|
);
|
|
63
|
-
return await u({ contractFunction: e, args: t, gasPrice:
|
|
64
|
-
} catch (
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
63
|
+
return await u({ contractFunction: e, args: t, gasPrice: r, gasLimit: a, nonce: s, confirmations: i });
|
|
64
|
+
} catch (r) {
|
|
65
|
+
const n = p(r);
|
|
66
|
+
if (n === g.MAX_FEE_GAS_ERROR || n === T.TRANSACTION_TIMEOUT) {
|
|
67
67
|
console.log("Timeout Hit: Increase gas");
|
|
68
68
|
const c = await m(
|
|
69
|
-
|
|
69
|
+
o,
|
|
70
70
|
1
|
|
71
71
|
/* Secondary */
|
|
72
72
|
);
|
|
73
|
-
return await u({ contractFunction: e, args: t, gasPrice: c, gasLimit:
|
|
73
|
+
return await u({ contractFunction: e, args: t, gasPrice: c, gasLimit: a, nonce: s, confirmations: i });
|
|
74
74
|
}
|
|
75
|
-
throw
|
|
75
|
+
throw r;
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("ethers"),d=require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");const C=require("../../constants/protocol.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const l=require("../../error-handling/error-codes.constants.cjs"),y=require("./etherFunctions.cjs");require("axios");require("../../types/circom-data.types.cjs");const u=require("../../types/ethereum-network.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs");const h=require("../../error-handling/logError.cjs"),w=async(t,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const q=require("ethers"),d=require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");const C=require("../../constants/protocol.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const l=require("../../error-handling/error-codes.constants.cjs"),y=require("./etherFunctions.cjs");require("axios");require("../../types/circom-data.types.cjs");const u=require("../../types/ethereum-network.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs");const h=require("../../error-handling/logError.cjs"),w=async(t,s,r,o)=>{const c=(await Promise.all([100,500,3e3,1e4].map(async e=>({poolAddress:await s.getPool(r,o,e),fee:e})))).filter(({poolAddress:e})=>e!==C.zeroAddress),n=await Promise.all(c.map(async e=>({poolAddress:e.poolAddress,fee:e.fee,token1Balance:(await t.balanceOf(e.poolAddress)).toBigInt()}))),i=n.map(e=>e.token1Balance).reduce((e,p)=>p>=e?p:e,0n);if(i===0n)throw new Error(l.transactionErrorCodes.UNISWAP_NOT_ENOUGH_LIQUIDITY);return n.find(e=>e.token1Balance===i)},g=async(t,s,r,o,c)=>{try{if(!d.networkRegistry[t.getCurrentChainId()].quoterV2Address)throw Error("No Quoter Contract Provided");return(await t.getContractWithFetcher(u.ContractType.UniswapV3QuoterContract,d.networkRegistry[t.getCurrentChainId()].quoterV2Address).callStatic.quoteExactInputSingle({tokenIn:s.wrappedErc20TokenAddress??s.erc20TokenAddress,tokenOut:r.wrappedErc20TokenAddress??r.erc20TokenAddress,fee:o,amountIn:c,sqrtPriceLimitX96:0})).amountOut.toBigInt()}catch(n){throw h.logError(n),n}},A=async(t,s,r)=>{try{const o=t.getCurrentChainId(),c=t.getContractWithFetcher(u.ContractType.UniswapV3FactoryContract,d.networkRegistry[o].uniswapV3FactoryAddress),n=t.getContractWithFetcher(u.ContractType.ERC20Contract,r.wrappedErc20TokenAddress??r.erc20TokenAddress),{fee:a}=await w(n,c,s.wrappedErc20TokenAddress??s.erc20TokenAddress,r.wrappedErc20TokenAddress??r.erc20TokenAddress);return a}catch(o){throw console.log("Error in getUniswapFee",o),o}},P=async(t,s,r,o)=>{try{const c=await A(t,r,o),n=q.utils.defaultAbiCoder.encode(["uint24"],[c]),a=y.getAmountInWei(r,s);return{tokenPrice:await g(t,r,o,c,a),poolFee:n}}catch{throw Error(l.transactionErrorCodes.NO_UNISWAP_PRICE)}};exports.getUniswapFee=A;exports.getUniswapPrice=P;exports.getUniswapPriceHelper=g;exports.searchPoolAndFee=w;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { utils as
|
|
1
|
+
import { utils as w } from "ethers";
|
|
2
2
|
import { networkRegistry as d } from "../../constants/chains.constants.mjs";
|
|
3
3
|
import "../../constants/vite.constants.mjs";
|
|
4
4
|
import "../../constants/contracts.constants.mjs";
|
|
5
5
|
import "../../constants/kyc.constants.mjs";
|
|
6
|
-
import { zeroAddress as
|
|
6
|
+
import { zeroAddress as A } from "../../constants/protocol.constants.mjs";
|
|
7
7
|
import "../../constants/coingecko.constants.mjs";
|
|
8
8
|
import "../../constants/axelar.constants.mjs";
|
|
9
9
|
import "../../constants/rewards.constants.mjs";
|
|
10
10
|
import "../../constants/reorg-depths.constants.mjs";
|
|
11
11
|
import { transactionErrorCodes as u } from "../../error-handling/error-codes.constants.mjs";
|
|
12
|
-
import { getAmountInWei as
|
|
12
|
+
import { getAmountInWei as l } from "./etherFunctions.mjs";
|
|
13
13
|
import "axios";
|
|
14
14
|
import "../../types/circom-data.types.mjs";
|
|
15
15
|
import { ContractType as p } from "../../types/ethereum-network.types.mjs";
|
|
@@ -17,23 +17,23 @@ import "../../types/transactions.types.mjs";
|
|
|
17
17
|
import "../../types/curve.types.mjs";
|
|
18
18
|
import "circomlibjs";
|
|
19
19
|
import { logError as C } from "../../error-handling/logError.mjs";
|
|
20
|
-
const
|
|
21
|
-
const
|
|
20
|
+
const f = async (e, s, t, o) => {
|
|
21
|
+
const c = (await Promise.all(
|
|
22
22
|
[100, 500, 3e3, 1e4].map(async (r) => ({
|
|
23
|
-
poolAddress: await
|
|
23
|
+
poolAddress: await s.getPool(t, o, r),
|
|
24
24
|
fee: r
|
|
25
25
|
}))
|
|
26
|
-
)).filter(({ poolAddress: r }) => r !==
|
|
27
|
-
|
|
26
|
+
)).filter(({ poolAddress: r }) => r !== A), n = await Promise.all(
|
|
27
|
+
c.map(async (r) => ({
|
|
28
28
|
poolAddress: r.poolAddress,
|
|
29
29
|
fee: r.fee,
|
|
30
30
|
token1Balance: (await e.balanceOf(r.poolAddress)).toBigInt()
|
|
31
31
|
}))
|
|
32
|
-
), i =
|
|
32
|
+
), i = n.map((r) => r.token1Balance).reduce((r, m) => m >= r ? m : r, 0n);
|
|
33
33
|
if (i === 0n)
|
|
34
34
|
throw new Error(u.UNISWAP_NOT_ENOUGH_LIQUIDITY);
|
|
35
|
-
return
|
|
36
|
-
},
|
|
35
|
+
return n.find((r) => r.token1Balance === i);
|
|
36
|
+
}, g = async (e, s, t, o, c) => {
|
|
37
37
|
try {
|
|
38
38
|
if (!d[e.getCurrentChainId()].quoterV2Address)
|
|
39
39
|
throw Error("No Quoter Contract Provided");
|
|
@@ -41,44 +41,44 @@ const g = async (e, c, t, o) => {
|
|
|
41
41
|
p.UniswapV3QuoterContract,
|
|
42
42
|
d[e.getCurrentChainId()].quoterV2Address
|
|
43
43
|
).callStatic.quoteExactInputSingle({
|
|
44
|
-
tokenIn:
|
|
44
|
+
tokenIn: s.wrappedErc20TokenAddress ?? s.erc20TokenAddress,
|
|
45
45
|
tokenOut: t.wrappedErc20TokenAddress ?? t.erc20TokenAddress,
|
|
46
46
|
fee: o,
|
|
47
|
-
amountIn:
|
|
47
|
+
amountIn: c,
|
|
48
48
|
sqrtPriceLimitX96: 0
|
|
49
49
|
})).amountOut.toBigInt();
|
|
50
|
-
} catch (
|
|
51
|
-
throw C(
|
|
50
|
+
} catch (n) {
|
|
51
|
+
throw C(n), n;
|
|
52
52
|
}
|
|
53
|
-
}, I = async (e,
|
|
53
|
+
}, I = async (e, s, t) => {
|
|
54
54
|
try {
|
|
55
|
-
const o = e.getCurrentChainId(),
|
|
55
|
+
const o = e.getCurrentChainId(), c = e.getContractWithFetcher(
|
|
56
56
|
p.UniswapV3FactoryContract,
|
|
57
57
|
d[o].uniswapV3FactoryAddress
|
|
58
|
-
),
|
|
58
|
+
), n = e.getContractWithFetcher(
|
|
59
59
|
p.ERC20Contract,
|
|
60
60
|
t.wrappedErc20TokenAddress ?? t.erc20TokenAddress
|
|
61
|
-
), { fee: a } = await
|
|
62
|
-
s,
|
|
61
|
+
), { fee: a } = await f(
|
|
63
62
|
n,
|
|
64
|
-
c
|
|
63
|
+
c,
|
|
64
|
+
s.wrappedErc20TokenAddress ?? s.erc20TokenAddress,
|
|
65
65
|
t.wrappedErc20TokenAddress ?? t.erc20TokenAddress
|
|
66
66
|
);
|
|
67
67
|
return a;
|
|
68
68
|
} catch (o) {
|
|
69
69
|
throw console.log("Error in getUniswapFee", o), o;
|
|
70
70
|
}
|
|
71
|
-
}, L = async (e,
|
|
71
|
+
}, L = async (e, s, t, o) => {
|
|
72
72
|
try {
|
|
73
|
-
const
|
|
74
|
-
return { tokenPrice: await
|
|
75
|
-
} catch
|
|
76
|
-
throw
|
|
73
|
+
const c = await I(e, t, o), n = w.defaultAbiCoder.encode(["uint24"], [c]), a = l(t, s);
|
|
74
|
+
return { tokenPrice: await g(e, t, o, c, a), poolFee: n };
|
|
75
|
+
} catch {
|
|
76
|
+
throw Error(u.NO_UNISWAP_PRICE);
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
export {
|
|
80
80
|
I as getUniswapFee,
|
|
81
81
|
L as getUniswapPrice,
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
g as getUniswapPriceHelper,
|
|
83
|
+
f as searchPoolAndFee
|
|
84
84
|
};
|
package/package.json
CHANGED
package/types/relayer.types.d.ts
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
1
|
export interface RelayerTransaction {
|
|
2
|
+
to: string;
|
|
3
|
+
from: string;
|
|
4
|
+
contractAddress: string | null;
|
|
5
|
+
gasUsed: {
|
|
6
|
+
type: string;
|
|
7
|
+
hex: string;
|
|
8
|
+
};
|
|
9
|
+
logsBloom: string;
|
|
10
|
+
blockHash: string;
|
|
2
11
|
transactionHash: string;
|
|
12
|
+
blockNumber: number;
|
|
13
|
+
confirmations: number;
|
|
14
|
+
cumulativeGasUsed: {
|
|
15
|
+
type: string;
|
|
16
|
+
hex: string;
|
|
17
|
+
};
|
|
18
|
+
effectiveGasPrice: {
|
|
19
|
+
type: string;
|
|
20
|
+
hex: string;
|
|
21
|
+
};
|
|
22
|
+
status: number;
|
|
23
|
+
type: number;
|
|
24
|
+
byzantium: boolean;
|
|
3
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/snarkjsWorkerLauncher-
|
|
1
|
+
"use strict";const e=""+(typeof document>"u"?require("url").pathToFileURL(__dirname+"/../../assets/snarkjsWorkerLauncher-D2n9Ry7V.js").href:new URL("../../assets/snarkjsWorkerLauncher-D2n9Ry7V.js",document.currentScript&&document.currentScript.src||document.baseURI).href);module.exports=e;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("../workerProxy.cjs"),
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("../workerProxy.cjs"),n=require("../../constants/vite.constants.cjs"),w=require("snarkjs");function $(t){const i=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const s=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,s.get?s:{enumerable:!0,get:()=>t[e]})}}return i.default=t,Object.freeze(i)}const h=$(w),c=new P.WorkerProxy,p=async t=>{const{input:i,wasmFilePath:e,zKeyFilePath:s,chainId:f}=t.payload.data,{hostLocation:{origin:l},constants:{isDevelopment:g,chains:{chainIds:b}}}=t.metadata;let o=e,r=s;const u=o.startsWith("https://");if(n.isNode&&!u){n.isWebpack?(o=`libs/hardhat/test/circuits/${e}`,r=`libs/hardhat/test/circuits/${s}`):!n.isWebpack&&g&&(o=`test/circuits/${e}`,r=`test/circuits/${s}`);const a=require("path");o=a.resolve(o),r=a.resolve(r)}n.isNode&&u?process.browser=!0:f===b.localhost&&!n.isNode&&(o=`${l}/${e}`,r=`${l}/${s}`);try{const{proof:a,publicSignals:d}=await h.groth16.fullProve(i,o,r),k=await h.groth16.exportSolidityCallData(a,d),y=JSON.parse(`[${k}]`);c.postMessageToMainThread({zkCallData:y,proof:a,publicSignals:d})}catch(a){console.log(a)}};c.attachWorkerSideOnMessage(p);exports.default=c;exports.onWorkerMessage=p;
|
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
import { WorkerProxy as w } from "../workerProxy.mjs";
|
|
2
|
-
import { isNode as
|
|
2
|
+
import { isNode as i, isWebpack as h } from "../../constants/vite.constants.mjs";
|
|
3
3
|
import * as p from "snarkjs";
|
|
4
|
-
const
|
|
5
|
-
const { input:
|
|
6
|
-
hostLocation: { origin:
|
|
4
|
+
const u = new w(), y = async (r) => {
|
|
5
|
+
const { input: d, wasmFilePath: e, zKeyFilePath: o, chainId: f } = r.payload.data, {
|
|
6
|
+
hostLocation: { origin: l },
|
|
7
7
|
constants: {
|
|
8
8
|
isDevelopment: m,
|
|
9
|
-
chains: { chainIds:
|
|
9
|
+
chains: { chainIds: $ }
|
|
10
10
|
}
|
|
11
|
-
} =
|
|
12
|
-
let t =
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
|
|
11
|
+
} = r.metadata;
|
|
12
|
+
let t = e, a = o;
|
|
13
|
+
const c = t.startsWith("https://");
|
|
14
|
+
if (i && !c) {
|
|
15
|
+
h ? (t = `libs/hardhat/test/circuits/${e}`, a = `libs/hardhat/test/circuits/${o}`) : !h && m && (t = `test/circuits/${e}`, a = `test/circuits/${o}`);
|
|
16
16
|
const s = require("path");
|
|
17
|
-
t = s.resolve(t),
|
|
17
|
+
t = s.resolve(t), a = s.resolve(a);
|
|
18
18
|
}
|
|
19
|
-
|
|
19
|
+
i && c ? process.browser = !0 : f === $.localhost && !i && (t = `${l}/${e}`, a = `${l}/${o}`);
|
|
20
20
|
try {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
f.postMessageToMainThread({ zkCallData: k, proof: s, publicSignals: h });
|
|
21
|
+
const { proof: s, publicSignals: n } = await p.groth16.fullProve(d, t, a), g = await p.groth16.exportSolidityCallData(s, n), k = JSON.parse(`[${g}]`);
|
|
22
|
+
u.postMessageToMainThread({ zkCallData: k, proof: s, publicSignals: n });
|
|
24
23
|
} catch (s) {
|
|
25
24
|
console.log(s);
|
|
26
25
|
}
|
|
27
26
|
};
|
|
28
|
-
|
|
27
|
+
u.attachWorkerSideOnMessage(y);
|
|
29
28
|
export {
|
|
30
|
-
|
|
29
|
+
u as default,
|
|
31
30
|
y as onWorkerMessage
|
|
32
31
|
};
|