Skip to content

Commit

Permalink
Merge ef6e18a into 3af3438
Browse files Browse the repository at this point in the history
  • Loading branch information
lawsonkight authored Sep 25, 2024
2 parents 3af3438 + ef6e18a commit 4571733
Show file tree
Hide file tree
Showing 73 changed files with 3,009 additions and 1,482 deletions.
19 changes: 19 additions & 0 deletions docs/bridge/docs/01-About/Synapse-DAO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
sidebar_position: 0
title: Synapse DAO
---

# Synapse DAO

Since launch of the Synapse Protocol, a number of governance initiatives have been put forward and voted on by the Synapse DAO.

## Governance Model

SYN holders with more than 100,000 SYN tokens can put forward proposals to be be voted on by the DAO. SYN holders can vote using SYN on multiple chains, or delegate their votes to other token holders.

In order to be adopted by the DAO, a proposal must gather at least `50% + 1` of all votes and reach the minimum quorum of 5 million SYN tokens.

## Governance Components

* [Forum](https://forum.synapseprotocol.com/): A Platform to post proposals for discussion before an official vote
* [Snapshot](https://snapshot.org/#/synapseprotocol.eth): A decentralized governance platform for conducting official votes.
70 changes: 70 additions & 0 deletions docs/bridge/docs/01-About/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
title: About
---
<br />

![Synapse mark](/img/synapse-mark.svg)

# Use Synapse

Synapse is an Interchain Programming Interface. Developers read and write interchain data with Synapse, which has settled $50B in transactions between 2M+ users, and generated $30M+ in fees [[source](https://explorer.synapseprotol.com)].

## Why Synapse?

_Description of top benefits Synapse brings to developers and users._


## Developer Guide

* **[Send and receive interchain data](#)**
* **[On-chain swaps](#)**
* **[Interchain swaps](#)**
* **[Upgrade to Synapse](#)**

:::tip[Supported Chains]

Synapse supports every chain and token that can be found on the [Synapse Bridge](https://synapseprotocol.com).

:::

## Interchain Bridge

Embed the Synapse Widget or build your own custom instance.

* **[Widget](/docs/Bridge/Widget)** – Embed a customized Synapse Bridge in your application.
* **[SDK](/docs/Bridge/SDK)** – Call Synapse Router functions from your frontend or backend application.

## Routers

Synapse offers several of routers for different transaction types.

* **[Synapse Router](/docs/Routers/Synapse-Router)** – Executable quotes for arbitrary blockchain transactions.
* **[CCTP](/docs/Routers/CCTP)** – Native router for USDC transactions.
* **[RFQ](/docs/Routers/RFQ)** – Fast router that allows on-chain agents to bid on interchain delivery.

## Essential Services

Bolt-on services for reliability and ease-of-use:

* **[Scribe](/docs/Services/Scribe)** – Index logs, receipts and transactions across multiple chains
* **[Omnirpc](/docs/Services/Omnirpc)** – Interchain RPC load balancer and verifier
* **[Key management](/docs/Services/Signer)** – Support for the AWS Key Management System (KMS)
* **[Ethergo](/docs/Services/Submitter)** – Gas management service to ensure transaction confirmation
* **[Telemetry](/docs/Services/Observability)** – Open telemetry system for Synapse SDK


## Community & Support

Connect with other developers and the Synapse team

* **[Discord](https://discord.gg/synapseprotocol)**
* **[Twitter](https://twitter.com/SynapseProtocol)**
* **[Telegram](https://t.me/synapseprotocol)**
* **[Forum](https://forum.synapseprotocol.com/)**

## Additional Links

Synapse transactions can be observed confirmed via the following methods:

* **[Synapse Bridge](https://synapseprotocol.com)** – Bridge, Swap, and Stake via Synapse's cross-chain pools.
* **[Synapse Explorer](https://explorer.synapseprotocol.com)** – Public explorer for Synapse Bridge transactions.
7 changes: 7 additions & 0 deletions docs/bridge/docs/02-Bridge/01-Widget.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: Widget
---

# Bridge Widget

Lorem ipsum
270 changes: 270 additions & 0 deletions docs/bridge/docs/02-Bridge/02-SDK/Examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,270 @@
---
sidebar_label: Examples
---

# SDK Examples

Implemented Bridge SDK examples

## Basic Implementation

```js
import { JsonRpcProvider } from '@ethersproject/providers'
import { Provider } from '@ethersproject/abstract-provider'
import { SynapseSDK } from '@synapsecns/sdk-router'
import { BigNumber } from '@ethersproject/bignumber'

//Set up providers (RPCs) for each chain desired**
const arbitrumProvider: Provider = new JsonRpcProvider('https://arb1.arbitrum.io/rpc')
const avalancheProvider: Provider = new JsonRpcProvider('https://api.avax.network/ext/bc/C/rpc')

//Structure arguments properly
const chainIds = [42161, 43114]
const providers = [arbitrumProvider, avalancheProvider]

//Set up a SynapseSDK instance
const Synapse = new SynapseSDK(chainIds, providers)

// quote
const quote = await Synapse.bridgeQuote(
42161, // From Chain
43114, // To Chain
'0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // From Token
'0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664', // To Token
BigNumber.from('20000000'), // Amount
{
deadline: 1234567890,
excludedModules: ['SynapseRFQ'],
originUserAddress: '0x1234567890abcdef1234567890abcdef12345678',
}
)

// bridge
await Synapse.bridge(
'0x0AF91FA049A7e1894F480bFE5bBa20142C6c29a9', // To Address
quote.routerAddress, // bridge router contract address
42161, // Origin Chain
43114, // Destination Chain
'0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // Origin Token Address
BigNumber.from('20000000'), // Amount
quote.originQuery, // Origin query from bridgeQuote()
quote.destQuery // Destination query from bridgeQuote()
)
```

## NextJS

Uses Wagmi, and RainbowKit

### `app.tsx`

```js
import '@styles/global.css'
import '@rainbow-me/rainbowkit/styles.css'
import { SynapseProvider } from '@/utils/SynapseProvider'
import type { AppProps } from 'next/app'
import { Provider as EthersProvider } from '@ethersproject/abstract-provider'
import { JsonRpcProvider } from '@ethersproject/providers'
import { configureChains, createClient, WagmiConfig } from 'wagmi'
import {
mainnet,
arbitrum,
aurora,
avalanche,
bsc,
canto,
fantom,
harmonyOne,
metis,
moonbeam,
moonriver,
optimism,
polygon,
} from 'wagmi/chains'

import {
getDefaultWallets,
RainbowKitProvider,
darkTheme,
} from '@rainbow-me/rainbowkit'
import { alchemyProvider } from 'wagmi/providers/alchemy'
import { publicProvider } from 'wagmi/providers/public'

export default function App({ Component, pageProps }: AppProps) {
const { chains, provider } = configureChains([mainnet,
arbitrum,
aurora,
avalanche,
bsc,
canto,
fantom,
harmonyOne,
metis,
moonbeam,
moonriver,
optimism,
polygon], [
alchemyProvider({ apiKey: 'API_KEY' }),
publicProvider(),
])

const { connectors } = getDefaultWallets({
appName: 'ExampleApp',
chains,
})

const wagmiClient = createClient({
autoConnect: true,
connectors,
provider,
})

// Synapse client params setup example
let synapseProviders: EthersProvider[] = []
chains.map((chain) => {
let rpc: EthersProvider = new JsonRpcProvider(chain.rpcUrls.default.http[0])
synapseProviders.push(rpc)
})

return (
<WagmiConfig client={wagmiClient}>
<RainbowKitProvider chains={chains} theme={darkTheme()}>
<SynapseProvider
chainIds={chains.map((chain) => chain.id)}
providers={synapseProviders}
>
<Component {...pageProps} />
</SynapseProvider>
</RainbowKitProvider>
</WagmiConfig>
)
}
```

### `@/utils/SynapseProvider.tsx`

```js
import { createContext, useContext } from 'react'
import { SynapseSDK } from '@synapsecns/sdk-router'
import { Provider } from '@ethersproject/abstract-provider'

export const SynapseContext = createContext<SynapseSDK>(null)

export const SynapseProvider = ({
children,
chainIds,
providers,
}: {
children: React.ReactNode
chainIds: number[]
providers: Provider[]
}) => {
const sdk = new SynapseSDK(chainIds, providers)
return (
<SynapseContext.Provider value={sdk}>{children}</SynapseContext.Provider>
)
}

export const useSynapseContext = () => useContext(SynapseContext)
```

### `/homepage/index.tsx`

```js
import { useSynapseContext } from '@/utils/SynapseProvider'
import { Zero } from '@ethersproject/constants'
import { useState, useEffect } from 'react'
import { getNetwork } from '@wagmi/core'
import {
DEFAULT_FROM_CHAIN,
DEFAULT_TO_CHAIN,
DEFAULT_FROM_TOKEN,
DEFAULT_TO_TOKEN,
} from '@/constants/bridge'

export default function HomePage({ address }: { address: `0x${string}` }) {
// Get the synapse sdk
const SynapseSDK = useSynapseContext()

// Get the current time
const time = // add logic to get the current unix timestamp
// Example state hooks
const [fromToken, setFromToken] = useState(DEFAULT_FROM_TOKEN)
const [toToken, setToToken] = useState(DEFAULT_TO_TOKEN)
const [fromChainId, setFromChainId] = useState(DEFAULT_FROM_CHAIN)
const [toChainId, setToChainId] = useState(DEFAULT_TO_CHAIN)
const [amount, setAmount] = useState(Zero)
const [bridgeQuote, setBridgeQuote] = useState({
outputAmountString: '',
quotes: { originQuery: null, destQuery: null },
})

// Set connected network when component is mounted
useEffect(() => {
const { chain: fromChainIdRaw } = getNetwork()
setFromChainId(fromChainIdRaw ? fromChainIdRaw?.id : DEFAULT_FROM_CHAIN)
}, [])

// Get Quote function
// Suggestion: this function should be triggered from an useEffect when amount or to/from token/chain is altered
const getQuote = async () = {
SynapseSDK.bridgeQuote(
fromChainId,
toChainId,
fromToken,
toToken,
amount,
{
deadline: time + 10000,
excludedModules: [],
originUserAddress: address,
}
)
.then(
({ feeAmount, bridgeFee, maxAmountOut, originQuery, destQuery }) => {
let toValueBigNum = maxAmountOut ?? Zero
let toValueBase = toValueBigNum.div(toDecimals).toString()
let toValueMantissa = toValueBigNum.mod(toDecimals).toString()

setBridgeQuote({
outputAmountString: toValueBase + '.' + toValueMantissa,
quotes: {
originQuery,
destQuery,
},
})
// do something
}
)
.catch((err) => {
alert('error getting quote', err)
// do something
})

}

// Execute bridge function
const executeBridge = async () = {
await Synapse.bridge(
toAddress, // To Address
bridgeQuote.routerAddress, // bridge router contract address
fromChainId, // Origin Chain
toChainId, // Destination Chain
fromToken, // Origin Token Address
amount, // Amount
bridgeQuote.quotes.originQuery, // Origin query from bridgeQuote()
bridgeQuote.quotes.destQuery // Destination query from bridgeQuote()
).then(({to, data}) => {
// do something
}
)
.catch((err) => {
alert('error bridging', err)
// do something
})
}

// ...

}
```
Loading

0 comments on commit 4571733

Please sign in to comment.