Skip to content
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
5 changes: 4 additions & 1 deletion src/apps/hedgey/positions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ const hook: PositionsHook = {
type: 'contract-position-definition',
network,
address: planNft.contractAddress,
tokens: [{ address: tokenAddress, network }],
tokens: [{ address: tokenAddress, network, category: 'claimable' }],
availableShortcutIds: [
`${planNft.contractAddress}:${planNft.tokenId}`,
],
balances: [balance],
displayProps: {
title: `${tokenSymbol} ${contractName} ${planId}`,
Expand Down
31 changes: 31 additions & 0 deletions src/apps/hedgey/shortcuts.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import hook from './shortcuts'

const POSITION_ADDRESS = '0x2cde9919e81b20b4b33dd562a48a84b54c48f00c'

describe('getShortcutDefinitions', () => {
it('should get the address definitions successfully', async () => {
const shortcuts = await hook.getShortcutDefinitions(
'celo',
'0x2b8441ef13333ffa955c9ea5ab5b3692da95260d',
)
expect(shortcuts.length).toBeGreaterThan(0)
})

describe('.onTrigger', () => {
it('should return a Transaction', async () => {
const shortcuts = await hook.getShortcutDefinitions(
'celo',
'0x2b8441ef13333ffa955c9ea5ab5b3692da95260d',
)
const shortcut = shortcuts[0]

const transactions = await shortcut.onTrigger(
'celo',
'0x2b8441ef13333ffa955c9ea5ab5b3692da95260d',
POSITION_ADDRESS,
)

expect(transactions.length).toEqual(1)
})
})
})
55 changes: 55 additions & 0 deletions src/apps/hedgey/shortcuts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { Address, createPublicClient, http, encodeFunctionData } from 'viem'
import { celo } from 'viem/chains'
import { ShortcutsHook } from '../../types/shortcuts'
import { getHedgeyPlanNfts } from './nfts'
import { tokenVestingPlansAbi } from './abis/token-vesting-plans'

const client = createPublicClient({
chain: celo,
transport: http(),
})

const hook: ShortcutsHook = {
async getShortcutDefinitions(network?: string, address?: string) {
if (network !== 'celo' || !address) {
return []
}

const planNfts = await getHedgeyPlanNfts({ address })

return planNfts.map((planNft) => ({
id: `${planNft.contractAddress}:${planNft.tokenId}`,
name: 'Claim',
description: 'Claim vested rewards',
networks: ['celo'],
category: 'claim',
async onTrigger(network, address, positionAddress) {
// positionAddress === planNft.contractAddress
const { request } = await client.simulateContract({
address: positionAddress as Address,
abi: tokenVestingPlansAbi,
functionName: 'redeemPlans',
args: [[BigInt(planNft.tokenId)]],
account: address as Address,
})

const data = encodeFunctionData({
abi: request.abi,
args: request.args,
functionName: request.functionName,
})

return [
{
network,
from: address,
to: positionAddress as Address,
data,
},
]
},
}))
},
}

export default hook