UNPKG

@quantara/sdk

Version:

JavaScript/TypeScript SDK for interacting with Quantara Protocol on Neura Testnet

63 lines (62 loc) 2.89 kB
import { describe, it, expect } from "vitest"; import { USD_DECIMALS } from "../../configs/factors"; import { numberToBigint } from "../numbers"; import { getFundingFactorPerPeriod } from "../fees"; const dollar = 10n ** BigInt(USD_DECIMALS); const eightMillion = 8000000n; const tenMillion = 10000000n; function toFactor(percent) { const value = parseFloat(percent.replace("%", "")); return numberToBigint(value, 30 - 2); } const second = 1; describe("getFundingFactorPerPeriod", () => { it("works when short pay, shorts OI bigger", () => { const marketInfo = { fundingFactorPerSecond: toFactor("50%"), longsPayShorts: false, longInterestUsd: eightMillion * dollar, shortInterestUsd: tenMillion * dollar, }; const forLongs = getFundingFactorPerPeriod(marketInfo, true, second); expect(forLongs.toString()).toBe(toFactor("62.5%").toString()); const forShorts = getFundingFactorPerPeriod(marketInfo, false, second); expect(forShorts.toString()).toBe(toFactor("-50%").toString()); }); it("works when short pay, longs OI bigger", () => { const marketInfo = { fundingFactorPerSecond: toFactor("50%"), longsPayShorts: false, longInterestUsd: tenMillion * dollar, shortInterestUsd: eightMillion * dollar, }; const forLongs = getFundingFactorPerPeriod(marketInfo, true, second); expect(forLongs.toString()).toBe(toFactor("50%").toString()); const forShorts = getFundingFactorPerPeriod(marketInfo, false, second); expect(forShorts.toString()).toBe(toFactor("-62.5%").toString()); }); it("works when long pay, shorts OI bigger", () => { const marketInfo = { fundingFactorPerSecond: toFactor("50%"), longsPayShorts: true, longInterestUsd: eightMillion * dollar, shortInterestUsd: tenMillion * dollar, }; const forLongs = getFundingFactorPerPeriod(marketInfo, true, second); expect(forLongs.toString()).toBe(toFactor("-62.5%").toString()); const forShorts = getFundingFactorPerPeriod(marketInfo, false, second); expect(forShorts.toString()).toBe(toFactor("50%").toString()); }); it("works when long pay, longs OI bigger", () => { const marketInfo = { fundingFactorPerSecond: toFactor("50%"), longsPayShorts: true, longInterestUsd: tenMillion * dollar, shortInterestUsd: eightMillion * dollar, }; const forLongs = getFundingFactorPerPeriod(marketInfo, true, second); expect(forLongs.toString()).toBe(toFactor("-50%").toString()); const forShorts = getFundingFactorPerPeriod(marketInfo, false, second); expect(forShorts.toString()).toBe(toFactor("62.5%").toString()); }); });