AutoShark
Search…
πŸ’»
Swap as a Service - Integration
AutoShark Finance allows DeFi applications and end users to integrate with its core protocol. This document helps project owners build a swap on top of AutoShark's core AMM contracts. In doing so, project owners can utilise AutoShark's liquidity to facilitate trades.
Find out how you will be able to earn revenue for your project whenever users perform trades through your swap!
Benefits of using AutoShark router.pdf
538KB
PDF

Quick Overview

This section describes the steps required for you to integrate our contracts, so that fees earned through trades are automatically disbursed to a wallet address that you define.
  1. 1.
    Setup Liquidity Pairs (LP) against our factory contract, under createPair(address tokenA, address tokenB) See: Factory Contract. You can skip this step if you have already created your LPs with us.
  2. 2.
    Use our LP pairs in your project (Strongly recommended). The more liquidity that we can collectively lock, the more trades that can happen at your swaps with lower slippage, and hence higher trading fees!
  3. 3.
    Deploy a customised router contract which is by default configured to disburse 0.13% of trading fees to a wallet that your project can specify. See: Router Contract Repo​
    1. 1.
      You can choose to customise by increasing or lowering swap fees, we will describe how you can do so in the next portion
    2. 2.
      You can optionally choose to deploy trade mining incentives so that you can incentivise more trades to happen against your router - more fees!
  4. 4.
    Install our router SDK into your frontend, and replace whatever SDK you are already using, by default most projects use PancakeSwap's SDK, which is denoted as @pancakeswap/sdk. See: AutoShark SDK​
  5. 5.
    If you face issues integrating, head over to our telegram channel, and look for our devs, and we will be glad to assist you in onboarding.

Deploy Router Contract

The AutoShark team has built a customised router that strictly adheres to the Uniswap router specifications, so that the swapping functionalities are consistent with the industry standard. This customised router allows projects to easily deploy and configure the parameters so that you get to leverage on AutoShark's trading liquidity, while being able to be awarded fees when trades happen against your router. You have the flexibility to choose the amount of fees that you wish to take. The AutoShark platform takes 0.17% as platform fees for LP holders. You are free to choose a range of fees you wish to take with a recommended range of 0.08% to 0.13%. If you choose to take 0.08% fees, the total fees incurred by a trader on your platform would be 0.25% (consistent with the industry standard of PCS). On the flip-side, the AutoShark DEX takes 0.13% (to a total of 0.3%) because we provide trade mining features. You can consider building a trade mining feature as well, which we will provide documentation for below!
In order to deploy the router contract, you can choose to use either truffle or hardhat. We generally prefer using hardhat. To get started, clone our repository:
1
git clone https://github.com/autoshark-finance/fins-periphery.git
Copied!
Install necessary packages:
1
cd fins-periphery
2
yarn
Copied!
Configure the fees you wish to take. Only contracts/FinsRouter02.sol needs to be modified (optional):
1
// IMPORTANT: Change Line 479, 502, 568
2
// 13 represents fees of 0.13% that goes to you. Change to a percentage you want.
3
// You can change 13 to 7, to charge a fee of 0.07% (total trading fee to user is 0.25%)
4
// See example below:
5
​
6
function getAmountsIn(uint amountOut, address[] memory path)
7
public
8
view
9
virtual
10
override
11
returns (uint[] memory amounts)
12
{
13
amounts = FinsLibrary.getAmountsIn(factory, amountOut, path);
14
uint routerSwapFeeBps = (path.length - 1) * 13; // change this 13 to 7 if you wish
15
..........
16
}
17
​
Copied!
Once configured, you will be able to deploy. First, configure your hardhat by running npx hardhat. Alternatively, you can copy the following hardhat template configured for typescript usage:
1
import "@nomiclabs/hardhat-waffle";
2
import "@nomiclabs/hardhat-ethers";
3
import "@nomiclabs/hardhat-etherscan";
4
import "@typechain/ethers-v5";
5
import "@typechain/hardhat";
6
import "@openzeppelin/hardhat-upgrades";
7
​
8
import { HardhatUserConfig } from "hardhat/types";
9
import { keys, bscScanKey } from "./secrets.json";
10
​
11
// You need to export an object to set up your config
12
// Go to https://hardhat.org/config/ to learn more
13
​
14
/**
15
* @type import('hardhat/config').HardhatUserConfig
16
*/
17
const config: HardhatUserConfig = {
18
defaultNetwork: "localhost",
19
etherscan: {
20
// Your API key for Etherscan
21
// Obtain one at https://etherscan.io/
22
apiKey: bscScanKey,
23
},
24
networks: {
25
localhost: {
26
url: "http://127.0.0.1:8545",
27
timeout: 180000
28
},
29
mainnet: {
30
url: "https://bsc-dataseed.binance.org/",
31
chainId: 56,
32
gasPrice: 10000000000,
33
accounts: keys,
34
},
35
},
36
solidity: {
37
version: "0.6.6",
38
settings: {
39
optimizer: {
40
enabled: true,
41
runs: 200,
42
},
43
},
44
},
45
paths: {
46
sources: "./contracts",
47
tests: "./test",
48
cache: "./cache",
49
artifacts: "./artifacts",
50
},
51
mocha: {
52
timeout: 20000,
53
},
54
typechain: {
55
target: "ethers-v5",
56
},
57
};
58
​
59
module.exports = config;
60
​
Copied!
Once done, you will be able to deploy, simply run the following commands
1
yarn hardhat run migrations/1-deploy.ts --network mainnet
Copied!
Remember to change your treasury address by running setTreasury(address _treasury):
1
// Sample hardhat code to change treasury address
2
await router.setTreasury("0x0000000000000000000000000000000000000000")
Copied!
And with that, your router is fully configured, and you will be able to use it in your frontend. Do remember to swap out the current SDK you are using, and use the one provided by our team, otherwise the trades will still route through the standard factories that you have configured. See: https://www.npmjs.com/package/@autoshark-finance/sdk​

Installing AutoShark SDK

We have published our SDK to npmjs, you can simply install it via running npm i @autoshark-finance/sdk. If you already have a swap interface setup, you simply need to search and replace all instances of your existing SDK. If you do not have a swap interface already setup, you can consider forking the PancakeSwap V1 swap interface, and host it on Netlify. The setup time should range from between 15mins - 30mins. See: Pancake Swap Interface V1​
You will only need to change 2 main things, the ROUTER_ADDRESS and all instances of @pancakeswap-libs/sdk to use @autoshark-finance/sdk.
1
// Under src/constants/index.ts
2
// Line 3
3
​
4
import { ChainId, JSBI, Percent, Token, WETH } from '@pancakeswap-libs/sdk'
5
​
6
export const ROUTER_ADDRESS = '0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F' // Change this to use your own router address
7
​
8
// a list of tokens by chain
9
type ChainTokenList = {
10
readonly [chainId in ChainId]: Token[]
11
}
Copied!
Once done, you can simply deploy via Netlify.

Facing Issues Integrating?

Please reach out to our team on Telegram at https://t.me/AutoSharkFinance​
Last modified 6d ago