-
Notifications
You must be signed in to change notification settings - Fork 127
@audius/eth refactor #13800
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
base: main
Are you sure you want to change the base?
@audius/eth refactor #13800
Changes from all commits
2410bb2
aa91fef
e3d9232
eec1a7a
c8f1408
71b7b11
30e3a4f
8911849
6f10f49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| --- | ||
| '@audius/eth': major | ||
| --- | ||
|
|
||
| Release 1.0.0 | ||
|
|
||
| - All contracts now simply export their ABIs and addresses. | ||
| - No viem dependency required. | ||
| - Treeshakable. | ||
| - Added examples and documentation. | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,114 @@ | ||
| # `@audius/eth` | ||
|
|
||
| A Typescript package for interacting with the Audius Governance and Staking [Ethereum Contracts](../../eth-contracts/). | ||
| Typed ABIs and production addresses for the [Audius Ethereum contracts](../../eth-contracts/). Designed for use with [viem](https://viem.sh/) and fully tree-shakable — import only the contracts you need. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| npm install @audius/eth viem | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| Each contract export is a plain object with `abi` and `address`: | ||
|
|
||
| ```ts | ||
| import { createPublicClient, http } from 'viem' | ||
| import { mainnet } from 'viem/chains' | ||
| import { Staking } from '@audius/eth' | ||
|
|
||
| const client = createPublicClient({ | ||
| chain: mainnet, | ||
| transport: http() | ||
| }) | ||
|
|
||
| const totalStaked = await client.readContract({ | ||
| ...Staking, | ||
| functionName: 'totalStaked' | ||
| }) | ||
| ``` | ||
|
|
||
| ### Check pending rewards claim | ||
|
|
||
| ```ts | ||
| import { ClaimsManager } from '@audius/eth' | ||
|
|
||
| const isPending = await client.readContract({ | ||
| ...ClaimsManager, | ||
| functionName: 'claimPending', | ||
| args: ['0xYourServiceProviderAddress'] | ||
| }) | ||
| ``` | ||
|
|
||
| ### Read a governance proposal | ||
|
|
||
| ```ts | ||
| import { Governance } from '@audius/eth' | ||
|
|
||
| const proposal = await client.readContract({ | ||
| ...Governance, | ||
| functionName: 'getProposalById', | ||
| args: [1n] | ||
| }) | ||
| ``` | ||
|
|
||
| ### Look up service provider endpoints | ||
|
|
||
| ```ts | ||
| import { ServiceProviderFactory, VALIDATOR_SERVICE_TYPE } from '@audius/eth' | ||
|
|
||
| // Get the total number of validators | ||
| const total = await client.readContract({ | ||
| ...ServiceProviderFactory, | ||
| functionName: 'getTotalServiceTypeProviders', | ||
| args: [VALIDATOR_SERVICE_TYPE] | ||
| }) | ||
|
|
||
| // Get the endpoint info for the first one | ||
| const info = await client.readContract({ | ||
| ...ServiceProviderFactory, | ||
| functionName: 'getServiceEndpointInfo', | ||
| args: [VALIDATOR_SERVICE_TYPE, 1n] | ||
| }) | ||
| ``` | ||
|
|
||
| ### EIP-2612 permit (gasless approval) | ||
|
|
||
| `AudiusToken` and `AudiusWormhole` include `domain` and `types` for EIP-712 signing: | ||
|
|
||
| ```ts | ||
| import { AudiusToken } from '@audius/eth' | ||
|
|
||
| const signature = await walletClient.signTypedData({ | ||
| domain: { | ||
| ...AudiusToken.domain, | ||
| chainId: 1, | ||
| verifyingContract: AudiusToken.address | ||
| }, | ||
| types: AudiusToken.types, | ||
| primaryType: 'Permit', | ||
| message: { | ||
| owner: '0x...', | ||
| spender: '0x...', | ||
| value: 1000000000000000000n, | ||
| nonce: 0n, | ||
| deadline: 99999999999n | ||
| } | ||
| }) | ||
| ``` | ||
|
|
||
| ## Contracts | ||
|
|
||
| | Export | Description | | ||
| | ------------------------ | ----------------------------------------------------------------------------------- | | ||
| | `AudiusToken` | The AUDIO ERC-20 token. Mintable, pausable, burnable. Supports EIP-2612 `permit()`. | | ||
| | `AudiusWormhole` | Sends AUDIO cross-chain via Wormhole with meta-transaction support. | | ||
| | `ClaimsManager` | Periodic minting and distribution of AUDIO staking rewards. | | ||
| | `DelegateManager` | Delegation of AUDIO tokens to service providers with lockup periods. | | ||
| | `EthRewardsManager` | Transfers AUDIO rewards from Ethereum to Solana via Wormhole. | | ||
| | `Governance` | On-chain governance: proposals, stake-weighted voting, execution. | | ||
| | `Registry` | Central directory mapping contract names to addresses. | | ||
| | `ServiceProviderFactory` | Registration and staking for discovery nodes and content nodes. | | ||
| | `ServiceTypeManager` | Registry of valid service types and their versions. | | ||
| | `Staking` | Core staking contract holding all staked AUDIO with checkpointing. | | ||
| | `TrustedNotifierManager` | Registry of trusted notifier entities. | |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,89 +1,11 @@ | ||
| import type { PublicClient } from 'viem' | ||
|
|
||
| import { abi } from './abi' | ||
| import { CLAIMS_MANAGER_CONTRACT_ADDRESS } from './constants' | ||
|
|
||
| export class ClaimsManager { | ||
| client: PublicClient | ||
| address: `0x${string}` | ||
|
|
||
| constructor( | ||
| client: PublicClient, | ||
| { address }: { address?: `0x${string}` } = {} | ||
| ) { | ||
| this.client = client | ||
| this.address = address ?? CLAIMS_MANAGER_CONTRACT_ADDRESS | ||
| } | ||
|
|
||
| // Get the duration of a funding round in blocks | ||
| getFundingRoundBlockDiff = () => | ||
| this.client.readContract({ | ||
| address: this.address, | ||
| abi, | ||
| functionName: 'getFundingRoundBlockDiff' | ||
| }) | ||
|
|
||
| // Get the last block where a funding round was initiated | ||
| getLastFundedBlock = () => | ||
| this.client.readContract({ | ||
| address: this.address, | ||
| abi, | ||
| functionName: 'getLastFundedBlock' | ||
| }) | ||
|
|
||
| // Get the amount funded per round in wei | ||
| getFundsPerRound = () => | ||
| this.client.readContract({ | ||
| address: this.address, | ||
| abi, | ||
| functionName: 'getFundsPerRound' | ||
| }) | ||
|
|
||
| // total amount claimed in the current round | ||
| getTotalClaimedInRound = () => | ||
| this.client.readContract({ | ||
| address: this.address, | ||
| abi, | ||
| functionName: 'getTotalClaimedInRound' | ||
| }) | ||
|
|
||
| // Get the Governance address | ||
| getGovernanceAddress = () => | ||
| this.client.readContract({ | ||
| address: this.address, | ||
| abi, | ||
| functionName: 'getGovernanceAddress' | ||
| }) | ||
|
|
||
| // Get the ServiceProviderFactory address | ||
| getServiceProviderFactoryAddress = () => | ||
| this.client.readContract({ | ||
| address: this.address, | ||
| abi, | ||
| functionName: 'getServiceProviderFactoryAddress' | ||
| }) | ||
|
|
||
| // Get the DelegateManager address | ||
| getDelegateManagerAddress = () => | ||
| this.client.readContract({ | ||
| address: this.address, | ||
| abi, | ||
| functionName: 'getDelegateManagerAddress' | ||
| }) | ||
|
|
||
| // Get the Staking address | ||
| getStakingAddress = () => | ||
| this.client.readContract({ | ||
| address: this.address, | ||
| abi, | ||
| functionName: 'getStakingAddress' | ||
| }) | ||
|
|
||
| claimPending = ({ address }: { address: `0x${string}` }) => | ||
| this.client.readContract({ | ||
| address: this.address, | ||
| abi, | ||
| functionName: 'claimPending', | ||
| args: [address] | ||
| }) | ||
| /** | ||
| * Manages periodic minting and distribution of AUDIO staking rewards. | ||
| * Controls funding rounds (~weekly), mints new tokens according to the | ||
| * protocol's inflation schedule, and tracks per-round claim amounts. | ||
| */ | ||
| export const ClaimsManager = { | ||
| abi, | ||
| address: '0x44617F9dCEd9787C3B06a05B35B4C779a2AA1334' as const | ||
| } |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| import { abi } from './abi' | ||
|
|
||
| export class DelegateManager { | ||
| public static readonly abi = abi | ||
|
|
||
| public static readonly address = '0x4d7968ebfD390D5E7926Cb3587C39eFf2F9FB225' | ||
| /** | ||
| * Manages delegation of AUDIO tokens to service providers. Delegators can | ||
| * increase or decrease their delegated stake with lockup periods to prevent | ||
| * anticipatory withdrawal before slashing. Includes per-SP minimum | ||
| * delegation amounts (V2). | ||
| */ | ||
| export const DelegateManager = { | ||
| abi, | ||
| address: '0x4d7968ebfD390D5E7926Cb3587C39eFf2F9FB225' as const | ||
| } |
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,24 +1,11 @@ | ||
| import type { PublicClient } from 'viem' | ||
|
|
||
| import { abi } from './abi' | ||
| import { ETH_REWARDS_MANAGER_CONTRACT_ADDRESS } from './constants' | ||
|
|
||
| export class EthRewardsManager { | ||
| client: PublicClient | ||
| address: `0x${string}` | ||
|
|
||
| constructor( | ||
| client: PublicClient, | ||
| { address }: { address?: `0x${string}` } = {} | ||
| ) { | ||
| this.client = client | ||
| this.address = address ?? ETH_REWARDS_MANAGER_CONTRACT_ADDRESS | ||
| } | ||
|
|
||
| getAntiAbuseOracleAddresses = () => | ||
| this.client.readContract({ | ||
| address: this.address, | ||
| abi, | ||
| functionName: 'getAntiAbuseOracleAddresses' | ||
| }) | ||
| /** | ||
| * Manages transferring AUDIO reward tokens from Ethereum to Solana via the | ||
| * Wormhole bridge for the Solana-based rewards system. Holds anti-abuse | ||
| * oracle addresses. Only governance can modify configuration. | ||
| */ | ||
| export const EthRewardsManager = { | ||
| abi, | ||
| address: '0x5aa6B99A2B461bA8E97207740f0A689C5C39C3b0' as const | ||
| } |
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.