mirror of
https://github.com/vacp2p/swap-contracts-module.git
synced 2025-02-27 10:20:38 +00:00
Add sign cheque script
This commit is contained in:
parent
9b6ef97fea
commit
989e70ef6d
69
scripts/sign-cheque.js
Normal file
69
scripts/sign-cheque.js
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
const hre = require("hardhat");
|
||||||
|
const eip712 = require("ethers-eip712");
|
||||||
|
|
||||||
|
const EIP712Domain = [
|
||||||
|
{ name: 'name', type: 'string' },
|
||||||
|
{ name: 'version', type: 'string' },
|
||||||
|
{ name: 'chainId', type: 'uint256' }
|
||||||
|
// Missing
|
||||||
|
// {name: "verifyingContract", type: "address"},
|
||||||
|
]
|
||||||
|
|
||||||
|
const ChequeType = [
|
||||||
|
{ name: 'chequebook', type: 'address' },
|
||||||
|
{ name: 'beneficiary', type: 'address' },
|
||||||
|
{ name: 'cumulativePayout', type: 'uint256' }
|
||||||
|
]
|
||||||
|
|
||||||
|
// XXX Hardcoded from recent deploy to Hardhat dev chain
|
||||||
|
var erc20address = "0x5FbDB2315678afecb367f032d93F642f64180aa3";
|
||||||
|
var aliceAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
|
||||||
|
var aliceSwapAddress = "0xCafac3dD18aC6c6e92c921884f9E4176737C052c";
|
||||||
|
var bobAddress = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";
|
||||||
|
|
||||||
|
// TODO This should be parameterized with arguments, so probably as a task or standalone script?
|
||||||
|
async function main() {
|
||||||
|
var swapAddress = aliceSwapAddress;
|
||||||
|
var beneficiary = bobAddress;
|
||||||
|
var cumulativePayout = 500;
|
||||||
|
var chainId = 31337;
|
||||||
|
|
||||||
|
var signers = await ethers.getSigners();
|
||||||
|
var aliceSigner = signers[0];
|
||||||
|
|
||||||
|
const cheque = {
|
||||||
|
chequebook: swapAddress,
|
||||||
|
beneficiary,
|
||||||
|
cumulativePayout: cumulativePayout
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log("Cheque", cheque);
|
||||||
|
|
||||||
|
const typedData = {
|
||||||
|
types: {
|
||||||
|
EIP712Domain,
|
||||||
|
Cheque: ChequeType
|
||||||
|
},
|
||||||
|
domain: {
|
||||||
|
name: "Chequebook",
|
||||||
|
version: "1.0",
|
||||||
|
chainId
|
||||||
|
},
|
||||||
|
primaryType: 'Cheque',
|
||||||
|
message: cheque
|
||||||
|
}
|
||||||
|
|
||||||
|
const digest = eip712.TypedDataUtils.encodeDigest(typedData)
|
||||||
|
const digestHex = ethers.utils.hexlify(digest)
|
||||||
|
|
||||||
|
// NOTE this may be different from eth_signTypedData_v3, etc
|
||||||
|
const signature = await aliceSigner.signMessage(digest)
|
||||||
|
console.log("Signature:", signature);
|
||||||
|
}
|
||||||
|
|
||||||
|
main()
|
||||||
|
.then(() => process.exit(0))
|
||||||
|
.catch(error => {
|
||||||
|
console.error(error);
|
||||||
|
process.exit(1);
|
||||||
|
});
|
@ -1,7 +1,8 @@
|
|||||||
|
// Example code to test EIP712 library
|
||||||
|
|
||||||
const hre = require("hardhat");
|
const hre = require("hardhat");
|
||||||
const eip712 = require("ethers-eip712");
|
const eip712 = require("ethers-eip712");
|
||||||
|
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const typedData = {
|
const typedData = {
|
||||||
types: {
|
types: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user