diff --git a/README.md b/README.md index 38fab9c..110ff3c 100644 --- a/README.md +++ b/README.md @@ -117,19 +117,21 @@ If a token is **unsupported**, these functions return `Promise`. ### Supported Routes ```ts -// Get all supported routes -const allRoutes = await sdk.getSupportedRoutes(); +// Get all possible routes +const allRoutes = await sdk.getPossibleRoutes(); -// Get all supported routes filtered by source chain -const routesBySourceChain = await sdk.getSupportedRoutes({ fromChain: KnownChainId.BRC20.Mainnet }); +// Get all possible routes filtered by source chain +const routesBySourceChain = await sdk.getPossibleRoutes({ + fromChain: KnownChainId.BRC20.Mainnet, +}); -// Get all supported routes filtered by source and target chain -const routesBySourceAndTargetChain = await sdk.getSupportedRoutes({ +// Get all possible routes filtered by source and target chain +const routesBySourceAndTargetChain = await sdk.getPossibleRoutes({ fromChain: KnownChainId.BRC20.Mainnet, toChain: KnownChainId.EVM.Ethereum, }); -// Check if a specific token pair is supported for at least one route +// Check if a specific token pair is supported for at least one route const isSupported = await sdk.isSupportedRoute({ fromChain: KnownChainId.BRC20.Mainnet, toChain: KnownChainId.EVM.Ethereum, @@ -139,7 +141,7 @@ const isSupported = await sdk.isSupportedRoute({ // If the token pair is supported, get all available routes for that pair if (isSupported) { - const routesByPair = await sdk.getSupportedRoutes({ + const routesByPair = await sdk.getPossibleRoutes({ fromChain: KnownChainId.BRC20.Mainnet, toChain: KnownChainId.EVM.Ethereum, fromToken: brc20Token as KnownTokenId.BRC20Token, @@ -188,7 +190,7 @@ Once the route is validated, the cross-chain transfer can be initiated. These me ```ts import { BridgeFromStacksInput, toSDKNumberOrUndefined, KnownChainId, KnownTokenId } from "@brotocol-xyz/bro-sdk"; -import { makeContractCall, broadcastTransaction } from "@stacks/transactions"; +import { makeContractCall, broadcastTransaction, deserializeCV } from "@stacks/transactions"; // Define bridge operation input const bridgeFromStacksInput: BridgeFromStacksInput = { @@ -213,7 +215,8 @@ const bridgeFromStacksInput: BridgeFromStacksInput = { contractAddress: tx.contractAddress, contractName: tx.contractName, functionName: tx.functionName, - functionArgs: tx.functionArgs, + // Deserialize each element of functionArgs and convert it into ClarityValue + functionArgs: tx.functionArgs.map(arg => deserializeCV(arg)), postConditions: [] /* Add post conditions */, validateWithAbi: true, senderKey: "b244296d5907de9864c0b0d51f98a13c52890be0404e83f273144cd5b9960eed01", @@ -230,6 +233,12 @@ const result = await sdk.bridgeFromStacks(bridgeFromStacksInput); console.log("Stacks Transaction ID:", result.txid); ``` +> [!NOTE] +> The `tx.functionArgs` field provided by the SDK is of type `SerializedClarityValue[]`. +> This differs from the `functionArgs` expected by the Stacks.js `makeContractCall` method, which requires `ClarityValue[]`. +> +> This design decision was intentional to maintain compatibility with both [Stacks.js](https://github.com/hirosystems/stacks.js) v6 and v7, as the implementation details of `ClarityValue` type differ between both versions. By using a serialized format, the SDK ensures flexibility and avoids locking users into a specific version of the Stacks.js library. + ### Bridge From EVM > [!IMPORTANT] diff --git a/docs/readmeCodeSnippets.ts b/docs/readmeCodeSnippets.ts index 60506d8..dce1e06 100644 --- a/docs/readmeCodeSnippets.ts +++ b/docs/readmeCodeSnippets.ts @@ -1,8 +1,8 @@ -import { XLinkSDK } from "../src/index"; +import { BroSDK } from "../src/index"; /* eslint-disable @typescript-eslint/no-unused-vars */ -const sdk = new XLinkSDK(); +const sdk = new BroSDK(); // Supported Chains @@ -53,16 +53,16 @@ const evmToken = await sdk.evmAddressToEVMToken( // Supported routes -// Get all supported routes -const allRoutes = await sdk.getSupportedRoutes(); +// Get all possible routes +const allRoutes = await sdk.getPossibleRoutes(); -// Get all supported routes filtered by source chain -const routesBySourceChain = await sdk.getSupportedRoutes({ +// Get all possible routes filtered by source chain +const routesBySourceChain = await sdk.getPossibleRoutes({ fromChain: KnownChainId.BRC20.Mainnet, }); -// Get all supported routes filtered by source and target chain -const routesBySourceAndTargetChain = await sdk.getSupportedRoutes({ +// Get all possible routes filtered by source and target chain +const routesBySourceAndTargetChain = await sdk.getPossibleRoutes({ fromChain: KnownChainId.BRC20.Mainnet, toChain: KnownChainId.EVM.Ethereum, }); @@ -77,7 +77,7 @@ const isSupported = await sdk.isSupportedRoute({ // If the token pair is supported, get all available routes for that pair if (isSupported) { - const routesByPair = await sdk.getSupportedRoutes({ + const routesByPair = await sdk.getPossibleRoutes({ fromChain: KnownChainId.BRC20.Mainnet, toChain: KnownChainId.EVM.Ethereum, fromToken: brc20Token as KnownTokenId.BRC20Token, @@ -87,8 +87,8 @@ if (isSupported) { // Bridge From Stacks -import { makeContractCall, broadcastTransaction } from "@stacks/transactions"; -import { ContractCallOptions } from "../src/stacksUtils/xlinkContractHelpers"; +import { makeContractCall, broadcastTransaction, deserializeCV } from "@stacks/transactions"; +import { ContractCallOptions } from "../src/stacksUtils/contractHelpers"; import { BridgeFromStacksInput, toSDKNumberOrUndefined } from "../src/index"; // Retrieve bridge information @@ -125,8 +125,8 @@ const bridgeFromStacksInput: BridgeFromStacksInput = { contractAddress: tx.contractAddress, contractName: tx.contractName, functionName: tx.functionName, - // TODO: deserialize each element of functionArgs and convert it into ClarityValue[] - functionArgs: tx.functionArgs, + // Deserialize each element of functionArgs and convert it into ClarityValue[] + functionArgs: tx.functionArgs.map(arg => deserializeCV(arg)), postConditions: [] /* Add post conditions */, validateWithAbi: true, senderKey: diff --git a/package.json b/package.json index 080acc1..55be2a3 100644 --- a/package.json +++ b/package.json @@ -69,6 +69,7 @@ "devDependencies": { "@stacks/stacks-blockchain-api-types": "^7.14.1", "@types/big.js": "^6.2.2", + "@types/node": "^22.14.1", "@typescript-eslint/eslint-plugin": "^8.24.0", "@typescript-eslint/parser": "^8.24.0", "eslint": "^9.20.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 582f2ef..93f9525 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,6 +39,9 @@ importers: '@types/big.js': specifier: ^6.2.2 version: 6.2.2 + '@types/node': + specifier: ^22.14.1 + version: 22.14.1 '@typescript-eslint/eslint-plugin': specifier: ^8.24.0 version: 8.30.1(@typescript-eslint/parser@8.30.1(eslint@9.25.0)(typescript@5.8.2))(eslint@9.25.0)(typescript@5.8.2) @@ -71,7 +74,7 @@ importers: version: 5.8.2 vitest: specifier: ^3.0.8 - version: 3.0.9(@types/node@22.13.10) + version: 3.0.9(@types/node@22.14.1) packages: @@ -717,8 +720,8 @@ packages: '@types/json-schema@7.0.15': resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} - '@types/node@22.13.10': - resolution: {integrity: sha512-I6LPUvlRH+O6VRUqYOcMudhaIdUVWfsjnZavnsraHvpBwaEyMN29ry+0UVJhImYL16xsscu0aske3yA+uPOWfw==} + '@types/node@22.14.1': + resolution: {integrity: sha512-u0HuPQwe/dHrItgHHpmw3N2fYCR6x4ivMNbPHRkBVP4CvN+kiRrKHWk3i8tXiO/joPwXLMYvF9TTF0eqgHIuOw==} '@types/unist@3.0.3': resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==} @@ -1711,8 +1714,8 @@ packages: uc.micro@2.1.0: resolution: {integrity: sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==} - undici-types@6.20.0: - resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==} + undici-types@6.21.0: + resolution: {integrity: sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==} uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} @@ -2299,10 +2302,9 @@ snapshots: '@types/json-schema@7.0.15': {} - '@types/node@22.13.10': + '@types/node@22.14.1': dependencies: - undici-types: 6.20.0 - optional: true + undici-types: 6.21.0 '@types/unist@3.0.3': {} @@ -2390,13 +2392,13 @@ snapshots: chai: 5.2.0 tinyrainbow: 2.0.0 - '@vitest/mocker@3.0.9(vite@5.3.5(@types/node@22.13.10))': + '@vitest/mocker@3.0.9(vite@5.3.5(@types/node@22.14.1))': dependencies: '@vitest/spy': 3.0.9 estree-walker: 3.0.3 magic-string: 0.30.17 optionalDependencies: - vite: 5.3.5(@types/node@22.13.10) + vite: 5.3.5(@types/node@22.14.1) '@vitest/pretty-format@3.0.9': dependencies: @@ -3334,8 +3336,7 @@ snapshots: uc.micro@2.1.0: {} - undici-types@6.20.0: - optional: true + undici-types@6.21.0: {} uri-js@4.4.1: dependencies: @@ -3358,13 +3359,13 @@ snapshots: - utf-8-validate - zod - vite-node@3.0.9(@types/node@22.13.10): + vite-node@3.0.9(@types/node@22.14.1): dependencies: cac: 6.7.14 debug: 4.4.0 es-module-lexer: 1.6.0 pathe: 2.0.3 - vite: 5.3.5(@types/node@22.13.10) + vite: 5.3.5(@types/node@22.14.1) transitivePeerDependencies: - '@types/node' - less @@ -3375,19 +3376,19 @@ snapshots: - supports-color - terser - vite@5.3.5(@types/node@22.13.10): + vite@5.3.5(@types/node@22.14.1): dependencies: esbuild: 0.21.5 postcss: 8.5.3 rollup: 4.19.1 optionalDependencies: - '@types/node': 22.13.10 + '@types/node': 22.14.1 fsevents: 2.3.3 - vitest@3.0.9(@types/node@22.13.10): + vitest@3.0.9(@types/node@22.14.1): dependencies: '@vitest/expect': 3.0.9 - '@vitest/mocker': 3.0.9(vite@5.3.5(@types/node@22.13.10)) + '@vitest/mocker': 3.0.9(vite@5.3.5(@types/node@22.14.1)) '@vitest/pretty-format': 3.0.9 '@vitest/runner': 3.0.9 '@vitest/snapshot': 3.0.9 @@ -3403,11 +3404,11 @@ snapshots: tinyexec: 0.3.2 tinypool: 1.0.2 tinyrainbow: 2.0.0 - vite: 5.3.5(@types/node@22.13.10) - vite-node: 3.0.9(@types/node@22.13.10) + vite: 5.3.5(@types/node@22.14.1) + vite-node: 3.0.9(@types/node@22.14.1) why-is-node-running: 2.3.0 optionalDependencies: - '@types/node': 22.13.10 + '@types/node': 22.14.1 transitivePeerDependencies: - less - lightningcss