evelyn-sdk v1.0.0
Evelyn SDK (ALPHA)
A Javascript SDK for Evelyn Perpetual.
This repo is still in beta.
Usage
Install
Install dependencies:
yarn add evelyn-sdkSee ./test/ for common use cases.
Development
Environment Variables
TRACK
METADATA_URL_CORE_OVERRIDE_FANTOM_TESTNET
METADATA_URL_CORE_OVERRIDE_FANTOM
METADATA_URL_PERIPHERY_OVERRIDE_FANTOM_TESTNET
METADATA_URL_PERIPHERY_OVERRIDE_FANTOM
enum TRACK {
  dev1 = "dev1"
  dev2 = "dev2"
  canary = "canary"
  rc = "rc"
  production = "production"
}Setup before development
yarn
yarn generate-type:[TRACK]Testing in other projects
In this repo, run:
yarn link
yarn start:[TRACK]To supply custom envs, run:
METADATA_URL_CORE_OVERRIDE_FANTOM_TESTNET="your_url" \
METADATA_URL_PERIPHERY_OVERRIDE_FANTOM="your_url" \
yarn start:[TRACK]In the repo that you want to test with, run:
yarn link evelyn-sdkCommit
We use commitizen and commitlint to regulate commit message.
yarn commitTest
yarn testUsage
Create a PerpetualProtocol instance
- Now we only support fantom
const perp = new PerpetualProtocol({
    chainId: 250,
    providerConfigs: [{ rpcUrl: "https://rpc.ftm.tools" }],
})
await perp.init()Open a position
- Remember to provide your signer when connecting.
For example:
Open a Long position using quoteToken. 
baseToken: ETH 
quoteToken: USD
const perp = new PerpetualProtocol({
    chainId: 250,
    providerConfigs: [{ rpcUrl: "https://rpc.ftm.tools" }],
})
await perp.init()
await perp.connect({ signer })const tickerSymbol = "ETHUSD"
const slippage = new Big(0.02) // remember to transform to Big type
const amountInput = new Big(100) // remember to transform to Big type
const side = PositionSide.LONG
const isAmountInputBase = false // we are not using base token to open a long position here.
const newPositionDraft = perp.clearingHouse.createPositionDraft({
    tickerSymbol,
    side,
    amountInput,
    isAmountInputBase,
})
perp.clearingHouse.openPosition(positionDraft, slippage)Close a position
const tickerSymbol = "ETHUSD"
const position = await perp.positions.getTakerPositionByTickerSymbol(tickerSymbol)
perp.clearingHouse.closePosition(position, slippage)Add liquidity
- Remember to provide your signer when connecting.
For example:
Use quoteToken to add liquidity. 
baseToken: ETH 
quoteToken: USD
const perpParam = {
    chainId: 250,
    providerConfigs: [{ rpcUrl: "https://rpc.ftm.tools/" }],
}
const perp = new PerpetualProtocol(perpParam)
await perp.init()
await perp.connect({ signer })const tickerSymbol = "ETHUSD"
const market = perp.markets.getMarket({ tickerSymbol })
const lowerTick = perp.market.getPriceToTick(lowerTickPrice)
const upperTick = perp.market.getPriceToTick(upperTickPrice)
const slippage = new Big(0.02) // remember to transform to Big type
const rawBaseAmount = undefined
const rawQuoteAmount = new Big(100) // remember to transform to Big type
const liquidityDraft = perp.clearingHouse.createLiquidityDraft({
    tickerSymbol,
    rawBaseAmount,
    rawQuoteAmount,
    upperTick,
    lowerTick,
})
perp.clearingHouse.addLiquidity(liquidityDraft, slippage)Remove liquidity
- ratiomeans how much ratio you would like to remove. 1 means 100%
- Use filterFnto filter out liquidity you would like to remove.
const ratio = new Big(1) // remember to transform to Big type
const slippage = new Big(0.02) // remember to transform to Big type
const liquidity = perp.liquidities.getTotalLiquidities().filter(filterFn)
perp.clearingHouse.removeLiquidity(liquidity, ratio, slippage)If any features/functionalities described in the Evelyn Perpetual documentation, code comments, marketing, community discussion or announcements, pre-production or testing code, or other non-production-code sources, vary or differ from the code used in production, in case of any dispute, the code used in production shall prevail.
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago