0x-starter-project
0x-starter-project copied to clipboard
'JSON RPC response has no result' when using fillLimitOrder
Hello, It is my first time testing the 0x API for limit orders.
Im creating some hardhat tasks to create and fill Limit Orders. Ive followed the tutorial fill_order_example but Im receiving this error `JSON RPC response has no result' I don't know why.
The exact message error is:
Error: JSON RPC response has no result
at Web3Wrapper.<anonymous> (<folder>/node_modules/@0x/web3-wrapper/src/web3_wrapper.ts:789:19)
at Generator.next (<anonymous>)
at fulfilled (<folder>/node_modules/@0x/web3-wrapper/lib/src/web3_wrapper.js:5:58)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
Below is the code of my task:
const utils = require('@0x/protocol-utils')
const { ContractWrappers, ERC20TokenContract } = require('@0x/contract-wrappers')
const BigNumber = require('bignumber.js')
const contractAddresses = require('@0x/contract-addresses')
task('fillLimitOrder', 'Fill Limit Order')
.addOptionalParam('gasmultiplier', 'gasmultiplier')
.setAction(async ({ gasmultiplier = 2 }, hre) => {
console.log('fillLimitOrder')
// 1) Get Exchange Address for Polygon
// 2) Approve Maker Token (CCB Token)
// 3) Approve Taker Token (USDC)
// 4) Fetch ordertxHash
// 5) Use the number 4) to fill the order
const CHAIN_ID = 137
const marketTokenAddress = '0x41d2f09f4899f16ed0ed86f8487018cc8c91f547'
const takerTokenAddress = '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174'
const marketTokenContract = await hre.ethers.getContractAt('ERC20', marketTokenAddress)
const takerTokenContract = await hre.ethers.getContractAt('ERC20', takerTokenAddress)
const MAX_UINT = hre.ethers.MaxUint256
const contractWrappers = new ContractWrappers(hre.ethers.provider, { chainId: CHAIN_ID })
const [makerSigner, takerSigner] = await hre.ethers.getSigners()
const takerAddress = await takerSigner.getAddress()
console.log('takerAddress', takerAddress)
const addresses = contractAddresses.getContractAddressesForChainOrThrow(
CHAIN_ID
)
const exchangeAddress = addresses.exchangeProxy
console.log('approving maker token')
await marketTokenContract.approve(exchangeAddress, MAX_UINT)
console.log('approving taker token')
await takerTokenContract.connect(takerSigner).approve(exchangeAddress, MAX_UINT)
const order = {
sender: '0x0000000000000000000000000000000000000000',
maker: '0x7e28184ebf20437051034232e7b9cbaa43d901d6',
taker: '0x0000000000000000000000000000000000000000',
takerTokenFeeAmount: '0',
makerAmount: '1000000000000000000',
takerAmount: '1000000',
makerToken: '0x41d2f09f4899f16ed0ed86f8487018cc8c91f547',
takerToken: '0x2791bca1f2de4661ed88a30c99a7a9449aa84174',
salt: '1698147146829',
verifyingContract: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
feeRecipient: '0x0000000000000000000000000000000000000000',
expiry: '1698150146',
chainId: 137,
pool: '0x0000000000000000000000000000000000000000000000000000000000000000'
}
const orderSignature = {
signatureType: 2,
r: '0xe83f724835b9f932da5e08a749aab5ecf866b4febad9e0a4a0e43b67034f4c42',
s: '0x767590a016cab96469d5513a91e1223fa0564c067242e17218562ea8f530c644',
v: 28
}
const takerAssetAmount = new BigNumber('100000')
// get the protocol fee multiplier
// protocol fee = multiplier * gasPrice * numOrders
const protocolFeeMultiplier = new BigNumber(
await contractWrappers.exchangeProxy.getProtocolFeeMultiplier().callAsync()
)
const feeData = hre.provider.getFeeData()
console.log('feeData', feeData)
const calculateProtocolFee = (
numOrders,
multiplier
) => {
return multiplier.times(feeData.gasPrice).times(numOrders)
}
// Fill the Order via 0x Exchange Proxy contract
try {
const txHash = await contractWrappers.exchangeProxy
.fillLimitOrder(order, orderSignature, takerAssetAmount)
.sendTransactionAsync({
from: taker,
value: calculateProtocolFee(1, protocolFeeMultiplier),
gasPrice: feeData.gasPrice * 2n
})
console.log(txHash)
} catch (err) {
console.log(err)
}
})