Skip to content
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

fix: revert 0xM Q02 #60

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion addresses.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
"Billing": "0x2da5DF23869B05b6641C91297b7025029112abA7",
"BanxaWrapper": "0xDc4787B4c822a36F72A0084B02dA213A7291C35B",
"GelatoAutomate": "0xa5f9b728ecEB9A1F6FCC89dcc2eFd810bA4Dec41",
"RecurringPayments": "0x3EAbD1e33d1d063E32B8479b3E7b8e22E62b0012"
"RecurringPayments": "0x68becb01A921855D2b85B2952ca10f1801b518eD"
}
}
2 changes: 1 addition & 1 deletion contracts/GelatoManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ contract GelatoManager is AutomateTaskCreator, Governed {
moduleData.modules[0] = Module.RESOLVER;
moduleData.args[0] = _resolverModuleArg(resolverAddress, resolverData);

bytes32 taskId = _createTask(execAddress, execDataOrSelector, moduleData, ETH);
bytes32 taskId = _createTask(execAddress, execDataOrSelector, moduleData, address(0));
emit ResolverTaskCreated(taskId);

return taskId;
Expand Down
81 changes: 81 additions & 0 deletions tasks/ops/recurringPayments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,41 @@ task('rp:deposit', 'Deposit eth into Gelato treasury')
console.log('Deposited with tx hash:', receipt.transactionHash)
})

task('rp:withdraw', 'Withdraw all funds from Gelato treasury').setAction(
async (taskArgs, hre: HardhatRuntimeEnvironment) => {
const chainId = (hre.network.config.chainId as number).toString()
const rpAddress = addresses[chainId]['RecurringPayments']

const artifact = loadArtifact('RecurringPayments')
const recurringPayments = new ethers.Contract(rpAddress, artifact.abi, hre.ethers.provider) as RecurringPayments

const treasuryAddress = await recurringPayments.taskTreasury()
const TREASURY_ABI = [
{
inputs: [
{ internalType: 'address', name: '_user', type: 'address' },
{ internalType: 'address', name: '_token', type: 'address' },
],
name: 'userTokenBalance',
outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],
stateMutability: 'view',
type: 'function',
},
]
const treasury = new ethers.Contract(treasuryAddress, TREASURY_ABI, hre.ethers.provider)

const accounts = await hre.ethers.getSigners()
const userBalance = await treasury.userTokenBalance(
recurringPayments.address,
'0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
)
console.log(`Withdrawing ${ethers.utils.formatEther(userBalance)} ETH ...`)
const tx = await recurringPayments.connect(accounts[0]).withdraw(accounts[0].address, userBalance)
const receipt = await tx.wait()
console.log('Withdrawn with tx hash:', receipt.transactionHash)
},
)

const ERC20_APPROVE_ABI = [
{
inputs: [
Expand Down Expand Up @@ -124,3 +159,49 @@ task('rp:setup', 'Create a recurring payment')

console.log('Created with tx hash:', receipt.transactionHash)
})

task('rp:cancel', 'Cancel a recurring payment')
.addParam('privateKey', 'Account private key')
.setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {
const chainId = (hre.network.config.chainId as number).toString()
const rpAddress = addresses[chainId]['RecurringPayments']

const artifact = loadArtifact('RecurringPayments')
const recurringPayments = new ethers.Contract(rpAddress, artifact.abi, hre.ethers.provider) as RecurringPayments

const account = new ethers.Wallet(taskArgs.privateKey, hre.ethers.provider)

console.log(`Cancelling recurring payment`)
console.log(` - account: ${account.address}`)

const tx = await recurringPayments.connect(account)['cancel()']()
const receipt = await tx.wait()

console.log('Cancelled with tx hash:', receipt.transactionHash)
})

task('rp:execute', 'Execute a recurring payment. Only owner can call.')
.addParam('privateKey', 'Account private key')
.setAction(async (taskArgs, hre: HardhatRuntimeEnvironment) => {
const chainId = (hre.network.config.chainId as number).toString()
const rpAddress = addresses[chainId]['RecurringPayments']

const artifact = loadArtifact('RecurringPayments')
const recurringPayments = new ethers.Contract(rpAddress, artifact.abi, hre.ethers.provider) as RecurringPayments

const account = new ethers.Wallet(taskArgs.privateKey, hre.ethers.provider)

const nextExecutionTime = await recurringPayments.getNextExecutionTime(account.address)

console.log(`Executing recurring payment`)
console.log(` - account: ${account.address}`)
console.log(` - next execution time: ${new Date(nextExecutionTime.toNumber() * 1000)}`)

const tx = await recurringPayments.connect(account).execute(account.address)
const receipt = await tx.wait()

console.log('Executed with tx hash:', receipt.transactionHash)

const newNextExecutionTime = await recurringPayments.getNextExecutionTime(account.address)
console.log(`Next execution time is now: ${new Date(newNextExecutionTime.toNumber() * 1000)}`)
})
Loading