@hinkal/common 0.1.33 → 0.1.34
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/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/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
|
@@ -11,7 +11,7 @@ import { caseInsensitiveEqual as i } from "../utils/caseInsensitive.utils.mjs";
|
|
|
11
11
|
import "../../types/circom-data.types.mjs";
|
|
12
12
|
import { PendleAction as p } from "../../types/hinkal.types.mjs";
|
|
13
13
|
import "../../types/transactions.types.mjs";
|
|
14
|
-
import { PendleAssetType as d, PendleSwapType as
|
|
14
|
+
import { PendleAssetType as d, PendleSwapType as o } from "../../types/pendle.types.mjs";
|
|
15
15
|
import "../../types/curve.types.mjs";
|
|
16
16
|
import "ethers";
|
|
17
17
|
import "circomlibjs";
|
|
@@ -24,77 +24,77 @@ import "axios";
|
|
|
24
24
|
import "../utils/userAgent.mjs";
|
|
25
25
|
import "../../data-structures/custom-token-registry/CustomTokenRegistry.mjs";
|
|
26
26
|
import "../../data-structures/volatile-helper/VolatileHelper.mjs";
|
|
27
|
-
import { isInEnum as
|
|
27
|
+
import { isInEnum as k } from "../utils/enum.utils.mjs";
|
|
28
28
|
function V(e) {
|
|
29
29
|
if (!e)
|
|
30
30
|
return;
|
|
31
31
|
const r = T(e.address, e.chainId);
|
|
32
32
|
if (!r?.isVolatile)
|
|
33
|
-
return r
|
|
33
|
+
return r;
|
|
34
34
|
}
|
|
35
35
|
function j(e, r) {
|
|
36
36
|
if (!e || !r)
|
|
37
37
|
return;
|
|
38
|
-
let
|
|
38
|
+
let t;
|
|
39
39
|
switch (r) {
|
|
40
40
|
case d.YT:
|
|
41
|
-
|
|
41
|
+
t = e?.yt;
|
|
42
42
|
break;
|
|
43
43
|
case d.PT:
|
|
44
|
-
|
|
44
|
+
t = e?.pt;
|
|
45
45
|
break;
|
|
46
46
|
case d.PENDLE_LP:
|
|
47
|
-
|
|
47
|
+
t = e?.lp;
|
|
48
48
|
break;
|
|
49
49
|
case d.SY:
|
|
50
|
-
|
|
50
|
+
t = e?.sy;
|
|
51
51
|
break;
|
|
52
52
|
default:
|
|
53
|
-
|
|
53
|
+
t = void 0;
|
|
54
54
|
break;
|
|
55
55
|
}
|
|
56
|
-
return
|
|
56
|
+
return t;
|
|
57
57
|
}
|
|
58
|
-
const z = (e, r,
|
|
59
|
-
if (i(e.yt.address,
|
|
60
|
-
return
|
|
61
|
-
if (i(e.pt.address,
|
|
62
|
-
return
|
|
58
|
+
const z = (e, r, t) => {
|
|
59
|
+
if (i(e.yt.address, t.erc20TokenAddress))
|
|
60
|
+
return o.SwapExactTokenForYt;
|
|
61
|
+
if (i(e.pt.address, t.erc20TokenAddress))
|
|
62
|
+
return o.SwapExactTokenForPt;
|
|
63
63
|
if (i(e.yt.address, r.erc20TokenAddress))
|
|
64
|
-
return
|
|
64
|
+
return o.SwapExactYtForToken;
|
|
65
65
|
if (i(e.pt.address, r.erc20TokenAddress))
|
|
66
|
-
return
|
|
66
|
+
return o.SwapExactPtForToken;
|
|
67
67
|
}, H = (e) => {
|
|
68
68
|
let r;
|
|
69
69
|
switch (e) {
|
|
70
|
-
case
|
|
70
|
+
case o.SwapExactTokenForYt:
|
|
71
71
|
r = n.ROUTES.pendleSwapExactTokenForYT;
|
|
72
72
|
break;
|
|
73
|
-
case
|
|
73
|
+
case o.SwapExactTokenForPt:
|
|
74
74
|
r = n.ROUTES.pendleSwapExactTokenForPt;
|
|
75
75
|
break;
|
|
76
|
-
case
|
|
76
|
+
case o.SwapExactYtForToken:
|
|
77
77
|
r = n.ROUTES.pendleSwapExactYtForToken;
|
|
78
78
|
break;
|
|
79
|
-
case
|
|
79
|
+
case o.SwapExactPtForToken:
|
|
80
80
|
r = n.ROUTES.pendleSwapExactPtForToken;
|
|
81
81
|
break;
|
|
82
82
|
default:
|
|
83
83
|
throw new Error("Cant determine Pendle Swap Type Api Route");
|
|
84
84
|
}
|
|
85
85
|
return r;
|
|
86
|
-
}, J = (e, r,
|
|
87
|
-
if (!
|
|
86
|
+
}, J = (e, r, t, s) => {
|
|
87
|
+
if (!k(p, e))
|
|
88
88
|
throw new Error("getTokenIndexForPendleFlatFee: Invalid Pendle Action");
|
|
89
89
|
if (s)
|
|
90
|
-
return
|
|
90
|
+
return t.findIndex(
|
|
91
91
|
(a) => a.toLowerCase() === s?.toLowerCase()
|
|
92
92
|
);
|
|
93
|
-
const
|
|
93
|
+
const c = r.findIndex((a) => a > 0n), m = r.length - 1;
|
|
94
94
|
if (r[m] <= 0n)
|
|
95
95
|
throw new Error("getTokenIndexForPendleFlatFee: Last token in amountChange is not > 0");
|
|
96
|
-
let
|
|
97
|
-
return (e === p.Mint || e === p.Redeem || e === p.PoolRemove) && (
|
|
96
|
+
let l = c;
|
|
97
|
+
return (e === p.Mint || e === p.Redeem || e === p.PoolRemove) && (l = c), l;
|
|
98
98
|
};
|
|
99
99
|
export {
|
|
100
100
|
z as determinePendleSwapType,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("../../constants/chains.constants.cjs"),j=require("../../constants/protocol.constants.cjs"),G=require("../../data-structures/utxo/Utxo.cjs"),m=require("../../types/hinkal.stake.types.cjs"),k=require("../../webworker/performTaskWithWorker.cjs"),S=require("../../webworker/worker.registry.cjs"),p=require("../../webworker/zkProofWorker/zkProofWorker.types.cjs"),J=require("../web3/etherFunctions.cjs"),i=require("./common.snarkjs.cjs"),F=require("./generateCircomData.cjs"),Q=require("./generateZkProof.cjs"),X=async(u,f,a,r,h,g,y,T,C,P=j.zeroAddress,z=V.chainIds.localhost,s=a.map(()=>!1),_=a.map(()=>0n),I=void 0,n)=>{const W=u.getRootHash(),H=f.getRootHash(),b=a.map(e=>e.map(t=>t.getConstructableParams())),D=h.getSignature(),{accessTokenSiblings:Z,accessTokenSiblingSides:K}=await k.performTaskWithWorker({type:S.WorkerVariant.ZKProof,payload:{type:p.ZKProofWorkerActionType.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES,data:{userSignature:D,merkleTreeAccessTokenSerialized:f.toJSON()}}}),{inCommitmentSiblings:O,inCommitmentSiblingSides:R}=await k.performTaskWithWorker({type:S.WorkerVariant.ZKProof,payload:{type:p.ZKProofWorkerActionType.CALC_COMMITMENTS_SIBLING_AND_SIDES,data:{inputUtxosSerialized:b,userSignature:D,merkleTreeSerialized:u.toJSON()}}}),B=i.calcAmountChanges(a,r),d=i.calcEncryptedOutputs(r,(n&&n.mode!==m.HinkalStakeMode.Deposit)??!1),l=h.getShieldedPrivateKey(),N=G.Utxo.findCorrectRandomization(J.randomBigInt(31),l),E=await k.performTaskWithWorker({type:S.WorkerVariant.ZKProof,payload:{type:p.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:b,onChainCreation:s}}}),o={rootHashHinkal:W,shieldedPrivateKey:l,erc20TokenAddresses:a.map(e=>e[0].erc20TokenAddress),inAmounts:a.map(e=>e.map(t=>t.amount.toString())),inTimeStamps:a.map(e=>e.map(t=>t.timeStamp)),inRandomizations:a.map(e=>e.map(t=>t.randomization)),inNullifiers:E,inCommitmentSiblings:O,inCommitmentSiblingSides:R,outAmounts:r.map(e=>e.map(t=>t.amount.toString())),outTimeStamp:BigInt(r[0][0].timeStamp),outPublicKeys:r.map(e=>e.map(t=>t.getStealthAddress())),extraRandomization:N,amountChanges:B,outCommitments:i.buildOutCommitments(r,s),rootHashAccessToken:H,accessTokenSiblings:Z,accessTokenSiblingSides:K,calldataHash:0n};n||(o.onChainCreation=s);const c=a.map(e=>e[0].tokenId??0),q=c.reduce((e,t)=>e+t,0)>0?c.length:0;q>0&&(o.tokenIds=c);const A=i.calcPublicSignalCount(g,o.erc20TokenAddresses,o.amountChanges,o.inNullifiers,o.outCommitments,q);o.calldataHash=i.createCallDataHash(A,P,T,y,C,d,_,I),n&&(n.mode===m.HinkalStakeMode.Deposit&&(o.mode=0),n.mode===m.HinkalStakeMode.Stake&&(o.mode=1),n.mode===m.HinkalStakeMode.Unstake&&(o.mode=2),o.stakedTokenRecipient=n.stakedTokenRecipient,o.stakeBlinding=n.stakeBlinding,o.depositorAddress=n.depositorAddress);const{zkCallData:L}=await Q.generateZkProof(z,g,o),M=i.calcStealthAddressStructure(N,l),w=await F.generateCircomData(W,H,a,r,d,_,A,y,T,C,P,o.calldataHash,c,M,s,I),v={tokenNumber:a.length,nullifierAmount:a[0].length,outputAmount:r[0].length};return{zkCallData:L,circomData:w,dimData:v,encryptedOutputs:d}};exports.constructZkProof=X;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { chainIds as
|
|
2
|
-
import { zeroAddress as
|
|
3
|
-
import { Utxo as
|
|
4
|
-
import { HinkalStakeMode as
|
|
1
|
+
import { chainIds as G } from "../../constants/chains.constants.mjs";
|
|
2
|
+
import { zeroAddress as J } from "../../constants/protocol.constants.mjs";
|
|
3
|
+
import { Utxo as V } from "../../data-structures/utxo/Utxo.mjs";
|
|
4
|
+
import { HinkalStakeMode as d } from "../../types/hinkal.stake.types.mjs";
|
|
5
5
|
import { performTaskWithWorker as l } from "../../webworker/performTaskWithWorker.mjs";
|
|
6
6
|
import { WorkerVariant as p } from "../../webworker/worker.registry.mjs";
|
|
7
7
|
import { ZKProofWorkerActionType as S } from "../../webworker/zkProofWorker/zkProofWorker.types.mjs";
|
|
8
|
-
import { randomBigInt as
|
|
9
|
-
import { calcAmountChanges as
|
|
10
|
-
import { generateCircomData as
|
|
11
|
-
import { generateZkProof as
|
|
12
|
-
const
|
|
13
|
-
const
|
|
8
|
+
import { randomBigInt as j } from "../web3/etherFunctions.mjs";
|
|
9
|
+
import { calcAmountChanges as q, calcEncryptedOutputs as F, buildOutCommitments as Q, calcPublicSignalCount as X, createCallDataHash as Y, calcStealthAddressStructure as $ } from "./common.snarkjs.mjs";
|
|
10
|
+
import { generateCircomData as U } from "./generateCircomData.mjs";
|
|
11
|
+
import { generateZkProof as x } from "./generateZkProof.mjs";
|
|
12
|
+
const po = async (f, g, a, n, h, k, u, C, I, T = J, R = G.localhost, m = a.map(() => !1), y = a.map(() => 0n), N = void 0, i) => {
|
|
13
|
+
const P = f.getRootHash(), D = g.getRootHash(), _ = a.map((o) => o.map((t) => t.getConstructableParams())), b = h.getSignature(), { accessTokenSiblings: B, accessTokenSiblingSides: E } = await l({
|
|
14
14
|
type: p.ZKProof,
|
|
15
15
|
payload: {
|
|
16
16
|
type: S.CALC_ACCESS_TOKEN_SIBLING_AND_SIDES,
|
|
17
17
|
data: {
|
|
18
|
-
userSignature:
|
|
18
|
+
userSignature: b,
|
|
19
19
|
merkleTreeAccessTokenSerialized: g.toJSON()
|
|
20
20
|
}
|
|
21
21
|
}
|
|
@@ -23,19 +23,19 @@ const So = async (f, g, a, n, h, u, k, C, I, T = V, R = J.localhost, m = a.map((
|
|
|
23
23
|
type: p.ZKProof,
|
|
24
24
|
payload: {
|
|
25
25
|
type: S.CALC_COMMITMENTS_SIBLING_AND_SIDES,
|
|
26
|
-
data: { inputUtxosSerialized:
|
|
26
|
+
data: { inputUtxosSerialized: _, userSignature: b, merkleTreeSerialized: f.toJSON() }
|
|
27
27
|
}
|
|
28
|
-
}), O =
|
|
28
|
+
}), O = q(a, n), c = F(
|
|
29
29
|
n,
|
|
30
|
-
(i && i.mode !==
|
|
31
|
-
), s = h.getShieldedPrivateKey(), H =
|
|
30
|
+
(i && i.mode !== d.Deposit) ?? !1
|
|
31
|
+
), s = h.getShieldedPrivateKey(), H = V.findCorrectRandomization(j(31), s), Z = await l({
|
|
32
32
|
type: p.ZKProof,
|
|
33
33
|
payload: {
|
|
34
34
|
type: S.BUILD_IN_NULLIFIERS,
|
|
35
|
-
data: { inputUtxosSerialized:
|
|
35
|
+
data: { inputUtxosSerialized: _, onChainCreation: m }
|
|
36
36
|
}
|
|
37
37
|
}), e = {
|
|
38
|
-
rootHashHinkal:
|
|
38
|
+
rootHashHinkal: P,
|
|
39
39
|
shieldedPrivateKey: s,
|
|
40
40
|
erc20TokenAddresses: a.map((o) => o[0].erc20TokenAddress),
|
|
41
41
|
inAmounts: a.map((o) => o.map((t) => t.amount.toString())),
|
|
@@ -49,8 +49,8 @@ const So = async (f, g, a, n, h, u, k, C, I, T = V, R = J.localhost, m = a.map((
|
|
|
49
49
|
outPublicKeys: n.map((o) => o.map((t) => t.getStealthAddress())),
|
|
50
50
|
extraRandomization: H,
|
|
51
51
|
amountChanges: O,
|
|
52
|
-
outCommitments:
|
|
53
|
-
rootHashAccessToken:
|
|
52
|
+
outCommitments: Q(n, m),
|
|
53
|
+
rootHashAccessToken: D,
|
|
54
54
|
accessTokenSiblings: B,
|
|
55
55
|
accessTokenSiblingSides: E,
|
|
56
56
|
calldataHash: 0n
|
|
@@ -58,50 +58,48 @@ const So = async (f, g, a, n, h, u, k, C, I, T = V, R = J.localhost, m = a.map((
|
|
|
58
58
|
i || (e.onChainCreation = m);
|
|
59
59
|
const r = a.map((o) => o[0].tokenId ?? 0), z = r.reduce((o, t) => o + t, 0) > 0 ? r.length : 0;
|
|
60
60
|
z > 0 && (e.tokenIds = r);
|
|
61
|
-
const A =
|
|
62
|
-
|
|
61
|
+
const A = X(
|
|
62
|
+
k,
|
|
63
63
|
e.erc20TokenAddresses,
|
|
64
64
|
e.amountChanges,
|
|
65
65
|
e.inNullifiers,
|
|
66
66
|
e.outCommitments,
|
|
67
67
|
z
|
|
68
68
|
);
|
|
69
|
-
e.calldataHash =
|
|
69
|
+
e.calldataHash = Y(
|
|
70
70
|
A,
|
|
71
71
|
T,
|
|
72
72
|
C,
|
|
73
|
-
|
|
73
|
+
u,
|
|
74
74
|
I,
|
|
75
|
-
|
|
75
|
+
c,
|
|
76
76
|
y,
|
|
77
|
-
|
|
78
|
-
), i && (i.mode ===
|
|
79
|
-
const { zkCallData: w
|
|
80
|
-
console.log("publicSignals", W);
|
|
81
|
-
const v = U(H, s), M = await x(
|
|
82
|
-
N,
|
|
77
|
+
N
|
|
78
|
+
), i && (i.mode === d.Deposit && (e.mode = 0), i.mode === d.Stake && (e.mode = 1), i.mode === d.Unstake && (e.mode = 2), e.stakedTokenRecipient = i.stakedTokenRecipient, e.stakeBlinding = i.stakeBlinding, e.depositorAddress = i.depositorAddress);
|
|
79
|
+
const { zkCallData: w } = await x(R, k, e), W = $(H, s), v = await U(
|
|
83
80
|
P,
|
|
81
|
+
D,
|
|
84
82
|
a,
|
|
85
83
|
n,
|
|
86
|
-
|
|
84
|
+
c,
|
|
87
85
|
y,
|
|
88
86
|
A,
|
|
89
|
-
|
|
87
|
+
u,
|
|
90
88
|
C,
|
|
91
89
|
I,
|
|
92
90
|
T,
|
|
93
91
|
e.calldataHash,
|
|
94
92
|
r,
|
|
95
|
-
|
|
93
|
+
W,
|
|
96
94
|
m,
|
|
97
|
-
|
|
98
|
-
),
|
|
95
|
+
N
|
|
96
|
+
), M = {
|
|
99
97
|
tokenNumber: a.length,
|
|
100
98
|
nullifierAmount: a[0].length,
|
|
101
99
|
outputAmount: n[0].length
|
|
102
100
|
};
|
|
103
|
-
return { zkCallData: w, circomData:
|
|
101
|
+
return { zkCallData: w, circomData: v, dimData: M, encryptedOutputs: c };
|
|
104
102
|
};
|
|
105
103
|
export {
|
|
106
|
-
|
|
104
|
+
po as constructZkProof
|
|
107
105
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./getDataFromTransaction.cjs"),C=require("idb-keyval"),u={encryptedOutputs:[],lastOutput:""},l=(e,t)=>{const s=e.substring(0,25),r=t.substring(0,25);return{shortPublicKey:s,shortHinkalAddress:r}},d=new Map,x=(e,t,s)=>{if(!e||!t||!s)throw Error("GetHinkalCache: incorrect arguments");const{shortPublicKey:r,shortHinkalAddress:a}=l(t,s);return JSON.parse(typeof localStorage<"u"?localStorage.getItem(`hinkalCache-${e}-${r}-${a}`)??JSON.stringify(u):d.get(`hinkalCache-${e}-${r}-${a}`)??JSON.stringify(u))},S=(e,t,s,r)=>{if(!t||!s||!r)throw Error("SetHinkalCache: incorrect arguments");const{shortPublicKey:a,shortHinkalAddress:o}=l(s,r);typeof localStorage<"u"?localStorage.setItem(`hinkalCache-${t}-${a}-${o}`,JSON.stringify(e)):d.set(`hinkalCache-${t}-${a}-${o}`,JSON.stringify(e))},H=(e,t,s)=>{S(u,e,t,s)},f=(e,t,s)=>`txsCache-${e}-${t}-${s}`,T=async(e,t,s,r,a)=>{if(!t||!s||!r)throw Error("saveTxsCache: incorrect arguments");const{shortPublicKey:o,shortHinkalAddress:n}=l(s,r),h=y.serializeDecodedTxs(e),c=f(t,o,n),g=JSON.stringify({serializedTxs:h,lastHash:a});try{await C.set(c,g)}catch{localStorage.setItem(c,g)}},m={serializedTxs:[],lastHash:""},$=async(e,t,s)=>{if(!e||!t||!s)throw Error("loadTxsCache: incorrect arguments");const{shortPublicKey:r,shortHinkalAddress:a}=l(t,s),o=f(e,r,a);let n;try{const i=await C.get(o);if(!i)throw new Error("Empty indexedDB cache");n=i}catch{n=localStorage.getItem(o)}const{serializedTxs:h,lastHash:c}=JSON.parse(n??JSON.stringify(m));return{decodedTxs:h.map(i=>y.deserializeDecodedTxs(i)),lastHash:c===""?void 0:c}};exports.getHinkalCache=x;exports.loadTxsCache=$;exports.resetCache=H;exports.saveTxsCache=T;exports.setHinkalCache=S;
|
|
@@ -1,57 +1,54 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { set as p, get as x } from "idb-keyval";
|
|
1
|
+
import { serializeDecodedTxs as C, deserializeDecodedTxs as S } from "./getDataFromTransaction.mjs";
|
|
2
|
+
import { set as d, get as m } from "idb-keyval";
|
|
4
3
|
const y = {
|
|
5
4
|
encryptedOutputs: [],
|
|
6
5
|
lastOutput: ""
|
|
7
|
-
},
|
|
6
|
+
}, l = (e, t) => {
|
|
8
7
|
const r = e.substring(0, 25), s = t.substring(0, 25);
|
|
9
8
|
return { shortPublicKey: r, shortHinkalAddress: s };
|
|
10
|
-
}, u = /* @__PURE__ */ new Map(),
|
|
9
|
+
}, u = /* @__PURE__ */ new Map(), k = (e, t, r) => {
|
|
11
10
|
if (!e || !t || !r)
|
|
12
11
|
throw Error("GetHinkalCache: incorrect arguments");
|
|
13
|
-
const { shortPublicKey: s, shortHinkalAddress: o } =
|
|
12
|
+
const { shortPublicKey: s, shortHinkalAddress: o } = l(t, r);
|
|
14
13
|
return JSON.parse(
|
|
15
14
|
typeof localStorage < "u" ? localStorage.getItem(`hinkalCache-${e}-${s}-${o}`) ?? JSON.stringify(y) : u.get(`hinkalCache-${e}-${s}-${o}`) ?? JSON.stringify(y)
|
|
16
15
|
);
|
|
17
|
-
},
|
|
16
|
+
}, p = (e, t, r, s) => {
|
|
18
17
|
if (!t || !r || !s)
|
|
19
18
|
throw Error("SetHinkalCache: incorrect arguments");
|
|
20
|
-
const { shortPublicKey: o, shortHinkalAddress: a } =
|
|
19
|
+
const { shortPublicKey: o, shortHinkalAddress: a } = l(r, s);
|
|
21
20
|
typeof localStorage < "u" ? localStorage.setItem(`hinkalCache-${t}-${o}-${a}`, JSON.stringify(e)) : u.set(`hinkalCache-${t}-${o}-${a}`, JSON.stringify(e));
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
},
|
|
21
|
+
}, T = (e, t, r) => {
|
|
22
|
+
p(y, e, t, r);
|
|
23
|
+
}, f = (e, t, r) => `txsCache-${e}-${t}-${r}`, O = async (e, t, r, s, o) => {
|
|
25
24
|
if (!t || !r || !s)
|
|
26
25
|
throw Error("saveTxsCache: incorrect arguments");
|
|
27
|
-
const { shortPublicKey: a, shortHinkalAddress:
|
|
28
|
-
f("saveTxsCache before saving", { serializedTxs: l });
|
|
29
|
-
const n = C(t, a, c), i = JSON.stringify({ serializedTxs: l, lastHash: o });
|
|
26
|
+
const { shortPublicKey: a, shortHinkalAddress: n } = l(r, s), g = C(e), c = f(t, a, n), h = JSON.stringify({ serializedTxs: g, lastHash: o });
|
|
30
27
|
try {
|
|
31
|
-
await
|
|
28
|
+
await d(c, h);
|
|
32
29
|
} catch {
|
|
33
|
-
localStorage.setItem(
|
|
30
|
+
localStorage.setItem(c, h);
|
|
34
31
|
}
|
|
35
|
-
},
|
|
32
|
+
}, x = { serializedTxs: [], lastHash: "" }, w = async (e, t, r) => {
|
|
36
33
|
if (!e || !t || !r)
|
|
37
34
|
throw Error("loadTxsCache: incorrect arguments");
|
|
38
|
-
const { shortPublicKey: s, shortHinkalAddress: o } =
|
|
39
|
-
let
|
|
35
|
+
const { shortPublicKey: s, shortHinkalAddress: o } = l(t, r), a = f(e, s, o);
|
|
36
|
+
let n;
|
|
40
37
|
try {
|
|
41
|
-
const
|
|
42
|
-
if (!
|
|
38
|
+
const i = await m(a);
|
|
39
|
+
if (!i)
|
|
43
40
|
throw new Error("Empty indexedDB cache");
|
|
44
|
-
|
|
41
|
+
n = i;
|
|
45
42
|
} catch {
|
|
46
|
-
|
|
43
|
+
n = localStorage.getItem(a);
|
|
47
44
|
}
|
|
48
|
-
const { serializedTxs:
|
|
49
|
-
return
|
|
45
|
+
const { serializedTxs: g, lastHash: c } = JSON.parse(n ?? JSON.stringify(x));
|
|
46
|
+
return { decodedTxs: g.map((i) => S(i)), lastHash: c === "" ? void 0 : c };
|
|
50
47
|
};
|
|
51
48
|
export {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
k as getHinkalCache,
|
|
50
|
+
w as loadTxsCache,
|
|
51
|
+
T as resetCache,
|
|
52
|
+
O as saveTxsCache,
|
|
53
|
+
p as setHinkalCache
|
|
57
54
|
};
|
|
@@ -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;
|