@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,8 +1,8 @@
|
|
|
1
|
-
import { getNonLocalhostChainId as
|
|
1
|
+
import { getNonLocalhostChainId as g, chainIdsByType as y, EthereumNetworkType as S } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import "../../constants/vite.constants.mjs";
|
|
3
3
|
import "axios";
|
|
4
4
|
import "../../constants/coingecko.constants.mjs";
|
|
5
|
-
import { API as
|
|
5
|
+
import { API as f } from "../../API/API.mjs";
|
|
6
6
|
import "ethers";
|
|
7
7
|
import "../../types/curve.types.mjs";
|
|
8
8
|
import { getHinkalParameters as k } from "../../constants/contracts.constants.mjs";
|
|
@@ -18,8 +18,8 @@ import { getTxDetails as w } from "./history/getTxDetails.mjs";
|
|
|
18
18
|
import "circomlibjs";
|
|
19
19
|
import { transactionErrorCodes as C } from "../../error-handling/error-codes.constants.mjs";
|
|
20
20
|
import { UserKeys as P } from "../crypto-keys/keys.mjs";
|
|
21
|
-
import { decryptUtxo as
|
|
22
|
-
import { decodeTxInput as
|
|
21
|
+
import { decryptUtxo as H } from "../crypto-keys/encryptDecryptUtxo.mjs";
|
|
22
|
+
import { decodeTxInput as v, decodeTxLogs as z } from "../../functions/utils/getDataFromTransaction.mjs";
|
|
23
23
|
import { saveTxsCache as E, loadTxsCache as b } from "../../functions/utils/cacheFunctions.mjs";
|
|
24
24
|
class et {
|
|
25
25
|
circuitSize = 50;
|
|
@@ -31,22 +31,22 @@ class et {
|
|
|
31
31
|
if (!this.hinkalContract)
|
|
32
32
|
throw Error("TransactionsManager not initialized");
|
|
33
33
|
}
|
|
34
|
-
filterOwnTransactions = async (r,
|
|
34
|
+
filterOwnTransactions = async (r, t, e, n) => {
|
|
35
35
|
const { transactMethodId: a, transactWithExternalActionMethodId: s, hinkalInterface: i } = k(
|
|
36
|
-
|
|
37
|
-
), c = (o) => "decodedInput" in o,
|
|
36
|
+
g(r)
|
|
37
|
+
), c = (o) => "decodedInput" in o, h = t.filter(
|
|
38
38
|
(o) => o.methodId === a || o.methodId === s
|
|
39
39
|
).map((o) => c(o) ? o : {
|
|
40
40
|
...o,
|
|
41
|
-
decodedInput:
|
|
41
|
+
decodedInput: v(i, o.input),
|
|
42
42
|
status: o.isError === "0" ? "SUCCESS" : "FAILURE"
|
|
43
|
-
}), u =
|
|
44
|
-
return
|
|
43
|
+
}), u = e.getShieldedPrivateKey();
|
|
44
|
+
return h.filter((o) => {
|
|
45
45
|
try {
|
|
46
46
|
if (c(o)) {
|
|
47
|
-
if (
|
|
48
|
-
const { extraRandomization:
|
|
49
|
-
return P.checkSignature(
|
|
47
|
+
if (H(Buffer.from(o.decodedInput.encryptedOutputs[0].slice(2), "hex"), e), !n && o.methodId === a) {
|
|
48
|
+
const { extraRandomization: m, H0: p, H1: T } = o.decodedInput.stealthAddressStructure;
|
|
49
|
+
return P.checkSignature(m, p, T, u);
|
|
50
50
|
}
|
|
51
51
|
return !0;
|
|
52
52
|
}
|
|
@@ -56,31 +56,31 @@ class et {
|
|
|
56
56
|
}
|
|
57
57
|
});
|
|
58
58
|
};
|
|
59
|
-
saveTxsInStorage = (r,
|
|
60
|
-
const a =
|
|
61
|
-
return E(r,
|
|
59
|
+
saveTxsInStorage = (r, t, e, n) => {
|
|
60
|
+
const a = e.getShieldedPublicKey();
|
|
61
|
+
return E(r, t, a, this.hinkalContract.address, n);
|
|
62
62
|
};
|
|
63
|
-
loadTxsFromStorage = async (r,
|
|
64
|
-
const
|
|
65
|
-
return await b(r,
|
|
63
|
+
loadTxsFromStorage = async (r, t) => {
|
|
64
|
+
const e = t.getShieldedPublicKey();
|
|
65
|
+
return await b(r, e, this.hinkalContract.address);
|
|
66
66
|
};
|
|
67
|
-
getAllTransactions = async (r,
|
|
68
|
-
if (
|
|
69
|
-
const { transactions: i } = await
|
|
67
|
+
getAllTransactions = async (r, t, e) => {
|
|
68
|
+
if (e) {
|
|
69
|
+
const { transactions: i } = await f.userGetTransactions(r, e);
|
|
70
70
|
return i;
|
|
71
71
|
}
|
|
72
|
-
const { decodedTxs: n, lastHash: a } = await this.loadTxsFromStorage(r,
|
|
72
|
+
const { decodedTxs: n, lastHash: a } = await this.loadTxsFromStorage(r, t), { transactions: s } = await f.userGetTransactions(r, e, a);
|
|
73
73
|
return [...s, ...n];
|
|
74
74
|
};
|
|
75
|
-
getHinkalHistoryBase = async (r,
|
|
75
|
+
getHinkalHistoryBase = async (r, t, e, n = !1) => {
|
|
76
76
|
this.requireInit();
|
|
77
|
-
const a = await this.getAllTransactions(r,
|
|
77
|
+
const a = await this.getAllTransactions(r, t, e) ?? [];
|
|
78
78
|
a.sort((i, c) => c.timeStamp - i.timeStamp);
|
|
79
|
-
const s = await this.filterOwnTransactions(r, a,
|
|
80
|
-
return !
|
|
79
|
+
const s = await this.filterOwnTransactions(r, a, t, n);
|
|
80
|
+
return !e && a.length > 0 && await this.saveTxsInStorage(s, r, t, a[0].hash), s;
|
|
81
81
|
};
|
|
82
|
-
getHinkalHistory = async (r,
|
|
83
|
-
const
|
|
82
|
+
getHinkalHistory = async (r, t) => {
|
|
83
|
+
const e = await this.getHinkalHistoryBase(r, t, void 0, !0), n = z(r, e);
|
|
84
84
|
return await Promise.all(
|
|
85
85
|
n.map(async (s) => ({
|
|
86
86
|
...s,
|
|
@@ -90,90 +90,82 @@ class et {
|
|
|
90
90
|
);
|
|
91
91
|
};
|
|
92
92
|
sortInBatches = (r) => {
|
|
93
|
-
const
|
|
94
|
-
let
|
|
93
|
+
const t = [];
|
|
94
|
+
let e = 0, n = 0;
|
|
95
95
|
r.forEach((i) => {
|
|
96
|
-
|
|
96
|
+
e === 0 && t.push([]), t[n].push(i), e += 1, e === this.circuitSize && (e = 0, n += 1);
|
|
97
97
|
});
|
|
98
|
-
const a =
|
|
98
|
+
const a = t[t.length - 1], s = a.length;
|
|
99
99
|
if (s < this.circuitSize) {
|
|
100
100
|
const i = this.circuitSize - s, c = new Array(i).fill(I);
|
|
101
|
-
|
|
101
|
+
t[t.length - 1] = a.concat(c);
|
|
102
102
|
}
|
|
103
|
-
return
|
|
103
|
+
return t;
|
|
104
104
|
};
|
|
105
|
-
generateTransactionsProof = async (r,
|
|
106
|
-
const n = this.sortInBatches(
|
|
105
|
+
generateTransactionsProof = async (r, t, e) => {
|
|
106
|
+
const n = this.sortInBatches(t), a = new Array(n.length).fill([]);
|
|
107
107
|
for (let s = 0; s < n.length; s += 1) {
|
|
108
108
|
const i = n[s].map(
|
|
109
|
-
(
|
|
110
|
-
), c = i.map((
|
|
111
|
-
|
|
112
|
-
const l = {
|
|
113
|
-
shieldedPrivateKey: t,
|
|
109
|
+
(l) => l.decodedInput.stealthAddressStructure
|
|
110
|
+
), c = i.map((l) => l.extraRandomization), d = i.map((l) => l.stealthAddress), h = {
|
|
111
|
+
shieldedPrivateKey: e,
|
|
114
112
|
extraRandomizations: c,
|
|
115
113
|
stealthAddresses: d
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
const { zkCallData: u } = await A(r, "transactionsProver", l);
|
|
119
|
-
console.log({ zkCallData: u }), a[s] = u;
|
|
114
|
+
}, { zkCallData: u } = await A(r, "transactionsProver", h);
|
|
115
|
+
a[s] = u;
|
|
120
116
|
}
|
|
121
117
|
return { zkCallDataArray: a };
|
|
122
118
|
};
|
|
123
|
-
userVerifyTransactions = async (r,
|
|
119
|
+
userVerifyTransactions = async (r, t, e, n, a, s) => await f.userVerifyTransactions(
|
|
124
120
|
r,
|
|
125
|
-
e,
|
|
126
121
|
t,
|
|
122
|
+
e,
|
|
127
123
|
n,
|
|
128
124
|
a,
|
|
129
125
|
s
|
|
130
126
|
);
|
|
131
|
-
processAndSendTransactionsForVerification = async (r,
|
|
127
|
+
processAndSendTransactionsForVerification = async (r, t, e, n) => {
|
|
132
128
|
this.requireInit();
|
|
133
|
-
const a = x(), s = n ? a - 1 : a;
|
|
134
|
-
console.log("retrieving transactions in processAndSendTransactionsForVerification", { week: s });
|
|
135
|
-
const i = await this.getHinkalHistoryBase(r, e, s);
|
|
136
|
-
console.log("retrieved transactions", i);
|
|
129
|
+
const a = x(), s = n ? a - 1 : a, i = await this.getHinkalHistoryBase(r, t, s);
|
|
137
130
|
let c = [], d = [];
|
|
138
131
|
i.length > 0 && ({ zkCallDataArray: d } = await this.generateTransactionsProof(
|
|
139
132
|
r,
|
|
140
133
|
i,
|
|
141
|
-
|
|
134
|
+
t.getShieldedPrivateKey()
|
|
142
135
|
), c = i.map((p) => p.hash));
|
|
143
|
-
const
|
|
136
|
+
const h = t.getBackendToken(), {
|
|
144
137
|
trade: u,
|
|
145
|
-
transactions:
|
|
138
|
+
transactions: l,
|
|
146
139
|
lockedDeposit: o,
|
|
147
|
-
verification:
|
|
140
|
+
verification: m
|
|
148
141
|
} = await this.userVerifyTransactions(
|
|
149
142
|
r,
|
|
150
143
|
c,
|
|
151
144
|
d,
|
|
152
|
-
|
|
153
|
-
|
|
145
|
+
h,
|
|
146
|
+
e,
|
|
154
147
|
s
|
|
155
148
|
);
|
|
156
|
-
return { trade: u, transactions:
|
|
149
|
+
return { trade: u, transactions: l, lockedDeposit: o, verification: m };
|
|
157
150
|
};
|
|
158
|
-
multiProcessAndSendTransactionsForVerification = async (r,
|
|
159
|
-
|
|
160
|
-
const t = y[S.Mainnet];
|
|
151
|
+
multiProcessAndSendTransactionsForVerification = async (r, t) => {
|
|
152
|
+
const e = y[S.Mainnet];
|
|
161
153
|
let n = !0;
|
|
162
|
-
for (let a = 0; a <
|
|
154
|
+
for (let a = 0; a < e.length; a += 1)
|
|
163
155
|
try {
|
|
164
|
-
const { hasCertified: s } = await
|
|
165
|
-
if (
|
|
156
|
+
const { hasCertified: s } = await f.verificationStartDate(e[a], t);
|
|
157
|
+
if (s)
|
|
166
158
|
continue;
|
|
167
|
-
const {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
if (
|
|
159
|
+
const { verification: i } = await this.processAndSendTransactionsForVerification(
|
|
160
|
+
e[a],
|
|
161
|
+
r,
|
|
162
|
+
t,
|
|
163
|
+
!0
|
|
164
|
+
);
|
|
165
|
+
if (n = n && i, !n)
|
|
174
166
|
break;
|
|
175
167
|
} catch (s) {
|
|
176
|
-
console.log(`current chain ${
|
|
168
|
+
console.log(`current chain ${e[a]} certification error`, { err: s }), n = !1;
|
|
177
169
|
break;
|
|
178
170
|
}
|
|
179
171
|
if (!n)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./history.types.cjs");require("../../../types/circom-data.types.cjs");const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./history.types.cjs");require("../../../types/circom-data.types.cjs");const A=require("../../../types/hinkal.types.cjs");require("../../../types/transactions.types.cjs");require("../../../types/curve.types.cjs");const d=require("../../../functions/utils/erc20tokenFunctions.cjs"),a=require("../../../functions/utils/caseInsensitive.utils.cjs"),v=require("../../../constants/token-data/ERC20Registry.cjs"),E=require("../../volatile-helper/VolatileHelper.cjs"),h=async(o,f,s)=>{const c=v.getERC20Registry(s),{externalActionMetadata:V}=o,{volatileAmounts:k,redirectActionId:q,volatileAction:T}=E.VolatileHelper.decodeVolatileMetadata(V);if(T===A.VolatileAction.Deposit){const r=o.erc20TokenAddresses[0],e=c.find(t=>a.caseInsensitiveEqual(t.sharedAddress,r));if(!e)throw Error("Volatile not found in statistics");return{tokenWithBalance:{token:d.getERC20Token(e.erc20TokenAddress,s)??{erc20TokenAddress:e.erc20TokenAddress},balance:k[0].toBigInt()},type:l.TransactionType.DEPOSIT}}if(T===A.VolatileAction.Withdraw){const r=o.erc20TokenAddresses[0],e=c.find(t=>a.caseInsensitiveEqual(t.sharedAddress,r));if(!e)throw Error("Volatile not found in statistics");return{tokenWithBalance:{token:d.getERC20Token(e.erc20TokenAddress,s)??{erc20TokenAddress:e.erc20TokenAddress},balance:k[0].toBigInt()},type:l.TransactionType.WITHDRAW}}if(T===A.VolatileAction.Swap){const r=o.erc20TokenAddresses[0],e=o.erc20TokenAddresses[1],u=o.amountChanges[0].toBigInt(),i=c.find(n=>a.caseInsensitiveEqual(n.sharedAddress,r)),t=c.find(n=>a.caseInsensitiveEqual(n.sharedAddress,e));if(!i&&!t)throw Error("Volatile not found in swap statistics");const p={token:d.getERC20Token(i?i.erc20TokenAddress:r,s),balance:i?k[0].toBigInt():u},g=f.find(n=>a.caseInsensitiveEqual(n.erc20TokenAddress,e));let y={token:d.getERC20Token(e,s),balance:g?.amount};if(t){const n=await E.VolatileHelper.getVolatileTokenBalance(s,e,g?.amount??0n);y={token:t,balance:n}}return{tokenIn:p,tokenOut:y,type:l.TransactionType.SWAP,protocol:q.toBigInt()}}return{type:l.TransactionType.UNKNOWN}};exports.getVolatileData=h;
|
|
@@ -7,10 +7,10 @@ import { getERC20Token as l } from "../../../functions/utils/erc20tokenFunctions
|
|
|
7
7
|
import { caseInsensitiveEqual as i } from "../../../functions/utils/caseInsensitive.utils.mjs";
|
|
8
8
|
import { getERC20Registry as W } from "../../../constants/token-data/ERC20Registry.mjs";
|
|
9
9
|
import { VolatileHelper as g } from "../../volatile-helper/VolatileHelper.mjs";
|
|
10
|
-
const
|
|
11
|
-
const c = W(s), { externalActionMetadata: B } = n, { volatileAmounts: k, redirectActionId:
|
|
10
|
+
const C = async (n, u, s) => {
|
|
11
|
+
const c = W(s), { externalActionMetadata: B } = n, { volatileAmounts: k, redirectActionId: V, volatileAction: A } = g.decodeVolatileMetadata(B);
|
|
12
12
|
if (A === f.Deposit) {
|
|
13
|
-
const r = n.erc20TokenAddresses[0], e = c.find((
|
|
13
|
+
const r = n.erc20TokenAddresses[0], e = c.find((t) => i(t.sharedAddress, r));
|
|
14
14
|
if (!e)
|
|
15
15
|
throw Error("Volatile not found in statistics");
|
|
16
16
|
return {
|
|
@@ -22,7 +22,7 @@ const N = async (n, u, s) => {
|
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
24
|
if (A === f.Withdraw) {
|
|
25
|
-
const r = n.erc20TokenAddresses[0], e = c.find((
|
|
25
|
+
const r = n.erc20TokenAddresses[0], e = c.find((t) => i(t.sharedAddress, r));
|
|
26
26
|
if (!e)
|
|
27
27
|
throw Error("Volatile not found in statistics");
|
|
28
28
|
return {
|
|
@@ -34,22 +34,22 @@ const N = async (n, u, s) => {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
if (A === f.Swap) {
|
|
37
|
-
const r = n.erc20TokenAddresses[0], e = n.erc20TokenAddresses[1], T = n.amountChanges[0].toBigInt(), a = c.find((
|
|
38
|
-
if (!a && !
|
|
37
|
+
const r = n.erc20TokenAddresses[0], e = n.erc20TokenAddresses[1], T = n.amountChanges[0].toBigInt(), a = c.find((o) => i(o.sharedAddress, r)), t = c.find((o) => i(o.sharedAddress, e));
|
|
38
|
+
if (!a && !t)
|
|
39
39
|
throw Error("Volatile not found in swap statistics");
|
|
40
|
-
const
|
|
40
|
+
const E = {
|
|
41
41
|
token: l(a ? a.erc20TokenAddress : r, s),
|
|
42
42
|
balance: a ? k[0].toBigInt() : T
|
|
43
|
-
}, m = u.find((
|
|
43
|
+
}, m = u.find((o) => i(o.erc20TokenAddress, e));
|
|
44
44
|
let p = { token: l(e, s), balance: m?.amount };
|
|
45
|
-
if (
|
|
46
|
-
const
|
|
47
|
-
|
|
45
|
+
if (t) {
|
|
46
|
+
const o = await g.getVolatileTokenBalance(s, e, m?.amount ?? 0n);
|
|
47
|
+
p = { token: t, balance: o };
|
|
48
48
|
}
|
|
49
|
-
return { tokenIn:
|
|
49
|
+
return { tokenIn: E, tokenOut: p, type: d.SWAP, protocol: V.toBigInt() };
|
|
50
50
|
}
|
|
51
51
|
return { type: d.UNKNOWN };
|
|
52
52
|
};
|
|
53
53
|
export {
|
|
54
|
-
|
|
54
|
+
C as getVolatileData
|
|
55
55
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("ethers"),d=require("../../constants/protocol.constants.cjs"),h=require("../../constants/chains.constants.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("ethers"),d=require("../../constants/protocol.constants.cjs"),h=require("../../constants/chains.constants.cjs"),i=require("../../types/hinkal.types.cjs"),w=require("../../types/ethereum-network.types.cjs"),A=require("../../types/external-action.types.cjs"),v=require("../../functions/utils/erc20tokenFunctions.cjs"),T=require("../../functions/utils/external-action.utils.cjs"),f=require("../../functions/utils/enum.utils.cjs"),g=new u.ethers.utils.Interface(["function volatileTokenToShareToken(address volatileToken) external view returns (address)","function shareTokenToVolatileToken(address volatileToken) external view returns (address)","function shareToVolatile(address shareToken, uint shareValue) external view returns (uint)","function volatileToShare(address volatileToken, uint volatileTokenValue, uint volatileTokenBalanceOverride) external view returns (uint)"]);class a{static getVolatileTokenAction(o){const n=h.networkRegistry[o],{fetchRpcUrl:t}=n,{volatileTokenActionInstanceAddress:e}=n.contractData;if(!e)throw Error("Volatile Token Address not found");const r=new u.ethers.providers.JsonRpcProvider(t);return new u.ethers.Contract(e,g,r)}static getVolatileTokenAddress=async(o,n)=>{try{const e=await a.getVolatileTokenAction(o).shareTokenToVolatileToken(n);if(e===d.zeroAddress)throw new Error("Can't get share token address");return e}catch(t){console.log("getShareTokenAddress error ",t.message);return}};static getShareTokenAddress=async(o,n)=>{if(n===d.zeroAddress)return a.getShareTokenAddress(o,d.ethVolatileAddress);try{const e=await a.getVolatileTokenAction(o).volatileTokenToShareToken(n);if(e===d.zeroAddress)throw new Error("Can't get share token address");return e}catch(t){console.log("getShareTokenAddress error ",t.message);return}};static getVolatileTokenBalance=async(o,n,t,e)=>{try{if(t===0n)return 0n;const r=a.getVolatileTokenAction(o),l=t<0n?-1n:1n,c=e?{blockTag:e}:{};return l*(await r.shareToVolatile(n,l*t,c)).toBigInt()}catch(r){return console.log("getVolatileTokenBalance convertToShare error",r),0n}};static getShareTokenBalance=async(o,n,t)=>{if(n===d.zeroAddress)return this.getShareTokenBalance(o,d.ethVolatileAddress,t);try{if(t===0n)return 0n;const e=a.getVolatileTokenAction(o),r=t<0n?-1n:1n;return r*(await e.volatileToShare(n,r*t,0n)).toBigInt()}catch(e){return console.log("getShareTokenBalance convertToShare error",e),0n}};static processVolatileData=async(o,n,t,e)=>{let r=[];if(n===i.VolatileAction.Deposit)e[0]=0n,t[0]=await a.getShareTokenAddress(o,t[0]),r=[!0];else if(n===i.VolatileAction.Withdraw)e[0]=-1n*await a.getShareTokenBalance(o,t[0],-e[0]),t[0]=await a.getShareTokenAddress(o,t[0]),r=[!1];else if(n===i.VolatileAction.Swap){const l=t.map(c=>v.getERC20Token(c,o));await Promise.all(l.map(async(c,s)=>{c?.isVolatile&&(e[s]<0n?e[s]=-1n*await a.getShareTokenBalance(o,t[s],-e[s]):e[s]>=0n&&(e[s]=0n),t[s]=await a.getShareTokenAddress(o,c.erc20TokenAddress))})),r=[!1,!0]}return{erc20Addresses:t,amountChanges:e,onChainCreation:r}};static decodeVolatileMetadata=o=>{const n=T.decodeMetadata(A.ExternalActionId.Volatile,o),t=n[0],e=n[2],r=n[4],l=f.toEnumValue(i.VolatileAction,r);return{volatileAmounts:t,redirectActionId:e,volatileAction:l}};static encodeVolatileActionMetadata=({actionType:o=i.VolatileAction.Deposit,volatileAmounts:n=[],withdrawRecipient:t=d.zeroAddress,redirectActionId:e=0,redirectMetadata:r="0x00"})=>u.ethers.utils.defaultAbiCoder.encode(["uint256[]","address","uint256","bytes","uint8"],[n,t,e,r,o]);static getVolotileMetadata=(o,n,t,e,r)=>{if(o===i.VolatileAction.Deposit)return{actionType:o,volatileAmounts:n};if(o===i.VolatileAction.Withdraw){if(!t)throw Error("No withdrawal recipient");return{actionType:o,volatileAmounts:n,withdrawRecipient:t}}if(o===i.VolatileAction.Swap){if(e===void 0||!r)throw Error("No redirect action Id");return{actionType:o,volatileAmounts:n,redirectActionId:T.getExternalActionIdHash(e),redirectMetadata:r}}throw new Error("Invalid Request")};static getVolatileExternalData=async(o,n,t,e,r,l)=>{const s=o.getContractWithFetcher(w.ContractType.VolatileTokenAction).address;let k=[];return n===i.VolatileAction.Deposit&&(k=t),n===i.VolatileAction.Withdraw&&(k=[-t[0]]),n===i.VolatileAction.Swap&&(k=[-t[0],0n]),{externalActionId:A.ExternalActionId.Volatile,externalAddress:s,externalActionMetadata:this.encodeVolatileActionMetadata(this.getVolotileMetadata(n,k,e,r,l))}};static decodeExternalActionId=o=>{let n=!1,t;const{externalActionId:e}=o.decodedInput;return(typeof e=="string"?e:e.toBigInt())===T.getExternalActionIdHash(A.ExternalActionId.Volatile)&&({redirectActionId:t}=a.decodeVolatileMetadata(o.decodedInput.externalActionMetadata),n=!0),{isVolatile:n,redirectActionId:t}}}exports.VolatileHelper=a;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { ethers as T } from "ethers";
|
|
2
2
|
import { zeroAddress as d, ethVolatileAddress as u } from "../../constants/protocol.constants.mjs";
|
|
3
3
|
import { networkRegistry as h } from "../../constants/chains.constants.mjs";
|
|
4
|
-
import { VolatileAction as
|
|
5
|
-
import { ContractType as
|
|
4
|
+
import { VolatileAction as i } from "../../types/hinkal.types.mjs";
|
|
5
|
+
import { ContractType as v } from "../../types/ethereum-network.types.mjs";
|
|
6
6
|
import { ExternalActionId as f } from "../../types/external-action.types.mjs";
|
|
7
|
-
import { getERC20Token as
|
|
8
|
-
import { decodeMetadata as A, getExternalActionIdHash as
|
|
7
|
+
import { getERC20Token as g } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
8
|
+
import { decodeMetadata as A, getExternalActionIdHash as w } from "../../functions/utils/external-action.utils.mjs";
|
|
9
9
|
import { toEnumValue as S } from "../../functions/utils/enum.utils.mjs";
|
|
10
10
|
const V = new T.utils.Interface([
|
|
11
11
|
"function volatileTokenToShareToken(address volatileToken) external view returns (address)",
|
|
@@ -14,16 +14,16 @@ const V = new T.utils.Interface([
|
|
|
14
14
|
"function volatileToShare(address volatileToken, uint volatileTokenValue, uint volatileTokenBalanceOverride) external view returns (uint)"
|
|
15
15
|
]);
|
|
16
16
|
class a {
|
|
17
|
-
static getVolatileTokenAction(
|
|
18
|
-
const
|
|
17
|
+
static getVolatileTokenAction(o) {
|
|
18
|
+
const n = h[o], { fetchRpcUrl: t } = n, { volatileTokenActionInstanceAddress: e } = n.contractData;
|
|
19
19
|
if (!e)
|
|
20
20
|
throw Error("Volatile Token Address not found");
|
|
21
21
|
const r = new T.providers.JsonRpcProvider(t);
|
|
22
22
|
return new T.Contract(e, V, r);
|
|
23
23
|
}
|
|
24
|
-
static getVolatileTokenAddress = async (
|
|
24
|
+
static getVolatileTokenAddress = async (o, n) => {
|
|
25
25
|
try {
|
|
26
|
-
const e = await a.getVolatileTokenAction(
|
|
26
|
+
const e = await a.getVolatileTokenAction(o).shareTokenToVolatileToken(n);
|
|
27
27
|
if (e === d)
|
|
28
28
|
throw new Error("Can't get share token address");
|
|
29
29
|
return e;
|
|
@@ -32,11 +32,11 @@ class a {
|
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
-
static getShareTokenAddress = async (
|
|
36
|
-
if (
|
|
37
|
-
return a.getShareTokenAddress(
|
|
35
|
+
static getShareTokenAddress = async (o, n) => {
|
|
36
|
+
if (n === d)
|
|
37
|
+
return a.getShareTokenAddress(o, u);
|
|
38
38
|
try {
|
|
39
|
-
const e = await a.getVolatileTokenAction(
|
|
39
|
+
const e = await a.getVolatileTokenAction(o).volatileTokenToShareToken(n);
|
|
40
40
|
if (e === d)
|
|
41
41
|
throw new Error("Can't get share token address");
|
|
42
42
|
return e;
|
|
@@ -45,29 +45,29 @@ class a {
|
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
};
|
|
48
|
-
static getVolatileTokenBalance = async (
|
|
48
|
+
static getVolatileTokenBalance = async (o, n, t, e) => {
|
|
49
49
|
try {
|
|
50
50
|
if (t === 0n)
|
|
51
51
|
return 0n;
|
|
52
|
-
const r = a.getVolatileTokenAction(
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
const r = a.getVolatileTokenAction(o), l = t < 0n ? -1n : 1n, s = e ? { blockTag: e } : {};
|
|
53
|
+
return l * (await r.shareToVolatile(
|
|
54
|
+
n,
|
|
55
|
+
l * t,
|
|
56
56
|
s
|
|
57
57
|
)).toBigInt();
|
|
58
58
|
} catch (r) {
|
|
59
59
|
return console.log("getVolatileTokenBalance convertToShare error", r), 0n;
|
|
60
60
|
}
|
|
61
61
|
};
|
|
62
|
-
static getShareTokenBalance = async (
|
|
63
|
-
if (
|
|
64
|
-
return this.getShareTokenBalance(
|
|
62
|
+
static getShareTokenBalance = async (o, n, t) => {
|
|
63
|
+
if (n === d)
|
|
64
|
+
return this.getShareTokenBalance(o, u, t);
|
|
65
65
|
try {
|
|
66
66
|
if (t === 0n)
|
|
67
67
|
return 0n;
|
|
68
|
-
const e = a.getVolatileTokenAction(
|
|
68
|
+
const e = a.getVolatileTokenAction(o), r = t < 0n ? -1n : 1n;
|
|
69
69
|
return r * (await e.volatileToShare(
|
|
70
|
-
|
|
70
|
+
n,
|
|
71
71
|
r * t,
|
|
72
72
|
0n
|
|
73
73
|
)).toBigInt();
|
|
@@ -75,85 +75,85 @@ class a {
|
|
|
75
75
|
return console.log("getShareTokenBalance convertToShare error", e), 0n;
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
|
-
static processVolatileData = async (
|
|
78
|
+
static processVolatileData = async (o, n, t, e) => {
|
|
79
79
|
let r = [];
|
|
80
|
-
if (
|
|
81
|
-
e[0] = 0n, t[0] = await a.getShareTokenAddress(
|
|
82
|
-
else if (
|
|
83
|
-
e[0] = -1n * await a.getShareTokenBalance(
|
|
84
|
-
else if (
|
|
85
|
-
const
|
|
80
|
+
if (n === i.Deposit)
|
|
81
|
+
e[0] = 0n, t[0] = await a.getShareTokenAddress(o, t[0]), r = [!0];
|
|
82
|
+
else if (n === i.Withdraw)
|
|
83
|
+
e[0] = -1n * await a.getShareTokenBalance(o, t[0], -e[0]), t[0] = await a.getShareTokenAddress(o, t[0]), r = [!1];
|
|
84
|
+
else if (n === i.Swap) {
|
|
85
|
+
const l = t.map((s) => g(s, o));
|
|
86
86
|
await Promise.all(
|
|
87
|
-
|
|
88
|
-
s?.isVolatile && (
|
|
87
|
+
l.map(async (s, c) => {
|
|
88
|
+
s?.isVolatile && (e[c] < 0n ? e[c] = -1n * await a.getShareTokenBalance(o, t[c], -e[c]) : e[c] >= 0n && (e[c] = 0n), t[c] = await a.getShareTokenAddress(o, s.erc20TokenAddress));
|
|
89
89
|
})
|
|
90
90
|
), r = [!1, !0];
|
|
91
91
|
}
|
|
92
92
|
return { erc20Addresses: t, amountChanges: e, onChainCreation: r };
|
|
93
93
|
};
|
|
94
|
-
static decodeVolatileMetadata = (
|
|
95
|
-
const
|
|
96
|
-
return { volatileAmounts: t, redirectActionId: e, volatileAction:
|
|
94
|
+
static decodeVolatileMetadata = (o) => {
|
|
95
|
+
const n = A(f.Volatile, o), t = n[0], e = n[2], r = n[4], l = S(i, r);
|
|
96
|
+
return { volatileAmounts: t, redirectActionId: e, volatileAction: l };
|
|
97
97
|
};
|
|
98
98
|
// TODO: Type descriminate these base on actionType
|
|
99
99
|
static encodeVolatileActionMetadata = ({
|
|
100
|
-
actionType:
|
|
101
|
-
volatileAmounts:
|
|
100
|
+
actionType: o = i.Deposit,
|
|
101
|
+
volatileAmounts: n = [],
|
|
102
102
|
withdrawRecipient: t = d,
|
|
103
103
|
redirectActionId: e = 0,
|
|
104
104
|
redirectMetadata: r = "0x00"
|
|
105
|
-
}) =>
|
|
105
|
+
}) => T.utils.defaultAbiCoder.encode(
|
|
106
106
|
["uint256[]", "address", "uint256", "bytes", "uint8"],
|
|
107
|
-
[
|
|
108
|
-
)
|
|
109
|
-
static getVolotileMetadata = (
|
|
110
|
-
if (
|
|
107
|
+
[n, t, e, r, o]
|
|
108
|
+
);
|
|
109
|
+
static getVolotileMetadata = (o, n, t, e, r) => {
|
|
110
|
+
if (o === i.Deposit)
|
|
111
111
|
return {
|
|
112
|
-
actionType:
|
|
113
|
-
volatileAmounts:
|
|
112
|
+
actionType: o,
|
|
113
|
+
volatileAmounts: n
|
|
114
114
|
};
|
|
115
|
-
if (
|
|
115
|
+
if (o === i.Withdraw) {
|
|
116
116
|
if (!t)
|
|
117
117
|
throw Error("No withdrawal recipient");
|
|
118
118
|
return {
|
|
119
|
-
actionType:
|
|
120
|
-
volatileAmounts:
|
|
119
|
+
actionType: o,
|
|
120
|
+
volatileAmounts: n,
|
|
121
121
|
withdrawRecipient: t
|
|
122
122
|
};
|
|
123
123
|
}
|
|
124
|
-
if (
|
|
124
|
+
if (o === i.Swap) {
|
|
125
125
|
if (e === void 0 || !r)
|
|
126
126
|
throw Error("No redirect action Id");
|
|
127
127
|
return {
|
|
128
|
-
actionType:
|
|
129
|
-
volatileAmounts:
|
|
130
|
-
redirectActionId:
|
|
128
|
+
actionType: o,
|
|
129
|
+
volatileAmounts: n,
|
|
130
|
+
redirectActionId: w(e),
|
|
131
131
|
redirectMetadata: r
|
|
132
132
|
};
|
|
133
133
|
}
|
|
134
134
|
throw new Error("Invalid Request");
|
|
135
135
|
};
|
|
136
|
-
static getVolatileExternalData = async (
|
|
137
|
-
const
|
|
136
|
+
static getVolatileExternalData = async (o, n, t, e, r, l) => {
|
|
137
|
+
const c = o.getContractWithFetcher(v.VolatileTokenAction).address;
|
|
138
138
|
let k = [];
|
|
139
|
-
return
|
|
139
|
+
return n === i.Deposit && (k = t), n === i.Withdraw && (k = [-t[0]]), n === i.Swap && (k = [-t[0], 0n]), {
|
|
140
140
|
externalActionId: f.Volatile,
|
|
141
|
-
externalAddress:
|
|
141
|
+
externalAddress: c,
|
|
142
142
|
externalActionMetadata: this.encodeVolatileActionMetadata(
|
|
143
143
|
this.getVolotileMetadata(
|
|
144
|
-
|
|
144
|
+
n,
|
|
145
145
|
k,
|
|
146
146
|
e,
|
|
147
147
|
r,
|
|
148
|
-
|
|
148
|
+
l
|
|
149
149
|
)
|
|
150
150
|
)
|
|
151
151
|
};
|
|
152
152
|
};
|
|
153
|
-
static decodeExternalActionId = (
|
|
154
|
-
let
|
|
155
|
-
const { externalActionId: e } =
|
|
156
|
-
return (typeof e == "string" ? e : e.toBigInt()) ===
|
|
153
|
+
static decodeExternalActionId = (o) => {
|
|
154
|
+
let n = !1, t;
|
|
155
|
+
const { externalActionId: e } = o.decodedInput;
|
|
156
|
+
return (typeof e == "string" ? e : e.toBigInt()) === w(f.Volatile) && ({ redirectActionId: t } = a.decodeVolatileMetadata(o.decodedInput.externalActionMetadata), n = !0), { isVolatile: n, redirectActionId: t };
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
159
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("../../types/beefy.types.cjs");require("../../types/circom-data.types.cjs");const T=require("../../types/hinkal.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const R=require("../utils/erc20tokenFunctions.cjs"),D=require("./process-gas-estimates.cjs"),c=require("./interaction-to-action.cjs"),g=async(a,I,o,_,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("../../types/beefy.types.cjs");require("../../types/circom-data.types.cjs");const T=require("../../types/hinkal.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");const R=require("../utils/erc20tokenFunctions.cjs"),D=require("./process-gas-estimates.cjs"),c=require("./interaction-to-action.cjs"),g=async(a,I,o,_,n,L)=>{let N;const A=c.getInteractionFromAction(o,n);if(A===T.INTERACTION.NONE)throw Error("No interaction was choosen");let t,k,C;switch(A){case T.INTERACTION.WITHDRAW:N=R.getERC20Token(I[0],a);break;case T.INTERACTION.SWAP:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.CURVE_DEPOSIT:N=R.getERC20Token(I[I.length-1],a);break;case T.INTERACTION.CURVE_WITHDRAW:{if(C=I.findIndex(O=>O.toLowerCase()===L?.toLowerCase()),C===-1)throw Error("Curve Withdraw Token Index not found");N=R.getERC20Token(I[C],a);break}case T.INTERACTION.STAKING:case T.INTERACTION.UNSTAKING:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.CLAIMING:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.BEEFY:t=P.isBeefyDeposit(n)?1:0,N=R.getERC20Token(I[t],a);break;case T.INTERACTION.BEEFY_STAKE:case T.INTERACTION.BEEFY_UNSTAKE:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.BEEFY_GET_REWARDS:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.LIDO_STAKE:N=R.getERC20Token(I[0],a);break;case T.INTERACTION.LIDO_REQUEST:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.LIDO_CLAIM:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.PENDLE_TRANSACT:N=R.getERC20Token(I[0],a);break;case T.INTERACTION.PENDLE_YT_IN_SWAP:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.PENDLE_YT_OUT_SWAP:N=R.getERC20Token(I[0],a);break;case T.INTERACTION.PENDLE_PT_SWAP:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.PENDLE_MINT:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.PENDLE_REDEEM:N=R.getERC20Token(I[2],a);break;case T.INTERACTION.PENDLE_CLAIM:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.VOLATILE_WITHDRAW:N=R.getERC20Token(I[0],a);break;case T.INTERACTION.VOLATILE_SWAP:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.PENDLE_LP:k=_.findIndex(O=>O>0),N=R.getERC20Token(I[k],a);break;case T.INTERACTION.PENDLE_LP_CLAIM:N=R.getERC20Token(I[1],a);break;case T.INTERACTION.EMPORIUM:}let E,b;const r=_.length;N&&({priceOfTransactionInToken:E,priceOfTransactionInUSD:b}=await D.processGasEstimates(a,N,o,n,r));const e=new Array(r).fill(0n);switch(A){case T.INTERACTION.WITHDRAW:e[0]=E||0n;break;case T.INTERACTION.SWAP:e[1]=E||0n;break;case T.INTERACTION.CURVE_DEPOSIT:e[e.length-1]=E||0n;break;case T.INTERACTION.CURVE_WITHDRAW:C!==void 0&&(e[C]=E||0n);break;case T.INTERACTION.STAKING:case T.INTERACTION.UNSTAKING:e[1]=E||0n,e[0]=E||0n;break;case T.INTERACTION.CLAIMING:e[1]=E||0n;break;case T.INTERACTION.BEEFY:t&&(e[t]=E||0n);break;case T.INTERACTION.BEEFY_STAKE:e[1]=E||0n,e[0]=E||0n;break;case T.INTERACTION.BEEFY_GET_REWARDS:e[1]=E||0n;break;case T.INTERACTION.LIDO_STAKE:e[0]=E||0n;break;case T.INTERACTION.LIDO_REQUEST:e[1]=E||0n;break;case T.INTERACTION.LIDO_CLAIM:e[1]=E||0n;break;case T.INTERACTION.PENDLE_TRANSACT:e[0]=E||0n;break;case T.INTERACTION.PENDLE_YT_IN_SWAP:e[1]=E||0n;break;case T.INTERACTION.PENDLE_YT_OUT_SWAP:e[0]=E||0n;break;case T.INTERACTION.PENDLE_PT_SWAP:e[1]=E||0n;break;case T.INTERACTION.PENDLE_MINT:e[1]=E||0n;break;case T.INTERACTION.PENDLE_REDEEM:e[2]=E||0n;break;case T.INTERACTION.PENDLE_CLAIM:e[1]=E||0n;break;case T.INTERACTION.VOLATILE_WITHDRAW:e[0]=E||0n;break;case T.INTERACTION.VOLATILE_SWAP:e[1]=E||0n;break;case T.INTERACTION.PENDLE_LP:k!==void 0&&(e[k]=E||0n);break;case T.INTERACTION.PENDLE_LP_CLAIM:e[1]=E||0n;break;case T.INTERACTION.EMPORIUM:break}return{flatFees:e,priceOfTransactionInToken:E,feeUnit:N,priceOfTransactionInUSD:b}};exports.getFlatFees=g;
|