Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/great-jars-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sei-js/precompiles": minor
---

Rename @sei-js/evm to @sei-js/precompiles
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# testing
packages/*/coverage

examples/

# compiled output
dist
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ please refer to the table below.

| Package | Description |
|---------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|
| [@sei-js/evm](packages/evm) | Typescript library containing helper functions for interacting with the EVM on Sei. |
| [@sei-js/precompiles](packages/precompiles) | Typescript library containing helper functions for interacting with Sei's precompile contracts. |
| [@sei-js/create-sei](packages/create-sei) | CLI Tool used to quickly spin up Sei Projects and dApps in either the cosmos or EVM ecosystem |
| [@sei-js/mcp-server](packages/mcp-server) | MCP server for interacting with Sei via LLM's and agents |
| [@sei-js/sei-global-wallet](packages/sei-global-wallet) | A global wallet conforming to EIP-6963 allowing for AA across dApps. |
Expand Down
8 changes: 4 additions & 4 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ flags:
create-sei:
paths:
- packages/create-sei/**
evm:
precompiles:
paths:
- packages/registry/**
- packages/precompiles/**
ledger:
paths:
- packages/ledger/**
Expand All @@ -21,10 +21,10 @@ coverage:
target: 80%
flags:
- create-sei
evm:
precompiles:
target: 80%
flags:
- evm
- precompiles
ledger:
target: 80%
flags:
Expand Down
3 changes: 2 additions & 1 deletion packages/create-sei/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"bin": "./dist/main.js",
"scripts": {
"build": "tsc && cp -r ./templates ./dist/templates",
"dev": "node --loader ts-node/esm src/main.ts"
"dev": "node --loader ts-node/esm src/main.ts",
"docs": "typedoc --out docs"
},
"dependencies": {
"boxen": "^7.1.1",
Expand Down
8 changes: 7 additions & 1 deletion packages/create-sei/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"]
"include": ["src"],
"typedocOptions": {
"readme": "./README.md",
"name": "create-sei",
"entryPoints": ["src/main.ts"],
"exclude": ["node_modules"]
}
}
270 changes: 0 additions & 270 deletions packages/evm/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion packages/ledger/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"typedocOptions": {
"readme": "./README.md",
"name": "registry",
"name": "ledger",
"entryPoints": ["src/index.ts"]
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# @sei-js/evm
# @sei-js/precompiles

<!-- Switched name to @sei-js/precompiles -->

## 2.0.5

Expand Down
147 changes: 147 additions & 0 deletions packages/precompiles/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# @sei-js/precompiles

[![npm version](https://badge.fury.io/js/@sei-js%2Fprecompiles.svg)](https://badge.fury.io/js/@sei-js%2Fprecompiles)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

TypeScript utilities and helpers for interacting with Sei's precompile contracts. Provides seamless integration with popular Ethereum development tools like Viem and Ethers.js, offering typed interfaces, contract factories, ABI's, contract addresses, and utilities specifically designed for Sei's precompile ecosystem.

## 📦 Installation

```bash
npm install @sei-js/precompiles
```

```bash
yarn add @sei-js/precompiles
```

```bash
pnpm add @sei-js/precompiles
```

### Peer Dependencies

This package requires either `ethers` (v6+) or `viem` (v2+) as peer dependencies:

```bash
# For Ethers.js users
npm install ethers@^6.0.0

# For Viem users
npm install viem@^2.0.0
```

## 🚀 Quick Start

### With Viem

```typescript
import { createPublicClient, http } from 'viem'
import { seiMainnet } from '@sei-js/precompiles/viem'
import { BANK_PRECOMPILE_ADDRESS, bankPrecompileAbi } from '@sei-js/precompiles'

const client = createPublicClient({
chain: seiMainnet,
transport: http()
})

// Read token balance
const balance = await client.readContract({
address: BANK_PRECOMPILE_ADDRESS,
abi: bankPrecompileAbi,
functionName: 'balance',
args: ['0x...', 'usei']
})
```

### With Ethers.js

```typescript
import { ethers } from 'ethers'
import { getBankPrecompileEthersV6Contract } from '@sei-js/precompiles/ethers'

const provider = new ethers.JsonRpcProvider('https://evm-rpc.sei-apis.com')
const bankContract = getBankPrecompileEthersV6Contract(provider)

// Read token balance
const balance = await bankContract.balance('0x...', 'usei')
```

## 📋 Available Precompiles

| Precompile | Address | Description |
|------------|---------|-------------|
| **Bank** | `0x0000000000000000000000000000000000001001` | Token operations and balance management |
| **Oracle** | `0x0000000000000000000000000000000000001002` | Price feeds and TWAP data |
| **JSON** | `0x0000000000000000000000000000000000001003` | JSON parsing utilities |
| **Address** | `0x0000000000000000000000000000000000001004` | Address association between EVM and Cosmos |
| **Staking** | `0x0000000000000000000000000000000000001005` | Validator operations and delegation |
| **Governance** | `0x0000000000000000000000000000000000001006` | Voting and proposal management |
| **Distribution** | `0x0000000000000000000000000000000000001007` | Reward distribution and claiming |
| **IBC** | `0x0000000000000000000000000000000000001009` | Cross-chain transfers |
| **Pointerview** | `0x000000000000000000000000000000000000100A` | Token pointer queries |
| **Pointer** | `0x000000000000000000000000000000000000100B` | Token pointer creation |
| **Confidential Transfers** | `0x0000000000000000000000000000000000001010` | Privacy-preserving transactions |
| **WASM** | `0x0000000000000000000000000000000000001002` | CosmWasm contract interaction |

## 📖 Documentation

For comprehensive guides, examples, and API reference, visit our documentation:

**📚 [Complete Documentation →](https://seilabs.mintlify.app/precompiles)**

### Quick Links

- **[Quick Start Guide](https://seilabs.mintlify.app/precompiles/quick-start)** - Get up and running in 5 minutes
- **[Viem Integration](https://seilabs.mintlify.app/precompiles/precompiles/viem)** - Type-safe precompile interactions with Viem
- **[Ethers.js Integration](https://seilabs.mintlify.app/precompiles/precompiles/ethers)** - Use precompile contract factories with Ethers.js

## 🏗️ Usage Examples

### Bank Precompile - Token Operations

```typescript
import { BANK_PRECOMPILE_ADDRESS, bankPrecompileAbi } from '@sei-js/precompiles'

// Send tokens
await writeContract({
address: BANK_PRECOMPILE_ADDRESS,
abi: bankPrecompileAbi,
functionName: 'send',
args: [fromAddress, toAddress, 'usei', amount]
})
```

### Oracle Precompile - Price Data

```typescript
import { ORACLE_PRECOMPILE_ADDRESS, oraclePrecompileAbi } from '@sei-js/precompiles'

// Get exchange rate
const rate = await readContract({
address: ORACLE_PRECOMPILE_ADDRESS,
abi: oraclePrecompileAbi,
functionName: 'getExchangeRate',
args: ['ATOM']
})
```

### Staking Precompile - Validator Operations

```typescript
import { STAKING_PRECOMPILE_ADDRESS, stakingPrecompileAbi } from '@sei-js/precompiles'

// Delegate to validator
await writeContract({
address: STAKING_PRECOMPILE_ADDRESS,
abi: stakingPrecompileAbi,
functionName: 'delegate',
args: [validatorAddress, amount]
})
```

## 🆘 Support

- **Documentation**: [https://seilabs.mintlify.app](https://seilabs.mintlify.app)
- **Discord**: [Sei Discord](https://discord.gg/sei)
- **GitHub Issues**: [Report a bug](https://github.com/sei-protocol/sei-js/issues)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ContractRunner, Contract, InterfaceAbi } from 'ethers';
import { type ContractRunner, Contract, type InterfaceAbi } from 'ethers';
import { ADDRESS_PRECOMPILE_ABI, ADDRESS_PRECOMPILE_ADDRESS } from '../precompiles';

/**
* The ABI for the Address precompile contract, used to create an Ethers contract.
* @category Cosmos Interoperability
* @category ABI
*/
export const ETHERS_ADDRESS_PRECOMPILE_ABI = ADDRESS_PRECOMPILE_ABI as InterfaceAbi;

Expand All @@ -13,7 +13,7 @@ export const ETHERS_ADDRESS_PRECOMPILE_ABI = ADDRESS_PRECOMPILE_ABI as Interface
*
* @example
* ```tsx
* import { getAddressPrecompileEthersV6Contract } from '@sei-js/evm/ethers';
* import { getAddressPrecompileEthersV6Contract } from '@sei-js/precompiles/ethers';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
Expand All @@ -28,7 +28,7 @@ export const ETHERS_ADDRESS_PRECOMPILE_ABI = ADDRESS_PRECOMPILE_ABI as Interface
*
* @param runner A [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance for interacting with the precompile contract.
* @category Cosmos Interoperability
* @category Contract Factory
*/
export function getAddressPrecompileEthersV6Contract(runner: ContractRunner) {
return new Contract(ADDRESS_PRECOMPILE_ADDRESS, ETHERS_ADDRESS_PRECOMPILE_ABI, runner);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Contract, ContractRunner, InterfaceAbi } from 'ethers';
import { Contract, type ContractRunner, type InterfaceAbi } from 'ethers';
import { BANK_PRECOMPILE_ABI, BANK_PRECOMPILE_ADDRESS } from '../precompiles';

/**
* The ABI for the Bank precompile contract, used to create an Ethers contract.
* @category Cosmos Interoperability
* @category ABI
*/
export const ETHERS_BANK_PRECOMPILE_ABI = BANK_PRECOMPILE_ABI as InterfaceAbi;

Expand All @@ -13,7 +13,7 @@ export const ETHERS_BANK_PRECOMPILE_ABI = BANK_PRECOMPILE_ABI as InterfaceAbi;
*
* @example
* ```tsx
* import { getBankPrecompileEthersV6Contract } from '@sei-js/evm/ethers';
* import { getBankPrecompileEthersV6Contract } from '@sei-js/precompiles/ethers';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
Expand All @@ -29,8 +29,8 @@ export const ETHERS_BANK_PRECOMPILE_ABI = BANK_PRECOMPILE_ABI as InterfaceAbi;
*
* @param runner A [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance for interacting with the Bank precompile contract.
* @category Cosmos Interoperability
* @category Contract Factory
*/
export const getBankPrecompileEthersV6Contract = (runner: ContractRunner) => {
return new Contract(BANK_PRECOMPILE_ADDRESS, BANK_PRECOMPILE_ABI, runner);
return new Contract(BANK_PRECOMPILE_ADDRESS, ETHERS_BANK_PRECOMPILE_ABI, runner);
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CONFIDENTIAL_TRANSFERS_PRECOMPILE_ABI, CONFIDENTIAL_TRANSFERS_PRECOMPIL

/**
* The ABI for the Confidential Transfers precompile contract, used to create an Ethers contract.
* @category Cosmos Interoperability
* @category ABI
*/
export const ETHERS_CONFIDENTIAL_TRANSFERS_PRECOMPILE_ABI = CONFIDENTIAL_TRANSFERS_PRECOMPILE_ABI as InterfaceAbi;

Expand All @@ -13,7 +13,7 @@ export const ETHERS_CONFIDENTIAL_TRANSFERS_PRECOMPILE_ABI = CONFIDENTIAL_TRANSFE
*
* @example
* ```tsx
* import { getConfidentialTransfersPrecompileEthersV6Contract } from '@sei-js/evm/ethers';
* import { getConfidentialTransfersPrecompileEthersV6Contract } from '@sei-js/precompiles/ethers';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(window.ethereum); // or any other provider
Expand All @@ -28,7 +28,7 @@ export const ETHERS_CONFIDENTIAL_TRANSFERS_PRECOMPILE_ABI = CONFIDENTIAL_TRANSFE
*
* @param runner A [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance for interacting with the precompile contract.
* @category Cosmos Interoperability
* @category Contract Factory
*/
export function getConfidentialTransfersPrecompileEthersV6Contract(runner: ContractRunner) {
return new Contract(CONFIDENTIAL_TRANSFERS_PRECOMPILE_ADDRESS, ETHERS_CONFIDENTIAL_TRANSFERS_PRECOMPILE_ABI, runner);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Contract, ContractRunner, InterfaceAbi } from 'ethers';
import { Contract, type ContractRunner, type InterfaceAbi } from 'ethers';
import { DISTRIBUTION_PRECOMPILE_ADDRESS, DISTRIBUTION_PRECOMPILE_ABI } from '../precompiles';

/**
* The ABI for the Distribution precompile contract, used to create an Ethers contract.
* @category Cosmos Interoperability
* @category ABI
*/
export const ETHERS_DISTRIBUTION_PRECOMPILE_ABI = DISTRIBUTION_PRECOMPILE_ABI as InterfaceAbi;

Expand All @@ -13,7 +13,7 @@ export const ETHERS_DISTRIBUTION_PRECOMPILE_ABI = DISTRIBUTION_PRECOMPILE_ABI as
*
* @example
* ```tsx
* import { getDistributionPrecompileEthersV6Contract } from '@sei-js/evm/ethers';
* import { getDistributionPrecompileEthersV6Contract } from '@sei-js/precompiles/ethers';
* import { ethers } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
Expand All @@ -27,7 +27,7 @@ export const ETHERS_DISTRIBUTION_PRECOMPILE_ABI = DISTRIBUTION_PRECOMPILE_ABI as
*
* @param runner A [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance for interacting with the Distribution precompile contract.
* @category Cosmos Interoperability
* @category Contract Factory
*/
export const getDistributionPrecompileEthersV6Contract = (runner: ContractRunner) => {
return new Contract(DISTRIBUTION_PRECOMPILE_ADDRESS, ETHERS_DISTRIBUTION_PRECOMPILE_ABI, runner);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Contract, ContractRunner, InterfaceAbi } from 'ethers';
import { Contract, type ContractRunner, type InterfaceAbi } from 'ethers';
import { GOVERNANCE_PRECOMPILE_ABI, GOVERNANCE_PRECOMPILE_ADDRESS } from '../precompiles';

/**
* The ABI for the Governance precompile contract, used to create an Ethers contract.
* @category Cosmos Interoperability
* @category ABI
*/
export const ETHERS_GOVERNANCE_PRECOMPILE_ABI = GOVERNANCE_PRECOMPILE_ABI as InterfaceAbi;

Expand All @@ -13,22 +13,22 @@ export const ETHERS_GOVERNANCE_PRECOMPILE_ABI = GOVERNANCE_PRECOMPILE_ABI as Int
*
* @example
* ```tsx
* import { getGovernancePrecompileEthersV6Contract, parseSei } from '@sei-js/evm/ethers';
* import { ethers } from 'ethers';
* import { getGovernancePrecompileEthersV6Contract } from '@sei-js/precompiles/ethers';
* import { ethers, parseEther } from 'ethers';
*
* const provider = new ethers.BrowserProvider(); // or any other provider
* const signer = provider.getSigner();
*
* const governancePrecompileContract = getGovernancePrecompileEthersV6Contract(signer);
*
* // Surround with try/catch for detailed errors
* const depositResponse = await governancePrecompileContract.connect(signer).deposit('1', { value: parseSei(1) });
* const depositResponse = await governancePrecompileContract.connect(signer).deposit('1', { value: parseEther(1) });

Copilot AI Jun 11, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parseEther function expects a string argument; passing a number will throw a runtime error. Use parseEther('1') instead of parseEther(1).

Suggested change
* const depositResponse = await governancePrecompileContract.connect(signer).deposit('1', { value: parseEther(1) });
* const depositResponse = await governancePrecompileContract.connect(signer).deposit('1', { value: parseEther('1') });

Copilot uses AI. Check for mistakes.
* console.log('Deposit Response:', depositResponse);
* ```
*
* @param runner A [Provider](https://docs.ethers.org/v6/api/providers/) (read-only) or ethers.Signer to use with the contract.
* @returns The typed contract instance for interacting with the Governance precompile contract.
* @category Cosmos Interoperability
* @category Contract Factory
*/
export const getGovernancePrecompileEthersV6Contract = (runner: ContractRunner) => {
return new Contract(GOVERNANCE_PRECOMPILE_ADDRESS, ETHERS_GOVERNANCE_PRECOMPILE_ABI, runner);
Expand Down
Loading