@hinkal/common 0.2.36 → 0.2.38
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/API.cjs +1 -1
- package/API/API.d.ts +0 -5
- package/API/API.mjs +112 -117
- package/API/enclaveUtxoCalls.cjs +1 -1
- package/API/enclaveUtxoCalls.mjs +6 -7
- package/README.md +0 -22
- package/constants/chains.constants.cjs +1 -1
- package/constants/chains.constants.mjs +2 -1
- package/constants/events.constants.cjs +1 -1
- package/constants/events.constants.mjs +3 -1
- package/constants/index.cjs +1 -1
- package/constants/index.d.ts +0 -2
- package/constants/index.mjs +0 -2
- package/constants/mediaUrls.constants.cjs +1 -1
- package/constants/mediaUrls.constants.d.ts +0 -1
- package/constants/mediaUrls.constants.mjs +0 -1
- package/constants/rewards.constants.cjs +1 -1
- package/constants/rewards.constants.d.ts +0 -2
- package/constants/rewards.constants.mjs +2 -2
- package/constants/server.constants.cjs +1 -1
- package/constants/server.constants.d.ts +1 -5
- package/constants/server.constants.mjs +1 -6
- package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.cjs +1 -1
- package/data-structures/ApprovalDBs/EventsPublicApprovalsDB.mjs +13 -13
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +5 -3
- package/data-structures/Hinkal/Hinkal.mjs +98 -99
- package/data-structures/Hinkal/IHinkal.d.ts +5 -3
- package/data-structures/Hinkal/hinkalDepositAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndBridge.d.ts +2 -2
- package/data-structures/Hinkal/hinkalDepositAndBridge.mjs +8 -5
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.d.ts +2 -2
- package/data-structures/Hinkal/hinkalDepositAndWithdraw.mjs +4 -1
- package/data-structures/Hinkal/hinkalNearDepositAndBridge.cjs +1 -1
- package/data-structures/Hinkal/hinkalNearDepositAndBridge.mjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.d.ts +2 -2
- package/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +4 -1
- package/data-structures/Hinkal/resetMerkleTrees.cjs +1 -1
- package/data-structures/Hinkal/resetMerkleTrees.mjs +12 -12
- package/data-structures/TokenDBs/AlchemyPublicTokensDB.cjs +1 -1
- package/data-structures/TokenDBs/AlchemyPublicTokensDB.mjs +3 -2
- package/data-structures/TokenDBs/EventsPublicTokensDB.cjs +1 -1
- package/data-structures/TokenDBs/EventsPublicTokensDB.d.ts +0 -1
- package/data-structures/TokenDBs/EventsPublicTokensDB.mjs +27 -36
- package/data-structures/TokenDBs/PublicTokensDB.cjs +1 -1
- package/data-structures/TokenDBs/PublicTokensDB.mjs +23 -20
- package/data-structures/TokenDBs/TempoPublicTokensDB.cjs +1 -0
- package/data-structures/TokenDBs/TempoPublicTokensDB.d.ts +9 -0
- package/data-structures/TokenDBs/TempoPublicTokensDB.mjs +42 -0
- package/data-structures/TokenDBs/TronPublicTokensDB.cjs +1 -0
- package/data-structures/TokenDBs/TronPublicTokensDB.d.ts +9 -0
- package/data-structures/TokenDBs/TronPublicTokensDB.mjs +47 -0
- package/data-structures/TokenDBs/index.cjs +1 -1
- package/data-structures/TokenDBs/index.d.ts +2 -0
- package/data-structures/TokenDBs/index.mjs +2 -0
- package/data-structures/index.cjs +1 -1
- package/data-structures/index.mjs +2 -0
- package/error-handling/error-codes.constants.cjs +1 -1
- package/error-handling/error-codes.constants.d.ts +0 -5
- package/error-handling/error-codes.constants.mjs +0 -5
- package/externalABIs/index.cjs +1 -1
- package/externalABIs/index.d.ts +1 -36
- package/externalABIs/index.mjs +2 -4
- package/functions/index.cjs +1 -1
- package/functions/index.d.ts +0 -1
- package/functions/index.mjs +1 -4
- package/functions/pre-transaction/sendV0Transaction.cjs +2 -2
- package/functions/pre-transaction/sendV0Transaction.mjs +69 -57
- package/functions/snarkjs/common.snarkjs.cjs +1 -1
- package/functions/snarkjs/common.snarkjs.mjs +2 -2
- package/functions/snarkjs/constant.cjs +1 -1
- package/functions/snarkjs/constant.mjs +1 -1
- package/functions/utils/enclaveHandshakeService.cjs +1 -0
- package/functions/utils/enclaveHandshakeService.d.ts +10 -0
- package/functions/utils/enclaveHandshakeService.mjs +22 -0
- package/functions/utils/encryptInputForEnclave.cjs +1 -1
- package/functions/utils/encryptInputForEnclave.mjs +23 -25
- package/functions/utils/index.cjs +1 -1
- package/functions/utils/index.d.ts +1 -0
- package/functions/utils/index.mjs +1 -0
- package/functions/utils/tron.utils.cjs +1 -1
- package/functions/utils/tron.utils.d.ts +1 -0
- package/functions/utils/tron.utils.mjs +1 -1
- package/index.cjs +1 -1
- package/index.mjs +314 -317
- package/package.json +2 -2
- package/types/cache.types.cjs +1 -1
- package/types/cache.types.d.ts +2 -0
- package/types/cache.types.mjs +1 -1
- package/types/commitments.types.d.ts +0 -10
- package/types/hinkal.types.cjs +1 -1
- package/types/hinkal.types.d.ts +0 -7
- package/types/hinkal.types.mjs +2 -4
- package/types/index.cjs +1 -1
- package/types/index.d.ts +0 -1
- package/types/index.mjs +0 -1
- package/types/new-rewards.type.cjs +1 -1
- package/types/new-rewards.type.d.ts +0 -1
- package/types/new-rewards.type.mjs +1 -1
- package/types/scheduled-transactions.types.d.ts +4 -0
- package/webworker/{logError-B1LyaM6e.js → logError-CU_5hb0O.js} +1 -1
- package/webworker/package.json +2 -2
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/snarkjsWorkerNode.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/utxoWorkerNode.cjs +1 -1
- package/webworker/viteWorkerURL.constant.cjs +3 -3
- package/webworker/viteWorkerURL.constant.mjs +3 -3
- package/webworker/{workerProxy-UUs7pDb1.js → workerProxy-JYVsEgnC.js} +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
- package/webworker/zkProofWorkerNode.cjs +1 -1
- package/API/kycCalls.cjs +0 -1
- package/API/kycCalls.d.ts +0 -14
- package/API/kycCalls.mjs +0 -26
- package/constants/assets.constants.cjs +0 -1
- package/constants/assets.constants.d.ts +0 -13
- package/constants/assets.constants.mjs +0 -16
- package/constants/kyc.constants.cjs +0 -1
- package/constants/kyc.constants.d.ts +0 -29
- package/constants/kyc.constants.mjs +0 -126
- package/data-structures/Hinkal/hinkalGetZkMeProvider.cjs +0 -1
- package/data-structures/Hinkal/hinkalGetZkMeProvider.d.ts +0 -28
- package/data-structures/Hinkal/hinkalGetZkMeProvider.mjs +0 -22
- package/externalABIs/BabPassport.json.cjs +0 -1
- package/externalABIs/BabPassport.json.mjs +0 -20
- package/externalABIs/GalxePassport.json.cjs +0 -1
- package/externalABIs/GalxePassport.json.mjs +0 -37
- package/functions/kyc/aiPriseHelper.d.ts +0 -0
- package/functions/kyc/checkTokenLimitsUSD.cjs +0 -1
- package/functions/kyc/checkTokenLimitsUSD.d.ts +0 -1
- package/functions/kyc/checkTokenLimitsUSD.mjs +0 -29
- package/functions/kyc/index.cjs +0 -1
- package/functions/kyc/index.d.ts +0 -3
- package/functions/kyc/index.mjs +0 -3
- package/functions/kyc/openDefaultPassportWindow.cjs +0 -1
- package/functions/kyc/openDefaultPassportWindow.d.ts +0 -1
- package/functions/kyc/openDefaultPassportWindow.mjs +0 -7
- package/functions/kyc/passportHelper.cjs +0 -1
- package/functions/kyc/passportHelper.d.ts +0 -3
- package/functions/kyc/passportHelper.mjs +0 -9
- package/functions/kyc/zkMeHelper.cjs +0 -1
- package/functions/kyc/zkMeHelper.d.ts +0 -4
- package/functions/kyc/zkMeHelper.mjs +0 -42
- package/types/kyc.types.cjs +0 -1
- package/types/kyc.types.d.ts +0 -41
- package/types/kyc.types.mjs +0 -12
|
@@ -3,28 +3,27 @@ import { CustomJSONStringify as t } from "../../functions/utils/serialize.utils.
|
|
|
3
3
|
import { isExtension as n } from "../../constants/vite.constants.mjs";
|
|
4
4
|
import { HINKAL_SUPPORTED_CHAINS as r, WALLET_SUPPORTED_CHAINS as i, chainIds as a, currentSolanaChainId as o, currentTronChainId as s, isSameOnchainNetwork as c, isSolanaLike as l, isTronLike as u, networkRegistry as d, setHinkalTronChainId as f } from "../../constants/chains.constants.mjs";
|
|
5
5
|
import { DETERMINISTIC_SOLANA_LEDGER_BLOCKHASH as p, DETERMINISTIC_SOLANA_LEDGER_LAST_VALID_BLOCK_HEIGHT as m } from "../../constants/protocol.constants.mjs";
|
|
6
|
-
import { EventType as
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { transactionErrorCodes as
|
|
10
|
-
import { getErc20TokensForChain as
|
|
6
|
+
import { EventType as ee, LoginMessageMode as h } from "../../types/hinkal.types.mjs";
|
|
7
|
+
import { getScheduledTransactionById as te } from "../../API/scheduled-transactions-calls.mjs";
|
|
8
|
+
import { API as g } from "../../API/API.mjs";
|
|
9
|
+
import { transactionErrorCodes as _ } from "../../error-handling/error-codes.constants.mjs";
|
|
10
|
+
import { getErc20TokensForChain as v } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
11
11
|
import "../../API/index.mjs";
|
|
12
|
-
import { poseidonFunction as
|
|
13
|
-
import { UserKeys as
|
|
14
|
-
import { validateAndGetChainId as
|
|
15
|
-
import { privateTokensDB as
|
|
16
|
-
import { getShieldedBalance as
|
|
17
|
-
import { getMerkleAccountPublicKey as
|
|
18
|
-
import { getContractWithFetcherByChainId as
|
|
19
|
-
import { reloadPage as
|
|
20
|
-
import { createCacheDevice as
|
|
21
|
-
import { SolanaProviderAdapter as
|
|
22
|
-
import { storeAndGetSignatureFromEnclave as
|
|
23
|
-
import { generateHashFromSeedPhrases as
|
|
24
|
-
import { fetchSolanaMerkleTreeRootHash as
|
|
25
|
-
import { createTransaferEmporiumOpsBatch as
|
|
26
|
-
import { hinkalDeposit as
|
|
27
|
-
import { checkTokenLimitsUSD as N } from "../../functions/kyc/checkTokenLimitsUSD.mjs";
|
|
12
|
+
import { poseidonFunction as ne } from "../../crypto/poseidon.mjs";
|
|
13
|
+
import { UserKeys as y } from "../crypto-keys/keys.mjs";
|
|
14
|
+
import { validateAndGetChainId as b } from "../../functions/utils/token-check.utils.mjs";
|
|
15
|
+
import { privateTokensDB as x } from "../TokenDBs/PrivateTokensDB.mjs";
|
|
16
|
+
import { getShieldedBalance as S } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
17
|
+
import { getMerkleAccountPublicKey as C } from "../../functions/pre-transaction/solana.mjs";
|
|
18
|
+
import { getContractWithFetcherByChainId as w } from "../../functions/web3/getContractMetadata.mjs";
|
|
19
|
+
import { reloadPage as T } from "../../functions/utils/reloadPage.mjs";
|
|
20
|
+
import { createCacheDevice as E } from "../../functions/utils/cacheDevice.utils.mjs";
|
|
21
|
+
import { SolanaProviderAdapter as D } from "../../providers/SolanaProviderAdapter.mjs";
|
|
22
|
+
import { storeAndGetSignatureFromEnclave as O } from "../../functions/utils/enclave-signature-storage.mjs";
|
|
23
|
+
import { generateHashFromSeedPhrases as k } from "../../functions/utils/mnemonics.mjs";
|
|
24
|
+
import { fetchSolanaMerkleTreeRootHash as A } from "../../functions/web3/fetchSolanaMerkleTreeRootHash.mjs";
|
|
25
|
+
import { createTransaferEmporiumOpsBatch as j } from "../../functions/private-wallet/emporium.helpers.mjs";
|
|
26
|
+
import { hinkalDeposit as M, hinkalDepositForOther as N } from "./hinkalDeposit.mjs";
|
|
28
27
|
import { hinkalDepositAndWithdraw as P } from "./hinkalDepositAndWithdraw.mjs";
|
|
29
28
|
import { hinkalSolanaDeposit as F, hinkalSolanaDepositForOther as I, hinkalSolanaProoflessDepositWithPublicFee as L } from "./hinkalSolanaDeposit.mjs";
|
|
30
29
|
import { hinkalSwap as R } from "./hinkalSwap.mjs";
|
|
@@ -32,8 +31,8 @@ import { hinkalWithdraw as z } from "./hinkalWithdraw.mjs";
|
|
|
32
31
|
import { MerkleTree as B } from "../merkle-tree/MerkleTree.mjs";
|
|
33
32
|
import "../merkle-tree/index.mjs";
|
|
34
33
|
import { resetMerkleTrees as V } from "./resetMerkleTrees.mjs";
|
|
35
|
-
import { MultiThreadedUtxoUtils as
|
|
36
|
-
import { hinkalPrivateWallet as
|
|
34
|
+
import { MultiThreadedUtxoUtils as H } from "../MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs";
|
|
35
|
+
import { hinkalPrivateWallet as re } from "./hinkalPrivateWallet.mjs";
|
|
37
36
|
import { getRecipientInfo as U } from "./hinkalGetRecipientInfo.mjs";
|
|
38
37
|
import { hinkalSignSubAccount as W } from "./hinkalSignSubAccount.mjs";
|
|
39
38
|
import { hinkalActionReceive as G } from "./hinkalActionReceive.mjs";
|
|
@@ -41,25 +40,25 @@ import "../TokenDBs/index.mjs";
|
|
|
41
40
|
import { hinkalProoflessDeposit as K, hinkalProoflessDepositWithPublicFee as q } from "./hinkalProoflessDeposit.mjs";
|
|
42
41
|
import { hinkalProxySwap as J } from "./hinkalProxySwap.mjs";
|
|
43
42
|
import { hinkalMultiSendPrivateRecipients as Y } from "./hinkalMultiSend.mjs";
|
|
44
|
-
import { hinkalTransfer as
|
|
45
|
-
import { hinkalProxyToPrivate as
|
|
46
|
-
import { TronProviderAdapter as
|
|
47
|
-
import { hinkalSolanaDepositAndWithdraw as
|
|
48
|
-
import { hinkalSolanaWithdraw as
|
|
49
|
-
import { hinkalSolanaTransfer as
|
|
50
|
-
import { hinkalSolanaSwap as
|
|
51
|
-
import { hinkalSolanaProxySend as
|
|
52
|
-
import { hinkalSolanaProxySwap as
|
|
53
|
-
import { hinkalSolanaProxyShield as
|
|
54
|
-
import { hinkalDepositAndBridge as
|
|
55
|
-
import { hinkalNearDepositAndBridge as
|
|
56
|
-
import { hinkalClaimUtxo as
|
|
57
|
-
import { hinkalSolanaProoflessDeposit as
|
|
58
|
-
import { hinkalSolanaClaimUtxo as
|
|
59
|
-
import { hinkalWithdrawStuckUtxos as
|
|
60
|
-
import { PublicKey as $, Transaction as
|
|
43
|
+
import { hinkalTransfer as X } from "./hinkalTransfer.mjs";
|
|
44
|
+
import { hinkalProxyToPrivate as ie } from "./hinkalProxyToPrivate.mjs";
|
|
45
|
+
import { TronProviderAdapter as Z } from "../../providers/TronProviderAdapter.mjs";
|
|
46
|
+
import { hinkalSolanaDepositAndWithdraw as ae } from "./hinkalSolanaDepositAndWithdraw.mjs";
|
|
47
|
+
import { hinkalSolanaWithdraw as oe } from "./hinkalSolanaWithdraw.mjs";
|
|
48
|
+
import { hinkalSolanaTransfer as se } from "./hinkalSolanaTransfer.mjs";
|
|
49
|
+
import { hinkalSolanaSwap as ce } from "./hinkalSolanaSwap.mjs";
|
|
50
|
+
import { hinkalSolanaProxySend as le } from "./hinkalSolanaProxySend.mjs";
|
|
51
|
+
import { hinkalSolanaProxySwap as ue } from "./hinkalSolanaProxySwap.mjs";
|
|
52
|
+
import { hinkalSolanaProxyShield as Q } from "./hinkalSolanaProxyShield.mjs";
|
|
53
|
+
import { hinkalDepositAndBridge as de } from "./hinkalDepositAndBridge.mjs";
|
|
54
|
+
import { hinkalNearDepositAndBridge as fe } from "./hinkalNearDepositAndBridge.mjs";
|
|
55
|
+
import { hinkalClaimUtxo as pe } from "./hinkalClaimUtxo.mjs";
|
|
56
|
+
import { hinkalSolanaProoflessDeposit as me } from "./hinkalSolanaProoflessDeposit.mjs";
|
|
57
|
+
import { hinkalSolanaClaimUtxo as he } from "./hinkalSolanaClaimUtxo.mjs";
|
|
58
|
+
import { hinkalWithdrawStuckUtxos as ge } from "./hinkalWithdrawStuckUtxos.mjs";
|
|
59
|
+
import { PublicKey as $, Transaction as _e } from "@solana/web3.js";
|
|
61
60
|
//#region libs/shared/common/src/data-structures/Hinkal/Hinkal.ts
|
|
62
|
-
var
|
|
61
|
+
var ve = class {
|
|
63
62
|
ethereumProviderAdapter;
|
|
64
63
|
solanaProviderAdapter;
|
|
65
64
|
tronProviderAdapter;
|
|
@@ -77,9 +76,9 @@ var ye = class {
|
|
|
77
76
|
generateProofRemotely;
|
|
78
77
|
disableMerkleTreeUpdates;
|
|
79
78
|
constructor(e) {
|
|
80
|
-
this.userKeys = new
|
|
81
|
-
this.merkleTreeHinkalByChain[e] = B.create(
|
|
82
|
-
}), this.generateProofRemotely = e?.generateProofRemotely ?? !0, this.utxoUtils = new
|
|
79
|
+
this.userKeys = new y(void 0), e?.tronChainOverride && f(e.tronChainOverride), r.forEach((e) => {
|
|
80
|
+
this.merkleTreeHinkalByChain[e] = B.create(ne, 0n), this.nullifiersByChain[e] = /* @__PURE__ */ new Set(), this.encryptedOutputsByChain[e] = [];
|
|
81
|
+
}), this.generateProofRemotely = e?.generateProofRemotely ?? !0, this.utxoUtils = new H(), this.cacheDevice = E(e), this.disableMerkleTreeUpdates = e?.disableMerkleTreeUpdates ?? !1;
|
|
83
82
|
}
|
|
84
83
|
enforceRateLimit(e, n, r = 1e3) {
|
|
85
84
|
let i = Date.now(), a = t(n), o = this.lastCallState.get(e);
|
|
@@ -98,23 +97,23 @@ var ye = class {
|
|
|
98
97
|
}
|
|
99
98
|
async initProviderAdapter(e, t) {
|
|
100
99
|
let n = a.ethMainnet;
|
|
101
|
-
t instanceof
|
|
100
|
+
t instanceof D ? n = o : t instanceof Z && (n = s), await this.updateProviderAdapter(n, t), t.initConnector(e);
|
|
102
101
|
let r = await t.connectAndPatchProvider(e);
|
|
103
102
|
await t.init(r), await this.setListeners();
|
|
104
103
|
}
|
|
105
|
-
getSigningMessage(e =
|
|
104
|
+
getSigningMessage(e = h.PROTOCOL) {
|
|
106
105
|
switch (e) {
|
|
107
|
-
case
|
|
108
|
-
case
|
|
106
|
+
case h.PRIVATE_TRANSFER: return this.privateTransferSigningMessage;
|
|
107
|
+
case h.PROTOCOL:
|
|
109
108
|
default: return this.signingMessage;
|
|
110
109
|
}
|
|
111
110
|
}
|
|
112
|
-
async signHinkalMessage(e =
|
|
111
|
+
async signHinkalMessage(e = h.PROTOCOL) {
|
|
113
112
|
let t = this.getSigningMessage(e);
|
|
114
113
|
return this.getProviderAdapter().signMessage(t);
|
|
115
114
|
}
|
|
116
115
|
async signSolanaLedgerMessage() {
|
|
117
|
-
let e = new
|
|
116
|
+
let e = new _e({
|
|
118
117
|
blockhash: p,
|
|
119
118
|
lastValidBlockHeight: m,
|
|
120
119
|
feePayer: this.getSolanaPublicKey()
|
|
@@ -125,20 +124,20 @@ var ye = class {
|
|
|
125
124
|
txMessageForSolanaLedger: t.transactionMessageB64
|
|
126
125
|
};
|
|
127
126
|
}
|
|
128
|
-
async initUserKeys(e =
|
|
129
|
-
this.userKeys = new
|
|
127
|
+
async initUserKeys(e = h.PROTOCOL) {
|
|
128
|
+
this.userKeys = new y(await this.signHinkalMessage(e));
|
|
130
129
|
}
|
|
131
130
|
initUserKeysWithSignature(e) {
|
|
132
|
-
this.userKeys = new
|
|
131
|
+
this.userKeys = new y(e);
|
|
133
132
|
}
|
|
134
133
|
async initUserKeysFromSeedPhrases(e) {
|
|
135
|
-
let t =
|
|
136
|
-
this.userKeys = new
|
|
134
|
+
let t = k(e);
|
|
135
|
+
this.userKeys = new y(t);
|
|
137
136
|
}
|
|
138
137
|
async storeAndGetInitialSignature(e, t = !1, n) {
|
|
139
138
|
let r = await this.getEthereumAddress();
|
|
140
139
|
if (!r) throw Error("Connected address not found");
|
|
141
|
-
return await
|
|
140
|
+
return await O(r, e, t, n);
|
|
142
141
|
}
|
|
143
142
|
async resetMerkle(e) {
|
|
144
143
|
this.disableMerkleTreeUpdates || (e?.every((e) => this.isSelectedNetworkSupported(e)) ?? !0) && await V(this, e);
|
|
@@ -146,7 +145,7 @@ var ye = class {
|
|
|
146
145
|
getTronWeb() {
|
|
147
146
|
let e = this.tronProviderAdapter;
|
|
148
147
|
if (!e) throw Error("Tron provider adapter not initialized");
|
|
149
|
-
if (!(e instanceof
|
|
148
|
+
if (!(e instanceof Z)) throw Error("Tron provider adapter is not a TronProviderAdapter");
|
|
150
149
|
let t = e.getTronWeb();
|
|
151
150
|
if (!t) throw Error("TronWeb not available");
|
|
152
151
|
return t;
|
|
@@ -161,7 +160,7 @@ var ye = class {
|
|
|
161
160
|
return this.getProviderAdapter(e).getContract(e, t, n);
|
|
162
161
|
}
|
|
163
162
|
getContractWithFetcherByChainId(e, t, n = void 0) {
|
|
164
|
-
return
|
|
163
|
+
return w(e, t, n);
|
|
165
164
|
}
|
|
166
165
|
async signMessage(e) {
|
|
167
166
|
return await this.getProviderAdapter().signMessage(e);
|
|
@@ -186,7 +185,7 @@ var ye = class {
|
|
|
186
185
|
if (!(e.chainId === n || r)) try {
|
|
187
186
|
await t.switchNetwork(e);
|
|
188
187
|
} catch {
|
|
189
|
-
throw Error(
|
|
188
|
+
throw Error(_.FAILED_TO_SWITCH_NETWORKS);
|
|
190
189
|
}
|
|
191
190
|
}
|
|
192
191
|
isPermitterAvailable(e) {
|
|
@@ -231,20 +230,20 @@ var ye = class {
|
|
|
231
230
|
}
|
|
232
231
|
async onAccountChanged() {
|
|
233
232
|
await this.ethereumProviderAdapter?.onAccountChanged(), await this.solanaProviderAdapter?.onAccountChanged(), await this.tronProviderAdapter?.onAccountChanged();
|
|
234
|
-
let e =
|
|
233
|
+
let e = ee.AccountChanged;
|
|
235
234
|
typeof document < "u" ? document?.dispatchEvent(new Event(e)) : process?.emit("message", e, void 0);
|
|
236
235
|
}
|
|
237
236
|
async onChainChanged(e) {
|
|
238
|
-
e ? await this.getProviderAdapter(e).onChainChanged(e) : (await this.disconnectFromConnector(),
|
|
237
|
+
e ? await this.getProviderAdapter(e).onChainChanged(e) : (await this.disconnectFromConnector(), T());
|
|
239
238
|
}
|
|
240
239
|
async monitorConnectedAddress(e) {
|
|
241
|
-
await
|
|
240
|
+
await g.monitor(await this.getEthereumAddressByChain(e));
|
|
242
241
|
}
|
|
243
242
|
async getBalances(e, t, n, r, i = !1, a, o = !1) {
|
|
244
|
-
return
|
|
243
|
+
return S(this, e, t, n, r, i, this.generateProofRemotely, a, o);
|
|
245
244
|
}
|
|
246
245
|
async getTotalBalance(e, t, r, i = !1, a, o = !1) {
|
|
247
|
-
let s = r ?? await this.getEthereumAddressByChain(e), c = t ?? this.userKeys, l = await this.getBalances(e, c.getShieldedPrivateKey(), c.getShieldedPublicKey(), s, i, a, o), u = n ? await
|
|
246
|
+
let s = r ?? await this.getEthereumAddressByChain(e), c = t ?? this.userKeys, l = await this.getBalances(e, c.getShieldedPrivateKey(), c.getShieldedPublicKey(), s, i, a, o), u = n ? await x.getPrivateTokens(e, s) : v(e), d = [];
|
|
248
247
|
return u.forEach((e) => {
|
|
249
248
|
let t = e.erc20TokenAddress.toLowerCase(), n = l.get(t), r = {
|
|
250
249
|
token: e,
|
|
@@ -258,21 +257,12 @@ var ye = class {
|
|
|
258
257
|
async getStuckShieldedBalances(e, t, n) {
|
|
259
258
|
return (await this.getTotalBalance(e, t, n, !1, !1, !0)).filter((e) => e.balance > 0n);
|
|
260
259
|
}
|
|
261
|
-
getSupportedPassportLinks() {
|
|
262
|
-
return ee;
|
|
263
|
-
}
|
|
264
|
-
checkAccessToken(e, t) {
|
|
265
|
-
return Promise.resolve(!0);
|
|
266
|
-
}
|
|
267
|
-
checkExternalTokenLimitsUSD(e, t, n) {
|
|
268
|
-
return N(e, t, n);
|
|
269
|
-
}
|
|
270
260
|
async getHinkalTreeRootHash(t) {
|
|
271
261
|
if (l(t)) {
|
|
272
262
|
let { hinkalIdl: e, hinkalAddress: n, originalDeployer: r } = d[t].contractData;
|
|
273
263
|
if (!e || !n || !r) throw Error(`Missing Solana configuration for chain ${t}`);
|
|
274
|
-
let i = new $(r), a =
|
|
275
|
-
return
|
|
264
|
+
let i = new $(r), a = C(new $(n), i);
|
|
265
|
+
return A(this.getSolanaProgram(e), a);
|
|
276
266
|
}
|
|
277
267
|
return this.getContractWithFetcherByChainId(t, e.HinkalContract).getRootHash();
|
|
278
268
|
}
|
|
@@ -295,7 +285,7 @@ var ye = class {
|
|
|
295
285
|
return this.getProviderAdapter(e).getAddress();
|
|
296
286
|
}
|
|
297
287
|
async getRandomRelay(e, t = !1) {
|
|
298
|
-
return (await
|
|
288
|
+
return (await g.getIdleRelay(e, t)).relay;
|
|
299
289
|
}
|
|
300
290
|
getGasPrice(e) {
|
|
301
291
|
let t = this.getProviderAdapter(e);
|
|
@@ -303,7 +293,7 @@ var ye = class {
|
|
|
303
293
|
return t.getGasPrice(e);
|
|
304
294
|
}
|
|
305
295
|
getAPI() {
|
|
306
|
-
return
|
|
296
|
+
return g;
|
|
307
297
|
}
|
|
308
298
|
snapshotsClearInterval() {
|
|
309
299
|
this.getSupportedChains().forEach((e) => {
|
|
@@ -314,7 +304,7 @@ var ye = class {
|
|
|
314
304
|
return U(this);
|
|
315
305
|
}
|
|
316
306
|
async deposit(e, t, n = !0, r = !1) {
|
|
317
|
-
return
|
|
307
|
+
return M(this, e, t, n, r);
|
|
318
308
|
}
|
|
319
309
|
async depositSolana(e, t, n = !1) {
|
|
320
310
|
return F(this, e, t, n);
|
|
@@ -324,7 +314,7 @@ var ye = class {
|
|
|
324
314
|
e,
|
|
325
315
|
t,
|
|
326
316
|
n
|
|
327
|
-
]),
|
|
317
|
+
]), N(this, e, t, n, r, i, a);
|
|
328
318
|
}
|
|
329
319
|
async depositSolanaForOther(e, t, n, r = !1, i) {
|
|
330
320
|
return this.enforceRateLimit(this.depositSolanaForOther.name, [
|
|
@@ -334,13 +324,22 @@ var ye = class {
|
|
|
334
324
|
]), I(this, e, t, n, r, i);
|
|
335
325
|
}
|
|
336
326
|
async depositAndWithdraw(e, t, n, r, i, a, o, s, c = !0) {
|
|
337
|
-
return
|
|
327
|
+
return (await this.depositAndWithdrawExtended(e, t, n, r, i, a, o, s, c)).depositTxHash;
|
|
328
|
+
}
|
|
329
|
+
async depositAndWithdrawExtended(e, t, n, r, i, a, o, s, c = !0) {
|
|
330
|
+
return l(b([e])) ? ae(this, e, t, n, r, i, a, o, s) : P(this, e, t, n, r, i, a, o, s, c);
|
|
338
331
|
}
|
|
339
332
|
async claimUtxo(e, t, n, r) {
|
|
340
|
-
return l(
|
|
333
|
+
return l(b([e])) ? he(this, e, t, n, r) : pe(this, e, t, n, r);
|
|
341
334
|
}
|
|
342
335
|
async depositAndBridge(e, t, n, r, i, a, o, s = !0) {
|
|
343
|
-
return
|
|
336
|
+
return (await this.depositAndBridgeExtended(e, t, n, r, i, a, o, s)).depositTxHash;
|
|
337
|
+
}
|
|
338
|
+
async depositAndBridgeExtended(e, t, n, r, i, a, o, s = !0) {
|
|
339
|
+
return de(this, e, t, n, r, i, a, o, s);
|
|
340
|
+
}
|
|
341
|
+
async checkSendTransactionStatus(e) {
|
|
342
|
+
return te(e);
|
|
344
343
|
}
|
|
345
344
|
async nearDepositAndBridge(e, t, n, r, i, a, o, s, c) {
|
|
346
345
|
return this.enforceRateLimit(this.nearDepositAndBridge.name, [
|
|
@@ -348,13 +347,13 @@ var ye = class {
|
|
|
348
347
|
t,
|
|
349
348
|
n,
|
|
350
349
|
r
|
|
351
|
-
]),
|
|
350
|
+
]), fe(this, e, t, n, r, i, a, o, s, c);
|
|
352
351
|
}
|
|
353
352
|
async prooflessDeposit(e, t, n, r, i = !1) {
|
|
354
|
-
return l(
|
|
353
|
+
return l(b(e)) ? me(this, e, t, n, r, i) : K(this, e, t, n, r, i);
|
|
355
354
|
}
|
|
356
355
|
async prooflessDepositWithPublicFee(e, t, n, r, i) {
|
|
357
|
-
let a =
|
|
356
|
+
let a = b([e]);
|
|
358
357
|
return l(a) ? L(this, e, t, n, r, i) : q(this, a, e, t, n, r, i);
|
|
359
358
|
}
|
|
360
359
|
getSolanaProgram(e) {
|
|
@@ -372,24 +371,24 @@ var ye = class {
|
|
|
372
371
|
e,
|
|
373
372
|
t,
|
|
374
373
|
n
|
|
375
|
-
]), l(
|
|
374
|
+
]), l(b(e)) ? se(this, e, t, n, r, i, a) : X(this, e, t, n, r, i, a);
|
|
376
375
|
}
|
|
377
376
|
async withdraw(e, t, n, r, i, a, o) {
|
|
378
|
-
return l(
|
|
377
|
+
return l(b(e)) ? oe(this, e, t, n, i, a, o) : z(this, e, t, n, r, i, a, o);
|
|
379
378
|
}
|
|
380
379
|
async withdrawStuckUtxos(e, t) {
|
|
381
|
-
return
|
|
380
|
+
return ge(this, e, t);
|
|
382
381
|
}
|
|
383
382
|
async swap(e, t, n, r, i, a, o) {
|
|
384
|
-
return l(
|
|
383
|
+
return l(b(e)) ? this.swapSolana(e, t, r, i, a, o) : R(this, e, t, n, r, i, a, o);
|
|
385
384
|
}
|
|
386
385
|
async swapSolana(e, t, n, r, i, a) {
|
|
387
386
|
let o = JSON.parse(n), s = BigInt(o.swapperAccountSalt), { instructionLists: c, addressLookupTableAccount: l } = o.data;
|
|
388
|
-
return
|
|
387
|
+
return ce(this, e, t, s, c, l, r, i, a);
|
|
389
388
|
}
|
|
390
389
|
async actionReceive(e, t, n, r, i, a) {
|
|
391
390
|
if (!i) throw Error("subAccount is required");
|
|
392
|
-
return l(
|
|
391
|
+
return l(b(e)) ? Q(this, e[0], t[0], i, void 0, a) : G(this, e, t, n, r, i, a);
|
|
393
392
|
}
|
|
394
393
|
async actionPrivateWallet(e, t, n, r, i, a, o, s, c, l, u = !1, d, f, p) {
|
|
395
394
|
return this.enforceRateLimit(this.actionPrivateWallet.name, [
|
|
@@ -403,23 +402,23 @@ var ye = class {
|
|
|
403
402
|
s,
|
|
404
403
|
c,
|
|
405
404
|
p
|
|
406
|
-
]),
|
|
405
|
+
]), re(this, e, t, n, r, i, a, o, s, c, l, u, d, f, p);
|
|
407
406
|
}
|
|
408
407
|
async proxySwap(e, t, n, r, i, a, o, s, c = !1, u, d) {
|
|
409
|
-
return l(
|
|
408
|
+
return l(b(e)) ? ue(this, e, t, r, a, n, o, s, d) : J(this, e, t, n, r, i, a, o, s, c, u, d);
|
|
410
409
|
}
|
|
411
410
|
async proxyToPrivate(e, t, n, r, i, a, o) {
|
|
412
|
-
return l(
|
|
411
|
+
return l(b(e)) ? (this.enforceRateLimit(this.proxyToPrivate.name, [
|
|
413
412
|
e[0],
|
|
414
413
|
t[0],
|
|
415
414
|
n,
|
|
416
415
|
r
|
|
417
|
-
]),
|
|
416
|
+
]), Q(this, e[0], t[0], n, r, o)) : ie(this, e, t, r, i, a, n, o);
|
|
418
417
|
}
|
|
419
418
|
async proxySend(e, t, n, r, i, a, o) {
|
|
420
|
-
let s =
|
|
421
|
-
if (l(s)) return
|
|
422
|
-
let c =
|
|
419
|
+
let s = b(e);
|
|
420
|
+
if (l(s)) return le(this, e[0], t[0], n, r, o);
|
|
421
|
+
let c = j(this, s, e.map((e) => e.erc20TokenAddress), t, r), u = e.map((e, n) => ({
|
|
423
422
|
token: e,
|
|
424
423
|
amount: -1n * t[n]
|
|
425
424
|
}));
|
|
@@ -440,4 +439,4 @@ var ye = class {
|
|
|
440
439
|
}
|
|
441
440
|
};
|
|
442
441
|
//#endregion
|
|
443
|
-
export {
|
|
442
|
+
export { ve as Hinkal };
|
|
@@ -19,6 +19,8 @@ import { Idl, Program } from '@coral-xyz/anchor';
|
|
|
19
19
|
import { PublicKey } from '@solana/web3.js';
|
|
20
20
|
import { BridgeRecipient } from '../../types/bridging-tx.types';
|
|
21
21
|
import { NearBridgeParams, NearBridgeResult } from '../../types/near-intents.types';
|
|
22
|
+
import { DepositAndSendExtendedResult } from '../../types/scheduled-transactions.types';
|
|
23
|
+
import { ScheduledTransactionByIdResponse } from '../../API/scheduled-transactions-calls';
|
|
22
24
|
import { Utxo } from '../utxo/Utxo';
|
|
23
25
|
export interface IHinkal<ConnectorType = unknown> {
|
|
24
26
|
userKeys: UserKeys;
|
|
@@ -35,9 +37,6 @@ export interface IHinkal<ConnectorType = unknown> {
|
|
|
35
37
|
getBalances(chainId: number, passedShieldedPrivateKey: string, passedShieldedPublicKey: string, ethAddress: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean): Promise<Map<string, TokenBalance>>;
|
|
36
38
|
getTotalBalance(chainId: number, userKeys?: UserKeys, ethAddress?: string, resetCacheBefore?: boolean, updateTokensListBefore?: boolean, useBlockedUtxos?: boolean): Promise<TokenBalance[]>;
|
|
37
39
|
getStuckShieldedBalances(chainId: number, userKeys?: UserKeys, ethAddress?: string): Promise<TokenBalance[]>;
|
|
38
|
-
getSupportedPassportLinks(): string[];
|
|
39
|
-
checkAccessToken(chainId: number, accessKeyOverride?: string): Promise<boolean>;
|
|
40
|
-
checkExternalTokenLimitsUSD(chainId: number, tokenAddresses: string[], amounts: bigint[]): Promise<boolean>;
|
|
41
40
|
getSupportedChains(): number[];
|
|
42
41
|
getEthereumAddress(): Promise<string>;
|
|
43
42
|
getEthereumAddressByChain(chainId: number): Promise<string>;
|
|
@@ -53,7 +52,10 @@ export interface IHinkal<ConnectorType = unknown> {
|
|
|
53
52
|
depositForOther(erc20Tokens: ERC20Token[], amountChanges: bigint[], recepinetInfo: string, preEstimateGas?: boolean, returnTxData?: boolean, action?: AdminTransactionType): Promise<ethers.TransactionResponse | ethers.TransactionRequest | string | TronWebTypes.Transaction<TronWebTypes.TriggerSmartContract>>;
|
|
54
53
|
claimUtxo(erc20Token: ERC20Token, utxo: Utxo, feeStructureOverride?: FeeStructure, claimableSignature?: string): Promise<string>;
|
|
55
54
|
depositAndWithdraw(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<string>;
|
|
55
|
+
depositAndWithdrawExtended(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<DepositAndSendExtendedResult>;
|
|
56
56
|
depositAndBridge(erc20Token: ERC20Token, recipientBridges: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<string>;
|
|
57
|
+
depositAndBridgeExtended(erc20Token: ERC20Token, recipientBridges: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean): Promise<DepositAndSendExtendedResult>;
|
|
58
|
+
checkSendTransactionStatus(scheduleId: string): Promise<ScheduledTransactionByIdResponse>;
|
|
57
59
|
nearDepositAndBridge(erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], params: NearBridgeParams, txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string): Promise<NearBridgeResult>;
|
|
58
60
|
prooflessDeposit(erc20Tokens: ERC20Token[], amountChanges: bigint[], stealthAddressStructures?: StealthAddressStructure[], action?: AdminTransactionType, returnTxData?: boolean): Promise<string | ethers.TransactionRequest | TronWebTypes.Transaction<TronWebTypes.TriggerSmartContract>>;
|
|
59
61
|
prooflessDepositWithPublicFee(erc20Token: ERC20Token, amounts: bigint[], stealthAddressStructures: StealthAddressStructure[], feeAmount: bigint, action?: AdminTransactionType): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../API/API.cjs`),s=require(`../../constants/addresses.constants.cjs`),c=require(`../../error-handling/error-codes.constants.cjs`),l=require(`../../functions/utils/erc20tokenFunctions.cjs`),u=require(`../../functions/utils/time.utils.cjs`),d=require(`../utxo/Utxo.cjs`),f=require(`../../functions/utils/token-check.utils.cjs`),p=require(`../../functions/pre-transaction/constructAdminData.cjs`),m=require(`../../functions/pre-transaction/getFeeStructure.cjs`),h=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),g=require(`../../functions/utils/convertEmporiumOpToCallInfo.cjs`),_=require(`../../functions/utils/fees.utils.cjs`);require(`../../functions/utils/index.cjs`);const v=require(`../../functions/private-wallet/emporium.helpers.cjs`),y=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),b=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),x=require(`../../API/deposit-and-withdraw-status-calls.cjs`),S=require(`./hinkalDepositOnChainUtxos.cjs`);require(`../../functions/index.cjs`);var C=async(a,l,f,m,h,g,S,C,w,T,E)=>{if(m.length===0)throw Error(`No recipients to bridge`);let D=f.erc20TokenAddress,{contractData:O}=t.networkRegistry[l],{emporiumAddress:k}=O;if(!k)throw Error(`No Emporium Address`);let A=s.SWAP_ROUTER_ADDRESSES[e.ExternalActionId.Lifi][l];if(!A)throw Error(`LIFI not configured for chain ${l}`);let j=await a.getRandomRelay(l);if(!j)throw Error(c.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let M=await a.getEthereumAddressByChain(l),N=u.getCurrentTimeInSeconds().toString(),P=a.generateProofRemotely?5:1,F=[];for(let t=0;t<m.length;t+=P){let r=m.slice(t,t+P),s=await Promise.all(r.map(async({utxo:t,nativeUtxo:r,bridgeAmount:s,quote:c,temporarySubAccount:u,recipientAddress:m})=>{await o.API.addTemporaryWalletNonce(l,g,u.index);let b=c.nativeFee>0n&&!i.caseInsensitiveEqual(D,n.zeroAddress),x=[D],S=[-t.amount],C=[!1],w=new d.Utxo({amount:0n,erc20TokenAddress:D,nullifyingKey:a.userKeys.getShieldedPrivateKey(),timeStamp:N,...t.isNewStyle?{spendingPublicKey:a.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),E=[[t,w]],O=[[w]];if(b&&r){let e=new d.Utxo({amount:0n,erc20TokenAddress:n.zeroAddress,nullifyingKey:a.userKeys.getShieldedPrivateKey(),timeStamp:N,...r.isNewStyle?{spendingPublicKey:a.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}});x.push(n.zeroAddress),S.push(-r.amount),C.push(!1),E.push([r,e]),O.push([e])}let P=v.createLifiBridgeOps(a,l,u.ethAddress,A,D,t.amount,s,c),F=await _.calculateModifiedFeeStructure(l,f,s,h),I=p.constructAdminData(T,l,x,[-t.amount],M),[{zkCallData:L,circomData:R,dimData:z,commitmentValidationData:B},V]=await Promise.all([y.constructZkProof(a.merkleTreeHinkalByChain[l],E,O,a.userKeys,e.ExternalActionId.Emporium,k,P,a.generateProofRemotely,F,j??n.zeroAddress,l,C,void 0,void 0,u.privateKey),v.getAuthorizationDataIfNeeded(l,u.privateKey)]);return{zkCallData:L,dimData:z,circomData:R,commitmentValidationData:B,authorizationData:V,recipientAddress:m,adminData:I}}));F.push(...s)}await x.safeUpdateDepositAndWithdrawStatus({id:S,chainId:l,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let I=await b.transactCallRelayerBatch(l,F,g,C,w,E);return await x.safeUpdateDepositAndWithdrawStatus({id:S,chainId:l,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:I}),I},w=async(t,r,o,c,u,d,p,_,y=!0)=>{let b=r.erc20TokenAddress,x=f.validateAndGetChainId([r]),w=_?a.hashString(_):void 0,T=a.hashEthereumAddress(await t.getEthereumAddressByChain(x)),E=s.SWAP_ROUTER_ADDRESSES[e.ExternalActionId.Lifi][x];if(!E)throw Error(`LIFI router not configured`);let D;if(u)D=u;else{let r=o[0],i=v.createLifiBridgeOps(t,x,r.temporarySubAccount.ethAddress,E,b,r.bridgeAmount,r.bridgeAmount,r.quote).map(e=>g.convertEmporiumOpToCallInfo(e,r.temporarySubAccount.ethAddress,x));D=await m.getFeeStructure(x,b,[b],e.ExternalActionId.Emporium,i,n.PAY_SEND_VARIABLE_RATE)}let O={feeToken:D.feeToken,flatFee:0n,variableRate:0n},k=o.reduce((e,t)=>e+t.quote.nativeFee,0n)>0n&&!i.caseInsensitiveEqual(b,n.zeroAddress),A=o.map(e=>e.bridgeAmount),j=o.map(e=>e.recipientAddress),{userDepositedUtxos:M,statusId:N,depositTxHash:P}=await S.hinkalDepositOnChainUtxos(t,x,r,A,j,D,T,y),F=[];if(k){let e=l.getERC20Token(n.zeroAddress,x);if(!e)throw Error(`No native token`);let{userDepositedUtxos:r}=await S.hinkalDepositOnChainUtxos(t,x,e,o.map(e=>e.quote.nativeFee),j,O,T,y);F=r}return await h.waitForDepositedUtxosInMerkleTree(t,x,[...M,...F]),await C(t,x,r,o.map((e,t)=>({...e,utxo:M[t].utxo,nativeUtxo:k?F[t]?.utxo:void 0})),D,T,N,c,d,p,w)
|
|
1
|
+
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../API/API.cjs`),s=require(`../../constants/addresses.constants.cjs`),c=require(`../../error-handling/error-codes.constants.cjs`),l=require(`../../functions/utils/erc20tokenFunctions.cjs`),u=require(`../../functions/utils/time.utils.cjs`),d=require(`../utxo/Utxo.cjs`),f=require(`../../functions/utils/token-check.utils.cjs`),p=require(`../../functions/pre-transaction/constructAdminData.cjs`),m=require(`../../functions/pre-transaction/getFeeStructure.cjs`),h=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),g=require(`../../functions/utils/convertEmporiumOpToCallInfo.cjs`),_=require(`../../functions/utils/fees.utils.cjs`);require(`../../functions/utils/index.cjs`);const v=require(`../../functions/private-wallet/emporium.helpers.cjs`),y=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),b=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),x=require(`../../API/deposit-and-withdraw-status-calls.cjs`),S=require(`./hinkalDepositOnChainUtxos.cjs`);require(`../../functions/index.cjs`);var C=async(a,l,f,m,h,g,S,C,w,T,E)=>{if(m.length===0)throw Error(`No recipients to bridge`);let D=f.erc20TokenAddress,{contractData:O}=t.networkRegistry[l],{emporiumAddress:k}=O;if(!k)throw Error(`No Emporium Address`);let A=s.SWAP_ROUTER_ADDRESSES[e.ExternalActionId.Lifi][l];if(!A)throw Error(`LIFI not configured for chain ${l}`);let j=await a.getRandomRelay(l);if(!j)throw Error(c.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let M=await a.getEthereumAddressByChain(l),N=u.getCurrentTimeInSeconds().toString(),P=a.generateProofRemotely?5:1,F=[];for(let t=0;t<m.length;t+=P){let r=m.slice(t,t+P),s=await Promise.all(r.map(async({utxo:t,nativeUtxo:r,bridgeAmount:s,quote:c,temporarySubAccount:u,recipientAddress:m})=>{await o.API.addTemporaryWalletNonce(l,g,u.index);let b=c.nativeFee>0n&&!i.caseInsensitiveEqual(D,n.zeroAddress),x=[D],S=[-t.amount],C=[!1],w=new d.Utxo({amount:0n,erc20TokenAddress:D,nullifyingKey:a.userKeys.getShieldedPrivateKey(),timeStamp:N,...t.isNewStyle?{spendingPublicKey:a.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),E=[[t,w]],O=[[w]];if(b&&r){let e=new d.Utxo({amount:0n,erc20TokenAddress:n.zeroAddress,nullifyingKey:a.userKeys.getShieldedPrivateKey(),timeStamp:N,...r.isNewStyle?{spendingPublicKey:a.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}});x.push(n.zeroAddress),S.push(-r.amount),C.push(!1),E.push([r,e]),O.push([e])}let P=v.createLifiBridgeOps(a,l,u.ethAddress,A,D,t.amount,s,c),F=await _.calculateModifiedFeeStructure(l,f,s,h),I=p.constructAdminData(T,l,x,[-t.amount],M),[{zkCallData:L,circomData:R,dimData:z,commitmentValidationData:B},V]=await Promise.all([y.constructZkProof(a.merkleTreeHinkalByChain[l],E,O,a.userKeys,e.ExternalActionId.Emporium,k,P,a.generateProofRemotely,F,j??n.zeroAddress,l,C,void 0,void 0,u.privateKey),v.getAuthorizationDataIfNeeded(l,u.privateKey)]);return{zkCallData:L,dimData:z,circomData:R,commitmentValidationData:B,authorizationData:V,recipientAddress:m,adminData:I}}));F.push(...s)}await x.safeUpdateDepositAndWithdrawStatus({id:S,chainId:l,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let I=await b.transactCallRelayerBatch(l,F,g,C,w,E);return await x.safeUpdateDepositAndWithdrawStatus({id:S,chainId:l,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:I}),I},w=async(t,r,o,c,u,d,p,_,y=!0)=>{let b=r.erc20TokenAddress,x=f.validateAndGetChainId([r]),w=_?a.hashString(_):void 0,T=a.hashEthereumAddress(await t.getEthereumAddressByChain(x)),E=s.SWAP_ROUTER_ADDRESSES[e.ExternalActionId.Lifi][x];if(!E)throw Error(`LIFI router not configured`);let D;if(u)D=u;else{let r=o[0],i=v.createLifiBridgeOps(t,x,r.temporarySubAccount.ethAddress,E,b,r.bridgeAmount,r.bridgeAmount,r.quote).map(e=>g.convertEmporiumOpToCallInfo(e,r.temporarySubAccount.ethAddress,x));D=await m.getFeeStructure(x,b,[b],e.ExternalActionId.Emporium,i,n.PAY_SEND_VARIABLE_RATE)}let O={feeToken:D.feeToken,flatFee:0n,variableRate:0n},k=o.reduce((e,t)=>e+t.quote.nativeFee,0n)>0n&&!i.caseInsensitiveEqual(b,n.zeroAddress),A=o.map(e=>e.bridgeAmount),j=o.map(e=>e.recipientAddress),{userDepositedUtxos:M,statusId:N,depositTxHash:P}=await S.hinkalDepositOnChainUtxos(t,x,r,A,j,D,T,y),F=[];if(k){let e=l.getERC20Token(n.zeroAddress,x);if(!e)throw Error(`No native token`);let{userDepositedUtxos:r}=await S.hinkalDepositOnChainUtxos(t,x,e,o.map(e=>e.quote.nativeFee),j,O,T,y);F=r}return await h.waitForDepositedUtxosInMerkleTree(t,x,[...M,...F]),{depositTxHash:P,scheduleId:await C(t,x,r,o.map((e,t)=>({...e,utxo:M[t].utxo,nativeUtxo:k?F[t]?.utxo:void 0})),D,T,N,c,d,p,w)}};exports.hinkalDepositAndBridge=w;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { IHinkal } from './IHinkal';
|
|
2
|
-
import { AdminTransactionType, BridgeRecipient, ERC20Token } from '../../types';
|
|
2
|
+
import { AdminTransactionType, BridgeRecipient, DepositAndSendExtendedResult, ERC20Token } from '../../types';
|
|
3
3
|
import { FeeStructure } from '../../types/hinkal.types';
|
|
4
|
-
export declare const hinkalDepositAndBridge: (hinkal: IHinkal, erc20Token: ERC20Token, recipients: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean) => Promise<
|
|
4
|
+
export declare const hinkalDepositAndBridge: (hinkal: IHinkal, erc20Token: ERC20Token, recipients: BridgeRecipient[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean) => Promise<DepositAndSendExtendedResult>;
|
|
@@ -107,11 +107,14 @@ var E = async (n, o, s, d, m, g, _, v, T, E, D) => {
|
|
|
107
107
|
let { userDepositedUtxos: n } = await T(t, C, e, c.map((e) => e.quote.nativeFee), N, A, D, x);
|
|
108
108
|
L = n;
|
|
109
109
|
}
|
|
110
|
-
return await _(t, C, [...P, ...L]),
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
110
|
+
return await _(t, C, [...P, ...L]), {
|
|
111
|
+
depositTxHash: I,
|
|
112
|
+
scheduleId: await E(t, C, i, c.map((e, t) => ({
|
|
113
|
+
...e,
|
|
114
|
+
utxo: P[t].utxo,
|
|
115
|
+
nativeUtxo: j ? L[t]?.utxo : void 0
|
|
116
|
+
})), k, D, F, u, p, h, w)
|
|
117
|
+
};
|
|
115
118
|
};
|
|
116
119
|
//#endregion
|
|
117
120
|
export { D as hinkalDepositAndBridge };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../error-handling/error-codes.constants.cjs`),s=require(`../../functions/utils/time.utils.cjs`),c=require(`../utxo/Utxo.cjs`),l=require(`../../functions/utils/tron.utils.cjs`),u=require(`../../functions/utils/token-check.utils.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`),p=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),m=require(`../../functions/utils/fees.utils.cjs`),h=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),g=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),_=require(`../../API/deposit-and-withdraw-status-calls.cjs`),v=require(`./hinkalDepositOnChainUtxos.cjs`);require(`../../functions/index.cjs`);var y=async(e,a,u,f,p,v,y,b,x,S,C,w)=>{let T=t.isTronLike(a);if(f.length===0)throw Error(`userDepositedUtxos must not be empty`);let E=u.erc20TokenAddress,[D,O]=await Promise.all([e.getRandomRelay(a),e.getEthereumAddressByChain(a)]);if(!D)throw Error(o.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let k=s.getCurrentTimeInSeconds().toString(),A=e.generateProofRemotely&&!T?5:1,j=[],M=l.addressToHexFormat(O);for(let t=0;t<f.length;t+=A){let r=f.slice(t,t+A),o=await Promise.all(r.map(async({recipientAddress:r,utxo:o},s)=>{let f=t+s,g=l.addressToHexFormat(r),_=new c.Utxo({amount:0n,erc20TokenAddress:E,nullifyingKey:e.userKeys.getShieldedPrivateKey(),timeStamp:k,...o.isNewStyle?{spendingPublicKey:e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),y=[[i.caseInsensitiveEqual(o.erc20TokenAddress,E)?o:c.Utxo.createFrom(o,{erc20TokenAddress:E}),_]],b=[[_]],x={externalActionId:0n,externalAddress:g,externalActionMetadata:`0x00`},S=d.constructAdminData(C,a,[E],[-o.amount],M),w=await m.calculateModifiedFeeStructure(a,u,p[f],v),{zkCallData:O,circomData:A,dimData:j,commitmentValidationData:N}=await h.constructZkProof(e.merkleTreeHinkalByChain[a],y,b,e.userKeys,x.externalActionId,x.externalAddress,x.externalActionMetadata,e.generateProofRemotely,w,D??n.zeroAddress,a);return{zkCallData:O,dimData:j,circomData:A,commitmentValidationData:N,adminData:S,recipientAddress:r,tronProofSignature:await l.reorderZkCallData(T,O,j,A)}}));j.push(...o)}await _.safeUpdateDepositAndWithdrawStatus({id:b,chainId:a,hashedEthereumAddress:y,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let N=await g.transactCallRelayerBatch(a,j,y,x,S,w);return await _.safeUpdateDepositAndWithdrawStatus({id:b,chainId:a,hashedEthereumAddress:y,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:N}),N},b=async(t,n,r,i,o,s,c,d,m,h=!0)=>{let g=u.validateAndGetChainId([n]),_=m?a.hashString(m):void 0,b=n.erc20TokenAddress,x=a.hashEthereumAddress(l.addressToHexFormat(await t.getEthereumAddressByChain(g))),S=s??await f.getFeeStructure(g,b,[b],e.ExternalActionId.Transact,[],10n),{userDepositedUtxos:C,statusId:w,depositTxHash:T}=await v.hinkalDepositOnChainUtxos(t,g,n,r,i,S,x,h);return await p.waitForDepositedUtxosInMerkleTree(t,g,C),await y(t,g,n,C,r,S,x,w,o,c,d,_)
|
|
1
|
+
const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/caseInsensitive.utils.cjs`),a=require(`../../functions/utils/addresses.cjs`),o=require(`../../error-handling/error-codes.constants.cjs`),s=require(`../../functions/utils/time.utils.cjs`),c=require(`../utxo/Utxo.cjs`),l=require(`../../functions/utils/tron.utils.cjs`),u=require(`../../functions/utils/token-check.utils.cjs`),d=require(`../../functions/pre-transaction/constructAdminData.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`),p=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`),m=require(`../../functions/utils/fees.utils.cjs`),h=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),g=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),_=require(`../../API/deposit-and-withdraw-status-calls.cjs`),v=require(`./hinkalDepositOnChainUtxos.cjs`);require(`../../functions/index.cjs`);var y=async(e,a,u,f,p,v,y,b,x,S,C,w)=>{let T=t.isTronLike(a);if(f.length===0)throw Error(`userDepositedUtxos must not be empty`);let E=u.erc20TokenAddress,[D,O]=await Promise.all([e.getRandomRelay(a),e.getEthereumAddressByChain(a)]);if(!D)throw Error(o.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let k=s.getCurrentTimeInSeconds().toString(),A=e.generateProofRemotely&&!T?5:1,j=[],M=l.addressToHexFormat(O);for(let t=0;t<f.length;t+=A){let r=f.slice(t,t+A),o=await Promise.all(r.map(async({recipientAddress:r,utxo:o},s)=>{let f=t+s,g=l.addressToHexFormat(r),_=new c.Utxo({amount:0n,erc20TokenAddress:E,nullifyingKey:e.userKeys.getShieldedPrivateKey(),timeStamp:k,...o.isNewStyle?{spendingPublicKey:e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),y=[[i.caseInsensitiveEqual(o.erc20TokenAddress,E)?o:c.Utxo.createFrom(o,{erc20TokenAddress:E}),_]],b=[[_]],x={externalActionId:0n,externalAddress:g,externalActionMetadata:`0x00`},S=d.constructAdminData(C,a,[E],[-o.amount],M),w=await m.calculateModifiedFeeStructure(a,u,p[f],v),{zkCallData:O,circomData:A,dimData:j,commitmentValidationData:N}=await h.constructZkProof(e.merkleTreeHinkalByChain[a],y,b,e.userKeys,x.externalActionId,x.externalAddress,x.externalActionMetadata,e.generateProofRemotely,w,D??n.zeroAddress,a);return{zkCallData:O,dimData:j,circomData:A,commitmentValidationData:N,adminData:S,recipientAddress:r,tronProofSignature:await l.reorderZkCallData(T,O,j,A)}}));j.push(...o)}await _.safeUpdateDepositAndWithdrawStatus({id:b,chainId:a,hashedEthereumAddress:y,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let N=await g.transactCallRelayerBatch(a,j,y,x,S,w);return await _.safeUpdateDepositAndWithdrawStatus({id:b,chainId:a,hashedEthereumAddress:y,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:N}),N},b=async(t,n,r,i,o,s,c,d,m,h=!0)=>{let g=u.validateAndGetChainId([n]),_=m?a.hashString(m):void 0,b=n.erc20TokenAddress,x=a.hashEthereumAddress(l.addressToHexFormat(await t.getEthereumAddressByChain(g))),S=s??await f.getFeeStructure(g,b,[b],e.ExternalActionId.Transact,[],10n),{userDepositedUtxos:C,statusId:w,depositTxHash:T}=await v.hinkalDepositOnChainUtxos(t,g,n,r,i,S,x,h);return await p.waitForDepositedUtxosInMerkleTree(t,g,C),{depositTxHash:T,scheduleId:await y(t,g,n,C,r,S,x,w,o,c,d,_)}};exports.hinkalDepositAndWithdraw=b,exports.hinkalWithdrawBatch=y;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IHinkal } from './IHinkal';
|
|
2
|
-
import { AdminTransactionType, ERC20Token, RecipientUtxo } from '../../types';
|
|
2
|
+
import { AdminTransactionType, DepositAndSendExtendedResult, ERC20Token, RecipientUtxo } from '../../types';
|
|
3
3
|
import { FeeStructure } from '../../types/hinkal.types';
|
|
4
4
|
export declare const hinkalWithdrawBatch: (hinkal: IHinkal, chainId: number, erc20Token: ERC20Token, userDepositedUtxos: RecipientUtxo[], recipientAmounts: bigint[], feeStructure: FeeStructure, hashedEthereumAddress: string, statusId: string | undefined, txCompletionTime?: number, ref?: string, action?: AdminTransactionType, hashedDashboardAccountId?: string) => Promise<string>;
|
|
5
5
|
export declare const hinkalDepositAndWithdraw: (hinkal: IHinkal, erc20Token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, // Should be passed fee for only one withdraw transaction, multiplication happening in this function
|
|
6
|
-
ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean) => Promise<
|
|
6
|
+
ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, preEstimateGas?: boolean) => Promise<DepositAndSendExtendedResult>;
|
|
@@ -70,7 +70,10 @@ var x = async (e, a, o, f, m, h, b, x, S, C, w, T) => {
|
|
|
70
70
|
}), P;
|
|
71
71
|
}, S = async (t, n, r, i, s, c, l, d, p, g = !0) => {
|
|
72
72
|
let _ = f([n]), v = p ? o(p) : void 0, y = n.erc20TokenAddress, S = a(u(await t.getEthereumAddressByChain(_))), C = c ?? await m(_, y, [y], e.Transact, [], 10n), { userDepositedUtxos: w, statusId: T, depositTxHash: E } = await b(t, _, n, r, i, C, S, g);
|
|
73
|
-
return await h(t, _, w),
|
|
73
|
+
return await h(t, _, w), {
|
|
74
|
+
depositTxHash: E,
|
|
75
|
+
scheduleId: await x(t, _, n, w, r, C, S, T, s, l, d, v)
|
|
76
|
+
};
|
|
74
77
|
};
|
|
75
78
|
//#endregion
|
|
76
79
|
export { S as hinkalDepositAndWithdraw, x as hinkalWithdrawBatch };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../API/callNearIntentsAPI.cjs`),n=require(`../../constants/bridging.constants.cjs`),r=require(`../../functions/utils/time.utils.cjs`),i=require(`../../functions/utils/token-check.utils.cjs`),a=require(`../../functions/utils/nearIntents.utils.cjs`),o=require(`./hinkalDepositAndWithdraw.cjs`),s=require(`./hinkalSolanaDepositAndWithdraw.cjs`);var c=async(c,l,u,d,f,p,m,h,g,_)=>{if(u.length!==d.length)throw Error(`recipientAmounts and recipientAddresses length mismatch`);if(u.length===0)throw Error(`No recipients to bridge`);let v=i.validateAndGetChainId([l]),y=r.secondsToMs(p),b=new Date(y+n.NEAR_BRIDGE_QUOTE_DEADLINE_BUFFER_MS).toISOString(),x=await Promise.all(d.map(async(e,n)=>{let r=u[n],{quote:i}=await t.getNearIntentsQuote({dry:!1,swapType:`EXACT_INPUT`,slippageTolerance:f.slippageBps??100,originAsset:f.originAsset,depositType:`ORIGIN_CHAIN`,destinationAsset:f.destinationAsset,amount:r.toString(),recipient:e,recipientType:`DESTINATION_CHAIN`,refundTo:c.userKeys.getNearIntentsAccountId(),refundType:`INTENTS`,deadline:b});if(!i.depositAddress)throw Error(`NEAR Intents quote returned no deposit address for recipient ${e}`);if(i.deadline&&new Date(i.deadline).getTime()<y)throw Error(`Bridge quote expires before the scheduled execution time. Choose a sooner time.`);return{destinationRecipient:e,amount:r,depositAddress:i.depositAddress,quote:i}})),S=m??await a.buildNearBridgeFeeStructure(v,l,x[0].depositAddress),C=x.map(e=>e.amount),w=x.map(e=>e.depositAddress),T;return
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../API/callNearIntentsAPI.cjs`),n=require(`../../constants/bridging.constants.cjs`),r=require(`../../functions/utils/time.utils.cjs`),i=require(`../../functions/utils/token-check.utils.cjs`),a=require(`../../functions/utils/nearIntents.utils.cjs`),o=require(`./hinkalDepositAndWithdraw.cjs`),s=require(`./hinkalSolanaDepositAndWithdraw.cjs`);var c=async(c,l,u,d,f,p,m,h,g,_)=>{if(u.length!==d.length)throw Error(`recipientAmounts and recipientAddresses length mismatch`);if(u.length===0)throw Error(`No recipients to bridge`);let v=i.validateAndGetChainId([l]),y=r.secondsToMs(p),b=new Date(y+n.NEAR_BRIDGE_QUOTE_DEADLINE_BUFFER_MS).toISOString(),x=await Promise.all(d.map(async(e,n)=>{let r=u[n],{quote:i}=await t.getNearIntentsQuote({dry:!1,swapType:`EXACT_INPUT`,slippageTolerance:f.slippageBps??100,originAsset:f.originAsset,depositType:`ORIGIN_CHAIN`,destinationAsset:f.destinationAsset,amount:r.toString(),recipient:e,recipientType:`DESTINATION_CHAIN`,refundTo:c.userKeys.getNearIntentsAccountId(),refundType:`INTENTS`,deadline:b});if(!i.depositAddress)throw Error(`NEAR Intents quote returned no deposit address for recipient ${e}`);if(i.deadline&&new Date(i.deadline).getTime()<y)throw Error(`Bridge quote expires before the scheduled execution time. Choose a sooner time.`);return{destinationRecipient:e,amount:r,depositAddress:i.depositAddress,quote:i}})),S=m??await a.buildNearBridgeFeeStructure(v,l,x[0].depositAddress),C=x.map(e=>e.amount),w=x.map(e=>e.depositAddress),T;return e.isSolanaLike(v)?{depositTxHash:T}=await s.hinkalSolanaDepositAndWithdraw(c,l,C,w,p,S,h,g,_,x.map(e=>e.destinationRecipient)):{depositTxHash:T}=await o.hinkalDepositAndWithdraw(c,l,C,w,p,S,h,g,_),{depositTxHash:T,legs:x}};exports.hinkalNearDepositAndBridge=c;
|
|
@@ -34,7 +34,7 @@ var c = async (c, l, u, d, f, p, m, h, g, _) => {
|
|
|
34
34
|
quote: i
|
|
35
35
|
};
|
|
36
36
|
})), S = m ?? await a(v, l, x[0].depositAddress), C = x.map((e) => e.amount), w = x.map((e) => e.depositAddress), T;
|
|
37
|
-
return
|
|
37
|
+
return e(v) ? {depositTxHash: T} = await s(c, l, C, w, p, S, h, g, _, x.map((e) => e.destinationRecipient)) : {depositTxHash: T} = await o(c, l, C, w, p, S, h, g, _), {
|
|
38
38
|
depositTxHash: T,
|
|
39
39
|
legs: x
|
|
40
40
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/addresses.cjs`),a=require(`../../error-handling/error-codes.constants.cjs`),o=require(`../../functions/web3/etherFunctions.cjs`),s=require(`../crypto-keys/keys.cjs`),c=require(`../../functions/utils/time.utils.cjs`),l=require(`../utxo/Utxo.cjs`),u=require(`../../functions/utils/solanaMint.utils.cjs`),d=require(`../../functions/utils/token-check.utils.cjs`),f=require(`../../functions/snarkjs/common.snarkjs.cjs`),p=require(`../../functions/pre-transaction/solana.cjs`),m=require(`../../functions/pre-transaction/constructAdminData.cjs`),h=require(`../../functions/pre-transaction/sendV0Transaction.cjs`),g=require(`../../functions/pre-transaction/getFeeStructure.cjs`),_=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`);require(`../../functions/pre-transaction/index.cjs`);const v=require(`../../functions/utils/getUtxosFromReceiptSolana.cjs`),y=require(`../../functions/utils/fees.utils.cjs`);require(`../../functions/web3/index.cjs`);const b=require(`../../functions/snarkjs/constructSolanaZkProof.cjs`),x=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),S=require(`../../API/deposit-and-withdraw-status-calls.cjs`);require(`../../functions/index.cjs`);let C=require(`ethers`),w=require(`@solana/web3.js`),T=require(`@coral-xyz/anchor`);var E=(e,r,i,a)=>{let{hinkalIdl:c,hinkalAddress:l,originalDeployer:d}=t.networkRegistry[r].contractData;if(!c)throw Error(`No IDL configured for Solana program on this network`);if(!d)throw Error(`missing original deployer`);let m=e.userKeys.getShieldedPrivateKey(),h=e.getSolanaProgram(c),g=e.getSolanaPublicKey(),_=new w.PublicKey(d),v=new w.PublicKey(l),{mintPublicKey:y}=u.formatMintAddress(i.erc20TokenAddress),b=y.toString(),x=p.getStorageAccountPublicKey(v,_),S=p.getStorageVaultPublicKey(v,_),C=p.getMerkleAccountPublicKey(v,_),T=a.map(()=>p.buildAnchorStealthAddressStructure(f.calcStealthAddressStructure(s.UserKeys.findCorrectRandomization(o.randomBigInt(31),m),m,e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint))),E=b===n.solanaNativeAddress;return{program:h,publicKey:g,originalDeployer:_,mint:E?null:y,atasValue:E?null:void 0,storageAccount:x,storageVault:S,merkleAccount:C,amounts:a,anchorStealthStructures:T}},D=e=>e.program.methods.multiPaymentDeposit(e.amounts.map(e=>new T.BN(e.toString())),e.anchorStealthStructures,!0).accounts({mint:e.mint,signer:e.publicKey,signerAta:e.atasValue,originalDeployer:e.originalDeployer,storageAccount:e.storageAccount,storageVault:e.storageVault,merkleAccount:e.merkleAccount,storageVaultAta:e.atasValue}),O=async(e,t,n,i,a,o,s)=>{let c=i.map(e=>e+y.calculateTotalFee(e,o)),l=E(e,t,n,c),d=(await S.updateDepositAndWithdrawStatus({chainId:t,hashedEthereumAddress:s,phase:r.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0,f=await D(l).rpc(),p=await l.program.provider.connection.getLatestBlockhash();await l.program.provider.connection.confirmTransaction({blockhash:p.blockhash,lastValidBlockHeight:p.lastValidBlockHeight,signature:f},`finalized`);let m=await h.fetchSolanaTransaction(l.program.provider.connection,f,`finalized`);if(!m)throw Error(`Transaction missing`);await S.safeUpdateDepositAndWithdrawStatus({id:d,chainId:t,hashedEthereumAddress:s,phase:r.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:f});let{compressedAddress:g}=u.formatMintAddress(n.erc20TokenAddress),_=v.getOnChainUtxosFromReceiptSolana(m,l.program,e.userKeys,g),b=[],x=[..._];return a.forEach((e,t)=>{let n=c[t],r=x.find(e=>e.amount===n);if(!r)throw Error(`Could not find newly created UTXO with amount ${n} for recipient ${e}.`);b.push({recipientAddress:e,utxo:r}),x.splice(x.indexOf(r),1)}),{userDepositedUtxos:b,depositTxHash:f,statusId:d}},k=async(e,i,d,p,h,g,_,v,w,T,E,D,O)=>{let k=d.erc20TokenAddress;if(p.length===0)throw Error(`userDepositedUtxos must not be empty`);let{originalDeployer:A}=t.networkRegistry[i].contractData;if(!A)throw Error(`missing data`);let j=await e.getRandomRelay(i,!0);if(!j)throw Error(a.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let M=c.getCurrentTimeInSeconds().toString(),N=e.generateProofRemotely?5:1,P=[];for(let t=0;t<p.length;t+=N){let r=p.slice(t,t+N),a=await Promise.all(r.map(async({recipientAddress:t,utxo:r},a)=>{let{compressedAddress:c}=u.formatMintAddress(n.solanaNativeAddress),p=new l.Utxo({amount:0n,mintAddress:k,erc20TokenAddress:c,nullifyingKey:e.userKeys.getShieldedPrivateKey(),timeStamp:M,...r.isNewStyle?{spendingPublicKey:e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),g=[r,p],v=[p],x=s.UserKeys.findCorrectRandomization(o.randomBigInt(31),e.userKeys.getShieldedPrivateKey()),S={tokenNumber:1,nullifierAmount:g.length,outputAmount:v.length},w=f.calcEncryptedOutputs([v])[0][0],T=Array.from(C.ethers.getBytes(w)),D=await y.calculateModifiedFeeStructure(i,d,_[a],h),A=m.constructAdminData(E,i,[k],[_[a]],await e.getEthereumAddress()),{proofAArr:N,proofBArr:P,proofCArr:F,publicInputsArr:I,commitmentValidationData:L}=await b.constructSolanaZkProof(e.generateProofRemotely,e.merkleTreeHinkalByChain[i],e.userKeys,[k],[g],[v],x,D.flatFee,D.variableRate,t,j,S,[T],i),R={recipient:t,mint:k===`11111111111111111111111111111111`?void 0:k};return{relayAddress:j,functionName:`transact`,chainId:i,recipientAmount:_[a].toString(),args:{proofAArr:N,proofBArr:P,proofCArr:F,publicInputsArr:I,encryptedOutputs:[T],relayerFee:D.flatFee.toString(),dimensions:S},accounts:R,adminData:A,commitmentValidationData:L,displayRecipient:O?.[a]}}));P.push(...a)}await S.safeUpdateDepositAndWithdrawStatus({id:v,chainId:i,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let F=await x.solanaTransactCallRelayerBatch(i,P,g,w,T,D);return await S.safeUpdateDepositAndWithdrawStatus({id:v,chainId:i,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:F}),F},A=async(t,n,r,a,o,s,c,l,u,f)=>{let p=d.validateAndGetChainId([n]),m=n.erc20TokenAddress,h=i.hashEthereumAddress(await t.getEthereumAddressByChain(p)),v=u?i.hashString(u):void 0,y=s??await g.getFeeStructure(p,m,[m],e.ExternalActionId.Transact,[],5n),{userDepositedUtxos:b,depositTxHash:x,statusId:S}=await O(t,p,n,r,a,y,h);return await _.waitForDepositedUtxosInMerkleTree(t,p,b),await k(t,p,n,b,y,h,r,S,o,c,l,v,f)
|
|
1
|
+
require(`../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../types/external-action.types.cjs`),t=require(`../../constants/chains.constants.cjs`),n=require(`../../constants/protocol.constants.cjs`),r=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const i=require(`../../functions/utils/addresses.cjs`),a=require(`../../error-handling/error-codes.constants.cjs`),o=require(`../../functions/web3/etherFunctions.cjs`),s=require(`../crypto-keys/keys.cjs`),c=require(`../../functions/utils/time.utils.cjs`),l=require(`../utxo/Utxo.cjs`),u=require(`../../functions/utils/solanaMint.utils.cjs`),d=require(`../../functions/utils/token-check.utils.cjs`),f=require(`../../functions/snarkjs/common.snarkjs.cjs`),p=require(`../../functions/pre-transaction/solana.cjs`),m=require(`../../functions/pre-transaction/constructAdminData.cjs`),h=require(`../../functions/pre-transaction/sendV0Transaction.cjs`),g=require(`../../functions/pre-transaction/getFeeStructure.cjs`),_=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`);require(`../../functions/pre-transaction/index.cjs`);const v=require(`../../functions/utils/getUtxosFromReceiptSolana.cjs`),y=require(`../../functions/utils/fees.utils.cjs`);require(`../../functions/web3/index.cjs`);const b=require(`../../functions/snarkjs/constructSolanaZkProof.cjs`),x=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),S=require(`../../API/deposit-and-withdraw-status-calls.cjs`);require(`../../functions/index.cjs`);let C=require(`ethers`),w=require(`@solana/web3.js`),T=require(`@coral-xyz/anchor`);var E=(e,r,i,a)=>{let{hinkalIdl:c,hinkalAddress:l,originalDeployer:d}=t.networkRegistry[r].contractData;if(!c)throw Error(`No IDL configured for Solana program on this network`);if(!d)throw Error(`missing original deployer`);let m=e.userKeys.getShieldedPrivateKey(),h=e.getSolanaProgram(c),g=e.getSolanaPublicKey(),_=new w.PublicKey(d),v=new w.PublicKey(l),{mintPublicKey:y}=u.formatMintAddress(i.erc20TokenAddress),b=y.toString(),x=p.getStorageAccountPublicKey(v,_),S=p.getStorageVaultPublicKey(v,_),C=p.getMerkleAccountPublicKey(v,_),T=a.map(()=>p.buildAnchorStealthAddressStructure(f.calcStealthAddressStructure(s.UserKeys.findCorrectRandomization(o.randomBigInt(31),m),m,e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint))),E=b===n.solanaNativeAddress;return{program:h,publicKey:g,originalDeployer:_,mint:E?null:y,atasValue:E?null:void 0,storageAccount:x,storageVault:S,merkleAccount:C,amounts:a,anchorStealthStructures:T}},D=e=>e.program.methods.multiPaymentDeposit(e.amounts.map(e=>new T.BN(e.toString())),e.anchorStealthStructures,!0).accounts({mint:e.mint,signer:e.publicKey,signerAta:e.atasValue,originalDeployer:e.originalDeployer,storageAccount:e.storageAccount,storageVault:e.storageVault,merkleAccount:e.merkleAccount,storageVaultAta:e.atasValue}),O=async(e,t,n,i,a,o,s)=>{let c=i.map(e=>e+y.calculateTotalFee(e,o)),l=E(e,t,n,c),d=(await S.updateDepositAndWithdrawStatus({chainId:t,hashedEthereumAddress:s,phase:r.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0,f=await D(l).rpc(),p=await l.program.provider.connection.getLatestBlockhash();await l.program.provider.connection.confirmTransaction({blockhash:p.blockhash,lastValidBlockHeight:p.lastValidBlockHeight,signature:f},`finalized`);let m=await h.fetchSolanaTransaction(l.program.provider.connection,f,`finalized`);if(!m)throw Error(`Transaction missing`);await S.safeUpdateDepositAndWithdrawStatus({id:d,chainId:t,hashedEthereumAddress:s,phase:r.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:f});let{compressedAddress:g}=u.formatMintAddress(n.erc20TokenAddress),_=v.getOnChainUtxosFromReceiptSolana(m,l.program,e.userKeys,g),b=[],x=[..._];return a.forEach((e,t)=>{let n=c[t],r=x.find(e=>e.amount===n);if(!r)throw Error(`Could not find newly created UTXO with amount ${n} for recipient ${e}.`);b.push({recipientAddress:e,utxo:r}),x.splice(x.indexOf(r),1)}),{userDepositedUtxos:b,depositTxHash:f,statusId:d}},k=async(e,i,d,p,h,g,_,v,w,T,E,D,O)=>{let k=d.erc20TokenAddress;if(p.length===0)throw Error(`userDepositedUtxos must not be empty`);let{originalDeployer:A}=t.networkRegistry[i].contractData;if(!A)throw Error(`missing data`);let j=await e.getRandomRelay(i,!0);if(!j)throw Error(a.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let M=c.getCurrentTimeInSeconds().toString(),N=e.generateProofRemotely?5:1,P=[];for(let t=0;t<p.length;t+=N){let r=p.slice(t,t+N),a=await Promise.all(r.map(async({recipientAddress:t,utxo:r},a)=>{let{compressedAddress:c}=u.formatMintAddress(n.solanaNativeAddress),p=new l.Utxo({amount:0n,mintAddress:k,erc20TokenAddress:c,nullifyingKey:e.userKeys.getShieldedPrivateKey(),timeStamp:M,...r.isNewStyle?{spendingPublicKey:e.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,isNewStyle:!0}:{isNewStyle:!1}}),g=[r,p],v=[p],x=s.UserKeys.findCorrectRandomization(o.randomBigInt(31),e.userKeys.getShieldedPrivateKey()),S={tokenNumber:1,nullifierAmount:g.length,outputAmount:v.length},w=f.calcEncryptedOutputs([v])[0][0],T=Array.from(C.ethers.getBytes(w)),D=await y.calculateModifiedFeeStructure(i,d,_[a],h),A=m.constructAdminData(E,i,[k],[_[a]],await e.getEthereumAddress()),{proofAArr:N,proofBArr:P,proofCArr:F,publicInputsArr:I,commitmentValidationData:L}=await b.constructSolanaZkProof(e.generateProofRemotely,e.merkleTreeHinkalByChain[i],e.userKeys,[k],[g],[v],x,D.flatFee,D.variableRate,t,j,S,[T],i),R={recipient:t,mint:k===`11111111111111111111111111111111`?void 0:k};return{relayAddress:j,functionName:`transact`,chainId:i,recipientAmount:_[a].toString(),args:{proofAArr:N,proofBArr:P,proofCArr:F,publicInputsArr:I,encryptedOutputs:[T],relayerFee:D.flatFee.toString(),dimensions:S},accounts:R,adminData:A,commitmentValidationData:L,displayRecipient:O?.[a]}}));P.push(...a)}await S.safeUpdateDepositAndWithdrawStatus({id:v,chainId:i,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let F=await x.solanaTransactCallRelayerBatch(i,P,g,w,T,D);return await S.safeUpdateDepositAndWithdrawStatus({id:v,chainId:i,hashedEthereumAddress:g,phase:r.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:F}),F},A=async(t,n,r,a,o,s,c,l,u,f)=>{let p=d.validateAndGetChainId([n]),m=n.erc20TokenAddress,h=i.hashEthereumAddress(await t.getEthereumAddressByChain(p)),v=u?i.hashString(u):void 0,y=s??await g.getFeeStructure(p,m,[m],e.ExternalActionId.Transact,[],5n),{userDepositedUtxos:b,depositTxHash:x,statusId:S}=await O(t,p,n,r,a,y,h);return await _.waitForDepositedUtxosInMerkleTree(t,p,b),{depositTxHash:x,scheduleId:await k(t,p,n,b,y,h,r,S,o,c,l,v,f)}};exports.buildMultiPaymentDepositBuilder=D,exports.buildMultiPaymentDepositSetup=E,exports.hinkalSolanaDepositAndWithdraw=A,exports.hinkalSolanaWithdrawBatch=k;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FeeStructure } from '../../types/hinkal.types';
|
|
2
2
|
import { IHinkal } from './IHinkal';
|
|
3
3
|
import { PublicKey } from '@solana/web3.js';
|
|
4
|
-
import { AdminTransactionType, RecipientUtxo } from '../../types';
|
|
4
|
+
import { AdminTransactionType, DepositAndSendExtendedResult, RecipientUtxo } from '../../types';
|
|
5
5
|
import { ERC20Token } from '../../types/token.types';
|
|
6
6
|
export declare const buildMultiPaymentDepositSetup: (hinkal: IHinkal, chainId: number, token: ERC20Token, amounts: bigint[]) => {
|
|
7
7
|
program: import('@coral-xyz/anchor').Program<import('@coral-xyz/anchor').Idl>;
|
|
@@ -21,4 +21,4 @@ export declare const buildMultiPaymentDepositBuilder: (setup: MultiPaymentDeposi
|
|
|
21
21
|
}, import('@coral-xyz/anchor/dist/cjs/idl').IdlInstructionAccountItem>;
|
|
22
22
|
export declare const hinkalSolanaWithdrawBatch: (hinkal: IHinkal, chainId: number, token: ERC20Token, userDepositedUtxos: RecipientUtxo[], feeStructure: FeeStructure, hashedEthereumAddress: string, recipientAmounts: bigint[], statusId: string | undefined, txCompletionTime?: number, ref?: string, action?: AdminTransactionType, hashedDashboardAccountId?: string, displayRecipients?: string[]) => Promise<string>;
|
|
23
23
|
export declare const hinkalSolanaDepositAndWithdraw: (hinkal: IHinkal, token: ERC20Token, recipientAmounts: bigint[], recipientAddresses: string[], txCompletionTime?: number, feeStructureOverride?: FeeStructure, // Should be passed fee for only one withdraw transaction, multiplication happening in this function
|
|
24
|
-
ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, displayRecipients?: string[]) => Promise<
|
|
24
|
+
ref?: string, action?: AdminTransactionType, dashboardAccountId?: string, displayRecipients?: string[]) => Promise<DepositAndSendExtendedResult>;
|
|
@@ -154,7 +154,10 @@ var N = (e, r, i, a) => {
|
|
|
154
154
|
}), F;
|
|
155
155
|
}, L = async (t, n, r, o, s, c, l, u, d, p) => {
|
|
156
156
|
let m = f([n]), h = n.erc20TokenAddress, g = i(await t.getEthereumAddressByChain(m)), _ = d ? a(d) : void 0, v = c ?? await x(m, h, [h], e.Transact, [], 5n), { userDepositedUtxos: y, depositTxHash: b, statusId: C } = await F(t, m, n, r, o, v, g);
|
|
157
|
-
return await S(t, m, y),
|
|
157
|
+
return await S(t, m, y), {
|
|
158
|
+
depositTxHash: b,
|
|
159
|
+
scheduleId: await I(t, m, n, y, v, g, r, C, s, l, u, _, p)
|
|
160
|
+
};
|
|
158
161
|
};
|
|
159
162
|
//#endregion
|
|
160
163
|
export { P as buildMultiPaymentDepositBuilder, N as buildMultiPaymentDepositSetup, L as hinkalSolanaDepositAndWithdraw, I as hinkalSolanaWithdrawBatch };
|