@wardenswap/bestrate-sdk-beta 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "@wardenswap/bestrate-sdk-beta",
3
+ "version": "2.3.0",
4
+ "main": "dist/index.js",
5
+ "module": "dist/index.es.js",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "keywords": [
10
+ "wardenswap",
11
+ "defi",
12
+ "bestrate"
13
+ ],
14
+ "types": "dist/index.d.ts",
15
+ "author": "Wardenswap",
16
+ "scripts": {
17
+ "watch": "rimraf dist && rollup -cw --bundleConfigAsCjs",
18
+ "build-dev": "rimraf dist && rollup -c --bundleConfigAsCjs",
19
+ "build": "rimraf dist && rollup -c --environment LOGGING,MINIFY --bundleConfigAsCjs",
20
+ "postbuild": "yarn run delDtsFiles",
21
+ "build-public": "rimraf dist && rollup -c --environment MINIFY --bundleConfigAsCjs",
22
+ "postbuild-public": "yarn run delDtsFiles",
23
+ "delDtsFiles": "rimraf dist/dts",
24
+ "coverage": "ts-node -O '{\"module\": \"commonjs\"}' src/coverage/index.ts",
25
+ "example": "ts-node -O '{\"module\": \"commonjs\"}' src/example.ts",
26
+ "test": "jest",
27
+ "typechain": "typechain --target=ethers-v5 src/abi/*.json && typechain --target=ethers-v5 --out-dir types/ethers-contracts/dexes src/abi/dexes/*.json",
28
+ "doc": "typedoc --plugin typedoc-plugin-markdown --disableSources --hideInPageTOC --hideBreadcrumbs --excludePrivate --excludeProtected --out docs src/index.ts"
29
+ },
30
+ "dependencies": {
31
+ "ethers": "^5.7.2"
32
+ },
33
+ "devDependencies": {
34
+ "@rollup/plugin-strip": "^3.0.4",
35
+ "@rollup/plugin-terser": "^0.4.4",
36
+ "@rollup/plugin-typescript": "^11.1.6",
37
+ "@typechain/ethers-v5": "^11.1.2",
38
+ "@types/jest": "^29.5.12",
39
+ "@types/node": "^20.12.5",
40
+ "csv-writer": "^1.6.0",
41
+ "decimal.js": "^10.4.3",
42
+ "dotenv": "^16.4.5",
43
+ "jest": "^29.7.0",
44
+ "jest-mock-extended": "^3.0.5",
45
+ "rimraf": "^5.0.5",
46
+ "rollup": "^4.14.0",
47
+ "rollup-plugin-dts": "^6.1.0",
48
+ "ts-jest": "^29.1.2",
49
+ "ts-node": "^10.9.2",
50
+ "tslib": "^2.6.2",
51
+ "typechain": "^8.3.2",
52
+ "typedoc": "^0.25.12",
53
+ "typedoc-plugin-markdown": "^3.17.1",
54
+ "typescript": "^5.4.4"
55
+ },
56
+ "jest": {
57
+ "setupFiles": [
58
+ "<rootDir>/.jest/setEnvVars.js"
59
+ ],
60
+ "transform": {
61
+ ".(ts|tsx)": "ts-jest"
62
+ },
63
+ "testTimeout": 60000,
64
+ "testEnvironment": "node",
65
+ "testRegex": "(/tests/.*|\\.(test|spec))\\.(ts|tsx|js)$",
66
+ "moduleFileExtensions": [
67
+ "ts",
68
+ "tsx",
69
+ "js",
70
+ "jsx",
71
+ "json",
72
+ "node"
73
+ ]
74
+ },
75
+ "description": "- Update src/config.ts to add more tables",
76
+ "directories": {
77
+ "test": "tests"
78
+ },
79
+ "repository": {
80
+ "type": "git",
81
+ "url": "git+https://github.com/Wardenswap/warden-bestrate-api.git"
82
+ },
83
+ "license": "UNLICENSED",
84
+ "bugs": {
85
+ "url": "https://github.com/Wardenswap/warden-bestrate-api/issues"
86
+ },
87
+ "homepage": "https://docs.wardenswap.finance/warden/wardenswap-sdk/overview",
88
+ "packageManager": "yarn@1.22.19+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
89
+ }
package/readme.md ADDED
@@ -0,0 +1,79 @@
1
+ # WardenSwap Best Rate Query SDK
2
+
3
+ An JavaScript/TypeScript SDK library for querying trading quotes from WardenSwap platform. In order to begin trading on WardenSwap, we need the trading path that provide the best rate. The SDK help finding the path with ease!
4
+
5
+ For more information, check out our documentation here: <https://docs.wardenswap.finance/warden/wardenswap-sdk/overview>
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ # For NPM
11
+ npm install @wardenswap/bestrate-sdk-private
12
+
13
+ # For Yarn
14
+ yarn add @wardenswap/bestrate-sdk-private
15
+ ```
16
+
17
+ ## Example
18
+
19
+ Here is the example if JavaScript code for querying best rate and perform a simple swap via WardenSwap SDK.
20
+
21
+ ```js
22
+ // npm install @wardenswap/bestrate-sdk-private ethers
23
+ const { WardenBestRate } = require('@wardenswap/bestrate-sdk-private')
24
+ const { ethers } = require('ethers')
25
+
26
+ // WardenRouter_2_0.abi.json can be found here: https://gist.github.com/AncientWarden/4aeae54509dd21020ab29a13c804cb57
27
+ // or BSCScan: https://bscscan.com/address/0x451ef8D6B645a60115EB8b8bEa76B39C0C761004#code
28
+ const wardenRouterAbi = require('./WardenRouter_2_0.abi.json')
29
+
30
+ const WARDEN_ROUTER_ADDRESS = '0x451ef8D6B645a60115EB8b8bEa76B39C0C761004'
31
+
32
+ const src = '0xe9e7cea3dedca5984780bafc599bd69add087d56' // source Token Address: BUSD
33
+ const dest = '0x0feadcc3824e7f3c12f40e324a60c23ca51627fc' // destination Token Address: WAD
34
+ const amountIn = ethers.utils.parseUnits('10', 18) // 10 BUSD in BigNumber
35
+ const gasFee = ethers.BigNumber.from('5000000000') // default BSC gas fee for rate calculation
36
+ const options = { enableSplit: false } // calculate without using split trades
37
+
38
+ // initialize provider, requires version of ether.js >= 5.4.0
39
+ const provider = new ethers.providers.JsonRpcProvider('https://bsc-dataseed.binance.org')
40
+
41
+ async function getQuote() {
42
+ // initialize the warden client
43
+ const wardenClient = new WardenBestRate(provider, 'bsc')
44
+
45
+ // get the quote detail with warden client
46
+ const quote = await wardenClient.getQuote(src, dest, amountIn, gasFee, options)
47
+ console.log('quote:', quote)
48
+
49
+ return quote
50
+ }
51
+
52
+ async function swap(quote) {
53
+ // add the acceptable slippage of 1% to amountOut
54
+ // since the actual amount can be lower or higher.
55
+ const minAmountOut = ethers.BigNumber.from(quote.amountOut).mul(99).div(100)
56
+
57
+ // Get the signer with private key
58
+ // For using with Metamask, see: https://docs.ethers.io/v5/getting-started/#getting-started--connecting
59
+ const signer = new ethers.Wallet(YOUR_PRIVATE_KEY, provider)
60
+ const wardenContract = new ethers.Contract(WARDEN_ROUTER_ADDRESS, wardenRouterAbi, signer)
61
+
62
+ // send a swap transaction to warden contract
63
+ const swapTx = await wardenContract.swap(
64
+ quote.swapAddress,
65
+ quote.data,
66
+ quote.depositAddress,
67
+ src,
68
+ amountIn,
69
+ dest,
70
+ minAmountOut,
71
+ signer.address, // dest token receiver
72
+ 0, // Partner ID for profit sharing, default to 0
73
+ 0) // metadata, reserved for future use
74
+
75
+ console.log(`swap tx successfully submitted, tx hash: ${swapTx.hash}`)
76
+ }
77
+
78
+ getQuote().then(quote => swap(quote))
79
+ ```