Skip to content

Commit

Permalink
Refactor scripts and adjust README
Browse files Browse the repository at this point in the history
  • Loading branch information
test committed Jan 14, 2024
1 parent 12806b6 commit 1da76ab
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 17 deletions.
61 changes: 60 additions & 1 deletion contracts/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
# GHOPAY
# GHOPAY - Smart Contracts
This directory contains the smart contracts related tests, utilities and deployment addresses for the Payment Settlement.

## How does it work ?
The smart contracts themselves have essentially three tasks:
1. Verify the user signature that was passed in by the Gelato relay in terms of amount and receiver
2. Use user signature to pull in GHO
3. Swap a fraction of the GHO for gas fee token (usually eth / native token) expected by relay
4. Pay the relay
5. Transfer remaining Gho to the receiver


## Installation
`yarn install`

## Run tests
`yarn test`


## Sepolia Deployment

### Warning:
Note that on Sepolia we have deployed the [PaymentSettlementTestHarness](contracts/contracts/test/PaymentSettlementTestHarness.sol) contract which extends the [PaymentSettlement](contracts/contracts/PaymentSettlement.sol) with some unsafe methods added for testing purposes.
One should NEVER deploy this version of the contract on a network were it will handle actual value.


### Run Deploy:
Delete deployment outputs of previous deployment if you want to redeploy:
`rm -rf deployments/sepolia`

Deploy on actual sepolia:
`deploy:sepolia --network sepolia`

Test deploy on local fork:
`deploy:sepolia --network localhost`

## Send Payment (on Sepolia)

You can use the [payment script](contracts/scripts/sendPayment.ts) to send a GHO payment gaslessly via the Gelato relay.
For this you will have to:
1. Adjust the `receiver` and `amount` variables in the script to your liking
2. Make sure you have set the `SEPOLIA_PRIVATE_KEY` environment variable to the private key of an account with sufficient GHO tokens on sepolia
3. Run `yarn send-payment:sepolia` to make the payment
4. Wait for the script to finish. In the success case the last emitted logs should llook something like this:
```
Task Status {
chainId: 11155111,
taskId: '0xaa31e9ec7dc88958e8d263b59575b2c22452985815552c4e189baa11e7141104',
taskState: 'ExecSuccess',
creationDate: '2024-01-14T06:51:54.367Z',
transactionHash: '0xa38b90e8af1f66425961e3e09deca5bc184b94cf10be95535893338ce7dcf1c9',
executionDate: '2024-01-14T06:52:01.839Z',
blockNumber: 5083156,
gasUsed: '295101',
effectiveGasPrice: '153284042'
}
```



3 changes: 2 additions & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"compile": "hardhat compile",
"test": "hardhat test",
"deploy:sepolia": "DEPLOY='v0.0.1.sepolia' hardhat deploy",
"verify:sepolia": "yarn hardhat etherscan-verify --network sepolia --api-url https://api-sepolia.etherscan.io/ --api-key $SEPOLIA_ETHERSCAN_API_KEY"
"verify:sepolia": "yarn hardhat etherscan-verify --network sepolia --api-url https://api-sepolia.etherscan.io/ --api-key $SEPOLIA_ETHERSCAN_API_KEY",
"send-payment:sepolia": "yarn hardhat run --network sepolia scripts/sendPayment.ts"
},
"devDependencies": {
"@gelatonetwork/relay-sdk": "^5.5.0",
Expand Down
13 changes: 7 additions & 6 deletions contracts/scripts/sendPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {

import {
ghoAddress,
wethAddress,
ethAddress,
} from "../constants/addresses";

async function createTask(
Expand Down Expand Up @@ -65,13 +65,13 @@ async function main() {
};
console.log("chainId:", chainId);

let amount = ethers.utils.parseEther("0.01");
let receiver = "0xef35B896e1c6c816177277924d04Ead587Bbc495";
let amount = ethers.utils.parseEther("100");
let receiver = "0x3C1a2E9CA00AF23Cd95000160f873f77F65a0041";
const gho = IERC20Complete__factory.connect(ghoAddress, deployerSigner);
const relativeDeadline = 60 * 60;
const deadline = Math.floor(new Date().getTime() / 1000) + relativeDeadline;
const fee = ethers.utils.parseEther("0.000000000001");
const feeToken = wethAddress;
const feeToken = ethAddress;
let verifyCalldata = await generateVerificationCallData(
gho,
amount,
Expand All @@ -87,13 +87,14 @@ async function main() {
ghoAddress,
amount,
receiver,
paymentSettlement
paymentSettlement,
false
);
const task = await createTask(
payCalldata,
paymentSettlement.address,
chainId,
ghoAddress
feeToken
);
await awaitTask(task);
}
Expand Down
22 changes: 13 additions & 9 deletions contracts/test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,16 +215,20 @@ export async function generatePayCallData(
tokenAddress: string,
amount: BigNumberish,
receiver: string,
paymentSettlement: PaymentSettlement
paymentSettlement: PaymentSettlement,
verifyCalldata: boolean = true
) {
const result = await paymentSettlement.signer.provider?.call({
to: paymentSettlement.address,
data: verifyCallData,
});
const expectedResult =
"0x0000000000000000000000000000000000000000000000000000000000000001";
if (result !== expectedResult) {
throw new Error("verifyData failed");

if(verifyCalldata) {
const result = await paymentSettlement.signer.provider?.call({
to: paymentSettlement.address,
data: verifyCallData,
});
const expectedResult =
"0x0000000000000000000000000000000000000000000000000000000000000001";
if (result !== expectedResult) {
throw new Error("verifyData failed");
}
}

const [paymentData, paySignature] = paymentSettlement.interface.decodeFunctionData(
Expand Down

0 comments on commit 1da76ab

Please sign in to comment.