Skip to content
Merged
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
75 changes: 73 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,79 @@ account recipient tag (`context` ends in `0x00`). Stellar routes require the
exclusivity identities for those orders are commitments, not padded EVM
addresses.

Current support is mainnet only. It covers G-account users and recipients,
escrow orders with 1–4 inputs and outputs, and no same-chain Stellar orders.
Builders support G-account users and recipients, escrow orders with 1–4 inputs
and outputs, and no same-chain Stellar orders. Mainnet deployments remain the
defaults. `STELLAR_TESTNET_CHAIN_ID` (`1201081091099711n`) has the testnet
passphrase hash configured, but **no default deployment addresses**.

Supply validated raw contract ids per `Intent` instance through `IntentDeps`:

```ts
import { STELLAR_TESTNET_CHAIN_ID, type IntentDeps } from "@lifi/intent";

type StellarResolver = NonNullable<IntentDeps["getStellarDeployment"]>;
// deployment is the validated public handoff, not credentials or predicted activation data.
const getStellarDeployment: StellarResolver = (chainId) =>
chainId === STELLAR_TESTNET_CHAIN_ID
? {
inputEscrow: stellarStrkeyToBytes32(deployment.stellar.inputEscrow),
outputSettler: stellarStrkeyToBytes32(deployment.stellar.outputSettler),
}
: undefined;
```

Pass `{ getOracle, getStellarDeployment }` as the constructor's dependencies.
The same optional resolver is accepted as the second argument of
`inputSettlerForStellar(chainId, resolver)` and
`outputSettlerForStellar(chainId, resolver)`. Explicit values win, `undefined`
falls back to the known mainnet defaults, and an unresolved testnet fails with
`Unsupported Stellar chain id`. No exported registry is mutated. Keep oracle
selection in `getOracle`; this resolver selects only the two settlers.

`IntentApi.getQuotes` accepts `oracle: { chainId: number | bigint;
namespace?: Namespace; address: string }[]`. Omitted namespaces remain `eip155`.
Set `namespace: "stellar"` for Stellar filters, using a C-StrKey or raw bytes32
contract id (converted to C-StrKey). G-account oracles and filters conflicting
with a route's namespace are rejected before HTTP. Use `new IntentApi(false)`
for the development API; explicitly allow both corridor oracle deployments.
Stellar testnet USDC has 7 decimals, Base Sepolia USDC 6.

`GetQuoteOptions` and `GetQuoteResponse` are exported. A selected quote can also
be typed as `Awaited<ReturnType<IntentApi["getQuotes"]>>["quotes"][number]`.
Keep the whole quote, including `quoteId`, optional `validUntil` (Unix seconds),
`metadata.oracle`, `metadata.quoteReference`, allowances, and `openIntentTx`.
The order type is `oif-user-open-v0`. Stellar `data` is base64 **order ScVal
XDR**, not a signed envelope; it has no `gasRequired`. Decode and pass the exact
ScVal to `open` on returned `to`, then simulate/sign on the selected network.
EVM returns calldata, gas and optional native `value`; Solana and Tron retain
their compute-unit and fee-limit fields. Do not reconstruct a nonce or re-encode
API payloads from preview amounts. This SDK returns quote payloads unchanged.

Order-status/list imports accept G/C-StrKeys as well as existing hex/base58.
Stellar output recipient kinds remain bound to their context tag (`00` account,
`01` contract); conflicting or missing tags fail instead of silently changing
identity. Contract-account users are explicitly unsupported by the G-account
order encoder. Hex claimant commitments remain opaque, never decoded as keys.

Git dependencies run the normal `prepare` build to generate `_esm`, `_cjs` and
`_types` exports (requires Bun and the package's development build dependencies).
Bun consumers must allow this package's lifecycle explicitly with
`"trustedDependencies": ["@lifi/intent"]` in their package manifest; merge that
entry with any existing audited trust list, not a blanket allow-all. The build
also supports Bun's in-place Git preparation under `node_modules`, while
transforming only this package's `src` tree.
Bun 1.4.2 does not install a Git dependency's own devDependencies for this
in-place build. Bun Git consumers must therefore declare these build tools in
their own devDependencies: `rollup: "^4.61.0"`,
`rollup-plugin-esbuild: "^6.2.1"`, `typescript: "^5.6.3"`, and
`@types/bun: "^1.3.8"` (keep compatible existing entries). Install with dev
dependencies enabled. No additional lifecycle trust was needed for those
tools in the verified install; esbuild's optional platform binary worked with
its postinstall still blocked. npm Git installation prepares in its temporary
checkout with the SDK's devDependencies and needs no consumer build-tool entries.
Consumers can pin the final SDK Git commit before a release; replacing that pin
with an npm version requires a later release/tag publication. No new
EVM/Stellar Axelar transport API or private-relay support is introduced here.

## Axelar (Solana)

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"build:markers": "node ./scripts/write-subdir-markers.mjs",
"build:smoke": "node ./scripts/smoke.mjs",
"build": "bun run build:js && bun run build:types && bun run build:markers && bun run build:smoke",
"prepare": "bun run build",
"lint:staged": "prettier -w",
"prepublishOnly": "bun run build && bun run check && bun run test",
"test": "bun test",
Expand Down
4 changes: 4 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export default {
],
plugins: [
esbuild({
// Bun prepares Git dependencies inside node_modules. Match only this
// package's sources instead of excluding every node_modules ancestor.
include: "src/**/*.{js,jsx,ts,tsx}",
exclude: "src/**/node_modules/**",
// Keep in sync with `target` in tsconfig.base.json. esbuild does NOT read
// `target` from a tsconfig (esbuild's `tsconfigRaw` only honours a subset
// of options, and `target` is not among them), so it must be set here
Expand Down
101 changes: 101 additions & 0 deletions src/api/intentApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import {
bytes32ToSolanaBase58,
solanaBase58ToBytes32,
} from "../helpers/solana";
import {
bytes32ToStellarAccount,
bytes32ToStellarContract,
stellarAddressCommitment,
stellarStrkeyToBytes32,
} from "../helpers/stellar";
import { computeStandardStellarId } from "../intent/stellar/standard.stellar";
import { IntentApi, parseOrderStatusPayload } from "./intentApi";

const BYTES32_ONE =
Expand Down Expand Up @@ -198,6 +205,100 @@ describe("parseOrderStatusPayload", () => {
expect(input[0]).toBe(123n);
});

it("imports Stellar strkeys without changing order identity or recipient kind", () => {
const key = `0x${"12".repeat(32)}` as const;
const contract = bytes32ToStellarContract(key);
const account = bytes32ToStellarAccount(key);
const commitment = stellarAddressCommitment(account);
const rawOrder = {
user: key,
nonce: 123n,
originChainId: STELLAR_MAINNET_CHAIN_ID,
expires: 2_000_000_000,
fillDeadline: 1_999_999_900,
inputOracle: key,
inputs: [[BigInt(key), 10_000_000n]] as [bigint, bigint][],
outputs: [
{
oracle: key,
settler: key,
chainId: STELLAR_MAINNET_CHAIN_ID,
token: key,
amount: 10_000_000n,
recipient: key,
callbackData: "0x" as const,
context: "0x01" as const,
},
],
};
for (const [recipient, context] of [
[account, "0x00"],
[contract, "0x01"],
] as const) {
const payload = {
inputSettler: contract,
order: {
...rawOrder,
user: account,
inputOracle: contract,
inputs: [[contract, "10000000"]],
outputs: [
{
...rawOrder.outputs[0],
oracle: contract,
settler: contract,
token: contract,
recipient,
context,
},
],
},
};
const parsed = parseOrderStatusPayload(payload);
if (!isStandardOrder(parsed.order))
throw new Error("Expected standard order");
expect(parsed.inputSettler).toBe(stellarStrkeyToBytes32(contract));
expect(parsed.order).toEqual({
...rawOrder,
outputs: [{ ...rawOrder.outputs[0]!, context }],
});
expect(computeStandardStellarId(parsed.inputSettler, parsed.order)).toBe(
computeStandardStellarId(key, {
...rawOrder,
outputs: [{ ...rawOrder.outputs[0]!, context }],
}),
);
expect(() =>
parseOrderStatusPayload({
...payload,
order: {
...payload.order,
outputs: [
{
...payload.order.outputs[0],
context: context === "0x01" ? "0x00" : "0x01",
},
],
},
}),
).toThrow("recipient kind");
}
const parsedCommitment = parseOrderStatusPayload({
inputSettler: contract,
order: {
...rawOrder,
outputs: [{ ...rawOrder.outputs[0], recipient: commitment }],
},
});
expect(parsedCommitment.order.outputs[0]!.recipient).toBe(commitment);
expect(() =>
parseOrderStatusPayload({
inputSettler: contract,
order: { ...rawOrder, user: contract },
}),
).toThrow("contract users are not supported");
});

it("throws for invalid payload", () => {
expect(() => parseOrderStatusPayload({ data: {} })).toThrow();
});
Expand Down
Loading
Loading