@hinkal/common 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/assets/snarkjsWorkerLauncher-SrStwJvX.js +1 -0
- package/assets/snarkjsWorkerLogic-DtIjisbE.js +132 -0
- package/assets/utxoWorkerLauncher-CIBeBAML.js +1 -0
- package/assets/utxoWorkerLogic-C8R4GSaf.js +199 -0
- package/assets/zkProofWorkerLauncher-DfwteloJ.js +1 -0
- package/assets/zkProofWorkerLogic-CY9y6rOV.js +199 -0
- package/common/src/constants/vite.constants.cjs +1 -1
- package/common/src/constants/vite.constants.mjs +23 -5
- package/common/src/crypto/index.cjs +1 -1
- package/common/src/crypto/index.d.ts +0 -1
- package/common/src/crypto/index.mjs +0 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaClaimUtxo.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaClaimUtxo.mjs +50 -97
- package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.mjs +90 -128
- package/common/src/data-structures/Hinkal/hinkalSolanaSwap.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaSwap.mjs +56 -110
- package/common/src/data-structures/Hinkal/hinkalSolanaTransact.cjs +1 -0
- package/common/src/data-structures/Hinkal/hinkalSolanaTransact.d.ts +3 -0
- package/common/src/data-structures/Hinkal/hinkalSolanaTransact.mjs +117 -0
- package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.d.ts +2 -31
- package/common/src/data-structures/Hinkal/hinkalSolanaTransfer.mjs +45 -121
- package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalSolanaWithdraw.mjs +41 -83
- package/common/src/data-structures/Hinkal/hinkalTransact.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalTransact.mjs +41 -42
- package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdrawStuckUtxos.mjs +106 -125
- package/common/src/data-structures/IndexedDB/pay-activity-db.cjs +1 -1
- package/common/src/data-structures/IndexedDB/pay-activity-db.mjs +43 -1
- package/common/src/functions/index.cjs +1 -1
- package/common/src/functions/index.mjs +0 -1
- package/common/src/functions/pre-transaction/ensureAmountChanges.cjs +1 -1
- package/common/src/functions/pre-transaction/ensureAmountChanges.mjs +3 -10
- package/common/src/functions/pre-transaction/outputUtxoProcessing.cjs +1 -1
- package/common/src/functions/pre-transaction/outputUtxoProcessing.d.ts +1 -0
- package/common/src/functions/pre-transaction/outputUtxoProcessing.mjs +13 -9
- package/common/src/functions/snarkjs/constructSolanaZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructSolanaZkProof.d.ts +1 -1
- package/common/src/functions/snarkjs/constructSolanaZkProof.mjs +35 -35
- package/common/src/functions/snarkjs/constructTxEnclave.cjs +1 -1
- package/common/src/functions/snarkjs/constructTxEnclave.d.ts +2 -0
- package/common/src/functions/snarkjs/constructTxEnclave.mjs +40 -40
- package/common/src/functions/utils/enum.utils.cjs +1 -0
- package/common/src/functions/utils/enum.utils.mjs +12 -0
- package/common/src/functions/utils/index.cjs +1 -1
- package/common/src/functions/utils/index.mjs +0 -1
- package/common/src/types/index.cjs +1 -1
- package/common/src/types/index.d.ts +1 -0
- package/common/src/types/index.mjs +1 -0
- package/common/src/types/pay-activities.types.d.ts +18 -3
- package/common/src/types/solana-transact.types.cjs +1 -0
- package/common/src/types/solana-transact.types.d.ts +35 -0
- package/common/src/types/solana-transact.types.mjs +6 -0
- package/common/src/webworker/logError-Dex6ch32.js +2 -0
- package/common/src/webworker/package.json +1 -1
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/snarkjsWorker/snarkjsWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/snarkjsWorkerNode.cjs +1 -1
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/utxoWorker/utxoWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/utxoWorkerNode.cjs +1 -1
- package/common/src/webworker/viteWorkerURL.constant.cjs +1 -28
- package/common/src/webworker/viteWorkerURL.constant.mjs +13 -27
- package/common/src/webworker/workerProxy-BuJUMCQ4.js +1 -0
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.cjs +1 -1
- package/common/src/webworker/zkProofWorker/zkProofWorkerLauncher.ts?worker&url.mjs +1 -1
- package/common/src/webworker/zkProofWorkerNode.cjs +1 -1
- package/package.json +12 -12
- package/common/src/crypto/ecdh-dual-path.cjs +0 -1
- package/common/src/crypto/ecdh-dual-path.d.ts +0 -13
- package/common/src/crypto/ecdh-dual-path.mjs +0 -6
- package/common/src/webworker/logError-CxZzSALU.js +0 -2
- package/common/src/webworker/workerProxy-swwPYw6e.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const e=require(`../functions/utils/enum.utils.cjs`);var t=function(e){return e.DEVELOPMENT=`development`,e.PLAYGROUND=`playground`,e.PRODUCTION=`production`,e.STAGING=`staging`,e}({}),n={[t.DEVELOPMENT]:[`localhost`,`192.`,`127.`],[t.PLAYGROUND]:[`playground`],[t.STAGING]:[`working`,`staging`]},r=typeof process<`u`&&process?.release?.name===`node`,i=typeof process<`u`&&process.versions!=null&&process.versions.node!=null,a=typeof window<`u`&&window?.location?.protocol===`chrome-extension:`;function o(e,t){return t.some(t=>e.includes(t))}var s=()=>(require(`dotenv`).config({path:`DOTENV_OVERRIDE`in process.env?process.env.DOTENV_OVERRIDE:void 0}),process.env.DEPLOYMENT_MODE?.startsWith(`production`)?t.PRODUCTION:e.toEnumValue(t,process.env.DEPLOYMENT_MODE)||t.DEVELOPMENT),c=(()=>{if(!r&&typeof window>`u`)return;if(r)return s();if(window?.location?.protocol===`chrome-extension:`)return e.toEnumValue(t,WALLET_DEPLOYMENT_MODE)||t.STAGING;let i=window?.location?.host;return i?o(i,n[t.DEVELOPMENT])?t.DEVELOPMENT:o(i,n[t.PLAYGROUND])?t.PLAYGROUND:o(i,n[t.STAGING])?t.STAGING:t.PRODUCTION:t.PRODUCTION})(),l=c===t.DEVELOPMENT,u=c===t.PLAYGROUND,d=c===t.STAGING,f=d||l||u,p=typeof navigator<`u`&&navigator.product===`ReactNative`,m=f||r&&c===t.PRODUCTION;exports.DEPLOYMENT_MODE=t,exports.deploymentMode=c,exports.isDevelopment=l,exports.isExtension=a,exports.isNode=i,exports.isNotClientProduction=m,exports.isNotProduction=f,exports.isPlayground=u,exports.isReactNative=p,exports.isStaging=d;
|
|
@@ -1,8 +1,26 @@
|
|
|
1
|
+
import { __require as e } from "../../../_virtual/_rolldown/runtime.mjs";
|
|
2
|
+
import { toEnumValue as t } from "../functions/utils/enum.utils.mjs";
|
|
1
3
|
//#region libs/shared/common/src/constants/vite.constants.ts
|
|
2
|
-
var
|
|
4
|
+
var n = /* @__PURE__ */ function(e) {
|
|
3
5
|
return e.DEVELOPMENT = "development", e.PLAYGROUND = "playground", e.PRODUCTION = "production", e.STAGING = "staging", e;
|
|
4
|
-
}({})
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
}({}), r = {
|
|
7
|
+
[n.DEVELOPMENT]: [
|
|
8
|
+
"localhost",
|
|
9
|
+
"192.",
|
|
10
|
+
"127."
|
|
11
|
+
],
|
|
12
|
+
[n.PLAYGROUND]: ["playground"],
|
|
13
|
+
[n.STAGING]: ["working", "staging"]
|
|
14
|
+
}, i = typeof process < "u" && process?.release?.name === "node", a = typeof process < "u" && process.versions != null && process.versions.node != null, o = typeof window < "u" && window?.location?.protocol === "chrome-extension:";
|
|
15
|
+
function s(e, t) {
|
|
16
|
+
return t.some((t) => e.includes(t));
|
|
17
|
+
}
|
|
18
|
+
var c = () => (e("dotenv").config({ path: "DOTENV_OVERRIDE" in process.env ? process.env.DOTENV_OVERRIDE : void 0 }), process.env.DEPLOYMENT_MODE?.startsWith("production") ? n.PRODUCTION : t(n, process.env.DEPLOYMENT_MODE) || n.DEVELOPMENT), l = (() => {
|
|
19
|
+
if (!i && typeof window > "u") return;
|
|
20
|
+
if (i) return c();
|
|
21
|
+
if (window?.location?.protocol === "chrome-extension:") return t(n, WALLET_DEPLOYMENT_MODE) || n.STAGING;
|
|
22
|
+
let e = window?.location?.host;
|
|
23
|
+
return e ? s(e, r[n.DEVELOPMENT]) ? n.DEVELOPMENT : s(e, r[n.PLAYGROUND]) ? n.PLAYGROUND : s(e, r[n.STAGING]) ? n.STAGING : n.PRODUCTION : n.PRODUCTION;
|
|
24
|
+
})(), u = l === n.DEVELOPMENT, d = l === n.PLAYGROUND, f = l === n.STAGING, p = f || u || d, m = typeof navigator < "u" && navigator.product === "ReactNative", h = p || i && l === n.PRODUCTION;
|
|
7
25
|
//#endregion
|
|
8
|
-
export {
|
|
26
|
+
export { n as DEPLOYMENT_MODE, l as deploymentMode, u as isDevelopment, o as isExtension, a as isNode, h as isNotClientProduction, p as isNotProduction, d as isPlayground, m as isReactNative, f as isStaging };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`./poseidon.cjs`),require(`./babyJub.cjs`),require(`./eddsa.cjs`),require(`./ecdh-sealed-keys.cjs`),require(`./preProcessing.cjs`),require(`./ecdh.cjs`)
|
|
1
|
+
require(`./poseidon.cjs`),require(`./babyJub.cjs`),require(`./eddsa.cjs`),require(`./ecdh-sealed-keys.cjs`),require(`./preProcessing.cjs`),require(`./ecdh.cjs`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../error-handling/error-codes.constants.cjs`),r=require(
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../error-handling/error-codes.constants.cjs`),r=require(`../crypto-keys/keys.cjs`),i=require(`../utxo/Utxo.cjs`),a=require(`../../types/external-action.types.cjs`),o=require(`../../types/solana-transact.types.cjs`);require(`../../types/index.cjs`);const s=require(`../../functions/utils/token-check.utils.cjs`),c=require(`../../functions/pre-transaction/getFeeStructure.cjs`),l=require(`./hinkalSolanaTransact.cjs`);var u=async(u,d,f,p,m)=>{let h=s.validateAndGetChainId([d]),g=d.erc20TokenAddress;if(f.getTokenAddress(h)!==g)throw Error(`Off-chain UTXO token mismatch`);let _=m?new r.UserKeys(m):new r.UserKeys(f.nullifyingKey,f.nullifyingKey);if(!f.nullifyingKey&&!m)throw Error(`Claimable UTXO nullifyingKey is missing`);let v=_.getShieldedPrivateKey();if(f.nullifyingKey&&f.nullifyingKey!==v)throw Error(`Claimable UTXO key mismatch`);let{originalDeployer:y}=e.networkRegistry[h].contractData;if(!y)throw Error(`missing data`);let b=i.Utxo.createFrom(f,{nullifyingKey:v}),x=p??await c.getFeeStructure(h,g,[g],a.ExternalActionId.Transact,void 0,void 0,{mintTo:g,nullifierCount:1,rootInsertCount:2});if(x.feeToken!==g)throw Error(`Claim fee token mismatch: fee must be paid from claimed UTXO token`);let S=x.variableRate>0n?x.variableRate:t.HINKAL_PRIVATE_SEND_VARIABLE_RATE;if(b.amount<=x.flatFee)throw Error(n.transactionErrorCodes.INSUFFICIENT_FUNDS_TO_TRANSACT);let C=b.amount-x.flatFee,w=C*S/10000n,T=C-w;if(T<=0n)throw Error(n.transactionErrorCodes.RECIPIENT_AMOUNT_INVALID);let E=x.flatFee+w,D=u.getRecipientInfo(),[O,k,A,,,j]=D.split(`,`);if(!k||!A||!O||!j)throw Error(`Invalid recipient info`);let M=new i.Utxo({amount:0n,erc20TokenAddress:b.erc20TokenAddress,mintAddress:b.mintAddress,nullifyingKey:_.getShieldedPrivateKey(),spendingPublicKey:_.getSpendingKeyPair().pubSpendingBJJPoint}),N=await u.getRandomRelay(h,!0);if(!N)throw Error(n.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let P={recipient:N,mint:g===`11111111111111111111111111111111`?void 0:g};return l.hinkalSolanaTransact(u,{chainId:h,mintAddresses:[g],amountChanges:[-(T+E)],relayAddress:N,recipient:t.solanaNativeAddress,signer:N,functionName:`transfer`,accounts:P,relayerFee:E,recipientAddress:D,recipientAmounts:[T],inputUtxos:[[b,M]],userKeys:_,submit:{mode:o.SolanaSubmitMode.Relayer}})};exports.hinkalSolanaClaimUtxo=u;
|
|
@@ -1,111 +1,64 @@
|
|
|
1
1
|
import { networkRegistry as e } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import { HINKAL_PRIVATE_SEND_VARIABLE_RATE as t, solanaNativeAddress as n } from "../../constants/protocol.constants.mjs";
|
|
3
3
|
import { transactionErrorCodes as r } from "../../error-handling/error-codes.constants.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { ExternalActionId as c } from "../../types/external-action.types.mjs";
|
|
4
|
+
import { UserKeys as i } from "../crypto-keys/keys.mjs";
|
|
5
|
+
import { Utxo as a } from "../utxo/Utxo.mjs";
|
|
6
|
+
import { ExternalActionId as o } from "../../types/external-action.types.mjs";
|
|
7
|
+
import { SolanaSubmitMode as s } from "../../types/solana-transact.types.mjs";
|
|
9
8
|
import "../../types/index.mjs";
|
|
10
|
-
import { validateAndGetChainId as
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { solanaTransactCallRelayer as p } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
14
|
-
import { constructSolanaZkProof as m } from "../../functions/snarkjs/constructSolanaZkProof.mjs";
|
|
9
|
+
import { validateAndGetChainId as c } from "../../functions/utils/token-check.utils.mjs";
|
|
10
|
+
import { getFeeStructure as l } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
11
|
+
import { hinkalSolanaTransact as u } from "./hinkalSolanaTransact.mjs";
|
|
15
12
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalSolanaClaimUtxo.ts
|
|
16
|
-
var
|
|
17
|
-
let
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
variableRate: 0n,
|
|
28
|
-
hinkalInstructions: [],
|
|
29
|
-
remainingAccounts: [],
|
|
30
|
-
recipientAddress: s,
|
|
31
|
-
recipientAmounts: [c],
|
|
32
|
-
inputCommitments: [p]
|
|
33
|
-
}, f), { R8: g, S: _ } = f.signEddsa(BigInt(h));
|
|
34
|
-
return u(m, {
|
|
35
|
-
R8: g,
|
|
36
|
-
S: _
|
|
37
|
-
}, t);
|
|
38
|
-
}, g = async (u, d, g, _, v) => {
|
|
39
|
-
let y = l([d]), b = d.erc20TokenAddress;
|
|
40
|
-
if (g.getTokenAddress(y) !== b) throw Error("Off-chain UTXO token mismatch");
|
|
41
|
-
let x = v ? new a(v) : new a(g.nullifyingKey, g.nullifyingKey);
|
|
42
|
-
if (!g.nullifyingKey && !v) throw Error("Claimable UTXO nullifyingKey is missing");
|
|
43
|
-
let S = x.getShieldedPrivateKey();
|
|
44
|
-
if (g.nullifyingKey && g.nullifyingKey !== S) throw Error("Claimable UTXO key mismatch");
|
|
45
|
-
let { originalDeployer: C } = e[y].contractData;
|
|
46
|
-
if (!C) throw Error("missing data");
|
|
47
|
-
let w = s.createFrom(g, { nullifyingKey: S }), T = _ ?? await f(y, b, [b], c.Transact, void 0, void 0, {
|
|
48
|
-
mintTo: b,
|
|
13
|
+
var d = async (d, f, p, m, h) => {
|
|
14
|
+
let g = c([f]), _ = f.erc20TokenAddress;
|
|
15
|
+
if (p.getTokenAddress(g) !== _) throw Error("Off-chain UTXO token mismatch");
|
|
16
|
+
let v = h ? new i(h) : new i(p.nullifyingKey, p.nullifyingKey);
|
|
17
|
+
if (!p.nullifyingKey && !h) throw Error("Claimable UTXO nullifyingKey is missing");
|
|
18
|
+
let y = v.getShieldedPrivateKey();
|
|
19
|
+
if (p.nullifyingKey && p.nullifyingKey !== y) throw Error("Claimable UTXO key mismatch");
|
|
20
|
+
let { originalDeployer: b } = e[g].contractData;
|
|
21
|
+
if (!b) throw Error("missing data");
|
|
22
|
+
let x = a.createFrom(p, { nullifyingKey: y }), S = m ?? await l(g, _, [_], o.Transact, void 0, void 0, {
|
|
23
|
+
mintTo: _,
|
|
49
24
|
nullifierCount: 1,
|
|
50
25
|
rootInsertCount: 2
|
|
51
26
|
});
|
|
52
|
-
if (
|
|
53
|
-
let
|
|
54
|
-
if (
|
|
55
|
-
let
|
|
56
|
-
if (
|
|
57
|
-
let
|
|
58
|
-
if (!
|
|
59
|
-
let
|
|
27
|
+
if (S.feeToken !== _) throw Error("Claim fee token mismatch: fee must be paid from claimed UTXO token");
|
|
28
|
+
let C = S.variableRate > 0n ? S.variableRate : t;
|
|
29
|
+
if (x.amount <= S.flatFee) throw Error(r.INSUFFICIENT_FUNDS_TO_TRANSACT);
|
|
30
|
+
let w = x.amount - S.flatFee, T = w * C / 10000n, E = w - T;
|
|
31
|
+
if (E <= 0n) throw Error(r.RECIPIENT_AMOUNT_INVALID);
|
|
32
|
+
let D = S.flatFee + T, O = d.getRecipientInfo(), [k, A, j, , , M] = O.split(",");
|
|
33
|
+
if (!A || !j || !k || !M) throw Error("Invalid recipient info");
|
|
34
|
+
let N = new a({
|
|
60
35
|
amount: 0n,
|
|
61
|
-
erc20TokenAddress:
|
|
62
|
-
mintAddress:
|
|
63
|
-
nullifyingKey:
|
|
64
|
-
spendingPublicKey:
|
|
65
|
-
}),
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
timeStamp: I,
|
|
71
|
-
spendingPublicKey: x.getSpendingKeyPair().pubSpendingBJJPoint
|
|
72
|
-
}), z = new s({
|
|
73
|
-
amount: k,
|
|
74
|
-
erc20TokenAddress: w.erc20TokenAddress,
|
|
75
|
-
mintAddress: w.mintAddress,
|
|
76
|
-
timeStamp: I,
|
|
77
|
-
H0: [BigInt(N), BigInt(P)],
|
|
78
|
-
stealthAddress: M,
|
|
79
|
-
encryptionKey: F
|
|
80
|
-
}), B = [w, L], V = [R, z], H = await u.getRandomRelay(y, !0);
|
|
81
|
-
if (!H) throw Error(r.RELAYER_NOT_AVAILABLE);
|
|
82
|
-
let U = {
|
|
83
|
-
recipient: H,
|
|
84
|
-
mint: b === "11111111111111111111111111111111" ? void 0 : b
|
|
36
|
+
erc20TokenAddress: x.erc20TokenAddress,
|
|
37
|
+
mintAddress: x.mintAddress,
|
|
38
|
+
nullifyingKey: v.getShieldedPrivateKey(),
|
|
39
|
+
spendingPublicKey: v.getSpendingKeyPair().pubSpendingBJJPoint
|
|
40
|
+
}), P = await d.getRandomRelay(g, !0);
|
|
41
|
+
if (!P) throw Error(r.RELAYER_NOT_AVAILABLE);
|
|
42
|
+
let F = {
|
|
43
|
+
recipient: P,
|
|
44
|
+
mint: _ === "11111111111111111111111111111111" ? void 0 : _
|
|
85
45
|
};
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
chainId: y,
|
|
94
|
-
relayAddress: H,
|
|
46
|
+
return u(d, {
|
|
47
|
+
chainId: g,
|
|
48
|
+
mintAddresses: [_],
|
|
49
|
+
amountChanges: [-(E + D)],
|
|
50
|
+
relayAddress: P,
|
|
51
|
+
recipient: n,
|
|
52
|
+
signer: P,
|
|
95
53
|
functionName: "transfer",
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
dimensions: G,
|
|
104
|
-
rootHashIndex: Z.toString()
|
|
105
|
-
},
|
|
106
|
-
accounts: U,
|
|
107
|
-
commitmentValidationData: X
|
|
54
|
+
accounts: F,
|
|
55
|
+
relayerFee: D,
|
|
56
|
+
recipientAddress: O,
|
|
57
|
+
recipientAmounts: [E],
|
|
58
|
+
inputUtxos: [[x, N]],
|
|
59
|
+
userKeys: v,
|
|
60
|
+
submit: { mode: s.Relayer }
|
|
108
61
|
});
|
|
109
62
|
};
|
|
110
63
|
//#endregion
|
|
111
|
-
export {
|
|
64
|
+
export { d as hinkalSolanaClaimUtxo };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../error-handling/error-codes.constants.cjs`),r=require(`../../functions/web3/etherFunctions.cjs`),i=require(`../crypto-keys/keys.cjs`),a=require(`../../functions/utils/time.utils.cjs`),o=require(`../utxo/Utxo.cjs`),s=require(`../../functions/utils/solanaMint.utils.cjs`),c=require(`../../functions/utils/addresses.cjs`),l=require(`../../types/external-action.types.cjs`),u=require(`../../types/scheduled-transactions.types.cjs`);require(`../../types/index.cjs`);const
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../error-handling/error-codes.constants.cjs`),r=require(`../../functions/web3/etherFunctions.cjs`),i=require(`../crypto-keys/keys.cjs`),a=require(`../../functions/utils/time.utils.cjs`),o=require(`../utxo/Utxo.cjs`),s=require(`../../functions/utils/solanaMint.utils.cjs`),c=require(`../../functions/utils/addresses.cjs`),l=require(`../../types/external-action.types.cjs`),u=require(`../../types/scheduled-transactions.types.cjs`),d=require(`../../types/solana-transact.types.cjs`);require(`../../types/index.cjs`);const f=require(`../../functions/utils/token-check.utils.cjs`),p=require(`../../functions/snarkjs/common.snarkjs.cjs`),m=require(`../../functions/pre-transaction/solana.cjs`),h=require(`../../functions/pre-transaction/constructAdminData.cjs`),g=require(`../../functions/pre-transaction/sendV0Transaction.cjs`),_=require(`../../functions/pre-transaction/getFeeStructure.cjs`),v=require(`../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.cjs`);require(`../../functions/pre-transaction/index.cjs`);const y=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),b=require(`./hinkalProoflessDeposit.utils.cjs`),x=require(`../../API/deposit-and-withdraw-status-calls.cjs`),S=require(`../../functions/utils/getUtxosFromReceiptSolana.cjs`),C=require(`../../functions/utils/fees.utils.cjs`);require(`../../functions/web3/index.cjs`),require(`../../functions/index.cjs`);const w=require(`./hinkalSolanaTransact.cjs`);let T=require(`@solana/web3.js`),E=require(`@coral-xyz/anchor`);var D=(n,a,o,c)=>{let{hinkalIdl:l,hinkalAddress:u,originalDeployer:d}=e.networkRegistry[a].contractData;if(!l)throw Error(`No IDL configured for Solana program on this network`);if(!d)throw Error(`missing original deployer`);let f=n.userKeys.getShieldedPrivateKey(),h=n.getSolanaProgram(l),g=n.getSolanaPublicKey(),_=new T.PublicKey(d),v=new T.PublicKey(u),{mintPublicKey:y}=s.formatMintAddress(o.erc20TokenAddress),b=y.toString(),x=m.getStorageAccountPublicKey(v,_),S=m.getStorageVaultPublicKey(v,_),C=m.getMerkleAccountPublicKey(v,_),w=c.map(()=>p.calcStealthAddressStructure(i.UserKeys.findCorrectRandomization(r.randomBigInt(31),f),f,n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint)),E=w.map(e=>m.buildAnchorStealthAddressStructure(e)),D=i.UserKeys.getEncryptionKeyPair(f).publicKey,O=b===t.solanaNativeAddress;return{program:h,publicKey:g,originalDeployer:_,mint:O?null:y,atasValue:O?null:void 0,storageAccount:x,storageVault:S,merkleAccount:C,amounts:c,mintAddressString:b,stealthAddressStructures:w,anchorStealthStructures:E,ownEncryptionKey:D}},O=async e=>{let t=b.buildProoflessEncryptedOutputs(e.stealthAddressStructures,e.amounts.map(()=>e.ownEncryptionKey)).map(e=>Buffer.from(e.slice(2),`hex`)),{current:n,next:r}=await m.resolveSolanaRootBuckets(e.program,e.merkleAccount,e.amounts.length);return e.program.methods.multiPaymentDeposit(e.amounts.map(e=>new E.BN(e.toString())),e.anchorStealthStructures,t,!0).accounts({mint:e.mint,signer:e.publicKey,signerAta:e.atasValue,originalDeployer:e.originalDeployer,storageAccount:e.storageAccount,storageVault:e.storageVault,merkleAccount:e.merkleAccount,rootBucketCurrent:n,rootBucketNext:r??e.program.programId,storageVaultAta:e.atasValue})},k=async(e,t,n,r,i,a,o)=>{let c=r.map(e=>e+C.calculateTotalFee(e,a)),l=D(e,t,n,c),d=(await x.updateDepositAndWithdrawStatus({chainId:t,hashedEthereumAddress:o,phase:u.DepositAndWithdrawPhase.BEFORE_DEPOSIT})).id??void 0,f=await(await O(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 g.fetchSolanaTransaction(l.program.provider.connection,f,`finalized`);if(!m)throw Error(`Transaction missing`);await x.safeUpdateDepositAndWithdrawStatus({id:d,chainId:t,hashedEthereumAddress:o,phase:u.DepositAndWithdrawPhase.AFTER_DEPOSIT,depositTxHash:f});let{compressedAddress:h}=s.formatMintAddress(n.erc20TokenAddress),_=S.getOnChainUtxosFromReceiptSolana(m,l.program,e.userKeys,h),v=[],y=[..._];return i.forEach((e,t)=>{let n=c[t],r=y.find(e=>e.amount===n);if(!r)throw Error(`Could not find newly created UTXO with amount ${n} for recipient ${e}.`);v.push({recipientAddress:e,utxo:r}),y.splice(y.indexOf(r),1)}),{userDepositedUtxos:v,depositTxHash:f,statusId:d}},A=async(r,i,c,l,f,p,m,g,_,v,b,S,T,E)=>{let D=c.erc20TokenAddress;if(l.length===0)throw Error(`userDepositedUtxos must not be empty`);let{originalDeployer:O}=e.networkRegistry[i].contractData;if(!O)throw Error(`missing data`);let k=await r.getRandomRelay(i,!0);if(!k)throw Error(n.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let A=a.getCurrentTimeInSeconds().toString(),j=r.generateProofRemotely?5:1,M=[];for(let e=0;e<l.length;e+=j){let n=l.slice(e,e+j),a=await Promise.all(n.map(async({recipientAddress:n,utxo:a},l)=>{let u=e+l,p={recipient:n,mint:D===`11111111111111111111111111111111`?void 0:D},g=await C.calculateModifiedFeeStructure(i,c,m[u],f),_=h.constructAdminData(b,i,[D],[m[u]],await r.getEthereumAddress()),{compressedAddress:v}=s.formatMintAddress(t.solanaNativeAddress),y=new o.Utxo({amount:0n,mintAddress:D,erc20TokenAddress:v,nullifyingKey:r.userKeys.getShieldedPrivateKey(),timeStamp:A,spendingPublicKey:r.userKeys.getSpendingKeyPair().pubSpendingBJJPoint}),{args:x,commitmentValidationData:S}=await w.hinkalSolanaTransact(r,{chainId:i,mintAddresses:[D],amountChanges:[-a.amount],relayAddress:k,recipient:n,signer:k,functionName:`transact`,accounts:p,relayerFee:g.flatFee,variableRate:g.variableRate,inputUtxos:[[a,y]],useBlockedUtxos:!0,submit:{mode:d.SolanaSubmitMode.ProofOnly}});return{relayAddress:k,functionName:`transact`,chainId:i,recipientAmount:m[u].toString(),args:x,accounts:p,adminData:_,commitmentValidationData:S,displayRecipient:T?.[u],destinationChainId:E?.chainId,destinationTokenAddress:E?.tokenAddress,destinationTokenAmount:E?.tokenAmounts?.[u]}}));M.push(...a)}await x.safeUpdateDepositAndWithdrawStatus({id:g,chainId:i,hashedEthereumAddress:p,phase:u.DepositAndWithdrawPhase.BEFORE_SCHEDULE_WITHDRAW});let N=await y.solanaTransactCallRelayerBatch(i,M,p,_,v,S);return await x.safeUpdateDepositAndWithdrawStatus({id:g,chainId:i,hashedEthereumAddress:p,phase:u.DepositAndWithdrawPhase.AFTER_SCHEDULE_WITHDRAW,scheduleId:N}),N},j=async(e,t,n,r,i,a,o,s,u,d,p)=>{let m=f.validateAndGetChainId([t]),h=t.erc20TokenAddress,g=c.hashEthereumAddress(await e.getEthereumAddressByChain(m)),y=u?c.hashString(u):void 0,b=a??await _.getFeeStructure(m,h,[h],l.ExternalActionId.Transact,[],5n,{mintTo:h,recipient:r[0],nullifierCount:1}),{userDepositedUtxos:x,depositTxHash:S,statusId:C}=await k(e,m,t,n,r,b,g);return await v.waitForDepositedUtxosInMerkleTree(e,m,x),{depositTxHash:S,scheduleId:await A(e,m,t,x,b,g,n,C,i,o,s,y,d,p)}};exports.hinkalSolanaDepositAndWithdraw=j;
|
|
@@ -9,34 +9,34 @@ import { formatMintAddress as s } from "../../functions/utils/solanaMint.utils.m
|
|
|
9
9
|
import { hashEthereumAddress as c, hashString as l } from "../../functions/utils/addresses.mjs";
|
|
10
10
|
import { ExternalActionId as u } from "../../types/external-action.types.mjs";
|
|
11
11
|
import { DepositAndWithdrawPhase as d } from "../../types/scheduled-transactions.types.mjs";
|
|
12
|
+
import { SolanaSubmitMode as f } from "../../types/solana-transact.types.mjs";
|
|
12
13
|
import "../../types/index.mjs";
|
|
13
|
-
import { validateAndGetChainId as
|
|
14
|
-
import { calcStealthAddressStructure as
|
|
15
|
-
import { buildAnchorStealthAddressStructure as
|
|
16
|
-
import { constructAdminData as
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import { waitForDepositedUtxosInMerkleTree as w } from "../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.mjs";
|
|
14
|
+
import { validateAndGetChainId as p } from "../../functions/utils/token-check.utils.mjs";
|
|
15
|
+
import { calcStealthAddressStructure as m } from "../../functions/snarkjs/common.snarkjs.mjs";
|
|
16
|
+
import { buildAnchorStealthAddressStructure as h, getMerkleAccountPublicKey as g, getStorageAccountPublicKey as _, getStorageVaultPublicKey as v, resolveSolanaRootBuckets as y } from "../../functions/pre-transaction/solana.mjs";
|
|
17
|
+
import { constructAdminData as b } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
18
|
+
import { fetchSolanaTransaction as x } from "../../functions/pre-transaction/sendV0Transaction.mjs";
|
|
19
|
+
import { getFeeStructure as S } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
20
|
+
import { waitForDepositedUtxosInMerkleTree as C } from "../../functions/pre-transaction/waitForDepositedUtxosInMerkleTree.mjs";
|
|
21
21
|
import "../../functions/pre-transaction/index.mjs";
|
|
22
|
-
import { solanaTransactCallRelayerBatch as
|
|
23
|
-
import { buildProoflessEncryptedOutputs as
|
|
24
|
-
import { safeUpdateDepositAndWithdrawStatus as
|
|
25
|
-
import { getOnChainUtxosFromReceiptSolana as
|
|
26
|
-
import { calculateModifiedFeeStructure as
|
|
22
|
+
import { solanaTransactCallRelayerBatch as w } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
23
|
+
import { buildProoflessEncryptedOutputs as T } from "./hinkalProoflessDeposit.utils.mjs";
|
|
24
|
+
import { safeUpdateDepositAndWithdrawStatus as E, updateDepositAndWithdrawStatus as D } from "../../API/deposit-and-withdraw-status-calls.mjs";
|
|
25
|
+
import { getOnChainUtxosFromReceiptSolana as O } from "../../functions/utils/getUtxosFromReceiptSolana.mjs";
|
|
26
|
+
import { calculateModifiedFeeStructure as k, calculateTotalFee as A } from "../../functions/utils/fees.utils.mjs";
|
|
27
27
|
import "../../functions/web3/index.mjs";
|
|
28
|
-
import { constructSolanaZkProof as M } from "../../functions/snarkjs/constructSolanaZkProof.mjs";
|
|
29
28
|
import "../../functions/index.mjs";
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
29
|
+
import { hinkalSolanaTransact as j } from "./hinkalSolanaTransact.mjs";
|
|
30
|
+
import { PublicKey as M } from "@solana/web3.js";
|
|
31
|
+
import { BN as N } from "@coral-xyz/anchor";
|
|
32
32
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalSolanaDepositAndWithdraw.ts
|
|
33
|
-
var
|
|
33
|
+
var P = (n, a, o, c) => {
|
|
34
34
|
let { hinkalIdl: l, hinkalAddress: u, originalDeployer: d } = e[a].contractData;
|
|
35
35
|
if (!l) throw Error("No IDL configured for Solana program on this network");
|
|
36
36
|
if (!d) throw Error("missing original deployer");
|
|
37
|
-
let f = n.userKeys.getShieldedPrivateKey(),
|
|
37
|
+
let f = n.userKeys.getShieldedPrivateKey(), p = n.getSolanaProgram(l), y = n.getSolanaPublicKey(), b = new M(d), x = new M(u), { mintPublicKey: S } = s(o.erc20TokenAddress), C = S.toString(), w = _(x, b), T = v(x, b), E = g(x, b), D = c.map(() => m(i.findCorrectRandomization(r(31), f), f, n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint)), O = D.map((e) => h(e)), k = i.getEncryptionKeyPair(f).publicKey, A = C === t;
|
|
38
38
|
return {
|
|
39
|
-
program:
|
|
39
|
+
program: p,
|
|
40
40
|
publicKey: y,
|
|
41
41
|
originalDeployer: b,
|
|
42
42
|
mint: A ? null : S,
|
|
@@ -50,9 +50,9 @@ var F = (n, a, o, c) => {
|
|
|
50
50
|
anchorStealthStructures: O,
|
|
51
51
|
ownEncryptionKey: k
|
|
52
52
|
};
|
|
53
|
-
},
|
|
54
|
-
let t =
|
|
55
|
-
return e.program.methods.multiPaymentDeposit(e.amounts.map((e) => new
|
|
53
|
+
}, F = async (e) => {
|
|
54
|
+
let t = T(e.stealthAddressStructures, e.amounts.map(() => e.ownEncryptionKey)).map((e) => Buffer.from(e.slice(2), "hex")), { current: n, next: r } = await y(e.program, e.merkleAccount, e.amounts.length);
|
|
55
|
+
return e.program.methods.multiPaymentDeposit(e.amounts.map((e) => new N(e.toString())), e.anchorStealthStructures, t, !0).accounts({
|
|
56
56
|
mint: e.mint,
|
|
57
57
|
signer: e.publicKey,
|
|
58
58
|
signerAta: e.atasValue,
|
|
@@ -64,27 +64,27 @@ var F = (n, a, o, c) => {
|
|
|
64
64
|
rootBucketNext: r ?? e.program.programId,
|
|
65
65
|
storageVaultAta: e.atasValue
|
|
66
66
|
});
|
|
67
|
-
},
|
|
68
|
-
let c = r.map((e) => e +
|
|
67
|
+
}, I = async (e, t, n, r, i, a, o) => {
|
|
68
|
+
let c = r.map((e) => e + A(e, a)), l = P(e, t, n, c), u = (await D({
|
|
69
69
|
chainId: t,
|
|
70
70
|
hashedEthereumAddress: o,
|
|
71
71
|
phase: d.BEFORE_DEPOSIT
|
|
72
|
-
})).id ?? void 0, f = await (await
|
|
72
|
+
})).id ?? void 0, f = await (await F(l)).rpc(), p = await l.program.provider.connection.getLatestBlockhash();
|
|
73
73
|
await l.program.provider.connection.confirmTransaction({
|
|
74
74
|
blockhash: p.blockhash,
|
|
75
75
|
lastValidBlockHeight: p.lastValidBlockHeight,
|
|
76
76
|
signature: f
|
|
77
77
|
}, "finalized");
|
|
78
|
-
let m = await
|
|
78
|
+
let m = await x(l.program.provider.connection, f, "finalized");
|
|
79
79
|
if (!m) throw Error("Transaction missing");
|
|
80
|
-
await
|
|
80
|
+
await E({
|
|
81
81
|
id: u,
|
|
82
82
|
chainId: t,
|
|
83
83
|
hashedEthereumAddress: o,
|
|
84
84
|
phase: d.AFTER_DEPOSIT,
|
|
85
85
|
depositTxHash: f
|
|
86
86
|
});
|
|
87
|
-
let { compressedAddress: h } = s(n.erc20TokenAddress), g =
|
|
87
|
+
let { compressedAddress: h } = s(n.erc20TokenAddress), g = O(m, l.program, e.userKeys, h), _ = [], v = [...g];
|
|
88
88
|
return i.forEach((e, t) => {
|
|
89
89
|
let n = c[t], r = v.find((e) => e.amount === n);
|
|
90
90
|
if (!r) throw Error(`Could not find newly created UTXO with amount ${n} for recipient ${e}.`);
|
|
@@ -97,120 +97,82 @@ var F = (n, a, o, c) => {
|
|
|
97
97
|
depositTxHash: f,
|
|
98
98
|
statusId: u
|
|
99
99
|
};
|
|
100
|
-
},
|
|
101
|
-
let
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
variableRate: s.variableRate,
|
|
112
|
-
hinkalInstructions: [],
|
|
113
|
-
remainingAccounts: [],
|
|
114
|
-
inputCommitments: [r.getCommitment()],
|
|
115
|
-
useBlockedUtxos: !0
|
|
116
|
-
}), { R8: u, S: d } = e.userKeys.signEddsa(BigInt(l));
|
|
117
|
-
return b(c, {
|
|
118
|
-
R8: u,
|
|
119
|
-
S: d
|
|
120
|
-
});
|
|
121
|
-
}, z = async (c, l, u, f, p, m, h, g, _, v, b, x, S, C) => {
|
|
122
|
-
let w = u.erc20TokenAddress;
|
|
123
|
-
if (f.length === 0) throw Error("userDepositedUtxos must not be empty");
|
|
124
|
-
let { originalDeployer: E } = e[l].contractData;
|
|
125
|
-
if (!E) throw Error("missing data");
|
|
126
|
-
let O = await c.getRandomRelay(l, !0);
|
|
127
|
-
if (!O) throw Error(n.RELAYER_NOT_AVAILABLE);
|
|
128
|
-
let k = a().toString(), j = c.generateProofRemotely, N = j ? 5 : 1, P = [];
|
|
129
|
-
for (let e = 0; e < f.length; e += N) {
|
|
130
|
-
let n = f.slice(e, e + N), a = await Promise.all(n.map(async ({ recipientAddress: n, utxo: a }, d) => {
|
|
131
|
-
let f = e + d, m = {
|
|
100
|
+
}, L = async (r, i, c, l, u, p, m, h, g, _, v, y, x, S) => {
|
|
101
|
+
let C = c.erc20TokenAddress;
|
|
102
|
+
if (l.length === 0) throw Error("userDepositedUtxos must not be empty");
|
|
103
|
+
let { originalDeployer: T } = e[i].contractData;
|
|
104
|
+
if (!T) throw Error("missing data");
|
|
105
|
+
let D = await r.getRandomRelay(i, !0);
|
|
106
|
+
if (!D) throw Error(n.RELAYER_NOT_AVAILABLE);
|
|
107
|
+
let O = a().toString(), A = r.generateProofRemotely ? 5 : 1, M = [];
|
|
108
|
+
for (let e = 0; e < l.length; e += A) {
|
|
109
|
+
let n = l.slice(e, e + A), a = await Promise.all(n.map(async ({ recipientAddress: n, utxo: a }, l) => {
|
|
110
|
+
let d = e + l, p = {
|
|
132
111
|
recipient: n,
|
|
133
|
-
mint:
|
|
134
|
-
},
|
|
135
|
-
if (j) {
|
|
136
|
-
let { solanaArgs: e, commitmentValidationData: t } = await R(c, l, w, a, n, O, m, g);
|
|
137
|
-
return {
|
|
138
|
-
relayAddress: O,
|
|
139
|
-
functionName: "transact",
|
|
140
|
-
chainId: l,
|
|
141
|
-
recipientAmount: h[f].toString(),
|
|
142
|
-
args: e,
|
|
143
|
-
accounts: m,
|
|
144
|
-
adminData: _,
|
|
145
|
-
commitmentValidationData: t,
|
|
146
|
-
displayRecipient: S?.[f],
|
|
147
|
-
destinationChainId: C?.chainId,
|
|
148
|
-
destinationTokenAddress: C?.tokenAddress,
|
|
149
|
-
destinationTokenAmount: C?.tokenAmounts?.[f]
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
let { compressedAddress: v } = s(t), x = new o({
|
|
112
|
+
mint: C === "11111111111111111111111111111111" ? void 0 : C
|
|
113
|
+
}, h = await k(i, c, m[d], u), g = b(v, i, [C], [m[d]], await r.getEthereumAddress()), { compressedAddress: _ } = s(t), y = new o({
|
|
153
114
|
amount: 0n,
|
|
154
|
-
mintAddress:
|
|
155
|
-
erc20TokenAddress:
|
|
156
|
-
nullifyingKey:
|
|
157
|
-
timeStamp:
|
|
158
|
-
spendingPublicKey:
|
|
159
|
-
}),
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
115
|
+
mintAddress: C,
|
|
116
|
+
erc20TokenAddress: _,
|
|
117
|
+
nullifyingKey: r.userKeys.getShieldedPrivateKey(),
|
|
118
|
+
timeStamp: O,
|
|
119
|
+
spendingPublicKey: r.userKeys.getSpendingKeyPair().pubSpendingBJJPoint
|
|
120
|
+
}), { args: w, commitmentValidationData: T } = await j(r, {
|
|
121
|
+
chainId: i,
|
|
122
|
+
mintAddresses: [C],
|
|
123
|
+
amountChanges: [-a.amount],
|
|
124
|
+
relayAddress: D,
|
|
125
|
+
recipient: n,
|
|
126
|
+
signer: D,
|
|
127
|
+
functionName: "transact",
|
|
128
|
+
accounts: p,
|
|
129
|
+
relayerFee: h.flatFee,
|
|
130
|
+
variableRate: h.variableRate,
|
|
131
|
+
inputUtxos: [[a, y]],
|
|
132
|
+
useBlockedUtxos: !0,
|
|
133
|
+
submit: { mode: f.ProofOnly }
|
|
134
|
+
});
|
|
164
135
|
return {
|
|
165
|
-
relayAddress:
|
|
136
|
+
relayAddress: D,
|
|
166
137
|
functionName: "transact",
|
|
167
|
-
chainId:
|
|
168
|
-
recipientAmount:
|
|
169
|
-
args:
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
rootHashIndex: B.toString()
|
|
178
|
-
},
|
|
179
|
-
accounts: m,
|
|
180
|
-
adminData: _,
|
|
181
|
-
commitmentValidationData: z,
|
|
182
|
-
displayRecipient: S?.[f],
|
|
183
|
-
destinationChainId: C?.chainId,
|
|
184
|
-
destinationTokenAddress: C?.tokenAddress,
|
|
185
|
-
destinationTokenAmount: C?.tokenAmounts?.[f]
|
|
138
|
+
chainId: i,
|
|
139
|
+
recipientAmount: m[d].toString(),
|
|
140
|
+
args: w,
|
|
141
|
+
accounts: p,
|
|
142
|
+
adminData: g,
|
|
143
|
+
commitmentValidationData: T,
|
|
144
|
+
displayRecipient: x?.[d],
|
|
145
|
+
destinationChainId: S?.chainId,
|
|
146
|
+
destinationTokenAddress: S?.tokenAddress,
|
|
147
|
+
destinationTokenAmount: S?.tokenAmounts?.[d]
|
|
186
148
|
};
|
|
187
149
|
}));
|
|
188
|
-
|
|
150
|
+
M.push(...a);
|
|
189
151
|
}
|
|
190
|
-
await
|
|
191
|
-
id:
|
|
192
|
-
chainId:
|
|
193
|
-
hashedEthereumAddress:
|
|
152
|
+
await E({
|
|
153
|
+
id: h,
|
|
154
|
+
chainId: i,
|
|
155
|
+
hashedEthereumAddress: p,
|
|
194
156
|
phase: d.BEFORE_SCHEDULE_WITHDRAW
|
|
195
157
|
});
|
|
196
|
-
let
|
|
197
|
-
return await
|
|
198
|
-
id:
|
|
199
|
-
chainId:
|
|
200
|
-
hashedEthereumAddress:
|
|
158
|
+
let N = await w(i, M, p, g, _, y);
|
|
159
|
+
return await E({
|
|
160
|
+
id: h,
|
|
161
|
+
chainId: i,
|
|
162
|
+
hashedEthereumAddress: p,
|
|
201
163
|
phase: d.AFTER_SCHEDULE_WITHDRAW,
|
|
202
|
-
scheduleId:
|
|
203
|
-
}),
|
|
204
|
-
},
|
|
205
|
-
let h =
|
|
164
|
+
scheduleId: N
|
|
165
|
+
}), N;
|
|
166
|
+
}, R = async (e, t, n, r, i, a, o, s, d, f, m) => {
|
|
167
|
+
let h = p([t]), g = t.erc20TokenAddress, _ = c(await e.getEthereumAddressByChain(h)), v = d ? l(d) : void 0, y = a ?? await S(h, g, [g], u.Transact, [], 5n, {
|
|
206
168
|
mintTo: g,
|
|
207
169
|
recipient: r[0],
|
|
208
170
|
nullifierCount: 1
|
|
209
|
-
}), { userDepositedUtxos: b, depositTxHash: x, statusId:
|
|
210
|
-
return await
|
|
171
|
+
}), { userDepositedUtxos: b, depositTxHash: x, statusId: w } = await I(e, h, t, n, r, y, _);
|
|
172
|
+
return await C(e, h, b), {
|
|
211
173
|
depositTxHash: x,
|
|
212
|
-
scheduleId: await
|
|
174
|
+
scheduleId: await L(e, h, t, b, y, _, n, w, i, o, s, v, f, m)
|
|
213
175
|
};
|
|
214
176
|
};
|
|
215
177
|
//#endregion
|
|
216
|
-
export {
|
|
178
|
+
export { R as hinkalSolanaDepositAndWithdraw };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../error-handling/error-codes.constants.cjs`),r=require(`../../functions/web3/etherFunctions.cjs`),i=require(
|
|
1
|
+
require(`../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../error-handling/error-codes.constants.cjs`),r=require(`../../functions/web3/etherFunctions.cjs`),i=require(`../../types/external-action.types.cjs`),a=require(`../../types/cache.types.cjs`),o=require(`../../types/solana-transact.types.cjs`);require(`../../types/index.cjs`);const s=require(`../../functions/utils/token-check.utils.cjs`),c=require(`../../functions/pre-transaction/solana.cjs`),l=require(`../../functions/pre-transaction/constructAdminData.cjs`),u=require(`../../functions/pre-transaction/calculateSolanaNullifierCount.cjs`),d=require(`../../functions/pre-transaction/convert-okx-instructions.cjs`),f=require(`../../functions/pre-transaction/getFeeStructure.cjs`),p=require(`./hinkalSolanaTransact.cjs`);let m=require(`@solana/web3.js`);var h=async(h,g,_,v,y,b,x,S,C)=>{let w=s.validateAndGetChainId(g),T=new m.PublicKey(t.solanaNativeAddress),{hinkalAddress:E,originalDeployer:D}=e.networkRegistry[w].contractData;if(!D)throw Error(`No IDL configured for Solana program on this network`);let O=new m.PublicKey(D),k=new m.PublicKey(E),A=g.map(e=>e.erc20TokenAddress),j=x??A[1];if(x&&x!==A[1])throw Error(`Solana swap fee token must match the output token`);let M={mintFrom:A[0],mintTo:A[1],nullifierCount:await u.calculateSolanaNullifierCount(h,w,A,_),rootInsertCount:2},N=S??await f.getFeeStructure(w,j,A,i.ExternalActionId.Okx,[],void 0,M),P=_[1],F=Number(h.cacheDevice.get(a.StorageKeys.SLIPPAGE_PERCENTAGE)??0),I=g[1],L=r.getAmountInToken(I,P),R=Number(L)*F/100;_[1]-=r.getAmountInWei(I,R.toFixed(I.decimals));let z=P*BigInt(N.variableRate??0)/10000n+N.flatFee;if(_[1]-=z,_[1]<0)throw Error(n.transactionErrorCodes.LOW_OUTPUT_AMOUNT);let[B,V]=await Promise.all([h.getRandomRelay(w,!0),h.getEthereumAddressByChain(w)]);if(!B)throw Error(n.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let H=c.getSwapperAccountPublicKeyFromSalt(k,O,v),{remainingAccounts:U,hinkalInstructions:W}=d.convertOKXToHinkalInstructions(y,H),G=c.getStorageAccountPublicKey(k,O),K=c.getStorageVaultPublicKey(k,O),q=g[0].erc20TokenAddress===`11111111111111111111111111111111`?null:new m.PublicKey(g[0].erc20TokenAddress),J=g[1].erc20TokenAddress===`11111111111111111111111111111111`?null:new m.PublicKey(g[1].erc20TokenAddress),Y={recipient:T.toString(),storageAccount:G.toString(),storageVault:K.toString(),swapperAccount:H.toString(),mintFrom:q?.toString()??null,mintTo:J?.toString()??null,remainingAccounts:U.map(e=>({pubkey:e.pubkey.toString(),isSigner:e.isSigner,isWritable:e.isWritable})),addressLookupTableAccount:b},X=l.constructAdminData(C,w,A,_,V,g),Z=W.map(e=>({accountIndexes:[...e.accountIndexes],data:[...e.data],programIndex:e.programIndex}));return p.hinkalSolanaTransact(h,{chainId:w,mintAddresses:A,amountChanges:_,relayAddress:B,recipient:T.toString(),signer:B,functionName:`swap`,accounts:Y,onChainCreation:[!1,!0],relayerFee:N.flatFee,variableRate:N.variableRate,hinkalInstructions:Z,remainingAccounts:Y.remainingAccounts,swapperAccountSalt:v,submit:{mode:o.SolanaSubmitMode.Relayer,adminData:X}})};exports.hinkalSolanaSwap=h;
|