@ape.swap/zap-tx-builder
v0.0.2
Published
Zap Tx Builder is a utility tool that helps in creating encoded data for zap.
Downloads
10
Keywords
Readme
Zap Tx Builder
Zap Tx Builder is a utility tool that helps in creating encoded data for zap.
Contracts
Zap Contracts: https://github.com/ApeSwapFinance/apeswap-hardhat-zap
Router Contracts: https://github.com/ApeSwapFinance/swap-router-contracts
Usage
npm i @ape.swap/zapTxBuilder
yarn add @ape.swap/zapTxBuilder
ZapBuilderFrom0xPath
!! CHECK test/zapTxBuilder.spec.tx
FOR MORE EXAMPLES !!
Example zapping WMATIC to ApeV2 BANANA-BUSD LP
With swap routing best path found by 0x API (https://0x.org/docs/0x-swap-api/api-references/overview)
import { ZapBuilderFrom0xPath } from "@ape.swap/zapTxBuilder";
const provider: providers.Provider = new providers.JsonRpcProvider(
"https://polygon.llamarpc.com"
);
const zapBuilder = new ZapBuilderFrom0xPath(provider, 137);
const zapLP = await zapBuilder.toLP(
WMATIC, //InputToken
AMOUNT, //Amount tof inputToken to zap
BANANA, //First token of LP
BUSD, //Second token of LP
APEV2, //LP router/factory
ADDRESS_THIS //Recipient (default: MSG_SENDER)
);
return zapLP.populatedTx; //Encoded data to zap into LP
ZapBuilder
!! CHECK test/zapTxBuilder.spec.tx
FOR MORE EXAMPLES !!
Example zapping WMATIC to ApeV2 BANANA-BUSD LP
With swap routing:
- WMATIC --UniV3--> ETH --ApeV2--> BANANA
- WMATIC --PcsV2--> BUSD
import { ZapBuilder } from "@ape.swap/zapTxBuilder";
const provider: providers.Provider = new providers.JsonRpcProvider(
"https://polygon.llamarpc.com"
);
const swapPath00: Path = {
swapRouter: UNIV3Factory,
swapType: SwapType.V3,
path: [WMATIC, ETH],
uniV3PoolFees: [500],
};
const swapPath01: Path = {
swapRouter: APEV2Router,
swapType: SwapType.V2,
path: [ETH, BANANA],
uniV3PoolFees: [],
};
const swapPath10: Path = {
swapRouter: PCSV2Router,
swapType: SwapType.V2,
path: [WMATIC, BUSD],
uniV3PoolFees: [],
};
const liquidityPath: LiquidityPath = {
lpRouter: APEV2Router,
liquidityType: LPType.V2,
tickLower: 0,
tickUpper: 0,
uniV3PoolLPFee: 0,
arrakisFactory: ZERO_ADDRESS,
};
const swapReturnsParams: SwapReturnsParams = {
inputAmount: ether("0.01").toString(),
path0: [swapPath00, swapPath01],
path1: [swapPath1],
liquidityPath: liquidityPath,
};
const zapBuilder = new ZapBuilder(provider, 137);
const zapLP = await zapBuilder.toLPFromPath(swapReturnsParams);
return zapLP.populatedTx; //Encoded data to zap into LP
Extra extensions
const zapBill = await zapLP.toBill({
bill: USDCWOMBATBOND,
inputAmount: 0,
maxPrice: "23382705930",
recipient: "0x5c7C7246bD8a18DF5f6Ee422f9F8CCDF716A6aD2",
});
return zapBill.populatedTx; //Encoded data to zap into Bill
const zapPool = await zapLP.toPool({
inputAmount: 0,
pool: "0xA3c3A929Ae19Bfc56E2A9B0f23e99bae8Bf6F11A",
recipient: MSG_SENDER,
});
return zapPool.populatedTx; //Encoded data to zap into Pool
const zapVault = await zapLP.toVault({
inputAmount: 0,
maximizerVaultApe: KEEPER_MAXIMIZER_VAULT_APE,
vaultPid: 0,
recipient: MSG_SENDER,
});
return zapVault.populatedTx; //Encoded data to zap into Vault
const zapMiniApe = await zapLP.toMiniApe({
inputAmount: 0,
miniApe: MINI_APE_V2,
pid: 0,
recipient: MSG_SENDER,
});
return zapMiniApe.populatedTx; //Encoded data to zap into Mini Ape