Created
February 6, 2025 11:35
-
-
Save tofmat/8fedada5132183cdf593c59249b4cd17 to your computer and use it in GitHub Desktop.
Get approval!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (Number(allowApproval) == 0) { | |
const deadline = Math.floor(Date.now() / 1000) + 3600; | |
const obj = { | |
owner: address as `0x${string}`, | |
spender: | |
selectedInvestmentType === "construction" | |
? (CONTRACT_CONFIG.CONSTRUCTION_POOL_ADDRESS as `0x${string}`) | |
: (CONTRACT_CONFIG.PERMANENT_POOL_ADDRESS as `0x${string}`), | |
value: BigInt( | |
"115792089237316195423570985008687907853269984665640564039457584007913129639935" | |
), | |
deadline: BigInt(deadline as number), | |
nonce: BigInt(usdc_nonce as number), | |
}; | |
const signature = await signTypedDataAsync({ | |
domain: { | |
name: "USD Coin", | |
version: usdcVersion as string, | |
chainId: CONTRACT_CONFIG.TEST_CHAIN_ID, | |
verifyingContract: CONTRACT_CONFIG.USDC_ADDRESS as `0x${string}`, | |
}, | |
types: { | |
Permit: [ | |
{ | |
name: "owner", | |
type: "address", | |
}, | |
{ | |
name: "spender", | |
type: "address", | |
}, | |
{ | |
name: "value", | |
type: "uint256", | |
}, | |
{ | |
name: "nonce", | |
type: "uint256", | |
}, | |
{ | |
name: "deadline", | |
type: "uint256", | |
}, | |
], | |
}, | |
primaryType: "Permit", | |
message: { | |
owner: obj.owner, | |
spender: obj.spender, | |
value: obj.value, | |
nonce: obj.nonce, | |
deadline: obj.deadline, | |
}, | |
}); | |
console.log( | |
"signature for usdc" + " " + signature.length + " " + signature | |
); | |
const signatureWithoutPrefix = signature.slice(2); // Remove the '0x' prefix | |
const r = `0x${signatureWithoutPrefix.slice(0, 64)}`; | |
const s = `0x${signatureWithoutPrefix.slice(64, 128)}`; | |
const v = parseInt(signatureWithoutPrefix.slice(128, 130), 16); | |
await writeContractAsync({ | |
abi: USDC_ABI, | |
functionName: "permit", | |
address: CONTRACT_CONFIG.USDC_ADDRESS as `0x${string}`, | |
args: [obj.owner, obj.spender, obj.value, obj.deadline, v, r, s], | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment