Skip to content
thalaswap-math / 1.0.1

thalaswap-math 1.0.1

Install from the command line:
Learn more about npm packages
$ npm install @thalalabs/thalaswap-math@1.0.1
Install via package.json:
"@thalalabs/thalaswap-math": "1.0.1"

About this version

thalaswap-math

SDK to calculate swap amounts and pool price.

install

Edit or add a .npmrc file to including following lines:

//npm.pkg.github.com/:_authToken=_authToken
@thalalabs:registry=https://npm.pkg.github.com

Run command to login:

$ npm login --registry=https://npm.pkg.github.com
> Username: USERNAME
> Password: TOKEN

USERNAME is you github account username. Get the token from your github settings, see "Managing your personal access tokens.".

$ npm i @thalalabs/thalaswap-math

example

import {
  calcInGivenOutStable,
  calcInGivenOutWeighted,
  calcOutGivenInStable,
  calcOutGivenInWeighted,
} from "@thalalabs/thalaswap-math";

// Calculate amount out given amount in:
// A stable pool with three tokens having balances of [100, 200, 300],
// The pool's amplification coefficient is 1.
// And the swap fee is 0.01.
// We use the second token as input and the third token as output.
// And the input token amount is 10.
console.log(calcOutGivenInStable(10, 1, 2, [100, 200, 300], 1, 0.01));

// Calculate amount in given amount out:
// A stable pool with three tokens having balances of [100, 200, 300],
// The pool's amplification coefficient is 1.
// And the swap fee is 0.01.
// We use the second token as input and the third token as output.
// And the output token amount is 10.
console.log(calcInGivenOutStable(10, 1, 2, [100, 200, 300], 1, 0.01));

// Calculate amount out given amount in:
// A weighted pool has a token whose balance is 100 and weight is 20,
// and the pool also has another token whose balance is 200 and weight is 30.
// The swap fee is 0.01.
// Use the first token as input and the second token as output.
// And the input token amount is 10.
console.log(calcOutGivenInWeighted(100, 20, 200, 30, 10, 0.01));

// Calculate amount out given amount out:
// A weighted pool has a token whose balance is 100 and weight is 20,
// and the pool also has another token whose balance is 200 and weight is 30.
// The swap fee is 0.01.
// Use the first token as input and the second token as output.
// And the output token amount is 10.
console.log(calcInGivenOutWeighted(100, 20, 200, 30, 10, 0.01));

Details


Assets

  • thalaswap-math-1.0.1.tgz

Download activity

  • Total downloads 0
  • Last 30 days 0
  • Last week 0
  • Today 0

Recent versions

View all