@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
|
@@ -1,120 +1,117 @@
|
|
|
1
|
-
import { utils as
|
|
1
|
+
import { utils as H } from "ethers";
|
|
2
2
|
import { zeroAddress as R } from "../../constants/protocol.constants.mjs";
|
|
3
|
-
import { networkRegistry as
|
|
4
|
-
import { getERC20Token as
|
|
5
|
-
import { getFlatFees as
|
|
6
|
-
import { processAmountChanges as
|
|
7
|
-
import { constructZkProof as
|
|
8
|
-
import { outputUtxoProcessing as
|
|
9
|
-
import { addPaddingToUtxos as
|
|
10
|
-
import { estimateGasRelayer as
|
|
11
|
-
import { transactCallRelayer as
|
|
12
|
-
import { transactCallDirect as
|
|
3
|
+
import { networkRegistry as O } from "../../constants/chains.constants.mjs";
|
|
4
|
+
import { getERC20Token as g } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
5
|
+
import { getFlatFees as U } from "../../functions/pre-transaction/getFlatFees.mjs";
|
|
6
|
+
import { processAmountChanges as b } from "../../functions/pre-transaction/processAmountChanges.mjs";
|
|
7
|
+
import { constructZkProof as k } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
8
|
+
import { outputUtxoProcessing as L } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
9
|
+
import { addPaddingToUtxos as N } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
10
|
+
import { estimateGasRelayer as $ } from "../../functions/web3/functionCalls/estimateGasRelayer.mjs";
|
|
11
|
+
import { transactCallRelayer as v } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
12
|
+
import { transactCallDirect as A } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
|
|
13
13
|
import { ContractType as E } from "../../types/ethereum-network.types.mjs";
|
|
14
|
-
import { defaultHookData as
|
|
14
|
+
import { defaultHookData as z } from "../../types/circom-data.types.mjs";
|
|
15
15
|
import { ExternalActionId as G } from "../../types/external-action.types.mjs";
|
|
16
|
-
import { PendleAction as
|
|
16
|
+
import { PendleAction as r } from "../../types/hinkal.types.mjs";
|
|
17
17
|
import { transactionErrorCodes as K } from "../../error-handling/error-codes.constants.mjs";
|
|
18
18
|
const _ = (t) => {
|
|
19
|
-
let
|
|
20
|
-
return t ===
|
|
21
|
-
}, B = (t,
|
|
22
|
-
const { pendleAction:
|
|
19
|
+
let e = [];
|
|
20
|
+
return t === r.Deposit ? e = [!1, !0] : t === r.Withdraw ? e = [!1, !0] : t === r.SwapFromYt ? e = [!1, !0, !0] : t === r.SwapToYt ? e = [!1, !1, !0] : t === r.SwapPt ? e = [!1, !0] : t === r.Mint ? e = [!1, !0, !1, !0] : t === r.Redeem ? e = [!1, !1, !0, !0] : t === r.Checkpoint && (e = [!1, !0]), e;
|
|
21
|
+
}, B = (t, e) => {
|
|
22
|
+
const { pendleAction: s, ytAddress: a, userAddress: c, evmData: d } = t, i = d ?? "0x00", n = c ?? R;
|
|
23
23
|
if ([
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
r.Deposit,
|
|
25
|
+
r.Withdraw,
|
|
26
|
+
r.SwapFromYt,
|
|
27
|
+
r.SwapToYt,
|
|
28
|
+
r.SwapPt,
|
|
29
|
+
r.Mint,
|
|
30
|
+
r.Redeem,
|
|
31
|
+
r.Checkpoint
|
|
32
32
|
].includes(t.pendleAction))
|
|
33
|
-
return
|
|
33
|
+
return H.defaultAbiCoder.encode(
|
|
34
34
|
["uint8", "address", "uint256", "uint256", "address", "bool", "bytes"],
|
|
35
35
|
[
|
|
36
|
-
n,
|
|
37
36
|
s,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
a,
|
|
38
|
+
e[0][0].amount,
|
|
39
|
+
e[0][0].timeStamp,
|
|
40
|
+
n,
|
|
41
41
|
!0,
|
|
42
|
-
|
|
42
|
+
i
|
|
43
43
|
]
|
|
44
44
|
);
|
|
45
45
|
throw new Error("Not implemented");
|
|
46
|
-
},
|
|
47
|
-
const
|
|
48
|
-
console.log({ inputUtxosArray: c, circuitName: C, pendleMetadata: s });
|
|
49
|
-
const { flatFees: w, feeUnit: T } = await O(
|
|
46
|
+
}, ut = async (t, e, s, a, c, d = !1) => {
|
|
47
|
+
const i = G.Pendle, { pendleAction: n } = a, f = [...await N(t, e, s)], T = `swapperMO${s.length.toString()}x${f[0].length}x1`, { flatFees: w, feeUnit: D } = await U(
|
|
50
48
|
t.getCurrentChainId(),
|
|
51
|
-
|
|
52
|
-
a,
|
|
53
|
-
n,
|
|
49
|
+
e,
|
|
54
50
|
i,
|
|
55
|
-
|
|
51
|
+
s,
|
|
52
|
+
n,
|
|
53
|
+
c
|
|
56
54
|
);
|
|
57
|
-
|
|
58
|
-
erc20Addresses:
|
|
59
|
-
amountChanges:
|
|
55
|
+
s = b({
|
|
56
|
+
erc20Addresses: e,
|
|
57
|
+
amountChanges: s,
|
|
60
58
|
flatFees: w,
|
|
61
|
-
feeUnit:
|
|
62
|
-
externalActionId:
|
|
63
|
-
action:
|
|
64
|
-
gasTokenAddress:
|
|
59
|
+
feeUnit: D,
|
|
60
|
+
externalActionId: i,
|
|
61
|
+
action: n,
|
|
62
|
+
gasTokenAddress: c
|
|
65
63
|
});
|
|
66
|
-
const
|
|
67
|
-
for (let
|
|
68
|
-
const { outputUtxos: p } =
|
|
69
|
-
|
|
64
|
+
const x = [];
|
|
65
|
+
for (let o = 0; o < e.length; o += 1) {
|
|
66
|
+
const { outputUtxos: p } = L(t.userKeys, f[o], s[o]);
|
|
67
|
+
x.push(p);
|
|
70
68
|
}
|
|
71
|
-
const
|
|
72
|
-
if (!
|
|
69
|
+
const S = _(n), { contractData: I } = O[t.getCurrentChainId()], P = I?.pendleExternalActionInstanceAddress, Y = B(a, f), y = n === r.Deposit || a.isRelayerOff ? R : await t.getRandomRelay();
|
|
70
|
+
if (!y)
|
|
73
71
|
throw Error(K.RELAYER_NOT_AVAILABLE);
|
|
74
|
-
const
|
|
72
|
+
const W = `0x0${n.toString(16)}`, h = { ...z, preHookMetadata: W }, { zkCallData: m, circomData: u, dimData: l } = await k(
|
|
75
73
|
t.merkleTreeHinkal,
|
|
76
74
|
t.merkleTreeAccessToken,
|
|
77
|
-
|
|
78
|
-
g,
|
|
79
|
-
t.userKeys,
|
|
80
|
-
C,
|
|
81
|
-
a,
|
|
82
|
-
I,
|
|
83
|
-
h,
|
|
75
|
+
f,
|
|
84
76
|
x,
|
|
85
|
-
t.
|
|
77
|
+
t.userKeys,
|
|
78
|
+
T,
|
|
79
|
+
i,
|
|
86
80
|
P,
|
|
81
|
+
Y,
|
|
82
|
+
y,
|
|
83
|
+
t.getCurrentChainId(),
|
|
84
|
+
S,
|
|
87
85
|
w,
|
|
88
|
-
|
|
86
|
+
h
|
|
89
87
|
);
|
|
90
|
-
if (
|
|
91
|
-
return await
|
|
92
|
-
const
|
|
93
|
-
if (
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
if (!r)
|
|
88
|
+
if (d)
|
|
89
|
+
return await $(t, m, l, u);
|
|
90
|
+
const C = t.getCurrentChainId();
|
|
91
|
+
if (n === r.Deposit) {
|
|
92
|
+
const o = g(a.ytAddress, C);
|
|
93
|
+
if (!o)
|
|
97
94
|
throw Error("Yt Token not found");
|
|
98
95
|
const p = t.getContractWithSigner(E.PendleGeneralExternalAction), F = t.getContractWithSigner(E.HinkalWrapper);
|
|
99
|
-
return await
|
|
96
|
+
return await A(
|
|
100
97
|
t,
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
f,
|
|
104
|
-
l,
|
|
98
|
+
s[0],
|
|
99
|
+
o,
|
|
105
100
|
m,
|
|
101
|
+
u,
|
|
102
|
+
l,
|
|
106
103
|
p,
|
|
107
104
|
F
|
|
108
105
|
);
|
|
109
106
|
}
|
|
110
|
-
if (
|
|
111
|
-
const
|
|
112
|
-
if (!
|
|
107
|
+
if (n === r.Withdraw && a.isRelayerOff) {
|
|
108
|
+
const o = g(a.ytAddress, C);
|
|
109
|
+
if (!o)
|
|
113
110
|
throw Error("Yt Token not found");
|
|
114
|
-
return await
|
|
111
|
+
return await A(t, s[0], o, m, u, l);
|
|
115
112
|
}
|
|
116
|
-
return await
|
|
113
|
+
return await v(t.getCurrentChainId(), m, l, u);
|
|
117
114
|
};
|
|
118
115
|
export {
|
|
119
|
-
|
|
116
|
+
ut as hinkalActionPendle
|
|
120
117
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("ethers"),U=require("../../types/circom-data.types.cjs"),D=require("../../types/external-action.types.cjs"),y=require("../../types/hinkal.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const A=require("../../functions/web3/events/getShieldedBalance.cjs"),I=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),_=require("../../functions/pre-transaction/getFlatFees.cjs"),b=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),k=require("../../functions/pre-transaction/processAmountChanges.cjs"),S=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),T=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),F=require("../../constants/chains.constants.cjs"),G=require("../../error-handling/error-codes.constants.cjs"),O=(t,e)=>{if(t===y.PendleLPAction.AddOrRemoveLiquidity)return e.length===3?[!1,!0,!1]:[!1,!0,!1,!1];if(t===y.PendleLPAction.Checkpoint)return[!1,!0];throw new Error("Unknown PendleLPAction not implemented")},v=(t,e)=>{const{pendleLPAction:n,lpAddress:r,evmData:o}=t;return E.ethers.utils.defaultAbiCoder.encode(["uint8","address","uint256","uint256","bytes"],[n,r,e[0][0].amount,e[0][0].timeStamp,o])},M=async(t,e,n,r,o,g=!1)=>{const i=D.ExternalActionId.PendleLP,{pendleLPAction:c}=r,s=[...await A.addPaddingToUtxos(t,e,n)],f=`swapperMO${n.length.toString()}x${s[0].length}x1`,{flatFees:l,feeUnit:C}=await _.getFlatFees(t.getCurrentChainId(),e,i,n,c,o);n=k.processAmountChanges({erc20Addresses:e,amountChanges:n,flatFees:l,feeUnit:C,externalActionId:i,action:c,gasTokenAddress:o});const u=[];for(let a=0;a<e.length;a+=1){const{outputUtxos:h}=b.outputUtxoProcessing(t.userKeys,s[a],n[a]);u.push(h)}const q=O(c,e),{contractData:x}=F.networkRegistry[t.getCurrentChainId()],w=x?.pendleLPExternalActionInstanceAddress,L=v(r,s),d=await t.getRandomRelay();if(!d)throw Error(G.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const R={...U.defaultHookData},{zkCallData:m,circomData:P,dimData:p}=await I.constructZkProof(t.merkleTreeHinkal,t.merkleTreeAccessToken,s,u,t.userKeys,f,i,w,L,d,t.getCurrentChainId(),q,l,R);return g?await S.estimateGasRelayer(t,m,p,P):await T.transactCallRelayer(t.getCurrentChainId(),m,p,P)},B=async(t,e,n)=>{const r=[...await A.addPaddingToUtxos(t,[e],[-1n*n])];return{amount:r[0][0].amount,timestamp:r[0][0].timeStamp}};exports.hinkalActionPendleLP=M;exports.hinkalGetPendleLPClaimableParams=B;
|
|
@@ -1,75 +1,75 @@
|
|
|
1
|
-
import { ethers as
|
|
1
|
+
import { ethers as D } from "ethers";
|
|
2
2
|
import { defaultHookData as U } from "../../types/circom-data.types.mjs";
|
|
3
3
|
import { ExternalActionId as h } from "../../types/external-action.types.mjs";
|
|
4
4
|
import { PendleLPAction as A } from "../../types/hinkal.types.mjs";
|
|
5
5
|
import "../../types/transactions.types.mjs";
|
|
6
6
|
import "../../types/curve.types.mjs";
|
|
7
|
-
import { addPaddingToUtxos as
|
|
8
|
-
import { constructZkProof as
|
|
9
|
-
import { getFlatFees as
|
|
10
|
-
import { outputUtxoProcessing as
|
|
11
|
-
import { processAmountChanges as
|
|
12
|
-
import { estimateGasRelayer as
|
|
13
|
-
import { transactCallRelayer as
|
|
7
|
+
import { addPaddingToUtxos as y } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
8
|
+
import { constructZkProof as O } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
9
|
+
import { getFlatFees as T } from "../../functions/pre-transaction/getFlatFees.mjs";
|
|
10
|
+
import { outputUtxoProcessing as b } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
11
|
+
import { processAmountChanges as F } from "../../functions/pre-transaction/processAmountChanges.mjs";
|
|
12
|
+
import { estimateGasRelayer as S } from "../../functions/web3/functionCalls/estimateGasRelayer.mjs";
|
|
13
|
+
import { transactCallRelayer as k } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
14
14
|
import { networkRegistry as v } from "../../constants/chains.constants.mjs";
|
|
15
|
-
import { transactionErrorCodes as
|
|
16
|
-
const
|
|
15
|
+
import { transactionErrorCodes as G } from "../../error-handling/error-codes.constants.mjs";
|
|
16
|
+
const H = (t, e) => {
|
|
17
17
|
if (t === A.AddOrRemoveLiquidity)
|
|
18
18
|
return e.length === 3 ? [!1, !0, !1] : [!1, !0, !1, !1];
|
|
19
19
|
if (t === A.Checkpoint)
|
|
20
20
|
return [!1, !0];
|
|
21
21
|
throw new Error("Unknown PendleLPAction not implemented");
|
|
22
|
-
},
|
|
22
|
+
}, K = (t, e) => {
|
|
23
23
|
const { pendleLPAction: o, lpAddress: r, evmData: a } = t;
|
|
24
|
-
return
|
|
24
|
+
return D.utils.defaultAbiCoder.encode(
|
|
25
25
|
["uint8", "address", "uint256", "uint256", "bytes"],
|
|
26
26
|
[o, r, e[0][0].amount, e[0][0].timeStamp, a]
|
|
27
27
|
);
|
|
28
|
-
}, et = async (t, e, o, r, a,
|
|
29
|
-
const s = h.PendleLP, { pendleLPAction:
|
|
28
|
+
}, et = async (t, e, o, r, a, P = !1) => {
|
|
29
|
+
const s = h.PendleLP, { pendleLPAction: m } = r, i = [...await y(t, e, o)], x = `swapperMO${o.length.toString()}x${i[0].length}x1`, { flatFees: c, feeUnit: C } = await T(
|
|
30
30
|
t.getCurrentChainId(),
|
|
31
31
|
e,
|
|
32
32
|
s,
|
|
33
33
|
o,
|
|
34
|
-
|
|
34
|
+
m,
|
|
35
35
|
a
|
|
36
36
|
);
|
|
37
|
-
|
|
37
|
+
o = F({
|
|
38
38
|
erc20Addresses: e,
|
|
39
39
|
amountChanges: o,
|
|
40
|
-
flatFees:
|
|
40
|
+
flatFees: c,
|
|
41
41
|
feeUnit: C,
|
|
42
42
|
externalActionId: s,
|
|
43
|
-
action:
|
|
43
|
+
action: m,
|
|
44
44
|
gasTokenAddress: a
|
|
45
45
|
});
|
|
46
|
-
const
|
|
46
|
+
const l = [];
|
|
47
47
|
for (let n = 0; n < e.length; n += 1) {
|
|
48
|
-
const { outputUtxos:
|
|
49
|
-
|
|
48
|
+
const { outputUtxos: I } = b(t.userKeys, i[n], o[n]);
|
|
49
|
+
l.push(I);
|
|
50
50
|
}
|
|
51
|
-
const
|
|
52
|
-
if (!
|
|
53
|
-
throw Error(
|
|
54
|
-
const
|
|
51
|
+
const g = H(m, e), { contractData: w } = v[t.getCurrentChainId()], E = w?.pendleLPExternalActionInstanceAddress, L = K(r, i), p = await t.getRandomRelay();
|
|
52
|
+
if (!p)
|
|
53
|
+
throw Error(G.RELAYER_NOT_AVAILABLE);
|
|
54
|
+
const R = { ...U }, { zkCallData: u, circomData: f, dimData: d } = await O(
|
|
55
55
|
t.merkleTreeHinkal,
|
|
56
56
|
t.merkleTreeAccessToken,
|
|
57
57
|
i,
|
|
58
|
-
|
|
58
|
+
l,
|
|
59
59
|
t.userKeys,
|
|
60
|
-
|
|
60
|
+
x,
|
|
61
61
|
s,
|
|
62
62
|
E,
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
L,
|
|
64
|
+
p,
|
|
65
65
|
t.getCurrentChainId(),
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
g,
|
|
67
|
+
c,
|
|
68
|
+
R
|
|
69
69
|
);
|
|
70
|
-
return
|
|
70
|
+
return P ? await S(t, u, d, f) : await k(t.getCurrentChainId(), u, d, f);
|
|
71
71
|
}, ot = async (t, e, o) => {
|
|
72
|
-
const r = [...await
|
|
72
|
+
const r = [...await y(t, [e], [-1n * o])];
|
|
73
73
|
return { amount: r[0][0].amount, timestamp: r[0][0].timeStamp };
|
|
74
74
|
};
|
|
75
75
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/protocol.constants.cjs"),p=require("../../functions/staking/index.cjs"),f=require("../../functions/utils/erc20tokenFunctions.cjs"),B=require("../../functions/web3/etherFunctions.cjs"),O=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),_=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/protocol.constants.cjs"),p=require("../../functions/staking/index.cjs"),f=require("../../functions/utils/erc20tokenFunctions.cjs"),B=require("../../functions/web3/etherFunctions.cjs"),O=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),_=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),b=require("../../functions/web3/events/getShieldedBalance.cjs"),l=require("../utxo/Utxo.cjs");require("../../types/circom-data.types.cjs");const S=require("../../types/ethereum-network.types.cjs"),M=require("../../types/external-action.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const m=require("../../types/hinkal.stake.types.cjs");require("ethers");const j=require("../crypto-keys/keys.cjs");require("../crypto-keys/encryptDecryptUtxo.cjs");const w=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),z=async(t,g,o,s,a)=>{const C=await t.getEthereumAddress(),i=f.getERC20Token(g[0],t.getCurrentChainId());if(!i)throw Error("Deposit Action: No Token Found");const u=s===m.HinkalStakeMode.Stake,n=s===m.HinkalStakeMode.Unstake,{erc20TokenAddress:E}=i,r=[...await b.addPaddingToUtxos(t,g,o,2,void 0,s!==m.HinkalStakeMode.Deposit)];if(u||n){r[0][0]=l.Utxo.createFrom(r[0][0],{amount:o[0]*(u?1n:-1n),isStakeOrUnstakeInput:!0});for(let e=0;e<r.length;e+=1)for(let c=0;c<r[e].length;c+=1)e===0&&c===0||(r[e][c]=l.Utxo.createFrom(r[e][c],{amount:0n}))}const{outputUtxos:H}=O.outputUtxoProcessing(t.userKeys,r[0],o[0]),d=[H.map(e=>l.Utxo.createFrom(e,{isStake:u,isUnstakeOutput:n}))];n&&(d[0][0]=l.Utxo.createFrom(d[0][0],{amount:0n,isUnstakeOutput:n}));const P=[!1],k=B.randomBigInt(30),h=j.UserKeys.getEncryptionKeyPair(t.userKeys.getShieldedPrivateKey()),K=p.encryptStake(k,a,T.ownerPublicKey),D=p.encryptStake(k,a,h.publicKey),F=n?0n:p.createStakeCommitment(!0,a,k,E,o[0],BigInt(d[0][0].timeStamp)),I=u?0:1,v=p.encodeHStakeMetadata(I,F,C,K,D),x=t.getContractWithSigner(S.ContractType.HinkalWrapper2),y=t.getContractWithSigner(S.ContractType.HinkalStakeExternalAction),{zkCallData:q,dimData:A,circomData:U}=await _.constructZkProof(t.merkleTreeHinkal,t.merkleTreeAccessToken,r,d,t.userKeys,"swapperME1x2x1",M.ExternalActionId.HinkalStake,y.address,v,T.zeroAddress,t.getCurrentChainId(),P,void 0,void 0,{stakedTokenRecipient:a,stakeBlinding:k,mode:s,depositorAddress:C});if(n){const e=f.getHToken(i,t.getCurrentChainId());if(!e)throw new Error("hToken not found");const W=(await t.getContractWithFetcher(S.ContractType.HToken,e.erc20TokenAddress).previewWithdraw(-o[0])).toBigInt();return w.transactCallDirect(t,W,e,q,U,A,y,x)}return w.transactCallDirect(t,o[0],i,q,U,A,y,x)};exports.hinkalActionStake=z;
|
|
@@ -1,122 +1,118 @@
|
|
|
1
|
-
import { ownerPublicKey as
|
|
2
|
-
import { encryptStake as T, createStakeCommitment as
|
|
3
|
-
import { getERC20Token as
|
|
4
|
-
import { randomBigInt as
|
|
5
|
-
import { outputUtxoProcessing as
|
|
6
|
-
import { constructZkProof as
|
|
7
|
-
import { addPaddingToUtxos as
|
|
8
|
-
import { Utxo as
|
|
1
|
+
import { ownerPublicKey as v, zeroAddress as h } from "../../constants/protocol.constants.mjs";
|
|
2
|
+
import { encryptStake as T, createStakeCommitment as B, encodeHStakeMetadata as O } from "../../functions/staking/index.mjs";
|
|
3
|
+
import { getERC20Token as b, getHToken as z } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
4
|
+
import { randomBigInt as j } from "../../functions/web3/etherFunctions.mjs";
|
|
5
|
+
import { outputUtxoProcessing as M } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
6
|
+
import { constructZkProof as N } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
7
|
+
import { addPaddingToUtxos as Z } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
8
|
+
import { Utxo as u } from "../utxo/Utxo.mjs";
|
|
9
9
|
import "../../types/circom-data.types.mjs";
|
|
10
10
|
import { ContractType as k } from "../../types/ethereum-network.types.mjs";
|
|
11
|
-
import { ExternalActionId as
|
|
11
|
+
import { ExternalActionId as q } from "../../types/external-action.types.mjs";
|
|
12
12
|
import "../../types/transactions.types.mjs";
|
|
13
13
|
import "../../types/curve.types.mjs";
|
|
14
|
-
import { HinkalStakeMode as
|
|
14
|
+
import { HinkalStakeMode as y } from "../../types/hinkal.stake.types.mjs";
|
|
15
15
|
import "ethers";
|
|
16
|
-
import { UserKeys as
|
|
16
|
+
import { UserKeys as G } from "../crypto-keys/keys.mjs";
|
|
17
17
|
import "../crypto-keys/encryptDecryptUtxo.mjs";
|
|
18
18
|
import { transactCallDirect as w } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
|
|
19
|
-
const
|
|
20
|
-
const A = await t.getEthereumAddress(),
|
|
21
|
-
if (!
|
|
19
|
+
const pt = async (t, g, e, a, s) => {
|
|
20
|
+
const A = await t.getEthereumAddress(), c = b(g[0], t.getCurrentChainId());
|
|
21
|
+
if (!c)
|
|
22
22
|
throw Error("Deposit Action: No Token Found");
|
|
23
|
-
const m = a ===
|
|
24
|
-
|
|
25
|
-
const { erc20TokenAddress: E } = s, r = [
|
|
26
|
-
...await q(
|
|
23
|
+
const m = a === y.Stake, n = a === y.Unstake, { erc20TokenAddress: U } = c, r = [
|
|
24
|
+
...await Z(
|
|
27
25
|
t,
|
|
28
|
-
|
|
26
|
+
g,
|
|
29
27
|
e,
|
|
30
28
|
2,
|
|
31
29
|
void 0,
|
|
32
|
-
a !==
|
|
30
|
+
a !== y.Deposit
|
|
33
31
|
)
|
|
34
32
|
];
|
|
35
33
|
if (m || n) {
|
|
36
|
-
r[0][0] =
|
|
34
|
+
r[0][0] = u.createFrom(r[0][0], {
|
|
37
35
|
amount: e[0] * (m ? 1n : -1n),
|
|
38
36
|
isStakeOrUnstakeInput: !0
|
|
39
37
|
});
|
|
40
38
|
for (let o = 0; o < r.length; o += 1)
|
|
41
39
|
for (let i = 0; i < r[o].length; i += 1)
|
|
42
|
-
o === 0 && i === 0 || (r[o][i] =
|
|
40
|
+
o === 0 && i === 0 || (r[o][i] = u.createFrom(r[o][i], { amount: 0n }));
|
|
43
41
|
}
|
|
44
|
-
const { outputUtxos:
|
|
45
|
-
|
|
46
|
-
(o) =>
|
|
42
|
+
const { outputUtxos: E } = M(t.userKeys, r[0], e[0]), p = [
|
|
43
|
+
E.map(
|
|
44
|
+
(o) => u.createFrom(o, {
|
|
47
45
|
isStake: m,
|
|
48
46
|
isUnstakeOutput: n
|
|
49
47
|
})
|
|
50
48
|
)
|
|
51
49
|
];
|
|
52
|
-
n && (p[0][0] =
|
|
50
|
+
n && (p[0][0] = u.createFrom(p[0][0], {
|
|
53
51
|
amount: 0n,
|
|
54
52
|
isUnstakeOutput: n
|
|
55
53
|
}));
|
|
56
|
-
const
|
|
54
|
+
const K = [!1], d = j(30), H = G.getEncryptionKeyPair(t.userKeys.getShieldedPrivateKey()), I = T(d, s, v), P = T(d, s, H.publicKey), D = n ? 0n : B(
|
|
57
55
|
!0,
|
|
58
|
-
|
|
56
|
+
s,
|
|
59
57
|
d,
|
|
60
|
-
|
|
58
|
+
U,
|
|
61
59
|
e[0],
|
|
62
60
|
BigInt(p[0][0].timeStamp)
|
|
63
|
-
),
|
|
61
|
+
), F = O(
|
|
64
62
|
m ? 0 : 1,
|
|
65
|
-
|
|
63
|
+
D,
|
|
66
64
|
A,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
), C = t.getContractWithSigner(k.HinkalWrapper2),
|
|
70
|
-
console.log("external action address", u.address);
|
|
71
|
-
const { zkCallData: S, dimData: x, circomData: l } = await Z(
|
|
65
|
+
I,
|
|
66
|
+
P
|
|
67
|
+
), C = t.getContractWithSigner(k.HinkalWrapper2), f = t.getContractWithSigner(k.HinkalStakeExternalAction), { zkCallData: S, dimData: l, circomData: x } = await N(
|
|
72
68
|
t.merkleTreeHinkal,
|
|
73
69
|
t.merkleTreeAccessToken,
|
|
74
70
|
r,
|
|
75
71
|
p,
|
|
76
72
|
t.userKeys,
|
|
77
73
|
"swapperME1x2x1",
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
q.HinkalStake,
|
|
75
|
+
f.address,
|
|
76
|
+
F,
|
|
77
|
+
h,
|
|
82
78
|
t.getCurrentChainId(),
|
|
83
|
-
|
|
79
|
+
K,
|
|
84
80
|
void 0,
|
|
85
81
|
void 0,
|
|
86
82
|
{
|
|
87
|
-
stakedTokenRecipient:
|
|
83
|
+
stakedTokenRecipient: s,
|
|
88
84
|
stakeBlinding: d,
|
|
89
85
|
mode: a,
|
|
90
86
|
depositorAddress: A
|
|
91
87
|
}
|
|
92
88
|
);
|
|
93
|
-
if (
|
|
94
|
-
const o = z(
|
|
89
|
+
if (n) {
|
|
90
|
+
const o = z(c, t.getCurrentChainId());
|
|
95
91
|
if (!o)
|
|
96
92
|
throw new Error("hToken not found");
|
|
97
|
-
const
|
|
93
|
+
const W = (await t.getContractWithFetcher(k.HToken, o.erc20TokenAddress).previewWithdraw(-e[0])).toBigInt();
|
|
98
94
|
return w(
|
|
99
95
|
t,
|
|
100
|
-
|
|
96
|
+
W,
|
|
101
97
|
o,
|
|
102
98
|
S,
|
|
103
|
-
l,
|
|
104
99
|
x,
|
|
105
|
-
|
|
100
|
+
l,
|
|
101
|
+
f,
|
|
106
102
|
C
|
|
107
103
|
);
|
|
108
104
|
}
|
|
109
105
|
return w(
|
|
110
106
|
t,
|
|
111
107
|
e[0],
|
|
112
|
-
|
|
108
|
+
c,
|
|
113
109
|
S,
|
|
114
|
-
l,
|
|
115
110
|
x,
|
|
116
|
-
|
|
111
|
+
l,
|
|
112
|
+
f,
|
|
117
113
|
C
|
|
118
114
|
);
|
|
119
115
|
};
|
|
120
116
|
export {
|
|
121
|
-
|
|
117
|
+
pt as hinkalActionStake
|
|
122
118
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("../../constants/protocol.constants.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("../../constants/protocol.constants.cjs"),m=require("../../functions/utils/erc20tokenFunctions.cjs"),P=require("../../functions/pre-transaction/getFlatFees.cjs"),U=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),H=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),N=require("../../functions/web3/events/getShieldedBalance.cjs"),f=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),W=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),b=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),E=require("../volatile-helper/VolatileHelper.cjs"),n=require("../../types/hinkal.types.cjs"),q=require("../../types/ethereum-network.types.cjs"),M=require("../../types/external-action.types.cjs"),z=require("../../error-handling/error-codes.constants.cjs"),G=async(t,a,e,D,R)=>{const{action:r,isRelayerOff:i,recipientAddress:T,baseExternalActionId:I,baseExternalActionMetadata:S}=D,p=m.getERC20Token(a[0],t.getCurrentChainId());if(!p)throw Error("Deposit Action: No Token Found");const A=[...e],F=[...a];let g=[],y=e.map(()=>0n);({erc20Addresses:a,amountChanges:e,onChainCreation:g}=await E.VolatileHelper.processVolatileData(t.getCurrentChainId(),r,a,e));const c=await E.VolatileHelper.getVolatileExternalData(t,r,A,T,I,S);if(!c)throw Error("No External Action Data");(r===n.VolatileAction.Withdraw&&!i||r===n.VolatileAction.Swap)&&({flatFees:y}=await P.getFlatFees(t.getCurrentChainId(),F,M.ExternalActionId.Volatile,A,r),r===n.VolatileAction.Swap&&(e[1]=0n));const d=[...await N.addPaddingToUtxos(t,a,e)],_=`swapperM${e.length.toString()}x${d[0].length}x1`,w=[];for(let o=0;o<a.length;o+=1){const{outputUtxos:x}=U.outputUtxoProcessing(t.userKeys,d[o],e[o]);w.push(x)}const C=r===n.VolatileAction.Deposit||i?V.zeroAddress:await t.getRandomRelay();if(!i&&!C)throw Error(z.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const{zkCallData:s,circomData:l,dimData:u}=await H.constructZkProof(t.merkleTreeHinkal,t.merkleTreeAccessToken,d,w,t.userKeys,_,c.externalActionId,c.externalAddress,c.externalActionMetadata,i?V.zeroAddress:C,t.getCurrentChainId(),g,y);if(r===n.VolatileAction.Deposit){const o=t.getContractWithSigner(q.ContractType.VolatileVault),x=t.getContractWithSigner(q.ContractType.HinkalWrapper);return await f.transactCallDirect(t,A[0],p,s,l,u,o,x)}return r===n.VolatileAction.Withdraw&&i?await f.transactCallDirect(t,e[0],p,s,l,u):R?await b.estimateGasRelayer(t,s,u,l):await W.transactCallRelayer(t.getCurrentChainId(),s,u,l)};exports.hinkalActionVolatile=G;
|