To start using the limit order and stop loss interface we have created an AutonomyProvider. You can easily wrap your app with the provider and pass the autonomy reducers into your redux store.
You can then go to your main file and wrap your app with the AutonomyProvider.
import React from "react";
import ReactDOM from "react-dom";
import { AutonomyProvider } from "@autonomylabs/limit-orders-react";
import { useActiveWeb3React } from "hooks/web3";
import { injected } from "connectors";
function Autonomy({ children }: { children?: React.ReactNode }) {
const { library, chainId, account, activate } = useActiveWeb3React();
return (
<AutonomyProvider
library={library}
chainId={chainId}
account={account ?? undefined}
// Optionally pass the handler to be able to connect to a wallet via the component button
onConnectWallet={() => activate(injected)}
// By default `useDefaultTheme` is set to true, will use Autonomy SDK default theme if set
useDefaultTheme={true}
// By default `useDarkMode` is set to true
usDarkMode={true}
// Optionally pass any DEX router information to be used in the sdk. By default ApeSwap router will be used on BSC, and TraderJoe will be used on Avalanche.
routerInfo={{
routerAddress: "",
factoryAddress: "",
initCodeHash: "",
}}
>
{children}
</AutonomyProvider>
);
}
ReactDOM.render(
<StrictMode>
<FixedGlobalStyle />
<Web3ReactProvider getLibrary={getLibrary}>
<Web3ProviderNetwork getLibrary={getLibrary}>
<Provider store={store}>
<ThemeProvider>
<ThemedGlobalStyle />
<HashRouter>
<Autonomy>
<App />
</Autonomy>
</HashRouter>
</ThemeProvider>
</Provider>
</Web3ProviderNetwork>
</Web3ReactProvider>
</StrictMode>,
document.getElementById("root")
);
Add the Limits Orders and Stops Losses:
You can easily then pass the order type (Limit or StopLoss) to our order components, AutonomyOrderPanel and AutonomyOrderHistoryPanel.
import { AutonomyLimitStopOrders } from "@autonomylabs/limit-stop-orders";
const autonomyLimitStopOrders = new AutonomyLimitStopOrders(
chainId, // BSC = 56, Avalanche = 43114
signerOrProvider, // Web3 Signer or Provider
routerAddress, // DEX router address, Apeswap by default on BSC / TraderJoe by default on Avalanche
factoryAddress, // DEX factory adderss, Apeswap by default on BSC / TraderJoe by default on Avalanche
initCodeHash // DEX init code hash, Apeswap by default on BSC / TraderJoe by default on Avalanche
);
Approve Tokens:
To create limit orders and stop losses you must first approve the tokens on the Autonomy router.