0.8.8 • Published 5 months ago

@autonomysdk/perpaggregator v0.8.8

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

PerpAggregator

This project has typescript implementation of how we can interact with contracts and use it in UI

Sample Code

// import {  swapPath } from "./domain/synthetics/orders/swapPath";
// import { ARBITRUM, getRpcUrl } from "./config/chains";
// import { useMarketInfo } from "./domain/synthetics/markets/useMarketInfo";
// import { BigNumber, ethers } from "ethers";
// import { getGasPrice } from "./domain/synthetics/fees/useGasPrice";
// import { useGasLimits } from "./domain/synthetics/fees/useGasLimits";
// import { estimateExecuteIncreaseOrderGasLimit, getExecutionFee } from "./domain/synthetics/fees/utils/executionFee";
// import { GasLimitsConfig } from "./domain/synthetics/fees/types";
// import { createIncreaseOrder } from "./domain/synthetics/orders/createIncreaseOrder";
// import { getSwapPathStats } from "./domain/synthetics/trade/utils/swapStats";
// import { kuseSwapRoutes } from "./domain/synthetics/trade/useSwapRoute";
// import { cancelOrdersTxn } from "./domain/synthetics/orders/cancelOrder";

// async function bootstrap() {
//   const {marketsInfoData}=await useMarketInfo(ARBITRUM)
//   const marketAddress='0x47c031236e19d024b42f8AE6780E44A573170703'
//   const marketInfo = marketsInfoData[marketAddress];
//   console.log(marketInfo);
  
//   const url = getRpcUrl(ARBITRUM)?.[0];
//   const provider = new ethers.providers.JsonRpcProvider(url);
//   const privateKey = process.env.PRIVATE_KEY as string;
//   const wallet = new ethers.Wallet(privateKey, provider);
//   const execFee=await exec()
  // const swapP=['0x47c031236e19d024b42f8AE6780E44A573170703']
  // const swap= getSwapPathStats({
  //   marketsInfoData:marketsInfoData,
  //   swapPath:swapP,
  //   initialCollateralAddress:"0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
  //   wrappedNativeTokenAddress:"0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
  //   usdIn: BigNumber.from('0x02034ea2c876458ba412da680000'),
  //   shouldApplyPriceImpact:false,
  //   shouldUnwrapNativeToken:false

  // })
 
  

  // const positionInfo ={
  //   isLong : false,
  //   sizeInUsd : BigNumber.from("188453000000000000000000000000000"),
  //   market: ethers.utils.getAddress("0x70d95587d40A2caf56bd97485aB3Eec10Bee6336"),
  //   collateralAmount:BigNumber.from("9930471606974805")
  // }
  const execFee=await exec()

  // const data   = await createClosePosition(marketInfo, wallet, ARBITRUM, positionInfo)
  // console.log('Hashs', data);

  const hashsx = await createDecreaseOrder(marketInfo, wallet, ARBITRUM,execFee)
  console.log('Hashs', hashsx);
  // const hash=await cancelOrdersTxn(ARBITRUM,wallet,['0x7d5c470655a19429153a1be5f3262b079e38025150fee56c67811a9ef5dcb1fc',
  // '0x2ac7d17d7f1f818866184ebff2a41b2788f3c635fdac308bdfac67490bfef621'],execFee)
  // console.log(hash);
  
  // const hash = await createIncreaseOrder(marketInfo,marketsInfoData, wallet, '0.0001', '10.00', ARBITRUM, '0.3', false, true,execFee,3,'0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f',"40000");
  // console.log('Hash', hash);



//   const { positionsInfoData } = await usePositionsInfo(ARBITRUM, {
//     account: wallet.address,
//     marketsInfoData: marketsInfoData,
//     tokensData: tokensData,
//     pricesUpdatedAt: pricesUpdatedAt,
//     showPnlInLeverage: true,
//   });

//   const parsedPosition = [];
//   for (const key in positionsInfoData) {
//     const position = positionsInfoData[key];
//     const poolName = getMarketPoolName(position.marketInfo);
//     const indexName = getMarketIndexName(position.marketInfo);
//     console.log("PPPPPP",position);
    
//     parsedPosition.push({
//       InitialCollateral: formatUsd(position.collateralUsd),
//       PnL: formatUsd(position.pnl),
//       PnLAfterFees: formatDeltaUsd(position.pnlAfterFees, position.pnlAfterFeesPercentage),
//       Market: position.marketAddress,
//       EntryPrice: formatUsd(position.entryPrice, { displayDecimals: position?.indexToken?.priceDecimals }),
//       MarkPrice: formatUsd(position.markPrice, { displayDecimals: position?.indexToken?.priceDecimals }),
//       LiqPrice: formatUsd(position.liquidationPrice, { displayDecimals: position?.indexToken?.priceDecimals }),
//       isLong: position.isLong,
//       NetValue: formatUsd(position.netValue),
//       PoolName: poolName,
//       IndexName: indexName,
//     });
//   }

//   console.log(parsedPosition);

//   // const hashs = await createDecreaseOrder(marketInfo, wallet, ARBITRUM);
//   // console.log('hashs', hashs);
}

bootstrap();

Execution Fee

import { getGasPrice } from './domain/synthetics/fees/useGasPrice';
import { useGasLimits } from './domain/synthetics/fees/useGasLimits';
import { estimateExecuteIncreaseOrderGasLimit, getExecutionFee } from './domain/synthetics/fees/utils/executionFee';
import { GasLimitsConfig } from './domain/synthetics/fees/types';

const exec=async () => {
  const activeChain = ARBITRUM;

  const gasPrice = await getGasPrice(activeChain);
  console.log('gasPrice', gasPrice.toString());

  const gasLimits = await useGasLimits(activeChain);
  console.log('gasLimits', gasLimits);

  const { marketsInfoData, tokensData, pricesUpdatedAt } = await useMarketInfo(activeChain);

  const estimatedGas = estimateExecuteIncreaseOrderGasLimit(gasLimits.gasLimits as GasLimitsConfig, {
    swapPath: [],
  });

  const executionFee = getExecutionFee(activeChain, gasLimits.gasLimits, tokensData, estimatedGas, gasPrice);
  console.log('executionFee', executionFee.feeTokenAmount);
  return executionFee.feeTokenAmount
};
0.8.8

5 months ago

0.8.7

5 months ago

0.8.6

5 months ago

0.8.5

5 months ago

0.8.4

5 months ago

0.8.1

5 months ago

0.8.3

5 months ago

0.8.2

5 months ago

0.7.4

5 months ago

0.7.9

5 months ago

0.7.6

5 months ago

0.7.5

5 months ago

0.7.8

5 months ago

0.7.7

5 months ago

0.8.0

5 months ago

0.7.2

5 months ago

0.7.3

5 months ago

0.7.1

5 months ago

0.7.0

5 months ago

0.6.9

5 months ago

0.6.8

5 months ago

0.6.7

6 months ago

0.6.6

6 months ago

0.6.3

6 months ago

0.6.5

6 months ago

0.6.4

6 months ago

0.5.8

6 months ago

0.4.9

6 months ago

0.5.7

6 months ago

0.4.8

6 months ago

0.5.9

6 months ago

0.5.4

6 months ago

0.4.5

6 months ago

0.6.2

6 months ago

0.5.3

6 months ago

0.4.4

6 months ago

0.5.6

6 months ago

0.4.7

6 months ago

0.5.5

6 months ago

0.4.6

6 months ago

0.5.0

6 months ago

0.4.1

6 months ago

0.6.1

6 months ago

0.5.2

6 months ago

0.4.3

6 months ago

0.6.0

6 months ago

0.5.1

6 months ago

0.4.2

6 months ago

0.3.9

7 months ago

0.3.8

7 months ago

0.3.7

7 months ago

0.4.0

6 months ago

0.3.6

7 months ago

0.3.5

7 months ago

0.3.4

7 months ago

0.3.3

7 months ago

0.3.2

7 months ago

0.3.1

7 months ago

0.3.0

7 months ago

0.2.9

7 months ago

0.2.8

7 months ago

0.2.7

7 months ago

0.2.6

7 months ago

0.2.5

7 months ago

0.2.4

7 months ago

0.2.3

7 months ago

0.2.2

7 months ago

0.2.1

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago