diff --git a/docs/docs/03-sdk/01-overview.md b/docs/docs/03-sdk/01-overview.md index 4449abc..1889033 100644 --- a/docs/docs/03-sdk/01-overview.md +++ b/docs/docs/03-sdk/01-overview.md @@ -36,10 +36,10 @@ import { Sprinter } from '@chainsafe/sprinter-sdk'; ### 2. Initialize the Sprinter SDK -To initialize the SDK, create a new instance of the `Sprinter` class with an Ethereum provider: +To initialize the SDK, create a new instance of the `Sprinter` class: ```typescript -const sprinter = new Sprinter(window.ethereum); +const sprinter = new Sprinter(); ``` ### 3. Fetch User Balances @@ -47,7 +47,8 @@ const sprinter = new Sprinter(window.ethereum); Once initialized, you can fetch the user's balances across multiple blockchains: ```typescript -sprinter.getUserBalances().then(console.log); +const ownerAddress = "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519"; +sprinter.getUserBalances(ownerAddress).then(console.log); ``` ### 4. Get Solution @@ -69,14 +70,17 @@ Here's a more detailed example that combines all the basic operations: ```typescript import { Sprinter } from '@chainsafe/sprinter-sdk'; -const sprinter = new Sprinter(window.ethereum); +const sprinter = new Sprinter(); + +const ownerAddress = "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519"; // Fetch user balances -sprinter.getUserBalances().then(balances => { +sprinter.getUserBalances(ownerAddress).then(balances => { console.log('User balances:', balances); // Get solution for transactions return sprinter.getSolution({ + account: ownerAddress, token: "USDC", destinationChain: 42161, // Destination chain ID amount: "1000000000" // Amount in the smallest unit (e.g., wei) diff --git a/docs/docs/03-sdk/02-advanced-usage.md b/docs/docs/03-sdk/02-advanced-usage.md index d4b4c6f..3cf8960 100644 --- a/docs/docs/03-sdk/02-advanced-usage.md +++ b/docs/docs/03-sdk/02-advanced-usage.md @@ -11,7 +11,8 @@ The dApp is responsible for handling errors that occur during the transaction pr ### Example ```typescript -sprinter.getUserBalances() +const ownerAddress = "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519"; +sprinter.getUserBalances(ownerAddress) .then(balances => { console.log('User balances:', balances); }) @@ -31,7 +32,9 @@ The Sprinter SDK allows you to customize requests to suit your application's nee ### Example ```typescript +const ownerAddress = "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519"; sprinter.getSolution({ + account: ownerAddress, token: "USDC", destinationChain: 42161, // Destination chain ID amount: "1000000000" // Amount in the smallest unit (e.g., wei) @@ -58,12 +61,13 @@ async function integrateWithWeb3() { const web3 = new Web3(window.ethereum); const accounts = await web3.eth.requestAccounts(); - const sprinter = new Sprinter(window.ethereum); + const sprinter = new Sprinter(); - const balances = await sprinter.getUserBalances(); + const balances = await sprinter.getUserBalances(accounts[0]); console.log('User balances:', balances); const solution = await sprinter.getSolution({ + account: accounts[0], token: "USDC", destinationChain: 42161, amount: "1000000000" diff --git a/docs/docs/03-sdk/03-class-reference.md b/docs/docs/03-sdk/03-class-reference.md index 70e23b7..edba76a 100644 --- a/docs/docs/03-sdk/03-class-reference.md +++ b/docs/docs/03-sdk/03-class-reference.md @@ -8,18 +8,18 @@ This section details the methods available to the `Sprinter` class in the Sprint ## Methods -### `constructor(provider: EIP1193Provider)` +### `constructor(fetchOptions: Omit)` Initializes the SDK with the given Ethereum provider. #### Parameters -- `provider`: An Ethereum provider instance conforming to the EIP-1193 standard (e.g., `window.ethereum`). +- `fetchOptions`: TODO :Sad: #### Example ```typescript -const sprinter = new Sprinter(window.ethereum); +const sprinter = new Sprinter(); ``` ### `getAvailableTokens(): Promise` @@ -54,12 +54,13 @@ sprinter.getAvailableChains().then(chains => { }); ``` -### `getUserBalances(tokens?: FungibleToken[]): Promise<{ [symbol: TokenSymbol]: { balances: FungibleTokenBalance[]; total: string } }>` +### `getUserBalances(account: Address, tokens?: FungibleToken[]): Promise<{ [symbol: TokenSymbol]: { balances: FungibleTokenBalance[]; total: string } }>` Fetches the user's balances for specified tokens across multiple blockchains. If no tokens are specified, it fetches balances for all available tokens. #### Parameters +- `account`: Targeted account address. - `tokens`: An optional array of fungible token objects. #### Returns @@ -69,24 +70,25 @@ Fetches the user's balances for specified tokens across multiple blockchains. If #### Example ```typescript -sprinter.getUserBalances().then(balances => { +const ownerAddress = "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519"; +sprinter.getUserBalances(ownerAddress).then(balances => { console.log('User balances:', balances); }); ``` -### `getSolution(settings: Omit, targetAccount?: Address): Promise` +### `getSolution(settings: SolutionOptions): Promise` Retrieves the optimal solution for managing cross-chain transactions based on the provided settings. #### Parameters - `settings`: An object containing the parameters for the solution request, excluding the account. - - `token`: The token symbol (e.g., "USDC"). - - `destinationChain`: The ID of the destination blockchain. - - `amount`: The amount to be transferred. - - `threshold?`: An optional threshold parameter. - - `whitelistedSourceChains?`: An optional array of whitelisted source chain IDs. -- `targetAccount`: An optional account address. If not provided, the current account will be used. + - `account`: Targeted account address. + - `token`: The token symbol (e.g., "USDC"). + - `destinationChain`: The ID of the destination blockchain. + - `amount`: The amount to be transferred. + - `threshold?`: An optional threshold parameter. + - `whitelistedSourceChains?`: An optional array of whitelisted source chain IDs. #### Returns @@ -95,7 +97,9 @@ Retrieves the optimal solution for managing cross-chain transactions based on th #### Example ```typescript +const ownerAddress = "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519"; sprinter.getSolution({ + account: ownerAddress, token: "USDC", destinationChain: 42161, // Destination chain ID amount: 1000000000 // Amount in the smallest unit (e.g., wei) diff --git a/packages/sdk/README.md b/packages/sdk/README.md index a505544..e3bbf07 100644 --- a/packages/sdk/README.md +++ b/packages/sdk/README.md @@ -25,9 +25,10 @@ The `Sprinter` class provides a convenient interface for interacting with the bl ```typescript import { Sprinter } from '@chainsafe/sprinter-sdk'; -const sprinter = new Sprinter(window.ethereum); +const sprinter = new Sprinter(); -sprinter.getUserBalances().then(console.log); +const ownerAddress = "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519"; +sprinter.getUserBalances(ownerAddress).then(console.log); ``` ### Calling API Endpoints Directly diff --git a/packages/sdk/package.json b/packages/sdk/package.json index babc2ab..f02df56 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -13,7 +13,6 @@ "devDependencies": { "@types/eslint": "^8.56.11", "@types/node": "18.19.42", - "eip1193-types": "^0.2.1", "eslint": "^8.57.0", "typescript": "^5.0.3" } diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index c4ec052..215090f 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -1,5 +1,3 @@ -import { EIP1193Provider } from "eip1193-types"; - import { getFungibleTokens, getSolution, @@ -27,19 +25,13 @@ export * as api from "./api"; export * from "./enums"; class Sprinter { - #provider: EIP1193Provider; - - // local "cache" + // in memory "cache" #tokens?: FungibleToken[]; #chains?: Chain[]; #fetchOptions: Omit; - constructor( - provider: EIP1193Provider, - fetchOptions: Omit = {}, - ) { - this.#provider = provider; + constructor(fetchOptions: Omit = {}) { this.#fetchOptions = fetchOptions; } @@ -60,13 +52,12 @@ class Sprinter { } public async getUserBalances( + account: Address, tokens?: FungibleToken[], options: FetchOptions = {}, ): Promise<{ [sybol: TokenSymbol]: { balances: FungibleTokenBalance[]; total: string }; }> { - const account = await this.getAccount(); - const tokenList = tokens || (await this.getAvailableTokens(options)); const balances = await Promise.all( @@ -98,72 +89,47 @@ class Sprinter { } public async getSolution( - settings: Omit, - targetAccount?: Address, + settings: ContractSolutionOptions, options?: FetchOptions, ): Promise; public async getSolution( - settings: Omit, - targetAccount?: Address, + settings: SolutionOptions, options?: FetchOptions, ): Promise; public async getSolution( settings: unknown, - targetAccount?: Address, options?: FetchOptions, ): Promise { - const account = targetAccount || (await this.getAccount()); - if (typeof settings !== "object" || settings === null) throw new Error("Missing settings object"); if ("contractCall" in settings) return await getContractSolution( - { - ...settings, - account, - }, + settings, this.makeFetchOptions(options || {}), ); return await getSolution( - { ...settings, account }, + settings, this.makeFetchOptions(options || {}), ); } public async getCallSolution( - settings: Omit, - targetAccount?: Address, + settings: ContractSolutionOptions, options?: FetchOptions, ): Promise { - const account = targetAccount || (await this.getAccount()); - if (typeof settings !== "object" || settings === null) throw new Error("Missing settings object"); return await getContractCallSolution( - { - ...settings, - account, - }, + settings, this.makeFetchOptions(options || {}), ); } - private async getAccount(): Promise
{ - const [account] = (await this.#provider.request({ - method: "eth_requestAccounts", - params: [], - })) as Address[]; - if (!account) - throw new Error("No available account! Check your provider or something"); - - return account; - } - private makeFetchOptions(options: FetchOptions): FetchOptions { return { ...this.#fetchOptions, ...options }; } } -export { Sprinter, setBaseUrl, BASE_URL, EIP1193Provider }; +export { Sprinter, setBaseUrl, BASE_URL }; diff --git a/web/src/lib/components/Account.svelte b/web/src/lib/components/Account.svelte index 4992e5b..c3727a7 100644 --- a/web/src/lib/components/Account.svelte +++ b/web/src/lib/components/Account.svelte @@ -1,5 +1,4 @@