UNPKG

@bancor/carbon-sdk

Version:

The SDK is a READ-ONLY tool, intended to facilitate working with Carbon contracts. It's a convenient wrapper around our matching algorithm, allowing programs and users get a ready to use transaction data that will allow them to manage strategies and fulfi

2 lines (1 loc) 1.11 kB
import{Decimal as t,ONE as r}from"../../../utils/numerics/index.js";import{decodeOrder as e,decodeFloat as n}from"../../../utils/encoders/index.js";import{BigNumber as o}from"@ethersproject/bignumber";const i=t.ln("1.0001"),c=1;function u(t,r){const e=t.ln().div(i);return r?e.ceil().toNumber():e.floor().toNumber()}function s(t){return t.A.isZero()?(1/0).toString():t.z.mul(r).div(n(t.A)).toString()}function l(r,e){const n=r.sqrt().mul(new t(2).pow(96));return e?n.ceil().toString():n.floor().toString()}function m(r,n){const o=e(r),i=new t(o.lowestRate),c=new t(o.highestRate),m=new t(o.marginalRate);if(!n)return{tickUpper:u(c,!0),tickLower:u(i,!1),liquidity:s(r),sqrtPriceX96:l(m,!1)};const d=new t(1).div(c),f=new t(1).div(i),k=new t(1).div(m);return{tickUpper:u(f,!0),tickLower:u(d,!1),liquidity:s(r),sqrtPriceX96:l(k,!0)}}function d(t){const r=o.from(t.token0),e=o.from(t.token1),n=r.lt(e);return{pool:{xAxisToken:n?t.token0:t.token1,yAxisToken:n?t.token1:t.token0,tickSpacing:c},sellOrder:m(t.order0,n),buyOrder:m(t.order1,!n)}}function f(t){return t.map(d)}export{f as batchCastToUniV3,d as castToUniV3};