Skip to content

Commit

Permalink
Merge pull request #31 from reservoirprotocol/ted/grwth-4122-sdk-methods
Browse files Browse the repository at this point in the history
Add getSolverCapacity, getCallQuote, getBridgeQuote methods
  • Loading branch information
ted-palmer authored Feb 22, 2024
2 parents 7c4a96f + b59c35a commit d777c8d
Show file tree
Hide file tree
Showing 16 changed files with 484 additions and 86 deletions.
5 changes: 5 additions & 0 deletions .changeset/two-cups-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@reservoir0x/relay-sdk': patch
---

Add getSolverCapacity, getCallQuote, getBridgeQuote methods
16 changes: 14 additions & 2 deletions demo/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,25 @@ const Index: NextPage = () => {
>
<h2>SDK Actions</h2>
<nav style={{ display: 'flex', gap: 15 }}>
<Link href="/sdk/callAction">
<Link href="/sdk/actions/call">
Call
</Link>
<Link href="/sdk/bridgeAction">
<Link href="/sdk/actions/bridge">
Bridge
</Link>
</nav>
<h2>SDK Methods</h2>
<nav style={{ display: 'flex', gap: 15 }}>
<Link href="/sdk/methods/getSolverCapacity">
getSolverCapacity
</Link>
<Link href="/sdk/methods/getCallQuote">
getCallQuote
</Link>
<Link href="/sdk/methods/getBridgeQuote">
getBridgeQuote
</Link>
</nav>
</div>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,38 +43,40 @@ const BridgeActionPage: NextPage = () => {
<label>To: </label>
<input type="number" placeholder='Who is the receiver?' value={to} onChange={(e) => setTo(e.target.value)} />
</div>
<button style={{
marginTop: 50,
padding: 24,
background: 'blue',
color: 'white',
fontSize: 18,
border: '1px solid #ffffff',
borderRadius: 8,
fontWeight: 800,
cursor: 'pointer',
}} onClick={() => {
if (!wallet) {
throw "Please connect to execute transactions"
}
if (to && !isAddress(to)) {
throw "To must be an address"
}
if (!value) {
throw "Must include a value for bridging"
}

getClient()?.actions.bridge({
chainId: fromChainId,
wallet,
toChainId,
value,
to: to ? to as Address : undefined,
onProgress: (steps: any, fees: any) => {
console.log(steps, fees)
<button
style={{
marginTop: 50,
padding: 24,
background: 'blue',
color: 'white',
fontSize: 18,
border: '1px solid #ffffff',
borderRadius: 8,
fontWeight: 800,
cursor: 'pointer',
}}
onClick={() => {
if (!wallet) {
throw "Please connect to execute transactions"
}
if (to && !isAddress(to)) {
throw "To must be an address"
}
})
}}>
if (!value) {
throw "Must include a value for bridging"
}

getClient()?.actions.bridge({
chainId: fromChainId,
wallet,
toChainId,
value,
to: to ? to as Address : undefined,
onProgress: (steps: any, fees: any) => {
console.log(steps, fees)
}
})
}}>
Execute Transactions
</button>
</div>
Expand Down
48 changes: 25 additions & 23 deletions demo/pages/sdk/callAction.tsx → demo/pages/sdk/actions/call.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,30 +69,32 @@ const CallActionPage: NextPage = () => {
</div>
))}
</div>
<button style={{
marginTop: 50,
padding: 24,
background: 'blue',
color: 'white',
fontSize: 18,
border: '1px solid #ffffff',
borderRadius: 8,
fontWeight: 800,
cursor: 'pointer',
}} onClick={() => {
if (!wallet) {
throw "Please connect to execute transactions"
}
getClient()?.actions.call({
chainId: fromChainId,
wallet,
txs: txs as any,
toChainId,
onProgress: (steps: any, fees: any) => {
console.log(steps, fees)
<button
style={{
marginTop: 50,
padding: 24,
background: 'blue',
color: 'white',
fontSize: 18,
border: '1px solid #ffffff',
borderRadius: 8,
fontWeight: 800,
cursor: 'pointer',
}}
onClick={() => {
if (!wallet) {
throw "Please connect to execute transactions"
}
})
}}>
getClient()?.actions.call({
chainId: fromChainId,
wallet,
txs: txs as any,
toChainId,
onProgress: (steps: any, fees: any) => {
console.log(steps, fees)
}
})
}}>
Execute Transactions
</button>
</div>
Expand Down
99 changes: 99 additions & 0 deletions demo/pages/sdk/methods/getBridgeQuote.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
import { NextPage } from 'next'
import { ConnectButton } from '@rainbow-me/rainbowkit'
import { useState } from 'react'
import { Execute, getClient } from '@reservoir0x/relay-sdk'
import { useWalletClient } from 'wagmi'
import { base, baseGoerli, sepolia, zora } from 'viem/chains'
import { Address, isAddress } from 'viem'

const GetBridgeQuotePage: NextPage = () => {
const [to, setTo] = useState<string | undefined>()
const [value, setValue] = useState<string>("")
const [toChainId, setToChainId] = useState<number>(zora.id)
const [fromChainId, setFromChainId] = useState<number>(base.id)
const { data: wallet } = useWalletClient()
const [response, setResponse] = useState<Execute |null>(null)

return (
<div
style={{
display: 'flex',
height: 50,
width: '100%',
gap: 12,
padding: 24,
flexDirection: 'column',
alignItems: 'center',
paddingTop: 150,
}}
>
<ConnectButton />
<div>
<label>To Chain Id: </label>
<input type="number" placeholder='Which chain to bridge to?' value={toChainId} onChange={(e) => setToChainId(Number(e.target.value))} />
</div>
<div>
<label>From Chain Id: </label>
<input type="number" placeholder='Which chain to deposit on?' value={fromChainId} onChange={(e) => setFromChainId(Number(e.target.value))} />
</div>
<div>
<label>Value: </label>
<input type="number" placeholder='How much to bridge?' value={value} onChange={(e) => setValue(e.target.value)} />
</div>
<div>
<label>To: </label>
<input type="number" placeholder='Who is the receiver?' value={to} onChange={(e) => setTo(e.target.value)} />
</div>
<button
style={{
marginTop: 50,
padding: 24,
background: 'blue',
color: 'white',
fontSize: 18,
border: '1px solid #ffffff',
borderRadius: 8,
fontWeight: 800,
cursor: 'pointer',
}}
onClick={async () => {
if (!wallet) {
throw "Please connect to execute transactions"
}
if (to && !isAddress(to)) {
throw "To must be an address"
}
if (!value) {
throw "Must include a value for bridging"
}

const quote = await getClient()?.methods.getBridgeQuote({
chainId: fromChainId,
wallet,
toChainId,
value,
to: to ? to as Address : undefined,
})
setResponse(quote as Execute)
}}>
Get Bridge Quote
</button>
{response && (
<div
style={{
marginTop: 20,
padding: '10px',
background: '#f0f0f0',
borderRadius: '8px',
width: '100%',
maxWidth: 1000,
}}
>
<pre>{JSON.stringify(response, null, 2)}</pre>
</div>
)}
</div>
)
}

export default GetBridgeQuotePage
120 changes: 120 additions & 0 deletions demo/pages/sdk/methods/getCallQuote.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import { NextPage } from 'next'
import { ConnectButton } from '@rainbow-me/rainbowkit'
import { useState } from 'react'
import { Execute, getClient, paths } from '@reservoir0x/relay-sdk'
import { useWalletClient } from 'wagmi'
import { base, baseGoerli, sepolia, zora } from 'viem/chains'


const GetCallQuotePage: NextPage = () => {
const [txs, setTxs] = useState<string[]>([])
const [tx, setTx] = useState<string>("")
const [toChainId, setToChainId] = useState<number>(zora.id)
const [fromChainId, setFromChainId] = useState<number>(base.id)
const { data: wallet } = useWalletClient()
const [response, setResponse] = useState<Execute |null>(null)

return (
<div
style={{
display: 'flex',
height: 50,
width: '100%',
gap: 12,
padding: 24,
flexDirection: 'column',
alignItems: 'center',
paddingTop: 150,
}}
>
<ConnectButton />
<div>
<label>To Chain Id: </label>
<input type="number" placeholder='Which chain to interact with?' value={toChainId} onChange={(e) => setToChainId(Number(e.target.value))} />
</div>
<div>
<label>From Chain Id: </label>
<input type="number" placeholder='Which chain to deposit on?' value={fromChainId} onChange={(e) => setFromChainId(Number(e.target.value))} />
</div>
<textarea style={{minHeight: 100, minWidth: 300}} placeholder='Add a transaction object, must be valid json: {to: "", data: "", value: ""}' value={tx} onChange={(e) => setTx(e.target.value)}/>
<button
style={{
background: 'blue',
color: 'white',
border: '1px solid #ffffff',
borderRadius: 8,
cursor: 'pointer',
padding: "4px 8px",
}}
disabled={!tx}
onClick={() => {
setTxs([...txs, JSON.parse(`${tx}`)])
}}
>
Add Transaction
</button>
<div
style={{
marginTop: 10,
border: '1px solid gray',
borderRadius: 4,
padding: 10,
display: 'flex',
flexDirection: 'column',
gap: 4,
}}
>
<b>Txs Added:</b>
{txs.map((tx, i) => (
<div key={i}>
{JSON.stringify(tx)}
</div>
))}
</div>
<button
style={{
marginTop: 50,
padding: 24,
background: 'blue',
color: 'white',
fontSize: 18,
border: '1px solid #ffffff',
borderRadius: 8,
fontWeight: 800,
cursor: 'pointer',
}}
onClick={async () => {
if (!wallet) {
throw "Please connect to execute transactions"
}
const quote = await getClient()?.methods.getCallQuote({
chainId: fromChainId,
wallet,
txs: txs as any,
toChainId,
precheck: true
})

setResponse(quote as Execute)
}}>
Get Call Quote
</button>
{response && (
<div
style={{
marginTop: 20,
padding: '10px',
background: '#f0f0f0',
borderRadius: '8px',
width: '100%',
maxWidth: 1000,
}}
>
<pre>{JSON.stringify(response, null, 2)}</pre>
</div>
)}
</div>
)
}

export default GetCallQuotePage
Loading

0 comments on commit d777c8d

Please sign in to comment.