API Reference

This function allows users to buy NFTs from the sell pool. You can buy from multiple pools in one transaction

Request Parameters
ParameterTypeDescriptionExample
swapListRobustPairSwapSpecific[]Data Content: [[[Contract Address, [Token ID 1, Token ID 2, ...],[Amount 1, Amount 2]], Expected Payment Amount]][[['0x4485aD38f3fe1DA3856155496f7fEce05d4C3B56', 3104', [1,2,3],[1,2,3]], 1000000000000000000]]
ethRecipientaddressUnused ETH recipient address, usually msg.sender0x0a9EE17c7B649dd30Db1450537576d313FF862C7
nftRecipientaddressNFT recipient address, usually msg.sender0x0a9EE17c7B649dd30Db1450537576d313FF862C7
deadlineuint256Expiration timestamp1665208404

call router contract

Additional
// The specific structure of swapList
struct RobustPairSwapSpecific {
        PairSwapSpecific swapInfo;
        uint256 maxCost;
}

struct PairSwapSpecific {
        LSSVMPair pair;
        uint256[] nftIds;
        uint256[] nftCounts;
}
Return Parameters
ParameterTypeDescriptionExample
remainingValueuint256Unspent ETH1000000000000000

ABI

function robustSwapETHForSpecificNFTs(tuple(tuple(address,uint256[],uint256[]),uint256)[],address,address,uint256) public payable returns (uint256)

Expected Payment Amount and Current NFT Price

Refer to the calculation library for detail.

When buying NFTs, a maximum expected cost needs to be set, and transactions exceeding this value will not be made.
//Example: Scenario: A user buys an NFT from a linear pool
mathLib.Linear.buy(1, 0.1, 0.003, 0.003, 1, 0, 'read')
//Return Value: The total price (totalETH) is priceData.userBuyPrice, and the price displayed on the page for that NFT is currentPrice.userBuyPrice
{
  priceData: {
    delta: 0.1,
    spotPrice: 1,
		userBuyPrice: 0.994,   --The amount of ETH the user can sell NFTs for
    poolBuyPrice: 0.997,    --The amount of ETH that the pool will spend to buy NFTs
    poolBuyPriceFee: 0.003,
    userSellPriceFee: 0.006
  },
  currentPrice: { userBuyPrice: 0.994 },   --The current price
  nextPrice: { userSellPrice: 0.8945999999999998 }  --The price of the next NFT
}

Code Example

import { ethers, utils } from 'ethers';

const DEADLINE = Date.parse(new Date()) / 1000 + 60 * 3600;
const abi = ['function robustSwapETHForSpecificNFTs(tuple(tuple(address,uint256[],uint256[]),uint256)[],address,address,uint256) public payable returns (uint256)'];
const signer = new ethers.providers.Web3Provider(window?.ethereum).getSigner();
const contract = new ethers.Contract(routerAddress, abi, signer);
const txResult = await contract.robustSwapETHForSpecificNFTs(
	swapList,
  ethRecipient,
  nftRecipient,
  DEADLINE,
  { value: totalETH },
);

Detailed and complete demo: https://github.com/EZswap-Labs/api-demo