Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: refactor api #61

Merged
merged 44 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f3da187
validate /w team
BeroBurny Sep 26, 2024
47afc40
swap `zod` with `superstruct`
BeroBurny Sep 26, 2024
3956863
first case for api refactor
BeroBurny Sep 26, 2024
ce3b88c
move sprinter to separate file
BeroBurny Sep 26, 2024
db2a9cf
refactor
BeroBurny Sep 26, 2024
18f768b
smoll fixes
BeroBurny Sep 30, 2024
b1151a8
sprinter class docs
BeroBurny Sep 30, 2024
c72bc78
add enum :man_shrugging:
BeroBurny Sep 30, 2024
ddd45f2
micro bug fixes
BeroBurny Sep 30, 2024
c61895f
refactor POC to match new SDK
BeroBurny Sep 30, 2024
ed12547
lint
BeroBurny Sep 30, 2024
9c4272d
change sprinter sdk from dependencies to peer dependencies
BeroBurny Sep 30, 2024
2121e83
partially refactor react sdk
BeroBurny Sep 30, 2024
b8656c9
react sdk docs and smool fix
BeroBurny Oct 1, 2024
4d73265
fix yarn.lock
BeroBurny Oct 1, 2024
c84f104
fix ci
BeroBurny Oct 1, 2024
33ef698
fix yarn command
BeroBurny Oct 1, 2024
c5e921d
save
BeroBurny Oct 8, 2024
a7f93e3
save general
BeroBurny Oct 8, 2024
56231ea
refactor `sourceChains` behavior for single hop
BeroBurny Oct 8, 2024
dd1d8c8
sdk docs v1 on new approach
BeroBurny Oct 8, 2024
e46aeed
react docs v1
BeroBurny Oct 8, 2024
7f72af1
Merge branch 'master' into beroburny/api-refactor
BeroBurny Oct 8, 2024
046d431
dirty fix
BeroBurny Oct 8, 2024
a75d753
wtf is that? remove! purger!
BeroBurny Oct 8, 2024
f45864e
prettify category and push overview into index
BeroBurny Oct 9, 2024
eeb6625
fix example response for available tokens
BeroBurny Oct 9, 2024
0589132
fix network list
BeroBurny Oct 10, 2024
2efbfd7
implement remark plugins
BeroBurny Oct 10, 2024
fbe318b
fix `recipient`
BeroBurny Oct 10, 2024
7d69042
implement calldata usages
BeroBurny Oct 10, 2024
b86162e
gas tips
BeroBurny Oct 10, 2024
9acc443
smoll fix
BeroBurny Oct 10, 2024
a4ddc83
refactor gas tip
BeroBurny Oct 14, 2024
bc516e4
implement tabs in bridge and call
BeroBurny Oct 15, 2024
dfad461
ci / cd
BeroBurny Oct 15, 2024
e1fd86c
gas limit
BeroBurny Oct 15, 2024
2566a3c
aggregate
BeroBurny Oct 15, 2024
06a56ac
fix links
BeroBurny Oct 15, 2024
2ca9ae6
breaking changes docs
BeroBurny Oct 16, 2024
33156ae
comments
BeroBurny Oct 18, 2024
edc6911
curl example
BeroBurny Oct 18, 2024
6622bd5
address comments regarding method names
BeroBurny Oct 24, 2024
9b04fb4
fix breaking changes doc
BeroBurny Oct 24, 2024
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
11 changes: 11 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,14 @@ jobs:

- run: yarn workspaces foreach --all -v --exclude root --no-private npm publish --tolerate-republish --access public
if: ${{ steps.release.outputs.releases_created }}

- name: Publish Docs to Cloudflare Pages
if: ${{ steps.release.outputs.releases_created }}
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: 2238a825c5aca59233eab1f221f7aefb
projectName: gopher-docs-preview
directory: ./docs/build
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref || github.ref_name }}
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
- run: corepack enable
- name: Install deps
run: yarn --immutable
- name: Lint
run: yarn run lint
- name: Build
run: yarn build
- name: Lint
run: yarn run lint
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
- name: "Unit Tests"
Expand All @@ -38,12 +38,12 @@ jobs:
directory: ./web/.svelte-kit/cloudflare
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref || github.ref_name }}
- name: Publish Docs to Cloudflare Pages
- name: Publish Preview Docs to Cloudflare Pages
uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: 2238a825c5aca59233eab1f221f7aefb
projectName: gopher-docs
projectName: gopher-docs-preview
directory: ./docs/build
gitHubToken: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.head_ref || github.ref_name }}
3 changes: 1 addition & 2 deletions docs/docs/01-introduction/01-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ Sprinter is a **fast, smooth, interoperable intent execution engine**. Our aim i
## What's Next

- If you're new to Sprinter, begin with [Quick Start](../02-quick-start.md).
- Explore detailed examples and advanced usage in the [SDK Documentation](../03-sdk/01-overview.md).
- Dive into the specifics of our API in the [API Documentation](../04-api/01-api-usage.md).
- Explore detailed examples and advanced usage in the [SDK Documentation](../sdk).

Stay tuned for the complete source code.

Expand Down
6 changes: 2 additions & 4 deletions docs/docs/01-introduction/04-supported-networks.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Supported Bridges And Networks
sidebar_position: 4
---

import SankeyNetworkToken from '@site/src/components/SankeyNetworkToken';
import SupportedList from '@site/src/components/SupportedList';

:::tip
New routes, networks, and tokens can readily be added by the Sprinter team. Please reach out at [[email protected]](mailto:[email protected]) to get a conversation started.
Expand All @@ -22,6 +22,4 @@ New routes, networks, and tokens can readily be added by the Sprinter team. Plea
Hover over network icon or token to show available routes
:::

| Mainnet | Testnet |
|--------------------------|------------|
| <SankeyNetworkToken url="https://api.sprinter.buildwithsygma.com/" /> | <SankeyNetworkToken url="https://api.test.sprinter.buildwithsygma.com/" /> |
<SupportedList />
BeroBurny marked this conversation as resolved.
Show resolved Hide resolved
91 changes: 72 additions & 19 deletions docs/docs/02-quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,99 @@ title: Quick Start
sidebar_position: 2
---

You have two main options for interacting with Sprinter:
## Quick Examples

Jump to the section that fits your development needs:

- [Using the SDK](#using-the-sdk)
- [Using the React SDK](#using-the-react-sdk)
- [Calling API Endpoints Directly](#calling-api-endpoints-directly)

You have three main options for interacting with Sprinter, depending on your development environment and the level of control you need:

- **Using the SDK**: Ideal for developers working in TypeScript or modern JavaScript frameworks. The SDK provides a simple, unified interface for retrieving intent-based solutions from Sprinter, helping developers easily determine the actions or transactions users should execute on the blockchain.

- **Using the React SDK**: Designed for React developers, this option offers hooks and context that make it simple to access intent-based solutions provided by Sprinter within React components, allowing seamless interaction with the intent engine.

- **Calling API Endpoints Directly**: This option is best suited for developers who want full control over API interactions. It’s flexible and can be used in any programming environment, but requires a deeper understanding of the Sprinter protocol. We recommend this for advanced users or those working in non-JavaScript environments.

### Using the SDK

Using the Sprinter SDK provides a convenient and unified interface for blockchain interactions, complete with TypeScript support for enhanced type safety and a better development experience. This approach is recommended for developers working with TypeScript or popular web frameworks.
The Sprinter SDK provides a streamlined interface for retrieving intent-based solutions from Sprinter, with built-in TypeScript support to ensure type safety and an enhanced development experience. This approach is recommended for developers who are comfortable with TypeScript or those working in modern web frameworks.

**Quick Example**

Here's a quick example of how to use the SDK in your project:
Heres a quick example of how to use the SDK in your project:

```typescript
import { Sprinter } from '@chainsafe/sprinter-sdk';
import { Sprinter, Environment } from '@chainsafe/sprinter-sdk';

const sprinter = new Sprinter(window.ethereum);
const sprinter = new Sprinter({ baseUrl: Environment.MAINNET });

sprinter.getUserBalances().then(console.log);
sprinter.getUserBalances('0xYourAddressHere').then(console.log);
```

For a more detailed guide on setting up and using the SDK, refer to the [SDK Documentation](03-sdk/01-overview.md).
For more details on using the SDK, refer to the [SDK Documentation](./sdk).

### Calling API Endpoints Directly
### Using the React SDK

If you prefer more control or wish to implement the solution in a different programming language, you can directly interact with the API endpoints provided by Sprinter.
If you're building a React application, you can use the Sprinter React SDK (`@chainsafe/sprinter-react`), which provides hooks and context to interact with the Sprinter core SDK.

**Quick Example**

Here’s how you can call the API directly using JavaScript's Fetch API:
Here’s how to set up a simple React component to fetch user balances:

```tsx
import React, { useEffect } from 'react';
import { SprinterContext, useSprinterBalances } from '@chainsafe/sprinter-react';
import { Environment } from '@chainsafe/sprinter-sdk';

function BalancesComponent() {
const { balances, getUserBalances } = useSprinterBalances('0xYourAddressHere');

useEffect(() => {
getUserBalances();
}, [getUserBalances]);

if (balances.loading) return <div>Loading...</div>;
if (balances.error) return <div>Error: {balances.error}</div>;

return (
<ul>
{Object.entries(balances.data || {}).map(([symbol, balanceEntry]) => (
<li key={symbol}>{symbol}: {balanceEntry.total}</li>
))}
</ul>
);
}

function App() {
return (
<SprinterContext baseUrl={Environment.MAINNET}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe change the name of baseUrl to environment

<BalancesComponent />
</SprinterContext>
);
}

export default App;
```

For detailed usage, check the [React SDK Documentation](./react-sdk).

### Calling API Endpoints Directly

This approach provides more control over how you interact with the API but is generally suited for advanced users or developers working in non-JavaScript environments.

:::caution For Advanced Users
Calling the API directly provides the most flexibility but requires a deeper understanding of the Sprinter protocol and how to structure API requests. It's recommended for experienced developers who need full control over API interactions.
:::

**Quick Example**

```javascript
const ownerAddress = "0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519";
const tokenSymbol = "USDC";
const baseUrl = "https://api.sprinter.buildwithsygma.com/";
Here’s how you can call the API directly using `curl`:

fetch(`${baseUrl}/accounts/${ownerAddress}/assets/fungible/${tokenSymbol}`)
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error fetching user fungible tokens:', error));
```bash
curl -X GET "https://api.sprinter.buildwithsygma.com/accounts/0x3E101Ec02e7A48D16DADE204C96bFF842E7E2519/assets/fungible/USDC"
```

For a comprehensive list of available endpoints and how to use them, check out the [API Documentation](04-api/01-api-usage.md).
For a comprehensive list of available endpoints and how to use them, check out the [API Documentation](https://api.sprinter.buildwithsygma.com/swagger/index.html).
97 changes: 0 additions & 97 deletions docs/docs/03-sdk/01-overview.md

This file was deleted.

97 changes: 0 additions & 97 deletions docs/docs/03-sdk/02-advanced-usage.md

This file was deleted.

Loading
Loading