@hinkal/common 0.2.17 → 0.2.18
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/API/getWebsiteURL.d.ts +1 -1
- package/README.md +9 -2
- package/constants/chains.constants.cjs +1 -1
- package/constants/chains.constants.mjs +2 -2
- package/constants/mediaUrls.constants.cjs +1 -1
- package/constants/mediaUrls.constants.d.ts +2 -0
- package/constants/mediaUrls.constants.mjs +3 -1
- package/constants/vite.constants.cjs +1 -1
- package/constants/vite.constants.mjs +36 -13
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +1 -1
- package/data-structures/Hinkal/Hinkal.mjs +2 -2
- package/data-structures/Hinkal/IHinkal.d.ts +1 -1
- package/data-structures/Hinkal/hinkalApprove.d.ts +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +136 -118
- package/data-structures/Hinkal/hinkalInsideTransact.d.ts +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.d.ts +1 -1
- package/data-structures/Hinkal/hinkalProxyToPrivate.d.ts +1 -1
- package/data-structures/Hinkal/hinkalSolanaSwap.d.ts +1 -1
- package/data-structures/Hinkal/hinkalSolanaTransfer.d.ts +1 -1
- package/data-structures/Hinkal/hinkalSolanaWithdraw.d.ts +1 -1
- package/data-structures/Hinkal/hinkalSwap.d.ts +1 -1
- package/data-structures/Hinkal/hinkalTransfer.d.ts +1 -1
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.d.ts +2 -2
- package/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +59 -58
- package/error-handling/error-codes.constants.cjs +1 -1
- package/error-handling/error-codes.constants.d.ts +2 -0
- package/error-handling/error-codes.constants.mjs +3 -1
- package/functions/snarkjs/constructEmporiumProof.d.ts +2 -2
- package/functions/snarkjs/constructGeneralZkProof.d.ts +2 -2
- package/functions/snarkjs/generateCircomData.d.ts +1 -1
- package/functions/utils/enum.utils.cjs +1 -0
- package/functions/utils/enum.utils.mjs +14 -0
- package/functions/utils/getDataFromTransaction.d.ts +3 -3
- package/functions/web3/events/getInputUtxosEnclave.d.ts +1 -1
- package/functions/web3/functionCalls/approveToken.cjs +1 -1
- package/functions/web3/functionCalls/approveToken.mjs +51 -47
- package/functions/web3/functionCalls/recoverTransactionFromError.cjs +1 -0
- package/functions/web3/functionCalls/recoverTransactionFromError.d.ts +2 -0
- package/functions/web3/functionCalls/recoverTransactionFromError.mjs +23 -0
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +45 -32
- package/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/functions/web3/functionCalls/transactCallRelayer.mjs +23 -22
- package/index.cjs +1 -1
- package/index.mjs +116 -115
- package/package.json +2 -2
- package/types/admin.types.cjs +1 -1
- package/types/admin.types.d.ts +3 -1
- package/types/admin.types.mjs +1 -1
- package/types/solana.types.d.ts +2 -0
- package/types/transactions.types.cjs +1 -1
- package/types/transactions.types.d.ts +4 -0
- package/types/transactions.types.mjs +5 -4
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.mjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.mjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +2 -2
|
@@ -1,188 +1,206 @@
|
|
|
1
|
-
import { ethers as
|
|
2
|
-
import { zeroAddress as
|
|
3
|
-
import { transactionErrorCodes as
|
|
4
|
-
import { outputUtxoProcessing as
|
|
5
|
-
import { constructZkProof as
|
|
6
|
-
import { addPaddingToUtxos as
|
|
7
|
-
import { transactCallDirect as
|
|
8
|
-
import { transactCallRelayerBatch as
|
|
9
|
-
import { ExternalActionId as
|
|
10
|
-
import { Utxo as
|
|
1
|
+
import { ethers as _ } from "ethers";
|
|
2
|
+
import { zeroAddress as W } from "../../constants/protocol.constants.mjs";
|
|
3
|
+
import { transactionErrorCodes as V } from "../../error-handling/error-codes.constants.mjs";
|
|
4
|
+
import { outputUtxoProcessing as X } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
5
|
+
import { constructZkProof as F } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
6
|
+
import { addPaddingToUtxos as Y } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
7
|
+
import { transactCallDirect as j } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
|
|
8
|
+
import { transactCallRelayerBatch as G } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
9
|
+
import { ExternalActionId as z } from "../../types/external-action.types.mjs";
|
|
10
|
+
import { Utxo as J } from "../utxo/Utxo.mjs";
|
|
11
11
|
import "../../types/circom-data.types.mjs";
|
|
12
|
-
import { ContractType as
|
|
12
|
+
import { ContractType as I } from "../../types/ethereum-network.types.mjs";
|
|
13
13
|
import "../../types/transactions.types.mjs";
|
|
14
|
+
import { AdminTransactionType as k } from "../../types/admin.types.mjs";
|
|
14
15
|
import "../../types/activities.types.mjs";
|
|
15
|
-
import { getSignatureDataForTransact as
|
|
16
|
-
import { shouldPatchAccessTokenMerkleTree as
|
|
17
|
-
import { getCurrentTimeInSeconds as
|
|
18
|
-
import { getUtxosFromReceipt as
|
|
19
|
-
import { getFeeStructure as
|
|
20
|
-
import { calculateTotalFee as
|
|
21
|
-
import { storeUnspentUtxos as
|
|
22
|
-
import { hashEthereumAddress as
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
import { getSignatureDataForTransact as $ } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
|
|
17
|
+
import { shouldPatchAccessTokenMerkleTree as q } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
|
|
18
|
+
import { getCurrentTimeInSeconds as Q } from "../../functions/utils/time.utils.mjs";
|
|
19
|
+
import { getUtxosFromReceipt as tt } from "../../functions/utils/getUtxosFromReceipt.utils.mjs";
|
|
20
|
+
import { getFeeStructure as et } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
21
|
+
import { calculateTotalFee as ot } from "../../functions/utils/fees.utils.mjs";
|
|
22
|
+
import { storeUnspentUtxos as rt } from "../../API/unspent-utxos-calls.mjs";
|
|
23
|
+
import { hashEthereumAddress as st } from "../../functions/utils/addresses.mjs";
|
|
24
|
+
import { constructAdminData as B } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
25
|
+
import { emitTxPublicData as at } from "../../API/admin-calls.mjs";
|
|
26
|
+
const nt = async (t, s, c, p, A, w) => {
|
|
27
|
+
const o = s.erc20TokenAddress, d = await t.getEthereumAddress(), r = c.map((e) => e + ot(e, A)), a = [o], n = [0n], g = [!0], { patchAccessTokenMerkleTree: m, kycRequired: E, hasAccessToken: R } = await q(
|
|
25
28
|
t,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
),
|
|
29
|
+
a,
|
|
30
|
+
n
|
|
31
|
+
), P = await $(
|
|
29
32
|
t.getCurrentChainId(),
|
|
30
|
-
await t.getEthereumAddress(),
|
|
31
|
-
t.userKeys,
|
|
32
33
|
d,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
t.userKeys,
|
|
35
|
+
E,
|
|
36
|
+
R
|
|
37
|
+
), i = [...await Y(t, a, n)], l = [];
|
|
38
|
+
for (let e = 0; e < i.length; e += 1) {
|
|
39
|
+
const { outputUtxos: f } = X(t.userKeys, i[e], n[e]);
|
|
40
|
+
l.push(f);
|
|
38
41
|
}
|
|
39
|
-
const
|
|
40
|
-
zkCallData:
|
|
41
|
-
circomData:
|
|
42
|
-
dimData:
|
|
43
|
-
} = await
|
|
42
|
+
const h = r.reduce((e, f) => e + f, 0n), T = _.utils.defaultAbiCoder.encode(["uint256[]"], [r]), y = t.getContractWithSigner(I.HinkalWrapper), D = t.getContractWithSigner(I.DepositOnChainUtxos), {
|
|
43
|
+
zkCallData: x,
|
|
44
|
+
circomData: S,
|
|
45
|
+
dimData: O
|
|
46
|
+
} = await F(
|
|
44
47
|
"v1x1",
|
|
45
48
|
t.merkleTreeHinkal,
|
|
46
49
|
t.merkleTreeAccessToken,
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
i,
|
|
51
|
+
l,
|
|
49
52
|
t.userKeys,
|
|
50
|
-
`swapperM1x${
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
`swapperM1x${i[0].length}x1`,
|
|
54
|
+
z.DepositOnChainUtxos,
|
|
55
|
+
D.address,
|
|
56
|
+
T,
|
|
54
57
|
t.generateProofRemotely,
|
|
55
|
-
|
|
58
|
+
W,
|
|
56
59
|
t.getCurrentChainId(),
|
|
57
|
-
|
|
60
|
+
g,
|
|
58
61
|
void 0,
|
|
59
62
|
void 0,
|
|
60
63
|
void 0,
|
|
61
|
-
|
|
64
|
+
m,
|
|
62
65
|
void 0,
|
|
63
66
|
void 0,
|
|
64
67
|
void 0,
|
|
65
|
-
t.getContractWithFetcher(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
t.getContractWithFetcher(I.HinkalHelperContract),
|
|
69
|
+
P,
|
|
70
|
+
y.address,
|
|
68
71
|
!1
|
|
69
|
-
), K = await (await
|
|
72
|
+
), K = await (await j(
|
|
70
73
|
t,
|
|
71
|
-
R,
|
|
72
|
-
o,
|
|
73
|
-
S,
|
|
74
74
|
h,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
s,
|
|
76
|
+
x,
|
|
77
|
+
S,
|
|
78
|
+
O,
|
|
79
|
+
D,
|
|
80
|
+
y
|
|
81
|
+
)).wait(), U = tt(K, t, o), v = [], C = [...U];
|
|
82
|
+
p.forEach((e, f) => {
|
|
83
|
+
const M = r[f], b = C.find((Z) => Z.amount === M);
|
|
84
|
+
if (!b)
|
|
85
|
+
throw new Error(`Could not find newly created UTXO with amount ${M} for recipient ${e}.`);
|
|
86
|
+
v.push({
|
|
84
87
|
recipientAddress: e,
|
|
85
|
-
utxo:
|
|
88
|
+
utxo: b
|
|
86
89
|
});
|
|
87
|
-
const
|
|
88
|
-
C.splice(
|
|
90
|
+
const N = C.indexOf(b);
|
|
91
|
+
C.splice(N, 1);
|
|
89
92
|
});
|
|
90
|
-
const
|
|
91
|
-
|
|
93
|
+
const u = t.getCurrentChainId();
|
|
94
|
+
await rt(u, {
|
|
92
95
|
hashedEthereumAddress: w,
|
|
93
|
-
chainId:
|
|
94
|
-
utxos:
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
|
|
96
|
+
chainId: u,
|
|
97
|
+
utxos: U
|
|
98
|
+
});
|
|
99
|
+
const L = B(
|
|
100
|
+
k.DepositOnChainUtxos,
|
|
101
|
+
u,
|
|
102
|
+
a,
|
|
103
|
+
[h],
|
|
104
|
+
d
|
|
105
|
+
);
|
|
106
|
+
return at(u, L), v;
|
|
107
|
+
}, it = async (t, s, c, p, A, w) => {
|
|
108
|
+
if (c.length === 0)
|
|
98
109
|
throw new Error("userDepositedUtxos must not be empty");
|
|
99
|
-
const
|
|
100
|
-
if (!
|
|
101
|
-
throw Error(
|
|
102
|
-
const
|
|
103
|
-
for (let
|
|
104
|
-
const E =
|
|
105
|
-
E.map(async ({ recipientAddress:
|
|
106
|
-
const
|
|
110
|
+
const o = s.erc20TokenAddress, d = await t.getRandomRelay();
|
|
111
|
+
if (!d)
|
|
112
|
+
throw Error(V.RELAYER_NOT_AVAILABLE);
|
|
113
|
+
const r = await t.getEthereumAddress(), a = Q().toString(), n = t.generateProofRemotely ? 5 : 1, g = [];
|
|
114
|
+
for (let m = 0; m < c.length; m += n) {
|
|
115
|
+
const E = c.slice(m, m + n), R = await Promise.all(
|
|
116
|
+
E.map(async ({ recipientAddress: P, utxo: i }) => {
|
|
117
|
+
const l = [-i.amount], h = new J({
|
|
107
118
|
amount: 0n,
|
|
108
|
-
erc20TokenAddress:
|
|
119
|
+
erc20TokenAddress: o,
|
|
109
120
|
shieldedPrivateKey: t.userKeys.getShieldedPrivateKey(),
|
|
110
121
|
timeStamp: a,
|
|
111
122
|
tokenId: 0
|
|
112
|
-
}),
|
|
123
|
+
}), T = [[i, h]], y = [[h]], D = `swapperM1x${T[0].length}x1`, x = {
|
|
113
124
|
externalActionId: 0n,
|
|
114
|
-
externalAddress:
|
|
125
|
+
externalAddress: P,
|
|
115
126
|
externalActionMetadata: "0x00"
|
|
116
127
|
}, {
|
|
117
|
-
patchAccessTokenMerkleTree:
|
|
118
|
-
kycRequired:
|
|
119
|
-
hasAccessToken:
|
|
120
|
-
} = await
|
|
128
|
+
patchAccessTokenMerkleTree: S,
|
|
129
|
+
kycRequired: O,
|
|
130
|
+
hasAccessToken: H
|
|
131
|
+
} = await q(t, [o], l), K = await $(
|
|
121
132
|
t.getCurrentChainId(),
|
|
122
|
-
|
|
133
|
+
r,
|
|
123
134
|
t.userKeys,
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
),
|
|
135
|
+
O,
|
|
136
|
+
H
|
|
137
|
+
), U = B(
|
|
138
|
+
k.WithdrawOnChainUtxos,
|
|
139
|
+
t.getCurrentChainId(),
|
|
140
|
+
[o],
|
|
141
|
+
[-i.amount],
|
|
142
|
+
r
|
|
143
|
+
), { zkCallData: v, circomData: C, dimData: u } = await F(
|
|
127
144
|
"v1x1",
|
|
128
145
|
t.merkleTreeHinkal,
|
|
129
146
|
t.merkleTreeAccessToken,
|
|
130
|
-
x,
|
|
131
147
|
T,
|
|
148
|
+
y,
|
|
132
149
|
t.userKeys,
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
150
|
+
D,
|
|
151
|
+
x.externalActionId,
|
|
152
|
+
x.externalAddress,
|
|
153
|
+
x.externalActionMetadata,
|
|
137
154
|
t.generateProofRemotely,
|
|
138
|
-
|
|
155
|
+
d ?? W,
|
|
139
156
|
t.getCurrentChainId(),
|
|
140
157
|
void 0,
|
|
141
158
|
void 0,
|
|
142
159
|
void 0,
|
|
143
160
|
void 0,
|
|
144
|
-
|
|
161
|
+
S,
|
|
145
162
|
void 0,
|
|
146
163
|
void 0,
|
|
147
|
-
|
|
148
|
-
t.getContractWithFetcher(
|
|
149
|
-
|
|
164
|
+
p,
|
|
165
|
+
t.getContractWithFetcher(I.HinkalHelperContract),
|
|
166
|
+
K,
|
|
150
167
|
void 0,
|
|
151
168
|
!1
|
|
152
169
|
);
|
|
153
170
|
return {
|
|
154
|
-
zkCallData:
|
|
155
|
-
dimData:
|
|
156
|
-
circomData: C
|
|
171
|
+
zkCallData: v,
|
|
172
|
+
dimData: u,
|
|
173
|
+
circomData: C,
|
|
174
|
+
adminData: U
|
|
157
175
|
};
|
|
158
176
|
})
|
|
159
177
|
);
|
|
160
|
-
g.push(...
|
|
178
|
+
g.push(...R);
|
|
161
179
|
}
|
|
162
|
-
return
|
|
180
|
+
return G(
|
|
163
181
|
t.getCurrentChainId(),
|
|
164
182
|
g,
|
|
165
|
-
|
|
183
|
+
A,
|
|
166
184
|
w
|
|
167
185
|
);
|
|
168
|
-
},
|
|
169
|
-
const
|
|
186
|
+
}, bt = async (t, s, c, p, A, w) => {
|
|
187
|
+
const o = s.erc20TokenAddress, d = t.getCurrentChainId(), r = st(await t.getEthereumAddress()), a = w ?? await et(d, o, [o], z.Transact), n = await nt(
|
|
170
188
|
t,
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
189
|
+
s,
|
|
190
|
+
c,
|
|
191
|
+
p,
|
|
174
192
|
a,
|
|
175
|
-
|
|
193
|
+
r
|
|
176
194
|
);
|
|
177
|
-
return
|
|
195
|
+
return it(
|
|
178
196
|
t,
|
|
179
|
-
|
|
180
|
-
|
|
197
|
+
s,
|
|
198
|
+
n,
|
|
181
199
|
a,
|
|
182
|
-
|
|
183
|
-
|
|
200
|
+
r,
|
|
201
|
+
A
|
|
184
202
|
);
|
|
185
203
|
};
|
|
186
204
|
export {
|
|
187
|
-
|
|
205
|
+
bt as hinkalDepositAndWithdraw
|
|
188
206
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IHinkal } from './IHinkal';
|
|
2
2
|
import { FeeStructure, type ParsedInLogicMetadata } from '../../types/hinkal.types';
|
|
3
3
|
import { AdminTransactionType } from '../../types/admin.types';
|
|
4
|
-
export declare const hinkalInsideTransact: (hinkal: IHinkal, erc20Addresses: string[], deltaChanges: bigint[], approvalChanges: bigint[], externalAddress: string, externalActionMetadata: string, parsedInLogicMetadata: ParsedInLogicMetadata, feeToken?: string, feeStructureOverride?: FeeStructure, action?: AdminTransactionType, onlyGasEstimate?: boolean) => Promise<bigint | import(
|
|
4
|
+
export declare const hinkalInsideTransact: (hinkal: IHinkal, erc20Addresses: string[], deltaChanges: bigint[], approvalChanges: bigint[], externalAddress: string, externalActionMetadata: string, parsedInLogicMetadata: ParsedInLogicMetadata, feeToken?: string, feeStructureOverride?: FeeStructure, action?: AdminTransactionType, onlyGasEstimate?: boolean) => Promise<bigint | import('../../index.ts').RelayerTransaction>;
|
|
@@ -3,4 +3,4 @@ import { FeeStructure } from '../../types/hinkal.types';
|
|
|
3
3
|
import { PrivateRecipientInfo, TokenChanges } from '../../types/token.types';
|
|
4
4
|
import { SubAccount } from '../../types/proxy.types';
|
|
5
5
|
import { AdminTransactionType } from '../../types/admin.types';
|
|
6
|
-
export declare const hinkalPrivateWallet: (hinkal: IHinkal, erc20Addresses: string[], deltaChanges: bigint[], onChainCreation: boolean[], ops: string[], emporiumTokenChanges: TokenChanges<bigint>[], subAccount: SubAccount, feeToken?: string, feeStructureOverride?: FeeStructure, relayOverride?: string, autoDepositBack?: boolean, maxGasInDollar?: string, action?: AdminTransactionType, privateRecipientInfo?: PrivateRecipientInfo, onlyGasEstimate?: boolean) => Promise<bigint | import(
|
|
6
|
+
export declare const hinkalPrivateWallet: (hinkal: IHinkal, erc20Addresses: string[], deltaChanges: bigint[], onChainCreation: boolean[], ops: string[], emporiumTokenChanges: TokenChanges<bigint>[], subAccount: SubAccount, feeToken?: string, feeStructureOverride?: FeeStructure, relayOverride?: string, autoDepositBack?: boolean, maxGasInDollar?: string, action?: AdminTransactionType, privateRecipientInfo?: PrivateRecipientInfo, onlyGasEstimate?: boolean) => Promise<bigint | import('../../index.ts').RelayerTransaction>;
|
|
@@ -3,4 +3,4 @@ import { FeeStructure } from '../../types/hinkal.types';
|
|
|
3
3
|
import { AdminTransactionType } from '../../types/admin.types';
|
|
4
4
|
import { IHinkal } from './IHinkal';
|
|
5
5
|
import { SubAccount } from '../../types/proxy.types';
|
|
6
|
-
export declare const hinkalProxyToPrivate: (hinkal: IHinkal, erc20Tokens: ERC20Token[], deltaAmountsBase: bigint[], recipientInfo: string, feeToken?: string, feeStructureOverride?: FeeStructure, subAccount?: SubAccount, action?: AdminTransactionType, onlyGasEstimate?: boolean) => Promise<bigint | import(
|
|
6
|
+
export declare const hinkalProxyToPrivate: (hinkal: IHinkal, erc20Tokens: ERC20Token[], deltaAmountsBase: bigint[], recipientInfo: string, feeToken?: string, feeStructureOverride?: FeeStructure, subAccount?: SubAccount, action?: AdminTransactionType, onlyGasEstimate?: boolean) => Promise<bigint | import('../../index.ts').RelayerTransaction>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { FeeStructure, OKXSwapResponseInstruction } from '../../types';
|
|
2
2
|
import { IHinkal } from './IHinkal';
|
|
3
3
|
import { ERC20Token } from '../../types/token.types';
|
|
4
|
-
export declare const hinkalSolanaSwap: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], instructionLists: OKXSwapResponseInstruction[], addressLookupTableAccount: string[], feeToken?: string, feeStructureOverride?: FeeStructure, onlyGasEstimate?: boolean) => Promise<import(
|
|
4
|
+
export declare const hinkalSolanaSwap: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], instructionLists: OKXSwapResponseInstruction[], addressLookupTableAccount: string[], feeToken?: string, feeStructureOverride?: FeeStructure, onlyGasEstimate?: boolean) => Promise<import('../../types/relayer.types').RelayerTransaction>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ERC20Token, FeeStructure } from '../../types';
|
|
2
2
|
import { IHinkal } from './IHinkal';
|
|
3
|
-
export declare const hinkalSolanaTransfer: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], recipientAddress: string, feeToken?: string, feeStructureOverride?: FeeStructure, onlyGasEstimate?: boolean) => Promise<import(
|
|
3
|
+
export declare const hinkalSolanaTransfer: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChanges: bigint[], recipientAddress: string, feeToken?: string, feeStructureOverride?: FeeStructure, onlyGasEstimate?: boolean) => Promise<import('../../types/relayer.types').RelayerTransaction>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { FeeStructure } from '../../types';
|
|
2
2
|
import { IHinkal } from './IHinkal';
|
|
3
|
-
export declare const hinkalSolanaWithdraw: (hinkal: IHinkal, mintAddresses: string[], amountChanges: bigint[], recipientAddress: string, feeToken?: string, feeStructureOverride?: FeeStructure, onlyGasEstimate?: boolean) => Promise<import(
|
|
3
|
+
export declare const hinkalSolanaWithdraw: (hinkal: IHinkal, mintAddresses: string[], amountChanges: bigint[], recipientAddress: string, feeToken?: string, feeStructureOverride?: FeeStructure, onlyGasEstimate?: boolean) => Promise<import('../../types/relayer.types').RelayerTransaction>;
|
|
@@ -3,4 +3,4 @@ import { IHinkal } from './IHinkal';
|
|
|
3
3
|
import { FeeStructure } from '../../types/hinkal.types';
|
|
4
4
|
import { type ERC20Token } from '../../types/token.types';
|
|
5
5
|
import { AdminTransactionType } from '../../types/admin.types';
|
|
6
|
-
export declare const hinkalSwap: (hinkal: IHinkal, erc20tokens: ERC20Token[], deltaAmounts: bigint[], externalActionId: ExternalActionId, data: string, feeToken?: string, feeStructureOverride?: FeeStructure, action?: AdminTransactionType, onlyGasEstimate?: boolean, withPrivateMempool?: boolean) => Promise<bigint | import(
|
|
6
|
+
export declare const hinkalSwap: (hinkal: IHinkal, erc20tokens: ERC20Token[], deltaAmounts: bigint[], externalActionId: ExternalActionId, data: string, feeToken?: string, feeStructureOverride?: FeeStructure, action?: AdminTransactionType, onlyGasEstimate?: boolean, withPrivateMempool?: boolean) => Promise<bigint | import('../../index.ts').RelayerTransaction>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { FeeStructure } from '../../types/hinkal.types';
|
|
2
2
|
import { AdminTransactionType, ERC20Token } from '../../types';
|
|
3
3
|
import { IHinkal } from './IHinkal';
|
|
4
|
-
export declare const hinkalTransfer: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChangesBase: bigint[], recipientAddress: string, feeToken?: string, feeStructureOverride?: FeeStructure, action?: AdminTransactionType, onlyGasEstimate?: boolean) => Promise<bigint | import(
|
|
4
|
+
export declare const hinkalTransfer: (hinkal: IHinkal, erc20Tokens: ERC20Token[], amountChangesBase: bigint[], recipientAddress: string, feeToken?: string, feeStructureOverride?: FeeStructure, action?: AdminTransactionType, onlyGasEstimate?: boolean) => Promise<bigint | import('../../types/relayer.types').RelayerTransaction>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("../../error-handling/error-codes.constants.cjs"),P=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),D=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),E=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),F=require("../../types/external-action.types.cjs"),R=require("../../types/hinkal.types.cjs"),_=require("../../functions/pre-transaction/outputApprovalDataProcessing.cjs"),M=require("../../functions/pre-transaction/getFeeStructure.cjs"),W=require("../../functions/pre-transaction/merge-with-fee-structure.cjs");require("../../types/circom-data.types.cjs");const B=require("../../types/ethereum-network.types.cjs");require("../../types/transactions.types.cjs");const b=require("../../types/admin.types.cjs");require("../../types/activities.types.cjs");const K=require("../../functions/pre-transaction/getSignatureDataForTransact.cjs"),L=require("../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.cjs");require("../../constants/server.constants.cjs");require("../../constants/chains.constants.cjs");require("../../constants/vite.constants.cjs");require("../http/HttpClient.cjs");require("axios");const H=require("../../functions/utils/amounts.utils.cjs");require("ethers");require("../../constants/token-data/index.cjs");require("../../API/getServerURL.cjs");require("circomlibjs-hinkal-fork");require("libsodium-wrappers");require("process");require("buffer");require("../../constants/save-depths.cjs");require("../../constants/reorg-depths.constants.cjs");require("../../functions/utils/mutexes.utils.cjs");require("@coral-xyz/anchor");require("@solana/web3.js");require("../crypto-keys/keys.cjs");const N=require("../../functions/utils/time.utils.cjs"),$=require("../../functions/pre-transaction/constructAdminData.cjs");require("@solana/spl-token");const O=require("../../functions/web3/events/getInputUtxoAndBalance.cjs"),Z=require("../../functions/web3/events/getShieldedBalance.cjs"),j=require("../../functions/utils/encodeTokenWithId.cjs"),z=require("../../API/unspent-utxos-calls.cjs"),G=require("../../functions/utils/addresses.cjs"),V=async(e,c,d,l)=>{const o=[c.erc20TokenAddress],A=c.erc20TokenAddress,a=await M.getFeeStructure(e.getCurrentChainId(),A,o,F.ExternalActionId.Transact),i=d-a.flatFee;if(i<=0n)throw new Error(`Insufficient balance to cover fee. Balance: ${d}, Fee: ${a.flatFee}`);const t=[-i];W.mergeWithFeeStructure(e.getCurrentChainId(),o,t,a);const u={externalActionId:0n,externalAddress:l,externalActionMetadata:"0x00"},s=[...await Z.addPaddingToUtxos(e,o,t,void 0,void 0,!1,!0)],g=`swapperM${t.length.toString()}x${s[0].length}x1`,r=R.defaultHinkalLogicArgs(t.length,e.userKeys),q=N.getCurrentTimeInSeconds().toString(),p=[];for(let n=0;n<o.length;n+=1){const{outputUtxos:S}=P.outputUtxoProcessing(e.userKeys,s[n],t[n],q,void 0,!1);p.push(S);const{useApprovalUtxoData:x}=_.outputApprovalDataProcessing(e,s[n],t[n]);x&&(r.useApprovalUtxoData[n]=x,r.doPreTxApproval=!0)}const m=await e.getRandomRelay(!0);if(!m)throw Error(k.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const{patchAccessTokenMerkleTree:h,kycRequired:f,hasAccessToken:C}=await L.shouldPatchAccessTokenMerkleTree(e,o,t),w=await K.getSignatureDataForTransact(e.getCurrentChainId(),await e.getEthereumAddress(),e.userKeys,f,C),{zkCallData:y,circomData:v,dimData:I}=await D.constructZkProof("v1x1",e.merkleTreeHinkal,e.merkleTreeAccessToken,s,p,e.userKeys,g,u.externalActionId,u.externalAddress,u.externalActionMetadata,e.generateProofRemotely,m,e.getCurrentChainId(),void 0,void 0,void 0,void 0,h,r,void 0,a,e.getContractWithFetcher(B.ContractType.HinkalHelperContract),w,void 0,!1),U=$.constructAdminData(b.AdminTransactionType.WithdrawOnChainUtxos,e.getCurrentChainId(),o,t,await e.getEthereumAddress());return{tx:await E.transactCallRelayer(e.getCurrentChainId(),y,I,v,void 0,void 0,void 0,U),amountToRecipient:i}},Y=async(e,c,d)=>{const l=[],o=e.getCurrentChainId(),A=j.encodeTokenWithId(o,{erc20TokenAddress:c.erc20TokenAddress,tokenId:0}),a=await e.getEthereumAddress(),i=G.hashEthereumAddress(a);for(;;){const t=((await O.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,useBlockedUtxos:!0}))?.get(A)??[]).filter(r=>r.amount>0n).slice(0,6).sort((r,q)=>Number(q.amount-r.amount)),u=H.countTotalAmountInUtxos(t);if(!u)break;const s=t.map(r=>r.nullifier).filter(r=>!!r),{tx:g}=await V(e,c,u,d);s.length>0&&await z.deleteUnspentUtxos(o,i,s),l.push(g)}return l};exports.hinkalWithdrawStuckUtxos=Y;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IHinkal } from './IHinkal';
|
|
2
|
-
import {
|
|
2
|
+
import { ERC20Token } from '../../types';
|
|
3
3
|
import { RelayerTransaction } from '../../types/relayer.types';
|
|
4
|
-
export declare const hinkalWithdrawStuckUtxos: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAddress: string
|
|
4
|
+
export declare const hinkalWithdrawStuckUtxos: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAddress: string) => Promise<RelayerTransaction[]>;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { transactionErrorCodes as
|
|
2
|
-
import { outputUtxoProcessing as
|
|
3
|
-
import { constructZkProof as
|
|
4
|
-
import { transactCallRelayer as
|
|
5
|
-
import { ExternalActionId as
|
|
6
|
-
import { defaultHinkalLogicArgs as
|
|
7
|
-
import { outputApprovalDataProcessing as
|
|
8
|
-
import { getFeeStructure as
|
|
9
|
-
import { mergeWithFeeStructure as
|
|
1
|
+
import { transactionErrorCodes as S } from "../../error-handling/error-codes.constants.mjs";
|
|
2
|
+
import { outputUtxoProcessing as P } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
3
|
+
import { constructZkProof as R } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
4
|
+
import { transactCallRelayer as k } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
5
|
+
import { ExternalActionId as F } from "../../types/external-action.types.mjs";
|
|
6
|
+
import { defaultHinkalLogicArgs as M } from "../../types/hinkal.types.mjs";
|
|
7
|
+
import { outputApprovalDataProcessing as K } from "../../functions/pre-transaction/outputApprovalDataProcessing.mjs";
|
|
8
|
+
import { getFeeStructure as L } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
9
|
+
import { mergeWithFeeStructure as W } from "../../functions/pre-transaction/merge-with-fee-structure.mjs";
|
|
10
10
|
import "../../types/circom-data.types.mjs";
|
|
11
|
-
import { ContractType as
|
|
11
|
+
import { ContractType as B } from "../../types/ethereum-network.types.mjs";
|
|
12
12
|
import "../../types/transactions.types.mjs";
|
|
13
|
+
import { AdminTransactionType as H } from "../../types/admin.types.mjs";
|
|
13
14
|
import "../../types/activities.types.mjs";
|
|
14
15
|
import { getSignatureDataForTransact as $ } from "../../functions/pre-transaction/getSignatureDataForTransact.mjs";
|
|
15
16
|
import { shouldPatchAccessTokenMerkleTree as b } from "../../functions/pre-transaction/shouldPatchAccessTokenMerkleTree.mjs";
|
|
@@ -32,116 +33,116 @@ import "../../functions/utils/mutexes.utils.mjs";
|
|
|
32
33
|
import "@coral-xyz/anchor";
|
|
33
34
|
import "@solana/web3.js";
|
|
34
35
|
import "../crypto-keys/keys.mjs";
|
|
35
|
-
import { getCurrentTimeInSeconds as
|
|
36
|
-
import { constructAdminData as
|
|
36
|
+
import { getCurrentTimeInSeconds as O } from "../../functions/utils/time.utils.mjs";
|
|
37
|
+
import { constructAdminData as _ } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
37
38
|
import "@solana/spl-token";
|
|
38
|
-
import { getInputUtxoAndBalancePerToken as
|
|
39
|
-
import { addPaddingToUtxos as
|
|
39
|
+
import { getInputUtxoAndBalancePerToken as q } from "../../functions/web3/events/getInputUtxoAndBalance.mjs";
|
|
40
|
+
import { addPaddingToUtxos as z } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
40
41
|
import { encodeTokenWithId as V } from "../../functions/utils/encodeTokenWithId.mjs";
|
|
41
42
|
import { deleteUnspentUtxos as Y } from "../../API/unspent-utxos-calls.mjs";
|
|
42
43
|
import { hashEthereumAddress as Z } from "../../functions/utils/addresses.mjs";
|
|
43
|
-
const j = async (t,
|
|
44
|
-
const o = [
|
|
44
|
+
const j = async (t, m, d, u) => {
|
|
45
|
+
const o = [m.erc20TokenAddress], p = m.erc20TokenAddress, a = await L(
|
|
45
46
|
t.getCurrentChainId(),
|
|
46
|
-
|
|
47
|
+
p,
|
|
47
48
|
o,
|
|
48
|
-
|
|
49
|
-
),
|
|
50
|
-
if (
|
|
49
|
+
F.Transact
|
|
50
|
+
), c = d - a.flatFee;
|
|
51
|
+
if (c <= 0n)
|
|
51
52
|
throw new Error(`Insufficient balance to cover fee. Balance: ${d}, Fee: ${a.flatFee}`);
|
|
52
|
-
const e = [-
|
|
53
|
-
|
|
53
|
+
const e = [-c];
|
|
54
|
+
W(t.getCurrentChainId(), o, e, a);
|
|
54
55
|
const i = {
|
|
55
56
|
externalActionId: 0n,
|
|
56
|
-
externalAddress:
|
|
57
|
+
externalAddress: u,
|
|
57
58
|
externalActionMetadata: "0x00"
|
|
58
59
|
}, s = [
|
|
59
|
-
...await
|
|
60
|
-
],
|
|
60
|
+
...await z(t, o, e, void 0, void 0, !1, !0)
|
|
61
|
+
], f = `swapperM${e.length.toString()}x${s[0].length}x1`, r = M(e.length, t.userKeys), l = O().toString(), A = [];
|
|
61
62
|
for (let n = 0; n < o.length; n += 1) {
|
|
62
|
-
const { outputUtxos:
|
|
63
|
+
const { outputUtxos: D } = P(
|
|
63
64
|
t.userKeys,
|
|
64
65
|
s[n],
|
|
65
66
|
e[n],
|
|
66
|
-
|
|
67
|
+
l,
|
|
67
68
|
void 0,
|
|
68
69
|
!1
|
|
69
70
|
);
|
|
70
|
-
|
|
71
|
-
const { useApprovalUtxoData:
|
|
72
|
-
|
|
71
|
+
A.push(D);
|
|
72
|
+
const { useApprovalUtxoData: x } = K(t, s[n], e[n]);
|
|
73
|
+
x && (r.useApprovalUtxoData[n] = x, r.doPreTxApproval = !0);
|
|
73
74
|
}
|
|
74
|
-
const
|
|
75
|
-
if (!
|
|
76
|
-
throw Error(
|
|
77
|
-
const { patchAccessTokenMerkleTree:
|
|
75
|
+
const g = await t.getRandomRelay(!0);
|
|
76
|
+
if (!g)
|
|
77
|
+
throw Error(S.RELAYER_NOT_AVAILABLE);
|
|
78
|
+
const { patchAccessTokenMerkleTree: w, kycRequired: C, hasAccessToken: h } = await b(
|
|
78
79
|
t,
|
|
79
80
|
o,
|
|
80
81
|
e
|
|
81
|
-
),
|
|
82
|
+
), v = await $(
|
|
82
83
|
t.getCurrentChainId(),
|
|
83
84
|
await t.getEthereumAddress(),
|
|
84
85
|
t.userKeys,
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
), { zkCallData:
|
|
86
|
+
C,
|
|
87
|
+
h
|
|
88
|
+
), { zkCallData: I, circomData: y, dimData: U } = await R(
|
|
88
89
|
"v1x1",
|
|
89
90
|
t.merkleTreeHinkal,
|
|
90
91
|
t.merkleTreeAccessToken,
|
|
91
92
|
s,
|
|
92
|
-
|
|
93
|
+
A,
|
|
93
94
|
t.userKeys,
|
|
94
|
-
|
|
95
|
+
f,
|
|
95
96
|
i.externalActionId,
|
|
96
97
|
i.externalAddress,
|
|
97
98
|
i.externalActionMetadata,
|
|
98
99
|
t.generateProofRemotely,
|
|
99
|
-
|
|
100
|
+
g,
|
|
100
101
|
t.getCurrentChainId(),
|
|
101
102
|
void 0,
|
|
102
103
|
void 0,
|
|
103
104
|
void 0,
|
|
104
105
|
void 0,
|
|
105
|
-
|
|
106
|
+
w,
|
|
106
107
|
r,
|
|
107
108
|
void 0,
|
|
108
109
|
a,
|
|
109
|
-
t.getContractWithFetcher(
|
|
110
|
-
|
|
110
|
+
t.getContractWithFetcher(B.HinkalHelperContract),
|
|
111
|
+
v,
|
|
111
112
|
void 0,
|
|
112
113
|
!1
|
|
113
|
-
),
|
|
114
|
-
|
|
114
|
+
), E = _(
|
|
115
|
+
H.WithdrawOnChainUtxos,
|
|
115
116
|
t.getCurrentChainId(),
|
|
116
117
|
o,
|
|
117
118
|
e,
|
|
118
119
|
await t.getEthereumAddress()
|
|
119
120
|
);
|
|
120
|
-
return { tx: await
|
|
121
|
+
return { tx: await k(
|
|
121
122
|
t.getCurrentChainId(),
|
|
122
|
-
|
|
123
|
-
E,
|
|
123
|
+
I,
|
|
124
124
|
U,
|
|
125
|
+
y,
|
|
125
126
|
void 0,
|
|
126
127
|
void 0,
|
|
127
128
|
void 0,
|
|
128
|
-
|
|
129
|
-
), amountToRecipient:
|
|
130
|
-
},
|
|
131
|
-
const u = [], o = t.getCurrentChainId(),
|
|
129
|
+
E
|
|
130
|
+
), amountToRecipient: c };
|
|
131
|
+
}, bt = async (t, m, d) => {
|
|
132
|
+
const u = [], o = t.getCurrentChainId(), p = V(o, { erc20TokenAddress: m.erc20TokenAddress, tokenId: 0 }), a = await t.getEthereumAddress(), c = Z(a);
|
|
132
133
|
for (; ; ) {
|
|
133
|
-
const e = ((await
|
|
134
|
+
const e = ((await q({
|
|
134
135
|
hinkal: t,
|
|
135
136
|
sliceIfMore6: !1,
|
|
136
137
|
useBlockedUtxos: !0
|
|
137
|
-
}))?.get(
|
|
138
|
+
}))?.get(p) ?? []).filter((r) => r.amount > 0n).slice(0, 6).sort((r, l) => Number(l.amount - r.amount)), i = N(e);
|
|
138
139
|
if (!i)
|
|
139
140
|
break;
|
|
140
|
-
const s = e.map((r) => r.nullifier).filter((r) => !!r), { tx:
|
|
141
|
-
s.length > 0 && await Y(o,
|
|
141
|
+
const s = e.map((r) => r.nullifier).filter((r) => !!r), { tx: f } = await j(t, m, i, d);
|
|
142
|
+
s.length > 0 && await Y(o, c, s), u.push(f);
|
|
142
143
|
}
|
|
143
144
|
return u;
|
|
144
145
|
};
|
|
145
146
|
export {
|
|
146
|
-
|
|
147
|
+
bt as hinkalWithdrawStuckUtxos
|
|
147
148
|
};
|