mirror of
https://github.com/vacp2p/swap-contracts-module.git
synced 2025-02-27 18:30:33 +00:00
Basic sign cheque task
This commit is contained in:
parent
89026b42a5
commit
7c23fc1858
@ -29,6 +29,13 @@ task("setupSwap", "Setup Swap")
|
|||||||
console.log(JSON.stringify(resp));
|
console.log(JSON.stringify(resp));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
task("signCheque", "Sign cheque")
|
||||||
|
.setAction(async taskArgs => {
|
||||||
|
// TODO Argument, aliceSwapAddress
|
||||||
|
var resp = await swap.signCheque();
|
||||||
|
console.log(JSON.stringify(resp));
|
||||||
|
});
|
||||||
|
|
||||||
// You need to export an object to set up your config
|
// You need to export an object to set up your config
|
||||||
// Go to https://hardhat.org/config/ to learn more
|
// Go to https://hardhat.org/config/ to learn more
|
||||||
|
|
||||||
|
@ -1,3 +1,28 @@
|
|||||||
|
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' }
|
||||||
|
]
|
||||||
|
|
||||||
|
// Seems to persist, first two default accounts
|
||||||
|
var aliceAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266";
|
||||||
|
var bobAddress = "0x70997970C51812dc3A010C7d01b50e0d17dc79C8";
|
||||||
|
|
||||||
|
// XXX These change
|
||||||
|
// TODO Parameterize
|
||||||
|
var erc20address = "0xa513E6E4b8f2a923D98304ec87F64353C4D5C853";
|
||||||
|
var aliceSwapAddress = "0x94099942864EA81cCF197E9D71ac53310b1468D8";
|
||||||
|
|
||||||
async function setupSwap() {
|
async function setupSwap() {
|
||||||
// Basic setup and definitions
|
// Basic setup and definitions
|
||||||
var signers = await ethers.getSigners();
|
var signers = await ethers.getSigners();
|
||||||
@ -69,4 +94,50 @@ async function setupSwap() {
|
|||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO This should be parameterized with arguments, so probably as a task or standalone script?
|
||||||
|
async function signCheque() {
|
||||||
|
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 types = {
|
||||||
|
Cheque: ChequeType
|
||||||
|
};
|
||||||
|
|
||||||
|
const domain = {
|
||||||
|
name: "Chequebook",
|
||||||
|
version: "1.0",
|
||||||
|
chainId
|
||||||
|
};
|
||||||
|
|
||||||
|
const value = cheque;
|
||||||
|
|
||||||
|
// XXX Workaround to get to private signTypedData interface
|
||||||
|
var mnemonic = "test test test test test test test test test test test junk";
|
||||||
|
var path0 = "m/44'/60'/0'/0/0";
|
||||||
|
var recoveredWallet = ethers.Wallet.fromMnemonic(mnemonic, path0);
|
||||||
|
var aliceSignerWallet = recoveredWallet.connect(ethers.provider);
|
||||||
|
|
||||||
|
var signature = await aliceSignerWallet._signTypedData(domain, types, value);
|
||||||
|
|
||||||
|
//console.log("Signer:", aliceSigner.address);
|
||||||
|
//console.log("Signature:", signature);
|
||||||
|
|
||||||
|
return {signer: aliceSigner.adress, signature: signature};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
module.exports.setupSwap = setupSwap;
|
module.exports.setupSwap = setupSwap;
|
||||||
|
module.exports.signCheque = signCheque;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user