-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from reservoirprotocol/ted/grwth-4122-sdk-methods
Add getSolverCapacity, getCallQuote, getBridgeQuote methods
- Loading branch information
Showing
16 changed files
with
484 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@reservoir0x/relay-sdk': patch | ||
--- | ||
|
||
Add getSolverCapacity, getCallQuote, getBridgeQuote methods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.