Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #223 from hermeznetwork/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
AlbertoElias authored Dec 16, 2021
2 parents 0a0228d + 77f0b6d commit 2d7a0a2
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 51 deletions.
70 changes: 39 additions & 31 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions src/tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,14 @@ async function createPermitSignature (
* Generates a permit data string to be passed to a smart contract function call
* @param {ethers.Contract} fromTokenContract - A Contract instance of an ERC 20 token
* @param {String} accountAddress - The Ethereum address of the transaction sender
* @param {String} contractAddress - The contract we are authorizing to handle our tokens
* @param {ethers.BigNumber} amount - The amount we want to authorize
* @param {Object} signerData - Signer data used to build a Signer to send the transaction
* @param {String} providerUrl - Network url (i.e, http://localhost:8545). Optional
* @returns {String} A hex string with the permit data
*/
async function permit (fromTokenContract, accountAddress, contractAddress, signerData, providerUrl) {
async function permit (fromTokenContract, accountAddress, contractAddress, amount, signerData, providerUrl) {
const nonce = await fromTokenContract.nonces(accountAddress)
const amount = ethersConstants.MaxUint256
const deadline = ethersConstants.MaxUint256
const { v, r, s } = await createPermitSignature(
fromTokenContract,
Expand Down
25 changes: 7 additions & 18 deletions src/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ async function getGasPrice (providerUrl) {
* @param {Object} signerData - Signer data used to build a Signer to send the transaction
* @param {String} providerUrl - Network url (i.e, http://localhost:8545). Optional
* @param {Number} gasLimit - Optional gas limit
* @param {Number} gasMultiplier - Optional gas multiplier
* @returns {Promise} transaction parameters
*/
const deposit = async (
Expand All @@ -69,8 +68,7 @@ const deposit = async (
babyJubJub,
signerData,
providerUrl,
gasLimit,
gasMultiplier
gasLimit
) => {
if (!HermezCompressedAmount.isHermezCompressedAmount(amount)) {
throw new Error('The parameter needs to be an instance of HermezCompressedAmount created with HermezCompressedAmount.compressAmount')
Expand All @@ -85,11 +83,12 @@ const deposit = async (
.catch(() => undefined)
const account = typeof accounts !== 'undefined' ? accounts.accounts[0] : null
const overrides = await getGasPrice(providerUrl)
const decompressedAmount = HermezCompressedAmount.decompressAmount(amount)

const usePermit = await isPermitSupported(fromTokenContract)
const permitSignature =
usePermit
? await permit(fromTokenContract, ethereumAddress, CONTRACT_ADDRESSES[ContractNames.Hermez], signerData, providerUrl)
? await permit(fromTokenContract, ethereumAddress, CONTRACT_ADDRESSES[ContractNames.Hermez], decompressedAmount, signerData, providerUrl)
: '0x'

const transactionParameters = [
Expand All @@ -102,8 +101,6 @@ const deposit = async (
permitSignature
]

const decompressedAmount = HermezCompressedAmount.decompressAmount(amount)

// Deposits need a gas limit to not have to wait for the approve to occur
// before calculating it automatically, which would slow down the process
overrides.gasLimit = typeof gasLimit === 'undefined'
Expand Down Expand Up @@ -131,7 +128,6 @@ const deposit = async (
* @param {Object} signerData - Signer data used to build a Signer to send the transaction
* @param {String} providerUrl - Network url (i.e, http://localhost:8545). Optional
* @param {Number} gasLimit - Optional gas limit
* @param {Number} gasMultiplier - Optional gas multiplier
* @returns {Promise} transaction parameters
* @throws {Error} Throws an error if account index isn't valid
*/
Expand All @@ -141,8 +137,7 @@ const forceExit = async (
token,
signerData,
providerUrl,
gasLimit,
gasMultiplier
gasLimit
) => {
if (!HermezCompressedAmount.isHermezCompressedAmount(amount)) {
throw new Error('The parameter needs to be an instance of HermezCompressedAmount created with HermezCompressedAmount.compressAmount')
Expand Down Expand Up @@ -187,7 +182,6 @@ const forceExit = async (
* @param {String} providerUrl - Network url (i.e, http://localhost:8545). Optional
* @param {Boolean} filterSiblings - Whether siblings should be filtered
* @param {Number} gasLimit - Optional gas limit
* @param {Number} gasMultiplier - Optional gas multiplier
* @returns {Promise} transaction parameters
* @throws {Error} Throws an error if account index isn't valid
*/
Expand All @@ -201,8 +195,7 @@ const withdraw = async (
isInstant = true,
signerData,
providerUrl,
gasLimit,
gasMultiplier
gasLimit
) => {
const account = await getAccount(accountIndex)
.catch(() => {
Expand Down Expand Up @@ -250,7 +243,6 @@ const withdraw = async (
* @param {Object} signerData - Signer data used to build a Signer to send the transaction
* @param {String} providerUrl - Network url (i.e, http://localhost:8545). Optional
* @param {Number} gasLimit - Optional gas limit
* @param {Number} gasMultiplier - Optional gas multiplier
* @returns {Promise} transaction parameters
*/
const withdrawCircuit = async (
Expand All @@ -260,8 +252,7 @@ const withdrawCircuit = async (
zkeyFilePath,
signerData,
providerUrl,
gasLimit,
gasMultiplier
gasLimit
) => {
const hermezContract = getContract(CONTRACT_ADDRESSES[ContractNames.Hermez], HermezABI, signerData, providerUrl)
const wasmFileInput = typeof window === 'undefined' ? wasmFilePath : wasmFilePath || WITHDRAWAL_WASM_URL
Expand Down Expand Up @@ -298,16 +289,14 @@ const withdrawCircuit = async (
* @param {Object} signerData - Signer data used to build a Signer to send the transaction
* @param {String} providerUrl - Network url (i.e, http://localhost:8545). Optional
* @param {Number} gasLimit - Optional gas limit
* @param {Number} gasMultiplier - Optional gas multiplier
* @returns {Promise} transaction parameters
*/
const delayedWithdraw = async (
hezEthereumAddress,
token,
signerData,
providerUrl,
gasLimit,
gasMultiplier
gasLimit
) => {
const ethereumAddress = getEthereumAddress(hezEthereumAddress)
const txSignerData = signerData || { type: SignerType.JSON_RPC, addressOrIndex: ethereumAddress }
Expand Down

0 comments on commit 2d7a0a2

Please sign in to comment.