Skip to content

Commit

Permalink
Merge pull request #3 from StauroDEV/jamesmccomish/master
Browse files Browse the repository at this point in the history
#1 cleanup + add delegates
  • Loading branch information
talentlessguy authored May 28, 2024
2 parents d45a50f + 40a8a8c commit 295174b
Show file tree
Hide file tree
Showing 44 changed files with 2,536 additions and 1,687 deletions.
9 changes: 9 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Account Variables
PK=

# Test Variables
VITE_TEST_NETWORK_TYPE='ETHEREUM_SEPOLIA'
VITE_ANVIL_SAFE_ADDRESS='SHORTNAME:ADDRESS' # sep:0xbcA814Ee6E571d0BbC335b4e3869F89E532Ba8B8
VITE_TEST_ADDRESS= # sep:0xD7a0ca30F71cFDF45534B058c567a5FaE6C33846
VITE_ANVIL_FORK_URL=https://rpc.sepolia.dev
VITE_ANVIL_BLOCK_NUMBER=5211612
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
run: pnpm install

- name: lint code
run: pnpm lint
run: pnpm lint && pnpm lint:types

- name: Install foundry
uses: foundry-rs/foundry-toolchain@v1
Expand All @@ -59,7 +59,8 @@ jobs:
env:
VITE_ANVIL_FORK_URL: ${{ vars.VITE_ANVIL_FORK_URL }}
VITE_ANVIL_BLOCK_NUMBER: ${{ vars.VITE_ANVIL_BLOCK_NUMBER }}
VITE_ANVIL_SAFE_ADDRESS: ${{ vars.VITE_SAFE_ADDRESS }}
VITE_ANVIL_SAFE_ADDRESS: ${{ vars.VITE_ANVIL_SAFE_ADDRESS }}
VITE_TEST_ADDRESS: ${{ vars.VITE_TEST_ADDRESS }}

# run coverage only on ubuntu
- name: Coveralls
Expand Down
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"editor.formatOnSave": false,
"eslint.experimental.useFlatConfig": true,
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"typescript.tsdk": "node_modules/typescript/lib"
}
33 changes: 33 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import eslint from '@eslint/js'
import tseslint from 'typescript-eslint'
import stylistic from '@stylistic/eslint-plugin'

const config = tseslint.config(
{
files: ['src/**/*.ts', 'src/*.tsx'],
ignores: ['node_modules', 'dist', '.next'],
},
eslint.configs.recommended,
...tseslint.configs.recommended,
stylistic.configs.customize({
indent: 2,
quotes: 'single',
jsx: true,
semi: false,
}),
{
settings: {
react: {
version: 'detect',
},
},
plugins: {
stylistic,
},
rules: {
'stylistic/no-multiple-empty-lines': ['error', { max: 1 }],
},
},
)

export default config
29 changes: 29 additions & 0 deletions examples/add-delegate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ApiClient } from '../src/api.js'
import { sepolia } from 'viem/chains'
import { EIP3770Address } from '../src/types.js'
import { createWalletClient, http, Hex, Address } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { generateSafeDelegateSignature } from '../src/actions.js'

const safeAddress = process.env.SAFE_ADDRESS as EIP3770Address

const delegate = process.env.SAFE_DELEGATE as Address

const apiClient = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', safeAddress, chainId: sepolia.id })

const walletClient = createWalletClient({
transport: http(),
chain: sepolia,
account: privateKeyToAccount(process.env.PK as Hex),
})

const signature = await generateSafeDelegateSignature(walletClient, {
delegate,
})

await apiClient.createDelegate({
delegate,
delegator: walletClient.account.address,
signature,
label: 'Delegate #1',
})
8 changes: 4 additions & 4 deletions examples/get-delegates.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ApiClient } from '../src/api.js'
import { goerli } from 'viem/chains'
import { sepolia } from 'viem/chains'
import { EIP3770Address } from '../src/types.js'

const safeAddress = process.env.SAFE_ADDRESS as EIP3770Address

const apiClient = new ApiClient({ url: 'https://safe-transaction-goerli.safe.global', safeAddress, chainId: goerli.id })
const apiClient = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', safeAddress, chainId: sepolia.id })

const response = await apiClient.getDelegates({ limit:'100' })
const response = await apiClient.getDelegates({ limit: '100' })

console.log(`List of delegates for ${safeAddress}:\n`)

for (const delegate of response.results) {
console.log(`${delegate.label}: ${delegate.delegate}`)
}
}
21 changes: 11 additions & 10 deletions examples/propose-tx.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
import { http, createPublicClient, createWalletClient, Hex, parseEther } from 'viem'
import { goerli } from 'viem/chains'
import { sepolia } from 'viem/chains'
import { publicSafeActions, walletSafeActions } from '../src/actions.js'
import { EIP3770Address, OperationType, SafeTransactionData } from '../src/types.js'
import { ApiClient } from '../src/api.js'
import { privateKeyToAccount } from 'viem/accounts'

const safeAddress = process.env.SAFE_ADDRESS as EIP3770Address

const publicClient = createPublicClient({
const config = {
transport: http(),
chain: goerli
}).extend(publicSafeActions(safeAddress))
chain: sepolia,
} as const

const publicClient = createPublicClient(config).extend(publicSafeActions(safeAddress))

const walletClient = createWalletClient({
transport: http(),
chain: goerli,
account: privateKeyToAccount(process.env.PK as Hex)
...config,
account: privateKeyToAccount(process.env.PK as Hex),
}).extend(walletSafeActions(safeAddress))

const txData: Pick<SafeTransactionData, 'to' | 'operation' | 'value'> = {
to: process.env.SAFE_TO as EIP3770Address,
operation: OperationType.Call,
value: parseEther('0.001')
value: parseEther('0.001'),
}

const safeTxGas = await publicClient.estimateSafeTransactionGas(txData)
Expand All @@ -34,12 +35,12 @@ const safeTxHash = await publicClient.getSafeTransactionHash({ ...txData, safeTx

const senderSignature = await walletClient.generateSafeTransactionSignature({ ...txData, nonce, safeTxGas, baseGas })

const apiClient = new ApiClient({ url: 'https://safe-transaction-goerli.safe.global', safeAddress, chainId: goerli.id })
const apiClient = new ApiClient({ url: 'https://safe-transaction-sepolia.safe.global', safeAddress, chainId: sepolia.id })

await apiClient.proposeTransaction({
safeTransactionData: { ...txData, safeTxGas, baseGas, nonce },
senderAddress: walletClient.account.address,
safeTxHash,
senderSignature,
origin: 'Piggybank'
origin: 'Piggybank',
})
31 changes: 16 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,35 @@
"dist"
],
"devDependencies": {
"@stylistic/eslint-plugin": "^1.6.0",
"@types/node": "^20.11.16",
"@types/semver": "^7.5.6",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@viem/anvil": "^0.0.7",
"@vitest/coverage-v8": "^1.2.2",
"eslint": "^8.56.0",
"@stylistic/eslint-plugin": "^2.1.0",
"@types/node": "^20.12.12",
"@types/semver": "^7.5.8",
"@viem/anvil": "^0.0.10",
"@vitest/coverage-v8": "^1.6.0",
"eslint": "^9.3.0",
"prettier": "^3.2.5",
"tsx": "^4.7.0",
"typescript": "^5.3.3",
"viem": "^2.7.6",
"vitest": "^1.2.2"
"tsx": "^4.11.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.11.0",
"viem": "^2.13.1",
"vitest": "^1.6.0"
},
"peerDependencies": {
"viem": ">=1.16"
},
"dependencies": {
"semver": "^7.6.0"
"semver": "^7.6.2"
},
"scripts": {
"build": "tsc -p tsconfig.build.json",
"lint": "eslint --ext .ts",
"lint": "eslint src/**/*.ts eslint.config.js",
"lint:types": "tsc --noEmit",
"prepublishOnly": "pnpm build",
"test": "vitest run",
"test:coverage": "vitest run --coverage"
},
"publishConfig": {
"access": "public"
}
},
"packageManager": "pnpm@9.0.6"
}
Loading

0 comments on commit 295174b

Please sign in to comment.