⚒️Developer Guide
The Gator SDK provides easy programmatic access to decentralized exchanges on NEAR.
1. Compute Swap Routes
A typical usage is to find the best swap route. This is what you can access on the gator.fi web page:
import { Gator } from '@gator/sdk';
const gator = new Gator();
const routes gator.computeRoutes({
input: 'wrap.near',
output: 'aurora.near',
amount: '3'
});
const txs = gator.generateTransactions(routes[0]);
// Transactions are ready to be signed and sent to blockchain
await wallet.signAndSendTransactions({ transactions: txs });
2. Find Best Bid/Offer - simple arbitrage bot
The Gator SDK also allows you to find the best bid/offer across decentralized exchanges on NEAR. The functions computeBestBid
and computeBestOffer
does the necessarily conversion so the numbers fit into a traditional base/quote pair paradigm. For example, we can use the Gator SDK to implement a simple arbitrage strategy:
while (true) {
const base = 'aurora.near';
const quote = 'wrap.near';
// Aggregate bid / ask levels within 10 bips
const bestBid = gator.computeBestBid({ base, quote }, 0.001);
const bestOffer = gator.computeBestOffer({ base, quote }, 0.001);
if (bestBid['price'] < bestOffer['price']) {
const amount = Math.min(bestBid['amount'], bestOffer['amount'])
await wallet.signAndSendTransactions({
transactions: [
...gator.generateTransactions({ ...bestBid, amount }),
...gator.generateTransactions({ ...bestOffer, amount }),
]
})
}
await new Promise((r) => setTimeout(r, 5000));
}
Last updated