-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathindex.ts
312 lines (302 loc) · 10.8 KB
/
index.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
import { Across } from '@rabbitholegg/questdk-plugin-across'
import { Aerodrome } from '@rabbitholegg/questdk-plugin-aerodrome'
import { Arbitrum } from '@rabbitholegg/questdk-plugin-arbitrum'
import { ArtBlocks } from '@rabbitholegg/questdk-plugin-artblocks'
import { Balancer } from '@rabbitholegg/questdk-plugin-balancer'
import { Base } from '@rabbitholegg/questdk-plugin-base'
import { BasePaint } from '@rabbitholegg/questdk-plugin-basepaint'
import { Boost } from '@rabbitholegg/questdk-plugin-boost'
import { Camelot } from '@rabbitholegg/questdk-plugin-camelot'
import { Connext } from '@rabbitholegg/questdk-plugin-connext'
import { Fabric } from '@rabbitholegg/questdk-plugin-fabric'
import { GMX } from '@rabbitholegg/questdk-plugin-gmx'
import { HandleFi } from '@rabbitholegg/questdk-plugin-handlefi'
import { Hop } from '@rabbitholegg/questdk-plugin-hop'
import { Hyphen } from '@rabbitholegg/questdk-plugin-hyphen'
import { JOJO } from '@rabbitholegg/questdk-plugin-jojo'
import { Kote } from '@rabbitholegg/questdk-plugin-kote'
import { Kwenta } from '@rabbitholegg/questdk-plugin-kwenta'
import { Llama } from '@rabbitholegg/questdk-plugin-llama'
import { Manifold } from '@rabbitholegg/questdk-plugin-manifold'
import { Mirror } from '@rabbitholegg/questdk-plugin-mirror'
import { Mux } from '@rabbitholegg/questdk-plugin-mux'
import { Neynar } from '@rabbitholegg/questdk-plugin-neynar'
import { OkuTrade } from '@rabbitholegg/questdk-plugin-okutrade'
import { Optimism } from '@rabbitholegg/questdk-plugin-optimism'
import { Orbit } from '@rabbitholegg/questdk-plugin-orbit'
import { Paragraph } from '@rabbitholegg/questdk-plugin-paragraph'
import { Paraswap } from '@rabbitholegg/questdk-plugin-paraswap'
import { Pendle } from '@rabbitholegg/questdk-plugin-pendle'
import { Pods } from '@rabbitholegg/questdk-plugin-pods'
import { Polygon } from '@rabbitholegg/questdk-plugin-polygon'
import { Rabbithole } from '@rabbitholegg/questdk-plugin-rabbithole'
import { Soundxyz } from '@rabbitholegg/questdk-plugin-soundxyz'
import { Stargate } from '@rabbitholegg/questdk-plugin-stargate'
import { Superbridge } from '@rabbitholegg/questdk-plugin-superbridge'
import { Sushi } from '@rabbitholegg/questdk-plugin-sushi'
import { Synapse } from '@rabbitholegg/questdk-plugin-synapse'
import { Tally } from '@rabbitholegg/questdk-plugin-tally'
import { Thruster } from '@rabbitholegg/questdk-plugin-thruster'
import { Titles } from '@rabbitholegg/questdk-plugin-titles'
import { TraderJoe } from '@rabbitholegg/questdk-plugin-traderjoe'
import { Treasure } from '@rabbitholegg/questdk-plugin-treasure'
import { Uniswap } from '@rabbitholegg/questdk-plugin-uniswap'
import { Vela } from '@rabbitholegg/questdk-plugin-vela'
import { WooFi } from '@rabbitholegg/questdk-plugin-woofi'
import { Zora } from '@rabbitholegg/questdk-plugin-zora'
import { Foundation } from '@rabbitholegg/questdk-plugin-foundation'
import { ThirdWeb } from '@rabbitholegg/questdk-plugin-thirdweb'
import { Lens } from '@rabbitholegg/questdk-plugin-lens'
import { Moshicam } from '@rabbitholegg/questdk-plugin-moshicam'
// ^^^ New Imports Go Here ^^^
import {
ActionType,
PluginActionNotImplementedError,
type ActionParams,
type BridgeActionParams,
type CreateActionParams,
type DelegateActionParams,
type IActionPlugin,
type IntentParams,
type MintActionParams,
type MintIntentParams,
type OptionsActionParams,
type PluginActionValidation,
type QuestActionParams,
type StakeActionParams,
type SwapActionParams,
type TransactionFilter,
type VoteActionParams,
} from '@rabbitholegg/questdk-plugin-utils'
import type { Address, PublicClient } from 'viem'
export const plugins: Record<string, IActionPlugin> = {
[Connext.pluginId]: Connext,
[Uniswap.pluginId]: Uniswap,
[Stargate.pluginId]: Stargate,
[Across.pluginId]: Across,
[Polygon.pluginId]: Polygon,
[Optimism.pluginId]: Optimism,
[Hop.pluginId]: Hop,
[Arbitrum.pluginId]: Arbitrum,
[GMX.pluginId]: GMX,
[Camelot.pluginId]: Camelot,
[Tally.pluginId]: Tally,
[BasePaint.pluginId]: BasePaint,
[Hyphen.pluginId]: Hyphen,
[Paraswap.pluginId]: Paraswap,
[Rabbithole.pluginId]: Rabbithole,
[OkuTrade.pluginId]: OkuTrade,
[Zora.pluginId]: Zora,
[Balancer.pluginId]: Balancer,
[TraderJoe.pluginId]: TraderJoe,
[Synapse.pluginId]: Synapse,
[WooFi.pluginId]: WooFi,
[Sushi.pluginId]: Sushi,
[Treasure.pluginId]: Treasure,
[Pendle.pluginId]: Pendle,
[HandleFi.pluginId]: HandleFi,
[Mirror.pluginId]: Mirror,
[Soundxyz.pluginId]: Soundxyz,
[Mux.pluginId]: Mux,
[Vela.pluginId]: Vela,
[Boost.pluginId]: Boost,
[Llama.pluginId]: Llama,
[Kote.pluginId]: Kote,
[JOJO.pluginId]: JOJO,
[ArtBlocks.pluginId]: ArtBlocks,
[Manifold.pluginId]: Manifold,
[Fabric.pluginId]: Fabric,
[Paragraph.pluginId]: Paragraph,
[Aerodrome.pluginId]: Aerodrome,
[Pods.pluginId]: Pods,
[Kwenta.pluginId]: Kwenta,
[Thruster.pluginId]: Thruster,
[Base.pluginId]: Base,
[Orbit.pluginId]: Orbit,
[Superbridge.pluginId]: Superbridge,
[Neynar.pluginId]: Neynar,
[Titles.pluginId]: Titles,
[Foundation.pluginId]: Foundation,
[ThirdWeb.pluginId]: ThirdWeb,
[Lens.pluginId]: Lens,
[Moshicam.pluginId]: Moshicam,
}
export const getPlugin = (pluginId: string) => {
const plugin = plugins[pluginId]
if (!plugin) {
throw new Error(`Unknown plugin "${pluginId}"`)
}
return plugin
}
export const getTxIntent = (
plugin: IActionPlugin,
actionType: ActionType,
params: IntentParams,
) => {
switch (actionType) {
case ActionType.Mint:
if (plugin.getMintIntent !== undefined) {
return plugin.getMintIntent(params as unknown as MintIntentParams)
} else {
throw new PluginActionNotImplementedError()
}
default:
throw new Error(`Unknown action type "${actionType}"`)
}
}
export const getTxSimulation = (
plugin: IActionPlugin,
actionType: ActionType,
params: IntentParams,
value: bigint,
client?: PublicClient,
account?: Address,
creatorAddress?: Address,
) => {
switch (actionType) {
case ActionType.Mint:
if (plugin.simulateMint !== undefined) {
return plugin.simulateMint(
params as unknown as MintIntentParams,
value,
account,
client,
creatorAddress,
)
} else {
throw new PluginActionNotImplementedError()
}
default:
throw new Error(`Unknown action type "${actionType}"`)
}
}
export const getProjectFees = (
plugin: IActionPlugin,
actionType: ActionType,
params: ActionParams,
) => {
switch (actionType) {
case ActionType.Mint:
if (plugin.mint && plugin.getProjectFees) {
return plugin.getProjectFees(params as unknown as MintActionParams)
} else {
throw new PluginActionNotImplementedError()
}
default:
throw new Error(`Unknown action type "${actionType}"`)
}
}
export const getFees = (
plugin: IActionPlugin,
actionType: ActionType,
params: ActionParams,
) => {
switch (actionType) {
case ActionType.Mint:
if (plugin.mint && plugin.getFees) {
return plugin.getFees(params as unknown as MintActionParams)
} else {
throw new PluginActionNotImplementedError()
}
default:
throw new Error(`Unknown action type "${actionType}"`)
}
}
export const getExternalUrl = (
plugin: IActionPlugin,
params: ActionParams,
actionType?: ActionType,
) => {
if (typeof plugin.getExternalUrl === 'function') {
return plugin.getExternalUrl(params, actionType)
} else {
throw new PluginActionNotImplementedError()
}
}
export const canValidate = (plugin: IActionPlugin, actionType: ActionType) => {
switch (actionType) {
case ActionType.Follow:
return plugin.validateFollow !== undefined
case ActionType.Recast:
return plugin.validateRecast !== undefined
case ActionType.Complete:
return plugin.validateComplete !== undefined
case ActionType.Collect:
return plugin.validateCollect !== undefined
default:
return false
}
}
// This should take a QuestActionValidationPaylod type
export const executeValidation = (
plugin: IActionPlugin,
validationPayload: PluginActionValidation,
) => {
const actionType = validationPayload.payload.validationParams.type
// We might not even need a switch statement here since we narrow in the actual plugin
switch (actionType) {
case ActionType.Recast:
case ActionType.Follow:
case ActionType.Complete:
case ActionType.Collect:
if (plugin.validate) {
return plugin.validate(validationPayload)
} else {
throw new PluginActionNotImplementedError()
}
default:
throw new Error(`Unknown action type "${actionType}"`)
}
}
export const executePlugin = (
plugin: IActionPlugin,
actionType: ActionType,
params: ActionParams,
): Promise<TransactionFilter | PluginActionNotImplementedError> => {
switch (actionType) {
case ActionType.Bridge:
if (plugin.bridge === undefined) {
return Promise.reject(new PluginActionNotImplementedError())
} else return plugin.bridge(params as unknown as BridgeActionParams)
case ActionType.Swap:
if (plugin.swap === undefined) {
return Promise.reject(new PluginActionNotImplementedError())
} else return plugin.swap(params as unknown as SwapActionParams)
case ActionType.Mint:
if (plugin.mint === undefined) {
return Promise.reject(new PluginActionNotImplementedError())
} else return plugin.mint(params as unknown as MintActionParams)
case ActionType.Delegate: {
if (plugin.delegate === undefined) {
return Promise.reject(new PluginActionNotImplementedError())
} else return plugin.delegate(params as unknown as DelegateActionParams)
}
case ActionType.Quest: {
if (plugin.quest === undefined) {
return Promise.reject(new PluginActionNotImplementedError())
} else return plugin.quest(params as unknown as QuestActionParams)
}
case ActionType.Stake: {
if (plugin.stake === undefined) {
return Promise.reject(new PluginActionNotImplementedError())
} else return plugin.stake(params as unknown as StakeActionParams)
}
case ActionType.Options: {
if (plugin.options === undefined) {
return Promise.reject(new PluginActionNotImplementedError())
} else return plugin.options(params as unknown as OptionsActionParams)
}
case ActionType.Vote: {
if (plugin.vote === undefined) {
return Promise.reject(new PluginActionNotImplementedError())
} else return plugin.vote(params as unknown as VoteActionParams)
}
case ActionType.Create: {
if (plugin.create === undefined) {
return Promise.reject(new PluginActionNotImplementedError())
} else return plugin.create(params as unknown as CreateActionParams)
}
default:
throw new Error(`Unknown action type "${actionType}"`)
}
}