From 6e2328cf083c97336c392a80dd1a2fb218a2519b Mon Sep 17 00:00:00 2001 From: Dong-Ha Kim Date: Thu, 19 Sep 2024 11:20:25 +0200 Subject: [PATCH] feat: add opt `forceOriginChain` to `executeQuote` --- packages/sdk/src/actions/executeQuote.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/sdk/src/actions/executeQuote.ts b/packages/sdk/src/actions/executeQuote.ts index f2427b0..a45de75 100644 --- a/packages/sdk/src/actions/executeQuote.ts +++ b/packages/sdk/src/actions/executeQuote.ts @@ -56,6 +56,7 @@ export type ExecuteQuoteParams = { infiniteApproval?: boolean; skipAllowanceCheck?: boolean; throwOnError?: boolean; + forceOriginChain?: boolean; onProgress?: (progress: ExecutionProgress) => void; }; @@ -69,6 +70,7 @@ export async function executeQuote(params: ExecuteQuoteParams) { skipAllowanceCheck, infiniteApproval, throwOnError = true, + forceOriginChain, onProgress, logger, } = params; @@ -91,6 +93,19 @@ export async function executeQuote(params: ExecuteQuoteParams) { throw new Error("Wallet account has to be set"); } + if (forceOriginChain) { + await walletClient.switchChain({ + id: deposit.originChainId, + }); + } + + const connectedChainId = await walletClient.getChainId(); + if (connectedChainId !== deposit.originChainId) { + throw new Error( + `Connected chain ${connectedChainId} does not match 'originChainId' ${deposit.originChainId}`, + ); + } + const { inputToken, inputAmount, spokePoolAddress } = deposit; // Handle token approval if necessary. This will: