Skip to content

Commit

Permalink
feat(rp): add rp management tasks and new rp address for arbgor
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
  • Loading branch information
tmigone committed Dec 4, 2023
1 parent 1562f35 commit b1f6909
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
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"
}
}
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)}`)
})

0 comments on commit b1f6909

Please sign in to comment.