Skip to content

Commit b7c9219

Browse files
authored
feat: add hedgey shortcut for claiming (#278)
1 parent 294c968 commit b7c9219

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

src/apps/hedgey/positions.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ const hook: PositionsHook = {
8080
type: 'contract-position-definition',
8181
network,
8282
address: planNft.contractAddress,
83-
tokens: [{ address: tokenAddress, network }],
83+
tokens: [{ address: tokenAddress, network, category: 'claimable' }],
84+
availableShortcutIds: [
85+
`${planNft.contractAddress}:${planNft.tokenId}`,
86+
],
8487
balances: [balance],
8588
displayProps: {
8689
title: `${tokenSymbol} ${contractName} ${planId}`,

src/apps/hedgey/shortcuts.e2e.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import hook from './shortcuts'
2+
3+
const POSITION_ADDRESS = '0x2cde9919e81b20b4b33dd562a48a84b54c48f00c'
4+
5+
describe('getShortcutDefinitions', () => {
6+
it('should get the address definitions successfully', async () => {
7+
const shortcuts = await hook.getShortcutDefinitions(
8+
'celo',
9+
'0x2b8441ef13333ffa955c9ea5ab5b3692da95260d',
10+
)
11+
expect(shortcuts.length).toBeGreaterThan(0)
12+
})
13+
14+
describe('.onTrigger', () => {
15+
it('should return a Transaction', async () => {
16+
const shortcuts = await hook.getShortcutDefinitions(
17+
'celo',
18+
'0x2b8441ef13333ffa955c9ea5ab5b3692da95260d',
19+
)
20+
const shortcut = shortcuts[0]
21+
22+
const transactions = await shortcut.onTrigger(
23+
'celo',
24+
'0x2b8441ef13333ffa955c9ea5ab5b3692da95260d',
25+
POSITION_ADDRESS,
26+
)
27+
28+
expect(transactions.length).toEqual(1)
29+
})
30+
})
31+
})

src/apps/hedgey/shortcuts.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { Address, createPublicClient, http, encodeFunctionData } from 'viem'
2+
import { celo } from 'viem/chains'
3+
import { ShortcutsHook } from '../../types/shortcuts'
4+
import { getHedgeyPlanNfts } from './nfts'
5+
import { tokenVestingPlansAbi } from './abis/token-vesting-plans'
6+
7+
const client = createPublicClient({
8+
chain: celo,
9+
transport: http(),
10+
})
11+
12+
const hook: ShortcutsHook = {
13+
async getShortcutDefinitions(network?: string, address?: string) {
14+
if (network !== 'celo' || !address) {
15+
return []
16+
}
17+
18+
const planNfts = await getHedgeyPlanNfts({ address })
19+
20+
return planNfts.map((planNft) => ({
21+
id: `${planNft.contractAddress}:${planNft.tokenId}`,
22+
name: 'Claim',
23+
description: 'Claim vested rewards',
24+
networks: ['celo'],
25+
category: 'claim',
26+
async onTrigger(network, address, positionAddress) {
27+
// positionAddress === planNft.contractAddress
28+
const { request } = await client.simulateContract({
29+
address: positionAddress as Address,
30+
abi: tokenVestingPlansAbi,
31+
functionName: 'redeemPlans',
32+
args: [[BigInt(planNft.tokenId)]],
33+
account: address as Address,
34+
})
35+
36+
const data = encodeFunctionData({
37+
abi: request.abi,
38+
args: request.args,
39+
functionName: request.functionName,
40+
})
41+
42+
return [
43+
{
44+
network,
45+
from: address,
46+
to: positionAddress as Address,
47+
data,
48+
},
49+
]
50+
},
51+
}))
52+
},
53+
}
54+
55+
export default hook

0 commit comments

Comments
 (0)