generated from valora-inc/typescript-app-starter
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathshortcuts.ts
60 lines (54 loc) · 1.71 KB
/
shortcuts.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { Address, createPublicClient, http, encodeFunctionData } from 'viem'
import { celo } from 'viem/chains'
import { createShortcut, ShortcutsHook } from '../../types/shortcuts'
import { ubiSchemeAbi } from './abis/ubi-scheme'
import { NetworkId } from '../../types/networkId'
import { ZodAddressLowerCased } from '../../types/address'
const client = createPublicClient({
chain: celo,
transport: http(),
})
const hook: ShortcutsHook = {
async getShortcutDefinitions(networkId: NetworkId, _address?: string) {
if (networkId !== NetworkId['celo-mainnet']) {
return []
}
return [
createShortcut({
id: 'claim-reward',
name: 'Claim',
description: 'Claim daily UBI rewards',
networkIds: [NetworkId['celo-mainnet']],
category: 'claim',
triggerInputShape: {
positionAddress: ZodAddressLowerCased,
},
async onTrigger({ networkId, address, positionAddress }) {
// This isn't strictly needed, but will help while we're developing shortcuts
const { request } = await client.simulateContract({
address: positionAddress, // This is the ubi contract address
abi: ubiSchemeAbi,
functionName: 'claim',
account: address as Address,
})
const data = encodeFunctionData({
abi: request.abi,
args: request.args,
functionName: request.functionName,
})
return {
transactions: [
{
networkId,
from: address,
to: positionAddress,
data,
},
],
}
},
}),
]
},
}
export default hook