Skip to content

Commit

Permalink
Merge pull request #139 from paraswap/feat/LOrders_draft
Browse files Browse the repository at this point in the history
Feat/Draft LOrders
  • Loading branch information
Velenir authored Nov 25, 2022
2 parents 89f08d5 + 2de1162 commit 5a61f28
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 51 deletions.
7 changes: 7 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
moduleNameMapper: {
// force resolve `axios` mopdule as CommonJS
// axios@>1.0.0 breaks in jest otherwise
'^axios$': require.resolve('axios'),
},
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"devDependencies": {
"@size-limit/preset-small-lib": "^7.0.8",
"@tsconfig/recommended": "^1.0.1",
"axios": "^0.27.2",
"axios": "^1.1.3",
"dotenv": "^16.0.0",
"dts-cli": "^1.5.1",
"ethers": "^5.6.5",
Expand All @@ -67,7 +67,7 @@
"web3": "^1.7.3"
},
"peerDependencies": {
"axios": ">=0.25.0 <1.0.0",
"axios": ">=0.25.0 <2.0.0",
"ethers": "^5.5.0",
"web3": "^1.7.1"
},
Expand Down
6 changes: 4 additions & 2 deletions src/helpers/fetchers/axios.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { FetcherFunction } from '../../types';
import type AxiosStatic from 'axios';
import type { AxiosStatic } from 'axios';
import { FetcherError } from '../misc';

export type AxiosRequirement = Pick<AxiosStatic, 'request' | 'isAxiosError'>;

export const constructFetcher =
(axios: typeof AxiosStatic): FetcherFunction =>
(axios: AxiosRequirement): FetcherFunction =>
async (params) => {
try {
const { data } = await axios.request(params);
Expand Down
4 changes: 2 additions & 2 deletions src/legacy/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { AxiosStatic } from 'axios';
import type Web3 from 'web3';
import type { SendOptions } from 'web3-eth-contract';
import type { ContractTransaction } from '@ethersproject/contracts';
Expand Down Expand Up @@ -36,6 +35,7 @@ import type {
} from '../methods/swap/transaction';
import type { AddressOrSymbol, Token, FetcherFunction } from '../types';
import type { Allowance } from '../methods/swap/balance';
import type { AxiosRequirement } from '../helpers/fetchers/axios';
import { isDataWithError } from '../helpers/misc';

export type APIError = {
Expand All @@ -53,7 +53,7 @@ type LegacyOptions = {
web3Provider?: Web3;
ethersDeps?: EthersProviderDeps; // need to be a provider with signer for approve requests
account?: Address;
axios?: AxiosStatic;
axios?: AxiosRequirement;
fetch?: Fetch;
};

Expand Down
22 changes: 8 additions & 14 deletions src/methods/limitOrders/helpers/types.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
import type { OrderData } from './buildOrderData';

export type LimitOrderStatus =
| 'open'
| 'filled'
| 'partiallyFilled'
| 'expired'
| 'canceled'
| 'unknown';

export type LimitOrderType = 'LIMIT' | 'P2P';

export type LimitOrder = LimitOrderFromApi & {
status: LimitOrderStatus; // `status` likely not available from API
amountFilled?: string;
transactionHashes?: string[];
};
export type LimitOrder = LimitOrderFromApi;

export type LimitOrderToSend = OrderData & {
permitMakerAsset?: string;
signature: string;
Expand All @@ -34,7 +23,12 @@ export type LimitOrderApiResponse = {
// display states such as EXPIRED and PARTIALLY_FILLLED derived on client side
// returned by API but can be calculated too, EXPIRED == order.expiry < Date.now()/1000
// PARTIALLY_FILLED == order.fillableBalance < order.makerAmount && order.fillableBalance !== '0'
export type LimitOrderState = 'PENDING' | 'FULFILLED' | 'CANCELLED' | 'EXPIRED';
export type LimitOrderState =
| 'DRAFT'
| 'PENDING'
| 'FULFILLED'
| 'CANCELLED'
| 'EXPIRED';

export type LimitOrderEvent = '';

Expand Down
2 changes: 2 additions & 0 deletions src/methods/swap/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ export type BuildTxInputBase = {
srcToken: Address;
destToken: Address;
userAddress: Address;
/** @description used with referral link */
referrer?: string;
partner?: string;
partnerAddress?: string;
partnerFeeBps?: number;
Expand Down
4 changes: 2 additions & 2 deletions src/sdk/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import type {
import type { EthersProviderDeps } from '../helpers';
import type Web3 from 'web3';

import type AxiosStatic from 'axios';
import type { SwapSDKMethods } from './full';
import {
BuildLimitOrderFunctions,
Expand Down Expand Up @@ -90,6 +89,7 @@ import {
} from '../methods/nftOrders';

import { constructSwapSDK } from '../methods/swap';
import type { AxiosRequirement } from '../helpers/fetchers/axios';

export type SwapFetchMethods = GetBalancesFunctions &
GetTokensFunctions &
Expand Down Expand Up @@ -124,7 +124,7 @@ export type SimpleSDK = {

export type FetcherOptions =
| {
axios: typeof AxiosStatic;
axios: AxiosRequirement;
}
| { fetch: typeof fetch };

Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export interface ConstructFetchInput extends ConstructBaseInput {
interface OverridesBase {
from?: string;
gasPrice?: string;
maxFeePerGas?: string;
maxPriorityFeePerGas?: string;
gas?: number;
value?: number | string;
}
Expand Down
26 changes: 12 additions & 14 deletions tests/__snapshots__/limitOrders.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,26 @@ Object {
"swapExchanges": Array [
Object {
"data": Object {
"factory": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
"feeFactor": 10000,
"gasUSD": "---",
"initCode": "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",
"path": Array [
"0x6b175474e89094c44da98b954eedeac495271d0f",
"0x0d8775f648430679a709e98d2b0cb6250d2887ef",
],
"pools": Array [
Object {
"address": "0x6929abD7931D0243777d3CD147fE863646A752ba",
"direction": false,
"fee": 30,
"fee": "500",
"tokenIn": "0x6b175474e89094c44da98b954eedeac495271d0f",
"tokenOut": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
},
Object {
"fee": "3000",
"tokenIn": "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
"tokenOut": "0x0d8775f648430679a709e98d2b0cb6250d2887ef",
},
],
"router": "0xF9234CB08edb93c0d4a4d4c70cC3FfD070e78e07",
},
"destAmount": "6000000000000000000",
"exchange": "UniswapV2",
"exchange": "UniswapV3",
"percent": 100,
"poolAddresses": Array [
"0x6929abD7931D0243777d3CD147fE863646A752ba",
"0x60594a405d53811d3BC4766596EFD80fd545A270",
"0xAE614a7a56cB79c04Df2aeBA6f5dAB80A39CA78E",
],
"srcAmount": "---",
},
Expand All @@ -51,7 +49,7 @@ Object {
"destDecimals": 18,
"destToken": "0x0d8775f648430679a709e98d2b0cb6250d2887ef",
"destUSD": "---",
"gasCost": "189300",
"gasCost": "206300",
"gasCostUSD": "---",
"hmac": "---",
"maxImpactReached": false,
Expand Down
1 change: 1 addition & 0 deletions tests/limitOrders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ describe('Limit Orders', () => {
srcToken,
destToken,
userAddress: senderAddress,
options: { includeDEXS: ['UniswapV3'] },
},
[order]
);
Expand Down
8 changes: 2 additions & 6 deletions tests/nftOrders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1111,16 +1111,12 @@ describe('NFT Orders', () => {
"swapExchanges": Array [
Object {
"data": Object {
"factory": "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",
"feeFactor": 10000,
"gasUSD": "---",
"initCode": "0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",
"path": "---",
"pools": "---",
"router": "0xF9234CB08edb93c0d4a4d4c70cC3FfD070e78e07",
},
"destAmount": "6000000000000000000",
"exchange": "UniswapV2",
"exchange": "UniswapV3",
"percent": 100,
"poolAddresses": Array [
"---",
Expand All @@ -1139,7 +1135,7 @@ describe('NFT Orders', () => {
"destDecimals": 18,
"destToken": "0x4fabb145d64652a948d72533023f6e7a623c7c53",
"destUSD": "---",
"gasCost": "276300",
"gasCost": "154300",
"gasCostUSD": "---",
"hmac": "---",
"maxImpactReached": false,
Expand Down
24 changes: 15 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2258,13 +2258,14 @@ axe-core@^4.3.5:
resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.1.tgz#7dbdc25989298f9ad006645cd396782443757413"
integrity sha512-gd1kmb21kwNuWr6BQz8fv6GNECPBnUasepcoLbekws23NVBLODdsClRZ+bQ8+9Uomf3Sm3+Vwn0oYG9NvwnJCw==

axios@^0.27.2:
version "0.27.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.27.2.tgz#207658cc8621606e586c85db4b41a750e756d972"
integrity sha512-t+yRIyySRTp/wua5xEr+z1q60QmLq8ABsS5O9Me1AsE5dfKqgnCFzwiCZZ/cGNd1lq4/7akDWMxdhVlucjmnOQ==
axios@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/axios/-/axios-1.1.3.tgz#8274250dada2edf53814ed7db644b9c2866c1e35"
integrity sha512-00tXVRwKx/FZr/IDVFt4C+f9FYairX517WoGCL6dpOntqLkZofjhu43F/Xl44UOpqa+9sLFDrG/XAnFsUYgkDA==
dependencies:
follow-redirects "^1.14.9"
follow-redirects "^1.15.0"
form-data "^4.0.0"
proxy-from-env "^1.1.0"

axobject-query@^2.2.0:
version "2.2.0"
Expand Down Expand Up @@ -4285,10 +4286,10 @@ flatted@^3.1.0:
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.2.5.tgz#76c8584f4fc843db64702a6bd04ab7a8bd666da3"
integrity sha512-WIWGi2L3DyTUvUrwRKgGi9TwxQMUEqPOPQBVi71R96jZXJdFskXEmf54BoZaS1kknGODoIGASGEzBUYdyMCBJg==

follow-redirects@^1.14.9:
version "1.15.0"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.0.tgz#06441868281c86d0dda4ad8bdaead2d02dca89d4"
integrity sha512-aExlJShTV4qOUOL7yF1U5tvLCB0xQuudbf6toyYA0E/acBNw71mvjFTnLaRp50aQaYocMR0a/RMMBIHeZnGyjQ==
follow-redirects@^1.15.0:
version "1.15.2"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.2.tgz#b460864144ba63f2681096f274c4e57026da2c13"
integrity sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==

foreach@^2.0.5:
version "2.0.5"
Expand Down Expand Up @@ -6807,6 +6808,11 @@ proxy-addr@~2.0.7:
forwarded "0.2.0"
ipaddr.js "1.9.1"

proxy-from-env@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

psl@^1.1.28, psl@^1.1.33:
version "1.8.0"
resolved "https://registry.yarnpkg.com/psl/-/psl-1.8.0.tgz#9326f8bcfb013adcc005fdff056acce020e51c24"
Expand Down

0 comments on commit 5a61f28

Please sign in to comment.