From 83996a2b8fb12e904f61d04dc01fddcbc959d4f0 Mon Sep 17 00:00:00 2001 From: Mohamed Hassen Mami Date: Sun, 13 Nov 2022 22:23:04 +0100 Subject: [PATCH] clean up redundant explanations in doc --- README.md | 84 +++----------------------------------------- docs/html/index.html | 39 ++++---------------- docs/md/README.md | 83 +++---------------------------------------- 3 files changed, 15 insertions(+), 191 deletions(-) diff --git a/README.md b/README.md index 11b92346..0b9bfb5f 100644 --- a/README.md +++ b/README.md @@ -102,14 +102,10 @@ If optional `providerOptions` is provided as the second parameter, then the resu await provider.waitForTransaction(txHash); ``` -### Composed SDK -Import the necessary functions +### Full SDK ```typescript import { constructSDK, constructAxiosFetcher, constructEthersContractCaller } from '@paraswap/sdk'; -``` -### Construct the ParaSwap object -```typescript const signer = ethers.Wallet.fromMnmemonic('__your_mnemonic__'); // or any other signer/provider const account = '__signer_address__'; @@ -119,86 +115,14 @@ const contractCaller = constructEthersContractCaller({ }, account); // alternatively constructWeb3ContractCaller const fetcher = constructAxiosFetcher(axios); // alternatively constructFetchFetcher -const paraswap = constructSDK({ +const paraswap = constructFullSDK({ chainId: 1, fetcher, contractCaller, }); ``` -### To approve ParaSwap contracts to swap an ERC20 token - -```typescript -// if created with constructEthersContractCaller -const contractTx: ContractTransaction = await paraSwap.approveToken(amount, tokenAddress); -const txReceipt = await contractTx.wait(); - -// if created with constructWeb3ContractCaller -const unpromiEvent: Web3UnpromiEvent = await paraSwap.approveToken(amount, tokenAddress); -const txReceipt = await new Promise((resolve, reject) => { - unpromiEvent.once('receipt', resolve); - unpromiEvent.once('error', reject); -}) -``` - -### To get the rate of a token pair - -```typescript -const srcToken = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'; // ETH -const destToken = '0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5'; // PSP -const srcAmount = '1000000000000000000'; //The source amount multiplied by its decimals: 10 ** 18 here -const srcDecimals = 18; -const destDecimals = 18; - -const priceRoute = await paraSwap.getRate( - { - srcToken, - destToken, - amount: srcAmount, - srcDecimals, - destDecimals, - } -); -``` - -Where priceRoute contains the rate and the distribution among exchanges, checkout the OptimalRates type for more details. - -### To build a transaction - -```typescript -const srcToken = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'; -const srcDecimals = 18; -const srcAmount = '1000000000000000000'; // The source amount multiplied by its decimals -const destToken = '0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5'; -const destDecimals = 18; -const destAmount = priceRoute.destAmount; // price route being output of paraSwap.getRate() -const senderAddress = '__sender_address__'; // mandatory -const receiver = '__receiver_address__'; // optional: for swap and transfer -const partnerAddress = '__fee_receiver_address__'; // optional: for permission-less monetization -const partnerFeeBps = 50; // optional: fee in base point, for permission-less monetization - - -const txParams = await paraSwap.buildTx( - { - srcAmount, - srcToken, - srcDecimals, - destAmount, - destToken, - destDecimals, - priceRoute, - senderAddress, - receiver, - partnerAddress, - partnerFeeBps, - } -); - -const transactionResponse = await signer.sendTransaction(txParams); -const transactionReceipt = await transactionResponse.wait(); -``` - -## Bundle Optimization +### Partial SDK For bundle-size savvy developers, you can construct a lightweight version of the SDK and bring only the functions you need. e.g. for only getting rates and allowances: @@ -217,7 +141,7 @@ const priceRoute = await minParaSwap.getRate(params); const allowance = await minParaSwap.getAllowance(userAddress, tokenAddress); ``` -## Legacy +### Legacy The `ParaSwap` class is exposed for backwards compatibility with previous versions of the SDK. ```typescript diff --git a/docs/html/index.html b/docs/html/index.html index 5f6e661d..455bc481 100644 --- a/docs/html/index.html +++ b/docs/html/index.html @@ -50,40 +50,14 @@

Simple SDK

  // with ethers.js
const providerOptionsEther = {
ethersProviderOrSigner: provider, // JsonRpcProvider
EthersContract: ethers.Contract,
account: senderAddress,
};

// or with web3.js
const providerOptionsWeb3 = {
web3, // new Web3(...) instance
account: senderAddress,
};

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

// approve token through sdk
const txHash = await paraSwap.approveToken(amountInWei, DAI);

// await tx somehow
await provider.waitForTransaction(txHash);
- -

Composed SDK

+
+

Full SDK

-

Import the necessary functions

-
import { constructSDK, constructAxiosFetcher, constructEthersContractCaller } from '@paraswap/sdk';
+
import { constructSDK, constructAxiosFetcher, constructEthersContractCaller } from '@paraswap/sdk';

const signer = ethers.Wallet.fromMnmemonic('__your_mnemonic__'); // or any other signer/provider
const account = '__signer_address__';

const contractCaller = constructEthersContractCaller({
ethersProviderOrSigner: signer,
EthersContract: ethers.Contract,
}, account); // alternatively constructWeb3ContractCaller
const fetcher = constructAxiosFetcher(axios); // alternatively constructFetchFetcher

const paraswap = constructFullSDK({
chainId: 1,
fetcher,
contractCaller,
});
- -

Construct the ParaSwap object

-
-
const signer = ethers.Wallet.fromMnmemonic('__your_mnemonic__'); // or any other signer/provider 
const account = '__signer_address__';

const contractCaller = constructEthersContractCaller({
ethersProviderOrSigner: signer,
EthersContract: ethers.Contract,
}, account); // alternatively constructWeb3ContractCaller
const fetcher = constructAxiosFetcher(axios); // alternatively constructFetchFetcher

const paraswap = constructSDK({
chainId: 1,
fetcher,
contractCaller,
}); -
- - -

To approve ParaSwap contracts to swap an ERC20 token

-
-
// if created with constructEthersContractCaller
const contractTx: ContractTransaction = await paraSwap.approveToken(amount, tokenAddress);
const txReceipt = await contractTx.wait();

// if created with constructWeb3ContractCaller
const unpromiEvent: Web3UnpromiEvent = await paraSwap.approveToken(amount, tokenAddress);
const txReceipt = await new Promise<Web3TransactionReceipt>((resolve, reject) => {
unpromiEvent.once('receipt', resolve);
unpromiEvent.once('error', reject);
}) -
- - -

To get the rate of a token pair

-
-
const srcToken = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'; // ETH
const destToken = '0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5'; // PSP
const srcAmount = '1000000000000000000'; //The source amount multiplied by its decimals: 10 ** 18 here
const srcDecimals = 18;
const destDecimals = 18;

const priceRoute = await paraSwap.getRate(
{
srcToken,
destToken,
amount: srcAmount,
srcDecimals,
destDecimals,
}
); -
-

Where priceRoute contains the rate and the distribution among exchanges, checkout the OptimalRates type for more details.

- - -

To build a transaction

-
-
const srcToken = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
const srcDecimals = 18;
const srcAmount = '1000000000000000000'; // The source amount multiplied by its decimals
const destToken = '0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5';
const destDecimals = 18;
const destAmount = priceRoute.destAmount; // price route being output of paraSwap.getRate()
const senderAddress = '__sender_address__'; // mandatory
const receiver = '__receiver_address__'; // optional: for swap and transfer
const partnerAddress = '__fee_receiver_address__'; // optional: for permission-less monetization
const partnerFeeBps = 50; // optional: fee in base point, for permission-less monetization


const txParams = await paraSwap.buildTx(
{
srcAmount,
srcToken,
srcDecimals,
destAmount,
destToken,
destDecimals,
priceRoute,
senderAddress,
receiver,
partnerAddress,
partnerFeeBps,
}
);

const transactionResponse = await signer.sendTransaction(txParams);
const transactionReceipt = await transactionResponse.wait(); -
- - -

Bundle Optimization

+
+

Partial SDK

For bundle-size savvy developers, you can construct a lightweight version of the SDK and bring only the functions you need.

e.g. for only getting rates and allowances:

@@ -91,7 +65,7 @@

Bundle Optimization

-

Legacy

+

Legacy

The ParaSwap class is exposed for backwards compatibility with previous versions of the SDK.

import { ParaSwap } from '@paraswap/sdk';
import axios from 'axios';
import Web3 from 'web3';

const web3Provider = new Web3(window.ethereum);
const account = '__user_address__';

const paraswap = new ParaSwap({chainId: 1, web3Provider, account, axios});
@@ -103,6 +77,7 @@

Legacy

import { ParaSwap } from '@paraswap/sdk';

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

Refer to this README for depecreated documentation for functions usage.

+

Refer to SDK API documentation for detailed documentation on the methods provided in this SDK.

Tests

diff --git a/docs/md/README.md b/docs/md/README.md index a703f51c..ff59ee82 100644 --- a/docs/md/README.md +++ b/docs/md/README.md @@ -104,14 +104,10 @@ If optional `providerOptions` is provided as the second parameter, then the resu await provider.waitForTransaction(txHash); ``` -### Composed SDK -Import the necessary functions +### Full SDK ```typescript import { constructSDK, constructAxiosFetcher, constructEthersContractCaller } from '@paraswap/sdk'; -``` -### Construct the ParaSwap object -```typescript const signer = ethers.Wallet.fromMnmemonic('__your_mnemonic__'); // or any other signer/provider const account = '__signer_address__'; @@ -121,85 +117,14 @@ const contractCaller = constructEthersContractCaller({ }, account); // alternatively constructWeb3ContractCaller const fetcher = constructAxiosFetcher(axios); // alternatively constructFetchFetcher -const paraswap = constructSDK({ +const paraswap = constructFullSDK({ chainId: 1, fetcher, contractCaller, }); ``` -### To approve ParaSwap contracts to swap an ERC20 token - -```typescript -// if created with constructEthersContractCaller -const contractTx: ContractTransaction = await paraSwap.approveToken(amount, tokenAddress); -const txReceipt = await contractTx.wait(); - -// if created with constructWeb3ContractCaller -const unpromiEvent: Web3UnpromiEvent = await paraSwap.approveToken(amount, tokenAddress); -const txReceipt = await new Promise((resolve, reject) => { - unpromiEvent.once('receipt', resolve); - unpromiEvent.once('error', reject); -}) -``` - -### To get the rate of a token pair - -```typescript -const srcToken = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'; // ETH -const destToken = '0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5'; // PSP -const srcAmount = '1000000000000000000'; //The source amount multiplied by its decimals: 10 ** 18 here -const srcDecimals = 18; -const destDecimals = 18; - -const priceRoute = await paraSwap.getRate( - { - srcToken, - destToken, - amount: srcAmount, - srcDecimals, - destDecimals, - } -); -``` - -Where priceRoute contains the rate and the distribution among exchanges, checkout the OptimalRates type for more details. - -### To build a transaction - -```typescript -const srcToken = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'; -const srcDecimals = 18; -const srcAmount = '1000000000000000000'; // The source amount multiplied by its decimals -const destToken = '0xcAfE001067cDEF266AfB7Eb5A286dCFD277f3dE5'; -const destDecimals = 18; -const destAmount = priceRoute.destAmount; // price route being output of paraSwap.getRate() -const senderAddress = '__sender_address__'; // mandatory -const receiver = '__receiver_address__'; // optional: for swap and transfer -const partnerAddress = '__fee_receiver_address__'; // optional: for permission-less monetization -const partnerFeeBps = 50; // optional: fee in base point, for permission-less monetization - -const txParams = await paraSwap.buildTx( - { - srcAmount, - srcToken, - srcDecimals, - destAmount, - destToken, - destDecimals, - priceRoute, - senderAddress, - receiver, - partnerAddress, - partnerFeeBps, - } -); - -const transactionResponse = await signer.sendTransaction(txParams); -const transactionReceipt = await transactionResponse.wait(); -``` - -## Bundle Optimization +### Partial SDK For bundle-size savvy developers, you can construct a lightweight version of the SDK and bring only the functions you need. e.g. for only getting rates and allowances: @@ -218,7 +143,7 @@ const priceRoute = await minParaSwap.getRate(params); const allowance = await minParaSwap.getAllowance(userAddress, tokenAddress); ``` -## Legacy +### Legacy The `ParaSwap` class is exposed for backwards compatibility with previous versions of the SDK. ```typescript