Skip to content

Commit

Permalink
feat: slippage tolerance in all trades
Browse files Browse the repository at this point in the history
  • Loading branch information
jackmellis committed Nov 22, 2023
1 parent 6abff1c commit 12e9f6d
Show file tree
Hide file tree
Showing 107 changed files with 4,471 additions and 3,184 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-node-resolve": "^5.2.0",
"typedoc": "^0.23.23",
"typescript": "^4.6.3"
"typescript": "5.2.2"
},
"workspaces": [
"packages/*"
Expand Down
6 changes: 3 additions & 3 deletions packages/abi/src/abis/PoolRouter.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"error NotPositionOwner()",
"error UnableToSendETH()",
"error ZeroLPTimelock()",
"event AddLiquidity(uint256 indexed positionId, uint256 vaultId, uint256 vTokensAmount, uint256[] nftIds, address pool)",
"event AddLiquidity(uint256 indexed positionId, uint256 vaultId, uint256 vTokensAmount, uint256[] nftIds, address pool, address recipient)",
"event BuyNFTs(uint256 nftCount, uint256 ethSpent)",
"event IncreaseLiquidity(uint256 indexed positionId, uint256 vaultId, uint256 vTokensAmount, uint256[] nftIds)",
"event OwnershipTransferred(address indexed previousOwner, address indexed newOwner)",
"event RemoveLiquidity(uint256 indexed positionId, uint256 vaultId, uint256 vTokenAmt, uint256 wethAmt)",
"event SellNFTs(uint256 nftCount, uint256 ethReceived)",
"function PERMIT2() view returns (address)",
"function WETH() view returns (address)",
"function addLiquidity(tuple(uint256 vaultId, uint256 vTokensAmount, uint256[] nftIds, uint256[] nftAmounts, int24 tickLower, int24 tickUpper, uint24 fee, uint160 sqrtPriceX96, uint256 vTokenMin, uint256 wethMin, uint256 deadline, bool forceTimelock) params) payable returns (uint256 positionId)",
"function addLiquidityWithPermit2(tuple(uint256 vaultId, uint256 vTokensAmount, uint256[] nftIds, uint256[] nftAmounts, int24 tickLower, int24 tickUpper, uint24 fee, uint160 sqrtPriceX96, uint256 vTokenMin, uint256 wethMin, uint256 deadline, bool forceTimelock) params, bytes encodedPermit2) payable returns (uint256 positionId)",
"function addLiquidity(tuple(uint256 vaultId, uint256 vTokensAmount, uint256[] nftIds, uint256[] nftAmounts, int24 tickLower, int24 tickUpper, uint24 fee, uint160 sqrtPriceX96, uint256 vTokenMin, uint256 wethMin, uint256 deadline, bool forceTimelock, address recipient) params) payable returns (uint256 positionId)",
"function addLiquidityWithPermit2(tuple(uint256 vaultId, uint256 vTokensAmount, uint256[] nftIds, uint256[] nftAmounts, int24 tickLower, int24 tickUpper, uint24 fee, uint160 sqrtPriceX96, uint256 vTokenMin, uint256 wethMin, uint256 deadline, bool forceTimelock, address recipient) params, bytes encodedPermit2) payable returns (uint256 positionId)",
"function buyNFTs(tuple(uint256 vaultId, uint256[] nftIds, uint256 vTokenPremiumLimit, uint256 deadline, uint24 fee, uint160 sqrtPriceLimitX96) params) payable",
"function computePool(address vToken_, uint24 fee) view returns (address)",
"function earlyWithdrawPenaltyInWei() view returns (uint256)",
Expand Down
2 changes: 1 addition & 1 deletion packages/abi/src/index.ts

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions packages/abi/src/json/PoolRouter.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
"internalType": "address",
"name": "pool",
"type": "address"
},
{
"indexed": false,
"internalType": "address",
"name": "recipient",
"type": "address"
}
],
"name": "AddLiquidity",
Expand Down Expand Up @@ -261,7 +267,8 @@
{ "internalType": "uint256", "name": "vTokenMin", "type": "uint256" },
{ "internalType": "uint256", "name": "wethMin", "type": "uint256" },
{ "internalType": "uint256", "name": "deadline", "type": "uint256" },
{ "internalType": "bool", "name": "forceTimelock", "type": "bool" }
{ "internalType": "bool", "name": "forceTimelock", "type": "bool" },
{ "internalType": "address", "name": "recipient", "type": "address" }
],
"internalType": "struct INFTXRouter.AddLiquidityParams",
"name": "params",
Expand Down Expand Up @@ -306,7 +313,8 @@
{ "internalType": "uint256", "name": "vTokenMin", "type": "uint256" },
{ "internalType": "uint256", "name": "wethMin", "type": "uint256" },
{ "internalType": "uint256", "name": "deadline", "type": "uint256" },
{ "internalType": "bool", "name": "forceTimelock", "type": "bool" }
{ "internalType": "bool", "name": "forceTimelock", "type": "bool" },
{ "internalType": "address", "name": "recipient", "type": "address" }
],
"internalType": "struct INFTXRouter.AddLiquidityParams",
"name": "params",
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@nftx/config": "^0.9.0",
"@nftx/types": "^0.9.0",
"@nftx/utils": "^0.9.0",
"viem": "0.1.19"
"viem": "^1.16.6"
},
"bugs": {
"url": "https://github.com/NFTX-project/nftxjs/issues"
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export * from './vaults';
export * from './users';
export * from './utils';
export * from './collections';
export * from './quotes';
4 changes: 3 additions & 1 deletion packages/api/src/prices/fetchQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type PriceArgs = CommonArgs & {
type QuoteArgs = CommonArgs & {
quoteType: 'quote';
userAddress: Address;
slippagePercentage?: number;
};

function fetchQuote(args: PriceArgs): Promise<MarketplacePrice>;
Expand Down Expand Up @@ -62,7 +63,7 @@ function fetchQuote(args: PriceArgs | QuoteArgs) {
});
}

const { userAddress } = args;
const { userAddress, slippagePercentage } = args;

return queryApi<MarketplaceQuote>({
url: `/${network}/quote`,
Expand All @@ -74,6 +75,7 @@ function fetchQuote(args: PriceArgs | QuoteArgs) {
sellTokenIds,
sellAmounts,
userAddress,
slippagePercentage,
},
});
}
Expand Down
3 changes: 3 additions & 0 deletions packages/api/src/prices/fetchVaultBuyQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const fetchVaultBuyQuote = ({
vaultId,
network,
userAddress,
slippagePercentage,
}: {
vaultId: string;
tokenIds: TokenId[] | [TokenId, number][];
userAddress: Address;
network?: number;
slippagePercentage?: number;
}) =>
fetchQuote({
quoteType: 'quote',
Expand All @@ -19,6 +21,7 @@ const fetchVaultBuyQuote = ({
buyTokenIds: tokenIds,
network,
userAddress,
slippagePercentage,
});

export default fetchVaultBuyQuote;
3 changes: 3 additions & 0 deletions packages/api/src/prices/fetchVaultMintQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const fetchVaultMintQuote = ({
vaultId,
network,
userAddress,
slippagePercentage,
}: {
vaultId: string;
tokenIds: TokenId[] | [TokenId, number][];
userAddress: Address;
network?: number;
slippagePercentage: number;
}) =>
fetchQuote({
quoteType: 'quote',
Expand All @@ -19,6 +21,7 @@ const fetchVaultMintQuote = ({
sellTokenIds: tokenIds,
network,
userAddress,
slippagePercentage,
});

export default fetchVaultMintQuote;
3 changes: 3 additions & 0 deletions packages/api/src/prices/fetchVaultRedeemQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const fetchVaultRedeemQuote = ({
vaultId,
network,
userAddress,
slippagePercentage,
}: {
vaultId: string;
tokenIds: TokenId[] | [TokenId, number][];
userAddress: Address;
network?: number;
slippagePercentage?: number;
}) =>
fetchQuote({
quoteType: 'quote',
Expand All @@ -19,6 +21,7 @@ const fetchVaultRedeemQuote = ({
buyTokenIds: tokenIds,
network,
userAddress,
slippagePercentage,
});

export default fetchVaultRedeemQuote;
3 changes: 3 additions & 0 deletions packages/api/src/prices/fetchVaultSellQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const fetchVaultSellQuote = ({
vaultId,
network,
userAddress,
slippagePercentage,
}: {
vaultId: string;
tokenIds: TokenId[] | [TokenId, number][];
userAddress: Address;
network?: number;
slippagePercentage?: number;
}) =>
fetchQuote({
quoteType: 'quote',
Expand All @@ -19,6 +21,7 @@ const fetchVaultSellQuote = ({
sellTokenIds: tokenIds,
network,
userAddress,
slippagePercentage,
});

export default fetchVaultSellQuote;
3 changes: 3 additions & 0 deletions packages/api/src/prices/fetchVaultSwapQuote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ const fetchVaultSwapQuote = ({
userAddress,
buyTokenIds,
sellTokenIds,
slippagePercentage,
}: {
vaultId: string;
sellTokenIds: `${number}`[];
buyTokenIds: `${number}`[];
userAddress: Address;
network?: number;
slippagePercentage?: number;
}) =>
fetchQuote({
quoteType: 'quote',
Expand All @@ -22,6 +24,7 @@ const fetchVaultSwapQuote = ({
sellTokenIds,
network,
userAddress,
slippagePercentage,
});

export default fetchVaultSwapQuote;
6 changes: 6 additions & 0 deletions packages/api/src/quotes/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export { default as quoteCreateInventoryPosition } from './quoteCreateInventoryPosition';
export { default as quoteCreateLiquidityPosition } from './quoteCreateLiquidityPosition';
export { default as quoteCreateVault } from './quoteCreateVault';
export { default as quoteIncreaseLiquidity } from './quoteIncreaseLiquidity';
export { default as quoteWithdrawInventory } from './quoteWithdrawInventory';
export { default as quoteWithdrawLiquidity } from './quoteWithdrawLiquidity';
19 changes: 19 additions & 0 deletions packages/api/src/quotes/quoteCreateInventoryPosition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import config from '@nftx/config';
import {
CreateInventoryPositionQuote,
CreateInventoryPositionQuoteParams,
} from '@nftx/types';
import { queryApi } from '../utils';

const quoteCreateInventoryPosition = ({
network = config.network,
...query
}: CreateInventoryPositionQuoteParams & { network?: number }) => {
return queryApi<CreateInventoryPositionQuote>({
url: `/${network}/quote/create-inventory-position`,
method: 'POST',
query,
});
};

export default quoteCreateInventoryPosition;
19 changes: 19 additions & 0 deletions packages/api/src/quotes/quoteCreateLiquidityPosition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import config from '@nftx/config';
import {
CreateLiquidityPositionQuote,
CreateLiquidityPositionQuoteParams,
} from '@nftx/types';
import { queryApi } from '../utils';

const quoteCreateLiquidityPosition = ({
network = config.network,
...query
}: CreateLiquidityPositionQuoteParams & { network?: number }) => {
return queryApi<CreateLiquidityPositionQuote>({
url: `/${network}/quote/create-liquidity-position`,
method: 'POST',
query,
});
};

export default quoteCreateLiquidityPosition;
16 changes: 16 additions & 0 deletions packages/api/src/quotes/quoteCreateVault.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import config from '@nftx/config';
import { CreateVaultQuote, CreateVaultQuoteParams } from '@nftx/types';
import { queryApi } from '../utils';

const quoteCreateVault = ({
network = config.network,
...query
}: CreateVaultQuoteParams & { network?: number }) => {
return queryApi<CreateVaultQuote>({
url: `/${network}/quote/create-vault`,
method: 'POST',
query,
});
};

export default quoteCreateVault;
19 changes: 19 additions & 0 deletions packages/api/src/quotes/quoteIncreaseLiquidity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import config from '@nftx/config';
import {
IncreaseLiquidityQuote,
IncreaseLiquidityQuoteParams,
} from '@nftx/types';
import { queryApi } from '../utils';

const quoteIncreaseLiquidity = ({
network = config.network,
...query
}: IncreaseLiquidityQuoteParams & { network?: number }) => {
return queryApi<IncreaseLiquidityQuote>({
url: `/${network}/quote/increase-liquidity`,
method: 'POST',
query,
});
};

export default quoteIncreaseLiquidity;
19 changes: 19 additions & 0 deletions packages/api/src/quotes/quoteWithdrawInventory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import config from '@nftx/config';
import { queryApi } from '../utils';
import {
WithdrawInventoryQuote,
WithdrawInventoryQuoteParams,
} from '@nftx/types';

const quoteWithdrawInventory = ({
network = config.network,
...query
}: { network?: number } & WithdrawInventoryQuoteParams) => {
return queryApi<WithdrawInventoryQuote>({
url: `/${network}/quote/withdraw-inventory`,
method: 'POST',
query,
});
};

export default quoteWithdrawInventory;
19 changes: 19 additions & 0 deletions packages/api/src/quotes/quoteWithdrawLiquidity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import config from '@nftx/config';
import { queryApi } from '../utils';
import {
WithdrawLiquidityQuote,
WithdrawLiquidityQuoteParams,
} from '@nftx/types';

const quoteWithdrawLiquidity = ({
network = config.network,
...query
}: WithdrawLiquidityQuoteParams & { network?: number }) => {
return queryApi<WithdrawLiquidityQuote>({
url: `/${network}/quote/withdraw-liquidity`,
method: 'POST',
query,
});
};

export default quoteWithdrawLiquidity;
3 changes: 0 additions & 3 deletions packages/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
ERC721_SUBGRAPH,
NFTX_SUBGRAPH,
NON_STANDARD_SUBGRAPH,
PUBLIC_GRAPH_API_KEY,
NFTX_APR_URL,
Network,
ALCHEMY_URL,
Expand All @@ -29,7 +28,6 @@ export interface Config {
*/
subgraph: {
/** A user-specific subgraph api key, if you have one */
API_KEY: string;
ERC1155_SUBGRAPH: Record<string, string | string[]>;
ERC721_SUBGRAPH: Record<string, string | string[]>;
NFTX_SUBGRAPH: Record<string, string | string[]>;
Expand Down Expand Up @@ -96,7 +94,6 @@ const storeSettings = <T extends Record<string, any>>(obj: T) => {
const defaultConfig: Config = {
network: Network.Mainnet,
subgraph: {
API_KEY: PUBLIC_GRAPH_API_KEY,
ERC1155_SUBGRAPH,
ERC721_SUBGRAPH,
NFTX_SUBGRAPH,
Expand Down
4 changes: 2 additions & 2 deletions packages/constants/src/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const OPENSEA_COLLECTION = a(

/** Zap specifically for creating new vaults */
export const CREATE_VAULT_ZAP = {
[Network.Goerli]: a('0xFE60863328735aE7EB289cAB99B37235add768Fa'),
[Network.Goerli]: a('0xFA7d98Ec2b046e636c45A0291F931b94a5a1CA59'),
};

/** Perform buy/sell/swaps */
Expand All @@ -54,7 +54,7 @@ export const NFTX_ROUTER = {

/** Staking / Liquidity / Pools (NftxRouter) */
export const POOL_ROUTER = {
[Network.Goerli]: a('0x3b79692Eb189a68E513ad5628A419950E5773e35'),
[Network.Goerli]: a('0xb95e2Fb1eDA32BbFbDaE2463BB3E64bb3E1E41D5'),
};

export const NONFUNGIBLE_POSITION_MANAGER = {
Expand Down
7 changes: 1 addition & 6 deletions packages/constants/src/subgraph.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import { Network } from './networks';

export const PUBLIC_GRAPH_API_KEY = '690cf8d6987a151008c2536454bd3d7a';
// Locked down to nftx.io
export const NFTX_GRAPH_API_KEY = '690cf8d6987a151008c2536454bd3d7a';

const SHARED_PATH = 'subgraphs/name';
const INDEXER_PATH = 'subgraphs/id';
const GATEWAY_PATH = `api/${PUBLIC_GRAPH_API_KEY}/subgraphs/id`;
const GATEWAY_PATH = `api/690cf8d6987a151008c2536454bd3d7a/subgraphs/id`;

const SHARED_HOST = 'https://api.thegraph.com';
const INDEXER_HOST = 'https://query.graph.nftx.xyz';
Expand Down Expand Up @@ -60,7 +56,6 @@ export const ERC1155_SUBGRAPH = {
'https://api.thegraph.com/subgraphs/name/nftx-project/eip1155-looksrare-goerli',
};

// TODO: update to the v3 subgraph urls
export const NFTX_SUBGRAPH_MAINNET_URLS = {
GATEWAY_PROXY: `${GATEWAY_CACHE_PROXY_ROOT}/4gZf3atMXjYDh4g48Zr83NFX3rkvZED86VqMNhgEXgLc`,
GATEWAY: `${GATEWAY_ROOT}/4gZf3atMXjYDh4g48Zr83NFX3rkvZED86VqMNhgEXgLc`,
Expand Down
Loading

0 comments on commit 12e9f6d

Please sign in to comment.