@hinkal/common 0.1.7 → 0.1.8
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/coingecko.constants.cjs +1 -1
- package/constants/coingecko.constants.mjs +13 -14
- package/constants/vite.constants.cjs +1 -1
- package/constants/vite.constants.mjs +21 -22
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.mjs +70 -71
- package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.mjs +7 -8
- package/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
- package/data-structures/crypto-keys/encryptDecryptUtxo.mjs +34 -35
- package/data-structures/transactions-manager/TransactionsManager.cjs +1 -1
- package/data-structures/transactions-manager/TransactionsManager.mjs +27 -28
- package/functions/pre-transaction/outputUtxoProcessing.cjs +1 -1
- package/functions/pre-transaction/outputUtxoProcessing.mjs +2 -3
- package/functions/pre-transaction/processAmountChanges.cjs +1 -1
- package/functions/pre-transaction/processAmountChanges.mjs +2 -3
- package/functions/protocols/pendle.helpers.cjs +1 -1
- package/functions/protocols/pendle.helpers.mjs +10 -11
- package/functions/snarkjs/common.snarkjs.cjs +1 -1
- package/functions/snarkjs/common.snarkjs.mjs +27 -28
- package/functions/staking/index.cjs +1 -1
- package/functions/staking/index.mjs +24 -25
- package/functions/utils/process.utils.cjs +1 -1
- package/functions/utils/process.utils.mjs +2 -3
- package/functions/utils/requireEnv.cjs +1 -1
- package/functions/utils/requireEnv.mjs +4 -5
- package/functions/web3/events/balanceChangedHandler.cjs +1 -1
- package/functions/web3/events/balanceChangedHandler.mjs +3 -4
- package/functions/web3/odosAPI.cjs +1 -1
- package/functions/web3/odosAPI.mjs +8 -9
- package/functions/web3/oneInchAPI.cjs +1 -1
- package/functions/web3/oneInchAPI.mjs +2 -3
- package/functions/web3/runContractFunction.cjs +1 -1
- package/functions/web3/runContractFunction.mjs +2 -3
- package/functions/web3/uniswapAPI.cjs +1 -1
- package/functions/web3/uniswapAPI.mjs +2 -3
- package/package.json +2 -1
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.mjs +2 -4
- package/providers/prepareWagmiv1Hinkal.cjs +1 -1
- package/providers/prepareWagmiv1Hinkal.mjs +2 -4
- 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 +10 -11
- package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.mjs +2 -2
- package/webworker/utxoWorker/utxoWorkerLogic.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLogic.mjs +28 -29
- package/webworker/workerProxy.cjs +1 -1
- package/webworker/workerProxy.mjs +3 -4
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("axios");require("../../constants/coingecko.constants.cjs");const f=require("../../API/API.cjs");require("ethers");require("../../types/curve.types.cjs");const A=require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const k=require("../../functions/snarkjs/generateZkProof.cjs");require("../../types/circom-data.types.cjs");const q=require("../../types/transactions.types.cjs"),I=require("../../types/time.types.cjs"),x=require("./history/getTxDetails.cjs");require("circomlibjs");const P=require("../../error-handling/error-codes.constants.cjs"),C=require("../crypto-keys/keys.cjs"),w=require("../crypto-keys/encryptDecryptUtxo.cjs"),p=require("../../functions/utils/getDataFromTransaction.cjs"),S=require("../../functions/utils/cacheFunctions.cjs");class v{circuitSize=50;hinkalContract;init(e){this.hinkalContract=e}requireInit(){if(!this.hinkalContract)throw Error("TransactionsManager not initialized")}filterOwnTransactions=async(e,r,t,a)=>{const{transactMethodId:s,transactWithExternalActionMethodId:n,hinkalInterface:i}=A.getHinkalParameters(T.getNonLocalhostChainId(e)),c=o=>"decodedInput"in o,l=r.filter(o=>o.methodId===s||o.methodId===n).map(o=>c(o)?o:{...o,decodedInput:p.decodeTxInput(i,o.input),status:o.isError==="0"?"SUCCESS":"FAILURE"}),h=t.getShieldedPrivateKey();return l.filter(o=>{try{if(c(o)){if(w.decryptUtxo(Buffer.from(o.decodedInput.encryptedOutputs[0].slice(2),"hex"),t),!a&&o.methodId===s){const{extraRandomization:g,H0:y,H1:m}=o.decodedInput.stealthAddressStructure;return C.UserKeys.checkSignature(g,y,m,h)}return!0}return!1}catch{return!1}})};saveTxsInStorage=(e,r,t,a)=>{const s=t.getShieldedPublicKey();return S.saveTxsCache(e,r,s,this.hinkalContract.address,a)};loadTxsFromStorage=async(e,r)=>{const t=r.getShieldedPublicKey();return await S.loadTxsCache(e,t,this.hinkalContract.address)};getAllTransactions=async(e,r,t)=>{if(t){const{transactions:i}=await f.API.userGetTransactions(e,t);return i}const{decodedTxs:a,lastHash:s}=await this.loadTxsFromStorage(e,r),{transactions:n}=await f.API.userGetTransactions(e,t,s);return[...n,...a]};getHinkalHistoryBase=async(e,r,t,a=!1)=>{this.requireInit();const s=await this.getAllTransactions(e,r,t)??[];s.sort((i,c)=>c.timeStamp-i.timeStamp);const n=await this.filterOwnTransactions(e,s,r,a);return!t&&s.length>0&&await this.saveTxsInStorage(n,e,r,s[0].hash),n};getHinkalHistory=async(e,r)=>{const t=await this.getHinkalHistoryBase(e,r,void 0,!0),a=p.decodeTxLogs(e,t);return await Promise.all(a.map(async n=>({...n,status:n.status,details:await x.getTxDetails(e,n.decodedInput,n.utxosArray)})))};sortInBatches=e=>{const r=[];let t=0,a=0;e.forEach(i=>{t===0&&r.push([]),r[a].push(i),t+=1,t===this.circuitSize&&(t=0,a+=1)});const s=r[r.length-1],n=s.length;if(n<this.circuitSize){const i=this.circuitSize-n,c=new Array(i).fill(q.emptyDecodedTx);r[r.length-1]=s.concat(c)}return r};generateTransactionsProof=async(e,r,t)=>{const a=this.sortInBatches(r),s=new Array(a.length).fill([]);for(let n=0;n<a.length;n+=1){const i=a[n].map(d=>d.decodedInput.stealthAddressStructure),c=i.map(d=>d.extraRandomization),u=i.map(d=>d.stealthAddress);console.log({extraRandomizations:c,stealthAddresses:u});const l={shieldedPrivateKey:t,extraRandomizations:c,stealthAddresses:u};console.log({chainId:e,input:l});const{zkCallData:h}=await k.generateZkProof(e,"transactionsProver",l);console.log({zkCallData:h}),s[n]=h}return{zkCallDataArray:s}};userVerifyTransactions=async(e,r,t,a,s,n)=>await f.API.userVerifyTransactions(e,r,t,a,s,n);processAndSendTransactionsForVerification=async(e,r,t,a)=>{this.requireInit();const s=I.getCurrentWeek(),n=a?s-1:s;console.log("retrieving transactions in processAndSendTransactionsForVerification",{week:n});const i=await this.getHinkalHistoryBase(e,r,n);console.log("retrieved transactions",i);let c=[],u=[];i.length>0&&({zkCallDataArray:u}=await this.generateTransactionsProof(e,i,r.getShieldedPrivateKey()),c=i.map(y=>y.hash));const l=r.getBackendToken(),{trade:h,transactions:d,lockedDeposit:o,verification:g}=await this.userVerifyTransactions(e,c,u,l,t,n);return{trade:h,transactions:d,lockedDeposit:o,verification:g}};multiProcessAndSendTransactionsForVerification=async(e,r)=>{console.log("Multi Certify Starts");const t=T.chainIdsByType[T.EthereumNetworkType.Mainnet];let a=!0;for(let s=0;s<t.length;s+=1)try{const{hasCertified:n}=await f.API.verificationStartDate(t[s],r);if(console.log(`certification status for chain ${t[s]} is ${n}`),n)continue;const{trade:i,transactions:c,lockedDeposit:u,verification:l}=await this.processAndSendTransactionsForVerification(t[s],e,r,!0);if(console.log({chainId:t[s],trade:i,totalTransactions:c,lockedDeposit:u,verification:l}),a=a&&l,!a)break}catch(n){console.log(`current chain ${t[s]} certification error`,{err:n}),a=!1;break}if(!a)throw Error(P.transactionErrorCodes.MULTI_VERIFICATION_FAILED);return!0}}exports.TransactionsManager=v;
|
|
@@ -1,28 +1,27 @@
|
|
|
1
|
-
import T from "../../
|
|
2
|
-
import { getNonLocalhostChainId as y, chainIdsByType as S, EthereumNetworkType as k } from "../../constants/chains.constants.mjs";
|
|
1
|
+
import { getNonLocalhostChainId as T, chainIdsByType as y, EthereumNetworkType as S } from "../../constants/chains.constants.mjs";
|
|
3
2
|
import "../../constants/vite.constants.mjs";
|
|
4
3
|
import "axios";
|
|
5
4
|
import "../../constants/coingecko.constants.mjs";
|
|
6
5
|
import { API as m } from "../../API/API.mjs";
|
|
7
6
|
import "ethers";
|
|
8
7
|
import "../../types/curve.types.mjs";
|
|
9
|
-
import { getHinkalParameters as
|
|
8
|
+
import { getHinkalParameters as k } from "../../constants/contracts.constants.mjs";
|
|
10
9
|
import "../../constants/kyc.constants.mjs";
|
|
11
10
|
import "../../constants/axelar.constants.mjs";
|
|
12
11
|
import "../../constants/rewards.constants.mjs";
|
|
13
12
|
import "../../constants/reorg-depths.constants.mjs";
|
|
14
|
-
import { generateZkProof as
|
|
13
|
+
import { generateZkProof as A } from "../../functions/snarkjs/generateZkProof.mjs";
|
|
15
14
|
import "../../types/circom-data.types.mjs";
|
|
16
|
-
import { emptyDecodedTx as
|
|
17
|
-
import { getCurrentWeek as
|
|
18
|
-
import { getTxDetails as
|
|
15
|
+
import { emptyDecodedTx as I } from "../../types/transactions.types.mjs";
|
|
16
|
+
import { getCurrentWeek as x } from "../../types/time.types.mjs";
|
|
17
|
+
import { getTxDetails as w } from "./history/getTxDetails.mjs";
|
|
19
18
|
import "circomlibjs";
|
|
20
|
-
import { transactionErrorCodes as
|
|
21
|
-
import { UserKeys as
|
|
22
|
-
import { decryptUtxo as
|
|
23
|
-
import { decodeTxInput as
|
|
24
|
-
import { saveTxsCache as
|
|
25
|
-
class
|
|
19
|
+
import { transactionErrorCodes as C } from "../../error-handling/error-codes.constants.mjs";
|
|
20
|
+
import { UserKeys as P } from "../crypto-keys/keys.mjs";
|
|
21
|
+
import { decryptUtxo as v } from "../crypto-keys/encryptDecryptUtxo.mjs";
|
|
22
|
+
import { decodeTxInput as H, decodeTxLogs as z } from "../../functions/utils/getDataFromTransaction.mjs";
|
|
23
|
+
import { saveTxsCache as E, loadTxsCache as b } from "../../functions/utils/cacheFunctions.mjs";
|
|
24
|
+
class et {
|
|
26
25
|
circuitSize = 50;
|
|
27
26
|
hinkalContract;
|
|
28
27
|
init(r) {
|
|
@@ -33,21 +32,21 @@ class st {
|
|
|
33
32
|
throw Error("TransactionsManager not initialized");
|
|
34
33
|
}
|
|
35
34
|
filterOwnTransactions = async (r, e, t, n) => {
|
|
36
|
-
const { transactMethodId: a, transactWithExternalActionMethodId: s, hinkalInterface: i } =
|
|
37
|
-
|
|
35
|
+
const { transactMethodId: a, transactWithExternalActionMethodId: s, hinkalInterface: i } = k(
|
|
36
|
+
T(r)
|
|
38
37
|
), c = (o) => "decodedInput" in o, l = e.filter(
|
|
39
38
|
(o) => o.methodId === a || o.methodId === s
|
|
40
39
|
).map((o) => c(o) ? o : {
|
|
41
40
|
...o,
|
|
42
|
-
decodedInput:
|
|
41
|
+
decodedInput: H(i, o.input),
|
|
43
42
|
status: o.isError === "0" ? "SUCCESS" : "FAILURE"
|
|
44
43
|
}), u = t.getShieldedPrivateKey();
|
|
45
44
|
return l.filter((o) => {
|
|
46
45
|
try {
|
|
47
46
|
if (c(o)) {
|
|
48
|
-
if (
|
|
47
|
+
if (v(Buffer.from(o.decodedInput.encryptedOutputs[0].slice(2), "hex"), t), !n && o.methodId === a) {
|
|
49
48
|
const { extraRandomization: f, H0: p, H1: g } = o.decodedInput.stealthAddressStructure;
|
|
50
|
-
return
|
|
49
|
+
return P.checkSignature(f, p, g, u);
|
|
51
50
|
}
|
|
52
51
|
return !0;
|
|
53
52
|
}
|
|
@@ -59,11 +58,11 @@ class st {
|
|
|
59
58
|
};
|
|
60
59
|
saveTxsInStorage = (r, e, t, n) => {
|
|
61
60
|
const a = t.getShieldedPublicKey();
|
|
62
|
-
return
|
|
61
|
+
return E(r, e, a, this.hinkalContract.address, n);
|
|
63
62
|
};
|
|
64
63
|
loadTxsFromStorage = async (r, e) => {
|
|
65
64
|
const t = e.getShieldedPublicKey();
|
|
66
|
-
return await
|
|
65
|
+
return await b(r, t, this.hinkalContract.address);
|
|
67
66
|
};
|
|
68
67
|
getAllTransactions = async (r, e, t) => {
|
|
69
68
|
if (t) {
|
|
@@ -81,12 +80,12 @@ class st {
|
|
|
81
80
|
return !t && a.length > 0 && await this.saveTxsInStorage(s, r, e, a[0].hash), s;
|
|
82
81
|
};
|
|
83
82
|
getHinkalHistory = async (r, e) => {
|
|
84
|
-
const t = await this.getHinkalHistoryBase(r, e, void 0, !0), n =
|
|
83
|
+
const t = await this.getHinkalHistoryBase(r, e, void 0, !0), n = z(r, t);
|
|
85
84
|
return await Promise.all(
|
|
86
85
|
n.map(async (s) => ({
|
|
87
86
|
...s,
|
|
88
87
|
status: s.status,
|
|
89
|
-
details: await
|
|
88
|
+
details: await w(r, s.decodedInput, s.utxosArray)
|
|
90
89
|
}))
|
|
91
90
|
);
|
|
92
91
|
};
|
|
@@ -98,7 +97,7 @@ class st {
|
|
|
98
97
|
});
|
|
99
98
|
const a = e[e.length - 1], s = a.length;
|
|
100
99
|
if (s < this.circuitSize) {
|
|
101
|
-
const i = this.circuitSize - s, c = new Array(i).fill(
|
|
100
|
+
const i = this.circuitSize - s, c = new Array(i).fill(I);
|
|
102
101
|
e[e.length - 1] = a.concat(c);
|
|
103
102
|
}
|
|
104
103
|
return e;
|
|
@@ -116,7 +115,7 @@ class st {
|
|
|
116
115
|
stealthAddresses: d
|
|
117
116
|
};
|
|
118
117
|
console.log({ chainId: r, input: l });
|
|
119
|
-
const { zkCallData: u } = await
|
|
118
|
+
const { zkCallData: u } = await A(r, "transactionsProver", l);
|
|
120
119
|
console.log({ zkCallData: u }), a[s] = u;
|
|
121
120
|
}
|
|
122
121
|
return { zkCallDataArray: a };
|
|
@@ -131,7 +130,7 @@ class st {
|
|
|
131
130
|
);
|
|
132
131
|
processAndSendTransactionsForVerification = async (r, e, t, n) => {
|
|
133
132
|
this.requireInit();
|
|
134
|
-
const a =
|
|
133
|
+
const a = x(), s = n ? a - 1 : a;
|
|
135
134
|
console.log("retrieving transactions in processAndSendTransactionsForVerification", { week: s });
|
|
136
135
|
const i = await this.getHinkalHistoryBase(r, e, s);
|
|
137
136
|
console.log("retrieved transactions", i);
|
|
@@ -158,7 +157,7 @@ class st {
|
|
|
158
157
|
};
|
|
159
158
|
multiProcessAndSendTransactionsForVerification = async (r, e) => {
|
|
160
159
|
console.log("Multi Certify Starts");
|
|
161
|
-
const t = S
|
|
160
|
+
const t = y[S.Mainnet];
|
|
162
161
|
let n = !0;
|
|
163
162
|
for (let a = 0; a < t.length; a += 1)
|
|
164
163
|
try {
|
|
@@ -178,10 +177,10 @@ class st {
|
|
|
178
177
|
break;
|
|
179
178
|
}
|
|
180
179
|
if (!n)
|
|
181
|
-
throw Error(
|
|
180
|
+
throw Error(C.MULTI_VERIFICATION_FAILED);
|
|
182
181
|
return !0;
|
|
183
182
|
};
|
|
184
183
|
}
|
|
185
184
|
export {
|
|
186
|
-
|
|
185
|
+
et as TransactionsManager
|
|
187
186
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../data-structures/utxo/Utxo.cjs"),c=require("../../error-handling/error-codes.constants.cjs");require("ethers");require("axios");require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../../
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("../../data-structures/utxo/Utxo.cjs"),c=require("../../error-handling/error-codes.constants.cjs");require("ethers");require("axios");require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs");require("../../constants/reorg-depths.constants.cjs");const d=(o,t,e,u,i)=>{let r=0n;if(t.forEach(s=>{r+=s.amount}),e<0n&&r+e<0n)throw Error(c.transactionErrorCodes.INSUFFICIENT_FUNDS_TO_TRANSACT);return{outputUtxos:[new n.Utxo({amount:r+e,erc20TokenAddress:t[0].erc20TokenAddress,shieldedPrivateKey:o.getShieldedPrivateKey(),timeStamp:u,tokenId:i})]}};exports.outputUtxoProcessing=d;
|
|
@@ -4,13 +4,12 @@ import "ethers";
|
|
|
4
4
|
import "axios";
|
|
5
5
|
import "../../constants/chains.constants.mjs";
|
|
6
6
|
import "../../constants/vite.constants.mjs";
|
|
7
|
-
import "../../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.mjs";
|
|
8
7
|
import "../../types/circom-data.types.mjs";
|
|
9
8
|
import "../../types/transactions.types.mjs";
|
|
10
9
|
import "../../types/curve.types.mjs";
|
|
11
10
|
import "circomlibjs";
|
|
12
11
|
import "../../constants/reorg-depths.constants.mjs";
|
|
13
|
-
const
|
|
12
|
+
const S = (e, r, o, i, m) => {
|
|
14
13
|
let t = 0n;
|
|
15
14
|
if (r.forEach((p) => {
|
|
16
15
|
t += p.amount;
|
|
@@ -27,5 +26,5 @@ const F = (e, r, o, i, m) => {
|
|
|
27
26
|
] };
|
|
28
27
|
};
|
|
29
28
|
export {
|
|
30
|
-
|
|
29
|
+
S as outputUtxoProcessing
|
|
31
30
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/fees.constants.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/fees.constants.cjs"),i=require("../../error-handling/customErrors/FeeOverTransactionValueError.cjs"),y=require("../utils/amounts.utils.cjs");require("ethers");require("axios");require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");const O=require("../../types/beefy.types.cjs");require("../../types/circom-data.types.cjs");const e=require("../../types/hinkal.types.cjs"),c=require("../../types/slippage.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs");require("../../constants/reorg-depths.constants.cjs");const _=require("./interaction-to-action.cjs"),N=(t,A,r)=>{const l=y.absBigInt(t)-A;if(A<0n)throw new i.FeeOverTransactionValueError({totalFeeWEI:l,feeUnit:r});return A},F=({erc20Addresses:t=[],amountChanges:A,flatFees:r,feeUnit:I,externalActionId:l,action:p,gasTokenAddress:b})=>{const d=_.getInteractionFromAction(l,p);if(d===e.INTERACTION.NONE)throw Error("No interaction was choosen");switch(d){case e.INTERACTION.WITHDRAW:{N(A[0],T.getAmountAfterRelayAndFlatFees(A[0],r[0],!0),I);break}case e.INTERACTION.SWAP:{A[1]=N(A[1],T.getAmountAfterRelayAndFlatFeesAndSlippage(A[1],r[1],c.SlippageType.Swap),I);break}case e.INTERACTION.CURVE_DEPOSIT:{const E=A.length-1;A[E]=N(A[E],T.getAmountAfterRelayAndFlatFeesAndSlippage(A[E],r[E],c.SlippageType.CurveDeposit),I);break}case e.INTERACTION.CURVE_WITHDRAW:r.forEach((E,R)=>{E>0n?A[R]=N(A[R],T.getAmountAfterRelayAndFlatFeesAndSlippage(A[R],E,c.SlippageType.CurveWithdraw),I):E===0n&&A[R]>0n&&R!==r.length-1&&(A[R]=T.getAmountAfterSlippage(A[R],c.SlippageType.CurveWithdraw))});break;case e.INTERACTION.CURVE_WITHDRAW_INBALANCED:break;case e.INTERACTION.STAKING:A[0]=N(A[0],T.getAmountAfterRelayAndFlatFees(A[1],r[1]),I);break;case e.INTERACTION.UNSTAKING:A[1]=N(A[1],T.getAmountAfterRelayAndFlatFees(A[0],r[0]),I);break;case e.INTERACTION.CLAIMING:A[1]=N(A[1],T.getAmountAfterRelayAndFlatFees(A[1],r[1]),I);break;case e.INTERACTION.BEEFY:{const E=O.isBeefyDeposit(p)?1:0;A[E]=N(A[E],T.getAmountAfterRelayAndFlatFeesAndSlippage(A[E],r[E],c.SlippageType.Beefy),I);break}case e.INTERACTION.BEEFY_STAKE:A[0]=N(A[0],T.getAmountAfterRelayAndFlatFees(A[1],r[1]),I);break;case e.INTERACTION.BEEFY_UNSTAKE:A[1]=N(A[1],T.getAmountAfterRelayAndFlatFees(A[0],r[0]),I);break;case e.INTERACTION.BEEFY_GET_REWARDS:A[1]=N(A[1],T.getAmountAfterRelayAndFlatFees(A[1],r[1]),I);break;case e.INTERACTION.LIDO_STAKE:A[0]=N(A[0],T.getAmountAfterRelayAndFlatFees(A[0],r[0]),I);break;case e.INTERACTION.LIDO_REQUEST:N(A[1],T.getAmountAfterRelayAndFlatFees(A[1],r[1]),I);break;case e.INTERACTION.LIDO_CLAIM:A[1]=N(A[1],T.getAmountAfterRelayAndFlatFees(A[1],r[1]),I);break;case e.INTERACTION.PENDLE_TRANSACT:A[0]<0n&&N(A[0],T.getAmountAfterRelayAndFlatFees(A[0],r[0],!0),I);break;case e.INTERACTION.PENDLE_YT_IN_SWAP:A[1]=N(A[1],T.getAmountAfterRelayAndFlatFees(A[1],r[1]),I);break;case e.INTERACTION.PENDLE_YT_OUT_SWAP:break;case e.INTERACTION.PENDLE_PT_SWAP:A[1]=N(A[1],T.getAmountAfterRelayAndFlatFees(A[1],r[1]),I);break;case e.INTERACTION.PENDLE_MINT:A[1]=N(A[1],T.getAmountAfterRelayAndFlatFees(A[1],r[1]),I);break;case e.INTERACTION.PENDLE_REDEEM:A[2]=N(A[2],T.getAmountAfterRelayAndFlatFees(A[2],r[2]),I);break;case e.INTERACTION.PENDLE_CLAIM:A[1]=N(A[1],T.getAmountAfterRelayAndFlatFees(A[1],r[1]),I);break;case e.INTERACTION.PENDLE_LP:{const E=A.findIndex(R=>R>0n);A[E]=N(A[E],T.getAmountAfterRelayAndFlatFeesAndSlippage(A[E],r[E],c.SlippageType.Pendle));break}case e.INTERACTION.PENDLE_LP_CLAIM:A[1]=N(A[1],T.getAmountAfterRelayAndFlatFees(A[1],r[1]),I);break}return A};exports.processAmountChanges=F;
|
|
@@ -5,7 +5,6 @@ import "ethers";
|
|
|
5
5
|
import "axios";
|
|
6
6
|
import "../../constants/chains.constants.mjs";
|
|
7
7
|
import "../../constants/vite.constants.mjs";
|
|
8
|
-
import "../../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.mjs";
|
|
9
8
|
import { isBeefyDeposit as R } from "../../types/beefy.types.mjs";
|
|
10
9
|
import "../../types/circom-data.types.mjs";
|
|
11
10
|
import { INTERACTION as c } from "../../types/hinkal.types.mjs";
|
|
@@ -23,7 +22,7 @@ const p = (D, r, E) => {
|
|
|
23
22
|
feeUnit: E
|
|
24
23
|
});
|
|
25
24
|
return r;
|
|
26
|
-
},
|
|
25
|
+
}, Z = ({
|
|
27
26
|
erc20Addresses: D = [],
|
|
28
27
|
amountChanges: r,
|
|
29
28
|
flatFees: E,
|
|
@@ -211,5 +210,5 @@ const p = (D, r, E) => {
|
|
|
211
210
|
return r;
|
|
212
211
|
};
|
|
213
212
|
export {
|
|
214
|
-
|
|
213
|
+
Z as processAmountChanges
|
|
215
214
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");const o=require("../../constants/server.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const i=require("../utils/caseInsensitive.utils.cjs");require("../../types/circom-data.types.cjs");const s=require("../../types/hinkal.types.cjs");require("../../types/transactions.types.cjs");const n=require("../../types/pendle.types.cjs");require("../../types/curve.types.cjs");require("ethers");require("circomlibjs");require("../../data-structures/crypto-keys/keys.cjs");require("idb-keyval");require("../utils/external-action.utils.cjs");const c=require("../utils/erc20tokenFunctions.cjs");require("
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");const o=require("../../constants/server.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const i=require("../utils/caseInsensitive.utils.cjs");require("../../types/circom-data.types.cjs");const s=require("../../types/hinkal.types.cjs");require("../../types/transactions.types.cjs");const n=require("../../types/pendle.types.cjs");require("../../types/curve.types.cjs");require("ethers");require("circomlibjs");require("../../data-structures/crypto-keys/keys.cjs");require("idb-keyval");require("../utils/external-action.utils.cjs");const c=require("../utils/erc20tokenFunctions.cjs");require("../utils/convertIntegrationProviderToExternalActionId.cjs");require("axios");require("../utils/userAgent.cjs");require("../../data-structures/custom-token-registry/CustomTokenRegistry.cjs");require("../../data-structures/volatile-helper/VolatileHelper.cjs");const T=require("../utils/enum.utils.cjs");function P(e){if(!e)return;const r=c.getERC20Token(e.address,e.chainId);if(!r?.isVolatile)return r?.symbol.toLowerCase()==="weth"&&console.log("token:",r),r}function w(e,r){if(!e||!r)return;let t;switch(r){case n.PendleAssetType.YT:t=e?.yt;break;case n.PendleAssetType.PT:t=e?.pt;break;case n.PendleAssetType.PENDLE_LP:t=e?.lp;break;case n.PendleAssetType.SY:t=e?.sy;break;default:t=void 0;break}return t}const F=(e,r,t)=>{if(i.caseInsensitiveEqual(e.yt.address,t.erc20TokenAddress))return n.PendleSwapType.SwapExactTokenForYt;if(i.caseInsensitiveEqual(e.pt.address,t.erc20TokenAddress))return n.PendleSwapType.SwapExactTokenForPt;if(i.caseInsensitiveEqual(e.yt.address,r.erc20TokenAddress))return n.PendleSwapType.SwapExactYtForToken;if(i.caseInsensitiveEqual(e.pt.address,r.erc20TokenAddress))return n.PendleSwapType.SwapExactPtForToken},k=e=>{let r;switch(e){case n.PendleSwapType.SwapExactTokenForYt:r=o.API_CONFIG.ROUTES.pendleSwapExactTokenForYT;break;case n.PendleSwapType.SwapExactTokenForPt:r=o.API_CONFIG.ROUTES.pendleSwapExactTokenForPt;break;case n.PendleSwapType.SwapExactYtForToken:r=o.API_CONFIG.ROUTES.pendleSwapExactYtForToken;break;case n.PendleSwapType.SwapExactPtForToken:r=o.API_CONFIG.ROUTES.pendleSwapExactPtForToken;break;default:throw new Error("Cant determine Pendle Swap Type Api Route")}return r},q=(e,r,t,a)=>{if(!T.isInEnum(s.PendleAction,e))throw new Error("getTokenIndexForPendleFlatFee: Invalid Pendle Action");if(a)return t.findIndex(d=>d.toLowerCase()===a?.toLowerCase());const l=r.findIndex(d=>d>0n),p=r.length-1;if(r[p]<=0n)throw new Error("getTokenIndexForPendleFlatFee: Last token in amountChange is not > 0");let u=l;return(e===s.PendleAction.Mint||e===s.PendleAction.Redeem||e===s.PendleAction.PoolRemove)&&(u=l),u};exports.determinePendleSwapType=F;exports.determinePendleSwapTypeApiRoute=k;exports.erc20TokenFromPendleAsset=P;exports.getAssetTypeFromPendleMarket=w;exports.getTokenIndexForPendleFlatFee=q;
|
|
@@ -19,21 +19,20 @@ import "../../data-structures/crypto-keys/keys.mjs";
|
|
|
19
19
|
import "idb-keyval";
|
|
20
20
|
import "../utils/external-action.utils.mjs";
|
|
21
21
|
import { getERC20Token as T } from "../utils/erc20tokenFunctions.mjs";
|
|
22
|
-
import "../../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.mjs";
|
|
23
22
|
import "../utils/convertIntegrationProviderToExternalActionId.mjs";
|
|
24
23
|
import "axios";
|
|
25
24
|
import "../utils/userAgent.mjs";
|
|
26
25
|
import "../../data-structures/custom-token-registry/CustomTokenRegistry.mjs";
|
|
27
26
|
import "../../data-structures/volatile-helper/VolatileHelper.mjs";
|
|
28
27
|
import { isInEnum as w } from "../utils/enum.utils.mjs";
|
|
29
|
-
function
|
|
28
|
+
function V(e) {
|
|
30
29
|
if (!e)
|
|
31
30
|
return;
|
|
32
31
|
const r = T(e.address, e.chainId);
|
|
33
32
|
if (!r?.isVolatile)
|
|
34
33
|
return r?.symbol.toLowerCase() === "weth" && console.log("token:", r), r;
|
|
35
34
|
}
|
|
36
|
-
function
|
|
35
|
+
function j(e, r) {
|
|
37
36
|
if (!e || !r)
|
|
38
37
|
return;
|
|
39
38
|
let o;
|
|
@@ -56,7 +55,7 @@ function z(e, r) {
|
|
|
56
55
|
}
|
|
57
56
|
return o;
|
|
58
57
|
}
|
|
59
|
-
const
|
|
58
|
+
const z = (e, r, o) => {
|
|
60
59
|
if (i(e.yt.address, o.erc20TokenAddress))
|
|
61
60
|
return t.SwapExactTokenForYt;
|
|
62
61
|
if (i(e.pt.address, o.erc20TokenAddress))
|
|
@@ -65,7 +64,7 @@ const H = (e, r, o) => {
|
|
|
65
64
|
return t.SwapExactYtForToken;
|
|
66
65
|
if (i(e.pt.address, r.erc20TokenAddress))
|
|
67
66
|
return t.SwapExactPtForToken;
|
|
68
|
-
},
|
|
67
|
+
}, H = (e) => {
|
|
69
68
|
let r;
|
|
70
69
|
switch (e) {
|
|
71
70
|
case t.SwapExactTokenForYt:
|
|
@@ -84,7 +83,7 @@ const H = (e, r, o) => {
|
|
|
84
83
|
throw new Error("Cant determine Pendle Swap Type Api Route");
|
|
85
84
|
}
|
|
86
85
|
return r;
|
|
87
|
-
},
|
|
86
|
+
}, J = (e, r, o, s) => {
|
|
88
87
|
if (!w(p, e))
|
|
89
88
|
throw new Error("getTokenIndexForPendleFlatFee: Invalid Pendle Action");
|
|
90
89
|
if (s)
|
|
@@ -98,9 +97,9 @@ const H = (e, r, o) => {
|
|
|
98
97
|
return (e === p.Mint || e === p.Redeem || e === p.PoolRemove) && (c = l), c;
|
|
99
98
|
};
|
|
100
99
|
export {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
z as determinePendleSwapType,
|
|
101
|
+
H as determinePendleSwapTypeApiRoute,
|
|
102
|
+
V as erc20TokenFromPendleAsset,
|
|
103
|
+
j as getAssetTypeFromPendleMarket,
|
|
104
|
+
J as getTokenIndexForPendleFlatFee
|
|
106
105
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("ethers"),u=require("../../constants/protocol.constants.cjs"),c=require("../../data-structures/crypto-keys/keys.cjs"),h=require("../../data-structures/crypto-keys/encryptDecryptUtxo.cjs"),S=require("../../types/circom-data.types.cjs"),m=require("../utils/external-action.utils.cjs"),A=(t,e)=>t.map((r,n)=>r.map(s=>e[n]?"0":s.getNullifier())),C=(t,e)=>t.map((r,n)=>r.map(s=>e[n]?"0":s.getCommitment())),p=(t,e,r=!1)=>{const n=[];for(let s=0;s<t.length;s+=1){let l=0n,a=0n;for(let i=0;i<t[s].length;i+=1)l+=t[s][i].amount;for(let i=0;i<e[s].length;i+=1)a+=e[s][i].amount;a-l<0?r?n.push(a-l):n.push(u.CIRCOM_P+(a-l)):n.push(a-l)}return n},b=(t,e)=>{const r=[[""]];for(let n=0;n<t.length;n+=1)n>0&&r.push([""]),t[n].forEach((s,l)=>{r[n][l]=`0x${Buffer.from(h.encryptUtxo(s,e)).toString("hex")}`});return r},f=(t,e)=>{const r=[];for(let s=0;s<t.length;s+=1){r.push([]);for(let l=0;l<t[s].length;l+=1)r[s][l]=e.getSiblingHashesForVerification(BigInt(t[s][l].getCommitment())).map(a=>a.toString())}const n=[];for(let s=0;s<t.length;s+=1){n.push([]);for(let l=0;l<t[s].length;l+=1)n[s][l]=e.getSiblingSides(BigInt(t[s][l].getCommitment())).map(a=>a.toString())}return{inCommitmentSiblings:r,inCommitmentSiblingSides:n}},H=(t,e)=>{const r=e.getSiblingHashesForVerification(BigInt(t.getAccessKey())).map(s=>s.toString()),n=e.getSiblingSides(BigInt(t.getAccessKey())).map(s=>s.toString());return{accessTokenSiblings:r,accessTokenSiblingSides:n}},y=t=>{const e={...t};return e.amountChanges=t.amountChanges.map(r=>r.toString()),e.calldataHash=t.calldataHash.toString(),e.rootHashAccessToken=t.rootHashAccessToken?.toString(),e.stealthAddressStructure.extraRandomization=t.stealthAddressStructure.extraRandomization.toString(),e.stealthAddressStructure.stealthAddress=t.stealthAddressStructure.stealthAddress.toString(),e.stealthAddressStructure.H0=t.stealthAddressStructure.H0.toString(),e.stealthAddressStructure.H1=t.stealthAddressStructure.H1.toString(),e.rootHashHinkal=t.rootHashHinkal?.toString(),e.externalActionId=t.externalActionId?.toString(),e.flatFees=t.flatFees.map(r=>r.toString()),e},I=t=>{const e={...t};return e.amountChanges=t.amountChanges.map(r=>BigInt(r)),e.calldataHash=BigInt(t.calldataHash),e.rootHashAccessToken=BigInt(t.rootHashAccessToken),e.rootHashHinkal=BigInt(t.rootHashHinkal),e.externalActionId=BigInt(t.externalActionId),e},k=(t,e,r,n,s,l,a,i)=>{const d=Object.values(i||S.defaultHookData),g=o.ethers.utils.defaultAbiCoder.encode(["uint16","address","address","uint256","bytes","tuple(address, address, bytes, bytes)","bytes[][]","uint256[]"],[t,e,r,typeof n=="bigint"?n:m.getExternalActionIdHash(n),s,d,l,a]);return BigInt(o.ethers.utils.keccak256(g))%u.CIRCOM_P},B=t=>t.startsWith("swapperMO")||t.startsWith("swapperME")?2:t.startsWith("swapperMW")?1:0,O=(t,e,r,n,s,l)=>{const a=B(t);return 9+e.length+r.length+n.flat().length+s.length+a+l},T=(t,e)=>{const{h0:r,h1:n}=c.UserKeys.getStealthAddressCompressedPoints(t,e),s=BigInt(c.UserKeys.getStealthAddress(t,e));return{extraRandomization:t,H0:r,H1:n,stealthAddress:s}};exports.buildInNullifiers=A;exports.buildOutCommitments=C;exports.calcAccessTokenSiblingsAndSides=H;exports.calcAmountChanges=p;exports.calcCommitmentsSiblingAndSides=f;exports.calcEncryptedOutputs=b;exports.calcPublicSignalCount=O;exports.calcStealthAddressStructure=T;exports.createCallDataHash=k;exports.deserializeCircomData=I;exports.serializeCircomData=y;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import h from "../../node_modules/vite-plugin-node-polyfills/shims/buffer/dist/index.mjs";
|
|
2
1
|
import { ethers as i } from "ethers";
|
|
3
2
|
import { CIRCOM_P as u } from "../../constants/protocol.constants.mjs";
|
|
4
3
|
import { UserKeys as g } from "../../data-structures/crypto-keys/keys.mjs";
|
|
5
|
-
import { encryptUtxo as
|
|
6
|
-
import { defaultHookData as
|
|
7
|
-
import { getExternalActionIdHash as
|
|
8
|
-
const
|
|
4
|
+
import { encryptUtxo as h } from "../../data-structures/crypto-keys/encryptDecryptUtxo.mjs";
|
|
5
|
+
import { defaultHookData as S } from "../../types/circom-data.types.mjs";
|
|
6
|
+
import { getExternalActionIdHash as m } from "../utils/external-action.utils.mjs";
|
|
7
|
+
const k = (t, e) => t.map((r, n) => r.map((s) => e[n] ? "0" : s.getNullifier())), B = (t, e) => t.map((r, n) => r.map((s) => e[n] ? "0" : s.getCommitment())), y = (t, e, r = !1) => {
|
|
9
8
|
const n = [];
|
|
10
9
|
for (let s = 0; s < t.length; s += 1) {
|
|
11
10
|
let o = 0n, l = 0n;
|
|
@@ -16,14 +15,14 @@ const y = (t, e) => t.map((r, n) => r.map((s) => e[n] ? "0" : s.getNullifier()))
|
|
|
16
15
|
l - o < 0 ? r ? n.push(l - o) : n.push(u + (l - o)) : n.push(l - o);
|
|
17
16
|
}
|
|
18
17
|
return n;
|
|
19
|
-
},
|
|
18
|
+
}, O = (t, e) => {
|
|
20
19
|
const r = [[""]];
|
|
21
20
|
for (let n = 0; n < t.length; n += 1)
|
|
22
21
|
n > 0 && r.push([""]), t[n].forEach((s, o) => {
|
|
23
|
-
r[n][o] = `0x${
|
|
22
|
+
r[n][o] = `0x${Buffer.from(h(s, e)).toString("hex")}`;
|
|
24
23
|
});
|
|
25
24
|
return r;
|
|
26
|
-
},
|
|
25
|
+
}, T = (t, e) => {
|
|
27
26
|
const r = [];
|
|
28
27
|
for (let s = 0; s < t.length; s += 1) {
|
|
29
28
|
r.push([]);
|
|
@@ -37,17 +36,17 @@ const y = (t, e) => t.map((r, n) => r.map((s) => e[n] ? "0" : s.getNullifier()))
|
|
|
37
36
|
n[s][o] = e.getSiblingSides(BigInt(t[s][o].getCommitment())).map((l) => l.toString());
|
|
38
37
|
}
|
|
39
38
|
return { inCommitmentSiblings: r, inCommitmentSiblingSides: n };
|
|
40
|
-
},
|
|
39
|
+
}, j = (t, e) => {
|
|
41
40
|
const r = e.getSiblingHashesForVerification(BigInt(t.getAccessKey())).map((s) => s.toString()), n = e.getSiblingSides(BigInt(t.getAccessKey())).map((s) => s.toString());
|
|
42
41
|
return { accessTokenSiblings: r, accessTokenSiblingSides: n };
|
|
43
|
-
},
|
|
42
|
+
}, E = (t) => {
|
|
44
43
|
const e = { ...t };
|
|
45
44
|
return e.amountChanges = t.amountChanges.map((r) => r.toString()), e.calldataHash = t.calldataHash.toString(), e.rootHashAccessToken = t.rootHashAccessToken?.toString(), e.stealthAddressStructure.extraRandomization = t.stealthAddressStructure.extraRandomization.toString(), e.stealthAddressStructure.stealthAddress = t.stealthAddressStructure.stealthAddress.toString(), e.stealthAddressStructure.H0 = t.stealthAddressStructure.H0.toString(), e.stealthAddressStructure.H1 = t.stealthAddressStructure.H1.toString(), e.rootHashHinkal = t.rootHashHinkal?.toString(), e.externalActionId = t.externalActionId?.toString(), e.flatFees = t.flatFees.map((r) => r.toString()), e;
|
|
46
|
-
},
|
|
45
|
+
}, F = (t) => {
|
|
47
46
|
const e = { ...t };
|
|
48
47
|
return e.amountChanges = t.amountChanges.map((r) => BigInt(r)), e.calldataHash = BigInt(t.calldataHash), e.rootHashAccessToken = BigInt(t.rootHashAccessToken), e.rootHashHinkal = BigInt(t.rootHashHinkal), e.externalActionId = BigInt(t.externalActionId), e;
|
|
49
|
-
},
|
|
50
|
-
const d = Object.values(a ||
|
|
48
|
+
}, M = (t, e, r, n, s, o, l, a) => {
|
|
49
|
+
const d = Object.values(a || S), c = i.utils.defaultAbiCoder.encode(
|
|
51
50
|
[
|
|
52
51
|
"uint16",
|
|
53
52
|
"address",
|
|
@@ -62,7 +61,7 @@ const y = (t, e) => t.map((r, n) => r.map((s) => e[n] ? "0" : s.getNullifier()))
|
|
|
62
61
|
t,
|
|
63
62
|
e,
|
|
64
63
|
r,
|
|
65
|
-
typeof n == "bigint" ? n :
|
|
64
|
+
typeof n == "bigint" ? n : m(n),
|
|
66
65
|
s,
|
|
67
66
|
d,
|
|
68
67
|
o,
|
|
@@ -70,10 +69,10 @@ const y = (t, e) => t.map((r, n) => r.map((s) => e[n] ? "0" : s.getNullifier()))
|
|
|
70
69
|
]
|
|
71
70
|
);
|
|
72
71
|
return BigInt(i.utils.keccak256(c)) % u;
|
|
73
|
-
},
|
|
74
|
-
const l =
|
|
72
|
+
}, f = (t) => t.startsWith("swapperMO") || t.startsWith("swapperME") ? 2 : t.startsWith("swapperMW") ? 1 : 0, W = (t, e, r, n, s, o) => {
|
|
73
|
+
const l = f(t);
|
|
75
74
|
return 9 + e.length + r.length + n.flat().length + s.length + l + o;
|
|
76
|
-
},
|
|
75
|
+
}, w = (t, e) => {
|
|
77
76
|
const { h0: r, h1: n } = g.getStealthAddressCompressedPoints(t, e), s = BigInt(g.getStealthAddress(t, e));
|
|
78
77
|
return {
|
|
79
78
|
extraRandomization: t,
|
|
@@ -83,15 +82,15 @@ const y = (t, e) => t.map((r, n) => r.map((s) => e[n] ? "0" : s.getNullifier()))
|
|
|
83
82
|
};
|
|
84
83
|
};
|
|
85
84
|
export {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
k as buildInNullifiers,
|
|
86
|
+
B as buildOutCommitments,
|
|
87
|
+
j as calcAccessTokenSiblingsAndSides,
|
|
88
|
+
y as calcAmountChanges,
|
|
89
|
+
T as calcCommitmentsSiblingAndSides,
|
|
90
|
+
O as calcEncryptedOutputs,
|
|
91
|
+
W as calcPublicSignalCount,
|
|
92
|
+
w as calcStealthAddressStructure,
|
|
93
|
+
M as createCallDataHash,
|
|
94
|
+
F as deserializeCircomData,
|
|
95
|
+
E as serializeCircomData
|
|
97
96
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("ethers"),y=require("../../data-structures/crypto-keys/keys.cjs"),s=require("libsodium-wrappers"),c=require("../../crypto/poseidon.cjs");require("circomlibjs");const f=(e,t,r)=>{const n=o.ethers.utils.defaultAbiCoder.encode(["uint256","address"],[e,t]),a=s.crypto_box_seal(n,o.ethers.utils.arrayify(r));return`0x${Buffer.from(a).toString("hex")}`},p=(e,t)=>{const r=Buffer.from(e.slice(2),"hex"),{publicKey:n,privateKey:a}=y.UserKeys.getEncryptionKeyPair(t.getShieldedPrivateKey());try{const i=s.crypto_box_seal_open(r,o.ethers.utils.arrayify(n),o.ethers.utils.arrayify(a)),d=Buffer.from(i).toString("utf-8"),[u,l]=o.ethers.utils.defaultAbiCoder.decode(["uint256","address"],d);return{stakeBlinding:u.toBigInt(),stakedTokenRecipient:l}}catch{console.log("failed to decrypt");return}},S=(e,t,r,n,a,i)=>BigInt(c.poseidonHash(...[e,t,r,n,a,i].map(BigInt))),k=(e,t)=>c.poseidonHash(e,t),g=(e,t,r,n,a)=>o.ethers.utils.defaultAbiCoder.encode(["uint8","uint256","address","bytes","bytes"],[e,t,r,n,a]);exports.calculateStakeNullifier=k;exports.createStakeCommitment=S;exports.decryptStake=p;exports.encodeHStakeMetadata=g;exports.encryptStake=f;
|
|
@@ -1,41 +1,40 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import c from "
|
|
5
|
-
import { poseidonHash as d } from "../../crypto/poseidon.mjs";
|
|
1
|
+
import { ethers as i } from "ethers";
|
|
2
|
+
import { UserKeys as f } from "../../data-structures/crypto-keys/keys.mjs";
|
|
3
|
+
import s from "libsodium-wrappers";
|
|
4
|
+
import { poseidonHash as c } from "../../crypto/poseidon.mjs";
|
|
6
5
|
import "circomlibjs";
|
|
7
|
-
const
|
|
8
|
-
const o =
|
|
6
|
+
const S = (t, e, r) => {
|
|
7
|
+
const o = i.utils.defaultAbiCoder.encode(
|
|
9
8
|
["uint256", "address"],
|
|
10
9
|
[t, e]
|
|
11
|
-
),
|
|
12
|
-
return `0x${
|
|
13
|
-
},
|
|
14
|
-
const r =
|
|
10
|
+
), n = s.crypto_box_seal(o, i.utils.arrayify(r));
|
|
11
|
+
return `0x${Buffer.from(n).toString("hex")}`;
|
|
12
|
+
}, k = (t, e) => {
|
|
13
|
+
const r = Buffer.from(t.slice(2), "hex"), { publicKey: o, privateKey: n } = f.getEncryptionKeyPair(e.getShieldedPrivateKey());
|
|
15
14
|
try {
|
|
16
|
-
const a =
|
|
15
|
+
const a = s.crypto_box_seal_open(
|
|
17
16
|
r,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
),
|
|
17
|
+
i.utils.arrayify(o),
|
|
18
|
+
i.utils.arrayify(n)
|
|
19
|
+
), d = Buffer.from(a).toString("utf-8"), [u, y] = i.utils.defaultAbiCoder.decode(
|
|
21
20
|
["uint256", "address"],
|
|
22
|
-
|
|
21
|
+
d
|
|
23
22
|
);
|
|
24
|
-
return { stakeBlinding:
|
|
23
|
+
return { stakeBlinding: u.toBigInt(), stakedTokenRecipient: y };
|
|
25
24
|
} catch {
|
|
26
25
|
console.log("failed to decrypt");
|
|
27
26
|
return;
|
|
28
27
|
}
|
|
29
|
-
}, B = (t, e, r, o,
|
|
30
|
-
|
|
31
|
-
),
|
|
28
|
+
}, B = (t, e, r, o, n, a) => BigInt(
|
|
29
|
+
c(...[t, e, r, o, n, a].map(BigInt))
|
|
30
|
+
), h = (t, e) => c(t, e), x = (t, e, r, o, n) => i.utils.defaultAbiCoder.encode(
|
|
32
31
|
["uint8", "uint256", "address", "bytes", "bytes"],
|
|
33
|
-
[t, e, r, o,
|
|
32
|
+
[t, e, r, o, n]
|
|
34
33
|
);
|
|
35
34
|
export {
|
|
36
|
-
|
|
35
|
+
h as calculateStakeNullifier,
|
|
37
36
|
B as createStakeCommitment,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
k as decryptStake,
|
|
38
|
+
x as encodeHStakeMetadata,
|
|
39
|
+
S as encryptStake
|
|
41
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=()=>typeof process<"u"&&process?.release?.name==="node";exports.isOnServer=e;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
const n = () => typeof e < "u" && e?.release?.name === "node";
|
|
1
|
+
const e = () => typeof process < "u" && process?.release?.name === "node";
|
|
3
2
|
export {
|
|
4
|
-
|
|
3
|
+
e as isOnServer
|
|
5
4
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=e=>{const r=process.env[e];return r===void 0&&(console.log(`Error: ${e} environment variable not set`),process.exitCode=1,process.exit()),r};exports.requireEnv=o;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
return e === void 0 && (console.log(`Error: ${r} environment variable not set`), o.exitCode = 1, o.exit()), e;
|
|
1
|
+
const r = (e) => {
|
|
2
|
+
const o = process.env[e];
|
|
3
|
+
return o === void 0 && (console.log(`Error: ${e} environment variable not set`), process.exitCode = 1, process.exit()), o;
|
|
5
4
|
};
|
|
6
5
|
export {
|
|
7
|
-
|
|
6
|
+
r as requireEnv
|
|
8
7
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("../../../types/circom-data.types.cjs");const n=require("../../../types/hinkal.types.cjs");require("../../../types/transactions.types.cjs");require("../../../types/curve.types.cjs");const t=()=>{const e=n.EventType.BalanceChange;typeof document<"u"?document.dispatchEvent(new Event(e)):process?.emit("message",e,void 0)};exports.balanceChangedHandler=t;
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import t from "../../../node_modules/vite-plugin-node-polyfills/shims/process/dist/index.mjs";
|
|
2
1
|
import "../../../types/circom-data.types.mjs";
|
|
3
2
|
import { EventType as n } from "../../../types/hinkal.types.mjs";
|
|
4
3
|
import "../../../types/transactions.types.mjs";
|
|
5
4
|
import "../../../types/curve.types.mjs";
|
|
6
|
-
const
|
|
5
|
+
const i = () => {
|
|
7
6
|
const e = n.BalanceChange;
|
|
8
|
-
typeof document < "u" ? document.dispatchEvent(new Event(e)) :
|
|
7
|
+
typeof document < "u" ? document.dispatchEvent(new Event(e)) : process?.emit("message", e, void 0);
|
|
9
8
|
};
|
|
10
9
|
export {
|
|
11
|
-
|
|
10
|
+
i as balanceChangedHandler
|
|
12
11
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../../API/callOdosAPI.cjs"),n=require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../../constants/contracts.constants.cjs");require("../../constants/kyc.constants.cjs");const d=require("../../constants/protocol.constants.cjs");require("../../constants/coingecko.constants.cjs");require("../../constants/axelar.constants.cjs");require("../../constants/rewards.constants.cjs");require("../../constants/reorg-depths.constants.cjs");const a=require("../../error-handling/error-codes.constants.cjs"),q=require("./etherFunctions.cjs");require("axios");require("../../types/circom-data.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs");require("ethers");const A=async(r,e,o,u)=>{try{const t={chainId:r.getCurrentChainId()!==31337?r.getCurrentChainId():n.localhostNetwork,inputTokens:[{tokenAddress:e?.wrappedErc20TokenAddress??e.erc20TokenAddress,amount:q.getAmountInWei(e,u).toString()}],outputTokens:[{tokenAddress:o?.wrappedErc20TokenAddress??o.erc20TokenAddress,proportion:1}],userAddr:n.networkRegistry[r.getCurrentChainId()].contractData.odosExternalActionInstanceAddress||d.zeroAddress,slippageLimitPercent:10,disableRFQs:!0},{odosResponse:s,status:c}=await i.callOdosAPI(r.getCurrentChainId(),t);if(c!=="success")throw Error("Odos API Fetch Error");return{outSwapAmountValue:BigInt(s.outputTokens[0].amount),odosDataValue:s.transaction.data}}catch(t){throw console.log({error:t}),Error(a.transactionErrorCodes.NO_ODOS_PRICE)}};exports.getOdosPrice=A;
|