@cloak.dev/sdk 0.2.20-staging.456721e → 0.2.20-staging.9533cda

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/CHANGELOG.md CHANGED
@@ -32,8 +32,10 @@ one call each. Everything earlier stays exported for full control. See
32
32
  no wallet of the user's is involved. Both are finished by `resume` if they stop halfway. The
33
33
  calls are hand-encoded (no LayerZero SDK) and pinned to live transactions; every account of the
34
34
  Solana send is read from LayerZero's own configuration and the route is refused, before any money
35
- moves, on any change this version cannot build for. Receipts and quotes report the fee paid in
36
- the other chain's coin as `networkFee`.
35
+ moves, on any change this version cannot build for. Both directions are also refused
36
+ (`route.unavailable`) while the relay does not serve the BRS pool, the same rule the 1Click route
37
+ applies, so no BRS is left waiting at a receiving address. Receipts and quotes report the fee paid
38
+ in the other chain's coin as `networkFee`.
37
39
  * **Wallets from anywhere.** One recognizer (`recognizeWallet`) for the wallet-adapter context and
38
40
  adapters, Wallet Standard wallets (Phantom, Solflare, Backpack, Slush, Suiet; driven with bytes,
39
41
  no web3.js), kit signers and web3.js key pairs (a signer that can also send, such as Privy's
package/dist/index.cjs CHANGED
@@ -21969,8 +21969,19 @@ var NATIVE_DROP_ONLY_PAYMASTER = {
21969
21969
  quoteTopUp: () => Promise.reject(new Error(NO_PAYMASTER)),
21970
21970
  topUp: () => Promise.reject(new Error(NO_PAYMASTER))
21971
21971
  };
21972
- async function nativeDropFor(ctx, receiver) {
21972
+ var LayerZeroRouteError = class extends Error {
21973
+ constructor(message) {
21974
+ super(message);
21975
+ this.name = "LayerZeroRouteError";
21976
+ }
21977
+ };
21978
+ async function relayServing(ctx) {
21973
21979
  const cap = await fetchRelayCapability(ctx.relayUrl, ctx.mint);
21980
+ if (!canServeDeposits(cap)) throw new LayerZeroRouteError(`the relay cannot shield a BRS deposit right now (${cap.detail}); nothing was sent`);
21981
+ return cap;
21982
+ }
21983
+ async function nativeDropFor(ctx, receiver, capability) {
21984
+ const cap = capability ?? await fetchRelayCapability(ctx.relayUrl, ctx.mint);
21974
21985
  const [ata] = await (0, import_token14.findAssociatedTokenPda)({ mint: ctx.mint, owner: receiver, tokenProgram: import_token14.TOKEN_PROGRAM_ADDRESS });
21975
21986
  const [grant, rentAta, held, ataAccount] = await Promise.all([
21976
21987
  receiverGrantLamports(ctx.rpc, receiver, ctx.mint, needsSelfFundedAlt(cap)),
@@ -21987,7 +21998,7 @@ function sendParam(receiver, amount, drop) {
21987
21998
  return { dstEid: LZ_EID_SOLANA, to, amountLD: amount, minAmountLD: amount, ...drop > 0n ? { extraOptions: nativeDropOptions(drop, to) } : {} };
21988
21999
  }
21989
22000
  async function quoteLayerZeroDeposit(ctx, request, receiver, amount) {
21990
- const drop = await nativeDropFor(ctx, receiver);
22001
+ const drop = await nativeDropFor(ctx, receiver, await relayServing(ctx));
21991
22002
  await ensureEvmChain(request, "base");
21992
22003
  const fee = decodeMessagingFee(
21993
22004
  await request({ method: "eth_call", params: [{ to: BRS_OFT_BASE, data: encodeQuoteSend(sendParam(receiver, amount, drop)) }, "latest"] })
@@ -22000,6 +22011,7 @@ async function peekReceiver(ctx) {
22000
22011
  }
22001
22012
  async function runLayerZeroDeposit(ctx, wallet, amount, hooks = {}) {
22002
22013
  assertAllowedRpcConnection(ctx.rpc);
22014
+ await relayServing(ctx);
22003
22015
  const say = hooks.onProgress ?? (() => {
22004
22016
  });
22005
22017
  const deposits = await discoverBridgeDeposits(ctx.rpc, ctx.owner, { programId: ctx.programId, mint: ctx.mint, includeLegacy: false }, ctx.ledger);
@@ -23271,7 +23283,10 @@ var _CloakImpl = class _CloakImpl {
23271
23283
  const wallet2 = __privateMethod(this, _CloakImpl_instances, walletFor_fn).call(this, request.from, "evm", "base");
23272
23284
  const ctx = __privateMethod(this, _CloakImpl_instances, layerZeroContext_fn).call(this);
23273
23285
  const receiver = await peekReceiver(ctx);
23274
- const lz = await quoteLayerZeroDeposit(ctx, wallet2.evm.request, receiver.address, amount2);
23286
+ const lz = await quoteLayerZeroDeposit(ctx, wallet2.evm.request, receiver.address, amount2).catch((e) => {
23287
+ if (e instanceof LayerZeroRouteError) throw new CloakCallError("route.unavailable", e.message, "network", true, { next: "Nothing was moved." });
23288
+ throw e;
23289
+ });
23275
23290
  return {
23276
23291
  arrives: { token: "BRS", atLeast: formatAmount2(amount2, token2.decimals), network: "cloak" },
23277
23292
  fee: "0",
@@ -23774,6 +23789,9 @@ shieldBrsFromBase_fn = async function(request) {
23774
23789
  if (e instanceof LayerZeroFundsError) {
23775
23790
  throw new CloakCallError("shield.insufficient_funds", e.message, "validation", false, { moneyAt: "Your money is still in your wallet.", next: "Nothing was sent." });
23776
23791
  }
23792
+ if (e instanceof LayerZeroRouteError) {
23793
+ throw new CloakCallError("route.unavailable", e.message, "network", true, { moneyAt: "Your money is still in your wallet.", next: "Nothing was sent." });
23794
+ }
23777
23795
  throw new CloakCallError("shield.failed", `the BRS deposit was not sent: ${describe(e)}`, "network", true, { moneyAt: "Your money is still in your wallet.", next: "Nothing was sent.", cause: e });
23778
23796
  }
23779
23797
  const sent = `${formatAmount2(amount, token.decimals)} BRS`;
@@ -24058,6 +24076,10 @@ lzSolNeeds_fn = async function(route, collector) {
24058
24076
  };
24059
24077
  lzPlan_fn = async function(amount) {
24060
24078
  const rpc = __privateGet(this, _s).rpc;
24079
+ const cap = await fetchRelayCapability(__privateGet(this, _s).relayUrl, CLOAK_TOKENS.BRS.mint);
24080
+ if (!canServeDeposits(cap)) {
24081
+ throw new CloakCallError("route.unavailable", `BRS cannot be sent to Base right now: the relay ${cap.detail}`, "network", true, { next: "Nothing was moved." });
24082
+ }
24061
24083
  let route;
24062
24084
  try {
24063
24085
  route = await prepareOftSendToBase(rpc);
@@ -24087,9 +24109,8 @@ sendBrsToBase_fn = async function(to, request) {
24087
24109
  }
24088
24110
  const say = request.onProgress ?? (() => {
24089
24111
  });
24090
- await __privateMethod(this, _CloakImpl_instances, ensureRegistered_fn).call(this, __privateGet(this, _s).keys);
24091
- await __privateMethod(this, _CloakImpl_instances, sync_fn).call(this);
24092
24112
  const plan = await __privateMethod(this, _CloakImpl_instances, lzPlan_fn).call(this, amount);
24113
+ await __privateMethod(this, _CloakImpl_instances, sync_fn).call(this);
24093
24114
  const have = (t) => __privateGet(this, _book).forMint(t.mint).reduce((a, n) => a + n.utxo.amount, 0n);
24094
24115
  if (have(token) < plan.brsGross) {
24095
24116
  throw new CloakCallError(
package/dist/index.js CHANGED
@@ -20818,8 +20818,19 @@ var NATIVE_DROP_ONLY_PAYMASTER = {
20818
20818
  quoteTopUp: () => Promise.reject(new Error(NO_PAYMASTER)),
20819
20819
  topUp: () => Promise.reject(new Error(NO_PAYMASTER))
20820
20820
  };
20821
- async function nativeDropFor(ctx, receiver) {
20821
+ var LayerZeroRouteError = class extends Error {
20822
+ constructor(message) {
20823
+ super(message);
20824
+ this.name = "LayerZeroRouteError";
20825
+ }
20826
+ };
20827
+ async function relayServing(ctx) {
20822
20828
  const cap = await fetchRelayCapability(ctx.relayUrl, ctx.mint);
20829
+ if (!canServeDeposits(cap)) throw new LayerZeroRouteError(`the relay cannot shield a BRS deposit right now (${cap.detail}); nothing was sent`);
20830
+ return cap;
20831
+ }
20832
+ async function nativeDropFor(ctx, receiver, capability) {
20833
+ const cap = capability ?? await fetchRelayCapability(ctx.relayUrl, ctx.mint);
20823
20834
  const [ata] = await findAssociatedTokenPda13({ mint: ctx.mint, owner: receiver, tokenProgram: TOKEN_PROGRAM_ADDRESS14 });
20824
20835
  const [grant, rentAta, held, ataAccount] = await Promise.all([
20825
20836
  receiverGrantLamports(ctx.rpc, receiver, ctx.mint, needsSelfFundedAlt(cap)),
@@ -20836,7 +20847,7 @@ function sendParam(receiver, amount, drop) {
20836
20847
  return { dstEid: LZ_EID_SOLANA, to, amountLD: amount, minAmountLD: amount, ...drop > 0n ? { extraOptions: nativeDropOptions(drop, to) } : {} };
20837
20848
  }
20838
20849
  async function quoteLayerZeroDeposit(ctx, request, receiver, amount) {
20839
- const drop = await nativeDropFor(ctx, receiver);
20850
+ const drop = await nativeDropFor(ctx, receiver, await relayServing(ctx));
20840
20851
  await ensureEvmChain(request, "base");
20841
20852
  const fee = decodeMessagingFee(
20842
20853
  await request({ method: "eth_call", params: [{ to: BRS_OFT_BASE, data: encodeQuoteSend(sendParam(receiver, amount, drop)) }, "latest"] })
@@ -20849,6 +20860,7 @@ async function peekReceiver(ctx) {
20849
20860
  }
20850
20861
  async function runLayerZeroDeposit(ctx, wallet, amount, hooks = {}) {
20851
20862
  assertAllowedRpcConnection(ctx.rpc);
20863
+ await relayServing(ctx);
20852
20864
  const say = hooks.onProgress ?? (() => {
20853
20865
  });
20854
20866
  const deposits = await discoverBridgeDeposits(ctx.rpc, ctx.owner, { programId: ctx.programId, mint: ctx.mint, includeLegacy: false }, ctx.ledger);
@@ -22118,7 +22130,10 @@ var _CloakImpl = class _CloakImpl {
22118
22130
  const wallet2 = __privateMethod(this, _CloakImpl_instances, walletFor_fn).call(this, request.from, "evm", "base");
22119
22131
  const ctx = __privateMethod(this, _CloakImpl_instances, layerZeroContext_fn).call(this);
22120
22132
  const receiver = await peekReceiver(ctx);
22121
- const lz = await quoteLayerZeroDeposit(ctx, wallet2.evm.request, receiver.address, amount2);
22133
+ const lz = await quoteLayerZeroDeposit(ctx, wallet2.evm.request, receiver.address, amount2).catch((e) => {
22134
+ if (e instanceof LayerZeroRouteError) throw new CloakCallError("route.unavailable", e.message, "network", true, { next: "Nothing was moved." });
22135
+ throw e;
22136
+ });
22122
22137
  return {
22123
22138
  arrives: { token: "BRS", atLeast: formatAmount2(amount2, token2.decimals), network: "cloak" },
22124
22139
  fee: "0",
@@ -22621,6 +22636,9 @@ shieldBrsFromBase_fn = async function(request) {
22621
22636
  if (e instanceof LayerZeroFundsError) {
22622
22637
  throw new CloakCallError("shield.insufficient_funds", e.message, "validation", false, { moneyAt: "Your money is still in your wallet.", next: "Nothing was sent." });
22623
22638
  }
22639
+ if (e instanceof LayerZeroRouteError) {
22640
+ throw new CloakCallError("route.unavailable", e.message, "network", true, { moneyAt: "Your money is still in your wallet.", next: "Nothing was sent." });
22641
+ }
22624
22642
  throw new CloakCallError("shield.failed", `the BRS deposit was not sent: ${describe(e)}`, "network", true, { moneyAt: "Your money is still in your wallet.", next: "Nothing was sent.", cause: e });
22625
22643
  }
22626
22644
  const sent = `${formatAmount2(amount, token.decimals)} BRS`;
@@ -22905,6 +22923,10 @@ lzSolNeeds_fn = async function(route, collector) {
22905
22923
  };
22906
22924
  lzPlan_fn = async function(amount) {
22907
22925
  const rpc = __privateGet(this, _s).rpc;
22926
+ const cap = await fetchRelayCapability(__privateGet(this, _s).relayUrl, CLOAK_TOKENS.BRS.mint);
22927
+ if (!canServeDeposits(cap)) {
22928
+ throw new CloakCallError("route.unavailable", `BRS cannot be sent to Base right now: the relay ${cap.detail}`, "network", true, { next: "Nothing was moved." });
22929
+ }
22908
22930
  let route;
22909
22931
  try {
22910
22932
  route = await prepareOftSendToBase(rpc);
@@ -22934,9 +22956,8 @@ sendBrsToBase_fn = async function(to, request) {
22934
22956
  }
22935
22957
  const say = request.onProgress ?? (() => {
22936
22958
  });
22937
- await __privateMethod(this, _CloakImpl_instances, ensureRegistered_fn).call(this, __privateGet(this, _s).keys);
22938
- await __privateMethod(this, _CloakImpl_instances, sync_fn).call(this);
22939
22959
  const plan = await __privateMethod(this, _CloakImpl_instances, lzPlan_fn).call(this, amount);
22960
+ await __privateMethod(this, _CloakImpl_instances, sync_fn).call(this);
22940
22961
  const have = (t) => __privateGet(this, _book).forMint(t.mint).reduce((a, n) => a + n.utxo.amount, 0n);
22941
22962
  if (have(token) < plan.brsGross) {
22942
22963
  throw new CloakCallError(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cloak.dev/sdk",
3
3
  "description": "Shield, send, and swap on Solana privately — TypeScript SDK with UTXO-based zero-knowledge transactions",
4
- "version": "0.2.20-staging.456721e",
4
+ "version": "0.2.20-staging.9533cda",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",