Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions demo/src/components/wallet/LocalSignerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ export function LocalSignerButton({ network, className }: Props) {
<button
type="button"
onClick={() => { setError(undefined); setIsOpen(true); }}
disabled={isConnected && !isLocal}
title={isConnected && !isLocal ? 'Disconnect your wallet before using a local signer' : undefined}
className={cn('cursor-pointer whitespace-nowrap rounded-md border border-line bg-surface px-4 py-2.5 text-sm font-semibold text-fg shadow-sm hover:bg-surface-muted disabled:cursor-not-allowed disabled:opacity-50', className)}
>
{isLocal && address ? `Local · ${truncateAddress(address)}` : 'Local signer'}
Expand All @@ -51,7 +49,7 @@ export function LocalSignerButton({ network, className }: Props) {
<p className="m-0 text-sm text-fg-muted">{chain?.name} · Signs locally</p>
{error && <p role="alert" className="m-0 text-sm text-error">{error}</p>}
<button type="button" onClick={disconnect} disabled={isPending} className="cursor-pointer rounded-sm border-0 bg-primary px-3.5 py-3 text-sm font-semibold text-white disabled:opacity-50">
{isPending ? 'Disconnecting…' : 'Disconnect local signer'}
{isPending ? 'Clearing…' : 'Clear local signer'}
</button>
</div>
) : (
Expand Down
8 changes: 7 additions & 1 deletion demo/src/components/wallet/LocalSignerForm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useId, useRef, useState, type FormEvent } from 'react';
import { useChainId, useChains, useConnect } from 'wagmi';
import { useAccount, useChainId, useChains, useConnect, useDisconnect } from 'wagmi';
import type { LocalSignerConnector } from '../../wallet/local-signer';

interface Props {
Expand All @@ -18,6 +18,8 @@ export function LocalSignerForm({ connector, network, onConnected, onCancel }: P
const [selectedChainId, setSelectedChainId] = useState(currentChainId);
const chainId = chains.find((chain) => chain.id === selectedChainId)?.id ?? chains[0]?.id;
const { connectAsync, isPending } = useConnect();
const { connector: activeConnector, isConnected } = useAccount();
const { disconnectAsync } = useDisconnect();
const [error, setError] = useState<string>();

async function submit(event: FormEvent) {
Expand All @@ -35,6 +37,9 @@ export function LocalSignerForm({ connector, network, onConnected, onCancel }: P
}
try {
// The key never enters Wagmi/React Query mutation variables or storage.
if (isConnected && activeConnector) {
await disconnectAsync({ connector: activeConnector });
}
await connectAsync({ connector, chainId });
onConnected();
} catch {
Expand All @@ -48,6 +53,7 @@ export function LocalSignerForm({ connector, network, onConnected, onCancel }: P
<p id={`${inputId}-help`} className="m-0 text-[13px] leading-relaxed text-fg-muted">
Use a development account. The key stays in this page’s memory until disconnect or reload.
Signing happens locally without wallet confirmation popups.
{isConnected && ' Connecting will disconnect the current EVM wallet.'}
</p>
<label htmlFor={inputId} className="text-sm font-semibold text-fg">EVM private key</label>
<input
Expand Down
20 changes: 20 additions & 0 deletions demo/test/miden-withdraw-recipient.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { AccountId, Address, NoteType, createP2IDNote } from '@miden-sdk/miden-sdk';

test('public P2ID delivery accepts the connected private Miden recipient', () => {
const recipient = AccountId.fromHex('0x0e9089055fb6f54170bbf6159da028');
assert.equal(recipient.isPublic(), false);
const faucet = Address.fromBech32(
'mm1arnfum9xuwwlrvgvrefejwvlavn3vk24_qr7qqq9wr6w',
).accountId();
// Construct a note locally; no client, proof, or network submission is used.
const note = createP2IDNote({
from: '0x5d38246547d94e5165c9e0fafbc667',
to: recipient,
assets: [{ token: faucet, amount: 10000n }],
type: 'public',
});
assert.equal(note.metadata().noteType(), NoteType.Public);
assert.match(note.id().toString(), /^0x[0-9a-f]{64}$/);
});
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,10 @@
"react",
"wagmi",
"viem"
]
],
"pnpm": {
"patchedDependencies": {
"@epoch-protocol/epoch-intents-sdk@1.0.39": "patches/@epoch-protocol__epoch-intents-sdk.patch"
}
}
}
53 changes: 53 additions & 0 deletions patches/@epoch-protocol__epoch-intents-sdk.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
diff --git a/dist/constants.js b/dist/constants.js
index e097c8340879d07992d7430128449e7e7376ea6b..7281fb79c30e251c924200949999f5e45c143911 100644
--- a/dist/constants.js
+++ b/dist/constants.js
@@ -1,4 +1,4 @@
-import { sepolia, baseSepolia, optimismSepolia, polygon, arbitrum, base, optimism, } from "viem/chains";
+import { mainnet, sepolia, baseSepolia, optimismSepolia, polygon, arbitrum, base, optimism, } from "viem/chains";
export { ALLOCATOR_ADDRESS, ARBITER_ADDRESS, getAllocatorAddress, getArbiterAddress, } from "@epoch-protocol/epoch-commons-sdk";
// The Compact is deployed at the same address on all networks
export const COMPACT_ADDRESS = {
@@ -14,6 +14,7 @@ export const COMPACT_ADDRESS = {
999999999: "0x00000000000000171ede64904551eeDF3C6C9788",
};
export const SUPPORTED_CHAINS = [
+ mainnet,
sepolia,
baseSepolia,
optimismSepolia,
diff --git a/dist/gasless/constants.js b/dist/gasless/constants.js
index 8c70395fc1440caffe22c7f4585edc99517dc106..338f9d1ef4051ad1fd745e53d17cf445bdf8b86b 100644
--- a/dist/gasless/constants.js
+++ b/dist/gasless/constants.js
@@ -1,5 +1,9 @@
-/** MetaMask DelegationManager (delegation-framework env on testnets). */
+/** Canonical MetaMask Delegation Framework deployments on supported chains. */
export const DELEGATION_MANAGER_ADDRESS = {
+ 1: "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3",
+ 10: "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3",
+ 137: "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3",
+ 8453: "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3",
11155111: "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3",
11155420: "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3",
84532: "0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3",
@@ -8,6 +12,10 @@ export const DELEGATION_MANAGER_ADDRESS = {
/** EIP-7702 delegated-code prefix (implementation address after 0xef0100). */
/** MetaMask EIP7702StatelessDeleGator — canonical delegate for gasless. */
export const METAMASK_STATELESS_7702_IMPLEMENTATION = {
+ 1: "0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B",
+ 10: "0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B",
+ 137: "0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B",
+ 8453: "0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B",
11155111: "0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B",
11155420: "0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B",
84532: "0x63c0c19a282a1B52b07dD5a65b58948A07DAE32B",
@@ -29,7 +37,7 @@ export function isApproved7702Implementation(chainId, delegateAddress) {
return delegate === metamask || delegate === legacy;
}
export const GASLESS_SUPPORTED_CHAIN_IDS = [
- 84532, 11155111, 11155420, 80002,
+ 1, 10, 137, 8453, 84532, 11155111, 11155420, 80002,
];
/** USDT-style tokens that need approve(0) before a new allowance on some chains. */
export const APPROVE_RESET_TOKENS = {
19 changes: 12 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions src/components/EarnIntentWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ export function EarnIntentWidget(props: EarnIntentWidgetProps) {
earnFlow.stepLabel ?? (smartWithdraw ? "Routing…" : "Withdrawing…")
);
if (earnFlow.isQuoting) return "Fetching quote…";
if (
ctaState.action === "switch" ||
ctaState.action === "retry" ||
ctaState.action === "disabled"
)
if (ctaState.action !== "submit")
return ctaState.label;
// Idle + ready. "Confirm" (not "Review") — the click executes: it re-quotes
// both legs and opens the wallet, it does not open a separate review step.
Expand Down Expand Up @@ -256,4 +252,4 @@ export function EarnIntentWidget(props: EarnIntentWidgetProps) {
{modalView.content}
</Modal>
);
}
}
2 changes: 1 addition & 1 deletion src/components/earn/EarnWithdrawDetailView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function EarnWithdrawDetailView({
midenRecipientAccount={earnMiden?.accountId}
midenFaucets={miden.destFaucets}
buildError={withdrawBuildError}
quoteError={earnFlow.quoteError}
quoteError={earnFlow.error ?? earnFlow.quoteError}
isQuoting={earnFlow.isQuoting}
approxUsd={(() => {
const usd = position.underlyingUsdValue;
Expand Down
11 changes: 11 additions & 0 deletions src/earn/use-earn-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,16 @@ export function useEarnEngine(props: EarnIntentWidgetProps) {
(!earnMiden?.connected || !miden.quoteSource)
)
return;
// A withdraw is sourced from the selected position's chain. Do not quote
// while the connected EVM wallet is still on another chain: the SDK would
// otherwise use the wallet chain as the intent origin and can construct a
// malformed route (for example, an Optimism token looked up on Base).
if (
fundingSource === "evm" &&
effectiveSourceChainId !== null &&
chainId !== effectiveSourceChainId
)
return;
// Destination not yet moved off the position's own chain/token → no route
// to quote. Skip until the user picks a real destination.
if (isSmartWithdrawDegenerate) return;
Expand Down Expand Up @@ -526,6 +536,7 @@ export function useEarnEngine(props: EarnIntentWidgetProps) {
activeMarket,
effectiveSourceChainId,
effectiveSourceToken?.address,
chainId,
address,
earnTab,
smartWithdraw,
Expand Down
31 changes: 28 additions & 3 deletions src/earn/use-earn-intent-flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,14 @@ export function useEarnIntentFlow({
pendingQuoteRef.current = null;

try {
const originChainId = params.isMidenDeposit ? input.sourceChainId : undefined;
// Withdrawals originate on the position's chain, not necessarily on
// the wallet's currently selected chain. Keeping this explicit avoids
// asking SIO/dex solvers to resolve a position token on the wrong EVM
// chain while the UI is switching networks.
const originChainId =
params.isMidenDeposit || input.tab === 'withdraw'
? input.sourceChainId
: undefined;
const sdk = createEarnIntentSdk(apiBaseUrl, walletClient, originChainId);

const { taskTypeString, intentData } = await sdk.getTaskData({
Expand Down Expand Up @@ -625,6 +632,22 @@ export function useEarnIntentFlow({
try {
const statusList = await sdk.getIntentStatus(address, nonceStr);
if (!mountedRef.current) return;
const failed = Array.isArray(statusList) && statusList.some(
(s: { status?: string }) => s.status?.toLowerCase() === 'failed',
);
if (failed) {
if (pollingRef.current) {
clearInterval(pollingRef.current);
pollingRef.current = null;
}
const failure = new Error('Intent execution failed on-chain. No deposit was completed.');
setStatus('error');
setError(failure.message);
setStatusProgress(0);
setActiveStep(0);
onErrorRef.current?.({ sessionId, error: failure });
return;
}
const isComplete = Array.isArray(statusList)
? statusList.some(
(s: { status?: string }) =>
Expand Down Expand Up @@ -740,7 +763,7 @@ export function useEarnIntentFlow({
setStatus('submitting');
setActiveStep(1);
setStatusProgress(10);
setStepLabel('Quoting withdrawal…');
setStepLabel('Preparing withdrawal and bridge quote…');
onStartRef.current?.({ sessionId, mode: 'earn' });
swLog('submit:begin — executeActions(Withdraw)', {
amount: input.amount,
Expand Down Expand Up @@ -873,7 +896,9 @@ export function useEarnIntentFlow({
const submitParams = buildParams(input);
const originChainId =
pendingQuoteRef.current?.originChainId ??
(submitParams.isMidenDeposit ? input.sourceChainId : undefined);
(submitParams.isMidenDeposit || input.tab === 'withdraw'
? input.sourceChainId
: undefined);
const sdk = createEarnIntentSdk(apiBaseUrl, walletClient, originChainId);

let taskTypeString: string;
Expand Down
5 changes: 2 additions & 3 deletions src/earn/use-earn-miden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,14 @@ export function useEarnMiden({

// The withdrawal still executes on the EVM position chain; only the swap-leg
// output is bridged. The connected adapter account is the recipient — the same
// one used to fund Miden deposits.
// one used to fund Miden deposits. Public P2ID notes can target either public
// or private accounts; recipient storage mode does not limit note delivery.
const smartDest = useMemo(() => {
if (
earnTab !== 'withdraw' ||
!smartWithdraw ||
smartDestChainId !== MIDEN_VIRTUAL_CHAIN_ID ||
!earnMiden?.accountId ||
earnMiden.accountIsPublic === false ||
!smartDestTokenAddress
) {
return undefined;
Expand All @@ -224,7 +224,6 @@ export function useEarnMiden({
smartDestChainId,
smartDestTokenAddress,
earnMiden?.accountId,
earnMiden?.accountIsPublic,
graphTokens,
]);

Expand Down
Loading
Loading