Back to all Bounties
Earn 2,250 ($22.50)
due 2 years ago
Canceled
Write me a 1Inch limit order function in JS! Updated with almost-working code!
AskProgrammers
Details
Applications
8
Discussion
Bounty Description
Problem Description
Write me a 1inch limit order function
The network should be arbitrum
https://docs.1inch.io/docs/limit-order-protocol/utils/guide/quick-start
Update: no working answers have been provided.
Latest pastebin code gets to the final line then:
server error 500
-> https://pastebin.com/dFVi9ksK
The function signature:
let limOrder = async (orderType='buy', outputTokenSymbol='uni', limitAmount='0.11', limitPriceUsd='5.12', inputTokenSymbol='usdc', chainId=42161, fromAddress=CRYPTO_ADDR_HERE) => {
The function should return the transaction hash of the broadcasted limit order + the limit order object (so that it can be cancelled if needed)
it should user ethers as the web3 library
Acceptance Criteria
The 1st implementation I see that runs (when I put in the required variables like private key, account and RPC URL) I'll accept immediately . I'll can pay for more crypto functions like this & hire you if you're good & motivated!
import ethers from 'ethers'import LimitOrderProtocol from '@1inch/limit-order-protocol-utils'const ChainId = 42161;import dotenv from 'dotenv';dotenv.config();import { LimitOrderBuilder } from '@1inch/limit-order-protocol-utils'let privateKey = process.env.ACCOUNT_PKEY;let limOrder = async (orderType='buy', outputTokenSymbol='uni', limitAmount='0.11', limitPriceUsd='5.12', inputTokenSymbol='usdc', ChainId= 42161, fromAddress=process.env.ACCOUNT_ADDR) => {//enter your rpc urlconst provider = new ethers.providers.JsonRpcProvider(process.env.JSON_RPC_URL);//enter your private keyconst wallet = new ethers.Wallet(privateKey, provider);const limitOrderProtocol = new LimitOrderBuilder(ChainId, wallet);// const inputTokenAddress = '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c' // await limitOrderProtocol.getTokenAddress(inputTokenSymbol);const outputTokenAddress = "0xFa7F8980b0f1E64A2062791cc3b0871572f1F7f0" // uniconst inputTokenAddress = '0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8' //usdclet inputAmount = ethers.utils.parseUnits("0.1", 6) //0.11 usdc forlimitAmount = ethers.utils.parseUnits(limitAmount, 18) //.11 uni// const inputAmount = await limitOrderProtocol.getLimitOrderInputAmount(inputTokenAddress, outputTokenAddress, orderType, limitAmount, limitPriceUsd);const order = limitOrderProtocol.buildLimitOrder({makerAssetAddress: orderType === 'buy' ? inputTokenAddress : outputTokenAddress,takerAssetAddress: orderType === 'buy' ? outputTokenAddress : inputTokenAddress,makerAddress: fromAddress,//as of now anyone can fill the limit orderallowedSender: '0x0000000000000000000000000000000000000000',makingAmount: orderType === 'buy' ? inputAmount : limitAmount,takingAmount: orderType === 'buy' ? limitAmount : inputAmount,predicate: '0x',permit: '0x',interaction: '0x',});const tx = await limitOrderProtocol.buildAndSendTransaction(order);return { txHash: tx.hash, order };}// Usage examplelimOrder('buy', 'uni', '0.11', '5.12', 'usdc', 42161, process.env.ACCOUNT_ADDR).then(result => {console.log(result);}).catch(error => {console.error(error);});