Insufficient funds after approve in ERC20 proxy
Expected Behavior
after i approve ERC20 Proxy to use my FAU coin, i should be able to submit a limit order to sell FAU and buy DAI
This is the code i use to approved
const w3provider = await detectEthereumProvider() as Web3JsProvider
const providerEngine = new MetamaskSubprovider(w3provider)
const contractWrappers = new ContractWrappers(providerEngine,{chainId:chainId})
const FAUCcontract = new ERC20TokenContract(quoteAsset.currentChainData.address, providerEngine, {from:account})
console.log("FAUCcontract", FAUCcontract)
// FAUCcontract.
const tx = await FAUCcontract
.approve(contractWrappers.contractAddresses.erc20Proxy, new BigNumber(amount))
.sendTransactionAsync({from:account})
This is the tx record https://etherscan.io/tx/0xa4975622f724f2c50d24e7528688134f3fa4fad54eda0f0d0d6ea1197f770083
This is my order Data
const utils = require('@0x/protocol-utils');
let orderData = {
takerTokenFeeAmount: new BigNumber(0),
sender:NULL_ADDRESS,
feeRecipient: NULL_ADDRESS,
makerToken: quoteAsset.currentChainData.address,
takerToken: baseAsset.currentChainData.address,
makerAmount: new BigNumber(buyMakeAmount),
takerAmount: new BigNumber(buyTakeAmount),
maker: walletAccount,
taker: NULL_ADDRESS,
pool:NULL_ADDRESS,
expiry: new BigNumber(Date.now() + 3600000),
verifyingContract: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
salt: salt,
chainId: chainId,
}
const order = new utils.LimitOrder(orderData)
makerToken: "0xfab46e002bbf0b4509813474841e0716e6730136",
takerToken: "0xc4777287ddceb283ed6db59c88db5074f1b25e4e",
makerAmount: BigNumber, takerAmount: BigNumber, maker: "0xd13e5853c037a67bb17640ff69ac770f3ea6b0e2",
chainId: 1
expiry: BigNumber {s: 1, e: 12, c: Array(1)}
feeRecipient: "0x0000000000000000000000000000000000000000"
maker: "0xd13e5853c037a67bb17640ff69ac770f3ea6b0e2"
makerAmount: BigNumber {s: 1, e: 3, c: Array(1)}
makerToken: "0xfab46e002bbf0b4509813474841e0716e6730136"
pool: "0x0000000000000000000000000000000000000000"
salt: BigNumber {s: 1, e: 75, c: Array(6)}
sender: "0x0000000000000000000000000000000000000000"
taker: "0x0000000000000000000000000000000000000000"
takerAmount: BigNumber {s: 1, e: 3, c: Array(1)}
takerToken: "0xc4777287ddceb283ed6db59c88db5074f1b25e4e"
takerTokenFeeAmount: BigNumber {s: 1, e: 0, c: Array(1)}
verifyingContract: "0xdef1c0ded9bec7f1a1670819833240f027b25eff"
Then sign with this
const signature = await order.getSignatureWithProviderAsync(
providerEngine,
utils.SignatureType.EIP712
);
This is the error from /sra/v4/order
{"code":100,"reason":"Validation Failed","validationErrors":[{"field":"signedOrder[0]","code":1007,"reason":"ORDER_UNFUNDED: maker has insufficient balance or allowance for this order to be filled"}]}
Current Behavior
/sra/v4/order can not use the funds i approved in ERC20 proxy
Steps to Reproduce (for bugs)
1.
2.
3.
Context
I can't submit order. As i know the exchange address in contractWrapper is also wrong, maybe its another document or lib error ?
Your Environment
ok, problem solved. I dig deep into 0x Discord and find the answer.
The ERC20 proxy endpt for V4 api is: 0xdef1c0ded9bec7f1a1670819833240f027b25eff
And the exchange address is: 0xdef1c0ded9bec7f1a1670819833240f027b25eff
The exchange address and proxy address provided in @0x/contract-wrappers is not correct, or maybe we need a clear guideline about that. Also i suggest dev team can show important address of V4 in cheatsheet to save others time.
Hey, I seem to have the same error, but arent the addresses you mentioned in the solution the same as that in the initial problem statement?
What was the final solution in that case then?
Hey, I seem to have the same error, but arent the addresses you mentioned in the solution the same as that in the initial problem statement?
What was the final solution in that case then?
the address is updated, so they look the same, this is my final solution, you can also ask 0x engineer in discord
p.s. coin.currentChainData.address is just ERC20 contract address
import {
BigNumber, ERC20TokenContract, MetamaskSubprovider, Web3JsProvider,
} from '0x.js';
import detectEthereumProvider from '@metamask/detect-provider';
export const exchange0xProxyAddress = '0xdef1c0ded9bec7f1a1670819833240f027b25eff'
export const GetAllowance = async(_account:string, coin:CoinData) =>{
const w3provider = await detectEthereumProvider() as Web3JsProvider
const providerEngine = new MetamaskSubprovider(w3provider)
const CoinCcontract = new ERC20TokenContract(coin.currentChainData.address, providerEngine, {from:_account})
const allowanceBN = await CoinCcontract
.allowance(_account,exchange0xProxyAddress)
.callAsync()
return allowanceBN
}
export const SetAllowance = async(_account:string, coin:CoinData, amount:number) =>{
const w3provider = await detectEthereumProvider() as Web3JsProvider
const providerEngine = new MetamaskSubprovider(w3provider)
const CoinCcontract = new ERC20TokenContract(coin.currentChainData.address, providerEngine, {from:_account})
const tx = await CoinCcontract
.approve(exchange0xProxyAddress, new BigNumber(amount))
.sendTransactionAsync({from:_account, gas:unlockAssetGasLimit})
return tx
}