Slippage is an important concept in trading that can have a significant impact on your trading outcomes. It refers to the difference between the expected price of a trade and the actual price at which the trade is executed. Slippage can occur in various market conditions and for several reasons, and it's crucial for traders to be aware of its potential effects.
Fibrous Finance uses slippage settings to prevent you from losing money; there is no need to increase your slippage when you spot an arbitrage opportunity.
Fibrous Finance is still in alpha version. Please make sure you have adjusted your slippage properly.
Generate transaction data for calling the Fibrous Finance Router contract
// Usage on your websiteconststarknet=awaitconnect({ showList:false })awaitstarknet.enable()if (starknet.isConnected) {// Call the buildTransaction method in order to build the transaction// slippage: The maximum acceptable slippage of the buyAmount amount.constslippage=1; // 1%const destination = starknet.selectedAddress; // The address to receive the tokens after the swap is completed (required)
consttokenInAddresses= [tokenInAddress_1, tokenInAddress_2, tokenInAddress_3];consttokenOutAddresses= [tokenOutAddress];constswapCalls=awaitfibrous.buildBatchTransaction( inputAmounts, tokenInAddresses, tokenOutAddresses, slippage, destination,"starknet",);constapproveCalls:Call[] = [];for(let i =0; i <inputAmounts.length; i++) {constapproveCall:Call=awaitfibrous.buildApproveStarknet( inputAmounts[i], tokenInAddresses[i], );approveCalls.push(approveCall); }awaitstarknet.account.execute([...approveCall,...swapCall]);}import { Call } from"starknet";conststarknet=awaitconnect({ showList:false })awaitstarknet.enable()if (starknet.isConnected) {// Call the buildTransaction method in order to build the transaction// slippage: The maximum acceptable slippage of the buyAmount amount. constslippage=1; // %1 slippageconstreceiverAddress=starknet.selectedAddress;constapproveCall:Call=awaitfibrous.buildApproveStarknet( inputAmount, tokenInAddress, );constswapCall:Call=awaitfibrous.buildTransaction( inputAmount, tokenInAddress, tokenOutAddress, slippage, receiverAddress,"starknet", );awaitstarknet.account.execute([approveCall,swapCall]);}
Usage on backend on Starknet
import { Account, Provider } from"starknet";import { Call } from"starknet";constprovider=newProvider();constprivateKey0="YOUR_PRIVATE_KEY";constaccountAddress0="YOUR_WALLET_ADDRESS";// https://www.starknetjs.com/docs/guides/connect_account// If this account is based on a Cairo v2 contract (for example OpenZeppelin account 0.7.0 or later), do not forget to add the parameter "1" after the privateKey parameter
constRPC_URL="RPC_URL";constaccount0=account(privateKey, public_key,"1",RPC_URL);// Call the buildTransaction method in order to build the transaction// slippage: The maximum acceptable slippage of the buyAmount amount.constslippage=1; // %1constswapCalls=awaitfibrous.buildBatchTransaction( inputAmounts, tokenInAddresses, tokenOutAddresses, slippage, destination,"starknet",);constapproveCalls:Call[] = [];for(let i =0; i <inputAmounts.length; i++) {constapproveCall:Call=awaitfibrous.buildApproveStarknet( inputAmounts[i], tokenInAddresses[i], );approveCalls.push(approveCall);}constresp=awaitaccount0.execute([...approveCalls,...swapCalls]);console.log(`https://voyager.online/tx/${resp.transaction_hash}`);