@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
|
@@ -8,62 +8,62 @@ import { outputUtxoProcessing as S } from "../../functions/pre-transaction/outpu
|
|
|
8
8
|
import { processAmountChanges as b } from "../../functions/pre-transaction/processAmountChanges.mjs";
|
|
9
9
|
import { estimateGasRelayer as v } from "../../functions/web3/functionCalls/estimateGasRelayer.mjs";
|
|
10
10
|
import { transactCallRelayer as K } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
11
|
-
import { ExternalActionId as
|
|
12
|
-
import { LidoAction as
|
|
11
|
+
import { ExternalActionId as i } from "../../types/external-action.types.mjs";
|
|
12
|
+
import { LidoAction as s, LidoVariant as d } from "../../types/hinkal.types.mjs";
|
|
13
13
|
const _ = (t, a) => {
|
|
14
|
-
if (t ===
|
|
15
|
-
return a ===
|
|
16
|
-
if (t ===
|
|
17
|
-
return a ===
|
|
14
|
+
if (t === d.Ethereum)
|
|
15
|
+
return a === s.Stake ? i.LidoETH : i.LidoETHNFT;
|
|
16
|
+
if (t === d.Polygon)
|
|
17
|
+
return a === s.Stake ? i.LidoMATIC : i.LidoMATICNFT;
|
|
18
18
|
throw new Error("Invalid LidoVariant used");
|
|
19
|
-
}, $ = (t) => M.utils.defaultAbiCoder.encode(["uint8"], [Number(t)]), X = async (t, a,
|
|
20
|
-
const
|
|
19
|
+
}, $ = (t) => M.utils.defaultAbiCoder.encode(["uint8"], [Number(t)]), X = async (t, a, o, n, e, p, A = !1) => {
|
|
20
|
+
const c = [...await D(t, n, e, 6, p)], y = c[0].length, C = `${o === s.Stake ? "swapperM" : "swapperToken"}2x${y}x1`, m = _(a, o), { flatFees: u, feeUnit: L } = await H(
|
|
21
21
|
t.getCurrentChainId(),
|
|
22
22
|
n,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
m,
|
|
24
|
+
e,
|
|
25
|
+
o
|
|
26
26
|
);
|
|
27
|
-
|
|
27
|
+
e = b({
|
|
28
28
|
erc20Addresses: n,
|
|
29
|
-
amountChanges:
|
|
30
|
-
flatFees:
|
|
29
|
+
amountChanges: e,
|
|
30
|
+
flatFees: u,
|
|
31
31
|
feeUnit: L,
|
|
32
|
-
externalActionId:
|
|
33
|
-
action:
|
|
32
|
+
externalActionId: m,
|
|
33
|
+
action: o
|
|
34
34
|
});
|
|
35
|
-
const
|
|
35
|
+
const T = o === s.Request ? e.map(() => !1) : e.map((r) => r > 0n), f = [];
|
|
36
36
|
for (let r = 0; r < n.length; r += 1) {
|
|
37
37
|
const { outputUtxos: F } = S(
|
|
38
38
|
t.userKeys,
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
c[r],
|
|
40
|
+
e[r],
|
|
41
41
|
void 0,
|
|
42
|
-
|
|
42
|
+
p[r]
|
|
43
43
|
);
|
|
44
|
-
|
|
44
|
+
f.push(F);
|
|
45
45
|
}
|
|
46
46
|
if (!await t.getRandomRelay())
|
|
47
47
|
throw Error(N.RELAYER_NOT_AVAILABLE);
|
|
48
|
-
const { lidoExternalActionEthAddress:
|
|
49
|
-
if (!
|
|
48
|
+
const { lidoExternalActionEthAddress: g, lidoExternalActionMaticAddress: I } = U[t.getCurrentChainId()].contractData, x = a === d.Ethereum ? g : I;
|
|
49
|
+
if (!x)
|
|
50
50
|
throw new Error("Can't find external action address");
|
|
51
|
-
const R = $(
|
|
51
|
+
const R = $(o), { zkCallData: E, circomData: l, dimData: w } = await P(
|
|
52
52
|
t.merkleTreeHinkal,
|
|
53
53
|
t.merkleTreeAccessToken,
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
c,
|
|
55
|
+
f,
|
|
56
56
|
t.userKeys,
|
|
57
57
|
C,
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
m,
|
|
59
|
+
x,
|
|
60
60
|
R,
|
|
61
61
|
await t.getRandomRelay(),
|
|
62
62
|
t.getCurrentChainId(),
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
T,
|
|
64
|
+
u
|
|
65
65
|
);
|
|
66
|
-
return
|
|
66
|
+
return A ? await v(t, E, w, l) : await K(t.getCurrentChainId(), E, w, l);
|
|
67
67
|
};
|
|
68
68
|
export {
|
|
69
69
|
X as hinkalActionLido
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const F=require("ethers"),q=require("../../constants/protocol.constants.cjs"),Y=require("../../constants/chains.constants.cjs"),g=require("../../functions/utils/erc20tokenFunctions.cjs"),b=require("../../functions/pre-transaction/getFlatFees.cjs"),O=require("../../functions/pre-transaction/processAmountChanges.cjs"),U=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),W=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),H=require("../../functions/web3/events/getShieldedBalance.cjs"),G=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),N=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),x=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),m=require("../../types/ethereum-network.types.cjs"),v=require("../../types/circom-data.types.cjs"),z=require("../../types/external-action.types.cjs"),t=require("../../types/hinkal.types.cjs"),L=require("../../error-handling/error-codes.constants.cjs"),$=e=>{let r=[];return e===t.PendleAction.Deposit?r=[!1,!0]:e===t.PendleAction.Withdraw?r=[!1,!0]:e===t.PendleAction.SwapFromYt?r=[!1,!0,!0]:e===t.PendleAction.SwapToYt?r=[!1,!1,!0]:e===t.PendleAction.SwapPt?r=[!1,!0]:e===t.PendleAction.Mint?r=[!1,!0,!1,!0]:e===t.PendleAction.Redeem?r=[!1,!1,!0,!0]:e===t.PendleAction.Checkpoint&&(r=[!1,!0]),r},B=(e,r)=>{const{pendleAction:o,ytAddress:c,userAddress:a,evmData:P}=e,i=P??"0x00",s=a??q.zeroAddress;if([t.PendleAction.Deposit,t.PendleAction.Withdraw,t.PendleAction.SwapFromYt,t.PendleAction.SwapToYt,t.PendleAction.SwapPt,t.PendleAction.Mint,t.PendleAction.Redeem,t.PendleAction.Checkpoint].includes(e.pendleAction))return F.utils.defaultAbiCoder.encode(["uint8","address","uint256","uint256","address","bool","bytes"],[o,c,r[0][0].amount,r[0][0].timeStamp,s,!0,i]);throw new Error("Not implemented")},K=async(e,r,o,c,a,P=!1)=>{const i=z.ExternalActionId.Pendle,{pendleAction:s}=c,l=[...await H.addPaddingToUtxos(e,r,o)],R=`swapperMO${o.length.toString()}x${l[0].length}x1`,{flatFees:y,feeUnit:T}=await b.getFlatFees(e.getCurrentChainId(),r,i,o,s,a);o=O.processAmountChanges({erc20Addresses:r,amountChanges:o,flatFees:y,feeUnit:T,externalActionId:i,action:s,gasTokenAddress:a});const p=[];for(let n=0;n<r.length;n+=1){const{outputUtxos:A}=W.outputUtxoProcessing(e.userKeys,l[n],o[n]);p.push(A)}const D=$(s),{contractData:E}=Y.networkRegistry[e.getCurrentChainId()],S=E?.pendleExternalActionInstanceAddress,h=B(c,l),C=s===t.PendleAction.Deposit||c.isRelayerOff?q.zeroAddress:await e.getRandomRelay();if(!C)throw Error(L.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const I=`0x0${s.toString(16)}`,k={...v.defaultHookData,preHookMetadata:I},{zkCallData:u,circomData:d,dimData:f}=await U.constructZkProof(e.merkleTreeHinkal,e.merkleTreeAccessToken,l,p,e.userKeys,R,i,S,h,C,e.getCurrentChainId(),D,y,k);if(P)return await G.estimateGasRelayer(e,u,f,d);const w=e.getCurrentChainId();if(s===t.PendleAction.Deposit){const n=g.getERC20Token(c.ytAddress,w);if(!n)throw Error("Yt Token not found");const A=e.getContractWithSigner(m.ContractType.PendleGeneralExternalAction),_=e.getContractWithSigner(m.ContractType.HinkalWrapper);return await x.transactCallDirect(e,o[0],n,u,d,f,A,_)}if(s===t.PendleAction.Withdraw&&c.isRelayerOff){const n=g.getERC20Token(c.ytAddress,w);if(!n)throw Error("Yt Token not found");return await x.transactCallDirect(e,o[0],n,u,d,f)}return await N.transactCallRelayer(e.getCurrentChainId(),u,f,d)};exports.hinkalActionPendle=K;
|
|
@@ -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;
|