Observed since 20 Oct, 19:52 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
3swap-sdk
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:
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:
| Name | Type |
|---|---|
| _address | string |
| _chainId | ChainId or number |
| _decimals | number or string |
| _name | string |
| _symbol | string |
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:
| Name | Type |
|---|---|
| liquidityToken | Token |
| 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;
}
Download counts and popularity will appear here as the collector receives them.
| Package / target | Requirement | Relationship |
|---|---|---|
3swap-v1-coreEnvironment{
"local_name": "3swap-v1-core",
"alias": false,
"peer_metadata": null
} | ^1.0.13 | runtime |
@ethersproject/abiEnvironment{
"local_name": "@ethersproject/abi",
"alias": false,
"peer_metadata": null
} | ^5.5.0 | runtime |
@ethersproject/addressEnvironment{
"local_name": "@ethersproject/address",
"alias": false,
"peer_metadata": null
} | ^5.5.0 | runtime |
@ethersproject/solidityEnvironment{
"local_name": "@ethersproject/solidity",
"alias": false,
"peer_metadata": null
} | ^5.5.0 | runtime |
axiosEnvironment{
"local_name": "axios",
"alias": false,
"peer_metadata": null
} | ^0.25.0 | runtime |
bignumber.jsEnvironment{
"local_name": "bignumber.js",
"alias": false,
"peer_metadata": null
} | ^9.0.2 | runtime |
jsbiEnvironment{
"local_name": "jsbi",
"alias": false,
"peer_metadata": null
} | ^4.1.0 | runtime |
tiny-invariantEnvironment{
"local_name": "tiny-invariant",
"alias": false,
"peer_metadata": null
} | ^1.2.0 | runtime |
tiny-warningEnvironment{
"local_name": "tiny-warning",
"alias": false,
"peer_metadata": null
} | ^1.0.3 | runtime |
@jest/typesEnvironment{
"local_name": "@jest/types",
"alias": false,
"peer_metadata": null
} | ^27.5.1 | development |
@types/jestEnvironment{
"local_name": "@types/jest",
"alias": false,
"peer_metadata": null
} | ^27.4.0 | development |
jestEnvironment{
"local_name": "jest",
"alias": false,
"peer_metadata": null
} | ^27.5.1 | development |
ts-jestEnvironment{
"local_name": "ts-jest",
"alias": false,
"peer_metadata": null
} | ^27.1.3 | development |
ts-nodeEnvironment{
"local_name": "ts-node",
"alias": false,
"peer_metadata": null
} | ^10.5.0 | development |
typescriptEnvironment{
"local_name": "typescript",
"alias": false,
"peer_metadata": null
} | ^4.5.5 | development |
Source distribution
{
"integrity": "sha512-CaiEYuPX9ABjBdn+gr8gI3N1cmXxIoV0AYiP8UDWSLaLvLlB8sOanCwVUpMHrrVfVq6LgT1PKg8AoE4kTXfSVQ==",
"shasum": "6a4976cd9913987057cf987a38342207ea7f2ec4",
"tarball": "https://registry.npmjs.org/3swap-sdk/-/3swap-sdk-1.0.8.tgz",
"fileCount": 26,
"unpackedSize": 51901,
"npm-signature": "-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJiMm8JACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmpWWw//bom7ffnf3EjfwV42xQthkbYBSDvhPvUfBFUdvv1AyHcwC4dy\r\nybPqcZlKAk18McX9vsL1lO3xBi1WwElLbNtwnckjBGXDTIKOs/EtL0RGJC1h\r\nYMRDn6+lc8tV5bq2be94Ky++AuhW+kleOU5+Ycbtb3Ug3NKuFDDdSavePwCC\r\nnUOsklk9drWqx68FAAOwoRn2SJAEYRogmF0c5+4JGLT4Y5qqf8Qw3J4DeKa4\r\nWZbN/DyJB+cVRSWCqTbbAycie9vlwiYFUUwIRwLDDFBelzj3DBAdPIjbP2N6\r\nmnMf0XDr6qEdlQFHqbZPnp1FnBvEO/mvwRJ8OWEBXOcrcT8zTqvKzs+Mauun\r\n5NxAGmUcCcUaPXfYSwMPreRV5vfV+w9wyys5920TuGBPKv+HAYJxFNIcLSh/\r\nhboy+NfcVWc2jjg8A/kCPjBcOky7Wa9StopbU9D/YBhOiC9WBaPeVu1dPjyI\r\n1gVcATeKAR8dJ+jFPk6tGBwmgFB6CbFz3DH64l5pNIh5F06T7s+NqtWsE7YK\r\nl71Pa7EMy6VWxPhF37nZZ4KFkWhTtULqfqDvklNQGMyZHD8LsSx1ZAdJSPeb\r\ncjuK/ClR6JosiWPvhzZ4KaCmU43IFRorMC1hd2jeiyiRBUD8Iq2eoOxErge+\r\n9PzHZCe/hyYYo+xpGofhLH3Z9YJs5cbn+14=\r\n=WWCT\r\n-----END PGP SIGNATURE-----\r\n",
"signatures": [
{
"keyid": "SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA",
"sig": "MEQCIHnttcq+cF2UchKxKq4QvF5w3YDLWmgoLYSpmKHRTBEcAiB+aY/F/oIDK/2tjZv4Xq0OtckybpjOca5U/bi+BcS/vA=="
}
]
}Observed since 20 Oct, 19:52 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package_version:b0170ec053de695d3d148fb090874ac493113bbef2945b8a59d486973fbe341c