Skip to content

Commit 590ef83

Browse files
Update @lifi/intent to 0.0.4 and fix breaking API changes
- Bump @lifi/intent from 0.0.3-alpha.1 to 0.0.4 - Add chainNamespace field to CoreToken in toCoreTokenContext - Fix containerToIntent: use 'in' narrowing for proper TypeScript overload resolution - Add StandardSolanaIntent guards in IntentFactory compact/escrow methods - Add StandardSolanaIntent guard in Solver.claim before finaliseIntent Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent a4a59a9 commit 590ef83

5 files changed

Lines changed: 44 additions & 17 deletions

File tree

bun.lock

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@
4646
"vite": "^7.1.1"
4747
},
4848
"dependencies": {
49-
"@lifi/intent": "0.0.3-alpha.1",
5049
"@electric-sql/pglite": "^0.3.15",
50+
"@lifi/intent": "0.0.4",
5151
"@metamask/sdk": "^0.34.0",
5252
"@sveltejs/adapter-cloudflare": "^7.0.3",
5353
"@wagmi/connectors": "^7.2.1",

src/lib/libraries/intentFactory.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,35 @@ import type {
1616
Signature,
1717
StandardOrder
1818
} from "@lifi/intent";
19+
import {
20+
Intent,
21+
IntentApi,
22+
StandardSolanaIntent,
23+
SOLANA_MAINNET_CHAIN_ID,
24+
SOLANA_TESTNET_CHAIN_ID,
25+
SOLANA_DEVNET_CHAIN_ID
26+
} from "@lifi/intent";
1927
import type { AppCreateIntentOptions, AppTokenContext } from "$lib/appTypes";
2028
import { ERC20_ABI } from "$lib/abi/erc20";
21-
import { Intent } from "@lifi/intent";
22-
import { IntentApi } from "@lifi/intent";
2329
import { store } from "$lib/state.svelte";
2430
import { depositAndRegisterCompact, openEscrowIntent, signIntentCompact } from "./intentExecution";
2531
import { intentDeps } from "./coreDeps";
2632

33+
const SOLANA_CHAIN_IDS = new Set([
34+
SOLANA_MAINNET_CHAIN_ID,
35+
SOLANA_TESTNET_CHAIN_ID,
36+
SOLANA_DEVNET_CHAIN_ID
37+
]);
38+
2739
function toCoreTokenContext(input: AppTokenContext): TokenContext {
40+
const chainId = BigInt(input.token.chainId);
2841
return {
2942
token: {
3043
address: input.token.address,
3144
name: input.token.name,
32-
chainId: BigInt(input.token.chainId),
33-
decimals: input.token.decimals
45+
chainId,
46+
decimals: input.token.decimals,
47+
chainNamespace: SOLANA_CHAIN_IDS.has(chainId) ? "solana" : "eip155"
3448
},
3549
amount: input.amount
3650
};
@@ -127,6 +141,8 @@ export class IntentFactory {
127141
const inputChain = inputTokens[0].token.chainId;
128142
if (this.preHook) await this.preHook(inputChain);
129143
const intent = new Intent(toCoreCreateIntentOptions(opts), intentDeps).order();
144+
if (intent instanceof StandardSolanaIntent)
145+
throw new Error("Compact signing is not supported for Solana intents.");
130146

131147
const sponsorSignature = await signIntentCompact(intent, account(), this.walletClient);
132148

@@ -165,6 +181,8 @@ export class IntentFactory {
165181
return async () => {
166182
const { inputTokens, account } = opts;
167183
const intent = new Intent(toCoreCreateIntentOptions(opts), intentDeps).singlechain();
184+
if (intent instanceof StandardSolanaIntent)
185+
throw new Error("Compact deposit and register is not supported for Solana intents.");
168186

169187
if (this.preHook) await this.preHook(inputTokens[0].token.chainId);
170188

@@ -200,6 +218,8 @@ export class IntentFactory {
200218
return async () => {
201219
const { inputTokens, account } = opts;
202220
const intent = new Intent(toCoreCreateIntentOptions(opts), intentDeps).order();
221+
if (intent instanceof StandardSolanaIntent)
222+
throw new Error("openEscrowIntent is not supported for Solana intents.");
203223

204224
const inputChain = inputTokens[0].token.chainId;
205225
if (this.preHook) await this.preHook(inputChain);

src/lib/libraries/solver.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BYTES32_ZERO, COIN_FILLER, getChain, getClient, getOracle, type WC } from "$lib/config";
22
import { hashStruct, maxUint256, parseEventLogs } from "viem";
33
import type { MandateOutput, OrderContainer } from "@lifi/intent";
4-
import { addressToBytes32, bytes32ToAddress } from "@lifi/intent";
4+
import { addressToBytes32, bytes32ToAddress, StandardSolanaIntent } from "@lifi/intent";
55
import axios from "axios";
66
import { POLYMER_ORACLE_ABI } from "$lib/abi/polymeroracle";
77
import { COIN_FILLER_ABI } from "$lib/abi/outputsettler";
@@ -311,6 +311,8 @@ export class Solver {
311311
const { orderContainer, fillTransactionHashes, sourceChainId } = args;
312312
const { order, inputSettler } = orderContainer;
313313
const intent = containerToIntent(orderContainer);
314+
if (intent instanceof StandardSolanaIntent)
315+
throw new Error("Finalise is not supported for Solana input intents.");
314316
if (fillTransactionHashes.length !== order.outputs.length) {
315317
throw new Error(
316318
`Fill transaction hash count (${fillTransactionHashes.length}) does not match output count (${order.outputs.length}).`

src/lib/utils/intent.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@ import {
22
orderToIntent,
33
SOLANA_MAINNET_CHAIN_ID,
44
SOLANA_TESTNET_CHAIN_ID,
5-
SOLANA_DEVNET_CHAIN_ID
5+
SOLANA_DEVNET_CHAIN_ID,
6+
StandardEVMIntent,
7+
StandardSolanaIntent,
8+
MultichainOrderIntent
69
} from "@lifi/intent";
7-
import type { OrderContainer, OrderIntent } from "@lifi/intent";
10+
import type { OrderContainer } from "@lifi/intent";
811

912
const SOLANA_CHAIN_IDS = new Set([
1013
SOLANA_MAINNET_CHAIN_ID,
1114
SOLANA_TESTNET_CHAIN_ID,
1215
SOLANA_DEVNET_CHAIN_ID
1316
]);
1417

15-
function isSolanaOrder(order: OrderContainer["order"]): boolean {
16-
if (!("originChainId" in order)) return false;
17-
return SOLANA_CHAIN_IDS.has(order.originChainId);
18-
}
19-
20-
export function containerToIntent(container: OrderContainer): OrderIntent {
18+
export function containerToIntent(
19+
container: OrderContainer
20+
): StandardEVMIntent | StandardSolanaIntent | MultichainOrderIntent {
2121
const { inputSettler, order } = container;
22-
if (isSolanaOrder(order)) {
22+
if (!("originChainId" in order)) {
23+
return orderToIntent({ namespace: "eip155", inputSettler, order });
24+
}
25+
if (SOLANA_CHAIN_IDS.has(order.originChainId)) {
2326
return orderToIntent({ namespace: "solana", inputSettler, order });
2427
}
2528
return orderToIntent({ namespace: "eip155", inputSettler, order });

0 commit comments

Comments
 (0)