-
Notifications
You must be signed in to change notification settings - Fork 40
Add withdrawer role to allow withdraw #406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
daveroga
wants to merge
6
commits into
master
Choose a base branch
from
chore/allow-withdrawer-role-withdraw
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b43cc3
add withdrawer role to allow withdraw
daveroga b599e23
add integration test
daveroga 459d8cc
small updates
daveroga bc48b47
merge from master
daveroga 3dc2379
merge from master
daveroga e6abc8d
fix safetransfer msgsender
daveroga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| import { ethers } from "hardhat"; | ||
|
|
||
| async function main() { | ||
| const mcPaymentAddress = "0xYourMCPaymentContractAddressHere"; // replace with actual deployed contract address | ||
| const tokenAddress = "0xYourTokenAddressHere"; // replace with actual token address | ||
| const issuerPrivateKey = "0xYourIssuerPrivateKeyHere"; // replace with actual issuer private key | ||
| const amount = 1000; // amount to be paid | ||
|
|
||
| const issuerWallet = new ethers.Wallet(issuerPrivateKey); | ||
|
|
||
| const [signer] = await ethers.getSigners(); | ||
| const token = await ethers.getContractAt("ERC20Token", tokenAddress); | ||
| const signerBalance = await token.balanceOf(signer.address); | ||
| console.log( | ||
| `Balance ${signer.address}: ${ethers.formatEther(signerBalance)} ${await token.symbol()}`, | ||
| ); | ||
|
|
||
| const payment = await ethers.getContractAt("MCPayment", mcPaymentAddress); | ||
|
|
||
| const domainData = { | ||
| name: "MCPayment", | ||
| version: "1.0.0", | ||
| chainId: 31337, | ||
| verifyingContract: await payment.getAddress(), | ||
| }; | ||
|
|
||
| const erc20types = { | ||
| Iden3PaymentRailsERC20RequestV1: [ | ||
| { name: "tokenAddress", type: "address" }, | ||
| { name: "recipient", type: "address" }, | ||
| { name: "amount", type: "uint256" }, | ||
| { name: "expirationDate", type: "uint256" }, | ||
| { name: "nonce", type: "uint256" }, | ||
| { name: "metadata", type: "bytes" }, | ||
| ], | ||
| }; | ||
|
|
||
| const paymentData = { | ||
| tokenAddress: tokenAddress, | ||
| recipient: issuerWallet.address, | ||
| amount: amount, | ||
| expirationDate: Math.round(new Date().getTime() / 1000) + 60 * 60, // 1 hour | ||
| nonce: 35, | ||
| metadata: "0x", | ||
| }; | ||
| const signature = await issuerWallet.signTypedData(domainData, erc20types, paymentData); | ||
|
|
||
| // approve MCPayment contract to spend tokens | ||
| const txApprove = await token.connect(signer).approve(await payment.getAddress(), amount); | ||
| await txApprove.wait(); | ||
| console.log( | ||
| `${signer.address} approved ${amount} ${await token.symbol()} for MCPayment contract at ${mcPaymentAddress}`, | ||
| ); | ||
|
|
||
| const erc20PaymentGas = await payment | ||
| .connect(signer) | ||
| .payERC20.estimateGas(paymentData, signature); | ||
| console.log("ERC-20 Payment Gas: " + erc20PaymentGas); | ||
|
|
||
| let ownerBalance = await payment.getOwnerERC20Balance(tokenAddress); | ||
| console.log(`Owner ERC-20 Balance before payment: ${ownerBalance}`); | ||
|
|
||
| const tx = await payment.connect(signer).payERC20(paymentData, signature); | ||
| console.log("ERC-20 Payment Tx Hash: " + tx.hash); | ||
| await tx.wait(); | ||
|
|
||
| ownerBalance = await payment.getOwnerERC20Balance(tokenAddress); | ||
| console.log(`Owner ERC-20 Balance after payment: ${ownerBalance}`); | ||
| } | ||
|
|
||
| main() | ||
| .then(() => process.exit(0)) | ||
| .catch((error) => { | ||
| console.error(error); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.