UNPKG

@dahlia-labs/stableswap-sdk

Version:
76 lines 2.92 kB
import { Fraction, Percent } from "@dahlia-labs/token-utils"; import { getContract } from "@dahlia-labs/use-ethers"; import { Interface } from "@ethersproject/abi"; import JSBI from "jsbi"; import LPTOKEN_ABI from "./abis/LPToken.json"; import SWAP_ABI from "./abis/Swap.json"; export const FEE_BASE = JSBI.exponentiate(JSBI.BigInt(10), JSBI.BigInt(10)); export function getLPTokenInterface() { return new Interface(LPTOKEN_ABI); } export function getSwapInterface() { return new Interface(SWAP_ABI); } export const lpTokenInterface = getLPTokenInterface(); export const swapInterface = getSwapInterface(); export const getLPTokenContract = (address, provider) => getContract(address, LPTOKEN_ABI, provider); export const getSwapContract = (address, provider) => getContract(address, SWAP_ABI, provider); export const LPMulticall = (swapAddress) => ({ call: { target: swapAddress, callData: swapInterface.encodeFunctionData("getLpToken"), }, parseReturn: (returnData) => returnData, }); export const ampMulticall = (swapAddress) => ({ call: { target: swapAddress, callData: swapInterface.encodeFunctionData("getA"), }, parseReturn: (returnData) => JSBI.BigInt(returnData), }); export const pausedMulticall = (swapAddress) => ({ call: { target: swapAddress, callData: swapInterface.encodeFunctionData("paused"), }, parseReturn: (returnData) => swapInterface.decodeFunctionResult("paused", returnData)[0], }); export const feesMulticall = (swapAddress) => ({ call: { target: swapAddress, callData: swapInterface.encodeFunctionData("swapStorage"), }, parseReturn: (returnData) => { const data = swapInterface.decodeFunctionResult("swapStorage", returnData); return { trade: new Percent(data.swapFee.toString(), FEE_BASE), admin: new Percent(data.adminFee.toString(), FEE_BASE), deposit: new Percent(data.defaultDepositFee.toString(), FEE_BASE), withdraw: new Percent(data.defaultWithdrawFee.toString(), FEE_BASE), }; }, }); export const tokenBalanceMulticall = (swapAddress, index) => ({ call: { target: swapAddress, callData: swapInterface.encodeFunctionData("getTokenBalance", [index]), }, parseReturn: (returnData) => new Fraction(swapInterface .decodeFunctionResult("getTokenBalance", returnData) .toString()), }); export const calculateSwapMulticall = (swapAddress, fromIndex, toIndex, amountIn) => ({ call: { target: swapAddress, callData: swapInterface.encodeFunctionData("calculateSwap", [ fromIndex, toIndex, amountIn, ]), }, parseReturn: (returnData) => new Fraction(swapInterface .decodeFunctionResult("calculateSwap", returnData) .toString()), }); //# sourceMappingURL=contract.js.map