Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat(tally): add support for tally delegate #41

Merged
merged 40 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
e950ee8
Feat(registry): add delegate action support
Quazia Sep 26, 2023
8b5314b
Test(registry): test delegate action executes
Quazia Sep 26, 2023
cf2cdad
Feat(tally): dupe template
Quazia Sep 27, 2023
13d54c7
Feat(tally): add abi
Quazia Sep 27, 2023
2298caf
Test(tally): add test tx
Quazia Sep 27, 2023
3487297
Feat(tally): implement delegate function
Quazia Sep 27, 2023
304b44e
Feat(tally): implement support functions
Quazia Sep 27, 2023
2a3bd68
Chore(pnpm): bump questdk version
Quazia Oct 2, 2023
7ab0189
Test(tally): valid filter
Quazia Oct 2, 2023
8ad15c2
Test(tally): tx testing
Quazia Oct 2, 2023
d60b55b
chore: format
Quazia Oct 2, 2023
bf9236e
Chore(pnpm): update questdk for registry
Quazia Oct 2, 2023
fb9d87a
Chore(pnpm): regen lockfile
Quazia Oct 2, 2023
8078682
chore: format
Quazia Oct 2, 2023
2817d39
Chore(pnpm): update questdk version
Quazia Oct 3, 2023
7135baf
chore: format
Quazia Oct 3, 2023
ae419cc
Fix(registry): tweak executePlugin types
Quazia Oct 3, 2023
65af2b0
Merge branch 'add_delegate_action_support' of https://github.com/rabb…
Quazia Oct 3, 2023
b868a36
chore: format
Quazia Oct 3, 2023
5a3f372
Merge branch 'add_delegate_action_support' of https://github.com/rabb…
Quazia Oct 3, 2023
7dcadd8
chore: format
Quazia Oct 3, 2023
244db6f
Chore(pnpm): update questdk version
Quazia Oct 3, 2023
c29b6c3
Merge branch 'add_tally_plugin' of https://github.com/rabbitholegg/qu…
Quazia Oct 3, 2023
c9a5f30
Chore(pnpm): regen lockfile
Quazia Oct 3, 2023
961034f
Fix(uniswap): update router address
Quazia Oct 3, 2023
fb2df32
chore: format
Quazia Oct 3, 2023
7e3b82d
Merge branch 'add_delegate_action_support' of https://github.com/rabb…
Quazia Oct 3, 2023
4572127
Fix(tally): fix delegatee vs delegate
Quazia Oct 3, 2023
815145d
chore: format
Quazia Oct 3, 2023
dffe8bf
Fix(tally): delegate vs delegatee in test
Quazia Oct 3, 2023
e5375ef
Merge branch 'add_tally_plugin' of https://github.com/rabbitholegg/qu…
Quazia Oct 3, 2023
0289ed8
Chore(changeset): tally release
Quazia Oct 3, 2023
6598da9
chore: format
Quazia Oct 3, 2023
858426e
Chore(registry): add tally to registry
Quazia Oct 3, 2023
72234a7
merge
Quazia Oct 3, 2023
9cf05c8
chore: format
Quazia Oct 3, 2023
05faf3d
Fix(tally): apply filter correctly
Quazia Oct 3, 2023
f34cfb8
Merge branch 'add_tally_plugin' of https://github.com/rabbitholegg/qu…
Quazia Oct 3, 2023
294e376
chore: format
Quazia Oct 3, 2023
11ea4ae
Docs(tally): remove hanging comments
Quazia Oct 3, 2023
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
6 changes: 6 additions & 0 deletions .changeset/rotten-monkeys-attack.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rabbitholegg/questdk-plugin-registry": minor
"@rabbitholegg/questdk-plugin-tally": minor
---

Add delegate for Tally
2 changes: 1 addition & 1 deletion packages/across/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"vitest": "0.33.0"
},
"dependencies": {
"@rabbitholegg/questdk": "1.0.1-alpha.10",
"@rabbitholegg/questdk": "1.1.0-alpha.13",
"viem": "1.2.15"
}
}
2 changes: 1 addition & 1 deletion packages/arbitrum/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"vitest": "0.33.0"
},
"dependencies": {
"@rabbitholegg/questdk": "1.0.1-alpha.10",
"@rabbitholegg/questdk": "1.1.0-alpha.13",
"viem": "1.2.15"
}
}
2 changes: 1 addition & 1 deletion packages/connext/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"@connext/nxtp-txservice": "^2.0.0",
"@connext/nxtp-utils": "^2.0.4",
"@connext/smart-contracts": "^2.0.0",
"@rabbitholegg/questdk": "1.0.1-alpha.10",
"@rabbitholegg/questdk": "1.1.0-alpha.13",
"viem": "^1.2.15"
}
}
2 changes: 1 addition & 1 deletion packages/gmx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"vitest": "0.33.0"
},
"dependencies": {
"@rabbitholegg/questdk": "1.0.1-alpha.10",
"@rabbitholegg/questdk": "1.1.0-alpha.13",
"axios": "1.5.0",
"viem": "1.2.15"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/hop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"dependencies": {
"@hop-protocol/core": "0.0.1-beta.182",
"@hop-protocol/sdk": "0.0.1-beta.535",
"@rabbitholegg/questdk": "1.0.1-alpha.10",
"@rabbitholegg/questdk": "1.1.0-alpha.13",
"viem": "1.2.15"
}
}
2 changes: 1 addition & 1 deletion packages/optimism/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"dependencies": {
"@eth-optimism/contracts-ts": "0.15.0",
"@rabbitholegg/questdk": "1.0.1-alpha.10",
"@rabbitholegg/questdk": "1.1.0-alpha.13",
"viem": "1.2.15"
}
}
2 changes: 1 addition & 1 deletion packages/polygon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
},
"dependencies": {
"@maticnetwork/pos-portal": "1.5.2",
"@rabbitholegg/questdk": "1.0.1-alpha.10",
"@rabbitholegg/questdk": "1.1.0-alpha.13",
"viem": "1.2.15"
}
}
3 changes: 2 additions & 1 deletion packages/registry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"vitest": "^0.33.0"
},
"dependencies": {
"@rabbitholegg/questdk": "1.0.1-alpha.10",
"@rabbitholegg/questdk": "1.1.0-alpha.14",
"@rabbitholegg/questdk-plugin-connext": "workspace:*",
"@rabbitholegg/questdk-plugin-uniswap": "workspace:*",
"@rabbitholegg/questdk-plugin-stargate": "workspace:*",
Expand All @@ -54,6 +54,7 @@
"@rabbitholegg/questdk-plugin-arbitrum": "workspace:*",
"@rabbitholegg/questdk-plugin-optimism": "workspace:*",
"@rabbitholegg/questdk-plugin-gmx": "workspace:*",
"@rabbitholegg/questdk-plugin-tally": "workspace:*",
"viem": "^1.2.15"
}
}
4 changes: 4 additions & 0 deletions packages/registry/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ describe('executePlugin', () => {
bridge: vi.fn(),
swap: vi.fn(),
mint: vi.fn(),
delegate: vi.fn(),
} as unknown as IActionPlugin

await executePlugin(mockPlugin, ActionType.Bridge, mockParams)
Expand All @@ -44,6 +45,9 @@ describe('executePlugin', () => {

await executePlugin(mockPlugin, ActionType.Mint, mockParams)
expect(mockPlugin.mint).toHaveBeenCalledWith(mockParams)

await executePlugin(mockPlugin, ActionType.Delegate, mockParams)
expect(mockPlugin.delegate).toHaveBeenCalledWith(mockParams)
})

test('should throw an error for unknown action type', () => {
Expand Down
12 changes: 10 additions & 2 deletions packages/registry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import {
ActionType,
type BridgeActionParams,
type IActionPlugin,
type MintActionParams,
PluginActionNotImplementedError,
type MintActionParams,
type SwapActionParams,
type DelegateActionParams,
type TransactionFilter,
} from '@rabbitholegg/questdk'

Expand All @@ -18,6 +19,7 @@ import { Optimism } from '@rabbitholegg/questdk-plugin-optimism'
import { Hop } from '@rabbitholegg/questdk-plugin-hop'
import { Arbitrum } from '@rabbitholegg/questdk-plugin-arbitrum'
import { GMX } from '@rabbitholegg/questdk-plugin-gmx'
import { Tally } from '@rabbitholegg/questdk-plugin-tally'

export const plugins: Record<string, IActionPlugin> = {
[Connext.pluginId]: Connext,
Expand All @@ -29,6 +31,7 @@ export const plugins: Record<string, IActionPlugin> = {
[Across.pluginId]: Across,
[Optimism.pluginId]: Optimism,
[GMX.pluginId]: GMX,
[Tally.pluginId]: Tally,
}

export const getPlugin = (pluginId: string) => {
Expand All @@ -43,14 +46,19 @@ export const executePlugin = (
plugin: IActionPlugin,
actionType: ActionType,
params: ActionParams,
): Promise<TransactionFilter> | Promise<PluginActionNotImplementedError> => {
): Promise<TransactionFilter | PluginActionNotImplementedError> => {
switch (actionType) {
case ActionType.Bridge:
return plugin.bridge(params as unknown as BridgeActionParams)
case ActionType.Swap:
return plugin.swap(params as unknown as SwapActionParams)
case ActionType.Mint:
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)
}
default:
throw new Error(`Unknown action type "${actionType}"`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/stargate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"vitest": "0.33.0"
},
"dependencies": {
"@rabbitholegg/questdk": "1.0.1-alpha.10",
"@rabbitholegg/questdk": "1.1.0-alpha.13",
"viem": "1.6.7"
}
}
Empty file added packages/tally/README.md
Empty file.
50 changes: 50 additions & 0 deletions packages/tally/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@rabbitholegg/questdk-plugin-tally",
"version": "1.0.0-alpha.1",
"type": "module",
"exports": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js",
"types": "./dist/types/index.d.ts"
},
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"packageManager": "[email protected]",
"description": "",
"scripts": {
"bench": "vitest bench",
"bench:ci": "CI=true vitest bench",
"build": "pnpm run clean && pnpm run build:cjs && pnpm run build:esm && pnpm run build:types",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
"build:esm": "tsc --project tsconfig.build.json --module es2015 --outDir ./dist/esm && echo > ./dist/esm/package.json '{\"type\":\"module\",\"sideEffects\":false}'",
"build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
"clean": "rimraf dist",
"format": "rome format . --write",
"lint": "rome check .",
"lint:fix": "pnpm lint --apply",
"preinstall": "npx only-allow pnpm",
"test": "vitest dev",
"test:cov": "vitest dev --coverage",
"test:ci": "CI=true vitest --coverage",
"test:ui": "vitest dev --ui"
},
"keywords": [],
"author": "",
"license": "ISC",
"types": "./dist/types/index.d.ts",
"typings": "./dist/types/index.d.ts",
"devDependencies": {
"@types/node": "^20.4.5",
"@vitest/coverage-v8": "^0.33.0",
"rimraf": "^5.0.1",
"rome": "^12.1.3",
"ts-node": "^10.9.1",
"tsconfig": "workspace:*",
"typescript": "^5.1.6",
"vitest": "^0.33.0"
},
"dependencies": {
"@rabbitholegg/questdk": "1.1.0-alpha.14",
"viem": "^1.2.15"
}
}
53 changes: 53 additions & 0 deletions packages/tally/src/Tally.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { apply } from '@rabbitholegg/questdk/filter'
import { describe, expect, test } from 'vitest'
import { TALLY_ABI } from './abi.js'
import { ARB_ONE_CHAIN_ID } from './chain-ids.js'
import { TALLY_TOKENS } from './token-addresses.js'
import { delegate } from './Tally.js'
import { ARBITRUM_DELEGATION } from './test-transactions.js'
const TEST_ADDRESS = '0x95222290DD7278Aa3Ddd389Cc1E1d165CC4BAfe5'
const TEST_PROJECT = TALLY_TOKENS[ARB_ONE_CHAIN_ID][0]

describe('Given the tally plugin', () => {
describe('When handling the delegate', () => {
test('should return a valid action filter', async () => {
const filter = await delegate({
chainId: ARB_ONE_CHAIN_ID,
delegate: TEST_ADDRESS,
project: TEST_PROJECT,
})
expect(filter).to.deep.equal({
chainId: ARB_ONE_CHAIN_ID,
to: TEST_PROJECT,
input: {
$abi: TALLY_ABI,
delegatee: TEST_ADDRESS,
},
})
})

test('should pass filter with valid transactions', async () => {
const transaction = ARBITRUM_DELEGATION
const PROJECT_TARGET = '0x912ce59144191c1204e64559fe8253a0e49e6548'

const filter = await delegate({
chainId: ARB_ONE_CHAIN_ID,
delegate: '0x3f9e3fbbbe967481222ddaa98e84470d7099381f',
project: PROJECT_TARGET,
})
expect(apply(transaction, filter)).to.be.true
})

test('should not pass filter with invalid transactions', async () => {
const transaction = ARBITRUM_DELEGATION
const PROJECT_TARGET = '0x912ce59144191c1204e64559fe8253a0e49e6548'
const filter = await delegate({
chainId: ARB_ONE_CHAIN_ID,
delegate: TEST_ADDRESS,
project: PROJECT_TARGET,
})
console.log(filter)
expect(apply(transaction, filter)).to.be.false
})
})
})
28 changes: 28 additions & 0 deletions packages/tally/src/Tally.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { type DelegateActionParams, compressJson } from '@rabbitholegg/questdk'
import { TALLY_ABI } from './abi.js'
import { CHAIN_ID_ARRAY } from './chain-ids.js'
import { TALLY_TOKENS } from './token-addresses.js'
// If you're implementing swap or mint, simply duplicate this function and change the name
export const delegate = async (delegateParams: DelegateActionParams) => {
// This is the information we'll use to compose the Transaction object
const { chainId, delegate, project } = delegateParams
// We always want to return a compressed JSON object which we'll transform into a TransactionFilter
return compressJson({
chainId: chainId, // The chainId of the source chain
to: project, // The contract address of the governance platform
input: {
$abi: TALLY_ABI, // The ABI of the contract
delegatee: delegate, // The address of the delegatee
}, // The input object is where we'll put the ABI and the parameters
})
}

export const getSupportedTokenAddresses = async (_chainId: number) => {
// Given a specific chain we would expect this function to return a list of supported token addresses
return TALLY_TOKENS[_chainId]
}

export const getSupportedChainIds = async () => {
// This should return all of the ChainIds that are supported by the Project we're integrating
return CHAIN_ID_ARRAY // only supporting ARB right now
}
53 changes: 53 additions & 0 deletions packages/tally/src/abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
export const TALLY_ABI = [
{
inputs: [
{
internalType: 'address',
name: 'delegatee',
type: 'address',
},
],
name: 'delegate',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: 'delegatee',
type: 'address',
},
{
internalType: 'uint256',
name: 'nonce',
type: 'uint256',
},
{
internalType: 'uint256',
name: 'expiry',
type: 'uint256',
},
{
internalType: 'uint8',
name: 'v',
type: 'uint8',
},
{
internalType: 'bytes32',
name: 'r',
type: 'bytes32',
},
{
internalType: 'bytes32',
name: 's',
type: 'bytes32',
},
],
name: 'delegateBySig',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
]
4 changes: 4 additions & 0 deletions packages/tally/src/chain-ids.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// The arbitrum Native Bridge only supports three chains, Arbitrum, Arbitrum Nova, and Ethereum
export const ARB_ONE_CHAIN_ID = 42161

export const CHAIN_ID_ARRAY = [ARB_ONE_CHAIN_ID]
24 changes: 24 additions & 0 deletions packages/tally/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file is standard for more projects.
// The main degree of nuance is in the

import {
type IActionPlugin,
PluginActionNotImplementedError,
} from '@rabbitholegg/questdk'

import {
delegate,
getSupportedChainIds,
getSupportedTokenAddresses,
} from './Tally.js'

// Replace *project* with the name of the project
export const Tally: IActionPlugin = {
pluginId: 'tally',
getSupportedTokenAddresses,
getSupportedChainIds,
bridge: async () => new PluginActionNotImplementedError(),
swap: async () => new PluginActionNotImplementedError(),
mint: async () => new PluginActionNotImplementedError(),
delegate,
}
Loading