Skip to content

Commit

Permalink
Merge branch 'feat/build_upgrade' into feat/viem_support
Browse files Browse the repository at this point in the history
  • Loading branch information
Velenir committed Oct 23, 2024
2 parents 332d98b + 5d392d7 commit 24e868c
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ You can see some examples in [/src/examples](src/examples) directory.

### Simple SDK

Can be created by providing `chainId` and either `axios` or `window.fetch` (or alternative `fetch` implementation), and an optional `version` (`'5'` or `'6.2'`) parameter that corresponds to the API version SDK will be making requests to. The resulting SDK will be able to use all methods that query the API.
Can be created by providing `chainId` and either `axios` or `window.fetch` (or alternative `fetch` implementation), and an optional `version` (`'5'` or `'6.1'`) parameter that corresponds to the API version SDK will be making requests to. The resulting SDK will be able to use all methods that query the API.

```ts
import { constructSimpleSDK } from '@paraswap/sdk';
Expand Down
2 changes: 1 addition & 1 deletion docs/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h2>Using ParaSwap SDK</h2>
<a href="#simple-sdk" id="simple-sdk" style="color: inherit; text-decoration: none;">
<h3>Simple SDK</h3>
</a>
<p>Can be created by providing <code>chainId</code> and either <code>axios</code> or <code>window.fetch</code> (or alternative <code>fetch</code> implementation), and an optional <code>version</code> (<code>&#39;5&#39;</code> or <code>&#39;6.2&#39;</code>) parameter that corresponds to the API version SDK will be making requests to. The resulting SDK will be able to use all methods that query the API.</p>
<p>Can be created by providing <code>chainId</code> and either <code>axios</code> or <code>window.fetch</code> (or alternative <code>fetch</code> implementation), and an optional <code>version</code> (<code>&#39;5&#39;</code> or <code>&#39;6.1&#39;</code>) parameter that corresponds to the API version SDK will be making requests to. The resulting SDK will be able to use all methods that query the API.</p>
<pre><code class="language-ts"><span class="hl-0"> </span><span class="hl-1">import</span><span class="hl-0"> { </span><span class="hl-2">constructSimpleSDK</span><span class="hl-0"> } </span><span class="hl-1">from</span><span class="hl-0"> </span><span class="hl-3">&#39;@paraswap/sdk&#39;</span><span class="hl-0">;</span><br/><span class="hl-0"> </span><span class="hl-1">import</span><span class="hl-0"> </span><span class="hl-2">axios</span><span class="hl-0"> </span><span class="hl-1">from</span><span class="hl-0"> </span><span class="hl-3">&#39;axios&#39;</span><span class="hl-0">;</span><br/><br/><span class="hl-0"> </span><span class="hl-4">// construct minimal SDK with fetcher only</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">paraSwapMin</span><span class="hl-0"> = </span><span class="hl-7">constructSimpleSDK</span><span class="hl-0">({</span><span class="hl-2">chainId:</span><span class="hl-0"> </span><span class="hl-8">1</span><span class="hl-0">, </span><span class="hl-2">axios</span><span class="hl-0">});</span><br/><span class="hl-0"> </span><span class="hl-4">// or</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">paraSwapMin</span><span class="hl-0"> = </span><span class="hl-7">constructSimpleSDK</span><span class="hl-0">({</span><span class="hl-2">chainId:</span><span class="hl-0"> </span><span class="hl-8">1</span><span class="hl-0">, </span><span class="hl-2">fetch:</span><span class="hl-0"> </span><span class="hl-2">window</span><span class="hl-0">.</span><span class="hl-2">fetch</span><span class="hl-0">, </span><span class="hl-2">version:</span><span class="hl-0"> </span><span class="hl-3">&#39;5&#39;</span><span class="hl-0">});</span><br/><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">ETH</span><span class="hl-0"> = </span><span class="hl-3">&#39;0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee&#39;</span><span class="hl-0">;</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">DAI</span><span class="hl-0"> = </span><span class="hl-3">&#39;0x6B175474E89094C44Da98b954EedeAC495271d0F&#39;</span><span class="hl-0">;</span><br/><br/><span class="hl-0"> </span><span class="hl-5">async</span><span class="hl-0"> </span><span class="hl-5">function</span><span class="hl-0"> </span><span class="hl-7">swapExample</span><span class="hl-0">() {</span><br/><span class="hl-0"> </span><span class="hl-4">// or any other signer/provider </span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">signer</span><span class="hl-0">: </span><span class="hl-9">JsonRpcSigner</span><span class="hl-0"> = </span><span class="hl-2">ethers</span><span class="hl-0">.</span><span class="hl-2">Wallet</span><span class="hl-0">.</span><span class="hl-7">fromMnmemonic</span><span class="hl-0">(</span><span class="hl-3">&#39;__your_mnemonic__&#39;</span><span class="hl-0">);</span><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">senderAddress</span><span class="hl-0"> = </span><span class="hl-2">signer</span><span class="hl-0">.</span><span class="hl-2">address</span><span class="hl-0">;</span><br/><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">priceRoute</span><span class="hl-0"> = </span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-2">paraSwapMin</span><span class="hl-0">.</span><span class="hl-2">swap</span><span class="hl-0">.</span><span class="hl-7">getRate</span><span class="hl-0">({</span><br/><span class="hl-0"> </span><span class="hl-2">srcToken:</span><span class="hl-0"> </span><span class="hl-6">ETH</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">destToken:</span><span class="hl-0"> </span><span class="hl-6">DAI</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">amount:</span><span class="hl-0"> </span><span class="hl-2">srcAmount</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">userAddress:</span><span class="hl-0"> </span><span class="hl-2">senderAddress</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">side:</span><span class="hl-0"> </span><span class="hl-2">SwapSide</span><span class="hl-0">.</span><span class="hl-6">SELL</span><span class="hl-0">,</span><br/><span class="hl-0"> });</span><br/><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">txParams</span><span class="hl-0"> = </span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-2">paraSwapMin</span><span class="hl-0">.</span><span class="hl-2">swap</span><span class="hl-0">.</span><span class="hl-7">buildTx</span><span class="hl-0">(</span><br/><span class="hl-0"> {</span><br/><span class="hl-0"> </span><span class="hl-2">srcToken</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">destToken</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">srcAmount</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">destAmount</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">priceRoute</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">userAddress:</span><span class="hl-0"> </span><span class="hl-2">senderAddress</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">partner:</span><span class="hl-0"> </span><span class="hl-2">referrer</span><span class="hl-0">,</span><br/><span class="hl-0"> } </span><br/><span class="hl-0"> );</span><br/><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">transaction</span><span class="hl-0"> = {</span><br/><span class="hl-0"> ...</span><span class="hl-2">txParams</span><span class="hl-0">,</span><br/><span class="hl-0"> </span><span class="hl-2">gasPrice:</span><span class="hl-0"> </span><span class="hl-3">&#39;0x&#39;</span><span class="hl-0"> + </span><span class="hl-5">new</span><span class="hl-0"> </span><span class="hl-7">BigNumber</span><span class="hl-0">(</span><span class="hl-2">txParams</span><span class="hl-0">.</span><span class="hl-2">gasPrice</span><span class="hl-0">).</span><span class="hl-7">toString</span><span class="hl-0">(</span><span class="hl-8">16</span><span class="hl-0">),</span><br/><span class="hl-0"> </span><span class="hl-2">gasLimit:</span><span class="hl-0"> </span><span class="hl-3">&#39;0x&#39;</span><span class="hl-0"> + </span><span class="hl-5">new</span><span class="hl-0"> </span><span class="hl-7">BigNumber</span><span class="hl-0">(</span><span class="hl-8">5000000</span><span class="hl-0">).</span><span class="hl-7">toString</span><span class="hl-0">(</span><span class="hl-8">16</span><span class="hl-0">),</span><br/><span class="hl-0"> </span><span class="hl-2">value:</span><span class="hl-0"> </span><span class="hl-3">&#39;0x&#39;</span><span class="hl-0"> + </span><span class="hl-5">new</span><span class="hl-0"> </span><span class="hl-7">BigNumber</span><span class="hl-0">(</span><span class="hl-2">txParams</span><span class="hl-0">.</span><span class="hl-2">value</span><span class="hl-0">).</span><span class="hl-7">toString</span><span class="hl-0">(</span><span class="hl-8">16</span><span class="hl-0">),</span><br/><span class="hl-0"> };</span><br/><br/><span class="hl-0"> </span><span class="hl-5">const</span><span class="hl-0"> </span><span class="hl-6">txr</span><span class="hl-0"> = </span><span class="hl-1">await</span><span class="hl-0"> </span><span class="hl-2">signer</span><span class="hl-0">.</span><span class="hl-7">sendTransaction</span><span class="hl-0">(</span><span class="hl-2">transaction</span><span class="hl-0">);</span><br/><span class="hl-0"> }</span>
</code></pre>
<p>If optional <code>providerOptions</code> is provided as the second parameter, then the resulting SDK will also be able to approve Tokens for swap.</p>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/types/GetRateFunctions.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h5>get<wbr/>Rate<span class="tsd-signature-symbol">: </span><a href="_internal_
<li class="tsd-parameter">
<h5>get<wbr/>Rate<wbr/>By<wbr/>Route<span class="tsd-signature-symbol">: </span><a href="_internal_.GetRateByRoute.html" class="tsd-signature-type" data-tsd-kind="Type alias">GetRateByRoute</a></h5></li></ul></div><aside class="tsd-sources">
<ul>
<li>Defined in <a href="https://github.com/paraswap/paraswap-sdk/blob/master/src/methods/swap/rates.ts#L196">src/methods/swap/rates.ts:196</a></li></ul></aside></div>
<li>Defined in <a href="https://github.com/paraswap/paraswap-sdk/blob/master/src/methods/swap/rates.ts#L197">src/methods/swap/rates.ts:197</a></li></ul></aside></div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<div class="tsd-navigation settings">
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
Expand Down
Loading

0 comments on commit 24e868c

Please sign in to comment.