Skip to content

Commit

Permalink
Fix Approve erc20 token
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Mar 19, 2020
1 parent 11d1826 commit 052be87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions js/tests/simple-integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ async function testDeposit(depositWallet: Wallet, syncWallet: Wallet, token: typ
console.log(`Deposit committed: ${(new Date().getTime()) - startTime} ms`);
const balanceAfterDep = await syncWallet.getBalance(token);

if (!zkutils.isTokenETH(token)) {
if (!await depositWallet.isERC20DepositsApproved(token)){
throw new Error("Token should still be approved");
}
}

if (!balanceAfterDep.sub(balanceBeforeDep).eq(amount)) {
throw new Error("Deposit checks failed");
}
Expand Down
3 changes: 3 additions & 0 deletions js/zksync.js/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export const SYNC_GOV_CONTRACT_INTERFACE = new utils.Interface(
export const MAX_ERC20_APPROVE_AMOUNT =
"115792089237316195423570985008687907853269984665640564039457584007913129639935"; // 2^256 - 1

export const ERC20_APPROVE_TRESHOLD =
"57896044618658097711785492504343953926634992332820282019728792003956564819968"; // 2^255

const AMOUNT_EXPONENT_BIT_WIDTH = 5;
const AMOUNT_MANTISSA_BIT_WIDTH = 35;
const FEE_EXPONENT_BIT_WIDTH = 5;
Expand Down
3 changes: 2 additions & 1 deletion js/zksync.js/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PubKeyHash
} from "./types";
import {
ERC20_APPROVE_TRESHOLD,
IERC20_INTERFACE,
isTokenETH,
MAX_ERC20_APPROVE_AMOUNT,
Expand Down Expand Up @@ -341,7 +342,7 @@ export class Wallet {
);
return utils
.bigNumberify(currentAllowance)
.eq(MAX_ERC20_APPROVE_AMOUNT);
.lte(ERC20_APPROVE_TRESHOLD);
}

async approveERC20TokenDeposits(
Expand Down

0 comments on commit 052be87

Please sign in to comment.