You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I created an example Permit2App.sol that has a public function which calls permit2.permit and permit2.transferFrom. It has been deployed, the example token (LINK on Sepolia) has been approved for the Permit2, and there have been multiple successful test signature creations and transfers via Permit2 functionality. The current nonce is 7 in the Permit2 allowance mapping for the [owner, token, spender].
// SPDX-License-Identifier: MITpragma solidity0.8.23;
import {IAllowanceTransfer} from"./IAllowanceTransfer.sol";
contractPermit2App {
IAllowanceTransfer publicimmutable permit2;
error InvalidSpender();
constructor(address_permit2) {
permit2 =IAllowanceTransfer(_permit2);
}
function permitAndTransferToMe(
IAllowanceTransfer.PermitSingle calldatapermitSingle,
bytescalldatasignature,
uint160amount
) public {
_permitWithPermit2(permitSingle, signature);
_transferToMe(permitSingle.details.token, amount);
}
function _permitWithPermit2(IAllowanceTransfer.PermitSingle calldatapermitSingle, bytescalldatasignature) internal {
if (permitSingle.spender !=address(this)) revertInvalidSpender(); // This contract must have spending permissions for the user.
permit2.permit(msg.sender, permitSingle, signature); // owner is explicitly msg.sender
}
function _transferToMe(addresstoken, uint160amount) internal {
permit2.transferFrom(msg.sender, address(this), amount, token); // actually transfer the tokens
}
}
Permit2's Sepolia Etherscan returns the correct non-zero read values for the allowance mapping result (amount, expiration, nonce) when my correct [owner, token, spender] values are input. As expected, manually calling directly on permit2.allowance also results in outputting the correct values. However, using the same input values for Permit2 SDK on Sepolia returns default zero values for getAllowanceData calls.
I suspect I'm doing something wrong with the SDK. My attempt appears identical to Uniswap's Permit2 integration guide. I am using ethers 5.7.2 because ethers v6 does not allow for AllowanceProvider instantiation. permit2-sdk is version 1.3.0. And using 0.8.23 solidity. IEIP712.sol and IAllowanceTransfer.sol are simply put in src along with Permitt2App.sol and Permit2App.js
const{ ethers }=require("ethers");const{ AllowanceProvider, AllowanceTransfer,PERMIT2_ADDRESS, MaxAllowanceTransferAmount }=require('@uniswap/permit2-sdk');require('dotenv/config');// 1. Instantiate Provider & Signerconstprovider=newethers.providers.InfuraProvider("sepolia",process.env.SEPOLIA_KEY);constsigner=newethers.Wallet(process.env.PRIVATE_KEY,provider);// 2. Instantiate our Permit2App Contractconstpermit2AppABI=require("../out/Permit2App.sol/Permit2App.json").abi;constpermit2AppAddress="0xMyExamplePermit2AppContract";constpermit2AppContract=newethers.Contract(permit2AppAddress,permit2AppABI,signer);// 3. Instantiate example token to use. (You must have some of these tokens on the chain you choose).consttokenAddress="0x779877A7B0D9E8603169DdbD7836e478b4624789";// LINK on SepoliaconsttokenApprovalABI=['function approve(address spender, uint256 amount) returns (bool)'];// only need `approve()`consttokenContract=newethers.Contract(tokenAddress,tokenApprovalABI,signer);// Example function that uses both methods to retrieve desired dataasyncfunctiongetData(){// 1. Using SDK (returns all 0's)constuser=awaitsigner.getAddress();constallowanceProvider=newAllowanceProvider(provider,PERMIT2_ADDRESS)const{amount: permitAmount, expiration, nonce }=awaitallowanceProvider.getAllowanceData(user,tokenAddress,permit2AppAddress);console.log("Allowance data:",{ permitAmount, expiration, nonce });// {0x00, 0, 0}// 2. Using Permit2 directly (returns correct data)constpermit2ABI=[{"inputs": [{"internalType": "address","name": "user","type": "address"},{"internalType": "address","name": "token","type": "address"},{"internalType": "address","name": "spender","type": "address"}],"name": "allowance","outputs": [{"internalType": "uint160","name": "amount","type": "uint160"},{"internalType": "uint48","name": "expiration","type": "uint48"},{"internalType": "uint48","name": "nonce","type": "uint48"}],"stateMutability": "view","type": "function"}];constpermit2Contract=newethers.Contract(PERMIT2_ADDRESS,permit2ABI,provider);const[amount,_expiration,_nonce]=awaitpermit2Contract.allowance(owner,tokenAddress,permit2AppAddress);constcurrentNonce=parseInt(_nonce,10);// parse nonce's returned string value into base 10 integer.console.log("Allowance data:",{ amount, _expiration, currentNonce });// {0xffff..., 1725933703, 7}}getData();
I created an example
Permit2App.sol
that has a public function which callspermit2.permit
andpermit2.transferFrom
. It has been deployed, the example token (LINK on Sepolia) has been approved for the Permit2, and there have been multiple successful test signature creations and transfers via Permit2 functionality. The current nonce is 7 in the Permit2allowance
mapping for the[owner, token, spender]
.Permit2's Sepolia Etherscan returns the correct non-zero read values for the
allowance
mapping result (amount, expiration, nonce) when my correct [owner, token, spender] values are input. As expected, manually calling directly onpermit2.allowance
also results in outputting the correct values. However, using the same input values for Permit2 SDK on Sepolia returns default zero values forgetAllowanceData
calls.I suspect I'm doing something wrong with the SDK. My attempt appears identical to Uniswap's Permit2 integration guide. I am using ethers 5.7.2 because ethers v6 does not allow for
AllowanceProvider
instantiation. permit2-sdk is version 1.3.0. And using 0.8.23 solidity. IEIP712.sol and IAllowanceTransfer.sol are simply put in src along with Permitt2App.sol and Permit2App.jsThe text was updated successfully, but these errors were encountered: