Catalog npm
Back to packageRELEASE DETAILS

1.0.0

npm

3swap-sdk

3Swap-SDK ===========================================

3swap
Published10 Feb 2022
Direct dependencies14
Transitive dependenciesNot calculated

README

Current package documentation

3Swap-SDK

The 3Swap SDK is a convenience library for querying chain state relevant to 3Swap DEX. Leveraging the SDK, you can compute parameters with which to interact with the 3Swap smart contract.

Examples:

  • Fetch token data:

You can query the chain for token info using the chain ID and the token address.

import { Fetcher, ChainId } from '3swap-sdk';

Fetcher.fetchTokenData(
  ChainId.BINANCE_TESTNET,'0x57c84e7bcbab211761a0cb91484ae896aa897ae9'
)
.then(token => {
  console.log('Name: %s, Decimals: %d', token.name(), token.decimals()); // 3Swap 0x, SAPX
});

// or use custom provider

Fetcher.fetchTokenData(
  ChainId.BINANCE_TESTNET,'0x57c84e7bcbab211761a0cb91484ae896aa897ae9', 'PROVIDER_URL'
)
.then(token => {
  console.log('Name: %s, Decimals: %d', token.name(), token.decimals()); // 3Swap 0x, SAPX
});

You can also set a number as the chain id:

Fetcher.fetchTokenData(
  97,'0x57c84e7bcbab211761a0cb91484ae896aa897ae9' // '97' is the chain ID for Binance Testnet
)
.then(token => {
  console.log('Name: %s, Decimals: %d', token.name(), token.decimals()); // 3Swap 0x, SAPX
});

The Fetcher.fetchTokenData function returns a Promise<Token>.

Fields in the token class include:

NameType
_addressstring
_chainIdChainId or number
_decimalsnumber or string
_namestring
_symbolstring
  • Fetch triad data:

Triad information can be fetched on-chain using a static helper method that returns a Promise<Triad>.

import { Fetcher, ChainId } from '3swap-sdk';

async function fetchTriad() {
  const tokenA = await Fetcher.fetchTokenData(
    ChainId.BINANCE_TESTNET, '0x57c84e7bcbab211761a0cb91484ae896aa897ae9'
  );
  
  //...2 other tokens

  const triad = await Fetcher.fetchTriadData(tokenA, tokenB, tokenC);
}
// or use custom provider url

const triad = await Fetcher.fetchTriadData(tokenA, tokenB, tokenC, 'PROVIDER_URL');

Fields in the triad class include:

NameType
liquidityTokenToken
tokenAmounts[TokenAmount, TokenAmount, TokenAmount]

Computing trades:

The SDK also provides the effective computation of trades through the Router class.

import { Router } from '3swap-sdk';

Router.swapCallParameter(trade, chainId, options);

The static swapCallParameter method of the Router class takes in a trade, a chain ID and a trade options object and then computes a SwapParams object which contains the method name, the arguments for the method and the hex encoded value of Ether to be sent in the transaction (this is 0 for transactions that do not involve Ether).

Constructing a Trade

A trade class is useful in the actual computation by the router class. The Trade constructor takes in three TokenAmount objects and a TradeType enum.

new Trade(input1amount, input2amount, outputamount, tradetype);

The TokenAmount constructor takes in a big number (the amount) and a token.

new TokenAmount(JSBI.BigInt(4000000000000000000), token);

The TradeType enum:

enum TradeType {
  EXACT_INPUT,
  EXACT_OUTPUT
}

The trade type is useful in determining how slippage is spread. EXACT_INPUT means no slippage tolerance is computed on the input amount while EXACT_OUTPUT means no slippage tolerance is applied on the output amount.

The TradeOptions interface:

/**
 * Trade options.
 */
export interface TradeOptions {
  /**
   * Price difference during latency in transaction submission and block confirmation
   */
  slippage: number;
  /**
   * How long the transaction should last before it becomes invalid (in seconds)
   */
  deadline: number;
  /**
   * The account that should receive the swap output
   */
  recipient: string;
}

Router.swapCallParameters returns a SwapParams object.

export interface SwapParams {
  /**
   * The method to send to the 3Swap router
   */
  methodName: string;
  /**
   * Arguments to pass to the method (all hex-encoded)
   */
  args: Array<string | string[]>;
  /**
   * Amount of wei to send in hex
   */
  value: string;
}

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 14

Native requirements
14 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
3swap-v1-core
Environment
{
  "local_name": "3swap-v1-core",
  "alias": false,
  "peer_metadata": null
}
^1.0.13runtime
@ethersproject/abi
Environment
{
  "local_name": "@ethersproject/abi",
  "alias": false,
  "peer_metadata": null
}
^5.5.0runtime
@ethersproject/address
Environment
{
  "local_name": "@ethersproject/address",
  "alias": false,
  "peer_metadata": null
}
^5.5.0runtime
@ethersproject/solidity
Environment
{
  "local_name": "@ethersproject/solidity",
  "alias": false,
  "peer_metadata": null
}
^5.5.0runtime
axios
Environment
{
  "local_name": "axios",
  "alias": false,
  "peer_metadata": null
}
^0.25.0runtime
jsbi
Environment
{
  "local_name": "jsbi",
  "alias": false,
  "peer_metadata": null
}
^4.1.0runtime
tiny-invariant
Environment
{
  "local_name": "tiny-invariant",
  "alias": false,
  "peer_metadata": null
}
^1.2.0runtime
tiny-warning
Environment
{
  "local_name": "tiny-warning",
  "alias": false,
  "peer_metadata": null
}
^1.0.3runtime
@jest/types
Environment
{
  "local_name": "@jest/types",
  "alias": false,
  "peer_metadata": null
}
^27.5.1development
@types/jest
Environment
{
  "local_name": "@types/jest",
  "alias": false,
  "peer_metadata": null
}
^27.4.0development
jest
Environment
{
  "local_name": "jest",
  "alias": false,
  "peer_metadata": null
}
^27.5.1development
ts-jest
Environment
{
  "local_name": "ts-jest",
  "alias": false,
  "peer_metadata": null
}
^27.1.3development
ts-node
Environment
{
  "local_name": "ts-node",
  "alias": false,
  "peer_metadata": null
}
^10.5.0development
typescript
Environment
{
  "local_name": "typescript",
  "alias": false,
  "peer_metadata": null
}
^4.5.5development

Distribution files

1 collected
Distribution 1

Source distribution

Source file
Checksums from source
{
  "integrity": "sha512-/epkaN4S6Rbl0wJ25QOMOa+38Y84x6mDYmWYTWQTGwPeZCZyrh6osO/BWDYmbHfFfaqTSuoHtVhCVBG9/+JeIQ==",
  "shasum": "62a49de0ab859ba6959db2bb76f3c62faac801d5",
  "tarball": "https://registry.npmjs.org/3swap-sdk/-/3swap-sdk-1.0.0.tgz",
  "fileCount": 26,
  "unpackedSize": 50931,
  "npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJiBYTQCRA9TVsSAnZWagAAZ+EP/24IibRPfrxYLMRZA5zz\ndhDP56bAWlAjtPzkUCIiKVjJvPHWRAWM4HVzqM6+rl9J+xb3jc3GFwvED5Uw\nCCeWqYtRBHjgYGBbdDhSUTZ1RaZwk6/VEQ1Jl+3fv/sLoI6mrbdXojWdP1ga\nSJPsZcCeqFoYvWwQVVUFpeVQPPpuK3OIqfuhhdDQwUFhgUcn6qItD7u5wikW\nfcxpdiK/W/AwVFMCJ8ygkrf3tn6meMV9BwLNJmwcBMeV2FenNzgrXwfzNeXq\n/xPAcbyzXzhbu79RSkaPszZopX5x2qBLIWd7QzMyEsRt/XbIb1JMwZ8cDlZD\nu/3PyLXRtcuvib2jbjNSk0AlDkUtsc5v2KtxXibmXGot6uw6Frfjoa2qOThY\nLeU28HIRSkTESoWUYAGa4CTUy8eOEjgLRLXEhQqo/z3B4sQDkBVA8lKQp9kk\nPA40VSmN7jfJQ5nV+fJYcAlRQqVmf26bjbKAM5lVh4EG8beISdZYNcvfV2hB\nmgb7tR2gi8SOOg1zPwmg/EPisI1b+mjea+4gWx1nclgwYemi3Cyop0bCgll7\n8CC0MNWYExHWHqs5/Xt2RTZLInCVE8oKD+klG007D7/96i657xGG2R/OaGWB\n1LaJleNejDkYet9dzmH8KQZubDTnueX4FXAuxINiimnbUWp07b+NtmF2HXTE\nbUzL\r\n=HtVe\r\n-----END PGP SIGNATURE-----\r\n",
  "signatures": [
    {
      "keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
      "sig": "MEUCIEA3yadnW32nF/lyD7P4mFMqbS6bTxjMkiN3myGr8Y8hAiEA2/4wh8JYl3u/UjVAeR87u91588tiBwUHiazIrxC//7M="
    }
  ]
}

Repository

PENDING
3swap/3swap-sdk

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 19:52 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:98f8140f2d536fbe6116e41ea6067b6fea083275038e582c93ad096ca0caa4e3

Other collected versions

1.0.1028 Mar1.0.916 Mar1.0.816 Mar1.0.716 Mar1.0.616 Mar1.0.516 MarView all collected versions →