@hinkal/common 0.2.24 → 0.2.26
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/README.md +270 -63
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +4 -4
- package/data-structures/Hinkal/Hinkal.mjs +17 -8
- package/data-structures/Hinkal/IHinkal.d.ts +4 -4
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.d.ts +2 -2
- package/data-structures/Hinkal/hinkalDeposit.mjs +67 -65
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.d.ts +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +46 -45
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.d.ts +1 -1
- package/data-structures/Hinkal/hinkalDepositOnChainUtxos.mjs +48 -47
- package/data-structures/Hinkal/hinkalDepostAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepostAndBridge.d.ts +1 -1
- package/data-structures/Hinkal/hinkalDepostAndBridge.mjs +86 -85
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.d.ts +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +30 -29
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { zeroAddress as
|
|
1
|
+
import { zeroAddress as d } from "../../constants/protocol.constants.mjs";
|
|
2
2
|
import { transactionErrorCodes as X } from "../../error-handling/error-codes.constants.mjs";
|
|
3
3
|
import { constructEmporiumProof as tt } from "../../functions/snarkjs/constructEmporiumProof.mjs";
|
|
4
4
|
import { transactCallRelayerBatch as et } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
5
|
-
import { ExternalActionId as
|
|
5
|
+
import { ExternalActionId as U } from "../../types/external-action.types.mjs";
|
|
6
6
|
import { Utxo as N } from "../utxo/Utxo.mjs";
|
|
7
7
|
import "../../types/circom-data.types.mjs";
|
|
8
8
|
import { ContractType as ot } from "../../types/ethereum-network.types.mjs";
|
|
@@ -53,55 +53,55 @@ import "../../API/tenderly.api.mjs";
|
|
|
53
53
|
import { hinkalDepositOnChainUtxos as H } from "./hinkalDepositOnChainUtxos.mjs";
|
|
54
54
|
import { createLifiBridgeOps as B } from "../../functions/private-wallet/emporium.helpers.mjs";
|
|
55
55
|
import { safeUpdateDepositAndWithdrawStatus as _ } from "../../API/deposit-and-withdraw-status-calls.mjs";
|
|
56
|
-
const ut = async (t,
|
|
56
|
+
const ut = async (t, u, s, C, n, h, D, m) => {
|
|
57
57
|
if (s.length === 0)
|
|
58
58
|
throw new Error("No recipients to bridge");
|
|
59
|
-
const i =
|
|
60
|
-
if (!
|
|
59
|
+
const i = u.erc20TokenAddress, o = t.getCurrentChainId(), { contractData: g } = mt[o], { emporiumAddress: a } = g;
|
|
60
|
+
if (!a)
|
|
61
61
|
throw Error("No Emporium Address");
|
|
62
|
-
const
|
|
63
|
-
if (!
|
|
62
|
+
const T = O[U.Lifi][o];
|
|
63
|
+
if (!T)
|
|
64
64
|
throw new Error(`LIFI not configured for chain ${o}`);
|
|
65
|
-
const
|
|
66
|
-
if (!
|
|
65
|
+
const I = await t.getRandomRelay();
|
|
66
|
+
if (!I)
|
|
67
67
|
throw Error(X.RELAYER_NOT_AVAILABLE);
|
|
68
|
-
const
|
|
69
|
-
for (let
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
await dt.addTemporaryWalletNonce(o,
|
|
73
|
-
const q =
|
|
68
|
+
const w = await t.getEthereumAddress(), E = it().toString(), f = t.generateProofRemotely ? 5 : 1, v = [];
|
|
69
|
+
for (let p = 0; p < s.length; p += f) {
|
|
70
|
+
const R = s.slice(p, p + f), x = await Promise.all(
|
|
71
|
+
R.map(async ({ utxo: e, nativeUtxo: r, bridgeAmount: A, quote: c, temporarySubAccount: F }) => {
|
|
72
|
+
await dt.addTemporaryWalletNonce(o, n, F.index);
|
|
73
|
+
const q = c.nativeFee > 0n && !z(i, d), l = [i], k = [-e.amount], P = [!1], L = new N({
|
|
74
74
|
amount: 0n,
|
|
75
75
|
erc20TokenAddress: i,
|
|
76
76
|
shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
|
|
77
|
-
timeStamp:
|
|
77
|
+
timeStamp: E,
|
|
78
78
|
tokenId: 0
|
|
79
|
-
}),
|
|
80
|
-
if (q &&
|
|
79
|
+
}), S = [[e, L]], b = [[L]];
|
|
80
|
+
if (q && r) {
|
|
81
81
|
const K = new N({
|
|
82
82
|
amount: 0n,
|
|
83
|
-
erc20TokenAddress:
|
|
83
|
+
erc20TokenAddress: d,
|
|
84
84
|
shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
|
|
85
|
-
timeStamp:
|
|
85
|
+
timeStamp: E,
|
|
86
86
|
tokenId: 0
|
|
87
87
|
});
|
|
88
|
-
|
|
88
|
+
l.push(d), k.push(-r.amount), P.push(!1), S.push([r, K]), b.push([K]);
|
|
89
89
|
}
|
|
90
90
|
const M = B(
|
|
91
91
|
t,
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
F.ethAddress,
|
|
93
|
+
T,
|
|
94
94
|
i,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
e.amount,
|
|
96
|
+
A,
|
|
97
|
+
c
|
|
98
98
|
), { patchAccessTokenMerkleTree: V, kycRequired: Y, hasAccessToken: Z } = await st(
|
|
99
99
|
t,
|
|
100
|
-
|
|
100
|
+
l,
|
|
101
101
|
k
|
|
102
102
|
), $ = await rt(
|
|
103
103
|
o,
|
|
104
|
-
|
|
104
|
+
w,
|
|
105
105
|
t.userKeys,
|
|
106
106
|
Y,
|
|
107
107
|
Z
|
|
@@ -109,25 +109,25 @@ const ut = async (t, f, s, R, a, T, c, d) => {
|
|
|
109
109
|
"v1x1",
|
|
110
110
|
t.merkleTreeHinkal,
|
|
111
111
|
t.merkleTreeAccessToken,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
l,
|
|
113
|
+
l.map(() => 0),
|
|
114
|
+
S,
|
|
115
115
|
b,
|
|
116
116
|
t.userKeys,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
l.length,
|
|
118
|
+
S[0].length,
|
|
119
|
+
a,
|
|
120
120
|
M,
|
|
121
121
|
t.generateProofRemotely,
|
|
122
|
-
|
|
122
|
+
I ?? d,
|
|
123
123
|
o,
|
|
124
124
|
P,
|
|
125
125
|
void 0,
|
|
126
|
-
|
|
126
|
+
F.privateKey,
|
|
127
127
|
void 0,
|
|
128
128
|
V,
|
|
129
129
|
void 0,
|
|
130
|
-
|
|
130
|
+
C,
|
|
131
131
|
t.getContractWithFetcher(ot.HinkalHelperContract),
|
|
132
132
|
$,
|
|
133
133
|
void 0,
|
|
@@ -136,93 +136,94 @@ const ut = async (t, f, s, R, a, T, c, d) => {
|
|
|
136
136
|
return { zkCallData: j, dimData: J, circomData: G, authorizationData: Q };
|
|
137
137
|
})
|
|
138
138
|
);
|
|
139
|
-
v.push(...
|
|
139
|
+
v.push(...x);
|
|
140
140
|
}
|
|
141
141
|
await _(o, {
|
|
142
|
-
id:
|
|
143
|
-
hashedEthereumAddress:
|
|
142
|
+
id: h,
|
|
143
|
+
hashedEthereumAddress: n,
|
|
144
144
|
phase: W.BEFORE_SCHEDULE_WITHDRAW
|
|
145
145
|
});
|
|
146
146
|
const y = await et(
|
|
147
147
|
o,
|
|
148
148
|
v,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
149
|
+
n,
|
|
150
|
+
D,
|
|
151
|
+
m
|
|
152
152
|
);
|
|
153
153
|
return await _(o, {
|
|
154
|
-
id:
|
|
155
|
-
hashedEthereumAddress:
|
|
154
|
+
id: h,
|
|
155
|
+
hashedEthereumAddress: n,
|
|
156
156
|
phase: W.AFTER_SCHEDULE_WITHDRAW,
|
|
157
157
|
scheduleId: y
|
|
158
158
|
}), y;
|
|
159
|
-
}, Ae = async (t,
|
|
160
|
-
const
|
|
161
|
-
if (!
|
|
159
|
+
}, Ae = async (t, u, s, C, n, h, D = !0) => {
|
|
160
|
+
const m = u.erc20TokenAddress, i = t.getCurrentChainId(), o = nt(await t.getEthereumAddress()), g = O[U.Lifi][i];
|
|
161
|
+
if (!g)
|
|
162
162
|
throw Error("LIFI router not configured");
|
|
163
|
-
let
|
|
164
|
-
if (
|
|
165
|
-
|
|
163
|
+
let a;
|
|
164
|
+
if (n)
|
|
165
|
+
a = n;
|
|
166
166
|
else {
|
|
167
|
-
const e = s[0],
|
|
167
|
+
const e = s[0], A = B(
|
|
168
168
|
t,
|
|
169
169
|
e.temporarySubAccount.ethAddress,
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
g,
|
|
171
|
+
m,
|
|
172
172
|
e.bridgeAmount,
|
|
173
173
|
e.bridgeAmount,
|
|
174
174
|
e.quote
|
|
175
175
|
).map(
|
|
176
|
-
(
|
|
176
|
+
(c) => ct(c, e.temporarySubAccount.ethAddress, i)
|
|
177
177
|
);
|
|
178
|
-
|
|
178
|
+
a = await at(i, m, [m], U.Emporium, A);
|
|
179
179
|
}
|
|
180
|
-
const
|
|
181
|
-
feeToken:
|
|
180
|
+
const T = {
|
|
181
|
+
feeToken: a.feeToken,
|
|
182
182
|
flatFee: 0n,
|
|
183
183
|
variableRate: 0n
|
|
184
|
-
},
|
|
185
|
-
userDepositedUtxos:
|
|
186
|
-
statusId:
|
|
187
|
-
depositTxHash:
|
|
184
|
+
}, w = s.reduce((e, r) => e + r.quote.nativeFee, 0n) > 0n && !z(m, d), E = s.map((e) => e.bridgeAmount), f = s.map((e) => e.recipientAddress), {
|
|
185
|
+
userDepositedUtxos: v,
|
|
186
|
+
statusId: y,
|
|
187
|
+
depositTxHash: p
|
|
188
188
|
} = await H(
|
|
189
189
|
t,
|
|
190
|
+
u,
|
|
191
|
+
E,
|
|
190
192
|
f,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
n,
|
|
194
|
-
i
|
|
193
|
+
a,
|
|
194
|
+
o
|
|
195
195
|
);
|
|
196
|
-
let
|
|
197
|
-
if (
|
|
198
|
-
const e = pt(
|
|
196
|
+
let R = [];
|
|
197
|
+
if (w) {
|
|
198
|
+
const e = pt(d, i);
|
|
199
199
|
if (!e)
|
|
200
200
|
throw Error("No native token");
|
|
201
|
-
const r = s.map((
|
|
201
|
+
const r = s.map((c) => c.quote.nativeFee), { userDepositedUtxos: A } = await H(
|
|
202
202
|
t,
|
|
203
203
|
e,
|
|
204
204
|
r,
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
205
|
+
f,
|
|
206
|
+
T,
|
|
207
|
+
o,
|
|
208
|
+
D
|
|
208
209
|
);
|
|
209
|
-
|
|
210
|
+
R = A;
|
|
210
211
|
}
|
|
211
|
-
const
|
|
212
|
+
const x = s.map((e, r) => ({
|
|
212
213
|
...e,
|
|
213
|
-
utxo:
|
|
214
|
-
nativeUtxo:
|
|
214
|
+
utxo: v[r].utxo,
|
|
215
|
+
nativeUtxo: w ? R[r]?.utxo : void 0
|
|
215
216
|
}));
|
|
216
217
|
return await ut(
|
|
217
218
|
t,
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
),
|
|
219
|
+
u,
|
|
220
|
+
x,
|
|
221
|
+
a,
|
|
222
|
+
o,
|
|
223
|
+
y,
|
|
224
|
+
C,
|
|
225
|
+
h
|
|
226
|
+
), p;
|
|
226
227
|
};
|
|
227
228
|
export {
|
|
228
229
|
Ae as hinkalDepositAndBridge
|
|
@@ -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("ethers"),f=require("../../../constants/protocol.constants.cjs"),S=require("../../../types/ethereum-network.types.cjs"),F=require("../../utils/time.utils.cjs"),N=require("./approveTokensToHinkal.cjs"),_=require("./constructBatchCall.cjs"),z=require("./recoverTransactionFromError.cjs"),G=require("../../utils/getContractAddress.cjs"),L=async(r,d,l,s,p,A,q,x,b=!0)=>{const n=Array.isArray(d)?d:[d],e=Array.isArray(l)?l:[l];if(n.length!==e.length)throw new Error("token and amount length mismatch");const w=r.getContractWithSigner(S.ContractType.HinkalContract),k=await r.getEthereumAddress(),v=q??w,a=x??w,m="transact",C=e.findIndex(({erc20TokenAddress:t})=>t===f.zeroAddress),H=e.some(({erc20TokenAddress:t})=>t!==f.zeroAddress),h=C===-1?0n:n[C],u=r.getProviderAdapter();if(H&&await u.supportsBatchCall?.()&&u.sendBatchCallsTransaction){const t=e.map(E=>E.erc20TokenAddress),i=await _.buildApproveAndTransactCalls(t,n,G.getContractAddress(v),a,s,A,p,h);return await u.sendBatchCallsTransaction(i)}await N.approveTokensToHinkal(r,v,e,n);const T={value:h>0n?BigInt(h).toString():void 0};let o;const y=[s[0],s[1],s[2],A,p,{...T,from:k}],{runner:c}=a;if(!(c instanceof I.ethers.AbstractSigner))throw new Error("expected signer");if(b)try{o=Number(await a[m].estimateGas(...y)),console.log({gasCosts:o}),console.log({signerAddress:await c.getAddress(),chainIdHinkal:r.getCurrentChainId(),ethersNetwork:await c.provider.getNetwork()})}catch(t){console.log("hinkalDeposit: gas estimation error",{err:t})}const B=o&&o>=0?Math.ceil(o*12/10):void 0;T.gasLimit=B,await F.waitLittle();let g;try{g=await a[m](...y)}catch(t){if(!t?.transactionHash)throw t;const i=await z.recoverTransactionFromError(c.provider,t.transactionHash);if(!i)throw t;g=i}return g};exports.transactCallDirect=L;
|
|
@@ -3,4 +3,4 @@ import { IHinkal } from '../../../data-structures/Hinkal/IHinkal';
|
|
|
3
3
|
import { CircomDataBaseType, DimDataType } from '../../../types/circom-data.types';
|
|
4
4
|
import { ERC20Token } from '../../../types/token.types';
|
|
5
5
|
import { NewZkCallDataType } from '../../../types/snark.types';
|
|
6
|
-
export declare const transactCallDirect: (hinkal: IHinkal, amount: bigint | bigint[], tokenToApprove: ERC20Token | ERC20Token[], newZkCallData: NewZkCallDataType, circomData: CircomDataBaseType, dimData: DimDataType, contractApproval?: ethers.Contract, contractTransaction?: ethers.Contract) => Promise<any>;
|
|
6
|
+
export declare const transactCallDirect: (hinkal: IHinkal, amount: bigint | bigint[], tokenToApprove: ERC20Token | ERC20Token[], newZkCallData: NewZkCallDataType, circomData: CircomDataBaseType, dimData: DimDataType, contractApproval?: ethers.Contract, contractTransaction?: ethers.Contract, preEstimateGas?: boolean) => Promise<any>;
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { ethers as
|
|
1
|
+
import { ethers as F } from "ethers";
|
|
2
2
|
import { zeroAddress as T } from "../../../constants/protocol.constants.mjs";
|
|
3
|
-
import { ContractType as
|
|
4
|
-
import { waitLittle as
|
|
5
|
-
import { approveTokensToHinkal as
|
|
6
|
-
import { buildApproveAndTransactCalls as
|
|
7
|
-
import { recoverTransactionFromError as
|
|
8
|
-
import { getContractAddress as
|
|
9
|
-
const
|
|
3
|
+
import { ContractType as N } from "../../../types/ethereum-network.types.mjs";
|
|
4
|
+
import { waitLittle as S } from "../../utils/time.utils.mjs";
|
|
5
|
+
import { approveTokensToHinkal as G } from "./approveTokensToHinkal.mjs";
|
|
6
|
+
import { buildApproveAndTransactCalls as L } from "./constructBatchCall.mjs";
|
|
7
|
+
import { recoverTransactionFromError as z } from "./recoverTransactionFromError.mjs";
|
|
8
|
+
import { getContractAddress as M } from "../../utils/getContractAddress.mjs";
|
|
9
|
+
const U = async (r, d, m, s, g, A, y, H, I = !0) => {
|
|
10
10
|
const n = Array.isArray(d) ? d : [d], o = Array.isArray(m) ? m : [m];
|
|
11
11
|
if (n.length !== o.length)
|
|
12
12
|
throw new Error("token and amount length mismatch");
|
|
13
|
-
const
|
|
14
|
-
if (
|
|
15
|
-
const t = o.map((
|
|
13
|
+
const f = r.getContractWithSigner(N.HinkalContract), b = await r.getEthereumAddress(), w = y ?? f, a = H ?? f, v = "transact", u = o.findIndex(({ erc20TokenAddress: t }) => t === T), B = o.some(({ erc20TokenAddress: t }) => t !== T), l = u === -1 ? 0n : n[u], p = r.getProviderAdapter();
|
|
14
|
+
if (B && await p.supportsBatchCall?.() && p.sendBatchCallsTransaction) {
|
|
15
|
+
const t = o.map((k) => k.erc20TokenAddress), c = await L(
|
|
16
16
|
t,
|
|
17
17
|
n,
|
|
18
|
-
|
|
18
|
+
M(w),
|
|
19
19
|
a,
|
|
20
20
|
s,
|
|
21
21
|
A,
|
|
@@ -24,8 +24,8 @@ const R = async (r, d, m, s, g, A, y, H) => {
|
|
|
24
24
|
);
|
|
25
25
|
return await p.sendBatchCallsTransaction(c);
|
|
26
26
|
}
|
|
27
|
-
await
|
|
28
|
-
const
|
|
27
|
+
await G(r, w, o, n);
|
|
28
|
+
const C = {
|
|
29
29
|
value: l > 0n ? BigInt(l).toString() : void 0
|
|
30
30
|
};
|
|
31
31
|
let e;
|
|
@@ -35,28 +35,29 @@ const R = async (r, d, m, s, g, A, y, H) => {
|
|
|
35
35
|
s[2],
|
|
36
36
|
A,
|
|
37
37
|
g,
|
|
38
|
-
{ ...
|
|
38
|
+
{ ...C, from: b }
|
|
39
39
|
], { runner: i } = a;
|
|
40
|
-
if (!(i instanceof
|
|
40
|
+
if (!(i instanceof F.AbstractSigner))
|
|
41
41
|
throw new Error("expected signer");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
42
|
+
if (I)
|
|
43
|
+
try {
|
|
44
|
+
e = Number(await a[v].estimateGas(...x)), console.log({ gasCosts: e }), console.log({
|
|
45
|
+
signerAddress: await i.getAddress(),
|
|
46
|
+
chainIdHinkal: r.getCurrentChainId(),
|
|
47
|
+
ethersNetwork: await i.provider.getNetwork()
|
|
48
|
+
});
|
|
49
|
+
} catch (t) {
|
|
50
|
+
console.log("hinkalDeposit: gas estimation error", { err: t });
|
|
51
|
+
}
|
|
52
|
+
const E = e && e >= 0 ? Math.ceil(e * 12 / 10) : void 0;
|
|
53
|
+
C.gasLimit = E, await S();
|
|
53
54
|
let h;
|
|
54
55
|
try {
|
|
55
56
|
h = await a[v](...x);
|
|
56
57
|
} catch (t) {
|
|
57
58
|
if (!t?.transactionHash)
|
|
58
59
|
throw t;
|
|
59
|
-
const c = await
|
|
60
|
+
const c = await z(i.provider, t.transactionHash);
|
|
60
61
|
if (!c)
|
|
61
62
|
throw t;
|
|
62
63
|
h = c;
|
|
@@ -64,5 +65,5 @@ const R = async (r, d, m, s, g, A, y, H) => {
|
|
|
64
65
|
return h;
|
|
65
66
|
};
|
|
66
67
|
export {
|
|
67
|
-
|
|
68
|
+
U as transactCallDirect
|
|
68
69
|
};
|