Twap swap using Jupiter aggregator
Built using:
First you need to copy the .env.example to .env and set the RPC_URL and WALLET_PK respectively.
WALLET_PKis a Base58 private key and it can be exported fromPhantom Wallet
yarn buildand then
yarn startThe required arguments are From, To, Amount and Interval.
- From and To: are the direction of the trading pair we want to swap.
- Amount: is the
From tokenamount we want to swap for theTo token. - Interval: is the duration (like 10s, 10m, 10h) interval to execute a swap.
Example:
yarn start twap --from USDC --to PRT --amount 100 --interval 10mIt will buy 100 USDC worth of PRT every 10 minutes
Optional you can specify a TransferAddress and TransferThreshold with the arguments --transferAddress and --transferThreshold respectively.
When the balance of the buying asset reach the TransferThreshold, all it's balance will be transfer to the TransferAddress associated token account.
Example:
yarn start twap --from USDC --to PRT --amount 100 --interval 10m --transferThreshold 100000 --transferAddress FRnCC8dBCcRabRv8xNbR5WHiGPGxdphjiRhE2qJZvwpmIt will buy 100 USDC worth of PRT every 10 minutes and it will transfer all the PRT balance to the Parrot Protocol address once greater than 100,000 PRT
Optional you can specify a swap PriceThreshold with the argument --priceThreshold.
When CoinGecko price for the To token goes below the PriceThreshold, the swap will be execute otherwise it will skip and wait for the next interval.
Example:
yarn start twap --from USDC --to PRT --amount 100 --interval 10m --priceThreshold 0.015It will buy 100 USDC worth of PRT every 10 minutes only if PRT price on CoinGecko goes below 0.015.