Skip to content

Commit

Permalink
Merge pull request #135 from paraswap/sdk-refactor-and-limit-orders
Browse files Browse the repository at this point in the history
Sdk refactor and limit orders
  • Loading branch information
alexshchur authored Oct 10, 2022
2 parents 952835c + e9f14e2 commit 926bdb6
Show file tree
Hide file tree
Showing 1,026 changed files with 326,027 additions and 1,471 deletions.
43 changes: 23 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ There are multiple ways to use ParaSwap SDK, ranging from a simple construct-and

### Simple SDK

Can be created by providing `network` and either `axios` or `window.fetch` (or alternative `fetch` implementation). 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). The resulting SDK will be able to use all methods that query the API.

```ts
import { constructSimpleSDK } from '@paraswap/sdk';
import axios from 'axios';

// construct minimal SDK with fetcher only
const paraSwapMin = constructSimpleSDK({network: 1, axios});
const paraSwapMin = constructSimpleSDK({chainId: 1, axios});
// or
const paraSwapMin = constructSimpleSDK({network: 1, fetch: window.fetch});
const paraSwapMin = constructSimpleSDK({chainId: 1, fetch: window.fetch});

const ETH = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
const DAI = '0x6B175474E89094C44Da98b954EedeAC495271d0F';
Expand All @@ -46,15 +46,15 @@ Can be created by providing `network` and either `axios` or `window.fetch` (or a
const signer: JsonRpcSigner = ethers.Wallet.fromMnmemonic('__your_mnemonic__');
const senderAddress = signer.address;

const priceRoute = await paraSwapMin.getRate({
const priceRoute = await paraSwapMin.swap.getRate({
srcToken: ETH,
destToken: DAI,
amount: srcAmount,
userAddress: senderAddress,
side: SwapSide.SELL,
});

const txParams = await paraSwapMin.buildTx(
const txParams = await paraSwapMin.swap.buildTx(
{
srcToken,
destToken,
Expand All @@ -78,7 +78,7 @@ Can be created by providing `network` and either `axios` or `window.fetch` (or a


async function approveTokenYourselfExample() {
const TransferProxy = await paraSwapMin.getSpender();
const TransferProxy = await paraSwapMin.swap.getSpender();

const DAI_CONTRACT = new ethers.Contract(DAI, ERC20_ABI, ethersSignerOrProvider);

Expand Down Expand Up @@ -106,7 +106,7 @@ If optional `providerOptions` is provided as the second parameter, then the resu
account: senderAddress,
};

const paraSwap = constructSimpleSDK({network: 1, axios}, providerOptionsEther);
const paraSwap = constructSimpleSDK({chainId: 1, axios}, providerOptionsEther);

async function approveTokenExample() {
const txHash = await paraSwap.approveToken(amountInWei, DAI);
Expand Down Expand Up @@ -134,7 +134,7 @@ const contractCaller = constructEthersContractCaller({
const fetcher = constructAxiosFetcher(axios); // alternatively constructFetchFetcher

const paraswap = constructSDK({
network: 1,
chainId: 1,
fetcher,
contractCaller,
});
Expand Down Expand Up @@ -226,7 +226,7 @@ import { constructPartialSDK, constructFetchFetcher, constructGetRate, construct
const fetcher = constructFetchFetcher(window.fetch);

const minParaSwap = constructPartialSDK({
network: 1,
chainId: 1,
fetcher,
}, constructGetRate, constructGetBalances);

Expand All @@ -245,15 +245,11 @@ import Web3 from 'web3';
const web3Provider = new Web3(window.ethereum);
const account = '__user_address__';

const paraswap = new ParaSwap({
network: 1,
web3Provider,
account,
axios,
});
const paraswap = new ParaSwap({chainId: 1, web3Provider, account, axios});

```


Or you can use `ethers` in place of `web3`

```typescript
Expand All @@ -264,7 +260,7 @@ const ethersProvider = new ethers.providers.Web3Provider(window.ethereum)
const account = '__user_address__';

const paraswap = new ParaSwap({
network: 1,
chainId: 1,
account,
ethersDeps: {
ethersProviderOrSigner: ethersProvider;
Expand All @@ -280,11 +276,18 @@ By analogy to ```constructPartialSDK```, you can leverage a lightweight version
```typescript
import { ParaSwap } from '@paraswap/sdk';

const paraswap = new ParaSwap({
network: 1,
fetch: window.fetch,
});
const paraswap = new ParaSwap({chainId: 1, fetch: window.fetch});

```

Refer to [this README for depecreated documentation](https://github.com/paraswap/paraswap-sdk/blob/c4c70c674fb2be4ec528064649d992d4b38c654b/README.md) for functions usage.


Refer to [SDK API documentation](docs/md/modules.md) for detailed documentation on the methods provided in this SDK.

## Tests

To run `yarn test` it is necessary to provide `PROVIDER_URL=<mainnet_rpc_url>` environment variable.
If it is necessary to run tests against a different API endpoint, provide `API_URL=url_to_API` environment variable.

<img src="./docs/passed_tests.jpg" width=350 />
1 change: 1 addition & 0 deletions docs/html/.nojekyll
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
120 changes: 120 additions & 0 deletions docs/html/assets/highlight.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
:root {
--light-hl-0: #000000;
--dark-hl-0: #D4D4D4;
--light-hl-1: #AF00DB;
--dark-hl-1: #C586C0;
--light-hl-2: #001080;
--dark-hl-2: #9CDCFE;
--light-hl-3: #A31515;
--dark-hl-3: #CE9178;
--light-hl-4: #008000;
--dark-hl-4: #6A9955;
--light-hl-5: #0000FF;
--dark-hl-5: #569CD6;
--light-hl-6: #0070C1;
--dark-hl-6: #4FC1FF;
--light-hl-7: #795E26;
--dark-hl-7: #DCDCAA;
--light-hl-8: #098658;
--dark-hl-8: #B5CEA8;
--light-hl-9: #267F99;
--dark-hl-9: #4EC9B0;
--light-hl-10: #CD3131;
--dark-hl-10: #F44747;
--light-hl-11: #000000FF;
--dark-hl-11: #D4D4D4;
--light-hl-12: #811F3F;
--dark-hl-12: #D16969;
--light-hl-13: #EE0000;
--dark-hl-13: #D7BA7D;
--light-code-background: #FFFFFF;
--dark-code-background: #1E1E1E;
}

@media (prefers-color-scheme: light) { :root {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--hl-7: var(--light-hl-7);
--hl-8: var(--light-hl-8);
--hl-9: var(--light-hl-9);
--hl-10: var(--light-hl-10);
--hl-11: var(--light-hl-11);
--hl-12: var(--light-hl-12);
--hl-13: var(--light-hl-13);
--code-background: var(--light-code-background);
} }

@media (prefers-color-scheme: dark) { :root {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--hl-7: var(--dark-hl-7);
--hl-8: var(--dark-hl-8);
--hl-9: var(--dark-hl-9);
--hl-10: var(--dark-hl-10);
--hl-11: var(--dark-hl-11);
--hl-12: var(--dark-hl-12);
--hl-13: var(--dark-hl-13);
--code-background: var(--dark-code-background);
} }

:root[data-theme='light'] {
--hl-0: var(--light-hl-0);
--hl-1: var(--light-hl-1);
--hl-2: var(--light-hl-2);
--hl-3: var(--light-hl-3);
--hl-4: var(--light-hl-4);
--hl-5: var(--light-hl-5);
--hl-6: var(--light-hl-6);
--hl-7: var(--light-hl-7);
--hl-8: var(--light-hl-8);
--hl-9: var(--light-hl-9);
--hl-10: var(--light-hl-10);
--hl-11: var(--light-hl-11);
--hl-12: var(--light-hl-12);
--hl-13: var(--light-hl-13);
--code-background: var(--light-code-background);
}

:root[data-theme='dark'] {
--hl-0: var(--dark-hl-0);
--hl-1: var(--dark-hl-1);
--hl-2: var(--dark-hl-2);
--hl-3: var(--dark-hl-3);
--hl-4: var(--dark-hl-4);
--hl-5: var(--dark-hl-5);
--hl-6: var(--dark-hl-6);
--hl-7: var(--dark-hl-7);
--hl-8: var(--dark-hl-8);
--hl-9: var(--dark-hl-9);
--hl-10: var(--dark-hl-10);
--hl-11: var(--dark-hl-11);
--hl-12: var(--dark-hl-12);
--hl-13: var(--dark-hl-13);
--code-background: var(--dark-code-background);
}

.hl-0 { color: var(--hl-0); }
.hl-1 { color: var(--hl-1); }
.hl-2 { color: var(--hl-2); }
.hl-3 { color: var(--hl-3); }
.hl-4 { color: var(--hl-4); }
.hl-5 { color: var(--hl-5); }
.hl-6 { color: var(--hl-6); }
.hl-7 { color: var(--hl-7); }
.hl-8 { color: var(--hl-8); }
.hl-9 { color: var(--hl-9); }
.hl-10 { color: var(--hl-10); }
.hl-11 { color: var(--hl-11); }
.hl-12 { color: var(--hl-12); }
.hl-13 { color: var(--hl-13); }
pre, code { background: var(--code-background); }
54 changes: 54 additions & 0 deletions docs/html/assets/main.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/html/assets/search.js

Large diffs are not rendered by default.

Loading

0 comments on commit 926bdb6

Please sign in to comment.